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