home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / menubut.test < prev    next >
Encoding:
Text File  |  1995-06-23  |  11.9 KB  |  322 lines

  1. # This file is a Tcl script to test menubuttons in Tk.  It is
  2. # organized in the standard fashion for Tcl tests.
  3. #
  4. # Copyright (c) 1994 The Regents of the University of California.
  5. # Copyright (c) 1994-1995 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. # @(#) menubut.test 1.11 95/05/19 15:52:54
  11.  
  12. # XXX This test file is woefully incomplete right now.  If any part
  13. # XXX of a procedure has tests then the whole procedure has tests,
  14. # XXX but many procedures have no tests.
  15.  
  16. if {[lsearch [image types] test] < 0} {
  17.     puts "This application hasn't been compiled with the \"test\" image"
  18.     puts "type, so I can't run this test.  Are you sure you're using"
  19.     puts "tktest instead of wish?"
  20.     return
  21. }
  22.  
  23. if {[info procs test] != "test"} {
  24.     source defs
  25. }
  26.  
  27. foreach i [winfo children .] {
  28.     destroy $i
  29. }
  30. wm geometry . {}
  31. raise .
  32.  
  33. eval image delete [image names]
  34. image create test image1
  35. menubutton .mb -text "Test"
  36. pack .mb
  37. update
  38. set i 1
  39. foreach test {
  40.     {-activebackground #012345 #012345 non-existent
  41.         {unknown color name "non-existent"}}
  42.     {-activeforeground #ff0000 #ff0000 non-existent
  43.         {unknown color name "non-existent"}}
  44.     {-anchor nw nw bogus {bad anchor position "bogus": must be n, ne, e, se, s, sw, w, nw, or center}}
  45.     {-background #ff0000 #ff0000 non-existent
  46.         {unknown color name "non-existent"}}
  47.     {-bd 4 4 badValue {bad screen distance "badValue"}}
  48.     {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  49.     {-bitmap questhead questhead badValue {bitmap "badValue" not defined}}
  50.     {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
  51.     {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
  52.     {-disabledforeground #00ff00 #00ff00 xyzzy {unknown color name "xyzzy"}}
  53.     {-fg #110022 #110022 bogus {unknown color name "bogus"}}
  54.     {-font -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* 
  55.         -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* bogus
  56.         {font "bogus" doesn't exist}}
  57.     {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
  58.     {-height 18 18 20.0 {expected integer but got "20.0"}}
  59.     {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
  60.     {-highlightcolor #110022 #110022 bogus {unknown color name "bogus"}}
  61.     {-highlightthickness 18 18 badValue {bad screen distance "badValue"}}
  62.     {-image image1 image1 bogus {image "bogus" doesn't exist}}
  63.     {-indicatoron yes 1 no_way {expected boolean value but got "no_way"}}
  64.     {-justify right right bogus {bad justification "bogus": must be left, right, or center}}
  65.     {-menu "any old string" "any old string" {} {}}
  66.     {-padx 12 12 420x {bad screen distance "420x"}}
  67.     {-pady 12 12 420x {bad screen distance "420x"}}
  68.     {-relief groove groove 1.5 {bad relief type "1.5":  must be flat, groove, raised, ridge, or sunken}}
  69.     {-state normal normal bogus {bad state value "bogus":  must be normal, active, or disabled}}
  70.     {-takefocus "any string" "any string" {} {}}
  71.     {-text "Sample text" {Sample text} {} {}}
  72.     {-textvariable i i {} {}}
  73.     {-underline 5 5 3p {expected integer but got "3p"}}
  74.     {-width 402 402 3p {expected integer but got "3p"}}
  75.     {-wraplength 100 100 6x {bad screen distance "6x"}}
  76. } {
  77.     set name [lindex $test 0]
  78.     test menubutton-1.$i {configuration options} {
  79.     .mb configure $name [lindex $test 1]
  80.     lindex [.mb configure $name] 4
  81.     } [lindex $test 2]
  82.     incr i
  83.     if {[lindex $test 3] != ""} {
  84.     test menubutton-1.$i {configuration options} {
  85.         list [catch {.mb configure $name [lindex $test 3]} msg] $msg
  86.     } [list 1 [lindex $test 4]]
  87.     }
  88.     .mb configure $name [lindex [.mb configure $name] 3]
  89.     incr i
  90. }
  91.  
  92. test menubutton-2.1 {Tk_MenubuttonCmd procedure} {
  93.     list [catch {menubutton} msg] $msg
  94. } {1 {wrong # args:  should be "menubutton pathName ?options?"}}
  95. test menubutton-2.2 {Tk_MenubuttonCmd procedure} {
  96.     list [catch {menubutton foo} msg] $msg
  97. } {1 {bad window path name "foo"}}
  98. test menubutton-2.3 {Tk_MenubuttonCmd procedure} {
  99.     catch {destroy .mb}
  100.     menubutton .mb
  101.     winfo class .mb
  102. } {Menubutton}
  103. test menubutton-2.4 {Tk_ButtonCmd procedure} {
  104.     catch {destroy .mb}
  105.     list [catch {menubutton .mb -gorp foo} msg] $msg [winfo exists .mb]
  106. } {1 {unknown option "-gorp"} 0}
  107.  
  108. catch {destroy .mb}
  109. menubutton .mb -text "Test Menu"
  110. pack .mb
  111. test menubutton-3.1 {MenuButtonWidgetCmd procedure} {
  112.     list [catch {.mb} msg] $msg
  113. } {1 {wrong # args: should be ".mb option ?arg arg ...?"}}
  114. test menubutton-3.2 {ButtonWidgetCmd procedure, "cget" option} {
  115.     list [catch {.mb c} msg] $msg
  116. } {1 {bad option "c":  must be cget or configure}}
  117. test menubutton-3.3 {ButtonWidgetCmd procedure, "cget" option} {
  118.     list [catch {.mb cget} msg] $msg
  119. } {1 {wrong # args: should be ".mb cget option"}}
  120. test menubutton-3.4 {ButtonWidgetCmd procedure, "cget" option} {
  121.     list [catch {.mb cget a b} msg] $msg
  122. } {1 {wrong # args: should be ".mb cget option"}}
  123. test menubutton-3.5 {ButtonWidgetCmd procedure, "cget" option} {
  124.     list [catch {.mb cget -gorp} msg] $msg
  125. } {1 {unknown option "-gorp"}}
  126. test menubutton-3.6 {ButtonWidgetCmd procedure, "cget" option} {
  127.     .mb configure -highlightthickness 3
  128.     .mb cget -highlightthickness
  129. } {3}
  130. test menubutton-3.7 {ButtonWidgetCmd procedure, "configure" option} {
  131.     llength [.mb configure]
  132. } {31}
  133. test menubutton-3.8 {ButtonWidgetCmd procedure, "configure" option} {
  134.     list [catch {.mb configure -gorp} msg] $msg
  135. } {1 {unknown option "-gorp"}}
  136. test menubutton-3.9 {ButtonWidgetCmd procedure, "configure" option} {
  137.     list [catch {.mb co -bg #ffffff -fg} msg] $msg
  138. } {1 {value for "-fg" missing}}
  139. test menubutton-3.10 {ButtonWidgetCmd procedure, "configure" option} {
  140.     .mb configure -fg #123456
  141.     .mb configure -bg #654321
  142.     lindex [.mb configure -fg] 4
  143. } {#123456}
  144. test menubutton-3.11 {ButtonWidgetCmd procedure, "configure" option} {
  145.     list [catch {.mb foobar} msg] $msg
  146. } {1 {bad option "foobar":  must be cget or configure}}
  147.  
  148. # XXX Need to add tests for several procedures here.   The tests for   XXX
  149. # XXX ConfigureMenuButton aren't complete either.                      XXX
  150.  
  151. test menubutton-4.1 {ConfigureMenuButton procedure} {
  152.     catch {destroy .mb1}
  153.     button .mb1 -text "Menubutton 1"
  154.     list [catch {.mb1 configure -width 1i} msg] $msg $errorInfo
  155. } {1 {expected integer but got "1i"} {expected integer but got "1i"
  156.     (processing -width option)
  157.     invoked from within
  158. ".mb1 configure -width 1i"}}
  159. test menubutton-4.2 {ConfigureMenuButton procedure} {
  160.     catch {destroy .mb1}
  161.     button .mb1 -text "Menubutton 1"
  162.     list [catch {.mb1 configure -height 0.5c} msg] $msg $errorInfo
  163. } {1 {expected integer but got "0.5c"} {expected integer but got "0.5c"
  164.     (processing -height option)
  165.     invoked from within
  166. ".mb1 configure -height 0.5c"}}
  167. test menubutton-4.3 {ConfigureMenuButton procedure} {
  168.     catch {destroy .mb1}
  169.     button .mb1 -bitmap questhead
  170.     list [catch {.mb1 configure -width abc} msg] $msg $errorInfo
  171. } {1 {bad screen distance "abc"} {bad screen distance "abc"
  172.     (processing -width option)
  173.     invoked from within
  174. ".mb1 configure -width abc"}}
  175. test menubutton-4.4 {ConfigureMenuButton procedure} {
  176.     catch {destroy .mb1}
  177.     eval image delete [image names]
  178.     image create test image1
  179.     button .mb1 -image image1
  180.     list [catch {.mb1 configure -height 0.5x} msg] $msg $errorInfo
  181. } {1 {bad screen distance "0.5x"} {bad screen distance "0.5x"
  182.     (processing -height option)
  183.     invoked from within
  184. ".mb1 configure -height 0.5x"}}
  185. if $doNonPortableTests {
  186.     test menubutton-4.5 {ConfigureMenuButton procedure} {
  187.     catch {destroy .mb1}
  188.     button .mb1 -text "Sample text" -width 10 -height 2
  189.     pack .mb1
  190.     set result "[winfo reqwidth .mb1] [winfo reqheight .mb1]"
  191.     .mb1 configure -bitmap questhead
  192.     lappend result [winfo reqwidth .mb1] [winfo reqheight .mb1]
  193.     } {102 48 20 12}
  194. }
  195.  
  196. # XXX Need to add tests for several procedures here. XXX
  197.  
  198. test button-5.1 {MenuButtonEventProc procedure} {
  199.     eval destroy [winfo children .]
  200.     menubutton .mb1 -bg #543210
  201.     rename .mb1 .mb2
  202.     set x {}
  203.     lappend x [winfo children .]
  204.     lappend x [.mb2 cget -bg]
  205.     destroy .mb1
  206.     lappend x [info command .mb*] [winfo children .]
  207. } {.mb1 #543210 {} {}}
  208.  
  209. test button-6.1 {MenuButtonCmdDeletedProc procedure} {
  210.     eval destroy [winfo children .]
  211.     menubutton .mb1
  212.     rename .mb1 {}
  213.     list [info command .mb*] [winfo children .]
  214. } {{} {}}
  215.  
  216. test menubutton-7.1 {ComputeMenuButtonGeometry procedure} {
  217.     catch {destroy .mb}
  218.     menubutton .mb -image image1 -bd 4 -highlightthickness 0
  219.     pack .mb
  220.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  221. } {38 23}
  222. test menubutton-7.2 {ComputeMenuButtonGeometry procedure} {
  223.     catch {destroy .mb}
  224.     menubutton .mb -image image1 -bd 1 -highlightthickness 2
  225.     pack .mb
  226.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  227. } {36 21}
  228. test menubutton-7.3 {ComputeMenuButtonGeometry procedure} {
  229.     catch {destroy .mb}
  230.     menubutton .mb -image image1 -bd 0 -highlightthickness 2 -padx 5 -pady 5
  231.     pack .mb
  232.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  233. } {34 19}
  234. test menubutton-7.4 {ComputeMenuButtonGeometry procedure} {
  235.     catch {destroy .mb}
  236.     menubutton .mb -image image1 -bd 2 -relief raised -width 40 \
  237.         -highlightthickness 2
  238.     pack .mb
  239.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  240. } {48 23}
  241. test menubutton-7.5 {ComputeMenuButtonGeometry procedure} {
  242.     catch {destroy .mb}
  243.     menubutton .mb -image image1 -bd 2 -relief raised -height 30 \
  244.         -highlightthickness 2
  245.     pack .mb
  246.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  247. } {38 38}
  248. test menubutton-7.6 {ComputeMenuButtonGeometry procedure} {
  249.     catch {destroy .mb}
  250.     menubutton .mb -bitmap question -bd 2 -relief raised \
  251.         -highlightthickness 2
  252.     pack .mb
  253.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  254. } {25 35}
  255. test menubutton-7.7 {ComputeMenuButtonGeometry procedure} {
  256.     catch {destroy .mb}
  257.     menubutton .mb -bitmap question -bd 2 -relief raised -width 40 \
  258.         -highlightthickness 1
  259.     pack .mb
  260.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  261. } {46 33}
  262. test menubutton-7.8 {ComputeMenuButtonGeometry procedure} {
  263.     catch {destroy .mb}
  264.     menubutton .mb -bitmap question -bd 2 -relief raised -height 50 \
  265.         -highlightthickness 1
  266.     pack .mb
  267.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  268. } {23 56}
  269. if $doNonPortableTests {
  270.     test menubutton-7.9 {ComputeMenuButtonGeometry procedure} {
  271.     catch {destroy .mb}
  272.     menubutton .mb -text String -bd 2 -relief raised -padx 0 -pady 0 \
  273.         -highlightthickness 1
  274.     pack .mb
  275.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  276.     } {40 21}
  277.     test menubutton-7.10 {ComputeMenuButtonGeometry procedure} {
  278.     catch {destroy .mb}
  279.     menubutton .mb -text String -bd 2 -relief raised -width 20 \
  280.         -padx 0 -pady 0 -highlightthickness 1
  281.     pack .mb
  282.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  283.     } {146 21}
  284.     test menubutton-7.11 {ComputeMenuButtonGeometry procedure} {
  285.     catch {destroy .mb}
  286.     menubutton .mb -text String -bd 2 -relief raised -height 2 \
  287.         -padx 0 -pady 0 -highlightthickness 1
  288.     pack .mb
  289.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  290.     } {40 36}
  291.     test menubutton-7.12 {ComputeMenuButtonGeometry procedure} {
  292.     catch {destroy .mb}
  293.     menubutton .mb -text String -bd 2 -relief raised -padx 10 -pady 5 \
  294.         -highlightthickness 1
  295.     pack .mb
  296.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  297.     } {60 31}
  298.     test menubutton-7.13 {ComputeMenuButtonGeometry procedure} {
  299.     catch {destroy .mb}
  300.     menubutton .mb -text String -bd 2 -relief raised \
  301.         -highlightthickness 1 -indicatoron 1
  302.     pack .mb
  303.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  304.     } {76 29}
  305. }
  306.  
  307. # The following test is non-portable because the indicator's pixel
  308. # size varies to maintain constant absolute size.
  309.  
  310. if $doNonPortableTests {
  311.     test menubutton-7.14 {ComputeMenuButtonGeometry procedure} {
  312.     catch {destroy .mb}
  313.     menubutton .mb -image image1 -bd 2 -relief raised \
  314.         -highlightthickness 2 -indicatoron 1
  315.     pack .mb
  316.     list [winfo reqwidth .mb] [winfo reqheight .mb]
  317.     } {64 23}
  318. }
  319.  
  320. eval image delete [image names]
  321. eval destroy [winfo children .]
  322.