69
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
0
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
118
|
5 |
TestCase subclass:#FileStreamTest
|
0
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
181
|
9 |
category:'tests-Regression'
|
0
|
10 |
!
|
|
11 |
|
|
12 |
|
120
|
13 |
!FileStreamTest methodsFor:'helpers'!
|
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 |
|
120
|
39 |
doTestWrite:size
|
|
40 |
"basic writing"
|
|
41 |
|
|
42 |
|file s sz buffer byte|
|
|
43 |
|
|
44 |
buffer := ByteArray new:size.
|
|
45 |
1 to:buffer size do:[:idx |
|
|
46 |
buffer at:idx put:(idx \\ 256)
|
|
47 |
].
|
|
48 |
|
|
49 |
file := Filename newTemporary.
|
|
50 |
s := file writeStream.
|
|
51 |
|
|
52 |
s binary.
|
|
53 |
s nextPutAll:buffer.
|
|
54 |
s close.
|
|
55 |
|
|
56 |
sz := file fileSize.
|
|
57 |
sz ~= size ifTrue:[self error:'size mismatch'].
|
|
58 |
|
|
59 |
s := file readStream.
|
|
60 |
s binary.
|
|
61 |
1 to:size do:[:idx |
|
|
62 |
byte := s next.
|
|
63 |
byte ~~ (idx \\ 256) ifTrue:[self error:'read data mismatch'].
|
|
64 |
].
|
|
65 |
s close.
|
|
66 |
|
|
67 |
(file binaryContentsOfEntireFile ~= buffer) ifTrue:[
|
|
68 |
self error:'read data mismatch2'
|
|
69 |
].
|
|
70 |
file delete.
|
|
71 |
|
|
72 |
"
|
|
73 |
self testWrite:1024
|
|
74 |
"
|
|
75 |
!
|
|
76 |
|
0
|
77 |
readFileExpecting:expect
|
|
78 |
"read test file, expect n bytes"
|
|
79 |
|
|
80 |
|f buffer n nRead|
|
|
81 |
|
|
82 |
f := 'testFile' asFilename readStream binary.
|
|
83 |
buffer := ByteArray new:128.
|
|
84 |
|
|
85 |
n := 0.
|
|
86 |
[f atEnd] whileFalse:[
|
1
|
87 |
nRead := f nextBytes:128 into:buffer.
|
|
88 |
n := n + nRead.
|
0
|
89 |
].
|
|
90 |
f close.
|
|
91 |
expect ~~ n ifTrue:[
|
1
|
92 |
self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
|
0
|
93 |
].
|
|
94 |
|
|
95 |
"Created: / 12.8.1998 / 13:29:41 / cg"
|
|
96 |
"Modified: / 12.8.1998 / 13:36:40 / cg"
|
120
|
97 |
! !
|
|
98 |
|
|
99 |
!FileStreamTest methodsFor:'tests'!
|
0
|
100 |
|
75
|
101 |
testAppend1
|
|
102 |
"basic open for appending."
|
|
103 |
|
119
|
104 |
|file s sz actualContents expectedContents|
|
75
|
105 |
|
|
106 |
file := Filename newTemporary.
|
|
107 |
s := file writeStream.
|
|
108 |
s binary.
|
|
109 |
s nextPutAll:(1 to:100).
|
|
110 |
s close.
|
|
111 |
|
|
112 |
sz := file fileSize.
|
119
|
113 |
self should:[ sz = 100 ]. "/ size mismatch
|
75
|
114 |
|
|
115 |
s := file appendingWriteStream.
|
|
116 |
s binary.
|
|
117 |
s nextPutAll:(101 to:200).
|
|
118 |
s close.
|
|
119 |
|
|
120 |
sz := file fileSize.
|
119
|
121 |
self should:[ sz = 200 ]. "/ size mismatch
|
75
|
122 |
|
119
|
123 |
actualContents := file binaryContentsOfEntireFile.
|
|
124 |
expectedContents := (1 to:200) asByteArray.
|
|
125 |
self should:[ (actualContents = expectedContents) ]. "/ contents mismatch
|
75
|
126 |
|
|
127 |
file delete.
|
|
128 |
|
|
129 |
"
|
119
|
130 |
self new testAppend1
|
75
|
131 |
"
|
|
132 |
!
|
|
133 |
|
|
134 |
testOpenRead1
|
|
135 |
"basic open for reading."
|
|
136 |
|
|
137 |
|sz|
|
|
138 |
|
|
139 |
self createTestFile.
|
|
140 |
|
|
141 |
sz := 'testFile' asFilename fileSize.
|
|
142 |
|
|
143 |
self readFileExpecting:sz.
|
|
144 |
|
|
145 |
"
|
119
|
146 |
self new testOpenRead1
|
75
|
147 |
"
|
|
148 |
!
|
|
149 |
|
|
150 |
testRead1
|
0
|
151 |
"read a file - check count read with files size."
|
|
152 |
|
|
153 |
|sz|
|
|
154 |
|
|
155 |
self createTestFile.
|
|
156 |
|
|
157 |
sz := 'testFile' asFilename fileSize.
|
|
158 |
|
|
159 |
self readFileExpecting:sz.
|
|
160 |
|
|
161 |
"
|
119
|
162 |
self new testRead1
|
0
|
163 |
"
|
|
164 |
|
|
165 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
166 |
!
|
|
167 |
|
75
|
168 |
testRead2
|
0
|
169 |
"read a file - check count read with files size.
|
|
170 |
Do this in 20 threads"
|
|
171 |
|
|
172 |
|sz|
|
|
173 |
|
|
174 |
self createTestFile.
|
|
175 |
|
|
176 |
sz := 'testFile' asFilename fileSize.
|
|
177 |
|
|
178 |
20 timesRepeat:[
|
75
|
179 |
[self readFileExpecting:sz. 'done' printCR.] fork.
|
0
|
180 |
].
|
|
181 |
|
|
182 |
"
|
119
|
183 |
self new testRead2
|
0
|
184 |
"
|
|
185 |
|
|
186 |
"Modified: / 12.8.1998 / 13:30:55 / cg"
|
|
187 |
!
|
|
188 |
|
75
|
189 |
testRead3
|
0
|
190 |
"read a file - check count read with files size.
|
|
191 |
Do this and interrupt the reading thread heavily"
|
|
192 |
|
|
193 |
|sz p count nLoop|
|
|
194 |
|
|
195 |
nLoop := 1000.
|
|
196 |
|
|
197 |
self createTestFile.
|
|
198 |
|
|
199 |
sz := 'testFile' asFilename fileSize.
|
|
200 |
|
|
201 |
p := [
|
75
|
202 |
nLoop timesRepeat:[
|
|
203 |
self readFileExpecting:sz.
|
|
204 |
].
|
30
|
205 |
] forkAt:7.
|
|
206 |
|
|
207 |
count := 0.
|
|
208 |
[p isDead] whileFalse:[
|
75
|
209 |
Delay waitForMilliseconds:5.
|
|
210 |
p interruptWith:[count := count + 1].
|
30
|
211 |
].
|
|
212 |
('read file <1p> times; interrupted <2p> times'
|
75
|
213 |
expandMacrosWith:nLoop with:count) printCR
|
30
|
214 |
|
|
215 |
"
|
119
|
216 |
self new testRead3
|
30
|
217 |
"
|
|
218 |
|
|
219 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
220 |
!
|
|
221 |
|
75
|
222 |
testRewrite1
|
|
223 |
"basic open for writing (with truncation)."
|
|
224 |
|
|
225 |
|file s sz|
|
|
226 |
|
|
227 |
file := Filename newTemporary.
|
|
228 |
s := file writeStream.
|
|
229 |
s binary.
|
|
230 |
s nextPutAll:(1 to:200).
|
|
231 |
s close.
|
|
232 |
|
|
233 |
sz := file fileSize.
|
|
234 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
235 |
|
|
236 |
s := file writeStream.
|
|
237 |
s binary.
|
|
238 |
s nextPutAll:(101 to:200).
|
|
239 |
s close.
|
|
240 |
|
|
241 |
sz := file fileSize.
|
|
242 |
sz ~= 100 ifTrue:[self error:'size mismatch'].
|
|
243 |
|
|
244 |
(file binaryContentsOfEntireFile ~= (101 to:200) asByteArray) ifTrue:[
|
|
245 |
self error:'contents mismatch'
|
|
246 |
].
|
|
247 |
|
|
248 |
file delete.
|
|
249 |
|
|
250 |
"
|
120
|
251 |
self new testRewrite1
|
75
|
252 |
"
|
|
253 |
!
|
|
254 |
|
|
255 |
testRewrite2
|
|
256 |
"basic open for re-writing (without truncation)."
|
|
257 |
|
|
258 |
|file s sz|
|
|
259 |
|
|
260 |
file := Filename newTemporary.
|
|
261 |
s := file writeStream.
|
|
262 |
s binary.
|
|
263 |
s nextPutAll:(1 to:200).
|
|
264 |
s close.
|
|
265 |
|
|
266 |
sz := file fileSize.
|
|
267 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
268 |
|
|
269 |
s := file readWriteStream.
|
|
270 |
s binary.
|
|
271 |
s nextPutAll:(101 to:200).
|
|
272 |
s close.
|
|
273 |
|
|
274 |
sz := file fileSize.
|
|
275 |
sz ~= 200 ifTrue:[self error:'size mismatch'].
|
|
276 |
|
|
277 |
(file binaryContentsOfEntireFile ~=
|
|
278 |
((101 to:200) asByteArray , (101 to:200) asByteArray)) ifTrue:[
|
|
279 |
self error:'contents mismatch'
|
|
280 |
].
|
|
281 |
|
|
282 |
file delete.
|
|
283 |
|
|
284 |
"
|
120
|
285 |
self new testRewrite2
|
75
|
286 |
"
|
76
|
287 |
!
|
|
288 |
|
|
289 |
testWrite1
|
|
290 |
"basic writing"
|
|
291 |
|
120
|
292 |
self doTestWrite:1024.
|
|
293 |
self doTestWrite:2048.
|
|
294 |
self doTestWrite:4096.
|
|
295 |
self doTestWrite:8192.
|
|
296 |
self doTestWrite:8192*2.
|
|
297 |
self doTestWrite:8192*4.
|
|
298 |
self doTestWrite:8192*8.
|
|
299 |
self doTestWrite:8192*16.
|
|
300 |
self doTestWrite:8192*32.
|
|
301 |
self doTestWrite:8192*64.
|
|
302 |
self doTestWrite:8192*128.
|
76
|
303 |
|
|
304 |
"
|
120
|
305 |
self new testWrite1
|
76
|
306 |
"
|
|
307 |
!
|
|
308 |
|
|
309 |
testWrite2
|
|
310 |
"basic writing"
|
|
311 |
|
|
312 |
10 timesRepeat:[
|
|
313 |
self testWrite1.
|
|
314 |
].
|
|
315 |
|
|
316 |
"
|
120
|
317 |
self new testWrite2
|
76
|
318 |
"
|
|
319 |
!
|
|
320 |
|
|
321 |
testWrite3
|
|
322 |
"basic writing"
|
|
323 |
|
|
324 |
|interruptor|
|
|
325 |
|
|
326 |
interruptor := [
|
|
327 |
[true] whileTrue:[
|
|
328 |
Delay waitForMilliseconds:10.
|
|
329 |
].
|
|
330 |
] forkAt:9.
|
|
331 |
|
|
332 |
[
|
|
333 |
50 timesRepeat:[
|
|
334 |
self testWrite1.
|
|
335 |
].
|
|
336 |
] valueNowOrOnUnwindDo:[
|
|
337 |
interruptor terminate
|
|
338 |
].
|
|
339 |
|
|
340 |
"
|
120
|
341 |
self new testWrite3
|
76
|
342 |
"
|
0
|
343 |
! !
|
|
344 |
|
|
345 |
!FileStreamTest class methodsFor:'documentation'!
|
|
346 |
|
|
347 |
version
|
|
348 |
^ '$Header$'
|
|
349 |
! !
|