1
# This file is a Tcl script to test out the "scale" command
2
# of Tk. It is organized in the standard fashion for Tcl tests.
4
# Copyright (c) 1994 The Regents of the University of California.
5
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
# RCS: @(#) $Id: scale.test,v 1.3 1998/11/03 02:06:43 stanton Exp $
12
if {[info procs test] != "test"} {
16
foreach i [winfo children .] {
22
# Create entries in the option database to be sure that geometry options
23
# like border width have predictable values.
25
option add *Scale.borderWidth 2
26
option add *Scale.highlightThickness 2
27
option add *Scale.font {Helvetica -12 bold}
29
scale .s -from 100 -to 300
34
{-activebackground #ff0000 #ff0000 non-existent
35
{unknown color name "non-existent"}}
36
{-background #ff0000 #ff0000 non-existent
37
{unknown color name "non-existent"}}
38
{-bd 4 4 badValue {bad screen distance "badValue"}}
39
{-bigincrement 12.5 12.5 badValue
40
{expected floating-point number but got "badValue"}}
41
{-bg #ff0000 #ff0000 non-existent
42
{unknown color name "non-existent"}}
43
{-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
44
{-command "set x" {set x} {} {}}
45
{-cursor arrow arrow badValue {bad cursor spec "badValue"}}
46
{-digits 5 5 badValue {expected integer but got "badValue"}}
47
{-fg #00ff00 #00ff00 badValue {unknown color name "badValue"}}
48
{-font fixed fixed {} {font "" doesn't exist}}
49
{-foreground green green badValue {unknown color name "badValue"}}
50
{-from -15.0 -15.0 badValue
51
{expected floating-point number but got "badValue"}}
52
{-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
53
{-highlightcolor #123456 #123456 non-existent
54
{unknown color name "non-existent"}}
55
{-highlightthickness 2 2 badValue {bad screen distance "badValue"}}
56
{-label "Some text" {Some text} {} {}}
57
{-length 130 130 badValue {bad screen distance "badValue"}}
58
{-orient horizontal horizontal badValue
59
{bad orientation "badValue": must be vertical or horizontal}}
60
{-orient horizontal horizontal {} {}}
61
{-relief ridge ridge badValue {bad relief type "badValue": must be flat, groove, raised, ridge, solid, or sunken}}
62
{-repeatdelay 14 14 bogus {expected integer but got "bogus"}}
63
{-repeatinterval 14 14 bogus {expected integer but got "bogus"}}
64
{-resolution 2.0 2.0 badValue
65
{expected floating-point number but got "badValue"}}
66
{-showvalue 0 0 badValue {expected boolean value but got "badValue"}}
67
{-sliderlength 86 86 badValue {bad screen distance "badValue"}}
68
{-sliderrelief raised raised badValue {bad relief type "badValue": must be flat, groove, raised, ridge, solid, or sunken}}
69
{-state disabled disabled badValue
70
{bad state value "badValue": must be normal, active, or disabled}}
71
{-state normal normal {} {}}
72
{-takefocus "any string" "any string" {} {}}
73
{-tickinterval 4.3 4.0 badValue
74
{expected floating-point number but got "badValue"}}
75
{-to 14.9 15.0 badValue
76
{expected floating-point number but got "badValue"}}
77
{-troughcolor #ff0000 #ff0000 non-existent
78
{unknown color name "non-existent"}}
80
{-width 32 32 badValue {bad screen distance "badValue"}}
82
set name [lindex $test 0]
83
test scale-1.$i {configuration options} {
84
.s configure $name [lindex $test 1]
85
lindex [.s configure $name] 4
88
if {[lindex $test 3] != ""} {
89
test scale-1.$i {configuration options} {
90
list [catch {.s configure $name [lindex $test 3]} msg] $msg
91
} [list 1 [lindex $test 4]]
93
.s configure $name [lindex [.s configure $name] 3]
98
test scale-2.1 {Tk_ScaleCmd procedure} {
99
list [catch {scale} msg] $msg
100
} {1 {wrong # args: should be "scale pathName ?options?"}}
101
test scale-2.2 {Tk_ScaleCmd procedure} {
102
list [catch {scale foo} msg] $msg [winfo child .]
103
} {1 {bad window path name "foo"} {}}
104
test scale-2.3 {Tk_ScaleCmd procedure} {
105
list [catch {scale .s -gorp dumb} msg] $msg [winfo child .]
106
} {1 {unknown option "-gorp"} {}}
108
scale .s -from 100 -to 200
111
test scale-3.1 {ScaleWidgetCmd procedure} {
112
list [catch {.s} msg] $msg
113
} {1 {wrong # args: should be ".s option ?arg arg ...?"}}
114
test scale-3.2 {ScaleWidgetCmd procedure, cget option} {
115
list [catch {.s cget} msg] $msg
116
} {1 {wrong # args: should be ".s cget option"}}
117
test scale-3.3 {ScaleWidgetCmd procedure, cget option} {
118
list [catch {.s cget a b} msg] $msg
119
} {1 {wrong # args: should be ".s cget option"}}
120
test scale-3.4 {ScaleWidgetCmd procedure, cget option} {
121
list [catch {.s cget -gorp} msg] $msg
122
} {1 {unknown option "-gorp"}}
123
test scale-3.5 {ScaleWidgetCmd procedure, cget option} {
124
.s cget -highlightthickness
126
test scale-3.6 {ScaleWidgetCmd procedure, configure option} {
127
list [llength [.s configure]] [lindex [.s configure] 5]
128
} {33 {-borderwidth borderWidth BorderWidth 2 2}}
129
test scale-3.7 {ScaleWidgetCmd procedure, configure option} {
130
list [catch {.s configure -foo} msg] $msg
131
} {1 {unknown option "-foo"}}
132
test scale-3.8 {ScaleWidgetCmd procedure, configure option} {
133
list [catch {.s configure -borderwidth 2 -bg} msg] $msg
134
} {1 {value for "-bg" missing}}
135
test scale-3.9 {ScaleWidgetCmd procedure, coords option} {
136
list [catch {.s coords a b} msg] $msg
137
} {1 {wrong # args: should be ".s coords ?value?"}}
138
test scale-3.10 {ScaleWidgetCmd procedure, coords option} {
139
list [catch {.s coords bad} msg] $msg
140
} {1 {expected floating-point number but got "bad"}}
141
test scale-3.11 {ScaleWidgetCmd procedure} {fonts} {
145
test scale-3.12 {ScaleWidgetCmd procedure, coords option} {fonts} {
146
.s configure -orient horizontal
151
.s configure -orient vertical
153
test scale-3.13 {ScaleWidgetCmd procedure, get option} {
154
list [catch {.s get a} msg] $msg
155
} {1 {wrong # args: should be ".s get ?x y?"}}
156
test scale-3.14 {ScaleWidgetCmd procedure, get option} {
157
list [catch {.s get a b c} msg] $msg
158
} {1 {wrong # args: should be ".s get ?x y?"}}
159
test scale-3.15 {ScaleWidgetCmd procedure, get option} {
160
list [catch {.s get a 11} msg] $msg
161
} {1 {expected integer but got "a"}}
162
test scale-3.16 {ScaleWidgetCmd procedure, get option} {
163
list [catch {.s get 12 b} msg] $msg
164
} {1 {expected integer but got "b"}}
165
test scale-3.17 {ScaleWidgetCmd procedure, get option} {
169
test scale-3.18 {ScaleWidgetCmd procedure, get option} {
170
.s configure -resolution 0.5
174
.s configure -resolution 1
175
test scale-3.19 {ScaleWidgetCmd procedure, identify option} {
176
list [catch {.s identify} msg] $msg
177
} {1 {wrong # args: should be ".s identify x y"}}
178
test scale-3.20 {ScaleWidgetCmd procedure, identify option} {
179
list [catch {.s identify 1 2 3} msg] $msg
180
} {1 {wrong # args: should be ".s identify x y"}}
181
test scale-3.21 {ScaleWidgetCmd procedure, identify option} {
182
list [catch {.s identify boo 16} msg] $msg
183
} {1 {expected integer but got "boo"}}
184
test scale-3.22 {ScaleWidgetCmd procedure, identify option} {
185
list [catch {.s identify 17 bad} msg] $msg
186
} {1 {expected integer but got "bad"}}
187
test scale-3.23 {ScaleWidgetCmd procedure, identify option} {fonts} {
189
list [.s identify 35 10] [.s identify 35 30] [.s identify 35 80] [.s identify 5 80]
190
} {trough1 slider trough2 {}}
191
test scale-3.24 {ScaleWidgetCmd procedure, set option} {
192
list [catch {.s set} msg] $msg
193
} {1 {wrong # args: should be ".s set value"}}
194
test scale-3.25 {ScaleWidgetCmd procedure, set option} {
195
list [catch {.s set a b} msg] $msg
196
} {1 {wrong # args: should be ".s set value"}}
197
test scale-3.26 {ScaleWidgetCmd procedure, set option} {
198
list [catch {.s set bad} msg] $msg
199
} {1 {expected floating-point number but got "bad"}}
200
test scale-3.27 {ScaleWidgetCmd procedure, set option} {
203
test scale-3.28 {ScaleWidgetCmd procedure, set option} {
205
.s configure -state disabled
207
.s configure -state normal
210
test scale-3.29 {ScaleWidgetCmd procedure} {
211
list [catch {.s dumb} msg] $msg
212
} {1 {bad option "dumb": must be cget, configure, coords, get, identify, or set}}
213
test scale-3.30 {ScaleWidgetCmd procedure} {
214
list [catch {.s c} msg] $msg
215
} {1 {bad option "c": must be cget, configure, coords, get, identify, or set}}
216
test scale-3.31 {ScaleWidgetCmd procedure} {
217
list [catch {.s co} msg] $msg
218
} {1 {bad option "co": must be cget, configure, coords, get, identify, or set}}
219
test scale-3.32 {ScaleWidgetCmd procedure, Tk_Preserve} {
224
scale .s -variable x -from 0 -to 100 -orient horizontal
227
.s configure -command kill
231
test scale-4.1 {DestroyScale procedure} {
234
scale .s -variable x -from 0 -to 100 -orient horizontal
238
list [catch {set x foo} msg] $msg $x
241
test scale-5.1 {ConfigureScale procedure} {
245
scale .s -variable x -from 0 -to 100
248
.s configure -variable y
249
list [catch {set x foo} msg] $msg $x [.s get]
251
test scale-5.2 {ConfigureScale procedure} {
253
scale .s -from 0 -to 100
254
list [catch {.s configure -foo bar} msg] $msg
255
} {1 {unknown option "-foo"}}
256
test scale-5.3 {ConfigureScale procedure} {
259
scale .s -from 0 -to 100 -variable x
261
lappend result [.s get]
263
lappend result [.s get]
267
lappend result [catch {set x} msg] $msg
269
test scale-5.4 {ConfigureScale procedure} {
271
scale .s -from 0 -to 100
272
list [catch {.s configure -orient dumb} msg] $msg
273
} {1 {bad orientation "dumb": must be vertical or horizontal}}
274
test scale-5.5 {ConfigureScale procedure} {
276
scale .s -from 1.11 -to 1.89 -resolution .1 -tickinterval .76
277
list [format %.1f [.s cget -from]] [format %.1f [.s cget -to]] \
278
[format %.1f [.s cget -tickinterval]]
280
test scale-5.6 {ConfigureScale procedure} {
282
scale .s -from 1 -to 10 -tickinterval -2
284
set result [lindex [.s configure -tickinterval] 4]
285
.s configure -from 10 -to 1 -tickinterval 2
286
lappend result [lindex [.s configure -tickinterval] 4]
288
test scale-5.7 {ConfigureScale procedure} {
290
list [catch {scale .s -from 0 -to 100 -state bogus} msg] $msg
291
} {1 {bad state value "bogus": must be normal, active, or disabled}}
294
scale .s -orient horizontal -length 200
296
test scale-6.1 {ComputeFormat procedure} {
297
.s configure -from 10 -to 100 -resolution 10
301
test scale-6.2 {ComputeFormat procedure} {
302
.s configure -from 100 -to 1000 -resolution 100
306
test scale-6.3 {ComputeFormat procedure} {
307
.s configure -from 1000 -to 10000 -resolution 1000
311
test scale-6.4 {ComputeFormat procedure} {
312
.s configure -from 10000 -to 100000 -resolution 10000
316
test scale-6.5 {ComputeFormat procedure} {
317
.s configure -from 100000 -to 1000000 -resolution 100000
321
test scale-6.6 {ComputeFormat procedure} {nonPortable} {
322
# This test is non-portable because some platforms format the
325
.s configure -from 1000000 -to 10000000 -resolution 1000000
329
test scale-6.7 {ComputeFormat procedure} {
330
.s configure -from 1000000000 -to 10000000000 -resolution 1000000000
332
expr {[.s get] == 5.0e+09}
334
test scale-6.8 {ComputeFormat procedure} {
335
.s configure -from .1 -to 1 -resolution .1
339
test scale-6.9 {ComputeFormat procedure} {
340
.s configure -from .01 -to .1 -resolution .01
344
test scale-6.10 {ComputeFormat procedure} {
345
.s configure -from .001 -to .01 -resolution .001
349
test scale-6.11 {ComputeFormat procedure} {
350
.s configure -from .0001 -to .001 -resolution .0001
354
test scale-6.12 {ComputeFormat procedure} {
355
.s configure -from .00001 -to .0001 -resolution .00001
359
test scale-6.13 {ComputeFormat procedure} {
360
.s configure -from .000001 -to .00001 -resolution .000001
362
expr {[.s get] == 6.0e-06}
364
test scale-6.14 {ComputeFormat procedure} {
365
.s configure -to .00001 -from .0001 -resolution .00001
369
test scale-6.15 {ComputeFormat procedure} {
370
.s configure -to .000001 -from .00001 -resolution .000001
372
expr {[.s get] == 6.0e-06}
374
test scale-6.16 {ComputeFormat procedure} {
375
.s configure -from .00001 -to .0001 -resolution .00001 -digits 1
377
expr {[.s get] == 6e-05}
379
test scale-6.17 {ComputeFormat procedure} {
380
.s configure -from 10000000 -to 100000000 -resolution 10000000 -digits 3
384
test scale-6.18 {ComputeFormat procedure} {
385
.s configure -length 200 -from 0 -to 10 -resolution 0 -digits 0
389
test scale-6.19 {ComputeFormat procedure} {
390
.s configure -length 200 -from 1000 -to 1002 -resolution 0 -digits 0
394
test scale-6.20 {ComputeFormat procedure} {
395
.s configure -length 200 -from 1000 -to 1001.8 -resolution 0 -digits 0
400
test scale-7.1 {ComputeScaleGeometry procedure} {fonts} {
402
scale .s -from 0 -to 10 -label "Short" -orient vertical -length 5i
405
list [winfo reqwidth .s] [winfo reqheight .s]
407
test scale-7.2 {ComputeScaleGeometry procedure} {fonts} {
409
scale .s -from 0 -to 1000 -label "Long string" -orient vertical -tick 200
412
list [winfo reqwidth .s] [winfo reqheight .s]
414
test scale-7.3 {ComputeScaleGeometry procedure} {fonts} {
416
scale .s -from 0 -to 1000 -orient vertical -showvalue 0 -width 10 \
420
list [winfo reqwidth .s] [winfo reqheight .s]
422
test scale-7.4 {ComputeScaleGeometry procedure} {fonts} {
424
scale .s -from 0 -to 1000 -orient vertical -showvalue 0 -bd 5 \
428
list [winfo reqwidth .s] [winfo reqheight .s]
430
test scale-7.5 {ComputeScaleGeometry procedure} {fonts} {
432
scale .s -from 0 -to 10 -label "Short" -orient horizontal -length 5i
435
list [winfo reqwidth .s] [winfo reqheight .s]
437
test scale-7.6 {ComputeScaleGeometry procedure} {fonts} {
439
scale .s -from 0 -to 1000 -label "Long string" -orient horizontal \
443
list [winfo reqwidth .s] [winfo reqheight .s]
445
test scale-7.7 {ComputeScaleGeometry procedure} {fonts} {
447
scale .s -from 0 -to 1000 -orient horizontal -showvalue 0
450
list [winfo reqwidth .s] [winfo reqheight .s]
452
test scale-7.8 {ComputeScaleGeometry procedure} {
454
scale .s -from 0 -to 1000 -orient horizontal -showvalue 0 -bd 5 \
455
-relief raised -highlightthickness 2
458
list [winfo reqwidth .s] [winfo reqheight .s]
461
test scale-8.1 {ScaleElement procedure} {fonts} {
463
scale .s -from 0 -to 100 -orient vertical -bd 1 -tick 20 -length 300
467
list [.s identify 53 52] [.s identify 54 52] [.s identify 70 52] \
469
} {{} trough1 trough1 {}}
470
test scale-8.2 {ScaleElement procedure} {fonts} {
472
scale .s -from 0 -to 100 -orient vertical -bd 1 -tick 20 -length 300
476
list [.s identify 60 2] [.s identify 60 3] [.s identify 60 302] \
478
} {{} trough1 trough2 {}}
479
test scale-8.3 {ScaleElement procedure} {fonts} {
481
scale .s -from 0 -to 100 -orient vertical -bd 1 -tick 20 -length 300
485
list [.s identify 60 83] [.s identify 60 84] [.s identify 60 113] \
486
[.s identify 60 114] \
487
} {trough1 slider slider trough2}
488
test scale-8.4 {ScaleElement procedure} {
490
scale .s -from 0 -to 100 -orient vertical -bd 4 -width 10 \
491
-highlightthickness 1 -length 300 -showvalue 0
495
list [.s identify 4 40] [.s identify 5 40] [.s identify 22 40] \
496
[.s identify 23 40] \
497
} {{} trough1 trough1 {}}
498
test scale-8.5 {ScaleElement procedure} {fonts} {
500
scale .s -from 0 -to 100 -orient horizontal -bd 1 \
501
-highlightthickness 2 -tick 20 -sliderlength 20 \
502
-length 200 -label Test
506
list [.s identify 150 36] [.s identify 150 37] [.s identify 150 53] \
508
} {{} trough2 trough2 {}}
509
test scale-8.6 {ScaleElement procedure} {fonts} {
511
scale .s -from 0 -to 100 -orient horizontal -bd 2 \
512
-highlightthickness 1 -tick 20 -length 200
516
list [.s identify 150 20] [.s identify 150 21] [.s identify 150 39] \
518
} {{} trough2 trough2 {}}
519
test scale-8.7 {ScaleElement procedure} {
521
scale .s -from 0 -to 100 -orient horizontal -bd 4 -highlightthickness 2 \
522
-length 200 -width 10 -showvalue 0
526
list [.s identify 30 5] [.s identify 30 6] [.s identify 30 23] \
528
} {{} trough1 trough1 {}}
529
test scale-8.8 {ScaleElement procedure} {
531
scale .s -from 0 -to 100 -orient horizontal -bd 1 -highlightthickness 2 \
532
-tick 20 -sliderlength 20 -length 200 -label Test -showvalue 0
536
list [.s identify 2 28] [.s identify 3 28] [.s identify 202 28] \
538
} {{} trough1 trough2 {}}
539
test scale-8.9 {ScaleElement procedure} {
541
scale .s -from 0 -to 100 -orient horizontal -bd 1 -highlightthickness 2 \
542
-tick 20 -sliderlength 20 -length 200 -label Test -showvalue 0
546
list [.s identify 145 28] [.s identify 146 28] [.s identify 165 28] \
548
} {trough1 slider slider trough2}
551
scale .s -from 0 -to 100 -sliderlength 10 -length 114 -bd 2
554
test scale-9.1 {PixelToValue procedure} {
557
test scale-9.2 {PixelToValue procedure} {
560
test scale-9.3 {PixelToValue procedure} {
563
test scale-9.4 {PixelToValue procedure} {
566
test scale-9.5 {PixelToValue procedure} {
569
test scale-9.6 {PixelToValue procedure} {
572
test scale-9.7 {PixelToValue procedure} {
575
test scale-9.8 {PixelToValue procedure} {
578
.s configure -orient horizontal
580
test scale-9.9 {PixelToValue procedure} {
584
test scale-10.1 {ValueToPixel procedure} {fonts} {
586
scale .s -from 0 -to 100 -sliderlength 20 -length 124 -bd 2 \
587
-orient horizontal -label Test -tick 20
590
list [.s coords -10] [.s coords 40] [.s coords 1000]
591
} {{16 47} {56 47} {116 47}}
592
test scale-10.2 {ValueToPixel procedure} {fonts} {
594
scale .s -from 100 -to 0 -sliderlength 20 -length 122 -bd 1 \
595
-orient vertical -label Test -tick 20
598
list [.s coords -10] [.s coords 40] [.s coords 1000]
599
} {{62 114} {62 74} {62 14}}
601
test scale-11.1 {ScaleEventProc procedure} {
602
proc killScale value {
606
lappend x [winfo exists .s1] [info commands .s1]
611
scale .s1 -from 0 -to 100 -command killScale
615
lappend x [winfo exists .s1]
621
test scale-11.2 {ScaleEventProc procedure} {
622
eval destroy [winfo children .]
623
scale .s1 -bg #543210
626
lappend x [winfo children .]
627
lappend x [.s2 cget -bg]
629
lappend x [info command .s*] [winfo children .]
630
} {.s1 #543210 {} {}}
632
test scale-12.1 {ScaleCmdDeletedProc procedure} {
633
eval destroy [winfo children .]
636
list [info command .s*] [winfo children .]
640
scale .s -from 0 -to 100 -command {set x} -variable y
647
test scale-13.1 {SetScaleValue procedure} {
650
set result [list $x $y]
654
test scale-13.2 {SetScaleValue procedure} {
658
test scale-13.3 {SetScaleValue procedure} {
662
.s configure -from 100 -to 0
663
test scale-13.4 {SetScaleValue procedure} {
667
test scale-13.5 {SetScaleValue procedure} {
671
test scale-13.6 {SetScaleValue procedure} {
674
trace variable y w varTrace
683
scale .s -from 0 -to 100 -sliderlength 10 -length 114 -bd 2 -orient horizontal
686
.s configure -resolution 4.0
688
test scale-14.1 {RoundToResolution procedure} {
691
test scale-14.2 {RoundToResolution procedure} {
694
.s configure -from 100 -to 0
696
test scale-14.3 {RoundToResolution procedure} {
699
test scale-14.4 {RoundToResolution procedure} {
702
.s configure -from -100 -to 0
704
test scale-14.5 {RoundToResolution procedure} {
707
test scale-14.6 {RoundToResolution procedure} {
710
.s configure -from 0 -to -100
712
test scale-14.7 {RoundToResolution procedure} {
715
test scale-14.8 {RoundToResolution procedure} {
718
.s configure -from 0 -to 2.25 -resolution 0
720
test scale-14.9 {RoundToResolution procedure} {
723
test scale-14.10 {RoundToResolution procedure} {
726
.s configure -from 0 -to 225 -resolution 0 -digits 5
728
test scale-14.11 {RoundToResolution procedure} {
731
test scale-14.12 {RoundToResolution procedure} {
735
test scale-15.1 {ScaleVarProc procedure} {
738
scale .s -from 0 -to -200 -variable y -orient horizontal -length 150
742
test scale-15.2 {ScaleVarProc procedure} {
745
scale .s -from -200 -to 0 -variable y -orient horizontal -length 150
750
test scale-15.3 {ScaleVarProc procedure} {
753
scale .s -from -200 -to 0 -variable y -orient horizontal -length 150
755
list [catch {set y 40q} msg] $msg [.s get]
756
} {1 {can't set "y": can't assign non-numeric value to scale variable} -130}
757
test scale-15.4 {ScaleVarProc procedure} {
760
scale .s -from 1 -to 0 -variable y -orient horizontal -length 150
762
list [catch {set y x} msg] $msg [.s get]
763
} {1 {can't set "y": can't assign non-numeric value to scale variable} 1}
764
test scale-15.5 {ScaleVarProc procedure, variable deleted} {
767
scale .s -from 10 -to 0 -variable y -orient horizontal -length 150 \
774
list [catch {set y} msg] $msg [.s get] $x
776
test scale-15.6 {ScaleVarProc procedure, don't call -command} {
779
scale .s -from 0 -to 100 -variable y -orient horizontal -length 150 \
789
set l [interp hidden]
790
eval destroy [winfo children .]
792
test scale-16.1 {scale widget vs hidden commands} {
797
list [winfo children .] [interp hidden]