1 # This file is a Tcl script to test out the old syntax of Tk's
2 # "pack" command (before release 3.3). It is organized in the
3 # standard fashion for Tcl tests.
5 # Copyright (c) 1991-1994 The Regents of the University of California.
6 # Copyright (c) 1994 Sun Microsystems, Inc.
7 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 package require tcltest 2.2
11 eval tcltest::configure $argv
12 tcltest::loadTestedCommands
13 namespace import -force tcltest::test
15 # First, test a single window packed in various ways in a parent
19 place .pack -width 100 -height 100
20 frame .pack.red -width 10 -height 20
21 label .pack.red.l -text R -bd 2 -relief raised
22 place .pack.red.l -relwidth 1.0 -relheight 1.0
23 frame .pack.green -width 30 -height 40
24 label .pack.green.l -text G -bd 2 -relief raised
25 place .pack.green.l -relwidth 1.0 -relheight 1.0
26 frame .pack.blue -width 40 -height 40
27 label .pack.blue.l -text B -bd 2 -relief raised
28 place .pack.blue.l -relwidth 1.0 -relheight 1.0
29 frame .pack.violet -width 80 -height 20
30 label .pack.violet.l -text P -bd 2 -relief raised
31 place .pack.violet.l -relwidth 1.0 -relheight 1.0
33 test oldpack-1.1 {basic positioning} -body {
34 pack ap .pack .pack.red top
36 winfo geometry .pack.red
38 test oldpack-1.2 {basic positioning} -body {
39 pack append .pack .pack.red bottom
41 winfo geometry .pack.red
43 test oldpack-1.3 {basic positioning} -body {
44 pack append .pack .pack.red left
46 winfo geometry .pack.red
48 test oldpack-1.4 {basic positioning} -body {
49 pack append .pack .pack.red right
51 winfo geometry .pack.red
54 # Try adding padding around the window and make sure that the
55 # window gets a larger frame.
57 test oldpack-2.1 {padding} -body {
58 pack append .pack .pack.red {t padx 20}
60 winfo geometry .pack.red
62 test oldpack-2.2 {padding} -body {
63 pack append .pack .pack.red {top pady 20}
65 winfo geometry .pack.red
67 test oldpack-2.3 {padding} -body {
68 pack append .pack .pack.red {l padx 20}
70 winfo geometry .pack.red
72 test oldpack-2.4 {padding} -body {
73 pack append .pack .pack.red {left pady 20}
75 winfo geometry .pack.red
78 # Position the window at different positions in its frame to
79 # make sure they all work. Try two differenet frame locations,
80 # to make sure that frame offsets are being added in correctly.
82 test oldpack-3.1 {framing} -body {
83 pack append .pack .pack.red {b padx 20 pady 30}
85 winfo geometry .pack.red
87 test oldpack-3.2 {framing} -body {
88 pack append .pack .pack.red {bottom padx 20 pady 30 fr n}
90 winfo geometry .pack.red
92 test oldpack-3.3 {framing} -body {
93 pack append .pack .pack.red {bottom padx 20 pady 30 frame ne}
95 winfo geometry .pack.red
97 test oldpack-3.4 {framing} -body {
98 pack append .pack .pack.red {bottom padx 20 pady 30 frame e}
100 winfo geometry .pack.red
101 } -result 10x20+90+65
102 test oldpack-3.5 {framing} -body {
103 pack append .pack .pack.red {bottom padx 20 pady 30 frame se}
105 winfo geometry .pack.red
106 } -result 10x20+90+80
107 test oldpack-3.6 {framing} -body {
108 pack append .pack .pack.red {bottom padx 20 pady 30 frame s}
110 winfo geometry .pack.red
111 } -result 10x20+45+80
112 test oldpack-3.7 {framing} -body {
113 pack append .pack .pack.red {bottom padx 20 pady 30 frame sw}
115 winfo geometry .pack.red
117 test oldpack-3.8 {framing} -body {
118 pack append .pack .pack.red {bottom padx 20 pady 30 frame w}
120 winfo geometry .pack.red
122 test oldpack-3.9 {framing} -body {
123 pack append .pack .pack.red {bottom padx 20 pady 30 frame nw}
125 winfo geometry .pack.red
127 test oldpack-3.10 {framing} -body {
128 pack append .pack .pack.red {bottom padx 20 pady 30 frame c}
130 winfo geometry .pack.red
131 } -result 10x20+45+65
132 test oldpack-3.11 {framing} -body {
133 pack append .pack .pack.red {r padx 20 pady 30}
135 winfo geometry .pack.red
136 } -result 10x20+80+40
137 test oldpack-3.12 {framing} -body {
138 pack append .pack .pack.red {right padx 20 pady 30 frame n}
140 winfo geometry .pack.red
142 test oldpack-3.13 {framing} -body {
143 pack append .pack .pack.red {right padx 20 pady 30 frame ne}
145 winfo geometry .pack.red
147 test oldpack-3.14 {framing} -body {
148 pack append .pack .pack.red {right padx 20 pady 30 frame e}
150 winfo geometry .pack.red
151 } -result 10x20+90+40
152 test oldpack-3.15 {framing} -body {
153 pack append .pack .pack.red {right padx 20 pady 30 frame se}
155 winfo geometry .pack.red
156 } -result 10x20+90+80
157 test oldpack-3.16 {framing} -body {
158 pack append .pack .pack.red {right padx 20 pady 30 frame s}
160 winfo geometry .pack.red
161 } -result 10x20+80+80
162 test oldpack-3.17 {framing} -body {
163 pack append .pack .pack.red {right padx 20 pady 30 frame sw}
165 winfo geometry .pack.red
166 } -result 10x20+70+80
167 test oldpack-3.18 {framing} -body {
168 pack append .pack .pack.red {right padx 20 pady 30 frame w}
170 winfo geometry .pack.red
171 } -result 10x20+70+40
172 test oldpack-3.19 {framing} -body {
173 pack append .pack .pack.red {right padx 20 pady 30 frame nw}
175 winfo geometry .pack.red
177 test oldpack-3.20 {framing} -body {
178 pack append .pack .pack.red {right padx 20 pady 30 frame center}
180 winfo geometry .pack.red
181 } -result 10x20+80+40
183 # Try out various filling combinations in a couple of different
186 test oldpack-4.1 {filling} -body {
187 pack append .pack .pack.red {bottom padx 20 pady 30 fillx}
189 winfo geometry .pack.red
190 } -result 100x20+0+65
191 test oldpack-4.2 {filling} -body {
192 pack append .pack .pack.red {bottom padx 20 pady 30 filly}
194 winfo geometry .pack.red
195 } -result 10x50+45+50
196 test oldpack-4.3 {filling} -body {
197 pack append .pack .pack.red {bottom padx 20 pady 30 fill}
199 winfo geometry .pack.red
200 } -result 100x50+0+50
201 test oldpack-4.4 {filling} -body {
202 pack append .pack .pack.red {right padx 20 pady 30 fillx}
204 winfo geometry .pack.red
205 } -result 30x20+70+40
206 test oldpack-4.5 {filling} -body {
207 pack append .pack .pack.red {right padx 20 pady 30 filly}
209 winfo geometry .pack.red
210 } -result 10x100+80+0
211 test oldpack-4.6 {filling} -body {
212 pack append .pack .pack.red {right padx 20 pady 30 fill}
214 winfo geometry .pack.red
215 } -result 30x100+70+0
217 # Multiple windows: make sure that space is properly subtracted
218 # from the cavity as windows are positioned inwards from all
219 # different sides. Also make sure that windows get unmapped if
220 # there isn't enough space for them.
222 pack append .pack .pack.red top .pack.green top .pack.blue top \
225 test oldpack-5.1 {multiple windows} -body {
226 winfo geometry .pack.red
228 test oldpack-5.2 {multiple windows} -body {
229 winfo geometry .pack.green
230 } -result 30x40+35+20
231 test oldpack-5.3 {multiple windows} -body {
232 winfo geometry .pack.blue
233 } -result 40x40+30+60
234 test oldpack-5.4 {multiple windows} -body {
235 winfo ismapped .pack.violet
238 pack b .pack.blue .pack.violet top
240 test oldpack-5.5 {multiple windows} -body {
241 winfo ismapped .pack.violet
243 test oldpack-5.6 {multiple windows} -body {
244 winfo geometry .pack.violet
245 } -result 80x20+10+60
246 test oldpack-5.7 {multiple windows} -body {
247 winfo geometry .pack.blue
248 } -result 40x20+30+80
250 pack after .pack.blue .pack.red top
252 test oldpack-5.8 {multiple windows} -body {
253 winfo geometry .pack.green
255 test oldpack-5.9 {multiple windows} -body {
256 winfo geometry .pack.violet
257 } -result 80x20+10+40
258 test oldpack-5.10 {multiple windows} -body {
259 winfo geometry .pack.blue
260 } -result 40x40+30+60
261 test oldpack-5.11 {multiple windows} -body {
262 winfo ismapped .pack.red
265 pack before .pack.green .pack.red right .pack.blue left
267 test oldpack-5.12 {multiple windows} -body {
268 winfo ismapped .pack.red
270 test oldpack-5.13 {multiple windows} -body {
271 winfo geometry .pack.red
272 } -result 10x20+90+40
273 test oldpack-5.14 {multiple windows} -body {
274 winfo geometry .pack.blue
276 test oldpack-5.15 {multiple windows} -body {
277 winfo geometry .pack.green
279 test oldpack-5.16 {multiple windows} -body {
280 winfo geometry .pack.violet
281 } -result 50x20+40+40
283 pack append .pack .pack.violet left .pack.green bottom .pack.red bottom \
286 test oldpack-5.17 {multiple windows} -body {
287 winfo geometry .pack.violet
289 test oldpack-5.18 {multiple windows} -body {
290 winfo geometry .pack.green
291 } -result 20x40+80+60
292 test oldpack-5.19 {multiple windows} -body {
293 winfo geometry .pack.red
294 } -result 10x20+85+40
295 test oldpack-5.20 {multiple windows} -body {
296 winfo geometry .pack.blue
299 pack after .pack.blue .pack.blue top .pack.red right .pack.green right \
302 test oldpack-5.21 {multiple windows} -body {
303 winfo geometry .pack.blue
305 test oldpack-5.22 {multiple windows} -body {
306 winfo geometry .pack.red
307 } -result 10x20+90+60
308 test oldpack-5.23 {multiple windows} -body {
309 winfo geometry .pack.green
310 } -result 30x40+60+50
311 test oldpack-5.24 {multiple windows} -body {
312 winfo geometry .pack.violet
315 pack after .pack.blue .pack.red left .pack.green left .pack.violet left
317 test oldpack-5.25 {multiple windows} -body {
318 winfo geometry .pack.blue
320 test oldpack-5.26 {multiple windows} -body {
321 winfo geometry .pack.red
323 test oldpack-5.27 {multiple windows} -body {
324 winfo geometry .pack.green
325 } -result 30x40+10+50
326 test oldpack-5.28 {multiple windows} -body {
327 winfo geometry .pack.violet
328 } -result 60x20+40+60
330 pack append .pack .pack.violet left .pack.green left .pack.blue left \
333 test oldpack-5.29 {multiple windows} -body {
334 winfo geometry .pack.violet
336 test oldpack-5.30 {multiple windows} -body {
337 winfo geometry .pack.green
338 } -result 20x40+80+30
339 test oldpack-5.31 {multiple windows} -body {
340 winfo ismapped .pack.blue
342 test oldpack-5.32 {multiple windows} -body {
343 winfo ismapped .pack.red
347 # Test the ability of the packer to propagate geometry information
348 # to its parent. Make sure it computes the parent's needs both in
349 # the direction of packing (width for "left" and "right" windows,
350 # for example), and perpendicular to the pack direction (height for
351 # "left" and "right" windows).
353 pack append .pack .pack.red top .pack.green top .pack.blue top \
356 test oldpack-6.1 {geometry propagation} -body {
357 winfo reqwidth .pack} -result 80
358 test oldpack-6.2 {geometry propagation} -body {
359 winfo reqheight .pack} -result 120
362 test oldpack-6.3 {geometry propagation} -body {
363 winfo reqwidth .pack} -result 40
364 test oldpack-6.4 {geometry propagation} -body {
365 winfo reqheight .pack} -result 100
366 frame .pack.violet -width 80 -height 20 -bg violet
367 label .pack.violet.l -text P -bd 2 -relief raised
368 place .pack.violet.l -relwidth 1.0 -relheight 1.0
369 pack append .pack .pack.red left .pack.green right .pack.blue bottom \
372 test oldpack-6.5 {geometry propagation} -body {
373 winfo reqwidth .pack} -result 120
374 test oldpack-6.6 {geometry propagation} -body {
375 winfo reqheight .pack} -result 60
376 pack append .pack .pack.violet top .pack.green top .pack.blue left \
379 test oldpack-6.7 {geometry propagation} -body {
380 winfo reqwidth .pack} -result 80
381 test oldpack-6.8 {geometry propagation} -body {
382 winfo reqheight .pack} -result 100
384 # Test the "expand" option, and make sure space is evenly divided
385 # when several windows request expansion.
387 pack append .pack .pack.violet top .pack.green {left e} \
388 .pack.blue {left expand} .pack.red {left expand}
390 test oldpack-7.1 {multiple expanded windows} -body {
391 pack append .pack .pack.violet top .pack.green {left e} \
392 .pack.blue {left expand} .pack.red {left expand}
394 list [winfo geometry .pack.green] [winfo geometry .pack.blue] \
395 [winfo geometry .pack.red]
396 } -result {30x40+3+40 40x40+39+40 10x20+86+50}
397 test oldpack-7.2 {multiple expanded windows} -body {
398 pack append .pack .pack.green left .pack.violet {bottom expand} \
399 .pack.blue {bottom expand} .pack.red {bottom expand}
401 list [winfo geometry .pack.violet] [winfo geometry .pack.blue] \
402 [winfo geometry .pack.red]
403 } -result {70x20+30+77 40x40+45+30 10x20+60+3}
404 test oldpack-7.3 {multiple expanded windows} -body {
405 foreach i [winfo child .pack] {
408 pack append .pack .pack.green {left e fill} .pack.red {left expand fill} \
409 .pack.blue {top fill}
411 list [winfo geometry .pack.green] [winfo geometry .pack.red] \
412 [winfo geometry .pack.blue]
413 } -result {40x100+0+0 20x100+40+0 40x40+60+0}
414 test oldpack-7.4 {multiple expanded windows} -body {
415 foreach i [winfo child .pack] {
418 pack append .pack .pack.red {top expand} .pack.violet {top expand} \
419 .pack.blue {right fill}
421 list [winfo geometry .pack.red] [winfo geometry .pack.violet] \
422 [winfo geometry .pack.blue]
423 } -result {10x20+45+5 80x20+10+35 40x40+60+60}
424 test oldpack-7.5 {multiple expanded windows} -body {
425 foreach i [winfo child .pack] {
428 pack append .pack .pack.green {right frame s} .pack.red {top expand}
430 list [winfo geometry .pack.green] [winfo geometry .pack.red]
431 } -result {30x40+70+60 10x20+30+40}
432 test oldpack-7.6 {multiple expanded windows} -body {
433 foreach i [winfo child .pack] {
436 pack append .pack .pack.violet {bottom frame e} .pack.red {right expand}
438 list [winfo geometry .pack.violet] [winfo geometry .pack.red]
439 } -result {80x20+20+80 10x20+45+30}
441 # Need more bizarre tests with combinations of expanded windows and
442 # windows in opposing directions! Also, include padding in expanded
443 # (and unexpanded) windows.
445 # Syntax errors on pack commands
447 test oldpack-8.1 {syntax errors} -body {
449 } -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
450 test oldpack-8.2 {syntax errors} -body {
452 } -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
453 test oldpack-8.3 {syntax errors} -body {
455 } -returnCodes error -result {bad option "gorp": must be configure, content, forget, info, propagate, or slaves}
456 test oldpack-8.4 {syntax errors} -body {
458 } -returnCodes error -result {bad option "a": must be configure, content, forget, info, propagate, or slaves}
459 test oldpack-8.5 {syntax errors} -body {
461 } -returnCodes error -result {bad window path name "foobar"}
462 test oldpack-8.6 {syntax errors} -setup {
465 frame .pack.yellow -bg yellow
466 pack after .pack.yellow
469 } -returnCodes error -result {window ".pack.yellow" isn't packed}
470 test oldpack-8.7 {syntax errors} -body {
472 } -returnCodes error -result {bad window path name "foobar"}
473 test oldpack-8.8 {syntax errors} -body {
475 } -returnCodes error -result {bad window path name "foobar"}
476 test oldpack-8.9 {syntax errors} -setup {
479 frame .pack.yellow -bg yellow
480 pack before .pack.yellow
483 } -returnCodes error -result {window ".pack.yellow" isn't packed}
484 test oldpack-8.10 {syntax errors} -body {
486 } -returnCodes error -result {wrong # args: should be "pack info window"}
487 test oldpack-8.11 {syntax errors} -body {
489 } -returnCodes error -result {bad window path name "foobar"}
490 test oldpack-8.12 {syntax errors} -body {
491 pack append .pack .pack.blue
492 } -returnCodes error -result {wrong # args: window ".pack.blue" should be followed by options}
493 test oldpack-8.13 {syntax errors} -body {
494 pack append . .pack.blue top
495 } -returnCodes error -result {can't pack .pack.blue inside .}
496 test oldpack-8.14 {syntax errors} -body {
497 pack append .pack .pack.blue f
498 } -returnCodes error -result {bad option "f": should be top, bottom, left, right, expand, fill, fillx, filly, padx, pady, or frame}
499 test oldpack-8.15 {syntax errors} -body {
500 pack append .pack .pack.blue pad
501 } -returnCodes error -result {bad option "pad": should be top, bottom, left, right, expand, fill, fillx, filly, padx, pady, or frame}
502 test oldpack-8.16 {syntax errors} -body {
503 pack append .pack .pack.blue {frame south}
504 } -returnCodes error -result {bad anchor "south": must be n, ne, e, se, s, sw, w, nw, or center}
505 test oldpack-8.17 {syntax errors} -body {
506 pack append .pack .pack.blue {padx -2}
507 } -returnCodes error -result {bad pad value "-2": must be positive screen distance}
508 test oldpack-8.18 {syntax errors} -body {
509 pack append .pack .pack.blue {padx}
510 } -returnCodes error -result {wrong # args: "padx" option must be followed by screen distance}
511 test oldpack-8.19 {syntax errors} -body {
512 pack append .pack .pack.blue {pady -2}
513 } -returnCodes error -result {bad pad value "-2": must be positive screen distance}
514 test oldpack-8.20 {syntax errors} -body {
515 pack append .pack .pack.blue {pady}
516 } -returnCodes error -result {wrong # args: "pady" option must be followed by screen distance}
517 test oldpack-8.21 {syntax errors} -body {
518 pack append .pack .pack.blue "\{abc"
519 } -returnCodes error -result {unmatched open brace in list}
520 test oldpack-8.22 {syntax errors} -body {
521 pack append .pack .pack.blue frame
522 } -returnCodes error -result {wrong # args: "frame" option must be followed by anchor point}
524 # Test "pack info" command output.
526 test oldpack-9.1 {information output} -body {
527 pack append .pack .pack.blue {top fillx frame n} \
528 .pack.red {bottom filly frame s} .pack.green {left fill frame w} \
529 .pack.violet {right expand frame e}
530 list [pack content .pack] [pack info .pack.blue] [pack info .pack.red] \
531 [pack info .pack.green] [pack info .pack.violet]
532 } -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor n -expand 0 -fill x -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor s -expand 0 -fill y -ipadx 0 -ipady 0 -padx 0 -pady 0 -side bottom} {-in .pack -anchor w -expand 0 -fill both -ipadx 0 -ipady 0 -padx 0 -pady 0 -side left} {-in .pack -anchor e -expand 1 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side right}}
533 test oldpack-9.2 {information output} -body {
534 pack append .pack .pack.blue {padx 10 frame nw} \
535 .pack.red {pady 20 frame ne} .pack.green {frame se} \
536 .pack.violet {frame sw}
537 list [pack content .pack] [pack info .pack.blue] [pack info .pack.red] \
538 [pack info .pack.green] [pack info .pack.violet]
539 } -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor nw -expand 0 -fill none -ipadx 0 -ipady 0 -padx 5 -pady 0 -side top} {-in .pack -anchor ne -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 10 -side top} {-in .pack -anchor se -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor sw -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top}}
540 test oldpack-9.3 {information output} -body {
541 pack append .pack .pack.blue {frame center} .pack.red {frame center} \
542 .pack.green {frame c} .pack.violet {frame c}
543 list [pack content .pack] [pack info .pack.blue] [pack info .pack.red] \
544 [pack info .pack.green] [pack info .pack.violet]
545 } -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top}}