summaryrefslogtreecommitdiffstats
path: root/tests/ttk/panedwindow.test
blob: 47764a2db7bd56e52269d75461acb5703f347423 (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
#
# $Id: panedwindow.test,v 1.3 2007/06/09 21:45:45 jenglish Exp $
#

package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
loadTestedCommands


# Basic sanity checks:
#
test panedwindow-1.0 "Setup" -body {
    ttk::panedwindow .pw
} -result .pw

test panedwindow-1.1 "Make sure empty panedwindow doesn't crash" -body {
    pack .pw -expand true -fill both
    update
}

test panedwindow-1.2 "Add a pane" -body {
    .pw add [ttk::frame .pw.f1]
    winfo manager .pw.f1
} -result "panedwindow"

test panedwindow-1.3 "Steal pane" -body {
    pack .pw.f1 -side bottom
    winfo manager .pw.f1
} -result "pack"

test panedwindow-1.4 "Make sure empty panedwindow still doesn't crash" -body {
    update
}

test panedwindow-1.5 "Remanage pane" -body {
    #XXX .pw insert 0 .pw.f1
    .pw add .pw.f1
    winfo manager .pw.f1
} -result "panedwindow"

test panedwindow-1.6 "Forget pane" -body {
    .pw forget .pw.f1
    winfo manager .pw.f1
} -result ""

test panedwindow-1.7 "Make sure empty panedwindow still still doesn't crash" -body {
    update
}

test panedwindow-1.8 "Re-forget pane" -body {
    .pw forget .pw.f1
} -returnCodes 1 -result ".pw.f1 is not managed by .pw"

test panedwindow-1.end "Cleanup" -body {
    destroy .pw
}

# Resize behavior:
#
test panedwindow-2.1 "..." -body {
    ttk::panedwindow .pw -orient horizontal

    .pw add [listbox .pw.l1]
    .pw add [listbox .pw.l2]
    .pw add [listbox .pw.l3]
    .pw add [listbox .pw.l4]

    pack .pw -expand true -fill both
    update
    set w1 [winfo width .]

    # This should make the window shrink:
    destroy .pw.l2

    update
    set w2 [winfo width .]

    expr {$w2 < $w1}
} -result 1

test panedwindow-2.2 "..., cont'd" -body {

    # This should keep the window from shrinking:
    wm geometry . [wm geometry .]

    set rw2 [winfo reqwidth .pw]

    destroy .pw.l1
    update

    set w3 [winfo width .]
    set rw3 [winfo reqwidth .pw]

    expr {$w3 == $w2 && $rw3 < $rw2}
    # problem: [winfo reqwidth] shrinks, but sashes haven't moved
    # since we haven't gotten a ConfigureNotify.
    # How to (a) check for this, and (b) fix it?
} -result 1

test panedwindow-2.3 "..., cont'd" -body {

    .pw add [listbox .pw.l5]
    update
    set rw4 [winfo reqwidth .pw]

    expr {$rw4 > $rw3}
} -result 1

test panedwindow-2.end "Cleanup" -body { destroy .pw }

#
# ...
#
test panedwindow-3.0 "configure pane" -body {
    ttk::panedwindow .pw
    .pw add [listbox .pw.lb1] 
    .pw add [listbox .pw.lb2] 
    .pw pane 1 -weight 2
    .pw pane 1 -weight
} -result 2

test panedwindow-3.1 "configure pane -- errors" -body {
    .pw pane 1 -weight -4
} -returnCodes 1 -match glob -result "-weight must be nonnegative"

test panedwindow-3.2 "add pane -- errors" -body {
    .pw add [ttk::label .pw.l] -weight -1
} -returnCodes 1 -match glob -result "-weight must be nonnegative"


test panedwindow-3.end "cleanup" -body { destroy .pw }


test panedwindow-4.1 "forget" -body {
    pack [ttk::panedwindow .pw -orient vertical] -expand true -fill both
    .pw add [label .pw.l1 -text "L1"]
    .pw add [label .pw.l2 -text "L2"]
    .pw add [label .pw.l3 -text "L3"]
    .pw add [label .pw.l4 -text "L4"]

    update

    .pw forget .pw.l1
    .pw forget .pw.l2
    .pw forget .pw.l3
    .pw forget .pw.l4
    update
}

test panedwindow-4.2 "forget forgotten" -body {
    .pw forget .pw.l1
} -returnCodes 1 -result ".pw.l1 is not managed by .pw"

# checkorder $winlist --
#	Ensure that Y coordinates windows in $winlist are strictly increasing.
#
proc checkorder {winlist} {
    set pos -1
    set positions [list]
    foreach win $winlist {
    	lappend positions [set nextpos [winfo y $win]]
	if {$nextpos <= $pos} {
	    error "window $win out of order ($positions)"
	}
	set pos $nextpos
    }
}

test panedwindow-4.3 "insert command" -body {
    .pw insert end .pw.l1
    .pw insert end .pw.l3
    .pw insert 1 .pw.l2
    .pw insert end .pw.l4

    update;
    checkorder {.pw.l1 .pw.l2 .pw.l3 .pw.l4}
}

test panedwindow-4.END "cleanup" -body {
    destroy .pw
}

# See #1292219

test panedwindow-5.1 "Propage Map/Unmap state to children" -body {
    set result [list]
    pack [ttk::panedwindow .pw]
    .pw add [ttk::button .pw.b]
    update

    lappend result [winfo ismapped .pw] [winfo ismapped .pw.b]

    pack forget .pw
    update
    lappend result [winfo ismapped .pw] [winfo ismapped .pw.b]

    set result
} -result [list 1 1 0 0] -cleanup {
    destroy .pw
}

tcltest::cleanupTests