aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
commit306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch)
tree32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/unit
parent11413d228bae2919fe69c83b74c7ff49209dd65a (diff)
downloadlibbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip
mkunit.sh was a little dumb, it didn't handle a number of things correctly.
I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad.
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/archive.unit337
-rw-r--r--src/unit/array.unit121
-rw-r--r--src/unit/file.unit123
-rw-r--r--src/unit/fstring.unit550
-rw-r--r--src/unit/hash.unit113
-rw-r--r--src/unit/list.unit206
-rw-r--r--src/unit/membuf.unit61
-rw-r--r--src/unit/queuebuf.unit148
-rw-r--r--src/unit/substream.unit74
-rw-r--r--src/unit/taf.unit180
-rw-r--r--src/unit/xml.unit13
11 files changed, 966 insertions, 960 deletions
diff --git a/src/unit/archive.unit b/src/unit/archive.unit
index a0ae3ef..a7f2640 100644
--- a/src/unit/archive.unit
+++ b/src/unit/archive.unit
@@ -12,184 +12,185 @@
12 12
13using namespace Bu; 13using namespace Bu;
14 14
15{=Init} 15suite Archive
16
17{%testPrimitives}
18{ 16{
19 MemBuf mb; 17 test primitives
20 {
21 Archive ar( mb, Archive::save );
22 ar << (int8_t)1;
23 ar << (uint8_t)2;
24 ar << (int16_t)3;
25 ar << (uint16_t)4;
26 ar << (int32_t)5;
27 ar << (uint32_t)6;
28 ar << (int64_t)7;
29 ar << (uint64_t)8;
30 ar << (char)9;
31 ar << (unsigned char)10;
32 ar << (short)11;
33 ar << (unsigned short)12;
34 ar << (int)13;
35 ar << (unsigned int)14;
36 ar << (long)15;
37 ar << (unsigned long)16;
38 ar << (long long)17;
39 ar << (unsigned long long)18;
40 ar.close();
41 }
42 mb.setPos( 0 );
43 { 18 {
44 Archive ar( mb, Archive::load ); 19 MemBuf mb;
45 int8_t p1; 20 {
46 uint8_t p2; 21 Archive ar( mb, Archive::save );
47 int16_t p3; 22 ar << (int8_t)1;
48 uint16_t p4; 23 ar << (uint8_t)2;
49 int32_t p5; 24 ar << (int16_t)3;
50 uint32_t p6; 25 ar << (uint16_t)4;
51 int64_t p7; 26 ar << (int32_t)5;
52 uint64_t p8; 27 ar << (uint32_t)6;
53 char p9; 28 ar << (int64_t)7;
54 unsigned char p10; 29 ar << (uint64_t)8;
55 short p11; 30 ar << (char)9;
56 unsigned short p12; 31 ar << (unsigned char)10;
57 int p13; 32 ar << (short)11;
58 unsigned int p14; 33 ar << (unsigned short)12;
59 long p15; 34 ar << (int)13;
60 unsigned long p16; 35 ar << (unsigned int)14;
61 long long p17; 36 ar << (long)15;
62 unsigned long long p18; 37 ar << (unsigned long)16;
63 ar >> p1; 38 ar << (long long)17;
64 ar >> p2; 39 ar << (unsigned long long)18;
65 ar >> p3; 40 ar.close();
66 ar >> p4; 41 }
67 ar >> p5; 42 mb.setPos( 0 );
68 ar >> p6; 43 {
69 ar >> p7; 44 Archive ar( mb, Archive::load );
70 ar >> p8; 45 int8_t p1;
71 ar >> p9; 46 uint8_t p2;
72 ar >> p10; 47 int16_t p3;
73 ar >> p11; 48 uint16_t p4;
74 ar >> p12; 49 int32_t p5;
75 ar >> p13; 50 uint32_t p6;
76 ar >> p14; 51 int64_t p7;
77 ar >> p15; 52 uint64_t p8;
78 ar >> p16; 53 char p9;
79 ar >> p17; 54 unsigned char p10;
80 ar >> p18; 55 short p11;
81 unitTest( p1 == 1 ); 56 unsigned short p12;
82 unitTest( p2 == 2 ); 57 int p13;
83 unitTest( p3 == 3 ); 58 unsigned int p14;
84 unitTest( p4 == 4 ); 59 long p15;
85 unitTest( p5 == 5 ); 60 unsigned long p16;
86 unitTest( p6 == 6 ); 61 long long p17;
87 unitTest( p7 == 7 ); 62 unsigned long long p18;
88 unitTest( p8 == 8 ); 63 ar >> p1;
89 unitTest( p9 == 9 ); 64 ar >> p2;
90 unitTest( p10 == 10 ); 65 ar >> p3;
91 unitTest( p11 == 11 ); 66 ar >> p4;
92 unitTest( p12 == 12 ); 67 ar >> p5;
93 unitTest( p13 == 13 ); 68 ar >> p6;
94 unitTest( p14 == 14 ); 69 ar >> p7;
95 unitTest( p15 == 15 ); 70 ar >> p8;
96 unitTest( p16 == 16 ); 71 ar >> p9;
97 unitTest( p17 == 17 ); 72 ar >> p10;
98 unitTest( p18 == 18 ); 73 ar >> p11;
99 ar.close(); 74 ar >> p12;
75 ar >> p13;
76 ar >> p14;
77 ar >> p15;
78 ar >> p16;
79 ar >> p17;
80 ar >> p18;
81 unitTest( p1 == 1 );
82 unitTest( p2 == 2 );
83 unitTest( p3 == 3 );
84 unitTest( p4 == 4 );
85 unitTest( p5 == 5 );
86 unitTest( p6 == 6 );
87 unitTest( p7 == 7 );
88 unitTest( p8 == 8 );
89 unitTest( p9 == 9 );
90 unitTest( p10 == 10 );
91 unitTest( p11 == 11 );
92 unitTest( p12 == 12 );
93 unitTest( p13 == 13 );
94 unitTest( p14 == 14 );
95 unitTest( p15 == 15 );
96 unitTest( p16 == 16 );
97 unitTest( p17 == 17 );
98 unitTest( p18 == 18 );
99 ar.close();
100 }
100 } 101 }
101}
102 102
103{%testContainers1} 103 test containers1
104{
105 MemBuf mb;
106 {
107 Archive ar( mb, Archive::save );
108 FString sStr("This is a test string.");
109 List<int> lList;
110 lList.append( 10 );
111 lList.append( 20 );
112 lList.append( 30 );
113 lList.append( 40 );
114 ar << sStr;
115 ar << lList;
116 ar.close();
117 }
118 mb.setPos( 0 );
119 { 104 {
120 Archive ar( mb, Archive::load ); 105 MemBuf mb;
121 FString sStr; 106 {
122 List<int> lList; 107 Archive ar( mb, Archive::save );
123 ar >> sStr; 108 FString sStr("This is a test string.");
124 ar >> lList; 109 List<int> lList;
125 unitTest( sStr == "This is a test string." ); 110 lList.append( 10 );
126 unitTest( lList.getSize() == 4 ); 111 lList.append( 20 );
127 List<int>::iterator i = lList.begin(); 112 lList.append( 30 );
128 unitTest( *i == 10 ); i++; 113 lList.append( 40 );
129 unitTest( *i == 20 ); i++; 114 ar << sStr;
130 unitTest( *i == 30 ); i++; 115 ar << lList;
131 unitTest( *i == 40 ); 116 ar.close();
132 ar.close(); 117 }
118 mb.setPos( 0 );
119 {
120 Archive ar( mb, Archive::load );
121 FString sStr;
122 List<int> lList;
123 ar >> sStr;
124 ar >> lList;
125 unitTest( sStr == "This is a test string." );
126 unitTest( lList.getSize() == 4 );
127 List<int>::iterator i = lList.begin();
128 unitTest( *i == 10 ); i++;
129 unitTest( *i == 20 ); i++;
130 unitTest( *i == 30 ); i++;
131 unitTest( *i == 40 );
132 ar.close();
133 }
133 } 134 }
134}
135 135
136{%testContainers2} 136 test containers2
137{
138 MemBuf mb;
139 {
140 Archive ar( mb, Archive::save );
141 FString sStr("This is a test string.");
142 Array<int> lArray;
143 lArray.append( 10 );
144 lArray.append( 20 );
145 lArray.append( 30 );
146 lArray.append( 40 );
147 ar << sStr;
148 ar << lArray;
149 ar.close();
150 }
151 mb.setPos( 0 );
152 { 137 {
153 Archive ar( mb, Archive::load ); 138 MemBuf mb;
154 FString sStr; 139 {
155 Array<int> lArray; 140 Archive ar( mb, Archive::save );
156 ar >> sStr; 141 FString sStr("This is a test string.");
157 ar >> lArray; 142 Array<int> lArray;
158 unitTest( sStr == "This is a test string." ); 143 lArray.append( 10 );
159 unitTest( lArray.getSize() == 4 ); 144 lArray.append( 20 );
160 Array<int>::iterator i = lArray.begin(); 145 lArray.append( 30 );
161 unitTest( *i == 10 ); i++; 146 lArray.append( 40 );
162 unitTest( *i == 20 ); i++; 147 ar << sStr;
163 unitTest( *i == 30 ); i++; 148 ar << lArray;
164 unitTest( *i == 40 ); 149 ar.close();
165 ar.close(); 150 }
151 mb.setPos( 0 );
152 {
153 Archive ar( mb, Archive::load );
154 FString sStr;
155 Array<int> lArray;
156 ar >> sStr;
157 ar >> lArray;
158 unitTest( sStr == "This is a test string." );
159 unitTest( lArray.getSize() == 4 );
160 Array<int>::iterator i = lArray.begin();
161 unitTest( *i == 10 ); i++;
162 unitTest( *i == 20 ); i++;
163 unitTest( *i == 30 ); i++;
164 unitTest( *i == 40 );
165 ar.close();
166 }
166 } 167 }
167}
168 168
169{%testContainers3} 169 test containers3
170{
171 MemBuf mb;
172 {
173 Archive ar( mb, Archive::save );
174 Array<FString> lArray;
175 lArray.append( "10" );
176 lArray.append( "20" );
177 lArray.append( "30" );
178 lArray.append( "40" );
179 ar << lArray;
180 ar.close();
181 }
182 mb.setPos( 0 );
183 { 170 {
184 Archive ar( mb, Archive::load ); 171 MemBuf mb;
185 Array<FString> lArray; 172 {
186 ar >> lArray; 173 Archive ar( mb, Archive::save );
187 unitTest( lArray.getSize() == 4 ); 174 Array<FString> lArray;
188 Array<FString>::iterator i = lArray.begin(); 175 lArray.append( "10" );
189 unitTest( *i == "10" ); i++; 176 lArray.append( "20" );
190 unitTest( *i == "20" ); i++; 177 lArray.append( "30" );
191 unitTest( *i == "30" ); i++; 178 lArray.append( "40" );
192 unitTest( *i == "40" ); 179 ar << lArray;
193 ar.close(); 180 ar.close();
181 }
182 mb.setPos( 0 );
183 {
184 Archive ar( mb, Archive::load );
185 Array<FString> lArray;
186 ar >> lArray;
187 unitTest( lArray.getSize() == 4 );
188 Array<FString>::iterator i = lArray.begin();
189 unitTest( *i == "10" ); i++;
190 unitTest( *i == "20" ); i++;
191 unitTest( *i == "30" ); i++;
192 unitTest( *i == "40" );
193 ar.close();
194 }
194 } 195 }
195} 196}
diff --git a/src/unit/array.unit b/src/unit/array.unit
index ad249ef..1493033 100644
--- a/src/unit/array.unit
+++ b/src/unit/array.unit
@@ -9,76 +9,77 @@
9#include "bu/hash.h" 9#include "bu/hash.h"
10#include "bu/array.h" 10#include "bu/array.h"
11 11
12{=Init} 12suite Array
13
14{%general}
15{ 13{
16 Bu::Array<int> ai; 14 test general
15 {
16 Bu::Array<int> ai;
17 17
18 ai.append( 5 ); 18 ai.append( 5 );
19 ai.append( 10 ); 19 ai.append( 10 );
20 unitTest( ai.getSize() == 2 ); 20 unitTest( ai.getSize() == 2 );
21 unitTest( ai.getCapacity() == 10 ); 21 unitTest( ai.getCapacity() == 10 );
22 unitTest( ai[0] == 5 ); 22 unitTest( ai[0] == 5 );
23 unitTest( ai[1] == 10 ); 23 unitTest( ai[1] == 10 );
24} 24 }
25 25
26{%iterate1} 26 test iterate1
27{ 27 {
28 Bu::Array<int> ai; 28 Bu::Array<int> ai;
29 for( int j = 0; j < 10; j++ ) 29 for( int j = 0; j < 10; j++ )
30 ai.append( j ); 30 ai.append( j );
31 31
32 int j = 0; 32 int j = 0;
33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
34 unitTest( (*i) == j++ ); 34 unitTest( (*i) == j++ );
35 unitTest( j == 10 ); 35 unitTest( j == 10 );
36 36
37 const Bu::Array<int> &ci = ai; 37 const Bu::Array<int> &ci = ai;
38 j = 0; 38 j = 0;
39 for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) 39 for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ )
40 unitTest( (*i) == j++ ); 40 unitTest( (*i) == j++ );
41 unitTest( j == 10 ); 41 unitTest( j == 10 );
42} 42 }
43 43
44{%iterate2} 44 test iterate2
45{ 45 {
46 Bu::Array<int> ai; 46 Bu::Array<int> ai;
47 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 47 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
48 unitFailed("Empty lists shouldn't be iterated through."); 48 unitFailed("Empty lists shouldn't be iterated through.");
49 for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) 49 for( Bu::Array<int>::iterator i = ai.begin(); i; i++ )
50 unitFailed("Empty lists shouldn't be iterated through."); 50 unitFailed("Empty lists shouldn't be iterated through.");
51} 51 }
52 52
53{%copy} 53 test copy
54{ 54 {
55 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash; 55 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
56 typedef Bu::Array<StrHash> StrHashArray; 56 typedef Bu::Array<StrHash> StrHashArray;
57 57
58 StrHash h1; 58 StrHash h1;
59 h1["Hi"] = "Yo"; 59 h1["Hi"] = "Yo";
60 h1["Bye"] = "Later"; 60 h1["Bye"] = "Later";
61 61
62 StrHash h2; 62 StrHash h2;
63 h2["Test"] = "Bloop"; 63 h2["Test"] = "Bloop";
64 h2["Foo"] = "ooF"; 64 h2["Foo"] = "ooF";
65 65
66 StrHashArray a1; 66 StrHashArray a1;
67 a1.append( h1 ); 67 a1.append( h1 );
68 a1.append( h2 ); 68 a1.append( h2 );
69 69
70 StrHashArray a2(a1); 70 StrHashArray a2(a1);
71 71
72 unitTest( a2[0].get("Hi") == "Yo" ); 72 unitTest( a2[0].get("Hi") == "Yo" );
73 unitTest( a2[0].get("Bye") == "Later" ); 73 unitTest( a2[0].get("Bye") == "Later" );
74 unitTest( a2[1].get("Test") == "Bloop" ); 74 unitTest( a2[1].get("Test") == "Bloop" );
75 unitTest( a2[1].get("Foo") == "ooF" ); 75 unitTest( a2[1].get("Foo") == "ooF" );
76 76
77 StrHashArray a3; 77 StrHashArray a3;
78 a3 = a1; 78 a3 = a1;
79 79
80 unitTest( a3[0].get("Hi") == "Yo" ); 80 unitTest( a3[0].get("Hi") == "Yo" );
81 unitTest( a3[0].get("Bye") == "Later" ); 81 unitTest( a3[0].get("Bye") == "Later" );
82 unitTest( a3[1].get("Test") == "Bloop" ); 82 unitTest( a3[1].get("Test") == "Bloop" );
83 unitTest( a3[1].get("Foo") == "ooF" ); 83 unitTest( a3[1].get("Foo") == "ooF" );
84 }
84} 85}
diff --git a/src/unit/file.unit b/src/unit/file.unit
index 11c82fb..f8cf7c1 100644
--- a/src/unit/file.unit
+++ b/src/unit/file.unit
@@ -12,84 +12,85 @@
12#include <sys/stat.h> 12#include <sys/stat.h>
13#include <unistd.h> 13#include <unistd.h>
14 14
15{=Init} 15suite File
16
17{%writeFull}
18{ 16{
19 Bu::File sf("testfile1", Bu::File::WriteNew ); 17 test writeFull
20 for( int c = 0; c < 256; c++ )
21 { 18 {
22 unsigned char ch = (unsigned char)c; 19 Bu::File sf("testfile1", Bu::File::WriteNew );
23 sf.write( &ch, 1 ); 20 for( int c = 0; c < 256; c++ )
24 unitTest( sf.tell() == c+1 ); 21 {
22 unsigned char ch = (unsigned char)c;
23 sf.write( &ch, 1 );
24 unitTest( sf.tell() == c+1 );
25 }
26 //unitTest( sf.canRead() == false );
27 //unitTest( sf.canWrite() == true );
28 //unitTest( sf.canSeek() == true );
29 sf.close();
30 struct stat sdat;
31 stat("testfile1", &sdat );
32 unitTest( sdat.st_size == 256 );
25 } 33 }
26 //unitTest( sf.canRead() == false );
27 //unitTest( sf.canWrite() == true );
28 //unitTest( sf.canSeek() == true );
29 sf.close();
30 struct stat sdat;
31 stat("testfile1", &sdat );
32 unitTest( sdat.st_size == 256 );
33}
34 34
35{%readBlocks} 35 test readBlocks
36{
37 Bu::File sf("testfile1", Bu::File::Read );
38 unsigned char buf[50];
39 size_t total = 0;
40 for(;;)
41 { 36 {
42 size_t s = sf.read( buf, 50 ); 37 Bu::File sf("testfile1", Bu::File::Read );
43 for( size_t c = 0; c < s; c++ ) 38 unsigned char buf[50];
39 size_t total = 0;
40 for(;;)
44 { 41 {
45 unitTest( buf[c] == (unsigned char)(c+total) ); 42 size_t s = sf.read( buf, 50 );
46 } 43 for( size_t c = 0; c < s; c++ )
47 total += s; 44 {
48 if( s < 50 ) 45 unitTest( buf[c] == (unsigned char)(c+total) );
49 { 46 }
50 unitTest( total == 256 ); 47 total += s;
51 unitTest( sf.isEos() == true ); 48 if( s < 50 )
52 break; 49 {
50 unitTest( total == 256 );
51 unitTest( sf.isEos() == true );
52 break;
53 }
53 } 54 }
55 sf.close();
54 } 56 }
55 sf.close();
56}
57 57
58{%readError1} 58 test readError1
59{
60 try
61 { 59 {
62 Bu::File sf("doesn'texist", Bu::File::Read ); 60 try
63 unitFailed("No exception thrown"); 61 {
64 } 62 Bu::File sf("doesn'texist", Bu::File::Read );
65 catch( Bu::FileException &e ) 63 unitFailed("No exception thrown");
66 { 64 }
67 return; 65 catch( Bu::FileException &e )
66 {
67 return;
68 }
68 } 69 }
69}
70 70
71{%readError2} 71 test readError2
72{
73 Bu::File sf("testfile1", Bu::File::Read );
74 char buf[256];
75 int r = sf.read( buf, 256 );
76 unitTest( r == 256 );
77 // You have to read past the end to set the EOS flag.
78 unitTest( sf.isEos() == false );
79 try
80 { 72 {
81 if( sf.read( buf, 5 ) > 0 ) 73 Bu::File sf("testfile1", Bu::File::Read );
74 char buf[256];
75 int r = sf.read( buf, 256 );
76 unitTest( r == 256 );
77 // You have to read past the end to set the EOS flag.
78 unitTest( sf.isEos() == false );
79 try
82 { 80 {
83 unitFailed("Non-zero read result"); 81 if( sf.read( buf, 5 ) > 0 )
82 {
83 unitFailed("Non-zero read result");
84 }
85 else
86 {
87 sf.close();
88 }
84 } 89 }
85 else 90 catch( Bu::FileException &e )
86 { 91 {
87 sf.close(); 92 sf.close();
93 return;
88 } 94 }
89 } 95 }
90 catch( Bu::FileException &e )
91 {
92 sf.close();
93 return;
94 }
95} 96}
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
index 8aaae93..00b6eed 100644
--- a/src/unit/fstring.unit
+++ b/src/unit/fstring.unit
@@ -10,333 +10,333 @@
10 10
11#include <dirent.h> 11#include <dirent.h>
12 12
13{=Init} 13suite FString
14
15{%compare1}
16{ 14{
17 Bu::FString b("Bob"); 15 test compare1
18 unitTest( !(b == "Bobo") ); 16 {
19 unitTest( b == "Bob" ); 17 Bu::FString b("Bob");
20} 18 unitTest( !(b == "Bobo") );
19 unitTest( b == "Bob" );
20 }
21 21
22{%compare2} 22 test compare2
23{ 23 {
24 Bu::FString b("Bobo"); 24 Bu::FString b("Bobo");
25 unitTest( !(b == "Bob") ); 25 unitTest( !(b == "Bob") );
26 unitTest( b == "Bobo" ); 26 unitTest( b == "Bobo" );
27} 27 }
28 28
29{%appendSingle} 29 test appendSingle
30{ 30 {
31 Bu::FString b; 31 Bu::FString b;
32 for( char l = 'a'; l < 'g'; l++ ) 32 for( char l = 'a'; l < 'g'; l++ )
33 b += l; 33 b += l;
34 unitTest( b == "abcdef" ); 34 unitTest( b == "abcdef" );
35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); 35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 );
36} 36 }
37 37
38{%shared1} 38 test shared1
39{ 39 {
40 Bu::FString a("Hey there"); 40 Bu::FString a("Hey there");
41 Bu::FString b( a ); 41 Bu::FString b( a );
42 unitTest( a.getConstStr() == b.getConstStr() ); 42 unitTest( a.getConstStr() == b.getConstStr() );
43 b += " guy"; 43 b += " guy";
44 unitTest( a.getConstStr() != b.getConstStr() ); 44 unitTest( a.getConstStr() != b.getConstStr() );
45 a = b; 45 a = b;
46 unitTest( a.getConstStr() == b.getConstStr() ); 46 unitTest( a.getConstStr() == b.getConstStr() );
47} 47 }
48 48
49{%insert} 49 test insert
50{ 50 {
51 Bu::FString a("abcd"); 51 Bu::FString a("abcd");
52 a.insert( 2, "-!-", 3 ); 52 a.insert( 2, "-!-", 3 );
53 unitTest( a == "ab-!-cd" ); 53 unitTest( a == "ab-!-cd" );
54 54
55 a.insert( 0, "!!", 2 ); 55 a.insert( 0, "!!", 2 );
56 unitTest( a == "!!ab-!-cd" ); 56 unitTest( a == "!!ab-!-cd" );
57 57
58 a.insert( -10, "789", 3 ); 58 a.insert( -10, "789", 3 );
59 unitTest( a == "789!!ab-!-cd" ); 59 unitTest( a == "789!!ab-!-cd" );
60 60
61 a.insert( 12, "89", 2 ); 61 a.insert( 12, "89", 2 );
62 unitTest( a == "789!!ab-!-cd89" ); 62 unitTest( a == "789!!ab-!-cd89" );
63 63
64 a.insert( 1203, "12", 2 ); 64 a.insert( 1203, "12", 2 );
65 unitTest( a == "789!!ab-!-cd8912" ); 65 unitTest( a == "789!!ab-!-cd8912" );
66} 66 }
67 67
68{%remove} 68 test remove
69{ 69 {
70 Bu::FString a("abHEYcd"); 70 Bu::FString a("abHEYcd");
71 a.remove( 2, 3 ); 71 a.remove( 2, 3 );
72 unitTest( a == "abcd" ); 72 unitTest( a == "abcd" );
73 a.remove( 2, 5 ); 73 a.remove( 2, 5 );
74 unitTest( a == "ab" ); 74 unitTest( a == "ab" );
75 a += "cdefghijklmnop"; 75 a += "cdefghijklmnop";
76 a.remove( 5, 1 ); 76 a.remove( 5, 1 );
77 unitTest( a == "abcdeghijklmnop" ); 77 unitTest( a == "abcdeghijklmnop" );
78} 78 }
79 79
80{%add1} 80 test add1
81{ 81 {
82 Bu::FString a("hi there"); 82 Bu::FString a("hi there");
83 Bu::FString b(", yeah!"); 83 Bu::FString b(", yeah!");
84 Bu::FString c = a + b; 84 Bu::FString c = a + b;
85 85
86 unitTest( c == "hi there, yeah!" ); 86 unitTest( c == "hi there, yeah!" );
87} 87 }
88 88
89{%add2} 89 test add2
90{ 90 {
91 Bu::FString a("hi there"); 91 Bu::FString a("hi there");
92 Bu::FString c = a + ", yeah!"; 92 Bu::FString c = a + ", yeah!";
93 93
94 unitTest( c == "hi there, yeah!" ); 94 unitTest( c == "hi there, yeah!" );
95} 95 }
96 96
97{%add3} 97 test add3
98{ 98 {
99 Bu::FString a("hi there"); 99 Bu::FString a("hi there");
100 Bu::FString b(", yeah!"); 100 Bu::FString b(", yeah!");
101 Bu::FString c = a + ", Mr. Man" + b; 101 Bu::FString c = a + ", Mr. Man" + b;
102 102
103 unitTest( c == "hi there, Mr. Man, yeah!" ); 103 unitTest( c == "hi there, Mr. Man, yeah!" );
104} 104 }
105 105
106{%add4} 106 test add4
107{ 107 {
108 Bu::FString b(", yeah!"); 108 Bu::FString b(", yeah!");
109 Bu::FString c = "hi there" + b; 109 Bu::FString c = "hi there" + b;
110 110
111 unitTest( c == "hi there, yeah!" ); 111 unitTest( c == "hi there, yeah!" );
112} 112 }
113 113
114{%add5} 114 test add5
115{ 115 {
116 Bu::FString b; 116 Bu::FString b;
117 Bu::FString c = "sup?"; 117 Bu::FString c = "sup?";
118 b += "hey, " + c; 118 b += "hey, " + c;
119 119
120 unitTest( b == "hey, sup?" ); 120 unitTest( b == "hey, sup?" );
121} 121 }
122 122
123{%add6} 123 test add6
124{ 124 {
125 Bu::FString a("Hello"); 125 Bu::FString a("Hello");
126 char b[256] = {"Dude"}; 126 char b[256] = {"Dude"};
127 Bu::FString c = a + "/" + b; 127 Bu::FString c = a + "/" + b;
128 128
129 unitTest( c == "Hello/Dude" ); 129 unitTest( c == "Hello/Dude" );
130} 130 }
131 131
132{%add7} 132 test add7
133{ 133 {
134 const Bu::FString a("hello "); 134 const Bu::FString a("hello ");
135 Bu::FString b(" how "); 135 Bu::FString b(" how ");
136 unitTest( a == "hello " ); 136 unitTest( a == "hello " );
137 unitTest( a + "dude" == "hello dude" ); 137 unitTest( a + "dude" == "hello dude" );
138 unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); 138 unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" );
139} 139 }
140 140
141{%subStr1} 141 test subStr1
142{ 142 {
143 Bu::FString a("abcdefghijklmnop"); 143 Bu::FString a("abcdefghijklmnop");
144 Bu::FString::iterator i = a.find('f'); 144 Bu::FString::iterator i = a.find('f');
145 unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" ); 145 unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" );
146 Bu::FString::iterator j = i.find('l'); 146 Bu::FString::iterator j = i.find('l');
147 unitTest( a.getSubStr( i, j ) == "fghijk" ); 147 unitTest( a.getSubStr( i, j ) == "fghijk" );
148} 148 }
149 149
150{%compareSub1} 150 test compareSub1
151{ 151 {
152 Bu::FString a("just a string."); 152 Bu::FString a("just a string.");
153 unitTest( a.compareSub("a ", 5, 2) == true ); 153 unitTest( a.compareSub("a ", 5, 2) == true );
154 unitTest( a.compareSub("string.aoeu", 7, 11 ) == false ); 154 unitTest( a.compareSub("string.aoeu", 7, 11 ) == false );
155 unitTest( a.compareSub("string.aoeu", 7, 3 ) == true ); 155 unitTest( a.compareSub("string.aoeu", 7, 3 ) == true );
156} 156 }
157 157
158{%compareSub2} 158 test compareSub2
159{ 159 {
160 Bu::FString a("just a string."); 160 Bu::FString a("just a string.");
161 unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true ); 161 unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true );
162 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false ); 162 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false );
163 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true ); 163 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true );
164} 164 }
165 165
166{%iterator1} 166 test iterator1
167{
168 Bu::FString a("This is a test.");
169 Bu::FString b;
170 for( Bu::FString::iterator i = a.begin(); i; i++ )
171 { 167 {
172 b += *i; 168 Bu::FString a("This is a test.");
169 Bu::FString b;
170 for( Bu::FString::iterator i = a.begin(); i; i++ )
171 {
172 b += *i;
173 }
174 unitTest( a == b );
173 } 175 }
174 unitTest( a == b );
175}
176 176
177{%iterator2} 177 test iterator2
178{ 178 {
179 Bu::FString a("This is a test."); 179 Bu::FString a("This is a test.");
180 Bu::FString b("--This is a test."); 180 Bu::FString b("--This is a test.");
181 Bu::FString::iterator ai = a.begin(); 181 Bu::FString::iterator ai = a.begin();
182 Bu::FString::iterator bi = b.begin(); 182 Bu::FString::iterator bi = b.begin();
183 unitTest( ai.compare( bi ) == false ); 183 unitTest( ai.compare( bi ) == false );
184 unitTest( bi.compare( ai ) == false ); 184 unitTest( bi.compare( ai ) == false );
185 bi++; bi++; 185 bi++; bi++;
186 unitTest( ai.compare( bi ) == true ); 186 unitTest( ai.compare( bi ) == true );
187 unitTest( bi.compare( ai ) == true ); 187 unitTest( bi.compare( ai ) == true );
188} 188 }
189 189
190{%iterator3} 190 test iterator3
191{ 191 {
192 Bu::FString a("1234honour"); 192 Bu::FString a("1234honour");
193 Bu::FString b("--1234ueje"); 193 Bu::FString b("--1234ueje");
194 Bu::FString::iterator ai = a.begin(); 194 Bu::FString::iterator ai = a.begin();
195 Bu::FString::iterator bi = b.begin(); 195 Bu::FString::iterator bi = b.begin();
196 unitTest( ai.compare( bi, 4 ) == false ); 196 unitTest( ai.compare( bi, 4 ) == false );
197 unitTest( bi.compare( ai, 4 ) == false ); 197 unitTest( bi.compare( ai, 4 ) == false );
198 bi++; bi++; 198 bi++; bi++;
199 unitTest( ai.compare( bi, 4 ) == true ); 199 unitTest( ai.compare( bi, 4 ) == true );
200 unitTest( bi.compare( ai, 4 ) == true ); 200 unitTest( bi.compare( ai, 4 ) == true );
201 unitTest( ai.compare( bi, 5 ) == false ); 201 unitTest( ai.compare( bi, 5 ) == false );
202 unitTest( bi.compare( ai, 5 ) == false ); 202 unitTest( bi.compare( ai, 5 ) == false );
203 203
204} 204 }
205 205
206{%iterator4} 206 test iterator4
207{ 207 {
208 Bu::FString a("1234aoeu"); 208 Bu::FString a("1234aoeu");
209 Bu::FString::iterator ai = a.begin(); 209 Bu::FString::iterator ai = a.begin();
210 unitTest( ai.compare("1234") == false ); 210 unitTest( ai.compare("1234") == false );
211 unitTest( ai.compare("1234aoeu") == true ); 211 unitTest( ai.compare("1234aoeu") == true );
212 unitTest( ai.compare("1234aoeuee") == false ); 212 unitTest( ai.compare("1234aoeuee") == false );
213} 213 }
214 214
215{%iterator5} 215 test iterator5
216{ 216 {
217 Bu::FString a("1234aoeu"); 217 Bu::FString a("1234aoeu");
218 Bu::FString::iterator ai = a.begin(); 218 Bu::FString::iterator ai = a.begin();
219 unitTest( ai.compare("1234", 4) == true ); 219 unitTest( ai.compare("1234", 4) == true );
220 unitTest( ai.compare("1234aoeu", 8) == true ); 220 unitTest( ai.compare("1234aoeu", 8) == true );
221 unitTest( ai.compare("1234aoeuee", 10) == false ); 221 unitTest( ai.compare("1234aoeuee", 10) == false );
222} 222 }
223 223
224{%iterator6} 224 test iterator6
225{
226 Bu::FString a("just ->this part");
227 Bu::FString b;
228 Bu::FString::iterator s = a.begin();
229 for(; s; s++ )
230 { 225 {
231 if( *s == '>' ) 226 Bu::FString a("just ->this part");
227 Bu::FString b;
228 Bu::FString::iterator s = a.begin();
229 for(; s; s++ )
232 { 230 {
233 s++; 231 if( *s == '>' )
234 b.set( s ); 232 {
235 break; 233 s++;
234 b.set( s );
235 break;
236 }
236 } 237 }
237 } 238 unitTest( b == "this part" );
238 unitTest( b == "this part" );
239 239
240 b.append( s ); 240 b.append( s );
241 241
242 Bu::FString c; 242 Bu::FString c;
243 c.set( b.begin() ); 243 c.set( b.begin() );
244 244
245 // This is here because the comparison operator used to cause flattening. 245 // This is here because the comparison operator used to cause flattening.
246 unitTest( b == "this partthis part" ); 246 unitTest( b == "this partthis part" );
247 unitTest( c == b ); 247 unitTest( c == b );
248} 248 }
249 249
250{%iterator7} 250 test iterator7
251{
252 Bu::FString a("just [this] part");
253 Bu::FString b;
254 Bu::FString::iterator s = a.begin();
255 for(; s; s++ )
256 { 251 {
257 if( *s == '[' ) 252 Bu::FString a("just [this] part");
253 Bu::FString b;
254 Bu::FString::iterator s = a.begin();
255 for(; s; s++ )
258 { 256 {
259 s++; 257 if( *s == '[' )
260 break; 258 {
259 s++;
260 break;
261 }
261 } 262 }
262 } 263 Bu::FString::iterator e = s;
263 Bu::FString::iterator e = s; 264 for(; e; e++ )
264 for(; e; e++ )
265 {
266 if( *e == ']' )
267 { 265 {
268 b.set( s, e ); 266 if( *e == ']' )
269 break; 267 {
268 b.set( s, e );
269 break;
270 }
270 } 271 }
271 } 272 unitTest( b == "this" );
272 unitTest( b == "this" );
273 273
274 b.append( s, e ); 274 b.append( s, e );
275 275
276 for( Bu::FString::iterator i = b.begin(); i;) 276 for( Bu::FString::iterator i = b.begin(); i;)
277 {
278 Bu::FString::iterator k = i;
279 k++;
280 if( !k )
281 { 277 {
282 b.append( b.begin(), i ); 278 Bu::FString::iterator k = i;
283 break; 279 k++;
280 if( !k )
281 {
282 b.append( b.begin(), i );
283 break;
284 }
285 i = k;
284 } 286 }
285 i = k; 287 Bu::FString l;
286 } 288 l.set( b.begin() );
287 Bu::FString l; 289 unitTest( l == "thisthisthisthi" );
288 l.set( b.begin() ); 290 for( Bu::FString::iterator i = b.begin(); i;)
289 unitTest( l == "thisthisthisthi" );
290 for( Bu::FString::iterator i = b.begin(); i;)
291 {
292 Bu::FString::iterator k = i;
293 k++;
294 if( !k )
295 { 291 {
296 b.append( b.begin(), i ); 292 Bu::FString::iterator k = i;
297 break; 293 k++;
294 if( !k )
295 {
296 b.append( b.begin(), i );
297 break;
298 }
299 i = k;
298 } 300 }
299 i = k; 301 l.set( b.begin() );
302 unitTest( l == "thisthisthisthithisthisthisth" );
300 } 303 }
301 l.set( b.begin() );
302 unitTest( l == "thisthisthisthithisthisthisth" );
303}
304 304
305{%isSet1} 305 test isSet1
306{ 306 {
307 Bu::FString bob; 307 Bu::FString bob;
308 308
309 unitTest( bob.isSet() == false ); 309 unitTest( bob.isSet() == false );
310 bob = "something"; 310 bob = "something";
311 unitTest( bob.isSet() == true ); 311 unitTest( bob.isSet() == true );
312 bob = ""; 312 bob = "";
313 unitTest( bob.isSet() == false ); 313 unitTest( bob.isSet() == false );
314} 314 }
315 315
316{%swap1} 316 test swap1
317{ 317 {
318 Bu::FString a, b; 318 Bu::FString a, b;
319 a = "Goodbye"; 319 a = "Goodbye";
320 b = "Hello"; 320 b = "Hello";
321 Bu::swap( a, b ); 321 Bu::swap( a, b );
322 unitTest( a == "Hello" ); 322 unitTest( a == "Hello" );
323 unitTest( b == "Goodbye" ); 323 unitTest( b == "Goodbye" );
324} 324 }
325 325
326{%swap2} 326 test swap2
327{ 327 {
328 Bu::FString a, b; 328 Bu::FString a, b;
329 a = "Goodbye"; 329 a = "Goodbye";
330 b = "Hello"; 330 b = "Hello";
331 std::swap( a, b ); 331 std::swap( a, b );
332 unitTest( a == "Hello" ); 332 unitTest( a == "Hello" );
333 unitTest( b == "Goodbye" ); 333 unitTest( b == "Goodbye" );
334} 334 }
335 335
336{%replace1} 336 test replace1
337{ 337 {
338 Bu::FString a; 338 Bu::FString a;
339 a = "This is a test."; 339 a = "This is a test.";
340 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); 340 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." );
341 }
341} 342}
342
diff --git a/src/unit/hash.unit b/src/unit/hash.unit
index c0a10e3..e3d7e42 100644
--- a/src/unit/hash.unit
+++ b/src/unit/hash.unit
@@ -15,72 +15,73 @@ typedef Bu::Hash<Bu::FString, int> StrIntHash;
15typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; 15typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash;
16typedef Bu::Hash<int, Bu::FString> IntStrHash; 16typedef Bu::Hash<int, Bu::FString> IntStrHash;
17 17
18{=Init} 18suite Hash
19
20{%probe1}
21{ 19{
22 StrIntHash h; 20 test probe1
23 char buf[20];
24 for(int i=1;i<10000;i++)
25 { 21 {
26 sprintf(buf,"%d",i); 22 StrIntHash h;
27 Bu::FString sTmp(buf); 23 char buf[20];
28 h[sTmp] = i; 24 for(int i=1;i<10000;i++)
29 unitTest( h.has(sTmp) ); 25 {
26 sprintf(buf,"%d",i);
27 Bu::FString sTmp(buf);
28 h[sTmp] = i;
29 unitTest( h.has(sTmp) );
30 }
30 } 31 }
31}
32
33{%insert1}
34{
35 StrIntHash h;
36 h["Hi"] = 42;
37 unitTest( h["Hi"] == 42 );
38}
39 32
40{%insert2} 33 test insert1
41{ 34 {
42 StrStrHash h; 35 StrIntHash h;
43 h["Hi"] = "Yo"; 36 h["Hi"] = 42;
44 h["Bye"] = "Later"; 37 unitTest( h["Hi"] == 42 );
45 unitTest( h["Hi"].getValue() == "Yo" ); 38 }
46 39
47 StrStrHash h2(h); 40 test insert2
48 unitTest( h2["Hi"].getValue() == "Yo" ); 41 {
49 unitTest( h2["Bye"].getValue() == "Later" ); 42 StrStrHash h;
43 h["Hi"] = "Yo";
44 h["Bye"] = "Later";
45 unitTest( h["Hi"].getValue() == "Yo" );
50 46
51 StrStrHash h3; 47 StrStrHash h2(h);
52 h3 = h; 48 unitTest( h2["Hi"].getValue() == "Yo" );
53 unitTest( h3["Hi"].getValue() == "Yo" ); 49 unitTest( h2["Bye"].getValue() == "Later" );
54 unitTest( h3["Bye"].getValue() == "Later" );
55}
56 50
57{%insert3} 51 StrStrHash h3;
58{ 52 h3 = h;
59 IntStrHash h; 53 unitTest( h3["Hi"].getValue() == "Yo" );
54 unitTest( h3["Bye"].getValue() == "Later" );
55 }
60 56
61 for( unsigned int i=1; i<50; i++ ) 57 test insert3
62 { 58 {
63 h[i] = "testing"; 59 IntStrHash h;
64 unitTest( h.getSize() == i );
65 }
66}
67 60
68{%erase1} 61 for( unsigned int i=1; i<50; i++ )
69{ 62 {
70 StrIntHash h; 63 h[i] = "testing";
71 h.insert("Number 1", 1 ); 64 unitTest( h.getSize() == i );
72 h.insert("Number 2", 2 ); 65 }
73 h.insert("Number 3", 3 ); 66 }
74 h.erase("Number 2");
75 h.get("Number 3");
76 try {
77 h.get("Number 2");
78 unitFailed("h.get(\"Number 2\") should have thrown an exception.");
79 } catch( Bu::HashException &e ) { }
80 67
81/* printf("\n"); 68 test erase1
82 for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ )
83 { 69 {
84 printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); 70 StrIntHash h;
85 } */ 71 h.insert("Number 1", 1 );
72 h.insert("Number 2", 2 );
73 h.insert("Number 3", 3 );
74 h.erase("Number 2");
75 h.get("Number 3");
76 try {
77 h.get("Number 2");
78 unitFailed("h.get(\"Number 2\") should have thrown an exception.");
79 } catch( Bu::HashException &e ) { }
80
81 /* printf("\n");
82 for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ )
83 {
84 printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() );
85 } */
86 }
86} 87}
diff --git a/src/unit/list.unit b/src/unit/list.unit
index 0dd9f40..66e45b2 100644
--- a/src/unit/list.unit
+++ b/src/unit/list.unit
@@ -11,138 +11,138 @@
11 11
12typedef Bu::List<int> IntList; 12typedef Bu::List<int> IntList;
13 13
14{=Init} 14suite List
15
16{%append}
17{ 15{
18 IntList lst; 16 test append
19 for( int j = 0; j < 50; j++ )
20 {
21 lst.append( j );
22 }
23 int j = 0;
24 for( IntList::iterator i = lst.begin(); i; i++, j++ )
25 { 17 {
26 unitTest( *i == j ); 18 IntList lst;
19 for( int j = 0; j < 50; j++ )
20 {
21 lst.append( j );
22 }
23 int j = 0;
24 for( IntList::iterator i = lst.begin(); i; i++, j++ )
25 {
26 unitTest( *i == j );
27 }
27 } 28 }
28}
29 29
30{%prepend} 30 test prepend
31{
32 IntList lst;
33 for( int j = 0; j < 50; j++ )
34 { 31 {
35 lst.prepend( j ); 32 IntList lst;
33 for( int j = 0; j < 50; j++ )
34 {
35 lst.prepend( j );
36 }
37 int j = 49;
38 for( IntList::iterator i = lst.begin(); i; i++, j-- )
39 {
40 unitTest( *i == j );
41 }
36 } 42 }
37 int j = 49;
38 for( IntList::iterator i = lst.begin(); i; i++, j-- )
39 {
40 unitTest( *i == j );
41 }
42}
43 43
44{%copy} 44 test copy
45{
46 IntList lst;
47 int j;
48 for( j = 0; j < 50; j++ )
49 { 45 {
50 lst.append( j ); 46 IntList lst;
47 int j;
48 for( j = 0; j < 50; j++ )
49 {
50 lst.append( j );
51 }
52 IntList lst2 = lst;
53
54 j = 0;
55 for( IntList::iterator i = lst2.begin(); i; i++, j++ )
56 {
57 unitTest( *i == j );
58 }
59 lst2.clear();
60 lst2 = lst;
61
62 j = 0;
63 for( IntList::iterator i = lst2.begin(); i; i++, j++ )
64 {
65 unitTest( *i == j );
66 }
51 } 67 }
52 IntList lst2 = lst;
53 68
54 j = 0; 69 test sort1
55 for( IntList::iterator i = lst2.begin(); i; i++, j++ )
56 { 70 {
57 unitTest( *i == j ); 71 IntList lst;
58 }
59 lst2.clear();
60 lst2 = lst;
61 72
62 j = 0; 73 lst.insertSorted( 5 );
63 for( IntList::iterator i = lst2.begin(); i; i++, j++ ) 74 lst.insertSorted( 1 );
64 { 75 lst.insertSorted( 10 );
65 unitTest( *i == j ); 76 lst.insertSorted( 3 );
66 }
67}
68
69{%sort1}
70{
71 IntList lst;
72 77
73 lst.insertSorted( 5 ); 78 unitTest( lst == IntList(1).append(3).append(5).append(10) );
74 lst.insertSorted( 1 ); 79 }
75 lst.insertSorted( 10 );
76 lst.insertSorted( 3 );
77
78 unitTest( lst == IntList(1).append(3).append(5).append(10) );
79}
80 80
81{%sort2} 81 test sort2
82{ 82 {
83 IntList lst; 83 IntList lst;
84 84
85 lst.insertSorted<Bu::__basicGTCmp<int> >( 5 ); 85 lst.insertSorted<Bu::__basicGTCmp<int> >( 5 );
86 lst.insertSorted<Bu::__basicGTCmp<int> >( 1 ); 86 lst.insertSorted<Bu::__basicGTCmp<int> >( 1 );
87 lst.insertSorted<Bu::__basicGTCmp<int> >( 10 ); 87 lst.insertSorted<Bu::__basicGTCmp<int> >( 10 );
88 lst.insertSorted<Bu::__basicGTCmp<int> >( 3 ); 88 lst.insertSorted<Bu::__basicGTCmp<int> >( 3 );
89 89
90 unitTest( lst == IntList(10).append(5).append(3).append(1) ); 90 unitTest( lst == IntList(10).append(5).append(3).append(1) );
91} 91 }
92 92
93{%sort3} 93 test sort3
94{ 94 {
95 IntList lst; 95 IntList lst;
96 Bu::__basicGTCmp<int> cmp; 96 Bu::__basicGTCmp<int> cmp;
97 97
98 lst.insertSorted( cmp, 5 ); 98 lst.insertSorted( cmp, 5 );
99 lst.insertSorted( cmp, 1 ); 99 lst.insertSorted( cmp, 1 );
100 lst.insertSorted( cmp, 10 ); 100 lst.insertSorted( cmp, 10 );
101 lst.insertSorted( cmp, 3 ); 101 lst.insertSorted( cmp, 3 );
102 102
103 unitTest( lst == IntList(10).append(5).append(3).append(1) ); 103 unitTest( lst == IntList(10).append(5).append(3).append(1) );
104} 104 }
105 105
106{%sort4} 106 test sort4
107{ 107 {
108 IntList lst; 108 IntList lst;
109 109
110 lst.append( 5 ); 110 lst.append( 5 );
111 lst.append( 1 ); 111 lst.append( 1 );
112 lst.append( 10 ); 112 lst.append( 10 );
113 lst.append( 3 ); 113 lst.append( 3 );
114 114
115 lst.sort(); 115 lst.sort();
116 116
117 unitTest( lst == IntList(1).append(3).append(5).append(10) ); 117 unitTest( lst == IntList(1).append(3).append(5).append(10) );
118} 118 }
119 119
120{%sort5} 120 test sort5
121{ 121 {
122 IntList lst; 122 IntList lst;
123 123
124 lst.append( 5 ); 124 lst.append( 5 );
125 lst.append( 1 ); 125 lst.append( 1 );
126 lst.append( 10 ); 126 lst.append( 10 );
127 lst.append( 3 ); 127 lst.append( 3 );
128 128
129 lst.sort<Bu::__basicGTCmp<int> >(); 129 lst.sort<Bu::__basicGTCmp<int> >();
130 130
131 unitTest( lst == IntList(10).append(5).append(3).append(1) ); 131 unitTest( lst == IntList(10).append(5).append(3).append(1) );
132} 132 }
133 133
134{%sort6} 134 test sort6
135{ 135 {
136 IntList lst; 136 IntList lst;
137 137
138 lst.append( 5 ); 138 lst.append( 5 );
139 lst.append( 1 ); 139 lst.append( 1 );
140 lst.append( 10 ); 140 lst.append( 10 );
141 lst.append( 3 ); 141 lst.append( 3 );
142 142
143 Bu::__basicGTCmp<int> x; 143 Bu::__basicGTCmp<int> x;
144 lst.sort( x ); 144 lst.sort( x );
145 145
146 unitTest( lst == IntList(10).append(5).append(3).append(1) ); 146 unitTest( lst == IntList(10).append(5).append(3).append(1) );
147 }
147} 148}
148
diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit
index 883b7f8..1da3b90 100644
--- a/src/unit/membuf.unit
+++ b/src/unit/membuf.unit
@@ -8,38 +8,39 @@
8 8
9#include "bu/membuf.h" 9#include "bu/membuf.h"
10 10
11{=Init} 11suite MemBuf
12
13{%testWriteRead01}
14{ 12{
15 Bu::MemBuf mb; 13 test testWriteRead01
16 unitTest( mb.write("ab", 2 ) == 2 ); 14 {
17 unitTest( mb.write("cde", 3 ) == 3 ); 15 Bu::MemBuf mb;
18 unitTest( mb.write("FG", 2 ) == 2 ); 16 unitTest( mb.write("ab", 2 ) == 2 );
17 unitTest( mb.write("cde", 3 ) == 3 );
18 unitTest( mb.write("FG", 2 ) == 2 );
19 19
20 mb.setPos( 0 ); 20 mb.setPos( 0 );
21 21
22 char buf[8]; 22 char buf[8];
23 buf[7] = '\0'; 23 buf[7] = '\0';
24 unitTest( mb.read( buf, 7 ) == 7 ); 24 unitTest( mb.read( buf, 7 ) == 7 );
25 unitTest( !strncmp( buf, "abcdeFG", 7 ) ); 25 unitTest( !strncmp( buf, "abcdeFG", 7 ) );
26 unitTest( mb.read( buf, 7 ) == 0 ); 26 unitTest( mb.read( buf, 7 ) == 0 );
27 mb.seek( -3 ); 27 mb.seek( -3 );
28 unitTest( mb.read( buf, 7 ) == 3 ); 28 unitTest( mb.read( buf, 7 ) == 3 );
29 unitTest( !strncmp( buf, "eFG", 3 ) ); 29 unitTest( !strncmp( buf, "eFG", 3 ) );
30} 30 }
31 31
32{%testOverwrite1} 32 test testOverwrite1
33{ 33 {
34 Bu::MemBuf mb; 34 Bu::MemBuf mb;
35 unitTest( mb.write("0123456789") == 10 ); 35 unitTest( mb.write("0123456789") == 10 );
36 mb.setPos( 4 ); 36 mb.setPos( 4 );
37 unitTest( mb.write("-5-") == 3 ); 37 unitTest( mb.write("-5-") == 3 );
38 mb.setPos( 9 ); 38 mb.setPos( 9 );
39 mb.write("Hey!!!"); 39 mb.write("Hey!!!");
40 unitTest( mb.tell() == 15 ); 40 unitTest( mb.tell() == 15 );
41 char buf[50]; 41 char buf[50];
42 mb.setPos( 0 ); 42 mb.setPos( 0 );
43 buf[mb.read( buf, 50 )] = '\0'; 43 buf[mb.read( buf, 50 )] = '\0';
44 unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); 44 unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) );
45 }
45} 46}
diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit
index 9ae7d36..29ba858 100644
--- a/src/unit/queuebuf.unit
+++ b/src/unit/queuebuf.unit
@@ -14,91 +14,91 @@
14 14
15#define RNDCHR ((char)(((double)random()/(double)RAND_MAX)*256.0)) 15#define RNDCHR ((char)(((double)random()/(double)RAND_MAX)*256.0))
16 16
17{=Init} 17suite QueueBuf
18
19{%testBasic01}
20{ 18{
21 Bu::QueueBuf qb; 19 test testBasic01
22 unitTest( qb.write("ab", 2 ) == 2 ); 20 {
23 unitTest( qb.write("cde", 3 ) == 3 ); 21 Bu::QueueBuf qb;
24 unitTest( qb.write("FG", 2 ) == 2 ); 22 unitTest( qb.write("ab", 2 ) == 2 );
23 unitTest( qb.write("cde", 3 ) == 3 );
24 unitTest( qb.write("FG", 2 ) == 2 );
25 25
26 char buf[8]; 26 char buf[8];
27 buf[7] = '\0'; 27 buf[7] = '\0';
28 unitTest( qb.read( buf, 7 ) == 7 ); 28 unitTest( qb.read( buf, 7 ) == 7 );
29 unitTest( !strncmp( buf, "abcdeFG", 7 ) ); 29 unitTest( !strncmp( buf, "abcdeFG", 7 ) );
30 unitTest( qb.read( buf, 7 ) == 0 ); 30 unitTest( qb.read( buf, 7 ) == 0 );
31} 31 }
32 32
33void QBUF_RANDSTR( Bu::FString &fill, unsigned int iSize ) 33 void QBUF_RANDSTR( Bu::FString &fill, unsigned int iSize )
34{
35 char c;
36 for( unsigned int i=0; i<iSize; ++i )
37 { 34 {
38 c = RNDCHR; 35 char c;
39 fill.append(&c,1); 36 for( unsigned int i=0; i<iSize; ++i )
37 {
38 c = RNDCHR;
39 fill.append(&c,1);
40 }
40 } 41 }
41}
42 42
43{%testAmounts} 43 test testAmounts
44{
45 srandom(time(NULL));
46 Bu::QueueBuf qb;
47 Bu::FString sTmp;
48 char buf[4096];
49
50 for( int i=0; i<200; ++i )
51 { 44 {
52 unsigned int iAmt = (int)RNDCHR+128; 45 srandom(time(NULL));
53 sTmp.clear(); 46 Bu::QueueBuf qb;
54 QBUF_RANDSTR( sTmp, iAmt ); 47 Bu::FString sTmp;
55 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == 48 char buf[4096];
56 (uint32_t)sTmp.getSize() );
57 size_t iRead = qb.read( buf, 4096 );
58 unitTest( iRead == iAmt );
59 }
60}
61 49
62void QBUF_HEXOUT( const char *s, int iSize ) 50 for( int i=0; i<200; ++i )
63{ 51 {
64 for( int i=0; i<iSize; ++i ) 52 unsigned int iAmt = (int)RNDCHR+128;
65 printf("%02x",(int)(uint8_t)s[i]); 53 sTmp.clear();
66} 54 QBUF_RANDSTR( sTmp, iAmt );
55 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) ==
56 (uint32_t)sTmp.getSize() );
57 size_t iRead = qb.read( buf, 4096 );
58 unitTest( iRead == iAmt );
59 }
60 }
67 61
68void QBUF_HASH( Bu::FString &fill, const char *s, int iSize ) 62 void QBUF_HEXOUT( const char *s, int iSize )
69{ 63 {
70 Bu::Md5 hash; 64 for( int i=0; i<iSize; ++i )
71 hash.reset(); 65 printf("%02x",(int)(uint8_t)s[i]);
72 hash.addData( s, iSize ); 66 }
73 const Bu::FString &sTmp = hash.getResult();
74 fill.append( sTmp.getStr(), 16 );
75}
76 67
77{%testRandomData} 68 void QBUF_HASH( Bu::FString &fill, const char *s, int iSize )
78{ 69 {
79 srandom(time(NULL)); 70 Bu::Md5 hash;
80 Bu::QueueBuf qb; 71 hash.reset();
81 Bu::FString sTmp; 72 hash.addData( s, iSize );
82 Bu::FString sTmp2; 73 const Bu::FString &sTmp = hash.getResult();
83 char buf[4096]; 74 fill.append( sTmp.getStr(), 16 );
75 }
84 76
85 for( int i=0; i<200; ++i ) 77 test testRandomData
86 { 78 {
87 uint32_t iAmt = (uint32_t)RNDCHR+128; 79 srandom(time(NULL));
88 sTmp.clear(); 80 Bu::QueueBuf qb;
89 sTmp.append( (const char *)&iAmt, 4 ); 81 Bu::FString sTmp;
90 QBUF_RANDSTR( sTmp, iAmt ); 82 Bu::FString sTmp2;
91 sTmp2.clear(); 83 char buf[4096];
92 QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); 84
93 sTmp.append( sTmp2 ); 85 for( int i=0; i<200; ++i )
94 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == 86 {
95 (uint32_t)sTmp.getSize() ); 87 uint32_t iAmt = (uint32_t)RNDCHR+128;
96 size_t iRead = qb.read( buf, 4096 ); 88 sTmp.clear();
97 uint32_t iGotSize = *((uint32_t *)buf); 89 sTmp.append( (const char *)&iAmt, 4 );
98 unitTest( iRead == iGotSize+4+16 ); 90 QBUF_RANDSTR( sTmp, iAmt );
99 sTmp2.clear(); 91 sTmp2.clear();
100 QBUF_HASH( sTmp2, buf+4, iGotSize ); 92 QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt );
101 unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); 93 sTmp.append( sTmp2 );
94 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) ==
95 (uint32_t)sTmp.getSize() );
96 size_t iRead = qb.read( buf, 4096 );
97 uint32_t iGotSize = *((uint32_t *)buf);
98 unitTest( iRead == iGotSize+4+16 );
99 sTmp2.clear();
100 QBUF_HASH( sTmp2, buf+4, iGotSize );
101 unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) );
102 }
102 } 103 }
103} 104}
104
diff --git a/src/unit/substream.unit b/src/unit/substream.unit
index 802ad4c..49817b0 100644
--- a/src/unit/substream.unit
+++ b/src/unit/substream.unit
@@ -9,44 +9,44 @@
9#include "bu/membuf.h" 9#include "bu/membuf.h"
10#include "bu/substream.h" 10#include "bu/substream.h"
11 11
12{=Init} 12suite SubStream
13
14{%testRead01}
15{ 13{
16 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); 14 test testRead01
17 mb.seek( 4 ); 15 {
18 Bu::SubStream ss( mb, 10 ); 16 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
19 unitTest( ss.readLine() == "efghijklmn" ); 17 mb.seek( 4 );
20} 18 Bu::SubStream ss( mb, 10 );
19 unitTest( ss.readLine() == "efghijklmn" );
20 }
21 21
22{%testRead02} 22 test testRead02
23{ 23 {
24 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); 24 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
25 mb.seek( 4 ); 25 mb.seek( 4 );
26 Bu::SubStream ss( mb, 10 ); 26 Bu::SubStream ss( mb, 10 );
27 char buf[8]; 27 char buf[8];
28 size_t iRead = ss.read( buf, 8 ); 28 size_t iRead = ss.read( buf, 8 );
29 unitTest( iRead == 8 ); 29 unitTest( iRead == 8 );
30 unitTest( strncmp( buf, "efghijkl", 8 ) == 0 ); 30 unitTest( strncmp( buf, "efghijkl", 8 ) == 0 );
31 unitTest( !ss.isEos() ); 31 unitTest( !ss.isEos() );
32 iRead = ss.read( buf, 8 ); 32 iRead = ss.read( buf, 8 );
33 unitTest( iRead == 2 ); 33 unitTest( iRead == 2 );
34 unitTest( strncmp( buf, "mn", 2 ) == 0 ); 34 unitTest( strncmp( buf, "mn", 2 ) == 0 );
35 unitTest( ss.isEos() ); 35 unitTest( ss.isEos() );
36} 36 }
37 37
38{%testRead03} 38 test testRead03
39{ 39 {
40 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); 40 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
41 mb.seek( 20 ); 41 mb.seek( 20 );
42 Bu::SubStream ss( mb, 10 ); 42 Bu::SubStream ss( mb, 10 );
43 char buf[8]; 43 char buf[8];
44 size_t iRead = ss.read( buf, 8 ); 44 size_t iRead = ss.read( buf, 8 );
45 unitTest( iRead == 6 ); 45 unitTest( iRead == 6 );
46 unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 ); 46 unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 );
47 unitTest( ss.isEos() ); 47 unitTest( ss.isEos() );
48 iRead = ss.read( buf, 8 ); 48 iRead = ss.read( buf, 8 );
49 unitTest( iRead == 0 ); 49 unitTest( iRead == 0 );
50 unitTest( ss.isEos() ); 50 unitTest( ss.isEos() );
51 }
51} 52}
52
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\\x96\\x97"
63 "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" 63 "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F"
64 "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" 64 "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7"
65 "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" 65 "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF"
66 "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" 66 "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7"
67 "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" 67 "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF"
68 "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" 68 "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7"
69 "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" 69 "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF"
70 "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" 70 "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7"
71 "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" 71 "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF"
72 "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" 72 "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7"
73 "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" 73 "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF"
74 "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\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
diff --git a/src/unit/xml.unit b/src/unit/xml.unit
index 1398237..67216f0 100644
--- a/src/unit/xml.unit
+++ b/src/unit/xml.unit
@@ -10,11 +10,12 @@
10#include "bu/xmlreader.h" 10#include "bu/xmlreader.h"
11#include "bu/membuf.h" 11#include "bu/membuf.h"
12 12
13{=Init} 13suite Xml
14
15{%declaration}
16{ 14{
17 Bu::FString sXml("<?xml ?> <hi />"); 15 test declaration
18 Bu::MemBuf buf( sXml ); 16 {
19 Bu::XmlReader xr( buf ); 17 Bu::FString sXml("<?xml ?> <hi />");
18 Bu::MemBuf buf( sXml );
19 Bu::XmlReader xr( buf );
20 }
20} 21}