1 # This file is a Tcl script to test out the "image" command and the
2 # other procedures in the file tkImage.c. It is organized in the
3 # standard fashion for Tcl tests.
5 # Copyright (c) 1994 The Regents of the University of California.
6 # Copyright (c) 1994 Sun Microsystems, Inc.
7 # Copyright (c) 1998-1999 by Scriptics Corporation.
12 if {[lsearch [namespace children] ::tcltest] == -1} {
13 source [file join [pwd] [file dirname [info script]] defs.tcl]
16 if {[lsearch [image types] test] < 0} {
17 puts "This application hasn't been compiled with the \"test\" image"
18 puts "type, so I can't run this test. Are you sure you're using"
19 puts "tktest instead of wish?"
20 ::tcltest::cleanupTests
24 foreach i [winfo children .] {
30 eval image delete [image names]
31 canvas .c -highlightthickness 2
34 test image-1.1 {Tk_ImageCmd procedure, "create" option} {
35 list [catch image msg] $msg
36 } {1 {wrong # args: should be "image option ?args?"}}
37 test image-1.2 {Tk_ImageCmd procedure, "create" option} {
38 list [catch {image gorp} msg] $msg
39 } {1 {bad option "gorp": must be create, delete, height, names, type, types, or width}}
40 test image-1.3 {Tk_ImageCmd procedure, "create" option} {
41 list [catch {image create} msg] $msg
42 } {1 {wrong # args: should be "image create type ?name? ?options?"}}
43 test image-1.4 {Tk_ImageCmd procedure, "create" option} {
44 list [catch {image c bad_type} msg] $msg
45 } {1 {image type "bad_type" doesn't exist}}
46 test image-1.5 {Tk_ImageCmd procedure, "create" option} {
47 list [image create test myimage] [image names]
49 test image-1.6 {Tk_ImageCmd procedure, "create" option} {
50 scan [image create test] image%d first
51 image create test myimage
52 scan [image create test -variable x] image%d second
55 test image-1.7 {Tk_ImageCmd procedure, "create" option} {
57 image create test myimage -variable x
58 .c create image 100 50 -image myimage
59 .c create image 100 150 -image myimage
62 image create test myimage -variable x
65 } {{myimage free} {myimage free} {myimage delete} {myimage get} {myimage get} {myimage display 0 0 30 15 30 30} {myimage display 0 0 30 15 30 130}}
66 test image-1.8 {Tk_ImageCmd procedure, "create" option} {
68 image create test myimage -variable x
69 .c create image 100 50 -image myimage
70 .c create image 100 150 -image myimage
74 image create test myimage -variable x
77 } {{myimage get} {myimage get} {myimage display 0 0 30 15 30 30} {myimage display 0 0 30 15 30 130}}
78 test image-1.9 {Tk_ImageCmd procedure, "create" option} {
80 eval image delete [image names]
81 list [catch {image create test -badName foo} msg] $msg [image names]
82 } {1 {bad option name "-badName"} {}}
84 test image-2.1 {Tk_ImageCmd procedure, "delete" option} {
85 list [catch {image delete} msg] $msg
87 test image-2.2 {Tk_ImageCmd procedure, "delete" option} {
89 eval image delete [image names]
90 image create test myimage
91 image create test img2
93 lappend result [lsort [image names]]
95 lappend result [image names]
97 test image-2.3 {Tk_ImageCmd procedure, "delete" option} {
99 eval image delete [image names]
100 image create test myimage
101 image create test img2
102 list [catch {image delete myimage gorp img2} msg] $msg [image names]
103 } {1 {image "gorp" doesn't exist} img2}
105 test image-3.1 {Tk_ImageCmd procedure, "height" option} {
106 list [catch {image height} msg] $msg
107 } {1 {wrong # args: should be "image height name"}}
108 test image-3.2 {Tk_ImageCmd procedure, "height" option} {
109 list [catch {image height a b} msg] $msg
110 } {1 {wrong # args: should be "image height name"}}
111 test image-3.3 {Tk_ImageCmd procedure, "height" option} {
112 list [catch {image height foo} msg] $msg
113 } {1 {image "foo" doesn't exist}}
114 test image-3.4 {Tk_ImageCmd procedure, "height" option} {
115 image create test myimage
116 set x [image h myimage]
117 myimage changed 0 0 0 0 60 50
118 list $x [image height myimage]
121 test image-4.1 {Tk_ImageCmd procedure, "names" option} {
122 list [catch {image names x} msg] $msg
123 } {1 {wrong # args: should be "image names"}}
124 test image-4.2 {Tk_ImageCmd procedure, "names" option} {
126 eval image delete [image names]
127 image create test myimage
128 image create test img2
129 image create test 24613
131 } {24613 img2 myimage}
132 test image-4.3 {Tk_ImageCmd procedure, "names" option} {
134 eval image delete [image names]
138 test image-5.1 {Tk_ImageCmd procedure, "type" option} {
139 list [catch {image type} msg] $msg
140 } {1 {wrong # args: should be "image type name"}}
141 test image-5.2 {Tk_ImageCmd procedure, "type" option} {
142 list [catch {image type a b} msg] $msg
143 } {1 {wrong # args: should be "image type name"}}
144 test image-5.3 {Tk_ImageCmd procedure, "type" option} {
145 list [catch {image type foo} msg] $msg
146 } {1 {image "foo" doesn't exist}}
147 test image-5.4 {Tk_ImageCmd procedure, "type" option} {
148 image create test myimage
151 test image-5.5 {Tk_ImageCmd procedure, "type" option} {
152 image create test myimage
153 .c create image 50 50 -image myimage
158 test image-6.1 {Tk_ImageCmd procedure, "types" option} {
159 list [catch {image types x} msg] $msg
160 } {1 {wrong # args: should be "image types"}}
161 test image-6.2 {Tk_ImageCmd procedure, "types" option} {
163 } {bitmap photo test}
165 test image-7.1 {Tk_ImageCmd procedure, "width" option} {
166 list [catch {image width} msg] $msg
167 } {1 {wrong # args: should be "image width name"}}
168 test image-7.2 {Tk_ImageCmd procedure, "width" option} {
169 list [catch {image width a b} msg] $msg
170 } {1 {wrong # args: should be "image width name"}}
171 test image-7.3 {Tk_ImageCmd procedure, "width" option} {
172 list [catch {image width foo} msg] $msg
173 } {1 {image "foo" doesn't exist}}
174 test image-7.4 {Tk_ImageCmd procedure, "width" option} {
175 image create test myimage
176 set x [image w myimage]
177 myimage changed 0 0 0 0 60 50
178 list $x [image width myimage]
181 test image-8.1 {Tk_ImageChanged procedure} {
183 eval image delete [image names]
184 image create test foo -variable x
185 .c create image 50 50 -image foo
188 foo changed 5 6 7 8 30 15
191 } {{foo display 5 6 7 8 30 30}}
192 test image-8.2 {Tk_ImageChanged procedure} {
194 eval image delete [image names]
195 image create test foo -variable x
196 .c create image 50 50 -image foo
197 .c create image 90 100 -image foo
200 foo changed 5 6 7 8 30 15
203 } {{foo display 5 6 25 9 30 30} {foo display 0 0 12 14 65 74}}
205 test image-9.1 {Tk_GetImage procedure} {
206 list [catch {.c create image 100 10 -image bad_name} msg] $msg
207 } {1 {image "bad_name" doesn't exist}}
208 test image-9.2 {Tk_GetImage procedure} {
209 image create test mytest
211 label .l -image mytest
213 set result [list [catch {label .l2 -image mytest} msg] $msg]
216 } {1 {image "mytest" doesn't exist}}
218 test image-10.1 {Tk_FreeImage procedure} {
220 eval image delete [image names]
221 image create test foo -variable x
222 .c create image 50 50 -image foo -tags i1
223 .c create image 90 100 -image foo -tags i2
230 list [image names] $x
231 } {foo {{foo free} {foo display 0 0 30 15 103 121}}}
232 test image-10.2 {Tk_FreeImage procedure} {
234 eval image delete [image names]
235 image create test foo -variable x
236 .c create image 50 50 -image foo -tags i1
239 set names [image names]
245 list $names [image names] $x
248 # Non-portable, apparently due to differences in rounding:
250 test image-11.1 {Tk_RedrawImage procedure, redisplay area clipping} \
253 eval image delete [image names]
254 image create test foo -variable x
255 .c create image 50 60 -image foo -tags i1 -anchor nw
257 .c create rectangle 30 40 55 65 -width 0 -fill black -outline {}
261 } {{foo display 0 0 5 5 50 50}}
262 test image-11.2 {Tk_RedrawImage procedure, redisplay area clipping} \
265 eval image delete [image names]
266 image create test foo -variable x
267 .c create image 50 60 -image foo -tags i1 -anchor nw
269 .c create rectangle 60 40 100 65 -width 0 -fill black -outline {}
273 } {{foo display 10 0 20 5 30 50}}
274 test image-11.3 {Tk_RedrawImage procedure, redisplay area clipping} \
277 eval image delete [image names]
278 image create test foo -variable x
279 .c create image 50 60 -image foo -tags i1 -anchor nw
281 .c create rectangle 60 70 100 200 -width 0 -fill black -outline {}
285 } {{foo display 10 10 20 5 30 30}}
286 test image-11.4 {Tk_RedrawImage procedure, redisplay area clipping} \
289 eval image delete [image names]
290 image create test foo -variable x
291 .c create image 50 60 -image foo -tags i1 -anchor nw
293 .c create rectangle 30 70 55 200 -width 0 -fill black -outline {}
297 } {{foo display 0 10 5 5 50 30}}
298 test image-11.5 {Tk_RedrawImage procedure, redisplay area clipping} \
301 eval image delete [image names]
302 image create test foo -variable x
303 .c create image 50 60 -image foo -tags i1 -anchor nw
305 .c create rectangle 10 20 120 130 -width 0 -fill black -outline {}
309 } {{foo display 0 0 30 15 70 70}}
310 test image-11.6 {Tk_RedrawImage procedure, redisplay area clipping} \
313 eval image delete [image names]
314 image create test foo -variable x
315 .c create image 50 60 -image foo -tags i1 -anchor nw
317 .c create rectangle 55 65 75 70 -width 0 -fill black -outline {}
321 } {{foo display 5 5 20 5 30 30}}
323 test image-12.1 {Tk_SizeOfImage procedure} {
324 eval image delete [image names]
325 image create test foo -variable x
326 set result [list [image width foo] [image height foo]]
327 foo changed 0 0 0 0 85 60
328 lappend result [image width foo] [image height foo]
331 test image-12.2 {DeleteImage procedure} {
333 eval image delete [image names]
334 image create test foo -variable x
335 .c create image 50 50 -image foo -tags i1
336 .c create image 90 100 -image foo -tags i2
339 lappend x | [image names] |
341 lappend x | [image names] |
342 } {{foo free} {foo free} {foo delete} | foo | | foo |}
344 catch {image delete hidden}
346 set h [interp hidden]
348 test image-13.1 {image command vs hidden commands} {
349 catch {image delete hidden}
350 image create photo hidden
351 interp hide {} hidden
353 list [image names] [interp hidden]
357 eval image delete [image names]
360 ::tcltest::cleanupTests