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