1
# This file is a Tcl script to test out images of type "bitmap" (i.e.,
2
# the procedures in the file tkImgBmap.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-1995 Sun Microsystems, Inc.
8
# See the file "license.terms" for information on usage and redistribution
9
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
# RCS: @(#) $Id: imgBmap.test,v 1.2 1998/09/14 18:23:47 stanton Exp $
13
if {[info procs test] != "test"} {
17
foreach i [winfo children .] {
23
set data1 {#define foo_width 16
27
static unsigned char foo_bits[] = {
28
0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
29
0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
30
0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff, 0xff};
34
#define foo2_height 16
35
static char foo2_bits[] = {
36
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
37
0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
38
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0xff};
40
makeFile $data1 foo.bm
41
makeFile $data2 foo2.bm
43
eval image delete [image names]
47
image create bitmap i1
48
.c create image 200 100 -image i1
54
test imageBmap-1.1 {options for bitmap images} {
55
image create bitmap i1 -background #123456
56
lindex [i1 configure -background] 4
58
test imageBmap-1.2 {options for bitmap images} {
60
image create bitmap i1 -background lousy
62
list $errMsg $errorInfo
63
} {{unknown color name "lousy"} {unknown color name "lousy"
64
(while configuring image "i1")}}
65
test imageBmap-1.3 {options for bitmap images} {
66
image create bitmap i1 -data $data1
67
lindex [i1 configure -data] 4
69
test imageBmap-1.4 {options for bitmap images} {
70
list [catch {image create bitmap i1 -data bogus} msg] $msg
71
} {1 {format error in bitmap data}}
72
test imageBmap-1.5 {options for bitmap images} {
73
image create bitmap i1 -file foo.bm
74
lindex [i1 configure -file] 4
76
test imageBmap-1.6 {options for bitmap images} {
77
list [catch {image create bitmap i1 -file bogus} msg] [string tolower $msg]
78
} {1 {couldn't read bitmap file "bogus": no such file or directory}}
79
test imageBmap-1.7 {options for bitmap images} {
80
image create bitmap i1 -foreground #00ff00
81
lindex [i1 configure -foreground] 4
83
test imageBmap-1.8 {options for bitmap images} {
85
image create bitmap i1 -foreground bad_color
87
list $errMsg $errorInfo
88
} {{unknown color name "bad_color"} {unknown color name "bad_color"
89
(while configuring image "i1")}}
90
test imageBmap-1.9 {options for bitmap images} {
91
image create bitmap i1 -data $data1 -maskdata $data2
92
lindex [i1 configure -maskdata] 4
94
test imageBmap-1.10 {options for bitmap images} {
95
list [catch {image create bitmap i1 -data $data1 -maskdata bogus} msg] $msg
96
} {1 {format error in bitmap data}}
97
test imageBmap-1.11 {options for bitmap images} {
98
image create bitmap i1 -file foo.bm -maskfile foo2.bm
99
lindex [i1 configure -maskfile] 4
101
test imageBmap-1.12 {options for bitmap images} {
102
list [catch {image create bitmap i1 -data $data1 -maskfile bogus} msg] \
103
[string tolower $msg]
104
} {1 {couldn't read bitmap file "bogus": no such file or directory}}
107
test imageBmap-2.1 {ImgBmapCreate procedure} {
108
eval image delete [image names]
110
list [catch {image create bitmap -gorp dum} msg] $msg [image names]
111
} {1 {unknown option "-gorp"} {}}
112
test imageBmap-2.2 {ImgBmapCreate procedure} {
113
eval image delete [image names]
115
image create bitmap image1
116
list [info commands image1] [image names] \
117
[image width image1] [image height image1] \
118
[lindex [image1 configure -foreground] 4] \
119
[lindex [image1 configure -background] 4]
120
} {image1 image1 0 0 #000000 {}}
122
test imageBmap-3.1 {ImgBmapConfigureMaster procedure, memory de-allocation} {
123
image create bitmap i1 -data $data1
124
i1 configure -data $data1
126
test imageBmap-3.2 {ImgBmapConfigureMaster procedure} {
127
image create bitmap i1 -data $data1
128
list [catch {i1 configure -data bogus} msg] $msg [image width i1] \
130
} {1 {format error in bitmap data} 16 16}
131
test imageBmap-3.3 {ImgBmapConfigureMaster procedure, memory de-allocation} {
132
image create bitmap i1 -data $data1 -maskdata $data2
133
i1 configure -maskdata $data2
135
test imageBmap-3.4 {ImgBmapConfigureMaster procedure} {
136
image create bitmap i1
137
list [catch {i1 configure -maskdata $data2} msg] $msg
138
} {1 {can't have mask without bitmap}}
139
test imageBmap-3.5 {ImgBmapConfigureMaster procedure} {
140
list [catch {image create bitmap i1 -data $data1 -maskdata {
142
#define foo_height 16
143
static char foo_bits[] = {
144
0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
145
0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81};
148
} {1 {bitmap and mask have different sizes}}
149
test imageBmap-3.6 {ImgBmapConfigureMaster procedure} {
150
list [catch {image create bitmap i1 -data $data1 -maskdata {
153
static char foo_bits[] = {
154
0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
155
0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81};
158
} {1 {bitmap and mask have different sizes}}
159
test imageBmap-3.7 {ImgBmapConfigureMaster procedure} {
160
image create bitmap i1 -data $data1
161
.c create image 100 100 -image i1 -tags i1.1 -anchor nw
162
.c create image 200 100 -image i1 -tags i1.2 -anchor nw
165
#define foo2_height 14
166
#define foo2_width 15
167
static char foo2_bits[] = {
168
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
169
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
170
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
174
list [image width i1] [image height i1] [.c bbox i1.1] [.c bbox i1.2]
175
} {15 14 {100 100 115 114} {200 100 215 114}}
177
test imageBmap-4.1 {ImgBmapConfigureInstance procedure: check error handling} {
180
image create bitmap i1 -file foo.bm
181
.c create image 100 100 -image i1
183
i1 configure -foreground bogus
187
test imageBmap-5.1 {GetBitmapData procedure} {
188
list [catch {image create bitmap -file ~bad_user/a/b} msg] \
189
[string tolower $msg]
190
} {1 {user "bad_user" doesn't exist}}
191
test imageBmap-5.2 {GetBitmapData procedure} {
192
list [catch {image create bitmap -file bad_name} msg] [string tolower $msg]
193
} {1 {couldn't read bitmap file "bad_name": no such file or directory}}
194
test imageBmap-5.3 {GetBitmapData procedure} {
195
eval image delete [image names]
197
list [catch {image create bitmap -data { }} msg] $msg
198
} {1 {format error in bitmap data}}
199
test imageBmap-5.4 {GetBitmapData procedure} {
200
eval image delete [image names]
202
list [catch {image create bitmap -data {#define foo2_width}} msg] $msg
203
} {1 {format error in bitmap data}}
204
test imageBmap-5.5 {GetBitmapData procedure} {
205
eval image delete [image names]
207
list [catch {image create bitmap -data {#define foo2_width gorp}} msg] $msg
208
} {1 {format error in bitmap data}}
209
test imageBmap-5.6 {GetBitmapData procedure} {
210
eval image delete [image names]
212
list [catch {image create bitmap -data {#define foo2_width 1.4}} msg] $msg
213
} {1 {format error in bitmap data}}
214
test imageBmap-5.7 {GetBitmapData procedure} {
215
eval image delete [image names]
217
list [catch {image create bitmap -data {#define foo2_height}} msg] $msg
218
} {1 {format error in bitmap data}}
219
test imageBmap-5.8 {GetBitmapData procedure} {
220
eval image delete [image names]
222
list [catch {image create bitmap -data {#define foo2_height gorp}} msg] $msg
223
} {1 {format error in bitmap data}}
224
test imageBmap-5.9 {GetBitmapData procedure} {
225
eval image delete [image names]
227
list [catch {image create bitmap -data {#define foo2_height 1.4}} msg] $msg
228
} {1 {format error in bitmap data}}
229
test imageBmap-5.10 {GetBitmapData procedure} {
230
eval image delete [image names]
232
image create bitmap i1 -data {
233
#define foo2_height 14
234
#define foo2_width 15 xx _widtg 18 xwidth 18 _heighz 18 xheight 18
235
static char foo2_bits[] = {
236
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
237
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
238
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
241
list [image width i1] [image height i1]
243
test imageBmap-5.11 {GetBitmapData procedure} {
244
eval image delete [image names]
246
image create bitmap i1 -data {
249
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
250
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
251
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
254
list [image width i1] [image height i1]
256
test imageBmap-5.12 {GetBitmapData procedure} {
257
eval image delete [image names]
259
list [catch {image create bitmap i1 -data {
260
#define foo2_height 14
261
#define foo2_width 15
262
static short foo2_bits[] = {
263
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
264
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
265
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
268
} {1 {format error in bitmap data; looks like it's an obsolete X10 bitmap file}}
269
test imageBmap-5.13 {GetBitmapData procedure} {
270
eval image delete [image names]
272
list [catch {image create bitmap i1 -data {
273
#define foo2_height 16
274
#define foo2_width 16
275
static char foo2_bits[] =
276
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
277
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
278
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
281
} {1 {format error in bitmap data}}
282
test imageBmap-5.14 {GetBitmapData procedure} {
283
eval image delete [image names]
285
list [catch {image create bitmap i1 -data {
286
#define foo2_width 16
287
static char foo2_bits[] = {
288
0xff, 0xff, 0xff, }}} msg] $msg
289
} {1 {format error in bitmap data}}
290
test imageBmap-5.15 {GetBitmapData procedure} {
291
eval image delete [image names]
293
list [catch {image create bitmap i1 -data {
294
#define foo2_height 16
295
static char foo2_bits[] = {
296
0xff, 0xff, 0xff, }}} msg] $msg
297
} {1 {format error in bitmap data}}
298
test imageBmap-5.16 {GetBitmapData procedure} {
299
eval image delete [image names]
301
list [catch {image create bitmap i1 -data {
302
#define foo2_height 16
303
#define foo2_width 16
304
static char foo2_bits[] = {
305
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
306
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
307
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
310
} {1 {format error in bitmap data}}
311
test imageBmap-5.17 {GetBitmapData procedure} {
312
eval image delete [image names]
314
list [catch {image create bitmap i1 -data "
315
#define foo2_height 16
316
#define foo2_width 16
317
static char foo2_bits[] = \{
318
0xff, 0xff, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
319
0xff, 0x81, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
320
0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff, 0x81,
323
} {1 {format error in bitmap data}}
325
test imageBmap-6.1 {NextBitmapWord procedure} {
326
eval image delete [image names]
328
list [catch {image create bitmap i1 -data {1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}} msg] $msg
329
} {1 {format error in bitmap data}}
330
test imageBmap-6.2 {NextBitmapWord procedure} {
331
eval image delete [image names]
333
makeFile {1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890} foo3.bm
334
list [catch {image create bitmap i1 -file foo3.bm} msg] $msg
335
} {1 {format error in bitmap data}}
336
test imageBmap-6.3 {NextBitmapWord procedure} {
337
eval image delete [image names]
340
list [catch {image create bitmap i1 -file foo3.bm} msg] $msg
341
} {1 {format error in bitmap data}}
344
eval image delete [image names]
346
image create bitmap i1
347
test imageBmap-7.1 {ImgBmapCmd procedure} {
348
list [catch {i1} msg] $msg
349
} {1 {wrong # args: should be "i1 option ?arg arg ...?"}}
350
test imageBmap-7.2 {ImgBmapCmd procedure, "cget" option} {
351
list [catch {i1 cget} msg] $msg
352
} {1 {wrong # args: should be "i1 cget option"}}
353
test imageBmap-7.3 {ImgBmapCmd procedure, "cget" option} {
354
list [catch {i1 cget a b} msg] $msg
355
} {1 {wrong # args: should be "i1 cget option"}}
356
test imageBmap-7.4 {ImgBmapCmd procedure, "cget" option} {
357
i1 co -foreground #123456
360
test imageBmap-7.5 {ImgBmapCmd procedure, "cget" option} {
361
list [catch {i1 cget -stupid} msg] $msg
362
} {1 {unknown option "-stupid"}}
363
test imageBmap-7.6 {ImgBmapCmd procedure} {
364
llength [i1 configure]
366
test imageBmap-7.7 {ImgBmapCmd procedure} {
367
i1 co -foreground #001122
368
i1 configure -foreground
369
} {-foreground {} {} #000000 #001122}
370
test imageBmap-7.8 {ImgBmapCmd procedure} {
371
list [catch {i1 configure -gorp} msg] $msg
372
} {1 {unknown option "-gorp"}}
373
test imageBmap-7.9 {ImgBmapCmd procedure} {
374
list [catch {i1 configure -foreground #221100 -background} msg] $msg
375
} {1 {value for "-background" missing}}
376
test imageBmap-7.10 {ImgBmapCmd procedure} {
377
list [catch {i1 gorp} msg] $msg
378
} {1 {bad option "gorp": must be cget or configure}}
380
test imageBmap-8.1 {ImgBmapGet/Free procedures, shared instances} {
381
eval image delete [image names]
383
image create bitmap i1 -data $data1
384
.c create image 50 100 -image i1 -tags i1.1
385
.c create image 150 100 -image i1 -tags i1.2
386
.c create image 250 100 -image i1 -tags i1.3
389
i1 configure -background black
392
i1 configure -background white
395
i1 configure -background black
400
test imageBmap-9.1 {ImgBmapDisplay procedure, nothing to display} {
402
eval image delete [image names]
404
image create bitmap i1 -data $data1
405
.c create image 50 100 -image i1 -tags i1.1
406
i1 configure -data {}
409
test imageBmap-9.2 {ImgBmapDisplay procedure, nothing to display} {
411
eval image delete [image names]
413
image create bitmap i1 -data $data1
414
.c create image 50 100 -image i1 -tags i1.1
415
i1 configure -foreground bogus
418
if {[info exists bgerror]} {
422
test imageBmap-10.1 {ImgBmapFree procedure, resource freeing} {
423
eval image delete [image names]
425
image create bitmap i1 -data $data1 -maskdata $data2 -foreground #112233 \
427
.c create image 100 100 -image i1
432
test imageBmap-10.2 {ImgBmapFree procedures, unlinking} {
433
eval image delete [image names]
435
image create bitmap i1 -data $data1 -maskdata $data2 -foreground #112233 \
437
.c create image 100 100 -image i1
452
test imageBmap-11.1 {ImgBmapDelete procedure} {
453
image create bitmap i2 -file foo.bm -maskfile foo2.bm
457
test imageBmap-11.2 {ImgBmapDelete procedure} {
458
image create bitmap i2 -file foo.bm -maskfile foo2.bm
460
set x [list [info command i2] [info command new*] [newi2 cget -file]]
462
lappend x [info command new*]
463
} {{} newi2 foo.bm {}}
465
test imageBmap-12.1 {ImgBmapCmdDeletedProc procedure} {
466
image create bitmap i2 -file foo.bm -maskfile foo2.bm
468
list [lsearch -exact [image names] i2] [catch {i2 foo} msg] $msg
469
} {-1 1 {invalid command name "i2"}}
474
eval image delete [image names]