69
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
0
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
118
|
5 |
TestCase subclass:#FileStreamTest
|
0
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
59
|
9 |
category:'Tests-Regression'
|
0
|
10 |
!
|
|
11 |
|
|
12 |
|
118
|
13 |
!FileStreamTest methodsFor:'tests'!
|
0
|
14 |
|
|
15 |
createTestFile
|
|
16 |
"create a test file (100k size)"
|
|
17 |
|
|
18 |
|f bytes|
|
|
19 |
|
|
20 |
f := 'testFile' asFilename writeStream binary.
|
|
21 |
bytes := ByteArray new:1024.
|
|
22 |
1 to:bytes size do:[:i |
|
119
|
23 |
bytes at:i put:(i \\ 256).
|
0
|
24 |
].
|
|
25 |
|
|
26 |
100 timesRepeat:[
|
119
|
27 |
f nextPutAll:bytes.
|
0
|
28 |
].
|
|
29 |
|
|
30 |
f close.
|
|
31 |
|
|
32 |
"
|
119
|
33 |
self new createTestFile
|
0
|
34 |
"
|
|
35 |
|
|
36 |
"Created: / 12.8.1998 / 13:25:25 / cg"
|
|
37 |
!
|
|
38 |
|
|
39 |
readFileExpecting:expect
|
|
40 |
"read test file, expect n bytes"
|
|
41 |
|
|
42 |
|f buffer n nRead|
|
|
43 |
|
|
44 |
f := 'testFile' asFilename readStream binary.
|
|
45 |
buffer := ByteArray new:128.
|
|
46 |
|
|
47 |
n := 0.
|
|
48 |
[f atEnd] whileFalse:[
|
1
|
49 |
nRead := f nextBytes:128 into:buffer.
|
|
50 |
n := n + nRead.
|
0
|
51 |
].
|
|
52 |
f close.
|
|
53 |
expect ~~ n ifTrue:[
|
1
|
54 |
self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
|
0
|
55 |
].
|
|
56 |
|
|
57 |
"Created: / 12.8.1998 / 13:29:41 / cg"
|
|
58 |
"Modified: / 12.8.1998 / 13:36:40 / cg"
|
|
59 |
!
|
|
60 |
|
75
|
61 |
testAppend1
|
|
62 |
"basic open for appending."
|
|
63 |
|
119
|
64 |
|file s sz actualContents expectedContents|
|
75
|
65 |
|
|
66 |
file := Filename newTemporary.
|
|
67 |
s := file writeStream.
|
|
68 |
s binary.
|
|
69 |
s nextPutAll:(1 to:100).
|
|
70 |
s close.
|
|
71 |
|
|
72 |
sz := file fileSize.
|
119
|
73 |
self should:[ sz = 100 ]. "/ size mismatch
|
75
|
74 |
|
|
75 |
s := file appendingWriteStream.
|
|
76 |
s binary.
|
|
77 |
s nextPutAll:(101 to:200).
|
|
78 |
s close.
|
|
79 |
|
|
80 |
sz := file fileSize.
|
119
|
81 |
self should:[ sz = 200 ]. "/ size mismatch
|
75
|
82 |
|
119
|
83 |
actualContents := file binaryContentsOfEntireFile.
|
|
84 |
expectedContents := (1 to:200) asByteArray.
|
|
85 |
self should:[ (actualContents = expectedContents) ]. "/ contents mismatch
|
75
|
86 |
|
|
87 |
file delete.
|
|
88 |
|
|
89 |
"
|
119
|
90 |
self new testAppend1
|
75
|
91 |
"
|
|
92 |
!
|
|
93 |
|
|
94 |
testOpenRead1
|
|
95 |
"basic open for reading."
|
|
96 |
|
|
97 |
|sz|
|
|
98 |
|
|
99 |
self createTestFile.
|
|
100 |
|
|
101 |
sz := 'testFile' asFilename fileSize.
|
|
102 |
|
|
103 |
self readFileExpecting:sz.
|
|
104 |
|
|
105 |
"
|
119
|
106 |
self new testOpenRead1
|
75
|
107 |
"
|
|
108 |
!
|
|
109 |
|
|
110 |
testRead1
|
0
|
111 |
"read a file - check count read with files size."
|
|
112 |
|
|
113 |
|sz|
|
|
114 |
|
|
115 |
self createTestFile.
|
|
116 |
|
|
117 |
sz := 'testFile' asFilename fileSize.
|
|
118 |
|
|
119 |
self readFileExpecting:sz.
|
|
120 |
|
|
121 |
"
|
119
|
122 |
self new testRead1
|
0
|
123 |
"
|
|
124 |
|
|
125 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
126 |
!
|
|
127 |
|
75
|
128 |
testRead2
|
0
|
129 |
"read a file - check count read with files size.
|
|
130 |
Do this in 20 threads"
|
|
131 |
|
|
132 |
|sz|
|
|
133 |
|
|
134 |
self createTestFile.
|
|
135 |
|
|
136 |
sz := 'testFile' asFilename fileSize.
|
|
137 |
|
|
138 |
20 timesRepeat:[
|
75
|
139 |
[self readFileExpecting:sz. 'done' printCR.] fork.
|
0
|
140 |
].
|
|
141 |
|
|
142 |
"
|
119
|
143 |
self new testRead2
|
0
|
144 |
"
|
|
145 |
|
|
146 |
"Modified: / 12.8.1998 / 13:30:55 / cg"
|
|
147 |
!
|
|
148 |
|
75
|
149 |
testRead3
|
0
|
150 |
"read a file - check count read with files size.
|
|
151 |
Do this and interrupt the reading thread heavily"
|
|
152 |
|
|
153 |
|sz p count nLoop|
|
|
154 |
|
|
155 |
nLoop := 1000.
|
|
156 |
|
|
157 |
self createTestFile.
|
|
158 |
|
|
159 |
sz := 'testFile' asFilename fileSize.
|
|
160 |
|
|
161 |
p := [
|
75
|
162 |
nLoop timesRepeat:[
|
|
163 |
self readFileExpecting:sz.
|
|
164 |
].
|
30
|
165 |
] forkAt:7.
|
|
166 |
|
|
167 |
count := 0.
|
|
168 |
[p isDead] whileFalse:[
|
75
|
169 |
Delay waitForMilliseconds:5.
|
|
170 |
p interruptWith:[count := count + 1].
|
30
|
171 |
].
|
|
172 |
('read file <1p> times; interrupted <2p> times'
|
75
|
173 |
expandMacrosWith:nLoop with:count) printCR
|
30
|
174 |
|
|
175 |
"
|
119
|
176 |
self new testRead3
|
30
|
177 |
"
|
|
178 |
|
|
179 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
180 |
!
|
|
181 |
|
75
|
182 |
testReadCheckPipe4
|
30
|
183 |
"readCheck a pipe.
|
|
184 |
Do this and interrupt the reading thread heavily"
|
|
185 |
|
119
|
186 |
| s p count nLoop|
|
30
|
187 |
|
|
188 |
nLoop := 1000.
|
|
189 |
|
|
190 |
self createTestFile.
|
|
191 |
|
|
192 |
s := PipeStream readingFrom:'sleep 5'.
|
|
193 |
|
|
194 |
p := [
|
75
|
195 |
s readWait.
|
|
196 |
'readWait finished' printCR.
|
30
|
197 |
] forkAt:7.
|
|
198 |
|
|
199 |
count := 0.
|
|
200 |
[p isDead] whileFalse:[
|
75
|
201 |
Delay waitForMilliseconds:5.
|
|
202 |
p interruptWith:[count := count + 1].
|
30
|
203 |
].
|
75
|
204 |
('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
|
30
|
205 |
|
|
206 |
s close.
|
|
207 |
|
|
208 |
"
|
119
|
209 |
self new testReadCheckPipe4
|
30
|
210 |
"
|
|
211 |
|
|
212 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
213 |
!
|
|
214 |
|
75
|
215 |
testReadCheckPipe5
|
30
|
216 |
"readCheck a pipe.
|
|
217 |
Do this and interrupt the reading thread heavily"
|
|
218 |
|
119
|
219 |
| s p count nLoop|
|
30
|
220 |
|
|
221 |
nLoop := 1000.
|
|
222 |
|
|
223 |
self createTestFile.
|
|
224 |
|
|
225 |
s := PipeStream readingFrom:'sleep 5; echo hello'.
|
|
226 |
|
|
227 |
p := [
|
75
|
228 |
s readWait.
|
|
229 |
'readWait finished' printCR.
|
0
|
230 |
] forkAt:7.
|
|
231 |
|
|
232 |
count := 0.
|
|
233 |
[p isDead] whileFalse:[
|
75
|
234 |
Delay waitForMilliseconds:5.
|
|
235 |
p interruptWith:[count := count + 1].
|
0
|
236 |
].
|
75
|
237 |
('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
|
30
|
238 |
|
|
239 |
s close.
|
0
|
240 |
|
|
241 |
"
|
119
|
242 |
self new testReadCheckPipe5
|
30
|
243 |
"
|
|
244 |
|
|
245 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
246 |
!
|
|
247 |
|
75
|
248 |
testReadPipe6
|
30
|
249 |
"read a pipe.
|
|
250 |
Do this and interrupt the reading thread heavily"
|
|
251 |
|
119
|
252 |
| s p count nLoop|
|
30
|
253 |
|
|
254 |
nLoop := 1000.
|
|
255 |
|
|
256 |
self createTestFile.
|
|
257 |
|
|
258 |
s := PipeStream readingFrom:'sleep 5'.
|
|
259 |
|
|
260 |
p := [
|
75
|
261 |
'read: ' print. s nextLine printCR.
|
30
|
262 |
] forkAt:7.
|
|
263 |
|
|
264 |
count := 0.
|
|
265 |
[p isDead] whileFalse:[
|
75
|
266 |
Delay waitForMilliseconds:5.
|
|
267 |
p interruptWith:[count := count + 1].
|
30
|
268 |
].
|
75
|
269 |
('read interrupted <1p> times' expandMacrosWith:count) printCR.
|
30
|
270 |
|
|
271 |
s close.
|
|
272 |
|
|
273 |
"
|
119
|
274 |
self new testReadPipe6
|
30
|
275 |
"
|
|
276 |
|
|
277 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
278 |
!
|
|
279 |
|
75
|
280 |
testReadPipe7
|
30
|
281 |
"read a pipe.
|
|
282 |
Do this and interrupt the reading thread heavily"
|
|
283 |
|
|
284 |
|sz s p count nLoop|
|
|
285 |
|
|
286 |
nLoop := 1000.
|
|
287 |
|
|
288 |
self createTestFile.
|
|
289 |
|
|
290 |
s := PipeStream readingFrom:'sleep 5; echo hello'.
|
|
291 |
|
|
292 |
p := [
|
75
|
293 |
'read: ' print. s nextLine printCR.
|
30
|
294 |
] forkAt:7.
|
|
295 |
|
|
296 |
count := 0.
|
|
297 |
[p isDead] whileFalse:[
|
75
|
298 |
Delay waitForMilliseconds:5.
|
|
299 |
p interruptWith:[count := count + 1].
|
30
|
300 |
].
|
75
|
301 |
('read interrupted <1p> times' expandMacrosWith:count) printCR.
|
30
|
302 |
|
|
303 |
s close.
|
|
304 |
|
|
305 |
"
|
|
306 |
self test7
|
0
|
307 |
"
|
|
308 |
|
|
309 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
75
|
310 |
!
|
|
311 |
|
|
312 |
testRewrite1
|
|
313 |
"basic open for writing (with truncation)."
|
|
314 |
|
|
315 |
|file s sz|
|
|
316 |
|
|
317 |
file := Filename newTemporary.
|
|
318 |
s := file writeStream.
|
|
319 |
s binary.
|
|
320 |
s nextPutAll:(1 to:200).
|
|
321 |
s close.
|
|
322 |
|
|
323 |
sz := file fileSize.
|
|
324 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
325 |
|
|
326 |
s := file writeStream.
|
|
327 |
s binary.
|
|
328 |
s nextPutAll:(101 to:200).
|
|
329 |
s close.
|
|
330 |
|
|
331 |
sz := file fileSize.
|
|
332 |
sz ~= 100 ifTrue:[self error:'size mismatch'].
|
|
333 |
|
|
334 |
(file binaryContentsOfEntireFile ~= (101 to:200) asByteArray) ifTrue:[
|
|
335 |
self error:'contents mismatch'
|
|
336 |
].
|
|
337 |
|
|
338 |
file delete.
|
|
339 |
|
|
340 |
"
|
|
341 |
self testRewrite1
|
|
342 |
"
|
|
343 |
!
|
|
344 |
|
|
345 |
testRewrite2
|
|
346 |
"basic open for re-writing (without truncation)."
|
|
347 |
|
|
348 |
|file s sz|
|
|
349 |
|
|
350 |
file := Filename newTemporary.
|
|
351 |
s := file writeStream.
|
|
352 |
s binary.
|
|
353 |
s nextPutAll:(1 to:200).
|
|
354 |
s close.
|
|
355 |
|
|
356 |
sz := file fileSize.
|
|
357 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
358 |
|
|
359 |
s := file readWriteStream.
|
|
360 |
s binary.
|
|
361 |
s nextPutAll:(101 to:200).
|
|
362 |
s close.
|
|
363 |
|
|
364 |
sz := file fileSize.
|
|
365 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
366 |
|
|
367 |
(file binaryContentsOfEntireFile ~=
|
|
368 |
((101 to:200) asByteArray , (101 to:200) asByteArray)) ifTrue:[
|
|
369 |
self error:'contents mismatch'
|
|
370 |
].
|
|
371 |
|
|
372 |
file delete.
|
|
373 |
|
|
374 |
"
|
|
375 |
self testRewrite2
|
|
376 |
"
|
76
|
377 |
!
|
|
378 |
|
|
379 |
testWrite1
|
|
380 |
"basic writing"
|
|
381 |
|
|
382 |
self testWrite:1024.
|
|
383 |
self testWrite:2048.
|
|
384 |
self testWrite:4096.
|
|
385 |
self testWrite:8192.
|
|
386 |
self testWrite:8192*2.
|
|
387 |
self testWrite:8192*4.
|
|
388 |
self testWrite:8192*8.
|
|
389 |
self testWrite:8192*16.
|
|
390 |
self testWrite:8192*32.
|
|
391 |
self testWrite:8192*64.
|
|
392 |
self testWrite:8192*128.
|
|
393 |
|
|
394 |
"
|
|
395 |
self testWrite1
|
|
396 |
"
|
|
397 |
!
|
|
398 |
|
|
399 |
testWrite2
|
|
400 |
"basic writing"
|
|
401 |
|
|
402 |
10 timesRepeat:[
|
|
403 |
self testWrite1.
|
|
404 |
].
|
|
405 |
|
|
406 |
"
|
|
407 |
self testWrite2
|
|
408 |
"
|
|
409 |
!
|
|
410 |
|
|
411 |
testWrite3
|
|
412 |
"basic writing"
|
|
413 |
|
|
414 |
|interruptor|
|
|
415 |
|
|
416 |
interruptor := [
|
|
417 |
[true] whileTrue:[
|
|
418 |
Delay waitForMilliseconds:10.
|
|
419 |
].
|
|
420 |
] forkAt:9.
|
|
421 |
|
|
422 |
[
|
|
423 |
50 timesRepeat:[
|
|
424 |
self testWrite1.
|
|
425 |
].
|
|
426 |
] valueNowOrOnUnwindDo:[
|
|
427 |
interruptor terminate
|
|
428 |
].
|
|
429 |
|
|
430 |
"
|
|
431 |
self testWrite3
|
|
432 |
"
|
|
433 |
!
|
|
434 |
|
|
435 |
testWrite:size
|
|
436 |
"basic writing"
|
|
437 |
|
|
438 |
|file s sz buffer byte|
|
|
439 |
|
|
440 |
buffer := ByteArray new:size.
|
|
441 |
1 to:buffer size do:[:idx |
|
|
442 |
buffer at:idx put:(idx \\ 256)
|
|
443 |
].
|
|
444 |
|
|
445 |
file := Filename newTemporary.
|
|
446 |
s := file writeStream.
|
|
447 |
|
|
448 |
s binary.
|
|
449 |
s nextPutAll:buffer.
|
|
450 |
s close.
|
|
451 |
|
|
452 |
sz := file fileSize.
|
|
453 |
sz ~= size ifTrue:[self error:'size mismatch'].
|
|
454 |
|
|
455 |
s := file readStream.
|
|
456 |
s binary.
|
|
457 |
1 to:size do:[:idx |
|
|
458 |
byte := s next.
|
|
459 |
byte ~~ (idx \\ 256) ifTrue:[self error:'read data mismatch'].
|
|
460 |
].
|
|
461 |
s close.
|
|
462 |
|
|
463 |
(file binaryContentsOfEntireFile ~= buffer) ifTrue:[
|
|
464 |
self error:'read data mismatch2'
|
|
465 |
].
|
|
466 |
file delete.
|
|
467 |
|
|
468 |
"
|
|
469 |
self testWrite:1024
|
|
470 |
"
|
0
|
471 |
! !
|
|
472 |
|
|
473 |
!FileStreamTest class methodsFor:'documentation'!
|
|
474 |
|
|
475 |
version
|
|
476 |
^ '$Header$'
|
|
477 |
! !
|