os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/event.test
Update contrib.
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.
6 # Copyright (c) 1995-1997 Sun Microsystems, Inc.
7 # Copyright (c) 1998-1999 by Scriptics Corporation.
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 # RCS: @(#) $Id: event.test,v 1.20.2.1 2006/11/28 16:29:47 kennykb Exp $
14 package require tcltest 2
15 namespace import -force ::tcltest::*
17 testConstraint testfilehandler [llength [info commands testfilehandler]]
18 testConstraint testexithandler [llength [info commands testexithandler]]
19 testConstraint testfilewait [llength [info commands testfilewait]]
21 test event-1.1 {Tcl_CreateFileHandler, reading} {testfilehandler} {
23 testfilehandler create 0 readable off
24 testfilehandler clear 0
25 testfilehandler oneevent
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]
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.
40 testfilehandler create 0 off writable
41 testfilehandler clear 0
42 testfilehandler oneevent
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]
54 test event-1.3 {Tcl_DeleteFileHandler} {testfilehandler nonPortable} {
56 testfilehandler create 2 disabled disabled
57 testfilehandler create 1 readable writable
58 testfilehandler create 0 disabled disabled
59 testfilehandler fillpartial 1
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]
72 } {{0 1} {1 1} {1 2} {0 0}}
74 test event-2.1 {Tcl_DeleteFileHandler} {testfilehandler nonPortable} {
76 testfilehandler create 2 disabled disabled
77 testfilehandler create 1 readable writable
78 testfilehandler fillpartial 1
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]
91 } {{0 1} {1 1} {1 2} {0 0}}
92 test event-2.2 {Tcl_DeleteFileHandler, fd reused & events still pending} \
93 {testfilehandler nonPortable} {
95 testfilehandler create 0 readable writable
96 testfilehandler fillpartial 0
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
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
118 test event-4.1 {FileHandlerEventProc, race between event and disabling} \
119 {testfilehandler nonPortable} {
121 testfilehandler close
122 testfilehandler create 2 disabled disabled
123 testfilehandler create 1 readable writable
124 testfilehandler fillpartial 1
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
137 } {{0 1} {1 1} {1 2} {0 0}}
138 test event-4.2 {FileHandlerEventProc, TCL_FILE_EVENTS off} \
139 {testfilehandler nonPortable} {
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
148 lappend result [testfilehandler counts 1] [testfilehandler counts 2]
149 testfilehandler windowevent
150 lappend result [testfilehandler counts 1] [testfilehandler counts 2]
151 testfilehandler close
153 } {{0 0} {0 1} {0 0} {0 1}}
156 test event-5.1 {Tcl_BackgroundError, HandleBgErrors procedures} {
157 catch {rename bgerror {}}
159 global errorInfo errorCode x
160 lappend x [list $msg $errorInfo $errorCode]
162 after idle {error "a simple error"}
163 after idle {open non_existent}
164 after idle {set errorInfo foobar; set errorCode xyzzy}
168 regsub -all [file join {} non_existent] $x "non_existent" x
170 } {{{a simple error} {a simple error
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
176 ("after" script)} {POSIX ENOENT {no such file or directory}}}}
177 test event-5.2 {Tcl_BackgroundError, HandleBgErrors procedures} {
178 catch {rename bgerror {}}
184 after idle {error "a simple error"}
185 after idle {open non_existent}
192 test event-6.1 {BgErrorDeleteProc procedure} {
193 catch {interp delete foo}
195 set erroutfile [makeFile Unmodified err.out]
196 foo eval [list set erroutfile $erroutfile]
199 global errorInfo erroutfile
200 set f [open $erroutfile r+]
202 puts $f "$args $errorInfo"
205 after 100 {error "first error"}
206 after 100 {error "second error"}
208 after 100 {interp delete foo}
211 set f [open $erroutfile r]
214 removeFile $erroutfile
219 test event-7.1 {bgerror / regular} {
230 test event-7.2 {bgerror / accumulation} {
243 test event-7.3 {bgerror / accumulation / break} {
248 return -code break "skip!";
257 test event-7.4 {tkerror is nothing special anymore to tcl} {
259 # we don't just rename bgerror to empty because it could then
263 lappend errRes "bg:$err";
267 lappend errRes "tk:$err";
275 testConstraint exec [llength [info commands exec]]
277 test event-7.5 {correct behaviour when there is no bgerror [Bug 219142]} {exec} {
279 after 1000 error hello
284 list [catch {exec [interpreter] << $script} errMsg] $errMsg
291 # someday : add a test checking that
292 # when there is no bgerror, an error msg goes to stderr
293 # ideally one would use sub interp and transfer a fake stderr
294 # to it, unfortunatly the current interp tcl API does not allow
295 # that. the other option would be to use fork a test but it
296 # then becomes more a file/exec test than a bgerror test.
298 # end of bgerror tests
299 catch {rename bgerror {}}
302 test event-8.1 {Tcl_CreateExitHandler procedure} {stdio testexithandler} {
303 set child [open |[list [interpreter]] r+]
304 puts $child "testexithandler create 41; testexithandler create 4"
305 puts $child "testexithandler create 6; exit"
307 set result [read $child]
315 test event-9.1 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} {
316 set child [open |[list [interpreter]] r+]
317 puts $child "testexithandler create 41; testexithandler create 4"
318 puts $child "testexithandler create 6; testexithandler delete 41"
319 puts $child "testexithandler create 16; exit"
321 set result [read $child]
328 test event-9.2 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} {
329 set child [open |[list [interpreter]] r+]
330 puts $child "testexithandler create 41; testexithandler create 4"
331 puts $child "testexithandler create 6; testexithandler delete 4"
332 puts $child "testexithandler create 16; exit"
334 set result [read $child]
341 test event-9.3 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} {
342 set child [open |[list [interpreter]] r+]
343 puts $child "testexithandler create 41; testexithandler create 4"
344 puts $child "testexithandler create 6; testexithandler delete 6"
345 puts $child "testexithandler create 16; exit"
347 set result [read $child]
354 test event-9.4 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} {
355 set child [open |[list [interpreter]] r+]
356 puts $child "testexithandler create 41; testexithandler delete 41"
357 puts $child "testexithandler create 16; exit"
359 set result [read $child]
365 test event-10.1 {Tcl_Exit procedure} {stdio} {
366 set child [open |[list [interpreter]] r+]
368 list [catch {close $child} msg] $msg [lindex $errorCode 0] \
369 [lindex $errorCode 2]
370 } {1 {child process exited abnormally} CHILDSTATUS 3}
372 test event-11.1 {Tcl_VwaitCmd procedure} {
373 list [catch {vwait} msg] $msg
374 } {1 {wrong # args: should be "vwait name"}}
375 test event-11.2 {Tcl_VwaitCmd procedure} {
376 list [catch {vwait a b} msg] $msg
377 } {1 {wrong # args: should be "vwait name"}}
378 test event-11.3 {Tcl_VwaitCmd procedure} {
381 list [catch {vwait x(1)} msg] $msg
382 } {1 {can't trace "x(1)": variable isn't array}}
383 test event-11.4 {Tcl_VwaitCmd procedure} {} {
384 foreach i [after info] {
387 after 10; update; # On Mac make sure update won't take long
388 after 100 {set x x-done}
389 after 200 {set y y-done}
390 after 300 {set z z-done}
391 after idle {set q q-done}
396 list [vwait y] $x $y $z $q
397 } {{} x-done y-done before q-done}
399 foreach i [after info] {
403 test event-11.5 {Tcl_VwaitCmd procedure: round robin scheduling, 2 sources} {socket} {
404 set test1file [makeFile "" test1]
405 set f1 [open $test1file w]
406 proc accept {s args} {
410 catch {set s1 [socket -server accept 0]}
412 catch {set s2 [socket 127.0.0.1 [lindex [fconfigure $s1 -sockname] 2]]}
417 fileevent $s2 readable {incr z}
419 fileevent $f1 writable {incr x; if {$y == 3} {set z done}}
420 fileevent $s2 readable {incr y; if {$x == 3} {set z done}}
424 removeFile $test1file
427 test event-11.6 {Tcl_VwaitCmd procedure: round robin scheduling, same source} {
428 set test1file [makeFile "" test1]
429 set test2file [makeFile "" test2]
430 set f1 [open $test1file w]
431 set f2 [open $test2file w]
436 fileevent $f1 writable {incr x; if {$y == 3} {set z done}}
437 fileevent $f2 writable {incr y; if {$x == 3} {set z done}}
441 removeFile $test1file
442 removeFile $test2file
447 test event-12.1 {Tcl_UpdateCmd procedure} {
448 list [catch {update a b} msg] $msg
449 } {1 {wrong # args: should be "update ?idletasks?"}}
450 test event-12.2 {Tcl_UpdateCmd procedure} {
451 list [catch {update bogus} msg] $msg
452 } {1 {bad option "bogus": must be idletasks}}
453 test event-12.3 {Tcl_UpdateCmd procedure} {
454 foreach i [after info] {
457 after 500 {set x after}
458 after idle {set y after}
459 after idle {set z "after, y = $y"}
465 } {before after {after, y = after}}
466 test event-12.4 {Tcl_UpdateCmd procedure} {
467 foreach i [after info] {
470 after 10; update; # On Mac make sure update won't take long
471 after 200 {set x x-done}
472 after 600 {set y y-done}
473 after idle {set z z-done}
480 } {x-done before z-done}
482 test event-13.1 {Tcl_WaitForFile procedure, readable} {testfilehandler} {
483 foreach i [after info] {
486 after 100 set x timeout
487 testfilehandler close
488 testfilehandler create 1 off off
490 set result [testfilehandler wait 1 readable 0]
492 testfilehandler close
495 test event-13.2 {Tcl_WaitForFile procedure, readable} testfilehandler {
496 foreach i [after info] {
499 after 100 set x timeout
500 testfilehandler close
501 testfilehandler create 1 off off
503 set result [testfilehandler wait 1 readable 100]
505 testfilehandler close
508 test event-13.3 {Tcl_WaitForFile procedure, readable} testfilehandler {
509 foreach i [after info] {
512 after 100 set x timeout
513 testfilehandler close
514 testfilehandler create 1 off off
515 testfilehandler fillpartial 1
517 set result [testfilehandler wait 1 readable 100]
519 testfilehandler close
521 } {readable {no timeout}}
522 test event-13.4 {Tcl_WaitForFile procedure, writable} \
523 {testfilehandler nonPortable} {
524 foreach i [after info] {
527 after 100 set x timeout
528 testfilehandler close
529 testfilehandler create 1 off off
530 testfilehandler fill 1
532 set result [testfilehandler wait 1 writable 0]
534 testfilehandler close
537 test event-13.5 {Tcl_WaitForFile procedure, writable} \
538 {testfilehandler nonPortable} {
539 foreach i [after info] {
542 after 100 set x timeout
543 testfilehandler close
544 testfilehandler create 1 off off
545 testfilehandler fill 1
547 set result [testfilehandler wait 1 writable 100]
549 testfilehandler close
552 test event-13.6 {Tcl_WaitForFile procedure, writable} testfilehandler {
553 foreach i [after info] {
556 after 100 set x timeout
557 testfilehandler close
558 testfilehandler create 1 off off
560 set result [testfilehandler wait 1 writable 100]
562 testfilehandler close
564 } {writable {no timeout}}
565 test event-13.7 {Tcl_WaitForFile procedure, don't call other event handlers} testfilehandler {
566 foreach i [after info] {
569 after 100 lappend x timeout
570 after idle lappend x idle
571 testfilehandler close
572 testfilehandler create 1 off off
574 set result [list [testfilehandler wait 1 readable 200] $x]
576 testfilehandler close
578 } {{} {} {timeout idle}}
580 test event-13.8 {Tcl_WaitForFile procedure, waiting indefinitely} testfilewait {
581 set f [open "|sleep 2" r]
583 lappend result [testfilewait $f readable 100]
584 lappend result [testfilewait $f readable -1]
590 test event-14.1 {Tcl_WaitForFile procedure, readable, big fd} \
591 -constraints {testfilehandler unix} \
594 for {set i 0} {$i < 32} {incr i} {
595 lappend chanList [open /dev/null r]
599 foreach i [after info] {
602 after 100 set x timeout
603 testfilehandler close
604 testfilehandler create 1 off off
606 set result [testfilehandler wait 1 readable 0]
608 testfilehandler close
611 -result {{} {no timeout}} \
613 foreach chan $chanList {close $chan}
616 test event-14.2 {Tcl_WaitForFile procedure, readable, big fd} \
617 -constraints {testfilehandler unix} \
620 for {set i 0} {$i < 32} {incr i} {
621 lappend chanList [open /dev/null r]
625 foreach i [after info] {
628 after 100 set x timeout
629 testfilehandler close
630 testfilehandler create 1 off off
632 set result [testfilehandler wait 1 readable 100]
634 testfilehandler close
637 -result {{} timeout} \
639 foreach chan $chanList {close $chan}
642 test event-14.3 {Tcl_WaitForFile procedure, readable, big fd} \
643 -constraints {testfilehandler unix} \
646 for {set i 0} {$i < 32} {incr i} {
647 lappend chanList [open /dev/null r]
651 foreach i [after info] {
654 after 100 set x timeout
655 testfilehandler close
656 testfilehandler create 1 off off
657 testfilehandler fillpartial 1
659 set result [testfilehandler wait 1 readable 100]
661 testfilehandler close
664 -result {readable {no timeout}} \
666 foreach chan $chanList {close $chan}
669 test event-14.4 {Tcl_WaitForFile procedure, writable, big fd} \
670 -constraints {testfilehandler unix nonPortable} \
673 for {set i 0} {$i < 32} {incr i} {
674 lappend chanList [open /dev/null r]
678 foreach i [after info] {
681 after 100 set x timeout
682 testfilehandler close
683 testfilehandler create 1 off off
684 testfilehandler fill 1
686 set result [testfilehandler wait 1 writable 0]
688 testfilehandler close
691 -result {{} {no timeout}} \
693 foreach chan $chanList {close $chan}
696 test event-14.5 {Tcl_WaitForFile procedure, writable, big fd} \
697 -constraints {testfilehandler unix nonPortable} \
700 for {set i 0} {$i < 32} {incr i} {
701 lappend chanList [open /dev/null r]
705 foreach i [after info] {
708 after 100 set x timeout
709 testfilehandler close
710 testfilehandler create 1 off off
711 testfilehandler fill 1
713 set result [testfilehandler wait 1 writable 100]
715 testfilehandler close
718 -result {{} timeout} \
720 foreach chan $chanList {close $chan}
723 test event-14.6 {Tcl_WaitForFile procedure, writable, big fd} \
724 -constraints {testfilehandler unix} \
727 for {set i 0} {$i < 32} {incr i} {
728 lappend chanList [open /dev/null r]
732 foreach i [after info] {
735 after 100 set x timeout
736 testfilehandler close
737 testfilehandler create 1 off off
739 set result [testfilehandler wait 1 writable 100]
741 testfilehandler close
744 -result {writable {no timeout}} \
746 foreach chan $chanList {close $chan}
749 test event-14.7 {Tcl_WaitForFile, don't call other event handlers, big fd} \
750 -constraints {testfilehandler unix} \
753 for {set i 0} {$i < 32} {incr i} {
754 lappend chanList [open /dev/null r]
758 foreach i [after info] {
761 after 100 lappend x timeout
762 after idle lappend x idle
763 testfilehandler close
764 testfilehandler create 1 off off
766 set result [list [testfilehandler wait 1 readable 200] $x]
768 testfilehandler close
771 -result {{} {} {timeout idle}} \
773 foreach chan $chanList {close $chan}
777 test event-14.8 {Tcl_WaitForFile procedure, waiting indefinitely, big fd} \
778 -constraints {testfilewait unix} \
780 set f [open "|sleep 2" r]
782 lappend result [testfilewait $f readable 100]
783 lappend result [testfilewait $f readable -1]
789 for {set i 0} {$i < 32} {incr i} {
790 lappend chanList [open /dev/null r]
793 -result {{} readable} \
795 foreach chan $chanList {close $chan}
799 foreach i [after info] {
802 ::tcltest::cleanupTests