1
# This file is a Tcl script to test out Tk's "tk_messageBox" command.
2
# It is organized in the standard fashion for Tcl tests.
4
# Copyright (c) 1996 Sun Microsystems, Inc.
6
# See the file "license.terms" for information on usage and redistribution
7
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
# RCS: @(#) $Id: msgbox.test,v 1.2 1998/09/14 18:23:49 stanton Exp $
12
if {[string compare test [info procs test]] == 1} {
16
test msgbox-1.1 {tk_messageBox command} {
17
list [catch {tk_messageBox -foo} msg] $msg
18
} {1 {unknown option "-foo", must be -default, -icon, -message, -parent, -title or -type}}
19
test msgbox-1.2 {tk_messageBox command} {
20
list [catch {tk_messageBox -foo bar} msg] $msg
21
} {1 {unknown option "-foo", must be -default, -icon, -message, -parent, -title or -type}}
23
catch {tk_messageBox -foo bar} msg
24
regsub -all , $msg "" options
25
regsub \"-foo\" $options "" options
27
foreach option $options {
28
if {[string index $option 0] == "-"} {
29
test msgbox-1.3 {tk_messageBox command} {
30
list [catch {tk_messageBox $option} msg] $msg
31
} [list 1 "value for \"$option\" missing"]
35
test msgbox-1.4 {tk_messageBox command} {
36
list [catch {tk_messageBox -default} msg] $msg
37
} {1 {value for "-default" missing}}
39
test msgbox-1.5 {tk_messageBox command} {
40
list [catch {tk_messageBox -type foo} msg] $msg
41
} {1 {invalid message box type "foo", must be abortretryignore, ok, okcancel, retrycancel, yesno or yesnocancel}}
43
test msgbox-1.6 {tk_messageBox command} {
44
list [catch {tk_messageBox -default 1.1} msg] $msg
45
} {1 {invalid default button "1.1"}}
47
test msgbox-1.7 {tk_messageBox command} {
48
list [catch {tk_messageBox -default foo} msg] $msg
49
} {1 {invalid default button "foo"}}
51
test msgbox-1.8 {tk_messageBox command} {
52
list [catch {tk_messageBox -type yesno -default 3} msg] $msg
53
} {1 {invalid default button "3"}}
55
test msgbox-1.9 {tk_messageBox command} {
56
list [catch {tk_messageBox -icon foo} msg] $msg
57
} {1 {invalid icon "foo", must be error, info, question or warning}}
59
test msgbox-1.10 {tk_messageBox command} {
60
list [catch {tk_messageBox -parent foo.bar} msg] $msg
61
} {1 {bad window path name "foo.bar"}}
63
if {[info commands tkMessageBox] == ""} {
69
if {$isNative && ![info exists INTERACTIVE]} {
70
puts " Some tests were skipped because they could not be performed"
71
puts " automatically on this platform. If you wish to execute them"
72
puts " interactively, set the TCL variable INTERACTIVE and re-run"
77
proc ChooseMsg {parent btn} {
80
after 100 SendEventToMsg $parent $btn mouse
84
proc ChooseMsgByKey {parent btn} {
87
after 100 SendEventToMsg $parent $btn key
91
proc PressButton {btn} {
92
event generate $btn <Enter>
93
event generate $btn <ButtonPress-1> -x 5 -y 5
94
event generate $btn <ButtonRelease-1> -x 5 -y 5
97
proc SendEventToMsg {parent btn type} {
99
set w $parent.__tk__messagebox
101
set w .__tk__messagebox
103
if ![winfo ismapped $w.$btn] {
106
if {$type == "mouse"} {
109
event generate $w <Enter>
111
event generate $w.$btn <Enter>
112
event generate $w <KeyPress> -keysym Return
119
{"abortretryignore" MB_ABORTRETRYIGNORE 3 {"abort" "retry" "ignore"}}
120
{"ok" MB_OK 1 {"ok" }}
121
{"okcancel" MB_OKCANCEL 2 {"ok" "cancel" }}
122
{"retrycancel" MB_RETRYCANCEL 2 {"retry" "cancel" }}
123
{"yesno" MB_YESNO 2 {"yes" "no" }}
124
{"yesnocancel" MB_YESNOCANCEL 3 {"yes" "no" "cancel"}}
128
# Try out all combinations of (type) x (default button) and
131
foreach spec $specs {
132
set type [lindex $spec 0]
133
set buttons [lindex $spec 3]
135
set button [lindex $buttons 0]
136
test msgbox-2.1 {tk_messageBox command} {
137
ChooseMsg $parent $button
138
tk_messageBox -title Hi -message "Please press $button" \
142
foreach icon {warning error info question} {
143
test msgbox-2.2 {tk_messageBox command -icon option} {
144
ChooseMsg $parent $button
145
tk_messageBox -title Hi -message "Please press $button" \
146
-type $type -icon $icon
150
foreach button $buttons {
151
test msgbox-2.3 {tk_messageBox command} {
152
ChooseMsg $parent $button
153
tk_messageBox -title Hi -message "Please press $button" \
154
-type $type -default $button