1# This file is a Tcl script to test out Tk's "tk_dialog" command.
2# It is organized in the standard fashion for Tcl tests.
3#
4# RCS: @(#) $Id: dialog.test,v 1.3 2002/07/14 05:48:46 dgp Exp $
5#
6
7package require tcltest 2.1
8namespace import -force tcltest::configure
9namespace import -force tcltest::testsDirectory
10configure -testdir [file join [pwd] [file dirname [info script]]]
11configure -loadfile [file join [testsDirectory] constraints.tcl]
12tcltest::loadTestedCommands
13
14test dialog-1.1 {tk_dialog command} {
15    list [catch {tk_dialog} msg] $msg
16} {1 {wrong # args: should be "tk_dialog w title text bitmap default args"}}
17test dialog-1.2 {tk_dialog command} {
18    list [catch {tk_dialog foo foo foo foo foo} msg] $msg
19} {1 {bad window path name "foo"}}
20test dialog-1.3 {tk_dialog command} {
21    set res [list [catch {tk_dialog .d foo foo foo foo} msg] $msg]
22    destroy .d
23    set res
24} {1 {bitmap "foo" not defined}}
25
26proc PressButton {btn} {
27    if {![winfo ismapped $btn]} {
28	update
29    }
30    event generate $btn <Enter>
31    event generate $btn <1> -x 5 -y 5
32    event generate $btn <ButtonRelease-1> -x 5 -y 5
33}
34
35proc HitReturn {w} {
36    event generate $w <Enter>
37    focus -force $w
38    event generate $w <KeyPress> -keysym Return
39}
40
41test dialog-2.0 {tk_dialog operation} {
42    set x [after 5000 [list set tk::Priv(button) "no response"]]
43    after 100 PressButton .d.button0
44    set res [tk_dialog .d foo foo info 0 click]
45    after cancel $x
46    set res
47} {0}
48test dialog-2.1 {tk_dialog operation} {
49    set x [after 5000 [list set tk::Priv(button) "no response"]]
50    after 100 HitReturn .d
51    set res [tk_dialog .d foo foo info 1 click default]
52    after cancel $x
53    set res
54} {1}
55test dialog-2.2 {tk_dialog operation} {
56    set x [after 5000 [list set tk::Priv(button) "no response"]]
57    after 100 destroy .d
58    set res [tk_dialog .d foo foo info 0 click]
59    after cancel $x
60    set res
61} {-1}
62
63tcltest::cleanupTests
64return
65