3 if {[string compare test [info procs test]] == 1} then \
7 # name - Name of test, in the form foo-1.2.
8 # description - Short textual description of the test, to
9 # help humans understand what it does.
10 # constraints - A list of one or more keywords, each of
11 # which must be the name of an element in
12 # the array "testConfig". If any of these
13 # elements is zero, the test is skipped.
14 # This argument may be omitted.
15 # script - Script to run to carry out the test. It must
16 # return a result that can be checked for
18 # answer - Expected result from script.
20 # One time setup. Create a font to insure the tests are font metric invariant.
24 font create test_font -family courier -size 14
25 text .t -font test_font
28 test textImage-1.1 {basic argument checking} {
30 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
32 list [catch {.t image} msg] $msg
33 } {1 {wrong # args: should be ".t image option ?arg arg ...?"}}
35 test textImage-1.2 {basic argument checking} {
37 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
39 list [catch {.t image c} msg] $msg
40 } {1 {bad image option "c": must be cget, configure, create, or names}}
42 test textImage-1.3 {cget argument checking} {
44 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
46 list [catch {.t image cget} msg] $msg
47 } {1 {wrong # args: should be ".t image cget index option"}}
49 test textImage-1.4 {cget argument checking} {
51 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
53 list [catch {.t image cget blurf -flurp} msg] $msg
54 } {1 {bad text index "blurf"}}
56 test textImage-1.5 {cget argument checking} {
58 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
60 list [catch {.t image cget 1.1 -flurp} msg] $msg
61 } {1 {no embedded image at index "1.1"}}
63 test textImage-1.6 {configure argument checking} {
65 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
67 list [catch {.t image configure } msg] $msg
68 } {1 {wrong # args: should be ".t image configure index ?option value ...?"}}
70 test textImage-1.7 {configure argument checking} {
72 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
74 list [catch {.t image configure blurf } msg] $msg
75 } {1 {bad text index "blurf"}}
77 test textImage-1.8 {configure argument checking} {
79 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
81 list [catch {.t image configure 1.1 } msg] $msg
82 } {1 {no embedded image at index "1.1"}}
84 test textImage-1.9 {create argument checking} {
86 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
88 list [catch {.t image create} msg] $msg
89 } {1 {wrong # args: should be ".t image create index ?option value ...?"}}
91 test textImage-1.10 {create argument checking} {
93 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
95 list [catch {.t image create blurf } msg] $msg
96 } {1 {bad text index "blurf"}}
98 test textImage-1.11 {basic argument checking} {
100 image create photo small -width 5 -height 5
101 small put red -to 0 0 4 4
104 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
106 list [catch {.t image create 1000.1000 -image small} msg] $msg
109 test textImage-1.12 {names argument checking} {
111 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
113 list [catch {.t image names dates places} msg] $msg
114 } {1 {wrong # args: should be ".t image names"}}
117 test textImage-1.13 {names argument checking} {
119 image create photo small -width 5 -height 5
120 small put red -to 0 0 4 4
123 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
126 lappend result [.t image names]
127 .t image create insert -image small
128 lappend result [.t image names]
129 .t image create insert -image small
130 lappend result [.t image names]
131 .t image create insert -image small -name little
132 lappend result [.t image names]
133 } {{} small {small#1 small} {small#1 small little}}
135 test textImage-1.14 {basic argument checking} {
137 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
139 list [catch {.t image huh} msg] $msg
140 } {1 {bad image option "huh": must be cget, configure, create, or names}}
142 test textImage-1.15 {align argument checking} {
144 image create photo small -width 5 -height 5
145 small put red -to 0 0 4 4
148 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
150 list [catch {.t image create end -image small -align wrong} msg] $msg
151 } {1 {bad alignment "wrong": must be baseline, bottom, center, or top}}
153 test textImage-1.16 {configure} {
155 image create photo small -width 5 -height 5
156 small put red -to 0 0 4 4
159 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
161 .t image create end -image small
162 .t image configure small
163 } {{-align {} {} center center} {-padx {} {} 0 0} {-pady {} {} 0 0} {-image {} {} {} small} {-name {} {} {} {}}}
165 test textImage-1.17 {basic cget options} {
167 image create photo small -width 5 -height 5
168 small put red -to 0 0 4 4
171 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
173 .t image create end -image small
175 foreach i {align padx pady image name} {
176 lappend result $i:[.t image cget small -$i]
179 } {align:center padx:0 pady:0 image:small name:}
181 test textImage-1.18 {basic configure options} {
183 image create photo small -width 5 -height 5
184 small put red -to 0 0 4 4
185 image create photo large -width 50 -height 50
186 large put green -to 0 0 50 50
189 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
191 .t image create end -image small
193 foreach {option value} {align top padx 5 pady 7 image large name none} {
194 .t image configure small -$option $value
197 .t image configure small
198 } {{-align {} {} center top} {-padx {} {} 0 5} {-pady {} {} 0 7} {-image {} {} {} large} {-name {} {} {} none}}
200 test textImage-1.19 {basic image naming} {
202 image create photo small -width 5 -height 5
203 small put red -to 0 0 4 4
206 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
208 .t image create end -image small
209 .t image create end -image small -name small
210 .t image create end -image small -name small#6342
211 .t image create end -image small -name small
212 lsort [.t image names]
213 } {small small#1 small#6342 small#6343}
215 test textImage-2.1 {debug} {
217 image create photo small -width 5 -height 5
218 small put red -to 0 0 4 4
221 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
225 .t image create end -image small
232 test textImage-3.1 {image change propagation} {
234 image create photo vary -width 5 -height 5
235 small put red -to 0 0 4 4
238 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
240 .t image create end -image vary -align top
243 lappend result base:[.t bbox vary]
244 foreach i {10 20 40} {
245 vary configure -width $i -height $i
247 lappend result $i:[.t bbox vary]
250 } {{base:0 0 5 5} {10:0 0 10 10} {20:0 0 20 20} {40:0 0 40 40}}
252 test textImage-3.2 {delayed image management} {
254 image create photo small -width 5 -height 5
255 small put red -to 0 0 4 4
258 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
260 .t image create end -name test
263 lappend result [.t bbox test]
264 .t image configure test -image small -align top
266 lappend result [.t bbox test]
269 # some temporary random tests
271 test textImage-4.1 {alignment checking - except baseline} {
273 image create photo small -width 5 -height 5
274 small put red -to 0 0 4 4
275 image create photo large -width 50 -height 50
276 large put green -to 0 0 50 50
279 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
281 .t image create end -image large
282 .t image create end -image small
286 lappend result default:[.t bbox small]
287 foreach i {top bottom center} {
288 .t image configure small -align $i
290 lappend result [.t image cget small -align]:[.t bbox small]
293 } {{default:50 22 5 5} {top:50 0 5 5} {bottom:50 45 5 5} {center:50 22 5 5}}
295 test textImage-4.2 {alignment checking - baseline} {
297 image create photo small -width 5 -height 5
298 small put red -to 0 0 4 4
299 image create photo large -width 50 -height 50
300 large put green -to 0 0 50 50
303 font create test_font2 -size 5
304 text .t -font test_font2 -bd 0 -highlightthickness 0 -padx 0 -pady 0
306 .t image create end -image large
307 .t image create end -image small -align baseline
310 foreach size {10 15 20 30} {
311 font configure test_font2 -size $size
312 array set Metrics [font metrics test_font2]
314 foreach {x y w h} [.t bbox small] {}
316 (([image height large] - $Metrics(-linespace))/2
317 + $Metrics(-ascent) - [image height small] - $y)
319 lappend result "$size $norm"
321 font delete test_font2
324 } {{10 0} {15 0} {20 0} {30 0}}
326 test textImage-4.3 {alignment and padding checking} {fonts} {
328 image create photo small -width 5 -height 5
329 small put red -to 0 0 4 4
330 image create photo large -width 50 -height 50
331 large put green -to 0 0 50 50
334 text .t -font test_font -bd 0 -highlightthickness 0 -padx 0 -pady 0
336 .t image create end -image large
337 .t image create end -image small -padx 5 -pady 10
341 lappend result default:[.t bbox small]
342 foreach i {top bottom center baseline} {
343 .t image configure small -align $i
345 lappend result $i:[.t bbox small]
348 } {{default:55 22 5 5} {top:55 10 5 5} {bottom:55 35 5 5} {center:55 22 5 5} {baseline:55 22 5 5}}
352 foreach image [image names] {image delete $image}
353 font delete test_font