summaryrefslogtreecommitdiffstats
path: root/tests/grid.test
blob: 8cec4aa2250533436c51662a64e43086b10fe43c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# This file is a Tcl script to test out the *NEW* "grid" command
# of Tk.  It is (almost) organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id: grid.test,v 1.5 1999/11/12 23:55:16 wart Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

# helper routine to return "." to a sane state after a test
# The variable GRID_VERBOSE can be used to "look" at the result
# of one or all of the tests

proc grid_reset {{test ?} {top .}} {
    global GRID_VERBOSE
    if {[info exists GRID_VERBOSE]} {
	if {$GRID_VERBOSE=="" || $GRID_VERBOSE==$test} {
	    puts -nonewline "grid test $test: "
	    flush stdout
	    gets stdin
	}
    }
    eval destroy [winfo children $top]
    update
    foreach {cols rows} [grid size .] {}
    for {set i 0} {$i <= $cols} {incr i} {
    	grid columnconfigure . $i -weight 0 -minsize 0 -pad 0
    }
    for {set i 0} {$i <= $rows} {incr i} {
    	grid rowconfigure . $i -weight 0 -minsize 0 -pad 0
    }
    grid propagate . 1
    update
}

grid_reset 0.0
wm geometry . {}

test grid-1.1 {basic argument checking} {
	list [catch grid msg] $msg
} {1 {wrong # args: should be "grid option arg ?arg ...?"}}

test grid-1.2 {basic argument checking} {
	list [catch {grid foo bar} msg] $msg
} {1 {bad option "foo":  must be bbox, columnconfigure, configure, forget, info, location, propagate, remove, rowconfigure, size, or slaves.}}

test grid-1.3 {basic argument checking} {
	button .b
	list [catch {grid .b -row 0 -column} msg] $msg
} {1 {extra option or option with no value}}
grid_reset 1.3

test grid-1.4 {basic argument checking} {
	button .b
	list [catch {grid configure .b - foo} msg] $msg
} {1 {unexpected parameter, "foo", in configure list. Should be window name or option}}
grid_reset 1.4

test grid-1.5 {basic argument checking} {
	list [catch {grid .} msg] $msg
} {1 {can't manage ".": it's a top-level window}}

test grid-1.6 {basic argument checking} {
	list [catch {grid x} msg] $msg
} {1 {can't determine master window}}

test grid-2.1 {bbox} {
	list [catch {grid bbox .} msg] $msg
} {0 {0 0 0 0}}

test grid-2.2 {bbox} {
	button .b
	grid .b
	destroy .b
	update
	list [catch {grid bbox .} msg] $msg
} {0 {0 0 0 0}}

test grid-2.3 {bbox: argument checking} {
	list [catch {grid bbox . 0 0 5} msg] $msg
} {1 {wrong number of arguments: must be "grid bbox master ?column row ?column row??"}}

test grid-2.4 {bbox} {
	list [catch {grid bbox .bad 0 0} msg] $msg
} {1 {bad window path name ".bad"}}

test grid-2.5 {bbox} {
	list [catch {grid bbox . x 0} msg] $msg
} {1 {expected integer but got "x"}}

test grid-2.6 {bbox} {
	list [catch {grid bbox . 0 x} msg] $msg
} {1 {expected integer but got "x"}}

test grid-2.7 {bbox} {
	list [catch {grid bbox . 0 0 x 0} msg] $msg
} {1 {expected integer but got "x"}}

test grid-2.8 {bbox} {
	list [catch {grid bbox . 0 0 0 x} msg] $msg
} {1 {expected integer but got "x"}}

test grid-2.9 {bbox} {
    frame .1 -width 75 -height 75 -bg red
    frame .2 -width 90 -height 90 -bg red
    grid .1 -row 0 -column 0
    grid .2 -row 1 -column 1
    update
    set a ""
    lappend a [grid bbox .]
    lappend a [grid bbox . 0 0]
    lappend a [grid bbox . 0 0 1 1]
    lappend a [grid bbox . 1 1]
    set a
} {{0 0 165 165} {0 0 75 75} {0 0 165 165} {75 75 90 90}}
grid_reset 2.9

test grid-2.10 {bbox} {
    frame .1 -width 75 -height 75 -bg red
    frame .2 -width 90 -height 90 -bg red
    grid .1 -row 0 -column 0
    grid .2 -row 1 -column 1
    update
    set a ""
    lappend a [grid bbox . 10 10 0 0]
    lappend a [grid bbox . -2 -2 -1 -1]
    lappend a [grid bbox . 10 10 12 12]
    set a
} {{0 0 165 165} {0 0 0 0} {165 165 0 0}}
grid_reset 2.10

test grid-3.1 {configure: basic argument checking} {
    list [catch {grid configure foo} msg] $msg
} {1 {bad argument "foo": must be name of window}}

test grid-3.2 {configure: basic argument checking} {
    button .b
    grid configure .b
    grid slaves .
} {.b}
grid_reset 3.2

test grid-3.3 {configure: basic argument checking} {
    button .b
    list [catch {grid .b -row -1} msg] $msg
} {1 {bad grid value "-1": must be a non-negative integer}}
grid_reset 3.3

test grid-3.4 {configure: basic argument checking} {
    button .b
    list [catch {grid .b -column -1} msg] $msg
} {1 {bad column value "-1": must be a non-negative integer}}
grid_reset 3.4

test grid-3.5 {configure: basic argument checking} {
    button .b
    list [catch {grid .b -rowspan 0} msg] $msg
} {1 {bad rowspan value "0": must be a positive integer}}
grid_reset 3.5

test grid-3.6 {configure: basic argument checking} {
    button .b
    list [catch {grid .b -columnspan 0} msg] $msg
} {1 {bad columnspan value "0": must be a positive integer}}
grid_reset 3.6

test grid-3.7 {configure: basic argument checking} {
    frame .f
    button .f.b
    list [catch {grid .f .f.b} msg] $msg
} {1 {can't put .f.b inside .}}
grid_reset 3.7

test grid-4.1 {forget: basic argument checking} {
    list [catch {grid forget foo} msg] $msg
} {1 {bad window path name "foo"}}

test grid-4.2 {forget} {
    button .c
    grid [button .b]
    set a [grid slaves .]
    grid forget .b .c
    lappend a [grid slaves .]
    set a
} {.b {}}
grid_reset 4.2

test grid-4.3 {forget} {
    button .c
    grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx 3 -pady 4 -sticky ns
    grid forget .c
    grid .c -row 0 -column 0
    grid info .c
} {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}
grid_reset 4.3

test grid-4.4 {forget, calling Tk_UnmaintainGeometry} {
    frame .f -bd 2 -relief raised
    place .f -x 10 -y 20 -width 200 -height 100
    frame .f2 -width 50 -height 30 -bg red
    grid .f2 -in .f
    update
    set x [winfo ismapped .f2]
    grid forget .f2
    place .f -x 30
    update
    lappend x [winfo ismapped .f2]
} {1 0}
grid_reset 4.4

test grid-5.1 {info: basic argument checking} {
	list [catch {grid info a b} msg] $msg
} {1 {wrong # args: should be "grid info window"}}

test grid-5.2 {info} {
    frame .1 -width 75 -height 75 -bg red
    grid .1 -row 0 -column 0
    update
    list [catch {grid info .x} msg] $msg
} {1 {bad window path name ".x"}}
grid_reset 5.2

test grid-5.3 {info} {
    frame .1 -width 75 -height 75 -bg red
    grid .1 -row 0 -column 0
    update
    list [catch {grid info .1} msg] $msg
} {0 {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}}
grid_reset 5.3

test grid-5.4 {info} {
    frame .1 -width 75 -height 75 -bg red
    update
    list [catch {grid info .1} msg] $msg
} {0 {}}
grid_reset 5.4

test grid-6.1 {location: basic argument checking} {
	list [catch "grid location ." msg] $msg
} {1 {wrong # args: should be "grid location master x y"}}

test grid-6.2 {location: basic argument checking} {
	list [catch "grid location .bad 0 0" msg] $msg
} {1 {bad window path name ".bad"}}

test grid-6.3 {location: basic argument checking} {
	list [catch "grid location . x y" msg] $msg
} {1 {bad screen distance "x"}}

test grid-6.4 {location: basic argument checking} {
	list [catch "grid location . 1c y" msg] $msg
} {1 {bad screen distance "y"}}

test grid-6.5 {location: basic argument checking} {
	frame .f
	grid location .f 10 10
} {-1 -1}
grid_reset 6.5

test grid-6.6 {location (x)} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set got ""
    set result ""
    for {set x -10} { $x < 220} { incr x} {
	set a [grid location . $x 0]
	if {$a != $got} {
	    lappend result $x->$a
	    set got $a
	}
    }
    set result
} {{-10->-1 0} {0->0 0} {201->1 0}}
grid_reset 6.6

test grid-6.7 {location (y)} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set got ""
    set result ""
    for {set y -10} { $y < 110} { incr y} {
	set a [grid location . 0 $y]
	if {$a != $got} {
	    lappend result $y->$a
	    set got $a
	}
    }
    set result
} {{-10->0 -1} {0->0 0} {101->0 1}}
grid_reset 6.7

test grid-6.8 {location (weights)} {
    frame .f -width 300 -height 100 -highlightthickness 0 -bg red
    frame .a
    grid .a
    grid .f -in .a
    grid rowconfigure .f 0 -weight 1
    grid columnconfigure .f 0 -weight 1
    grid propagate .a 0
    .a configure -width 200 -height 15
    update
    set got ""
    set result ""
    for {set y -10} { $y < 210} { incr y} {
	set a [grid location . $y $y]
	if {$a != $got} {
	    lappend result $y->$a
	    set got $a
	}
    }
    set result
} {{-10->-1 -1} {0->0 0} {16->0 1} {201->1 1}}
grid_reset 6.8

test grid-6.9 {location: check updates pending} {nonPortable} {
	set a ""
	foreach i {0 1 2} {
	    frame .$i -width 120 -height 75 -bg red
	    lappend a [grid location . 150 90]
	    grid .$i -row $i -column $i
	}
	set a
} {{0 0} {1 1} {1 1}}
grid_reset 6.9

test grid-7.1 {propagate} {
    list [catch {grid propagate . 1 xxx} msg] $msg
} {1 {wrong # args: should be "grid propagate window ?boolean?"}}
grid_reset 7.1

test grid-7.2 {propagate} {
    list [catch {grid propagate .} msg] $msg
} {0 1}
grid_reset 7.2

test grid-7.3 {propagate} {
    list [catch {grid propagate . 0;grid propagate .} msg] $msg
} {0 0}
grid_reset 7.3

test grid-7.4 {propagate} {
    list [catch {grid propagate .x} msg] $msg
} {1 {bad window path name ".x"}}
grid_reset 7.4

test grid-7.5 {propagate} {
    list [catch {grid propagate . x} msg] $msg
} {1 {expected boolean value but got "x"}}
grid_reset 7.5

test grid-7.6 {propagate} {
    frame .f -width 100 -height 100 -bg red
    grid .f -row 0 -column 0
    update
    set a [winfo width .f]x[winfo height .f]
    grid propagate .f 0
    frame .g -width 75 -height 85 -bg green
    grid .g -in .f -row 0 -column 0
    update
    lappend a [winfo width .f]x[winfo height .f]
    grid propagate .f 1
    update
    lappend a [winfo width .f]x[winfo height .f]
    set a
} {100x100 100x100 75x85}
grid_reset 7.6


test grid-8.1 {size} {
    list [catch {grid size . foo} msg] $msg
} {1 {wrong # args: should be "grid size window"}}
grid_reset 8.1

test grid-8.2 {size} {
    list [catch {grid size .x} msg] $msg
} {1 {bad window path name ".x"}}
grid_reset 8.2

test grid-8.3 {size} {
    frame .f
    list [catch {grid size .f} msg] $msg
} {0 {0 0}}
grid_reset 8.3

test grid-8.4 {size} {
    catch {unset a}
    scale .f
    grid .f -row 0 -column 0
    update
    lappend a [grid size .]
    grid .f -row 4 -column 5
    update
    lappend a [grid size .]
    grid .f -row 947 -column 663
    update
    lappend a [grid size .]
    grid .f -row 0 -column 0
    update
    lappend a [grid size .]
    set a
} {{1 1} {6 5} {664 948} {1 1}}
grid_reset 8.4

test grid-8.5 {size} {
    catch {unset a}
    scale .f
    grid .f -row 0 -column 0
    update
    lappend a [grid size .]
    grid rowconfigure . 17 -weight 1
    update
    lappend a [grid size .]
    grid columnconfigure . 63 -weight 1
    update
    lappend a [grid size .]
    grid columnconfigure . 63 -weight 0
    grid rowconfigure . 17 -weight 0
    update
    lappend a [grid size .]
    set a
} {{1 1} {1 18} {64 18} {1 1}}
grid_reset 8.5

test grid-8.6 {size} {
    catch {unset a}
    scale .f
    grid .f -row 10 -column 50
    update
    lappend a [grid size .]
    grid columnconfigure . 15 -weight 1
    grid columnconfigure . 30 -weight 1
    update
    lappend a [grid size .]
    grid .f -row 10 -column 20
    update
    lappend a [grid size .]
    grid columnconfigure . 30 -weight 0
    update
    lappend a [grid size .]
    grid .f -row 0 -column 0
    update
    lappend a [grid size .]
    grid columnconfigure . 15 -weight 0
    update
    lappend a [grid size .]
    set a
} {{51 11} {51 11} {31 11} {21 11} {16 1} {1 1}}
grid_reset 8.6

test grid-9.1 {slaves} {
	list [catch {grid slaves .} msg] $msg
} {0 {}}

test grid-9.2 {slaves} {
	list [catch {grid slaves .foo} msg] $msg
} {1 {bad window path name ".foo"}}

test grid-9.3 {slaves} {
	list [catch {grid slaves a b} msg] $msg
} {1 {wrong # args: should be "grid slaves window ?-option value...?"}}

test grid-9.4 {slaves} {
	list [catch {grid slaves . a b} msg] $msg
} {1 {invalid args: should be "grid slaves window ?-option value...?"}}

test grid-9.5 {slaves} {
	list [catch {grid slaves . -foo x} msg] $msg
} {1 {expected integer but got "x"}}

test grid-9.6 {slaves} {
	list [catch {grid slaves . -foo -3} msg] $msg
} {1 {-foo is an invalid value: should NOT be < 0}}

test grid-9.7 {slaves} {
	list [catch {grid slaves . -foo 3} msg] $msg
} {1 {-foo is an invalid option: should be "-row, -column"}}

test grid-9.8 {slaves} {
	list [catch {grid slaves .x -row 3} msg] $msg
} {1 {bad window path name ".x"}}

test grid-9.9 {slaves} {
	list [catch {grid slaves . -row 3} msg] $msg
} {0 {}}

test grid-9.10 {slaves} {
	foreach i {0 1 2} {
	    label .$i -text $i
	    grid .$i -row $i -column $i
	}
	list [catch {grid slaves .} msg] $msg
} {0 {.2 .1 .0}}
grid_reset 9.10

test grid-9.11 {slaves} {
    catch {unset a}
    foreach i {0 1 2} {
	label .$i -text $i
	label .$i-x -text $i-x
	grid .$i -row $i -column $i
	grid .$i-x -row $i -column [incr i]
    }
    foreach row {0 1 2 3} {
	lappend a $row{[grid slaves . -row $row]}
    }
    foreach col {0 1 2 3} {
	lappend a $col{[grid slaves . -column $col]}
    }
    set a
} {{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}} 
grid_reset 9.11

# column/row configure

test grid-10.1 {column/row configure} {
	list [catch {grid columnconfigure .} msg] $msg
} {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
grid_reset 10.1

test grid-10.2 {column/row configure} {
	list [catch {grid columnconfigure . 0 -weight 0 -pad} msg] $msg
} {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
grid_reset 10.2

test grid-10.3 {column/row configure} {
	list [catch {grid columnconfigure .f 0 -weight} msg] $msg
} {1 {bad window path name ".f"}}
grid_reset 10.3

test grid-10.4 {column/row configure} {
	list [catch {grid columnconfigure . nine -weight} msg] $msg
} {1 {expected integer but got "nine"}}
grid_reset 10.4

test grid-10.5 {column/row configure} {
	list [catch {grid columnconfigure . 265 -weight} msg] $msg
} {0 0}
grid_reset 10.5

test grid-10.6 {column/row configure} {
	list [catch {grid columnconfigure . 0} msg] $msg
} {0 {-minsize 0 -pad 0 -weight 0}}
grid_reset 10.6

test grid-10.7 {column/row configure} {
	list [catch {grid columnconfigure . 0 -foo} msg] $msg
} {1 {invalid arg "-foo": expecting -minsize, -pad, or -weight.}}
grid_reset 10.7

test grid-10.8 {column/row configure} {
	list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
} {1 {bad screen distance "foo"}}
grid_reset 10.8

test grid-10.9 {column/row configure} {
	list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
} {1 {bad screen distance "foo"}}
grid_reset 10.9

test grid-10.10 {column/row configure} {
	grid columnconfigure . 0 -minsize 10
	grid columnconfigure . 0 -minsize
} {10}
grid_reset 10.10

test grid-10.11 {column/row configure} {
	list [catch {grid columnconfigure . 0 -weight bad} msg] $msg
} {1 {expected integer but got "bad"}}
grid_reset 10.10a

test grid-10.12 {column/row configure} {
	list [catch {grid columnconfigure . 0 -weight -3} msg] $msg
} {1 {invalid arg "-weight": should be non-negative}}
grid_reset 10.11

test grid-10.13 {column/row configure} {
	grid columnconfigure . 0 -weight 3
	grid columnconfigure . 0 -weight
} {3}
grid_reset 10.12

test grid-10.14 {column/row configure} {
	list [catch {grid columnconfigure . 0 -pad foo} msg] $msg
} {1 {bad screen distance "foo"}}
grid_reset 10.13

test grid-10.15 {column/row configure} {
	list [catch {grid columnconfigure . 0 -pad -3} msg] $msg
} {1 {invalid arg "-pad": should be non-negative}}
grid_reset 10.14

test grid-10.16 {column/row configure} {
	grid columnconfigure . 0 -pad 3
	grid columnconfigure . 0 -pad
} {3}
grid_reset 10.15

test grid-10.17 {column/row configure} {
	frame .f
	set a ""
	grid columnconfigure .f 0 -weight 0
	lappend a [grid columnconfigure .f 0 -weight]
	grid columnconfigure .f 0 -weight 1
	lappend a [grid columnconfigure .f 0 -weight]
	grid rowconfigure .f 0 -weight 0
	lappend a [grid rowconfigure .f 0 -weight]
	grid rowconfigure .f 0 -weight 1
	lappend a [grid columnconfigure .f 0 -weight]
	grid columnconfigure .f 0 -weight 0
	set a
} {0 1 0 1}
grid_reset 10.16

test grid-10.18 {column/row configure} {
	frame .f
	grid columnconfigure .f 0 -minsize 10 -weight 1
	list [grid columnconfigure .f 0 -minsize] \
		[grid columnconfigure .f 1 -minsize] \
		[grid columnconfigure .f 0 -weight] \
		[grid columnconfigure .f 1 -weight]
}  {10 0 1 0}
grid_reset 10.17

# auto-placement tests

test grid-11.1 {default widget placement} {
	list [catch {grid ^} msg] $msg
} {1 {can't use '^', cant find master}}
grid_reset 11.1

test grid-11.2 {default widget placement} {
	button .b
	list [catch {grid .b ^} msg] $msg
} {1 {can't find slave to extend with "^".}}
grid_reset 11.2

test grid-11.3 {default widget placement} {
	button .b
	list [catch {grid .b - - .c} msg] $msg
} {1 {bad window path name ".c"}}
grid_reset 11.3

test grid-11.4 {default widget placement} {
	button .b
	list [catch {grid .b - - = -} msg] $msg
} {1 {invalid window shortcut, "=" should be '-', 'x', or '^'}}
grid_reset 11.4

test grid-11.5 {default widget placement} {
	button .b
	list [catch {grid .b - x -} msg] $msg
} {1 {Must specify window before shortcut '-'.}}
grid_reset 11.5

test grid-11.6 {default widget placement} {
    foreach i {1 2 3 4 5 6} {
	frame .f$i -width 50 -height 50 -highlightthickness 0 -bg red
    }
    grid .f1 .f2 .f3 .f4
    grid .f5   -  x  .f6 -sticky nsew
    update
    set a ""
    foreach i {5 6} {
	lappend a "[winfo x .f$i],[winfo y .f$i] \
		[winfo width .f$i],[winfo height .f$i]"
    }
    set a
} {{0,50  100,50} {150,50  50,50}}
grid_reset 11.6

test grid-11.7 {default widget placement} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid .f -row 5 -column 5
    list [catch "grid .f x -" msg] $msg
} {1 {Must specify window before shortcut '-'.}}
grid_reset 11.7

test grid-11.8 {default widget placement} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid .f -row 5 -column 5
    list [catch "grid .f ^ -" msg] $msg
} {1 {Must specify window before shortcut '-'.}}
grid_reset 11.8

test grid-11.9 {default widget placement} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid .f -row 5 -column 5
    list [catch "grid .f x ^" msg] $msg
} {1 {can't find slave to extend with "^".}}
grid_reset 11.9

test grid-11.10 {default widget placement} {
    foreach i {1 2 3} {
		frame .f$i -width 100 -height 50 -highlightthickness 0 -bg red
    }
    grid .f1 .f2  -sticky nsew
    grid .f3   ^  -sticky nsew
    update
    set a ""
    foreach i {1 2 3} {
	lappend a "[winfo x .f$i],[winfo y .f$i] \
		[winfo width .f$i],[winfo height .f$i]"
    }
    set a
} {{0,0  100,50} {100,0  100,100} {0,50  100,50}}
grid_reset 11.10

test grid-11.11 {default widget placement} {
    foreach i {1 2 3 4 5 6 7 8 9 10 11 12} {
		frame .f$i -width 50 -height 50 -highlightthickness 1 -highlightbackground black
    }
    grid .f1  .f2  .f3 .f4 -sticky nsew
    grid .f5  .f6   -  .f7  -sticky nsew
    grid .f8    ^   ^  .f9  -sticky nsew
    grid .f10   ^   ^  .f11  -sticky nsew
	grid .f12   -   -   - -sticky nsew
    update
    set a ""
    foreach i {5 6 7 8 9 10 11 12 } {
	lappend a "[winfo x .f$i],[winfo y .f$i] \
		[winfo width .f$i],[winfo height .f$i]"
    }
    set a
} {{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}}
grid_reset 11.11

test grid-11.12 {default widget placement} {
    foreach i {1 2 3 4} {
		frame .f$i -width 75 -height 50 -highlightthickness 1 -highlightbackground black
    }
    grid .f1  .f2   .f3     -sticky nsew
    grid .f4    ^           -sticky nsew
    update
    set a ""
    foreach i {1 2 3 4} {
		lappend a "[winfo x .f$i],[winfo y .f$i] \
			[winfo width .f$i],[winfo height .f$i]"
    }
    grid .f4    ^   -column 1
    update
    foreach i {1 2 3 4} {
		lappend a "[winfo x .f$i],[winfo y .f$i] \
			[winfo width .f$i],[winfo height .f$i]"
	}
	set a
} {{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}}
grid_reset 11.12

test grid-11.13 {default widget placement} {
    foreach i {1 2 3 4 5 6 7} {
		frame .f$i -width 40 -height 50 -highlightthickness 1 -highlightbackground black
    }
    grid .f1  .f2  .f3 .f4 .f5 -sticky nsew
    grid .f6    -  .f7         -sticky nsew -columnspan 2
    update
    set a ""
    foreach i {6 7} {
	lappend a "[winfo x .f$i],[winfo y .f$i] \
		[winfo width .f$i],[winfo height .f$i]"
    }
    set a
} {{0,50  120,50} {120,50  80,50}}
grid_reset 11.13

test grid-11.14 {default widget placement} {
    foreach i {1 2 3} {
	frame .f$i -width 50 -height 50 -highlightthickness 0 -bg red
    }
    grid .f1 .f2
    grid  ^  .f3
    update
    set a ""
    foreach i {1 2 3} {
	lappend a "[winfo x .f$i],[winfo y .f$i] \
		[winfo width .f$i],[winfo height .f$i]"
    }
    set a
} {{0,25  50,50} {50,0  50,50} {50,50  50,50}}
grid_reset 11.14

test grid-12.1 {-sticky} {
    catch {unset data}
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    set a ""
    grid .f
    grid rowconfigure . 0 -weight 1
    grid columnconfigure . 0 -weight 1
    grid propagate . 0
    . configure -width 250 -height 150
    foreach i { {} n s e w ns ew nw ne se sw nse nsw sew new nsew} {
	grid .f -sticky $i
	update
	array set data [grid info .f]
	append a "($data(-sticky)) [winfo x .f] [winfo y .f] [winfo width .f] [winfo height .f]\n"
    }
    set a
} {() 25 25 200 100
(n) 25 0 200 100
(s) 25 50 200 100
(e) 50 25 200 100
(w) 0 25 200 100
(ns) 25 0 200 150
(ew) 0 25 250 100
(nw) 0 0 200 100
(ne) 50 0 200 100
(es) 50 50 200 100
(sw) 0 50 200 100
(nes) 50 0 200 150
(nsw) 0 0 200 150
(esw) 0 50 250 100
(new) 0 0 250 100
(nesw) 0 0 250 150
}
grid_reset 12.1
   
test grid-12.2 {-sticky} {
    frame .f -bg red
    list [catch "grid .f -sticky glue" msg] $msg
} {1 {bad stickyness value "glue": must be a string containing n, e, s, and/or w}}
grid_reset 12.2
   
test grid-12.3 {-sticky} {
    frame .f -bg red
    grid .f -sticky {n,s,e,w}
    array set A [grid info .f]
    set A(-sticky)
} {nesw}
grid_reset 12.3

test grid-13.1 {-in} {
    frame .f -bg red
    list [catch "grid .f -in .f" msg] $msg
} {1 {Window can't be managed in itself}}
grid_reset 13.1

test grid-13.2 {-in} {
    frame .f -bg red
    list [catch "grid .f -in .bad" msg] $msg
} {1 {bad window path name ".bad"}}
grid_reset 13.2

test grid-13.3 {-in} {
    frame .f -bg red
    toplevel .top
    list [catch "grid .f -in .top" msg] $msg
} {1 {can't put .f inside .top}}
destroy .top
grid_reset 13.3

test grid-13.4 {-ipadx} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    list [catch "grid .f -ipadx x" msg] $msg
} {1 {bad ipadx value "x": must be positive screen distance}}
grid_reset 13.4

test grid-13.5 {-ipadx} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set a [winfo width .f]
    grid .f -ipadx 1
    update
    list $a [winfo width .f]
} {200 202}
grid_reset 13.5

test grid-13.6 {-ipady} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    list [catch "grid .f -ipady x" msg] $msg
} {1 {bad ipady value "x": must be positive screen distance}}
grid_reset 13.6

test grid-13.7 {-ipady} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set a [winfo height .f]
    grid .f -ipady 1
    update
    list $a [winfo height .f]
} {100 102}
grid_reset 13.7

test grid-13.8 {-padx} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    list [catch "grid .f -padx x" msg] $msg
} {1 {bad padx value "x": must be positive screen distance}}
grid_reset 13.8

test grid-13.9 {-padx} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set a "[winfo width .f] [winfo width .]"
    grid .f -padx 1
    update
    list $a "[winfo width .f] [winfo width .]"
} {{200 200} {200 202}}
grid_reset 13.9

test grid-13.10 {-pady} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    list [catch "grid .f -pady x" msg] $msg
} {1 {bad pady value "x": must be positive screen distance}}
grid_reset 13.10

test grid-13.11 {-pady} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f
    update
    set a "[winfo height .f] [winfo height .]"
    grid .f -pady 1
    update
    list $a "[winfo height .f] [winfo height .]"
} {{100 100} {100 102}}
grid_reset 13.11

test grid-13.12 {-ipad x and y} {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid columnconfigure . 0 -minsize 150
    grid rowconfigure . 0 -minsize 100
    set a ""
    foreach x {0 5} {
    	foreach y {0 5} {
	    grid .f -ipadx $x -ipady $y
	    update
	    append a " $x,$y:"
	    foreach prop {x y width height} {
	    	append a ,[winfo $prop .f]
	    }
	}
    }
    set a
} { 0,0:,65,40,20,20 0,5:,65,35,20,30 5,0:,60,40,30,20 5,5:,60,35,30,30}
grid_reset 13.12

test grid-13.13 {reparenting} {
    frame .1
    frame .2
    button .b
    grid .1 .2
    grid .b -in .1
    set a ""
    catch {unset info}; array set info [grid info .b]
    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
    grid .b -in .2
    catch {unset info}; array set info [grid info .b]
    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
    unset info
    set a
} {.b,,.1 ,.b,.2}
grid_reset 13.13

test grid-14.1 {structure notify} {
    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
    frame .g -width 200 -height 100 -highlightthickness 0 -bg red
    grid .f 
    grid .g -in .f    
    update
    set a ""
    lappend a "[winfo x .g],[winfo y .g] \
        [winfo width .g],[winfo height .g]"
    .f configure -bd 5 -relief raised
    update
    lappend a "[winfo x .g],[winfo y .g] \
        [winfo width .g],[winfo height .g]"
    set a
} {{0,0  200,100} {5,5  200,100}}
grid_reset 14.1

test grid-14.2 {structure notify} {
    frame .f -width 200 -height 100 
    frame .f.g -width 200 -height 100 
    grid .f 
    grid .f.g
    update
    set a ""
    lappend a [grid bbox .],[grid bbox .f]
    .f config -bd 20
    update
    lappend a [grid bbox .],[grid bbox .f]
} {{0 0 200 100,0 0 200 100} {0 0 240 140,20 20 200 100}}
grid_reset 14.2

test grid-14.3 {map notify: bug 1648} {nonPortable} {
    # This test is nonPortable because the number of times
    # A(.) will be incremented is unspecified--the behavior
    # is different accross window managers.
    global A
    catch {unset A}
    bind . <Configure> {incr A(%W)}
    set A(.) 0
    foreach i {0 1 2} {
	frame .$i -width 100 -height 75
	set A(.$i) 0
    }
    grid .0 .1 .2
    update
    bind <Configure> .1 {destroy .0}
    .2 configure -bd 10
    update
    bind . <Configure> {}
    array get A
} {.2 2 .0 1 . 2 .1 1}
grid_reset 14.3

test grid-15.1 {lost slave} {
    button .b
    grid .b
    set a [grid slaves .]
    pack .b
    lappend a [grid slaves .]
    grid .b
    lappend a [grid slaves .]
} {.b {} .b}
grid_reset 15.1

test grid-15.2 {lost slave} {
    frame .f
    grid .f
    button .b
    grid .b -in .f
    set a [grid slaves .f]
    pack .b
    lappend a [grid slaves .f]
    grid .b -in .f
    lappend a [grid slaves .f]
} {.b {} .b}
grid_reset 15.2

test grid-16.1 {layout centering} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    }
    grid propagate . 0
    . configure -width 300 -height 250
    update
    grid bbox .
} {37 50 225 150}
grid_reset 16.1

test grid-16.2 {layout weights (expanding)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    	grid rowconfigure . $i -weight [expr $i + 1]
    	grid columnconfigure . $i -weight [expr $i + 1]
    }
    grid propagate . 0
    . configure -width 500 -height 300
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]
    }
    set a
} {120-75 167-100 213-125}
grid_reset 16.2

test grid-16.3 {layout weights (shrinking)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    	grid rowconfigure . $i -weight [expr $i + 1]
    	grid columnconfigure . $i -weight [expr $i + 1]
    }
    grid propagate . 0
    . configure -width 200 -height 150
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]
    }
    set a
} {84-63 66-50 50-37}
grid_reset 16.3

test grid-16.4 {layout weights (shrinking with minsize)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    	grid rowconfigure . $i -weight [expr $i + 1] -minsize 45
    	grid columnconfigure . $i -weight [expr $i + 1] -minsize 65
    }
    grid propagate . 0
    . configure -width 200 -height 150
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]
    }
    set a
} {70-60 65-45 65-45}
grid_reset 16.4

test grid-16.5 {layout weights (shrinking at minsize)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    	grid rowconfigure . $i -weight 0 -minsize 70
    	grid columnconfigure . $i -weight 0 -minsize 90
    }
    grid propagate . 0
    . configure -width 100 -height 75
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]
    }
    set a
} {100-75 100-75 100-75}
grid_reset 16.5


test grid-16.6 {layout weights (shrinking at minsize)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    	grid rowconfigure . $i -weight [expr $i + 1] -minsize 52
    	grid columnconfigure . $i -weight [expr $i + 1] -minsize 69
    }
    grid propagate . 0
    . configure -width 200 -height 150
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]
    }
    set a
} {69-52 69-52 69-52}
grid_reset 16.6

