1 # This file is a Tcl script to test out Tk's "tk_chooseDir" and
2 # It is organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1996 Sun Microsystems, Inc.
5 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 package require tcltest 2.1
12 namespace import -force tcltest::configure
13 namespace import -force tcltest::testsDirectory
14 configure -testdir [file join [pwd] [file dirname [info script]]]
15 configure -loadfile [file join [testsDirectory] constraints.tcl]
16 tcltest::loadTestedCommands
18 namespace import -force tcltest::makeDirectory
20 #----------------------------------------------------------------------
22 # Procedures needed by this test file
24 #----------------------------------------------------------------------
26 proc ToPressButton {parent btn} {
27 after 100 SendButtonPress $parent $btn mouse
30 proc ToEnterDirsByKey {parent dirs} {
31 after 100 [list EnterDirsByKey $parent $dirs]
34 proc PressButton {btn} {
35 event generate $btn <Enter>
36 event generate $btn <1> -x 5 -y 5
37 event generate $btn <ButtonRelease-1> -x 5 -y 5
40 proc EnterDirsByKey {parent dirs} {
45 set w $parent.__tk_choosedir
47 upvar ::tk::dialog::file::__tk_choosedir data
50 $data(ent) delete 0 end
51 $data(ent) insert 0 $dir
53 SendButtonPress $parent ok mouse
58 proc SendButtonPress {parent btn type} {
63 set w $parent.__tk_choosedir
65 upvar ::tk::dialog::file::__tk_choosedir data
67 set button $data($btn\Btn)
68 if ![winfo ismapped $button] {
72 if {$type == "mouse"} {
75 event generate $w <Enter>
77 event generate $button <Enter>
78 event generate $w <KeyPress> -keysym Return
83 #----------------------------------------------------------------------
85 # The test suite proper
87 #----------------------------------------------------------------------
88 # Make a dir for us to rely on for tests
89 makeDirectory choosedirTest
91 set fake [file join $dir non-existant]
92 set real [file join $dir choosedirTest]
96 foreach opt {-initialdir -mustexist -parent -title} {
97 test choosedir-1.1 "tk_chooseDirectory command" unixOnly {
98 list [catch {tk_chooseDirectory $opt} msg] $msg
99 } [list 1 "value for \"$opt\" missing"]
101 test choosedir-1.2 "tk_chooseDirectory command" unixOnly {
102 list [catch {tk_chooseDirectory -foo bar} msg] $msg
103 } [list 1 "bad option \"-foo\": must be -initialdir, -mustexist, -parent, or -title"]
104 test choosedir-1.3 "tk_chooseDirectory command" unixOnly {
105 list [catch {tk_chooseDirectory -parent foo.bar} msg] $msg
106 } {1 {bad window path name "foo.bar"}}
109 test choosedir-2.1 "tk_chooseDirectory command, cancel gives null" {unixOnly} {
110 ToPressButton $parent cancel
111 tk_chooseDirectory -title "Press Cancel" -parent $parent
114 test choosedir-3.1 "tk_chooseDirectory -mustexist 1" {unixOnly} {
115 # first enter a bogus dirname, then enter a real one.
116 ToEnterDirsByKey $parent [list $fake $real $real]
117 set result [tk_chooseDirectory \
118 -title "Enter \"$fake\", press OK, enter \"$real\", press OK" \
119 -parent $parent -mustexist 1]
122 test choosedir-3.2 "tk_chooseDirectory -mustexist 0" {unixOnly} {
123 ToEnterDirsByKey $parent [list $fake $fake]
124 tk_chooseDirectory -title "Enter \"$fake\", press OK" \
125 -parent $parent -mustexist 0
128 test choosedir-4.1 "tk_chooseDirectory command, initialdir" {unixOnly} {
129 ToPressButton $parent ok
130 tk_chooseDirectory -title "Press Ok" -parent $parent -initialdir $real
132 test choosedir-4.2 "tk_chooseDirectory command, initialdir" {unixOnly} {
133 ToEnterDirsByKey $parent [list $fake $fake]
135 -title "Enter \"$fake\" and press Ok" \
136 -parent $parent -initialdir $real
138 test choosedir-4.3 "tk_chooseDirectory, -initialdir {}" {unixOnly} {
139 catch {unset ::tk::dialog::file::__tk_choosedir}
140 ToPressButton $parent ok
143 -parent $parent -initialdir ""
146 test choosedir-5.1 "tk_chooseDirectory, handles {} entry text" {unixOnly} {
147 ToEnterDirsByKey $parent [list "" $real $real]
148 tk_chooseDirectory -title "Clear entry, Press OK; Enter $real, press OK" \
153 ::tcltest::cleanupTests