OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [tests/] [option.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file is a Tcl script to test out the option-handling facilities
2
# of Tk.  It is organized in the standard fashion for Tcl tests.
3
#
4
# Copyright (c) 1991-1993 The Regents of the University of California.
5
# Copyright (c) 1994 Sun Microsystems, Inc.
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
# RCS: @(#) $Id: option.test,v 1.1.1.1 2002-01-16 10:25:59 markom Exp $
11
 
12
if {[string compare test [info procs test]] == 1} then \
13
  {source defs}
14
 
15
catch {destroy .op1}
16
catch {destroy .op2}
17
set appName [winfo name .]
18
 
19
# First, test basic retrievals, being sure to trigger all the various
20
# types of NodeElements (EXACT_LEAF_NAME, WILDCARD_NODE_CLASS, and
21
# everything in-between).
22
 
23
frame .op1 -class Class1
24
frame .op2 -class Class2
25
frame .op1.op3 -class Class1
26
frame .op1.op4 -class Class3
27
frame .op2.op5 -class Class2
28
frame .op1.op3.op6 -class Class4
29
 
30
option clear
31
option add *Color1 red
32
option add *x blue
33
option add *Class1.x yellow
34
option add $appName.op1.x green
35
option add *Class2.Color1 orange
36
option add $appName.op2.op5.Color2 purple
37
option add $appName.Class1.Class3.y brown
38
option add $appName*op6*Color2 black
39
option add $appName*Class1.op1.Color2 grey
40
 
41
test option-1.1 {basic option retrieval} {option get . x Color1} blue
42
test option-1.2 {basic option retrieval} {option get . y Color1} red
43
test option-1.3 {basic option retrieval} {option get . z Color1} red
44
test option-1.4 {basic option retrieval} {option get . x Color2} blue
45
test option-1.5 {basic option retrieval} {option get . y Color2} {}
46
test option-1.6 {basic option retrieval} {option get . z Color2} {}
47
 
48
test option-2.1 {basic option retrieval} {option get .op1 x Color1} green
49
test option-2.2 {basic option retrieval} {option get .op1 y Color1} red
50
test option-2.3 {basic option retrieval} {option get .op1 z Color1} red
51
test option-2.4 {basic option retrieval} {option get .op1 x Color2} green
52
test option-2.5 {basic option retrieval} {option get .op1 y Color2} {}
53
test option-2.6 {basic option retrieval} {option get .op1 z Color2} {}
54
 
55
test option-3.1 {basic option retrieval} {option get .op1.op3 x Color1} yellow
56
test option-3.2 {basic option retrieval} {option get .op1.op3 y Color1} red
57
test option-3.3 {basic option retrieval} {option get .op1.op3 z Color1} red
58
test option-3.4 {basic option retrieval} {option get .op1.op3 x Color2} yellow
59
test option-3.5 {basic option retrieval} {option get .op1.op3 y Color2} {}
60
test option-3.6 {basic option retrieval} {option get .op1.op3 z Color2} {}
61
 
62
test option-4.1 {basic option retrieval} {option get .op1.op3.op6 x Color1} blue
63
test option-4.2 {basic option retrieval} {option get .op1.op3.op6 y Color1} red
64
test option-4.3 {basic option retrieval} {option get .op1.op3.op6 z Color1} red
65
test option-4.4 {basic option retrieval} {option get .op1.op3.op6 x Color2} black
66
test option-4.5 {basic option retrieval} {option get .op1.op3.op6 y Color2} black
67
test option-4.6 {basic option retrieval} {option get .op1.op3.op6 z Color2} black
68
 
69
test option-5.1 {basic option retrieval} {option get .op1.op4 x Color1} blue
70
test option-5.2 {basic option retrieval} {option get .op1.op4 y Color1} brown
71
test option-5.3 {basic option retrieval} {option get .op1.op4 z Color1} red
72
test option-5.4 {basic option retrieval} {option get .op1.op4 x Color2} blue
73
test option-5.5 {basic option retrieval} {option get .op1.op4 y Color2} brown
74
test option-5.6 {basic option retrieval} {option get .op1.op4 z Color2} {}
75
 
76
test option-6.1 {basic option retrieval} {option get .op2 x Color1} orange
77
test option-6.2 {basic option retrieval} {option get .op2 y Color1} orange
78
test option-6.3 {basic option retrieval} {option get .op2 z Color1} orange
79
test option-6.4 {basic option retrieval} {option get .op2 x Color2} blue
80
test option-6.5 {basic option retrieval} {option get .op2 y Color2} {}
81
test option-6.6 {basic option retrieval} {option get .op2 z Color2} {}
82
 
83
test option-7.1 {basic option retrieval} {option get .op2.op5 x Color1} orange
84
test option-7.2 {basic option retrieval} {option get .op2.op5 y Color1} orange
85
test option-7.3 {basic option retrieval} {option get .op2.op5 z Color1} orange
86
test option-7.4 {basic option retrieval} {option get .op2.op5 x Color2} purple
87
test option-7.5 {basic option retrieval} {option get .op2.op5 y Color2} purple
88
test option-7.6 {basic option retrieval} {option get .op2.op5 z Color2} purple
89
 
90
# Now try similar tests to above, except jump around non-hierarchically
91
# between windows to make sure that the option stacks are pushed and
92
# popped correctly.
93
 
94
option get . foo Foo
95
test option-8.1 {stack pushing/popping} {option get .op2.op5 x Color1} orange
96
test option-8.2 {stack pushing/popping} {option get .op2.op5 y Color1} orange
97
test option-8.3 {stack pushing/popping} {option get .op2.op5 z Color1} orange
98
test option-8.4 {stack pushing/popping} {option get .op2.op5 x Color2} purple
99
test option-8.5 {stack pushing/popping} {option get .op2.op5 y Color2} purple
100
test option-8.6 {stack pushing/popping} {option get .op2.op5 z Color2} purple
101
 
102
test option-9.1 {stack pushing/popping} {option get . x Color1} blue
103
test option-9.2 {stack pushing/popping} {option get . y Color1} red
104
test option-9.3 {stack pushing/popping} {option get . z Color1} red
105
test option-9.4 {stack pushing/popping} {option get . x Color2} blue
106
test option-9.5 {stack pushing/popping} {option get . y Color2} {}
107
test option-9.6 {stack pushing/popping} {option get . z Color2} {}
108
 
109
test option-10.1 {stack pushing/popping} {option get .op1.op3.op6 x Color1} blue
110
test option-10.2 {stack pushing/popping} {option get .op1.op3.op6 y Color1} red
111
test option-10.3 {stack pushing/popping} {option get .op1.op3.op6 z Color1} red
112
test option-10.4 {stack pushing/popping} {option get .op1.op3.op6 x Color2} black
113
test option-10.5 {stack pushing/popping} {option get .op1.op3.op6 y Color2} black
114
test option-10.6 {stack pushing/popping} {option get .op1.op3.op6 z Color2} black
115
 
116
test option-11.1 {stack pushing/popping} {option get .op1.op3 x Color1} yellow
117
test option-11.2 {stack pushing/popping} {option get .op1.op3 y Color1} red
118
test option-11.3 {stack pushing/popping} {option get .op1.op3 z Color1} red
119
test option-11.4 {stack pushing/popping} {option get .op1.op3 x Color2} yellow
120
test option-11.5 {stack pushing/popping} {option get .op1.op3 y Color2} {}
121
test option-11.6 {stack pushing/popping} {option get .op1.op3 z Color2} {}
122
 
123
test option-12.1 {stack pushing/popping} {option get .op1 x Color1} green
124
test option-12.2 {stack pushing/popping} {option get .op1 y Color1} red
125
test option-12.3 {stack pushing/popping} {option get .op1 z Color1} red
126
test option-12.4 {stack pushing/popping} {option get .op1 x Color2} green
127
test option-12.5 {stack pushing/popping} {option get .op1 y Color2} {}
128
test option-12.6 {stack pushing/popping} {option get .op1 z Color2} {}
129
 
130
# Test the major priority levels (widgetDefault, etc.)
131
 
132
option add $appName.op1.a 100 100
133
option add $appName.op1.A interactive interactive
134
option add $appName.op1.b userDefault userDefault
135
option add $appName.op1.B startupFile startupFile
136
option add $appName.op1.c widgetDefault widgetDefault
137
option add $appName.op1.C 0 0
138
 
139
test option-13.1 {priority levels} {option get .op1 a A} 100
140
test option-13.2 {priority levels} {option get .op1 b A} interactive
141
test option-13.3 {priority levels} {option get .op1 b B} userDefault
142
test option-13.4 {priority levels} {option get .op1 c B} startupFile
143
test option-13.5 {priority levels} {option get .op1 c C} widgetDefault
144
option add $appName.op1.B file2 widget
145
test option-13.6 {priority levels} {option get .op1 c B} startupFile
146
option add $appName.op1.B file2 startupFile
147
test option-13.7 {priority levels} {option get .op1 c B} file2
148
 
149
# Test various error conditions
150
 
151
test option-14.1 {error conditions} {
152
    list [catch {option} msg] $msg
153
} {1 {wrong # args: should be "option cmd arg ?arg ...?"}}
154
test option-14.2 {error conditions} {
155
    list [catch {option x} msg] $msg
156
} {1 {bad option "x": must be add, clear, get, or readfile}}
157
test option-14.3 {error conditions} {
158
    list [catch {option foo 3} msg] $msg
159
} {1 {bad option "foo": must be add, clear, get, or readfile}}
160
test option-14.4 {error conditions} {
161
    list [catch {option add 3} msg] $msg
162
} {1 {wrong # args: should be "option add pattern value ?priority?"}}
163
test option-14.5 {error conditions} {
164
    list [catch {option add . a b c} msg] $msg
165
} {1 {wrong # args: should be "option add pattern value ?priority?"}}
166
test option-14.6 {error conditions} {
167
    list [catch {option add . a -1} msg] $msg
168
} {1 {bad priority level "-1": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
169
test option-14.7 {error conditions} {
170
    list [catch {option add . a 101} msg] $msg
171
} {1 {bad priority level "101": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
172
test option-14.8 {error conditions} {
173
    list [catch {option add . a gorp} msg] $msg
174
} {1 {bad priority level "gorp": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
175
test option-14.9 {error conditions} {
176
    list [catch {option get 3} msg] $msg
177
} {1 {wrong # args: should be "option get window name class"}}
178
test option-14.10 {error conditions} {
179
    list [catch {option get 3 4} msg] $msg
180
} {1 {wrong # args: should be "option get window name class"}}
181
test option-14.11 {error conditions} {
182
    list [catch {option get 3 4 5 6} msg] $msg
183
} {1 {wrong # args: should be "option get window name class"}}
184
test option-14.12 {error conditions} {
185
    list [catch {option get .gorp.gorp a A} msg] $msg
186
} {1 {bad window path name ".gorp.gorp"}}
187
 
188
if {$tcl_platform(os) == "Win32s"} {
189
    set option1 OPTION~2.FIL
190
    set option2 OPTION~1.FIL
191
    set option3 OPTION~3.FIL
192
} else {
193
    set option1 option.file1
194
    set option2 option.file2
195
    set option3 option.file3
196
}
197
 
198
test option-15.1 {database files} {
199
    list [catch {option read non-existent} msg] $msg
200
} {1 {couldn't open "non-existent": no such file or directory}}
201
option read $option1
202
test option-15.2 {database files} {option get . x1 color} blue
203
if {$appName == "tktest"} {
204
    test option-15.3 {database files} {option get . x2 color} green
205
}
206
test option-15.4 {database files} {option get . x3 color} purple
207
test option-15.5 {database files} {option get . {x 4} color} brown
208
test option-15.6 {database files} {option get . x6 color} {}
209
test option-15.7 {database files} {
210
    list [catch {option read $option1 widget foo} msg] $msg
211
} {1 {wrong # args: should be "option readfile fileName ?priority?"}}
212
option add *x3 burgundy
213
catch {option read $option1 userDefault}
214
test option-15.8 {database files} {option get . x3 color} burgundy
215
test option-15.9 {database files} {
216
    list [catch {option read $option2} msg] $msg
217
} {1 {missing colon on line 2}}
218
 
219
test option-16.1 {ReadOptionFile} {
220
    set file [open "$option3" w]
221
    fconfigure $file -translation crlf
222
    puts $file "*x7: true\n*x8: false"
223
    close $file
224
    option read $option3 userDefault
225
    set result [list [option get . x7 color] [option get . x8 color]]
226
    removeFile $option3
227
    set result
228
} {true false}
229
 
230
catch {destroy .op1}
231
catch {destroy .op2}
232
concat {}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.