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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
# This file is a Tcl script to test out the "winfo" command. It is
# organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands
# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w - Name of toplevel window to create.
# options - Options for w, such as "-colormap new".
proc eatColors {w {options ""}} {
catch {destroy $w}
eval toplevel $w $options
wm geom $w +0+0
canvas $w.c -width 400 -height 200 -bd 0
pack $w.c
for {set y 0} {$y < 8} {incr y} {
for {set x 0} {$x < 40} {incr x} {
set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
$w.c create rectangle [expr 10*$x] [expr 20*$y] \
[expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
-fill $color
}
}
update
}
# XXX - This test file is woefully incomplete. At present, only a
# few of the winfo options are tested.
test winfo-1.1 {"winfo atom" command} {
list [catch {winfo atom} msg] $msg
} {1 {wrong # args: should be "winfo atom ?-displayof window? name"}}
test winfo-1.2 {"winfo atom" command} {
list [catch {winfo atom a b} msg] $msg
} {1 {wrong # args: should be "winfo atom ?-displayof window? name"}}
test winfo-1.3 {"winfo atom" command} {
list [catch {winfo atom a b c d} msg] $msg
} {1 {wrong # args: should be "winfo atom ?-displayof window? name"}}
test winfo-1.4 {"winfo atom" command} {
list [catch {winfo atom -displayof geek foo} msg] $msg
} {1 {bad window path name "geek"}}
test winfo-1.5 {"winfo atom" command} {
winfo atom PRIMARY
} 1
test winfo-1.6 {"winfo atom" command} {
winfo atom -displayof . PRIMARY
} 1
test winfo-2.1 {"winfo atomname" command} {
list [catch {winfo atomname} msg] $msg
} {1 {wrong # args: should be "winfo atomname ?-displayof window? id"}}
test winfo-2.2 {"winfo atomname" command} {
list [catch {winfo atomname a b} msg] $msg
} {1 {wrong # args: should be "winfo atomname ?-displayof window? id"}}
test winfo-2.3 {"winfo atomname" command} {
list [catch {winfo atomname a b c d} msg] $msg
} {1 {wrong # args: should be "winfo atomname ?-displayof window? id"}}
test winfo-2.4 {"winfo atomname" command} {
list [catch {winfo atomname -displayof geek foo} msg] $msg
} {1 {bad window path name "geek"}}
test winfo-2.5 {"winfo atomname" command} {
list [catch {winfo atomname 44215} msg] $msg
} {1 {no atom exists with id "44215"}}
test winfo-2.6 {"winfo atomname" command} {
winfo atomname 2
} SECONDARY
test winfo-2.7 {"winfo atom" command} {
winfo atomname -displayof . 2
} SECONDARY
test winfo-3.1 {"winfo colormapfull" command} defaultPseudocolor8 {
list [catch {winfo colormapfull} msg] $msg
} {1 {wrong # args: should be "winfo colormapfull window"}}
test winfo-3.2 {"winfo colormapfull" command} defaultPseudocolor8 {
list [catch {winfo colormapfull a b} msg] $msg
} {1 {wrong # args: should be "winfo colormapfull window"}}
test winfo-3.3 {"winfo colormapfull" command} defaultPseudocolor8 {
list [catch {winfo colormapfull foo} msg] $msg
} {1 {bad window path name "foo"}}
test winfo-3.4 {"winfo colormapfull" command} {unix defaultPseudocolor8} {
eatColors .t {-colormap new}
set result [list [winfo colormapfull .] [winfo colormapfull .t]]
.t.c delete 34
lappend result [winfo colormapfull .t]
.t.c create rectangle 30 30 80 80 -fill #441739
lappend result [winfo colormapfull .t]
.t.c create rectangle 40 40 90 90 -fill #ffeedd
lappend result [winfo colormapfull .t]
destroy .t.c
lappend result [winfo colormapfull .t]
} {0 1 0 0 1 0}
catch {destroy .t}
toplevel .t -width 550 -height 400
frame .t.f -width 80 -height 60 -bd 2 -relief raised
place .t.f -x 50 -y 50
wm geom .t +0+0
update
test winfo-4.1 {"winfo containing" command} {
list [catch {winfo containing 22} msg] $msg
} {1 {wrong # args: should be "winfo containing ?-displayof window? rootX rootY"}}
test winfo-4.2 {"winfo containing" command} {
list [catch {winfo containing a b c} msg] $msg
} {1 {wrong # args: should be "winfo containing ?-displayof window? rootX rootY"}}
test winfo-4.3 {"winfo containing" command} {
list [catch {winfo containing a b c d e} msg] $msg
} {1 {wrong # args: should be "winfo containing ?-displayof window? rootX rootY"}}
test winfo-4.4 {"winfo containing" command} {
list [catch {winfo containing -displayof geek 25 30} msg] $msg
} {1 {bad window path name "geek"}}
test winfo-4.5 {"winfo containing" command} {
raise .t
winfo containing [winfo rootx .t.f] [winfo rooty .t.f]
} .t.f
test winfo-4.6 {"winfo containing" command} {nonPortable} {
winfo containing [expr [winfo rootx .t.f]-1] [expr [winfo rooty .t.f]-1]
} .t
test winfo-4.7 {"winfo containing" command} {
set x [winfo containing -display .t.f [expr [winfo rootx .t]+600] \
[expr [winfo rooty .t.f]+450]]
expr {($x == ".") || ($x == "")}
} {1}
destroy .t
test winfo-5.1 {"winfo interps" command} {
list [catch {winfo interps a} msg] $msg
} {1 {wrong # args: should be "winfo interps ?-displayof window?"}}
test winfo-5.2 {"winfo interps" command} {
list [catch {winfo interps a b c} msg] $msg
} {1 {wrong # args: should be "winfo interps ?-displayof window?"}}
test winfo-5.3 {"winfo interps" command} {
list [catch {winfo interps -displayof geek} msg] $msg
} {1 {bad window path name "geek"}}
test winfo-5.4 {"winfo interps" command} unix {
expr [lsearch -exact [winfo interps] [tk appname]] >= 0
} {1}
test winfo-5.5 {"winfo interps" command} unix {
expr [lsearch -exact [winfo interps -displayof .] [tk appname]] >= 0
} {1}
test winfo-6.1 {"winfo exists" command} {
list [catch {winfo exists} msg] $msg
} {1 {wrong # args: should be "winfo exists window"}}
test winfo-6.2 {"winfo exists" command} {
list [catch {winfo exists a b} msg] $msg
} {1 {wrong # args: should be "winfo exists window"}}
test winfo-6.3 {"winfo exists" command} {
winfo exists gorp
} {0}
test winfo-6.4 {"winfo exists" command} {
winfo exists .
} {1}
test winfo-6.5 {"winfo exists" command} {
button .b -text "Test button"
set x [winfo exists .b]
pack .b
update
bind .b <Destroy> {lappend x [winfo exists .x]}
destroy .b
lappend x [winfo exists .x]
} {1 0 0}
catch {destroy .b}
button .b -text "Help"
update
test winfo-7.1 {"winfo pathname" command} {
list [catch {winfo pathname} msg] $msg
} {1 {wrong # args: should be "winfo pathname ?-displayof window? id"}}
test winfo-7.2 {"winfo pathname" command} {
list [catch {winfo pathname a b} msg] $msg
} {1 {wrong # args: should be "winfo pathname ?-displayof window? id"}}
test winfo-7.3 {"winfo pathname" command} {
list [catch {winfo pathname a b c d} msg] $msg
} {1 {wrong # args: should be "winfo pathname ?-displayof window? id"}}
test winfo-7.4 {"winfo pathname" command} {
list [catch {winfo pathname -displayof geek 25} msg] $msg
} {1 {bad window path name "geek"}}
test winfo-7.5 {"winfo pathname" command} {
list [catch {winfo pathname xyz} msg] $msg
} {1 {expected integer but got "xyz"}}
test winfo-7.6 {"winfo pathname" command} {
list [catch {winfo pathname 224} msg] $msg
} {1 {window id "224" doesn't exist in this application}}
test winfo-7.7 {"winfo pathname" command} {
winfo pathname -displayof .b [winfo id .]
} {.}
test winfo-7.8 {"winfo pathname" command} {unix testwrapper} {
winfo pathname [testwrapper .]
} {}
test winfo-8.1 {"winfo pointerx" command} {
catch [winfo pointerx .b]
} 1
test winfo-8.2 {"winfo pointery" command} {
catch [winfo pointery .b]
} 1
test winfo-8.3 {"winfo pointerxy" command} {
catch [winfo pointerxy .b]
} 1
test winfo-9.1 {"winfo viewable" command} {
list [catch {winfo viewable} msg] $msg
} {1 {wrong # args: should be "winfo viewable window"}}
test winfo-9.2 {"winfo viewable" command} {
list [catch {winfo viewable foo} msg] $msg
} {1 {bad window path name "foo"}}
test winfo-9.3 {"winfo viewable" command} {
winfo viewable .
} {1}
test winfo-9.4 {"winfo viewable" command} {
wm iconify .
winfo viewable .
} {0}
wm deiconify .
test winfo-9.5 {"winfo viewable" command} {
frame .f1 -width 100 -height 100 -relief raised -bd 2
place .f1 -x 0 -y 0
frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
place .f1.f2 -x 0 -y 0
update
list [winfo viewable .f1] [winfo viewable .f1.f2]
} {1 1}
test winfo-9.6 {"winfo viewable" command} {
deleteWindows
frame .f1 -width 100 -height 100 -relief raised -bd 2
frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
place .f1.f2 -x 0 -y 0
update
list [winfo viewable .f1] [winfo viewable .f1.f2]
} {0 0}
test winfo-9.7 {"winfo viewable" command} {
deleteWindows
frame .f1 -width 100 -height 100 -relief raised -bd 2
place .f1 -x 0 -y 0
frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
place .f1.f2 -x 0 -y 0
update
wm iconify .
list [winfo viewable .f1] [winfo viewable .f1.f2]
} {0 0}
wm deiconify .
deleteWindows
test winfo-10.1 {"winfo visualid" command} {
list [catch {winfo visualid} msg] $msg
} {1 {wrong # args: should be "winfo visualid window"}}
test winfo-10.2 {"winfo visualid" command} {
list [catch {winfo visualid gorp} msg] $msg
} {1 {bad window path name "gorp"}}
test winfo-10.3 {"winfo visualid" command} {
expr 2+[winfo visualid .]-[winfo visualid .]
} {2}
test winfo-11.1 {"winfo visualid" command} {
list [catch {winfo visualsavailable} msg] $msg
} {1 {wrong # args: should be "winfo visualsavailable window ?includeids?"}}
test winfo-11.2 {"winfo visualid" command} {
list [catch {winfo visualsavailable gorp} msg] $msg
} {1 {bad window path name "gorp"}}
test winfo-11.3 {"winfo visualid" command} {
list [catch {winfo visualsavailable . includeids foo} msg] $msg
} {1 {wrong # args: should be "winfo visualsavailable window ?includeids?"}}
test winfo-11.4 {"winfo visualid" command} {
llength [lindex [winfo visualsa .] 0]
} {2}
test winfo-11.5 {"winfo visualid" command} {
llength [lindex [winfo visualsa . includeids] 0]
} {3}
test winfo-11.6 {"winfo visualid" command} {
set x [lindex [lindex [winfo visualsa . includeids] 0] 2]
expr $x + 2 - $x
} {2}
test winfo-12.1 {GetDisplayOf procedure} {
list [catch {winfo atom - foo x} msg] $msg
} {1 {wrong # args: should be "winfo atom ?-displayof window? name"}}
test winfo-12.2 {GetDisplayOf procedure} {
list [catch {winfo atom -d bad_window x} msg] $msg
} {1 {bad window path name "bad_window"}}
# Some embedding tests
#
proc MakeEmbed {} {
frame .con -container 1
pack .con -expand yes -fill both
toplevel .emb -use [winfo id .con] -bd 0 -highlightthickness 0
button .emb.b
pack .emb.b -expand yes -fill both
update
}
test winfo-13.1 {root coordinates of embedded toplevel} {
MakeEmbed
set z [expr [winfo rootx .emb] == [winfo rootx .con] && \
[winfo rooty .emb] == [winfo rooty .con]]
destroy .emb
destroy .con
set z
} {1}
test winfo-13.2 {destroying embedded toplevel} {
destroy .emb
update
expr [winfo exists .emb.b] || [winfo exists .con]
} 0
deleteWindows
test winfo-13.3 {destroying container window} {
MakeEmbed
destroy .con
update
set z [expr [winfo exists .emb.b] || [winfo exists .emb]]
catch {destroy .emb}
catch {destroy .con}
set z
} 0
deleteWindows
test winfo-13.4 {[winfo containing] with embedded windows} {
MakeEmbed
button .b
pack .b -expand yes -fill both
update
set z [string compare \
[winfo containing [winfo rootx .emb.b] [winfo rooty .emb.b]] .emb.b]
catch {destroy .con}
catch {destroy .emb}
set z
} 0
test winfo-14.1 {usage} {
list [catch {winfo ismapped} msg] $msg
} {1 {wrong # args: should be "winfo ismapped window"}}
test winfo-14.2 {usage} {
list [catch {winfo ismapped . .} msg] $msg
} {1 {wrong # args: should be "winfo ismapped window"}}
test winfo-14.3 {initially unmapped} {
catch {destroy .t}
toplevel .t
winfo ismapped .t
} 0
test winfo-14.4 {mapped at idle time} {
catch {destroy .t}
toplevel .t
update idletasks
winfo ismapped .t
} 1
deleteWindows
# cleanup
cleanupTests
return
|