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