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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
|
# This file is a Tcl script to test out the "message" command
# of Tk.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# All rights reserved.
#
# TESTFILE INITIALIZATION
#
package require tcltest 2.2; # needed in mode -singleproc 0
# Load the main script main.tcl, which takes care of:
# - setup for the application and the root window
# - importing commands from the tcltest namespace
# - loading of the testutils mechanism along with its utility procs
# - loading of Tk specific test constraints (additionally to constraints
# provided by the package tcltest)
source [file join [tcltest::configure -testdir] main.tcl]
# Ensure a pristine initial window state
resetWindows
#
# TESTS
#
test message-1.1 {configuration option: "anchor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -anchor w
.m cget -anchor
} -cleanup {
destroy .m
} -result {w}
test message-1.2 {configuration option: "anchor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -anchor bogus
} -cleanup {
destroy .m
} -returnCodes error -result {bad anchor "bogus": must be n, ne, e, se, s, sw, w, nw, or center}
test message-1.3 {configuration option: "aspect"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -aspect 3
.m cget -aspect
} -cleanup {
destroy .m
} -result 3
test message-1.4 {configuration option: "aspect"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -aspect bogus
} -cleanup {
destroy .m
} -returnCodes error -result {expected integer but got "bogus"}
test message-1.5 {configuration option: "background"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -background #ff0000
.m cget -background
} -cleanup {
destroy .m
} -result {#ff0000}
test message-1.6 {configuration option: "background"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -background non-existent
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "non-existent"}
test message-1.7 {configuration option: "bd"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -bd 4
.m cget -bd
} -cleanup {
destroy .m
} -result 4
test message-1.8 {configuration option: "bd"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -bd badValue
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance but got "badValue"}
test message-1.9 {configuration option: "bg"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -bg #ff0000
.m cget -bg
} -cleanup {
destroy .m
} -result {#ff0000}
test message-1.10 {configuration option: "bg"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -bg non-existent
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "non-existent"}
test message-1.11 {configuration option: "borderwidth"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -borderwidth 1.3
.m cget -borderwidth
} -cleanup {
destroy .m
} -result 1.3
test message-1.12 {configuration option: "borderwidth"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -borderwidth badValue
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance but got "badValue"}
test message-1.13 {configuration option: "cursor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -cursor arrow
.m cget -cursor
} -cleanup {
destroy .m
} -result {arrow}
test message-1.14 {configuration option: "cursor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -cursor badValue
} -cleanup {
destroy .m
} -returnCodes error -result {bad cursor spec "badValue"}
test message-1.15 {configuration option: "fg"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -fg #00ff00
.m cget -fg
} -cleanup {
destroy .m
} -result {#00ff00}
test message-1.16 {configuration option: "fg"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -fg badValue
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "badValue"}
test message-1.17 {configuration option: "font"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -font fixed
.m cget -font
} -cleanup {
destroy .m
} -result {fixed}
test message-1.18 {configuration option: "font"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -font {}
} -cleanup {
destroy .m
} -returnCodes error -result {font "" does not exist}
test message-1.19 {configuration option: "-foreground"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -foreground green
.m cget -foreground
} -cleanup {
destroy .m
} -result {green}
test message-1.20 {configuration option: "-foreground"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -foreground badValue
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "badValue"}
test message-1.21 {configuration option: "highlightbackground"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightbackground #112233
.m cget -highlightbackground
} -cleanup {
destroy .m
} -result {#112233}
test message-1.22 {configuration option: "highlightbackground"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightbackground ugly
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "ugly"}
test message-1.23 {configuration option: "highlightcolor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightcolor #123456
.m cget -highlightcolor
} -cleanup {
destroy .m
} -result {#123456}
test message-1.24 {configuration option: "highlightcolor"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightcolor non-existent
} -cleanup {
destroy .m
} -returnCodes error -result {unknown color name "non-existent"}
test message-1.25 {configuration option: "highlightthickness"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightthickness 2
.m cget -highlightthickness
} -cleanup {
destroy .m
} -result 2
test message-1.26 {configuration option: "highlightthickness"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -highlightthickness badValue
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance but got "badValue"}
test message-1.27 {configuration option: "justify"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -justify right
.m cget -justify
} -cleanup {
destroy .m
} -result {right}
test message-1.28 {configuration option: "justify"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -justify bogus
} -cleanup {
destroy .m
} -returnCodes error -result {bad justification "bogus": must be left, right, or center}
test message-1.29 {configuration option: "padx"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -padx 12m
.m cget -padx
} -cleanup {
destroy .m
} -result {12m}
test message-1.30 {configuration option: "padx"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -padx 420x
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance or "" but got "420x"}
test message-1.31 {configuration option: "pady"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -pady 12m
.m cget -pady
} -cleanup {
destroy .m
} -result {12m}
test message-1.32 {configuration option: "pady"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -pady 420x
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance or "" but got "420x"}
test message-1.33 {configuration option: "relief"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -relief ridge
.m cget -relief
} -cleanup {
destroy .m
} -result {ridge}
test message-1.34 {configuration option: "relief"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -relief badValue
} -cleanup {
destroy .m
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test message-1.35 {configuration options: "text"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -text "Sample text"
.m cget -text
} -cleanup {
destroy .m
} -result {Sample text}
test message-1.36 {configuration option: "textvariable"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -textvariable i
.m cget -textvariable
} -cleanup {
destroy .m
} -result {i}
test message-1.37 {configuration option: "width"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -width 2
.m cget -width
} -cleanup {
destroy .m
} -result 2
test message-1.38 {configuration option: "width"} -setup {
message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -width badValue
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance but got "badValue"}
test message-1.39 {configuration options, fallback to default} -setup {
message .m -borderwidth 0 -highlightthickness 0 -font {Helvetica -12 bold}
pack .m
update
} -body {
.m configure -padx -2 -pady -2 -width -2
list [.m cget -padx] [.m cget -pady] [.m cget -borderwidth] [.m cget -highlightthickness] [.m cget -width]
} -cleanup {
destroy .m
} -returnCodes error -result {expected screen distance or "" but got "-2"}
test message-2.1 {Tk_MessageObjCmd procedure} -body {
message
} -returnCodes error -result {wrong # args: should be "message pathName ?-option value ...?"}
test message-2.2 {Tk_MessageObjCmd procedure} -body {
message foo
} -returnCodes error -result {bad window path name "foo"}
test message-2.3 {Tk_MessageObjCmd procedure} -body {
catch {message foo}
winfo children .
} -result {}
test message-2.4 {Tk_MessageObjCmd procedure} -body {
message .s -gorp dump
} -returnCodes error -result {unknown option "-gorp"}
test message-2.5 {Tk_MessageObjCmd procedure} -body {
catch {message .s -gorp dump}
winfo children .
} -result {}
test message-3.1 {MessageWidgetObjCmd procedure} -setup {
message .m
} -body {
.m
} -cleanup {
destroy .m
} -returnCodes error -result {wrong # args: should be ".m option ?arg ...?"}
test message-3.2 {MessageWidgetObjCmd procedure, "cget"} -setup {
message .m
} -body {
.m cget
} -cleanup {
destroy .m
} -returnCodes error -result {wrong # args: should be ".m cget option"}
test message-3.3 {MessageWidgetObjCmd procedure, "cget"} -setup {
message .m
} -body {
.m cget -gorp
} -cleanup {
destroy .m
} -returnCodes error -result {unknown option "-gorp"}
test message-3.4 {MessageWidgetObjCmd procedure, "configure"} -setup {
message .m
} -body {
.m configure -text foobar
lindex [.m configure -text] 4
} -cleanup {
destroy .m
} -result {foobar}
test message-3.5 {MessageWidgetObjCmd procedure, "configure"} -setup {
message .m
} -body {
llength [.m configure]
} -cleanup {
destroy .m
} -result 21
test message-3.6 {MessageWidgetObjCmd procedure, "configure"} -setup {
message .m
} -body {
.m configure -foo
} -cleanup {
destroy .m
} -returnCodes error -result {unknown option "-foo"}
test message-3.7 {MessageWidgetObjCmd procedure, "configure"} -setup {
message .m
} -body {
.m configure -bd 4
.m configure -bg #ffffff
lindex [.m configure -bd] 4
} -cleanup {
destroy .m
} -result 4
test message-4.1 {Bug [5d991b822e]} {
# Want this not to segfault, or write to variable with empty name
unset -nocomplain {}
set var INIT
message .b -textvariable var
trace add variable var unset {apply {args {
.b configure -textvariable {}
}}}
pack .b
bind .b <Configure> {unset var}
update
destroy .b
info exists {}
} 0
test message-4.2 {Bug [5d991b822e]} {
# Want this not to leak traces
set var INIT
message .b -textvariable var
trace add variable var unset {apply {args {
.b configure -textvariable new
}}}
pack .b
bind .b <Configure> {unset -nocomplain var}
update
destroy .b
unset new
} {}
#
# TESTFILE CLEANUP
#
cleanupTests
|