1 # This file is a Tcl script to test menus in Tk. It is
2 # organized in the standard fashion for Tcl tests. It tests
3 # the common implementation of Macintosh and Windows menus.
5 # Copyright (c) 1995-1996 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 if {[lsearch [namespace children] ::tcltest] == -1} {
12 source [file join [pwd] [file dirname [info script]] defs.tcl]
15 if {[lsearch [image types] test] < 0} {
16 puts "This application hasn't been compiled with the \"test\" image"
17 puts "type, so I can't run this test. Are you sure you're using"
18 puts "tktest instead of wish?"
19 ::tcltest::cleanupTests
23 # Some tests require user interaction on non-unix platform
24 set ::tcltest::testConfig(nonUnixUserInteraction) \
25 [expr {$::tcltest::testConfig(userInteraction) || \
26 $::tcltest::testConfig(unixOnly)}]
28 proc deleteWindows {} {
29 foreach i [winfo children .] {
38 test macWinMenu-1.1 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
40 menu .m1 -postcommand "destroy .m1"
41 .m1 add command -label "macWinMenu-1.1: Hit Escape"
42 list [catch {.m1 post 40 40} msg] $msg
44 test macWinMenu-1.2 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
49 menu .m1 -postcommand "set foo1 .m1"
50 .m1 add cascade -menu .m2 -label "macWinMenu-1.2: Hit Escape"
51 menu .m2 -postcommand "set foo2 .m2"
53 list [catch {.m1 post 40 40} msg] $msg [set foo1] [set foo2] \
54 [destroy .m1 .m2] [catch {unset foo1}] [catch {unset foo2}]
55 } {0 .m2 .m1 .m2 {} 0 0}
57 test macWinMenu-1.3 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
62 label .l1 -text "Preparing menus..."
65 menu .m1 -postcommand ".l1 configure -text \"Destroying .m1...\"; update idletasks; destroy .m1"
66 menu .m2 -postcommand ".l1 configure -text \"Destroying .m2...\"; update idletasks; destroy .m2"
67 menu .m3 -postcommand ".l1 configure -text \"Destroying .m3...\"; update idletasks; destroy .m3"
68 .m1 add cascade -menu .m2 -label "macWinMenu-1.3: Hit Escape (.m2)"
69 .m1 add cascade -menu .m3 -label ".m3"
71 list [catch {.m1 post 40 40} msg] $msg [destroy .l1 .m2 .m3]
73 test macWinMenu-1.4 {PreprocessMenu} {macOrPc} {
79 label .l1 -text "Preparing menus..."
82 menu .m1 -postcommand ".l1 configure -text \"Destroying .m1...\"; update idletasks; destroy .m1"
83 .m1 add cascade -menu .m2 -label "macWinMenu-1.4: Hit Escape (.m2)"
84 .m1 add cascade -menu .m3 -label ".m3"
85 menu .m2 -postcommand ".l1 configure -text \"Destroying .m2...\"; update idletasks; destroy .m2"
86 .m2 add cascade -menu .m4 -label ".m4"
87 menu .m3 -postcommand ".l1 configure -text \"Destroying .m3...\"; update idletasks; destroy .m3"
88 menu .m4 -postcommand ".l1 configure -text \"Destroying .m4...\"; update idletasks; destroy .m4"
90 list [catch {.m1 post 40 40} msg] $msg [destroy .l1 .m2 .m3 .m4]
92 test macWinMenu-1.5 {PreprocessMenu} {macOrPc} {
96 .m1 add cascade -menu .m2 -label "You may need to hit Escape to get this menu to go away."
97 menu .m2 -postcommand glorp
98 list [catch {.m1 post 40 40} msg] $msg [destroy .m1 .m2]
99 } {1 {invalid command name "glorp"} {}}
101 test macWinMenu-2.1 {TkPreprocessMenu} {macOrPc nonUnixUserInteraction} {
104 menu .m1 -postcommand "set foo 2.1"
105 .m1 add command -label "macWinMenu-2.1: Hit Escape"
106 list [catch {.m1 post 40 40} msg] $msg [set foo] [destroy .m1] [unset foo]
111 ::tcltest::cleanupTests