diff options
Diffstat (limited to '')
-rw-r--r-- | src/unit/archive.unit | 352 | ||||
-rw-r--r-- | src/unit/array.unit | 174 | ||||
-rw-r--r-- | src/unit/base64.unit | 24 | ||||
-rw-r--r-- | src/unit/blowfish.unit | 44 | ||||
-rw-r--r-- | src/unit/buffer.unit | 22 | ||||
-rw-r--r-- | src/unit/file.unit | 160 | ||||
-rw-r--r-- | src/unit/hash.unit | 378 | ||||
-rw-r--r-- | src/unit/list.unit | 264 | ||||
-rw-r--r-- | src/unit/md5.unit | 124 | ||||
-rw-r--r-- | src/unit/membuf.unit | 60 | ||||
-rw-r--r-- | src/unit/myriad.unit | 678 | ||||
-rw-r--r-- | src/unit/queuebuf.unit | 154 | ||||
-rw-r--r-- | src/unit/sha1.unit | 112 | ||||
-rw-r--r-- | src/unit/string.unit | 1148 | ||||
-rw-r--r-- | src/unit/substream.unit | 72 | ||||
-rw-r--r-- | src/unit/taf.unit | 94 | ||||
-rw-r--r-- | src/unit/variant.unit | 70 | ||||
-rw-r--r-- | src/unit/xml.unit | 12 |
18 files changed, 1971 insertions, 1971 deletions
diff --git a/src/unit/archive.unit b/src/unit/archive.unit index 359f380..d0427a5 100644 --- a/src/unit/archive.unit +++ b/src/unit/archive.unit | |||
@@ -14,183 +14,183 @@ using namespace Bu; | |||
14 | 14 | ||
15 | suite Archive | 15 | suite Archive |
16 | { | 16 | { |
17 | test primitives | 17 | test primitives |
18 | { | 18 | { |
19 | MemBuf mb; | 19 | MemBuf mb; |
20 | { | 20 | { |
21 | Archive ar( mb, Archive::save ); | 21 | Archive ar( mb, Archive::save ); |
22 | ar << (int8_t)1; | 22 | ar << (int8_t)1; |
23 | ar << (uint8_t)2; | 23 | ar << (uint8_t)2; |
24 | ar << (int16_t)3; | 24 | ar << (int16_t)3; |
25 | ar << (uint16_t)4; | 25 | ar << (uint16_t)4; |
26 | ar << (int32_t)5; | 26 | ar << (int32_t)5; |
27 | ar << (uint32_t)6; | 27 | ar << (uint32_t)6; |
28 | ar << (int64_t)7; | 28 | ar << (int64_t)7; |
29 | ar << (uint64_t)8; | 29 | ar << (uint64_t)8; |
30 | ar << (char)9; | 30 | ar << (char)9; |
31 | ar << (unsigned char)10; | 31 | ar << (unsigned char)10; |
32 | ar << (short)11; | 32 | ar << (short)11; |
33 | ar << (unsigned short)12; | 33 | ar << (unsigned short)12; |
34 | ar << (int)13; | 34 | ar << (int)13; |
35 | ar << (unsigned int)14; | 35 | ar << (unsigned int)14; |
36 | ar << (long)15; | 36 | ar << (long)15; |
37 | ar << (unsigned long)16; | 37 | ar << (unsigned long)16; |
38 | ar << (long long)17; | 38 | ar << (long long)17; |
39 | ar << (unsigned long long)18; | 39 | ar << (unsigned long long)18; |
40 | ar.close(); | 40 | ar.close(); |
41 | } | 41 | } |
42 | mb.setPos( 0 ); | 42 | mb.setPos( 0 ); |
43 | { | 43 | { |
44 | Archive ar( mb, Archive::load ); | 44 | Archive ar( mb, Archive::load ); |
45 | int8_t p1; | 45 | int8_t p1; |
46 | uint8_t p2; | 46 | uint8_t p2; |
47 | int16_t p3; | 47 | int16_t p3; |
48 | uint16_t p4; | 48 | uint16_t p4; |
49 | int32_t p5; | 49 | int32_t p5; |
50 | uint32_t p6; | 50 | uint32_t p6; |
51 | int64_t p7; | 51 | int64_t p7; |
52 | uint64_t p8; | 52 | uint64_t p8; |
53 | char p9; | 53 | char p9; |
54 | unsigned char p10; | 54 | unsigned char p10; |
55 | short p11; | 55 | short p11; |
56 | unsigned short p12; | 56 | unsigned short p12; |
57 | int p13; | 57 | int p13; |
58 | unsigned int p14; | 58 | unsigned int p14; |
59 | long p15; | 59 | long p15; |
60 | unsigned long p16; | 60 | unsigned long p16; |
61 | long long p17; | 61 | long long p17; |
62 | unsigned long long p18; | 62 | unsigned long long p18; |
63 | ar >> p1; | 63 | ar >> p1; |
64 | ar >> p2; | 64 | ar >> p2; |
65 | ar >> p3; | 65 | ar >> p3; |
66 | ar >> p4; | 66 | ar >> p4; |
67 | ar >> p5; | 67 | ar >> p5; |
68 | ar >> p6; | 68 | ar >> p6; |
69 | ar >> p7; | 69 | ar >> p7; |
70 | ar >> p8; | 70 | ar >> p8; |
71 | ar >> p9; | 71 | ar >> p9; |
72 | ar >> p10; | 72 | ar >> p10; |
73 | ar >> p11; | 73 | ar >> p11; |
74 | ar >> p12; | 74 | ar >> p12; |
75 | ar >> p13; | 75 | ar >> p13; |
76 | ar >> p14; | 76 | ar >> p14; |
77 | ar >> p15; | 77 | ar >> p15; |
78 | ar >> p16; | 78 | ar >> p16; |
79 | ar >> p17; | 79 | ar >> p17; |
80 | ar >> p18; | 80 | ar >> p18; |
81 | unitTest( p1 == 1 ); | 81 | unitTest( p1 == 1 ); |
82 | unitTest( p2 == 2 ); | 82 | unitTest( p2 == 2 ); |
83 | unitTest( p3 == 3 ); | 83 | unitTest( p3 == 3 ); |
84 | unitTest( p4 == 4 ); | 84 | unitTest( p4 == 4 ); |
85 | unitTest( p5 == 5 ); | 85 | unitTest( p5 == 5 ); |
86 | unitTest( p6 == 6 ); | 86 | unitTest( p6 == 6 ); |
87 | unitTest( p7 == 7 ); | 87 | unitTest( p7 == 7 ); |
88 | unitTest( p8 == 8 ); | 88 | unitTest( p8 == 8 ); |
89 | unitTest( p9 == 9 ); | 89 | unitTest( p9 == 9 ); |
90 | unitTest( p10 == 10 ); | 90 | unitTest( p10 == 10 ); |
91 | unitTest( p11 == 11 ); | 91 | unitTest( p11 == 11 ); |
92 | unitTest( p12 == 12 ); | 92 | unitTest( p12 == 12 ); |
93 | unitTest( p13 == 13 ); | 93 | unitTest( p13 == 13 ); |
94 | unitTest( p14 == 14 ); | 94 | unitTest( p14 == 14 ); |
95 | unitTest( p15 == 15 ); | 95 | unitTest( p15 == 15 ); |
96 | unitTest( p16 == 16 ); | 96 | unitTest( p16 == 16 ); |
97 | unitTest( p17 == 17 ); | 97 | unitTest( p17 == 17 ); |
98 | unitTest( p18 == 18 ); | 98 | unitTest( p18 == 18 ); |
99 | ar.close(); | 99 | ar.close(); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | test containers1 | 103 | test containers1 |
104 | { | 104 | { |
105 | MemBuf mb; | 105 | MemBuf mb; |
106 | { | 106 | { |
107 | Archive ar( mb, Archive::save ); | 107 | Archive ar( mb, Archive::save ); |
108 | String sStr("This is a test string."); | 108 | String sStr("This is a test string."); |
109 | List<int> lList; | 109 | List<int> lList; |
110 | lList.append( 10 ); | 110 | lList.append( 10 ); |
111 | lList.append( 20 ); | 111 | lList.append( 20 ); |
112 | lList.append( 30 ); | 112 | lList.append( 30 ); |
113 | lList.append( 40 ); | 113 | lList.append( 40 ); |
114 | ar << sStr; | 114 | ar << sStr; |
115 | ar << lList; | 115 | ar << lList; |
116 | ar.close(); | 116 | ar.close(); |
117 | } | 117 | } |
118 | mb.setPos( 0 ); | 118 | mb.setPos( 0 ); |
119 | { | 119 | { |
120 | Archive ar( mb, Archive::load ); | 120 | Archive ar( mb, Archive::load ); |
121 | String sStr; | 121 | String sStr; |
122 | List<int> lList; | 122 | List<int> lList; |
123 | ar >> sStr; | 123 | ar >> sStr; |
124 | ar >> lList; | 124 | ar >> lList; |
125 | unitTest( sStr == "This is a test string." ); | 125 | unitTest( sStr == "This is a test string." ); |
126 | unitTest( lList.getSize() == 4 ); | 126 | unitTest( lList.getSize() == 4 ); |
127 | List<int>::iterator i = lList.begin(); | 127 | List<int>::iterator i = lList.begin(); |
128 | unitTest( *i == 10 ); i++; | 128 | unitTest( *i == 10 ); i++; |
129 | unitTest( *i == 20 ); i++; | 129 | unitTest( *i == 20 ); i++; |
130 | unitTest( *i == 30 ); i++; | 130 | unitTest( *i == 30 ); i++; |
131 | unitTest( *i == 40 ); | 131 | unitTest( *i == 40 ); |
132 | ar.close(); | 132 | ar.close(); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | test containers2 | 136 | test containers2 |
137 | { | 137 | { |
138 | MemBuf mb; | 138 | MemBuf mb; |
139 | { | 139 | { |
140 | Archive ar( mb, Archive::save ); | 140 | Archive ar( mb, Archive::save ); |
141 | String sStr("This is a test string."); | 141 | String sStr("This is a test string."); |
142 | Array<int> lArray; | 142 | Array<int> lArray; |
143 | lArray.append( 10 ); | 143 | lArray.append( 10 ); |
144 | lArray.append( 20 ); | 144 | lArray.append( 20 ); |
145 | lArray.append( 30 ); | 145 | lArray.append( 30 ); |
146 | lArray.append( 40 ); | 146 | lArray.append( 40 ); |
147 | ar << sStr; | 147 | ar << sStr; |
148 | ar << lArray; | 148 | ar << lArray; |
149 | ar.close(); | 149 | ar.close(); |
150 | } | 150 | } |
151 | mb.setPos( 0 ); | 151 | mb.setPos( 0 ); |
152 | { | 152 | { |
153 | Archive ar( mb, Archive::load ); | 153 | Archive ar( mb, Archive::load ); |
154 | String sStr; | 154 | String sStr; |
155 | Array<int> lArray; | 155 | Array<int> lArray; |
156 | ar >> sStr; | 156 | ar >> sStr; |
157 | ar >> lArray; | 157 | ar >> lArray; |
158 | unitTest( sStr == "This is a test string." ); | 158 | unitTest( sStr == "This is a test string." ); |
159 | unitTest( lArray.getSize() == 4 ); | 159 | unitTest( lArray.getSize() == 4 ); |
160 | Array<int>::iterator i = lArray.begin(); | 160 | Array<int>::iterator i = lArray.begin(); |
161 | unitTest( *i == 10 ); i++; | 161 | unitTest( *i == 10 ); i++; |
162 | unitTest( *i == 20 ); i++; | 162 | unitTest( *i == 20 ); i++; |
163 | unitTest( *i == 30 ); i++; | 163 | unitTest( *i == 30 ); i++; |
164 | unitTest( *i == 40 ); | 164 | unitTest( *i == 40 ); |
165 | ar.close(); | 165 | ar.close(); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | test containers3 | 169 | test containers3 |
170 | { | 170 | { |
171 | MemBuf mb; | 171 | MemBuf mb; |
172 | { | 172 | { |
173 | Archive ar( mb, Archive::save ); | 173 | Archive ar( mb, Archive::save ); |
174 | Array<String> lArray; | 174 | Array<String> lArray; |
175 | lArray.append( "10" ); | 175 | lArray.append( "10" ); |
176 | lArray.append( "20" ); | 176 | lArray.append( "20" ); |
177 | lArray.append( "30" ); | 177 | lArray.append( "30" ); |
178 | lArray.append( "40" ); | 178 | lArray.append( "40" ); |
179 | ar << lArray; | 179 | ar << lArray; |
180 | ar.close(); | 180 | ar.close(); |
181 | } | 181 | } |
182 | mb.setPos( 0 ); | 182 | mb.setPos( 0 ); |
183 | { | 183 | { |
184 | Archive ar( mb, Archive::load ); | 184 | Archive ar( mb, Archive::load ); |
185 | Array<String> lArray; | 185 | Array<String> lArray; |
186 | ar >> lArray; | 186 | ar >> lArray; |
187 | unitTest( lArray.getSize() == 4 ); | 187 | unitTest( lArray.getSize() == 4 ); |
188 | Array<String>::iterator i = lArray.begin(); | 188 | Array<String>::iterator i = lArray.begin(); |
189 | unitTest( *i == "10" ); i++; | 189 | unitTest( *i == "10" ); i++; |
190 | unitTest( *i == "20" ); i++; | 190 | unitTest( *i == "20" ); i++; |
191 | unitTest( *i == "30" ); i++; | 191 | unitTest( *i == "30" ); i++; |
192 | unitTest( *i == "40" ); | 192 | unitTest( *i == "40" ); |
193 | ar.close(); | 193 | ar.close(); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | } | 196 | } |
diff --git a/src/unit/array.unit b/src/unit/array.unit index 6e985d8..ca85b4d 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit | |||
@@ -14,91 +14,91 @@ using Bu::sio; | |||
14 | 14 | ||
15 | suite Array | 15 | suite Array |
16 | { | 16 | { |
17 | test general | 17 | test general |
18 | { | 18 | { |
19 | Bu::Array<int> ai; | 19 | Bu::Array<int> ai; |
20 | 20 | ||
21 | ai.append( 5 ); | 21 | ai.append( 5 ); |
22 | ai.append( 10 ); | 22 | ai.append( 10 ); |
23 | unitTest( ai.getSize() == 2 ); | 23 | unitTest( ai.getSize() == 2 ); |
24 | unitTest( ai.getCapacity() == 10 ); | 24 | unitTest( ai.getCapacity() == 10 ); |
25 | unitTest( ai[0] == 5 ); | 25 | unitTest( ai[0] == 5 ); |
26 | unitTest( ai[1] == 10 ); | 26 | unitTest( ai[1] == 10 ); |
27 | } | 27 | } |
28 | 28 | ||
29 | test iterate1 | 29 | test iterate1 |
30 | { | 30 | { |
31 | Bu::Array<int> ai; | 31 | Bu::Array<int> ai; |
32 | for( int j = 0; j < 10; j++ ) | 32 | for( int j = 0; j < 10; j++ ) |
33 | ai.append( j ); | 33 | ai.append( j ); |
34 | 34 | ||
35 | int j = 0; | 35 | int j = 0; |
36 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | 36 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) |
37 | unitTest( (*i) == j++ ); | 37 | unitTest( (*i) == j++ ); |
38 | unitTest( j == 10 ); | 38 | unitTest( j == 10 ); |
39 | 39 | ||
40 | const Bu::Array<int> &ci = ai; | 40 | const Bu::Array<int> &ci = ai; |
41 | j = 0; | 41 | j = 0; |
42 | for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) | 42 | for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) |
43 | unitTest( (*i) == j++ ); | 43 | unitTest( (*i) == j++ ); |
44 | unitTest( j == 10 ); | 44 | unitTest( j == 10 ); |
45 | } | 45 | } |
46 | 46 | ||
47 | test iterate2 | 47 | test iterate2 |
48 | { | 48 | { |
49 | Bu::Array<int> ai; | 49 | Bu::Array<int> ai; |
50 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | 50 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) |
51 | unitFailed("Empty lists shouldn't be iterated through."); | 51 | unitFailed("Empty lists shouldn't be iterated through."); |
52 | for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) | 52 | for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) |
53 | unitFailed("Empty lists shouldn't be iterated through."); | 53 | unitFailed("Empty lists shouldn't be iterated through."); |
54 | } | 54 | } |
55 | 55 | ||
56 | test copy | 56 | test copy |
57 | { | 57 | { |
58 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; | 58 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; |
59 | typedef Bu::Array<StrHash> StrHashArray; | 59 | typedef Bu::Array<StrHash> StrHashArray; |
60 | 60 | ||
61 | StrHash h1; | 61 | StrHash h1; |
62 | h1["Hi"] = "Yo"; | 62 | h1["Hi"] = "Yo"; |
63 | h1["Bye"] = "Later"; | 63 | h1["Bye"] = "Later"; |
64 | 64 | ||
65 | StrHash h2; | 65 | StrHash h2; |
66 | h2["Test"] = "Bloop"; | 66 | h2["Test"] = "Bloop"; |
67 | h2["Foo"] = "ooF"; | 67 | h2["Foo"] = "ooF"; |
68 | 68 | ||
69 | StrHashArray a1; | 69 | StrHashArray a1; |
70 | a1.append( h1 ); | 70 | a1.append( h1 ); |
71 | a1.append( h2 ); | 71 | a1.append( h2 ); |
72 | 72 | ||
73 | StrHashArray a2(a1); | 73 | StrHashArray a2(a1); |
74 | 74 | ||
75 | unitTest( a2[0].get("Hi") == "Yo" ); | 75 | unitTest( a2[0].get("Hi") == "Yo" ); |
76 | unitTest( a2[0].get("Bye") == "Later" ); | 76 | unitTest( a2[0].get("Bye") == "Later" ); |
77 | unitTest( a2[1].get("Test") == "Bloop" ); | 77 | unitTest( a2[1].get("Test") == "Bloop" ); |
78 | unitTest( a2[1].get("Foo") == "ooF" ); | 78 | unitTest( a2[1].get("Foo") == "ooF" ); |
79 | 79 | ||
80 | StrHashArray a3; | 80 | StrHashArray a3; |
81 | a3 = a1; | 81 | a3 = a1; |
82 | 82 | ||
83 | unitTest( a3[0].get("Hi") == "Yo" ); | 83 | unitTest( a3[0].get("Hi") == "Yo" ); |
84 | unitTest( a3[0].get("Bye") == "Later" ); | 84 | unitTest( a3[0].get("Bye") == "Later" ); |
85 | unitTest( a3[1].get("Test") == "Bloop" ); | 85 | unitTest( a3[1].get("Test") == "Bloop" ); |
86 | unitTest( a3[1].get("Foo") == "ooF" ); | 86 | unitTest( a3[1].get("Foo") == "ooF" ); |
87 | } | 87 | } |
88 | 88 | ||
89 | test insert | 89 | test insert |
90 | { | 90 | { |
91 | Bu::Array<int> aInts; | 91 | Bu::Array<int> aInts; |
92 | aInts.insert( aInts.end(), 4 ); | 92 | aInts.insert( aInts.end(), 4 ); |
93 | aInts.insert( aInts.begin(), 1 ); | 93 | aInts.insert( aInts.begin(), 1 ); |
94 | aInts.insert( aInts.end(), 5 ); | 94 | aInts.insert( aInts.end(), 5 ); |
95 | aInts.insert( aInts.begin()+1, 3 ); | 95 | aInts.insert( aInts.begin()+1, 3 ); |
96 | aInts.insert( aInts.begin()+1, 2 ); | 96 | aInts.insert( aInts.begin()+1, 2 ); |
97 | aInts.insert( aInts.begin(), 0 ); | 97 | aInts.insert( aInts.begin(), 0 ); |
98 | 98 | ||
99 | for( int j = 0; j < 6; j++ ) | 99 | for( int j = 0; j < 6; j++ ) |
100 | { | 100 | { |
101 | unitTest( aInts[j] == j ); | 101 | unitTest( aInts[j] == j ); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | } | 104 | } |
diff --git a/src/unit/base64.unit b/src/unit/base64.unit index 5266b48..bd5bc97 100644 --- a/src/unit/base64.unit +++ b/src/unit/base64.unit | |||
@@ -11,18 +11,18 @@ | |||
11 | 11 | ||
12 | suite MemBuf | 12 | suite MemBuf |
13 | { | 13 | { |
14 | test decode01 | 14 | test decode01 |
15 | { | 15 | { |
16 | unitTest( Bu::decodeStr<Bu::Base64>("RnVu") == "Fun" ); | 16 | unitTest( Bu::decodeStr<Bu::Base64>("RnVu") == "Fun" ); |
17 | unitTest( Bu::decodeStr<Bu::Base64>("V2hhdA==") == "What" ); | 17 | unitTest( Bu::decodeStr<Bu::Base64>("V2hhdA==") == "What" ); |
18 | unitTest( Bu::decodeStr<Bu::Base64>("SGVsbG8=") == "Hello" ); | 18 | unitTest( Bu::decodeStr<Bu::Base64>("SGVsbG8=") == "Hello" ); |
19 | } | 19 | } |
20 | 20 | ||
21 | test encode01 | 21 | test encode01 |
22 | { | 22 | { |
23 | unitTest( Bu::decodeStr<Bu::Base64>("R n V u") == "Fun" ); | 23 | unitTest( Bu::decodeStr<Bu::Base64>("R n V u") == "Fun" ); |
24 | unitTest( Bu::decodeStr<Bu::Base64>("V2\n\n\thh dA==") == "What" ); | 24 | unitTest( Bu::decodeStr<Bu::Base64>("V2\n\n\thh dA==") == "What" ); |
25 | unitTest( Bu::decodeStr<Bu::Base64>("\n\n\t\t SGV\r\ns\tbG8\n=") == "Hello" ); | 25 | unitTest( Bu::decodeStr<Bu::Base64>("\n\n\t\t SGV\r\ns\tbG8\n=") == "Hello" ); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
diff --git a/src/unit/blowfish.unit b/src/unit/blowfish.unit index abab63d..1b4ca18 100644 --- a/src/unit/blowfish.unit +++ b/src/unit/blowfish.unit | |||
@@ -50,29 +50,29 @@ static const char *testdat[34][3] ={ | |||
50 | 50 | ||
51 | suite Blowfish | 51 | suite Blowfish |
52 | { | 52 | { |
53 | test standard | 53 | test standard |
54 | { | 54 | { |
55 | for( int j = 0; j < 34; j++ ) | 55 | for( int j = 0; j < 34; j++ ) |
56 | { | 56 | { |
57 | Bu::MemBuf mb; | 57 | Bu::MemBuf mb; |
58 | Bu::BlowfishEcb bf( mb ); | 58 | Bu::BlowfishEcb bf( mb ); |
59 | bf.setPassword( Bu::decodeStr<Bu::Hex>( testdat[j][0] ) ); | 59 | bf.setPassword( Bu::decodeStr<Bu::Hex>( testdat[j][0] ) ); |
60 | bf.write( Bu::decodeStr<Bu::Hex>( testdat[j][1] ) ); | 60 | bf.write( Bu::decodeStr<Bu::Hex>( testdat[j][1] ) ); |
61 | unitTest( | 61 | unitTest( |
62 | mb.getString() == Bu::decodeStr<Bu::Hex>( testdat[j][2] ) | 62 | mb.getString() == Bu::decodeStr<Bu::Hex>( testdat[j][2] ) |
63 | ); | 63 | ); |
64 | 64 | ||
65 | mb.setPos( 0 ); | 65 | mb.setPos( 0 ); |
66 | Bu::BlowfishEcb bf2( mb ); | 66 | Bu::BlowfishEcb bf2( mb ); |
67 | bf2.setPassword( Bu::decodeStr<Bu::Hex>( testdat[j][0] ) ); | 67 | bf2.setPassword( Bu::decodeStr<Bu::Hex>( testdat[j][0] ) ); |
68 | char buf[8]; | 68 | char buf[8]; |
69 | bf2.read( buf, 8 ); | 69 | bf2.read( buf, 8 ); |
70 | 70 | ||
71 | unitTest( | 71 | unitTest( |
72 | Bu::String(testdat[j][1]) == | 72 | Bu::String(testdat[j][1]) == |
73 | Bu::encodeStr<Bu::Hex>(Bu::String(buf,8),true) | 73 | Bu::encodeStr<Bu::Hex>(Bu::String(buf,8),true) |
74 | ); | 74 | ); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
diff --git a/src/unit/buffer.unit b/src/unit/buffer.unit index 8bfdc3d..8613c5b 100644 --- a/src/unit/buffer.unit +++ b/src/unit/buffer.unit | |||
@@ -12,16 +12,16 @@ | |||
12 | 12 | ||
13 | suite Buffer | 13 | suite Buffer |
14 | { | 14 | { |
15 | test emptyFile | 15 | test emptyFile |
16 | { | 16 | { |
17 | Bu::String sTmp("empty-XXXXXX"); | 17 | Bu::String sTmp("empty-XXXXXX"); |
18 | Bu::File fEmpty = tempFile(sTmp); | 18 | Bu::File fEmpty = tempFile(sTmp); |
19 | Bu::Buffer buf( fEmpty ); | 19 | Bu::Buffer buf( fEmpty ); |
20 | 20 | ||
21 | unitTest( buf.isEos() == false ); | 21 | unitTest( buf.isEos() == false ); |
22 | Bu::String sLine = buf.readLine(); | 22 | Bu::String sLine = buf.readLine(); |
23 | unitTest( sLine == "" ); | 23 | unitTest( sLine == "" ); |
24 | unitTest( fEmpty.isEos() == true ); | 24 | unitTest( fEmpty.isEos() == true ); |
25 | unitTest( buf.isEos() == true ); | 25 | unitTest( buf.isEos() == true ); |
26 | } | 26 | } |
27 | } | 27 | } |
diff --git a/src/unit/file.unit b/src/unit/file.unit index 7140d03..c0358ac 100644 --- a/src/unit/file.unit +++ b/src/unit/file.unit | |||
@@ -14,87 +14,87 @@ | |||
14 | 14 | ||
15 | suite File | 15 | suite File |
16 | { | 16 | { |
17 | test writeFull | 17 | test writeFull |
18 | { | 18 | { |
19 | Bu::File sf("testfile1", Bu::File::WriteNew ); | 19 | Bu::File sf("testfile1", Bu::File::WriteNew ); |
20 | for( int c = 0; c < 256; c++ ) | 20 | for( int c = 0; c < 256; c++ ) |
21 | { | 21 | { |
22 | unsigned char ch = (unsigned char)c; | 22 | unsigned char ch = (unsigned char)c; |
23 | sf.write( &ch, 1 ); | 23 | sf.write( &ch, 1 ); |
24 | unitTest( sf.tell() == c+1 ); | 24 | unitTest( sf.tell() == c+1 ); |
25 | } | 25 | } |
26 | //unitTest( sf.canRead() == false ); | 26 | //unitTest( sf.canRead() == false ); |
27 | //unitTest( sf.canWrite() == true ); | 27 | //unitTest( sf.canWrite() == true ); |
28 | //unitTest( sf.canSeek() == true ); | 28 | //unitTest( sf.canSeek() == true ); |
29 | sf.close(); | 29 | sf.close(); |
30 | struct stat sdat; | 30 | struct stat sdat; |
31 | stat("testfile1", &sdat ); | 31 | stat("testfile1", &sdat ); |
32 | unitTest( sdat.st_size == 256 ); | 32 | unitTest( sdat.st_size == 256 ); |
33 | } | 33 | } |
34 | 34 | ||
35 | test readBlocks | 35 | test readBlocks |
36 | { | 36 | { |
37 | Bu::File sf("testfile1", Bu::File::Read ); | 37 | Bu::File sf("testfile1", Bu::File::Read ); |
38 | unsigned char buf[50]; | 38 | unsigned char buf[50]; |
39 | size_t total = 0; | 39 | size_t total = 0; |
40 | for(;;) | 40 | for(;;) |
41 | { | 41 | { |
42 | size_t s = sf.read( buf, 50 ); | 42 | size_t s = sf.read( buf, 50 ); |
43 | for( size_t c = 0; c < s; c++ ) | 43 | for( size_t c = 0; c < s; c++ ) |
44 | { | 44 | { |
45 | unitTest( buf[c] == (unsigned char)(c+total) ); | 45 | unitTest( buf[c] == (unsigned char)(c+total) ); |
46 | } | 46 | } |
47 | total += s; | 47 | total += s; |
48 | if( s < 50 ) | 48 | if( s < 50 ) |
49 | { | 49 | { |
50 | unitTest( total == 256 ); | 50 | unitTest( total == 256 ); |
51 | unitTest( sf.isEos() == false ); | 51 | unitTest( sf.isEos() == false ); |
52 | unitTest( sf.read( buf, 1 ) == 0 ); | 52 | unitTest( sf.read( buf, 1 ) == 0 ); |
53 | unitTest( sf.isEos() == true ); | 53 | unitTest( sf.isEos() == true ); |
54 | // EOS is only set when an attempt to read past the end of | 54 | // EOS is only set when an attempt to read past the end of |
55 | // the stream is made, not when a short block is returned. | 55 | // the stream is made, not when a short block is returned. |
56 | break; | 56 | break; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | sf.close(); | 59 | sf.close(); |
60 | } | 60 | } |
61 | 61 | ||
62 | test readError1 | 62 | test readError1 |
63 | { | 63 | { |
64 | try | 64 | try |
65 | { | 65 | { |
66 | Bu::File sf("doesn'texist", Bu::File::Read ); | 66 | Bu::File sf("doesn'texist", Bu::File::Read ); |
67 | unitFailed("No exception thrown"); | 67 | unitFailed("No exception thrown"); |
68 | } | 68 | } |
69 | catch( Bu::FileException &e ) | 69 | catch( Bu::FileException &e ) |
70 | { | 70 | { |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | test readError2 | 75 | test readError2 |
76 | { | 76 | { |
77 | Bu::File sf("testfile1", Bu::File::Read ); | 77 | Bu::File sf("testfile1", Bu::File::Read ); |
78 | char buf[256]; | 78 | char buf[256]; |
79 | int r = sf.read( buf, 256 ); | 79 | int r = sf.read( buf, 256 ); |
80 | unitTest( r == 256 ); | 80 | unitTest( r == 256 ); |
81 | // You have to read past the end to set the EOS flag. | 81 | // You have to read past the end to set the EOS flag. |
82 | unitTest( sf.isEos() == false ); | 82 | unitTest( sf.isEos() == false ); |
83 | try | 83 | try |
84 | { | 84 | { |
85 | if( sf.read( buf, 5 ) > 0 ) | 85 | if( sf.read( buf, 5 ) > 0 ) |
86 | { | 86 | { |
87 | unitFailed("Non-zero read result"); | 87 | unitFailed("Non-zero read result"); |
88 | } | 88 | } |
89 | else | 89 | else |
90 | { | 90 | { |
91 | sf.close(); | 91 | sf.close(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | catch( Bu::FileException &e ) | 94 | catch( Bu::FileException &e ) |
95 | { | 95 | { |
96 | sf.close(); | 96 | sf.close(); |
97 | return; | 97 | return; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | } | 100 | } |
diff --git a/src/unit/hash.unit b/src/unit/hash.unit index 3abc6a5..e30c62b 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit | |||
@@ -19,193 +19,193 @@ typedef Bu::Hash<int, Bu::String> IntStrHash; | |||
19 | 19 | ||
20 | suite Hash | 20 | suite Hash |
21 | { | 21 | { |
22 | test probe1 | 22 | test probe1 |
23 | { | 23 | { |
24 | StrIntHash h; | 24 | StrIntHash h; |
25 | char buf[20]; | 25 | char buf[20]; |
26 | for(int i=1;i<10000;i++) | 26 | for(int i=1;i<10000;i++) |
27 | { | 27 | { |
28 | sprintf(buf,"%d",i); | 28 | sprintf(buf,"%d",i); |
29 | Bu::String sTmp(buf); | 29 | Bu::String sTmp(buf); |
30 | h[sTmp] = i; | 30 | h[sTmp] = i; |
31 | unitTest( h.has(sTmp) ); | 31 | unitTest( h.has(sTmp) ); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | test insert1 | 35 | test insert1 |
36 | { | 36 | { |
37 | StrIntHash h; | 37 | StrIntHash h; |
38 | h["Hi"] = 42; | 38 | h["Hi"] = 42; |
39 | unitTest( h["Hi"] == 42 ); | 39 | unitTest( h["Hi"] == 42 ); |
40 | } | 40 | } |
41 | 41 | ||
42 | test insert2 | 42 | test insert2 |
43 | { | 43 | { |
44 | StrStrHash h; | 44 | StrStrHash h; |
45 | h["Hi"] = "Yo"; | 45 | h["Hi"] = "Yo"; |
46 | h["Bye"] = "Later"; | 46 | h["Bye"] = "Later"; |
47 | unitTest( h["Hi"].getValue() == "Yo" ); | 47 | unitTest( h["Hi"].getValue() == "Yo" ); |
48 | 48 | ||
49 | StrStrHash h2(h); | 49 | StrStrHash h2(h); |
50 | unitTest( h2["Hi"].getValue() == "Yo" ); | 50 | unitTest( h2["Hi"].getValue() == "Yo" ); |
51 | unitTest( h2["Bye"].getValue() == "Later" ); | 51 | unitTest( h2["Bye"].getValue() == "Later" ); |
52 | 52 | ||
53 | StrStrHash h3; | 53 | StrStrHash h3; |
54 | h3 = h; | 54 | h3 = h; |
55 | unitTest( h3["Hi"].getValue() == "Yo" ); | 55 | unitTest( h3["Hi"].getValue() == "Yo" ); |
56 | unitTest( h3["Bye"].getValue() == "Later" ); | 56 | unitTest( h3["Bye"].getValue() == "Later" ); |
57 | } | 57 | } |
58 | 58 | ||
59 | test insert3 | 59 | test insert3 |
60 | { | 60 | { |
61 | IntStrHash h; | 61 | IntStrHash h; |
62 | 62 | ||
63 | for( unsigned int i=1; i<50; i++ ) | 63 | for( unsigned int i=1; i<50; i++ ) |
64 | { | 64 | { |
65 | h[i] = "testing"; | 65 | h[i] = "testing"; |
66 | unitTest( h.getSize() == i ); | 66 | unitTest( h.getSize() == i ); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | test erase1 | 70 | test erase1 |
71 | { | 71 | { |
72 | StrIntHash h; | 72 | StrIntHash h; |
73 | h.insert("Number 1", 1 ); | 73 | h.insert("Number 1", 1 ); |
74 | h.insert("Number 2", 2 ); | 74 | h.insert("Number 2", 2 ); |
75 | h.insert("Number 3", 3 ); | 75 | h.insert("Number 3", 3 ); |
76 | h.erase("Number 2"); | 76 | h.erase("Number 2"); |
77 | h.get("Number 3"); | 77 | h.get("Number 3"); |
78 | try { | 78 | try { |
79 | h.get("Number 2"); | 79 | h.get("Number 2"); |
80 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); | 80 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); |
81 | } catch( Bu::HashException &e ) { } | 81 | } catch( Bu::HashException &e ) { } |
82 | 82 | ||
83 | /* printf("\n"); | 83 | /* printf("\n"); |
84 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) | 84 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) |
85 | { | 85 | { |
86 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | 86 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); |
87 | } */ | 87 | } */ |
88 | } | 88 | } |
89 | 89 | ||
90 | test copy | 90 | test copy |
91 | { | 91 | { |
92 | StrIntHash h; | 92 | StrIntHash h; |
93 | h.insert("hello", 55 ); | 93 | h.insert("hello", 55 ); |
94 | h.insert("goodbye", -1812 ); | 94 | h.insert("goodbye", -1812 ); |
95 | 95 | ||
96 | StrIntHash h2 = h; | 96 | StrIntHash h2 = h; |
97 | unitTest( h2.isCoreShared( h ) ); | 97 | unitTest( h2.isCoreShared( h ) ); |
98 | 98 | ||
99 | StrIntHash h3 = h.clone(); | 99 | StrIntHash h3 = h.clone(); |
100 | unitTest( !h3.isCoreShared( h ) ); | 100 | unitTest( !h3.isCoreShared( h ) ); |
101 | } | 101 | } |
102 | 102 | ||
103 | test reHashSpecial | 103 | test reHashSpecial |
104 | { | 104 | { |
105 | IntStrHash hTest; | 105 | IntStrHash hTest; |
106 | 106 | ||
107 | setStepCount( 1000000 ); | 107 | setStepCount( 1000000 ); |
108 | for( int i=0; i<1000000; ++i ) | 108 | for( int i=0; i<1000000; ++i ) |
109 | { | 109 | { |
110 | char buf[40]; snprintf(buf,40,"num%d",i); | 110 | char buf[40]; snprintf(buf,40,"num%d",i); |
111 | incProgress(); | 111 | incProgress(); |
112 | 112 | ||
113 | if( ((double)random()/(double)RAND_MAX)<.01 ) | 113 | if( ((double)random()/(double)RAND_MAX)<.01 ) |
114 | { | 114 | { |
115 | //printf("ERASE: %d (%s)\n",i%64,buf); | 115 | //printf("ERASE: %d (%s)\n",i%64,buf); |
116 | hTest.erase(i%64); | 116 | hTest.erase(i%64); |
117 | } | 117 | } |
118 | else | 118 | else |
119 | { | 119 | { |
120 | hTest[i%64]=buf; | 120 | hTest[i%64]=buf; |
121 | } | 121 | } |
122 | 122 | ||
123 | /*printf("(%d) size: %u fill: %u cap:%u\n", | 123 | /*printf("(%d) size: %u fill: %u cap:%u\n", |
124 | i, | 124 | i, |
125 | hTest.getSize(), | 125 | hTest.getSize(), |
126 | hTest.getFill(), | 126 | hTest.getFill(), |
127 | hTest.getCapacity() | 127 | hTest.getCapacity() |
128 | );*/ | 128 | );*/ |
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | test stress | 132 | test stress |
133 | { | 133 | { |
134 | srandom(time(NULL)); | 134 | srandom(time(NULL)); |
135 | 135 | ||
136 | IntStrHash hTest; | 136 | IntStrHash hTest; |
137 | IntStrHash hReUse; | 137 | IntStrHash hReUse; |
138 | setStepCount( 100000 ); | 138 | setStepCount( 100000 ); |
139 | 139 | ||
140 | for( int i=0; i<100000; ++i ) | 140 | for( int i=0; i<100000; ++i ) |
141 | { | 141 | { |
142 | char buf[40]; snprintf(buf,40,"num%d",i); | 142 | char buf[40]; snprintf(buf,40,"num%d",i); |
143 | hTest[i] = buf; | 143 | hTest[i] = buf; |
144 | incProgress(); | 144 | incProgress(); |
145 | 145 | ||
146 | 146 | ||
147 | if( ((double)random()/(double)RAND_MAX)<.01 ) | 147 | if( ((double)random()/(double)RAND_MAX)<.01 ) |
148 | { | 148 | { |
149 | Bu::List<int> lKeys = hReUse.getKeys(); | 149 | Bu::List<int> lKeys = hReUse.getKeys(); |
150 | Bu::List<int>::const_iterator it = lKeys.begin(); | 150 | Bu::List<int>::const_iterator it = lKeys.begin(); |
151 | int iIdx = (int)(((double)random()/(double)RAND_MAX) | 151 | int iIdx = (int)(((double)random()/(double)RAND_MAX) |
152 | *lKeys.getSize()); | 152 | *lKeys.getSize()); |
153 | for( int l=0; it; ++it, ++l ) | 153 | for( int l=0; it; ++it, ++l ) |
154 | { | 154 | { |
155 | if( l==iIdx ) | 155 | if( l==iIdx ) |
156 | { | 156 | { |
157 | int iVal = *it; | 157 | int iVal = *it; |
158 | hReUse.erase( *it ); | 158 | hReUse.erase( *it ); |
159 | char buf[40]; snprintf(buf,40,"num%d",iVal); | 159 | char buf[40]; snprintf(buf,40,"num%d",iVal); |
160 | hTest[i] = buf; | 160 | hTest[i] = buf; |
161 | //printf("re-use: %s\n",buf); | 161 | //printf("re-use: %s\n",buf); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | /*printf("(%s) size: %u fill: %u cap:%u\n", | 166 | /*printf("(%s) size: %u fill: %u cap:%u\n", |
167 | buf, | 167 | buf, |
168 | hTest.getSize(), | 168 | hTest.getSize(), |
169 | hTest.getFill(), | 169 | hTest.getFill(), |
170 | hTest.getCapacity() | 170 | hTest.getCapacity() |
171 | );*/ | 171 | );*/ |
172 | 172 | ||
173 | if( ((double)random()/(double)RAND_MAX)<.3 ) | 173 | if( ((double)random()/(double)RAND_MAX)<.3 ) |
174 | { | 174 | { |
175 | Bu::List<int> lKeys = hTest.getKeys(); | 175 | Bu::List<int> lKeys = hTest.getKeys(); |
176 | int iIdx = (int)(((double)random()/(double)RAND_MAX) | 176 | int iIdx = (int)(((double)random()/(double)RAND_MAX) |
177 | *lKeys.getSize()); | 177 | *lKeys.getSize()); |
178 | Bu::List<int>::const_iterator it = lKeys.begin(); | 178 | Bu::List<int>::const_iterator it = lKeys.begin(); |
179 | for( int k=0; it; ++it, ++k ) | 179 | for( int k=0; it; ++it, ++k ) |
180 | { | 180 | { |
181 | if( k == iIdx ) | 181 | if( k == iIdx ) |
182 | { | 182 | { |
183 | hReUse.insert(*it,"yo"); | 183 | hReUse.insert(*it,"yo"); |
184 | hTest.erase( *it ); | 184 | hTest.erase( *it ); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | if( hTest.getSize() > 100 ) | 189 | if( hTest.getSize() > 100 ) |
190 | { | 190 | { |
191 | int iK = (int)(((double)random()/(double)RAND_MAX)*50)+10; | 191 | int iK = (int)(((double)random()/(double)RAND_MAX)*50)+10; |
192 | for( int j=0; j<iK; ++j ) | 192 | for( int j=0; j<iK; ++j ) |
193 | { | 193 | { |
194 | Bu::List<int> lKeys = hTest.getKeys(); | 194 | Bu::List<int> lKeys = hTest.getKeys(); |
195 | int iIdx = (int)(((double)random()/(double)RAND_MAX) | 195 | int iIdx = (int)(((double)random()/(double)RAND_MAX) |
196 | *lKeys.getSize()); | 196 | *lKeys.getSize()); |
197 | Bu::List<int>::const_iterator it = lKeys.begin(); | 197 | Bu::List<int>::const_iterator it = lKeys.begin(); |
198 | for( int k=0; it; ++it, ++k ) | 198 | for( int k=0; it; ++it, ++k ) |
199 | { | 199 | { |
200 | if( k == iIdx ) | 200 | if( k == iIdx ) |
201 | { | 201 | { |
202 | hReUse.insert(*it,"yo"); | 202 | hReUse.insert(*it,"yo"); |
203 | hTest.erase( *it ); | 203 | hTest.erase( *it ); |
204 | break; | 204 | break; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } | 209 | } |
210 | } | 210 | } |
211 | } | 211 | } |
diff --git a/src/unit/list.unit b/src/unit/list.unit index ec92fd5..0b60e43 100644 --- a/src/unit/list.unit +++ b/src/unit/list.unit | |||
@@ -13,136 +13,136 @@ typedef Bu::List<int> IntList; | |||
13 | 13 | ||
14 | suite List | 14 | suite List |
15 | { | 15 | { |
16 | test append | 16 | test append |
17 | { | 17 | { |
18 | IntList lst; | 18 | IntList lst; |
19 | for( int j = 0; j < 50; j++ ) | 19 | for( int j = 0; j < 50; j++ ) |
20 | { | 20 | { |
21 | lst.append( j ); | 21 | lst.append( j ); |
22 | } | 22 | } |
23 | int j = 0; | 23 | int j = 0; |
24 | for( IntList::iterator i = lst.begin(); i; i++, j++ ) | 24 | for( IntList::iterator i = lst.begin(); i; i++, j++ ) |
25 | { | 25 | { |
26 | unitTest( *i == j ); | 26 | unitTest( *i == j ); |
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | test prepend | 30 | test prepend |
31 | { | 31 | { |
32 | IntList lst; | 32 | IntList lst; |
33 | for( int j = 0; j < 50; j++ ) | 33 | for( int j = 0; j < 50; j++ ) |
34 | { | 34 | { |
35 | lst.prepend( j ); | 35 | lst.prepend( j ); |
36 | } | 36 | } |
37 | int j = 49; | 37 | int j = 49; |
38 | for( IntList::iterator i = lst.begin(); i; i++, j-- ) | 38 | for( IntList::iterator i = lst.begin(); i; i++, j-- ) |
39 | { | 39 | { |
40 | unitTest( *i == j ); | 40 | unitTest( *i == j ); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | test copy | 44 | test copy |
45 | { | 45 | { |
46 | IntList lst; | 46 | IntList lst; |
47 | int j; | 47 | int j; |
48 | for( j = 0; j < 50; j++ ) | 48 | for( j = 0; j < 50; j++ ) |
49 | { | 49 | { |
50 | lst.append( j ); | 50 | lst.append( j ); |
51 | } | 51 | } |
52 | IntList lst2 = lst; | 52 | IntList lst2 = lst; |
53 | 53 | ||
54 | j = 0; | 54 | j = 0; |
55 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) | 55 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) |
56 | { | 56 | { |
57 | unitTest( *i == j ); | 57 | unitTest( *i == j ); |
58 | } | 58 | } |
59 | lst2.clear(); | 59 | lst2.clear(); |
60 | lst2 = lst; | 60 | lst2 = lst; |
61 | 61 | ||
62 | j = 0; | 62 | j = 0; |
63 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) | 63 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) |
64 | { | 64 | { |
65 | unitTest( *i == j ); | 65 | unitTest( *i == j ); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | test sort1 | 69 | test sort1 |
70 | { | 70 | { |
71 | IntList lst; | 71 | IntList lst; |
72 | 72 | ||
73 | lst.insertSorted( 5 ); | 73 | lst.insertSorted( 5 ); |
74 | lst.insertSorted( 1 ); | 74 | lst.insertSorted( 1 ); |
75 | lst.insertSorted( 10 ); | 75 | lst.insertSorted( 10 ); |
76 | lst.insertSorted( 3 ); | 76 | lst.insertSorted( 3 ); |
77 | 77 | ||
78 | unitTest( lst == IntList(1).append(3).append(5).append(10) ); | 78 | unitTest( lst == IntList(1).append(3).append(5).append(10) ); |
79 | } | 79 | } |
80 | 80 | ||
81 | test 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 | test 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 | test 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 | test 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 | test 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/md5.unit b/src/unit/md5.unit index 248aaaf..aaba113 100644 --- a/src/unit/md5.unit +++ b/src/unit/md5.unit | |||
@@ -12,71 +12,71 @@ | |||
12 | 12 | ||
13 | suite Md5 | 13 | suite Md5 |
14 | { | 14 | { |
15 | test basics | 15 | test basics |
16 | { | 16 | { |
17 | #define tryStr( a, b ) \ | 17 | #define tryStr( a, b ) \ |
18 | { Bu::Md5 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 | 18 | { Bu::Md5 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 |
19 | tryStr("", "d41d8cd98f00b204e9800998ecf8427e"); | 19 | tryStr("", "d41d8cd98f00b204e9800998ecf8427e"); |
20 | tryStr("a", "0cc175b9c0f1b6a831c399e269772661"); | 20 | tryStr("a", "0cc175b9c0f1b6a831c399e269772661"); |
21 | tryStr("abc", "900150983cd24fb0d6963f7d28e17f72"); | 21 | tryStr("abc", "900150983cd24fb0d6963f7d28e17f72"); |
22 | tryStr("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); | 22 | tryStr("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); |
23 | tryStr("abcdefghijklmnopqrstuvwxyz", | 23 | tryStr("abcdefghijklmnopqrstuvwxyz", |
24 | "c3fcd3d76192e4007dfb496cca67e13b"); | 24 | "c3fcd3d76192e4007dfb496cca67e13b"); |
25 | tryStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | 25 | tryStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", |
26 | "d174ab98d277d9f5a5611c2c9f419d9f"); | 26 | "d174ab98d277d9f5a5611c2c9f419d9f"); |
27 | tryStr("12345678901234567890123456789012345" | 27 | tryStr("12345678901234567890123456789012345" |
28 | "678901234567890123456789012345678901234567890", | 28 | "678901234567890123456789012345678901234567890", |
29 | "57edf4a22be3c955ac49da2e2107b67a"); | 29 | "57edf4a22be3c955ac49da2e2107b67a"); |
30 | } | 30 | } |
31 | 31 | ||
32 | test twoChunks | 32 | test twoChunks |
33 | { | 33 | { |
34 | Bu::Md5 m; | 34 | Bu::Md5 m; |
35 | m.addData("12345678901234567890123456789012345"); | 35 | m.addData("12345678901234567890123456789012345"); |
36 | m.addData("678901234567890123456789012345678901234567890"); | 36 | m.addData("678901234567890123456789012345678901234567890"); |
37 | unitTest( m.getHexResult() == "57edf4a22be3c955ac49da2e2107b67a" ); | 37 | unitTest( m.getHexResult() == "57edf4a22be3c955ac49da2e2107b67a" ); |
38 | } | 38 | } |
39 | 39 | ||
40 | test biggerBlocks | 40 | test biggerBlocks |
41 | { | 41 | { |
42 | const char *sums[33] = { | 42 | const char *sums[33] = { |
43 | "75fcf199abe516903321095a588b938d", | 43 | "75fcf199abe516903321095a588b938d", |
44 | "e26a863c96d6bdba6601175aedaae108", | 44 | "e26a863c96d6bdba6601175aedaae108", |
45 | "2b207fdcb222078d3ebfeb8d5e7c9315", | 45 | "2b207fdcb222078d3ebfeb8d5e7c9315", |
46 | "b08683aaa465add72cc2b43ae42f4f70", | 46 | "b08683aaa465add72cc2b43ae42f4f70", |
47 | "638bb73963b2d925771c3579ccb5e879", | 47 | "638bb73963b2d925771c3579ccb5e879", |
48 | "c727bd4b48a88e3df5924a2604de0790", | 48 | "c727bd4b48a88e3df5924a2604de0790", |
49 | "f33d21203c80490f7342e5853c5550eb", | 49 | "f33d21203c80490f7342e5853c5550eb", |
50 | "db449faca66a177aae59b1e36a19d053", | 50 | "db449faca66a177aae59b1e36a19d053", |
51 | "c800d429afb5f5c820f75c2c94e2e2bb", | 51 | "c800d429afb5f5c820f75c2c94e2e2bb", |
52 | "43b79c70b9a6a11e823ffbfa0f45a4db", | 52 | "43b79c70b9a6a11e823ffbfa0f45a4db", |
53 | "0177ffc483cf598ae3966b3a5ae00c8c", | 53 | "0177ffc483cf598ae3966b3a5ae00c8c", |
54 | "1a68fdf4b17a3820d48d101e9355a818" | 54 | "1a68fdf4b17a3820d48d101e9355a818" |
55 | }; | 55 | }; |
56 | 56 | ||
57 | char block[128]; | 57 | char block[128]; |
58 | for( int i = 0; i < 128; i++ ) | 58 | for( int i = 0; i < 128; i++ ) |
59 | block[i] = i*2; | 59 | block[i] = i*2; |
60 | 60 | ||
61 | const char **curSum = sums; | 61 | const char **curSum = sums; |
62 | for( int j = 1; j < 4096; j*=2 ) | 62 | for( int j = 1; j < 4096; j*=2 ) |
63 | { | 63 | { |
64 | /* | 64 | /* |
65 | Bu::File fOut("temp", Bu::File::WriteNew ); | 65 | Bu::File fOut("temp", Bu::File::WriteNew ); |
66 | for( int b = 0; b < j; b++ ) | 66 | for( int b = 0; b < j; b++ ) |
67 | { | 67 | { |
68 | fOut.write( block, 128 ); | 68 | fOut.write( block, 128 ); |
69 | } | 69 | } |
70 | fOut.close(); | 70 | fOut.close(); |
71 | system("md5sum -b temp"); | 71 | system("md5sum -b temp"); |
72 | */ | 72 | */ |
73 | Bu::Md5 m; | 73 | Bu::Md5 m; |
74 | for( int b = 0; b < j; b++ ) | 74 | for( int b = 0; b < j; b++ ) |
75 | { | 75 | { |
76 | m.addData( block, 128 ); | 76 | m.addData( block, 128 ); |
77 | } | 77 | } |
78 | unitTest( m.getHexResult() == *curSum ); | 78 | unitTest( m.getHexResult() == *curSum ); |
79 | curSum++; | 79 | curSum++; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit index 37ea77e..e5ee073 100644 --- a/src/unit/membuf.unit +++ b/src/unit/membuf.unit | |||
@@ -10,37 +10,37 @@ | |||
10 | 10 | ||
11 | suite MemBuf | 11 | suite MemBuf |
12 | { | 12 | { |
13 | test testWriteRead01 | 13 | test testWriteRead01 |
14 | { | 14 | { |
15 | Bu::MemBuf mb; | 15 | Bu::MemBuf mb; |
16 | unitTest( mb.write("ab", 2 ) == 2 ); | 16 | unitTest( mb.write("ab", 2 ) == 2 ); |
17 | unitTest( mb.write("cde", 3 ) == 3 ); | 17 | unitTest( mb.write("cde", 3 ) == 3 ); |
18 | unitTest( mb.write("FG", 2 ) == 2 ); | 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 | test 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 | } | 46 | } |
diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit index 8c96f79..4960f38 100644 --- a/src/unit/myriad.unit +++ b/src/unit/myriad.unit | |||
@@ -26,360 +26,360 @@ class VerifyObject | |||
26 | friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ); | 26 | friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ); |
27 | friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ); | 27 | friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ); |
28 | public: | 28 | public: |
29 | VerifyObject( int iUnits ) : | 29 | VerifyObject( int iUnits ) : |
30 | iUnits( iUnits ), | 30 | iUnits( iUnits ), |
31 | iBytesWritten( 0 ) | 31 | iBytesWritten( 0 ) |
32 | { | 32 | { |
33 | } | 33 | } |
34 | 34 | ||
35 | virtual ~VerifyObject() | 35 | virtual ~VerifyObject() |
36 | { | 36 | { |
37 | } | 37 | } |
38 | 38 | ||
39 | int getBytesWritten() | 39 | int getBytesWritten() |
40 | { | 40 | { |
41 | return iBytesWritten; | 41 | return iBytesWritten; |
42 | } | 42 | } |
43 | 43 | ||
44 | private: | 44 | private: |
45 | int iUnits; | 45 | int iUnits; |
46 | mutable int iBytesWritten; | 46 | mutable int iBytesWritten; |
47 | }; | 47 | }; |
48 | 48 | ||
49 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ) | 49 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ) |
50 | { | 50 | { |
51 | Md5 sum; | 51 | Md5 sum; |
52 | ar << vo.iUnits; | 52 | ar << vo.iUnits; |
53 | vo.iBytesWritten = 4; | 53 | vo.iBytesWritten = 4; |
54 | sum.addData( &vo.iUnits, 4 ); | 54 | sum.addData( &vo.iUnits, 4 ); |
55 | for( int j = 0; j < vo.iUnits; j++ ) | 55 | for( int j = 0; j < vo.iUnits; j++ ) |
56 | { | 56 | { |
57 | int iRand = random()%128; | 57 | int iRand = random()%128; |
58 | // ar << iRand; | 58 | // ar << iRand; |
59 | Bu::String sDat( iRand ); | 59 | Bu::String sDat( iRand ); |
60 | for( int j = 0; j < iRand; j++ ) | 60 | for( int j = 0; j < iRand; j++ ) |
61 | sDat[j] = (char)((uint8_t)(random()%256)); | 61 | sDat[j] = (char)((uint8_t)(random()%256)); |
62 | ar << sDat; | 62 | ar << sDat; |
63 | sum.addData( &iRand, 4 ); | 63 | sum.addData( &iRand, 4 ); |
64 | sum.addData( sDat.getStr(), iRand ); | 64 | sum.addData( sDat.getStr(), iRand ); |
65 | vo.iBytesWritten += 4 + iRand; | 65 | vo.iBytesWritten += 4 + iRand; |
66 | } | 66 | } |
67 | Bu::String sRes = sum.getResult(); | 67 | Bu::String sRes = sum.getResult(); |
68 | ar << sRes; | 68 | ar << sRes; |
69 | vo.iBytesWritten += 4 + sRes.getSize(); | 69 | vo.iBytesWritten += 4 + sRes.getSize(); |
70 | return ar; | 70 | return ar; |
71 | } | 71 | } |
72 | 72 | ||
73 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ) | 73 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ) |
74 | { | 74 | { |
75 | Md5 sum; | 75 | Md5 sum; |
76 | ar >> vo.iUnits; | 76 | ar >> vo.iUnits; |
77 | sum.addData( &vo.iUnits, 4 ); | 77 | sum.addData( &vo.iUnits, 4 ); |
78 | for( int j = 0; j < vo.iUnits; j++ ) | 78 | for( int j = 0; j < vo.iUnits; j++ ) |
79 | { | 79 | { |
80 | int iRand; | 80 | int iRand; |
81 | // ar >> iRand; | 81 | // ar >> iRand; |
82 | Bu::String sStr; | 82 | Bu::String sStr; |
83 | ar >> sStr; | 83 | ar >> sStr; |
84 | iRand = sStr.getSize(); | 84 | iRand = sStr.getSize(); |
85 | sum.addData( &iRand, 4 ); | 85 | sum.addData( &iRand, 4 ); |
86 | sum.addData( sStr.getStr(), iRand ); | 86 | sum.addData( sStr.getStr(), iRand ); |
87 | } | 87 | } |
88 | Bu::String sSum; | 88 | Bu::String sSum; |
89 | ar >> sSum; | 89 | ar >> sSum; |
90 | unitTest( sSum == sum.getResult() ); | 90 | unitTest( sSum == sum.getResult() ); |
91 | int iTooMuch; | 91 | int iTooMuch; |
92 | try | 92 | try |
93 | { | 93 | { |
94 | ar >> iTooMuch; | 94 | ar >> iTooMuch; |
95 | unitFailed("should have thrown an exception."); | 95 | unitFailed("should have thrown an exception."); |
96 | } | 96 | } |
97 | catch( Bu::ExceptionBase &e ) | 97 | catch( Bu::ExceptionBase &e ) |
98 | { | 98 | { |
99 | } | 99 | } |
100 | return ar; | 100 | return ar; |
101 | } | 101 | } |
102 | 102 | ||
103 | suite Myriad | 103 | suite Myriad |
104 | { | 104 | { |
105 | test setSize | 105 | test setSize |
106 | { | 106 | { |
107 | String sFileName("myriad-XXXXXXX"); | 107 | String sFileName("myriad-XXXXXXX"); |
108 | 108 | ||
109 | File fMyriad = tempFile( sFileName ); | 109 | File fMyriad = tempFile( sFileName ); |
110 | Myriad m( fMyriad, 32 ); | 110 | Myriad m( fMyriad, 32 ); |
111 | 111 | ||
112 | MyriadStream ms = m.openStream( m.createStream() ); | 112 | MyriadStream ms = m.openStream( m.createStream() ); |
113 | ms.setSize( 150 ); | 113 | ms.setSize( 150 ); |
114 | ms.setPos( 145 ); | 114 | ms.setPos( 145 ); |
115 | char stuff[10]; | 115 | char stuff[10]; |
116 | unitTest( ms.read( stuff, 10 ) == 5 ); | 116 | unitTest( ms.read( stuff, 10 ) == 5 ); |
117 | 117 | ||
118 | ms.setSize( 12 ); | 118 | ms.setSize( 12 ); |
119 | unitTest( ms.read( stuff, 10 ) == 0 ); | 119 | unitTest( ms.read( stuff, 10 ) == 0 ); |
120 | unitTest( ms.write( "hello", 5 ) == 5 ); | 120 | unitTest( ms.write( "hello", 5 ) == 5 ); |
121 | unitTest( ms.tell() == 17 ); | 121 | unitTest( ms.tell() == 17 ); |
122 | 122 | ||
123 | ms.setSize( 500 ); | 123 | ms.setSize( 500 ); |
124 | unitTest( ms.tell() == 17 ); | 124 | unitTest( ms.tell() == 17 ); |
125 | } | 125 | } |
126 | 126 | ||
127 | void addBlock( Stream &s, bool bAppend=true ) | 127 | void addBlock( Stream &s, bool bAppend=true ) |
128 | { | 128 | { |
129 | if( bAppend ) | 129 | if( bAppend ) |
130 | s.setPosEnd( 0 ); | 130 | s.setPosEnd( 0 ); |
131 | int iSize = (random()%1016)+8; | 131 | int iSize = (random()%1016)+8; |
132 | s.write( &iSize, 4 ); | 132 | s.write( &iSize, 4 ); |
133 | char *buf = new char[iSize-8]; | 133 | char *buf = new char[iSize-8]; |
134 | for( int j = 0; j < iSize-8; j++ ) | 134 | for( int j = 0; j < iSize-8; j++ ) |
135 | { | 135 | { |
136 | buf[j] = (j+iSize)%256; | 136 | buf[j] = (j+iSize)%256; |
137 | } | 137 | } |
138 | if( random()%2 == 0 ) | 138 | if( random()%2 == 0 ) |
139 | { | 139 | { |
140 | s.write( buf, iSize-8 ); | 140 | s.write( buf, iSize-8 ); |
141 | } | 141 | } |
142 | else | 142 | else |
143 | { | 143 | { |
144 | for( int j = 0; j < iSize-8; ) | 144 | for( int j = 0; j < iSize-8; ) |
145 | { | 145 | { |
146 | int iAmnt = (random()%8)+1; | 146 | int iAmnt = (random()%8)+1; |
147 | if( iAmnt+j > iSize-8 ) | 147 | if( iAmnt+j > iSize-8 ) |
148 | iAmnt = iSize-8-j; | 148 | iAmnt = iSize-8-j; |
149 | iAmnt = s.write( buf+j, iAmnt ); | 149 | iAmnt = s.write( buf+j, iAmnt ); |
150 | j += iAmnt; | 150 | j += iAmnt; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | delete[] buf; | 153 | delete[] buf; |
154 | iSize = ~iSize; | 154 | iSize = ~iSize; |
155 | s.write( &iSize, 4 ); | 155 | s.write( &iSize, 4 ); |
156 | } | 156 | } |
157 | 157 | ||
158 | void verifyBlock( Stream &s ) | 158 | void verifyBlock( Stream &s ) |
159 | { | 159 | { |
160 | int iSize, iInv; | 160 | int iSize, iInv; |
161 | if( s.read( &iSize, 4 ) == 0 ) | 161 | if( s.read( &iSize, 4 ) == 0 ) |
162 | return; | 162 | return; |
163 | if( iSize < 8 || iSize > 1024 ) | 163 | if( iSize < 8 || iSize > 1024 ) |
164 | throw ExceptionBase("Read bad data, %d", iSize ); | 164 | throw ExceptionBase("Read bad data, %d", iSize ); |
165 | char *buf = new char[iSize-8]; | 165 | char *buf = new char[iSize-8]; |
166 | if( s.read( buf, iSize-8 ) < (size_t)iSize-8 ) | 166 | if( s.read( buf, iSize-8 ) < (size_t)iSize-8 ) |
167 | { | 167 | { |
168 | delete[] buf; | 168 | delete[] buf; |
169 | throw ExceptionBase("Block failed verify (insuffient block data)."); | 169 | throw ExceptionBase("Block failed verify (insuffient block data)."); |
170 | } | 170 | } |
171 | for( int j = 0; j < iSize-8; j++ ) | 171 | for( int j = 0; j < iSize-8; j++ ) |
172 | { | 172 | { |
173 | if( buf[j] != (char)((j+iSize)%256) ) | 173 | if( buf[j] != (char)((j+iSize)%256) ) |
174 | { | 174 | { |
175 | char b = buf[j]; | 175 | char b = buf[j]; |
176 | delete[] buf; | 176 | delete[] buf; |
177 | throw ExceptionBase("Block failed computed data verify " | 177 | throw ExceptionBase("Block failed computed data verify " |
178 | "(%02X==%02X).", b, (char)((j+iSize)%256) ); | 178 | "(%02X==%02X).", b, (char)((j+iSize)%256) ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | delete[] buf; | 181 | delete[] buf; |
182 | if( s.read( &iInv, 4 ) < 4 ) | 182 | if( s.read( &iInv, 4 ) < 4 ) |
183 | throw ExceptionBase("Block failed verify (insufficient data)."); | 183 | throw ExceptionBase("Block failed verify (insufficient data)."); |
184 | if( iInv != ~iSize ) | 184 | if( iInv != ~iSize ) |
185 | throw ExceptionBase("Block failed inversion verify."); | 185 | throw ExceptionBase("Block failed inversion verify."); |
186 | } | 186 | } |
187 | 187 | ||
188 | void verifyStream( Stream &s ) | 188 | void verifyStream( Stream &s ) |
189 | { | 189 | { |
190 | s.setPos( 0 ); | 190 | s.setPos( 0 ); |
191 | while( !s.isEos() ) | 191 | while( !s.isEos() ) |
192 | verifyBlock( s ); | 192 | verifyBlock( s ); |
193 | } | 193 | } |
194 | 194 | ||
195 | test stressGrow | 195 | test stressGrow |
196 | { | 196 | { |
197 | String sFileName("myriad-XXXXXXX"); | 197 | String sFileName("myriad-XXXXXXX"); |
198 | 198 | ||
199 | File fMyriad = tempFile( sFileName ); | 199 | File fMyriad = tempFile( sFileName ); |
200 | Myriad m( fMyriad ); | 200 | Myriad m( fMyriad ); |
201 | m.initialize( 64 ); | 201 | m.initialize( 64 ); |
202 | 202 | ||
203 | Array<int> aStreams; | 203 | Array<int> aStreams; |
204 | for( int j = 0; j < 5; j++ ) | 204 | for( int j = 0; j < 5; j++ ) |
205 | { | 205 | { |
206 | aStreams.append( m.createStream() ); | 206 | aStreams.append( m.createStream() ); |
207 | } | 207 | } |
208 | 208 | ||
209 | srandom( 512 ); | 209 | srandom( 512 ); |
210 | 210 | ||
211 | for( int j = 0; j < 2500; j++ ) | 211 | for( int j = 0; j < 2500; j++ ) |
212 | { | 212 | { |
213 | switch( random()%5 ) | 213 | switch( random()%5 ) |
214 | { | 214 | { |
215 | case 0: | 215 | case 0: |
216 | aStreams.append( m.createStream() ); | 216 | aStreams.append( m.createStream() ); |
217 | break; | 217 | break; |
218 | 218 | ||
219 | case 1: | 219 | case 1: |
220 | if( aStreams.getSize() > 0 ) | 220 | if( aStreams.getSize() > 0 ) |
221 | { | 221 | { |
222 | int iStream = random()%aStreams.getSize(); | 222 | int iStream = random()%aStreams.getSize(); |
223 | { | 223 | { |
224 | MyriadStream ms = m.openStream( aStreams[iStream] ); | 224 | MyriadStream ms = m.openStream( aStreams[iStream] ); |
225 | verifyStream( ms ); | 225 | verifyStream( ms ); |
226 | } | 226 | } |
227 | m.deleteStream( aStreams[iStream] ); | 227 | m.deleteStream( aStreams[iStream] ); |
228 | Array<int>::iterator i = aStreams.begin(); | 228 | Array<int>::iterator i = aStreams.begin(); |
229 | for( int k = 0; k < iStream; k++ ) | 229 | for( int k = 0; k < iStream; k++ ) |
230 | i++; | 230 | i++; |
231 | aStreams.erase( i ); | 231 | aStreams.erase( i ); |
232 | } | 232 | } |
233 | break; | 233 | break; |
234 | 234 | ||
235 | default: | 235 | default: |
236 | if( aStreams.getSize() == 0 ) | 236 | if( aStreams.getSize() == 0 ) |
237 | { | 237 | { |
238 | aStreams.append( m.createStream() ); | 238 | aStreams.append( m.createStream() ); |
239 | } | 239 | } |
240 | { | 240 | { |
241 | int iStream = random()%aStreams.getSize(); | 241 | int iStream = random()%aStreams.getSize(); |
242 | MyriadStream ms = m.openStream( aStreams[iStream] ); | 242 | MyriadStream ms = m.openStream( aStreams[iStream] ); |
243 | addBlock( ms ); | 243 | addBlock( ms ); |
244 | verifyStream( ms ); | 244 | verifyStream( ms ); |
245 | } | 245 | } |
246 | break; | 246 | break; |
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ||
250 | for( Array<int>::iterator i = aStreams.begin(); i; i++ ) | 250 | for( Array<int>::iterator i = aStreams.begin(); i; i++ ) |
251 | { | 251 | { |
252 | MyriadStream ms = m.openStream( *i ); | 252 | MyriadStream ms = m.openStream( *i ); |
253 | verifyStream( ms ); | 253 | verifyStream( ms ); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | test stressTruncate | 257 | test stressTruncate |
258 | { | 258 | { |
259 | String sFileName("myriad-XXXXXXX"); | 259 | String sFileName("myriad-XXXXXXX"); |
260 | 260 | ||
261 | File fMyriad = tempFile( sFileName ); | 261 | File fMyriad = tempFile( sFileName ); |
262 | Myriad m( fMyriad ); | 262 | Myriad m( fMyriad ); |
263 | m.initialize( 128 ); | 263 | m.initialize( 128 ); |
264 | 264 | ||
265 | Array<int> aStream; | 265 | Array<int> aStream; |
266 | 266 | ||
267 | for( int j = 0; j < 5; j++ ) | 267 | for( int j = 0; j < 5; j++ ) |
268 | { | 268 | { |
269 | aStream.append( m.createStream() ); | 269 | aStream.append( m.createStream() ); |
270 | } | 270 | } |
271 | 271 | ||
272 | srandom( 1024 ); | 272 | srandom( 1024 ); |
273 | 273 | ||
274 | char b; | 274 | char b; |
275 | for( int iter = 0; iter < 2500; iter++ ) | 275 | for( int iter = 0; iter < 2500; iter++ ) |
276 | { | 276 | { |
277 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | 277 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) |
278 | { | 278 | { |
279 | MyriadStream ms = m.openStream( *i ); | 279 | MyriadStream ms = m.openStream( *i ); |
280 | addBlock( ms, false ); | 280 | addBlock( ms, false ); |
281 | ms.setSize( ms.tell() ); | 281 | ms.setSize( ms.tell() ); |
282 | unitTest( ms.read( &b, 1 ) == 0 ); | 282 | unitTest( ms.read( &b, 1 ) == 0 ); |
283 | ms.setPos( 0 ); | 283 | ms.setPos( 0 ); |
284 | verifyBlock( ms ); | 284 | verifyBlock( ms ); |
285 | unitTest( ms.read( &b, 1 ) == 0 ); | 285 | unitTest( ms.read( &b, 1 ) == 0 ); |
286 | } | 286 | } |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | test stressTruncate2 | 290 | test stressTruncate2 |
291 | { | 291 | { |
292 | String sFileName("myriad-XXXXXXX"); | 292 | String sFileName("myriad-XXXXXXX"); |
293 | 293 | ||
294 | Array<int> aStream; | 294 | Array<int> aStream; |
295 | 295 | ||
296 | setStepCount( 5*2500 + 5 ); | 296 | setStepCount( 5*2500 + 5 ); |
297 | 297 | ||
298 | { | 298 | { |
299 | File fMyriad = tempFile( sFileName ); | 299 | File fMyriad = tempFile( sFileName ); |
300 | Myriad m( fMyriad, 128 ); | 300 | Myriad m( fMyriad, 128 ); |
301 | 301 | ||
302 | for( int j = 0; j < 5; j++ ) | 302 | for( int j = 0; j < 5; j++ ) |
303 | { | 303 | { |
304 | aStream.append( m.createStream() ); | 304 | aStream.append( m.createStream() ); |
305 | incProgress(); | 305 | incProgress(); |
306 | } | 306 | } |
307 | } | 307 | } |
308 | 308 | ||
309 | srandom( 1024 ); | 309 | srandom( 1024 ); |
310 | 310 | ||
311 | char b; | 311 | char b; |
312 | for( int iter = 0; iter < 2500; iter++ ) | 312 | for( int iter = 0; iter < 2500; iter++ ) |
313 | { | 313 | { |
314 | File fMyriad( sFileName, File::ReadWrite ); | 314 | File fMyriad( sFileName, File::ReadWrite ); |
315 | Myriad m( fMyriad ); | 315 | Myriad m( fMyriad ); |
316 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | 316 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) |
317 | { | 317 | { |
318 | MyriadStream ms = m.openStream( *i ); | 318 | MyriadStream ms = m.openStream( *i ); |
319 | addBlock( ms, false ); | 319 | addBlock( ms, false ); |
320 | ms.setSize( ms.tell() ); | 320 | ms.setSize( ms.tell() ); |
321 | unitTest( ms.read( &b, 1 ) == 0 ); | 321 | unitTest( ms.read( &b, 1 ) == 0 ); |
322 | ms.setPos( 0 ); | 322 | ms.setPos( 0 ); |
323 | verifyBlock( ms ); | 323 | verifyBlock( ms ); |
324 | unitTest( ms.read( &b, 1 ) == 0 ); | 324 | unitTest( ms.read( &b, 1 ) == 0 ); |
325 | incProgress(); | 325 | incProgress(); |
326 | } | 326 | } |
327 | } | 327 | } |
328 | } | 328 | } |
329 | 329 | ||
330 | test stressArchive | 330 | test stressArchive |
331 | { | 331 | { |
332 | String sFileName("myriad-XXXXXX"); | 332 | String sFileName("myriad-XXXXXX"); |
333 | Array<int> aStream; | 333 | Array<int> aStream; |
334 | 334 | ||
335 | srandom( 2096 ); | 335 | srandom( 2096 ); |
336 | 336 | ||
337 | setStepCount( 15*250 + 15 ); | 337 | setStepCount( 15*250 + 15 ); |
338 | 338 | ||
339 | { | 339 | { |
340 | File fMyriad = tempFile( sFileName ); | 340 | File fMyriad = tempFile( sFileName ); |
341 | Myriad m( fMyriad, 1024 ); | 341 | Myriad m( fMyriad, 1024 ); |
342 | 342 | ||
343 | for( int j = 0; j < 15; j++ ) | 343 | for( int j = 0; j < 15; j++ ) |
344 | { | 344 | { |
345 | int iStream = m.createStream(); | 345 | int iStream = m.createStream(); |
346 | aStream.append( iStream ); | 346 | aStream.append( iStream ); |
347 | VerifyObject vo( random()%1024 ); | 347 | VerifyObject vo( random()%1024 ); |
348 | { | 348 | { |
349 | MyriadStream ms = m.openStream( iStream ); | 349 | MyriadStream ms = m.openStream( iStream ); |
350 | Archive ar( ms, Archive::save ); | 350 | Archive ar( ms, Archive::save ); |
351 | ar << vo; | 351 | ar << vo; |
352 | unitTest( ms.tell() == vo.getBytesWritten() ); | 352 | unitTest( ms.tell() == vo.getBytesWritten() ); |
353 | ms.setSize( ms.tell() ); | 353 | ms.setSize( ms.tell() ); |
354 | } | 354 | } |
355 | unitTest( m.getStreamSize( iStream ) == vo.getBytesWritten() ); | 355 | unitTest( m.getStreamSize( iStream ) == vo.getBytesWritten() ); |
356 | incProgress(); | 356 | incProgress(); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | for( int iter = 0; iter < 250; iter++ ) | 360 | for( int iter = 0; iter < 250; iter++ ) |
361 | { | 361 | { |
362 | File fMyriad( sFileName, File::ReadWrite ); | 362 | File fMyriad( sFileName, File::ReadWrite ); |
363 | Myriad m( fMyriad ); | 363 | Myriad m( fMyriad ); |
364 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | 364 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) |
365 | { | 365 | { |
366 | VerifyObject vo( random()%1024 ); | 366 | VerifyObject vo( random()%1024 ); |
367 | { | 367 | { |
368 | MyriadStream ms = m.openStream( *i ); | 368 | MyriadStream ms = m.openStream( *i ); |
369 | Archive ar( ms, Archive::load ); | 369 | Archive ar( ms, Archive::load ); |
370 | ar >> vo; | 370 | ar >> vo; |
371 | } | 371 | } |
372 | { | 372 | { |
373 | MyriadStream ms = m.openStream( *i ); | 373 | MyriadStream ms = m.openStream( *i ); |
374 | Archive ar( ms, Archive::save ); | 374 | Archive ar( ms, Archive::save ); |
375 | ar << vo; | 375 | ar << vo; |
376 | unitTest( ms.tell() == vo.getBytesWritten() ); | 376 | unitTest( ms.tell() == vo.getBytesWritten() ); |
377 | ms.setSize( ms.tell() ); | 377 | ms.setSize( ms.tell() ); |
378 | } | 378 | } |
379 | unitTest( m.getStreamSize( *i ) == vo.getBytesWritten() ); | 379 | unitTest( m.getStreamSize( *i ) == vo.getBytesWritten() ); |
380 | incProgress(); | 380 | incProgress(); |
381 | } | 381 | } |
382 | } | 382 | } |
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit index 553d9fc..bc55a04 100644 --- a/src/unit/queuebuf.unit +++ b/src/unit/queuebuf.unit | |||
@@ -16,89 +16,89 @@ | |||
16 | 16 | ||
17 | suite QueueBuf | 17 | suite QueueBuf |
18 | { | 18 | { |
19 | test testBasic01 | 19 | test testBasic01 |
20 | { | 20 | { |
21 | Bu::QueueBuf qb; | 21 | Bu::QueueBuf qb; |
22 | unitTest( qb.write("ab", 2 ) == 2 ); | 22 | unitTest( qb.write("ab", 2 ) == 2 ); |
23 | unitTest( qb.write("cde", 3 ) == 3 ); | 23 | unitTest( qb.write("cde", 3 ) == 3 ); |
24 | unitTest( qb.write("FG", 2 ) == 2 ); | 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 | ||
33 | void QBUF_RANDSTR( Bu::String &fill, unsigned int iSize ) | 33 | void QBUF_RANDSTR( Bu::String &fill, unsigned int iSize ) |
34 | { | 34 | { |
35 | char c; | 35 | char c; |
36 | for( unsigned int i=0; i<iSize; ++i ) | 36 | for( unsigned int i=0; i<iSize; ++i ) |
37 | { | 37 | { |
38 | c = RNDCHR; | 38 | c = RNDCHR; |
39 | fill.append(&c,1); | 39 | fill.append(&c,1); |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | test testAmounts | 43 | test testAmounts |
44 | { | 44 | { |
45 | srandom(time(NULL)); | 45 | srandom(time(NULL)); |
46 | Bu::QueueBuf qb; | 46 | Bu::QueueBuf qb; |
47 | Bu::String sTmp; | 47 | Bu::String sTmp; |
48 | char buf[4096]; | 48 | char buf[4096]; |
49 | 49 | ||
50 | for( int i=0; i<200; ++i ) | 50 | for( int i=0; i<200; ++i ) |
51 | { | 51 | { |
52 | unsigned int iAmt = (int)RNDCHR+128; | 52 | unsigned int iAmt = (int)RNDCHR+128; |
53 | sTmp.clear(); | 53 | sTmp.clear(); |
54 | QBUF_RANDSTR( sTmp, iAmt ); | 54 | QBUF_RANDSTR( sTmp, iAmt ); |
55 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | 55 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == |
56 | (uint32_t)sTmp.getSize() ); | 56 | (uint32_t)sTmp.getSize() ); |
57 | size_t iRead = qb.read( buf, 4096 ); | 57 | size_t iRead = qb.read( buf, 4096 ); |
58 | unitTest( iRead == iAmt ); | 58 | unitTest( iRead == iAmt ); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | void QBUF_HEXOUT( const char *s, int iSize ) | 62 | void QBUF_HEXOUT( const char *s, int iSize ) |
63 | { | 63 | { |
64 | for( int i=0; i<iSize; ++i ) | 64 | for( int i=0; i<iSize; ++i ) |
65 | printf("%02x",(int)(uint8_t)s[i]); | 65 | printf("%02x",(int)(uint8_t)s[i]); |
66 | } | 66 | } |
67 | 67 | ||
68 | void QBUF_HASH( Bu::String &fill, const char *s, int iSize ) | 68 | void QBUF_HASH( Bu::String &fill, const char *s, int iSize ) |
69 | { | 69 | { |
70 | Bu::Md5 hash; | 70 | Bu::Md5 hash; |
71 | hash.reset(); | 71 | hash.reset(); |
72 | hash.addData( s, iSize ); | 72 | hash.addData( s, iSize ); |
73 | const Bu::String &sTmp = hash.getResult(); | 73 | const Bu::String &sTmp = hash.getResult(); |
74 | fill.append( sTmp.getStr(), 16 ); | 74 | fill.append( sTmp.getStr(), 16 ); |
75 | } | 75 | } |
76 | 76 | ||
77 | test testRandomData | 77 | test testRandomData |
78 | { | 78 | { |
79 | srandom(time(NULL)); | 79 | srandom(time(NULL)); |
80 | Bu::QueueBuf qb; | 80 | Bu::QueueBuf qb; |
81 | Bu::String sTmp; | 81 | Bu::String sTmp; |
82 | Bu::String sTmp2; | 82 | Bu::String sTmp2; |
83 | char buf[4096]; | 83 | char buf[4096]; |
84 | 84 | ||
85 | for( int i=0; i<200; ++i ) | 85 | for( int i=0; i<200; ++i ) |
86 | { | 86 | { |
87 | uint32_t iAmt = (uint32_t)RNDCHR+128; | 87 | uint32_t iAmt = (uint32_t)RNDCHR+128; |
88 | sTmp.clear(); | 88 | sTmp.clear(); |
89 | sTmp.append( (const char *)&iAmt, 4 ); | 89 | sTmp.append( (const char *)&iAmt, 4 ); |
90 | QBUF_RANDSTR( sTmp, iAmt ); | 90 | QBUF_RANDSTR( sTmp, iAmt ); |
91 | sTmp2.clear(); | 91 | sTmp2.clear(); |
92 | QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); | 92 | QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); |
93 | sTmp.append( sTmp2 ); | 93 | sTmp.append( sTmp2 ); |
94 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | 94 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == |
95 | (uint32_t)sTmp.getSize() ); | 95 | (uint32_t)sTmp.getSize() ); |
96 | size_t iRead = qb.read( buf, 4096 ); | 96 | size_t iRead = qb.read( buf, 4096 ); |
97 | uint32_t iGotSize = *((uint32_t *)buf); | 97 | uint32_t iGotSize = *((uint32_t *)buf); |
98 | unitTest( iRead == iGotSize+4+16 ); | 98 | unitTest( iRead == iGotSize+4+16 ); |
99 | sTmp2.clear(); | 99 | sTmp2.clear(); |
100 | QBUF_HASH( sTmp2, buf+4, iGotSize ); | 100 | QBUF_HASH( sTmp2, buf+4, iGotSize ); |
101 | unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); | 101 | unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | } | 104 | } |
diff --git a/src/unit/sha1.unit b/src/unit/sha1.unit index d91b4c3..1151cfb 100644 --- a/src/unit/sha1.unit +++ b/src/unit/sha1.unit | |||
@@ -12,65 +12,65 @@ | |||
12 | 12 | ||
13 | suite Sha1 | 13 | suite Sha1 |
14 | { | 14 | { |
15 | test basics | 15 | test basics |
16 | { | 16 | { |
17 | #define tryStr( a, b ) \ | 17 | #define tryStr( a, b ) \ |
18 | { Bu::Sha1 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 | 18 | { Bu::Sha1 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 |
19 | tryStr("", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); | 19 | tryStr("", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); |
20 | tryStr("The quick brown fox jumps over the lazy dog", | 20 | tryStr("The quick brown fox jumps over the lazy dog", |
21 | "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); | 21 | "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); |
22 | tryStr("The quick brown fox jumps over the lazy cog", | 22 | tryStr("The quick brown fox jumps over the lazy cog", |
23 | "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"); | 23 | "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"); |
24 | } | 24 | } |
25 | 25 | ||
26 | test twoChunks | 26 | test twoChunks |
27 | { | 27 | { |
28 | Bu::Sha1 m; | 28 | Bu::Sha1 m; |
29 | m.addData("The quick brown fo"); | 29 | m.addData("The quick brown fo"); |
30 | m.addData("x jumps over the lazy dog"); | 30 | m.addData("x jumps over the lazy dog"); |
31 | unitTest( m.getHexResult() == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ); | 31 | unitTest( m.getHexResult() == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ); |
32 | } | 32 | } |
33 | 33 | ||
34 | test biggerBlocks | 34 | test biggerBlocks |
35 | { | 35 | { |
36 | const char *sums[41] = { | 36 | const char *sums[41] = { |
37 | "2356aab95478d8e3c2c918e36f383e46d06154c7", | 37 | "2356aab95478d8e3c2c918e36f383e46d06154c7", |
38 | "e3f663240c185a95111c4e00e20865dfbda390aa", | 38 | "e3f663240c185a95111c4e00e20865dfbda390aa", |
39 | "3f21881040b42f44476b610b6d2191f72afc1cb5", | 39 | "3f21881040b42f44476b610b6d2191f72afc1cb5", |
40 | "493fe9da6de598c52ea56962b15ccc4405a8dfda", | 40 | "493fe9da6de598c52ea56962b15ccc4405a8dfda", |
41 | "4684ff568f7c1198a258eb04d88209f4feab4e05", | 41 | "4684ff568f7c1198a258eb04d88209f4feab4e05", |
42 | "614101c1c164b8b6099f63165ea01078cbb6c77f", | 42 | "614101c1c164b8b6099f63165ea01078cbb6c77f", |
43 | "393f1c1a9f6384653029ab807756e85a13147029", | 43 | "393f1c1a9f6384653029ab807756e85a13147029", |
44 | "fd66443d68f8b0508b4f125f2cff1192bfc01913", | 44 | "fd66443d68f8b0508b4f125f2cff1192bfc01913", |
45 | "1ef66120e530731194554bb2cd51293779a0bcc7", | 45 | "1ef66120e530731194554bb2cd51293779a0bcc7", |
46 | "d77e0eda0037f51b0b6c197371c5fd801cc0eede", | 46 | "d77e0eda0037f51b0b6c197371c5fd801cc0eede", |
47 | "ce8b579bd3aa2ccac2e0205f52a8ed03777117ac", | 47 | "ce8b579bd3aa2ccac2e0205f52a8ed03777117ac", |
48 | "d9e9d7fc411de2f89329ab758dc8f4302f80ff23" | 48 | "d9e9d7fc411de2f89329ab758dc8f4302f80ff23" |
49 | }; | 49 | }; |
50 | 50 | ||
51 | char block[128]; | 51 | char block[128]; |
52 | for( int i = 0; i < 128; i++ ) | 52 | for( int i = 0; i < 128; i++ ) |
53 | block[i] = i*2; | 53 | block[i] = i*2; |
54 | 54 | ||
55 | const char **curSum = sums; | 55 | const char **curSum = sums; |
56 | for( int j = 1; j < 4096; j*=2 ) | 56 | for( int j = 1; j < 4096; j*=2 ) |
57 | { | 57 | { |
58 | /* | 58 | /* |
59 | Bu::File fOut("temp", Bu::File::WriteNew ); | 59 | Bu::File fOut("temp", Bu::File::WriteNew ); |
60 | for( int b = 0; b < j; b++ ) | 60 | for( int b = 0; b < j; b++ ) |
61 | { | 61 | { |
62 | fOut.write( block, 128 ); | 62 | fOut.write( block, 128 ); |
63 | } | 63 | } |
64 | fOut.close(); | 64 | fOut.close(); |
65 | system("sha1sum -b temp"); | 65 | system("sha1sum -b temp"); |
66 | */ | 66 | */ |
67 | Bu::Sha1 m; | 67 | Bu::Sha1 m; |
68 | for( int b = 0; b < j; b++ ) | 68 | for( int b = 0; b < j; b++ ) |
69 | { | 69 | { |
70 | m.addData( block, 128 ); | 70 | m.addData( block, 128 ); |
71 | } | 71 | } |
72 | unitTest( m.getHexResult() == *curSum ); | 72 | unitTest( m.getHexResult() == *curSum ); |
73 | curSum++; | 73 | curSum++; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | } | 76 | } |
diff --git a/src/unit/string.unit b/src/unit/string.unit index 4ea878e..ddd89a6 100644 --- a/src/unit/string.unit +++ b/src/unit/string.unit | |||
@@ -12,580 +12,580 @@ | |||
12 | 12 | ||
13 | suite String | 13 | suite String |
14 | { | 14 | { |
15 | test compare1 | 15 | test compare1 |
16 | { | 16 | { |
17 | Bu::String b("Bob"); | 17 | Bu::String b("Bob"); |
18 | unitTest( !(b == "Bobo") ); | 18 | unitTest( !(b == "Bobo") ); |
19 | unitTest( b == "Bob" ); | 19 | unitTest( b == "Bob" ); |
20 | } | 20 | } |
21 | 21 | ||
22 | test compare2 | 22 | test compare2 |
23 | { | 23 | { |
24 | Bu::String b("Bobo"); | 24 | Bu::String b("Bobo"); |
25 | unitTest( !(b == "Bob") ); | 25 | unitTest( !(b == "Bob") ); |
26 | unitTest( b == "Bobo" ); | 26 | unitTest( b == "Bobo" ); |
27 | } | 27 | } |
28 | 28 | ||
29 | test appendSingle | 29 | test appendSingle |
30 | { | 30 | { |
31 | Bu::String b; | 31 | Bu::String 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 | test shared1 | 38 | test shared1 |
39 | { | 39 | { |
40 | Bu::String a("Hey there"); | 40 | Bu::String a("Hey there"); |
41 | Bu::String b( a ); | 41 | Bu::String 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 | test insert | 49 | test insert |
50 | { | 50 | { |
51 | Bu::String a("abcd"); | 51 | Bu::String 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 | test remove | 68 | test remove |
69 | { | 69 | { |
70 | Bu::String a("abHEYcd"); | 70 | Bu::String 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 | test add1 | 80 | test add1 |
81 | { | 81 | { |
82 | Bu::String a("hi there"); | 82 | Bu::String a("hi there"); |
83 | Bu::String b(", yeah!"); | 83 | Bu::String b(", yeah!"); |
84 | Bu::String c = a + b; | 84 | Bu::String c = a + b; |
85 | 85 | ||
86 | unitTest( c == "hi there, yeah!" ); | 86 | unitTest( c == "hi there, yeah!" ); |
87 | } | 87 | } |
88 | 88 | ||
89 | test add2 | 89 | test add2 |
90 | { | 90 | { |
91 | Bu::String a("hi there"); | 91 | Bu::String a("hi there"); |
92 | Bu::String c = a + ", yeah!"; | 92 | Bu::String c = a + ", yeah!"; |
93 | 93 | ||
94 | unitTest( c == "hi there, yeah!" ); | 94 | unitTest( c == "hi there, yeah!" ); |
95 | } | 95 | } |
96 | 96 | ||
97 | test add3 | 97 | test add3 |
98 | { | 98 | { |
99 | Bu::String a("hi there"); | 99 | Bu::String a("hi there"); |
100 | Bu::String b(", yeah!"); | 100 | Bu::String b(", yeah!"); |
101 | Bu::String c = a + ", Mr. Man" + b; | 101 | Bu::String 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 | test add4 | 106 | test add4 |
107 | { | 107 | { |
108 | Bu::String b(", yeah!"); | 108 | Bu::String b(", yeah!"); |
109 | Bu::String c = "hi there" + b; | 109 | Bu::String c = "hi there" + b; |
110 | 110 | ||
111 | unitTest( c == "hi there, yeah!" ); | 111 | unitTest( c == "hi there, yeah!" ); |
112 | } | 112 | } |
113 | 113 | ||
114 | test add5 | 114 | test add5 |
115 | { | 115 | { |
116 | Bu::String b; | 116 | Bu::String b; |
117 | Bu::String c = "sup?"; | 117 | Bu::String 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 | test add6 | 123 | test add6 |
124 | { | 124 | { |
125 | Bu::String a("Hello"); | 125 | Bu::String a("Hello"); |
126 | char b[256] = {"Dude"}; | 126 | char b[256] = {"Dude"}; |
127 | Bu::String c = a + "/" + b; | 127 | Bu::String c = a + "/" + b; |
128 | 128 | ||
129 | unitTest( c == "Hello/Dude" ); | 129 | unitTest( c == "Hello/Dude" ); |
130 | } | 130 | } |
131 | 131 | ||
132 | test add7 | 132 | test add7 |
133 | { | 133 | { |
134 | const Bu::String a("hello "); | 134 | const Bu::String a("hello "); |
135 | Bu::String b(" how "); | 135 | Bu::String 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 | test subStr1 | 141 | test subStr1 |
142 | { | 142 | { |
143 | Bu::String a("abcdefghijklmnop"); | 143 | Bu::String a("abcdefghijklmnop"); |
144 | Bu::String::iterator i = a.find('f'); | 144 | Bu::String::iterator i = a.find('f'); |
145 | unitTest( a.getSubStr( i, Bu::String::iterator() ) == "fghijklmnop" ); | 145 | unitTest( a.getSubStr( i, Bu::String::iterator() ) == "fghijklmnop" ); |
146 | Bu::String::iterator j = i.find('l'); | 146 | Bu::String::iterator j = i.find('l'); |
147 | unitTest( a.getSubStr( i, j ) == "fghijk" ); | 147 | unitTest( a.getSubStr( i, j ) == "fghijk" ); |
148 | } | 148 | } |
149 | 149 | ||
150 | test compareSub1 | 150 | test compareSub1 |
151 | { | 151 | { |
152 | Bu::String a("just a string."); | 152 | Bu::String 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 | test compareSub2 | 158 | test compareSub2 |
159 | { | 159 | { |
160 | Bu::String a("just a string."); | 160 | Bu::String a("just a string."); |
161 | unitTest( a.compareSub(Bu::String("a "), 5, 2) == true ); | 161 | unitTest( a.compareSub(Bu::String("a "), 5, 2) == true ); |
162 | unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 11 ) == false ); | 162 | unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 11 ) == false ); |
163 | unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 3 ) == true ); | 163 | unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 3 ) == true ); |
164 | } | 164 | } |
165 | 165 | ||
166 | test iterator1 | 166 | test iterator1 |
167 | { | 167 | { |
168 | Bu::String a("This is a test."); | 168 | Bu::String a("This is a test."); |
169 | Bu::String b; | 169 | Bu::String b; |
170 | for( Bu::String::iterator i = a.begin(); i; i++ ) | 170 | for( Bu::String::iterator i = a.begin(); i; i++ ) |
171 | { | 171 | { |
172 | b += *i; | 172 | b += *i; |
173 | } | 173 | } |
174 | unitTest( a == b ); | 174 | unitTest( a == b ); |
175 | } | 175 | } |
176 | 176 | ||
177 | test iteratorCompare1 | 177 | test iteratorCompare1 |
178 | { | 178 | { |
179 | Bu::String a("This is a test."); | 179 | Bu::String a("This is a test."); |
180 | Bu::String b("--This is a test."); | 180 | Bu::String b("--This is a test."); |
181 | Bu::String::iterator ai = a.begin(); | 181 | Bu::String::iterator ai = a.begin(); |
182 | Bu::String::iterator bi = b.begin(); | 182 | Bu::String::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 | b += "hi"; | 188 | b += "hi"; |
189 | unitTest( ai.compare( bi ) == false ); | 189 | unitTest( ai.compare( bi ) == false ); |
190 | unitTest( bi.compare( ai ) == false ); | 190 | unitTest( bi.compare( ai ) == false ); |
191 | } | 191 | } |
192 | 192 | ||
193 | test iteratorCompare2 | 193 | test iteratorCompare2 |
194 | { | 194 | { |
195 | Bu::String a("1234honour"); | 195 | Bu::String a("1234honour"); |
196 | Bu::String b("--1234ueje"); | 196 | Bu::String b("--1234ueje"); |
197 | Bu::String::iterator ai = a.begin(); | 197 | Bu::String::iterator ai = a.begin(); |
198 | Bu::String::iterator bi = b.begin(); | 198 | Bu::String::iterator bi = b.begin(); |
199 | unitTest( ai.compare( bi, 4 ) == false ); | 199 | unitTest( ai.compare( bi, 4 ) == false ); |
200 | unitTest( bi.compare( ai, 4 ) == false ); | 200 | unitTest( bi.compare( ai, 4 ) == false ); |
201 | bi++; bi++; | 201 | bi++; bi++; |
202 | unitTest( ai.compare( bi, 4 ) == true ); | 202 | unitTest( ai.compare( bi, 4 ) == true ); |
203 | unitTest( bi.compare( ai, 4 ) == true ); | 203 | unitTest( bi.compare( ai, 4 ) == true ); |
204 | unitTest( ai.compare( bi, 5 ) == false ); | 204 | unitTest( ai.compare( bi, 5 ) == false ); |
205 | unitTest( bi.compare( ai, 5 ) == false ); | 205 | unitTest( bi.compare( ai, 5 ) == false ); |
206 | 206 | ||
207 | a = "fell"; | 207 | a = "fell"; |
208 | b = "-felloo"; | 208 | b = "-felloo"; |
209 | ai = a.begin(); | 209 | ai = a.begin(); |
210 | bi = b.begin()+1; | 210 | bi = b.begin()+1; |
211 | unitTest( ai.compare( bi, 4 ) == true ); | 211 | unitTest( ai.compare( bi, 4 ) == true ); |
212 | ai++; | 212 | ai++; |
213 | bi++; | 213 | bi++; |
214 | unitTest( ai.compare( bi, 4 ) == false ); | 214 | unitTest( ai.compare( bi, 4 ) == false ); |
215 | } | 215 | } |
216 | 216 | ||
217 | test iteratorCompare3 | 217 | test iteratorCompare3 |
218 | { | 218 | { |
219 | Bu::String a("1234aoeu"); | 219 | Bu::String a("1234aoeu"); |
220 | Bu::String::iterator ai = a.begin(); | 220 | Bu::String::iterator ai = a.begin(); |
221 | unitTest( ai.compare("1234") == false ); | 221 | unitTest( ai.compare("1234") == false ); |
222 | unitTest( ai.compare("1234aoeu") == true ); | 222 | unitTest( ai.compare("1234aoeu") == true ); |
223 | unitTest( ai.compare("1234aoeuee") == false ); | 223 | unitTest( ai.compare("1234aoeuee") == false ); |
224 | ai += 4; | 224 | ai += 4; |
225 | unitTest( ai.compare("aoeu") == true ); | 225 | unitTest( ai.compare("aoeu") == true ); |
226 | unitTest( ai.compare("aoeubo") == false ); | 226 | unitTest( ai.compare("aoeubo") == false ); |
227 | unitTest( ai.compare("aoe") == false ); | 227 | unitTest( ai.compare("aoe") == false ); |
228 | unitTest( ai.compare("wrong") == false ); | 228 | unitTest( ai.compare("wrong") == false ); |
229 | unitTest( ai.compare("boeu") == false ); | 229 | unitTest( ai.compare("boeu") == false ); |
230 | } | 230 | } |
231 | 231 | ||
232 | test iteratorCompare4 | 232 | test iteratorCompare4 |
233 | { | 233 | { |
234 | Bu::String a("1234aoeu"); | 234 | Bu::String a("1234aoeu"); |
235 | Bu::String::iterator ai = a.begin(); | 235 | Bu::String::iterator ai = a.begin(); |
236 | unitTest( ai.compare("1234", 4) == true ); | 236 | unitTest( ai.compare("1234", 4) == true ); |
237 | unitTest( ai.compare("1234aoeu", 8) == true ); | 237 | unitTest( ai.compare("1234aoeu", 8) == true ); |
238 | unitTest( ai.compare("1234aoeuee", 10) == false ); | 238 | unitTest( ai.compare("1234aoeuee", 10) == false ); |
239 | } | 239 | } |
240 | 240 | ||
241 | test iteratorCompare5 | 241 | test iteratorCompare5 |
242 | { | 242 | { |
243 | Bu::String a("1234aoeu"); | 243 | Bu::String a("1234aoeu"); |
244 | Bu::String b("34ao"); | 244 | Bu::String b("34ao"); |
245 | Bu::String::iterator ai = a.begin(); | 245 | Bu::String::iterator ai = a.begin(); |
246 | unitTest( ai.compare( b ) == false ); | 246 | unitTest( ai.compare( b ) == false ); |
247 | ai += 2; | 247 | ai += 2; |
248 | unitTest( ai.compare( b ) == false ); | 248 | unitTest( ai.compare( b ) == false ); |
249 | b = "oeu"; | 249 | b = "oeu"; |
250 | ai += 3; | 250 | ai += 3; |
251 | unitTest( ai.compare( b ) == true ); | 251 | unitTest( ai.compare( b ) == true ); |
252 | b += "boo"; | 252 | b += "boo"; |
253 | unitTest( ai.compare( b ) == false ); | 253 | unitTest( ai.compare( b ) == false ); |
254 | } | 254 | } |
255 | 255 | ||
256 | test iteratorCompare6 | 256 | test iteratorCompare6 |
257 | { | 257 | { |
258 | Bu::String a("1234aoeu"); | 258 | Bu::String a("1234aoeu"); |
259 | Bu::String::iterator ai = a.begin(); | 259 | Bu::String::iterator ai = a.begin(); |
260 | unitTest( ai.compare( Bu::String("1234"), 4) == true ); | 260 | unitTest( ai.compare( Bu::String("1234"), 4) == true ); |
261 | unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); | 261 | unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); |
262 | unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); | 262 | unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); |
263 | } | 263 | } |
264 | 264 | ||
265 | test const_iteratorCompare1 | 265 | test const_iteratorCompare1 |
266 | { | 266 | { |
267 | Bu::String a("This is a test."); | 267 | Bu::String a("This is a test."); |
268 | Bu::String b("--This is a test."); | 268 | Bu::String b("--This is a test."); |
269 | Bu::String::const_iterator ai = a.begin(); | 269 | Bu::String::const_iterator ai = a.begin(); |
270 | Bu::String::const_iterator bi = b.begin(); | 270 | Bu::String::const_iterator bi = b.begin(); |
271 | unitTest( ai.compare( bi ) == false ); | 271 | unitTest( ai.compare( bi ) == false ); |
272 | unitTest( bi.compare( ai ) == false ); | 272 | unitTest( bi.compare( ai ) == false ); |
273 | bi++; bi++; | 273 | bi++; bi++; |
274 | unitTest( ai.compare( bi ) == true ); | 274 | unitTest( ai.compare( bi ) == true ); |
275 | unitTest( bi.compare( ai ) == true ); | 275 | unitTest( bi.compare( ai ) == true ); |
276 | b += "hi"; | 276 | b += "hi"; |
277 | unitTest( ai.compare( bi ) == false ); | 277 | unitTest( ai.compare( bi ) == false ); |
278 | unitTest( bi.compare( ai ) == false ); | 278 | unitTest( bi.compare( ai ) == false ); |
279 | } | 279 | } |
280 | 280 | ||
281 | test const_iteratorCompare2 | 281 | test const_iteratorCompare2 |
282 | { | 282 | { |
283 | Bu::String a("1234honour"); | 283 | Bu::String a("1234honour"); |
284 | Bu::String b("--1234ueje"); | 284 | Bu::String b("--1234ueje"); |
285 | Bu::String::const_iterator ai = a.begin(); | 285 | Bu::String::const_iterator ai = a.begin(); |
286 | Bu::String::const_iterator bi = b.begin(); | 286 | Bu::String::const_iterator bi = b.begin(); |
287 | unitTest( ai.compare( bi, 4 ) == false ); | 287 | unitTest( ai.compare( bi, 4 ) == false ); |
288 | unitTest( bi.compare( ai, 4 ) == false ); | 288 | unitTest( bi.compare( ai, 4 ) == false ); |
289 | bi++; bi++; | 289 | bi++; bi++; |
290 | unitTest( ai.compare( bi, 4 ) == true ); | 290 | unitTest( ai.compare( bi, 4 ) == true ); |
291 | unitTest( bi.compare( ai, 4 ) == true ); | 291 | unitTest( bi.compare( ai, 4 ) == true ); |
292 | unitTest( ai.compare( bi, 5 ) == false ); | 292 | unitTest( ai.compare( bi, 5 ) == false ); |
293 | unitTest( bi.compare( ai, 5 ) == false ); | 293 | unitTest( bi.compare( ai, 5 ) == false ); |
294 | 294 | ||
295 | a = "fell"; | 295 | a = "fell"; |
296 | b = "-felloo"; | 296 | b = "-felloo"; |
297 | ai = a.begin(); | 297 | ai = a.begin(); |
298 | bi = b.begin()+1; | 298 | bi = b.begin()+1; |
299 | unitTest( ai.compare( bi, 4 ) == true ); | 299 | unitTest( ai.compare( bi, 4 ) == true ); |
300 | ai++; | 300 | ai++; |
301 | bi++; | 301 | bi++; |
302 | unitTest( ai.compare( bi, 4 ) == false ); | 302 | unitTest( ai.compare( bi, 4 ) == false ); |
303 | } | 303 | } |
304 | 304 | ||
305 | test const_iteratorCompare3 | 305 | test const_iteratorCompare3 |
306 | { | 306 | { |
307 | Bu::String a("1234aoeu"); | 307 | Bu::String a("1234aoeu"); |
308 | Bu::String::const_iterator ai = a.begin(); | 308 | Bu::String::const_iterator ai = a.begin(); |
309 | unitTest( ai.compare("1234") == false ); | 309 | unitTest( ai.compare("1234") == false ); |
310 | unitTest( ai.compare("1234aoeu") == true ); | 310 | unitTest( ai.compare("1234aoeu") == true ); |
311 | unitTest( ai.compare("1234aoeuee") == false ); | 311 | unitTest( ai.compare("1234aoeuee") == false ); |
312 | ai += 4; | 312 | ai += 4; |
313 | unitTest( ai.compare("aoeu") == true ); | 313 | unitTest( ai.compare("aoeu") == true ); |
314 | unitTest( ai.compare("aoeubo") == false ); | 314 | unitTest( ai.compare("aoeubo") == false ); |
315 | unitTest( ai.compare("aoe") == false ); | 315 | unitTest( ai.compare("aoe") == false ); |
316 | unitTest( ai.compare("wrong") == false ); | 316 | unitTest( ai.compare("wrong") == false ); |
317 | unitTest( ai.compare("boeu") == false ); | 317 | unitTest( ai.compare("boeu") == false ); |
318 | } | 318 | } |
319 | 319 | ||
320 | test const_iteratorCompare4 | 320 | test const_iteratorCompare4 |
321 | { | 321 | { |
322 | Bu::String a("1234aoeu"); | 322 | Bu::String a("1234aoeu"); |
323 | Bu::String::const_iterator ai = a.begin(); | 323 | Bu::String::const_iterator ai = a.begin(); |
324 | unitTest( ai.compare("1234", 4) == true ); | 324 | unitTest( ai.compare("1234", 4) == true ); |
325 | unitTest( ai.compare("1234aoeu", 8) == true ); | 325 | unitTest( ai.compare("1234aoeu", 8) == true ); |
326 | unitTest( ai.compare("1234aoeuee", 10) == false ); | 326 | unitTest( ai.compare("1234aoeuee", 10) == false ); |
327 | } | 327 | } |
328 | 328 | ||
329 | test const_iteratorCompare5 | 329 | test const_iteratorCompare5 |
330 | { | 330 | { |
331 | Bu::String a("1234aoeu"); | 331 | Bu::String a("1234aoeu"); |
332 | Bu::String b("34ao"); | 332 | Bu::String b("34ao"); |
333 | Bu::String::const_iterator ai = a.begin(); | 333 | Bu::String::const_iterator ai = a.begin(); |
334 | unitTest( ai.compare( b ) == false ); | 334 | unitTest( ai.compare( b ) == false ); |
335 | ai += 2; | 335 | ai += 2; |
336 | unitTest( ai.compare( b ) == false ); | 336 | unitTest( ai.compare( b ) == false ); |
337 | b = "oeu"; | 337 | b = "oeu"; |
338 | ai += 3; | 338 | ai += 3; |
339 | unitTest( ai.compare( b ) == true ); | 339 | unitTest( ai.compare( b ) == true ); |
340 | b += "boo"; | 340 | b += "boo"; |
341 | unitTest( ai.compare( b ) == false ); | 341 | unitTest( ai.compare( b ) == false ); |
342 | } | 342 | } |
343 | 343 | ||
344 | test const_iteratorCompare6 | 344 | test const_iteratorCompare6 |
345 | { | 345 | { |
346 | Bu::String a("1234aoeu"); | 346 | Bu::String a("1234aoeu"); |
347 | Bu::String::const_iterator ai = a.begin(); | 347 | Bu::String::const_iterator ai = a.begin(); |
348 | unitTest( ai.compare( Bu::String("1234"), 4) == true ); | 348 | unitTest( ai.compare( Bu::String("1234"), 4) == true ); |
349 | unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); | 349 | unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); |
350 | unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); | 350 | unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); |
351 | } | 351 | } |
352 | 352 | ||
353 | test iteratorAppend1 | 353 | test iteratorAppend1 |
354 | { | 354 | { |
355 | Bu::String a("just ->this part"); | 355 | Bu::String a("just ->this part"); |
356 | Bu::String b; | 356 | Bu::String b; |
357 | Bu::String::iterator s = a.begin(); | 357 | Bu::String::iterator s = a.begin(); |
358 | for(; s; s++ ) | 358 | for(; s; s++ ) |
359 | { | 359 | { |
360 | if( *s == '>' ) | 360 | if( *s == '>' ) |
361 | { | 361 | { |
362 | s++; | 362 | s++; |
363 | b.set( s ); | 363 | b.set( s ); |
364 | break; | 364 | break; |
365 | } | 365 | } |
366 | } | 366 | } |
367 | unitTest( b == "this part" ); | 367 | unitTest( b == "this part" ); |
368 | 368 | ||
369 | b.append( s ); | 369 | b.append( s ); |
370 | 370 | ||
371 | Bu::String c; | 371 | Bu::String c; |
372 | c.set( b.begin() ); | 372 | c.set( b.begin() ); |
373 | 373 | ||
374 | // This is here because the comparison operator used to cause flattening. | 374 | // This is here because the comparison operator used to cause flattening. |
375 | unitTest( b == "this partthis part" ); | 375 | unitTest( b == "this partthis part" ); |
376 | unitTest( c == b ); | 376 | unitTest( c == b ); |
377 | } | 377 | } |
378 | 378 | ||
379 | test iteratorAppend2 | 379 | test iteratorAppend2 |
380 | { | 380 | { |
381 | Bu::String a("just [this] part"); | 381 | Bu::String a("just [this] part"); |
382 | Bu::String b; | 382 | Bu::String b; |
383 | Bu::String::iterator s = a.begin(); | 383 | Bu::String::iterator s = a.begin(); |
384 | for(; s; s++ ) | 384 | for(; s; s++ ) |
385 | { | 385 | { |
386 | if( *s == '[' ) | 386 | if( *s == '[' ) |
387 | { | 387 | { |
388 | s++; | 388 | s++; |
389 | break; | 389 | break; |
390 | } | 390 | } |
391 | } | 391 | } |
392 | Bu::String::iterator e = s; | 392 | Bu::String::iterator e = s; |
393 | for(; e; e++ ) | 393 | for(; e; e++ ) |
394 | { | 394 | { |
395 | if( *e == ']' ) | 395 | if( *e == ']' ) |
396 | { | 396 | { |
397 | b.set( s, e ); | 397 | b.set( s, e ); |
398 | break; | 398 | break; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | unitTest( b == "this" ); | 401 | unitTest( b == "this" ); |
402 | 402 | ||
403 | b.append( s, e ); | 403 | b.append( s, e ); |
404 | 404 | ||
405 | for( Bu::String::iterator i = b.begin(); i;) | 405 | for( Bu::String::iterator i = b.begin(); i;) |
406 | { | 406 | { |
407 | Bu::String::iterator k = i; | 407 | Bu::String::iterator k = i; |
408 | k++; | 408 | k++; |
409 | if( !k ) | 409 | if( !k ) |
410 | { | 410 | { |
411 | b.append( b.begin(), i ); | 411 | b.append( b.begin(), i ); |
412 | break; | 412 | break; |
413 | } | 413 | } |
414 | i = k; | 414 | i = k; |
415 | } | 415 | } |
416 | Bu::String l; | 416 | Bu::String l; |
417 | l.set( b.begin() ); | 417 | l.set( b.begin() ); |
418 | unitTest( l == "thisthisthisthi" ); | 418 | unitTest( l == "thisthisthisthi" ); |
419 | for( Bu::String::iterator i = b.begin(); i;) | 419 | for( Bu::String::iterator i = b.begin(); i;) |
420 | { | 420 | { |
421 | Bu::String::iterator k = i; | 421 | Bu::String::iterator k = i; |
422 | k++; | 422 | k++; |
423 | if( !k ) | 423 | if( !k ) |
424 | { | 424 | { |
425 | b.append( b.begin(), i ); | 425 | b.append( b.begin(), i ); |
426 | break; | 426 | break; |
427 | } | 427 | } |
428 | i = k; | 428 | i = k; |
429 | } | 429 | } |
430 | l.set( b.begin() ); | 430 | l.set( b.begin() ); |
431 | unitTest( l == "thisthisthisthithisthisthisth" ); | 431 | unitTest( l == "thisthisthisthithisthisthisth" ); |
432 | } | 432 | } |
433 | 433 | ||
434 | test isSet1 | 434 | test isSet1 |
435 | { | 435 | { |
436 | Bu::String bob; | 436 | Bu::String bob; |
437 | 437 | ||
438 | unitTest( bob.isSet() == false ); | 438 | unitTest( bob.isSet() == false ); |
439 | bob = "something"; | 439 | bob = "something"; |
440 | unitTest( bob.isSet() == true ); | 440 | unitTest( bob.isSet() == true ); |
441 | bob = ""; | 441 | bob = ""; |
442 | unitTest( bob.isSet() == false ); | 442 | unitTest( bob.isSet() == false ); |
443 | } | 443 | } |
444 | 444 | ||
445 | test swap1 | 445 | test swap1 |
446 | { | 446 | { |
447 | Bu::String a, b; | 447 | Bu::String a, b; |
448 | a = "Goodbye"; | 448 | a = "Goodbye"; |
449 | b = "Hello"; | 449 | b = "Hello"; |
450 | Bu::swap( a, b ); | 450 | Bu::swap( a, b ); |
451 | unitTest( a == "Hello" ); | 451 | unitTest( a == "Hello" ); |
452 | unitTest( b == "Goodbye" ); | 452 | unitTest( b == "Goodbye" ); |
453 | } | 453 | } |
454 | 454 | ||
455 | test swap2 | 455 | test swap2 |
456 | { | 456 | { |
457 | Bu::String a, b; | 457 | Bu::String a, b; |
458 | a = "Goodbye"; | 458 | a = "Goodbye"; |
459 | b = "Hello"; | 459 | b = "Hello"; |
460 | std::swap( a, b ); | 460 | std::swap( a, b ); |
461 | unitTest( a == "Hello" ); | 461 | unitTest( a == "Hello" ); |
462 | unitTest( b == "Goodbye" ); | 462 | unitTest( b == "Goodbye" ); |
463 | } | 463 | } |
464 | 464 | ||
465 | test replace1 | 465 | test replace1 |
466 | { | 466 | { |
467 | Bu::String a; | 467 | Bu::String a; |
468 | a = "This is a test."; | 468 | a = "This is a test."; |
469 | unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); | 469 | unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); |
470 | } | 470 | } |
471 | 471 | ||
472 | test replace2 | 472 | test replace2 |
473 | { | 473 | { |
474 | Bu::String a; | 474 | Bu::String a; |
475 | a = "aaaboostuffb"; | 475 | a = "aaaboostuffb"; |
476 | unitTest( a.replace("boo", "/") == "aaa/stuffb" ); | 476 | unitTest( a.replace("boo", "/") == "aaa/stuffb" ); |
477 | } | 477 | } |
478 | 478 | ||
479 | test coreDerefBug1 | 479 | test coreDerefBug1 |
480 | { | 480 | { |
481 | Bu::String a, b; | 481 | Bu::String a, b; |
482 | a = "bob"; | 482 | a = "bob"; |
483 | a.setSize( 0 ); | 483 | a.setSize( 0 ); |
484 | b = a; | 484 | b = a; |
485 | b.getStr(); | 485 | b.getStr(); |
486 | } | 486 | } |
487 | 487 | ||
488 | test padding1 | 488 | test padding1 |
489 | { | 489 | { |
490 | Bu::String a; | 490 | Bu::String a; |
491 | a.append('a'); | 491 | a.append('a'); |
492 | a.append('b'); | 492 | a.append('b'); |
493 | a.append('c'); | 493 | a.append('c'); |
494 | a.append("hello"); | 494 | a.append("hello"); |
495 | a.clear(); | 495 | a.clear(); |
496 | } | 496 | } |
497 | 497 | ||
498 | test padding2 | 498 | test padding2 |
499 | { | 499 | { |
500 | Bu::String src("It's all sorts of things"); | 500 | Bu::String src("It's all sorts of things"); |
501 | Bu::String::const_iterator i = src.find('a'); | 501 | Bu::String::const_iterator i = src.find('a'); |
502 | Bu::String::const_iterator j = src.find('f'); | 502 | Bu::String::const_iterator j = src.find('f'); |
503 | Bu::String a, b; | 503 | Bu::String a, b; |
504 | a.append( i ); | 504 | a.append( i ); |
505 | i += 2; | 505 | i += 2; |
506 | a.append( i, j ); | 506 | a.append( i, j ); |
507 | a.append('a'); | 507 | a.append('a'); |
508 | a.append('b'); | 508 | a.append('b'); |
509 | a.append('c'); | 509 | a.append('c'); |
510 | a.append("hello"); | 510 | a.append("hello"); |
511 | a.append( src ); | 511 | a.append( src ); |
512 | b = a; | 512 | b = a; |
513 | a.clear(); | 513 | a.clear(); |
514 | } | 514 | } |
515 | 515 | ||
516 | test append | 516 | test append |
517 | { | 517 | { |
518 | // This is the byte sequence that caused += to die | 518 | // This is the byte sequence that caused += to die |
519 | // 03 F0 9C A4 F5 8A C8 CA 0E | 519 | // 03 F0 9C A4 F5 8A C8 CA 0E |
520 | uint8_t b; | 520 | uint8_t b; |
521 | Bu::String m1; | 521 | Bu::String m1; |
522 | b = 0x03; m1 += (char)b; | 522 | b = 0x03; m1 += (char)b; |
523 | b = 0xF0; m1 += (char)b; | 523 | b = 0xF0; m1 += (char)b; |
524 | b = 0x9C; m1 += (char)b; | 524 | b = 0x9C; m1 += (char)b; |
525 | b = 0xA4; m1 += (char)b; | 525 | b = 0xA4; m1 += (char)b; |
526 | b = 0xF5; m1 += (char)b; | 526 | b = 0xF5; m1 += (char)b; |
527 | b = 0x8A; m1 += (char)b; | 527 | b = 0x8A; m1 += (char)b; |
528 | b = 0xC8; m1 += (char)b; | 528 | b = 0xC8; m1 += (char)b; |
529 | b = 0xCA; m1 += (char)b; | 529 | b = 0xCA; m1 += (char)b; |
530 | b = 0x0E; m1 += (char)b; | 530 | b = 0x0E; m1 += (char)b; |
531 | 531 | ||
532 | Bu::String m2; | 532 | Bu::String m2; |
533 | b = 0x03; m2.append( (const char *)&b, 1 ); | 533 | b = 0x03; m2.append( (const char *)&b, 1 ); |
534 | b = 0xF0; m2.append( (const char *)&b, 1 ); | 534 | b = 0xF0; m2.append( (const char *)&b, 1 ); |
535 | b = 0x9C; m2.append( (const char *)&b, 1 ); | 535 | b = 0x9C; m2.append( (const char *)&b, 1 ); |
536 | b = 0xA4; m2.append( (const char *)&b, 1 ); | 536 | b = 0xA4; m2.append( (const char *)&b, 1 ); |
537 | b = 0xF5; m2.append( (const char *)&b, 1 ); | 537 | b = 0xF5; m2.append( (const char *)&b, 1 ); |
538 | b = 0x8A; m2.append( (const char *)&b, 1 ); | 538 | b = 0x8A; m2.append( (const char *)&b, 1 ); |
539 | b = 0xC8; m2.append( (const char *)&b, 1 ); | 539 | b = 0xC8; m2.append( (const char *)&b, 1 ); |
540 | b = 0xCA; m2.append( (const char *)&b, 1 ); | 540 | b = 0xCA; m2.append( (const char *)&b, 1 ); |
541 | b = 0x0E; m2.append( (const char *)&b, 1 ); | 541 | b = 0x0E; m2.append( (const char *)&b, 1 ); |
542 | 542 | ||
543 | unitTest( m1 == m2 ); | 543 | unitTest( m1 == m2 ); |
544 | unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" ); | 544 | unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" ); |
545 | } | 545 | } |
546 | 546 | ||
547 | test toUpper1 | 547 | test toUpper1 |
548 | { | 548 | { |
549 | Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); | 549 | Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); |
550 | unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" ); | 550 | unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" ); |
551 | unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); | 551 | unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); |
552 | } | 552 | } |
553 | 553 | ||
554 | test toLower1 | 554 | test toLower1 |
555 | { | 555 | { |
556 | Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); | 556 | Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); |
557 | unitTest( s1.toLower() == "hello there, how are you doing?" ); | 557 | unitTest( s1.toLower() == "hello there, how are you doing?" ); |
558 | unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); | 558 | unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); |
559 | } | 559 | } |
560 | 560 | ||
561 | test trimWhitespace1 | 561 | test trimWhitespace1 |
562 | { | 562 | { |
563 | unitTest( Bu::String("Hello there").trimWhitespace() | 563 | unitTest( Bu::String("Hello there").trimWhitespace() |
564 | == "Hello there" ); | 564 | == "Hello there" ); |
565 | unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() | 565 | unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() |
566 | == "Hello there" ); | 566 | == "Hello there" ); |
567 | unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() | 567 | unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() |
568 | == "Hello there" ); | 568 | == "Hello there" ); |
569 | unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() | 569 | unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() |
570 | == "Hello there" ); | 570 | == "Hello there" ); |
571 | unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); | 571 | unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); |
572 | unitTest( Bu::String().trimWhitespace() == "" ); | 572 | unitTest( Bu::String().trimWhitespace() == "" ); |
573 | unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() | 573 | unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() |
574 | == "Hello \t\t\r\nthere" ); | 574 | == "Hello \t\t\r\nthere" ); |
575 | } | 575 | } |
576 | 576 | ||
577 | test format1 | 577 | test format1 |
578 | { | 578 | { |
579 | unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" ); | 579 | unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" ); |
580 | unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" ); | 580 | unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" ); |
581 | unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" ); | 581 | unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" ); |
582 | unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" ); | 582 | unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" ); |
583 | } | 583 | } |
584 | 584 | ||
585 | test format2 | 585 | test format2 |
586 | { | 586 | { |
587 | unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" ); | 587 | unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" ); |
588 | } | 588 | } |
589 | } | 589 | } |
590 | // 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 | 590 | // 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 |
591 | // | 591 | // |
diff --git a/src/unit/substream.unit b/src/unit/substream.unit index c66238d..b0d1407 100644 --- a/src/unit/substream.unit +++ b/src/unit/substream.unit | |||
@@ -11,42 +11,42 @@ | |||
11 | 11 | ||
12 | suite SubStream | 12 | suite SubStream |
13 | { | 13 | { |
14 | test testRead01 | 14 | test testRead01 |
15 | { | 15 | { |
16 | Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); | 16 | Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); |
17 | mb.seek( 4 ); | 17 | mb.seek( 4 ); |
18 | Bu::SubStream ss( mb, 10 ); | 18 | Bu::SubStream ss( mb, 10 ); |
19 | unitTest( ss.readLine() == "efghijklmn" ); | 19 | unitTest( ss.readLine() == "efghijklmn" ); |
20 | } | 20 | } |
21 | 21 | ||
22 | test 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 | test 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 12e93c2..47605ee 100644 --- a/src/unit/taf.unit +++ b/src/unit/taf.unit | |||
@@ -15,64 +15,64 @@ | |||
15 | 15 | ||
16 | suite Taf | 16 | suite Taf |
17 | { | 17 | { |
18 | test read1 | 18 | test read1 |
19 | { | 19 | { |
20 | #define FN_TMP ("/tmp/tmpXXXXXXXX") | 20 | #define FN_TMP ("/tmp/tmpXXXXXXXX") |
21 | Bu::String sFnTmp(FN_TMP); | 21 | Bu::String 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 | test 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::String sData( 256 ); | 46 | Bu::String 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 ); |
diff --git a/src/unit/variant.unit b/src/unit/variant.unit index 684bea1..68c7be5 100644 --- a/src/unit/variant.unit +++ b/src/unit/variant.unit | |||
@@ -16,46 +16,46 @@ using namespace Bu; | |||
16 | 16 | ||
17 | Bu::String mkastring() | 17 | Bu::String mkastring() |
18 | { | 18 | { |
19 | Bu::String a = "s"; | 19 | Bu::String a = "s"; |
20 | a += "tu"; | 20 | a += "tu"; |
21 | a += "f"; | 21 | a += "f"; |
22 | a += "f"; | 22 | a += "f"; |
23 | return a; | 23 | return a; |
24 | } | 24 | } |
25 | 25 | ||
26 | suite Variant | 26 | suite Variant |
27 | { | 27 | { |
28 | test construction | 28 | test construction |
29 | { | 29 | { |
30 | Bu::Variant v( 55 ); | 30 | Bu::Variant v( 55 ); |
31 | v.get<int>(); | 31 | v.get<int>(); |
32 | 32 | ||
33 | Bu::Variant v2( v ); | 33 | Bu::Variant v2( v ); |
34 | v2.get<int>(); | 34 | v2.get<int>(); |
35 | } | 35 | } |
36 | 36 | ||
37 | test formatting | 37 | test formatting |
38 | { | 38 | { |
39 | Bu::Variant v("hello"); | 39 | Bu::Variant v("hello"); |
40 | Bu::MemBuf mb; | 40 | Bu::MemBuf mb; |
41 | Bu::Formatter f( mb ); | 41 | Bu::Formatter f( mb ); |
42 | f << v; | 42 | f << v; |
43 | unitTest( mb.getString() == v.get<Bu::String>() ); | 43 | unitTest( mb.getString() == v.get<Bu::String>() ); |
44 | } | 44 | } |
45 | 45 | ||
46 | test stringForamtting | 46 | test stringForamtting |
47 | { | 47 | { |
48 | Bu::String s1; | 48 | Bu::String s1; |
49 | s1 = "hello"; | 49 | s1 = "hello"; |
50 | int32_t i1, i2; | 50 | int32_t i1, i2; |
51 | i1 = 32; | 51 | i1 = 32; |
52 | i2 = 0; | 52 | i2 = 0; |
53 | Bu::String out = Bu::String("%1-%2-%3-%4.odp"). | 53 | Bu::String out = Bu::String("%1-%2-%3-%4.odp"). |
54 | arg( s1.getStr() ). | 54 | arg( s1.getStr() ). |
55 | arg( mkastring().getStr() ). | 55 | arg( mkastring().getStr() ). |
56 | arg( i1, Fmt(2).fill('0') ). | 56 | arg( i1, Fmt(2).fill('0') ). |
57 | arg( i2, Fmt(2).fill('0') ); | 57 | arg( i2, Fmt(2).fill('0') ); |
58 | // sio << sio.nl << out << sio.nl; | 58 | // sio << sio.nl << out << sio.nl; |
59 | unitTest( out == "hello-stuff-32-00.odp" ); | 59 | unitTest( out == "hello-stuff-32-00.odp" ); |
60 | } | 60 | } |
61 | } | 61 | } |
diff --git a/src/unit/xml.unit b/src/unit/xml.unit index 0db21c1..57e1c1c 100644 --- a/src/unit/xml.unit +++ b/src/unit/xml.unit | |||
@@ -12,10 +12,10 @@ | |||
12 | 12 | ||
13 | suite Xml | 13 | suite Xml |
14 | { | 14 | { |
15 | test declaration | 15 | test declaration |
16 | { | 16 | { |
17 | Bu::String sXml("<?xml ?> <hi />"); | 17 | Bu::String sXml("<?xml ?> <hi />"); |
18 | Bu::MemBuf buf( sXml ); | 18 | Bu::MemBuf buf( sXml ); |
19 | Bu::XmlReader xr( buf ); | 19 | Bu::XmlReader xr( buf ); |
20 | } | 20 | } |
21 | } | 21 | } |