blob: 2507a0e50b342989f8c790185ff86493ee55bccf (
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
# This file is a Tcl script to test drawing of menus in Tk. It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.
package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
imageInit
test menuDraw-1.1 {TkMenuInitializeDrawingFields} -setup {
deleteWindows
} -body {
menu .m1
} -cleanup {
deleteWindows
} -result {.m1}
test menuDraw-2.1 {TkInitializeMenuEntryDrawingFields} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command
} -cleanup {
deleteWindows
} -result {}
test menuDraw-3.1 {TkMenuFreeDrawOptions} -setup {
deleteWindows
} -body {
menu .m1
destroy .m1
} -result {}
test menuDraw-4.1 {TkMenuEntryFreeDrawOptions} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "This is a test"
destroy .m1
} -result {}
test menuDraw-4.2 {TkMenuEntryFreeDrawOptions} -setup {
deleteWindows
} -body {
menu .m1
.m1 add checkbutton -label "This is a test." -font "Courier 12" \
-activeforeground red -background green -selectcolor purple
destroy .m1
} -result {}
test menuDraw-5.1 {TkMenuConfigureDrawOptions - new menu} -setup {
deleteWindows
} -body {
menu .m1
} -cleanup {
deleteWindows
} -result {.m1}
test menuDraw-5.2 {TkMenuConfigureDrawOptions - old menu} -setup {
deleteWindows
} -body {
menu .m1
.m1 configure -fg red
} -cleanup {
deleteWindows
} -result {}
test menuDraw-5.3 {TkMenuConfigureDrawOptions - no disabledFg} -setup {
deleteWindows
} -body {
menu .m1 -disabledforeground ""
} -cleanup {
deleteWindows
} -result {.m1}
test menuDraw-6.1 {TkMenuConfigureEntryDrawOptions - no tkfont specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.2 {TkMenuConfigureEntryDrawOptions - tkfont specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -font "Courier 12"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.3 {TkMenuConfigureEntryDrawOptions - active state - wrong entry} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
.m1 entryconfigure 1 -state active
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.4 {TkMenuConfigureEntryDrawOptions - active state - correct entry} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
.m1 activate 1
.m1 entryconfigure 1 -state active
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.5 {TkMenuConfigureEntryDrawOptions - deactivate entry} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
.m1 activate 1
.m1 entryconfigure 1 -state normal
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.6 {TkMenuConfigureEntryDrawOptions - bad state} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
.m1 entryconfigure 1 -state foo
} -cleanup {
deleteWindows
} -returnCodes error -result {bad state "foo": must be active, normal, or disabled}
test menuDraw-6.7 {TkMenuConfigureEntryDrawOptions - tkfont specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -font "Courier 12"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.8 {TkMenuConfigureEntryDrawOptions - border specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -background "red"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.9 {TkMenuConfigureEntryDrawOptions - foreground specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -foreground "red"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.10 {TkMenuConfigureEntryDrawOptions - activeBorder specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -activebackground "red"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.11 {TkMenuConfigureEntryDrawOptions - activeforeground specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -activeforeground "red"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.12 {TkMenuConfigureEntryDrawOptions - selectcolor specified} -setup {
deleteWindows
} -body {
menu .m1
.m1 add radiobutton -label "foo" -selectcolor "red"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.13 {TkMenuConfigureEntryDrawOptions - textGC disposal} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -font "Helvetica 12"
.m1 entryconfigure 1 -font "Courier 12"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.14 {TkMenuConfigureEntryDrawOptions - activeGC disposal} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -activeforeground "red"
.m1 entryconfigure 1 -activeforeground "green"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.15 {TkMenuConfigureEntryDrawOptions - disabledGC disposal} -setup {
deleteWindows
} -body {
menu .m1 -disabledforeground "red"
.m1 add command -label "foo"
.m1 configure -disabledforeground "green"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-6.16 {TkMenuConfigureEntryDrawOptions - indicatorGC disposal} -setup {
deleteWindows
} -body {
menu .m1
.m1 add radiobutton -label "foo" -selectcolor "red"
.m1 entryconfigure 1 -selectcolor "green"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-7.1 {TkEventuallyRecomputeMenu} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "This is a long label"
set tearoff [tk::TearOffMenu .m1]
update idletasks
.m1 entryconfigure 1 -label "foo"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-7.2 {TkEventuallyRecomputeMenu - update pending} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "This is a long label"
set tearoff [tk::TearOffMenu .m1]
.m1 entryconfigure 1 -label "foo"
} -cleanup {
deleteWindows
} -result {}
test menuDraw-8.1 {TkRecomputeMenu} -constraints {
win userInteraction
} -setup {
deleteWindows
} -body {
menu .m1
.m1 configure -postcommand [.m1 add command -label foo]
.m1 add command -label "Hit ESCAPE to make this menu go away."
.m1 post 0 0
} -cleanup {
deleteWindows
} -result {}
test menuDraw-9.1 {TkEventuallyRedrawMenu - entry test} -setup {
deleteWindows
} -body {
catch {unset foo}
menu .m1
set foo 0
.m1 add radiobutton -variable foo -label test
tk::TearOffMenu .m1
update idletasks
list [set foo test] [destroy .m1] [unset foo]
} -result {test {} {}}
test menuDraw-9.2 {TkEventuallyRedrawMenu - whole menu} -setup {
deleteWindows
} -body {
menu .m1
tk::TearOffMenu .m1
} -cleanup {
deleteWindows
} -returnCodes ok -match glob -result *
# Don't know how to test when window has been deleted and ComputeMenuGeometry
# gets called.
test menuDraw-10.1 {ComputeMenuGeometry - menubar} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label test
. configure -menu .m1
list [update idletasks] [. configure -menu ""]
} -cleanup {
deleteWindows
} -result {{} {}}
test menuDraw-10.2 {ComputeMenuGeometry - non-menubar} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label test
update idletasks
} -cleanup {
deleteWindows
} -result {}
test menuDraw-10.3 {ComputeMenuGeometry - Resize necessary} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label test
update idletasks
} -cleanup {
deleteWindows
} -result {}
test menuDraw-10.4 {ComputeMenuGeometry - resize not necessary} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label test
update idletasks
.m1 entryconfigure 1 -label test
update idletasks
} -cleanup {
deleteWindows
} -result {}
test menuDraw-11.1 {TkMenuSelectImageProc - entry selected; redraw not pending} -constraints {
testImageType
} -setup {
deleteWindows
imageCleanup
} -body {
image create test image1
image create test image2
menu .m1
.m1 add checkbutton -image image1 -selectimage image2
.m1 invoke 1
set tearoff [tk::TearOffMenu .m1 40 40]
update idletasks
list [image delete image2] [destroy .m1]
} -cleanup {
imageCleanup
} -result {{} {}}
test menuDraw-11.2 {TkMenuSelectImageProc - entry selected; redraw pending} -constraints {
testImageType
} -setup {
deleteWindows
imageCleanup
} -body {
image create test image1
image create test image2
menu .m1
.m1 add checkbutton -image image1 -selectimage image2
.m1 invoke 1
set tearoff [tk::TearOffMenu .m1 40 40]
list [image delete image2] [destroy .m1]
} -cleanup {
imageCleanup
} -result {{} {}}
test menuDraw-11.3 {TkMenuSelectImageProc - entry not selected} -constraints {
testImageType
} -setup {
deleteWindows
imageCleanup
} -body {
image create test image1
image create test image2
menu .m1
.m1 add checkbutton -image image1 -selectimage image2
set tearoff [tk::TearOffMenu .m1 40 40]
update idletasks
list [image delete image2] [destroy .m1]
} -cleanup {
imageCleanup
} -result {{} {}}
#Don't know how to test missing tkwin in DisplayMenu
test menuDraw-12.1 {DisplayMenu - menubar background} -constraints unix -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label foo -menu .m2
. configure -menu .m1
list [update] [. configure -menu ""]
} -cleanup {
deleteWindows
} -result {{} {}}
test menuDraw-12.2 {Display menu - no entries} -setup {
deleteWindows
} -body {
menu .m1
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw-12.3 {DisplayMenu - one entry} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label foo
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw-12.4 {DisplayMenu - two entries} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "one"
.m1 add command -label "two"
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw.12.5 {DisplayMenu - two columns - first bigger} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "one"
.m1 add command -label "two"
.m1 add command -label "three" -columnbreak 1
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw-12.5 {DisplayMenu - two column - second bigger} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "one"
.m1 add command -label "two" -columnbreak 1
.m1 add command -label "three"
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw.12.7 {DisplayMenu - three columns} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "one"
.m1 add command -label "two" -columnbreak 1
.m1 add command -label "three"
.m1 add command -label "four"
.m1 add command -label "five"
.m1 add command -label "six"
set tearoff [tk::TearOffMenu .m1 40 40]
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw-12.6 {Display menu - testing for extra space and menubars} -constraints {
unix
} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label foo
. configure -menu .m1
update
. configure -menu ""
} -cleanup {
deleteWindows
} -result {}
test menuDraw-12.7 {Display menu - extra space at end of menu} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label foo
set tearoff [tk::TearOffMenu .m1 40 40]
wm geometry $tearoff 200x100
update
} -cleanup {
deleteWindows
} -result {}
test menuDraw-13.1 {TkMenuEventProc - Expose} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "one"
menu .m2
.m2 add command -label "two"
set tearoff1 [tk::TearOffMenu .m1 40 40]
set tearoff2 [tk::TearOffMenu .m2 40 40]
list [raise $tearoff2] [update]
} -cleanup {
deleteWindows
} -result {{} {}}
test menuDraw-13.2 {TkMenuEventProc - ConfigureNotify} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
set tearoff [tk::TearOffMenu .m1 40 40]
list [wm geometry $tearoff 200x100] [update]
} -cleanup {
deleteWindows
} -result {{} {}}
# Testing deletes is hard, and I am going to do my best. Don't know how
# to test the case where we have already cleared the tkwin field in the
# menuPtr.
test menuDraw-13.4 {TkMenuEventProc - simple delete} -setup {
deleteWindows
} -body {
menu .m1
destroy .m1
} -result {}
test menuDraw-13.5 {TkMenuEventProc - nothing pending} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label foo
update idletasks
destroy .m1
} -result {}
test menuDraw-14.1 {TkMenuImageProc} -constraints testImageType -setup {
deleteWindows
} -body {
catch {image delete image1}
menu .m1
image create test image1
.m1 add command -image image1
update idletasks
image delete image1
} -cleanup {
deleteWindows
} -result {}
test menuDraw-14.2 {TkMenuImageProc} -constraints testImageType -setup {
deleteWindows
} -body {
catch {image delete image1}
menu .m1
image create test image1
.m1 add command -image image1
image delete image1
} -cleanup {
deleteWindows
} -result {}
test menuDraw-15.1 {TkPostTearoffMenu - Basic posting} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
tk::TearOffMenu .m1 40 40
} -cleanup {
deleteWindows
} -returnCodes ok -match glob -result *
test menuDraw-15.2 {TkPostTearoffMenu - Deactivation} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo" -state active
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff index active
} -cleanup {
deleteWindows
} -result none
test menuDraw-15.3 {TkPostTearoffMenu - post command} -setup {
deleteWindows
} -body {
catch {unset foo}
menu .m1 -postcommand "set foo .m1"
.m1 add command -label "foo"
list [catch {tk::TearOffMenu .m1 40 40}] [set foo] [unset foo] [destroy .m1]
} -result {0 .m1 {} {}}
test menuDraw-15.4 {TkPostTearoffMenu - post command deleting the menu} -setup {
deleteWindows
} -body {
menu .m1 -postcommand "destroy .m1"
.m1 add command -label "foo"
list [catch {tk::TearOffMenu .m1 40 40} msg] $msg [winfo exists .m1]
} -result {0 {} 0}
test menuDraw-15.5 {TkPostTearoffMenu - tearoff at edge of screen} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
set height [winfo screenheight .m1]
tk::TearOffMenu .m1 40 $height
} -cleanup {
deleteWindows
} -returnCodes ok -match glob -result *
test menuDraw-15.6 {TkPostTearoffMenu - tearoff off right} -setup {
deleteWindows
} -body {
menu .m1
.m1 add command -label "foo"
set width [winfo screenwidth .m1]
tk::TearOffMenu .m1 $width 40
} -cleanup {
deleteWindows
} -returnCodes ok -match glob -result *
test menuDraw-16.1 {TkPostSubmenu} -constraints nonUnixUserInteraction -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test -menu .m2
menu .m2
.m2 add command -label "Hit ESCAPE to make this menu go away."
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade 0
$tearoff postcascade 0
} -cleanup {
deleteWindows
} -result {}
test menuDraw-16.2 {TkPostSubMenu} -constraints nonUnixUserInteraction -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label "two" -menu .m2
.m1 add cascade -label "three" -menu .m3
menu .m2
.m2 add command -label "two"
menu .m3
.m3 add command -label "three"
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade 0
$tearoff postcascade 1
} -cleanup {
deleteWindows
} -result {}
test menuDraw-16.3 {TkPostSubMenu} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test -menu .m2
.m1 postcascade 1
} -cleanup {
deleteWindows
} -result {}
test menuDraw-16.4 {TkPostSubMenu} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade 0
} -cleanup {
deleteWindows
} -result {}
test menuDraw-16.5 {TkPostSubMenu} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test -menu .m2
menu .m2 -postcommand "glorp"
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade test
} -cleanup {
deleteWindows
} -returnCodes error -result {invalid command name "glorp"}
test menuDraw-16.6 {TkPostSubMenu} -constraints {
win userInteraction
} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test -menu .m2
menu .m2
.m2 add command -label "Hit ESCAPE to get rid of this menu"
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade 0
} -cleanup {
deleteWindows
} -result {}
test menuDraw-17.1 {AdjustMenuCoords - menubar} -constraints unix -setup {
deleteWindows
} -body {
menu .m1 -tearoff 0
.m1 add cascade -label test -menu .m2
menu .m2 -tearoff 0
.m2 add command -label foo
. configure -menu .m1
foreach w [winfo children .] {
if {[$w cget -type] == "menubar"} {
break
}
}
list [$w postcascade 0] [. configure -menu ""]
} -cleanup {
deleteWindows
} -result {{} {}}
test menuDraw-17.2 {AdjustMenuCoords - menu} -constraints {
win userInteraction
} -setup {
deleteWindows
} -body {
menu .m1
.m1 add cascade -label test -menu .m2
menu .m2
.m2 add command -label "Hit ESCAPE to make this menu go away"
set tearoff [tk::TearOffMenu .m1 40 40]
$tearoff postcascade 0
} -cleanup {
deleteWindows
} -result {}
# cleanup
imageFinish
deleteWindows
cleanupTests
return
# Local variables:
# mode: tcl
# End:
|