From 417ef942fde06a2b3db96e4e7fe092742e38ae67 Mon Sep 17 00:00:00 2001 From: treectrl Date: Sat, 25 Nov 2006 21:40:07 +0000 Subject: Added some display-related tests. Try to cause a segfault by deleting items/columns/treectrl during display udpates. --- tests/display.test | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 tests/display.test diff --git a/tests/display.test b/tests/display.test new file mode 100644 index 0000000..e19783d --- /dev/null +++ b/tests/display.test @@ -0,0 +1,142 @@ +# Commands covered: display code +# +# This file contains a collection of tests for the style widget command of +# the tktreectrl extension. Sourcing this file into Tcl runs the tests and +# generates output for errors. No output means no errors were found. +# +# Copyright (c) 2000 by Scriptics Corporation. +# Copyright (c) 2002 by Christian Krone. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# CVS: @(#) $Id: display.test,v 1.1 2006/11/25 21:40:07 treectrl Exp $ + +if {[lsearch [namespace children] ::tcltest] == -1} { + package require tcltest 2 + namespace import ::tcltest::* +} + +package require Tk +package require treectrl + +test display-0.1 {some needed preparations} -body { + + # The size of the window is important. + pack [treectrl .t -width 500 -height 400] + + .t element create e1 text -text "Hello," + .t element create e2 window -destroy yes + .t element create e3 text -text " world!" + + .t style create S1 + .t style elements S1 {e1 e2 e3} + .t style layout S1 e2 -iexpand x -squeeze x + + .t column create -text "Column 0" -tags C0 -itemstyle S1 + .t column create -text "Column 1" -tags C1 -itemstyle S1 + .t column create -text "Column 2" -tags C2 -itemstyle S1 + .t column create -text "Column 3" -tags C3 -itemstyle S1 + + foreach I [.t item create -count 10 -parent root] { + foreach C [.t column list] { + .t item element configure $I $C e2 -window [entry .t.w${I}C$C] + } + } + + update ; # make sure it is visible +} -result {} + +test display-1.1 {: hide some items} -body { + .t notify bind .t { + puts -nonewline "%P visible=[list [lsort -integer %v]] hidden=[list [lsort -integer %h]]" + } + .t item configure {list {2 5 9}} -visible no + update idletasks +} -output { visible={} hidden={2 5 9}} + +test display-1.2 {: show some items} -body { + .t item configure {list {9 2}} -visible yes + update idletasks +} -output { visible={2 9} hidden={}} + +test display-1.3 {: hide & show some items} -body { + .t item configure {list {5}} -visible yes + .t item configure {list {6 7}} -visible no + update idletasks +} -output { visible=5 hidden={6 7}} + +test display-1.4 {: delete an item when it becomes visible} -body { + .t notify bind .t { + %T item delete {list %v} + } + .t notify bind .t { + puts -nonewline "%P [list [lsort -integer %i]]" + } + .t item configure 6 -visible yes + # Deleting an item that is being displayed should not segfault. + update idletasks +} -output { 6} + +test display-2.1 {: resizing a column resizes a window element} -body { + set w [.t item element cget 2 C1 e2 -window] + bind $w { + puts -nonewline " %W" + } + .t column configure C1 -width 100 + update idletasks +} -output { .t.w2C1} + +test display-2.2 {: delete a column when a window in a previous column is resized during a display update} -body { + set w [.t item element cget 2 C1 e2 -window] + bind $w {+ + .t column delete C2 + } + .t column configure C1 -width 150 + # Deleting a column while displaying an item should not segfault. + update idletasks +} -output { .t.w2C1} + +test display-2.3 {: delete a column when a window in a previous column is resized during a display update} -body { + set w [.t item element cget 2 C1 e2 -window] + bind $w { + .t item delete 2 + } + .t column configure C1 -width 100 + # Deleting an item while displaying it should not segfault. + update idletasks +} -output { 2} + +test display-3.1 {} -body { + .t configure -width 200 + update idletasks + .t notify bind .t { + puts -nonewline "%P" + } + .t xview moveto 1.0 + update idletasks +} -output {} + +test display-3.2 {: delete an item while scrolling} -body { + .t notify bind .t { + .t item delete 8 + .t notify unbind .t + } + .t xview moveto 0.0 + # Causing a display update while scrolling (during a display update) should + # restart the display update and not operate on deleted items. + update idletasks +} -output { 8} + +test display-99.1 {delete the tree during a display update} -body { + .t notify bind .t { + destroy .t + } + .t item configure 4 -visible no + update idletasks + winfo exists .t +} -result {0} + +# cleanup +::tcltest::cleanupTests +return -- cgit v0.12