sl@0
|
1 |
# This file (ioUtil.test) tests the hookable TclStat(), TclAccess(),
|
sl@0
|
2 |
# and Tcl_OpenFileChannel, routines in the file generic/tclIOUtils.c.
|
sl@0
|
3 |
# Sourcing this file into Tcl runs the tests and generates output for
|
sl@0
|
4 |
# errors. No output means no errors were found.
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
7 |
#
|
sl@0
|
8 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
9 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# RCS: @(#) $Id: ioUtil.test,v 1.13.2.1 2003/04/14 15:45:57 vincentdarley Exp $
|
sl@0
|
12 |
|
sl@0
|
13 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
14 |
package require tcltest 2
|
sl@0
|
15 |
namespace import -force ::tcltest::*
|
sl@0
|
16 |
}
|
sl@0
|
17 |
|
sl@0
|
18 |
::tcltest::testConstraint testopenfilechannelproc \
|
sl@0
|
19 |
[llength [info commands testopenfilechannelproc]]
|
sl@0
|
20 |
::tcltest::testConstraint testaccessproc \
|
sl@0
|
21 |
[llength [info commands testaccessproc]]
|
sl@0
|
22 |
::tcltest::testConstraint teststatproc \
|
sl@0
|
23 |
[llength [info commands teststatproc]]
|
sl@0
|
24 |
|
sl@0
|
25 |
set unsetScript {
|
sl@0
|
26 |
catch {unset testStat1(size)}
|
sl@0
|
27 |
catch {unset testStat2(size)}
|
sl@0
|
28 |
catch {unset testStat3(size)}
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
test ioUtil-1.1 {TclStat: Check that none of the test procs are there.} {} {
|
sl@0
|
32 |
catch {file stat testStat1%.fil testStat1} err1
|
sl@0
|
33 |
catch {file stat testStat2%.fil testStat2} err2
|
sl@0
|
34 |
catch {file stat testStat3%.fil testStat3} err3
|
sl@0
|
35 |
list $err1 $err2 $err3
|
sl@0
|
36 |
} {{could not read "testStat1%.fil": no such file or directory} {could not read "testStat2%.fil": no such file or directory} {could not read "testStat3%.fil": no such file or directory}}
|
sl@0
|
37 |
|
sl@0
|
38 |
test ioUtil-1.2 {TclStatInsertProc: Insert the 3 test TclStat_ procedures.} {teststatproc} {
|
sl@0
|
39 |
catch {teststatproc insert TclpStat} err1
|
sl@0
|
40 |
teststatproc insert TestStatProc1
|
sl@0
|
41 |
teststatproc insert TestStatProc2
|
sl@0
|
42 |
teststatproc insert TestStatProc3
|
sl@0
|
43 |
set err1
|
sl@0
|
44 |
} {bad arg "insert": must be TestStatProc1, TestStatProc2, or TestStatProc3}
|
sl@0
|
45 |
|
sl@0
|
46 |
test ioUtil-1.3 {TclStat: Use "file stat ?" to invoke each procedure.} {teststatproc} {
|
sl@0
|
47 |
file stat testStat2%.fil testStat2
|
sl@0
|
48 |
file stat testStat1%.fil testStat1
|
sl@0
|
49 |
file stat testStat3%.fil testStat3
|
sl@0
|
50 |
|
sl@0
|
51 |
list $testStat2(size) $testStat1(size) $testStat3(size)
|
sl@0
|
52 |
} {2345 1234 3456}
|
sl@0
|
53 |
|
sl@0
|
54 |
eval $unsetScript
|
sl@0
|
55 |
|
sl@0
|
56 |
test ioUtil-1.4 {TclStatDeleteProc: "TclpStat" function should not be deletable.} {teststatproc} {
|
sl@0
|
57 |
catch {teststatproc delete TclpStat} err2
|
sl@0
|
58 |
set err2
|
sl@0
|
59 |
} {"TclpStat": could not be deleteed}
|
sl@0
|
60 |
|
sl@0
|
61 |
test ioUtil-1.5 {TclStatDeleteProc: Delete the 2nd TclStat procedure.} {teststatproc} {
|
sl@0
|
62 |
# Delete the 2nd procedure and test that it longer exists but that
|
sl@0
|
63 |
# the others do actually return a result.
|
sl@0
|
64 |
|
sl@0
|
65 |
teststatproc delete TestStatProc2
|
sl@0
|
66 |
file stat testStat1%.fil testStat1
|
sl@0
|
67 |
catch {file stat testStat2%.fil testStat2} err3
|
sl@0
|
68 |
file stat testStat3%.fil testStat3
|
sl@0
|
69 |
|
sl@0
|
70 |
list $testStat1(size) $err3 $testStat3(size)
|
sl@0
|
71 |
} {1234 {could not read "testStat2%.fil": no such file or directory} 3456}
|
sl@0
|
72 |
|
sl@0
|
73 |
eval $unsetScript
|
sl@0
|
74 |
|
sl@0
|
75 |
test ioUtil-1.6 {TclStatDeleteProc: Delete the 1st TclStat procedure.} {teststatproc} {
|
sl@0
|
76 |
# Next delete the 1st procedure and test that only the 3rd procedure
|
sl@0
|
77 |
# is the only one that exists.
|
sl@0
|
78 |
|
sl@0
|
79 |
teststatproc delete TestStatProc1
|
sl@0
|
80 |
catch {file stat testStat1%.fil testStat1} err4
|
sl@0
|
81 |
catch {file stat testStat2%.fil testStat2} err5
|
sl@0
|
82 |
file stat testStat3%.fil testStat3
|
sl@0
|
83 |
|
sl@0
|
84 |
list $err4 $err5 $testStat3(size)
|
sl@0
|
85 |
} {{could not read "testStat1%.fil": no such file or directory} {could not read "testStat2%.fil": no such file or directory} 3456}
|
sl@0
|
86 |
|
sl@0
|
87 |
eval $unsetScript
|
sl@0
|
88 |
|
sl@0
|
89 |
test ioUtil-1.7 {TclStatDeleteProc: Delete the 3rd procedure & verify all are gone.} {teststatproc} {
|
sl@0
|
90 |
# Finally delete the 3rd procedure and check that none of the
|
sl@0
|
91 |
# procedures exist.
|
sl@0
|
92 |
|
sl@0
|
93 |
teststatproc delete TestStatProc3
|
sl@0
|
94 |
catch {file stat testStat1%.fil testStat1} err6
|
sl@0
|
95 |
catch {file stat testStat2%.fil testStat2} err7
|
sl@0
|
96 |
catch {file stat testStat3%.fil testStat3} err8
|
sl@0
|
97 |
|
sl@0
|
98 |
list $err6 $err7 $err8
|
sl@0
|
99 |
} {{could not read "testStat1%.fil": no such file or directory} {could not read "testStat2%.fil": no such file or directory} {could not read "testStat3%.fil": no such file or directory}}
|
sl@0
|
100 |
|
sl@0
|
101 |
eval $unsetScript
|
sl@0
|
102 |
|
sl@0
|
103 |
test ioUtil-1.8 {TclStatDeleteProc: Verify that all procs have been deleted.} {teststatproc} {
|
sl@0
|
104 |
# Attempt to delete all the Stat procs. again to ensure they no longer
|
sl@0
|
105 |
# exist and an error is returned.
|
sl@0
|
106 |
|
sl@0
|
107 |
catch {teststatproc delete TestStatProc1} err9
|
sl@0
|
108 |
catch {teststatproc delete TestStatProc2} err10
|
sl@0
|
109 |
catch {teststatproc delete TestStatProc3} err11
|
sl@0
|
110 |
|
sl@0
|
111 |
list $err9 $err10 $err11
|
sl@0
|
112 |
} {{"TestStatProc1": could not be deleteed} {"TestStatProc2": could not be deleteed} {"TestStatProc3": could not be deleteed}}
|
sl@0
|
113 |
|
sl@0
|
114 |
eval $unsetScript
|
sl@0
|
115 |
|
sl@0
|
116 |
test ioUtil-1.9 {TclAccess: Check that none of the test procs are there.} {
|
sl@0
|
117 |
catch {file exists testAccess1%.fil} err1
|
sl@0
|
118 |
catch {file exists testAccess2%.fil} err2
|
sl@0
|
119 |
catch {file exists testAccess3%.fil} err3
|
sl@0
|
120 |
list $err1 $err2 $err3
|
sl@0
|
121 |
} {0 0 0}
|
sl@0
|
122 |
|
sl@0
|
123 |
test ioUtil-1.10 {TclAccessInsertProc: Insert the 3 test TclAccess_ procedures.} {testaccessproc} {
|
sl@0
|
124 |
catch {testaccessproc insert TclpAccess} err1
|
sl@0
|
125 |
testaccessproc insert TestAccessProc1
|
sl@0
|
126 |
testaccessproc insert TestAccessProc2
|
sl@0
|
127 |
testaccessproc insert TestAccessProc3
|
sl@0
|
128 |
set err1
|
sl@0
|
129 |
} {bad arg "insert": must be TestAccessProc1, TestAccessProc2, or TestAccessProc3}
|
sl@0
|
130 |
|
sl@0
|
131 |
test ioUtil-2.3 {TclAccess: Use "file access ?" to invoke each procedure.} {testaccessproc} {
|
sl@0
|
132 |
list [file exists testAccess2%.fil] \
|
sl@0
|
133 |
[file exists testAccess1%.fil] \
|
sl@0
|
134 |
[file exists testAccess3%.fil]
|
sl@0
|
135 |
} {1 1 1}
|
sl@0
|
136 |
|
sl@0
|
137 |
test ioUtil-2.4 {TclAccessDeleteProc: "TclpAccess" function should not be deletable.} {testaccessproc} {
|
sl@0
|
138 |
catch {testaccessproc delete TclpAccess} err2
|
sl@0
|
139 |
set err2
|
sl@0
|
140 |
} {"TclpAccess": could not be deleteed}
|
sl@0
|
141 |
|
sl@0
|
142 |
test ioUtil-2.5 {TclAccessDeleteProc: Delete the 2nd TclAccess procedure.} {testaccessproc} {
|
sl@0
|
143 |
# Delete the 2nd procedure and test that it longer exists but that
|
sl@0
|
144 |
# the others do actually return a result.
|
sl@0
|
145 |
|
sl@0
|
146 |
testaccessproc delete TestAccessProc2
|
sl@0
|
147 |
set res1 [file exists testAccess1%.fil]
|
sl@0
|
148 |
catch {file exists testAccess2%.fil} err3
|
sl@0
|
149 |
set res2 [file exists testAccess3%.fil]
|
sl@0
|
150 |
|
sl@0
|
151 |
list $res1 $err3 $res2
|
sl@0
|
152 |
} {1 0 1}
|
sl@0
|
153 |
|
sl@0
|
154 |
test ioUtil-2.6 {TclAccessDeleteProc: Delete the 1st TclAccess procedure.} {testaccessproc} {
|
sl@0
|
155 |
# Next delete the 1st procedure and test that only the 3rd procedure
|
sl@0
|
156 |
# is the only one that exists.
|
sl@0
|
157 |
|
sl@0
|
158 |
testaccessproc delete TestAccessProc1
|
sl@0
|
159 |
catch {file exists testAccess1%.fil} err4
|
sl@0
|
160 |
catch {file exists testAccess2%.fil} err5
|
sl@0
|
161 |
set res3 [file exists testAccess3%.fil]
|
sl@0
|
162 |
|
sl@0
|
163 |
list $err4 $err5 $res3
|
sl@0
|
164 |
} {0 0 1}
|
sl@0
|
165 |
|
sl@0
|
166 |
test ioUtil-2.7 {TclAccessDeleteProc: Delete the 3rd procedure & verify all are gone.} {testaccessproc} {
|
sl@0
|
167 |
# Finally delete the 3rd procedure and check that none of the
|
sl@0
|
168 |
# procedures exist.
|
sl@0
|
169 |
|
sl@0
|
170 |
testaccessproc delete TestAccessProc3
|
sl@0
|
171 |
catch {file exists testAccess1%.fil} err6
|
sl@0
|
172 |
catch {file exists testAccess2%.fil} err7
|
sl@0
|
173 |
catch {file exists testAccess3%.fil} err8
|
sl@0
|
174 |
|
sl@0
|
175 |
list $err6 $err7 $err8
|
sl@0
|
176 |
} {0 0 0}
|
sl@0
|
177 |
|
sl@0
|
178 |
test ioUtil-2.8 {TclAccessDeleteProc: Verify that all procs have been deleted.} {testaccessproc} {
|
sl@0
|
179 |
# Attempt to delete all the Access procs. again to ensure they no longer
|
sl@0
|
180 |
# exist and an error is returned.
|
sl@0
|
181 |
|
sl@0
|
182 |
catch {testaccessproc delete TestAccessProc1} err9
|
sl@0
|
183 |
catch {testaccessproc delete TestAccessProc2} err10
|
sl@0
|
184 |
catch {testaccessproc delete TestAccessProc3} err11
|
sl@0
|
185 |
|
sl@0
|
186 |
list $err9 $err10 $err11
|
sl@0
|
187 |
} {{"TestAccessProc1": could not be deleteed} {"TestAccessProc2": could not be deleteed} {"TestAccessProc3": could not be deleteed}}
|
sl@0
|
188 |
|
sl@0
|
189 |
# Some of the following tests require a writable current directory
|
sl@0
|
190 |
set oldpwd [pwd]
|
sl@0
|
191 |
cd [temporaryDirectory]
|
sl@0
|
192 |
|
sl@0
|
193 |
test ioUtil-3.1 {TclOpenFileChannel: Check that none of the test procs are there.} {testopenfilechannelproc} {
|
sl@0
|
194 |
catch {eval [list file delete -force] [glob *testOpenFileChannel*]}
|
sl@0
|
195 |
catch {file exists testOpenFileChannel1%.fil} err1
|
sl@0
|
196 |
catch {file exists testOpenFileChannel2%.fil} err2
|
sl@0
|
197 |
catch {file exists testOpenFileChannel3%.fil} err3
|
sl@0
|
198 |
catch {file exists __testOpenFileChannel1%__.fil} err4
|
sl@0
|
199 |
catch {file exists __testOpenFileChannel2%__.fil} err5
|
sl@0
|
200 |
catch {file exists __testOpenFileChannel3%__.fil} err6
|
sl@0
|
201 |
list $err1 $err2 $err3 $err4 $err5 $err6
|
sl@0
|
202 |
} {0 0 0 0 0 0}
|
sl@0
|
203 |
|
sl@0
|
204 |
test ioUtil-3.2 {TclOpenFileChannelInsertProc: Insert the 3 test TclOpenFileChannel_ procedures.} {testopenfilechannelproc} {
|
sl@0
|
205 |
catch {testopenfilechannelproc insert TclpOpenFileChannel} err1
|
sl@0
|
206 |
testopenfilechannelproc insert TestOpenFileChannelProc1
|
sl@0
|
207 |
testopenfilechannelproc insert TestOpenFileChannelProc2
|
sl@0
|
208 |
testopenfilechannelproc insert TestOpenFileChannelProc3
|
sl@0
|
209 |
set err1
|
sl@0
|
210 |
} {bad arg "insert": must be TestOpenFileChannelProc1, TestOpenFileChannelProc2, or TestOpenFileChannelProc3}
|
sl@0
|
211 |
|
sl@0
|
212 |
test ioUtil-3.3 {TclOpenFileChannel: Use "file openfilechannel ?" to invoke each procedure.} {testopenfilechannelproc} {
|
sl@0
|
213 |
close [open __testOpenFileChannel1%__.fil w]
|
sl@0
|
214 |
close [open __testOpenFileChannel2%__.fil w]
|
sl@0
|
215 |
close [open __testOpenFileChannel3%__.fil w]
|
sl@0
|
216 |
|
sl@0
|
217 |
catch {
|
sl@0
|
218 |
close [open testOpenFileChannel1%.fil r]
|
sl@0
|
219 |
close [open testOpenFileChannel2%.fil r]
|
sl@0
|
220 |
close [open testOpenFileChannel3%.fil r]
|
sl@0
|
221 |
} err
|
sl@0
|
222 |
|
sl@0
|
223 |
file delete __testOpenFileChannel1%__.fil
|
sl@0
|
224 |
file delete __testOpenFileChannel2%__.fil
|
sl@0
|
225 |
file delete __testOpenFileChannel3%__.fil
|
sl@0
|
226 |
|
sl@0
|
227 |
set err
|
sl@0
|
228 |
} {}
|
sl@0
|
229 |
|
sl@0
|
230 |
test ioUtil-3.4 {TclOpenFileChannelDeleteProc: "TclpOpenFileChannel" function should not be deletable.} {testopenfilechannelproc} {
|
sl@0
|
231 |
catch {testopenfilechannelproc delete TclpOpenFileChannel} err2
|
sl@0
|
232 |
set err2
|
sl@0
|
233 |
} {"TclpOpenFileChannel": could not be deleteed}
|
sl@0
|
234 |
|
sl@0
|
235 |
test ioUtil-3.5 {TclOpenFileChannelDeleteProc: Delete the 2nd TclOpenFileChannel procedure.} {testopenfilechannelproc} {
|
sl@0
|
236 |
# Delete the 2nd procedure and test that it longer exists but that
|
sl@0
|
237 |
# the others do actually return a result.
|
sl@0
|
238 |
|
sl@0
|
239 |
testopenfilechannelproc delete TestOpenFileChannelProc2
|
sl@0
|
240 |
|
sl@0
|
241 |
close [open __testOpenFileChannel1%__.fil w]
|
sl@0
|
242 |
close [open __testOpenFileChannel3%__.fil w]
|
sl@0
|
243 |
|
sl@0
|
244 |
catch {
|
sl@0
|
245 |
close [open testOpenFileChannel1%.fil r]
|
sl@0
|
246 |
catch {close [open testOpenFileChannel2%.fil r]} msg1
|
sl@0
|
247 |
close [open testOpenFileChannel3%.fil r]
|
sl@0
|
248 |
} err3
|
sl@0
|
249 |
|
sl@0
|
250 |
file delete __testOpenFileChannel1%__.fil
|
sl@0
|
251 |
file delete __testOpenFileChannel3%__.fil
|
sl@0
|
252 |
|
sl@0
|
253 |
list $err3 $msg1
|
sl@0
|
254 |
} {{} {couldn't open "testOpenFileChannel2%.fil": no such file or directory}}
|
sl@0
|
255 |
|
sl@0
|
256 |
test ioUtil-3.6 {TclOpenFileChannelDeleteProc: Delete the 1st TclOpenFileChannel procedure.} {testopenfilechannelproc} {
|
sl@0
|
257 |
# Next delete the 1st procedure and test that only the 3rd procedure
|
sl@0
|
258 |
# is the only one that exists.
|
sl@0
|
259 |
|
sl@0
|
260 |
testopenfilechannelproc delete TestOpenFileChannelProc1
|
sl@0
|
261 |
|
sl@0
|
262 |
close [open __testOpenFileChannel3%__.fil w]
|
sl@0
|
263 |
|
sl@0
|
264 |
catch {
|
sl@0
|
265 |
catch {close [open testOpenFileChannel1%.fil r]} msg2
|
sl@0
|
266 |
catch {close [open testOpenFileChannel2%.fil r]} msg3
|
sl@0
|
267 |
close [open testOpenFileChannel3%.fil r]
|
sl@0
|
268 |
} err4
|
sl@0
|
269 |
|
sl@0
|
270 |
file delete __testOpenFileChannel3%__.fil
|
sl@0
|
271 |
|
sl@0
|
272 |
list $err4 $msg2 $msg3
|
sl@0
|
273 |
} [list {} \
|
sl@0
|
274 |
{couldn't open "testOpenFileChannel1%.fil": no such file or directory}\
|
sl@0
|
275 |
{couldn't open "testOpenFileChannel2%.fil": no such file or directory}]
|
sl@0
|
276 |
|
sl@0
|
277 |
test ioUtil-3.7 {TclOpenFileChannelDeleteProc: Delete the 3rd procedure & verify all are gone.} {testopenfilechannelproc} {
|
sl@0
|
278 |
# Finally delete the 3rd procedure and check that none of the
|
sl@0
|
279 |
# procedures exist.
|
sl@0
|
280 |
|
sl@0
|
281 |
testopenfilechannelproc delete TestOpenFileChannelProc3
|
sl@0
|
282 |
catch {
|
sl@0
|
283 |
catch {close [open testOpenFileChannel1%.fil r]} msg4
|
sl@0
|
284 |
catch {close [open testOpenFileChannel2%.fil r]} msg5
|
sl@0
|
285 |
catch {close [open testOpenFileChannel3%.fil r]} msg6
|
sl@0
|
286 |
} err5
|
sl@0
|
287 |
|
sl@0
|
288 |
list $err5 $msg4 $msg5 $msg6
|
sl@0
|
289 |
} [list 1 \
|
sl@0
|
290 |
{couldn't open "testOpenFileChannel1%.fil": no such file or directory}\
|
sl@0
|
291 |
{couldn't open "testOpenFileChannel2%.fil": no such file or directory}\
|
sl@0
|
292 |
{couldn't open "testOpenFileChannel3%.fil": no such file or directory}]
|
sl@0
|
293 |
|
sl@0
|
294 |
test ioUtil-3.8 {TclOpenFileChannelDeleteProc: Verify that all procs have been deleted.} {testopenfilechannelproc} {
|
sl@0
|
295 |
|
sl@0
|
296 |
# Attempt to delete all the OpenFileChannel procs. again to ensure they no
|
sl@0
|
297 |
# longer exist and an error is returned.
|
sl@0
|
298 |
|
sl@0
|
299 |
catch {testopenfilechannelproc delete TestOpenFileChannelProc1} err9
|
sl@0
|
300 |
catch {testopenfilechannelproc delete TestOpenFileChannelProc2} err10
|
sl@0
|
301 |
catch {testopenfilechannelproc delete TestOpenFileChannelProc3} err11
|
sl@0
|
302 |
|
sl@0
|
303 |
list $err9 $err10 $err11
|
sl@0
|
304 |
} {{"TestOpenFileChannelProc1": could not be deleteed} {"TestOpenFileChannelProc2": could not be deleteed} {"TestOpenFileChannelProc3": could not be deleteed}}
|
sl@0
|
305 |
|
sl@0
|
306 |
cd $oldpwd
|
sl@0
|
307 |
|
sl@0
|
308 |
# cleanup
|
sl@0
|
309 |
::tcltest::cleanupTests
|
sl@0
|
310 |
return
|