OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tk/] [tests/] [unixEmbed.test] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file is a Tcl script to test out the procedures in the file
2
# tkUnixEmbed.c.  It is organized in the standard fashion for Tcl
3
# tests.
4
#
5
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
# RCS: @(#) $Id: unixEmbed.test,v 1.1.1.1 2002-01-16 10:26:00 markom Exp $
11
 
12
if {$tcl_platform(platform) != "unix"} {
13
    return
14
}
15
 
16
if {[info procs test] != "test"} {
17
    source defs
18
}
19
 
20
eval destroy [winfo children .]
21
wm geometry . {}
22
raise .
23
 
24
setupbg
25
dobg {wm withdraw .}
26
 
27
# eatColors --
28
# Creates a toplevel window and allocates enough colors in it to
29
# use up all the slots in the colormap.
30
#
31
# Arguments:
32
# w -           Name of toplevel window to create.
33
 
34
proc eatColors {w} {
35
    catch {destroy $w}
36
    toplevel $w
37
    wm geom $w +0+0
38
    canvas $w.c -width 400 -height 200 -bd 0
39
    pack $w.c
40
    for {set y 0} {$y < 8} {incr y} {
41
        for {set x 0} {$x < 40} {incr x} {
42
            set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
43
            $w.c create rectangle [expr 10*$x] [expr 20*$y] \
44
                    [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
45
                    -fill $color
46
        }
47
    }
48
    update
49
}
50
 
51
# colorsFree --
52
#
53
# Returns 1 if there appear to be free colormap entries in a window,
54
# 0 otherwise.
55
#
56
# Arguments:
57
# w -                   Name of window in which to check.
58
# red, green, blue -    Intensities to use in a trial color allocation
59
#                       to see if there are colormap entries free.
60
 
61
proc colorsFree {w {red 31} {green 245} {blue 192}} {
62
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
63
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
64
            && ([lindex $vals 2]/256 == $blue)
65
}
66
 
67
test unixEmbed-1.1 {TkpUseWindow procedure, bad window identifier} {
68
    catch {destroy .t}
69
    list [catch {toplevel .t -use xyz} msg] $msg
70
} {1 {expected integer but got "xyz"}}
71
test unixEmbed-1.2 {TkpUseWindow procedure, bad window identifier} {
72
    catch {destroy .t}
73
    list [catch {toplevel .t -use 47} msg] $msg
74
} {1 {couldn't create child of window "47"}}
75
test unixEmbed-1.3 {TkpUseWindow procedure, inheriting colormap} {
76
    catch {destroy .t}
77
    catch {destroy .x}
78
    toplevel .t -colormap new
79
    wm geometry .t +0+0
80
    eatColors .t.t
81
    frame .t.f -container 1
82
    toplevel .x -use [winfo id .t.f]
83
    set result [colorsFree .x]
84
    destroy .t
85
    set result
86
} {0}
87
test unixEmbed-1.4 {TkpUseWindow procedure, inheriting colormap} {
88
    catch {destroy .t}
89
    catch {destroy .t2}
90
    catch {destroy .x}
91
    toplevel .t -container 1 -colormap new
92
    wm geometry .t +0+0
93
    eatColors .t2
94
    toplevel .x -use [winfo id .t]
95
    set result [colorsFree .x]
96
    destroy .t
97
    set result
98
} {1}
99
 
100
if {[string compare testembed [info commands testembed]] != 0} {
101
    puts "This application hasn't been compiled with the testembed command,"
102
    puts "therefore I am skipping all of these tests."
103
    return
104
}
105
 
106
test unixEmbed-1.5 {TkpUseWindow procedure, creating Container records} {
107
    eval destroy [winfo child .]
108
    frame .f1 -container 1 -width 200 -height 50
109
    frame .f2 -container 1 -width 200 -height 50
110
    pack .f1 .f2
111
    dobg "set w [winfo id .f1]"
112
    dobg {
113
        eval destroy [winfo child .]
114
        toplevel .t -use $w
115
        list [testembed] [expr [lindex [lindex [testembed all] 0] 0] - $w]
116
    }
117
} {{{XXX {} {} .t}} 0}
118
test unixEmbed-1.6 {TkpUseWindow procedure, creating Container records} {
119
    eval destroy [winfo child .]
120
    frame .f1 -container 1 -width 200 -height 50
121
    frame .f2 -container 1 -width 200 -height 50
122
    pack .f1 .f2
123
    dobg "set w1 [winfo id .f1]"
124
    dobg "set w2 [winfo id .f2]"
125
    dobg {
126
        eval destroy [winfo child .]
127
        toplevel .t1 -use $w1
128
        toplevel .t2 -use $w2
129
        testembed
130
    }
131
} {{XXX {} {} .t2} {XXX {} {} .t1}}
132
test unixEmbed-1.7 {TkpUseWindow procedure, container and embedded in same app} {
133
    eval destroy [winfo child .]
134
    frame .f1 -container 1 -width 200 -height 50
135
    frame .f2 -container 1 -width 200 -height 50
136
    pack .f1 .f2
137
    toplevel .t1 -use [winfo id .f1]
138
    toplevel .t2 -use [winfo id .f2]
139
    testembed
140
} {{XXX .f2 {} .t2} {XXX .f1 {} .t1}}
141
 
142
# Can't think of any way to test the procedures TkpMakeWindow,
143
# TkpMakeContainer, or EmbedErrorProc.
144
 
145
test unixEmbed-2.1 {EmbeddedEventProc procedure} {
146
    foreach w [winfo child .] {
147
        catch {destroy $w}
148
    }
149
    frame .f1 -container 1 -width 200 -height 50
150
    pack .f1
151
    dobg "set w1 [winfo id .f1]"
152
    dobg {
153
        eval destroy [winfo child .]
154
        toplevel .t1 -use $w1
155
        testembed
156
    }
157
    destroy .f1
158
    update
159
    dobg {
160
        testembed
161
    }
162
} {}
163
test unixEmbed-2.2 {EmbeddedEventProc procedure} {
164
    foreach w [winfo child .] {
165
        catch {destroy $w}
166
    }
167
    frame .f1 -container 1 -width 200 -height 50
168
    pack .f1
169
    dobg "set w1 [winfo id .f1]"
170
    dobg {
171
        eval destroy [winfo child .]
172
        toplevel .t1 -use $w1
173
        testembed
174
        destroy .t1
175
        testembed
176
    }
177
} {}
178
test unixEmbed-2.3 {EmbeddedEventProc procedure} {
179
    foreach w [winfo child .] {
180
        catch {destroy $w}
181
    }
182
    frame .f1 -container 1 -width 200 -height 50
183
    pack .f1
184
    toplevel .t1 -use [winfo id .f1]
185
    update
186
    destroy .f1
187
    testembed
188
} {}
189
test unixEmbed-2.4 {EmbeddedEventProc procedure} {
190
    foreach w [winfo child .] {
191
        catch {destroy $w}
192
    }
193
    frame .f1 -container 1 -width 200 -height 50
194
    pack .f1
195
    toplevel .t1 -use [winfo id .f1]
196
    update
197
    destroy .t1
198
    set x [testembed]
199
    update
200
    list $x [testembed]
201
} {{{XXX .f1 {} {}}} {}}
202
 
203
test unixEmbed-3.1 {ContainerEventProc procedure, detect creation} {
204
    foreach w [winfo child .] {
205
        catch {destroy $w}
206
    }
207
    frame .f1 -container 1 -width 200 -height 50
208
    pack .f1
209
    dobg "set w1 [winfo id .f1]"
210
    set x [testembed]
211
    dobg {
212
        eval destroy [winfo child .]
213
        toplevel .t1 -use $w1
214
        wm withdraw .t1
215
    }
216
    list $x [testembed]
217
} {{{XXX .f1 {} {}}} {{XXX .f1 XXX {}}}}
218
test unixEmbed-3.2 {ContainerEventProc procedure, set size on creation} {
219
    foreach w [winfo child .] {
220
        catch {destroy $w}
221
    }
222
    toplevel .t1 -container 1
223
    wm geometry .t1 +0+0
224
    toplevel .t2 -use [winfo id .t1] -bg red
225
    update
226
    wm geometry .t2
227
} {200x200+0+0}
228
test unixEmbed-3.2 {ContainerEventProc procedure, disallow position changes} {
229
    foreach w [winfo child .] {
230
        catch {destroy $w}
231
    }
232
    frame .f1 -container 1 -width 200 -height 50
233
    pack .f1
234
    dobg "set w1 [winfo id .f1]"
235
    dobg {
236
        eval destroy [winfo child .]
237
        toplevel .t1 -use $w1 -bd 2 -relief raised
238
        update
239
        wm geometry .t1 +30+40
240
    }
241
    update
242
    dobg {
243
        wm geometry .t1
244
    }
245
} {200x200+0+0}
246
test unixEmbed-3.3 {ContainerEventProc procedure, disallow position changes} {
247
    foreach w [winfo child .] {
248
        catch {destroy $w}
249
    }
250
    frame .f1 -container 1 -width 200 -height 50
251
    pack .f1
252
    dobg "set w1 [winfo id .f1]"
253
    dobg {
254
        eval destroy [winfo child .]
255
        toplevel .t1 -use $w1
256
        update
257
        wm geometry .t1 300x100+30+40
258
    }
259
    update
260
    dobg {
261
        wm geometry .t1
262
    }
263
} {300x100+0+0}
264
test unixEmbed-3.4 {ContainerEventProc procedure, geometry requests} {
265
    foreach w [winfo child .] {
266
        catch {destroy $w}
267
    }
268
    frame .f1 -container 1 -width 200 -height 50
269
    pack .f1
270
    dobg "set w1 [winfo id .f1]"
271
    dobg {
272
        eval destroy [winfo child .]
273
        toplevel .t1 -use $w1
274
    }
275
    update
276
    dobg {
277
        .t1 configure -width 300 -height 80
278
    }
279
    update
280
    list [winfo width .f1] [winfo height .f1] [dobg {wm geometry .t1}]
281
} {300 80 300x80+0+0}
282
test unixEmbed-3.5 {ContainerEventProc procedure, map requests} {
283
    foreach w [winfo child .] {
284
        catch {destroy $w}
285
    }
286
    frame .f1 -container 1 -width 200 -height 50
287
    pack .f1
288
    dobg "set w1 [winfo id .f1]"
289
    dobg {
290
        eval destroy [winfo child .]
291
        toplevel .t1 -use $w1
292
        set x unmapped
293
        bind .t1  {set x mapped}
294
    }
295
    update
296
    dobg {
297
        after 100
298
        update
299
        set x
300
    }
301
} {mapped}
302
test unixEmbed-3.6 {ContainerEventProc procedure, destroy events} {
303
    foreach w [winfo child .] {
304
        catch {destroy $w}
305
    }
306
    frame .f1 -container 1 -width 200 -height 50
307
    pack .f1
308
    dobg "set w1 [winfo id .f1]"
309
    bind .f1  {set x dead}
310
    set x alive
311
    dobg {
312
        eval destroy [winfo child .]
313
        toplevel .t1 -use $w1
314
    }
315
    update
316
    dobg {
317
        destroy .t1
318
    }
319
    update
320
    list $x [winfo exists .f1]
321
} {dead 0}
322
 
323
test unixEmbed-4.1 {EmbedStructureProc procedure, configure events} {
324
    foreach w [winfo child .] {
325
        catch {destroy $w}
326
    }
327
    frame .f1 -container 1 -width 200 -height 50
328
    pack .f1
329
    dobg "set w1 [winfo id .f1]"
330
    dobg {
331
        eval destroy [winfo child .]
332
        toplevel .t1 -use $w1
333
    }
334
    update
335
    dobg {
336
        .t1 configure -width 180 -height 100
337
    }
338
    update
339
    dobg {
340
        winfo geometry .t1
341
    }
342
} {180x100+0+0}
343
test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} {
344
    foreach w [winfo child .] {
345
        catch {destroy $w}
346
    }
347
    frame .f1 -container 1 -width 200 -height 50
348
    pack .f1
349
    dobg "set w1 [winfo id .f1]"
350
    dobg {
351
        eval destroy [winfo child .]
352
        toplevel .t1 -use $w1
353
    }
354
    update
355
    set x [testembed]
356
    destroy .f1
357
    list $x [testembed]
358
} {{{XXX .f1 XXX {}}} {}}
359
 
360
test unixEmbed-5.1 {EmbedFocusProc procedure, FocusIn events} {
361
    foreach w [winfo child .] {
362
        catch {destroy $w}
363
    }
364
    frame .f1 -container 1 -width 200 -height 50
365
    pack .f1
366
    dobg "set w1 [winfo id .f1]"
367
    dobg {
368
        eval destroy [winfo child .]
369
        toplevel .t1 -use $w1
370
        bind .t1  {lappend x "focus in %W"}
371
        bind .t1  {lappend x "focus out %W"}
372
        set x {}
373
    }
374
    focus -force .f1
375
    update
376
    dobg {set x}
377
} {{focus in .t1}}
378
test unixEmbed-5.2 {EmbedFocusProc procedure, focusing on dead window} {
379
    foreach w [winfo child .] {
380
        catch {destroy $w}
381
    }
382
    frame .f1 -container 1 -width 200 -height 50
383
    pack .f1
384
    dobg "set w1 [winfo id .f1]"
385
    dobg {
386
        eval destroy [winfo child .]
387
        toplevel .t1 -use $w1
388
    }
389
    update
390
    dobg {
391
        after 200 {destroy .t1}
392
    }
393
    after 400
394
    focus -force .f1
395
    update
396
} {}
397
test unixEmbed-5.3 {EmbedFocusProc procedure, FocusOut events} {
398
    foreach w [winfo child .] {
399
        catch {destroy $w}
400
    }
401
    frame .f1 -container 1 -width 200 -height 50
402
    pack .f1
403
    dobg "set w1 [winfo id .f1]"
404
    dobg {
405
        eval destroy [winfo child .]
406
        toplevel .t1 -use $w1
407
        bind .t1  {lappend x "focus in %W"}
408
        bind .t1  {lappend x "focus out %W"}
409
        set x {}
410
    }
411
    focus -force .f1
412
    update
413
    set x [dobg {update; set x}]
414
    focus .
415
    update
416
    list $x [dobg {update; set x}]
417
} {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}
418
 
419
test unixEmbed-6.1 {EmbedGeometryRequest procedure, window changes size} {
420
    foreach w [winfo child .] {
421
        catch {destroy $w}
422
    }
423
    frame .f1 -container 1 -width 200 -height 50
424
    pack .f1
425
    dobg "set w1 [winfo id .f1]"
426
    dobg {
427
        eval destroy [winfo child .]
428
        toplevel .t1 -use $w1
429
    }
430
    update
431
    dobg {
432
        bind .t1  {lappend x {configure .t1 %w %h}}
433
        set x {}
434
        .t1 configure -width 300 -height 120
435
        update
436
        list $x [winfo geom .t1]
437
    }
438
} {{{configure .t1 300 120}} 300x120+0+0}
439
test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} {
440
    foreach w [winfo child .] {
441
        catch {destroy $w}
442
    }
443
    frame .f1 -container 1 -width 200 -height 50
444
    place .f1 -width 200 -height 200
445
    dobg "set w1 [winfo id .f1]"
446
    dobg {
447
        eval destroy [winfo child .]
448
        toplevel .t1 -use $w1
449
    }
450
    after 300 {set x done}
451
    vwait x
452
    dobg {
453
        bind .t1  {lappend x {configure .t1 %w %h}}
454
        set x {}
455
        .t1 configure -width 300 -height 120
456
        update
457
        list $x [winfo geom .t1]
458
    }
459
} {{{configure .t1 200 200}} 200x200+0+0}
460
 
461
# Can't think up any tests for TkpGetOtherWindow procedure.
462
 
463
test unixEmbed-7.1 {TkpRedirectKeyEvent procedure, forward keystroke} {
464
    foreach w [winfo child .] {
465
        catch {destroy $w}
466
    }
467
    frame .f1 -container 1 -width 200 -height 50
468
    pack .f1
469
    dobg "set w1 [winfo id .f1]"
470
    dobg {
471
        eval destroy [winfo child .]
472
        toplevel .t1 -use $w1
473
    }
474
    focus -force .
475
    bind .  {lappend x {key %A %E}}
476
    set x {}
477
    set y [dobg {
478
        update
479
        bind .t1  {lappend y {key %A}}
480
        set y {}
481
        event generate .t1  -keysym a
482
        set y
483
    }]
484
    update
485
    bind .  {}
486
    list $x $y
487
} {{{key a 1}} {}}
488
test unixEmbed-7.2 {TkpRedirectKeyEvent procedure, don't forward keystroke width} {
489
    foreach w [winfo child .] {
490
        catch {destroy $w}
491
    }
492
    frame .f1 -container 1 -width 200 -height 50
493
    pack .f1
494
    dobg "set w1 [winfo id .f1]"
495
    dobg {
496
        eval destroy [winfo child .]
497
        toplevel .t1 -use $w1
498
    }
499
    update
500
    focus -force .f1
501
    update
502
    bind .  {lappend x {key %A}}
503
    set x {}
504
    set y [dobg {
505
        update
506
        bind .t1  {lappend y {key %A}}
507
        set y {}
508
        event generate .t1  -keysym b
509
        set y
510
    }]
511
    update
512
    bind .  {}
513
    list $x $y
514
} {{} {{key b}}}
515
 
516
test unixEmbed-8.1 {TkpClaimFocus procedure} {
517
    foreach w [winfo child .] {
518
        catch {destroy $w}
519
    }
520
    frame .f1 -container 1 -width 200 -height 50
521
    frame .f2 -width 200 -height 50
522
    pack .f1 .f2
523
    dobg "set w1 [winfo id .f1]"
524
    dobg {
525
        eval destroy [winfo child .]
526
        toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
527
    }
528
    focus -force .f2
529
    update
530
    list [dobg {
531
        focus .t1
532
        set x [list [focus]]
533
        update
534
        after 500
535
        update
536
        lappend x [focus]
537
    }] [focus]
538
} {{{} .t1} .f1}
539
test unixEmbed-8.2 {TkpClaimFocus procedure} {
540
    catch {interp delete child}
541
    foreach w [winfo child .] {
542
        catch {destroy $w}
543
    }
544
    frame .f1 -container 1 -width 200 -height 50
545
    frame .f2 -width 200 -height 50
546
    pack .f1 .f2
547
    interp create child
548
    child eval "set argv {-use [winfo id .f1]}"
549
    load {} tk child
550
    child eval {
551
        . configure -bd 2 -highlightthickness 2 -relief sunken
552
    }
553
    focus -force .f2
554
    update
555
    list [child eval {
556
        focus .
557
        set x [list [focus]]
558
        update
559
        lappend x [focus]
560
    }] [focus]
561
} {{{} .} .f1}
562
catch {interp delete child}
563
 
564
test unixEmbed-9.1 {EmbedWindowDeleted procedure, check parentPtr} {
565
    foreach w [winfo child .] {
566
        catch {destroy $w}
567
    }
568
    frame .f1 -container 1 -width 200 -height 50
569
    frame .f2 -container 1 -width 200 -height 50
570
    frame .f3 -container 1 -width 200 -height 50
571
    frame .f4 -container 1 -width 200 -height 50
572
    pack .f1 .f2 .f3 .f4
573
    set x {}
574
    lappend x [testembed]
575
    foreach w {.f3 .f4 .f1 .f2} {
576
        destroy $w
577
        lappend x [testembed]
578
    }
579
    set x
580
} {{{XXX .f4 {} {}} {XXX .f3 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f4 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}}} {}}
581
test unixEmbed-9.2 {EmbedWindowDeleted procedure, check embeddedPtr} {
582
    foreach w [winfo child .] {
583
        catch {destroy $w}
584
    }
585
    frame .f1 -container 1 -width 200 -height 50
586
    pack .f1
587
    dobg "set w1 [winfo id .f1]"
588
    dobg {
589
        eval destroy [winfo child .]
590
        toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
591
        set x {}
592
        lappend x [testembed]
593
        destroy .t1
594
        lappend x [testembed]
595
    }
596
} {{{XXX {} {} .t1}} {}}
597
 
598
test unixEmbed-10.1 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} {
599
    foreach w [winfo child .] {
600
        catch {destroy $w}
601
    }
602
    frame .f1 -container 1 -width 200 -height 50
603
    pack .f1
604
    toplevel .t1 -use [winfo id .f1] -width 150 -height 80
605
    update
606
    wm geometry .t1 +40+50
607
    update
608
    wm geometry .t1
609
} {150x80+0+0}
610
test unixEmbed-10.2 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} {
611
    foreach w [winfo child .] {
612
        catch {destroy $w}
613
    }
614
    frame .f1 -container 1 -width 200 -height 50
615
    pack .f1
616
    toplevel .t1 -use [winfo id .f1] -width 150 -height 80
617
    update
618
    wm geometry .t1 70x300+10+20
619
    update
620
    wm geometry .t1
621
} {70x300+0+0}
622
 
623
 
624
foreach w [winfo child .] {
625
    catch {destroy $w}
626
}
627
cleanupbg

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.