summaryrefslogtreecommitdiff
path: root/src/unit/taf.unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit/taf.unit')
-rw-r--r--src/unit/taf.unit180
1 files changed, 90 insertions, 90 deletions
diff --git a/src/unit/taf.unit b/src/unit/taf.unit
index a4f4f86..eb9475e 100644
--- a/src/unit/taf.unit
+++ b/src/unit/taf.unit
@@ -13,109 +13,109 @@
13#include <string.h> 13#include <string.h>
14#include <unistd.h> 14#include <unistd.h>
15 15
16{=Init} 16suite Taf
17
18{%read1}
19{ 17{
18 test read1
19 {
20#define FN_TMP ("/tmp/tmpXXXXXXXX") 20#define FN_TMP ("/tmp/tmpXXXXXXXX")
21 Bu::FString sFnTmp(FN_TMP); 21 Bu::FString sFnTmp(FN_TMP);
22 Bu::File fOut = Bu::File::tempFile( sFnTmp ); 22 Bu::File fOut = Bu::File::tempFile( sFnTmp );
23 const char *data = 23 const char *data =
24"{test: name=\"Bob\"}" 24 "{test: name=\"Bob\"}"
25; 25 ;
26 fOut.write(data,strlen(data)); 26 fOut.write(data,strlen(data));
27 fOut.close(); 27 fOut.close();
28 28
29 Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); 29 Bu::File fIn(sFnTmp.getStr(), Bu::File::Read );
30 Bu::TafReader tr(fIn); 30 Bu::TafReader tr(fIn);
31 31
32 Bu::TafGroup *tn = tr.readGroup(); 32 Bu::TafGroup *tn = tr.readGroup();
33 unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); 33 unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) );
34 delete tn; 34 delete tn;
35 35
36 unlink(sFnTmp.getStr()); 36 unlink(sFnTmp.getStr());
37#undef FN_TMP 37#undef FN_TMP
38} 38 }
39 39
40{%encode1} 40 test encode1
41{ 41 {
42 Bu::MemBuf mb; 42 Bu::MemBuf mb;
43 Bu::TafWriter tw( mb ); 43 Bu::TafWriter tw( mb );
44 44
45 Bu::TafGroup g("Test data"); 45 Bu::TafGroup g("Test data");
46 Bu::FString sData( 256 ); 46 Bu::FString sData( 256 );
47 for( int j = 0; j < 256; j++ ) 47 for( int j = 0; j < 256; j++ )
48 sData[j] = (unsigned char)j; 48 sData[j] = (unsigned char)j;
49 g.addChild( new Bu::TafProperty("Encoded", sData) ); 49 g.addChild( new Bu::TafProperty("Encoded", sData) );
50 tw.writeGroup( &g ); 50 tw.writeGroup( &g );
51 51
52 static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" 52 static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\""
53 "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" 53 "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07"
54 "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" 54 "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F"
55 "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" 55 "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17"
56 "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" 56 "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F"
57 " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" 57 " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD"
58 "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" 58 "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi"
59 "jklmnopqrstuvwxyz{|}~\\x7F" 59 "jklmnopqrstuvwxyz{|}~\\x7F"
60 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" 60 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87"
61 "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" 61 "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F"
62 "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" 62 "\\x90\\x91\\x92\\x93\\x94\\x95\\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5\\xF6\\xF7" 74 "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7"
75 "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; 75 "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n";
76 unitTest( mb.getString() == cmpdata ); 76 unitTest( mb.getString() == cmpdata );
77 mb.setPos( 0 ); 77 mb.setPos( 0 );
78 Bu::TafReader tr( mb ); 78 Bu::TafReader tr( mb );
79 Bu::TafGroup *rg = tr.readGroup(); 79 Bu::TafGroup *rg = tr.readGroup();
80 unitTest( rg->getProperty("Encoded") == sData ); 80 unitTest( rg->getProperty("Encoded") == sData );
81 delete rg; 81 delete rg;
82} 82 }
83 83
84{%emptyStr1} 84 test emptyStr1
85{ 85 {
86 Bu::MemBuf mb; 86 Bu::MemBuf mb;
87 Bu::TafWriter tw( mb ); 87 Bu::TafWriter tw( mb );
88 88
89 Bu::TafGroup g("Test Group"); 89 Bu::TafGroup g("Test Group");
90 Bu::FString sVal; 90 Bu::FString sVal;
91 g.addChild( new Bu::TafProperty("Lame", sVal) ); 91 g.addChild( new Bu::TafProperty("Lame", sVal) );
92 tw.writeGroup( &g ); 92 tw.writeGroup( &g );
93 93
94 unitTest( 94 unitTest(
95 mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); 95 mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" );
96} 96 }
97 97
98{%incomplete1} 98 test incomplete1
99{
100 try
101 { 99 {
102 Bu::MemBuf mb("{Lame: \"Hello=\""); 100 try
103 Bu::TafReader tr( mb ); 101 {
104 delete tr.readGroup(); 102 Bu::MemBuf mb("{Lame: \"Hello=\"");
105 unitFailed("Should have thrown an exception, didn't."); 103 Bu::TafReader tr( mb );
104 delete tr.readGroup();
105 unitFailed("Should have thrown an exception, didn't.");
106 }
107 catch( Bu::TafException &e )
108 {
109 // Woot
110 }
106 } 111 }
107 catch( Bu::TafException &e ) 112
113 test bypath1
108 { 114 {
109 // Woot 115 Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }");
116 Bu::TafReader tr( mb );
117 const Bu::TafGroup *g = tr.readGroup();
118 unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" );
119 unitTest( g->getByPath("inner/final/test") == "hi" );
110 } 120 }
111} 121}
112
113{%bypath1}
114{
115 Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }");
116 Bu::TafReader tr( mb );
117 const Bu::TafGroup *g = tr.readGroup();
118 unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" );
119 unitTest( g->getByPath("inner/final/test") == "hi" );
120}
121