summaryrefslogtreecommitdiffstats
path: root/tk8.6/tests/visual.test
blob: 2f5c34ac1b1c4b6fd6e4901bb33f90261bcc9f83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# This file is a Tcl script to test the visual- and colormap-handling
# procedures in the file tkVisual.c.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

update

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -        Name of toplevel window to create.

proc eatColors {w} {
    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
        for {set x 0} {$x < 40} {incr x} {
            set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
            $w.c create rectangle [expr 10*$x] [expr 20*$y] \
                [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
                -fill $color
        }
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -            Name of window in which to check.
# red, green, blue -    Intensities to use in a trial color allocation
#            to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
        && ([lindex $vals 2]/256 == $blue)
}

# If more than one visual type is available for the screen, pick one
# that is *not* the default.

set default "[winfo visual .] [winfo depth .]"
set avail [winfo visualsavailable .]
set other {}
if {[llength $avail] > 1} {
    foreach visual $avail {
        if {$visual != $default} {
            set other $visual
            break
        }
    }
}
testConstraint haveOtherVisual [expr {$other ne ""}]
testConstraint havePseudocolorVisual [string match *pseudocolor* $avail]
testConstraint haveMultipleVisuals [expr {[llength $avail] > 1}]

# ----------------------------------------------------------------------

test visual-1.1 {Tk_GetVisual, copying from other window} -body {
    toplevel .t -visual .foo.bar
} -returnCodes error -result {bad window path name ".foo.bar"}
test visual-1.2 {Tk_GetVisual, copying from other window} -constraints {
    haveOtherVisual nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual $other
    wm geom .t1 +0+0
    toplevel .t2 -width 200 -height 80 -visual .t1
    wm geom .t2 +5+5
    concat "[winfo visual .t2] [winfo depth .t2]"
} -cleanup {
    deleteWindows
} -result $other
test visual-1.3 {Tk_GetVisual, copying from other window} -constraints {
    haveOtherVisual
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual $other
    wm geom .t1 +0+0
    toplevel .t2 -width 200 -height 80 -visual .
    wm geom .t2 +5+5
    concat "[winfo visual .t2] [winfo depth .t2]"
} -cleanup {
    deleteWindows
} -result $default
# Make sure reference count is incremented when copying visual (the
# following test will cause the colormap to be freed prematurely if
# the reference count isn't incremented).
test visual-1.4 {Tk_GetVisual, colormap reference count} -constraints {
    haveOtherVisual
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual $other
    wm geom .t1 +0+0
    set result [toplevel .t2 -gorp 80 -visual .t1]
    update
    return $result
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown option "-gorp"}
test visual-1.5 {Tk_GetVisual, default colormap} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual default
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result $default


test visual-2.1 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.2 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.3 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.4 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.5 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.6 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.7 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.8 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 24}
test visual-2.9 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.10 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.11 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.12 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.13 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.14 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.15 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.16 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {directcolor 24}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {directcolor 24}
test visual-2.17 {Tk_GetVisual, different visual types} -constraints {
    nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual {truecolor 32}
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result {truecolor 32}


test visual-3.1 {Tk_GetVisual, parsing visual string} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 \
        -visual "[winfo visual .][winfo depth .]"
    wm geometry .t1 +0+0
    update
    concat "[winfo visual .t1] [winfo depth .t1]"
} -cleanup {
    deleteWindows
} -result $default
test visual-3.2 {Tk_GetVisual, parsing visual string} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual goop20
    wm geometry .t1 +0+0
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown or ambiguous visual name "goop20": class must be best, directcolor, grayscale, greyscale, pseudocolor, staticcolor, staticgray, staticgrey, truecolor, or default}
test visual-3.3 {Tk_GetVisual, parsing visual string} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual d
    wm geometry .t1 +0+0
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown or ambiguous visual name "d": class must be best, directcolor, grayscale, greyscale, pseudocolor, staticcolor, staticgray, staticgrey, truecolor, or default}
test visual-3.4 {Tk_GetVisual, parsing visual string} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual static
    wm geometry .t1 +0+0
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown or ambiguous visual name "static": class must be best, directcolor, grayscale, greyscale, pseudocolor, staticcolor, staticgray, staticgrey, truecolor, or default}
test visual-3.5 {Tk_GetVisual, parsing visual string} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual "pseudocolor 48x"
    wm geometry .t1 +0+0
} -cleanup {
    deleteWindows
} -returnCodes error -result {expected integer but got "48x"}


