summaryrefslogtreecommitdiffstats
path: root/tests/winDialog.test
blob: 9f49f2874ff24d0fc816c0610186722dbbb270a2 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# This file is a Tcl script to test the Windows specific behavior of
# the common dialog boxes.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 1998-1999 ActiveState Corporation.
#
# RCS: @(#) $Id: winDialog.test,v 1.9 2002/07/13 20:28:36 dgp Exp $

package require tcltest 2.1
namespace import -force tcltest::configure
namespace import -force tcltest::testsDirectory
configure -testdir [file join [pwd] [file dirname [info script]]]
configure -loadfile [file join [testsDirectory] constraints.tcl]
tcltest::loadTestedCommands

testConstraint testwinevent [llength [info commands testwinevent]]

catch {testwinevent debug 1}

proc start {arg} {
    set ::tk_dialog 0
    set ::iter_after 0

    after 1 $arg
}

proc then {cmd} {
    set ::command $cmd
    set ::dialogresult {}

    afterbody
    vwait ::dialogresult
    return $::dialogresult
}

proc afterbody {} {
    if {$::tk_dialog == 0} {
	if {[incr ::iter_after] > 30} {
	    set ::dialogresult ">30 iterations waiting on tk_dialog"
	    return
	}
	after 150 {afterbody}
	return
    }
    uplevel #0 {set dialogresult [eval $command]}
}

proc Click {button} {
    testwinevent $::tk_dialog $button WM_LBUTTONDOWN 1 0x000a000b
    testwinevent $::tk_dialog $button WM_LBUTTONUP 0 0x000a000b
}

proc GetText {button} {
    return [testwinevent $::tk_dialog $button WM_GETTEXT]
}

proc SetText {button text} {
    return [testwinevent $::tk_dialog $button WM_SETTEXT $text]
}

test winDialog-1.1 {Tk_ChooseColorObjCmd} {nt} {
} {}

test winDialog-2.1 {ColorDlgHookProc} {nt} {
} {}

test winDialog-3.1 {Tk_GetOpenFileObjCmd} {nt testwinevent} {
    start {tk_getOpenFile}
    then {
	set x [GetText 2]
	Click 2
    }
    set x
} {Cancel}

test winDialog-4.1 {Tk_GetSaveFileObjCmd} {nt testwinevent} {
    start {tk_getSaveFile}
    then {
	set x [GetText 2]
	Click 2
    }
    set x
} {Cancel}

