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]
|
|
106 |
raise:(OSErrorHolder unavailableReferentSignal).
|
|
107 |
|
|
108 |
"/ raised signal should be a child of inaccessibleSignal
|
|
109 |
self
|
|
110 |
should:[
|
|
111 |
OperatingSystem createFileForReadWrite:fn name]
|
|
112 |
raise:(OSErrorHolder inaccessibleSignal ).
|
|
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 |
|
|
147 |
testOpen1
|
|
148 |
"open an existing file"
|
|
149 |
|
|
150 |
|h|
|
|
151 |
|
|
152 |
self createWithSize10:'xxx2'.
|
|
153 |
|
|
154 |
h := OperatingSystem openFileForRead:'xxx2'.
|
122
|
155 |
self assert:(h notNil).
|
123
|
156 |
self assert:(h isValid).
|
|
157 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
158 |
self assert:(h address ~~ 0).
|
|
159 |
].
|
122
|
160 |
|
|
161 |
h close.
|
123
|
162 |
self assert:(h isValid not).
|
|
163 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
164 |
self assert:(h address == 0).
|
|
165 |
].
|
122
|
166 |
|
125
|
167 |
'xxx2' asFilename delete.
|
|
168 |
|
122
|
169 |
"
|
|
170 |
self new testOpen1
|
|
171 |
"
|
|
172 |
|
|
173 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
174 |
! !
|
|
175 |
|
|
176 |
!FileOpenTest class methodsFor:'documentation'!
|
|
177 |
|
|
178 |
version
|
|
179 |
^ '$Header$'
|
|
180 |
! !
|