summaryrefslogtreecommitdiffstats
path: root/tests/option.test
blob: 1d6094b0cb35e6c520b18f162856d48de1245418 (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
# This file is a Tcl script to test out the option-handling facilities
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1991-1993 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint appNameIsTktest [expr {[winfo name .] eq "tktest"}]

deleteWindows
set appName [winfo name .]

# First, test basic retrievals, being sure to trigger all the various
# types of NodeElements (EXACT_LEAF_NAME, WILDCARD_NODE_CLASS, and
# everything in-between).

frame .op1 -class Class1
frame .op2 -class Class2
frame .op1.op3 -class Class1
frame .op1.op4 -class Class3
frame .op2.op5 -class Class2
frame .op1.op3.op6 -class Class4

# Configurations for tests 1.* - 12.*
option clear
option add *Color1 red
option add *x blue
option add *Class1.x yellow
option add $appName.op1.x green
option add *Class2.Color1 orange
option add $appName.op2.op5.Color2 purple
option add $appName.Class1.Class3.y brown
option add $appName*op6*Color2 black
option add $appName*Class1.op1.Color2 grey

test option-1.1 {basic option retrieval} -body {
    option get . x Color1
} -result blue
test option-1.2 {basic option retrieval} -body {
    option get . y Color1
} -result red
test option-1.3 {basic option retrieval} -body {
    option get . z Color1
} -result red
test option-1.4 {basic option retrieval} -body {
    option get . x Color2
} -result blue
test option-1.5 {basic option retrieval} -body {
    option get . y Color2
} -result {}
test option-1.6 {basic option retrieval} -body {
    option get . z Color2
} -result {}


test option-2.1 {basic option retrieval} -body {
    option get .op1 x Color1
} -result green
test option-2.2 {basic option retrieval} -body {
    option get .op1 y Color1
} -result red
test option-2.3 {basic option retrieval} -body {
    option get .op1 z Color1
} -result red
test option-2.4 {basic option retrieval} -body {
    option get .op1 x Color2
} -result green
test option-2.5 {basic option retrieval} -body {
    option get .op1 y Color2
} -result {}
test option-2.6 {basic option retrieval} -body {
    option get .op1 z Color2
} -result {}


test option-3.1 {basic option retrieval} -body {
    option get .op1.op3 x Color1
} -result yellow
test option-3.2 {basic option retrieval} -body {
    option get .op1.op3 y Color1
} -result red
test option-3.3 {basic option retrieval} -body {
    option get .op1.op3 z Color1
} -result red
test option-3.4 {basic option retrieval} -body {
    option get .op1.op3 x Color2
} -result yellow
test option-3.5 {basic option retrieval} -body {
    option get .op1.op3 y Color2
} -result {}
test option-3.6 {basic option retrieval} -body {
    option get .op1.op3 z Color2
} -result {}


test option-4.1 {basic option retrieval} -body {
    option get .op1.op3.op6 x Color1
} -result blue
test option-4.2 {basic option retrieval} -body {
    option get .op1.op3.op6 y Color1
} -result red
test option-4.3 {basic option retrieval} -body {
    option get .op1.op3.op6 z Color1
} -result red
test option-4.4 {basic option retrieval} -body {
    option get .op1.op3.op6 x Color2
} -result black
test option-4.5 {basic option retrieval} -body {
    option get .op1.op3.op6 y Color2
} -result black
test option-4.6 {basic option retrieval} -body {
    option get .op1.op3.op6 z Color2
} -result black


test option-5.1 {basic option retrieval} -body {
    option get .op1.op4 x Color1
} -result blue
test option-5.2 {basic option retrieval} -body {
    option get .op1.op4 y Color1
} -result brown
test option-5.3 {basic option retrieval} -body {
    option get .op1.op4 z Color1
} -result red
test option-5.4 {basic option retrieval} -body {
    option get .op1.op4 x Color2
} -result blue
test option-5.5 {basic option retrieval} -body {
    option get .op1.op4 y Color2
} -result brown
test option-5.6 {basic option retrieval} -body {
    option get .op1.op4 z Color2
} -result {}


test option-6.1 {basic option retrieval} -body {
    option get .op2 x Color1
} -result orange
test option-6.2 {basic option retrieval} -body {
    option get .op2 y Color1
} -result orange
test option-6.3 {basic option retrieval} -body {
    option get .op2 z Color1
} -result orange
test option-6.4 {basic option retrieval} -body {
    option get .op2 x Color2
} -result blue
test option-6.5 {basic option retrieval} -body {
    option get .op2 y Color2
} -result {}
test option-6.6 {basic option retrieval} -body {
    option get .op2 z Color2
} -result {}


test option-7.1 {basic option retrieval} -body {
    option get .op2.op5 x Color1
} -result orange
test option-7.2 {basic option retrieval} -body {
    option get .op2.op5 y Color1
} -result orange
test option-7.3 {basic option retrieval} -body {
    option get .op2.op5 z Color1
} -result orange
test option-7.4 {basic option retrieval} -body {
    option get .op2.op5 x Color2
} -result purple
test option-7.5 {basic option retrieval} -body {
    option get .op2.op5 y Color2
} -result purple
test option-7.6 {basic option retrieval} -body {
    option get .op2.op5 z Color2
} -result purple


# Now try similar tests to above, except jump around non-hierarchically
# between windows to make sure that the option stacks are pushed and
# popped correctly.

option get . foo Foo
test option-8.1 {stack pushing/popping} -body {
    option get .op2.op5 x Color1
} -result orange
test option-8.2 {stack pushing/popping} -body {
    option get .op2.op5 y Color1
} -result orange
test option-8.3 {stack pushing/popping} -body {
    option get .op2.op5 z Color1
} -result orange
test option-8.4 {stack pushing/popping} -body {
    option get .op2.op5 x Color2
} -result purple
test option-8.5 {stack pushing/popping} -body {
    option get .op2.op5 y Color2
} -result purple
test option-8.6 {stack pushing/popping} -body {
    option get .op2.op5 z Color2
} -result purple


test option-9.1 {stack pushing/popping} -body {
    option get . x Color1
} -result blue
test option-9.2 {stack pushing/popping} -body {
    option get . y Color1
} -result red
test option-9.3 {stack pushing/popping} -body {
    option get . z Color1
} -result red
test option-9.4 {stack pushing/popping} -body {
    option get . x Color2
} -result blue
test option-9.5 {stack pushing/popping} -body {
    option get . y Color2
} -result {}
test option-9.6 {stack pushing/popping} -body {
    option get . z Color2
} -result {}


test option-10.1 {stack pushing/popping} -body {
    option get .op1.op3.op6 x Color1
} -result blue
test option-10.2 {stack pushing/popping} -body {
    option get .op1.op3.op6 y Color1
} -result red
test option-10.3 {stack pushing/popping} -body {
    option get .op1.op3.op6 z Color1
} -result red
test option-10.4 {stack pushing/popping} -body {
    option get .op1.op3.op6 x Color2
} -result black
test option-10.5 {stack pushing/popping} -body {
    option get .op1.op3.op6 y Color2
} -result black
test option-10.6 {stack pushing/popping} -body {
    option get .op1.op3.op6 z Color2
} -result black


test option-11.1 {stack pushing/popping} -body {
    option get .op1.op3 x Color1
} -result yellow
test option-11.2 {stack pushing/popping} -body {
    option get .op1.op3 y Color1
} -result red
test option-11.3 {stack pushing/popping} -body {
    option get .op1.op3 z Color1
} -result red
test option-11.4 {stack pushing/popping} -body {
    option get .op1.op3 x Color2
} -result yellow
test option-11.5 {stack pushing/popping} -body {
    option get .op1.op3 y Color2
} -result {}
test option-11.6 {stack pushing/popping} -body {
    option get .op1.op3 z Color2
} -result {}


test option-12.1 {stack pushing/popping} -body {
    option get .op1 x Color1
} -result green
test option-12.2 {stack pushing/popping} -body {
    option get .op1 y Color1
} -result red
test option-12.3 {stack pushing/popping} -body {
    option get .op1 z Color1
} -result red
test option-12.4 {stack pushing/popping} -body {
    option get .op1 x Color2
} -result green
test option-12.5 {stack pushing/popping} -body {
    option get .op1 y Color2
} -result {}
test option-12.6 {stack pushing/popping} -body {
    option get .op1 z Color2
} -result {}

# Test the major priority levels (widgetDefault, etc.)

# Configurations for tests 13.*
option clear
option add $appName.op1.a 100 100
option add $appName.op1.A interactive interactive
option add $appName.op1.b userDefault userDefault
option add $appName.op1.B startupFile startupFile
option add $appName.op1.c widgetDefault widgetDefault
option add $appName.op1.C 0 0

test option-13.1 {priority levels} -body {
    option get .op1 a A
} -result 100
test option-13.2 {priority levels} -body {
    option get .op1 b A
} -result interactive
test option-13.3 {priority levels} -body {
    option get .op1 b B
} -result userDefault
test option-13.4 {priority levels} -body {
    option get .op1 c B
} -result startupFile
test option-13.5 {priority levels} -body {
    option get .op1 c C
} -result widgetDefault
option add $appName.op1.B file2 widget
test option-13.6 {priority levels} -body {
    option get .op1 c B
} -result startupFile
option add $appName.op1.B file2 startupFile
test option-13.7 {priority levels} -body {
    option get .op1 c B
} -result file2


# Test various error conditions

test option-14.1 {error conditions} -body {
    option
} -returnCodes error -result {wrong # args: should be "option cmd arg ?arg ...?"}
test option-14.2 {error conditions} -body {
    option x
} -returnCodes error -result {bad option "x": must be add, clear, get, or readfile}
test option-14.3 {error conditions} -body {
    option foo 3
} -returnCodes error -result {bad option "foo": must be add, clear, get, or readfile}
test option-14.4 {error conditions} -body {
    option add 3
} -returnCodes error -result {wrong # args: should be "option add pattern value ?priority?"}
test option-14.5 {error conditions} -body {
    option add . a b c
} -returnCodes error -result {wrong # args: should be "option add pattern value ?priority?"}
test option-14.6 {error conditions} -body {
    option add . a -1
} -returnCodes error -result {bad priority level "-1": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}
test option-14.7 {error conditions} -body {
    option add . a 101
} -returnCodes error -result {bad priority level "101": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}
test option-14.8 {error conditions} -body {
    option add . a gorp
} -returnCodes error -result {bad priority level "gorp": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}
test option-14.9 {error conditions} -body {
    option get 3
} -returnCodes error -result {wrong # args: should be "option get window name class"}
test option-14.10 {error conditions} -body {
    option get 3 4
} -returnCodes error -result {wrong # args: should be "option get window name class"}
test option-14.11 {error conditions} -body {
    option get 3 4 5 6
} -returnCodes error -result {wrong # args: should be "option get window name class"}
test option-14.12 {error conditions} -body {
    option get .gorp.gorp a A
} -returnCodes error -result {bad window path name ".gorp.gorp"}


set option1 [file join [testsDirectory] option.file1]
test option-15.1 {database files} -body {
    option read non-existent
} -returnCodes error -result {couldn't open "non-existent": no such file or directory}
test option-15.2 {database files} -body {
    option read $option1
    option get . x1 color
} -result blue
test option-15.3 {database files} -constraints appNameIsTktest -body {
    option read $option1
    option get . x2 color
} -result green
test option-15.4 {database files} -body {
    option read $option1
    option get . x3 color
} -result purple
test option-15.5 {database files} -body {
    option read $option1
    option get . {x 4} color
} -result brown
test option-15.6 {database files} -body {
    option read $option1
	option get . x6 color
} -result {}
test option-15.7 {database files} -body {
    option read $option1
	option get . x9 color
} -result " \t\\A\n"
test option-15.8 {database files} -body {
    option read $option1 widget foo
} -returnCodes error -result {wrong # args: should be "option readfile fileName ?priority?"}
test option-15.9 {database files} -body {
    option add *x3 burgundy
    catch {option read $option1 userDefault}
    option get . x3 color
} -result burgundy
test option-15.10 {database files} -body {
    set option2 [file join [testsDirectory] option.file2]
    option read $option2
} -returnCodes error -result {missing colon on line 2}
set option3 [file join [testsDirectory] option.file3]
option read $option3
test option-15.11 {database files} {option get . {x 4} color} br\xf3wn

test option-16.1 {ReadOptionFile} -body {
    set option4 [makeFile {} option.file3]
    set file [open $option4 w]
    fconfigure $file -translation crlf
    puts $file "*x7: true\n*x8: false"
    close $file
    option read $option4 userDefault
    list [option get . x7 color] [option get . x8 color]
} -cleanup {
    removeFile $option4
} -result {true false}

deleteWindows

# cleanup
cleanupTests
return