1# Commands covered: treectrl's widget command item 2# 3# This file contains a collection of tests for the item widget command of 4# the tktreectrl extension. Sourcing this file into Tcl runs the tests and 5# generates output for errors. No output means no errors were found. 6# 7# Copyright (c) 2000 by Scriptics Corporation. 8# Copyright (c) 2002 by Christian Krone. 9# 10# See the file "license.terms" for information on usage and redistribution 11# of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12# 13# CVS: @(#) $Id: item.test,v 1.20 2007/03/03 22:24:16 treectrl Exp $ 14 15if {[lsearch [namespace children] ::tcltest] == -1} { 16 package require tcltest 2 17 namespace import ::tcltest::* 18} 19 20package require Tk 21package require treectrl 22 23test item-0.1 {some needed preparations} -body { 24 pack [treectrl .t] 25} -result {} 26 27test item-1.1 {item: missing command} -body { 28 .t item 29} -returnCodes error -result {wrong # args: should be ".t item command ?arg arg ...?"} 30 31test item-2.2 {item: invalid command} -body { 32 .t item foo 33} -returnCodes error -result {bad command "foo": must be *} -match glob 34 35# Before continuing to test the item descriptions and their modifiers, 36# lets create some items with this hierarchy: 37# 0 38# + 1 39# | + 2 40# | + 3 41# | + 4 42# + 5 43# | + 6 44# | + 7 45# + 8 46test item-2.4 {create some items} -body { 47 set n1 [.t item create]; .t item lastchild 0 $n1 48 set n2 [.t item create]; .t item lastchild $n1 $n2 49 set n3 [.t item create]; .t item lastchild $n1 $n3 50 set n4 [.t item create]; .t item lastchild $n3 $n4 51 set n5 [.t item create]; .t item lastchild 0 $n5 52 set n6 [.t item create]; .t item lastchild $n5 $n6 53 set n7 [.t item create]; .t item lastchild $n5 $n7 54 set n8 [.t item create]; .t item lastchild 0 $n8 55} -result {8} 56 57test item-2.5 {some more preparations} -body { 58 .t state define state0 59 .t element create eBorder border 60 .t element create eImage image 61 .t element create eRect rect 62 .t element create eText text -fill red 63 .t style create testStyle 64 .t style elements testStyle {eText eBorder} 65} -result {} 66 67test item-2.6 {item create} -body { 68 list [.t item create] [.t item create] [.t item create] 69} -result {9 10 11} 70 71test item-3.1 {item delete: missing itemDesc} -body { 72 .t item delete 73} -returnCodes error -result {wrong # args: should be ".t item delete first ?last?"} 74 75test item-3.2 {item delete: unknown item} -body { 76 .t item delete 999 77} -returnCodes error -result {item "999" doesn't exist} 78 79test item-3.3 {item delete: one item} -body { 80 .t item delete 9 81} -result {} 82 83test item-3.4 {item delete: item range without common ancestor} -body { 84 .t item delete 10 11 85} -returnCodes error -result {item 10 and item 11 don't share a common ancestor} 86 87test item-3.5 {item delete: item range with common ancestor} -body { 88 .t item lastchild 8 10 89 .t item lastchild 8 11 90 .t item delete 10 11 91} -result {} 92 93test item-3.6 {item delete: don't delete "root" itemDesc} -body { 94 .t item delete root 95 .t item id root 96} -result {0} 97 98test item-3.7 {item delete: deleting root should be ignored} -body { 99 .t item delete [.t item id root] 100 update idletasks 101} -result {} 102 103test item-4.1 {item ancestors: no ancestor yet} -body { 104 .t item create 105 .t item ancestors 12 106} -result {} 107 108test item-4.2 {item ancestors} -body { 109 .t item lastchild 7 12 110 .t item ancestors 12 111} -result {7 5 0} 112 113test item-5.1 {item children: no children} -body { 114 .t item children 12 115} -result {} 116 117test item-5.2 {item children} -body { 118 .t item children 0 119} -result {1 5 8} 120 121test item-6.1 {item firstchild: missing itemDesc} -body { 122 .t item firstchild 123} -returnCodes error -result {wrong # args: should be ".t item firstchild item ?newFirstChild?"} 124 125test item-6.2 {item firstchild: no children} -body { 126 .t item firstchild 12 127} -result {} 128 129test item-6.3 {item firstchild} -body { 130 .t item firstchild 1 131} -result {2} 132 133test item-7.1 {item lastchild: no children} -body { 134 .t item lastchild 1 135} -result {3} 136 137test item-8.1 {item nextsibling: no sibling} -body { 138 .t item nextsibling 12 139} -result {} 140 141test item-8.2 {item nextsibling: no sibling} -body { 142 .t item nextsibling 2 143} -result {3} 144 145test item-9.1 {item numchildren: no children} -body { 146 .t item numchildren 12 147} -result {0} 148 149test item-9.2 {item numchildren} -body { 150 .t item numchildren 1 151} -result {2} 152 153test item-10.1 {item parent: no parent} -body { 154 .t item parent root 155} -result {} 156 157test item-10.2 {item parent} -body { 158 .t item parent "root firstchild" 159} -result {0} 160 161test item-11.1 {item prevsibling: missing arg} -body { 162 .t item prevsibling 163} -returnCodes error -result {wrong # args: should be ".t item prevsibling item ?newPrevSibling?"} 164 165test item-11.2 {item prevsibling: no prevsibling} -body { 166 .t item prevsibling 1 167} -result {} 168 169test item-11.3 {item prevsibling} -body { 170 .t item prevsibling 3 171} -result {2} 172 173test item-12.1 {item remove: invalid item} -body { 174 .t item remove 999 175} -returnCodes error -result {item "999" doesn't exist} 176 177test item-12.2 {item remove} -body { 178 .t item remove 12 179} -result {} 180 181test item-13.1 {item complex: missing args} -constraints { 182 deprecated 183} -body { 184 .t item complex 8 185} -returnCodes error -result {wrong # args: should be ".t item complex item list ..."} 186 187test item-13.2 {item complex: only allowed if column style is defined} -constraints { 188 deprecated 189} -body { 190 .t item complex 8 {{e1 -text Hallo}} 191} -returnCodes error -result {column #0 doesn't exist} 192 193test item-13.3 {item complex: invalid list} -constraints { 194 deprecated 195} -body { 196 .t column create -tag column0 197 .t item style set 8 0 testStyle 198 .t item complex 8 {{e1 -text}} 199} -returnCodes error -result {wrong # args: should be "element option value ..."} 200 201test item-13.4 {item complex: element name not defined in style} -constraints { 202 deprecated 203} -body { 204 .t item complex 8 {{e1 -text Hallo}} 205} -returnCodes error -result {element "e1" doesn't exist} 206 207test item-13.5 {item complex: option not known in element} -constraints { 208 deprecated 209} -body { 210 .t item complex 8 {{eText -bitmap questhead}} 211} -returnCodes error -result {unknown option "-bitmap"} 212 213test item-13.6 {item complex: invalid option value in element} -constraints { 214 deprecated 215} -body { 216 .t item complex 8 {{eText -fill foo}} 217} -cleanup { 218 .t column delete column0 219} -returnCodes error -result {unknown color name "foo"} 220 221test item-14.1 {item element: missing command} -setup { 222 # in case the deprecated complex command is not run... 223 .t column create -tag column0 224 .t item style set 8 0 testStyle 225 .t item text 8 0 "" 226} -body { 227 .t item element 228} -returnCodes error -result {wrong # args: should be ".t item element command item column element ?arg ...?"} 229 230test item-14.2 {item element: invalid command} -body { 231 .t item element foo 8 column0 eText 232} -returnCodes error -result {bad command "foo": must be *} -match glob 233 234test item-14.3 {item element perstate: missing arg} -body { 235 .t item element perstate 8 column0 eText 236} -returnCodes error -result {wrong # args: should be ".t item element perstate item column element option ?stateList?"} 237 238test item-14.4 {item element perstate: without stateList} -body { 239 .t element configure eText -fill {red !selected blue {}} 240 .t item element perstate 8 column0 eText -fill 241} -result {red} 242 243test item-14.5 {item element perstate: without stateList} -body { 244 .t item element perstate 8 column0 eText -fill 245} -result {red} 246 247test item-14.6 {item element perstate: with stateList} -body { 248 .t item element perstate 8 column0 eText -fill {selected} 249} -result {blue} 250 251test item-14.7 {item element perstate: all items} -body { 252 .t item element perstate all column0 eText -fill {selected} 253} -returnCodes error -result {can't specify > 1 item for this command} 254 255test item-14.8 {item element perstate: several items} -body { 256 .t item element perstate {list {8 root}} column0 eText -fill {selected} 257} -returnCodes error -result {can't specify > 1 item for this command} 258 259test item-14.21 {item element cget: missing arg} -body { 260 .t item element cget 8 column0 eText 261} -returnCodes error -result {wrong # args: should be ".t item element cget item column element option"} 262 263test item-14.22 {item element cget: too many args} -body { 264 .t item element cget 8 a b c d 265} -returnCodes error -result {wrong # args: should be ".t item element cget item column element option"} 266 267test item-14.23 {item element cget: single item, get -fill} -body { 268 .t item element cget 8 column0 eText -fill 269} -result {} 270 271test item-14.24 {item element cget: all items, get -fill} -body { 272 .t item element cget all column0 eText -fill 273} -returnCodes error -result {can't specify > 1 item for this command} 274 275test item-14.25 {item element cget: multiple items, get -fill} -body { 276 .t item element cget {list {8 1 3}} column0 eText -fill 277} -returnCodes error -result {can't specify > 1 item for this command} 278 279test item-14.31 {item element configure: get all config info} -body { 280 .t item element configure 8 column0 eText 281} -result {{-data {} {} {} {}} {-datatype {} {} {} {}} *} -match glob 282 283test item-14.32 {item element configure: single item, set -fill} -body { 284 .t item element configure 8 column0 eText -fill yellow 285 .t item element cget 8 0 eText -fill 286} -result {yellow} 287 288test item-14.33 {item element configure: single item, get -fill} -body { 289 .t item element configure 8 column0 eText -fill 290} -result {-fill {} {} {} yellow} 291 292test item-14.34 {item element configure: all items, get -fill} -body { 293 .t item element configure all column0 eText -fill 294} -returnCodes error -result {can't specify > 1 item for this command} 295 296test item-14.35 {item element configure: several items, get -fill} -body { 297 .t item element configure {list {8 3}} column0 eText -fill 298} -returnCodes error -result {can't specify > 1 item for this command} 299 300test item-14.36 {item element configure: all items, set -fill} -body { 301 .t item style set all column0 testStyle 302 .t item element configure all column0 eText -fill orange 303 set res {} 304 foreach I [.t item id {range first last}] { 305 lappend res [.t item element cget $I column0 eText -fill] 306 } 307 set res 308} -result {orange orange orange orange orange orange orange orange orange} 309 310test item-14.37 {item element configure: single item, multiple elements} -body { 311 .t item element configure root column0 eText -fill blue + 312} -returnCodes error -result {missing element name after "+"} 313 314test item-14.38 {item element configure: single item, multiple elements} -body { 315 .t item element configure root column0 eText -fill blue + eBorder 316} -returnCodes error -result {missing option-value pair after element "eBorder"} 317 318test item-14.39 {item element configure: single item, multiple elements} -body { 319 .t item element configure root column0 eText -fill blue + eBorder -draw 320} -returnCodes error -result {missing option-value pair after element "eBorder"} 321 322test item-14.40 {item element configure: single item, multiple elements} -body { 323 .t item element configure root column0 eText -fill blue + eBorder -draw false 324 list [.t item element cget root column0 eText -fill] \ 325 [.t item element cget root column0 eBorder -draw] 326} -result {blue false} 327 328test item-14.41 {item element configure: single item, multiple columns} -body { 329 .t item element configure root column0 eText -fill blue , 330} -returnCodes error -result {missing column after ","} 331 332test item-14.42 {item element configure: single item, multiple columns} -body { 333 .t column create -tag column1 334 .t item style set all column1 testStyle 335 .t item element configure root column0 eText -fill blue , column1 336} -returnCodes error -result {missing element name after column "column1"} 337 338test item-14.43 {item element configure: single item, multiple columns} -body { 339 .t item element configure root column0 eText -fill blue , column1 eBorder 340} -returnCodes error -result {missing option-value pair after element "eBorder"} 341 342test item-14.44 {item element configure: single item, multiple columns} -body { 343 .t item element configure root column0 eText -fill blue , column1 eBorder -draw 344} -returnCodes error -result {missing option-value pair after element "eBorder"} 345 346test item-14.45 {item element configure: single item, multiple columns} -body { 347 .t item element configure root column0 eText -fill green , column1 eBorder -draw true 348 list [.t item element cget root column0 eText -fill] \ 349 [.t item element cget root column1 eBorder -draw] 350} -result {green true} 351 352test item-14.46 {item element configure: multiple items, multiple columns/elements} -body { 353 .t item element configure {list {1 3}} column0 eText -fill green -text boo + \ 354 eBorder -background red , column1 eBorder -draw true + eText -font {{times 12}} 355 set res {} 356 foreach I {1 3} { 357 lappend res [.t item element cget $I column0 eText -fill] 358 lappend res [.t item element cget $I column0 eText -text] 359 lappend res [.t item element cget $I column0 eBorder -background] 360 lappend res [.t item element cget $I column1 eBorder -draw] 361 lappend res [.t item element cget $I column1 eText -font] 362 } 363 set res 364} -result {green boo red true {{times 12}} green boo red true {{times 12}}} 365 366test item-14.50 {item element configure: cleanup} -body { 367 .t item style set all 0 "" 368 .t column delete all 369 .t column create 370 .t item style set 8 0 testStyle 371 .t item element configure 8 0 eText -fill yellow 372} -result {} 373 374test item-15.1 {item style: missing args} -body { 375 .t item style 376} -returnCodes error -result {wrong # args: should be ".t item style command item ?arg ...?"} 377 378test item-15.2 {item style: invalid command} -body { 379 .t item style foo bar 380} -returnCodes error -result {bad command "foo": must be *} -match glob 381 382test item-15.3 {item style: invalid command} -body { 383 .t item style foo bar 384} -returnCodes error -result {bad command "foo": must be *} -match glob 385 386test item-15.4 {item style elements: missing args} -body { 387 .t item style elements 8 388} -returnCodes error -result {wrong # args: should be ".t item style elements item column"} 389 390test item-15.5 {item style elements: invalid item} -body { 391 .t item style elements 999 392} -returnCodes error -result {item "999" doesn't exist} 393 394test item-15.6 {item style elements: item without style} -body { 395 .t item style elements 1 0 396} -returnCodes error -result {item 1 column 0 has no style} 397 398test item-15.7 {item style elements} -body { 399 .t item style elements 8 0 400} -result {eText} 401 402test item-15.8 {item style map: missing args} -body { 403 .t item style map 8 404} -returnCodes error -result {wrong # args: should be ".t item style map item column style map"} 405 406test item-15.9 {item style map: invalid item} -body { 407 .t item style map 999 408} -returnCodes error -result {item "999" doesn't exist} 409 410test item-15.10 {item style map: item with unknown style} -body { 411 .t item style map 1 0 noStyle {foo bar} 412} -returnCodes error -result {style "noStyle" doesn't exist} 413 414test item-15.11 {item style map: odd elemented list} -body { 415 .t item style map 8 0 testStyle foo 416 .t item style elements 8 0 417} -returnCodes error -result {list must contain even number of elements} 418 419test item-15.12 {item style map: unknown element} -body { 420 .t style create testStyle2 421 .t item style map 8 0 testStyle2 {eText foo} 422 .t item style elements 8 0 423} -returnCodes error -result {element "foo" doesn't exist} 424 425test item-15.13 {item style map: element not in to-style} -body { 426 .t item style map 8 0 testStyle2 {eText eRect} 427} -returnCodes error -result {style testStyle2 does not use element eRect} 428 429test item-15.14 {item style map: element not in from-style} -body { 430 # .t style elements testStyle2 {eImage eRect} 431 .t item style map 8 0 testStyle2 {eRect eBorder} 432} -returnCodes error -result {style testStyle does not use element eRect} 433 434test item-15.15 {item style map: different element types} -body { 435 .t style elements testStyle2 {eImage eRect} 436 .t item style map 8 0 testStyle2 {eBorder eRect} 437} -returnCodes error -result {can't map element type border to rect} 438 439test item-15.16 {item style set: invalid item} -body { 440 .t item style set foo bar 441} -returnCodes error -result {item "foo" doesn't exist} 442 443test item-15.17 {item style set: without args returns all styles} -body { 444 .t item style set 2 445} -result {{}} 446 447test item-15.18 {item style set: without args returns style} -body { 448 .t item style set 2 0 449} -result {} 450 451test item-15.19 {item style set: without args returns style} -body { 452 .t item style set 8 0 453} -result {testStyle} 454 455test item-15.20 {item style set: single item, single column} -body { 456 .t item style set 8 0 testStyle2 457 .t item style set 8 458} -result {testStyle2} 459 460test item-15.21 {item style set: all items, single column} -body { 461 .t item style set all 0 testStyle2 462 set res {} 463 foreach I [.t item id {range 1 8}] { 464 lappend res [.t item style set $I] 465 } 466 set res 467} -result {testStyle2 testStyle2 testStyle2 testStyle2 testStyle2 testStyle2 testStyle2 testStyle2} 468 469test item-15.22 {item style set: list of items, single column} -body { 470 .t item style set {list {2 4 6 8}} 0 "" 471 set res {} 472 foreach I [.t item id {range 1 8}] { 473 lappend res [.t item style set $I] 474 } 475 set res 476} -result {testStyle2 {{}} testStyle2 {{}} testStyle2 {{}} testStyle2 {{}}} 477 478test item-15.23 {item style set: all items, multiple columns} -body { 479 .t column create 480 .t item style set all 0 testStyle 1 testStyle2 481 set res {} 482 foreach I [.t item id {range 1 8}] { 483 lappend res [.t item style set $I] 484 } 485 set res 486} -result {{testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2} {testStyle testStyle2}} 487 488test item-15.24 {item style set: list of items, multiple columns} -body { 489 .t item style set {list {2 4 6 8}} 0 testStyle2 1 "" 490 set res {} 491 foreach I [.t item id {range 1 8}] { 492 lappend res [.t item style set $I] 493 } 494 set res 495} -result {{testStyle testStyle2} {testStyle2 {}} {testStyle testStyle2} {testStyle2 {}} {testStyle testStyle2} {testStyle2 {}} {testStyle testStyle2} {testStyle2 {}}} 496 497test item-15.25 {item style set: all items, multiple columns} -body { 498 .t item style set all 1 "" 0 "" 499 set res {} 500 foreach I [.t item id {range 1 8}] { 501 lappend res [.t item style set $I] 502 } 503 .t column delete all 504 .t column create 505 set res 506} -result {{{} {}} {{} {}} {{} {}} {{} {}} {{} {}} {{} {}} {{} {}} {{} {}}} 507 508test item-16.1 {item state: missing args} -body { 509 .t item state 510} -returnCodes error -result {wrong # args: should be ".t item state command item ?arg ...?"} 511 512test item-16.2 {item state: unknown command} -body { 513 .t item state foo bar 514} -returnCodes error -result {bad command "foo": must be *} -match glob 515 516test item-16.3 {item state get: unknown item} -body { 517 .t item state get 999 518} -returnCodes error -result {item "999" doesn't exist} 519 520test item-16.4 {item state get: too much arg} -body { 521 .t item state get 8 open enabled 522} -returnCodes error -result {wrong # args: should be ".t item state get 8 ?state?"} 523 524test item-16.5 {item state get: invalid arg} -body { 525 .t item state get 8 !open 526} -returnCodes error -result {can't specify '!' for this command} 527 528test item-16.6 {item state get: invalid arg} -body { 529 .t item state get 8 ~open 530} -returnCodes error -result {can't specify '~' for this command} 531 532test item-16.6 {item state get: unknown state} -body { 533 .t item state get 8 foo 534} -returnCodes error -result {unknown state "foo"} 535 536test item-16.7 {item state: list all set states} -body { 537 .t item state get 8 538} -result {open enabled} 539 540test item-16.8 {item state get: state not set} -body { 541 .t item state get 8 active 542} -result {0} 543 544test item-16.9 {item state get: state set} -body { 545 .t item state get 8 open 546} -result {1} 547 548test item-16.10 {item state get: user defined state not set} -body { 549 .t item state get 8 state0 550} -result {0} 551 552test item-16.11 {item state set: missing arg} -body { 553 .t item state set 8 554} -returnCodes error -result {wrong # args: should be ".t item state set 8 ?last? stateList"} 555 556test item-16.12 {item state: try to reset predefined state} -body { 557 .t item state set 8 open 558} -returnCodes error -result {can't specify state "open" for this command} 559 560test item-16.13 {item state: unknown states} -body { 561 .t item state set 8 {foo bar} 562} -returnCodes error -result {unknown state "foo"} 563 564test item-16.14 {item state: unknown state leaded by !} -body { 565 .t item state set 8 !foo 566} -returnCodes error -result {unknown state "foo"} 567 568test item-16.15 {item state: unknown state leaded by ~} -body { 569 .t item state set 8 ~bar 570} -returnCodes error -result {unknown state "bar"} 571 572test item-16.16 {item state: switch on states} -body { 573 .t item state set 8 state0 574 .t item state get 8 575} -result {open enabled state0} 576 577test item-16.17 {item state get: user defined state set} -body { 578 .t item state get 8 state0 579} -result {1} 580 581test item-16.18 {item state: toggle state} -body { 582 .t item state set 8 ~state0 583 .t item state get 8 584} -result {open enabled} 585 586test item-16.19 {item state: switch off states} -body { 587 .t item state set 8 !state0 588 .t item state get 8 state0 589} -result {0} 590 591test item-16.20 {item state: reset predefined state} -body { 592 .t item collapse 8 593 .t item state get 8 594} -result {enabled} 595 596test item-16.21 {item state: reset predefined state} -body { 597 .t item expand 8 598 .t item state get 8 599} -result {open enabled} 600 601test item-16.22 {item state: reset predefined state} -body { 602 .t item toggle 8 603 .t item state get 8 enabled 604} -result {1} 605 606test item-16.23 {item state: set range} -body { 607 .t item state set 1 8 state0 608 set res {} 609 foreach I [.t item id {range 1 8}] { 610 lappend res [.t item state get $I state0] 611 } 612 set res 613} -result {1 1 1 1 1 1 1 1} 614 615test item-16.24 {item state: set list} -body { 616 .t item state set {list {2 4 6 8}} !state0 617 set res {} 618 foreach I [.t item id {range 1 8}] { 619 lappend res [.t item state get $I state0] 620 } 621 set res 622} -result {1 0 1 0 1 0 1 0} 623 624test item-16.25 {item state: set all} -body { 625 .t item state set all ~state0 626 set res {} 627 foreach I [.t item id {range 1 8}] { 628 lappend res [.t item state get $I state0] 629 } 630 set res 631} -result {0 1 0 1 0 1 0 1} 632 633test item-16.26 {item state set: invalid range} -body { 634 set I [.t item create] 635 .t item state set $I 8 state0 636} -returnCodes error -result {item 13 and item 8 don't share a common ancestor} 637 638test item-16.40 {item state forcolumn: missing arg} -body { 639 .t item state forcolumn 640} -returnCodes error -result {wrong # args: should be ".t item state command item ?arg ...?"} 641 642test item-16.41 {item state forcolumn: missing arg} -body { 643 .t item state forcolumn 8 644} -returnCodes error -result {wrong # args: should be ".t item state forcolumn item column ?stateList?"} 645 646test item-16.42 {item state forcolumn: too many args} -body { 647 .t item state forcolumn a b c d 648} -returnCodes error -result {wrong # args: should be ".t item state forcolumn item column ?stateList?"} 649 650test item-16.43 {item state forcolumn: get for single item} -body { 651 .t item state forcolumn 8 0 652} -result {} 653 654test item-16.44 {item state forcolumn: get for all} -body { 655 .t item state forcolumn all 0 656} -returnCodes error -result {can't specify > 1 item for this command} 657 658test item-16.45 {item state forcolumn: set for single item} -body { 659 .t item state forcolumn 8 0 state0 660 .t item state forcolumn 8 0 661} -result {state0} 662 663test item-16.46 {item state forcolumn: set all} -body { 664 .t item state forcolumn all 0 state0 665 set res {} 666 foreach I [.t item id {range 1 8}] { 667 lappend res [.t item state forcolumn $I 0] 668 } 669 set res 670} -result {state0 state0 state0 state0 state0 state0 state0 state0} 671 672test item-16.47 {item state forcolumn: set list} -body { 673 .t item state forcolumn {list {2 4 6 8}} 0 !state0 674 set res {} 675 foreach I [.t item id {range 1 8}] { 676 lappend res [.t item state forcolumn $I 0] 677 } 678 set res 679} -result {state0 {} state0 {} state0 {} state0 {}} 680 681test item-17.1 {item sort: missing args} -body { 682 .t item sort 683} -returnCodes error -result {wrong # args: should be ".t item sort item ?option ...?"} 684 685test item-17.2 {item sort: invalid item} -body { 686 .t item sort foo 687} -returnCodes error -result {item "foo" doesn't exist} 688 689test item-17.3 {item sort: is all allowed?} -body { 690 .t item sort all 691} -returnCodes error -result {can't specify > 1 item for this command} 692 693test item-17.4 {item sort: invalid option} -body { 694 .t item sort root -foo 695} -returnCodes error -result {bad option "-foo": must be *} -match glob 696 697test item-17.5 {item sort: missing arg to an option} -body { 698 .t item sort root -first 699} -returnCodes error -result {missing value for "-first" option} 700 701test item-17.6 {item sort: invalid column} -body { 702 .t item sort root -column 3 703} -returnCodes error -result {column "3" doesn't exist} 704 705test item-17.7 {item sort: invalid column, second try} -body { 706 .t item sort root -column tail 707} -returnCodes error -result {can't specify "tail" for this command} 708 709test item-17.8 {item sort: sort needs style to find text} -body { 710 .t item sort root 711} -returnCodes error -result {item 1 column 0 has no style} 712 713proc listItems {t {i root}} { 714 set res {} 715 foreach c [$t item children $i] { 716 lappend res $c 717 eval lappend res [listItems $t $c] 718 } 719 return $res 720} 721 722test item-17.9 {item sort: set the texts in column 0 for all items} -body { 723 .t column create 724 .t style create textStyle 725 .t style elements textStyle {eRect eBorder eText} 726 .t element create eTime text 727 .t style create timeStyle 728 .t style elements timeStyle eTime 729 foreach i [listItems .t] { 730 .t item style set $i 0 textStyle 731 .t item style set $i 1 timeStyle 732 .t item text $i 0 [expr {$i+5}] 733 } 734 .t item text 8 0 735} -result {13} 736 737test item-17.10 {item sort: sort all by ascii} -body { 738 .t item sort root 739 listItems .t 740} -result {5 6 7 8 1 2 3 4} 741 742test item-17.11 {item sort: sort all decreasing by ascii} -body { 743 .t item sort root -decreasing 744 listItems .t 745} -result {1 2 3 4 8 5 6 7} 746 747test item-17.12 {item sort: sort all as integer} -body { 748 .t item sort root -integer 749 listItems .t 750} -result {1 2 3 4 5 6 7 8} 751 752test item-17.13 {item sort: for integers -dictionary works also} -body { 753 .t item sort root -dictionary 754 listItems .t 755} -result {1 2 3 4 5 6 7 8} 756 757test item-17.14 {item sort: sort all decreasing as integer} -body { 758 .t item sort root -integer -decreasing 759 listItems .t 760} -result {8 5 6 7 1 2 3 4} 761 762test item-17.15 {item sort: don't sort, only return sorted items} -body { 763 .t item lastchild root 5 764 list [.t item sort root -notreally] [listItems .t] 765} -result {{5 8 1} {8 1 2 3 4 5 6 7}} 766 767test item-17.16 {item sort: return integer sorted items} -body { 768 .t item sort root -notreally -integer 769} -result {1 5 8} 770 771test item-17.17 {item sort: return integer sorted items} -body { 772 .t item sort root -notreally -dictionary -decreasing 773} -result {8 5 1} 774 775test item-17.18 {item sort: two sort options, last wins (as in lsort)} -body { 776 .t item sort root -integer -ascii 777 listItems .t 778} -result {5 6 7 8 1 2 3 4} 779 780test item-17.19 {item sort: two order options, last wins (as in lsort)} -body { 781 .t item sort root -real -decreasing -increasing 782 listItems .t 783} -result {1 2 3 4 5 6 7 8} 784 785test item-17.20 {item sort: restrict to item of different parent} -body { 786 .t item sort root -first 2 787} -returnCodes error -result {item 2 is not a child of item 0} 788 789test item-17.21 {item sort: restrict to unknown item} -body { 790 .t item sort root -first foo 791} -returnCodes error -result {item "foo" doesn't exist} 792 793test item-17.22 {item sort: restricted sort} -body { 794 .t item sort root -first 5 -last 8 -decreasing 795 listItems .t 796} -result {1 2 3 4 8 5 6 7} 797 798test item-17.23 {item sort: restricted sort returned} -body { 799 .t item sort root -first 5 -last 8 -notreally 800} -result {5 8} 801 802test item-17.24 {item sort: order of restriction doesn't matter} -body { 803 .t item sort root -first 8 -last 5 -notreally 804} -result {5 8} 805 806test item-17.25 {item sort: very restricted sort returned} -body { 807 .t item sort root -first 5 -last 5 -notreally 808} -result {5} 809 810test item-17.26 {item sort -command: missing arg} -body { 811 .t item sort root -command 812} -returnCodes error -result {missing value for "-command" option} 813 814test item-17.27 {item sort -command: unknown command} -body { 815 .t item sort root -command foo 816} -returnCodes error -result {invalid command name "foo"} 817 818test item-17.28 {item sort -command: unknown command} -body { 819 .t item sort root -command # 820} -returnCodes error -result {invalid command name "#"} 821 822test item-17.29 {item sort -command: invalid return value} -body { 823 .t item sort root -command list 824} -returnCodes error -result {-command returned non-numeric result} 825 826proc myCompare {op item1 item2} { 827 switch -- $op { 828 1 - 0 - -1 { 829 return $op 830 } 831 timespan-1 { 832 regsub -all : [.t item text $item1 1] "" val1 833 regsub -all : [.t item text $item2 1] "" val2 834 return [expr {[string trimleft $val1 0]-[string trimleft $val2 0]}] 835 } 836 ascii { 837 return [string compare [.t item text $item1 0] \ 838 [.t item text $item2 0]] 839 } 840 ascii-1 { 841 return [string compare [.t item text $item1 1] \ 842 [.t item text $item2 1]] 843 } 844 default { 845 return -code $op 0 846 } 847 } 848} 849 850test item-17.30 {item sort -command: too less arguments to proc call} -body { 851 .t item sort root -command myCompare 852} -returnCodes error -result {wrong # args: should be "myCompare op item1 item2"} 853 854test item-17.31 {item sort -command: always returning 0 is identity} -body { 855 set res [list [listItems .t]] 856 .t item sort root -command {myCompare 0} 857 lappend res [listItems .t] 858} -result {{1 2 3 4 8 5 6 7} {1 2 3 4 8 5 6 7}} 859 860test item-17.32 {item sort -command: returnCode break} -body { 861 list [catch {.t item sort root -command {myCompare break}} msg] $msg \ 862 $errorInfo 863} -result {3 0 {0 864 (evaluating item sort -command)}} 865 866test item-17.33 {item sort -command: always returning 1 is identity?} -body { 867 set res [list [listItems .t]] 868 .t item sort root -command {myCompare 1} 869} -returnCodes error -result {buggy item sort -command detected} 870 871test item-17.34 {item sort -command: always returning -1 reverts?} -constraints { 872 knownBug 873} -body { 874 .t item sort root -command {myCompare -1} 875} -returnCodes error -result {buggy item sort -command detected} 876 877test item-17.35 {item sort -command: ascii} -body { 878 .t item sort root -command {myCompare ascii} 879 listItems .t 880} -result {5 6 7 8 1 2 3 4} 881 882test item-17.36 {item sort -command: reverse ascii} -body { 883 .t item sort root -command {myCompare ascii} -decreasing 884 listItems .t 885} -result {1 2 3 4 8 5 6 7} 886 887test item-17.37 {item sort: with timespans column} -body { 888 .t item text 1 1 "01:00" 889 .t item text 5 1 "10:00" 890 .t item text 8 1 "02:09:00" 891 .t item sort root -column 1 892 listItems .t 893} -result {1 2 3 4 8 5 6 7} 894 895test item-17.38 {item sort -command: ascii with timespans column} -body { 896 .t item sort root -command {myCompare ascii-1} 897 listItems .t 898} -result {1 2 3 4 8 5 6 7} 899 900test item-17.39 {item sort -command: timespan with timespans column} -body { 901 .t item sort root -command {myCompare timespan-1} 902 listItems .t 903} -result {1 2 3 4 5 6 7 8} 904 905test item-17.40 {item sort -command: reverse timespan with timespans} -body { 906 .t item sort root -command {myCompare timespan-1} -decreasing 907 listItems .t 908} -result {8 5 6 7 1 2 3 4} 909 910test item-17.41 {item sort -command: reverse timespan with timespans} -body { 911 .t item sort root -command {myCompare timespan-1} -decreasing -notreally 912} -result {8 5 1} 913 914test item-17.42 {item sort -element: missing arg} -body { 915 .t item sort root -element 916} -returnCodes error -result {missing value for "-element" option} 917 918test item-17.43 {item sort -element: invalid element} -body { 919 .t item sort root -element foo 920} -returnCodes error -result {element "foo" doesn't exist} 921 922test item-17.44 {item sort -element: no text element} -body { 923 .t item sort root -element eBorder 924} -returnCodes error -result {element eBorder is not of type "text"} 925 926test item-17.45 {item sort -element: element in wrong column} -body { 927 .t item sort root -column 1 -element eText -dictionary 928 listItems .t 929} -returnCodes error -result {style timeStyle does not use element eText} 930 931test item-17.46 {item sort -element: -colum defaults to 0} -body { 932 .t item sort root -element eTime 933 listItems .t 934} -returnCodes error -result {style textStyle does not use element eTime} 935 936test item-17.47 {item sort -element: element in columns} -body { 937 .t item sort root -column 1 -element eTime 938 listItems .t 939} -result {1 2 3 4 8 5 6 7} ;# same result as in 17.37 940 941test item-17.48 {item sort -element: useless for -command} -body { 942 .t item sort root -column 1 -element eTime -command {myCompare timespan-1} 943 listItems .t 944} -result {1 2 3 4 5 6 7 8} ;# same result as in 17.39 945 946test item-17.49 {item sort -command: no columns} -body { 947 while {![catch {.t column configure "order 0"}]} { 948 .t column delete "order 0" 949 } 950 .t item sort root 951} -returnCodes error -result {there are no columns} 952 953test item-18.1 {item enabled: too few args} -body { 954 .t item enabled 955} -returnCodes error -result {wrong # args: should be ".t item enabled item ?boolean?"} 956 957test item-18.2 {item enabled: too many args} -body { 958 .t item enabled a b c 959} -returnCodes error -result {wrong # args: should be ".t item enabled item ?boolean?"} 960 961test item-18.3 {item enabled: null item} -body { 962 .t item enabled 99 963} -returnCodes error -result {item "99" doesn't exist} 964 965test item-18.4 {item enabled: single item get} -body { 966 .t item enabled root 967} -result {1} 968 969test item-18.5 {item enabled: single item set} -body { 970 .t item enabled root false 971 set res {} 972 foreach I [.t item id {range first last}] { 973 lappend res [.t item enabled $I] 974 } 975 set res 976} -result {0 1 1 1 1 1 1 1 1} 977 978test item-18.6 {item enabled: all get} -body { 979 .t item enabled all 980} -returnCodes error -result {can't specify > 1 item for this command} 981 982test item-18.7 {item enabled: all set} -body { 983 .t item enabled all false 984 set res {} 985 foreach I [.t item id {range first last}] { 986 lappend res [.t item enabled $I] 987 } 988 set res 989} -result {0 0 0 0 0 0 0 0 0} 990 991test item-18.8 {item enabled: multi get} -body { 992 .t item enabled {list {2 4 7}} 993} -returnCodes error -result {can't specify > 1 item for this command} 994 995test item-18.9 {item enabled: multi set} -body { 996 .t item enabled {list {2 4 7}} true 997 set res {} 998 foreach I [.t item id {range first last}] { 999 lappend res [.t item enabled $I] 1000 } 1001 set res 1002} -result {0 0 1 0 1 0 0 1 0} 1003 1004test item-19.1 {item text: too few args} -body { 1005 .t item text 1006} -returnCodes error -result {wrong # args: should be ".t item text item ?column? ?text? ?column text ...?"} 1007 1008test item-19.2 {item text: all items, get every column} -body { 1009 .t item text all 1010} -returnCodes error -result {can't specify > 1 item for this command} 1011 1012test item-19.3 {item text: all items, set first column} -body { 1013 .t column create 1014 .t item style set all first testStyle 1015 .t item text all first abc 1016 set res {} 1017 foreach I [.t item id {range first last}] { 1018 lappend res [.t item text $I first] 1019 } 1020 set res 1021} -result {abc abc abc abc abc abc abc abc abc} 1022 1023test item-19.4 {item text: all items, get first column} -body { 1024 .t item text all first 1025} -returnCodes error -result {can't specify > 1 item for this command} 1026 1027test item-19.5 {item text: several items, set first column} -body { 1028 .t item text {list {2 4 6 8}} first def 1029 set res {} 1030 foreach I [.t item id {range first last}] { 1031 lappend res [.t item text $I first] 1032 } 1033 set res 1034} -result {abc abc def abc def abc def abc def} 1035 1036test item-19.6 {item text: several items, get first column} -body { 1037 .t item text {list {2 4 6 8}} first 1038} -returnCodes error -result {can't specify > 1 item for this command} 1039 1040test item-20.1 {item tag: too few args} -body { 1041 .t item tag 1042} -returnCodes error -result {wrong # args: should be ".t item tag command ?arg arg ...?"} 1043 1044test item-20.2 {item tag add: too few args} -body { 1045 .t item tag add 1046} -returnCodes error -result {wrong # args: should be ".t item tag add item tagList"} 1047 1048test item-20.3 {item tag add: too many args} -body { 1049 .t item tag add a b c 1050} -returnCodes error -result {wrong # args: should be ".t item tag add item tagList"} 1051 1052test item-20.4 {item tag names: too few args} -body { 1053 .t item tag names 1054} -returnCodes error -result {wrong # args: should be ".t item tag names item"} 1055 1056test item-20.5 {item tag names: too many args} -body { 1057 .t item tag names a b 1058} -returnCodes error -result {wrong # args: should be ".t item tag names item"} 1059 1060test item-20.6 {item tag remove: too few args} -body { 1061 .t item tag remove 1062} -returnCodes error -result {wrong # args: should be ".t item tag remove item tagList"} 1063 1064test item-20.7 {item tag remove: too many args} -body { 1065 .t item tag remove a b c 1066} -returnCodes error -result {wrong # args: should be ".t item tag remove item tagList"} 1067 1068test item-20.11 {item tag: add tags to all} -body { 1069 .t item delete all 1070 .t item create -count 9999 -parent root 1071 .t item tag add all {a b c} 1072 .t item tag expr all {c && a && b} 1073} -result {1} 1074 1075test item-20.12 {item tag: add duplicate tags} -body { 1076 .t item tag add all {c b a} 1077 lsort [.t item tag names all] 1078} -result {a b c} 1079 1080test item-20.13 {item tag: remove 1 tag from several items} -body { 1081 .t item tag remove {range 100 5000} b 1082 list [lsort [.t item tag names all]] [lsort [.t item tag names {range 100 5000}]] 1083} -result {{a b c} {a c}} 1084 1085test item-20.14 {item tag: remove 1 tag from all items} -body { 1086 .t item tag remove all b 1087 lsort [.t item tag names all] 1088} -result {a c} 1089 1090test item-20.15 {item tag: add tags to all (some dups)} -body { 1091 .t item tag add all {a e f b d h g} 1092 lsort [.t item tag names all] 1093} -result {a b c d e f g h} 1094 1095test item-20.16 {item tag: long expr} -body { 1096 llength [.t item id "tag {(a && e) && (f && b) && (d && h && g)}"] 1097} -result {10000} 1098 1099test item-20.17 {item tag: remove b from 100 items} -body { 1100 .t item tag remove {range 100 199} b 1101 llength [.t item id "tag !b"] 1102} -result {100} 1103 1104test item-20.18 {item tag: expr} -body { 1105 llength [.t item id "tag b"] 1106} -result {9900} 1107 1108test item-20.19 {item tag: remove e from 100 items, overlapping 50 of !b items} -body { 1109 .t item tag remove {range 150 249} e 1110 llength [.t item id "tag !e"] 1111} -result {100} 1112 1113test item-20.20 {item tag: expr} -body { 1114 llength [.t item id "tag {(!b || !e)}"] 1115} -result {150} 1116 1117test item-20.21 {item tag: expr} -body { 1118 llength [.t item id "tag b^e"] 1119} -result {100} 1120 1121test item-20.22 {item tag: expr} -body { 1122 .t item tag remove {tag !b||!e} {a c d f g h} 1123 llength [.t item id "tag !a"] 1124} -result {150} 1125 1126test item-20.23 {item tag: item create -tags} -body { 1127 .t item create -count 50 -tags {orphan50 x y z} 1128 llength [.t item id "tag x"] 1129} -result {50} 1130 1131test item-20.24 {item tag: item create -tags with dups} -body { 1132 .t item create -count 10 -tags {orphan10 x z x y z y} 1133 lsort [.t item tag names "tag orphan10"] 1134} -result {orphan10 x y z} 1135 1136test item-20.40 {item tag: [expr]} -body { 1137 .t item tag expr "tag orphan50" x 1138} -result {1} 1139 1140test item-20.41 {item tag: [expr]} -body { 1141 .t item tag expr "all tag orphan50" x&&y&&z 1142} -result {1} 1143 1144test item-20.42 {item tag: [expr]} -body { 1145 .t item tag expr "tag orphan50" a 1146} -result {0} 1147 1148test item-20.43 {item tag: [expr]} -body { 1149 .t item tag expr 100 e^b 1150} -cleanup { 1151 .t item delete all 1152} -result {1} 1153 1154test item-21.1 {item count: too many args} -body { 1155 .t item count a b 1156} -returnCodes error -result {wrong # args: should be ".t item count ?itemDesc?"} 1157 1158test item-21.2 {item count: no args, only root} -body { 1159 .t item count 1160} -result {1} 1161 1162test item-21.2 {item count: no args, many items} -setup { 1163 .t item create -count 50 -parent root 1164} -body { 1165 .t item count 1166} -result {51} 1167 1168test item-21.3 {item count: double-check with range} -body { 1169 expr {[.t item count] == [llength [.t item range first last]]} 1170} -result {1} 1171 1172test item-21.4 {item count: double-check with range} -body { 1173 expr {[.t item count] == [.t item count "range first last"]} 1174} -result {1} 1175 1176test item-21.5 {item count: all is same as no args} -body { 1177 expr {[.t item count] == [.t item count all]} 1178} -result {1} 1179 1180test item-21.6 {item count: depth test} -body { 1181 .t item count "depth 1" 1182} -result {50} 1183 1184test item-21.7 {item count: double-check with selection} -setup { 1185 .t selection add "range 10 20" 1186} -body { 1187 expr {[.t item count "state selected"] == [.t selection count]} 1188} -result {1} 1189 1190test item-22.1 {-button: default value} -setup { 1191 .t item delete all 1192 .t item create -tags foo 1193} -body { 1194 .t item cget foo -button 1195} -result {0} 1196 1197test item-22.2 {-button: default value} -body { 1198 .t item cget foo -button 1199} -result {0} 1200 1201test item-22.3 {-button: set true} -body { 1202 .t item conf foo -button true 1203 .t item cget foo -button 1204} -result {1} 1205 1206test item-22.4 {-button: set true} -body { 1207 .t item conf foo -button ON 1208 .t item cget foo -button 1209} -result {1} 1210 1211test item-22.5 {-button: set false} -body { 1212 .t item conf foo -button NO 1213 .t item cget foo -button 1214} -result {0} 1215 1216test item-22.6 {-button: set auto} -body { 1217 .t item conf foo -button auto 1218 .t item cget foo -button 1219} -result {auto} 1220 1221test item-22.7 {-button: set auto abbreviation} -body { 1222 .t item conf foo -button a 1223 .t item cget foo -button 1224} -result {auto} 1225 1226test item-99.1 {some needed cleanup} -body { 1227 destroy .t 1228} -result {} 1229 1230# cleanup 1231::tcltest::cleanupTests 1232return 1233