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
|
# This file is a Tcl script to test the procedures in the file
# tkWindow.c. It is organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id: window.test,v 1.7.2.1 2004/02/13 01:43:05 hobbs Exp $
package require tcltest 2.1
namespace import -force tcltest::configure
namespace import -force tcltest::testsDirectory
namespace import -force tcltest::interpreter
namespace import -force tcltest::makeFile
namespace import -force tcltest::removeFile
configure -testdir [file join [pwd] [file dirname [info script]]]
configure -loadfile [file join [testsDirectory] constraints.tcl]
tcltest::loadTestedCommands
update
# XXX This file is woefully incomplete. Right now it only tests
# a few parts of a few procedures in tkWindow.c
test window-1.1 {Tk_CreateWindowFromPath procedure, parent dead} {
proc bgerror msg {
global x errorInfo
set x [list $msg $errorInfo]
}
set x unchanged
catch {destroy .t}
frame .t -width 100 -height 50
place .t -x 10 -y 10
bind .t <Destroy> {button .t.b -text hello; pack .t.b}
update
destroy .t
update
rename bgerror {}
set x
} {{can't create window: parent has been destroyed} {can't create window: parent has been destroyed
while executing
"button .t.b -text hello"
(command bound to event)}}
# Most of the tests below don't produce meaningful results; they
# will simply dump core if there are bugs.
test window-2.1 {Tk_DestroyWindow procedure, destroy handler deletes parent} {
toplevel .t -width 300 -height 200
wm geometry .t +0+0
frame .t.f -width 200 -height 200 -relief raised -bd 2
place .t.f -x 0 -y 0
frame .t.f.f -width 100 -height 100 -relief raised -bd 2
place .t.f.f -relx 1 -rely 1 -anchor se
bind .t.f <Destroy> {destroy .t}
update
destroy .t.f
} {}
test window-2.2 {Tk_DestroyWindow procedure, destroy handler deletes parent} {
toplevel .t -width 300 -height 200
wm geometry .t +0+0
frame .t.f -width 200 -height 200 -relief raised -bd 2
place .t.f -x 0 -y 0
frame .t.f.f -width 100 -height 100 -relief raised -bd 2
place .t.f.f -relx 1 -rely 1 -anchor se
bind .t.f.f <Destroy> {destroy .t}
update
destroy .t.f
} {}
test window-2.3 {Tk_DestroyWindow procedure, destroy handler deletes parent} {
frame .f -width 80 -height 120 -relief raised -bd 2
place .f -relx 0.5 -rely 0.5 -anchor center
toplevel .f.t -width 300 -height 200
wm geometry .f.t +0+0
frame .f.t.f -width 200 -height 200 -relief raised -bd 2
place .f.t.f -x 0 -y 0
frame .f.t.f.f -width 100 -height 100 -relief raised -bd 2
place .f.t.f.f -relx 1 -rely 1 -anchor se
update
destroy .f
} {}
test window-2.4 {Tk_DestroyWindow, cleanup half dead window at exit} \
unixOrWin {
set script [makeFile {
update
bind . <Destroy> exit
destroy .
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {}}
test window-2.5 {Tk_DestroyWindow, cleanup half dead windows at exit} \
unixOrWin {
set script [makeFile {
toplevel .t
update
bind .t <Destroy> exit
destroy .t
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {}}
test window-2.6 {Tk_DestroyWindow, cleanup half dead windows at exit} \
unixOrWin {
set script [makeFile {
toplevel .t
update
bind .t <Destroy> exit
destroy .
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {}}
test window-2.7 {Tk_DestroyWindow, cleanup half dead windows at exit} \
unixOrWin {
set script [makeFile {
toplevel .t
toplevel .t.f
update
bind .t.f <Destroy> exit
destroy .
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {}}
test window-2.8 {Tk_DestroyWindow, cleanup half dead windows at exit} \
unixOrWin {
set script [makeFile {
toplevel .t1
toplevel .t2
toplevel .t3
update
bind .t3 <Destroy> {destroy .t2}
bind .t2 <Destroy> {destroy .t1}
bind .t1 <Destroy> {exit 0}
destroy .t3
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {}}
test window-2.9 {Tk_DestroyWindow, Destroy bindings evaluated after exit} \
unixOrWin {
set script [makeFile {
toplevel .t1
toplevel .t2
update
bind .t2 <Destroy> {puts "Destroy .t2" ; exit 1}
bind .t1 <Destroy> {puts "Destroy .t1" ; exit 0}
destroy .t2
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {Destroy .t2
Destroy .t1}}
test window-2.10 {Tk_DestroyWindow, Destroy binding evaluated once} unixOrWin {
set script [makeFile {
update
bind . <Destroy> {
puts "Destroy ."
bind . <Destroy> {puts "Re-Destroy ."}
exit 0
}
destroy .
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 {Destroy .}}
test window-2.11 {Tk_DestroyWindow, don't reanimate a half-dead window} \
unixOrWin {
set script [makeFile {
toplevel .t1
toplevel .t2
update
bind .t1 <Destroy> {
if {[catch {entry .t2.newchild}]} {
puts YES
} else {
puts NO
}
}
bind .t2 <Destroy> {exit}
destroy .t2
} script]
set error [catch {exec [interpreter] $script -geometry 10x10+0+0} msg]
removeFile script
list $error $msg
} {0 YES}
# Some tests require the testmenubar command
testConstraint testmenubar [llength [info commands testmenubar]]
test window-3.1 {Tk_MakeWindowExist procedure, stacking order and menubars} \
{unixOnly testmenubar} {
catch {destroy .t}
toplevel .t -width 300 -height 200
wm geometry .t +0+0
pack [entry .t.e]
frame .t.f -bd 2 -relief raised
testmenubar window .t .t.f
update
# If stacking order isn't handle properly, generates an X error.
} {}
test window-3.2 {Tk_MakeWindowExist procedure, stacking order and menubars} \
{unixOnly testmenubar} {
catch {destroy .t}
toplevel .t -width 300 -height 200
wm geometry .t +0+0
pack [entry .t.e]
pack [entry .t.e2]
update
frame .t.f -bd 2 -relief raised
raise .t.f .t.e
testmenubar window .t .t.f
update
# If stacking order isn't handled properly, generates an X error.
} {}
test window-4.1 {Tk_NameToWindow procedure} {testmenubar} {
catch {destroy .t}
list [catch {winfo geometry .t} msg] $msg
} {1 {bad window path name ".t"}}
test window-4.2 {Tk_NameToWindow procedure} {testmenubar} {
catch {destroy .t}
frame .t -width 100 -height 50
place .t -x 10 -y 10
update
list [catch {winfo geometry .t} msg] $msg
} {0 100x50+10+10}
test window-5.1 {Tk_MakeWindowExist procedure, stacking order and menubars} \
{unixOnly testmenubar} {
catch {destroy .t}
toplevel .t -width 300 -height 200
wm geometry .t +0+0
pack [entry .t.e]
pack [entry .t.e2]
frame .t.f -bd 2 -relief raised
testmenubar window .t .t.f
update
lower .t.e2 .t.f
update
# If stacking order isn't handled properly, generates an X error.
} {}
# cleanup
::tcltest::cleanupTests
return
|