1 # This file is a Tcl script to test entry widgets in Tk. It is
2 # organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1994 The Regents of the University of California.
5 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 if {[lsearch [namespace children] ::tcltest] == -1} {
12 source [file join [pwd] [file dirname [info script]] defs.tcl]
15 if {[lsearch [image types] test] < 0} {
16 puts "This application hasn't been compiled with the \"test\""
17 puts "image, so I can't run this test. Are you sure you're using"
18 puts "tktest instead of wish?"
19 ::tcltest::cleanupTests
23 foreach i [winfo children .] {
34 # Create additional widget that's used to hold the selection at times.
37 .sel insert end "This is some sample text"
41 set big -adobe-helvetica-medium-r-normal--24-240-75-75-p-*-iso8859-1
42 set fixed -adobe-courier-medium-r-normal--12-120-75-75-m-*-iso8859-1
44 # Create entries in the option database to be sure that geometry options
45 # like border width have predictable values.
47 option add *Entry.borderWidth 2
48 option add *Entry.highlightThickness 2
49 option add *Entry.font {Helvetica -12}
51 entry .e -bd 2 -relief sunken
57 {-background #ff0000 #ff0000 non-existent
58 {unknown color name "non-existent"}}
59 {-bd 4 4 badValue {bad screen distance "badValue"}}
60 {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
61 {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
62 {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
63 {-exportselection yes 1 xyzzy {expected boolean value but got "xyzzy"}}
64 {-fg #110022 #110022 bogus {unknown color name "bogus"}}
65 {-font -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
66 -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* {}
67 {font "" doesn't exist}}
68 {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
69 {-highlightbackground #123456 #123456 ugly {unknown color name "ugly"}}
70 {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}}
71 {-highlightthickness 6 6 bogus {bad screen distance "bogus"}}
72 {-highlightthickness -2 0 {} {}}
73 {-insertbackground #110022 #110022 bogus {unknown color name "bogus"}}
74 {-insertborderwidth 1.3 1 2.6x {bad screen distance "2.6x"}}
75 {-insertofftime 100 100 3.2 {expected integer but got "3.2"}}
76 {-insertontime 100 100 3.2 {expected integer but got "3.2"}}
77 {-justify right right bogus {bad justification "bogus": must be left, right, or center}}
78 {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
79 {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
80 {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
81 {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
83 {-state n normal bogus {bad state "bogus": must be disabled or normal}}
84 {-takefocus "any string" "any string" {} {}}
85 {-textvariable i i {} {}}
86 {-width 402 402 3p {expected integer but got "3p"}}
87 {-xscrollcommand {Some command} {Some command} {} {}}
89 set name [lindex $test 0]
90 test entry-1.$i {configuration options} {
91 .e configure $name [lindex $test 1]
92 list [lindex [.e configure $name] 4] [.e cget $name]
93 } [list [lindex $test 2] [lindex $test 2]]
95 if {[lindex $test 3] != ""} {
96 test entry-1.$i {configuration options} {
97 list [catch {.e configure $name [lindex $test 3]} msg] $msg
98 } [list 1 [lindex $test 4]]
100 .e configure $name [lindex [.e configure $name] 3]
104 test entry-2.1 {Tk_EntryCmd procedure} {
105 list [catch {entry} msg] $msg
106 } {1 {wrong # args: should be "entry pathName ?options?"}}
107 test entry-2.2 {Tk_EntryCmd procedure} {
108 list [catch {entry gorp} msg] $msg
109 } {1 {bad window path name "gorp"}}
110 test entry-2.3 {Tk_EntryCmd procedure} {
113 list [winfo exists .e] [winfo class .e] [info commands .e]
115 test entry-2.4 {Tk_EntryCmd procedure} {
117 list [catch {entry .e -gorp foo} msg] $msg [winfo exists .e] \
119 } {1 {unknown option "-gorp"} 0 {}}
120 test entry-2.5 {Tk_EntryCmd procedure} {
126 entry .e -font $fixed
130 set cx [font measure $fixed a]
131 set cy [font metrics $fixed -linespace]
132 set ux [font measure $fixed \u4e4e]
134 test entry-3.1 {EntryWidgetCmd procedure} {
135 list [catch {.e} msg] $msg
136 } {1 {wrong # args: should be ".e option ?arg arg ...?"}}
137 test entry-3.2 {EntryWidgetCmd procedure, "bbox" widget command} {
138 list [catch {.e bbox} msg] $msg
139 } {1 {wrong # args: should be ".e bbox index"}}
140 test entry-3.3 {EntryWidgetCmd procedure, "bbox" widget command} {
141 list [catch {.e bbox a b} msg] $msg
142 } {1 {wrong # args: should be ".e bbox index"}}
143 test entry-3.4 {EntryWidgetCmd procedure, "bbox" widget command} {
144 list [catch {.e bbox bogus} msg] $msg
145 } {1 {bad entry index "bogus"}}
146 test entry-3.5 {EntryWidgetCmd procedure, "bbox" widget command} {
150 test entry-3.6 {EntryWidgetCmd procedure, "bbox" widget command} {
151 # Tcl_UtfAtIndex(): no utf chars
155 list [.e bbox 3] [.e bbox end]
156 } [list "[expr 5+2*$cx] 5 $cx $cy" "[expr 5+2*$cx] 5 $cx $cy"]
157 test entry-3.7 {EntryWidgetCmd procedure, "bbox" widget command} {
158 # Tcl_UtfAtIndex(): utf at end
160 .e insert 0 "ab\u4e4e"
162 } "[expr 5+2*$cx] 5 $ux $cy"
163 test entry-3.8 {EntryWidgetCmd procedure, "bbox" widget command} {
164 # Tcl_UtfAtIndex(): utf before index
166 .e insert 0 "ab\u4e4ec"
168 } "[expr 5+2*$cx+$ux] 5 $cx $cy"
169 test entry-3.9 {EntryWidgetCmd procedure, "bbox" widget command} {
170 # Tcl_UtfAtIndex(): no chars
174 test entry-3.10 {EntryWidgetCmd procedure, "bbox" widget command} {
176 .e insert 0 "abcdefghij\u4e4eklmnop"
177 list [.e bbox 0] [.e bbox 1] [.e bbox 10] [.e bbox end]
178 } [list "5 5 $cx $cy" "[expr 5+$cx] 5 $cx $cy" "[expr 5+10*$cx] 5 $ux $cy" "[expr 5+$ux+15*$cx] 5 $cx $cy"]
179 test entry-3.11 {EntryWidgetCmd procedure, "cget" widget command} {
180 list [catch {.e cget} msg] $msg
181 } {1 {wrong # args: should be ".e cget option"}}
182 test entry-3.12 {EntryWidgetCmd procedure, "cget" widget command} {
183 list [catch {.e cget a b} msg] $msg
184 } {1 {wrong # args: should be ".e cget option"}}
185 test entry-3.13 {EntryWidgetCmd procedure, "cget" widget command} {
186 list [catch {.e cget -gorp} msg] $msg
187 } {1 {unknown option "-gorp"}}
188 test entry-3.14 {EntryWidgetCmd procedure, "cget" widget command} {
192 test entry-3.15 {EntryWidgetCmd procedure, "configure" widget command} {
193 llength [.e configure]
195 test entry-3.16 {EntryWidgetCmd procedure, "configure" widget command} {
196 list [catch {.e configure -foo} msg] $msg
197 } {1 {unknown option "-foo"}}
198 test entry-3.17 {EntryWidgetCmd procedure, "configure" widget command} {
200 .e configure -bg #ffffff
201 lindex [.e configure -bd] 4
203 test entry-3.18 {EntryWidgetCmd procedure, "delete" widget command} {
204 list [catch {.e delete} msg] $msg
205 } {1 {wrong # args: should be ".e delete firstIndex ?lastIndex?"}}
206 test entry-3.19 {EntryWidgetCmd procedure, "delete" widget command} {
207 list [catch {.e delete a b c} msg] $msg
208 } {1 {wrong # args: should be ".e delete firstIndex ?lastIndex?"}}
209 test entry-3.20 {EntryWidgetCmd procedure, "delete" widget command} {
210 list [catch {.e delete foo} msg] $msg
211 } {1 {bad entry index "foo"}}
212 test entry-3.21 {EntryWidgetCmd procedure, "delete" widget command} {
213 list [catch {.e delete 0 bar} msg] $msg
214 } {1 {bad entry index "bar"}}
215 test entry-3.22 {EntryWidgetCmd procedure, "delete" widget command} {
217 .e insert end "01234567890"
221 test entry-3.23 {EntryWidgetCmd procedure, "delete" widget command} {
223 .e insert end "01234567890"
227 test entry-3.24 {EntryWidgetCmd procedure, "delete" widget command} {
231 .e insert end "01234\u4e4e67890"
235 .e insert end "012345\u4e4e7890"
239 .e insert end "0123456\u4e4e890"
242 } [list "01234\u4e4e7890" "0123457890" "012345\u4e4e890"]
243 test entry-3.25 {EntryWidgetCmd procedure, "delete" widget command} {
245 .e insert end "01234567890"
249 test entry-3.26 {EntryWidgetCmd procedure, "delete" widget command} {
251 .e insert end "01234567890"
252 .e configure -state disabled
254 .e configure -state normal
257 test entry-3.27 {EntryWidgetCmd procedure, "get" widget command} {
258 list [catch {.e get foo} msg] $msg
259 } {1 {wrong # args: should be ".e get"}}
260 test entry-3.28 {EntryWidgetCmd procedure, "icursor" widget command} {
261 list [catch {.e icursor} msg] $msg
262 } {1 {wrong # args: should be ".e icursor pos"}}
263 test entry-3.29 {EntryWidgetCmd procedure, "icursor" widget command} {
264 list [catch {.e icursor foo} msg] $msg
265 } {1 {bad entry index "foo"}}
266 test entry-3.30 {EntryWidgetCmd procedure, "icursor" widget command} {
268 .e insert end "01234567890"
272 test entry-3.31 {EntryWidgetCmd procedure, "index" widget command} {
273 list [catch {.e in} msg] $msg
274 } {1 {ambiguous option "in": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}}
275 test entry-3.32 {EntryWidgetCmd procedure, "index" widget command} {
276 list [catch {.e index} msg] $msg
277 } {1 {wrong # args: should be ".e index string"}}
278 test entry-3.33 {EntryWidgetCmd procedure, "index" widget command} {
279 list [catch {.e index foo} msg] $msg
280 } {1 {bad entry index "foo"}}
281 test entry-3.34 {EntryWidgetCmd procedure, "index" widget command} {
282 list [catch {.e index 0} msg] $msg
284 test entry-3.35 {EntryWidgetCmd procedure, "index" widget command} {
287 .e insert 0 abc\u4e4e\u0153def
288 list [.e index 3] [.e index 4] [.e index end]
290 test entry-3.36 {EntryWidgetCmd procedure, "insert" widget command} {
291 list [catch {.e insert a} msg] $msg
292 } {1 {wrong # args: should be ".e insert index text"}}
293 test entry-3.37 {EntryWidgetCmd procedure, "insert" widget command} {
294 list [catch {.e insert a b c} msg] $msg
295 } {1 {wrong # args: should be ".e insert index text"}}
296 test entry-3.38 {EntryWidgetCmd procedure, "insert" widget command} {
297 list [catch {.e insert foo Text} msg] $msg
298 } {1 {bad entry index "foo"}}
299 test entry-3.39 {EntryWidgetCmd procedure, "insert" widget command} {
301 .e insert end "01234567890"
305 test entry-3.40 {EntryWidgetCmd procedure, "insert" widget command} {
307 .e insert end "01234567890"
308 .e configure -state disabled
310 .e configure -state normal
313 test entry-3.41 {EntryWidgetCmd procedure, "insert" widget command} {
314 list [catch {.e insert a b c} msg] $msg
315 } {1 {wrong # args: should be ".e insert index text"}}
316 test entry-3.42 {EntryWidgetCmd procedure, "scan" widget command} {
317 list [catch {.e scan a} msg] $msg
318 } {1 {wrong # args: should be ".e scan mark|dragto x"}}
319 test entry-3.43 {EntryWidgetCmd procedure, "scan" widget command} {
320 list [catch {.e scan a b c} msg] $msg
321 } {1 {wrong # args: should be ".e scan mark|dragto x"}}
322 test entry-3.44 {EntryWidgetCmd procedure, "scan" widget command} {
323 list [catch {.e scan foobar 20} msg] $msg
324 } {1 {bad scan option "foobar": must be mark or dragto}}
325 test entry-3.45 {EntryWidgetCmd procedure, "scan" widget command} {
326 list [catch {.e scan mark 20.1} msg] $msg
327 } {1 {expected integer but got "20.1"}}
328 # This test is non-portable because character sizes vary.
330 test entry-3.46 {EntryWidgetCmd procedure, "scan" widget command} {fonts} {
333 .e insert end "This is quite a long string, in fact a "
334 .e insert end "very very long string"
339 test entry-3.47 {EntryWidgetCmd procedure, "select" widget command} {
340 list [catch {.e select} msg] $msg
341 } {1 {wrong # args: should be ".e selection option ?index?"}}
342 test entry-3.48 {EntryWidgetCmd procedure, "select" widget command} {
343 list [catch {.e select foo} msg] $msg
344 } {1 {bad selection option "foo": must be adjust, clear, from, present, range, or to}}
345 test entry-3.49 {EntryWidgetCmd procedure, "select clear" widget command} {
346 list [catch {.e select clear gorp} msg] $msg
347 } {1 {wrong # args: should be ".e selection clear"}}
348 test entry-3.50 {EntryWidgetCmd procedure, "select clear" widget command} {
350 .e insert end "0123456789"
355 list [catch {selection get} msg] $msg [selection own]
356 } {1 {PRIMARY selection doesn't exist or form "STRING" not defined} .e}
357 test entry-3.51 {EntryWidgetCmd procedure, "selection present" widget command} {
358 list [catch {.e selection present foo} msg] $msg
359 } {1 {wrong # args: should be ".e selection present"}}
360 test entry-3.52 {EntryWidgetCmd procedure, "selection present" widget command} {
362 .e insert end 0123456789
367 test entry-3.53 {EntryWidgetCmd procedure, "selection present" widget command} {
369 .e insert end 0123456789
372 .e configure -exportselection false
375 .e configure -exportselection true
376 test entry-3.54 {EntryWidgetCmd procedure, "selection present" widget command} {
378 .e insert end 0123456789
384 test entry-3.55 {EntryWidgetCmd procedure, "selection adjust" widget command} {
385 list [catch {.e select adjust x} msg] $msg
386 } {1 {bad entry index "x"}}
387 test entry-3.56 {EntryWidgetCmd procedure, "selection adjust" widget command} {
388 list [catch {.e select adjust 2 3} msg] $msg
389 } {1 {wrong # args: should be ".e selection adjust index"}}
390 test entry-3.57 {EntryWidgetCmd procedure, "selection adjust" widget command} {
392 .e insert end "0123456789"
399 test entry-3.58 {EntryWidgetCmd procedure, "selection adjust" widget command} {
401 .e insert end "0123456789"
408 test entry-3.59 {EntryWidgetCmd procedure, "selection from" widget command} {
409 list [catch {.e select from 2 3} msg] $msg
410 } {1 {wrong # args: should be ".e selection from index"}}
411 test entry-3.60 {EntryWidgetCmd procedure, "selection range" widget command} {
412 list [catch {.e select range 2} msg] $msg
413 } {1 {wrong # args: should be ".e selection range start end"}}
414 test entry-3.61 {EntryWidgetCmd procedure, "selection range" widget command} {
415 list [catch {.e selection range 2 3 4} msg] $msg
416 } {1 {wrong # args: should be ".e selection range start end"}}
417 test entry-3.62 {EntryWidgetCmd procedure, "selection range" widget command} {
419 .e insert end 0123456789
423 list [catch {.e index sel.first} msg] $msg
424 } {1 {selection isn't in entry}}
425 test entry-3.63 {EntryWidgetCmd procedure, "selection range" widget command} {
427 .e insert end 0123456789
431 list [.e index sel.first] [.e index sel.last] [.e index anchor]
434 .e insert end "This is quite a long text string, so long that it "
435 .e insert end "runs off the end of the window quite a bit."
436 test entry-3.64 {EntryWidgetCmd procedure, "selection to" widget command} {
437 list [catch {.e select to 2 3} msg] $msg
438 } {1 {wrong # args: should be ".e selection to index"}}
439 test entry-3.65 {EntryWidgetCmd procedure, "xview" widget command} {
442 } {0.0537634 0.268817}
443 test entry-3.66 {EntryWidgetCmd procedure, "xview" widget command} {
444 list [catch {.e xview gorp} msg] $msg
445 } {1 {bad entry index "gorp"}}
446 test entry-3.67 {EntryWidgetCmd procedure, "xview" widget command} {
451 } {0.107527 0.322581}
452 test entry-3.68 {EntryWidgetCmd procedure, "xview" widget command} {
453 list [catch {.e xview moveto foo bar} msg] $msg
454 } {1 {wrong # args: should be ".e xview moveto fraction"}}
455 test entry-3.69 {EntryWidgetCmd procedure, "xview" widget command} {
456 list [catch {.e xview moveto foo} msg] $msg
457 } {1 {expected floating-point number but got "foo"}}
458 test entry-3.70 {EntryWidgetCmd procedure, "xview" widget command} {
462 test entry-3.71 {EntryWidgetCmd procedure, "xview" widget command} {
463 list [catch {.e xview scroll 24} msg] $msg
464 } {1 {wrong # args: should be ".e xview scroll number units|pages"}}
465 test entry-3.72 {EntryWidgetCmd procedure, "xview" widget command} {
466 list [catch {.e xview scroll gorp units} msg] $msg
467 } {1 {expected integer but got "gorp"}}
468 test entry-3.73 {EntryWidgetCmd procedure, "xview" widget command} {
470 .e xview scroll 1 pages
472 } {0.193548 0.408602}
473 test entry-3.74 {EntryWidgetCmd procedure, "xview" widget command} {
478 } {0.397849 0.612903}
479 test entry-3.75 {EntryWidgetCmd procedure, "xview" widget command} {
482 .e xview scroll 2 units
485 test entry-3.76 {EntryWidgetCmd procedure, "xview" widget command} {
488 .e xview scroll -1 units
491 test entry-3.77 {EntryWidgetCmd procedure, "xview" widget command} {
492 list [catch {.e xview scroll 23 foobars} msg] $msg
493 } {1 {bad argument "foobars": must be units or pages}}
494 test entry-3.78 {EntryWidgetCmd procedure, "xview" widget command} {
495 list [catch {.e xview eat 23 hamburgers} msg] $msg
496 } {1 {unknown option "eat": must be moveto or scroll}}
497 test entry-3.79 {EntryWidgetCmd procedure, "xview" widget command} {
503 test entry-3.80 {EntryWidgetCmd procedure, "xview" widget command} {
508 test entry-3.81 {EntryWidgetCmd procedure, "xview" widget command} {
510 # If Tcl_NumUtfChars wasn't used, wrong answer would be:
511 # 0.106383 0.117021 0.117021
515 lappend x [lindex [.e xview] 0]
517 lappend x [lindex [.e xview] 0]
519 lappend x [lindex [.e xview] 0]
520 } {0.0957447 0.106383 0.117021}
521 test entry-3.82 {EntryWidgetCmd procedure} {
522 list [catch {.e gorp} msg] $msg
523 } {1 {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}}
525 # The test below doesn't actually check anything directly, but if run
526 # with Purify or some other memory-allocation-checking program it will
527 # ensure that resources get properly freed.
529 test entry-4.1 {DestroyEntry procedure} {
531 entry .e -textvariable x -show *
533 .e insert end "Sample text"
538 frame .f -width 200 -height 50 -relief raised -bd 2
540 test entry-5.1 {ConfigureEntry procedure, -textvariable} {
543 entry .e -textvariable x
546 test entry-5.2 {ConfigureEntry procedure, -textvariable} {
549 entry .e -textvariable x
551 .e configure -textvariable y
555 test entry-5.3 {ConfigureEntry procedure, -textvariable} {
559 .e insert 0 "Some text"
560 .e configure -textvariable x
563 test entry-5.4 {ConfigureEntry procedure, -textvariable} {
570 trace variable x w override
572 .e insert 0 "Some text"
573 .e configure -textvariable x
574 set result [list $x [.e get]]
575 unset x; rename override {}
578 test entry-5.5 {ConfigureEntry procedure} {
580 entry .e -exportselection false
582 .e insert end "0123456789"
586 lappend x [selection get]
589 lappend x [selection get]
590 .e configure -exportselection 1
591 lappend x [selection get]
593 } {{This is so} {This is so} 1234}
594 test entry-5.6 {ConfigureEntry procedure} {
598 .e insert end "0123456789"
601 .e configure -exportselection 0
602 list [catch {selection get} msg] $msg [.e index sel.first] \
604 } {1 {PRIMARY selection doesn't exist or form "STRING" not defined} 1 5}
605 test entry-5.7 {ConfigureEntry procedure} {
607 entry .e -font $fixed -width 4 -xscrollcommand scroll
609 .e insert end "01234567890"
611 .e configure -width 5
614 test entry-5.8 {ConfigureEntry procedure} {fonts} {
620 .e configure -font $big
624 test entry-5.9 {ConfigureEntry procedure} {fonts} {
626 entry .e -font $fixed -bd 2 -relief raised
630 list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
632 test entry-5.10 {ConfigureEntry procedure} {fonts} {
634 entry .e -font $fixed -bd 2 -relief flat
638 list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
640 test entry-5.11 {ConfigureEntry procedure} {
641 # If "0" in selected font had 0 width, caused divide-by-zero error.
644 pack [entry .e -font {{open look glyph}}]
649 # No tests for DisplayEntry.
651 test entry-6.1 {EntryComputeGeometry procedure} {fonts} {
653 entry .e -font $fixed -bd 2 -relief raised -width 20 -highlightthickness 3
655 .e insert end 012\t45
657 list [.e index @61] [.e index @62]
659 test entry-6.2 {EntryComputeGeometry procedure} {fonts} {
661 entry .e -font $fixed -bd 2 -relief raised -width 20 -justify center \
662 -highlightthickness 3
664 .e insert end 012\t45
666 list [.e index @96] [.e index @97]
668 test entry-6.3 {EntryComputeGeometry procedure} {fonts} {
670 entry .e -font $fixed -bd 2 -relief raised -width 20 -justify right \
671 -highlightthickness 3
673 .e insert end 012\t45
675 list [.e index @131] [.e index @132]
677 test entry-6.4 {EntryComputeGeometry procedure} {
679 entry .e -font $fixed -bd 2 -relief raised -width 5
681 .e insert end "01234567890"
686 test entry-6.5 {EntryComputeGeometry procedure} {
688 entry .e -font $fixed -bd 2 -relief raised -width 5
690 .e insert end "01234567890"
695 test entry-6.6 {EntryComputeGeometry procedure} {fonts} {
697 entry .e -font $fixed -bd 2 -relief raised -width 10
699 .e insert end "01234\t67890"
702 list [.e index @39] [.e index @40]
704 test entry-6.7 {EntryComputeGeometry procedure} {fonts} {
706 entry .e -font $big -bd 3 -relief raised -width 5
708 .e insert end "01234567"
710 list [winfo reqwidth .e] [winfo reqheight .e]
712 test entry-6.8 {EntryComputeGeometry procedure} {fonts} {
714 entry .e -font $big -bd 3 -relief raised -width 0
716 .e insert end "01234567"
718 list [winfo reqwidth .e] [winfo reqheight .e]
720 test entry-6.9 {EntryComputeGeometry procedure} {fonts} {
722 entry .e -font $big -bd 3 -relief raised -width 0 -highlightthickness 2
725 list [winfo reqwidth .e] [winfo reqheight .e]
727 test entry-6.10 {EntryComputeGeometry procedure} {unixOnly fonts} {
729 entry .e -bd 1 -relief raised -width 0 -show .
733 set x [winfo reqwidth .e]
735 lappend x [winfo reqwidth .e]
736 .e configure -show ""
737 lappend x [winfo reqwidth .e]
739 test entry-6.11 {EntryComputeGeometry procedure} {pcOnly} {
741 entry .e -bd 1 -relief raised -width 0 -show . -font {helvetica 12}
745 set x [winfo reqwidth .e]
747 lappend x [winfo reqwidth .e]
748 .e configure -show ""
749 lappend x [winfo reqwidth .e]
751 [expr 8+5*[font measure {helvetica 12} .]] \
752 [expr 8+5*[font measure {helvetica 12} X]] \
753 [expr 8+[font measure {helvetica 12} 12345]]]
756 entry .e -width 10 -font $fixed -textvariable contents -xscrollcommand scroll
759 test entry-7.1 {InsertChars procedure} {
764 list [.e get] $contents $scrollInfo
765 } {abXXXcde abXXXcde {0 1}}
766 test entry-7.2 {InsertChars procedure} {
771 list [.e get] $contents $scrollInfo
772 } {abcdeXXX abcdeXXX {0 1}}
773 test entry-7.3 {InsertChars procedure} {
775 .e insert 0 0123456789
779 set x "[.e index sel.first] [.e index sel.last]"
781 lappend x [.e index sel.first] [.e index sel.last]
783 test entry-7.4 {InsertChars procedure} {
785 .e insert 0 0123456789
789 set x "[.e index sel.first] [.e index sel.last]"
791 lappend x [.e index sel.first] [.e index sel.last]
793 test entry-7.5 {InsertChars procedure} {
795 .e insert 0 0123456789
799 set x "[.e index sel.first] [.e index sel.last]"
801 lappend x [.e index sel.first] [.e index sel.last]
803 test entry-7.6 {InsertChars procedure} {
805 .e insert 0 0123456789
809 set x "[.e index sel.first] [.e index sel.last]"
811 lappend x [.e index sel.first] [.e index sel.last]
813 test entry-7.7 {InsertChars procedure} {
815 .e insert 0 0123456789
820 test entry-7.8 {InsertChars procedure} {
822 .e insert 0 0123456789
827 test entry-7.9 {InsertChars procedure} {
829 .e insert 0 "This is a very long string"
835 test entry-7.10 {InsertChars procedure} {
837 .e insert 0 "This is a very long string"
843 .e configure -width 0
844 test entry-7.11 {InsertChars procedure} {fonts} {
852 .e configure -width 10
853 test entry-8.1 {DeleteChars procedure} {
858 list [.e get] $contents $scrollInfo
860 test entry-8.2 {DeleteChars procedure} {
865 list [.e get] $contents $scrollInfo
867 test entry-8.3 {DeleteChars procedure} {
872 list [.e get] $contents $scrollInfo
874 test entry-8.4 {DeleteChars procedure} {
876 .e insert 0 0123456789abcde
881 set x "[.e index sel.first] [.e index sel.last]"
883 lappend x [.e index sel.first] [.e index sel.last]
885 test entry-8.5 {DeleteChars procedure} {
887 .e insert 0 0123456789abcde
892 set x "[.e index sel.first] [.e index sel.last]"
894 lappend x [.e index sel.first] [.e index sel.last]
896 test entry-8.6 {DeleteChars procedure} {
898 .e insert 0 0123456789abcde
903 set x "[.e index sel.first] [.e index sel.last]"
905 lappend x [.e index sel.first] [.e index sel.last]
907 test entry-8.7 {DeleteChars procedure} {
909 .e insert 0 0123456789abcde
913 list [catch {.e index sel.first} msg] $msg
914 } {1 {selection isn't in entry}}
915 test entry-8.8 {DeleteChars procedure} {
917 .e insert 0 0123456789abcde
922 set x "[.e index sel.first] [.e index sel.last]"
924 lappend x [.e index sel.first] [.e index sel.last]
926 test entry-8.9 {DeleteChars procedure} {
928 .e insert 0 0123456789abcde
932 list [catch {.e index sel.first} msg] $msg
933 } {1 {selection isn't in entry}}
934 test entry-8.10 {DeleteChars procedure} {
936 .e insert 0 0123456789abcde
941 set x "[.e index sel.first] [.e index sel.last]"
943 lappend x [.e index sel.first] [.e index sel.last]
945 test entry-8.11 {DeleteChars procedure} {
947 .e insert 0 0123456789abcde
952 set x "[.e index sel.first] [.e index sel.last]"
954 lappend x [.e index sel.first] [.e index sel.last]
956 test entry-8.12 {DeleteChars procedure} {
958 .e insert 0 0123456789abcde
963 test entry-8.13 {DeleteChars procedure} {
965 .e insert 0 0123456789abcde
970 test entry-8.14 {DeleteChars procedure} {
972 .e insert 0 0123456789abcde
977 test entry-8.15 {DeleteChars procedure} {
979 .e insert 0 "This is a very long string"
984 test entry-8.16 {DeleteChars procedure} {
986 .e insert 0 "This is a very long string"
991 test entry-8.17 {DeleteChars procedure} {
993 .e insert 0 "This is a very long string"
998 .e configure -width 0
999 test entry-8.18 {DeleteChars procedure} {fonts} {
1007 test entry-9.1 {EntryValueChanged procedure} {
1009 proc override args {
1014 trace variable x w override
1015 entry .e -textvariable x
1017 set result [list $x [.e get]]
1018 unset x; rename override {}
1025 .e configure -width 0
1026 test entry-10.1 {EntrySetValue procedure} {fonts} {
1029 .e configure -textvariable x
1031 .e configure -textvariable y
1033 list [.e get] [winfo reqwidth .e]
1035 test entry-10.2 {EntrySetValue procedure, updating selection} {
1037 entry .e -textvariable x
1038 .e insert 0 "abcdefghjklmnopqrstu"
1039 .e selection range 4 10
1041 list [catch {.e index sel.first} msg] $msg
1042 } {1 {selection isn't in entry}}
1043 test entry-10.3 {EntrySetValue procedure, updating selection} {
1045 entry .e -textvariable x
1046 .e insert 0 "abcdefghjklmnopqrstu"
1047 .e selection range 4 10
1049 list [.e index sel.first] [.e index sel.last]
1051 test entry-10.4 {EntrySetValue procedure, updating selection} {
1053 entry .e -textvariable x
1054 .e insert 0 "abcdefghjklmnopqrstu"
1055 .e selection range 4 10
1056 set x "abcdefghijklmn"
1057 list [.e index sel.first] [.e index sel.last]
1059 test entry-10.5 {EntrySetValue procedure, updating display position} {
1061 entry .e -width 10 -font $fixed -textvariable x
1063 .e insert 0 "abcdefghjklmnopqrstuvwxyz"
1070 test entry-10.6 {EntrySetValue procedure, updating display position} {
1072 entry .e -width 10 -font $fixed -textvariable x
1074 .e insert 0 "abcdefghjklmnopqrstuvwxyz"
1077 set x "1234567890123456789012"
1081 test entry-10.7 {EntrySetValue procedure, updating insertion cursor} {
1083 entry .e -width 10 -font $fixed -textvariable x
1085 .e insert 0 "abcdefghjklmnopqrstuvwxyz"
1090 test entry-10.8 {EntrySetValue procedure, updating insertion cursor} {
1092 entry .e -width 10 -font $fixed -textvariable x
1094 .e insert 0 "abcdefghjklmnopqrstuvwxyz"
1100 test entry-11.1 {EntryEventProc procedure} {
1107 test entry-11.2 {EntryEventProc procedure} {
1108 eval destroy [winfo children .]
1109 entry .e1 -fg #112233
1112 lappend x [winfo children .]
1113 lappend x [.e2 cget -fg]
1115 lappend x [info command .e*] [winfo children .]
1116 } {.e1 #112233 {} {}}
1118 test entry-12.1 {EntryCmdDeletedProc procedure} {
1119 eval destroy [winfo children .]
1120 button .e1 -text "xyz_123"
1122 list [info command .e*] [winfo children .]
1126 entry .e -font $fixed -width 5 -bd 2 -relief sunken
1128 .e insert 0 012345678901234567890
1131 test entry-13.1 {GetEntryIndex procedure} {
1134 test entry-13.2 {GetEntryIndex procedure} {
1135 list [catch {.e index abogus} msg] $msg
1136 } {1 {bad entry index "abogus"}}
1137 test entry-13.3 {GetEntryIndex procedure} {
1142 test entry-13.4 {GetEntryIndex procedure} {
1147 test entry-13.5 {GetEntryIndex procedure} {
1153 test entry-13.6 {GetEntryIndex procedure} {
1154 list [catch {.e index ebogus} msg] $msg
1155 } {1 {bad entry index "ebogus"}}
1156 test entry-13.7 {GetEntryIndex procedure} {
1160 test entry-13.8 {GetEntryIndex procedure} {
1161 list [catch {.e index ibogus} msg] $msg
1162 } {1 {bad entry index "ibogus"}}
1163 test entry-13.9 {GetEntryIndex procedure} {
1166 list [.e index sel.first] [.e index sel.last]
1169 test entry-13.10 {GetEntryIndex procedure} {unixOnly} {
1170 # On unix, when selection is cleared, entry widget's internal
1171 # selection range is reset.
1173 list [catch {.e index sel.first} msg] $msg
1174 } {1 {selection isn't in entry}}
1175 test entry-13.11 {GetEntryIndex procedure} {macOrPc} {
1176 # On mac and pc, when selection is cleared, entry widget remembers
1177 # last selected range. When selection ownership is restored to
1178 # entry, the old range will be rehighlighted.
1180 list [catch {selection get}] [.e index sel.first]
1182 test entry-13.12 {GetEntryIndex procedure} {unixOnly} {
1183 list [catch {.e index sbogus} msg] $msg
1184 } {1 {selection isn't in entry}}
1185 test entry-13.13 {GetEntryIndex procedure} {macOrPc} {
1186 list [catch {.e index sbogus} msg] $msg
1187 } {1 {bad entry index "sbogus"}}
1188 test entry-13.14 {GetEntryIndex procedure} {macOrPc} {
1189 list [catch {selection get}] [catch {.e index sbogus}]
1191 test entry-13.15 {GetEntryIndex procedure} {
1192 list [catch {.e index @xyz} msg] $msg
1193 } {1 {bad entry index "@xyz"}}
1194 test entry-13.16 {GetEntryIndex procedure} {fonts} {
1197 test entry-13.17 {GetEntryIndex procedure} {fonts} {
1200 test entry-13.18 {GetEntryIndex procedure} {fonts} {
1203 test entry-13.19 {GetEntryIndex procedure} {fonts} {
1204 .e index @[expr [winfo width .e] - 6]
1206 test entry-13.20 {GetEntryIndex procedure} {fonts} {
1207 .e index @[expr [winfo width .e] - 5]
1209 test entry-13.21 {GetEntryIndex procedure} {
1212 test entry-13.22 {GetEntryIndex procedure} {
1213 list [catch {.e index 1xyz} msg] $msg
1214 } {1 {bad entry index "1xyz"}}
1215 test entry-13.23 {GetEntryIndex procedure} {
1218 test entry-13.24 {GetEntryIndex procedure} {
1221 test entry-13.25 {GetEntryIndex procedure} {
1224 test entry-13.26 {GetEntryIndex procedure} {fonts} {
1230 list [.e index @7] [.e index @8]
1233 # XXX Still need to write tests for EntryScanTo and EntrySelectTo.
1236 for {set i 1} {$i <= 500} {incr i} {
1237 append x "This is line $i, out of 500\n"
1239 test entry-14.1 {EntryFetchSelection procedure} {
1242 .e insert end "This is a test string"
1246 } {his is a test str}
1247 test entry-14.2 {EntryFetchSelection procedure} {
1250 .e insert end "This is a test string"
1254 } {*****************}
1255 test entry-14.3 {EntryFetchSelection procedure} {
1261 string compare [selection get] $x
1264 test entry-15.1 {EntryLostSelection} {
1270 set result [selection get]
1274 lappend result [selection get]
1277 # No tests for EventuallyRedraw.
1280 entry .e -width 10 -xscrollcommand scroll
1284 test entry-16.1 {EntryVisibleRange procedure} {fonts} {
1286 .e insert 0 .............................
1289 test entry-15.2 {EntryVisibleRange procedure} {unixOnly fonts} {
1290 .e configure -show X
1292 .e insert 0 .............................
1295 test entry-15.3 {EntryVisibleRange procedure} {pcOnly} {
1296 .e configure -show .
1298 .e insert 0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1301 .e configure -show ""
1302 test entry-15.4 {EntryVisibleRange procedure} {
1308 entry .e -width 10 -xscrollcommand scroll -font $fixed
1311 test entry-17.1 {EntryUpdateScrollbar procedure} {
1317 test entry-17.2 {EntryUpdateScrollbar procedure} {
1319 .e insert 0 0123456789abcdef
1324 test entry-17.3 {EntryUpdateScrollbar procedure} {
1326 .e insert 0 abcdefghijklmnopqrs
1330 } {0.315789 0.842105}
1331 test entry-17.4 {EntryUpdateScrollbar procedure} {
1337 entry .e -width 5 -xscrollcommand thisisnotacommand
1342 } {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
1344 "thisisnotacommand 0 1"
1345 (horizontal scrolling command executed by entry)}}
1347 set l [interp hidden]
1348 eval destroy [winfo children .]
1350 test entry-18.1 {Entry widget vs hiding} {
1355 list [winfo children .] [interp hidden]
1359 ## Entry widget VALIDATION tests
1364 catch {unset ::vVals}
1365 entry .e -validate all \
1366 -validatecommand [list doval %W %d %i %P %s %S %v %V] \
1367 -invalidcommand bell \
1369 -background red -foreground white
1371 proc doval {W d i P s S v V} {
1372 set ::vVals [list $W $d $i $P $s $S $v $V]
1376 # The validation tests build each one upon the previous, so cascading
1377 # failures aren't good
1379 test entry-19.1 {entry widget validation} {
1382 } {.e 1 0 a {} a all key}
1383 test entry-19.2 {entry widget validation} {
1386 } {.e 1 1 ab a b all key}
1387 test entry-19.3 {entry widget validation} {
1390 } {.e 1 2 abc ab c all key}
1391 test entry-19.4 {entry widget validation} {
1394 } {{.e 1 1 a123bc abc 123 all key} a123bc}
1395 test entry-19.5 {entry widget validation} {
1398 } {.e 0 2 a13bc a123bc 2 all key}
1399 test entry-19.6 {entry widget validation} {
1400 .e configure -validate key
1403 } {.e 0 1 abc a13bc 13 key key}
1404 test entry-19.7 {entry widget validation} {
1406 .e configure -validate focus
1410 test entry-19.8 {entry widget validation} {
1412 # update necessary to process FocusIn event
1415 } {.e -1 -1 abcd abcd {} focus focusin}
1416 test entry-19.9 {entry widget validation} {
1418 # update necessary to process FocusOut event
1421 } {.e -1 -1 abcd abcd {} focus focusout}
1422 .e configure -validate all
1423 test entry-19.10 {entry widget validation} {
1425 # update necessary to process FocusIn event
1428 } {.e -1 -1 abcd abcd {} all focusin}
1429 test entry-19.11 {entry widget validation} {
1431 # update necessary to process FocusOut event
1434 } {.e -1 -1 abcd abcd {} all focusout}
1435 .e configure -validate focusin
1436 test entry-19.12 {entry widget validation} {
1438 # update necessary to process FocusIn event
1441 } {.e -1 -1 abcd abcd {} focusin focusin}
1442 test entry-19.13 {entry widget validation} {
1445 # update necessary to process FocusOut event
1449 .e configure -validate focuso
1450 test entry-19.14 {entry widget validation} {
1452 # update necessary to process FocusIn event
1456 test entry-19.15 {entry widget validation} {
1458 # update necessary to process FocusOut event
1461 } {.e -1 -1 abcd abcd {} focusout focusout}
1462 test entry-19.16 {entry widget validation} {
1463 list [.e validate] $::vVals
1464 } {1 {.e -1 -1 abcd abcd {} all forced}}
1465 test entry-19.17 {entry widget validation} {
1467 list [.e cget -validate] $::vVals
1468 } {focusout {.e -1 -1 newdata abcd {} focusout forced}}
1470 proc doval {W d i P s S v V} {
1471 set ::vVals [list $W $d $i $P $s $S $v $V]
1474 .e configure -validate all
1476 test entry-19.18 {entry widget validation} {
1478 list [.e cget -validate] $::vVals
1479 } {none {.e -1 -1 nextdata newdata {} all forced}}
1481 proc doval {W d i P s S v V} {
1482 set ::vVals [list $W $d $i $P $s $S $v $V]
1486 .e configure -validate all
1488 ## This sets validate to none because it shows that we prevent a possible
1489 ## loop condition in the validation, when the entry textvar is also set
1490 test entry-19.19 {entry widget validation} {
1492 list [.e cget -validate] [.e get] $::vVals
1493 } {none mydata {.e -1 -1 nextdata nextdata {} all forced}}
1495 .e configure -validate all
1497 ## This leaves validate alone because we trigger validation through the
1498 ## textvar (a write trace), and the write during validation triggers
1499 ## nothing (by definition of avoiding loops on var traces). This is
1500 ## one of those "dangerous" conditions where the user will have a
1501 ## different value in the entry widget shown as is in the textvar.
1502 test entry-19.20 {entry widget validation} {
1504 list [.e cget -validate] [.e get] $::e $::vVals
1505 } {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}
1508 catch {unset ::e ::vVals}
1511 ## End validation tests
1514 # XXX Still need to write tests for EntryBlinkProc, EntryFocusProc,
1515 # and EntryTextVarProc.
1520 ::tcltest::cleanupTests