summaryrefslogtreecommitdiffstats
path: root/tests/border.test
blob: e59b405c3a2a8c314248b99844d227a54380cfc7 (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
# This file is a Tcl script to test out the procedures in the file
# tkBorder.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id: border.test,v 1.2 1999/04/16 01:51:34 stanton Exp $

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

if {[info commands testborder] != "testborder"} {
    puts "testborder command not available; skipping tests"
    ::tcltest::cleanupTests
    return
}

eval destroy [winfo children .]
wm geometry . {}
raise .

# Create a top-level with its own colormap (so we can test under
# controlled conditions), then check to make sure that the visual
# is color-mapped with 256 borders.  If not, just skip this whole
# test file.

if [catch {toplevel .t -visual {pseudocolor 8} -colormap new}] {
    ::tcltest::cleanupTests
    return
}
wm geom .t +0+0
if {[winfo depth .t] != 8} {
    destroy .t
    ::tcltest::cleanupTests
    return
}

test border-1.1 {Tk_AllocBorderFromObj - converting internal reps} {
    set x orange
    lindex $x 0
    destroy .b1
    button .b1 -bg $x -text .b1
    lindex $x 0
    testborder orange
} {{1 0}}
test border-1.3 {Tk_AllocBorderFromObj - discard stale border} {
    set x orange
    destroy .b1 .b2
    button .b1 -bg $x -text First
    destroy .b1
    set result {}
    lappend result [testborder orange]
    button .b2 -bg $x -text Second
    lappend result [testborder orange]
} {{} {{1 1}}}
test border-1.2 {Tk_AllocBorderFromObj - reuse existing border} {
    set x orange
    destroy .b1 .b2
    button .b1 -bg $x -text First
    set result {}
    lappend result [testborder orange]
    button .b2 -bg $x -text Second
    pack .b1 .b2 -side top
    lappend result [testborder orange]
} {{{1 1}} {{2 1}}}
test border-1.4 {Tk_AllocBorderFromObj - try other borders in list} {
    set x purple
    destroy .b1 .b2 .t.b
    button .b1 -bg $x -text First
    pack .b1 -side top
    set result {}
    lappend result [testborder purple]
    button .t.b -bg $x -text Second
    pack .t.b -side top
    lappend result [testborder purple]
    button .b2 -bg $x -text Third
    pack .b2 -side top
    lappend result [testborder purple]
} {{{1 1}} {{1 1} {1 0}} {{1 0} {2 1}}}

test border-3.1 {Tk_Free3DBorder - reference counts} {
    set x purple
    destroy .b1 .b2 .t.b
    button .b1 -bg $x -text First
    pack .b1 -side top
    button .t.b -bg $x -text Second
    pack .t.b -side top
    button .b2 -bg $x -text Third
    pack .b2 -side top
    set result {}
    lappend result [testborder purple]
    destroy .b1
    lappend result [testborder purple]
    destroy .b2
    lappend result [testborder purple]
    destroy .t.b
    lappend result [testborder purple]
} {{{1 0} {2 1}} {{1 0} {1 1}} {{1 0}} {}}
test border-3.4 {Tk_Free3DBorder - unlinking from list} {
    destroy .b .t.b .t2 .t3
    toplevel .t2 -visual {pseudocolor 8} -colormap new
    toplevel .t3 -visual {pseudocolor 8} -colormap new
    set x purple
    button .b -bg $x -text .b1
    button .t.b1 -bg $x -text .t.b1
    button .t.b2 -bg $x -text .t.b2
    button .t2.b1 -bg $x -text .t2.b1
    button .t2.b2 -bg $x -text .t2.b2
    button .t2.b3 -bg $x -text .t2.b3
    button .t3.b1 -bg $x -text .t3.b1
    button .t3.b2 -bg $x -text .t3.b2
    button .t3.b3 -bg $x -text .t3.b3
    button .t3.b4 -bg $x -text .t3.b4
    set result {}
    lappend result [testborder purple]
    destroy .t2
    lappend result [testborder purple]
    destroy .b
    lappend result [testborder purple]
    destroy .t3
    lappend result [testborder purple]
    destroy .t
    lappend result [testborder purple]
} {{{4 1} {3 0} {2 0} {1 0}} {{4 1} {2 0} {1 0}} {{4 1} {2 0}} {{2 0}} {}}

test border-4.1 {FreeBorderObjProc} {
    destroy .b
    set x [format purple]
    button .b -bg $x -text .b1
    set y [format purple]
    .b configure -bg $y
    set z [format purple]
    .b configure -bg $z
    set result {}
    lappend result [testborder purple]
    set x red
    lappend result [testborder purple]
    set z 32
    lappend result [testborder purple]
    destroy .b
    lappend result [testborder purple]
    set y bogus
    set result
} {{{1 3}} {{1 2}} {{1 1}} {}}

catch {destroy .b}
button .b
test get-2.1 {Tk_GetReliefFromObj} {
    .b configure -relief flat
    .b cget -relief
} {flat}
test get-2.2 {Tk_GetReliefFromObj} {
    .b configure -relief groove
    .b cget -relief
} {groove}
test get-2.3 {Tk_GetReliefFromObj} {
    .b configure -relief raised
    .b cget -relief
} {raised}
test get-2.3 {Tk_GetReliefFromObj} {
    .b configure -relief ridge
    .b cget -relief
} {ridge}
test get-2.3 {Tk_GetReliefFromObj} {
    .b configure -relief solid
    .b cget -relief
} {solid}
test get-2.3 {Tk_GetReliefFromObj} {
    .b configure -relief sunken
    .b cget -relief
} {sunken}
test get-2.4 {Tk_GetReliefFromObj - error} {
    list [catch {.b configure -relief upanddown} msg] $msg
} {1 {bad relief "upanddown": must be flat, groove, raised, ridge, solid, or sunken}}

destroy .t

# cleanup
::tcltest::cleanupTests
return