test visual-4.1 {Tk_GetVisual, numerical visual id}  -constraints {
    haveOtherVisual nonPortable
} -setup {
    deleteWindows
    toplevel .t1 -width 250 -height 100 -visual $other
    wm geom .t1 +0+0
    toplevel .t2 -width 200 -height 80 -visual [winfo visual .]
    wm geom .t2 +5+5
    toplevel .t3 -width 150 -height 250 -visual [winfo visual .t1]
    wm geom .t3 +10+10
} -body {
    set v1 [list [winfo visualid .t2] [winfo visualid .t3]]
    set v2 [list [winfo visualid .] [winfo visualid .t1]]
    expr {$v1 eq $v2 ? "OK" : "[list $v1] ne [list $v2]"}
} -cleanup {
    deleteWindows
} -result OK
test visual-4.2 {Tk_GetVisual, numerical visual id} -setup {
    deleteWindows
} -body {
    toplevel .t1 -visual 12xyz
} -cleanup {
    deleteWindows
} -returnCodes error -result {bad X identifier for visual: "12xyz"}
test visual-4.3 {Tk_GetVisual, numerical visual id} -setup {
    deleteWindows
} -body {
    toplevel .t1 -visual 1291673
} -cleanup {
    deleteWindows
} -returnCodes error -result {couldn't find an appropriate visual}


test visual-5.1 {Tk_GetVisual, no matching visual} -constraints {
    !havePseudocolorVisual
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual "pseudocolor 8"
    wm geometry .t1 +0+0
} -cleanup {
    deleteWindows
} -returnCodes error -result {couldn't find an appropriate visual}


test visual-6.1 {Tk_GetVisual, no matching visual} -constraints {
    havePseudocolorVisual haveMultipleVisuals nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 250 -height 100 -visual "best"
    wm geometry .t1 +0+0
    update
    winfo visual .t1
} -cleanup {
    deleteWindows
} -result {pseudocolor}


# These tests are non-portable due to variations in how many colors
# are already in use on the screen.
test visual-7.1 {Tk_GetColormap, "new"} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t2 -width 30 -height 20
    wm geom .t2 +0+0
    update
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result {0}
test visual-7.2 {Tk_GetColormap, "new"} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t2 -width 30 -height 20 -colormap new
    wm geom .t2 +0+0
    update
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result {1}
test visual-7.3 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t3 -width 400 -height 50 -colormap new
    wm geom .t3 +0+0
    toplevel .t2 -width 30 -height 20 -colormap .t3
    wm geom .t2 +0+0
    update
    destroy .t3
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result {1}
test visual-7.4 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t3 -width 400 -height 50 -colormap new
    wm geom .t3 +0+0
    toplevel .t2 -width 30 -height 20 -colormap .
    wm geom .t2 +0+0
    update
    destroy .t3
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result {0}
test visual-7.5 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 400 -height 50 -colormap .choke.lots
} -cleanup {
    deleteWindows
} -returnCodes error -result {bad window path name ".choke.lots"}
test visual-7.6 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 haveOtherVisual nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 300 -height 150 -visual $other
    wm geometry .t1 +0+0
    toplevel .t2 -width 400 -height 50 -colormap .t1
} -cleanup {
    deleteWindows
} -returnCodes error -result {can't use colormap for .t1: incompatible visuals}


test visual-8.1 {Tk_FreeColormap procedure} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 300 -height 180 -colormap new
    wm geometry .t1 +0+0
    foreach i {.t2 .t3 .t4} {
        toplevel $i -width 250 -height 150 -colormap .t1
        wm geometry $i +0+0
    }
    destroy .t1
    destroy .t3
    destroy .t4
    update
} -cleanup {
    deleteWindows
} -result {}
test visual-8.2 {Tk_FreeColormap procedure} -constraints haveOtherVisual -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 300 -height 180 -visual $other
    wm geometry .t1 +0+0
    foreach i {.t2 .t3 .t4} {
        toplevel $i -width 250 -height 150 -visual $other
        wm geometry $i +0+0
    }
    destroy .t2
    destroy .t3
    destroy .t4
    update
} -cleanup {
    deleteWindows
} -result {}


deleteWindows
rename eatColors {}
rename colorsFree {}

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End: