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}
192 test timer-6.5 {Tcl_AfterCmd procedure, ms argument} {
194 after 60 {set x after}
202 test timer-6.6 {Tcl_AfterCmd procedure, cancel option} {
203 list [catch {after cancel} msg] $msg
204 } {1 {wrong # args: should be "after cancel id|command"}}
205 test timer-6.7 {Tcl_AfterCmd procedure, cancel option} {
208 test timer-6.8 {Tcl_AfterCmd procedure, cancel option} {
209 after cancel {foo bar}
211 test timer-6.9 {Tcl_AfterCmd procedure, cancel option} {
212 foreach i [after info] {
216 set y [after 20 set x after]
222 test timer-6.10 {Tcl_AfterCmd procedure, cancel option} {
223 foreach i [after info] {
228 after cancel set x after
233 test timer-6.11 {Tcl_AfterCmd procedure, cancel option} {
234 foreach i [after info] {
239 set id [after 60 set x after]
249 test timer-6.12 {Tcl_AfterCmd procedure, cancel option} {
250 foreach i [after info] {
254 after idle lappend x second
255 after idle lappend x third
256 set i [after idle lappend x fourth]
257 after cancel {lappend x second}
262 test timer-6.13 {Tcl_AfterCmd procedure, cancel option, multiple arguments for command} {
263 foreach i [after info] {
267 after idle lappend x second
268 after idle lappend x third
269 set i [after idle lappend x fourth]
270 after cancel lappend x second
275 test timer-6.14 {Tcl_AfterCmd procedure, cancel option, cancel during handler, used to dump core} {
276 foreach i [after info] {
287 test timer-6.16 {Tcl_AfterCmd procedure, idle option} {
288 list [catch {after idle} msg] $msg
289 } {1 {wrong # args: should be "after idle script ?script ...?"}}
290 test timer-6.17 {Tcl_AfterCmd procedure, idle option} {
292 after idle {set x after}
297 test timer-6.18 {Tcl_AfterCmd procedure, idle option} {
299 after idle set x after
305 test timer-6.23 {Tcl_AfterCmd procedure, no option, script with NULL} {
306 foreach i [after info] {
310 after 1 "set x ab\0cd"
315 test timer-6.24 {Tcl_AfterCmd procedure, no option, script with NULL} {
316 foreach i [after info] {
325 test timer-6.25 {Tcl_AfterCmd procedure, cancel option, script with NULL} {
326 foreach i [after info] {
331 after cancel "set x ab\0ef"
332 set x [llength [after info]]
333 foreach i [after info] {
338 test timer-6.26 {Tcl_AfterCmd procedure, cancel option, script with NULL} {
339 foreach i [after info] {
344 after cancel set x ab\0ef
345 set y [llength [after info]]
346 foreach i [after info] {
351 test timer-6.27 {Tcl_AfterCmd procedure, idle option, script with NULL} {
352 foreach i [after info] {
356 after idle "set x ab\0cd"
360 test timer-6.28 {Tcl_AfterCmd procedure, idle option, script with NULL} {
361 foreach i [after info] {
365 after idle set x ab\0cd
369 test timer-6.29 {Tcl_AfterCmd procedure, info option, script with NULL} {
370 foreach i [after info] {
375 set id [after 10 set x ab\0cd]
377 set y [string length [lindex [lindex [after info $id] 0] 2]]
378 foreach i [after info] {
384 set event [after idle foo bar]
385 scan $event after#%d id
387 test timer-7.1 {GetAfterEvent procedure} {
388 list [catch {after info xfter#$id} msg] $msg
389 } "1 {event \"xfter#$id\" doesn't exist}"
390 test timer-7.2 {GetAfterEvent procedure} {
391 list [catch {after info afterx$id} msg] $msg
392 } "1 {event \"afterx$id\" doesn't exist}"
393 test timer-7.3 {GetAfterEvent procedure} {
394 list [catch {after info after#ab} msg] $msg
395 } {1 {event "after#ab" doesn't exist}}
396 test timer-7.4 {GetAfterEvent procedure} {
397 list [catch {after info after#} msg] $msg
398 } {1 {event "after#" doesn't exist}}
399 test timer-7.5 {GetAfterEvent procedure} {
400 list [catch {after info after#${id}x} msg] $msg
401 } "1 {event \"after#${id}x\" doesn't exist}"
402 test timer-7.6 {GetAfterEvent procedure} {
403 list [catch {after info afterx[expr $id+1]} msg] $msg
404 } "1 {event \"afterx[expr $id+1]\" doesn't exist}"
407 test timer-8.1 {AfterProc procedure} {
411 after 20 {set x after}
418 test timer-8.2 {AfterProc procedure} {
419 catch {rename bgerror {}}
424 after 20 {error "After error"}
428 catch {rename bgerror {}}
430 } {empty {After error}}
432 test timer-8.4 {AfterProc procedure, deleting handler from itself} {
433 foreach i [after info] {
439 foreach i [after info] {
440 lappend x [after info $i]
444 after 1000 {error "I shouldn't ever have executed"}
448 } {{{error "I shouldn't ever have executed"} timer}}
450 foreach i [after info] {