1 # vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
3 if {[lsearch [namespace children] ::tcltest] == -1} {
4 package require tcltest 2.2.5
5 namespace import ::tcltest::*
8 package require TLC-base
10 test signalsource-1.1 {Create a Signalsource} -body { #<<<
11 set obj [tlc::Signalsource #auto]
12 $obj isa tlc::Signalsource
14 if {[info exists obj] && [itcl::is object $obj]} {
20 test signalsource-1.2 {Host some signals} -body { #<<<
22 inherit tlc::Signalsource
25 tlc::Signal testsig1 signals(test1) -name "$this test1"
26 tlc::Signal testsig2 signals(test2) -name "$this test2"
33 array set a [foo signals_available]
34 foreach name [lsort [array names a]] {
35 lappend available $name $a($name)
40 if {[itcl::is object foo]} {delete object foo}
41 if {[itcl::is class Foo]} {delete class Foo}
43 foreach var {available a} {
44 if {[info exists $var]} {
48 } -result {test1 ::Foo::testsig1 test2 ::Foo::testsig2}
50 test signalsource-1.3 {signal_ref method, valid signal} -body { #<<<
52 inherit tlc::Signalsource
55 tlc::Signal testsig1 signals(test1) -name "$this test1"
56 tlc::Signal testsig2 signals(test2) -name "$this test2"
58 $signals(test1) set_state 1
64 list [[foo signal_ref test1] state] [[foo signal_ref test2] state]
66 if {[itcl::is object foo]} {delete object foo}
67 if {[itcl::is class Foo]} {delete class Foo}
70 test signalsource-1.4 {signal_ref method, invalid signal} -body { #<<<
72 inherit tlc::Signalsource
75 tlc::Signal testsig1 signals(test1) -name "$this test1"
76 tlc::Signal testsig2 signals(test2) -name "$this test2"
78 $signals(test1) set_state 1
87 set options [dict merge {-errorcode ""} $options]
89 list $errmsg [dict get $options -errorcode]
91 if {[itcl::is object foo]} {delete object foo}
92 if {[itcl::is class Foo]} {delete class Foo}
93 } -result {{Invalid signal (test3)} {invalid_signal test3}}
95 test signalsource-1.5 {signal_state method, valid signal} -body { #<<<
97 inherit tlc::Signalsource
100 tlc::Signal testsig1 signals(test1) -name "$this test1"
101 tlc::Signal testsig2 signals(test2) -name "$this test2"
103 $signals(test1) set_state 1
109 list [foo signal_state test1] [foo signal_state test2]
111 if {[itcl::is object foo]} {delete object foo}
112 if {[itcl::is class Foo]} {delete class Foo}
115 test signalsource-1.6 {signal_state method, invalid signal} -body { #<<<
117 inherit tlc::Signalsource
120 tlc::Signal testsig1 signals(test1) -name "$this test1"
121 tlc::Signal testsig2 signals(test2) -name "$this test2"
123 $signals(test1) set_state 1
130 foo signal_state test3
132 set options [dict merge {-errorcode ""} $options]
134 list $errmsg [dict get $options -errorcode]
136 if {[itcl::is object foo]} {delete object foo}
137 if {[itcl::is class Foo]} {delete class Foo}
138 } -result {{Invalid signal (test3)} {invalid_signal test3}}
140 test signalsource-1.7 {Signal lifespan management} -body { #<<<
142 inherit tlc::Signalsource
145 tlc::Signal testsig1 signals(test1) -name "$this test1"
146 tlc::Signal testsig2 signals(test2) -name "$this test2"
152 set signal [foo signal_ref test1]
153 set before [itcl::is object $signal]
157 set after [itcl::is object $signal]
161 if {[itcl::is object foo]} {delete object foo}
162 if {[itcl::is class Foo]} {delete class Foo}
164 foreach var {available a} {
165 if {[info exists $var]} {
171 test signalsource-1.8 {waitfor method, invalid signal} -body { #<<<
173 inherit tlc::Signalsource
176 tlc::Signal testsig1 signals(test1) -name "$this test1"
177 tlc::Signal testsig2 signals(test2) -name "$this test2"
179 $signals(test1) set_state 1
188 set options [dict merge {-errorcode ""} $options]
190 list $errmsg [dict get $options -errorcode]
192 if {[itcl::is object foo]} {delete object foo}
193 if {[itcl::is class Foo]} {delete class Foo}
194 } -result {{Invalid signal (test3)} {invalid_signal test3}}
196 test signalsource-1.9 {waitfor method, already true} -body { #<<<
198 inherit tlc::Signalsource
201 tlc::Signal testsig1 signals(test1) -name "$this test1"
202 tlc::Signal testsig2 signals(test2) -name "$this test2"
204 $signals(test1) set_state 1
212 foo signal_state test1
214 if {[itcl::is object foo]} {delete object foo}
215 if {[itcl::is class Foo]} {delete class Foo}
218 test signalsource-1.10 {waitfor method with timeout, already true} -body { #<<<
220 inherit tlc::Signalsource
223 tlc::Signal testsig1 signals(test1) -name "$this test1"
224 tlc::Signal testsig2 signals(test2) -name "$this test2"
226 $signals(test1) set_state 1
232 foo waitfor test1 1000
234 foo signal_state test1
236 if {[itcl::is object foo]} {delete object foo}
237 if {[itcl::is class Foo]} {delete class Foo}
240 test signalsource-1.11 {waitfor method with timeout, timeout reached} -body { #<<<
242 inherit tlc::Signalsource
245 tlc::Signal testsig1 signals(test1) -name "$this test1"
246 tlc::Signal testsig2 signals(test2) -name "$this test2"
248 $signals(test1) set_state 1
254 set before [clock milliseconds]
256 foo waitfor test2 100
258 set after [clock milliseconds]
260 set options [dict merge {-errorcode ""} $options]
262 list [expr {$after - $before >= 100}] $errmsg [dict get $options -errorcode]
264 if {[itcl::is object foo]} {delete object foo}
265 if {[itcl::is class Foo]} {delete class Foo}
267 foreach var {before after} {
268 if {[info exists $var]} {
272 } -result {1 {Timeout waiting for signal "::foo test2"} {timeout {::foo test2}}}
274 test signalsource-1.12 {waitfor method with timeout, timeout not reached} -body { #<<<
276 inherit tlc::Signalsource
279 tlc::Signal testsig1 signals(test1) -name "$this test1"
280 tlc::Signal testsig2 signals(test2) -name "$this test2"
282 $signals(test1) set_state 1
288 set afterid [after 50 [list apply {
292 } [foo signal_ref test2]]]
294 set before [clock milliseconds]
295 foo waitfor test2 100
296 set after [clock milliseconds]
298 list [expr {$after - $before < 80}] [foo signal_state test2]
300 if {[info exists afterid]} {
301 after cancel $afterid
305 if {[itcl::is object foo]} {delete object foo}
306 if {[itcl::is class Foo]} {delete class Foo}
308 foreach var {before after} {
309 if {[info exists $var]} {
315 test signalsource-1.13 {waitfor method with timeout, waited signal dies} -body { #<<<
317 inherit tlc::Signalsource
320 tlc::Signal testsig1 signals(test1) -name "$this test1"
321 tlc::Signal testsig2 signals(test2) -name "$this test2"
323 $signals(test1) set_state 1
329 set afterid [after 50 [list apply {
333 } [foo signal_ref test2]]]
336 foo waitfor test2 100
338 set options [dict merge {-errorcode ""} $options]
340 list $errmsg [dict get $options -errorcode]
342 if {[info exists afterid]} {
343 after cancel $afterid
347 if {[itcl::is object foo]} {delete object foo}
348 if {[itcl::is class Foo]} {delete class Foo}
349 } -result {{Source died while waiting for signal "::foo test2"} {source_died {::foo test2}}}
351 test signalsource-1.14 {waitfor method with timeout, Signalsource dies} -body { #<<<
353 inherit tlc::Signalsource
356 tlc::Signal testsig1 signals(test1) -name "$this test1"
357 tlc::Signal testsig2 signals(test2) -name "$this test2"
359 $signals(test1) set_state 1
365 set afterid [after 50 {apply {
372 foo waitfor test2 1000
374 set options [dict merge {-errorcode ""} $options]
376 list $errmsg [dict get $options -errorcode]
378 if {[info exists afterid]} {
379 after cancel $afterid
383 if {[itcl::is object foo]} {delete object foo}
384 if {[itcl::is class Foo]} {delete class Foo}
385 } -result {{Source died while waiting for signal "::foo test2"} {source_died {::foo test2}}}
388 ::tcltest::cleanupTests