author | "Patrik Svestka <patrik.svestka@gmail.com>" |
Fri, 16 Dec 2022 10:44:49 +0100 | |
branch | jv |
changeset 2608 | b77fda6a2e98 |
parent 1567 | e17701a073f9 |
permissions | -rwxr-xr-x |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
243 | 2 |
|
3 |
"{ NameSpace: RegressionTests }" |
|
4 |
||
5 |
TestCase subclass:#BinaryIOTests |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1346 | 9 |
category:'tests-Regression-Streams' |
243 | 10 |
! |
11 |
||
12 |
!BinaryIOTests class methodsFor:'documentation'! |
|
13 |
||
14 |
documentation |
|
15 |
" |
|
16 |
documentation to be added. |
|
17 |
||
18 |
[author:] |
|
1545 | 19 |
Claus Gittinger (cg@alan) |
243 | 20 |
|
21 |
[instance variables:] |
|
22 |
||
23 |
[class variables:] |
|
24 |
||
25 |
[see also:] |
|
26 |
||
27 |
" |
|
28 |
! |
|
29 |
||
30 |
history |
|
31 |
"Created: / 09-09-2004 / 13:13:39 / cg" |
|
32 |
! ! |
|
33 |
||
1388 | 34 |
!BinaryIOTests class methodsFor:'queries'! |
35 |
||
36 |
coveredPackageNames |
|
37 |
^ #( 'stx:libboss' ) |
|
38 |
! ! |
|
39 |
||
243 | 40 |
!BinaryIOTests methodsFor:'initialize / release'! |
41 |
||
42 |
setUp |
|
43 |
"common setup - invoked before testing." |
|
44 |
||
45 |
super setUp |
|
46 |
! |
|
47 |
||
48 |
tearDown |
|
49 |
"common cleanup - invoked after testing." |
|
50 |
||
51 |
super tearDown |
|
52 |
! ! |
|
53 |
||
54 |
!BinaryIOTests methodsFor:'tests'! |
|
55 |
||
56 |
test1 |
|
57 |
|test test2 loaders bytes outStream inStream| |
|
58 |
||
59 |
loaders := OrderedCollection new. |
|
60 |
||
61 |
outStream := ByteArray new writeStream. |
|
62 |
||
63 |
test := [:objWritten | |
|
1545 | 64 |
objWritten storeBinaryOn:outStream. |
65 |
loaders add:[ |
|
66 |
|objRead expected| |
|
243 | 67 |
|
1545 | 68 |
expected := objWritten. |
69 |
objRead := inStream nextObject. |
|
70 |
self assert:( objRead = expected ) |
|
71 |
] |
|
72 |
]. |
|
243 | 73 |
|
74 |
test2 := [:val | test value:val. test value: val negated]. |
|
75 |
||
76 |
test value:(1 to:99). |
|
77 |
test value:(1 to:99) asArray. |
|
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
78 |
test value:(1 to:99) asArray beImmutable. |
243 | 79 |
|
80 |
bytes := outStream contents. |
|
81 |
inStream := BinaryInputManager on:bytes readStream. |
|
82 |
||
83 |
loaders do:[:action | action value ]. |
|
84 |
||
85 |
" |
|
86 |
self run:#test1 |
|
87 |
self new test1 |
|
88 |
" |
|
89 |
! |
|
90 |
||
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
91 |
testArrays1 |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
92 |
|objs outStream inStream| |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
93 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
94 |
outStream := ByteArray new writeStream. |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
95 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
96 |
objs := #( |
1545 | 97 |
() |
98 |
(1) |
|
99 |
(1 2) |
|
100 |
(1 2 3) |
|
101 |
(nil true false 1 1.0) |
|
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
102 |
). |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
103 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
104 |
objs do:[:written | |
1545 | 105 |
written storeBinaryOn:outStream. |
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
106 |
]. |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
107 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
108 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
109 |
inStream := BinaryInputManager on:(outStream contents readStream). |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
110 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
111 |
objs do:[:expected | |read| |
1545 | 112 |
read := inStream nextObject. |
113 |
self assert:( read = expected). |
|
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
114 |
]. |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
115 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
116 |
" |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
117 |
self run:#testArrays1 |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
118 |
self new testArrays1 |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
119 |
" |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
120 |
! |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
121 |
|
1388 | 122 |
testBehavior |
123 |
|clsOut clsIn outStream boss inStream| |
|
124 |
||
125 |
Class withoutUpdatingChangesDo:[ |
|
1545 | 126 |
clsOut := Object |
127 |
subclass:#BinarioTestClass |
|
128 |
instanceVariableNames:'a b c' |
|
129 |
classVariableNames:'' |
|
130 |
poolDictionaries:'' |
|
131 |
category:'tests' |
|
132 |
inEnvironment:nil. |
|
1388 | 133 |
]. |
1545 | 134 |
|
1388 | 135 |
outStream := ByteArray new writeStream. |
136 |
boss := BinaryOutputManager new. |
|
137 |
clsOut storeBinaryClassOn:outStream manager:boss. |
|
138 |
||
139 |
inStream := BinaryInputManager on:(outStream contents readStream). |
|
140 |
BinaryIOManager nonexistingClassSignal handle:[:ex | |
|
1545 | 141 |
ex proceedWith:ex parameter |
142 |
] do:[ |
|
143 |
clsIn := inStream nextObject. |
|
1388 | 144 |
]. |
145 |
self assert:( clsIn name = clsOut name ). |
|
146 |
self assert:( clsIn superclass == clsOut superclass ). |
|
147 |
self assert:( clsIn instVarNames = clsOut instVarNames ). |
|
148 |
self assert:( clsIn category = clsOut category ). |
|
149 |
self assert:( clsIn poolDictionaries = clsOut poolDictionaries ). |
|
150 |
self assert:( clsIn methodDictionary sameContentsAs: clsOut methodDictionary ). |
|
151 |
||
152 |
" |
|
153 |
self run:#testBehavior |
|
154 |
self new testBehavior |
|
155 |
" |
|
156 |
! |
|
157 |
||
243 | 158 |
testByteArrays1 |
159 |
|objs outStream inStream| |
|
160 |
||
161 |
outStream := ByteArray new writeStream. |
|
162 |
||
163 |
objs := #( |
|
1545 | 164 |
[] |
165 |
[1] |
|
166 |
[1 2] |
|
167 |
[1 2 3] |
|
168 |
[1 2 3 4] |
|
169 |
[1 2 3 4 5] |
|
170 |
[1 2 3 4 5 6] |
|
171 |
[1 2 3 4 5 6 7] |
|
172 |
[1 2 3 4 5 6 7 8] |
|
173 |
[1 2 3 4 5 6 7 8 9] |
|
243 | 174 |
). |
175 |
||
176 |
objs do:[:written | |
|
1545 | 177 |
written storeBinaryOn:outStream. |
243 | 178 |
]. |
179 |
||
180 |
||
181 |
inStream := BinaryInputManager on:(outStream contents readStream). |
|
182 |
||
183 |
objs do:[:expected | |read| |
|
1545 | 184 |
read := inStream nextObject. |
185 |
self assert:( read = expected). |
|
243 | 186 |
]. |
187 |
||
188 |
" |
|
189 |
self run:#testByteArrays1 |
|
190 |
self new testByteArrays1 |
|
191 |
" |
|
192 |
! |
|
193 |
||
194 |
testByteArrays2 |
|
195 |
|outStream inStream test| |
|
196 |
||
197 |
test := [:obj | |
|
1545 | 198 |
|written read| |
243 | 199 |
|
1545 | 200 |
outStream := ByteArray new writeStream. |
201 |
written := obj. |
|
202 |
written storeBinaryOn:outStream. |
|
243 | 203 |
|
1545 | 204 |
inStream := BinaryInputManager on:(outStream contents readStream). |
243 | 205 |
|
1545 | 206 |
read := inStream nextObject. |
207 |
self assert:( read = written). |
|
243 | 208 |
]. |
209 |
||
210 |
test value:(1 to:254) asByteArray. |
|
211 |
test value:(1 to:255) asByteArray. |
|
212 |
test value:(0 to:255) asByteArray. |
|
213 |
||
214 |
test value:(ByteArray new:100). |
|
215 |
test value:(ByteArray new:127). |
|
216 |
test value:(ByteArray new:128). |
|
217 |
test value:(ByteArray new:129). |
|
218 |
test value:(ByteArray new:254). |
|
219 |
test value:(ByteArray new:255). |
|
220 |
test value:(ByteArray new:256). |
|
221 |
test value:(ByteArray new:257). |
|
222 |
test value:(ByteArray new:1000). |
|
223 |
test value:(ByteArray new:10000). |
|
224 |
test value:(ByteArray new:100000). |
|
225 |
test value:(ByteArray new:1000000). |
|
226 |
test value:(ByteArray new:10000000). |
|
227 |
||
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
228 |
test value:(ByteArray new:1000) beImmutable. |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
229 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
230 |
|
243 | 231 |
" |
232 |
self run:#testByteArrays2 |
|
233 |
self new testByteArrays2 |
|
234 |
" |
|
235 |
! |
|
236 |
||
1388 | 237 |
testCharacters |
238 |
|objs outStream inStream| |
|
239 |
||
240 |
outStream := ByteArray new writeStream. |
|
241 |
||
1545 | 242 |
objs := |
243 |
{ |
|
244 |
$a . |
|
245 |
(Character value:0) . |
|
246 |
(Character value:255) . |
|
247 |
(Character value:256) . |
|
248 |
(Character value:16rFFFF) . |
|
249 |
(Character value:16r10000) . |
|
250 |
(Character value:16rFFFFFF) . |
|
251 |
}. |
|
1388 | 252 |
|
253 |
objs do:[:written | |
|
1545 | 254 |
written storeBinaryOn:outStream. |
1388 | 255 |
]. |
256 |
||
257 |
||
258 |
inStream := BinaryInputManager on:(outStream contents readStream). |
|
259 |
||
260 |
objs do:[:expected | |read| |
|
1545 | 261 |
read := inStream nextObject. |
262 |
self assert:( read = expected). |
|
1388 | 263 |
]. |
264 |
||
265 |
" |
|
266 |
self run:#testCharacters |
|
267 |
self new testCharacters |
|
268 |
" |
|
269 |
! |
|
270 |
||
243 | 271 |
testIntegers1 |
649 | 272 |
|nums outStream bytes inStream verbose| |
273 |
||
274 |
verbose := false. |
|
1545 | 275 |
"/ verbose := true. |
243 | 276 |
|
277 |
outStream := ByteArray new writeStream. |
|
278 |
||
279 |
nums := #( |
|
1545 | 280 |
0 |
281 |
1 |
|
282 |
15 |
|
283 |
16 |
|
284 |
30 |
|
285 |
31 |
|
286 |
32 |
|
287 |
62 |
|
288 |
63 |
|
289 |
64 |
|
290 |
127 |
|
291 |
128 |
|
292 |
129 |
|
293 |
254 |
|
294 |
255 |
|
295 |
256 |
|
296 |
16r0FFF |
|
297 |
16r1000 |
|
298 |
16r1001 |
|
299 |
16r1FFF |
|
300 |
16r2000 |
|
301 |
16r2001 |
|
302 |
16r3FFF |
|
303 |
16r4000 |
|
304 |
16r4001 |
|
305 |
16r7FFF |
|
306 |
16r8000 |
|
307 |
16r8001 |
|
308 |
16rFFFF |
|
309 |
16r10000 |
|
310 |
16r10001 |
|
243 | 311 |
|
1545 | 312 |
16r3FFFFF |
313 |
16r400000 |
|
314 |
16r400001 |
|
315 |
16r7FFFFF |
|
316 |
16r800000 |
|
317 |
16r800001 |
|
318 |
16rFFFFFF |
|
319 |
16r1000000 |
|
320 |
16r1000001 |
|
243 | 321 |
|
1545 | 322 |
16r3FFFFFFF "/ largest SmallInt on 32bit machines |
323 |
16r40000000 |
|
324 |
16r40000001 |
|
325 |
16r7FFFFFFF "/ largest FullInt on 32bit machines |
|
326 |
16r80000000 |
|
327 |
16r80000001 |
|
328 |
16rFFFFFFFF "/ largest unsigned FullInt on 32bit machines |
|
329 |
16r100000000 |
|
330 |
16r100000001 |
|
243 | 331 |
|
1545 | 332 |
16r3FFFFFFFFF |
333 |
16r4000000000 |
|
334 |
16r4000000001 |
|
335 |
16r7FFFFFFFFF |
|
336 |
16r8000000000 |
|
337 |
16r8000000001 |
|
338 |
16rFFFFFFFFFF |
|
339 |
16r10000000000 |
|
340 |
16r10000000001 |
|
243 | 341 |
|
1545 | 342 |
16r3FFFFFFFFFFF |
343 |
16r400000000000 |
|
344 |
16r400000000001 |
|
345 |
16r7FFFFFFFFFFF |
|
346 |
16r800000000000 |
|
347 |
16r800000000001 |
|
348 |
16rFFFFFFFFFFFF |
|
349 |
16r1000000000000 |
|
350 |
16r1000000000001 |
|
243 | 351 |
|
1545 | 352 |
16r3FFFFFFFFFFFFF |
353 |
16r40000000000000 |
|
354 |
16r40000000000001 |
|
355 |
16r7FFFFFFFFFFFFF |
|
356 |
16r80000000000000 |
|
357 |
16r80000000000001 |
|
358 |
16rFFFFFFFFFFFFFF |
|
359 |
16r100000000000000 |
|
360 |
16r100000000000001 |
|
243 | 361 |
|
1545 | 362 |
16r3FFFFFFFFFFFFFFF |
363 |
16r4000000000000000 |
|
364 |
16r4000000000000001 |
|
365 |
16r7FFFFFFFFFFFFFFF |
|
366 |
16r8000000000000000 |
|
367 |
16r8000000000000001 |
|
368 |
16rFFFFFFFFFFFFFFFF |
|
369 |
16r10000000000000000 |
|
370 |
16r10000000000000001 |
|
243 | 371 |
|
1545 | 372 |
16r3FFFFFFFFFFFFFFFFF |
373 |
16r400000000000000000 |
|
374 |
16r400000000000000001 |
|
375 |
16r7FFFFFFFFFFFFFFFFF |
|
376 |
16r800000000000000000 |
|
377 |
16r800000000000000001 |
|
378 |
16rFFFFFFFFFFFFFFFFFF |
|
379 |
16r1000000000000000000 |
|
380 |
16r1000000000000000001 |
|
243 | 381 |
|
1545 | 382 |
16r3FFFFFFFFFFFFFFFFFFF "/ largest SmallInt on 64bit machines |
383 |
16r40000000000000000000 "/ smallest SmallInt on 64bit machines |
|
384 |
16r40000000000000000001 |
|
385 |
16r7FFFFFFFFFFFFFFFFFFF "/ largest FullInt on 64bit machines |
|
386 |
16r80000000000000000000 |
|
387 |
16r80000000000000000001 |
|
388 |
16rFFFFFFFFFFFFFFFFFFFF "/ largest unsigned FullInt on 64bit machines |
|
389 |
16r100000000000000000000 |
|
390 |
16r100000000000000000001 |
|
243 | 391 |
|
1545 | 392 |
16r3FFFFFFFFFFFFFFFFFFFF |
393 |
16r400000000000000000000 |
|
394 |
16r400000000000000000001 |
|
395 |
16r7FFFFFFFFFFFFFFFFFFFF |
|
396 |
16r800000000000000000000 |
|
397 |
16r800000000000000000001 |
|
398 |
16rFFFFFFFFFFFFFFFFFFFFF |
|
399 |
16r1000000000000000000000 |
|
400 |
16r1000000000000000000001 |
|
1399 | 401 |
|
1545 | 402 |
16r7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF |
403 |
16r80000000000000000000000000000000000000 |
|
404 |
16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF |
|
243 | 405 |
). |
406 |
||
407 |
nums do:[:written | |
|
1545 | 408 |
|bytes read| |
554 | 409 |
|
1545 | 410 |
bytes := written binaryStoreBytes. |
411 |
verbose ifTrue:[ |
|
412 |
Transcript show:written. |
|
413 |
Transcript show:' -> '. |
|
414 |
Transcript showCR:bytes. |
|
415 |
]. |
|
416 |
read := Object fromBinaryStoreBytes:bytes. |
|
417 |
self assert:(read = written). |
|
554 | 418 |
]. |
419 |
||
420 |
nums do:[:written | |
|
1545 | 421 |
|bytes read| |
554 | 422 |
|
1545 | 423 |
bytes := written negated binaryStoreBytes. |
424 |
verbose ifTrue:[ |
|
425 |
Transcript show:written. |
|
426 |
Transcript show:' -> '. |
|
427 |
Transcript showCR:bytes. |
|
428 |
]. |
|
429 |
read := Object fromBinaryStoreBytes:bytes. |
|
430 |
self assert:(read = written negated). |
|
554 | 431 |
]. |
432 |
||
433 |
nums do:[:written | |
|
1545 | 434 |
written storeBinaryOn:outStream. |
435 |
written negated storeBinaryOn:outStream. |
|
243 | 436 |
]. |
437 |
||
554 | 438 |
bytes := outStream contents. |
439 |
inStream := BinaryInputManager on:(bytes readStream). |
|
243 | 440 |
|
441 |
nums do:[:expected | |read| |
|
1545 | 442 |
read := inStream nextObject. |
443 |
self assert:( read = expected). |
|
243 | 444 |
|
1545 | 445 |
read := inStream nextObject. |
446 |
self assert:( read = expected negated). |
|
243 | 447 |
|
448 |
]. |
|
449 |
||
1399 | 450 |
"/ some very big numbers... |
451 |
#( 10 20 30 50 100) do:[:n | |
|
1545 | 452 |
|written read| |
453 |
||
454 |
bytes := (written := n factorial) binaryStoreBytes. |
|
455 |
verbose ifTrue:[ |
|
456 |
Transcript show:written. |
|
457 |
Transcript show:' -> '. |
|
458 |
Transcript showCR:bytes. |
|
459 |
]. |
|
460 |
read := Object fromBinaryStoreBytes:bytes. |
|
461 |
self assert:(read = written). |
|
1399 | 462 |
|
1545 | 463 |
bytes := (written := n factorial negated) binaryStoreBytes. |
464 |
verbose ifTrue:[ |
|
465 |
Transcript show:written. |
|
466 |
Transcript show:' -> '. |
|
467 |
Transcript showCR:bytes. |
|
468 |
]. |
|
469 |
read := Object fromBinaryStoreBytes:bytes. |
|
470 |
self assert:(read = written). |
|
1399 | 471 |
]. |
1545 | 472 |
|
243 | 473 |
" |
474 |
self run:#testIntegers1 |
|
475 |
self new testIntegers1 |
|
476 |
" |
|
649 | 477 |
|
478 |
"Modified: / 10-01-2012 / 19:23:44 / cg" |
|
243 | 479 |
! |
480 |
||
1388 | 481 |
testNumbers1 |
482 |
|floats fractions nums outStream bytes inStream verbose| |
|
483 |
||
484 |
verbose := false. |
|
485 |
||
486 |
outStream := ByteArray new writeStream. |
|
487 |
||
488 |
floats := #( |
|
1545 | 489 |
0.0 |
490 |
1.0 |
|
491 |
2.0 |
|
492 |
1.23456 |
|
493 |
1e17 |
|
1388 | 494 |
). |
495 |
fractions := { |
|
1545 | 496 |
(1/2) . |
497 |
(3/17) . |
|
498 |
(1234567890123456789/17) . |
|
499 |
(12345678901234567890123456789/17) . |
|
500 |
(17/1234567890123456789) . |
|
501 |
(17/12345678901234567890123456789) . |
|
502 |
(1234567890123456788/1234567890123456789) . |
|
503 |
(12345678901234567890123456788/12345678901234567890123456789) . |
|
1388 | 504 |
}. |
505 |
nums := floats , fractions. |
|
1545 | 506 |
|
1388 | 507 |
nums do:[:written | |
1545 | 508 |
|bytes read| |
1388 | 509 |
|
1545 | 510 |
bytes := written binaryStoreBytes. |
511 |
verbose ifTrue:[ |
|
512 |
Transcript show:written. |
|
513 |
Transcript show:' -> '. |
|
514 |
Transcript showCR:bytes. |
|
515 |
]. |
|
516 |
read := Object fromBinaryStoreBytes:bytes. |
|
517 |
self assert:(read = written). |
|
1388 | 518 |
]. |
519 |
||
520 |
nums do:[:written | |
|
1545 | 521 |
|bytes read| |
1388 | 522 |
|
1545 | 523 |
bytes := written negated binaryStoreBytes. |
524 |
verbose ifTrue:[ |
|
525 |
Transcript show:written. |
|
526 |
Transcript show:' -> '. |
|
527 |
Transcript showCR:bytes. |
|
528 |
]. |
|
529 |
read := Object fromBinaryStoreBytes:bytes. |
|
530 |
self assert:(read = written negated). |
|
1388 | 531 |
]. |
532 |
||
533 |
nums do:[:written | |
|
1545 | 534 |
written storeBinaryOn:outStream. |
535 |
written negated storeBinaryOn:outStream. |
|
1388 | 536 |
]. |
537 |
||
538 |
bytes := outStream contents. |
|
539 |
inStream := BinaryInputManager on:(bytes readStream). |
|
540 |
||
541 |
nums do:[:expected | |read| |
|
1545 | 542 |
read := inStream nextObject. |
543 |
self assert:( read = expected). |
|
1388 | 544 |
|
1545 | 545 |
read := inStream nextObject. |
546 |
self assert:( read = expected negated). |
|
1388 | 547 |
|
548 |
]. |
|
549 |
||
550 |
" |
|
551 |
self run:#testNumbers1 |
|
552 |
self new testNumbers1 |
|
553 |
" |
|
554 |
! |
|
555 |
||
1397 | 556 |
testNumbers1_differentFormat |
557 |
"BOSS, formatVersion2 had a bug in always storing floats & doubles in |
|
1545 | 558 |
native byte order. |
1397 | 559 |
This has been changed in formatVersion3, to MSB (which is the expected behavior). |
560 |
To read old-style BOSS objects, the usedFormat an be explicitly set..." |
|
1545 | 561 |
|
1397 | 562 |
|manager outStream bytes objectInStream verbose written read tmpBytes| |
563 |
||
564 |
verbose := false. |
|
565 |
outStream := ByteArray new writeStream. |
|
566 |
||
567 |
"/ write in old format |
|
568 |
manager := BinaryOutputManager new. |
|
569 |
manager usedFormat:2. |
|
570 |
manager store:(written := 1.2345) on:outStream. |
|
571 |
||
572 |
bytes := outStream contents. |
|
1545 | 573 |
|
1397 | 574 |
"/ read in old format |
575 |
objectInStream := BinaryInputManager on:(bytes readStream). |
|
576 |
objectInStream usedFormat:2. |
|
577 |
read := objectInStream nextObject. |
|
1545 | 578 |
|
1397 | 579 |
self assert:(read = written). |
580 |
||
581 |
"/ write in old format |
|
582 |
manager := BinaryOutputManager new. |
|
583 |
manager usedFormat:2. |
|
584 |
manager store:(written := 1.2345) on:outStream. |
|
585 |
||
586 |
bytes := outStream contents. |
|
587 |
||
588 |
"/ read in new format |
|
589 |
objectInStream := BinaryInputManager on:(bytes readStream). |
|
590 |
objectInStream usedFormat:3. |
|
591 |
read := objectInStream nextObject. |
|
592 |
||
593 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
1545 | 594 |
self assert:(read = written). |
1397 | 595 |
] ifFalse:[ |
1545 | 596 |
"/ expect wrong values!! |
597 |
self assert:(read ~= written). |
|
598 |
"/ in wrong byte order |
|
599 |
tmpBytes := ByteArray new:8. |
|
600 |
tmpBytes doubleAt:1 put:read. |
|
601 |
tmpBytes reverse. |
|
602 |
self assert:(tmpBytes doubleAt:1) = written. |
|
1397 | 603 |
]. |
1545 | 604 |
|
1397 | 605 |
" |
606 |
self run:#testNumbers1_differentFormat |
|
607 |
self new testNumbers1_differentFormat |
|
608 |
" |
|
609 |
! |
|
610 |
||
555 | 611 |
testOrderedCollection1 |
612 |
|o rw| |
|
613 |
||
614 |
rw := [:obj | |
|
1545 | 615 |
|read outStream inStream| |
555 | 616 |
|
1545 | 617 |
outStream := ByteArray new writeStream. |
555 | 618 |
|
1545 | 619 |
obj storeBinaryOn:outStream. |
555 | 620 |
|
1545 | 621 |
inStream := BinaryInputManager on:(outStream contents readStream). |
622 |
read := inStream nextObject. |
|
623 |
self assert:( read = obj). |
|
555 | 624 |
]. |
625 |
||
626 |
o := OrderedCollection new. |
|
627 |
rw value:o. |
|
628 |
||
629 |
o add:1. |
|
630 |
rw value:o. |
|
631 |
||
632 |
o add:2. |
|
633 |
rw value:o. |
|
634 |
||
635 |
o add:#(). |
|
636 |
rw value:o. |
|
637 |
||
638 |
o add:#(1 2 3). |
|
639 |
rw value:o. |
|
640 |
||
641 |
" |
|
642 |
self run:#testOrderedCollection1 |
|
643 |
self new testOrderedCollection1 |
|
644 |
" |
|
645 |
! |
|
646 |
||
339 | 647 |
testSaveReadBOS |
648 |
||
1545 | 649 |
|objStored childStored childrenStored objLoaded childrenLoaded childLoaded |
1345 | 650 |
fn bos privateClass didConvert verbose| |
339 | 651 |
|
1345 | 652 |
verbose := false. |
1349 | 653 |
"/ verbose := true. |
1545 | 654 |
|
339 | 655 |
Class withoutUpdatingChangesDo:[ |
1545 | 656 |
HierarchicalItem subclass:#XHierarchicalItem |
657 |
instanceVariableNames:'' |
|
658 |
classVariableNames:'' |
|
659 |
poolDictionaries:'' |
|
660 |
category:'Views-Support'. |
|
614 | 661 |
|
1545 | 662 |
privateClass := Smalltalk at:#XHierarchicalItem. |
339 | 663 |
]. |
664 |
||
1345 | 665 |
objStored := privateClass new. |
666 |
childStored := privateClass new. |
|
667 |
objStored add: childStored. |
|
668 |
childStored instVarNamed:#width put:privateClass. |
|
339 | 669 |
|
1345 | 670 |
self assert:(objStored hasChildren). |
671 |
self assert:(objStored children size == 1). |
|
672 |
self assert:(objStored children first == childStored). |
|
1545 | 673 |
|
555 | 674 |
"/ fn := '/tmp/HI' asFilename. |
675 |
fn := Filename newTemporary. |
|
339 | 676 |
bos := BinaryObjectStorage onNew: (fn writeStream). |
1345 | 677 |
bos nextPut: objStored. |
614 | 678 |
|
1345 | 679 |
verbose ifTrue:[ |
1545 | 680 |
Transcript showCR:'object saved:'. |
681 |
"/ obj inspect. |
|
682 |
ObjectMemory dumpObject:objStored. |
|
683 |
]. |
|
339 | 684 |
bos close. |
685 |
||
614 | 686 |
didConvert := false. |
687 |
||
1345 | 688 |
"/ now, change the class (stored object is old) |
339 | 689 |
Class withoutUpdatingChangesDo:[ |
1545 | 690 |
verbose ifTrue:[ |
691 |
Transcript showCR:'changing the class (add a slot)...'. |
|
692 |
]. |
|
693 |
privateClass addInstVarName:'foo'. |
|
694 |
verbose ifTrue:[ |
|
695 |
Transcript showCR:'done.'. |
|
696 |
]. |
|
339 | 697 |
]. |
698 |
||
699 |
bos := BinaryObjectStorage onOld: fn readStream. |
|
700 |
BinaryIOManager requestConversionSignal handle:[:ex| |
|
1545 | 701 |
| oldObject newClass | |
339 | 702 |
|
1545 | 703 |
newClass := ex parameter key. |
704 |
oldObject := ex parameter value. |
|
705 |
verbose ifTrue:[ |
|
706 |
Transcript showCR: 'converting...'. |
|
707 |
]. |
|
708 |
didConvert := true. |
|
709 |
ex proceedWith: (newClass cloneFrom: oldObject). |
|
339 | 710 |
] do:[ |
1545 | 711 |
BinaryIOManager invalidClassSignal handle:[:ex2| |
712 |
| oldClass newClass proceedClass | |
|
339 | 713 |
|
1545 | 714 |
newClass := Smalltalk at: ex2 parameter name asSymbol. |
715 |
oldClass := ex2 parameter. |
|
339 | 716 |
|
1545 | 717 |
verbose ifTrue:[ |
718 |
Transcript showCR: 'will convert instance of ',oldClass name. |
|
719 |
]. |
|
720 |
proceedClass :=(((newClass isSubclassOf: HierarchicalItem) or:[newClass == HierarchicalItem]) ifTrue:[newClass] ifFalse:[oldClass]). |
|
721 |
ex2 proceedWith: proceedClass. |
|
722 |
] do:[ |
|
723 |
objLoaded := bos next. |
|
724 |
verbose ifTrue:[ |
|
725 |
"/ obj inspect. |
|
726 |
Transcript showCR:'object restored (new class):'. |
|
727 |
ObjectMemory dumpObject:objLoaded. |
|
728 |
]. |
|
729 |
]. |
|
339 | 730 |
]. |
731 |
||
614 | 732 |
self assert:(didConvert). |
1345 | 733 |
self assert:(objLoaded class instSize == (HierarchicalItem instSize + 1)). |
734 |
||
735 |
self assert:(objLoaded hasChildren). |
|
736 |
self assert:(objLoaded children size == 1). |
|
737 |
self assert:(objLoaded children == (objLoaded instVarNamed:#children) ). |
|
614 | 738 |
|
339 | 739 |
"Created: / 26-09-2007 / 18:21:11 / cg" |
614 | 740 |
"Modified: / 07-08-2011 / 15:29:35 / cg" |
339 | 741 |
! |
742 |
||
243 | 743 |
testStrings1 |
744 |
|objs outStream inStream| |
|
745 |
||
746 |
outStream := ByteArray new writeStream. |
|
747 |
||
748 |
objs := #( |
|
1545 | 749 |
'' |
750 |
'1' |
|
751 |
'12' |
|
752 |
'123' |
|
753 |
"/ 1 2 3 4 5 6 7 8 9 0 1 2 |
|
754 |
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678' |
|
243 | 755 |
|
1545 | 756 |
"/ 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
757 |
'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345' |
|
243 | 758 |
|
1545 | 759 |
"/ 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
760 |
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456' |
|
243 | 761 |
|
1545 | 762 |
"/ 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
763 |
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567' |
|
243 | 764 |
). |
765 |
||
766 |
objs do:[:written | |
|
1545 | 767 |
written storeBinaryOn:outStream. |
243 | 768 |
]. |
769 |
||
770 |
||
771 |
inStream := BinaryInputManager on:(outStream contents readStream). |
|
772 |
||
773 |
objs do:[:expected | |read| |
|
1545 | 774 |
read := inStream nextObject. |
775 |
self assert:( read = expected). |
|
243 | 776 |
]. |
777 |
||
778 |
" |
|
779 |
self run:#testStrings1 |
|
780 |
self new testStrings1 |
|
781 |
" |
|
782 |
! |
|
783 |
||
784 |
testStrings2 |
|
785 |
|outStream inStream test| |
|
786 |
||
787 |
test := [:obj | |
|
1545 | 788 |
|written read| |
243 | 789 |
|
1545 | 790 |
outStream := ByteArray new writeStream. |
791 |
written := obj. |
|
792 |
written storeBinaryOn:outStream. |
|
243 | 793 |
|
1545 | 794 |
inStream := BinaryInputManager on:(outStream contents readStream). |
243 | 795 |
|
1545 | 796 |
read := inStream nextObject. |
797 |
self assert:( read = written). |
|
243 | 798 |
]. |
799 |
||
1386 | 800 |
test value:(String new:14). |
801 |
test value:(String new:15). |
|
802 |
test value:(String new:16). |
|
803 |
test value:(String new:30). |
|
804 |
test value:(String new:31). |
|
805 |
test value:(String new:32). |
|
806 |
test value:(String new:62). |
|
807 |
test value:(String new:63). |
|
808 |
test value:(String new:64). |
|
809 |
test value:(String new:65). |
|
243 | 810 |
test value:(String new:100). |
811 |
test value:(String new:127). |
|
812 |
test value:(String new:128). |
|
813 |
test value:(String new:129). |
|
814 |
test value:(String new:254). |
|
815 |
test value:(String new:255). |
|
816 |
test value:(String new:256). |
|
817 |
test value:(String new:257). |
|
818 |
test value:(String new:1000). |
|
819 |
test value:(String new:10000). |
|
820 |
test value:(String new:100000). |
|
821 |
test value:(String new:1000000). |
|
822 |
test value:(String new:10000000). |
|
823 |
||
1274
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
824 |
test value:(ImmutableString new:1000). |
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
825 |
|
8501a2b641b2
class: RegressionTests::BinaryIOTests
Stefan Vogel <sv@exept.de>
parents:
693
diff
changeset
|
826 |
|
243 | 827 |
" |
828 |
self run:#testStrings2 |
|
829 |
self new testStrings2 |
|
830 |
" |
|
693
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
831 |
! |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
832 |
|
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
833 |
test_store_retrieve_string_and_array_01 |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
834 |
|original retrieved hello inStream outStream| |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
835 |
|
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
836 |
hello := 'hello'. |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
837 |
original := Array with:hello with:hello. |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
838 |
|
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
839 |
[ |
1545 | 840 |
outStream := 'data.bos' asFilename writeStream binary. |
841 |
original storeBinaryOn:outStream. |
|
842 |
outStream close. |
|
693
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
843 |
|
1545 | 844 |
inStream := 'data.bos' asFilename readStream binary. |
845 |
retrieved := Object readBinaryFrom:inStream. |
|
846 |
inStream close. |
|
693
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
847 |
] ensure:[ |
1545 | 848 |
'data.bos' asFilename delete |
693
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
849 |
]. |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
850 |
|
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
851 |
self assert:( (original at:1) == (original at:2) ). "must be identical" |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
852 |
self assert:( (retrieved at:1) == (retrieved at:2) ). "must be identical" |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
853 |
|
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
854 |
" |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
855 |
self new test01_store_retrieve_string_and_array_01 |
29463cb88dd5
added: #test_store_retrieve_string_and_array_01
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
856 |
" |
243 | 857 |
! ! |
858 |
||
859 |
!BinaryIOTests class methodsFor:'documentation'! |
|
860 |
||
861 |
version |
|
862 |
^ '$Header$' |
|
554 | 863 |
! |
864 |
||
865 |
version_CVS |
|
866 |
^ '$Header$' |
|
243 | 867 |
! ! |
1567
e17701a073f9
Added abstract VMSpawningTestCase
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1564
diff
changeset
|
868 |