summaryrefslogtreecommitdiffstats
path: root/tests/menubut.test
blob: 6613af1b8452d8b562afb2f160c3a461304d01e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# This file is a Tcl script to test menubuttons in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id: menubut.test,v 1.11 2008/07/23 23:24:25 nijtmans Exp $

# XXX This test file is woefully incomplete right now.  If any part
# XXX of a procedure has tests then the whole procedure has tests,
# XXX but many procedures have no tests.

package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Menubutton.borderWidth 2
option add *Menubutton.highlightThickness 2
option add *Menubutton.font {Helvetica -12 bold}
option add *Button.borderWidth 2
option add *Button.highlightThickness 2
option add *Button.font {Helvetica -12 bold}

eval image delete [image names]
if {[testConstraint testImageType]} {
    image create test image1
}
menubutton .mb -text "Test"
pack .mb
update
set i 1
foreach test {
    {-activebackground #012345 #012345 non-existent
	    {unknown color name "non-existent"}}
    {-activeforeground #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-anchor nw nw bogus {bad anchor "bogus": must be n, ne, e, se, s, sw, w, nw, or center}}
    {-background #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-bd 4 4 badValue {bad screen distance "badValue"}}
    {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
    {-bitmap questhead questhead badValue {bitmap "badValue" not defined}}
    {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
    {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
    {-direction below below badValue {bad direction "badValue": must be above, below, flush, left, or right}}
    {-disabledforeground #00ff00 #00ff00 xyzzy {unknown color name "xyzzy"}}
    {-fg #110022 #110022 bogus {unknown color name "bogus"}}
    {-font {Helvetica 12} {Helvetica 12} {} {font "" doesn't exist}}
    {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
    {-height 18 18 20.0 {expected integer but got "20.0"}}
    {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
    {-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}}
    {-highlightthickness 18 18 badValue {bad screen distance "badValue"}}
    {-image image1 image1 bogus {image "bogus" doesn't exist}}
    {-indicatoron yes 1 no_way {expected boolean value but got "no_way"}}
    {-justify right right bogus {bad justification "bogus": must be left, right, or center}}
    {-menu "any old string" "any old string" {} {}}
    {-padx 12 12 420x {bad screen distance "420x"}}
    {-pady 12 12 420x {bad screen distance "420x"}}
    {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
    {-state normal normal bogus {bad state "bogus": must be active, disabled, or normal}}
    {-takefocus "any string" "any string" {} {}}
    {-text "Sample text" {Sample text} {} {}}
    {-textvariable i i {} {}}
    {-underline 5 5 3p {expected integer but got "3p"}}
    {-width 402 402 3p {expected integer but got "3p"}}
    {-wraplength 100 100 6x {bad screen distance "6x"}}
} {
    set name [lindex $test 0]
    test menubutton-1.$i {configuration options} testImageType {
	.mb configure $name [lindex $test 1]
	lindex [.mb configure $name] 4
    } [lindex $test 2]
    incr i
    if {[lindex $test 3] != ""} {
	test menubutton-1.$i {configuration options} {
	    list [catch {.mb configure $name [lindex $test 3]} msg] $msg
	} [list 1 [lindex $test 4]]
    }
    .mb configure $name [lindex [.mb configure $name] 3]
    incr i
}

test menubutton-2.1 {Tk_MenubuttonCmd procedure} {
    list [catch {menubutton} msg] $msg
} {1 {wrong # args: should be "menubutton pathName ?-option value ...?"}}
test menubutton-2.2 {Tk_MenubuttonCmd procedure} {
    list [catch {menubutton foo} msg] $msg
} {1 {bad window path name "foo"}}
test menubutton-2.3 {Tk_MenubuttonCmd procedure} {
    catch {destroy .mb}
    menubutton .mb
    winfo class .mb
} {Menubutton}
test menubutton-2.4 {Tk_ButtonCmd procedure} {
    catch {destroy .mb}
    list [catch {menubutton .mb -gorp foo} msg] $msg [winfo exists .mb]
} {1 {unknown option "-gorp"} 0}

catch {destroy .mb}
menubutton .mb -text "Test Menu"
pack .mb
test menubutton-3.1 {MenuButtonWidgetCmd procedure} {
    list [catch {.mb} msg] $msg
} {1 {wrong # args: should be ".mb option ?arg ...?"}}
test menubutton-3.2 {ButtonWidgetCmd procedure, "cget" option} {
    list [catch {.mb c} msg] $msg
} {1 {ambiguous option "c": must be cget or configure}}
test menubutton-3.3 {ButtonWidgetCmd procedure, "cget" option} {
    list [catch {.mb cget} msg] $msg
} {1 {wrong # args: should be ".mb cget option"}}
test menubutton-3.4 {ButtonWidgetCmd procedure, "cget" option} {
    list [catch {.mb cget a b} msg] $msg
} {1 {wrong # args: should be ".mb cget option"}}
test menubutton-3.5 {ButtonWidgetCmd procedure, "cget" option} {
    list [catch {.mb cget -gorp} msg] $msg
} {1 {unknown option "-gorp"}}
test menubutton-3.6 {ButtonWidgetCmd procedure, "cget" option} {
    .mb configure -highlightthickness 3
    .mb cget -highlightthickness
} {3}
test menubutton-3.7 {ButtonWidgetCmd procedure, "configure" option} {
    llength [.mb configure]
} {33}
test menubutton-3.8 {ButtonWidgetCmd procedure, "configure" option} {
    list [catch {.mb configure -gorp} msg] $msg
} {1 {unknown option "-gorp"}}
test menubutton-3.9 {ButtonWidgetCmd procedure, "configure" option} {
    list [catch {.mb co -bg #ffffff -fg} msg] $msg
} {1 {value for "-fg" missing}}
test menubutton-3.10 {ButtonWidgetCmd procedure, "configure" option} {
    .mb configure -fg #123456
    .mb configure -bg #654321
    lindex [.mb configure -fg] 4
} {#123456}
test menubutton-3.11 {ButtonWidgetCmd procedure, "configure" option} {
    list [catch {.mb foobar} msg] $msg
} {1 {bad option "foobar": must be cget or configure}}

# XXX Need to add tests for several procedures here.   The tests for   XXX
# XXX ConfigureMenuButton aren't complete either.                      XXX

test menubutton-4.1 {ConfigureMenuButton procedure} {
    catch {destroy .mb1}
    button .mb1 -text "Menubutton 1"
    list [catch {.mb1 configure -width 1i} msg] $msg $errorInfo
} {1 {expected integer but got "1i"} {expected integer but got "1i"
    (processing -width option)
    invoked from within
".mb1 configure -width 1i"}}
test menubutton-4.2 {ConfigureMenuButton procedure} {
    catch {destroy .mb1}
    button .mb1 -text "Menubutton 1"
    list [catch {.mb1 configure -height 0.5c} msg] $msg $errorInfo
} {1 {expected integer but got "0.5c"} {expected integer but got "0.5c"
    (processing -height option)
    invoked from within
".mb1 configure -height 0.5c"}}
test menubutton-4.3 {ConfigureMenuButton procedure} {
    catch {destroy .mb1}
    button .mb1 -bitmap questhead
    list [catch {.mb1 configure -width abc} msg] $msg $errorInfo
} {1 {bad screen distance "abc"} {bad screen distance "abc"
    (processing -width option)
    invoked from within
".mb1 configure -width abc"}}
test menubutton-4.4 {ConfigureMenuButton procedure} testImageType {
    catch {destroy .mb1}
    eval image delete [image names]
    image create test image1
    button .mb1 -image image1
    list [catch {.mb1 configure -height 0.5x} msg] $msg $errorInfo
} {1 {bad screen distance "0.5x"} {bad screen distance "0.5x"
    (processing -height option)
    invoked from within
".mb1 configure -height 0.5x"}}
test menubutton-4.5 {ConfigureMenuButton procedure} {nonPortable fonts} {
    catch {destroy .mb1}
    button .mb1 -text "Sample text" -width 10 -height 2
    pack .mb1
    set result "[winfo reqwidth .mb1] [winfo reqheight .mb1]"
    .mb1 configure -bitmap questhead
    lappend result [winfo reqwidth .mb1] [winfo reqheight .mb1]
} {102 46 20 12}
test menubutton-4.6 {ConfigureMenuButton procedure - bad direction} {
    catch {destroy .mb}
    menubutton .mb -text "Test"
    list [catch {.mb configure -direction badValue} msg] $msg \
	[.mb cget -direction] [destroy .mb]
} {1 {bad direction "badValue": must be above, below, flush, left, or right} below {}}

# XXX Need to add tests for several procedures here. XXX

test menubutton-5.1 {MenuButtonEventProc procedure} {
    deleteWindows
    menubutton .mb1 -bg #543210
    rename .mb1 .mb2
    set x {}
    lappend x [winfo children .]
    lappend x [.mb2 cget -bg]
    destroy .mb1
    lappend x [info command .mb*] [winfo children .]
} {.mb1 #543210 {} {}}

test menubutton-6.1 {MenuButtonCmdDeletedProc procedure} {
    deleteWindows
    menubutton .mb1
    rename .mb1 {}
    list [info command .mb*] [winfo children .]
} {{} {}}

test menubutton-7.1 {ComputeMenuButtonGeometry procedure} testImageType {
    catch {destroy .mb}
    menubutton .mb -image image1 -bd 4 -highlightthickness 0
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {38 23}
test menubutton-7.2 {ComputeMenuButtonGeometry procedure} testImageType {
    catch {destroy .mb}
    menubutton .mb -image image1 -bd 1 -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {36 21}
test menubutton-7.3 {ComputeMenuButtonGeometry procedure} testImageType {
    catch {destroy .mb}
    menubutton .mb -image image1 -bd 0 -highlightthickness 2 -padx 5 -pady 5
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {34 19}
test menubutton-7.4 {ComputeMenuButtonGeometry procedure} testImageType {
    catch {destroy .mb}
    menubutton .mb -image image1 -bd 2 -relief raised -width 40 \
	    -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {48 23}
test menubutton-7.5 {ComputeMenuButtonGeometry procedure} testImageType {
    catch {destroy .mb}
    menubutton .mb -image image1 -bd 2 -relief raised -height 30 \
	    -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {38 38}
test menubutton-7.6 {ComputeMenuButtonGeometry procedure} {
    catch {destroy .mb}
    menubutton .mb -bitmap question -bd 2 -relief raised \
	    -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {25 35}
test menubutton-7.7 {ComputeMenuButtonGeometry procedure} {
    catch {destroy .mb}
    menubutton .mb -bitmap question -bd 2 -relief raised -width 40 \
	    -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {46 33}
test menubutton-7.8 {ComputeMenuButtonGeometry procedure} {
    catch {destroy .mb}
    menubutton .mb -bitmap question -bd 2 -relief raised -height 50 \
	    -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {23 56}
test menubutton-7.9 {ComputeMenuButtonGeometry procedure} {fonts} {
    catch {destroy .mb}
    menubutton .mb -text String -bd 2 -relief raised -padx 0 -pady 0 \
	    -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {42 20}
test menubutton-7.10 {ComputeMenuButtonGeometry procedure} {fonts} {
    catch {destroy .mb}
    menubutton .mb -text String -bd 2 -relief raised -width 20 \
	    -padx 0 -pady 0 -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {146 20}
test menubutton-7.11 {ComputeMenuButtonGeometry procedure} {fonts} {
    catch {destroy .mb}
    menubutton .mb -text String -bd 2 -relief raised -height 2 \
	    -padx 0 -pady 0 -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {42 34}
test menubutton-7.12 {ComputeMenuButtonGeometry procedure} {fonts} {
    catch {destroy .mb}
    menubutton .mb -text String -bd 2 -relief raised -padx 10 -pady 5 \
	    -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {62 30}
test menubutton-7.13 {ComputeMenuButtonGeometry procedure} {nonPortable fonts} {
    catch {destroy .mb}
    menubutton .mb -text String -bd 2 -relief raised \
	    -highlightthickness 1 -indicatoron 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {78 28}
test menubutton-7.14 {ComputeMenuButtonGeometry procedure} {testImageType unix nonPortable} {
    # The following test is non-portable because the indicator's pixel
    # size varies to maintain constant absolute size.

    catch {destroy .mb}
    menubutton .mb -image image1 -bd 2 -relief raised \
	    -highlightthickness 2 -indicatoron 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {64 23}
test menubutton-7.15 {ComputeMenuButtonGeometry procedure} {testImageType win nonPortable} {
    # The following test is non-portable because the indicator's pixel
    # size varies to maintain constant absolute size.

    catch {destroy .mb}
    menubutton .mb -image image1 -bd 2 -relief raised \
	    -highlightthickness 2 -indicatoron 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} {65 23}

set l [interp hidden]
deleteWindows

test menubutton-8.1 {menubutton vs hidden commands} {
    catch {destroy .mb}
    menubutton .mb
    interp hide {} .mb
    destroy .mb
    list [winfo children .] [interp hidden]
} [list {} $l]

eval image delete [image names]
deleteWindows
option clear

# cleanup
cleanupTests
return