1 # This file is a Tcl script to test menubuttons in Tk. It is
2 # organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1994 The Regents of the University of California.
5 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # XXX This test file is woefully incomplete right now. If any part
12 # XXX of a procedure has tests then the whole procedure has tests,
13 # XXX but many procedures have no tests.
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 # Create entries in the option database to be sure that geometry options
23 # like border width have predictable values.
25 option add *Menubutton.borderWidth 2
26 option add *Menubutton.highlightThickness 2
27 option add *Menubutton.font {Helvetica -12 bold}
28 option add *Button.borderWidth 2
29 option add *Button.highlightThickness 2
30 option add *Button.font {Helvetica -12 bold}
32 eval image delete [image names]
33 if {[testConstraint testImageType]} {
34 image create test image1
36 menubutton .mb -text "Test"
41 {-activebackground #012345 #012345 non-existent
42 {unknown color name "non-existent"}}
43 {-activeforeground #ff0000 #ff0000 non-existent
44 {unknown color name "non-existent"}}
45 {-anchor nw nw bogus {bad anchor "bogus": must be n, ne, e, se, s, sw, w, nw, or center}}
46 {-background #ff0000 #ff0000 non-existent
47 {unknown color name "non-existent"}}
48 {-bd 4 4 badValue {bad screen distance "badValue"}}
49 {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
50 {-bitmap questhead questhead badValue {bitmap "badValue" not defined}}
51 {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
52 {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
53 {-direction below below badValue {bad direction "badValue": must be above, below, flush, left, or right}}
54 {-disabledforeground #00ff00 #00ff00 xyzzy {unknown color name "xyzzy"}}
55 {-fg #110022 #110022 bogus {unknown color name "bogus"}}
56 {-font {Helvetica 12} {Helvetica 12} {} {font "" doesn't exist}}
57 {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
58 {-height 18 18 20.0 {expected integer but got "20.0"}}
59 {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
60 {-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}}
61 {-highlightthickness 18 18 badValue {bad screen distance "badValue"}}
62 {-image image1 image1 bogus {image "bogus" doesn't exist}}
63 {-indicatoron yes 1 no_way {expected boolean value but got "no_way"}}
64 {-justify right right bogus {bad justification "bogus": must be left, right, or center}}
65 {-menu "any old string" "any old string" {} {}}
66 {-padx 12 12 420x {bad screen distance "420x"}}
67 {-pady 12 12 420x {bad screen distance "420x"}}
68 {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
69 {-state normal normal bogus {bad state "bogus": must be active, disabled, or normal}}
70 {-takefocus "any string" "any string" {} {}}
71 {-text "Sample text" {Sample text} {} {}}
72 {-textvariable i i {} {}}
73 {-underline 5 5 3p {expected integer but got "3p"}}
74 {-width 402 402 3p {expected integer but got "3p"}}
75 {-wraplength 100 100 6x {bad screen distance "6x"}}
77 set name [lindex $test 0]
78 test menubutton-1.$i {configuration options} testImageType {
79 .mb configure $name [lindex $test 1]
80 lindex [.mb configure $name] 4
83 if {[lindex $test 3] != ""} {
84 test menubutton-1.$i {configuration options} {
85 list [catch {.mb configure $name [lindex $test 3]} msg] $msg
86 } [list 1 [lindex $test 4]]
88 .mb configure $name [lindex [.mb configure $name] 3]
92 test menubutton-2.1 {Tk_MenubuttonCmd procedure} {
93 list [catch {menubutton} msg] $msg
94 } {1 {wrong # args: should be "menubutton pathName ?options?"}}
95 test menubutton-2.2 {Tk_MenubuttonCmd procedure} {
96 list [catch {menubutton foo} msg] $msg
97 } {1 {bad window path name "foo"}}
98 test menubutton-2.3 {Tk_MenubuttonCmd procedure} {
103 test menubutton-2.4 {Tk_ButtonCmd procedure} {
105 list [catch {menubutton .mb -gorp foo} msg] $msg [winfo exists .mb]
106 } {1 {unknown option "-gorp"} 0}
109 menubutton .mb -text "Test Menu"
111 test menubutton-3.1 {MenuButtonWidgetCmd procedure} {
112 list [catch {.mb} msg] $msg
113 } {1 {wrong # args: should be ".mb option ?arg arg ...?"}}
114 test menubutton-3.2 {ButtonWidgetCmd procedure, "cget" option} {
115 list [catch {.mb c} msg] $msg
116 } {1 {ambiguous option "c": must be cget or configure}}
117 test menubutton-3.3 {ButtonWidgetCmd procedure, "cget" option} {
118 list [catch {.mb cget} msg] $msg
119 } {1 {wrong # args: should be ".mb cget option"}}
120 test menubutton-3.4 {ButtonWidgetCmd procedure, "cget" option} {
121 list [catch {.mb cget a b} msg] $msg
122 } {1 {wrong # args: should be ".mb cget option"}}
123 test menubutton-3.5 {ButtonWidgetCmd procedure, "cget" option} {
124 list [catch {.mb cget -gorp} msg] $msg
125 } {1 {unknown option "-gorp"}}
126 test menubutton-3.6 {ButtonWidgetCmd procedure, "cget" option} {
127 .mb configure -highlightthickness 3
128 .mb cget -highlightthickness
130 test menubutton-3.7 {ButtonWidgetCmd procedure, "configure" option} {
131 llength [.mb configure]
133 test menubutton-3.8 {ButtonWidgetCmd procedure, "configure" option} {
134 list [catch {.mb configure -gorp} msg] $msg
135 } {1 {unknown option "-gorp"}}
136 test menubutton-3.9 {ButtonWidgetCmd procedure, "configure" option} {
137 list [catch {.mb co -bg #ffffff -fg} msg] $msg
138 } {1 {value for "-fg" missing}}
139 test menubutton-3.10 {ButtonWidgetCmd procedure, "configure" option} {
140 .mb configure -fg #123456
141 .mb configure -bg #654321
142 lindex [.mb configure -fg] 4
144 test menubutton-3.11 {ButtonWidgetCmd procedure, "configure" option} {
145 list [catch {.mb foobar} msg] $msg
146 } {1 {bad option "foobar": must be cget or configure}}
148 # XXX Need to add tests for several procedures here. The tests for XXX
149 # XXX ConfigureMenuButton aren't complete either. XXX
151 test menubutton-4.1 {ConfigureMenuButton procedure} {
153 button .mb1 -text "Menubutton 1"
154 list [catch {.mb1 configure -width 1i} msg] $msg $errorInfo
155 } {1 {expected integer but got "1i"} {expected integer but got "1i"
156 (processing -width option)
158 ".mb1 configure -width 1i"}}
159 test menubutton-4.2 {ConfigureMenuButton procedure} {
161 button .mb1 -text "Menubutton 1"
162 list [catch {.mb1 configure -height 0.5c} msg] $msg $errorInfo
163 } {1 {expected integer but got "0.5c"} {expected integer but got "0.5c"
164 (processing -height option)
166 ".mb1 configure -height 0.5c"}}
167 test menubutton-4.3 {ConfigureMenuButton procedure} {
169 button .mb1 -bitmap questhead
170 list [catch {.mb1 configure -width abc} msg] $msg $errorInfo
171 } {1 {bad screen distance "abc"} {bad screen distance "abc"
172 (processing -width option)
174 ".mb1 configure -width abc"}}
175 test menubutton-4.4 {ConfigureMenuButton procedure} testImageType {
177 eval image delete [image names]
178 image create test image1
179 button .mb1 -image image1
180 list [catch {.mb1 configure -height 0.5x} msg] $msg $errorInfo
181 } {1 {bad screen distance "0.5x"} {bad screen distance "0.5x"
182 (processing -height option)
184 ".mb1 configure -height 0.5x"}}
185 test menubutton-4.5 {ConfigureMenuButton procedure} {nonPortable fonts} {
187 button .mb1 -text "Sample text" -width 10 -height 2
189 set result "[winfo reqwidth .mb1] [winfo reqheight .mb1]"
190 .mb1 configure -bitmap questhead
191 lappend result [winfo reqwidth .mb1] [winfo reqheight .mb1]
193 test menubutton-4.6 {ConfigureMenuButton procedure - bad direction} {
195 menubutton .mb -text "Test"
196 list [catch {.mb configure -direction badValue} msg] $msg \
197 [.mb cget -direction] [destroy .mb]
198 } {1 {bad direction "badValue": must be above, below, flush, left, or right} below {}}
200 # XXX Need to add tests for several procedures here. XXX
202 test menubutton-5.1 {MenuButtonEventProc procedure} {
204 menubutton .mb1 -bg #543210
207 lappend x [winfo children .]
208 lappend x [.mb2 cget -bg]
210 lappend x [info command .mb*] [winfo children .]
211 } {.mb1 #543210 {} {}}
213 test menubutton-6.1 {MenuButtonCmdDeletedProc procedure} {
217 list [info command .mb*] [winfo children .]
220 test menubutton-7.1 {ComputeMenuButtonGeometry procedure} testImageType {
222 menubutton .mb -image image1 -bd 4 -highlightthickness 0
224 list [winfo reqwidth .mb] [winfo reqheight .mb]
226 test menubutton-7.2 {ComputeMenuButtonGeometry procedure} testImageType {
228 menubutton .mb -image image1 -bd 1 -highlightthickness 2
230 list [winfo reqwidth .mb] [winfo reqheight .mb]
232 test menubutton-7.3 {ComputeMenuButtonGeometry procedure} testImageType {
234 menubutton .mb -image image1 -bd 0 -highlightthickness 2 -padx 5 -pady 5
236 list [winfo reqwidth .mb] [winfo reqheight .mb]
238 test menubutton-7.4 {ComputeMenuButtonGeometry procedure} testImageType {
240 menubutton .mb -image image1 -bd 2 -relief raised -width 40 \
241 -highlightthickness 2
243 list [winfo reqwidth .mb] [winfo reqheight .mb]
245 test menubutton-7.5 {ComputeMenuButtonGeometry procedure} testImageType {
247 menubutton .mb -image image1 -bd 2 -relief raised -height 30 \
248 -highlightthickness 2
250 list [winfo reqwidth .mb] [winfo reqheight .mb]
252 test menubutton-7.6 {ComputeMenuButtonGeometry procedure} {
254 menubutton .mb -bitmap question -bd 2 -relief raised \
255 -highlightthickness 2
257 list [winfo reqwidth .mb] [winfo reqheight .mb]
259 test menubutton-7.7 {ComputeMenuButtonGeometry procedure} {
261 menubutton .mb -bitmap question -bd 2 -relief raised -width 40 \
262 -highlightthickness 1
264 list [winfo reqwidth .mb] [winfo reqheight .mb]
266 test menubutton-7.8 {ComputeMenuButtonGeometry procedure} {
268 menubutton .mb -bitmap question -bd 2 -relief raised -height 50 \
269 -highlightthickness 1
271 list [winfo reqwidth .mb] [winfo reqheight .mb]
273 test menubutton-7.9 {ComputeMenuButtonGeometry procedure} {fonts} {
275 menubutton .mb -text String -bd 2 -relief raised -padx 0 -pady 0 \
276 -highlightthickness 1
278 list [winfo reqwidth .mb] [winfo reqheight .mb]
280 test menubutton-7.10 {ComputeMenuButtonGeometry procedure} {fonts} {
282 menubutton .mb -text String -bd 2 -relief raised -width 20 \
283 -padx 0 -pady 0 -highlightthickness 1
285 list [winfo reqwidth .mb] [winfo reqheight .mb]
287 test menubutton-7.11 {ComputeMenuButtonGeometry procedure} {fonts} {
289 menubutton .mb -text String -bd 2 -relief raised -height 2 \
290 -padx 0 -pady 0 -highlightthickness 1
292 list [winfo reqwidth .mb] [winfo reqheight .mb]
294 test menubutton-7.12 {ComputeMenuButtonGeometry procedure} {fonts} {
296 menubutton .mb -text String -bd 2 -relief raised -padx 10 -pady 5 \
297 -highlightthickness 1
299 list [winfo reqwidth .mb] [winfo reqheight .mb]
301 test menubutton-7.13 {ComputeMenuButtonGeometry procedure} {nonPortable fonts} {
303 menubutton .mb -text String -bd 2 -relief raised \
304 -highlightthickness 1 -indicatoron 1
306 list [winfo reqwidth .mb] [winfo reqheight .mb]
308 test menubutton-7.14 {ComputeMenuButtonGeometry procedure} {testImageType unixOnly nonPortable} {
309 # The following test is non-portable because the indicator's pixel
310 # size varies to maintain constant absolute size.
313 menubutton .mb -image image1 -bd 2 -relief raised \
314 -highlightthickness 2 -indicatoron 1
316 list [winfo reqwidth .mb] [winfo reqheight .mb]
318 test menubutton-7.15 {ComputeMenuButtonGeometry procedure} {testImageType pcOnly nonPortable} {
319 # The following test is non-portable because the indicator's pixel
320 # size varies to maintain constant absolute size.
323 menubutton .mb -image image1 -bd 2 -relief raised \
324 -highlightthickness 2 -indicatoron 1
326 list [winfo reqwidth .mb] [winfo reqheight .mb]
329 set l [interp hidden]
332 test menubutton-8.1 {menubutton vs hidden commands} {
337 list [winfo children .] [interp hidden]
340 eval image delete [image names]
345 ::tcltest::cleanupTests