aboutsummaryrefslogtreecommitdiff
path: root/src/unit/taf.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/taf.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp
index 71bd867..0813444 100644
--- a/src/unit/taf.cpp
+++ b/src/unit/taf.cpp
@@ -8,6 +8,8 @@
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/tafreader.h" 10#include "bu/tafreader.h"
11#include "bu/tafwriter.h"
12#include "bu/membuf.h"
11 13
12#include <string.h> 14#include <string.h>
13#include <unistd.h> 15#include <unistd.h>
@@ -19,6 +21,7 @@ public:
19 { 21 {
20 setName("taf"); 22 setName("taf");
21 addTest( Unit::read1 ); 23 addTest( Unit::read1 );
24 addTest( Unit::encode );
22 } 25 }
23 26
24 virtual ~Unit() 27 virtual ~Unit()
@@ -46,6 +49,50 @@ public:
46 unlink(sFnTmp.getStr()); 49 unlink(sFnTmp.getStr());
47#undef FN_TMP 50#undef FN_TMP
48 } 51 }
52
53 void encode()
54 {
55 Bu::MemBuf mb;
56 Bu::TafWriter tw( mb );
57
58 Bu::TafGroup g("Test data");
59 Bu::FString sData( 256 );
60 for( int j = 0; j < 256; j++ )
61 sData[j] = (unsigned char)j;
62 g.addChild( new Bu::TafProperty("Encoded", sData) );
63 tw.writeGroup( &g );
64
65 static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\""
66 "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07"
67 "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F"
68 "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17"
69 "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F"
70 " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD"
71 "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi"
72 "jklmnopqrstuvwxyz{|}~\\x7F"
73 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87"
74 "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F"
75 "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97"
76 "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F"
77 "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7"
78 "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF"
79 "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7"
80 "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF"
81 "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7"
82 "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF"
83 "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7"
84 "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF"
85 "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7"
86 "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF"
87 "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7"
88 "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n";
89 unitTest( mb.getString() == cmpdata );
90 mb.setPos( 0 );
91 Bu::TafReader tr( mb );
92 Bu::TafGroup *rg = tr.readGroup();
93 unitTest( rg->getProperty("Encoded") == sData );
94 delete rg;
95 }
49}; 96};
50 97
51int main( int argc, char *argv[] ) 98int main( int argc, char *argv[] )