1 |
578 |
markom |
# 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.
|
4 |
|
|
#
|
5 |
|
|
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
|
6 |
|
|
# Copyright (c) 1998 by Scriptics Corporation.
|
7 |
|
|
#
|
8 |
|
|
# See the file "license.terms" for information on usage and redistribution
|
9 |
|
|
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
10 |
|
|
#
|
11 |
|
|
# RCS: @(#) $Id: canvas.test,v 1.1.1.1 2002-01-16 10:25:58 markom Exp $
|
12 |
|
|
|
13 |
|
|
if {[info procs test] != "test"} {
|
14 |
|
|
source defs
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
foreach i [winfo children .] {
|
18 |
|
|
destroy $i
|
19 |
|
|
}
|
20 |
|
|
wm geometry . {}
|
21 |
|
|
raise .
|
22 |
|
|
|
23 |
|
|
# XXX - This test file is woefully incomplete. At present, only a
|
24 |
|
|
# few of the features are tested.
|
25 |
|
|
|
26 |
|
|
canvas .c
|
27 |
|
|
pack .c
|
28 |
|
|
update
|
29 |
|
|
set i 1
|
30 |
|
|
foreach test {
|
31 |
|
|
{-background #ff0000 #ff0000 non-existent
|
32 |
|
|
{unknown color name "non-existent"}}
|
33 |
|
|
{-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
|
34 |
|
|
{-bd 4 4 badValue {bad screen distance "badValue"}}
|
35 |
|
|
{-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
|
36 |
|
|
{-closeenough 24 24.0 bogus {expected floating-point number but got "bogus"}}
|
37 |
|
|
{-confine true 1 silly {expected boolean value but got "silly"}}
|
38 |
|
|
{-cursor arrow arrow badValue {bad cursor spec "badValue"}}
|
39 |
|
|
{-height 2.1 2 x42 {bad screen distance "x42"}}
|
40 |
|
|
{-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
|
41 |
|
|
{-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}}
|
42 |
|
|
{-highlightthickness 18 18 badValue {bad screen distance "badValue"}}
|
43 |
|
|
{-insertbackground #110022 #110022 bogus {unknown color name "bogus"}}
|
44 |
|
|
{-insertborderwidth 1.3 1 2.6x {bad screen distance "2.6x"}}
|
45 |
|
|
{-insertofftime 100 100 3.2 {expected integer but got "3.2"}}
|
46 |
|
|
{-insertontime 100 100 3.2 {expected integer but got "3.2"}}
|
47 |
|
|
{-insertwidth 1.3 1 6x {bad screen distance "6x"}}
|
48 |
|
|
{-relief groove groove 1.5 {bad relief type "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
|
49 |
|
|
{-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
|
50 |
|
|
{-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
|
51 |
|
|
{-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
|
52 |
|
|
{-takefocus "any string" "any string" {} {}}
|
53 |
|
|
{-width 402 402 xyz {bad screen distance "xyz"}}
|
54 |
|
|
{-xscrollcommand {Some command} {Some command} {} {}}
|
55 |
|
|
{-yscrollcommand {Another command} {Another command} {} {}}
|
56 |
|
|
} {
|
57 |
|
|
set name [lindex $test 0]
|
58 |
|
|
test canvas-1.$i {configuration options} {
|
59 |
|
|
.c configure $name [lindex $test 1]
|
60 |
|
|
lindex [.c configure $name] 4
|
61 |
|
|
} [lindex $test 2]
|
62 |
|
|
incr i
|
63 |
|
|
if {[lindex $test 3] != ""} {
|
64 |
|
|
test canvas-1.$i {configuration options} {
|
65 |
|
|
list [catch {.c configure $name [lindex $test 3]} msg] $msg
|
66 |
|
|
} [list 1 [lindex $test 4]]
|
67 |
|
|
}
|
68 |
|
|
.c configure $name [lindex [.c configure $name] 3]
|
69 |
|
|
incr i
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
catch {destroy .c}
|
74 |
|
|
canvas .c -width 60 -height 40 -scrollregion {0 0 200 150} -bd 0 \
|
75 |
|
|
-highlightthickness 0
|
76 |
|
|
pack .c
|
77 |
|
|
update
|
78 |
|
|
test canvas-2.1 {CanvasWidgetCmd, xview option} {
|
79 |
|
|
.c configure -xscrollincrement 40 -yscrollincrement 5
|
80 |
|
|
.c xview moveto 0
|
81 |
|
|
update
|
82 |
|
|
set x [list [.c xview]]
|
83 |
|
|
.c xview scroll 2 units
|
84 |
|
|
update
|
85 |
|
|
lappend x [.c xview]
|
86 |
|
|
} {{0 0.3} {0.4 0.7}}
|
87 |
|
|
test canvas-2.2 {CanvasWidgetCmd, xview option} {nonPortable} {
|
88 |
|
|
# This test gives slightly different results on platforms such
|
89 |
|
|
# as NetBSD. I don't know why...
|
90 |
|
|
.c configure -xscrollincrement 0 -yscrollincrement 5
|
91 |
|
|
.c xview moveto 0.6
|
92 |
|
|
update
|
93 |
|
|
set x [list [.c xview]]
|
94 |
|
|
.c xview scroll 2 units
|
95 |
|
|
update
|
96 |
|
|
lappend x [.c xview]
|
97 |
|
|
} {{0.6 0.9} {0.66 0.96}}
|
98 |
|
|
|
99 |
|
|
catch {destroy .c}
|
100 |
|
|
canvas .c -width 60 -height 40 -scrollregion {0 0 200 80} \
|
101 |
|
|
-borderwidth 0 -highlightthickness 0
|
102 |
|
|
pack .c
|
103 |
|
|
update
|
104 |
|
|
test canvas-3.1 {CanvasWidgetCmd, yview option} {
|
105 |
|
|
.c configure -xscrollincrement 40 -yscrollincrement 5
|
106 |
|
|
.c yview moveto 0
|
107 |
|
|
update
|
108 |
|
|
set x [list [.c yview]]
|
109 |
|
|
.c yview scroll 3 units
|
110 |
|
|
update
|
111 |
|
|
lappend x [.c yview]
|
112 |
|
|
} {{0 0.5} {0.1875 0.6875}}
|
113 |
|
|
test canvas-3.2 {CanvasWidgetCmd, yview option} {
|
114 |
|
|
.c configure -xscrollincrement 40 -yscrollincrement 0
|
115 |
|
|
.c yview moveto 0
|
116 |
|
|
update
|
117 |
|
|
set x [list [.c yview]]
|
118 |
|
|
.c yview scroll 2 units
|
119 |
|
|
update
|
120 |
|
|
lappend x [.c yview]
|
121 |
|
|
} {{0 0.5} {0.1 0.6}}
|
122 |
|
|
|
123 |
|
|
test canvas-4.1 {ButtonEventProc procedure} {
|
124 |
|
|
eval destroy [winfo children .]
|
125 |
|
|
canvas .c1 -bg #543210
|
126 |
|
|
rename .c1 .c2
|
127 |
|
|
set x {}
|
128 |
|
|
lappend x [winfo children .]
|
129 |
|
|
lappend x [.c2 cget -bg]
|
130 |
|
|
destroy .c1
|
131 |
|
|
lappend x [info command .c*] [winfo children .]
|
132 |
|
|
} {.c1 #543210 {} {}}
|
133 |
|
|
|
134 |
|
|
test canvas-5.1 {ButtonCmdDeletedProc procedure} {
|
135 |
|
|
eval destroy [winfo children .]
|
136 |
|
|
canvas .c1
|
137 |
|
|
rename .c1 {}
|
138 |
|
|
list [info command .c*] [winfo children .]
|
139 |
|
|
} {{} {}}
|
140 |
|
|
|
141 |
|
|
catch {destroy .c}
|
142 |
|
|
canvas .c -width 100 -height 50 -scrollregion {-200 -100 305 102} \
|
143 |
|
|
-borderwidth 2 -highlightthickness 3
|
144 |
|
|
pack .c
|
145 |
|
|
update
|
146 |
|
|
test canvas-6.1 {CanvasSetOrigin procedure} {
|
147 |
|
|
.c configure -xscrollincrement 0 -yscrollincrement 0
|
148 |
|
|
.c xview moveto 0
|
149 |
|
|
.c yview moveto 0
|
150 |
|
|
update
|
151 |
|
|
list [.c canvasx 0] [.c canvasy 0]
|
152 |
|
|
} {-205.0 -105.0}
|
153 |
|
|
test canvas-6.2 {CanvasSetOrigin procedure} {
|
154 |
|
|
.c configure -xscrollincrement 20 -yscrollincrement 10
|
155 |
|
|
set x ""
|
156 |
|
|
foreach i {.08 .10 .48 .50} {
|
157 |
|
|
.c xview moveto $i
|
158 |
|
|
update
|
159 |
|
|
lappend x [.c canvasx 0]
|
160 |
|
|
}
|
161 |
|
|
set x
|
162 |
|
|
} {-165.0 -145.0 35.0 55.0}
|
163 |
|
|
test canvas-6.3 {CanvasSetOrigin procedure} {
|
164 |
|
|
.c configure -xscrollincrement 20 -yscrollincrement 10
|
165 |
|
|
set x ""
|
166 |
|
|
foreach i {.06 .08 .70 .72} {
|
167 |
|
|
.c yview moveto $i
|
168 |
|
|
update
|
169 |
|
|
lappend x [.c canvasy 0]
|
170 |
|
|
}
|
171 |
|
|
set x
|
172 |
|
|
} {-95.0 -85.0 35.0 45.0}
|
173 |
|
|
test canvas-6.4 {CanvasSetOrigin procedure} {
|
174 |
|
|
.c configure -xscrollincrement 20 -yscrollincrement 10
|
175 |
|
|
.c xview moveto 1.0
|
176 |
|
|
.c canvasx 0
|
177 |
|
|
} {215.0}
|
178 |
|
|
test canvas-6.5 {CanvasSetOrigin procedure} {
|
179 |
|
|
.c configure -xscrollincrement 20 -yscrollincrement 10
|
180 |
|
|
.c yview moveto 1.0
|
181 |
|
|
.c canvasy 0
|
182 |
|
|
} {55.0}
|
183 |
|
|
|
184 |
|
|
set l [interp hidden]
|
185 |
|
|
eval destroy [winfo children .]
|
186 |
|
|
|
187 |
|
|
test canvas-7.1 {canvas widget vs hidden commands} {
|
188 |
|
|
catch {destroy .c}
|
189 |
|
|
canvas .c
|
190 |
|
|
interp hide {} .c
|
191 |
|
|
destroy .c
|
192 |
|
|
list [winfo children .] [interp hidden]
|
193 |
|
|
} [list {} $l]
|
194 |
|
|
|
195 |
|
|
test canvas-8.1 {canvas arc bbox} {
|
196 |
|
|
catch {destroy .c}
|
197 |
|
|
canvas .c
|
198 |
|
|
.c create arc -100 10 100 210 -start 10 -extent 50 -style arc -tags arc1
|
199 |
|
|
set arcBox [.c bbox arc1]
|
200 |
|
|
.c create arc 100 10 300 210 -start 10 -extent 50 -style chord -tags arc2
|
201 |
|
|
set coordBox [.c bbox arc2]
|
202 |
|
|
.c create arc 300 10 500 210 -start 10 -extent 50 -style pieslice -tags arc3
|
203 |
|
|
set pieBox [.c bbox arc3]
|
204 |
|
|
list $arcBox $coordBox $pieBox
|
205 |
|
|
} {{48 21 100 94} {248 21 300 94} {398 21 500 112}}
|
206 |
|
|
test canvas-9.1 {canvas id creation and deletion} {
|
207 |
|
|
# With Tk 8.0.4 the ids are now stored in a hash table. You
|
208 |
|
|
# can use this test as a performance test with older versions
|
209 |
|
|
# by changing the value of size.
|
210 |
|
|
set size 15
|
211 |
|
|
|
212 |
|
|
catch {destroy .c}
|
213 |
|
|
set c [canvas .c]
|
214 |
|
|
for {set i 0} {$i < $size} {incr i} {
|
215 |
|
|
set x [expr {-10 + 3*$i}]
|
216 |
|
|
for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
|
217 |
|
|
$c create rect ${x}c ${y}c [expr $x+2]c [expr $y+2]c \
|
218 |
|
|
-outline black -fill blue -tags rect
|
219 |
|
|
$c create text [expr $x+1]c [expr $y+1]c -text "$i,$j" \
|
220 |
|
|
-anchor center -tags text
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
# The actual bench mark - this code also exercises all the hash
|
225 |
|
|
# table changes.
|
226 |
|
|
|
227 |
|
|
set time [lindex [time {
|
228 |
|
|
foreach id [$c find withtag all] {
|
229 |
|
|
$c lower $id
|
230 |
|
|
$c raise $id
|
231 |
|
|
$c find withtag $id
|
232 |
|
|
$c bind $id {}
|
233 |
|
|
$c delete $id
|
234 |
|
|
}
|
235 |
|
|
}] 0]
|
236 |
|
|
|
237 |
|
|
set x ""
|
238 |
|
|
} {}
|