1 | # This file contains a collection of tests for the procedures in the file |
---|
2 | # tclEvent.c, which includes the "update", and "vwait" Tcl |
---|
3 | # commands. Sourcing this file into Tcl runs the tests and generates |
---|
4 | # output for errors. No output means no errors were found. |
---|
5 | # |
---|
6 | # Copyright (c) 1995-1997 Sun Microsystems, Inc. |
---|
7 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
8 | # |
---|
9 | # See the file "license.terms" for information on usage and redistribution |
---|
10 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | # |
---|
12 | # RCS: @(#) $Id: event.test,v 1.27 2008/03/10 17:54:47 dgp Exp $ |
---|
13 | |
---|
14 | package require tcltest 2 |
---|
15 | namespace import -force ::tcltest::* |
---|
16 | |
---|
17 | testConstraint testfilehandler [llength [info commands testfilehandler]] |
---|
18 | testConstraint testexithandler [llength [info commands testexithandler]] |
---|
19 | testConstraint testfilewait [llength [info commands testfilewait]] |
---|
20 | |
---|
21 | test event-1.1 {Tcl_CreateFileHandler, reading} {testfilehandler} { |
---|
22 | testfilehandler close |
---|
23 | testfilehandler create 0 readable off |
---|
24 | testfilehandler clear 0 |
---|
25 | testfilehandler oneevent |
---|
26 | set result "" |
---|
27 | lappend result [testfilehandler counts 0] |
---|
28 | testfilehandler fillpartial 0 |
---|
29 | testfilehandler oneevent |
---|
30 | lappend result [testfilehandler counts 0] |
---|
31 | testfilehandler oneevent |
---|
32 | lappend result [testfilehandler counts 0] |
---|
33 | testfilehandler close |
---|
34 | set result |
---|
35 | } {{0 0} {1 0} {2 0}} |
---|
36 | test event-1.2 {Tcl_CreateFileHandler, writing} {testfilehandler nonPortable} { |
---|
37 | # This test is non-portable because on some systems (e.g. |
---|
38 | # SunOS 4.1.3) pipes seem to be writable always. |
---|
39 | testfilehandler close |
---|
40 | testfilehandler create 0 off writable |
---|
41 | testfilehandler clear 0 |
---|
42 | testfilehandler oneevent |
---|
43 | set result "" |
---|
44 | lappend result [testfilehandler counts 0] |
---|
45 | testfilehandler fillpartial 0 |
---|
46 | testfilehandler oneevent |
---|
47 | lappend result [testfilehandler counts 0] |
---|
48 | testfilehandler fill 0 |
---|
49 | testfilehandler oneevent |
---|
50 | lappend result [testfilehandler counts 0] |
---|
51 | testfilehandler close |
---|
52 | set result |
---|
53 | } {{0 1} {0 2} {0 2}} |
---|
54 | test event-1.3 {Tcl_DeleteFileHandler} {testfilehandler nonPortable} { |
---|
55 | testfilehandler close |
---|
56 | testfilehandler create 2 disabled disabled |
---|
57 | testfilehandler create 1 readable writable |
---|
58 | testfilehandler create 0 disabled disabled |
---|
59 | testfilehandler fillpartial 1 |
---|
60 | set result "" |
---|
61 | testfilehandler oneevent |
---|
62 | lappend result [testfilehandler counts 1] |
---|
63 | testfilehandler oneevent |
---|
64 | lappend result [testfilehandler counts 1] |
---|
65 | testfilehandler oneevent |
---|
66 | lappend result [testfilehandler counts 1] |
---|
67 | testfilehandler create 1 off off |
---|
68 | testfilehandler oneevent |
---|
69 | lappend result [testfilehandler counts 1] |
---|
70 | testfilehandler close |
---|
71 | set result |
---|
72 | } {{0 1} {1 1} {1 2} {0 0}} |
---|
73 | |
---|
74 | test event-2.1 {Tcl_DeleteFileHandler} {testfilehandler nonPortable} { |
---|
75 | testfilehandler close |
---|
76 | testfilehandler create 2 disabled disabled |
---|
77 | testfilehandler create 1 readable writable |
---|
78 | testfilehandler fillpartial 1 |
---|
79 | set result "" |
---|
80 | testfilehandler oneevent |
---|
81 | lappend result [testfilehandler counts 1] |
---|
82 | testfilehandler oneevent |
---|
83 | lappend result [testfilehandler counts 1] |
---|
84 | testfilehandler oneevent |
---|
85 | lappend result [testfilehandler counts 1] |
---|
86 | testfilehandler create 1 off off |
---|
87 | testfilehandler oneevent |
---|
88 | lappend result [testfilehandler counts 1] |
---|
89 | testfilehandler close |
---|
90 | set result |
---|
91 | } {{0 1} {1 1} {1 2} {0 0}} |
---|
92 | test event-2.2 {Tcl_DeleteFileHandler, fd reused & events still pending} \ |
---|
93 | {testfilehandler nonPortable} { |
---|
94 | testfilehandler close |
---|
95 | testfilehandler create 0 readable writable |
---|
96 | testfilehandler fillpartial 0 |
---|
97 | set result "" |
---|
98 | testfilehandler oneevent |
---|
99 | lappend result [testfilehandler counts 0] |
---|
100 | testfilehandler close |
---|
101 | testfilehandler create 0 readable writable |
---|
102 | testfilehandler oneevent |
---|
103 | lappend result [testfilehandler counts 0] |
---|
104 | testfilehandler close |
---|
105 | set result |
---|
106 | } {{0 1} {0 0}} |
---|
107 | |
---|
108 | test event-3.1 {FileHandlerCheckProc, TCL_FILE_EVENTS off } {testfilehandler} { |
---|
109 | testfilehandler close |
---|
110 | testfilehandler create 1 readable writable |
---|
111 | testfilehandler fillpartial 1 |
---|
112 | testfilehandler windowevent |
---|
113 | set result [testfilehandler counts 1] |
---|
114 | testfilehandler close |
---|
115 | set result |
---|
116 | } {0 0} |
---|
117 | |
---|
118 | test event-4.1 {FileHandlerEventProc, race between event and disabling} \ |
---|
119 | {testfilehandler nonPortable} { |
---|
120 | update |
---|
121 | testfilehandler close |
---|
122 | testfilehandler create 2 disabled disabled |
---|
123 | testfilehandler create 1 readable writable |
---|
124 | testfilehandler fillpartial 1 |
---|
125 | set result "" |
---|
126 | testfilehandler oneevent |
---|
127 | lappend result [testfilehandler counts 1] |
---|
128 | testfilehandler oneevent |
---|
129 | lappend result [testfilehandler counts 1] |
---|
130 | testfilehandler oneevent |
---|
131 | lappend result [testfilehandler counts 1] |
---|
132 | testfilehandler create 1 disabled disabled |
---|
133 | testfilehandler oneevent |
---|
134 | lappend result [testfilehandler counts 1] |
---|
135 | testfilehandler close |
---|
136 | set result |
---|
137 | } {{0 1} {1 1} {1 2} {0 0}} |
---|
138 | test event-4.2 {FileHandlerEventProc, TCL_FILE_EVENTS off} \ |
---|
139 | {testfilehandler nonPortable} { |
---|
140 | update |
---|
141 | testfilehandler close |
---|
142 | testfilehandler create 1 readable writable |
---|
143 | testfilehandler create 2 readable writable |
---|
144 | testfilehandler fillpartial 1 |
---|
145 | testfilehandler fillpartial 2 |
---|
146 | testfilehandler oneevent |
---|
147 | set result "" |
---|
148 | lappend result [testfilehandler counts 1] [testfilehandler counts 2] |
---|
149 | testfilehandler windowevent |
---|
150 | lappend result [testfilehandler counts 1] [testfilehandler counts 2] |
---|
151 | testfilehandler close |
---|
152 | set result |
---|
153 | } {{0 0} {0 1} {0 0} {0 1}} |
---|
154 | update |
---|
155 | |
---|
156 | test event-5.1 {Tcl_BackgroundError, HandleBgErrors procedures} { |
---|
157 | catch {rename bgerror {}} |
---|
158 | proc bgerror msg { |
---|
159 | global errorInfo errorCode x |
---|
160 | lappend x [list $msg $errorInfo $errorCode] |
---|
161 | } |
---|
162 | after idle {error "a simple error"} |
---|
163 | after idle {open non_existent} |
---|
164 | after idle {set errorInfo foobar; set errorCode xyzzy} |
---|
165 | set x {} |
---|
166 | update idletasks |
---|
167 | rename bgerror {} |
---|
168 | regsub -all [file join {} non_existent] $x "non_existent" x |
---|
169 | set x |
---|
170 | } {{{a simple error} {a simple error |
---|
171 | while executing |
---|
172 | "error "a simple error"" |
---|
173 | ("after" script)} NONE} {{couldn't open "non_existent": no such file or directory} {couldn't open "non_existent": no such file or directory |
---|
174 | while executing |
---|
175 | "open non_existent" |
---|
176 | ("after" script)} {POSIX ENOENT {no such file or directory}}}} |
---|
177 | test event-5.2 {Tcl_BackgroundError, HandleBgErrors procedures} { |
---|
178 | catch {rename bgerror {}} |
---|
179 | proc bgerror msg { |
---|
180 | global x |
---|
181 | lappend x $msg |
---|
182 | return -code break |
---|
183 | } |
---|
184 | after idle {error "a simple error"} |
---|
185 | after idle {open non_existent} |
---|
186 | set x {} |
---|
187 | update idletasks |
---|
188 | rename bgerror {} |
---|
189 | set x |
---|
190 | } {{a simple error}} |
---|
191 | test event-5.3 {HandleBgErrors: [Bug 1670155]} -setup { |
---|
192 | variable x |
---|
193 | proc demo args {variable x done} |
---|
194 | variable target [list [namespace which demo] x] |
---|
195 | proc trial args {variable target; string length $target} |
---|
196 | trace add execution demo enter [namespace code trial] |
---|
197 | variable save [interp bgerror {}] |
---|
198 | interp bgerror {} $target |
---|
199 | } -body { |
---|
200 | after 0 {error bar} |
---|
201 | vwait [namespace which -variable x] |
---|
202 | } -cleanup { |
---|
203 | interp bgerror {} $save |
---|
204 | unset x target save |
---|
205 | rename demo {} |
---|
206 | rename trial {} |
---|
207 | } -result {} |
---|
208 | test event-5.3 {Default [interp bgerror] handler} -body { |
---|
209 | ::tcl::Bgerror |
---|
210 | } -returnCodes error -match glob -result {*msg options*} |
---|
211 | test event-5.4 {Default [interp bgerror] handler} -body { |
---|
212 | ::tcl::Bgerror {} |
---|
213 | } -returnCodes error -match glob -result {*msg options*} |
---|
214 | test event-5.5 {Default [interp bgerror] handler} -body { |
---|
215 | ::tcl::Bgerror {} {} {} |
---|
216 | } -returnCodes error -match glob -result {*msg options*} |
---|
217 | test event-5.6 {Default [interp bgerror] handler} -body { |
---|
218 | ::tcl::Bgerror {} {} |
---|
219 | } -returnCodes error -match glob -result {*-level*} |
---|
220 | test event-5.7 {Default [interp bgerror] handler} -body { |
---|
221 | ::tcl::Bgerror {} {-level foo} |
---|
222 | } -returnCodes error -match glob -result {*expected integer*} |
---|
223 | test event-5.8 {Default [interp bgerror] handler} -body { |
---|
224 | ::tcl::Bgerror {} {-level 0} |
---|
225 | } -returnCodes error -match glob -result {*-code*} |
---|
226 | test event-5.9 {Default [interp bgerror] handler} -body { |
---|
227 | ::tcl::Bgerror {} {-level 0 -code ok} |
---|
228 | } -returnCodes error -match glob -result {*expected integer*} |
---|
229 | test event-5.10 {Default [interp bgerror] handler} { |
---|
230 | proc bgerror {m} {append ::res $m} |
---|
231 | set ::res {} |
---|
232 | ::tcl::Bgerror {} {-level 0 -code 0} |
---|
233 | rename bgerror {} |
---|
234 | set ::res |
---|
235 | } {} |
---|
236 | test event-5.11 {Default [interp bgerror] handler} { |
---|
237 | proc bgerror {m} {append ::res $m} |
---|
238 | set ::res {} |
---|
239 | ::tcl::Bgerror msg {-level 0 -code 1} |
---|
240 | rename bgerror {} |
---|
241 | set ::res |
---|
242 | } {msg} |
---|
243 | test event-5.12 {Default [interp bgerror] handler} { |
---|
244 | proc bgerror {m} {append ::res $m} |
---|
245 | set ::res {} |
---|
246 | ::tcl::Bgerror msg {-level 0 -code 2} |
---|
247 | rename bgerror {} |
---|
248 | set ::res |
---|
249 | } {command returned bad code: 2} |
---|
250 | test event-5.13 {Default [interp bgerror] handler} { |
---|
251 | proc bgerror {m} {append ::res $m} |
---|
252 | set ::res {} |
---|
253 | ::tcl::Bgerror msg {-level 0 -code 3} |
---|
254 | rename bgerror {} |
---|
255 | set ::res |
---|
256 | } {invoked "break" outside of a loop} |
---|
257 | test event-5.14 {Default [interp bgerror] handler} { |
---|
258 | proc bgerror {m} {append ::res $m} |
---|
259 | set ::res {} |
---|
260 | ::tcl::Bgerror msg {-level 0 -code 4} |
---|
261 | rename bgerror {} |
---|
262 | set ::res |
---|
263 | } {invoked "continue" outside of a loop} |
---|
264 | test event-5.15 {Default [interp bgerror] handler} { |
---|
265 | proc bgerror {m} {append ::res $m} |
---|
266 | set ::res {} |
---|
267 | ::tcl::Bgerror msg {-level 0 -code 5} |
---|
268 | rename bgerror {} |
---|
269 | set ::res |
---|
270 | } {command returned bad code: 5} |
---|
271 | |
---|
272 | test event-6.1 {BgErrorDeleteProc procedure} { |
---|
273 | catch {interp delete foo} |
---|
274 | interp create foo |
---|
275 | set erroutfile [makeFile Unmodified err.out] |
---|
276 | foo eval [list set erroutfile $erroutfile] |
---|
277 | foo eval { |
---|
278 | proc bgerror args { |
---|
279 | global errorInfo erroutfile |
---|
280 | set f [open $erroutfile r+] |
---|
281 | seek $f 0 end |
---|
282 | puts $f "$args $errorInfo" |
---|
283 | close $f |
---|
284 | } |
---|
285 | after 100 {error "first error"} |
---|
286 | after 100 {error "second error"} |
---|
287 | } |
---|
288 | after 100 {interp delete foo} |
---|
289 | after 200 |
---|
290 | update |
---|
291 | set f [open $erroutfile r] |
---|
292 | set result [read $f] |
---|
293 | close $f |
---|
294 | removeFile $erroutfile |
---|
295 | set result |
---|
296 | } {Unmodified |
---|
297 | } |
---|
298 | |
---|
299 | test event-7.1 {bgerror / regular} { |
---|
300 | set errRes {} |
---|
301 | proc bgerror {err} { |
---|
302 | global errRes; |
---|
303 | set errRes $err; |
---|
304 | } |
---|
305 | after 0 {error err1} |
---|
306 | vwait errRes; |
---|
307 | set errRes; |
---|
308 | } err1 |
---|
309 | |
---|
310 | test event-7.2 {bgerror / accumulation} { |
---|
311 | set errRes {} |
---|
312 | proc bgerror {err} { |
---|
313 | global errRes; |
---|
314 | lappend errRes $err; |
---|
315 | } |
---|
316 | after 0 {error err1} |
---|
317 | after 0 {error err2} |
---|
318 | after 0 {error err3} |
---|
319 | update |
---|
320 | set errRes; |
---|
321 | } {err1 err2 err3} |
---|
322 | |
---|
323 | test event-7.3 {bgerror / accumulation / break} { |
---|
324 | set errRes {} |
---|
325 | proc bgerror {err} { |
---|
326 | global errRes; |
---|
327 | lappend errRes $err; |
---|
328 | return -code break "skip!"; |
---|
329 | } |
---|
330 | after 0 {error err1} |
---|
331 | after 0 {error err2} |
---|
332 | after 0 {error err3} |
---|
333 | update |
---|
334 | set errRes; |
---|
335 | } err1 |
---|
336 | |
---|
337 | test event-7.4 {tkerror is nothing special anymore to tcl} { |
---|
338 | set errRes {} |
---|
339 | # we don't just rename bgerror to empty because it could then |
---|
340 | # be autoloaded... |
---|
341 | proc bgerror {err} { |
---|
342 | global errRes; |
---|
343 | lappend errRes "bg:$err"; |
---|
344 | } |
---|
345 | proc tkerror {err} { |
---|
346 | global errRes; |
---|
347 | lappend errRes "tk:$err"; |
---|
348 | } |
---|
349 | after 0 {error err1} |
---|
350 | update |
---|
351 | rename tkerror {} |
---|
352 | set errRes |
---|
353 | } bg:err1 |
---|
354 | |
---|
355 | testConstraint exec [llength [info commands exec]] |
---|
356 | |
---|
357 | test event-7.5 {correct behaviour when there is no bgerror [Bug 219142]} {exec} { |
---|
358 | set script { |
---|
359 | after 1000 error hello |
---|
360 | after 2000 set a 0 |
---|
361 | vwait a |
---|
362 | } |
---|
363 | |
---|
364 | list [catch {exec [interpreter] << $script} errMsg] $errMsg |
---|
365 | } {1 {hello |
---|
366 | while executing |
---|
367 | "error hello" |
---|
368 | ("after" script)}} |
---|
369 | |
---|
370 | test event-7.6 {safe hidden bgerror fallback} { |
---|
371 | variable result {} |
---|
372 | interp create -safe safe |
---|
373 | safe alias puts puts |
---|
374 | safe alias result ::append [namespace which -variable result] |
---|
375 | safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} |
---|
376 | safe hide bgerror |
---|
377 | safe eval after 0 error foo |
---|
378 | update |
---|
379 | interp delete safe |
---|
380 | set result |
---|
381 | } {foo |
---|
382 | NONE |
---|
383 | foo |
---|
384 | while executing |
---|
385 | "error foo" |
---|
386 | ("after" script) |
---|
387 | } |
---|
388 | |
---|
389 | test event-7.7 {safe hidden bgerror fallback} { |
---|
390 | variable result {} |
---|
391 | interp create -safe safe |
---|
392 | safe alias puts puts |
---|
393 | safe alias result ::append [namespace which -variable result] |
---|
394 | safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} |
---|
395 | safe hide bgerror |
---|
396 | safe eval {proc bgerror m {error bar soom baz}} |
---|
397 | safe eval after 0 error foo |
---|
398 | update |
---|
399 | interp delete safe |
---|
400 | set result |
---|
401 | } {foo |
---|
402 | NONE |
---|
403 | foo |
---|
404 | while executing |
---|
405 | "error foo" |
---|
406 | ("after" script) |
---|
407 | } |
---|
408 | |
---|
409 | |
---|
410 | # someday : add a test checking that |
---|
411 | # when there is no bgerror, an error msg goes to stderr |
---|
412 | # ideally one would use sub interp and transfer a fake stderr |
---|
413 | # to it, unfortunatly the current interp tcl API does not allow |
---|
414 | # that. the other option would be to use fork a test but it |
---|
415 | # then becomes more a file/exec test than a bgerror test. |
---|
416 | |
---|
417 | # end of bgerror tests |
---|
418 | catch {rename bgerror {}} |
---|
419 | |
---|
420 | |
---|
421 | test event-8.1 {Tcl_CreateExitHandler procedure} {stdio testexithandler} { |
---|
422 | set child [open |[list [interpreter]] r+] |
---|
423 | puts $child "testexithandler create 41; testexithandler create 4" |
---|
424 | puts $child "testexithandler create 6; exit" |
---|
425 | flush $child |
---|
426 | set result [read $child] |
---|
427 | close $child |
---|
428 | set result |
---|
429 | } {even 6 |
---|
430 | even 4 |
---|
431 | odd 41 |
---|
432 | } |
---|
433 | |
---|
434 | test event-9.1 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} { |
---|
435 | set child [open |[list [interpreter]] r+] |
---|
436 | puts $child "testexithandler create 41; testexithandler create 4" |
---|
437 | puts $child "testexithandler create 6; testexithandler delete 41" |
---|
438 | puts $child "testexithandler create 16; exit" |
---|
439 | flush $child |
---|
440 | set result [read $child] |
---|
441 | close $child |
---|
442 | set result |
---|
443 | } {even 16 |
---|
444 | even 6 |
---|
445 | even 4 |
---|
446 | } |
---|
447 | test event-9.2 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} { |
---|
448 | set child [open |[list [interpreter]] r+] |
---|
449 | puts $child "testexithandler create 41; testexithandler create 4" |
---|
450 | puts $child "testexithandler create 6; testexithandler delete 4" |
---|
451 | puts $child "testexithandler create 16; exit" |
---|
452 | flush $child |
---|
453 | set result [read $child] |
---|
454 | close $child |
---|
455 | set result |
---|
456 | } {even 16 |
---|
457 | even 6 |
---|
458 | odd 41 |
---|
459 | } |
---|
460 | test event-9.3 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} { |
---|
461 | set child [open |[list [interpreter]] r+] |
---|
462 | puts $child "testexithandler create 41; testexithandler create 4" |
---|
463 | puts $child "testexithandler create 6; testexithandler delete 6" |
---|
464 | puts $child "testexithandler create 16; exit" |
---|
465 | flush $child |
---|
466 | set result [read $child] |
---|
467 | close $child |
---|
468 | set result |
---|
469 | } {even 16 |
---|
470 | even 4 |
---|
471 | odd 41 |
---|
472 | } |
---|
473 | test event-9.4 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} { |
---|
474 | set child [open |[list [interpreter]] r+] |
---|
475 | puts $child "testexithandler create 41; testexithandler delete 41" |
---|
476 | puts $child "testexithandler create 16; exit" |
---|
477 | flush $child |
---|
478 | set result [read $child] |
---|
479 | close $child |
---|
480 | set result |
---|
481 | } {even 16 |
---|
482 | } |
---|
483 | |
---|
484 | test event-10.1 {Tcl_Exit procedure} {stdio} { |
---|
485 | set child [open |[list [interpreter]] r+] |
---|
486 | puts $child "exit 3" |
---|
487 | list [catch {close $child} msg] $msg [lindex $::errorCode 0] \ |
---|
488 | [lindex $::errorCode 2] |
---|
489 | } {1 {child process exited abnormally} CHILDSTATUS 3} |
---|
490 | |
---|
491 | test event-11.1 {Tcl_VwaitCmd procedure} { |
---|
492 | list [catch {vwait} msg] $msg |
---|
493 | } {1 {wrong # args: should be "vwait name"}} |
---|
494 | test event-11.2 {Tcl_VwaitCmd procedure} { |
---|
495 | list [catch {vwait a b} msg] $msg |
---|
496 | } {1 {wrong # args: should be "vwait name"}} |
---|
497 | test event-11.3 {Tcl_VwaitCmd procedure} { |
---|
498 | catch {unset x} |
---|
499 | set x 1 |
---|
500 | list [catch {vwait x(1)} msg] $msg |
---|
501 | } {1 {can't trace "x(1)": variable isn't array}} |
---|
502 | test event-11.4 {Tcl_VwaitCmd procedure} {} { |
---|
503 | foreach i [after info] { |
---|
504 | after cancel $i |
---|
505 | } |
---|
506 | after 10; update; # On Mac make sure update won't take long |
---|
507 | after 100 {set x x-done} |
---|
508 | after 200 {set y y-done} |
---|
509 | after 300 {set z z-done} |
---|
510 | after idle {set q q-done} |
---|
511 | set x before |
---|
512 | set y before |
---|
513 | set z before |
---|
514 | set q before |
---|
515 | list [vwait y] $x $y $z $q |
---|
516 | } {{} x-done y-done before q-done} |
---|
517 | |
---|
518 | foreach i [after info] { |
---|
519 | after cancel $i |
---|
520 | } |
---|
521 | |
---|
522 | test event-11.5 {Tcl_VwaitCmd procedure: round robin scheduling, 2 sources} {socket} { |
---|
523 | set test1file [makeFile "" test1] |
---|
524 | set f1 [open $test1file w] |
---|
525 | proc accept {s args} { |
---|
526 | puts $s foobar |
---|
527 | close $s |
---|
528 | } |
---|
529 | catch {set s1 [socket -server accept -myaddr 127.0.0.1 0]} |
---|
530 | after 1000 |
---|
531 | catch {set s2 [socket 127.0.0.1 [lindex [fconfigure $s1 -sockname] 2]]} |
---|
532 | close $s1 |
---|
533 | set x 0 |
---|
534 | set y 0 |
---|
535 | set z 0 |
---|
536 | fileevent $s2 readable {incr z} |
---|
537 | vwait z |
---|
538 | fileevent $f1 writable {incr x; if {$y == 3} {set z done}} |
---|
539 | fileevent $s2 readable {incr y; if {$x == 3} {set z done}} |
---|
540 | vwait z |
---|
541 | close $f1 |
---|
542 | close $s2 |
---|
543 | removeFile $test1file |
---|
544 | list $x $y $z |
---|
545 | } {3 3 done} |
---|
546 | test event-11.6 {Tcl_VwaitCmd procedure: round robin scheduling, same source} { |
---|
547 | set test1file [makeFile "" test1] |
---|
548 | set test2file [makeFile "" test2] |
---|
549 | set f1 [open $test1file w] |
---|
550 | set f2 [open $test2file w] |
---|
551 | set x 0 |
---|
552 | set y 0 |
---|
553 | set z 0 |
---|
554 | update |
---|
555 | fileevent $f1 writable {incr x; if {$y == 3} {set z done}} |
---|
556 | fileevent $f2 writable {incr y; if {$x == 3} {set z done}} |
---|
557 | vwait z |
---|
558 | close $f1 |
---|
559 | close $f2 |
---|
560 | removeFile $test1file |
---|
561 | removeFile $test2file |
---|
562 | list $x $y $z |
---|
563 | } {3 3 done} |
---|
564 | |
---|
565 | |
---|
566 | test event-12.1 {Tcl_UpdateCmd procedure} { |
---|
567 | list [catch {update a b} msg] $msg |
---|
568 | } {1 {wrong # args: should be "update ?idletasks?"}} |
---|
569 | test event-12.2 {Tcl_UpdateCmd procedure} { |
---|
570 | list [catch {update bogus} msg] $msg |
---|
571 | } {1 {bad option "bogus": must be idletasks}} |
---|
572 | test event-12.3 {Tcl_UpdateCmd procedure} { |
---|
573 | foreach i [after info] { |
---|
574 | after cancel $i |
---|
575 | } |
---|
576 | after 500 {set x after} |
---|
577 | after idle {set y after} |
---|
578 | after idle {set z "after, y = $y"} |
---|
579 | set x before |
---|
580 | set y before |
---|
581 | set z before |
---|
582 | update idletasks |
---|
583 | list $x $y $z |
---|
584 | } {before after {after, y = after}} |
---|
585 | test event-12.4 {Tcl_UpdateCmd procedure} { |
---|
586 | foreach i [after info] { |
---|
587 | after cancel $i |
---|
588 | } |
---|
589 | after 10; update; # On Mac make sure update won't take long |
---|
590 | after 200 {set x x-done} |
---|
591 | after 600 {set y y-done} |
---|
592 | after idle {set z z-done} |
---|
593 | set x before |
---|
594 | set y before |
---|
595 | set z before |
---|
596 | after 300 |
---|
597 | update |
---|
598 | list $x $y $z |
---|
599 | } {x-done before z-done} |
---|
600 | |
---|
601 | test event-13.1 {Tcl_WaitForFile procedure, readable} {testfilehandler} { |
---|
602 | foreach i [after info] { |
---|
603 | after cancel $i |
---|
604 | } |
---|
605 | after 100 set x timeout |
---|
606 | testfilehandler close |
---|
607 | testfilehandler create 1 off off |
---|
608 | set x "no timeout" |
---|
609 | set result [testfilehandler wait 1 readable 0] |
---|
610 | update |
---|
611 | testfilehandler close |
---|
612 | list $result $x |
---|
613 | } {{} {no timeout}} |
---|
614 | test event-13.2 {Tcl_WaitForFile procedure, readable} testfilehandler { |
---|
615 | foreach i [after info] { |
---|
616 | after cancel $i |
---|
617 | } |
---|
618 | after 100 set x timeout |
---|
619 | testfilehandler close |
---|
620 | testfilehandler create 1 off off |
---|
621 | set x "no timeout" |
---|
622 | set result [testfilehandler wait 1 readable 100] |
---|
623 | update |
---|
624 | testfilehandler close |
---|
625 | list $result $x |
---|
626 | } {{} timeout} |
---|
627 | test event-13.3 {Tcl_WaitForFile procedure, readable} testfilehandler { |
---|
628 | foreach i [after info] { |
---|
629 | after cancel $i |
---|
630 | } |
---|
631 | after 100 set x timeout |
---|
632 | testfilehandler close |
---|
633 | testfilehandler create 1 off off |
---|
634 | testfilehandler fillpartial 1 |
---|
635 | set x "no timeout" |
---|
636 | set result [testfilehandler wait 1 readable 100] |
---|
637 | update |
---|
638 | testfilehandler close |
---|
639 | list $result $x |
---|
640 | } {readable {no timeout}} |
---|
641 | test event-13.4 {Tcl_WaitForFile procedure, writable} \ |
---|
642 | {testfilehandler nonPortable} { |
---|
643 | foreach i [after info] { |
---|
644 | after cancel $i |
---|
645 | } |
---|
646 | after 100 set x timeout |
---|
647 | testfilehandler close |
---|
648 | testfilehandler create 1 off off |
---|
649 | testfilehandler fill 1 |
---|
650 | set x "no timeout" |
---|
651 | set result [testfilehandler wait 1 writable 0] |
---|
652 | update |
---|
653 | testfilehandler close |
---|
654 | list $result $x |
---|
655 | } {{} {no timeout}} |
---|
656 | test event-13.5 {Tcl_WaitForFile procedure, writable} \ |
---|
657 | {testfilehandler nonPortable} { |
---|
658 | foreach i [after info] { |
---|
659 | after cancel $i |
---|
660 | } |
---|
661 | after 100 set x timeout |
---|
662 | testfilehandler close |
---|
663 | testfilehandler create 1 off off |
---|
664 | testfilehandler fill 1 |
---|
665 | set x "no timeout" |
---|
666 | set result [testfilehandler wait 1 writable 100] |
---|
667 | update |
---|
668 | testfilehandler close |
---|
669 | list $result $x |
---|
670 | } {{} timeout} |
---|
671 | test event-13.6 {Tcl_WaitForFile procedure, writable} testfilehandler { |
---|
672 | foreach i [after info] { |
---|
673 | after cancel $i |
---|
674 | } |
---|
675 | after 100 set x timeout |
---|
676 | testfilehandler close |
---|
677 | testfilehandler create 1 off off |
---|
678 | set x "no timeout" |
---|
679 | set result [testfilehandler wait 1 writable 100] |
---|
680 | update |
---|
681 | testfilehandler close |
---|
682 | list $result $x |
---|
683 | } {writable {no timeout}} |
---|
684 | test event-13.7 {Tcl_WaitForFile procedure, don't call other event handlers} testfilehandler { |
---|
685 | foreach i [after info] { |
---|
686 | after cancel $i |
---|
687 | } |
---|
688 | after 100 lappend x timeout |
---|
689 | after idle lappend x idle |
---|
690 | testfilehandler close |
---|
691 | testfilehandler create 1 off off |
---|
692 | set x "" |
---|
693 | set result [list [testfilehandler wait 1 readable 200] $x] |
---|
694 | update |
---|
695 | testfilehandler close |
---|
696 | lappend result $x |
---|
697 | } {{} {} {timeout idle}} |
---|
698 | |
---|
699 | test event-13.8 {Tcl_WaitForFile procedure, waiting indefinitely} testfilewait { |
---|
700 | set f [open "|sleep 2" r] |
---|
701 | set result "" |
---|
702 | lappend result [testfilewait $f readable 100] |
---|
703 | lappend result [testfilewait $f readable -1] |
---|
704 | close $f |
---|
705 | set result |
---|
706 | } {{} readable} |
---|
707 | |
---|
708 | |
---|
709 | test event-14.1 {Tcl_WaitForFile procedure, readable, big fd} \ |
---|
710 | -constraints {testfilehandler unix} \ |
---|
711 | -setup { |
---|
712 | set chanList {} |
---|
713 | for {set i 0} {$i < 32} {incr i} { |
---|
714 | lappend chanList [open /dev/null r] |
---|
715 | } |
---|
716 | } \ |
---|
717 | -body { |
---|
718 | foreach i [after info] { |
---|
719 | after cancel $i |
---|
720 | } |
---|
721 | after 100 set x timeout |
---|
722 | testfilehandler close |
---|
723 | testfilehandler create 1 off off |
---|
724 | set x "no timeout" |
---|
725 | set result [testfilehandler wait 1 readable 0] |
---|
726 | update |
---|
727 | testfilehandler close |
---|
728 | list $result $x |
---|
729 | } \ |
---|
730 | -result {{} {no timeout}} \ |
---|
731 | -cleanup { |
---|
732 | foreach chan $chanList {close $chan} |
---|
733 | } |
---|
734 | |
---|
735 | test event-14.2 {Tcl_WaitForFile procedure, readable, big fd} \ |
---|
736 | -constraints {testfilehandler unix} \ |
---|
737 | -setup { |
---|
738 | set chanList {} |
---|
739 | for {set i 0} {$i < 32} {incr i} { |
---|
740 | lappend chanList [open /dev/null r] |
---|
741 | } |
---|
742 | } \ |
---|
743 | -body { |
---|
744 | foreach i [after info] { |
---|
745 | after cancel $i |
---|
746 | } |
---|
747 | after 100 set x timeout |
---|
748 | testfilehandler close |
---|
749 | testfilehandler create 1 off off |
---|
750 | set x "no timeout" |
---|
751 | set result [testfilehandler wait 1 readable 100] |
---|
752 | update |
---|
753 | testfilehandler close |
---|
754 | list $result $x |
---|
755 | } \ |
---|
756 | -result {{} timeout} \ |
---|
757 | -cleanup { |
---|
758 | foreach chan $chanList {close $chan} |
---|
759 | } |
---|
760 | |
---|
761 | test event-14.3 {Tcl_WaitForFile procedure, readable, big fd} \ |
---|
762 | -constraints {testfilehandler unix} \ |
---|
763 | -setup { |
---|
764 | set chanList {} |
---|
765 | for {set i 0} {$i < 32} {incr i} { |
---|
766 | lappend chanList [open /dev/null r] |
---|
767 | } |
---|
768 | } \ |
---|
769 | -body { |
---|
770 | foreach i [after info] { |
---|
771 | after cancel $i |
---|
772 | } |
---|
773 | after 100 set x timeout |
---|
774 | testfilehandler close |
---|
775 | testfilehandler create 1 off off |
---|
776 | testfilehandler fillpartial 1 |
---|
777 | set x "no timeout" |
---|
778 | set result [testfilehandler wait 1 readable 100] |
---|
779 | update |
---|
780 | testfilehandler close |
---|
781 | list $result $x |
---|
782 | } \ |
---|
783 | -result {readable {no timeout}} \ |
---|
784 | -cleanup { |
---|
785 | foreach chan $chanList {close $chan} |
---|
786 | } |
---|
787 | |
---|
788 | test event-14.4 {Tcl_WaitForFile procedure, writable, big fd} \ |
---|
789 | -constraints {testfilehandler unix nonPortable} \ |
---|
790 | -setup { |
---|
791 | set chanList {} |
---|
792 | for {set i 0} {$i < 32} {incr i} { |
---|
793 | lappend chanList [open /dev/null r] |
---|
794 | } |
---|
795 | } \ |
---|
796 | -body { |
---|
797 | foreach i [after info] { |
---|
798 | after cancel $i |
---|
799 | } |
---|
800 | after 100 set x timeout |
---|
801 | testfilehandler close |
---|
802 | testfilehandler create 1 off off |
---|
803 | testfilehandler fill 1 |
---|
804 | set x "no timeout" |
---|
805 | set result [testfilehandler wait 1 writable 0] |
---|
806 | update |
---|
807 | testfilehandler close |
---|
808 | list $result $ |
---|
809 | } \ |
---|
810 | -result {{} {no timeout}} \ |
---|
811 | -cleanup { |
---|
812 | foreach chan $chanList {close $chan} |
---|
813 | } |
---|
814 | |
---|
815 | test event-14.5 {Tcl_WaitForFile procedure, writable, big fd} \ |
---|
816 | -constraints {testfilehandler unix nonPortable} \ |
---|
817 | -setup { |
---|
818 | set chanList {} |
---|
819 | for {set i 0} {$i < 32} {incr i} { |
---|
820 | lappend chanList [open /dev/null r] |
---|
821 | } |
---|
822 | } \ |
---|
823 | -body { |
---|
824 | foreach i [after info] { |
---|
825 | after cancel $i |
---|
826 | } |
---|
827 | after 100 set x timeout |
---|
828 | testfilehandler close |
---|
829 | testfilehandler create 1 off off |
---|
830 | testfilehandler fill 1 |
---|
831 | set x "no timeout" |
---|
832 | set result [testfilehandler wait 1 writable 100] |
---|
833 | update |
---|
834 | testfilehandler close |
---|
835 | list $result $x |
---|
836 | } \ |
---|
837 | -result {{} timeout} \ |
---|
838 | -cleanup { |
---|
839 | foreach chan $chanList {close $chan} |
---|
840 | } |
---|
841 | |
---|
842 | test event-14.6 {Tcl_WaitForFile procedure, writable, big fd} \ |
---|
843 | -constraints {testfilehandler unix} \ |
---|
844 | -setup { |
---|
845 | set chanList {} |
---|
846 | for {set i 0} {$i < 32} {incr i} { |
---|
847 | lappend chanList [open /dev/null r] |
---|
848 | } |
---|
849 | } \ |
---|
850 | -body { |
---|
851 | foreach i [after info] { |
---|
852 | after cancel $i |
---|
853 | } |
---|
854 | after 100 set x timeout |
---|
855 | testfilehandler close |
---|
856 | testfilehandler create 1 off off |
---|
857 | set x "no timeout" |
---|
858 | set result [testfilehandler wait 1 writable 100] |
---|
859 | update |
---|
860 | testfilehandler close |
---|
861 | list $result $x |
---|
862 | } \ |
---|
863 | -result {writable {no timeout}} \ |
---|
864 | -cleanup { |
---|
865 | foreach chan $chanList {close $chan} |
---|
866 | } |
---|
867 | |
---|
868 | test event-14.7 {Tcl_WaitForFile, don't call other event handlers, big fd} \ |
---|
869 | -constraints {testfilehandler unix} \ |
---|
870 | -setup { |
---|
871 | set chanList {} |
---|
872 | for {set i 0} {$i < 32} {incr i} { |
---|
873 | lappend chanList [open /dev/null r] |
---|
874 | } |
---|
875 | } \ |
---|
876 | -body { |
---|
877 | foreach i [after info] { |
---|
878 | after cancel $i |
---|
879 | } |
---|
880 | after 100 lappend x timeout |
---|
881 | after idle lappend x idle |
---|
882 | testfilehandler close |
---|
883 | testfilehandler create 1 off off |
---|
884 | set x "" |
---|
885 | set result [list [testfilehandler wait 1 readable 200] $x] |
---|
886 | update |
---|
887 | testfilehandler close |
---|
888 | lappend result $x |
---|
889 | } \ |
---|
890 | -result {{} {} {timeout idle}} \ |
---|
891 | -cleanup { |
---|
892 | foreach chan $chanList {close $chan} |
---|
893 | } |
---|
894 | |
---|
895 | |
---|
896 | test event-14.8 {Tcl_WaitForFile procedure, waiting indefinitely, big fd} \ |
---|
897 | -constraints {testfilewait unix} \ |
---|
898 | -body { |
---|
899 | set f [open "|sleep 2" r] |
---|
900 | set result "" |
---|
901 | lappend result [testfilewait $f readable 100] |
---|
902 | lappend result [testfilewait $f readable -1] |
---|
903 | close $f |
---|
904 | set result |
---|
905 | } \ |
---|
906 | -setup { |
---|
907 | set chanList {} |
---|
908 | for {set i 0} {$i < 32} {incr i} { |
---|
909 | lappend chanList [open /dev/null r] |
---|
910 | } |
---|
911 | } \ |
---|
912 | -result {{} readable} \ |
---|
913 | -cleanup { |
---|
914 | foreach chan $chanList {close $chan} |
---|
915 | } |
---|
916 | |
---|
917 | # cleanup |
---|
918 | foreach i [after info] { |
---|
919 | after cancel $i |
---|
920 | } |
---|
921 | ::tcltest::cleanupTests |
---|
922 | return |
---|