home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / tests / grid.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  31.4 KB  |  1,192 lines  |  [TEXT/ALFA]

  1. # This file is a Tcl script to test out the *NEW* "grid" command
  2. # of Tk.  It is (almost) organized in the standard fashion for Tcl tests.
  3. #
  4. # Copyright (c) 1996 Sun Microsystems, Inc.
  5. #
  6. # See the file "license.terms" for information on usage and redistribution
  7. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  8. #
  9. # SCCS: @(#) grid.test 1.21 97/06/24 13:32:58
  10.  
  11. if {[string compare test [info procs test]] == 1} then \
  12.   {source ../tests/defs}
  13.  
  14. # Test Arguments:
  15. # name -                Name of test, in the form foo-1.2.
  16. # description -         Short textual description of the test, to
  17. #                       help humans understand what it does.
  18. # constraints -         A list of one or more keywords, each of
  19. #                       which must be the name of an element in
  20. #                       the array "testConfig".  If any of these
  21. #                       elements is zero, the test is skipped.
  22. #                       This argument may be omitted.
  23. # script -              Script to run to carry out the test.  It must
  24. #                       return a result that can be checked for
  25. #                       correctness.
  26. # answer -              Expected result from script.
  27.  
  28. # helper routine to return "." to a sane state after a test
  29. # The variable GRID_VERBOSE can be used to "look" at the result
  30. # of one or all of the tests
  31.  
  32. proc grid_reset {{test ?} {top .}} {
  33.     global GRID_VERBOSE
  34.     if {[info exists GRID_VERBOSE]} {
  35.     if {$GRID_VERBOSE=="" || $GRID_VERBOSE==$test} {
  36.         puts -nonewline "grid test $test: "
  37.         flush stdout
  38.         gets stdin
  39.     }
  40.     }
  41.     eval destroy [winfo children $top]
  42.     update
  43.     foreach {cols rows} [grid size .] {}
  44.     for {set i 0} {$i <= $cols} {incr i} {
  45.         grid columnconfigure . $i -weight 0 -minsize 0 -pad 0
  46.     }
  47.     for {set i 0} {$i <= $rows} {incr i} {
  48.         grid rowconfigure . $i -weight 0 -minsize 0 -pad 0
  49.     }
  50.     grid propagate . 1
  51.     update
  52. }
  53.  
  54. grid_reset 0.0
  55. wm geometry . {}
  56.  
  57. test grid-1.1 {basic argument checking} {
  58.     list [catch grid msg] $msg
  59. } {1 {wrong # args: should be "grid option arg ?arg ...?"}}
  60.  
  61. test grid-1.2 {basic argument checking} {
  62.     list [catch {grid foo bar} msg] $msg
  63. } {1 {bad option "foo":  must be bbox, columnconfigure, configure, forget, info, location, propagate, remove, rowconfigure, size, or slaves.}}
  64.  
  65. test grid-1.3 {basic argument checking} {
  66.     button .b
  67.     list [catch {grid .b -row 0 -column} msg] $msg
  68. } {1 {extra option or option with no value}}
  69. grid_reset 1.3
  70.  
  71. test grid-1.4 {basic argument checking} {
  72.     button .b
  73.     list [catch {grid configure .b - foo} msg] $msg
  74. } {1 {unexpected parameter, "foo", in configure list. Should be window name or option}}
  75. grid_reset 1.4
  76.  
  77. test grid-1.5 {basic argument checking} {
  78.     list [catch {grid .} msg] $msg
  79. } {1 {can't manage ".": it's a top-level window}}
  80.  
  81. test grid-1.6 {basic argument checking} {
  82.     list [catch {grid x} msg] $msg
  83. } {1 {can't determine master window}}
  84.  
  85. test grid-2.1 {bbox} {
  86.     list [catch {grid bbox .} msg] $msg
  87. } {0 {0 0 0 0}}
  88.  
  89. test grid-2.2 {bbox} {
  90.     button .b
  91.     grid .b
  92.     destroy .b
  93.     update
  94.     list [catch {grid bbox .} msg] $msg
  95. } {0 {0 0 0 0}}
  96.  
  97. test grid-2.3 {bbox: argument checking} {
  98.     list [catch {grid bbox . 0 0 5} msg] $msg
  99. } {1 {wrong number of arguments: must be "grid bbox master ?column row ?column row??"}}
  100.  
  101. test grid-2.4 {bbox} {
  102.     list [catch {grid bbox .bad 0 0} msg] $msg
  103. } {1 {bad window path name ".bad"}}
  104.  
  105. test grid-2.5 {bbox} {
  106.     list [catch {grid bbox . x 0} msg] $msg
  107. } {1 {expected integer but got "x"}}
  108.  
  109. test grid-2.6 {bbox} {
  110.     list [catch {grid bbox . 0 x} msg] $msg
  111. } {1 {expected integer but got "x"}}
  112.  
  113. test grid-2.7 {bbox} {
  114.     list [catch {grid bbox . 0 0 x 0} msg] $msg
  115. } {1 {expected integer but got "x"}}
  116.  
  117. test grid-2.8 {bbox} {
  118.     list [catch {grid bbox . 0 0 0 x} msg] $msg
  119. } {1 {expected integer but got "x"}}
  120.  
  121. test grid-2.9 {bbox} {
  122.     frame .1 -width 75 -height 75 -bg red
  123.     frame .2 -width 90 -height 90 -bg red
  124.     grid .1 -row 0 -column 0
  125.     grid .2 -row 1 -column 1
  126.     update
  127.     set a ""
  128.     lappend a [grid bbox .]
  129.     lappend a [grid bbox . 0 0]
  130.     lappend a [grid bbox . 0 0 1 1]
  131.     lappend a [grid bbox . 1 1]
  132.     set a
  133. } {{0 0 165 165} {0 0 75 75} {0 0 165 165} {75 75 90 90}}
  134. grid_reset 2.9
  135.  
  136. test grid-2.10 {bbox} {
  137.     frame .1 -width 75 -height 75 -bg red
  138.     frame .2 -width 90 -height 90 -bg red
  139.     grid .1 -row 0 -column 0
  140.     grid .2 -row 1 -column 1
  141.     update
  142.     set a ""
  143.     lappend a [grid bbox . 10 10 0 0]
  144.     lappend a [grid bbox . -2 -2 -1 -1]
  145.     lappend a [grid bbox . 10 10 12 12]
  146.     set a
  147. } {{0 0 165 165} {0 0 0 0} {165 165 0 0}}
  148. grid_reset 2.10
  149.  
  150. test grid-3.1 {configure: basic argument checking} {
  151.     list [catch {grid configure foo} msg] $msg
  152. } {1 {bad argument "foo": must be name of window}}
  153.  
  154. test grid-3.2 {configure: basic argument checking} {
  155.     button .b
  156.     grid configure .b
  157.     grid slaves .
  158. } {.b}
  159. grid_reset 3.2
  160.  
  161. test grid-3.3 {configure: basic argument checking} {
  162.     button .b
  163.     list [catch {grid .b -row -1} msg] $msg
  164. } {1 {bad grid value "-1": must be a non-negative integer}}
  165. grid_reset 3.3
  166.  
  167. test grid-3.4 {configure: basic argument checking} {
  168.     button .b
  169.     list [catch {grid .b -column -1} msg] $msg
  170. } {1 {bad column value "-1": must be a non-negative integer}}
  171. grid_reset 3.4
  172.  
  173. test grid-3.5 {configure: basic argument checking} {
  174.     button .b
  175.     list [catch {grid .b -rowspan 0} msg] $msg
  176. } {1 {bad rowspan value "0": must be a positive integer}}
  177. grid_reset 3.5
  178.  
  179. test grid-3.6 {configure: basic argument checking} {
  180.     button .b
  181.     list [catch {grid .b -columnspan 0} msg] $msg
  182. } {1 {bad columnspan value "0": must be a positive integer}}
  183. grid_reset 3.6
  184.  
  185. test grid-3.7 {configure: basic argument checking} {
  186.     frame .f
  187.     button .f.b
  188.     list [catch {grid .f .f.b} msg] $msg
  189. } {1 {can't put .f.b inside .}}
  190. grid_reset 3.7
  191.  
  192. test grid-4.1 {forget: basic argument checking} {
  193.     list [catch {grid forget foo} msg] $msg
  194. } {1 {bad window path name "foo"}}
  195.  
  196. test grid-4.2 {forget} {
  197.     button .c
  198.     grid [button .b]
  199.     set a [grid slaves .]
  200.     grid forget .b .c
  201.     lappend a [grid slaves .]
  202.     set a
  203. } {.b {}}
  204. grid_reset 4.2
  205.  
  206. test grid-4.3 {forget} {
  207.     button .c
  208.     grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx 3 -pady 4 -sticky ns
  209.     grid forget .c
  210.     grid .c -row 0 -column 0
  211.     grid info .c
  212. } {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}
  213. grid_reset 4.3
  214.  
  215. test grid-5.1 {info: basic argument checking} {
  216.     list [catch {grid info a b} msg] $msg
  217. } {1 {wrong # args: should be "grid info window"}}
  218.  
  219. test grid-5.2 {info} {
  220.     frame .1 -width 75 -height 75 -bg red
  221.     grid .1 -row 0 -column 0
  222.     update
  223.     list [catch {grid info .x} msg] $msg
  224. } {1 {bad window path name ".x"}}
  225. grid_reset 5.2
  226.  
  227. test grid-5.3 {info} {
  228.     frame .1 -width 75 -height 75 -bg red
  229.     grid .1 -row 0 -column 0
  230.     update
  231.     list [catch {grid info .1} msg] $msg
  232. } {0 {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}}
  233. grid_reset 5.3
  234.  
  235. test grid-5.4 {info} {
  236.     frame .1 -width 75 -height 75 -bg red
  237.     update
  238.     list [catch {grid info .1} msg] $msg
  239. } {0 {}}
  240. grid_reset 5.4
  241.  
  242. test grid-6.1 {location: basic argument checking} {
  243.     list [catch "grid location ." msg] $msg
  244. } {1 {wrong # args: should be "grid location master x y"}}
  245.  
  246. test grid-6.2 {location: basic argument checking} {
  247.     list [catch "grid location .bad 0 0" msg] $msg
  248. } {1 {bad window path name ".bad"}}
  249.  
  250. test grid-6.3 {location: basic argument checking} {
  251.     list [catch "grid location . x y" msg] $msg
  252. } {1 {bad screen distance "x"}}
  253.  
  254. test grid-6.4 {location: basic argument checking} {
  255.     list [catch "grid location . 1c y" msg] $msg
  256. } {1 {bad screen distance "y"}}
  257.  
  258. test grid-6.5 {location: basic argument checking} {
  259.     frame .f
  260.     grid location .f 10 10
  261. } {-1 -1}
  262. grid_reset 6.5
  263.  
  264. test grid-6.6 {location (x)} {
  265.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  266.     grid .f
  267.     update
  268.     set got ""
  269.     set result ""
  270.     for {set x -10} { $x < 220} { incr x} {
  271.     set a [grid location . $x 0]
  272.     if {$a != $got} {
  273.         lappend result $x->$a
  274.         set got $a
  275.     }
  276.     }
  277.     set result
  278. } {{-10->-1 0} {0->0 0} {201->1 0}}
  279. grid_reset 6.6
  280.  
  281. test grid-6.7 {location (y)} {
  282.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  283.     grid .f
  284.     update
  285.     set got ""
  286.     set result ""
  287.     for {set y -10} { $y < 110} { incr y} {
  288.     set a [grid location . 0 $y]
  289.     if {$a != $got} {
  290.         lappend result $y->$a
  291.         set got $a
  292.     }
  293.     }
  294.     set result
  295. } {{-10->0 -1} {0->0 0} {101->0 1}}
  296. grid_reset 6.7
  297.  
  298. test grid-6.8 {location (weights)} {
  299.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  300.     frame .a
  301.     grid .a
  302.     grid .f -in .a
  303.     grid rowconfigure .f 0 -weight 1
  304.     grid columnconfigure .f 0 -weight 1
  305.     grid propagate .a 0
  306.     .a configure -width 110 -height 15
  307.     update
  308.     set got ""
  309.     set result ""
  310.     for {set y -10} { $y < 120} { incr y} {
  311.     set a [grid location . $y $y]
  312.     if {$a != $got} {
  313.         lappend result $y->$a
  314.         set got $a
  315.     }
  316.     }
  317.     set result
  318. } {{-10->-1 -1} {0->0 0} {16->0 1} {111->1 1}}
  319. grid_reset 6.8
  320.  
  321. test grid-6.9 {location: check updates pending} {
  322.     set a ""
  323.     foreach i {0 1 2} {
  324.         frame .$i -width 120 -height 75 -bg red
  325.         lappend a [grid location . 150 90]
  326.         grid .$i -row $i -column $i
  327.     }
  328.     set a
  329. } {{0 0} {1 1} {1 1}}
  330. grid_reset 6.9
  331.  
  332. test grid-7.1 {propagate} {
  333.     list [catch {grid propagate . 1 xxx} msg] $msg
  334. } {1 {wrong # args: should be "grid propagate window ?boolean?"}}
  335. grid_reset 7.1
  336.  
  337. test grid-7.2 {propagate} {
  338.     list [catch {grid propagate .} msg] $msg
  339. } {0 1}
  340. grid_reset 7.2
  341.  
  342. test grid-7.3 {propagate} {
  343.     list [catch {grid propagate . 0;grid propagate .} msg] $msg
  344. } {0 0}
  345. grid_reset 7.3
  346.  
  347. test grid-7.4 {propagate} {
  348.     list [catch {grid propagate .x} msg] $msg
  349. } {1 {bad window path name ".x"}}
  350. grid_reset 7.4
  351.  
  352. test grid-7.5 {propagate} {
  353.     list [catch {grid propagate . x} msg] $msg
  354. } {1 {expected boolean value but got "x"}}
  355. grid_reset 7.5
  356.  
  357. test grid-7.6 {propagate} {
  358.     frame .f -width 100 -height 100 -bg red
  359.     grid .f -row 0 -column 0
  360.     update
  361.     set a [winfo width .f]x[winfo height .f]
  362.     grid propagate .f 0
  363.     frame .g -width 75 -height 85 -bg green
  364.     grid .g -in .f -row 0 -column 0
  365.     update
  366.     lappend a [winfo width .f]x[winfo height .f]
  367.     grid propagate .f 1
  368.     update
  369.     lappend a [winfo width .f]x[winfo height .f]
  370.     set a
  371. } {100x100 100x100 75x85}
  372. grid_reset 7.6
  373.  
  374.  
  375. test grid-8.1 {size} {
  376.     list [catch {grid size . foo} msg] $msg
  377. } {1 {wrong # args: should be "grid size window"}}
  378. grid_reset 8.1
  379.  
  380. test grid-8.2 {size} {
  381.     list [catch {grid size .x} msg] $msg
  382. } {1 {bad window path name ".x"}}
  383. grid_reset 8.2
  384.  
  385. test grid-8.3 {size} {
  386.     frame .f
  387.     list [catch {grid size .f} msg] $msg
  388. } {0 {0 0}}
  389. grid_reset 8.3
  390.  
  391. test grid-8.4 {size} {
  392.     catch {unset a}
  393.     scale .f
  394.     grid .f -row 0 -column 0
  395.     update
  396.     lappend a [grid size .]
  397.     grid .f -row 4 -column 5
  398.     update
  399.     lappend a [grid size .]
  400.     grid .f -row 947 -column 663
  401.     update
  402.     lappend a [grid size .]
  403.     grid .f -row 0 -column 0
  404.     update
  405.     lappend a [grid size .]
  406.     set a
  407. } {{1 1} {6 5} {664 948} {1 1}}
  408. grid_reset 8.4
  409.  
  410. test grid-8.5 {size} {
  411.     catch {unset a}
  412.     scale .f
  413.     grid .f -row 0 -column 0
  414.     update
  415.     lappend a [grid size .]
  416.     grid rowconfigure . 17 -weight 1
  417.     update
  418.     lappend a [grid size .]
  419.     grid columnconfigure . 63 -weight 1
  420.     update
  421.     lappend a [grid size .]
  422.     grid columnconfigure . 63 -weight 0
  423.     grid rowconfigure . 17 -weight 0
  424.     update
  425.     lappend a [grid size .]
  426.     set a
  427. } {{1 1} {1 18} {64 18} {1 1}}
  428. grid_reset 8.5
  429.  
  430. test grid-8.6 {size} {
  431.     catch {unset a}
  432.     scale .f
  433.     grid .f -row 10 -column 50
  434.     update
  435.     lappend a [grid size .]
  436.     grid columnconfigure . 15 -weight 1
  437.     grid columnconfigure . 30 -weight 1
  438.     update
  439.     lappend a [grid size .]
  440.     grid .f -row 10 -column 20
  441.     update
  442.     lappend a [grid size .]
  443.     grid columnconfigure . 30 -weight 0
  444.     update
  445.     lappend a [grid size .]
  446.     grid .f -row 0 -column 0
  447.     update
  448.     lappend a [grid size .]
  449.     grid columnconfigure . 15 -weight 0
  450.     update
  451.     lappend a [grid size .]
  452.     set a
  453. } {{51 11} {51 11} {31 11} {21 11} {16 1} {1 1}}
  454. grid_reset 8.6
  455.  
  456. test grid-9.1 {slaves} {
  457.     list [catch {grid slaves .} msg] $msg
  458. } {0 {}}
  459.  
  460. test grid-9.2 {slaves} {
  461.     list [catch {grid slaves .foo} msg] $msg
  462. } {1 {bad window path name ".foo"}}
  463.  
  464. test grid-9.3 {slaves} {
  465.     list [catch {grid slaves a b} msg] $msg
  466. } {1 {wrong # args: should be "grid slaves window ?-option value...?"}}
  467.  
  468. test grid-9.4 {slaves} {
  469.     list [catch {grid slaves . a b} msg] $msg
  470. } {1 {invalid args: should be "grid slaves window ?-option value...?"}}
  471.  
  472. test grid-9.5 {slaves} {
  473.     list [catch {grid slaves . -foo x} msg] $msg
  474. } {1 {expected integer but got "x"}}
  475.  
  476. test grid-9.6 {slaves} {
  477.     list [catch {grid slaves . -foo -3} msg] $msg
  478. } {1 {-foo is an invalid value: should NOT be < 0}}
  479.  
  480. test grid-9.7 {slaves} {
  481.     list [catch {grid slaves . -foo 3} msg] $msg
  482. } {1 {-foo is an invalid option: should be "-row, -column"}}
  483.  
  484. test grid-9.8 {slaves} {
  485.     list [catch {grid slaves .x -row 3} msg] $msg
  486. } {1 {bad window path name ".x"}}
  487.  
  488. test grid-9.9 {slaves} {
  489.     list [catch {grid slaves . -row 3} msg] $msg
  490. } {0 {}}
  491.  
  492. test grid-9.10 {slaves} {
  493.     foreach i {0 1 2} {
  494.         label .$i -text $i
  495.         grid .$i -row $i -column $i
  496.     }
  497.     list [catch {grid slaves .} msg] $msg
  498. } {0 {.2 .1 .0}}
  499. grid_reset 9.10
  500.  
  501. test grid-9.11 {slaves} {
  502.     catch {unset a}
  503.     foreach i {0 1 2} {
  504.     label .$i -text $i
  505.     label .$i-x -text $i-x
  506.     grid .$i -row $i -column $i
  507.     grid .$i-x -row $i -column [incr i]
  508.     }
  509.     foreach row {0 1 2 3} {
  510.     lappend a $row{[grid slaves . -row $row]}
  511.     }
  512.     foreach col {0 1 2 3} {
  513.     lappend a $col{[grid slaves . -column $col]}
  514.     }
  515.     set a
  516. } {{0{.0-x .0}} {1{.1-x .1}} {2{.2-x .2}} 3{} 0{.0} {1{.1 .0-x}} {2{.2 .1-x}} 3{.2-x}} 
  517. grid_reset 9.11
  518.  
  519. # column/row configure
  520.  
  521. test grid-10.1 {column/row configure} {
  522.     list [catch {grid columnconfigure .} msg] $msg
  523. } {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
  524. grid_reset 10.1
  525.  
  526. test grid-10.2 {column/row configure} {
  527.     list [catch {grid columnconfigure . 0 -weight 0 -pad} msg] $msg
  528. } {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
  529. grid_reset 10.2
  530.  
  531. test grid-10.3 {column/row configure} {
  532.     list [catch {grid columnconfigure .f 0 -weight} msg] $msg
  533. } {1 {bad window path name ".f"}}
  534. grid_reset 10.3
  535.  
  536. test grid-10.4 {column/row configure} {
  537.     list [catch {grid columnconfigure . nine -weight} msg] $msg
  538. } {1 {expected integer but got "nine"}}
  539. grid_reset 10.4
  540.  
  541. test grid-10.5 {column/row configure} {
  542.     list [catch {grid columnconfigure . 265 -weight} msg] $msg
  543. } {0 0}
  544. grid_reset 10.5
  545.  
  546. test grid-10.6 {column/row configure} {
  547.     list [catch {grid columnconfigure . 0} msg] $msg
  548. } {0 {-minsize 0 -pad 0 -weight 0}}
  549. grid_reset 10.6
  550.  
  551. test grid-10.7 {column/row configure} {
  552.     list [catch {grid columnconfigure . 0 -foo} msg] $msg
  553. } {1 {invalid arg "-foo": expecting -minsize, -pad, or -weight.}}
  554. grid_reset 10.7
  555.  
  556. test grid-10.8 {column/row configure} {
  557.     list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
  558. } {1 {bad screen distance "foo"}}
  559. grid_reset 10.8
  560.  
  561. test grid-10.9 {column/row configure} {
  562.     list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
  563. } {1 {bad screen distance "foo"}}
  564. grid_reset 10.9
  565.  
  566. test grid-10.10 {column/row configure} {
  567.     grid columnconfigure . 0 -minsize 10
  568.     grid columnconfigure . 0 -minsize
  569. } {10}
  570. grid_reset 10.10
  571.  
  572. test grid-10.11 {column/row configure} {
  573.     list [catch {grid columnconfigure . 0 -weight bad} msg] $msg
  574. } {1 {expected integer but got "bad"}}
  575. grid_reset 10.10a
  576.  
  577. test grid-10.12 {column/row configure} {
  578.     list [catch {grid columnconfigure . 0 -weight -3} msg] $msg
  579. } {1 {invalid arg "-weight": should be non-negative}}
  580. grid_reset 10.11
  581.  
  582. test grid-10.13 {column/row configure} {
  583.     grid columnconfigure . 0 -weight 3
  584.     grid columnconfigure . 0 -weight
  585. } {3}
  586. grid_reset 10.12
  587.  
  588. test grid-10.14 {column/row configure} {
  589.     list [catch {grid columnconfigure . 0 -pad foo} msg] $msg
  590. } {1 {bad screen distance "foo"}}
  591. grid_reset 10.13
  592.  
  593. test grid-10.15 {column/row configure} {
  594.     list [catch {grid columnconfigure . 0 -pad -3} msg] $msg
  595. } {1 {invalid arg "-pad": should be non-negative}}
  596. grid_reset 10.14
  597.  
  598. test grid-10.16 {column/row configure} {
  599.     grid columnconfigure . 0 -pad 3
  600.     grid columnconfigure . 0 -pad
  601. } {3}
  602. grid_reset 10.15
  603.  
  604. test grid-10.17 {column/row configure} {
  605.     frame .f
  606.     set a ""
  607.     grid columnconfigure .f 0 -weight 0
  608.     lappend a [grid columnconfigure .f 0 -weight]
  609.     grid columnconfigure .f 0 -weight 1
  610.     lappend a [grid columnconfigure .f 0 -weight]
  611.     grid rowconfigure .f 0 -weight 0
  612.     lappend a [grid rowconfigure .f 0 -weight]
  613.     grid rowconfigure .f 0 -weight 1
  614.     lappend a [grid columnconfigure .f 0 -weight]
  615.     grid columnconfigure .f 0 -weight 0
  616.     set a
  617. } {0 1 0 1}
  618. grid_reset 10.16
  619.  
  620. test grid-10.18 {column/row configure} {
  621.     frame .f
  622.     grid columnconfigure .f 0 -minsize 10 -weight 1
  623.     list [grid columnconfigure .f 0 -minsize] \
  624.         [grid columnconfigure .f 1 -minsize] \
  625.         [grid columnconfigure .f 0 -weight] \
  626.         [grid columnconfigure .f 1 -weight]
  627. }  {10 0 1 0}
  628. grid_reset 10.17
  629.  
  630. # auto-placement tests
  631.  
  632. test grid-11.1 {default widget placement} {
  633.     list [catch {grid ^} msg] $msg
  634. } {1 {can't use '^', cant find master}}
  635. grid_reset 11.1
  636.  
  637. test grid-11.2 {default widget placement} {
  638.     button .b
  639.     list [catch {grid .b ^} msg] $msg
  640. } {1 {can't find slave to extend with "^".}}
  641. grid_reset 11.2
  642.  
  643. test grid-11.3 {default widget placement} {
  644.     button .b
  645.     list [catch {grid .b - - .c} msg] $msg
  646. } {1 {bad window path name ".c"}}
  647. grid_reset 11.3
  648.  
  649. test grid-11.4 {default widget placement} {
  650.     button .b
  651.     list [catch {grid .b - - = -} msg] $msg
  652. } {1 {invalid window shortcut, "=" should be '-', 'x', or '^'}}
  653. grid_reset 11.4
  654.  
  655. test grid-11.5 {default widget placement} {
  656.     button .b
  657.     list [catch {grid .b - x -} msg] $msg
  658. } {1 {Must specify window before shortcut '-'.}}
  659. grid_reset 11.5
  660.  
  661. test grid-11.6 {default widget placement} {
  662.     foreach i {1 2 3 4 5 6} {
  663.     frame .f$i -width 50 -height 50 -highlightthickness 0 -bg red
  664.     }
  665.     grid .f1 .f2 .f3 .f4
  666.     grid .f5   -  x  .f6 -sticky nsew
  667.     update
  668.     set a ""
  669.     foreach i {5 6} {
  670.     lappend a "[winfo x .f$i],[winfo y .f$i] \
  671.         [winfo width .f$i],[winfo height .f$i]"
  672.     }
  673.     set a
  674. } {{0,50  100,50} {150,50  50,50}}
  675. grid_reset 11.6
  676.  
  677. test grid-11.7 {default widget placement} {
  678.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  679.     grid .f -row 5 -column 5
  680.     list [catch "grid .f x -" msg] $msg
  681. } {1 {Must specify window before shortcut '-'.}}
  682. grid_reset 11.7
  683.  
  684. test grid-11.8 {default widget placement} {
  685.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  686.     grid .f -row 5 -column 5
  687.     list [catch "grid .f ^ -" msg] $msg
  688. } {1 {Must specify window before shortcut '-'.}}
  689. grid_reset 11.8
  690.  
  691. test grid-11.9 {default widget placement} {
  692.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  693.     grid .f -row 5 -column 5
  694.     list [catch "grid .f x ^" msg] $msg
  695. } {1 {can't find slave to extend with "^".}}
  696. grid_reset 11.9
  697.  
  698. test grid-11.10 {default widget placement} {
  699.     foreach i {1 2 3} {
  700.         frame .f$i -width 100 -height 50 -highlightthickness 0 -bg red
  701.     }
  702.     grid .f1 .f2  -sticky nsew
  703.     grid .f3   ^  -sticky nsew
  704.     update
  705.     set a ""
  706.     foreach i {1 2 3} {
  707.     lappend a "[winfo x .f$i],[winfo y .f$i] \
  708.         [winfo width .f$i],[winfo height .f$i]"
  709.     }
  710.     set a
  711. } {{0,0  100,50} {100,0  100,100} {0,50  100,50}}
  712. grid_reset 11.10
  713.  
  714. test grid-11.11 {default widget placement} {
  715.     foreach i {1 2 3 4 5 6 7 8 9 10 11 12} {
  716.         frame .f$i -width 50 -height 50 -highlightthickness 1 -highlightbackground black
  717.     }
  718.     grid .f1  .f2  .f3 .f4 -sticky nsew
  719.     grid .f5  .f6   -  .f7  -sticky nsew
  720.     grid .f8    ^   ^  .f9  -sticky nsew
  721.     grid .f10   ^   ^  .f11  -sticky nsew
  722.     grid .f12   -   -   - -sticky nsew
  723.     update
  724.     set a ""
  725.     foreach i {5 6 7 8 9 10 11 12 } {
  726.     lappend a "[winfo x .f$i],[winfo y .f$i] \
  727.         [winfo width .f$i],[winfo height .f$i]"
  728.     }
  729.     set a
  730. } {{0,50  50,50} {50,50  100,150} {150,50  50,50} {0,100  50,50} {150,100  50,50} {0,150  50,50} {150,150  50,50} {0,200  200,50}}
  731. grid_reset 11.11
  732.  
  733. test grid-11.12 {default widget placement} {
  734.     foreach i {1 2 3 4} {
  735.         frame .f$i -width 75 -height 50 -highlightthickness 1 -highlightbackground black
  736.     }
  737.     grid .f1  .f2   .f3     -sticky nsew
  738.     grid .f4    ^           -sticky nsew
  739.     update
  740.     set a ""
  741.     foreach i {1 2 3 4} {
  742.         lappend a "[winfo x .f$i],[winfo y .f$i] \
  743.             [winfo width .f$i],[winfo height .f$i]"
  744.     }
  745.     grid .f4    ^   -column 1
  746.     update
  747.     foreach i {1 2 3 4} {
  748.         lappend a "[winfo x .f$i],[winfo y .f$i] \
  749.             [winfo width .f$i],[winfo height .f$i]"
  750.     }
  751.     set a
  752. } {{0,0  75,50} {75,0  75,100} {150,0  75,50} {0,50  75,50} {0,0  75,50} {75,0  75,100} {150,0  75,100} {75,50  75,50}}
  753. grid_reset 11.12
  754.  
  755. test grid-11.13 {default widget placement} {
  756.     foreach i {1 2 3 4 5 6 7} {
  757.         frame .f$i -width 40 -height 50 -highlightthickness 1 -highlightbackground black
  758.     }
  759.     grid .f1  .f2  .f3 .f4 .f5 -sticky nsew
  760.     grid .f6    -  .f7         -sticky nsew -columnspan 2
  761.     update
  762.     set a ""
  763.     foreach i {6 7} {
  764.     lappend a "[winfo x .f$i],[winfo y .f$i] \
  765.         [winfo width .f$i],[winfo height .f$i]"
  766.     }
  767.     set a
  768. } {{0,50  120,50} {120,50  80,50}}
  769. grid_reset 11.13
  770.  
  771. test grid-11.14 {default widget placement} {
  772.     foreach i {1 2 3} {
  773.     frame .f$i -width 50 -height 50 -highlightthickness 0 -bg red
  774.     }
  775.     grid .f1 .f2
  776.     grid  ^  .f3
  777.     update
  778.     set a ""
  779.     foreach i {1 2 3} {
  780.     lappend a "[winfo x .f$i],[winfo y .f$i] \
  781.         [winfo width .f$i],[winfo height .f$i]"
  782.     }
  783.     set a
  784. } {{0,25  50,50} {50,0  50,50} {50,50  50,50}}
  785. grid_reset 11.14
  786.  
  787. test grid-12.1 {-sticky} {
  788.     catch {unset data}
  789.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  790.     set a ""
  791.     grid .f
  792.     grid rowconfigure . 0 -weight 1
  793.     grid columnconfigure . 0 -weight 1
  794.     grid propagate . 0
  795.     . configure -width 250 -height 150
  796.     foreach i { {} n s e w ns ew nw ne se sw nse nsw sew new nsew} {
  797.     grid .f -sticky $i
  798.     update
  799.     array set data [grid info .f]
  800.     append a "($data(-sticky)) [winfo x .f] [winfo y .f] [winfo width .f] [winfo height .f]\n"
  801.     }
  802.     set a
  803. } {() 25 25 200 100
  804. (n) 25 0 200 100
  805. (s) 25 50 200 100
  806. (e) 50 25 200 100
  807. (w) 0 25 200 100
  808. (ns) 25 0 200 150
  809. (ew) 0 25 250 100
  810. (nw) 0 0 200 100
  811. (ne) 50 0 200 100
  812. (es) 50 50 200 100
  813. (sw) 0 50 200 100
  814. (nes) 50 0 200 150
  815. (nsw) 0 0 200 150
  816. (esw) 0 50 250 100
  817. (new) 0 0 250 100
  818. (nesw) 0 0 250 150
  819. }
  820. grid_reset 12.1
  821.    
  822. test grid-12.2 {-sticky} {
  823.     frame .f -bg red
  824.     list [catch "grid .f -sticky glue" msg] $msg
  825. } {1 {bad stickyness value "glue": must be a string containing n, e, s, and/or w}}
  826. grid_reset 12.2
  827.    
  828. test grid-12.3 {-sticky} {
  829.     frame .f -bg red
  830.     grid .f -sticky {n,s,e,w}
  831.     array set A [grid info .f]
  832.     set A(-sticky)
  833. } {nesw}
  834. grid_reset 12.3
  835.  
  836. test grid-13.1 {-in} {
  837.     frame .f -bg red
  838.     list [catch "grid .f -in .f" msg] $msg
  839. } {1 {Window can't be managed in itself}}
  840. grid_reset 13.1
  841.  
  842. test grid-13.2 {-in} {
  843.     frame .f -bg red
  844.     list [catch "grid .f -in .bad" msg] $msg
  845. } {1 {bad window path name ".bad"}}
  846. grid_reset 13.2
  847.  
  848. test grid-13.3 {-in} {
  849.     frame .f -bg red
  850.     toplevel .top
  851.     list [catch "grid .f -in .top" msg] $msg
  852. } {1 {can't put .f inside .top}}
  853. destroy .top
  854. grid_reset 13.3
  855.  
  856. test grid-13.4 {-ipadx} {
  857.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  858.     list [catch "grid .f -ipadx x" msg] $msg
  859. } {1 {bad ipadx value "x": must be positive screen distance}}
  860. grid_reset 13.4
  861.  
  862. test grid-13.5 {-ipadx} {
  863.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  864.     grid .f
  865.     update
  866.     set a [winfo width .f]
  867.     grid .f -ipadx 1
  868.     update
  869.     list $a [winfo width .f]
  870. } {200 202}
  871. grid_reset 13.5
  872.  
  873. test grid-13.6 {-ipady} {
  874.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  875.     list [catch "grid .f -ipady x" msg] $msg
  876. } {1 {bad ipady value "x": must be positive screen distance}}
  877. grid_reset 13.6
  878.  
  879. test grid-13.7 {-ipady} {
  880.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  881.     grid .f
  882.     update
  883.     set a [winfo height .f]
  884.     grid .f -ipady 1
  885.     update
  886.     list $a [winfo height .f]
  887. } {100 102}
  888. grid_reset 13.7
  889.  
  890. test grid-13.8 {-padx} {
  891.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  892.     list [catch "grid .f -padx x" msg] $msg
  893. } {1 {bad padx value "x": must be positive screen distance}}
  894. grid_reset 13.8
  895.  
  896. test grid-13.9 {-padx} {
  897.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  898.     grid .f
  899.     update
  900.     set a "[winfo width .f] [winfo width .]"
  901.     grid .f -padx 1
  902.     update
  903.     list $a "[winfo width .f] [winfo width .]"
  904. } {{200 200} {200 202}}
  905. grid_reset 13.9
  906.  
  907. test grid-13.10 {-pady} {
  908.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  909.     list [catch "grid .f -pady x" msg] $msg
  910. } {1 {bad pady value "x": must be positive screen distance}}
  911. grid_reset 13.10
  912.  
  913. test grid-13.11 {-pady} {
  914.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  915.     grid .f
  916.     update
  917.     set a "[winfo height .f] [winfo height .]"
  918.     grid .f -pady 1
  919.     update
  920.     list $a "[winfo height .f] [winfo height .]"
  921. } {{100 100} {100 102}}
  922. grid_reset 13.11
  923.  
  924. test grid-13.12 {-ipad x and y} {
  925.     frame .f -width 20 -height 20 -highlightthickness 0 -bg red
  926.     grid columnconfigure . 0 -minsize 150
  927.     grid rowconfigure . 0 -minsize 100
  928.     set a ""
  929.     foreach x {0 5} {
  930.         foreach y {0 5} {
  931.         grid .f -ipadx $x -ipady $y
  932.         update
  933.         append a " $x,$y:"
  934.         foreach prop {x y width height} {
  935.             append a ,[winfo $prop .f]
  936.         }
  937.     }
  938.     }
  939.     set a
  940. } { 0,0:,65,40,20,20 0,5:,65,35,20,30 5,0:,60,40,30,20 5,5:,60,35,30,30}
  941. grid_reset 13.12
  942.  
  943. test grid-13.13 {reparenting} {
  944.     frame .1
  945.     frame .2
  946.     button .b
  947.     grid .1 .2
  948.     grid .b -in .1
  949.     set a ""
  950.     catch {unset info}; array set info [grid info .b]
  951.     lappend a [grid slaves .1],[grid slaves .2],$info(-in)
  952.     grid .b -in .2
  953.     catch {unset info}; array set info [grid info .b]
  954.     lappend a [grid slaves .1],[grid slaves .2],$info(-in)
  955.     unset info
  956.     set a
  957. } {.b,,.1 ,.b,.2}
  958. grid_reset 13.13
  959.  
  960. test grid-14.1 {structure notify} {
  961.     frame .f -width 200 -height 100 -highlightthickness 0 -bg red
  962.     frame .g -width 200 -height 100 -highlightthickness 0 -bg red
  963.     grid .f 
  964.     grid .g -in .f    
  965.     update
  966.     set a ""
  967.     lappend a "[winfo x .g],[winfo y .g] \
  968.         [winfo width .g],[winfo height .g]"
  969.     .f configure -bd 5 -relief raised
  970.     update
  971.     lappend a "[winfo x .g],[winfo y .g] \
  972.         [winfo width .g],[winfo height .g]"
  973.     set a
  974. } {{0,0  200,100} {5,5  200,100}}
  975. grid_reset 14.1
  976.  
  977. test grid-14.2 {structure notify} {
  978.     frame .f -width 200 -height 100 
  979.     frame .f.g -width 200 -height 100 
  980.     grid .f 
  981.     grid .f.g
  982.     update
  983.     set a ""
  984.     lappend a [grid bbox .],[grid bbox .f]
  985.     .f config -bd 20
  986.     update
  987.     lappend a [grid bbox .],[grid bbox .f]
  988. } {{0 0 200 100,0 0 200 100} {0 0 240 140,20 20 200 100}}
  989. grid_reset 14.2
  990.  
  991. test grid-14.3 {map notify} {
  992.     global A
  993.     catch {unset A}
  994.     bind . <Configure> {incr A(%W)}
  995.     set A(.) 0
  996.     foreach i {0 1 2} {
  997.         frame .$i -width 100 -height 75
  998.         set A(.$i) 0
  999.     }
  1000.     grid .0 .1 .2
  1001.     update
  1002.     bind <Configure> .1 {destroy .0}
  1003.     .2 configure -bd 10
  1004.     update
  1005.     bind . <Configure> {}
  1006.     array get A
  1007. } {.2 2 .0 1 . 1 .1 1}
  1008. grid_reset 14.3
  1009.  
  1010. test grid-15.1 {lost slave} {
  1011.     button .b
  1012.     grid .b
  1013.     set a [grid slaves .]
  1014.     pack .b
  1015.     lappend a [grid slaves .]
  1016.     grid .b
  1017.     lappend a [grid slaves .]
  1018. } {.b {} .b}
  1019. grid_reset 15.1
  1020.  
  1021. test grid-15.2 {lost slave} {
  1022.     frame .f
  1023.     grid .f
  1024.     button .b
  1025.     grid .b -in .f
  1026.     set a [grid slaves .f]
  1027.     pack .b
  1028.     lappend a [grid slaves .f]
  1029.     grid .b -in .f
  1030.     lappend a [grid slaves .f]
  1031. } {.b {} .b}
  1032. grid_reset 15.2
  1033.  
  1034. test grid-16.1 {layout centering} {
  1035.     foreach i {0 1 2} {
  1036.         frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
  1037.         grid .$i -row $i -column $i -sticky nswe
  1038.     }
  1039.     grid propagate . 0
  1040.     . configure -width 300 -height 250
  1041.     update
  1042.     grid bbox .
  1043. } {37 50 225 150}
  1044. grid_reset 16.1
  1045.  
  1046. test grid-16.2 {layout weights (expanding)} {
  1047.     foreach i {0 1 2} {
  1048.         frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
  1049.         grid .$i -row $i -column $i -sticky nswe
  1050.         grid rowconfigure . $i -weight [expr $i + 1]
  1051.         grid columnconfigure . $i -weight [expr $i + 1]
  1052.     }
  1053.     grid propagate . 0
  1054.     . configure -width 500 -height 300
  1055.     set a ""
  1056.     update
  1057.     foreach i {0 1 2} {
  1058.     lappend a [winfo width .$i]-[winfo height .$i]
  1059.     }
  1060.     set a
  1061. } {120-75 167-100 213-125}
  1062. grid_reset 16.2
  1063.  
  1064. test grid-16.3 {layout weights (shrinking)} {
  1065.     foreach i {0 1 2} {
  1066.         frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
  1067.         grid .$i -row $i -column $i -sticky nswe
  1068.         grid rowconfigure . $i -weight [expr $i + 1]
  1069.         grid columnconfigure . $i -weight [expr $i + 1]
  1070.     }
  1071.     grid propagate . 0
  1072.     . configure -width 200 -height 150
  1073.     set a ""
  1074.     update
  1075.     foreach i {0 1 2} {
  1076.     lappend a [winfo width .$i]-[winfo height .$i]
  1077.     }
  1078.     set a
  1079. } {84-63 66-50 50-37}
  1080. grid_reset 16.3
  1081.  
  1082. test grid-16.4 {layout weights (shrinking with minsize)} {
  1083.     foreach i {0 1 2} {
  1084.         frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
  1085.         grid .$i -row $i -column $i -sticky nswe
  1086.         grid rowconfigure . $i -weight [expr $i + 1] -minsize 45
  1087.         grid columnconfigure . $i -weight [expr $i + 1] -minsize 65
  1088.     }
  1089.     grid propagate . 0
  1090.     . configure -width 200 -height 150
  1091.     set a ""
  1092.     update
  1093.     foreach i {0 1 2} {
  1094.     lappend a [winfo width .$i]-[winfo height .$i]
  1095.     }
  1096.     set a
  1097. } {70-60 65-45 65-45}
  1098. grid_reset 16.4
  1099.  
  1100. test grid-16.5 {layout weights (shrinking at minsize)} {
  1101.     foreach i {0 1 2} {
  1102.         frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
  1103.         grid .$i -row $i -column $i -sticky nswe
  1104.         grid rowconfigure . $i -weight 0 -minsize 70
  1105.         grid columnconfigure . $i -weight 0 -minsize 90
  1106.     }
  1107.     grid propagate . 0
  1108.     . configure -width 100 -height 75
  1109.     set a ""
  1110.     update
  1111.     foreach i {0 1 2} {
  1112.     lappend a [winfo width .$i]-[winfo height .$i]
  1113.     }
  1114.     set a
  1115. } {100-75 100-75 100-75}
  1116. grid_reset 16.5
  1117.  
  1118.  
  1119. test grid-16.6 {layout weights (shrinking at minsize)} {
  1120.     foreach i {0 1 2} {
  1121.         frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
  1122.         grid .$i -row $i -column $i -sticky nswe
  1123.         grid rowconfigure . $i -weight [expr $i + 1] -minsize 52
  1124.         grid columnconfigure . $i -weight [expr $i + 1] -minsize 69
  1125.     }
  1126.     grid propagate . 0
  1127.     . configure -width 200 -height 150
  1128.     set a ""
  1129.     update
  1130.     foreach i {0 1 2} {
  1131.     lappend a [winfo width .$i]-[winfo height .$i]
  1132.     }
  1133.     set a
  1134. } {69-52 69-52 69-52}
  1135. grid_reset 16.6
  1136.  
  1137. test grid-16.7 {layout weights (shrinking at minsize)} {
  1138.     foreach i {0 1 2} {
  1139.         frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
  1140.         grid .$i -row $i -column $i -sticky nswe
  1141.     }
  1142.     grid propagate . 0
  1143.     grid columnconfigure . 1 -weight 1 -minsize 0
  1144.     grid rowconfigure . 1 -weight 1 -minsize 0
  1145.     . configure -width 100 -height 75
  1146.     set a ""
  1147.     update
  1148.     foreach i {0 1 2} {
  1149.     lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
  1150.     }
  1151.     set a
  1152. } {100-75-1 1-1-0 200-150-1}
  1153. grid_reset 16.7
  1154.  
  1155. test grid-16.8 {layout internal constraints} {
  1156.     foreach i {0 1 2 3 4} {
  1157.         frame .$i -bg gray  -width 30 -height 25 -bd 2 -relief ridge
  1158.         grid .$i -row $i -column $i -sticky nswe
  1159.     }
  1160.     frame .f -bg red -width 250 -height 200
  1161.     frame .g -bg green -width 200 -height 180
  1162.     lower .f
  1163.     raise .g .f
  1164.     grid .f -row 1 -column 1 -rowspan 3 -columnspan 3 -sticky nswe
  1165.     grid .g -row 1 -column 1 -rowspan 2 -columnspan 2 -sticky nswe
  1166.     update
  1167.     set a ""
  1168.     foreach i {0 1 2 3 4} {
  1169.         append a "[winfo x .$i] "
  1170.     }
  1171.     append a ", "
  1172.     grid remove .f
  1173.     update
  1174.     foreach i {0 1 2 3 4} {
  1175.         append a "[winfo x .$i] "
  1176.     }
  1177.     append a ", "
  1178.     grid remove .g
  1179.     grid .f
  1180.     update
  1181.     foreach i {0 1 2 3 4} {
  1182.         append a "[winfo x .$i] "
  1183.     }
  1184.     append a ", "
  1185.     grid remove .f
  1186.     update
  1187.     foreach i {0 1 2 3 4} {
  1188.         append a "[winfo x .$i] "
  1189.     }
  1190.     set a
  1191. } {0 30 70 250 280 , 0 30 130 230 260 , 0 30 113 197 280 , 0 30 60 90 120 }
  1192.