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