1815
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1793
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2002 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:goodies/regression' }"
|
|
15 |
|
|
16 |
"{ NameSpace: RegressionTests }"
|
|
17 |
|
|
18 |
TestCase subclass:#CompressionStreamTest
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'tests-Regression-Streams'
|
|
23 |
!
|
|
24 |
|
|
25 |
!CompressionStreamTest class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2002 by eXept Software AG
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
extracted testCases from CompressionStream
|
|
44 |
"
|
|
45 |
! !
|
|
46 |
|
|
47 |
!CompressionStreamTest class methodsFor:'tests'!
|
|
48 |
|
|
49 |
compress
|
|
50 |
"
|
|
51 |
self compress
|
|
52 |
"
|
|
53 |
|fileContents in zip out|
|
|
54 |
|
|
55 |
fileContents := 'symbols.stc' asFilename contentsOfEntireFile.
|
|
56 |
|
|
57 |
in := fileContents readStream.
|
|
58 |
out := FileStream newFileNamed:'YYY.gz'.
|
|
59 |
out ifNil:[ ^ self ].
|
|
60 |
[
|
|
61 |
zip := ZipStream writeOpenOn:out.
|
|
62 |
|
|
63 |
[in atEnd] whileFalse:[ |buf|
|
|
64 |
buf := in nextAvailable:512.
|
|
65 |
buf do:[:n|
|
|
66 |
zip nextPut:n
|
|
67 |
]
|
|
68 |
].
|
|
69 |
] ensure:[
|
|
70 |
zip notNil ifTrue:[ zip close ].
|
|
71 |
out isOpen ifTrue: [ out close ].
|
|
72 |
].
|
|
73 |
!
|
|
74 |
|
|
75 |
compress:fn
|
|
76 |
"
|
|
77 |
self compress
|
|
78 |
"
|
|
79 |
|fileContents in zip out|
|
|
80 |
|
|
81 |
fileContents := fn asFilename contentsOfEntireFile.
|
|
82 |
|
|
83 |
in := fileContents readStream.
|
|
84 |
out := FileStream newFileNamed:'YYY.gz'.
|
|
85 |
out ifNil:[ ^ self ].
|
|
86 |
[
|
|
87 |
zip := ZipStream writeOpenOn:out.
|
|
88 |
|
|
89 |
[in atEnd] whileFalse:[ |buf|
|
|
90 |
buf := in nextAvailable:512.
|
|
91 |
buf do:[:n|
|
|
92 |
zip nextPut:n
|
|
93 |
]
|
|
94 |
].
|
|
95 |
] ensure:[
|
|
96 |
zip notNil ifTrue:[ zip close ].
|
|
97 |
out close.
|
|
98 |
].
|
|
99 |
!
|
|
100 |
|
|
101 |
testUncompress
|
|
102 |
"
|
|
103 |
self testUncompress #(521755 686495 false) #(521755 686495 false)
|
|
104 |
"
|
|
105 |
|stream zipStream contents contentsOfOriginal|
|
|
106 |
|
|
107 |
[
|
|
108 |
stream := 'YYY.gz' asFilename readStream.
|
|
109 |
zipStream := ZipStream readOpenOn:stream.
|
|
110 |
contents := zipStream contents.
|
|
111 |
] ensure:[
|
|
112 |
zipStream notNil ifTrue:[zipStream close].
|
|
113 |
stream notNil ifTrue:[stream close].
|
|
114 |
].
|
|
115 |
stream := 'symbols.stc' asFilename readStream.
|
|
116 |
contentsOfOriginal := stream contentsOfEntireFile.
|
|
117 |
stream close.
|
|
118 |
^ Array with: contents size
|
|
119 |
with: contentsOfOriginal size
|
|
120 |
with: contents = contentsOfOriginal.
|
|
121 |
!
|
|
122 |
|
|
123 |
testUncompress: fn
|
|
124 |
"
|
|
125 |
(self testUncompress: 'symbols.stc') inspect
|
|
126 |
"
|
|
127 |
|stream zipStream contents contentsOfOriginal|
|
|
128 |
|
|
129 |
self compress: fn.
|
|
130 |
[
|
|
131 |
stream := 'YYY.gz' asFilename readStream.
|
|
132 |
zipStream := ZipStream readOpenOn:stream.
|
|
133 |
contents := zipStream contents.
|
|
134 |
] ensure:[
|
|
135 |
zipStream notNil ifTrue:[zipStream close].
|
|
136 |
stream notNil ifTrue:[stream close].
|
|
137 |
].
|
|
138 |
stream := fn asFilename readStream.
|
|
139 |
contentsOfOriginal := stream contentsOfEntireFile.
|
|
140 |
stream close.
|
|
141 |
^ Array with: contents size
|
|
142 |
with: contentsOfOriginal size
|
|
143 |
with: contents = contentsOfOriginal.
|
|
144 |
!
|
|
145 |
|
|
146 |
uncompress
|
|
147 |
"
|
|
148 |
self uncompress
|
|
149 |
"
|
|
150 |
|stream zipStream contents|
|
|
151 |
|
|
152 |
[
|
|
153 |
stream := 'YYY.gz' asFilename readStream.
|
|
154 |
zipStream := ZipStream readOpenOn:stream.
|
|
155 |
contents := zipStream contents.
|
|
156 |
] ensure:[
|
|
157 |
zipStream notNil ifTrue:[zipStream close].
|
|
158 |
(stream notNil and: [stream isOpen]) ifTrue:[stream close].
|
|
159 |
].
|
|
160 |
^ contents
|
|
161 |
! !
|
|
162 |
|
|
163 |
!CompressionStreamTest class methodsFor:'ttt'!
|
|
164 |
|
|
165 |
compress:fn toFileNamed:aName
|
|
166 |
"
|
|
167 |
self compress:'symbols.stc' toFileNamed:'YYY'.
|
|
168 |
"
|
|
169 |
|sourceFile in zip out zipFile|
|
|
170 |
|
|
171 |
sourceFile := fn asFilename.
|
|
172 |
sourceFile exists ifFalse:[self error].
|
|
173 |
|
|
174 |
zipFile := aName asFilename.
|
|
175 |
zipFile := zipFile withSuffix:'gz'.
|
|
176 |
zipFile exists ifTrue:[ zipFile remove ].
|
|
177 |
|
|
178 |
in := sourceFile readStream.
|
|
179 |
out := FileStream newFileNamed:zipFile.
|
|
180 |
|
|
181 |
[
|
|
182 |
in := sourceFile readStream.
|
|
183 |
in binary.
|
|
184 |
out := FileStream newFileNamed:zipFile.
|
|
185 |
out binary.
|
|
186 |
zip := ZipStream writeOpenOn:out.
|
|
187 |
zip binary.
|
|
188 |
|
|
189 |
[in atEnd] whileFalse:[ |buf|
|
|
190 |
buf := in nextAvailable:512.
|
|
191 |
buf do:[:n|
|
|
192 |
zip nextPut:n
|
|
193 |
]
|
|
194 |
].
|
|
195 |
] ensure:[
|
|
196 |
zip notNil ifTrue:[ zip close ].
|
|
197 |
in notNil ifTrue:[ in close ].
|
|
198 |
out notNil ifTrue:[ out close ].
|
|
199 |
|
|
200 |
].
|
|
201 |
^ zipFile
|
|
202 |
!
|
|
203 |
|
|
204 |
test
|
|
205 |
"
|
|
206 |
self test
|
|
207 |
"
|
|
208 |
|zipFile srcFile oldContents newContents s|
|
|
209 |
|
|
210 |
srcFile := 'symbols.stc' asFilename.
|
|
211 |
zipFile := 'YYY'.
|
|
212 |
|
|
213 |
self compress:srcFile toFileNamed:zipFile.
|
|
214 |
newContents := self uncompressFileNamed:zipFile.
|
|
215 |
oldContents := srcFile binaryContentsOfEntireFile asString.
|
|
216 |
newContents := newContents asString.
|
|
217 |
|
|
218 |
oldContents keysAndValuesDo:[:i :v|
|
|
219 |
s := newContents at:i ifAbsent:nil.
|
|
220 |
v = s ifFalse:[
|
|
221 |
Transcript showCR:'#ERROR#'.
|
|
222 |
self halt.
|
|
223 |
^ self
|
|
224 |
].
|
|
225 |
Transcript show:v.
|
|
226 |
].
|
|
227 |
self halt.
|
|
228 |
!
|
|
229 |
|
|
230 |
uncompressFileNamed:aName
|
|
231 |
"
|
|
232 |
self uncompressFileNamed:'YYY'
|
|
233 |
"
|
|
234 |
|stream zipFile zipStream outStream c|
|
|
235 |
|
|
236 |
zipFile := aName asFilename.
|
|
237 |
zipFile := zipFile withSuffix:'gz'.
|
|
238 |
|
|
239 |
zipFile exists ifFalse:[ self error ].
|
|
240 |
|
|
241 |
[
|
|
242 |
stream := zipFile readStream.
|
|
243 |
stream binary.
|
|
244 |
|
|
245 |
zipStream := ZipStream readOpenOn:stream.
|
|
246 |
zipStream binary.
|
|
247 |
|
|
248 |
outStream := #[] writeStream.
|
|
249 |
|
|
250 |
[ (c := zipStream next) notNil ] whileTrue:[
|
|
251 |
outStream nextPut:c
|
|
252 |
].
|
|
253 |
] ensure:[
|
|
254 |
zipStream notNil ifTrue:[zipStream close].
|
|
255 |
stream notNil ifTrue:[stream close].
|
|
256 |
].
|
|
257 |
^ outStream contents
|
|
258 |
! !
|
|
259 |
|
|
260 |
!CompressionStreamTest methodsFor:'helpers'!
|
|
261 |
|
|
262 |
doTest01:compressionStreamClass
|
|
263 |
"
|
|
264 |
ZipStream test
|
|
265 |
self test01_ZipStream
|
|
266 |
"
|
|
267 |
|original compressed contents in out zip|
|
|
268 |
|
1895
|
269 |
original := self originalTestFileContent.
|
1793
|
270 |
|
|
271 |
in := original readStream.
|
|
272 |
|
|
273 |
[ |b|
|
|
274 |
out := WriteStream on:(ByteArray new:10).
|
|
275 |
zip := compressionStreamClass writeOpenOn:out.
|
|
276 |
|
|
277 |
[in atEnd] whileFalse:[
|
|
278 |
zip nextPut:in next
|
|
279 |
]
|
|
280 |
] ensure:[ zip notNil ifTrue:[ zip close ] ].
|
|
281 |
|
|
282 |
compressed := out contents.
|
|
283 |
[ |b|
|
|
284 |
zip := compressionStreamClass readOpenOn:(compressed readStream).
|
|
285 |
out := String writeStream.
|
|
286 |
|
|
287 |
[ (b := zip next) notNil ] whileTrue:[ out nextPut:b ]
|
|
288 |
|
|
289 |
] ensure:[
|
|
290 |
zip notNil ifTrue:[ zip close ].
|
|
291 |
contents := out contents.
|
|
292 |
|
|
293 |
Transcript showCR:(contents size).
|
|
294 |
Transcript showCR:(compressed size).
|
|
295 |
].
|
|
296 |
|
|
297 |
original = contents ifFalse:[
|
|
298 |
self error:'contents differs'.
|
|
299 |
^ self
|
|
300 |
].
|
|
301 |
Transcript showCR:'OK'.
|
1895
|
302 |
!
|
|
303 |
|
|
304 |
originalTestFileContent
|
1896
|
305 |
^ (OperatingSystem pathOfSTXExecutable asFilename asAbsoluteFilename directory / 'smalltalk.rc') contentsOfEntireFile
|
1793
|
306 |
! !
|
|
307 |
|
|
308 |
!CompressionStreamTest methodsFor:'tests'!
|
|
309 |
|
|
310 |
test01_ZipStream
|
|
311 |
"
|
|
312 |
ZipStream test
|
|
313 |
self test01_ZipStream
|
|
314 |
"
|
|
315 |
self doTest01:ZipStream
|
|
316 |
!
|
|
317 |
|
|
318 |
test02_ZipStream
|
|
319 |
"
|
|
320 |
ZipStream testFile
|
|
321 |
"
|
|
322 |
|fileContents in zip out gzipCmd|
|
|
323 |
|
1895
|
324 |
fileContents := self originalTestFileContent.
|
1793
|
325 |
|
|
326 |
in := fileContents readStream.
|
|
327 |
out := FileStream newFileNamed:'YYY.gz'.
|
|
328 |
out ifNil:[ ^ self ].
|
|
329 |
|
|
330 |
[
|
|
331 |
zip := ZipStream writeOpenOn:out.
|
|
332 |
|
|
333 |
[in atEnd] whileFalse:[ |buf|
|
|
334 |
buf := in nextAvailable:512.
|
|
335 |
buf do:[:n|
|
|
336 |
zip nextPut:n
|
|
337 |
]
|
|
338 |
].
|
|
339 |
] ensure:[
|
|
340 |
zip notNil ifTrue:[ zip close ].
|
|
341 |
out close.
|
|
342 |
].
|
|
343 |
gzipCmd := 'gzip -dc YYY.gz > YYY; diff YYY smalltalk.rc'.
|
|
344 |
|
|
345 |
Transcript showCR:gzipCmd.
|
|
346 |
gzipCmd printCR.
|
|
347 |
!
|
|
348 |
|
|
349 |
test03_ZipStream_testUnixAgainstClass
|
|
350 |
"
|
|
351 |
CompressionStream doTestUnixAgainstClass
|
|
352 |
"
|
|
353 |
|stream time file zipCont cmdCont|
|
|
354 |
|
1815
|
355 |
self
|
|
356 |
skipIf:OperatingSystem isUNIXlike not
|
|
357 |
description:'test is only for linux'.
|
|
358 |
|
1816
|
359 |
self
|
|
360 |
skipIf:true
|
|
361 |
description:'zipStream contents returns not enough memory... pls someone fix ist'.
|
|
362 |
|
1793
|
363 |
file := '/boot/vmlinuz' asFilename.
|
|
364 |
file isReadable ifFalse:[^ self error:'not existant'].
|
|
365 |
|
|
366 |
time := Time millisecondsToRun:[ |zipStream|
|
|
367 |
zipStream := stream := zipCont := nil.
|
|
368 |
[
|
|
369 |
stream := file readStream.
|
|
370 |
zipStream := BZip2Stream readOpenOn:stream.
|
|
371 |
zipCont := zipStream contents.
|
|
372 |
] ensure:[
|
|
373 |
zipStream notNil ifTrue:[zipStream close].
|
|
374 |
stream notNil ifTrue:[stream close].
|
|
375 |
].
|
|
376 |
].
|
|
377 |
Transcript showCR:('STX Time : %1 Size: %2' bindWith:time with:(zipCont size)).
|
|
378 |
|
|
379 |
time := Time millisecondsToRun:[ |command|
|
|
380 |
cmdCont := stream := nil.
|
|
381 |
[
|
|
382 |
command := 'gunzip < ' , file pathName.
|
|
383 |
stream := PipeStream readingFrom:command.
|
|
384 |
cmdCont := stream contentsOfEntireFile.
|
|
385 |
|
|
386 |
] ensure:[
|
|
387 |
stream notNil ifTrue:[stream close].
|
|
388 |
]
|
|
389 |
].
|
|
390 |
Transcript showCR:('UNIX Time : %1 Size: %2' bindWith:time with:(cmdCont size)).
|
|
391 |
|
|
392 |
cmdCont = zipCont ifTrue:[ Transcript showCR:'OK' ]
|
|
393 |
ifFalse:[ self error:'contents differs' ].
|
|
394 |
!
|
|
395 |
|
|
396 |
test04_ZipStream_NextN
|
|
397 |
"
|
|
398 |
CompressionStream doTestNextN
|
|
399 |
"
|
|
400 |
|stream time file zipCont nxtCont|
|
|
401 |
|
1815
|
402 |
self
|
|
403 |
skipIf:OperatingSystem isUNIXlike not
|
|
404 |
description:'test is only for linux'.
|
|
405 |
|
1816
|
406 |
self
|
|
407 |
skipIf:true
|
|
408 |
description:'zipStream contents returns not enough memory... pls someone fix ist'.
|
|
409 |
|
1793
|
410 |
file := '/boot/vmlinuz' asFilename.
|
|
411 |
file isReadable ifFalse:[^ self error:'not existant'].
|
|
412 |
|
|
413 |
time := Time millisecondsToRun:[ |zipStream|
|
|
414 |
zipStream := stream := zipCont := nil.
|
|
415 |
[
|
|
416 |
stream := file readStream.
|
|
417 |
zipStream := BZip2Stream readOpenOn:stream.
|
|
418 |
zipCont := zipStream contents.
|
|
419 |
] ensure:[
|
|
420 |
zipStream notNil ifTrue:[zipStream close].
|
|
421 |
stream notNil ifTrue:[stream close].
|
|
422 |
].
|
|
423 |
].
|
|
424 |
Transcript showCR:('STX Time : %1 Size: %2' bindWith:time with:(zipCont size)).
|
|
425 |
|
|
426 |
time := Time millisecondsToRun:[ |zipStream wstream|
|
|
427 |
zipStream := stream := nxtCont := nil.
|
|
428 |
[
|
|
429 |
stream := file readStream.
|
|
430 |
wstream := String writeStream.
|
|
431 |
zipStream := BZip2Stream readOpenOn:stream.
|
|
432 |
|
|
433 |
[zipStream atEnd] whileFalse:[
|
|
434 |
wstream nextPutAll:(zipStream next:117)
|
|
435 |
].
|
|
436 |
nxtCont := wstream contents.
|
|
437 |
] ensure:[
|
|
438 |
zipStream notNil ifTrue:[zipStream close].
|
|
439 |
stream notNil ifTrue:[stream close].
|
|
440 |
].
|
|
441 |
].
|
|
442 |
Transcript showCR:('NEXT Time : %1 Size: %2' bindWith:time with:(nxtCont size)).
|
|
443 |
|
|
444 |
nxtCont = zipCont ifTrue:[ Transcript showCR:'OK' ]
|
|
445 |
ifFalse:[ self error:'contents differs' ].
|
|
446 |
!
|
|
447 |
|
|
448 |
test04_ZipStream_SkipN
|
|
449 |
"
|
|
450 |
CompressionStream doTestSkipN
|
|
451 |
"
|
|
452 |
|stream time file skpCont nxtCont skip|
|
|
453 |
|
1815
|
454 |
self
|
|
455 |
skipIf:OperatingSystem isUNIXlike not
|
|
456 |
description:'test is only for linux'.
|
|
457 |
|
1816
|
458 |
self
|
|
459 |
skipIf:true
|
|
460 |
description:'zipStream contents returns not enough memory... pls someone fix ist'.
|
|
461 |
|
1793
|
462 |
file := '/boot/vmlinuz' asFilename.
|
|
463 |
file isReadable ifFalse:[^ self error:'not existant'].
|
|
464 |
|
|
465 |
skip := 6885379.
|
|
466 |
|
|
467 |
time := Time millisecondsToRun:[ |zipStream wstream|
|
|
468 |
zipStream := stream := nxtCont := nil.
|
|
469 |
[
|
|
470 |
stream := file readStream.
|
|
471 |
wstream := String writeStream.
|
|
472 |
zipStream := BZip2Stream readOpenOn:stream.
|
|
473 |
skip timesRepeat:[ zipStream next ].
|
|
474 |
|
|
475 |
[zipStream atEnd] whileFalse:[
|
|
476 |
wstream nextPutAll:(zipStream next:117)
|
|
477 |
].
|
|
478 |
nxtCont := wstream contents.
|
|
479 |
] ensure:[
|
|
480 |
zipStream notNil ifTrue:[zipStream close].
|
|
481 |
stream notNil ifTrue:[stream close].
|
|
482 |
].
|
|
483 |
].
|
|
484 |
|
|
485 |
Transcript showCR:('STX Time : %1 Size: %2' bindWith:time with:(nxtCont size)).
|
|
486 |
|
|
487 |
time := Time millisecondsToRun:[ |zipStream wstream|
|
|
488 |
zipStream := stream := skpCont := nil.
|
|
489 |
[
|
|
490 |
stream := file readStream.
|
|
491 |
wstream := '' writeStream.
|
|
492 |
zipStream := BZip2Stream readOpenOn:stream.
|
|
493 |
zipStream skip:skip.
|
|
494 |
[zipStream atEnd] whileFalse:[
|
|
495 |
wstream nextPutAll:(zipStream next:117)
|
|
496 |
].
|
|
497 |
skpCont := wstream contents.
|
|
498 |
] ensure:[
|
|
499 |
zipStream notNil ifTrue:[zipStream close].
|
|
500 |
stream notNil ifTrue:[stream close].
|
|
501 |
].
|
|
502 |
].
|
|
503 |
Transcript showCR:('NEXT Time : %1 Size: %2' bindWith:time with:(skpCont size)).
|
|
504 |
|
|
505 |
nxtCont = skpCont ifTrue:[ Transcript showCR:'OK' ]
|
|
506 |
ifFalse:[ self error:'contents differs' ].
|
|
507 |
! !
|
|
508 |
|
|
509 |
!CompressionStreamTest class methodsFor:'documentation'!
|
|
510 |
|
|
511 |
version
|
|
512 |
^ '$Header$'
|
|
513 |
!
|
|
514 |
|
|
515 |
version_CVS
|
|
516 |
^ '$Header$'
|
|
517 |
! !
|
|
518 |
|