test grid-16.7 {layout weights (shrinking at minsize)} {
    foreach i {0 1 2} {
    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    }
    grid propagate . 0
    grid columnconfigure . 1 -weight 1 -minsize 0
    grid rowconfigure . 1 -weight 1 -minsize 0
    . configure -width 100 -height 75
    set a ""
    update
    foreach i {0 1 2} {
	lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
    }
    set a
} {100-75-1 1-1-0 200-150-1}
grid_reset 16.7

test grid-16.8 {layout internal constraints} {
    foreach i {0 1 2 3 4} {
    	frame .$i -bg gray  -width 30 -height 25 -bd 2 -relief ridge
    	grid .$i -row $i -column $i -sticky nswe
    }
    frame .f -bg red -width 250 -height 200
    frame .g -bg green -width 200 -height 180
    lower .f
    raise .g .f
    grid .f -row 1 -column 1 -rowspan 3 -columnspan 3 -sticky nswe
    grid .g -row 1 -column 1 -rowspan 2 -columnspan 2 -sticky nswe
    update
    set a ""
    foreach i {0 1 2 3 4} {
    	append a "[winfo x .$i] "
    }
    append a ", "
    grid remove .f
    update
    foreach i {0 1 2 3 4} {
    	append a "[winfo x .$i] "
    }
    append a ", "
    grid remove .g
    grid .f
    update
    foreach i {0 1 2 3 4} {
    	append a "[winfo x .$i] "
    }
    append a ", "
    grid remove .f
    update
    foreach i {0 1 2 3 4} {
    	append a "[winfo x .$i] "
    }
    set a
} {0 30 70 250 280 , 0 30 130 230 260 , 0 30 113 197 280 , 0 30 60 90 120 }

test grid-17.1 {forget and pending idle handlers} {
    # This test is intended to detect a crash caused by a failure to remove
    # pending idle handlers when grid forget is invoked.

    toplevel .t
    wm geometry .t +0+0
    frame .t.f
    label .t.f.l -text foobar
    grid .t.f.l
    grid .t.f
    update
    grid forget .t.f.l
    grid forget .t.f
    destroy .t

    toplevel .t -geometry +0+0
    frame .t.f
    label .t.f.l -text foobar
    grid .t.f.l
    destroy .t
    set result ok
} ok

# cleanup
::tcltest::cleanupTests
return