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
|
# This file is a Tcl script to test out the "place" command. It is
# organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
# Used for constraining memory leak tests
testConstraint memory [llength [info commands memory]]
# XXX - This test file is woefully incomplete. At present, only a
# few of the features are tested.
# Widgets used in tests 1.* - 8.*
toplevel .t -width 300 -height 200 -bd 0
wm geom .t +0+0
frame .t.f -width 154 -height 84 -bd 2 -relief raised
place .t.f -x 48 -y 38
frame .t.f2 -width 30 -height 60 -bd 2 -relief raised
update
test place-1.1 {Tk_PlaceCmd procedure, "info" option} -setup {
place forget .t.f2
} -body {
place .t.f2 -x 0
place info .t.f2
} -result {-in .t -x 0 -relx 0 -y 0 -rely 0 -width {} -relwidth {} -height {} -relheight {} -anchor nw -bordermode inside}
test place-1.2 {Tk_PlaceCmd procedure, "info" option} -setup {
place forget .t.f2
} -body {
place .t.f2 -x 1 -y 2 -width 3 -height 4 -relx 0.1 -rely 0.2 \
-relwidth 0.3 -relheight 0.4 -anchor se -in .t.f \
-bordermode outside
place info .t.f2
} -result {-in .t.f -x 1 -relx 0.1 -y 2 -rely 0.2 -width 3 -relwidth 0.3 -height 4 -relheight 0.4 -anchor se -bordermode outside}
test place-1.3 {Tk_PlaceCmd procedure, "info" option} -setup {
place forget .t.f2
destroy .t.a.b
} -body {
# Make sure the result is built as a proper list by using a space in parent
frame ".t.a b"
place .t.f2 -x 1 -y 2 -width {} -height 4 -relx 0.2 -rely 0.2 \
-relwidth 0.3 -relheight {} -anchor w -in ".t.a b" \
-bordermode ignore
place info .t.f2
} -cleanup {
destroy ".t.a.b"
} -result {-in {.t.a b} -x 1 -relx 0.2 -y 2 -rely 0.2 -width {} -relwidth 0.3 -height 4 -relheight {} -anchor w -bordermode ignore}
test place-2.1 {ConfigureSlave procedure, -height option} -body {
place .t.f2 -height abcd
} -returnCodes error -result {bad screen distance "abcd"}
test place-2.2 {ConfigureSlave procedure, -height option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -height 40
update
winfo height .t.f2
} -result {40}
test place-2.3 {ConfigureSlave procedure, -height option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -height 120
update
place .t.f2 -height {}
update
winfo height .t.f2
} -result {60}
test place-3.1 {ConfigureSlave procedure, -relheight option} -body {
place .t.f2 -relheight abcd
} -returnCodes error -result {expected floating-point number but got "abcd"}
test place-3.2 {ConfigureSlave procedure, -relheight option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -relheight .5
update
winfo height .t.f2
} -result {40}
test place-3.3 {ConfigureSlave procedure, -relheight option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -relheight .8
update
place .t.f2 -relheight {}
update
winfo height .t.f2
} -result {60}
test place-4.1 {ConfigureSlave procedure, bad -in options} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f2
} -returnCodes error -result {can't place .t.f2 relative to itself}
test place-4.2 {ConfigureSlave procedure, bad -in option} -setup {
place forget .t.f2
} -body {
set result [list [winfo manager .t.f2]]
catch {place .t.f2 -in .t.f2}
lappend result [winfo manager .t.f2]
} -result {{} {}}
test place-4.3 {ConfigureSlave procedure, bad -in option} -setup {
place forget .t.f2
} -body {
winfo manager .t.f2
place .t.f2 -in .t.f2
} -returnCodes error -result {can't place .t.f2 relative to itself}
test place-4.4 {ConfigureSlave procedure, bad -in option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .
} -returnCodes error -result {can't place .t.f2 relative to .}
test place-4.5 {ConfigureSlave procedure, bad -in option} -setup {
} -body {
frame .t.f1
place .t.f1 -in .t.f1
} -returnCodes error -result {can't place .t.f1 relative to itself}
test place-4.6 {prevent management loops} -setup {
place forget .t.f1
} -body {
place .t.f1 -in .t.f2
place .t.f2 -in .t.f1
} -returnCodes error -result {can't put .t.f2 inside .t.f1, would cause management loop}
test place-4.7 {prevent management loops} -setup {
place forget .t.f1
place forget .t.f2
} -body {
frame .t.f3
place .t.f1 -in .t.f2
place .t.f2 -in .t.f3
place .t.f3 -in .t.f1
} -returnCodes error -result {can't put .t.f3 inside .t.f1, would cause management loop}
test place-5.1 {ConfigureSlave procedure, -relwidth option} -body {
place .t.f2 -relwidth abcd
} -returnCodes error -result {expected floating-point number but got "abcd"}
test place-5.2 {ConfigureSlave procedure, -relwidth option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -relwidth .5
update
winfo width .t.f2
} -result {75}
test place-5.3 {ConfigureSlave procedure, -relwidth option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -relwidth .8
update
place .t.f2 -relwidth {}
update
winfo width .t.f2
} -result {30}
test place-6.1 {ConfigureSlave procedure, -width option} -body {
place .t.f2 -width abcd
} -returnCodes error -result {bad screen distance "abcd"}
test place-6.2 {ConfigureSlave procedure, -width option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -width 100
update
winfo width .t.f2
} -result {100}
test place-6.3 {ConfigureSlave procedure, -width option} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -width 120
update
place .t.f2 -width {}
update
winfo width .t.f2
} -result {30}
test place-7.1 {ReconfigurePlacement procedure, computing position} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -x -2 -relx .5 -y 3 -rely .4
update
winfo geometry .t.f2
} -result {30x60+123+75}
test place-7.2 {ReconfigurePlacement procedure, position rounding} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -x -1.4 -y -2.3
update
winfo geometry .t.f2
} -result {30x60+49+38}
test place-7.3 {ReconfigurePlacement procedure, position rounding} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -x 1.4 -y 2.3
update
winfo geometry .t.f2
} -result {30x60+51+42}
test place-7.4 {ReconfigurePlacement procedure, position rounding} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -x -1.6 -y -2.7
update
winfo geometry .t.f2
} -result {30x60+48+37}
test place-7.5 {ReconfigurePlacement procedure, position rounding} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -x 1.6 -y 2.7
update
winfo geometry .t.f2
} -result {30x60+52+43}
test place-7.6 {ReconfigurePlacement procedure, position rounding} -setup {
destroy .t.f3
} -body {
frame .t.f3 -width 100 -height 100 -bg #f00000 -bd 0
place .t.f3 -x 0 -y 0
raise .t.f2
place forget .t.f2
place .t.f2 -in .t.f3 -relx .303 -rely .406 -relwidth .304 -relheight .206
update
winfo geometry .t.f2
} -cleanup {
destroy .t.f3
} -result {31x20+30+41}
test place-7.7 {ReconfigurePlacement procedure, computing size} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -width 120 -height 89
update
list [winfo width .t.f2] [winfo height .t.f2]
} -result {120 89}
test place-7.8 {ReconfigurePlacement procedure, computing size} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -relwidth .4 -relheight .5
update
list [winfo width .t.f2] [winfo height .t.f2]
} -result {60 40}
test place-7.9 {ReconfigurePlacement procedure, computing size} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -width 10 -relwidth .4 -height -4 -relheight .5
update
list [winfo width .t.f2] [winfo height .t.f2]
} -result {70 36}
test place-7.10 {ReconfigurePlacement procedure, computing size} -setup {
place forget .t.f2
} -body {
place .t.f2 -in .t.f -width 10 -relwidth .4 -height -4 -relheight .5
place .t.f2 -width {} -relwidth {} -height {} -relheight {}
update
list [winfo width .t.f2] [winfo height .t.f2]
} -result {30 60}
test place-8.1 {MasterStructureProc, mapping and unmapping slaves} -setup {
place forget .t.f2
place forget .t.f
} -body {
place .t.f2 -relx 1.0 -rely 1.0 -anchor sw
update idletasks
set result [winfo ismapped .t.f2]
wm iconify .t
update idletasks
lappend result [winfo ismapped .t.f2]
place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
update idletasks
lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
wm deiconify .t
update idletasks
lappend result [winfo ismapped .t.f2]
} -result {1 0 40 30 0 1}
test place-8.2 {MasterStructureProc, mapping and unmapping slaves} -setup {
place forget .t.f2
place forget .t.f
update idletasks
} -body {
place .t.f -x 0 -y 0 -width 200 -height 100
place .t.f2 -in .t.f -relx 1.0 -rely 1.0 -anchor sw -width 50 -height 20
update idletasks
set result [winfo ismapped .t.f2]
wm iconify .t
update idletasks
lappend result [winfo ismapped .t.f2]
place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
update idletasks
lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
wm deiconify .t
update idletasks
lappend result [winfo ismapped .t.f2]
} -result {1 0 42 32 0 1}
destroy .t
test place-9.1 {PlaceObjCmd} -body {
place
} -returnCodes error -result {wrong # args: should be "place option|pathName args"}
test place-9.2 {PlaceObjCmd} -body {
place foo
} -returnCodes error -result {wrong # args: should be "place option|pathName args"}
test place-9.3 {PlaceObjCmd} -setup {
destroy .foo
} -body {
place .foo bar
} -returnCodes error -result {bad window path name ".foo"}
test place-9.4 {PlaceObjCmd} -setup {
destroy .foo
} -body {
place bar .foo
} -cleanup {
destroy .foo
} -returnCodes error -result {bad window path name ".foo"}
test place-9.5 {PlaceObjCmd} -setup {
destroy .foo
} -body {
frame .foo
place badopt .foo
} -cleanup {
destroy .foo
} -returnCodes error -result {bad option "badopt": must be configure, forget, info, or slaves}
test place-9.6 {PlaceObjCmd, configure errors} -setup {
destroy .foo
} -body {
frame .foo
place configure .foo
} -cleanup {
destroy .foo
} -returnCodes ok -result {}
test place-9.7 {PlaceObjCmd, configure errors} -setup {
destroy .foo
} -body {
frame .foo
place configure .foo bar
} -cleanup {
destroy .foo
} -returnCodes ok -result {}
test place-9.8 {PlaceObjCmd, configure} -setup {
destroy .foo
} -body {
frame .foo
place .foo -x 0 -y 0
place configure .foo
} -cleanup {
destroy .foo
} -result [list {-anchor {} {} nw nw} {-bordermode {} {} inside inside} {-height {} {} {} {}} {-in {} {} {} .} {-relheight {} {} {} {}} {-relwidth {} {} {} {}} {-relx {} {} 0 0.0} {-rely {} {} 0 0.0} {-width {} {} {} {}} {-x {} {} 0 0} {-y {} {} 0 0}]
test place-9.9 {PlaceObjCmd, configure} -setup {
destroy .foo
} -body {
frame .foo
place .foo -x 0 -y 0
place configure .foo -x
} -cleanup {
destroy .foo
} -result {-x {} {} 0 0}
test place-9.10 {PlaceObjCmd, forget errors} -setup {
destroy .foo
} -body {
frame .foo
place forget .foo bar
} -cleanup {
destroy .foo
} -returnCodes error -result {wrong # args: should be "place forget pathName"}
test place-9.11 {PlaceObjCmd, info errors} -setup {
destroy .foo
} -body {
frame .foo
place info .foo bar
} -cleanup {
destroy .foo
} -returnCodes error -result {wrong # args: should be "place info pathName"}
test place-9.12 {PlaceObjCmd, slaves errors} -setup {
destroy .foo
} -body {
frame .foo
place slaves .foo bar
} -cleanup {
destroy .foo
} -returnCodes error -result {wrong # args: should be "place slaves pathName"}
test place-10.1 {ConfigureSlave} -setup {
destroy .foo
} -body {
frame .foo
place .foo -badopt
} -cleanup {
destroy .foo
} -returnCodes error -result {unknown option "-badopt"}
test place-10.2 {ConfigureSlave} -setup {
destroy .foo
} -body {
frame .foo
place .foo -anchor
} -cleanup {
destroy .foo
} -returnCodes error -result {value for "-anchor" missing}
test place-10.3 {ConfigureSlave} -setup {
destroy .foo
} -body {
frame .foo
place .foo -bordermode j
} -cleanup {
destroy .foo
} -returnCodes error -result {bad bordermode "j": must be inside, outside, or ignore}
test place-10.4 {ConfigureSlave} -setup {
destroy .foo
} -body {
frame .foo
place configure .foo -x 0 -y
} -cleanup {
destroy .foo
} -returnCodes error -result {value for "-y" missing}
test place-11.1 {PlaceObjCmd, slaves command} -setup {
destroy .foo
} -body {
frame .foo
place slaves .foo
} -cleanup {
destroy .foo
} -result {}
test place-11.2 {PlaceObjCmd, slaves command} -setup {
destroy .foo .bar
} -body {
frame .foo
frame .bar
place .bar -in .foo
place slaves .foo
} -cleanup {
destroy .foo .bar
} -result [list .bar]
test place-12.1 {PlaceObjCmd, forget command} -setup {
destroy .foo
} -body {
frame .foo
place .foo -width 50 -height 50
update
set res [winfo ismapped .foo]
place forget .foo
update
lappend res [winfo ismapped .foo]
} -cleanup {
destroy .foo
} -result {1 0}
test place-13.1 {test respect for internalborder} -setup {
destroy .pack
} -body {
toplevel .pack
wm geometry .pack 200x200
frame .pack.l -width 15 -height 10
labelframe .pack.lf -labelwidget .pack.l
pack .pack.lf -fill both -expand 1
frame .pack.lf.f
place .pack.lf.f -x 0 -y 0 -relwidth 1.0 -relheight 1.0
update
set res [list [winfo geometry .pack.lf.f]]
.pack.lf configure -labelanchor e -padx 3 -pady 5
update
lappend res [winfo geometry .pack.lf.f]
} -cleanup {
destroy .pack
} -result {196x188+2+10 177x186+5+7}
test place-14.1 {memory leak testing} -constraints memory -setup {
destroy .f
proc getbytes {} {
set lines [split [memory info] "\n"]
lindex [lindex $lines 3] 3
}
# Repeat each body checking that memory does not increase
proc stress {args} {
set res {}
foreach body $args {
set end 0
for {set i 0} {$i < 5} {incr i} {
uplevel 1 $body
set tmp $end
set end [getbytes]
}
lappend res [expr {$end - $tmp}]
}
return $res
}
} -body {
# Test all manners of forgetting a slave
frame .f
frame .f.f
stress {
place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
place forget .f.f
} {
place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
pack .f.f
} {
place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
destroy .f
frame .f
frame .f.f
}
} -cleanup {
destroy .f
rename getbytes {}
rename stress {}
} -result {0 0 0}
# cleanup
cleanupTests
return
|