1 |
578 |
markom |
# This file is a Tcl script to test out the procedures in tkCanvImg.c,
|
2 |
|
|
# which implement canvas "image" items. It is organized in the standard
|
3 |
|
|
# fashion for Tcl tests.
|
4 |
|
|
#
|
5 |
|
|
# Copyright (c) 1994 The Regents of the University of California.
|
6 |
|
|
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
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: canvImg.test,v 1.1.1.1 2002-01-16 10:25:58 markom Exp $
|
12 |
|
|
|
13 |
|
|
if {[lsearch [image types] test] < 0} {
|
14 |
|
|
puts "This application hasn't been compiled with the \"test\" image"
|
15 |
|
|
puts "type, so I can't run this test. Are you sure you're using"
|
16 |
|
|
puts "tktest instead of wish?"
|
17 |
|
|
return
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
if {[info procs test] != "test"} {
|
21 |
|
|
source defs
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
foreach i [winfo children .] {
|
25 |
|
|
destroy $i
|
26 |
|
|
}
|
27 |
|
|
wm geometry . {}
|
28 |
|
|
raise .
|
29 |
|
|
|
30 |
|
|
eval image delete [image names]
|
31 |
|
|
canvas .c
|
32 |
|
|
pack .c
|
33 |
|
|
update
|
34 |
|
|
image create test foo -variable x
|
35 |
|
|
image create test foo2 -variable y
|
36 |
|
|
foo2 changed 0 0 0 0 80 60
|
37 |
|
|
test canvImg-1.1 {options for image items} {
|
38 |
|
|
.c delete all
|
39 |
|
|
.c create image 50 50 -anchor nw -tags i1
|
40 |
|
|
.c itemconfigure i1 -anchor
|
41 |
|
|
} {-anchor {} {} center nw}
|
42 |
|
|
test canvImg-1.2 {options for image items} {
|
43 |
|
|
.c delete all
|
44 |
|
|
list [catch {.c create image 50 50 -anchor gorp -tags i1} msg] $msg
|
45 |
|
|
} {1 {bad anchor position "gorp": must be n, ne, e, se, s, sw, w, nw, or center}}
|
46 |
|
|
test canvImg-1.3 {options for image items} {
|
47 |
|
|
.c delete all
|
48 |
|
|
.c create image 50 50 -image foo -tags i1
|
49 |
|
|
.c itemconfigure i1 -image
|
50 |
|
|
} {-image {} {} {} foo}
|
51 |
|
|
test canvImg-1.4 {options for image items} {
|
52 |
|
|
.c delete all
|
53 |
|
|
list [catch {.c create image 50 50 -image unknown -tags i1} msg] $msg
|
54 |
|
|
} {1 {image "unknown" doesn't exist}}
|
55 |
|
|
test canvImg-1.5 {options for image items} {
|
56 |
|
|
.c delete all
|
57 |
|
|
.c create image 50 50 -image foo -tags {i1 foo}
|
58 |
|
|
.c itemconfigure i1 -tags
|
59 |
|
|
} {-tags {} {} {} {i1 foo}}
|
60 |
|
|
|
61 |
|
|
test canvImg-2.1 {CreateImage procedure} {
|
62 |
|
|
list [catch {.c create image 40} msg] $msg
|
63 |
|
|
} {1 {wrong # args: should be ".c create image x y ?options?"}}
|
64 |
|
|
test canvImg-2.2 {CreateImage procedure} {
|
65 |
|
|
list [catch {.c create image 40 50 60} msg] $msg
|
66 |
|
|
} {1 {unknown option "60"}}
|
67 |
|
|
test canvImg-2.3 {CreateImage procedure} {
|
68 |
|
|
.c delete all
|
69 |
|
|
set i [.c create image 50 50]
|
70 |
|
|
list [lindex [.c itemconf $i -anchor] 4] \
|
71 |
|
|
[lindex [.c itemconf $i -image] 4] \
|
72 |
|
|
[lindex [.c itemconf $i -tags] 4]
|
73 |
|
|
} {center {} {}}
|
74 |
|
|
test canvImg-2.4 {CreateImage procedure} {
|
75 |
|
|
list [catch {.c create image xyz 40} msg] $msg
|
76 |
|
|
} {1 {bad screen distance "xyz"}}
|
77 |
|
|
test canvImg-2.5 {CreateImage procedure} {
|
78 |
|
|
list [catch {.c create image 50 qrs} msg] $msg
|
79 |
|
|
} {1 {bad screen distance "qrs"}}
|
80 |
|
|
test canvImg-2.6 {CreateImage procedure} {
|
81 |
|
|
list [catch {.c create image 50 50 -gorp foo} msg] $msg
|
82 |
|
|
} {1 {unknown option "-gorp"}}
|
83 |
|
|
|
84 |
|
|
test canvImg-3.1 {ImageCoords procedure} {
|
85 |
|
|
.c delete all
|
86 |
|
|
.c create image 50 100 -image foo -tags i1
|
87 |
|
|
.c coords i1
|
88 |
|
|
} {50.0 100.0}
|
89 |
|
|
test canvImg-3.2 {ImageCoords procedure} {
|
90 |
|
|
.c delete all
|
91 |
|
|
.c create image 50 100 -image foo -tags i1
|
92 |
|
|
list [catch {.c coords i1 dumb 100} msg] $msg
|
93 |
|
|
} {1 {bad screen distance "dumb"}}
|
94 |
|
|
test canvImg-3.3 {ImageCoords procedure} {
|
95 |
|
|
.c delete all
|
96 |
|
|
.c create image 50 100 -image foo -tags i1
|
97 |
|
|
list [catch {.c coords i1 250 dumb0} msg] $msg
|
98 |
|
|
} {1 {bad screen distance "dumb0"}}
|
99 |
|
|
test canvImg-3.4 {ImageCoords procedure} {
|
100 |
|
|
.c delete all
|
101 |
|
|
.c create image 50 100 -image foo -tags i1
|
102 |
|
|
list [catch {.c coords i1 250} msg] $msg
|
103 |
|
|
} {1 {wrong # coordinates: expected 0 or 2, got 1}}
|
104 |
|
|
test canvImg-3.5 {ImageCoords procedure} {
|
105 |
|
|
.c delete all
|
106 |
|
|
.c create image 50 100 -image foo -tags i1
|
107 |
|
|
list [catch {.c coords i1 250 300 400} msg] $msg
|
108 |
|
|
} {1 {wrong # coordinates: expected 0 or 2, got 3}}
|
109 |
|
|
|
110 |
|
|
test canvImg-4.1 {ConfiugreImage procedure} {
|
111 |
|
|
.c delete all
|
112 |
|
|
.c create image 50 100 -image foo -tags i1
|
113 |
|
|
update
|
114 |
|
|
set x {}
|
115 |
|
|
.c itemconfigure i1 -image {}
|
116 |
|
|
update
|
117 |
|
|
list $x [.c bbox i1]
|
118 |
|
|
} {{{foo free}} {}}
|
119 |
|
|
test canvImg-4.2 {ConfiugreImage procedure} {
|
120 |
|
|
.c delete all
|
121 |
|
|
.c create image 50 100 -image foo -tags i1 -anchor nw
|
122 |
|
|
update
|
123 |
|
|
set x {}
|
124 |
|
|
set y {}
|
125 |
|
|
.c itemconfigure i1 -image foo2
|
126 |
|
|
update
|
127 |
|
|
list $x $y [.c bbox i1]
|
128 |
|
|
} {{{foo free}} {{foo2 get} {foo2 display 0 0 80 60 30 30}} {50 100 130 160}}
|
129 |
|
|
test canvImg-4.3 {ConfiugreImage procedure} {
|
130 |
|
|
.c delete all
|
131 |
|
|
.c create image 50 100 -image foo -tags i1 -anchor nw
|
132 |
|
|
update
|
133 |
|
|
set x {}
|
134 |
|
|
set y {}
|
135 |
|
|
list [catch {.c itemconfigure i1 -image lousy} msg] $msg
|
136 |
|
|
} {1 {image "lousy" doesn't exist}}
|
137 |
|
|
|
138 |
|
|
test canvImg-5.1 {DeleteImage procedure} {
|
139 |
|
|
image create test xyzzy -variable z
|
140 |
|
|
.c delete all
|
141 |
|
|
.c create image 50 100 -image xyzzy -tags i1
|
142 |
|
|
update
|
143 |
|
|
image delete xyzzy
|
144 |
|
|
set z {}
|
145 |
|
|
set names [lsort [image names]]
|
146 |
|
|
.c delete i1
|
147 |
|
|
update
|
148 |
|
|
list $names $z [lsort [image names]]
|
149 |
|
|
} {{foo foo2 xyzzy} {} {foo foo2}}
|
150 |
|
|
test canvImg-5.2 {DeleteImage procedure (don't delete non-existent image)} {
|
151 |
|
|
.c delete all
|
152 |
|
|
.c create image 50 100 -tags i1
|
153 |
|
|
update
|
154 |
|
|
.c delete i1
|
155 |
|
|
update
|
156 |
|
|
} {}
|
157 |
|
|
|
158 |
|
|
test canvImg-6.1 {ComputeImageBbox procedure} {
|
159 |
|
|
.c delete all
|
160 |
|
|
.c create image 15.51 17.51 -image foo -tags i1 -anchor nw
|
161 |
|
|
.c bbox i1
|
162 |
|
|
} {16 18 46 33}
|
163 |
|
|
test canvImg-6.2 {ComputeImageBbox procedure} {
|
164 |
|
|
.c delete all
|
165 |
|
|
.c create image 15.49 17.49 -image foo -tags i1 -anchor nw
|
166 |
|
|
.c bbox i1
|
167 |
|
|
} {15 17 45 32}
|
168 |
|
|
test canvImg-6.3 {ComputeImageBbox procedure} {
|
169 |
|
|
.c delete all
|
170 |
|
|
.c create image 20 30 -tags i1 -anchor nw
|
171 |
|
|
.c bbox i1
|
172 |
|
|
} {}
|
173 |
|
|
test canvImg-6.4 {ComputeImageBbox procedure} {
|
174 |
|
|
.c delete all
|
175 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor nw
|
176 |
|
|
.c bbox i1
|
177 |
|
|
} {20 30 50 45}
|
178 |
|
|
test canvImg-6.5 {ComputeImageBbox procedure} {
|
179 |
|
|
.c delete all
|
180 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor n
|
181 |
|
|
.c bbox i1
|
182 |
|
|
} {5 30 35 45}
|
183 |
|
|
test canvImg-6.6 {ComputeImageBbox procedure} {
|
184 |
|
|
.c delete all
|
185 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor ne
|
186 |
|
|
.c bbox i1
|
187 |
|
|
} {-10 30 20 45}
|
188 |
|
|
test canvImg-6.7 {ComputeImageBbox procedure} {
|
189 |
|
|
.c delete all
|
190 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor e
|
191 |
|
|
.c bbox i1
|
192 |
|
|
} {-10 23 20 38}
|
193 |
|
|
test canvImg-6.8 {ComputeImageBbox procedure} {
|
194 |
|
|
.c delete all
|
195 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor se
|
196 |
|
|
.c bbox i1
|
197 |
|
|
} {-10 15 20 30}
|
198 |
|
|
test canvImg-6.9 {ComputeImageBbox procedure} {
|
199 |
|
|
.c delete all
|
200 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor s
|
201 |
|
|
.c bbox i1
|
202 |
|
|
} {5 15 35 30}
|
203 |
|
|
test canvImg-6.10 {ComputeImageBbox procedure} {
|
204 |
|
|
.c delete all
|
205 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor sw
|
206 |
|
|
.c bbox i1
|
207 |
|
|
} {20 15 50 30}
|
208 |
|
|
test canvImg-6.11 {ComputeImageBbox procedure} {
|
209 |
|
|
.c delete all
|
210 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor w
|
211 |
|
|
.c bbox i1
|
212 |
|
|
} {20 23 50 38}
|
213 |
|
|
test canvImg-6.12 {ComputeImageBbox procedure} {
|
214 |
|
|
.c delete all
|
215 |
|
|
.c create image 20 30 -image foo -tags i1 -anchor center
|
216 |
|
|
.c bbox i1
|
217 |
|
|
} {5 23 35 38}
|
218 |
|
|
|
219 |
|
|
# The following test is non-portable because of differences in
|
220 |
|
|
# coordinate rounding on some machines (does 0.5 round up?).
|
221 |
|
|
|
222 |
|
|
test canvImg-7.1 {DisplayImage procedure} {nonPortable} {
|
223 |
|
|
.c delete all
|
224 |
|
|
.c create image 50 100 -image foo -tags i1 -anchor nw
|
225 |
|
|
update
|
226 |
|
|
set x {}
|
227 |
|
|
.c create rect 55 110 65 115 -width 1 -outline black -fill white
|
228 |
|
|
update
|
229 |
|
|
set x
|
230 |
|
|
} {{foo display 4 9 12 6 30 30}}
|
231 |
|
|
test canvImg-7.2 {DisplayImage procedure, no image} {
|
232 |
|
|
.c delete all
|
233 |
|
|
.c create image 50 100 -tags i1
|
234 |
|
|
update
|
235 |
|
|
.c create rect 55 110 65 115 -width 1 -outline black -fill white
|
236 |
|
|
update
|
237 |
|
|
} {}
|
238 |
|
|
|
239 |
|
|
set i 1
|
240 |
|
|
.c delete all
|
241 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
242 |
|
|
.c create rect 10 10 20 20 -tags rect -fill black -width 0 -outline {}
|
243 |
|
|
foreach check {
|
244 |
|
|
{{50 70 80 81} {70 90} {rect}}
|
245 |
|
|
{{50 70 80 79} {70 90} {image}}
|
246 |
|
|
{{99 70 110 81} {90 90} {rect}}
|
247 |
|
|
{{101 70 110 79} {90 90} {image}}
|
248 |
|
|
{{99 100 110 115} {90 110} {rect}}
|
249 |
|
|
{{101 100 110 115} {90 110} {image}}
|
250 |
|
|
{{99 134 110 145} {90 125} {rect}}
|
251 |
|
|
{{101 136 110 145} {90 125} {image}}
|
252 |
|
|
{{50 134 80 145} {70 125} {rect}}
|
253 |
|
|
{{50 136 80 145} {70 125} {image}}
|
254 |
|
|
{{20 134 31 145} {40 125} {rect}}
|
255 |
|
|
{{20 136 29 145} {40 125} {image}}
|
256 |
|
|
{{20 100 31 115} {40 110} {rect}}
|
257 |
|
|
{{20 100 29 115} {40 110} {image}}
|
258 |
|
|
{{20 70 31 80} {40 90} {rect}}
|
259 |
|
|
{{20 70 29 79} {40 90} {image}}
|
260 |
|
|
{{60 70 69 109} {70 110} {image}}
|
261 |
|
|
{{60 70 71 111} {70 110} {rect}}
|
262 |
|
|
} {
|
263 |
|
|
test canvImg-8.$i {ImageToPoint procedure} {
|
264 |
|
|
eval .c coords rect [lindex $check 0]
|
265 |
|
|
.c gettags [eval .c find closest [lindex $check 1]]
|
266 |
|
|
} [lindex $check 2]
|
267 |
|
|
incr i
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
.c delete all
|
271 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
272 |
|
|
test canvImg-8.19 {ImageToArea procedure} {
|
273 |
|
|
.c gettags [.c find overlapping 60 0 70 99]
|
274 |
|
|
} {}
|
275 |
|
|
test canvImg-8.20 {ImageToArea procedure} {
|
276 |
|
|
.c gettags [.c find overlapping 60 0 70 99.999]
|
277 |
|
|
} {}
|
278 |
|
|
test canvImg-8.21 {ImageToArea procedure} {
|
279 |
|
|
.c gettags [.c find overlapping 60 0 70 101]
|
280 |
|
|
} {image}
|
281 |
|
|
test canvImg-8.22 {ImageToArea procedure} {
|
282 |
|
|
.c gettags [.c find overlapping 81 105 120 115]
|
283 |
|
|
} {}
|
284 |
|
|
test canvImg-8.23 {ImageToArea procedure} {
|
285 |
|
|
.c gettags [.c find overlapping 80.001 105 120 115]
|
286 |
|
|
} {}
|
287 |
|
|
test canvImg-8.24 {ImageToArea procedure} {
|
288 |
|
|
.c gettags [.c find overlapping 79 105 120 115]
|
289 |
|
|
} {image}
|
290 |
|
|
test canvImg-8.25 {ImageToArea procedure} {
|
291 |
|
|
.c gettags [.c find overlapping 60 116 70 150]
|
292 |
|
|
} {}
|
293 |
|
|
test canvImg-8.26 {ImageToArea procedure} {
|
294 |
|
|
.c gettags [.c find overlapping 60 115.001 70 150]
|
295 |
|
|
} {}
|
296 |
|
|
test canvImg-8.27 {ImageToArea procedure} {
|
297 |
|
|
.c gettags [.c find overlapping 60 114 70 150]
|
298 |
|
|
} {image}
|
299 |
|
|
test canvImg-8.28 {ImageToArea procedure} {
|
300 |
|
|
.c gettags [.c find overlapping 0 105 49 115]
|
301 |
|
|
} {}
|
302 |
|
|
test canvImg-8.29 {ImageToArea procedure} {
|
303 |
|
|
.c gettags [.c find overlapping 0 105 50 114.999]
|
304 |
|
|
} {}
|
305 |
|
|
test canvImg-8.30 {ImageToArea procedure} {
|
306 |
|
|
.c gettags [.c find overlapping 0 105 51 115]
|
307 |
|
|
} {image}
|
308 |
|
|
test canvImg-8.31 {ImageToArea procedure} {
|
309 |
|
|
.c gettags [.c find overlapping 0 0 49.999 99.999]
|
310 |
|
|
} {}
|
311 |
|
|
test canvImg-8.32 {ImageToArea procedure} {
|
312 |
|
|
.c gettags [.c find overlapping 0 0 51 101]
|
313 |
|
|
} {image}
|
314 |
|
|
test canvImg-8.33 {ImageToArea procedure} {
|
315 |
|
|
.c gettags [.c find overlapping 80 0 150 100]
|
316 |
|
|
} {}
|
317 |
|
|
test canvImg-8.34 {ImageToArea procedure} {
|
318 |
|
|
.c gettags [.c find overlapping 79 0 150 101]
|
319 |
|
|
} {image}
|
320 |
|
|
test canvImg-8.35 {ImageToArea procedure} {
|
321 |
|
|
.c gettags [.c find overlapping 80.001 115.001 150 180]
|
322 |
|
|
} {}
|
323 |
|
|
test canvImg-8.36 {ImageToArea procedure} {
|
324 |
|
|
.c gettags [.c find overlapping 79 114 150 180]
|
325 |
|
|
} {image}
|
326 |
|
|
test canvImg-8.37 {ImageToArea procedure} {
|
327 |
|
|
.c gettags [.c find overlapping 0 115 50 180]
|
328 |
|
|
} {}
|
329 |
|
|
test canvImg-8.38 {ImageToArea procedure} {
|
330 |
|
|
.c gettags [.c find overlapping 0 114 51 180]
|
331 |
|
|
} {image}
|
332 |
|
|
test canvImg-8.39 {ImageToArea procedure} {
|
333 |
|
|
.c gettags [.c find enclosed 0 0 200 200]
|
334 |
|
|
} {image}
|
335 |
|
|
test canvImg-8.40 {ImageToArea procedure} {
|
336 |
|
|
.c gettags [.c find enclosed 49.999 99.999 80.001 115.001]
|
337 |
|
|
} {image}
|
338 |
|
|
test canvImg-8.41 {ImageToArea procedure} {
|
339 |
|
|
.c gettags [.c find enclosed 51 100 80 115]
|
340 |
|
|
} {}
|
341 |
|
|
test canvImg-8.42 {ImageToArea procedure} {
|
342 |
|
|
.c gettags [.c find enclosed 50 101 80 115]
|
343 |
|
|
} {}
|
344 |
|
|
test canvImg-8.43 {ImageToArea procedure} {
|
345 |
|
|
.c gettags [.c find enclosed 50 100 79 115]
|
346 |
|
|
} {}
|
347 |
|
|
test canvImg-8.44 {ImageToArea procedure} {
|
348 |
|
|
.c gettags [.c find enclosed 50 100 80 114]
|
349 |
|
|
} {}
|
350 |
|
|
|
351 |
|
|
test canvImg-9.1 {DisplayImage procedure} {
|
352 |
|
|
.c delete all
|
353 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
354 |
|
|
.c scale image 25 0 2.0 1.5
|
355 |
|
|
.c bbox image
|
356 |
|
|
} {75 150 105 165}
|
357 |
|
|
|
358 |
|
|
test canvImg-10.1 {TranslateImage procedure} {
|
359 |
|
|
.c delete all
|
360 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
361 |
|
|
update
|
362 |
|
|
set x {}
|
363 |
|
|
foo changed 2 4 6 8 30 15
|
364 |
|
|
update
|
365 |
|
|
set x
|
366 |
|
|
} {{foo display 2 4 6 8 30 30}}
|
367 |
|
|
|
368 |
|
|
test canvImg-11.1 {TranslateImage procedure} {
|
369 |
|
|
.c delete all
|
370 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
371 |
|
|
update
|
372 |
|
|
set x {}
|
373 |
|
|
foo changed 2 4 6 8 40 50
|
374 |
|
|
update
|
375 |
|
|
set x
|
376 |
|
|
} {{foo display 0 0 40 50 30 30}}
|
377 |
|
|
test canvImg-11.2 {ImageChangedProc procedure} {
|
378 |
|
|
.c delete all
|
379 |
|
|
image create test foo -variable x
|
380 |
|
|
.c create image 50 100 -image foo -tags image -anchor center
|
381 |
|
|
update
|
382 |
|
|
set x {}
|
383 |
|
|
foo changed 0 0 0 0 40 50
|
384 |
|
|
.c bbox image
|
385 |
|
|
} {30 75 70 125}
|
386 |
|
|
test canvImg-11.3 {ImageChangedProc procedure} {
|
387 |
|
|
.c delete all
|
388 |
|
|
image create test foo -variable x
|
389 |
|
|
foo changed 0 0 0 0 40 50
|
390 |
|
|
.c create image 50 100 -image foo -tags image -anchor nw
|
391 |
|
|
.c create image 70 110 -image foo2 -anchor nw
|
392 |
|
|
update
|
393 |
|
|
set y {}
|
394 |
|
|
image create test foo -variable x
|
395 |
|
|
update
|
396 |
|
|
set y
|
397 |
|
|
} {{foo2 display 0 0 20 40 50 40}}
|