1# This file is a Tcl script to test labels, buttons, checkbuttons, and
2# radiobuttons in Tk (i.e., all the widgets defined in tkButton.c).  It is
3# organized in the standard fashion for Tcl tests.
4#
5# Copyright (c) 1994 The Regents of the University of California.
6# Copyright (c) 1994-1996 Sun Microsystems, Inc.
7# Copyright (c) 1998-1999 by Scriptics Corporation.
8# All rights reserved.
9
10package require tcltest 2.1
11eval tcltest::configure $argv
12tcltest::loadTestedCommands
13
14proc bogusTrace args {
15    error "trace aborted"
16}
17catch {unset value}
18catch {unset value2}
19
20# Create entries in the option database to be sure that geometry options
21# like border width have predictable values.
22
23option add *Button.borderWidth 2
24option add *Button.highlightThickness 2
25option add *Button.font {Helvetica -12 bold}
26
27eval image delete [image names]
28if {[testConstraint testImageType]} {
29    image create test image1
30}
31label .l -text Label
32button .b -text Button
33checkbutton .c -text Checkbutton
34radiobutton .r -text Radiobutton
35pack .l .b .c .r
36update
37set i 1
38foreach test {
39    {-activebackground #012345 #012345 non-existent
40	    {unknown color name "non-existent"} {1 1 1 1}}
41    {-activeforeground #ff0000 #ff0000 non-existent
42	    {unknown color name "non-existent"} {1 1 1 1}}
43    {-anchor nw nw bogus
44	    {bad anchor "bogus": must be n, ne, e, se, s, sw, w, nw, or center}
45	    {1 1 1 1}}
46    {-background #ff0000 #ff0000 non-existent
47	    {unknown color name "non-existent"} {1 1 1 1}}
48    {-bd 4 4 badValue {bad screen distance "badValue"} {1 1 1 1}}
49    {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}
50	    {1 1 1 1}}
51    {-bitmap questhead questhead badValue {bitmap "badValue" not defined}
52	    {1 1 1 1}}
53    {-borderwidth 1.3 1.3 badValue {bad screen distance "badValue"} {1 1 1 1}}
54    {-command "set x" {set x} {} {} {0 1 1 1}}
55    {-compound left left bogus
56	    {bad compound "bogus": must be bottom, center, left, none, right, or top}
57	    {1 1 1 1}}
58    {-cursor arrow arrow badValue {bad cursor spec "badValue"} {1 1 1 1}}
59    {-default active active huh?
60	    {bad default "huh?": must be active, disabled, or normal}
61	    {0 1 0 0}}
62    {-disabledforeground #00ff00 #00ff00 xyzzy {unknown color name "xyzzy"}
63	    {1 1 1 1}}
64    {-fg #110022 #110022 bogus {unknown color name "bogus"} {1 1 1 1}}
65    {-font {Helvetica 12} {Helvetica 12} {} {font "" doesn't exist} {1 1 1 1}}
66    {-foreground #110022 #110022 bogus {unknown color name "bogus"} {1 1 1 1}}
67    {-height 18 18 20.0 {expected integer but got "20.0"} {1 1 1 1}}
68    {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}
69	    {1 1 1 1}}
70    {-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}
71	    {1 1 1 1}}
72    {-highlightthickness 6m 6m badValue {bad screen distance "badValue"}
73	    {1 1 1 1}}
74    {-image image1 image1 bogus {image "bogus" doesn't exist} {1 1 1 1}}
75    {-indicatoron yes 1 no_way {expected boolean value but got "no_way"}
76	    {0 0 1 1}}
77    {-justify right right bogus
78	    {bad justification "bogus": must be left, right, or center}
79	    {1 1 1 1}}
80    {-offrelief flat flat 1.5
81	    {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
82	    {0 0 1 1}}
83    {-offvalue lousy lousy {} {} {0 0 1 0}}
84    {-onvalue fantastic fantastic {} {} {0 0 1 0}}
85    {-overrelief "" "" 1.5
86	    {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
87	    {0 1 1 1}}
88    {-padx 12m 12m 420x {bad screen distance "420x"} {1 1 1 1}}
89    {-pady 12m 12m 420x {bad screen distance "420x"} {1 1 1 1}}
90    {-repeatdelay 100 100 foo {expected integer but got "foo"} {0 1 0 0}}
91    {-repeatinterval 100 100 foo {expected integer but got "foo"} {0 1 0 0}}
92    {-relief flat flat 1.5
93	    {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
94	    {1 1 1 1}}
95    {-selectcolor #110022 #110022 bogus {unknown color name "bogus"} {0 0 1 1}}
96    {-selectimage image1 image1 bogus {image "bogus" doesn't exist} {0 0 1 1}}
97    {-state normal normal bogus
98	    {bad state "bogus": must be active, disabled, or normal}
99	    {1 1 1 1}}
100    {-takefocus "any string" "any string" {} {} {1 1 1 1}}
101    {-text "Sample text" {Sample text} {} {} {1 1 1 1}}
102    {-textvariable i i {} {} {1 1 1 1}}
103    {-tristateimage image1 image1 bogus {image "bogus" doesn't exist}
104	    {0 0 1 1}}
105    {-tristatevalue unknowable unknowable {} {} {0 0 1 1}}
106    {-underline 5 5 3p {expected integer but got "3p"} {1 1 1 1}}
107    {-value anyString anyString {} {} {0 0 0 1}}
108    {-width 402 402 3p {expected integer but got "3p"} {1 1 1 1}}
109    {-wraplength 100 100 6x {bad screen distance "6x"} {1 1 1 1}}
110} {
111    lassign $test name value okResult badValue badResult classes
112    foreach w {.l .b .c .r} hasOption $classes {
113	set classname [winfo class $w]
114	if {$hasOption} {
115	    test button-1.$i "configuration option $name for $classname" \
116		-constraints testImageType -body "
117		    $w configure $name [list $value]
118		    lindex \[$w configure $name] 4
119		" -result $okResult
120	    incr i
121	    if {$badValue ne ""} {
122		test button-1.$i "configuration option $name for $classname" \
123		    -constraints testImageType \
124		    -body [list $w configure $name $badValue] \
125		    -returnCodes error -result $badResult
126		incr i
127	    }
128	    $w configure $name [lindex [$w configure $name] 3]
129	} else {
130	    test button-1.$i "configuration option $name for $classname" \
131		-constraints testImageType \
132		-body [list $w configure $name $value] \
133		-returnCodes error -result "unknown option \"$name\""
134	    incr i
135	}
136    }
137}
138test button-1.$i {configuration options} {
139    # Additional check to make sure that -selectcolor may be empty in
140    # checkbox widgets
141    .c configure -selectcolor {}
142} {}
143
144test button-3.1 {ButtonCreate - not enough cd ../unix
145} {
146    list [catch {button} msg] $msg
147} {1 {wrong # args: should be "button pathName ?options?"}}
148test button-3.2 {ButtonCreate procedure - setting label class} {
149    catch {destroy .x}
150    label .x
151    winfo class .x
152} {Label}
153test button-3.3 {ButtonCreate - setting button class} {
154    catch {destroy .x}
155    button .x
156    winfo class .x
157} {Button}
158test button-3.4 {ButtonCreate - setting checkbutton class} {
159    catch {destroy .x}
160    checkbutton .x
161    winfo class .x
162} {Checkbutton}
163test button-3.5 {ButtonCreate - setting radiobutton class} {
164    catch {destroy .x}
165    radiobutton .x
166    winfo class .x
167} {Radiobutton}
168rename button gorp
169test button-3.6 {ButtonCreate - setting class} {
170    catch {destroy .x}
171    gorp .x
172    winfo class .x
173} {Button}
174rename gorp button
175test button-3.7 {ButtonCreate - bad window name} {
176    list [catch {button foo} msg] $msg
177} {1 {bad window path name "foo"}}
178test button-3.8 {ButtonCreate procedure - error in default option value} {
179    catch {destroy .funny}
180    option add *funny.background bogus
181    list [catch {button .funny} msg] $msg $errorInfo
182} {1 {unknown color name "bogus"} {unknown color name "bogus"
183    (database entry for "-background" in widget ".funny")
184    invoked from within
185"button .funny"}}
186test button-3.9 {ButtonCreate procedure - option error} {
187    catch {destroy .x}
188    list [catch {button .x -gorp foo} msg] $msg [winfo exists .x]
189} {1 {unknown option "-gorp"} 0}
190test button-3.10 {ButtonCreate procedure - return value} {
191    catch {destroy .abcd}
192    set x [button .abcd]
193    destroy .abc
194    set x
195} {.abcd}
196
197test button-4.1 {ButtonWidgetCmd - too few arguments} {
198    list [catch {.b} msg] $msg
199} {1 {wrong # args: should be ".b option ?arg arg ...?"}}
200test button-4.2 {ButtonWidgetCmd - bad option name} {
201    list [catch {.b c} msg] $msg
202} {1 {ambiguous option "c": must be cget, configure, flash, or invoke}}
203test button-4.3 {ButtonWidgetCmd - bad option name} {
204    list [catch {.b bogus} msg] $msg
205} {1 {bad option "bogus": must be cget, configure, flash, or invoke}}
206test button-4.4 {ButtonWidgetCmd procedure, "cget" option} {
207    list [catch {.b cget a b} msg] $msg
208} {1 {wrong # args: should be ".b cget option"}}
209test button-4.5 {ButtonWidgetCmd procedure, "cget" option} {
210    list [catch {.b cget -gorp} msg] $msg
211} {1 {unknown option "-gorp"}}
212test button-4.6 {ButtonWidgetCmd procedure, "cget" option} {
213    .b configure -highlightthickness 3
214    .b cget -highlightthickness
215} {3}
216test button-4.7 {ButtonWidgetCmd procedure, "cget" option} {
217    catch {.l cget -disabledforeground}
218} {0}
219test button-4.8 {ButtonWidgetCmd procedure, "cget" option} {
220    catch {.b cget -disabledforeground}
221} {0}
222test button-4.9 {ButtonWidgetCmd procedure, "cget" option} {
223    list [catch {.b cget -variable} msg] $msg
224} {1 {unknown option "-variable"}}
225test button-4.10 {ButtonWidgetCmd procedure, "cget" option} {
226    catch {.c cget -variable}
227} {0}
228test button-4.11 {ButtonWidgetCmd procedure, "cget" option} {
229    list [catch {.c cget -value} msg] $msg
230} {1 {unknown option "-value"}}
231test button-4.12 {ButtonWidgetCmd procedure, "cget" option} {
232    catch {.r cget -value}
233} {0}
234test button-4.13 {ButtonWidgetCmd procedure, "cget" option} {
235    list [catch {.r cget -onvalue} msg] $msg
236} {1 {unknown option "-onvalue"}}
237test button-4.14 {ButtonWidgetCmd procedure, "configure" option} {
238    llength [.c configure]
239} {41}
240test button-4.15 {ButtonWidgetCmd procedure, "configure" option} {
241    list [catch {.b configure -gorp} msg] $msg
242} {1 {unknown option "-gorp"}}
243test button-4.16 {ButtonWidgetCmd procedure, "configure" option} {
244    list [catch {.b co -bg #ffffff -fg} msg] $msg
245} {1 {value for "-fg" missing}}
246test button-4.17 {ButtonWidgetCmd procedure, "configure" option} {
247    .b configure -fg #123456
248    .b configure -bg #654321
249    lindex [.b configure -fg] 4
250} {#123456}
251.c configure -variable value -onvalue 1 -offvalue 0
252.r configure -variable value2 -value red
253test button-4.18 {ButtonWidgetCmd procedure, "deselect" option} {
254    list [catch {.c deselect foo} msg] $msg
255} {1 {wrong # args: should be ".c deselect"}}
256test button-4.19 {ButtonWidgetCmd procedure, "deselect" option} {
257    list [catch {.l deselect} msg] $msg
258} {1 {bad option "deselect": must be cget or configure}}
259test button-4.20 {ButtonWidgetCmd procedure, "deselect" option} {
260    list [catch {.b deselect} msg] $msg
261} {1 {bad option "deselect": must be cget, configure, flash, or invoke}}
262test button-4.21 {ButtonWidgetCmd procedure, "deselect" option} {
263    set value 1
264    .c d
265    set value
266} {0}
267test button-4.22 {ButtonWidgetCmd procedure, "deselect" option} {
268    set value2 green
269    .r deselect
270    set value2
271} {green}
272test button-4.23 {ButtonWidgetCmd procedure, "deselect" option} {
273    set value2 red
274    .r deselect
275    set value2
276} {}
277test button-4.24 {ButtonWidgetCmd procedure, "deselect" option} -body {
278    set value 1
279    trace variable value w bogusTrace
280    set result [list [catch {.c deselect} msg] $msg $errorInfo $value]
281    trace vdelete value w bogusTrace
282    set result
283} -match glob -result {1 {can't set "value": trace aborted} {*trace aborted
284    while executing
285*
286".c deselect"} 0}
287test button-4.25 {ButtonWidgetCmd procedure, "deselect" option} -body {
288    set value2 red
289    trace variable value2 w bogusTrace
290    set result [list [catch {.r deselect} msg] $msg $errorInfo $value2]
291    trace vdelete value2 w bogusTrace
292    set result
293} -match glob -result {1 {can't set "value2": trace aborted} {*trace aborted
294    while executing
295*
296".r deselect"} {}}
297test button-4.26 {ButtonWidgetCmd procedure, "flash" option} {
298    list [catch {.b flash foo} msg] $msg
299} {1 {wrong # args: should be ".b flash"}}
300test button-4.27 {ButtonWidgetCmd procedure, "flash" option} {
301    list [catch {.l flash} msg] $msg
302} {1 {bad option "flash": must be cget or configure}}
303test button-4.28 {ButtonWidgetCmd procedure, "flash" option} {
304    list [catch {.b flash} msg] $msg
305} {0 {}}
306test button-4.29 {ButtonWidgetCmd procedure, "flash" option} {
307    list [catch {.c flash} msg] $msg
308} {0 {}}
309test button-4.30 {ButtonWidgetCmd procedure, "flash" option} {
310    list [catch {.r f} msg] $msg
311} {0 {}}
312test button-4.31 {ButtonWidgetCmd procedure, "invoke" option} {
313    list [catch {.b invoke foo} msg] $msg
314} {1 {wrong # args: should be ".b invoke"}}
315test button-4.32 {ButtonWidgetCmd procedure, "invoke" option} {
316    list [catch {.l invoke} msg] $msg
317} {1 {bad option "invoke": must be cget or configure}}
318test button-4.33 {ButtonWidgetCmd procedure, "invoke" option} {
319    .b configure -command {set x invoked}
320    set x "not invoked"
321    .b invoke
322    set x
323} {invoked}
324test button-4.34 {ButtonWidgetCmd procedure, "invoke" option} {
325    .b configure -command {set x invoked} -state disabled
326    set x "not invoked"
327    .b invoke
328    set x
329} {not invoked}
330test button-4.35 {ButtonWidgetCmd procedure, "invoke" option} {
331    set value bogus
332    .c configure -command {set x invoked} -variable value -onvalue 1 \
333	    -offvalue 0
334    set x "not invoked"
335    .c invoke
336    list $x $value
337} {invoked 1}
338test button-4.36 {ButtonWidgetCmd procedure, "invoke" option} {
339    set value2 green
340    .r configure -command {set x invoked} -variable value2 -value red
341    set x "not invoked"
342    .r i
343    list $x $value2
344} {invoked red}
345test button-4.37 {ButtonWidgetCmd procedure, "select" option} {
346    list [catch {.l select} msg] $msg
347} {1 {bad option "select": must be cget or configure}}
348test button-4.38 {ButtonWidgetCmd procedure, "select" option} {
349    list [catch {.b select} msg] $msg
350} {1 {bad option "select": must be cget, configure, flash, or invoke}}
351test button-4.39 {ButtonWidgetCmd procedure, "select" option} {
352    list [catch {.c select foo} msg] $msg
353} {1 {wrong # args: should be ".c select"}}
354test button-4.40 {ButtonWidgetCmd procedure, "select" option} {
355    set value bogus
356    .c configure -command {} -variable value -onvalue lovely -offvalue 0
357    .c s
358    set value
359} {lovely}
360test button-4.41 {ButtonWidgetCmd procedure, "select" option} {
361    set value2 green
362    .r configure -command {} -variable value2 -value red
363    .r select
364    set value2
365} {red}
366test button-4.42 {ButtonWidgetCmd procedure, "select" option} -body {
367    set value2 yellow
368    trace variable value2 w bogusTrace
369    set result [list [catch {.r select} msg] $msg $errorInfo $value2]
370    trace vdelete value2 w bogusTrace
371    set result
372} -match glob -result {1 {can't set "value2": trace aborted} {*trace aborted
373    while executing
374*
375".r select"} red}
376test button-4.43 {ButtonWidgetCmd procedure, "toggle" option} {
377    list [catch {.l toggle} msg] $msg
378} {1 {bad option "toggle": must be cget or configure}}
379test button-4.44 {ButtonWidgetCmd procedure, "toggle" option} {
380    list [catch {.b toggle} msg] $msg
381} {1 {bad option "toggle": must be cget, configure, flash, or invoke}}
382test button-4.45 {ButtonWidgetCmd procedure, "toggle" option} {
383    list [catch {.r toggle} msg] $msg
384} {1 {bad option "toggle": must be cget, configure, deselect, flash, invoke, or select}}
385test button-4.46 {ButtonWidgetCmd procedure, "toggle" option} {
386    list [catch {.c toggle foo} msg] $msg
387} {1 {wrong # args: should be ".c toggle"}}
388test button-4.47 {ButtonWidgetCmd procedure, "toggle" option} {
389    set value bogus
390    .c configure -command {} -variable value -onvalue sunshine -offvalue rain
391    .c toggle
392    set result $value
393    .c toggle
394    lappend result $value
395    .c toggle
396    lappend result $value
397} {sunshine rain sunshine}
398test button-4.48 {ButtonWidgetCmd procedure, "toggle" option} -body {
399    .c configure -onvalue xyz -offvalue abc
400    set value xyz
401    trace variable value w bogusTrace
402    set result [list [catch {.c toggle} msg] $msg $errorInfo $value]
403    trace vdelete value w bogusTrace
404    set result
405} -match glob -result {1 {can't set "value": trace aborted} {*trace aborted
406    while executing
407*
408".c toggle"} abc}
409test button-4.49 {ButtonWidgetCmd procedure, "toggle" option} -body {
410    .c configure -onvalue xyz -offvalue abc
411    set value abc
412    trace variable value w bogusTrace
413    set result [list [catch {.c toggle} msg] $msg $errorInfo $value]
414    trace vdelete value w bogusTrace
415    set result
416} -match glob -result {1 {can't set "value": trace aborted} {*trace aborted
417    while executing
418*
419".c toggle"} xyz}
420test button-4.50 {ButtonWidgetCmd procedure, "toggle" option} {
421    catch {unset value}; set value(1) 1;
422    set result [list [catch {.c toggle} msg] $msg $errorInfo]
423    unset value;
424    set result
425} {1 {can't set "value": variable is array} {can't set "value": variable is array
426    while executing
427".c toggle"}}
428
429test button-5.1 {DestroyButton procedure} testImageType {
430    image create test image1
431    button .b1 -image image1
432    button .b2 -fg #ff0000 -text "Button 2"
433    button .b3 -state active -text "Button 3"
434    button .b4 -disabledforeground #0000ff -state disabled -text "Button 4"
435    checkbutton .b5 -variable x -text "Checkbutton 5"
436    set x 1
437    pack .b1 .b2 .b3 .b4 .b5
438    update
439    deleteWindows
440} {}
441
442test button-6.1 {ConfigureButton - textvariable trace} {
443    catch {destroy .b1}
444    button .b1 -bd 4 -bg green
445    catch {.b1 configure -bd 7 -bg green -fg bogus}
446    list [catch {.b1 configure -bd 7 -bg red -fg bogus} msg] \
447	    $msg [.b1 cget -bd] [.b1 cget -bg]
448} {1 {unknown color name "bogus"} 4 green}
449test button-6.2 {ConfigureButton - textvariable trace} {
450    catch {destroy .b1}
451    set x From-x
452    set y From-y
453    button .b1 -textvariable x
454    .b1 configure -textvariable y
455    set x New
456    lindex [.b1 configure -text] 4
457} {From-y}
458test button-6.2a {ConfigureButton - variable traces} {
459    catch {destroy .b1}
460    catch {unset x}
461    checkbutton .b1 -variable x
462    set x 1
463    set y 1
464    .b1 configure -textvariable y
465    set x 0
466    .b1 toggle
467    set y
468} {1}
469test button-6.3 {ConfigureButton - image handling} testImageType {
470    catch {destroy .b1}
471    eval image delete [image names]
472    image create test image1
473    image create test image2
474    button .b1 -image image1
475    image delete image1
476    .b1 configure -image image2
477    image names
478} {image2}
479test button-6.5 {ConfigureButton - default value for variable} {
480    catch {destroy .b1}
481    checkbutton .b1
482    .b1 cget -variable
483} {b1}
484test button-6.6 {ConfigureButton - setting selected state from variable} {
485    catch {destroy .b1}
486    set x 0
487    set y Shiny
488    checkbutton .b1 -variable x
489    .b1 configure -variable y -onvalue Shiny
490    .b1 toggle
491    set y
492} 0
493test button-6.7 {ConfigureButton - setting selected state from variable} {
494    catch {destroy .b1}
495    catch {unset x}
496    checkbutton .b1 -variable x -offvalue Bogus
497    set x
498} Bogus
499test button-6.8 {ConfigureButton - setting selected state from variable} {
500    catch {destroy .b1}
501    catch {unset x}
502    radiobutton .b1 -variable x
503    set x
504} {}
505test button-6.9 {ConfigureButton - error in setting variable} {
506    catch {destroy .b1}
507    catch {unset x}
508    trace variable x w bogusTrace
509    set result [list [catch {radiobutton .b1 -variable x} msg] $msg]
510    trace vdelete x w bogusTrace
511    set result
512} {1 {can't set "x": trace aborted}}
513test button-6.10 {ConfigureButton - bad image name} {
514    catch {destroy .b1}
515    list [catch {button .b1 -image bogus} msg] $msg
516} {1 {image "bogus" doesn't exist}}
517test button-6.11 {ConfigureButton - setting variable from current text value} {
518    catch {destroy .b1}
519    catch {unset x}
520    button .b1 -textvariable x -text "Button 1"
521    set x
522} {Button 1}
523test button-6.12 {ConfigureButton - using current value of variable} {
524    catch {destroy .b1}
525    set x Override
526    button .b1 -textvariable x -text "Button 1"
527    set x
528} {Override}
529test button-6.13 {ConfigureButton - variable handling} {
530    catch {destroy .b1}
531    catch {unset x}
532    trace variable x w bogusTrace
533    set result [list [catch {radiobutton .b1 -text foo -textvariable x} msg] \
534	    $msg $x]
535    trace vdelete x w bogusTrace
536    set result
537} {1 {can't set "x": trace aborted} foo}
538test button-6.14 {ConfigureButton - -width option} {
539    catch {destroy .b1}
540    button .b1 -text "Button 1"
541    list [catch {.b1 configure -width 1i} msg] $msg $errorInfo
542} {1 {expected integer but got "1i"} {expected integer but got "1i"
543    (processing -width option)
544    invoked from within
545".b1 configure -width 1i"}}
546test button-6.15 {ConfigureButton - -height option} {
547    catch {destroy .b1}
548    button .b1 -text "Button 1"
549    list [catch {.b1 configure -height 0.5c} msg] $msg $errorInfo
550} {1 {expected integer but got "0.5c"} {expected integer but got "0.5c"
551    (processing -height option)
552    invoked from within
553".b1 configure -height 0.5c"}}
554test button-6.16 {ConfigureButton - -width option} {
555    catch {destroy .b1}
556    button .b1 -bitmap questhead
557    list [catch {.b1 configure -width abc} msg] $msg $errorInfo
558} {1 {bad screen distance "abc"} {bad screen distance "abc"
559    (processing -width option)
560    invoked from within
561".b1 configure -width abc"}}
562test button-6.17 {ConfigureButton - -height option} testImageType {
563    catch {destroy .b1}
564    eval image delete [image names]
565    image create test image1
566    button .b1 -image image1
567    list [catch {.b1 configure -height 0.5x} msg] $msg $errorInfo
568} {1 {bad screen distance "0.5x"} {bad screen distance "0.5x"
569    (processing -height option)
570    invoked from within
571".b1 configure -height 0.5x"}}
572test button-6.18 {ConfigureButton - computing geometry} {nonPortable fonts} {
573    catch {destroy .b1}
574    button .b1 -text "Sample text" -width 10 -height 2
575    pack .b1
576    set result "[winfo reqwidth .b1] [winfo reqheight .b1]"
577    .b1 configure -bitmap questhead
578    lappend result [winfo reqwidth .b1] [winfo reqheight .b1]
579} {102 46 20 12}
580test button-6.19 {ConfigureButton - computing geometry} {
581    catch {destroy .b1}
582    button .b1 -text "Button 1"
583    set old [winfo reqwidth .b1]
584    .b1 configure -text "Much longer text"
585    set new [winfo reqwidth .b1]
586    expr $old == $new
587} {0}
588
589test button-7.1 {ButtonEventProc procedure} {
590    catch {destroy .b1}
591    button .b1 -text "Test Button" -command {
592	destroy .b1
593	set x [list [winfo exists .b1] [info commands .b1]]
594    }
595    .b1 invoke
596    set x
597} {0 {}}
598test button-7.2 {ButtonEventProc procedure} {
599    deleteWindows
600    button .b1 -bg #543210
601    rename .b1 .b2
602    set x {}
603    lappend x [winfo children .]
604    lappend x [.b2 cget -bg]
605    destroy .b1
606    lappend x [info command .b*] [winfo children .]
607} {.b1 #543210 {} {}}
608
609test button-8.1 {ButtonCmdDeletedProc procedure} {
610    deleteWindows
611    button .b1
612    rename .b1 {}
613    list [info command .b*] [winfo children .]
614} {{} {}}
615
616test button-9.1 {TkInvokeButton procedure} {
617    catch {destroy .b1}
618    set x 0
619    checkbutton .b1 -variable x
620    set result $x
621    .b1 invoke
622    lappend result $x
623    .b1 invoke
624    lappend result $x
625} {0 1 0}
626test button-9.2 {TkInvokeButton procedure} {
627    catch {destroy .b1}
628    set x 0
629    checkbutton .b1 -variable x
630    trace variable x w bogusTrace
631    set result [list [catch {.b1 invoke} msg] $msg $x]
632    trace vdelete x w bogusTrace
633    set result
634} {1 {can't set "x": trace aborted} 1}
635test button-9.3 {TkInvokeButton procedure} {
636    catch {destroy .b1}
637    set x 1
638    checkbutton .b1 -variable x
639    trace variable x w bogusTrace
640    set result [list [catch {.b1 invoke} msg] $msg $x]
641    trace vdelete x w bogusTrace
642    set result
643} {1 {can't set "x": trace aborted} 0}
644test button-9.4 {TkInvokeButton procedure} {
645    catch {destroy .b1}
646    set x 0
647    radiobutton .b1 -variable x -value red
648    set result $x
649    .b1 invoke
650    lappend result $x
651    .b1 invoke
652    lappend result $x
653} {0 red red}
654test button-9.5 {TkInvokeButton procedure} -body {
655    catch {destroy .b1}
656    radiobutton .b1 -variable x -value red
657    set x green
658    trace variable x w bogusTrace
659    set result [list [catch {.b1 invoke} msg] $msg $errorInfo $x]
660    trace vdelete x w bogusTrace
661    set result
662} -match glob -result {1 {can't set "x": trace aborted} {*trace aborted
663    while executing
664*
665".b1 invoke"} red}
666test button-9.6 {TkInvokeButton procedure} {
667    deleteWindows
668    set result untouched
669    button .b1 -command {set result invoked}
670    list [catch {.b1 invoke} msg] $msg $result
671} {0 invoked invoked}
672test button-9.7 {TkInvokeButton procedure} {
673    deleteWindows
674    set result untouched
675    set x 0
676    checkbutton .b1 -variable x -command {set result "invoked $x"}
677    list [catch {.b1 invoke} msg] $msg $result
678} {0 {invoked 1} {invoked 1}}
679test button-9.8 {TkInvokeButton procedure} {
680    deleteWindows
681    set result untouched
682    set x 0
683    radiobutton .b1 -variable x -value red -command {set result "invoked $x"}
684    list [catch {.b1 invoke} msg] $msg $result
685} {0 {invoked red} {invoked red}}
686
687test button-10.1 {ButtonVarProc procedure} {
688    deleteWindows
689    set x 1
690    checkbutton .b1 -variable x
691    unset x
692    set result [info exists x]
693    .b1 toggle
694    lappend result $x
695    set x 0
696    .b1 toggle
697    lappend result $x
698} {0 1 1}
699test button-10.2 {ButtonVarProc procedure} {
700    deleteWindows
701    set x 0
702    checkbutton .b1 -variable x
703    set x 44
704    .b1 toggle
705    set x
706} {1}
707test button-10.3 {ButtonVarProc procedure} {
708    deleteWindows
709    set x 1
710    checkbutton .b1 -variable x
711    set x 44
712    .b1 toggle
713    set x
714} {1}
715test button-10.4 {ButtonVarProc procedure} {
716    deleteWindows
717    set x 0
718    checkbutton .b1 -variable x
719    set x 1
720    .b1 toggle
721    set x
722} {0}
723test button-10.5 {ButtonVarProc procedure} {
724    deleteWindows
725    set x 1
726    checkbutton .b1 -variable x
727    set x 1
728    .b1 toggle
729    set x
730} {0}
731test button-10.6 {ButtonVarProc procedure} {
732    deleteWindows
733    set x 0
734    checkbutton .b1 -variable x
735    set x 0
736    .b1 toggle
737    set x
738} {1}
739test button-10.7 {ButtonVarProc procedure} {
740    deleteWindows
741    set x 1
742    checkbutton .b1 -variable x
743    set x 0
744    .b1 toggle
745    set x
746} {1}
747test button-10.8 {ButtonVarProc procedure, can't read variable} {
748    # This test does nothing but produce a core dump if there's a prbblem.
749    deleteWindows
750    catch {unset a}
751    checkbutton .b1 -variable a
752    unset a
753    set a(32) 0
754    unset a
755} {}
756
757test button-11.1 {ButtonTextVarProc procedure} {
758    deleteWindows
759    set x Label
760    button .b1 -textvariable x
761    unset x
762    set result [list $x [lindex [.b1 configure -text] 4]]
763    set x New
764    lappend result [lindex [.b1 configure -text] 4]
765} {Label Label New}
766test button-11.2 {ButtonTextVarProc procedure} {
767    deleteWindows
768    # Windows buttons have a default min width, so we have to
769    # set this to be longer to force the wider button.
770    set x ExtraLongLabel
771    button .b1 -textvariable x
772    set old [winfo reqwidth .b1]
773    set x New
774    set new [winfo reqwidth .b1]
775    list [lindex [.b1 configure -text] 4] [expr $old == $new]
776} {New 0}
777
778test button-12.1 {ButtonImageProc procedure} testImageType {
779    deleteWindows
780    eval image delete [image names]
781    image create test image1
782    label .b1 -image image1 -padx 0 -pady 0 -bd 0
783    pack .b1
784    set result "[winfo reqwidth .b1] [winfo reqheight .b1]"
785    image1 changed 0 0 0 0 80 100
786    lappend result [winfo reqwidth .b1] [winfo reqheight .b1]
787} {30 15 80 100}
788
789deleteWindows
790set l [interp hidden]
791
792test button-13.1 {button widget vs hidden commands} {
793    catch {destroy .b}
794    button .b -text hello
795    interp hide {} .b
796    destroy .b
797    list [winfo children .] [interp hidden]
798} [list {} $l]
799
800deleteWindows
801
802test button-14.1 {size behaviouor} {
803    set res {}
804    foreach class {label button radiobutton checkbutton} {
805	eval destroy [winfo children .]
806
807	$class .a -text Hej
808	$class .b -text Hej -width 10 -height 1
809	$class .c -text "" -width 10 -height 1
810
811	for {set t 0} {$t < 2} {incr t} {
812	    set res2 {}
813	    # With -width, width should not be affected by text change
814	    lappend res2 [expr {[winfo reqwidth .b] == [winfo reqwidth .c]}]
815	    # With -height, height should not be affected by text change
816	    lappend res2 [expr {[winfo reqheight .b] == [winfo reqheight .c]}]
817	    # A one line text should be as high as -height 1
818	    lappend res2 [expr {[winfo reqheight .a] == [winfo reqheight .b]}]
819	    lappend res $res2
820
821	    # Do the second round with another font
822	    .a configure -font "Arial 20"
823	    .b configure -font "Arial 20"
824	    .c configure -font "Arial 20"
825	}
826    }
827    set res
828} {{1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1}}
829
830deleteWindows
831
832option clear
833
834# cleanup
835cleanupTests
836return
837