122
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#FileOpenTest
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Tests-Regression'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!FileOpenTest methodsFor:'tests'!
|
|
14 |
|
124
|
15 |
createWithSize10:fileName
|
|
16 |
"helper"
|
|
17 |
|
|
18 |
(fileName asFilename exists) ifTrue:[
|
|
19 |
fileName asFilename delete
|
|
20 |
].
|
|
21 |
fileName asFilename writeStream
|
|
22 |
nextPutAll:'1234567890';
|
|
23 |
close.
|
|
24 |
self assert:(fileName asFilename exists).
|
|
25 |
self assert:(fileName asFilename fileSize == 10).
|
|
26 |
|
|
27 |
"
|
|
28 |
self new createWithSize10:'xxx1'
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
testCreate1
|
126
|
33 |
"create a new file (initially not existing)"
|
124
|
34 |
|
|
35 |
|h|
|
|
36 |
|
|
37 |
('xxx1' asFilename exists) ifTrue:[
|
|
38 |
'xxx1' asFilename delete
|
|
39 |
].
|
|
40 |
|
|
41 |
h := OperatingSystem createFileForReadWrite:'xxx1'.
|
|
42 |
self assert:(h notNil).
|
|
43 |
self assert:(h isValid).
|
|
44 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
45 |
self assert:(h address ~~ 0).
|
|
46 |
].
|
|
47 |
|
|
48 |
h close.
|
|
49 |
self assert:(h isValid not).
|
|
50 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
51 |
self assert:(h address == 0).
|
|
52 |
].
|
|
53 |
|
|
54 |
self assert:('xxx1' asFilename exists).
|
|
55 |
self assert:('xxx1' asFilename fileSize == 0).
|
|
56 |
|
|
57 |
'xxx1' asFilename delete
|
|
58 |
|
|
59 |
"
|
|
60 |
self new testCreate1
|
|
61 |
"
|
|
62 |
|
|
63 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
64 |
!
|
|
65 |
|
|
66 |
testCreate2
|
|
67 |
"create a file; checks if the file is truncated if already existing"
|
|
68 |
|
|
69 |
|h|
|
|
70 |
|
|
71 |
self createWithSize10:'xxx1'.
|
|
72 |
|
|
73 |
|
|
74 |
h := OperatingSystem createFileForReadWrite:'xxx1'.
|
|
75 |
self assert:(h notNil).
|
|
76 |
self assert:(h isValid).
|
|
77 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
78 |
self assert:(h address ~~ 0).
|
|
79 |
].
|
|
80 |
|
|
81 |
h close.
|
|
82 |
self assert:(h isValid not).
|
|
83 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
84 |
self assert:(h address == 0).
|
|
85 |
].
|
|
86 |
|
|
87 |
self assert:('xxx1' asFilename exists).
|
|
88 |
self assert:('xxx1' asFilename fileSize == 0).
|
|
89 |
|
|
90 |
"
|
|
91 |
self new testCreate2
|
|
92 |
"
|
|
93 |
|
|
94 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
95 |
!
|
|
96 |
|
126
|
97 |
testFailCreate1
|
|
98 |
"try to create an uncreatable new file (directory not existing)"
|
|
99 |
|
|
100 |
|fn|
|
|
101 |
|
|
102 |
fn := (('.' asFilename construct:'foo') construct:'bar') construct:'xxx1'.
|
|
103 |
self
|
|
104 |
should:[
|
|
105 |
OperatingSystem createFileForReadWrite:fn name]
|
127
|
106 |
raise:(OSErrorHolder nonexistentSignal).
|
126
|
107 |
|
|
108 |
"/ raised signal should be a child of inaccessibleSignal
|
|
109 |
self
|
|
110 |
should:[
|
|
111 |
OperatingSystem createFileForReadWrite:fn name]
|
127
|
112 |
raise:(OSErrorHolder nonexistentSignal ).
|
126
|
113 |
|
|
114 |
"/ raised signal should be a child of OsError
|
|
115 |
self
|
|
116 |
should:[
|
|
117 |
OperatingSystem createFileForReadWrite:fn name]
|
|
118 |
raise:(OsError ).
|
|
119 |
|
|
120 |
"
|
|
121 |
self new testFailCreate1
|
|
122 |
"
|
|
123 |
|
|
124 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
125 |
!
|
|
126 |
|
125
|
127 |
testFailOpen1
|
|
128 |
"open a non-existing file; must fail"
|
122
|
129 |
|
|
130 |
|h|
|
|
131 |
|
125
|
132 |
'xxx2' asFilename delete.
|
|
133 |
|
|
134 |
self
|
|
135 |
should:[
|
|
136 |
h := OperatingSystem openFileForRead:'xxx2'.]
|
|
137 |
raise:(OSErrorHolder nonexistentSignal).
|
|
138 |
|
|
139 |
|
|
140 |
"
|
|
141 |
self new testFailOpen1
|
|
142 |
"
|
|
143 |
|
|
144 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
145 |
!
|
|
146 |
|
128
|
147 |
testFailOpen2
|
|
148 |
"open a non-existing file for writing; must fail"
|
|
149 |
|
|
150 |
|h|
|
|
151 |
|
|
152 |
'xxx2' asFilename delete.
|
|
153 |
|
|
154 |
self
|
|
155 |
should:[
|
|
156 |
h := OperatingSystem openFileForWrite:'xxx2'.]
|
|
157 |
raise:(OSErrorHolder nonexistentSignal).
|
|
158 |
|
|
159 |
|
|
160 |
"
|
|
161 |
self new testFailOpen2
|
|
162 |
"
|
|
163 |
|
|
164 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
165 |
!
|
|
166 |
|
|
167 |
testFinalization1
|
|
168 |
"open an existing file; check if GC closes it"
|
|
169 |
|
|
170 |
|h|
|
|
171 |
|
|
172 |
self createWithSize10:'xxx2'.
|
|
173 |
|
|
174 |
h := OperatingSystem openFileForWrite:'xxx2'.
|
|
175 |
|
|
176 |
self assert:(h notNil).
|
|
177 |
self assert:(h isValid).
|
|
178 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
179 |
self assert:(h address ~~ 0).
|
|
180 |
].
|
|
181 |
|
|
182 |
h := nil.
|
|
183 |
ObjectMemory tenure.
|
|
184 |
ObjectMemory garbageCollect.
|
|
185 |
|
|
186 |
self assert:(h isValid not).
|
|
187 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
188 |
self assert:(h address == 0).
|
|
189 |
].
|
|
190 |
|
|
191 |
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size
|
|
192 |
'xxx2' asFilename delete.
|
|
193 |
|
|
194 |
"
|
|
195 |
self new testFinalization1
|
|
196 |
"
|
|
197 |
|
|
198 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
199 |
!
|
|
200 |
|
125
|
201 |
testOpen1
|
128
|
202 |
"open an existing file for reading"
|
125
|
203 |
|
|
204 |
|h|
|
|
205 |
|
|
206 |
self createWithSize10:'xxx2'.
|
|
207 |
|
|
208 |
h := OperatingSystem openFileForRead:'xxx2'.
|
122
|
209 |
self assert:(h notNil).
|
123
|
210 |
self assert:(h isValid).
|
|
211 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
212 |
self assert:(h address ~~ 0).
|
|
213 |
].
|
122
|
214 |
|
|
215 |
h close.
|
123
|
216 |
self assert:(h isValid not).
|
|
217 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
218 |
self assert:(h address == 0).
|
|
219 |
].
|
122
|
220 |
|
128
|
221 |
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size
|
125
|
222 |
'xxx2' asFilename delete.
|
|
223 |
|
122
|
224 |
"
|
|
225 |
self new testOpen1
|
|
226 |
"
|
|
227 |
|
|
228 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
128
|
229 |
!
|
|
230 |
|
|
231 |
testOpen2
|
|
232 |
"open an existing file for writing; should be truncated"
|
|
233 |
|
|
234 |
|h|
|
|
235 |
|
|
236 |
self createWithSize10:'xxx2'.
|
|
237 |
|
|
238 |
h := OperatingSystem openFileForWrite:'xxx2'.
|
|
239 |
self assert:(h notNil).
|
|
240 |
self assert:(h isValid).
|
|
241 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
242 |
self assert:(h address ~~ 0).
|
|
243 |
].
|
|
244 |
|
|
245 |
h close.
|
|
246 |
self assert:(h isValid not).
|
|
247 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
248 |
self assert:(h address == 0).
|
|
249 |
].
|
|
250 |
|
|
251 |
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size
|
|
252 |
'xxx2' asFilename delete.
|
|
253 |
|
|
254 |
"
|
|
255 |
self new testOpen2
|
|
256 |
"
|
|
257 |
|
|
258 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
259 |
!
|
|
260 |
|
|
261 |
testRead1
|
|
262 |
"open an existing file for reading; should read 10 chars"
|
|
263 |
|
|
264 |
|h buffer nBytesRead|
|
|
265 |
|
|
266 |
self createWithSize10:'xxx2'.
|
|
267 |
|
|
268 |
h := OperatingSystem openFileForRead:'xxx2'.
|
|
269 |
|
|
270 |
buffer := ExternalBytes new:10.
|
|
271 |
nBytesRead := h readBytes:10 into:buffer startingAt:1.
|
|
272 |
|
|
273 |
h close.
|
|
274 |
|
|
275 |
self assert:(nBytesRead == 10).
|
|
276 |
self assert:(buffer asString = '1234567890').
|
|
277 |
|
|
278 |
'xxx2' asFilename delete.
|
|
279 |
|
|
280 |
"
|
|
281 |
self new testRead1
|
|
282 |
"
|
|
283 |
|
|
284 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
285 |
!
|
|
286 |
|
|
287 |
testRead2
|
|
288 |
"open an existing file for reading; should read 10 chars"
|
|
289 |
|
|
290 |
|h buffer nBytesRead|
|
|
291 |
|
|
292 |
self createWithSize10:'xxx2'.
|
|
293 |
|
|
294 |
h := OperatingSystem openFileForRead:'xxx2'.
|
|
295 |
|
|
296 |
buffer := ExternalBytes new:20.
|
|
297 |
nBytesRead := h readBytes:20 into:buffer startingAt:1.
|
|
298 |
|
|
299 |
h close.
|
|
300 |
|
|
301 |
self assert:(nBytesRead == 10).
|
|
302 |
self assert:(buffer asString startsWith:'1234567890').
|
|
303 |
|
|
304 |
'xxx2' asFilename delete.
|
|
305 |
|
|
306 |
"
|
|
307 |
self new testRead2
|
|
308 |
"
|
|
309 |
|
|
310 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
311 |
!
|
|
312 |
|
|
313 |
xtestFailCreate1
|
|
314 |
"try to create an uncreatable new file (directory not existing)"
|
|
315 |
|
|
316 |
|fn|
|
|
317 |
|
|
318 |
fn := (('.' asFilename construct:'foo') construct:'bar') construct:'xxx1'.
|
|
319 |
OperatingSystem createFileForReadWrite:fn name
|
|
320 |
|
|
321 |
"
|
|
322 |
self new xtestFailCreate1
|
|
323 |
"
|
|
324 |
|
|
325 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
326 |
!
|
|
327 |
|
|
328 |
xtestFailOpen2
|
|
329 |
"open a non-existing file for writing; must fail"
|
|
330 |
|
|
331 |
|h|
|
|
332 |
|
|
333 |
'xxx2' asFilename delete.
|
|
334 |
|
|
335 |
h := OperatingSystem openFileForWrite:'xxx2'.
|
|
336 |
h close
|
|
337 |
|
|
338 |
|
|
339 |
"
|
|
340 |
self new xtestFailOpen2
|
|
341 |
"
|
|
342 |
|
|
343 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
122
|
344 |
! !
|
|
345 |
|
|
346 |
!FileOpenTest class methodsFor:'documentation'!
|
|
347 |
|
|
348 |
version
|
|
349 |
^ '$Header$'
|
|
350 |
! !
|