1 # This file contains a collection of tests for the procedures in the
2 # file tclTimer.c, which includes the "after" Tcl command. Sourcing
3 # this file into Tcl runs the tests and generates output for errors.
4 # No output means no errors were found.
6 # This file contains a collection of tests for one or more of the Tcl
7 # built-in commands. Sourcing this file into Tcl runs the tests and
8 # generates output for errors. No output means no errors were found.
10 # Copyright (c) 1997 by Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # RCS: @(#) $Id: timer.test,v 1.7.2.1 2001/10/13 01:14:19 hobbs Exp $
18 source [file dirname [info script]]/testing.tcl
19 needs cmd after eventloop
21 test timer-1.1 {Tcl_CreateTimerHandler procedure} {
22 foreach i [after info] {
26 foreach i {20 40 200 10 30} {
34 test timer-2.1 {Tcl_DeleteTimerHandler procedure} {
35 foreach i [after info] {
39 foreach i {20 40 60 10 30} {
42 after cancel lappend x 60
43 after cancel lappend x 10
49 # No tests for Tcl_ServiceTimer or ResetTimer, since it is already tested
52 test timer-3.1 {TimerHandlerEventProc procedure: event masks} {
54 after 20 { set x fired }
61 test timer-3.2 {TimerHandlerEventProc procedure: multiple timers} {
62 foreach i [after info] {
65 foreach i {40 120 200} {
79 } {40 {40 120} {40 120 200}}
80 test timer-3.3 {TimerHandlerEventProc procedure: reentrant timer deletion} {
81 foreach i [after info] {
86 set i [after 60 lappend x 60]
87 after 40 after cancel $i
92 test timer-3.4 {TimerHandlerEventProc procedure: all expired timers fire} {
93 foreach i [after info] {
104 test timer-3.5 {TimerHandlerEventProc procedure: reentrantly added timers don't fire} {
105 foreach i [after info] {
109 after 20 {lappend x a; after 0 lappend x b}
114 test timer-3.6 {TimerHandlerEventProc procedure: reentrantly added timers don't fire} {
115 foreach i [after info] {
119 after 20 {lappend x a; after 20 lappend x b; after 20}
127 # No tests for Tcl_DoWhenIdle: it's already tested by other tests
130 test timer-4.1 {Tcl_CancelIdleCall procedure} {
131 foreach i [after info] {
137 after idle set x after1
138 after idle set y after2
139 after idle set z after3
140 after cancel set y after2
143 } {after1 before after3}
144 test timer-4.2 {Tcl_CancelIdleCall procedure} {
145 foreach i [after info] {
151 after idle set x after1
152 after idle set y after2
153 after idle set z after3
154 after cancel set x after1
157 } {before after2 after3}
159 test timer-5.1 {Tcl_ServiceIdle, self-rescheduling handlers} {
160 foreach i [after info] {
165 after idle {incr x; after idle {incr x; after idle {incr x}}}
173 test timer-6.1 {Tcl_AfterCmd procedure, basics} {
174 list [catch {after} msg] $msg
175 } {1 {wrong # args: should be "after option ?arg ...?"}}
176 test timer-6.2 {Tcl_AfterCmd procedure, basics} jim {
177 list [catch {after 2x} msg] $msg
178 } {1 {bad argument "2x": must be cancel, idle, or info}}
179 test timer-6.3 {Tcl_AfterCmd procedure, basics} jim {
180 list [catch {after gorp} msg] $msg
181 } {1 {bad argument "gorp": must be cancel, idle, or info}}
182 test timer-6.4 {Tcl_AfterCmd procedure, ms argument} {
184 after 80 {set x after}
193 test timer-6.6 {Tcl_AfterCmd procedure, cancel option} {
194 list [catch {after cancel} msg] $msg
195 } {1 {wrong # args: should be "after cancel id|command"}}
196 test timer-6.7 {Tcl_AfterCmd procedure, cancel option} {
199 test timer-6.8 {Tcl_AfterCmd procedure, cancel option} {
200 after cancel {foo bar}
202 test timer-6.9 {Tcl_AfterCmd procedure, cancel option} {
203 foreach i [after info] {
207 set y [after 20 set x after]
213 test timer-6.10 {Tcl_AfterCmd procedure, cancel option} {
214 foreach i [after info] {
219 after cancel set x after
224 test timer-6.11 {Tcl_AfterCmd procedure, cancel option} {
225 foreach i [after info] {
230 set id [after 60 set x after]
240 test timer-6.12 {Tcl_AfterCmd procedure, cancel option} {
241 foreach i [after info] {
245 after idle lappend x second
246 after idle lappend x third
247 set i [after idle lappend x fourth]
248 after cancel {lappend x second}
253 test timer-6.13 {Tcl_AfterCmd procedure, cancel option, multiple arguments for command} {
254 foreach i [after info] {
258 after idle lappend x second
259 after idle lappend x third
260 set i [after idle lappend x fourth]
261 after cancel lappend x second
266 test timer-6.14 {Tcl_AfterCmd procedure, cancel option, cancel during handler, used to dump core} {
267 foreach i [after info] {
278 test timer-6.16 {Tcl_AfterCmd procedure, idle option} {
279 list [catch {after idle} msg] $msg
280 } {1 {wrong # args: should be "after idle script ?script ...?"}}
281 test timer-6.17 {Tcl_AfterCmd procedure, idle option} {
283 after idle {set x after}
288 test timer-6.18 {Tcl_AfterCmd procedure, idle option} {
290 after idle set x after
296 test timer-6.23 {Tcl_AfterCmd procedure, no option, script with NULL} {
297 foreach i [after info] {
301 after 1 "set x ab\0cd"
306 test timer-6.24 {Tcl_AfterCmd procedure, no option, script with NULL} {
307 foreach i [after info] {
316 test timer-6.25 {Tcl_AfterCmd procedure, cancel option, script with NULL} {
317 foreach i [after info] {
322 after cancel "set x ab\0ef"
323 set x [llength [after info]]
324 foreach i [after info] {
329 test timer-6.26 {Tcl_AfterCmd procedure, cancel option, script with NULL} {
330 foreach i [after info] {
335 after cancel set x ab\0ef
336 set y [llength [after info]]
337 foreach i [after info] {
342 test timer-6.27 {Tcl_AfterCmd procedure, idle option, script with NULL} {
343 foreach i [after info] {
347 after idle "set x ab\0cd"
351 test timer-6.28 {Tcl_AfterCmd procedure, idle option, script with NULL} {
352 foreach i [after info] {
356 after idle set x ab\0cd
360 test timer-6.29 {Tcl_AfterCmd procedure, info option, script with NULL} {
361 foreach i [after info] {
366 set id [after 10 set x ab\0cd]
368 set y [string length [lindex [lindex [after info $id] 0] 2]]
369 foreach i [after info] {
375 set event [after idle foo bar]
376 scan $event after#%d id
378 test timer-7.1 {GetAfterEvent procedure} {
379 list [catch {after info xfter#$id} msg] $msg
380 } "1 {event \"xfter#$id\" doesn't exist}"
381 test timer-7.2 {GetAfterEvent procedure} {
382 list [catch {after info afterx$id} msg] $msg
383 } "1 {event \"afterx$id\" doesn't exist}"
384 test timer-7.3 {GetAfterEvent procedure} {
385 list [catch {after info after#ab} msg] $msg
386 } {1 {event "after#ab" doesn't exist}}
387 test timer-7.4 {GetAfterEvent procedure} {
388 list [catch {after info after#} msg] $msg
389 } {1 {event "after#" doesn't exist}}
390 test timer-7.5 {GetAfterEvent procedure} {
391 list [catch {after info after#${id}x} msg] $msg
392 } "1 {event \"after#${id}x\" doesn't exist}"
393 test timer-7.6 {GetAfterEvent procedure} {
394 list [catch {after info afterx[expr $id+1]} msg] $msg
395 } "1 {event \"afterx[expr $id+1]\" doesn't exist}"
398 test timer-8.1 {AfterProc procedure} {
402 after 20 {set x after}
409 test timer-8.2 {AfterProc procedure} {
410 catch {rename bgerror {}}
415 after 20 {error "After error"}
419 catch {rename bgerror {}}
421 } {empty {After error}}
423 test timer-8.4 {AfterProc procedure, deleting handler from itself} {
424 foreach i [after info] {
430 foreach i [after info] {
431 lappend x [after info $i]
435 after 1000 {error "I shouldn't ever have executed"}
439 } {{{error "I shouldn't ever have executed"} timer}}
441 foreach i [after info] {