test winDialog-5.1 {GetFileName: no arguments} {nt testwinevent} {
    start {tk_getOpenFile -title Open}
    then {
	Click cancel
    }
} {0}
test winDialog-5.2 {GetFileName: one argument} {nt} {
    list [catch {tk_getOpenFile -foo} msg] $msg
} {1 {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, or -title}}
test winDialog-5.4 {GetFileName: many arguments} {nt testwinevent} {
    start {tk_getOpenFile -initialdir c:/ -parent . -title test -initialfile foo}
    then {
	Click cancel
    }
} {0}
test winDialog-5.5 {GetFileName: Tcl_GetIndexFromObj() != TCL_OK} {nt} {
    list [catch {tk_getOpenFile -foo bar -abc} msg] $msg
} {1 {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, or -title}}
test winDialog-5.6 {GetFileName: Tcl_GetIndexFromObj() == TCL_OK} {nt testwinevent} {
    start {tk_getOpenFile -title bar}
    then {
	Click cancel
    }
} {0}
test winDialog-5.7 {GetFileName: valid option, but missing value} {nt} {
    list [catch {tk_getOpenFile -initialdir bar -title} msg] $msg
} {1 {value for "-title" missing}}
test winDialog-5.8 {GetFileName: extension begins with .} {nt testwinevent} {
#    if (string[0] == '.') {
#	string++;
#    }

    start {set x [tk_getSaveFile -defaultextension .foo -title Save]}
    then {
	SetText 0x480 bar
	Click 1
    }
    string totitle $x
} [string totitle [file join [pwd] bar.foo]]
test winDialog-5.9 {GetFileName: extension doesn't begin with .} {nt testwinevent} {
    start {set x [tk_getSaveFile -defaultextension foo -title Save]}
    then {
	SetText 0x480 bar
	Click 1
    }
    string totitle $x
} [string totitle [file join [pwd] bar.foo]]
test winDialog-5.10 {GetFileName: file types} {nt testwinevent} {
#	    case FILE_TYPES: 

    start {tk_getSaveFile -filetypes {{"foo files" .foo FOOF}} -title Foo}
    then {
	set x [GetText 0x470]
	Click cancel
    }
    set x
} {foo files (*.foo)}
test winDialog-5.11 {GetFileName: file types: MakeFilter() fails} {nt} {
#		if (MakeFilter(interp, string, &utfFilterString) != TCL_OK) 

    list [catch {tk_getSaveFile -filetypes {{"foo" .foo FOO}}} msg] $msg
} {1 {bad Macintosh file type "FOO"}}
test winDialog-5.12 {GetFileName: initial directory} {nt testwinevent} {
#	    case FILE_INITDIR: 

    start {set x [tk_getSaveFile -initialdir c:/ -initialfile "12x 455" -title Foo]}
    then {
	Click 1
    }
    set x
} {C:/12x 455}
test winDialog-5.13 {GetFileName: initial directory: Tcl_TranslateFilename()} \
	{nt} {
#		if (Tcl_TranslateFileName(interp, string, &ds) == NULL) 
    
    list [catch {tk_getOpenFile -initialdir ~12x/455} msg] $msg
} {1 {user "12x" doesn't exist}}
test winDialog-5.14 {GetFileName: initial file} {nt testwinevent} {
#	    case FILE_INITFILE: 

    start {set x [tk_getSaveFile -initialfile "12x 456" -title Foo]}
    then {
	Click 1
    }
    string totitle $x
} [string totitle [file join [pwd] "12x 456"]]
test winDialog-5.15 {GetFileName: initial file: Tcl_TranslateFileName()} {nt} {
#		if (Tcl_TranslateFileName(interp, string, &ds) == NULL) 
    list [catch {tk_getOpenFile -initialfile ~12x/455} msg] $msg
} {1 {user "12x" doesn't exist}}
set a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
append a $a
append a $a
append a $a
append a $a
test winDialog-5.16 {GetFileName: initial file: long name} {nt testwinevent} {
    start {set x [tk_getSaveFile -initialfile $a -title Long]}
    then {
	Click 1
    }
    string totitle $x
} [string totitle [string range [file join [pwd] $a] 0 257]]
test winDialog-5.17 {GetFileName: parent} {nt} {
#	    case FILE_PARENT: 

    toplevel .t
    set x 0
    start {tk_getOpenFile -parent .t -title Parent; set x 1}
    then {
	destroy .t
    }
    set x
} {1}
test winDialog-5.18 {GetFileName: title} {nt testwinevent} {
#	    case FILE_TITLE: 
    
    start {tk_getOpenFile -title Narf}
    then {
	Click 2
    }
} {0}
test winDialog-5.19 {GetFileName: no filter specified} {nt testwinevent} {
#    if (ofn.lpstrFilter == NULL) 

    start {tk_getOpenFile -title Filter} 
    then {
	set x [GetText 0x470]
	Click 2
    }
    set x
} {All Files (*.*)}
test winDialog-5.20 {GetFileName: parent HWND doesn't yet exist} {nt} {
#    if (Tk_WindowId(parent) == None) 

    toplevel .t
    start {tk_getOpenFile -parent .t -title Open}
    then {
	destroy .t
    }
} {}
test winDialog-5.21 {GetFileName: parent HWND already exists} {nt} {
    toplevel .t
    update
    start {tk_getOpenFile -parent .t -title Open}
    then {
	destroy .t
    }
} {}
test winDialog-5.22 {GetFileName: call GetOpenFileName} {nt testwinevent} {
#	    winCode = GetOpenFileName(&ofn);
    
    start {tk_getOpenFile -title Open}
    then {
	set x [GetText 1]
	Click 2
    }
    set x
} {&Open}
test winDialog-5.23 {GetFileName: call GetSaveFileName} {nt testwinevent} {
#	    winCode = GetSaveFileName(&ofn);

    start {tk_getSaveFile -title Save}
    then {
	set x [GetText 1]
	Click 2
    }
    set x
} {&Save}
test winDialog-5.24 {GetFileName: convert \ to /} {nt testwinevent} {
    start {set x [tk_getSaveFile -title Back]}
    then {
	SetText 0x480 "c:\\12x 457"
	Click 1
    }
    set x
} {c:/12x 457}

test winDialog-6.1 {MakeFilter} {emptyTest nt} {} {}

test winDialog-7.1 {Tk_MessageBoxObjCmd} {emptyTest nt} {} {}

test winDialog-8.1 {OFNHookProc} {emptyTest nt} {} {}

## The Tk_ChooseDirectoryObjCmd hang on the static build of Windows
## because somehow the GetOpenFileName ends up a noop in the static
## build.
##
test winDialog-9.1 {Tk_ChooseDirectoryObjCmd: no arguments} {nt testwinevent} {
    start {tk_chooseDirectory}
    then {
	Click cancel
    }
} {0}
test winDialog-9.2 {Tk_ChooseDirectoryObjCmd: one argument} {nt} {
    list [catch {tk_chooseDirectory -foo} msg] $msg
} {1 {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}}
test winDialog-9.3 {Tk_ChooseDirectoryObjCmd: many arguments} {nt testwinevent} {
    start {
	tk_chooseDirectory -initialdir c:/ -mustexist 1 -parent . -title test
    }
    then {
	Click cancel
    }
} {0}
test winDialog-9.4 {Tk_ChooseDirectoryObjCmd:\
	Tcl_GetIndexFromObj() != TCL_OK} {nt} {
    list [catch {tk_chooseDirectory -foo bar -abc} msg] $msg
} {1 {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}}
test winDialog-9.5 {Tk_ChooseDirectoryObjCmd:\
	Tcl_GetIndexFromObj() == TCL_OK} {nt testwinevent} {
    start {tk_chooseDirectory -title bar}
    then {
	Click cancel
    }
} {0}
test winDialog-9.6 {Tk_ChooseDirectoryObjCmd:\
	valid option, but missing value} {nt} {
    list [catch {tk_chooseDirectory -initialdir bar -title} msg] $msg
} {1 {value for "-title" missing}}
test winDialog-9.7 {Tk_ChooseDirectoryObjCmd: -initialdir} {nt testwinevent} {
#	    case DIR_INITIAL: 

    start {set x [tk_chooseDirectory -initialdir c:/ -title Foo]}
    then {
	Click 1
    }
    string tolower [set x]
} {c:/}
test winDialog-9.8 {Tk_ChooseDirectoryObjCmd:\
	initial directory: Tcl_TranslateFilename()} {nt} {
#		if (Tcl_TranslateFileName(interp, string, 
#			&utfDirString) == NULL) 
    
    list [catch {tk_chooseDirectory -initialdir ~12x/455} msg] $msg
} {1 {user "12x" doesn't exist}}

catch {testwinevent debug 0}

# cleanup
::tcltest::cleanupTests
return