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 source [file dirname [info script]]/testing.tcl
14 needs cmd after eventloop
15 testConstraint socket [expr {[info commands socket] ne ""}]
16 testConstraint exec [expr {[info commands exec] ne ""}]
17 testConstraint signal [expr {[info commands signal] ne ""}]
18 catch {[socket -ipv6 stream ::1:5000]} res
20 if {[string match "*not supported" $res]} {
23 # Also, if we can't bind an IPv6 socket, don't run IPv6 tests
25 [socket -ipv6 stream.server ::1:5000] close
30 testConstraint ipv6 $ipv6
32 test event-5.1 {Tcl_BackgroundError, HandleBgErrors procedures} jim {
33 catch {rename bgerror {}}
37 after idle {error "a simple error"}
38 after idle {open non_existent}
39 after idle {set errorInfo foobar; set errorCode xyzzy}
44 } {{a simple error} {non_existent: No such file or directory}}
46 test event-7.1 {bgerror / regular} {
57 test event-7.2 {bgerror / accumulation} {
70 test event-7.3 {bgerror / accumulation / break} {
75 return -code break "skip!";
84 # Tcl handles errors in bgerror slightly differently
85 # Jim prints the original error to stderr
86 test event-7.4 {bgerror throws an error} -constraints jim -body {
87 exec [info nameofexecutable] - << {
89 error "inside bgerror"
94 } -result {stdin:3: Error: inside bgerror
95 at file "stdin", line 3}
97 # end of bgerror tests
98 catch {rename bgerror {}}
101 test event-10.1 {Tcl_Exit procedure} exec {
102 set cmd [list exec [info nameofexecutable] "<<exit 3"]
103 list [catch $cmd msg] [lindex $errorCode 0] \
104 [lindex $errorCode 2]
107 test event-11.1 {Tcl_VwaitCmd procedure} {
108 list [catch {vwait} msg] $msg
109 } {1 {wrong # args: should be "vwait name"}}
110 test event-11.2 {Tcl_VwaitCmd procedure} {
111 list [catch {vwait a b} msg] $msg
112 } {1 {wrong # args: should be "vwait name"}}
113 test event-11.3 {Tcl_VwaitCmd procedure} jim {
116 list [catch {vwait x(1)} msg] $msg
117 } {1 {can't read "x(1)": variable isn't array}}
118 test event-11.4 {Tcl_VwaitCmd procedure} {
119 foreach i [after info] {
122 after 10; update; # On Mac make sure update won't take long
123 after 100 {set x x-done}
124 after 200 {set y y-done}
125 after 300 {set z z-done}
126 after idle {set q q-done}
131 list [vwait y] $x $y $z $q
132 } {{} x-done y-done before q-done}
134 foreach i [after info] {
138 test event-11.5 {Tcl_VwaitCmd procedure: round robin scheduling, 2 sources} {jim socket} {
139 set f1 [open test1 w]
140 proc accept {s args} {
144 set s1 [socket stream.server 5001]
146 set s2 [socket stream 127.0.0.1:5001]
151 fileevent $s2 writable { incr z }
153 fileevent $f1 writable { incr x; if { $y == 3 } { set z done } }
154 fileevent $s2 writable { incr y; if { $x == 3 } { set z done } }
158 file delete test1 test2
162 # Note: This one doesn't really require socket, but mingw32 doesn't have socket and
163 # also doesn't allow file events (select) on non-sockets
164 test event-11.6 {Tcl_VwaitCmd procedure: round robin scheduling, same source} {socket} {
165 file delete test1 test2
166 set f1 [open test1 w]
167 set f2 [open test2 w]
172 fileevent $f1 writable { incr x; if { $y == 3 } { set z done } }
173 fileevent $f2 writable { incr y; if { $x == 3 } { set z done } }
177 file delete test1 test2
181 test event-12.1 {Tcl_UpdateCmd procedure} {
182 list [catch {update a b} msg] $msg
183 } {1 {wrong # args: should be "update ?idletasks?"}}
184 test event-12.3 {Tcl_UpdateCmd procedure} {
185 foreach i [after info] {
188 after 500 {set x after}
189 after idle {set y after}
190 after idle {set z "after, y = $y"}
196 } {before after {after, y = after}}
197 test event-12.4 {Tcl_UpdateCmd procedure} {
198 foreach i [after info] {
201 after 10; update; # On Mac make sure update won't take long
202 after 200 {set x x-done}
203 after 400 {set y y-done}
204 after idle {set z z-done}
211 } {x-done before z-done}
214 foreach i [after info] {
218 test event-13.1 "vwait/signal" signal {
220 list [catch -signal {
222 # This is just to prevent the vwait from exiting immediately
223 stdin readable { format test }
228 test event-13.2 {after info invalid} -body {
229 after info not-a-valid-id
230 } -returnCodes error -result {event "not-a-valid-id" doesn't exist}
232 test event-13.3 {after info noexist} -body {
233 after info after#99999999
234 } -returnCodes error -result {event "after#99999999" doesn't exist}
236 test event-13.4 {after info usage} -body {
237 after info too-many args
238 } -returnCodes error -result {wrong # args: should be "after info ?id?"}
240 test event-13.5 {after cancel noexist} {
241 after cancel after#99999999
244 test event-14.1 {socket stream.server client address} {jim socket} {
245 set s1 [socket stream.server 5001]
247 set s2 [socket stream 127.0.0.1:5001]
255 # Return client address without the port.
256 list [lindex [split $addr :] 0]
259 test event-14.2 {IPv6 socket stream.server client address} {jim socket ipv6} {
260 set s1 [socket -ipv6 stream.server ::1:5001]
262 set s2 [socket -ipv6 stream ::1:5001]
270 # Return client IPv6 address without the port.
271 list [join [lrange [split $addr6 :] 0 end-1] :]