1 # This file is a Tcl script to test out the procedures in tkCanvas.c,
2 # which implements generic code for canvases. It is organized in the
3 # standard fashion for Tcl tests.
5 # Copyright (c) 1995-1996 Sun Microsystems, Inc.
6 # Copyright (c) 1998-2000 Ajuba Solutions.
11 if {[lsearch [namespace children] ::tcltest] == -1} {
12 source [file join [pwd] [file dirname [info script]] defs.tcl]
15 foreach i [winfo children .] {
21 # XXX - This test file is woefully incomplete. At present, only a
22 # few of the features are tested.
29 {-background #ff0000 #ff0000 non-existent
30 {unknown color name "non-existent"}}
31 {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
32 {-bd 4 4 badValue {bad screen distance "badValue"}}
33 {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
34 {-closeenough 24 24.0 bogus {expected floating-point number but got "bogus"}}
35 {-confine true 1 silly {expected boolean value but got "silly"}}
36 {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
37 {-height 2.1 2 x42 {bad screen distance "x42"}}
38 {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
39 {-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}}
40 {-highlightthickness 18 18 badValue {bad screen distance "badValue"}}
41 {-insertbackground #110022 #110022 bogus {unknown color name "bogus"}}
42 {-insertborderwidth 1.3 1 2.6x {bad screen distance "2.6x"}}
43 {-insertofftime 100 100 3.2 {expected integer but got "3.2"}}
44 {-insertontime 100 100 3.2 {expected integer but got "3.2"}}
45 {-insertwidth 1.3 1 6x {bad screen distance "6x"}}
46 {-relief groove groove 1.5 {bad relief type "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
47 {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
48 {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
49 {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
50 {-takefocus "any string" "any string" {} {}}
51 {-width 402 402 xyz {bad screen distance "xyz"}}
52 {-xscrollcommand {Some command} {Some command} {} {}}
53 {-yscrollcommand {Another command} {Another command} {} {}}
55 set name [lindex $test 0]
56 test canvas-1.$i {configuration options} {
57 .c configure $name [lindex $test 1]
58 lindex [.c configure $name] 4
61 if {[lindex $test 3] != ""} {
62 test canvas-1.$i {configuration options} {
63 list [catch {.c configure $name [lindex $test 3]} msg] $msg
64 } [list 1 [lindex $test 4]]
66 .c configure $name [lindex [.c configure $name] 3]
70 test canvas-1.40 {configure throws error on bad option} {
71 set res [list [catch {.c configure -gorp foo}]]
72 .c create rect 10 10 100 100
73 lappend res [catch {.c configure -gorp foo}]
79 canvas .c -width 60 -height 40 -scrollregion {0 0 200 150} -bd 0 \
84 test canvas-2.1 {CanvasWidgetCmd, bind option} {
85 set i [.c create rect 10 10 100 100]
86 list [catch {.c bind $i <a>} msg] $msg
88 test canvas-2.2 {CanvasWidgetCmd, bind option} {
89 set i [.c create rect 10 10 100 100]
90 list [catch {.c bind $i <} msg] $msg
91 } {1 {no event type or button # or keysym}}
92 test canvas-2.3 {CanvasWidgetCmd, xview option} {
93 .c configure -xscrollincrement 40 -yscrollincrement 5
96 set x [list [.c xview]]
97 .c xview scroll 2 units
100 } {{0 0.3} {0.4 0.7}}
101 test canvas-2.4 {CanvasWidgetCmd, xview option} {nonPortable} {
102 # This test gives slightly different results on platforms such
103 # as NetBSD. I don't know why...
104 .c configure -xscrollincrement 0 -yscrollincrement 5
107 set x [list [.c xview]]
108 .c xview scroll 2 units
111 } {{0.6 0.9} {0.66 0.96}}
114 canvas .c -width 60 -height 40 -scrollregion {0 0 200 80} \
115 -borderwidth 0 -highlightthickness 0
118 test canvas-3.1 {CanvasWidgetCmd, yview option} {
119 .c configure -xscrollincrement 40 -yscrollincrement 5
122 set x [list [.c yview]]
123 .c yview scroll 3 units
126 } {{0 0.5} {0.1875 0.6875}}
127 test canvas-3.2 {CanvasWidgetCmd, yview option} {
128 .c configure -xscrollincrement 40 -yscrollincrement 0
131 set x [list [.c yview]]
132 .c yview scroll 2 units
135 } {{0 0.5} {0.1 0.6}}
137 test canvas-4.1 {ButtonEventProc procedure} {
138 eval destroy [winfo children .]
139 canvas .c1 -bg #543210
142 lappend x [winfo children .]
143 lappend x [.c2 cget -bg]
145 lappend x [info command .c*] [winfo children .]
146 } {.c1 #543210 {} {}}
148 test canvas-5.1 {ButtonCmdDeletedProc procedure} {
149 eval destroy [winfo children .]
152 list [info command .c*] [winfo children .]
156 canvas .c -width 100 -height 50 -scrollregion {-200 -100 305 102} \
157 -borderwidth 2 -highlightthickness 3
160 test canvas-6.1 {CanvasSetOrigin procedure} {
161 .c configure -xscrollincrement 0 -yscrollincrement 0
165 list [.c canvasx 0] [.c canvasy 0]
167 test canvas-6.2 {CanvasSetOrigin procedure} {
168 .c configure -xscrollincrement 20 -yscrollincrement 10
170 foreach i {.08 .10 .48 .50} {
173 lappend x [.c canvasx 0]
176 } {-165.0 -145.0 35.0 55.0}
177 test canvas-6.3 {CanvasSetOrigin procedure} {
178 .c configure -xscrollincrement 20 -yscrollincrement 10
180 foreach i {.06 .08 .70 .72} {
183 lappend x [.c canvasy 0]
186 } {-95.0 -85.0 35.0 45.0}
187 test canvas-6.4 {CanvasSetOrigin procedure} {
188 .c configure -xscrollincrement 20 -yscrollincrement 10
192 test canvas-6.5 {CanvasSetOrigin procedure} {
193 .c configure -xscrollincrement 20 -yscrollincrement 10
198 set l [interp hidden]
199 eval destroy [winfo children .]
201 test canvas-7.1 {canvas widget vs hidden commands} {
206 list [winfo children .] [interp hidden]
209 test canvas-8.1 {canvas arc bbox} {
212 .c create arc -100 10 100 210 -start 10 -extent 50 -style arc -tags arc1
213 set arcBox [.c bbox arc1]
214 .c create arc 100 10 300 210 -start 10 -extent 50 -style chord -tags arc2
215 set coordBox [.c bbox arc2]
216 .c create arc 300 10 500 210 -start 10 -extent 50 -style pieslice -tags arc3
217 set pieBox [.c bbox arc3]
218 list $arcBox $coordBox $pieBox
219 } {{48 21 100 94} {248 21 300 94} {398 21 500 112}}
220 test canvas-9.1 {canvas id creation and deletion} {
221 # With Tk 8.0.4 the ids are now stored in a hash table. You
222 # can use this test as a performance test with older versions
223 # by changing the value of size.
228 for {set i 0} {$i < $size} {incr i} {
229 set x [expr {-10 + 3*$i}]
230 for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
231 $c create rect ${x}c ${y}c [expr $x+2]c [expr $y+2]c \
232 -outline black -fill blue -tags rect
233 $c create text [expr $x+1]c [expr $y+1]c -text "$i,$j" \
234 -anchor center -tags text
238 # The actual bench mark - this code also exercises all the hash
241 set time [lindex [time {
242 foreach id [$c find withtag all] {
246 $c bind <Return> $id {}
253 test canvas-10.1 {find items using tag expressions} {
256 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
257 .c create oval 20 60 40 80 -fill yellow -tag [list b a]
258 .c create oval 20 100 40 120 -fill green -tag [list c b]
259 .c create oval 20 140 40 160 -fill blue -tag [list b]
260 .c create oval 20 180 40 200 -fill bisque -tag [list a d e]
261 .c create oval 20 220 40 240 -fill bisque -tag b
262 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
264 lappend res [.c find withtag {!a}]
265 lappend res [.c find withtag {b&&c}]
266 lappend res [.c find withtag {b||c}]
267 lappend res [.c find withtag {a&&!b}]
268 lappend res [.c find withtag {!b&&!c}]
269 lappend res [.c find withtag {d&&a&&c&&b}]
270 lappend res [.c find withtag {b^a}]
271 lappend res [.c find withtag {(a&&!b)||(!a&&b)}]
272 lappend res [.c find withtag { ( a && ! b ) || ( ! a && b ) }]
273 lappend res [.c find withtag {a&&!(c||d)}]
274 lappend res [.c find withtag {d&&"tag with spaces"}]
275 lappend res [.c find withtag "tag with spaces"]
276 } {{3 4 6 7} {1 3} {1 2 3 4 6} 5 {5 7} 1 {3 4 5 6} {3 4 5 6} {3 4 5 6} 2 7 7}
277 test canvas-10.2 {check errors from tag expressions} {
280 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
281 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
282 catch {.c find withtag {&&c}} err
284 } {Unexpected operator in tag search expression}
285 test canvas-10.3 {check errors from tag expressions} {
288 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
289 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
290 catch {.c find withtag {!!c}} err
292 } {Too many '!' in tag search expression}
293 test canvas-10.4 {check errors from tag expressions} {
296 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
297 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
298 catch {.c find withtag {b||}} err
300 } {Missing tag in tag search expression}
301 test canvas-10.5 {check errors from tag expressions} {
304 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
305 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
306 catch {.c find withtag {b&&(c||)}} err
308 } {Unexpected operator in tag search expression}
309 test canvas-10.6 {check errors from tag expressions} {
312 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
313 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
314 catch {.c find withtag {d&&""}} err
316 } {Null quoted tag string in tag search expression}
317 test canvas-10.7 {check errors from tag expressions} {
320 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
321 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
322 catch {.c find withtag "d&&\"tag with spaces"} err
324 } {Missing endquote in tag search expression}
325 test canvas-10.8 {check errors from tag expressions} {
328 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
329 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
330 catch {.c find withtag {a&&"tag with spaces"z}} err
332 } {Invalid boolean operator in tag search expression}
333 test canvas-10.9 {check errors from tag expressions} {
336 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
337 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
338 catch {.c find withtag {a&&b&c}} err
340 } {Singleton '&' in tag search expression}
341 test canvas-10.10 {check errors from tag expressions} {
344 .c create oval 20 20 40 40 -fill red -tag [list a b c d]
345 .c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
346 catch {.c find withtag {a||b|c}} err
348 } {Singleton '|' in tag search expression}
349 test canvas-10.11 {backward compatility - strange tags that are not expressions} {
352 .c create oval 20 20 40 40 -fill red -tag [list { strange tag(xxx&yyy|zzz) " && \" || ! ^ " }]
353 .c find withtag { strange tag(xxx&yyy|zzz) " && \" || ! ^ " }
355 test canvas-10.12 {multple events bound to same tag expr} {
358 .c bind {a && b} <Enter> {puts Enter}
359 .c bind {a && b} <Leave> {puts Leave}
362 test canvas-11.1 {canvas poly fill check, bug 5783} {
363 # This would crash in 8.3.0 and 8.3.1
366 .c create polygon 0 0 100 100 200 50 \
367 -fill {} -stipple gray50 -outline black
371 ::tcltest::cleanupTests