home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / canvRect.test < prev    next >
Encoding:
Text File  |  1995-05-29  |  11.5 KB  |  336 lines

  1. # This file is a Tcl script to test out the procedures in tkRectOval.c,
  2. # which implement canvas "rectangle" and "oval" items.  It is organized
  3. # in the standard fashion for Tcl tests.
  4. #
  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. # @(#) canvRect.test 1.7 95/05/28 17:49:21
  11.  
  12. if {[info procs test] != "test"} {
  13.     source defs
  14. }
  15.  
  16. foreach i [winfo children .] {
  17.     destroy $i
  18. }
  19. wm geometry . {}
  20. raise .
  21.  
  22. canvas .c -width 400 -height 300 -bd 2 -relief sunken
  23. pack .c
  24. bind .c <1> {
  25.     puts "button down at (%x,%y)"
  26. }
  27. update
  28.  
  29. set i 1
  30. .c create rectangle 20 20 80 80 -tag test
  31. foreach test {
  32.     {-fill #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  33.     {-outline #123456 #123456 bad_color {unknown color name "bad_color"}}
  34.     {-stipple gray50 gray50 bogus {bitmap "bogus" not defined}}
  35.     {-tags {test a b c} {test a b c} {} {}}
  36.     {-width 6 6 abc {bad screen distance "abc"}}
  37. } {
  38.     set name [lindex $test 0]
  39.     test canvRect-1.$i {configuration options} {
  40.     .c itemconfigure test $name [lindex $test 1]
  41.     list [lindex [.c itemconfigure test $name] 4] [.c itemcget test $name]
  42.     } [list [lindex $test 2] [lindex $test 2]]
  43.     incr i
  44.     if {[lindex $test 3] != ""} {
  45.     test canvRect-1.$i {configuration options} {
  46.         list [catch {.c itemconfigure test $name [lindex $test 3]} msg] $msg
  47.     } [list 1 [lindex $test 4]]
  48.     }
  49.     incr i
  50. }
  51. test canvRect-1.$i {configuration options} {
  52.     .c itemconfigure test -tags {test xyz}
  53.     .c itemcget xyz -tags
  54. } {test xyz}
  55.  
  56. test canvRect-2.1 {CreateRectOval procedure} {
  57.     list [catch {.c create rect} msg] $msg
  58. } {1 {wrong # args:  should be ".c" create rectangle x1 y1 x2 y2 ?options?}}
  59. test canvRect-2.2 {CreateRectOval procedure} {
  60.     list [catch {.c create oval x y z} msg] $msg
  61. } {1 {wrong # args:  should be ".c" create oval x1 y1 x2 y2 ?options?}}
  62. test canvRect-2.3 {CreateRectOval procedure} {
  63.     list [catch {.c create rectangle x 2 3 4} msg] $msg
  64. } {1 {bad screen distance "x"}}
  65. test canvRect-2.4 {CreateRectOval procedure} {
  66.     list [catch {.c create rectangle 1 y 3 4} msg] $msg
  67. } {1 {bad screen distance "y"}}
  68. test canvRect-2.5 {CreateRectOval procedure} {
  69.     list [catch {.c create rectangle 1 2 z 4} msg] $msg
  70. } {1 {bad screen distance "z"}}
  71. test canvRect-2.6 {CreateRectOval procedure} {
  72.     list [catch {.c create rectangle 1 2 3 q} msg] $msg
  73. } {1 {bad screen distance "q"}}
  74. test canvRect-2.7 {CreateRectOval procedure} {
  75.     .c create rectangle 1 2 3 4 -tags x
  76.     .c coords x
  77. } {1.0 2.0 3.0 4.0}
  78. test canvRect-2.8 {CreateRectOval procedure} {
  79.     list [catch {.c create rectangle 1 2 3 4 -gorp foo} msg] $msg
  80. } {1 {unknown option "-gorp"}}
  81.  
  82. .c delete withtag all
  83. .c create rectangle 10 20 30 40 -tags x
  84. test canvRect-3.1 {RectOvalCoords procedure} {
  85.     .c coords x
  86. } {10.0 20.0 30.0 40.0}
  87. test canvRect-3.2 {RectOvalCoords procedure} {
  88.     list [catch {.c coords x a 2 3 4} msg] $msg
  89. } {1 {bad screen distance "a"}}
  90. test canvRect-3.3 {RectOvalCoords procedure} {
  91.     list [catch {.c coords x 1 b 3 4} msg] $msg
  92. } {1 {bad screen distance "b"}}
  93. test canvRect-3.4 {RectOvalCoords procedure} {
  94.     list [catch {.c coords x 1 2 c 4} msg] $msg
  95. } {1 {bad screen distance "c"}}
  96. test canvRect-3.5 {RectOvalCoords procedure} {
  97.     list [catch {.c coords x 1 2 3 d} msg] $msg
  98. } {1 {bad screen distance "d"}}
  99.  
  100. # Non-portable due to rounding differences:
  101.  
  102. if $doNonPortableTests {
  103.     test canvRect-3.6 {RectOvalCoords procedure} {
  104.     .c coords x 10 25 15 40
  105.     .c bbox x
  106.     } {9 24 17 42}
  107. }
  108. test canvRect-3.7 {RectOvalCoords procedure} {
  109.     list [catch {.c coords x 1 2 3 4 5} msg] $msg
  110. } {1 {wrong # coordinates:  expected 0 or 4, got 5}}
  111.  
  112. .c delete withtag all
  113. .c create rectangle 10 20 30 40 -tags x -width 1
  114. test canvRect-4.1 {ConfigureRectOval procedure} {
  115.     list [catch {.c itemconfigure x -width abc} msg] $msg \
  116.         [.c itemcget x -width]
  117. } {1 {bad screen distance "abc"} 1}
  118. test canvRect-4.2 {ConfigureRectOval procedure} {
  119.     .c itemconfigure x -width -5
  120.     .c itemcget x -width
  121. } {1}
  122.  
  123. # Non-portable due to rounding differences:
  124.  
  125. if $doNonPortableTests {
  126.     test canvRect-4.3 {ConfigureRectOval procedure} {
  127.     .c itemconfigure x -width 10
  128.     .c bbox x
  129.     } {5 15 36 46}
  130. }
  131.  
  132. # I can't come up with any good tests for DeleteRectOval.
  133.  
  134.  
  135. # Non-portable due to rounding differences:
  136.  
  137. if $doNonPortableTests {
  138.     .c delete withtag all
  139.     .c create rectangle 10 20 30 40 -tags x -width 1 -outline {}
  140.     test canvRect-5.1 {ComputeRectOvalBbox procedure} {
  141.     .c coords x 20 15 10 5
  142.     .c bbox x
  143.     } {10 5 21 16}
  144.     test canvRect-5.2 {ComputeRectOvalBbox procedure} {
  145.     .c coords x 10 20 30 10
  146.     .c itemconfigure x -width 1 -outline red
  147.     .c bbox x
  148.     } {9 9 32 22}
  149.     test canvRect-5.3 {ComputeRectOvalBbox procedure} {
  150.     .c coords x 10 20 30 10
  151.     .c itemconfigure x -width 2 -outline red
  152.     .c bbox x
  153.     } {9 9 32 22}
  154.     test canvRect-5.4 {ComputeRectOvalBbox procedure} {
  155.     .c coords x 10 20 30 10
  156.     .c itemconfigure x -width 3 -outline red
  157.     .c bbox x
  158.     } {8 8 33 23}
  159. }
  160.  
  161. # I can't come up with any good tests for DisplayRectOval.
  162.  
  163. .c delete withtag all
  164. set x  [.c create rectangle 10 20 30 35 -tags x -fill green]
  165. set y [.c create rectangle 15 25 25 30  -tags y -fill red]
  166. test canvRect-6.1 {RectToPoint procedure} {
  167.     .c itemconfigure y -outline {}
  168.     list [.c find closest 14.9 28] [.c find closest 15.1 28] \
  169.         [.c find closest 24.9 28] [.c find closest 25.1 28]
  170. } "$x $y $y $x"
  171. test canvRect-6.2 {RectToPoint procedure} {
  172.     .c itemconfigure y -outline {}
  173.     list [.c find closest 20 24.9] [.c find closest 20 25.1] \
  174.         [.c find closest 20 29.9]  [.c find closest 20 30.1]
  175. } "$x $y $y $x"
  176. test canvRect-6.3 {RectToPoint procedure} {
  177.     .c itemconfigure y -width 1 -outline black
  178.     list [.c find closest 14.4 28] [.c find closest 14.6 28] \
  179.         [.c find closest 25.4 28] [.c find closest 25.6 28]
  180. } "$x $y $y $x"
  181. test canvRect-6.4 {RectToPoint procedure} {
  182.     .c itemconfigure  y -width 1 -outline black
  183.     list [.c find closest 20 24.4] [.c find closest 20 24.6] \
  184.         [.c find closest 20 30.4] [.c find closest 20 30.6]
  185. } "$x $y $y $x"
  186. .c itemconfigure x -fill {} -outline black -width 3
  187. .c itemconfigure y -outline {}
  188. test canvRect-6.5 {RectToPoint procedure} {
  189.     list [.c find closest 13.2 28] [.c find closest 13.3 28] \
  190.         [.c find closest 26.7 28] [.c find closest 26.8 28]
  191. } "$x $y $y $x"
  192. test canvRect-6.6 {RectToPoint procedure} {
  193.     list [.c find closest 20 23.2] [.c find closest 20 23.3] \
  194.         [.c find closest 20 31.7] [.c find closest 20 31.8]
  195. } "$x $y $y $x"
  196. .c delete withtag all
  197. set x [.c create rectangle 10 20 30 40 -outline {} -fill black]
  198. set y [.c create rectangle 40 40 50 50 -outline {} -fill black]
  199. test canvRect-6.7 {RectToPoint procedure} {
  200.     list [.c find closest 35 35] [.c find closest 36 36] \
  201.         [.c find closest 37 37] [.c find closest 38 38]
  202. } "$x $y $y $y"
  203.  
  204. .c delete withtag all
  205. set x  [.c create rectangle 10 20 30 35 -fill green -outline {}]
  206. set y [.c create rectangle 40 45 60 70 -fill red -outline black -width 3]
  207. set z [.c create rectangle 100 150 120 170 -fill {} -outline black -width 3]
  208. test canvRect-7.1 {RectToArea procedure} {
  209.     list [.c find overlapping 20 50 38 60] \
  210.         [.c find overlapping 20 50 39 60] \
  211.         [.c find overlapping 20 50 70 60] \
  212.         [.c find overlapping 61 50 70 60] \
  213.         [.c find overlapping 62 50 70 60]
  214. } "{} $y $y $y {}"
  215. test canvRect-7.2 {RectToArea procedure} {
  216.     list [.c find overlapping 45 20 55 43] \
  217.         [.c find overlapping 45 20 55 44] \
  218.         [.c find overlapping 45 20 55 80] \
  219.         [.c find overlapping 45 71 55 80] \
  220.         [.c find overlapping 45 72 55 80]
  221. } "{} $y $y $y {}"
  222. test canvRect-7.3 {RectToArea procedure} {
  223.     list [.c find overlapping 5 25 9.9 30] [.c find overlapping 5 25 10.1 30]
  224. } "{} $x"
  225. test canvRect-7.4 {RectToArea procedure} {
  226.     list [.c find overlapping 102 152 118 168] \
  227.         [.c find overlapping 101 152 118 168] \
  228.         [.c find overlapping 102 151 118 168] \
  229.         [.c find overlapping 102 152 119 168] \
  230.         [.c find overlapping 102 152 118 169]
  231. } "{} $z $z $z $z"
  232. test canvRect-7.5 {RectToArea procedure} {
  233.     list [.c find enclosed 20 40 38 80] \
  234.         [.c find enclosed 20 40 39 80] \
  235.         [.c find enclosed 20 40 70 80] \
  236.         [.c find enclosed 61 40 70 80] \
  237.         [.c find enclosed 62 40 70 80]
  238. } "{} {} $y {} {}"
  239. test canvRect-7.6 {RectToArea procedure} {
  240.     list [.c find enclosed 20 20 65 43] \
  241.         [.c find enclosed 20 20 65 44] \
  242.         [.c find enclosed 20 20 65 80] \
  243.         [.c find enclosed 20 71 65 80] \
  244.         [.c find enclosed 20 72 65 80]
  245. } "{} {} $y {} {}"
  246.  
  247. .c delete withtag all
  248. set x  [.c create oval 50 100 200 150 -fill green -outline {}]
  249. set y [.c create oval 50 100 200 150 -fill red -outline black -width 3]
  250. set z [.c create oval 50 100 200 150 -fill {} -outline black -width 3]
  251. test canvRect-8.1 {OvalToArea procedure} {
  252.     list [.c find overlapping 20 120 48 130] \
  253.         [.c find overlapping 20 120 49 130] \
  254.         [.c find overlapping 20 120 50.2 130] \
  255.         [.c find overlapping 20 120 300 130] \
  256.         [.c find overlapping 60 120 190 130] \
  257.         [.c find overlapping 199.9 120 300 130] \
  258.         [.c find overlapping 201 120 300 130] \
  259.         [.c find overlapping 202 120 300 130]
  260. } "{} {$y $z} {$x $y $z} {$x $y $z} {$x $y} {$x $y $z} {$y $z} {}"
  261. test canvRect-8.2 {OvalToArea procedure} {
  262.     list [.c find overlapping 100 50 150 98] \
  263.         [.c find overlapping 100 50 150 99] \
  264.         [.c find overlapping 100 50 150 100.1] \
  265.         [.c find overlapping 100 50 150 200] \
  266.         [.c find overlapping 100 110 150 140] \
  267.         [.c find overlapping 100 149.9 150 200] \
  268.         [.c find overlapping 100 151 150 200] \
  269.         [.c find overlapping 100 152 150 200]
  270. } "{} {$y $z} {$x $y $z} {$x $y $z} {$x $y} {$x $y $z} {$y $z} {}"
  271. test canvRect-8.3 {OvalToArea procedure} {
  272.     list [.c find overlapping 176 104 177 105] \
  273.         [.c find overlapping 187 116 188 117] \
  274.         [.c find overlapping 192 142 193 143] \
  275.         [.c find overlapping 180 138 181 139] \
  276.         [.c find overlapping 61 142 62 143] \
  277.         [.c find overlapping 65 137 66 136] \
  278.         [.c find overlapping 62 108 63 109] \
  279.         [.c find overlapping 68 115 69 116]
  280. } "{} {$x $y} {} {$x $y} {} {$x $y} {} {$x $y}"
  281.  
  282. test canvRect-9.1 {ScaleRectOval procedure} {
  283.     .c delete withtag all
  284.     .c create rect 100 300 200 350 -tags x
  285.     .c scale x 50 100 2 4
  286.     .c coords x
  287. } {150.0 900.0 350.0 1100.0}
  288.  
  289. test canvRect-10.1 {TranslateRectOval procedure} {
  290.     .c delete withtag all
  291.     .c create rect 100 300 200 350 -tags x
  292.     .c move x 100 -10
  293.     .c coords x
  294. } {200.0 290.0 300.0 340.0}
  295.  
  296. if $doNonPortableTests {
  297.     # This test is non-portable because different color information
  298.     # will get generated on different displays (e.g. mono displays
  299.     # vs. color).
  300.  
  301.     test canvRect-11.1 {RectOvalToPostscript procedure} {
  302.     .c configure -bd 0 -highlightthickness 0
  303.     .c delete withtag all
  304.     .c create rect 50 60 90 80 -fill black -stipple gray50 -outline {}
  305.     .c create oval 100 150 200 200 -fill {} -outline #ff0000 -width 5
  306.     update
  307.     set x [.c postscript]
  308.     string range $x [string first "%%Page: 1 1" $x] end
  309.     } {%%Page: 1 1
  310. save
  311. 306.0 396.0 translate
  312. 0.7997 0.7997 scale
  313. -200 -150 translate
  314. 0 300 moveto 400 300 lineto 400 0 lineto 0 0 lineto closepath clip newpath
  315. gsave
  316. 50 240 moveto 40 0 rlineto 0 -20 rlineto -40 0 rlineto closepath
  317. 0.000 0.000 0.000 setrgbcolor AdjustColor
  318. clip 16 16 <5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555
  319. aaaa> StippleFill
  320. grestore
  321. gsave
  322. matrix currentmatrix
  323. 150 125 translate 50 25 scale 1 0 moveto 0 0 1 0 360 arc
  324. setmatrix
  325. 5 setlinewidth 0 setlinejoin 2 setlinecap
  326. 1.000 0.000 0.000 setrgbcolor AdjustColor
  327. stroke
  328. grestore
  329. restore showpage
  330.  
  331. %%Trailer
  332. end
  333. %%EOF
  334. }
  335. }
  336.