1 # This file is a Tcl script to test out the procedures in the file
2 # tkCursor.c. It is organized in the standard white-box fashion for
5 # Copyright (c) 1998 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
9 package require tcltest 2.2
10 namespace import ::tcltest::*
11 eval tcltest::configure $argv
12 tcltest::loadTestedCommands
15 # Tests 2.3 and 2.4 need a helper file with a very specific name and
17 proc setWincur {wincurName} {
18 upvar $wincurName wincur
19 set wincur(data_octal) {
20 000 000 002 000 001 000 040 040 000 000 007 000 007 000 060 001
21 000 000 026 000 000 000 050 000 000 000 040 000 000 000 100 000
22 000 000 001 000 001 000 000 000 000 000 000 000 000 000 000 000
23 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
24 000 000 377 377 377 000 000 000 000 000 000 000 000 000 000 000
25 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
26 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
27 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
28 000 000 000 000 000 000 000 000 000 000 160 016 000 000 170 036
29 000 000 174 076 000 000 076 174 000 000 037 370 000 000 017 360
30 000 000 007 340 000 000 007 340 000 000 017 360 000 000 037 370
31 000 000 076 174 000 000 174 076 000 000 170 036 000 000 160 016
32 000 000 000 000 000 000 377 377 377 377 377 377 377 377 377 377
33 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377
34 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377
35 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377
36 377 377 377 377 377 377 017 360 377 377 007 340 377 377 003 300
37 377 377 001 200 377 377 200 001 377 377 300 003 377 377 340 007
38 377 377 360 017 377 377 360 017 377 377 340 007 377 377 300 003
39 377 377 200 001 377 377 001 200 377 377 003 300 377 377 007 340
40 377 377 017 360 377 377
42 set wincur(data_binary) {}
43 foreach wincur(num) $wincur(data_octal) {
44 append wincur(data_binary) [binary format c [scan $wincur(num) %o]]
46 set wincur(dir) [makeDirectory {dir with spaces}]
47 set wincur(file) [makeFile $wincur(data_binary) "test file.cur" $wincur(dir)]
51 test cursor-1.1 {Tk_AllocCursorFromObj - converting internal reps} -constraints {
62 test cursor-1.2 {Tk_AllocCursorFromObj - discard stale cursor} -constraints {
69 lappend result [testcursor watch]
71 lappend result [testcursor watch]
74 } -result {{} {{1 1}}}
75 test cursor-1.3 {Tk_AllocCursorFromObj - reuse existing cursor} -constraints {
81 lappend result [testcursor watch]
83 pack .b1 .b2 -side top
84 lappend result [testcursor watch]
87 } -result {{{1 1}} {{2 1}}}
89 test cursor-2.1 {Tk_GetCursor procedure} -body {
90 button .b -cursor bad_name
93 } -returnCodes error -result {bad cursor spec "bad_name"}
94 test cursor-2.2 {Tk_GetCursor procedure} -body {
95 button .b -cursor @xyzzy
98 } -returnCodes error -result {bad cursor spec "@xyzzy"}
100 test cursor-2.3 {Tk_GetCursor procedure: cursor specs are lists} -constraints {
103 unset -nocomplain wincur
107 button .b -cursor [list @$wincur(file)]
110 removeDirectory $wincur(dir)
113 test cursor-2.4 {Tk_GetCursor procedure: cursor specs are lists} -constraints {
116 unset -nocomplain wincur
120 button .b -cursor @[regsub -all {[][ \\{}""$#]} $wincur(file) {\\&}]
123 removeDirectory $wincur(dir)
127 test cursor-3.1 {Tk_FreeCursorFromObj - reference counts} -constraints {
133 button .b1 -cursor $x
134 button .b3 -cursor $x
135 button .b2 -cursor $x
136 lappend result [testcursor heart]
138 lappend result [testcursor heart]
140 lappend result [testcursor heart]
142 lappend result [testcursor heart]
143 } -result {{{3 1}} {{2 1}} {{1 1}} {}}
145 test cursor-4.1 {FreeCursorObjProc} -constraints {
148 proc copy {s} {return [string index $s 0][string range $s 1 end]}
153 .b configure -cursor $y
155 .b configure -cursor $z
157 lappend result [testcursor heart]
159 lappend result [testcursor heart]
161 lappend result [testcursor heart]
163 lappend result [testcursor heart]
169 } -result {{{1 3}} {{1 2}} {{1 1}} {}}
171 # -------------------------------------------------------------------------
172 test cursor-5.1 {assert consistent cursor configuration command} -setup {
175 .b configure -cursor {watch red black}
180 # -------------------------------------------------------------------------
181 # Check for the standard set of cursors.
182 test cursor-6.1 {check cursor-font cursor X_cursor} -setup {
183 button .b -text X_cursor
185 .b configure -cursor X_cursor
189 test cursor-6.2 {check cursor-font cursor arrow} -setup {
190 button .b -text arrow
192 .b configure -cursor arrow
196 test cursor-6.3 {check cursor-font cursor based_arrow_down} -setup {
197 button .b -text based_arrow_down
199 .b configure -cursor based_arrow_down
203 test cursor-6.4 {check cursor-font cursor based_arrow_up} -setup {
204 button .b -text based_arrow_up
206 .b configure -cursor based_arrow_up
210 test cursor-6.5 {check cursor-font cursor boat} -setup {
213 .b configure -cursor boat
217 test cursor-6.6 {check cursor-font cursor bogosity} -setup {
218 button .b -text bogosity
220 .b configure -cursor bogosity
224 test cursor-6.7 {check cursor-font cursor bottom_left_corner} -setup {
225 button .b -text bottom_left_corner
227 .b configure -cursor bottom_left_corner
231 test cursor-6.8 {check cursor-font cursor bottom_right_corner} -setup {
232 button .b -text bottom_right_corner
234 .b configure -cursor bottom_right_corner
238 test cursor-6.9 {check cursor-font cursor bottom_side} -setup {
239 button .b -text bottom_side
241 .b configure -cursor bottom_side
245 test cursor-6.10 {check cursor-font cursor bottom_tee} -setup {
246 button .b -text bottom_tee
248 .b configure -cursor bottom_tee
252 test cursor-6.11 {check cursor-font cursor box_spiral} -setup {
253 button .b -text box_spiral
255 .b configure -cursor box_spiral
259 test cursor-6.12 {check cursor-font cursor center_ptr} -setup {
260 button .b -text center_ptr
262 .b configure -cursor center_ptr
266 test cursor-6.13 {check cursor-font cursor circle} -setup {
267 button .b -text circle
269 .b configure -cursor circle
273 test cursor-6.14 {check cursor-font cursor clock} -setup {
274 button .b -text clock
276 .b configure -cursor clock
280 test cursor-6.15 {check cursor-font cursor coffee_mug} -setup {
281 button .b -text coffee_mug
283 .b configure -cursor coffee_mug
287 test cursor-6.16 {check cursor-font cursor cross} -setup {
288 button .b -text cross
290 .b configure -cursor cross
294 test cursor-6.17 {check cursor-font cursor cross_reverse} -setup {
295 button .b -text cross_reverse
297 .b configure -cursor cross_reverse
301 test cursor-6.18 {check cursor-font cursor crosshair} -setup {
302 button .b -text crosshair
304 .b configure -cursor crosshair
308 test cursor-6.19 {check cursor-font cursor diamond_cross} -setup {
309 button .b -text diamond_cross
311 .b configure -cursor diamond_cross
315 test cursor-6.20 {check cursor-font cursor dot} -setup {
318 .b configure -cursor dot
322 test cursor-6.21 {check cursor-font cursor dotbox} -setup {
323 button .b -text dotbox
325 .b configure -cursor dotbox
329 test cursor-6.22 {check cursor-font cursor double_arrow} -setup {
330 button .b -text double_arrow
332 .b configure -cursor double_arrow
336 test cursor-6.23 {check cursor-font cursor draft_large} -setup {
337 button .b -text draft_large
339 .b configure -cursor draft_large
343 test cursor-6.24 {check cursor-font cursor draft_small} -setup {
344 button .b -text draft_small
346 .b configure -cursor draft_small
350 test cursor-6.25 {check cursor-font cursor draped_box} -setup {
351 button .b -text draped_box
353 .b configure -cursor draped_box
357 test cursor-6.26 {check cursor-font cursor exchange} -setup {
358 button .b -text exchange
360 .b configure -cursor exchange
364 test cursor-6.27 {check cursor-font cursor fleur} -setup {
365 button .b -text fleur
367 .b configure -cursor fleur
371 test cursor-6.28 {check cursor-font cursor gobbler} -setup {
372 button .b -text gobbler
374 .b configure -cursor gobbler
378 test cursor-6.29 {check cursor-font cursor gumby} -setup {
379 button .b -text gumby
381 .b configure -cursor gumby
385 test cursor-6.30 {check cursor-font cursor hand1} -setup {
386 button .b -text hand1
388 .b configure -cursor hand1
392 test cursor-6.31 {check cursor-font cursor hand2} -setup {
393 button .b -text hand2
395 .b configure -cursor hand2
399 test cursor-6.32 {check cursor-font cursor heart} -setup {
400 button .b -text heart
402 .b configure -cursor heart
406 test cursor-6.33 {check cursor-font cursor icon} -setup {
409 .b configure -cursor icon
413 test cursor-6.34 {check cursor-font cursor iron_cross} -setup {
414 button .b -text iron_cross
416 .b configure -cursor iron_cross
420 test cursor-6.35 {check cursor-font cursor left_ptr} -setup {
421 button .b -text left_ptr
423 .b configure -cursor left_ptr
427 test cursor-6.36 {check cursor-font cursor left_side} -setup {
428 button .b -text left_side
430 .b configure -cursor left_side
434 test cursor-6.37 {check cursor-font cursor left_tee} -setup {
435 button .b -text left_tee
437 .b configure -cursor left_tee
441 test cursor-6.38 {check cursor-font cursor leftbutton} -setup {
442 button .b -text leftbutton
444 .b configure -cursor leftbutton
448 test cursor-6.39 {check cursor-font cursor ll_angle} -setup {
449 button .b -text ll_angle
451 .b configure -cursor ll_angle
455 test cursor-6.40 {check cursor-font cursor lr_angle} -setup {
456 button .b -text lr_angle
458 .b configure -cursor lr_angle
462 test cursor-6.41 {check cursor-font cursor man} -setup {
465 .b configure -cursor man
469 test cursor-6.42 {check cursor-font cursor middlebutton} -setup {
470 button .b -text middlebutton
472 .b configure -cursor middlebutton
476 test cursor-6.43 {check cursor-font cursor mouse} -setup {
477 button .b -text mouse
479 .b configure -cursor mouse
483 test cursor-6.44 {check cursor-font cursor pencil} -setup {
484 button .b -text pencil
486 .b configure -cursor pencil
490 test cursor-6.45 {check cursor-font cursor pirate} -setup {
491 button .b -text pirate
493 .b configure -cursor pirate
497 test cursor-6.46 {check cursor-font cursor plus} -setup {
500 .b configure -cursor plus
504 test cursor-6.47 {check cursor-font cursor question_arrow} -setup {
505 button .b -text question_arrow
507 .b configure -cursor question_arrow
511 test cursor-6.48 {check cursor-font cursor right_ptr} -setup {
512 button .b -text right_ptr
514 .b configure -cursor right_ptr
518 test cursor-6.49 {check cursor-font cursor right_side} -setup {
519 button .b -text right_side
521 .b configure -cursor right_side
525 test cursor-6.50 {check cursor-font cursor right_tee} -setup {
526 button .b -text right_tee
528 .b configure -cursor right_tee
532 test cursor-6.51 {check cursor-font cursor rightbutton} -setup {
533 button .b -text rightbutton
535 .b configure -cursor rightbutton
539 test cursor-6.52 {check cursor-font cursor rtl_logo} -setup {
540 button .b -text rtl_logo
542 .b configure -cursor rtl_logo
546 test cursor-6.53 {check cursor-font cursor sailboat} -setup {
547 button .b -text sailboat
549 .b configure -cursor sailboat
553 test cursor-6.54 {check cursor-font cursor sb_down_arrow} -setup {
554 button .b -text sb_down_arrow
556 .b configure -cursor sb_down_arrow
560 test cursor-6.55 {check cursor-font cursor sb_h_double_arrow} -setup {
561 button .b -text sb_h_double_arrow
563 .b configure -cursor sb_h_double_arrow
567 test cursor-6.56 {check cursor-font cursor sb_left_arrow} -setup {
568 button .b -text sb_left_arrow
570 .b configure -cursor sb_left_arrow
574 test cursor-6.57 {check cursor-font cursor sb_right_arrow} -setup {
575 button .b -text sb_right_arrow
577 .b configure -cursor sb_right_arrow
581 test cursor-6.58 {check cursor-font cursor sb_up_arrow} -setup {
582 button .b -text sb_up_arrow
584 .b configure -cursor sb_up_arrow
588 test cursor-6.59 {check cursor-font cursor sb_v_double_arrow} -setup {
589 button .b -text sb_v_double_arrow
591 .b configure -cursor sb_v_double_arrow
595 test cursor-6.60 {check cursor-font cursor shuttle} -setup {
596 button .b -text shuttle
598 .b configure -cursor shuttle
602 test cursor-6.61 {check cursor-font cursor sizing} -setup {
603 button .b -text sizing
605 .b configure -cursor sizing
609 test cursor-6.62 {check cursor-font cursor spider} -setup {
610 button .b -text spider
612 .b configure -cursor spider
616 test cursor-6.63 {check cursor-font cursor spraycan} -setup {
617 button .b -text spraycan
619 .b configure -cursor spraycan
623 test cursor-6.64 {check cursor-font cursor star} -setup {
626 .b configure -cursor star
630 test cursor-6.65 {check cursor-font cursor target} -setup {
631 button .b -text target
633 .b configure -cursor target
637 test cursor-6.66 {check cursor-font cursor tcross} -setup {
638 button .b -text tcross
640 .b configure -cursor tcross
644 test cursor-6.67 {check cursor-font cursor top_left_arrow} -setup {
645 button .b -text top_left_arrow
647 .b configure -cursor top_left_arrow
651 test cursor-6.68 {check cursor-font cursor top_left_corner} -setup {
652 button .b -text top_left_corner
654 .b configure -cursor top_left_corner
658 test cursor-6.69 {check cursor-font cursor top_right_corner} -setup {
659 button .b -text top_right_corner
661 .b configure -cursor top_right_corner
665 test cursor-6.70 {check cursor-font cursor top_side} -setup {
666 button .b -text top_side
668 .b configure -cursor top_side
672 test cursor-6.71 {check cursor-font cursor top_tee} -setup {
673 button .b -text top_tee
675 .b configure -cursor top_tee
679 test cursor-6.72 {check cursor-font cursor trek} -setup {
682 .b configure -cursor trek
686 test cursor-6.73 {check cursor-font cursor ul_angle} -setup {
687 button .b -text ul_angle
689 .b configure -cursor ul_angle
693 test cursor-6.74 {check cursor-font cursor umbrella} -setup {
694 button .b -text umbrella
696 .b configure -cursor umbrella
700 test cursor-6.75 {check cursor-font cursor ur_angle} -setup {
701 button .b -text ur_angle
703 .b configure -cursor ur_angle
707 test cursor-6.76 {check cursor-font cursor watch} -setup {
708 button .b -text watch
710 .b configure -cursor watch
714 test cursor-6.77 {check cursor-font cursor xterm} -setup {
715 button .b -text xterm
717 .b configure -cursor xterm
722 # Test cursor named "none", it is not defined in
723 # the X cursor table. It is defined in a Tk specific
724 # table of named cursors and should be available on
726 test cursor-6.78 {test cursor named "none"} -setup {
727 button .b -text CButton
729 .b configure -cursor none
735 test cursor-6.79 {test cursor named "none"} -setup {
736 button .b -text CButton
738 .b configure -cursor none
739 .b configure -cursor {}
745 test cursor-6.80 {test cursor named "none"} -setup {
746 button .b -text CButton
748 .b configure -cursor none
749 .b configure -cursor {}
750 .b configure -cursor none
756 test cursor-6.81 {test cursor named "none"} -setup {
757 button .b -text CButton
759 # Setting fg and bg does nothing for the none cursor
760 # because it displays no fg or bg pixels.
762 .b configure -cursor none
763 lappend results [.b cget -cursor]
764 .b configure -cursor {none blue}
765 lappend results [.b cget -cursor]
766 .b configure -cursor {none blue green}
767 lappend results [.b cget -cursor]
768 .b configure -cursor {}
769 lappend results [.b cget -cursor]
774 } -result {none {none blue} {none blue green} {}}
776 # -------------------------------------------------------------------------
777 # Check the Windows specific cursors
778 test cursor-7.1 {check Windows cursor no} -constraints win -setup {
781 .b configure -cursor no
785 test cursor-7.2 {check Windows cursor starting} -constraints win -setup {
786 button .b -text starting
788 .b configure -cursor starting
792 test cursor-7.3 {check Windows cursor size} -constraints win -setup {
795 .b configure -cursor size
799 test cursor-7.4 {check Windows cursor size_ne_sw} -constraints win -setup {
800 button .b -text size_ne_sw
802 .b configure -cursor size_ne_sw
806 test cursor-7.5 {check Windows cursor size_ns} -constraints win -setup {
807 button .b -text size_ns
809 .b configure -cursor size_ns
813 test cursor-7.6 {check Windows cursor size_nw_se} -constraints win -setup {
814 button .b -text size_nw_se
816 .b configure -cursor size_nw_se
820 test cursor-7.7 {check Windows cursor size_we} -constraints win -setup {
821 button .b -text size_we
823 .b configure -cursor size_we
827 test cursor-7.8 {check Windows cursor uparrow} -constraints win -setup {
828 button .b -text uparrow
830 .b configure -cursor uparrow
834 test cursor-7.9 {check Windows cursor wait} -constraints win -setup {
837 .b configure -cursor wait
842 # -------------------------------------------------------------------------