home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / tclMotif-1.4 / tests / cstext.test < prev    next >
Encoding:
Text File  |  1995-06-29  |  6.6 KB  |  298 lines

  1.  
  2.  
  3. # just ignore this file for before Motif 2.0
  4. if {$XmVersion >= 2000} {
  5.  
  6. if {[string compare test [info procs test]] == 1} then \
  7.   {source defs}
  8.  
  9. # set VERBOSE 1
  10. # set INTERACTIVE 1
  11.  
  12. proc no-changeCB {doit} {
  13.     upvar 1 $doit d
  14.  
  15.     set d false
  16. }
  17.  
  18. proc allcaps {text} {
  19.   upvar 1 $text p
  20.  
  21.   set upper [string toupper $p]
  22.   set p $upper
  23. }
  24.  
  25.  
  26. #############
  27. # starts here
  28. #############
  29.  
  30. xtAppInitialize -class Text
  31. . setValues -allowShellResize true
  32.  
  33. # XtText does not have a natural size, but doesn't like
  34. # zero width, so let a label set a >0 width
  35. xmRowColumn .rc managed
  36. xmLabel .rc.label managed
  37.  
  38. xmCSText .rc.text managed \
  39.    -columns 40
  40. . realizeWidget
  41.  
  42. ##################################
  43. # Manipulating text by resources #
  44. ##################################
  45.  
  46. test text-1.1 {setting and getting text} {
  47.     .rc.text setValues -cstextValue "The rain in Spain"
  48.     .rc.text getValues -cstextValue v
  49.     set v
  50. } {The rain in Spain}
  51.  
  52. ################################
  53. # Manipulating text by actions #
  54. ################################
  55.  
  56. test text-2.1 {appending text by insert-string} {
  57.     .rc.text callActionProc end-of-file()
  58.     .rc.text callActionProc {insert-string(" falls mainly")}
  59.     .rc.text getValues -cstextValue v
  60.     set v
  61. } {The rain in Spain falls mainly}
  62.  
  63. test text-2.2 {deleting text by delete-previous-character} {
  64.     .rc.text callActionProc delete-previous-character()
  65.     .rc.text callActionProc delete-previous-character()
  66.     .rc.text getValues -cstextValue v
  67.     set v
  68. } {The rain in Spain falls main}
  69.  
  70. test test-2.3 {inserting text by self-insert} {
  71.     .rc.text setValues -cstextValue ""
  72.     .rc.text callActionProc self-insert() \
  73.     -type KeyPress \
  74.     -keysym T
  75.     .rc.text callActionProc self-insert() \
  76.     -type KeyPress \
  77.     -keysym h
  78.     .rc.text callActionProc self-insert() \
  79.     -type KeyPress \
  80.     -keysym space
  81.     .rc.text callActionProc self-insert() \
  82.     -type KeyPress \
  83.     -keysym 9
  84.     .rc.text getValues -cstextValue v
  85.     set v
  86. } {Th 9}
  87.  
  88. #############################
  89. # modification verification #
  90. #############################
  91.  
  92. ############
  93. # no changes
  94. ############
  95. test text-3.1 {turn off every change in modifyVerify callback} {
  96.     .rc.text setValues -cstextValue "The rain in Spain"
  97.  
  98.     .rc.text modifyVerifyCallback {no-changeCB %doit}
  99.  
  100.     .rc.text callActionProc {insert-string(" falls mainly")}
  101.     .rc.text getValues -cstextValue v
  102.     set v
  103. } {The rain in Spain}
  104.  
  105. ####################
  106. # capitalize changes
  107. ####################
  108. .rc.text destroyWidget
  109. xmCSText .rc.text managed \
  110.     -columns 40
  111.  
  112. test text-3.2 {change text in modifyVerify callback} {
  113.     .rc.text setValues -cstextValue "The rain in Spain"
  114.     .rc.text callActionProc end-of-file()
  115.  
  116.     .rc.text modifyVerifyCallback {allcaps %text}
  117.  
  118.     .rc.text callActionProc {insert-string(" FalLs mAInlY")}
  119.     .rc.text getValues -cstextValue v
  120.     set v
  121. } {The rain in Spain FALLS MAINLY}
  122.  
  123. #####################################    
  124. # setting and getting text by methods
  125. #####################################
  126.  
  127. .rc.text destroyWidget
  128. puts stdout destroyed
  129. xmCSText .rc.text managed \
  130.     -columns 40
  131.  
  132. test text-4.1 {set and get text} {
  133.     .rc.text setString "hello world"
  134.     .rc.text getString 
  135. } {hello world}
  136.  
  137. if {$XmVersion >= 1002} {
  138. test text-4.2 {get a substring} {
  139.     set found [.rc.text getSubstring 2 3 value]
  140.     if {$found == "succeeded"} {
  141.     set result $value
  142.     } else {set result $found}
  143.     set result
  144. } {llo}    
  145. }
  146.  
  147. ####################################
  148. # getting and setting editable state
  149. ####################################
  150.  
  151. test text-5.1 {set and get editable state} {
  152.     .rc.text setEditable false
  153.     .rc.text getEditable
  154. } {false}
  155.  
  156. test text-5.2 {set and get editable state} {
  157.     .rc.text setEditable true
  158.     .rc.text getEditable
  159. } {true}
  160.  
  161. ########################################
  162. # getting and setting insertion position
  163. ########################################
  164.  
  165. test text-6.1 {getting and setting insertion position} {
  166.     .rc.text setInsertionPosition 5
  167.     .rc.text getInsertionPosition
  168. } {5}
  169.  
  170. test text-6.2 {getting last position} {
  171.     .rc.text setString "hello porkpie hat"
  172.     .rc.text getLastPosition
  173. } {17}
  174.  
  175. #################
  176. # finding strings
  177. #################
  178.  
  179. .rc.text setString "hello world"
  180.  
  181. if {$XmVersion >= 1002} {
  182. test text-7.1 {search forward for string} {
  183.     .rc.text findString 1 wor forward position
  184.     set position
  185. } {6}
  186.  
  187. test text-7.2 {search backward for string} {
  188.     .rc.text findString 10 wor backward position
  189.     set position
  190. } {6}
  191.  
  192. test text-7.3 {search for non-existent string} {
  193.     .rc.text findString 1 universe forward position
  194. } {false}
  195. }
  196.  
  197. ############################
  198. # manipulating parts of text
  199. ############################
  200.  
  201. test text-8.1 {insert text} {
  202.     .rc.text setString "abcdefgh"
  203.     .rc.text insert 3 PQRST
  204.     .rc.text getString
  205. } {abcPQRSTdefgh}
  206.  
  207. test text-8.2 {replace text} {
  208.     .rc.text replace 3 8 IJKL
  209.     .rc.text getString
  210. } {abcIJKLdefgh}
  211.  
  212. #########################
  213. # scroll and top position
  214. #########################
  215.  
  216. test text-9.1 {scroll and top position} {
  217.     .rc.text setValues -editMode multi_line_edit
  218.     .rc.text setString "one @n two @n three"
  219.     .rc.text scroll 2
  220.     .rc.text getTopCharacter
  221. } {8}
  222.  
  223. test text-9.2 {set top character} {
  224.     .rc.text setTopCharacter 5
  225.     .rc.text getTopCharacter
  226. } {4}
  227.  
  228. test text-9.3 {show position} {
  229.     .rc.text setValues -autoShowCursorPosition true
  230.     .rc.text showPosition 2
  231.     .rc.text getInsertionPosition
  232. } {0}
  233.  
  234. ##################
  235. # multiple sources
  236. ##################
  237.  
  238. test text-10.1 {two sources} {
  239.     .rc.text destroyWidget
  240.     xmRowColumn .rc.rc managed
  241.     xmCSText .rc.rc.text managed
  242.     xmCSText .rc.rc.text2 managed
  243.     .rc.rc.text setString abcdefgh
  244.     .rc.rc.text2 setSource .rc.rc.text 0 0
  245.     .rc.rc.text2 getString
  246. } {abcdefgh}
  247.  
  248. .rc.rc destroyWidget
  249.  
  250.  
  251. ###################
  252. # primary selection
  253. ###################
  254.  
  255. xmCSText .rc.text managed
  256.  
  257. test text-11.1 {managing the primary selection} {
  258.     .rc.text setString "hello world"
  259.     .rc.text setSelection 2 7
  260.     .rc.text getSelection
  261. } {llo w}
  262.  
  263. test text-11.2 {locating primary selection} {
  264.     .rc.text getSelectionPosition left right
  265.     set result "$left $right"
  266.     set result
  267. } {2 7}
  268.  
  269. test text-11.3 {copy and paste primary selection} {
  270.     .rc.text copy
  271.     .rc.text setInsertionPosition 1
  272.     .rc.text paste
  273.     .rc.text getString
  274. } {hllo wello world}
  275.  
  276. test text-11.4 {cut and paste the primary selection} {
  277.     .rc.text setString "hello world"
  278.     .rc.text setSelection 2 7
  279.     .rc.text cut
  280.     .rc.text setInsertionPosition 0
  281.     .rc.text paste
  282.     .rc.text getString
  283. } {llo wheorld}
  284.  
  285.  
  286. #############
  287. # Finish up #
  288. #############
  289. if { ! $INTERACTIVE} {
  290.   .rc.label destroyWidget
  291.   .rc.text destroyWidget
  292.   .rc destroyWidget
  293. } else {
  294.   . mainLoop
  295. }
  296.  
  297. }
  298.