console.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # console tests. -*- tcl -*-
  2. #
  3. # Sourcing this file into Tcl runs the tests and
  4. # generates output for errors. No output means no errors were found.
  5. #
  6. # Copyright 2004 Mayo Foundation. All rights reserved.
  7. # $Id: console.test,v 1.1 2004/02/12 20:56:57 techenti Exp $
  8. if {[lsearch [namespace children] ::tcltest] == -1} {
  9. package require tcltest
  10. namespace import ::tcltest::*
  11. }
  12. #-------------------------------------------------------------------------
  13. # Tell tcltest to log error messages.
  14. # Since we're using child interps, you don't get much
  15. # in the way of meaningful test failures - just a return code
  16. # mismatch.
  17. #-------------------------------------------------------------------------
  18. ::tcltest::configure -verbose be
  19. #-------------------------------------------------------------------------
  20. # Set the auto_path for the child interps.
  21. #-------------------------------------------------------------------------
  22. set auto_path [concat [file dirname [info script]] $auto_path]
  23. #-------------------------------------------------------------------------
  24. # Create child interps using this autopath.
  25. # Add code to load console package, and remove a special
  26. # tkcon variable which would cause problems with
  27. # tkcon's checkpointing when run in child interps.
  28. #-------------------------------------------------------------------------
  29. proc createInterp {} {
  30. set c [interp create]
  31. $c alias parentSet set
  32. $c eval {
  33. set argv ""
  34. set auto_path [parentSet ::auto_path]
  35. package require console
  36. unset ::tkcon::CPS(slave,,cmd)
  37. }
  38. return $c
  39. }
  40. #-------------------------------------------------------------------------
  41. # Begin tests
  42. #-------------------------------------------------------------------------
  43. test console-1.0 {create console, no options} {
  44. set c [createInterp]
  45. set result [$c eval {
  46. console::create
  47. update
  48. #::tkcon close
  49. }]
  50. interp delete $c
  51. set result
  52. } {}
  53. test console-1.1 {create console, specify window name} {
  54. set c [createInterp]
  55. set result [$c eval {
  56. console::create -root .myconsole
  57. update
  58. set result [winfo exists .myconsole]
  59. }]
  60. interp delete $c
  61. set result
  62. } {1}
  63. test console-1.2 {create console, show on startup} {
  64. set c [createInterp]
  65. set result [$c eval {
  66. console::create -root .myconsole -showOnStartup 1
  67. update
  68. set result [winfo ismapped .myconsole]
  69. }]
  70. interp delete $c
  71. set result
  72. } {1}
  73. test console-1.3 {create console, don't show on startup} {
  74. set c [createInterp]
  75. set result [$c eval {
  76. console::create -root .myconsole -showOnStartup 0
  77. update
  78. set result [winfo ismapped .myconsole]
  79. }]
  80. interp delete $c
  81. set result
  82. } {0}
  83. test console-1.4 {create console, set title} {
  84. set c [createInterp]
  85. set result [$c eval {
  86. console::create -root .myconsole -title "console title"
  87. update
  88. set result [wm title .myconsole]
  89. }]
  90. interp delete $c
  91. set result
  92. } {console title}
  93. test console-1.5 {create console, set protocol script} {
  94. set c [createInterp]
  95. set result [$c eval {
  96. console::create -root .myconsole -protocol "protocol script"
  97. update
  98. set result [wm protocol .myconsole WM_DELETE_WINDOW]
  99. }]
  100. interp delete $c
  101. set result
  102. } {protocol script}
  103. test console-1.6 {create console, hide menu} {
  104. set c [createInterp]
  105. set result [$c eval {
  106. console::create -root .myconsole -showMenu 0
  107. update
  108. set result $::tkcon::OPT(showmenu)
  109. }]
  110. interp delete $c
  111. set result
  112. } {0}
  113. test console-1.7 {create console, show menu} {
  114. set c [createInterp]
  115. set result [$c eval {
  116. console::create -root .myconsole -showMenu 1
  117. update
  118. set result $::tkcon::OPT(showmenu)
  119. }]
  120. interp delete $c
  121. set result
  122. } {1}
  123. #-------------------------------------------------------------------------
  124. # Test using global variable
  125. # Note: these tests all fail for some reason. It acts like the
  126. # package never creates the global variable. Don't know if this
  127. # is just an artifact of the child interp or the test harness.
  128. # *sigh*
  129. #-------------------------------------------------------------------------
  130. if 0 {
  131. test console-2.0 {create console with global variable} {
  132. set c [createInterp]
  133. set result [$c eval {
  134. console::create -root .myconsole -variable ::myglobal
  135. update
  136. set result [info exists ::myglobal]
  137. }]
  138. interp delete $c
  139. set result
  140. } {1}
  141. test console-2.1 {create console with global variable, show and hide} {
  142. set c [createInterp]
  143. set result [$c eval {
  144. console::create -root .myconsole -variable ::myglobal
  145. set ::myglobal 1
  146. update
  147. set result [list [winfo ismapped .myconsole]]
  148. set ::myglobal 0
  149. update
  150. lappend result [winfo ismapped .myconsole]
  151. }]
  152. interp delete $c
  153. set result
  154. } {1 0}
  155. test console-2.2 {create console with global variable, show and hide} {
  156. set c [createInterp]
  157. set result [$c eval {
  158. console::create -root .myconsole -variable ::myglobal
  159. console::show
  160. update
  161. set result [list $::myglobal]
  162. console::hide
  163. lappend result $::myglobal
  164. }]
  165. interp delete $c
  166. set result
  167. } {1 0}
  168. }
  169. ::tcltest::cleanupTests