1 # This file is a Tcl script to test out the "send" command and the
2 # other procedures in the file tkSend.c. It is organized in the
3 # standard fashion for Tcl tests.
5 # Copyright (c) 1994 Sun Microsystems, Inc.
6 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
7 # Copyright (c) 1998-1999 by Scriptics Corporation.
8 # Copyright (c) 2001 by ActiveState Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 package require tcltest 2.1
16 namespace import -force tcltest::configure
17 namespace import -force tcltest::testsDirectory
18 configure -testdir [file join [pwd] [file dirname [info script]]]
19 configure -loadfile [file join [testsDirectory] constraints.tcl]
20 tcltest::loadTestedCommands
22 testConstraint xhost [llength [auto_execok xhost]]
23 testConstraint testsend [llength [info commands testsend]]
25 # Compute a script that will load Tk into a child interpreter.
27 foreach pkg [info loaded] {
28 if {[lindex $pkg 1] == "Tk"} {
29 set loadTk "load $pkg"
34 # Procedure to create a new application with a given name and class.
36 proc newApp {screen name class} {
39 $name eval [list set argv [list -display $screen -name $name -class $class]]
46 set registry [testsend prop root InterpRegistry]
47 set commId [lindex [testsend prop root InterpRegistry] 0]
50 catch {send t_s_1 destroy .}
51 catch {send t_s_2 destroy .}
53 test send-1.1 {RegOpen procedure, bogus property} {secureserver testsend} {
55 set result [winfo interps]
57 list $result [winfo interps]
59 test send-1.2 {RegOpen procedure, bogus property} {secureserver testsend} {
60 testsend prop root InterpRegistry {}
61 set result [winfo interps]
63 list $result [winfo interps]
65 test send-1.3 {RegOpen procedure, bogus property} {secureserver testsend} {
66 testsend prop root InterpRegistry abcdefg
68 set x [testsend prop root InterpRegistry]
69 string range $x [string first " " $x] end
70 } " tktest\nabcdefg\n"
72 frame .f -width 1 -height 1
73 set id [string range [winfo id .f] 2 end]
74 test send-2.1 {RegFindName procedure} {secureserver testsend} {
75 testsend prop root InterpRegistry {}
76 list [catch {send foo bar} msg] $msg
77 } {1 {no application named "foo"}}
78 test send-2.2 {RegFindName procedure} {secureserver testsend} {
79 testsend prop root InterpRegistry " abc\n def\nghi\n\n$id foo\n"
82 test send-2.3 {RegFindName procedure} {secureserver testsend} {
83 testsend prop root InterpRegistry "gyz foo\n"
86 test send-2.4 {RegFindName procedure} {secureserver testsend} {
87 testsend prop root InterpRegistry "${id}z foo\n"
91 test send-3.1 {RegDeleteName procedure} {secureserver testsend} {
93 testsend prop root InterpRegistry "012345 gorp\n12345 foo\n12345 tktest"
95 set x [testsend prop root InterpRegistry]
96 string range $x [string first " " $x] end
97 } " x\n012345 gorp\n12345 foo\n"
98 test send-3.2 {RegDeleteName procedure} {secureserver testsend} {
100 testsend prop root InterpRegistry "012345 gorp\n12345 tktest\n23456 tktest"
102 set x [testsend prop root InterpRegistry]
103 string range $x [string first " " $x] end
104 } " x\n012345 gorp\n23456 tktest\n"
105 test send-3.3 {RegDeleteName procedure} {secureserver testsend} {
107 testsend prop root InterpRegistry "012345 tktest\n12345 bar\n23456 tktest"
109 set x [testsend prop root InterpRegistry]
110 string range $x [string first " " $x] end
111 } " x\n12345 bar\n23456 tktest\n"
112 test send-3.4 {RegDeleteName procedure} {secureserver testsend} {
114 testsend prop root InterpRegistry "foo"
116 set x [testsend prop root InterpRegistry]
117 string range $x [string first " " $x] end
119 test send-3.5 {RegDeleteName procedure} {secureserver testsend} {
121 testsend prop root InterpRegistry ""
123 set x [testsend prop root InterpRegistry]
124 string range $x [string first " " $x] end
127 test send-4.1 {RegAddName procedure} {secureserver testsend} {
128 testsend prop root InterpRegistry ""
130 testsend prop root InterpRegistry
132 test send-4.2 {RegAddName procedure} {secureserver testsend} {
133 testsend prop root InterpRegistry "abc def"
136 testsend prop root InterpRegistry
137 } "$commId foo\nabc def\n"
139 # Previous checks should already cover the Regclose procedure.
141 test send-5.1 {ValidateName procedure} {secureserver testsend} {
142 testsend prop root InterpRegistry "123 abc\n"
145 test send-5.2 {ValidateName procedure} {secureserver testsend} {
146 testsend prop root InterpRegistry "$id Hi there"
149 test send-5.3 {ValidateName procedure} {secureserver testsend} {
150 testsend prop root InterpRegistry "$id Bogus"
151 list [catch {send Bogus set a 44} msg] $msg
152 } {1 {target application died or uses a Tk version before 4.0}}
153 test send-5.4 {ValidateName procedure} {secureserver testsend} {
155 testsend prop root InterpRegistry "$commId Bogus\n$commId test\n"
159 if {[testConstraint xhost]} {
164 set x [split [exec xhost] \n]
165 foreach i [lrange $x 1 end] {
170 test send-6.1 {ServerSecure procedure} {nonPortable secureserver} {
172 list [dobg [list send [tk appname] set a 55]] $a
174 test send-6.2 {ServerSecure procedure} {nonPortable secureserver} {
176 exec xhost [exec hostname]
177 list [catch {dobg [list send [tk appname] set a 33]} msg] $a $msg
178 } {0 22 {X server insecure (must use xauth-style authorization); command ignored}}
179 test send-6.3 {ServerSecure procedure} {nonPortable secureserver} {
181 exec xhost - [exec hostname]
182 list [dobg [list send [tk appname] set a new]] $a
186 test send-7.1 {Tk_SetAppName procedure} {secureserver testsend} {
187 testsend prop root InterpRegistry ""
189 list [tk appname oldName] [testsend prop root InterpRegistry]
190 } "oldName {$commId oldName\n}"
191 test send-7.2 {Tk_SetAppName procedure, name not in use} {secureserver testsend} {
192 testsend prop root InterpRegistry ""
193 list [tk appname gorp] [testsend prop root InterpRegistry]
194 } "gorp {$commId gorp\n}"
195 test send-7.3 {Tk_SetAppName procedure, name in use by us} {secureserver testsend} {
197 testsend prop root InterpRegistry "$commId name2\n"
198 list [tk appname name2] [testsend prop root InterpRegistry]
199 } "name2 {$commId name2\n}"
200 test send-7.4 {Tk_SetAppName procedure, name in use} {secureserver testsend} {
202 testsend prop root InterpRegistry "$id foo\n$id foo #2\n$id foo #3\n"
203 list [tk appname foo] [testsend prop root InterpRegistry]
204 } "{foo #4} {$commId foo #4\n$id foo\n$id foo #2\n$id foo #3\n}"
206 test send-8.1 {Tk_SendCmd procedure, options} {secureserver} {
208 set app [dobg {tk appname}]
210 send -async $app [list send [tk appname] set a 77]
217 test send-8.2 {Tk_SendCmd procedure, options} {secureserver altDisplay} {
218 setupbg -display $env(TK_ALT_DISPLAY)
222 toplevel .t -screen [winfo screen .]
226 list \[send xyzgorp set a\] \[send -displayof .t xyzgorp set a\]
230 } {altDisplay homeDisplay}
231 test send-8.3 {Tk_SendCmd procedure, options} {secureserver} {
232 list [catch {send -- -async foo bar baz} msg] $msg
233 } {1 {no application named "-async"}}
234 test send-8.4 {Tk_SendCmd procedure, options} {secureserver} {
235 list [catch {send -gorp foo bar baz} msg] $msg
236 } {1 {bad option "-gorp": must be -async, -displayof, or --}}
237 test send-8.5 {Tk_SendCmd procedure, options} {secureserver} {
238 list [catch {send -async foo} msg] $msg
239 } {1 {wrong # args: should be "send ?options? interpName arg ?arg ...?"}}
240 test send-8.6 {Tk_SendCmd procedure, options} {secureserver} {
241 list [catch {send foo} msg] $msg
242 } {1 {wrong # args: should be "send ?options? interpName arg ?arg ...?"}}
243 test send-8.7 {Tk_SendCmd procedure, local execution} {secureserver} {
245 send [tk appname] {set a new}
248 test send-8.8 {Tk_SendCmd procedure, local execution} {secureserver} {
250 send [tk appname] set a new
253 test send-8.9 {Tk_SendCmd procedure, local execution} {secureserver} {
255 string tolower [list [catch {send [tk appname] open bad_file} msg] \
256 $msg $errorInfo $errorCode]
257 } {1 {couldn't open "bad_file": no such file or directory} {couldn't open "bad_file": no such file or directory
261 "send [tk appname] open bad_file"} {posix enoent {no such file or directory}}}
262 test send-8.10 {Tk_SendCmd procedure, no such interpreter} {secureserver} {
263 list [catch {send bogus_name bogus_command} msg] $msg
264 } {1 {no application named "bogus_name"}}
268 t_s_1 eval wm withdraw .
271 test send-8.11 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
273 send t_s_1 set a them
274 list $a [send t_s_1 set a]
276 test send-8.12 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
278 send t_s_1 {set a them}
279 list $a [send t_s_1 {set a}]
281 test send-8.13 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
283 send t_s_1 {set a them}
284 list $a [send t_s_1 {set a}]
286 test send-8.14 {Tk_SendCmd procedure, local interp killed by send} {secureserver testsend} {
288 list [catch {send t_s_2 {destroy .; concat result}} msg] $msg
291 catch {interp delete t_s_2}
293 test send-8.15 {Tk_SendCmd procedure, local interp, error info} {secureserver testsend} {
295 list [catch {send t_s_1 {if 1 {open bogus_file_name}}} msg] $msg $errorInfo $errorCode
296 } {1 {couldn't open "bogus_file_name": no such file or directory} {couldn't open "bogus_file_name": no such file or directory
298 "open bogus_file_name"
300 "if 1 {open bogus_file_name}"
302 "send t_s_1 {if 1 {open bogus_file_name}}"} {POSIX ENOENT {no such file or directory}}}
303 test send-8.16 {Tk_SendCmd procedure, bogusCommWindow} {secureserver testsend} {
304 testsend prop root InterpRegistry "10234 bogus\n"
305 set result [list [catch {send bogus bogus command} msg] $msg]
309 } {1 {no application named "bogus"}}
311 catch {interp delete t_s_1}
313 test send-8.17 {Tk_SendCmd procedure, deferring events} {secureserver nonPortable} {
314 # Non-portable because some window managers ignore "raise"
315 # requests so can't guarantee that new app's window won't
316 # obscure .f, thereby masking the Expose event.
319 set app [dobg {tk appname}]
320 raise . ; # Don't want new app obscuring .f
324 bind .f <Expose> {set a exposed}
327 lappend result [send $app send [list [tk appname]] set a]
332 } {{no event yet} {no event yet} exposed}
333 test send-8.18 {Tk_SendCmd procedure, error in remote app} {secureserver} {
335 set app [dobg {tk appname}]
336 set result [string tolower [list [catch {send $app open bad_name} msg] \
337 $msg $errorInfo $errorCode]]
340 } {1 {couldn't open "bad_name": no such file or directory} {couldn't open "bad_name": no such file or directory
344 "send $app open bad_name"} {posix enoent {no such file or directory}}}
345 test send-8.19 {Tk_SendCmd, using modal timeouts} {secureserver} {
347 set app [dobg {tk appname}]
351 lappend result [send $app {concat x y z}]
361 set id [string range [winfo id .f] 2 end]
363 test send-9.1 {Tk_GetInterpNames procedure} {secureserver testsend} {
364 testsend prop root InterpRegistry \
365 "$commId tktest\nfoo bar\n$commId tktest\n$id frame .f\n\n\n"
366 list [winfo interps] [testsend prop root InterpRegistry]
367 } "{tktest tktest {frame .f}} {$commId tktest\n$commId tktest\n$id frame .f
369 test send-9.2 {Tk_GetInterpNames procedure} {secureserver testsend} {
370 testsend prop root InterpRegistry \
371 "$commId tktest\nfoobar\n$commId gorp\n"
372 list [winfo interps] [testsend prop root InterpRegistry]
373 } "tktest {$commId tktest\n}"
374 test send-9.3 {Tk_GetInterpNames procedure} {secureserver testsend} {
375 testsend prop root InterpRegistry {}
376 list [winfo interps] [testsend prop root InterpRegistry]
379 catch {testsend prop root InterpRegistry "$commId tktest\n$id dummy\n"}
381 test send-10.1 {SendEventProc procedure, bogus comm property} {secureserver testsend} {
382 testsend prop comm Comm {abc def}
383 testsend prop comm Comm {}
386 test send-10.2 {SendEventProc procedure, simultaneous messages} {secureserver testsend} {
387 testsend prop comm Comm \
388 "c\n-n tktest\n-s set a 44\nc\n-n tktest\n-s set b 45\n"
394 test send-10.3 {SendEventProc procedure, simultaneous messages} {secureserver testsend} {
395 testsend prop comm Comm \
396 "c\n-n tktest\n-s set a newA\nr\n-s [testsend serial]\n-r 12345\nc\n-n tktest\n-s set b newB\n"
399 set x [send dummy bogus]
402 test send-10.4 {SendEventProc procedure, leading nulls, bogus commands} {secureserver testsend} {
403 testsend prop comm Comm \
404 "\n\nx\n-bogus\n\nc\n-n tktest\n-s set a 44\n"
409 test send-10.5 {SendEventProc procedure, extraneous command options} {secureserver testsend} {
410 testsend prop comm Comm \
411 "c\n-n tktest\n-x miscellanous\n-y who knows?\n-s set a new\n"
416 test send-10.6 {SendEventProc procedure, unknown interpreter} {secureserver testsend} {
417 testsend prop [winfo id .f] Comm {}
418 testsend prop comm Comm \
419 "c\n-n unknown\n-r $id 44\n-s set a new\n"
422 list [testsend prop [winfo id .f] Comm] $a
423 } "{\nr\n-s 44\n-r receiver never heard of interpreter \"unknown\"\n-c 1\n} null"
424 test send-10.7 {SendEventProc procedure, error in script} {secureserver testsend} {
425 testsend prop [winfo id .f] Comm {}
426 testsend prop comm Comm \
427 "c\n-n tktest\n-r $id 62\n-s foreach i {1 2 3} {error {test error} {Initial errorInfo} {test code}}\n"
429 testsend prop [winfo id .f] Comm
435 ("foreach" body line 1)
437 "foreach i {1 2 3} {error {test error} {Initial errorInfo} {test code}}"
441 test send-10.8 {SendEventProc procedure, exceptional return} {secureserver testsend} {
442 testsend prop [winfo id .f] Comm {}
443 testsend prop comm Comm \
444 "c\n-n tktest\n-r $id 62\n-s break\n"
446 testsend prop [winfo id .f] Comm
453 test send-10.9 {SendEventProc procedure, empty return} {secureserver testsend} {
454 testsend prop [winfo id .f] Comm {}
455 testsend prop comm Comm \
456 "c\n-n tktest\n-r $id 62\n-s concat\n"
458 testsend prop [winfo id .f] Comm
464 test send-10.10 {SendEventProc procedure, asynchronous calls} {secureserver testsend} {
465 testsend prop [winfo id .f] Comm {}
466 testsend prop comm Comm \
467 "c\n-n tktest\n-s foreach i {1 2 3} {error {test error} {Initial errorInfo} {test code}}\n"
469 testsend prop [winfo id .f] Comm
471 test send-10.11 {SendEventProc procedure, exceptional return} {secureserver testsend} {
472 testsend prop [winfo id .f] Comm {}
473 testsend prop comm Comm \
474 "c\n-n tktest\n-s break\n"
476 testsend prop [winfo id .f] Comm
478 test send-10.12 {SendEventProc procedure, empty return} {secureserver testsend} {
479 testsend prop [winfo id .f] Comm {}
480 testsend prop comm Comm \
481 "c\n-n tktest\n-s concat\n"
483 testsend prop [winfo id .f] Comm
485 test send-10.13 {SendEventProc procedure, return processing} {secureserver testsend} {
486 testsend prop comm Comm \
487 "r\n-c 1\n-e test1\n-i test2\n-r test3\n-s [testsend serial]\n"
488 list [catch {send dummy foo} msg] $msg $errorInfo $errorCode
491 "send dummy foo"} test1}
492 test send-10.14 {SendEventProc procedure, extraneous return options} {secureserver testsend} {
493 testsend prop comm Comm \
494 "r\n-x test1\n-y test2\n-r result\n-s [testsend serial]\n"
495 list [catch {send dummy foo} msg] $msg
497 test send-10.15 {SendEventProc procedure, serial number} {secureserver testsend} {
498 testsend prop comm Comm \
500 list [catch {send dummy foo} msg] $msg
501 } {1 {target application died or uses a Tk version before 4.0}}
502 test send-10.16 {SendEventProc procedure, serial number} {secureserver testsend} {
503 testsend prop comm Comm \
504 "r\n-r response\n\n-s 0"
505 list [catch {send dummy foo} msg] $msg
506 } {1 {target application died or uses a Tk version before 4.0}}
507 test send-10.17 {SendEventProc procedure, errorCode and errorInfo} {secureserver testsend} {
508 testsend prop comm Comm \
509 "r\n-i test1\n-e test2\n-c 4\n-s [testsend serial]\n"
510 set errorCode oldErrorCode
511 set errorInfo oldErrorInfo
512 list [catch {send dummy foo} msg] $msg $errorInfo $errorCode
513 } {4 {} oldErrorInfo oldErrorCode}
514 test send-10.18 {SendEventProc procedure, send kills application} {secureserver testsend} {
516 dobg {tk appname t_s_3}
517 set x [list [catch {send t_s_3 destroy .} msg] $msg]
521 test send-10.19 {SendEventProc procedure, send exits} {secureserver testsend} {
523 dobg {tk appname t_s_3}
524 set x [list [catch {send t_s_3 exit} msg] $msg]
527 } {1 {target application died}}
529 test send-11.1 {AppendPropCarefully and AppendErrorProc procedures} {secureserver testsend} {
530 testsend prop root InterpRegistry "0x21447 dummy\n"
531 list [catch {send dummy foo} msg] $msg
532 } {1 {no application named "dummy"}}
533 test send-11.2 {AppendPropCarefully and AppendErrorProc procedures} {secureserver testsend} {
534 testsend prop comm Comm "c\n-r0x123 44\n-n tktest\n-s concat a b c\n"
542 set id [string range [winfo id .f] 2 end]
544 test send-12.1 {TimeoutProc procedure} {secureserver testsend} {
545 testsend prop root InterpRegistry "$id dummy\n"
546 list [catch {send dummy foo} msg] $msg
547 } {1 {target application died or uses a Tk version before 4.0}}
549 catch {testsend prop root InterpRegistry ""}
551 test send-12.2 {TimeoutProc procedure} {secureserver} {
557 after 10 {after 10 {after 5000; exit}}
561 set result [list [catch {send $app foo} msg] $msg]
564 } {1 {target application died}}
568 test send-13.1 {DeleteProc procedure} {secureserver} {
570 set app [dobg {rename send {}; tk appname}]
571 set result [list [catch {send $app foo} msg] $msg [winfo interps]]
574 } {1 {no application named "tktest #2"} tktest}
575 test send-13.2 {DeleteProc procedure} {secureserver} {
580 lappend result [winfo interps] [info commands send]
582 lappend result [winfo interps] [info commands send]
585 test send-14.1 {SendRestrictProc procedure, sends crossing from different displays} {secureserver altDisplay} {
586 setupbg -display $env(TK_ALT_DISPLAY)
588 toplevel .t -screen [winfo screen .]
593 toplevel .t -screen $env(TK_ALT_DISPLAY)
598 set result [send -displayof .t xyzgorp1 {list $x [send -displayof .t xyzgorp2 set y]}]
605 testsend prop root InterpRegister $registry
608 test send-15.1 {UpdateCommWindow procedure} {secureserver testsend} {
609 set x [list [testsend prop comm TK_APPLICATION]]
611 send t_s_1 wm withdraw .
613 send t_s_2 wm withdraw .
614 lappend x [testsend prop comm TK_APPLICATION]
616 lappend x [testsend prop comm TK_APPLICATION]
618 lappend x [testsend prop comm TK_APPLICATION]
619 } {tktest {t_s_2 t_s_1 tktest} {t_s_2 tktest} tktest}
623 testsend prop root InterpRegistry $registry
629 ::tcltest::cleanupTests