1 | | |
2 | | |
3 | | |
4 | | |
5 | | |
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
16 | | |
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
47 | | |
48 | | |
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
58 | | |
59 | | |
60 | | |
61 | | |
62 | | |
63 | | |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | |
71 | | |
72 | | |
73 | | |
74 | | |
75 | | |
76 | | |
77 | | |
78 | | |
79 | | |
80 | | |
81 | | |
82 | | |
83 | | |
84 | | |
85 | | |
86 | | |
87 | | |
88 | | |
89 | | |
90 | | |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 | | |
98 | | |
99 | | |
100 | | |
101 | | |
102 | | |
103 | | |
104 | | |
105 | | |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | |
112 | | |
113 | | |
114 | | |
115 | | |
116 | | |
117 | | |
118 | | |
119 | | |
120 | | |
121 | | |
122 | | |
123 | | |
124 | | |
125 | | |
126 | | |
127 | | |
128 | | |
129 | | |
130 | | |
131 | | |
132 | | |
133 | | |
134 | | |
135 | | |
136 | | |
137 | | |
138 | | |
139 | | |
140 | | |
141 | | |
142 | | |
143 | | |
144 | | |
145 | | |
146 | | |
147 | | |
148 | | |
149 | | |
150 | | |
151 | | |
152 | | |
153 | | |
154 | | |
155 | | |
156 | | |
157 | | |
158 | | |
159 | | |
160 | | |
161 | | |
162 | | |
163 | | |
164 | | |
165 | | |
166 | | |
167 | | |
168 | | |
169 | | |
170 | | |
171 | | |
172 | | |
173 | | |
174 | | |
175 | | |
176 | | |
177 | | |
178 | | |
179 | | |
180 | | |
181 | | |
182 | | |
183 | | |
184 | | |
185 | | |
186 | | |
187 | | |
188 | | |
189 | | |
190 | | |
191 | | |
192 | | |
193 | | |
194 | | |
195 | | |
196 | | |
197 | | |
198 | | |
199 | | |
200 | | |
201 | | |
202 | | |
203 | | |
204 | | |
205 | | |
206 | | |
207 | | |
208 | | |
209 | | |
210 | | |
211 | | |
212 | | |
213 | | |
214 | | |
215 | | |
216 | | |
217 | | |
218 | | |
219 | | |
220 | | |
221 | | |
222 | | |
223 | | |
224 | | |
225 | | |
226 | | |
227 | | |
228 | | |
229 | | |
230 | | |
231 | | |
232 | | |
233 | | |
234 | | |
235 | | |
236 | | |
237 | | |
238 | | |
239 | | |
240 | | |
241 | | |
242 | | |
243 | | |
244 | | |
245 | | |
246 | | |
247 | | |
248 | | |
249 | | |
250 | | |
251 | | |
252 | | |
253 | | |
254 | | |
255 | | |
256 | | |
257 | | |
258 | | |
259 | | |
260 | | |
261 | | |
262 | | |
263 | | |
264 | | |
265 | | |
266 | | |
267 | | |
268 | | |
269 | | |
270 | | |
271 | | |
272 | | |
273 | | |
274 | | |
275 | | |
276 | | |
277 | | |
278 | | |
279 | | |
280 | | |
281 | | |
282 | | |
283 | | |
284 | | |
285 | | |
286 | | |
287 | | |
288 | | |
289 | | |
290 | | |
291 | | |
292 | | |
293 | | |
294 | | |
295 | | |
296 | | |
297 | | |
298 | | |
299 | | |
300 | | |
301 | | |
302 | | |
303 | | |
304 | | |
305 | | |
306 | | |
307 | | |
308 | | |
309 | | |
310 | | |
311 | | |
312 | | |
313 | | |
314 | | |
315 | | |
316 | | |
317 | | |
318 | | |
319 | | |
320 | | |
321 | | |
322 | | |
323 | | |
324 | | |
325 | | |
326 | | |
327 | | |
328 | | |
329 | | |
330 | | |
331 | | |
332 | | |
333 | | |
334 | | |
335 | | |
336 | | |
337 | | |
338 | | |
339 | | |
340 | | |
341 | | |
342 | | |
343 | | |
344 | | |
345 | | |
346 | | |
347 | | |
348 | | |
349 | | |
350 | | |
351 | | |
352 | | |
353 | | |
354 | | |
355 | | |
356 | | |
357 | | |
358 | | |
359 | | |
360 | | |
361 | | |
362 | | |
363 | | |
364 | | |
365 | | |
366 | | |
367 | | |
| dnl $Id: testsuite.in,v 1.14 2004/05/01 16:02:30 nilsson Exp $ | | dnl - ADT.BitBuffer | | test_do( add_constant( "B", ADT.BitBuffer() ) ) | test_eq( B->drain(), "" ) | test_eq( B->feed(""), B ) | test_eval_error( B->feed("\400") ) | test_eq( B->drain(), "" ) | test_eq( sizeof(B), 0 ) | | test_eq( B->put(3,3), B ) | test_eq( sizeof(B), 3 ) | test_eq( B->get(2), 1 ) | test_eq( sizeof(B), 1 ) | test_eq( B->drain(), "" ) | | test_eq( B->feed("foo"), B ) | test_eq( sizeof(B), 3*8+1 ) | test_eq( B->drain(), "\xb3""7\xb7" ) | test_eq( sizeof(B), 1 ) | test_eq( B->get(1), 1 ) | | test_eq( B->feed("\xff\0"), B ) | test_eq( B->get(7), 127 ) | test_eq( B->get(4), 8 ) | test_eq( B->get(5), 0 ) | | test_eq( B->put1(9), B ) | test_eq( B->get(9), 0b111111111 ) | | test_eq( B->put1(1), B ) | test_eq( B->put0(4), B ) | test_eq( sizeof(B), 5 ) | test_eq( B->put1(4), B ) | test_eq( sizeof(B), 9 ) | test_eq( B->get(1), 1 ) | test_eq( B->drain(), "\17" ) | test_eq( sizeof(B), 0 ) | test_eq( B->drain(), "" ) | test_eval_error( B->get(1) ) | | test_do( add_constant( "B" ) ) | | | dnl - ADT.History | | test_eq(sizeof(ADT.History(2)),0) | | test_do(add_constant("adth", ADT.History(2))) | test_eq(adth->get_maxsize(),2) | test_any([[ | adth->push(17); | return sizeof(adth); | ]], 1) | test_any([[ | adth->push(18); | return sizeof(adth); | ]], 2) | test_any([[ | adth->push(19); | return sizeof(adth); | ]], 2) | test_eq(adth->get_latest_entry_num(),3) | test_eq(adth->get_first_entry_num(),2) | test_eval_error(return adth[0]) | test_eval_error(return adth[1]) | test_eq(adth[2],18) | test_eq(adth[3],19) | test_eq(adth[-1],19) | test_eq(adth[-2],18) | test_eval_error(return adth[-3]) | test_do( adth->set_maxsize(4) ) | test_eq(adth->get_maxsize(),4) | test_eq(sizeof(adth),2) | test_eq(adth[-1],19) | test_eq(adth[-2],18) | test_eval_error(return adth[-3]) | test_do( adth->push(20); adth->push(21); adth->push(22); ) | test_eq(adth[3],19) | test_eq(adth[6],22) | test_do( adth->flush() ) | test_eq(adth->get_latest_entry_num(),6) | test_eq(adth->get_first_entry_num(),0) | test_do( adth->set_maxsize(0) ) | test_do( adth->push(23) ) | test_eq(sizeof(adth),0) | test_do( adth->set_maxsize(2) ) | test_eq(adth->query_no_adjacent_duplicates(), 0) | test_do( adth->set_no_adjacent_duplicates(1), 0) | test_do( adth->push(24) ) | test_do( adth->push(25) ) | test_do( adth->push(25) ) | test_do( adth->push(25) ) | test_eq(adth[-2],24) | test_do( adth->set_no_adjacent_duplicates(0), 0) | test_do( adth->push(26) ) | test_do( adth->push(26) ) | test_eq(adth[-2],26) | test_do( adth[-1]=27 ) | test_equal(indices(adth),[[ ({9,10}) ]]) | test_equal(values(adth),[[ ({26,27}) ]]) | test_do(add_constant("adth")) | | | | dnl - ADT.Stack | | test_any([[ | object s = ADT.Stack(); | s->push(1); | return s->pop(); | ]], 1) | | test_eval_error(return ADT.Stack()->pop()) | | test_any([[ | object s = ADT.Stack(); | for(int i; i<1000; i++) | s->push(i); | for(int i; i<1000; i++) | s->pop(); | for(int i; i<1000; i++) | s->push(i); | return s->pop(); | ]], 999) | | test_equal_any([[ | object s = ADT.Stack(); | s->push(2); | s->push(3); | s->push(4); | s->pop(); | return s->pop(2); | ]], ({2,3}) ) | | test_any([[ | object s = ADT.Stack(); | s->push(5); | return s->top(); | ]], 5) | | test_eval_error(return ADT.Stack()->top()) | | test_any([[ | object s = ADT.Stack(); | for(int i; i<1000; i++) | s->push(i); | for(int i; i<1000; i++) | s->quick_pop(); | for(int i; i<1000; i++) | s->push(i); | return sizeof(s); | ]], 1000) | | test_any([[ | object s = ADT.Stack(); | for(int i; i<1000; i++) | s->push(i); | return sizeof(s); | ]], 1000) | | test_any([[ | object s = ADT.Stack(); | s->push(3); | s->reset(); | return sizeof(s); | ]], 0) | | test_any([[ | object s = ADT.Stack(); | s->set_stack( "1234"/1 ); | s->push("5"); | return s->pop()+sizeof(s); | ]], "54") | | test_any([[ | object s = ADT.Stack(); | s->push("a"); | s->push("b"); | return values(s)*","; | ]], [["a,b"]]) | | test_any([[ | object s = ADT.Stack(); | s->set_stack( "1234"/1 ); | object t = ADT.Stack(); | t->push("5"); | return values(s+t)*""; | ]], "12345") | | | dnl - ADT.Struct | | test_do([[ | class Test { | inherit ADT.Struct; | Item one = Byte(); | Item two = Word(2); | Item three = Chars(3); | }; | add_constant("Test", Test); | ]]) | test_equal( sizeof(Test()), 6 ) | test_equal( indices(Test()), ({ "one", "two", "three" }) ) | test_equal( values(Test()), ({ 0, 2, "\0\0\0" }) ) | test_eq( (string)Test("123456"), "123456" ) | test_eq( (string)Test("1234567"), "123456" ) | test_equal( (array)Test("123456"), ({ "1", "23", "456" }) ) | test_any([[ | Test test=Test(); | test->one=1; | test->two=3; | test->three="klm"; | return (string)test; | ]], "\1\0\3klm") | test_any([[ | Test test=Test(); | test["one"]=1; | test["two"]=3; | test["three"]="klm"; | return (string)test; | ]], "\1\0\3klm") | test_any([[ | Test test=Test(); | return sprintf("%O%O%O", test->one, test->two, test->three); | ]], "02\"\\0\\0\\0\"") | test_any([[ | Test test=Test(); | return sprintf("%O%O%O", test["one"], test["two"], test["three"]); | ]], "02\"\\0\\0\\0\"") | test_any([[ | Test test=Test(); | test->decode("123456"); | return test->encode(); | ]], "123456") | test_eval_error([[ | Test test=Test(); | test->one=-1; | ]]) | test_eval_error([[ | Test test=Test(); | test->one=256; | ]]) | test_eval_error([[ | Test test=Test(); | test->two=-1; | ]]) | test_eval_error([[ | Test test=Test(); | test->two=65536; | ]]) | test_eval_error([[ | Test test=Test(); | test->three=""; | ]]) | test_eval_error([[ | Test test=Test(); | test->three="xx\0777"; | ]]) | test_do( add_constant("Test") ) | test_do([[ | class Test { | inherit ADT.Struct; | }; | add_constant( "Test", Test ); | ]]) | test_equal( sizeof(Test()), 0 ) | test_equal( indices(Test()), ({}) ) | test_equal( values(Test()), ({}) ) | test_equal( (string)Test(), "" ) | test_do( Test()->decode("123") ) | test_do( Test()->decode("") ) | test_do( add_constant("Test") ) | test_any([[ | class Test { | inherit ADT.Struct; | Item one = Byte(1); | Item two = Word(); | Item three = Chars(3, "klm"); | }; | return (string)Test(); | ]], "\1\0\0klm") | test_any([[ | class Test { | inherit ADT.Struct; | Item a = Word(0x1234); | Item b = Drow(0x1234); | Item c = Long(0x12345678); | Item d = Gnol(0x12345678); | }; | return (string)Test(); | ]], "\22""44\22\22""4VxxV4\22"); | test_do([[ | class Test { | inherit ADT.Struct; | Item a = Varchars(); | Item b = Varchars(1,3); | Item c = Chars(1); | }; | add_constant("Test",Test); | ]]) | test_eq( (string)Test("a\0b\0c"), "a\0b\0c" ) | test_eq( (string)Test("a\0b\0c\0"), "a\0b\0c" ) | test_eval_error( Test("a\0\0c") ) | test_eval_error( Test("a\0bbbb\0c") ) | test_eval_error( Test("a\0b\0") ) | test_eq( sizeof(Test("aa\0b\0c")), 6 ) | test_do( add_constant("Test"); ) | | | dnl - ADT.Table | | test_true(ADT.Table.table( | ({ ({ "a", "b", 42 }), | ({ "c", "b", 41 }), | ({ "a", "a", 76 }) }), | ({ "X", "Y", "z" }))->select("x", 2)->sum("Z")->distinct(0)->rsort("X") | ->rename(0, "fOo")->sort("foO")->cast("array"), | ({ ({ "a", 118 }), | ({ "c", 41 }) })) | | | dnl - ADT.struct | | define(test_put,[[ | test_any([[ | object s=ADT.struct(); | s->$1; | return s->pop_data()+"\7777"+s->pop_data(); | ]],$2"\7777") | test_any_equal([[ | object s=ADT.struct($2); | return s->$3; | ]], $4) | ]]) | | test_put(add_data("hej"), "hej", get_fix_string(3), "hej") | test_put(put_uint(17,1), "\21", get_uint(1), 17) | test_put(put_uint(17,2), "\0\21", get_uint(2), 17) | test_put(put_var_string("hej",1), "\3hej", get_var_string(1), "hej") | cond([[ master()->resolv("Gmp")->mpz ]],[[ | test_put(put_bignum(Gmp.mpz(123456789)), "\0\4\7[\315\25", get_bignum(), | Gmp.mpz(123456789)) | ]]) | test_put(put_fix_string("hej"), "hej", get_fix_string(3), "hej") | test_put(put_fix_uint_array(({1,2,3,4}), 1), "\1\2\3\4", get_fix_uint_array(1,4), | ({1,2,3,4})) | test_put(put_var_uint_array(({1,2,3,4}),1,1), "\4\1\2\3\4", get_var_uint_array(1,1), | ({1,2,3,4})) | | test_any([[ | object s=ADT.struct("abcdefghijk"); | return s->get_fix_string(3)+" "+s->contents()+" "+s->get_fix_string(3); | ]], "abc defghijk def") | | test_any([[ | object s=ADT.struct("abcdefghijk"); | return s->get_fix_string(3)+" "+s->get_rest(); | ]], "abc defghijk") | | test_eval_error([[ | object s=ADT.struct("abc"); | s->get_rest(); | s->get_fix_string(1); | ]]) | |
|