summaryrefslogtreecommitdiff
path: root/tk/tests/macWinMenu.test
blob: 8e59d00ce57ca961e5f36fcd16ab56faa64d2a3d (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
# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests. It tests
# the common implementation of Macintosh and Windows menus.
#
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id$

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

if {[lsearch [image types] test] < 0} {
    puts "This application hasn't been compiled with the \"test\" image"
    puts "type, so I can't run this test.  Are you sure you're using"
    puts "tktest instead of wish?"
    ::tcltest::cleanupTests
    return
}

# Some tests require user interaction on non-unix platform
set ::tcltest::testConfig(nonUnixUserInteraction) \
    [expr {$::tcltest::testConfig(userInteraction) || \
	$::tcltest::testConfig(unixOnly)}]

proc deleteWindows {} {
    foreach i [winfo children .] {
    	catch [destroy $i]
    }
}

deleteWindows
wm geometry . {}
raise .

test macWinMenu-1.1 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
    catch {destroy .m1}
    menu .m1 -postcommand "destroy .m1"
    .m1 add command -label "macWinMenu-1.1: Hit Escape"
    list [catch {.m1 post 40 40} msg] $msg
} {0 {}}
test macWinMenu-1.2 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
    catch {destroy .m1}
    catch {destroy .m2}
    set foo1 foo
    set foo2 foo
    menu .m1 -postcommand "set foo1 .m1"
    .m1 add cascade -menu .m2 -label "macWinMenu-1.2: Hit Escape"
    menu .m2 -postcommand "set foo2 .m2"
    update idletasks
    list [catch {.m1 post 40 40} msg] $msg [set foo1] [set foo2] \
	    [destroy .m1 .m2] [catch {unset foo1}] [catch {unset foo2}]
} {0 .m2 .m1 .m2 {} 0 0}

test macWinMenu-1.3 {PreprocessMenu} {macOrPc nonUnixUserInteraction} {
    catch {destroy .l1}
    catch {destroy .m1}
    catch {destroy .m2}
    catch {destroy .m3}
    label .l1 -text "Preparing menus..."
    pack .l1
    update idletasks
    menu .m1 -postcommand ".l1 configure -text \"Destroying .m1...\"; update idletasks; destroy .m1"
    menu .m2 -postcommand ".l1 configure -text \"Destroying .m2...\"; update idletasks; destroy .m2"
    menu .m3 -postcommand ".l1 configure -text \"Destroying .m3...\"; update idletasks; destroy .m3"
    .m1 add cascade -menu .m2 -label "macWinMenu-1.3: Hit Escape (.m2)"
    .m1 add cascade -menu .m3 -label ".m3"
    update idletasks
    list [catch {.m1 post 40 40} msg] $msg [destroy .l1 .m2 .m3]
} {0 {} {}}
test macWinMenu-1.4 {PreprocessMenu} {macOrPc} {
    catch {destroy .l1}
    catch {destroy .m1}
    catch {destroy .m2}
    catch {destroy .m3}
    catch {destroy .m4}
    label .l1 -text "Preparing menus..."
    pack .l1
    update idletasks
    menu .m1 -postcommand ".l1 configure -text \"Destroying .m1...\"; update idletasks; destroy .m1"
    .m1 add cascade -menu .m2 -label "macWinMenu-1.4: Hit Escape (.m2)"
    .m1 add cascade -menu .m3 -label ".m3"
    menu .m2 -postcommand ".l1 configure -text \"Destroying .m2...\"; update idletasks; destroy .m2"
    .m2 add cascade -menu .m4 -label ".m4"
    menu .m3 -postcommand ".l1 configure -text \"Destroying .m3...\"; update idletasks; destroy .m3"
    menu .m4 -postcommand ".l1 configure -text \"Destroying .m4...\"; update idletasks; destroy .m4"
    update idletasks
    list [catch {.m1 post 40 40} msg] $msg [destroy .l1 .m2 .m3 .m4]
} {0 {} {}}
test macWinMenu-1.5 {PreprocessMenu} {macOrPc} {
    catch {destroy .m1}
    catch {destroy .m2}
    menu .m1
    .m1 add cascade -menu .m2 -label "You may need to hit Escape to get this menu to go away."
    menu .m2 -postcommand glorp
    list [catch {.m1 post 40 40} msg] $msg [destroy .m1 .m2]
} {1 {invalid command name "glorp"} {}}

test macWinMenu-2.1 {TkPreprocessMenu} {macOrPc nonUnixUserInteraction} {
    catch {destroy .m1}
    set foo test
    menu .m1 -postcommand "set foo 2.1"
    .m1 add command -label "macWinMenu-2.1: Hit Escape"
    list [catch {.m1 post 40 40} msg] $msg [set foo] [destroy .m1] [unset foo]
} {0 2.1 2.1 {} {}}

# cleanup
deleteWindows
::tcltest::cleanupTests
return