clipboard.test
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:9k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # This file is a Tcl script to test out Tk's clipboard management code,
  2. # especially the "clipboard" command.  It is organized in the standard
  3. # fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1994 Sun Microsystems, Inc.
  6. # Copyright (c) 1998-1999 by Scriptics Corporation.
  7. # All rights reserved.
  8. #
  9. # RCS: @(#) $Id: clipboard.test,v 1.6 2002/07/14 05:48:46 dgp Exp $
  10. #
  11. # Note: Multiple display clipboard handling will only be tested if the
  12. # environment variable TK_ALT_DISPLAY is set to an alternate display.
  13. #
  14. package require tcltest 2.1
  15. namespace import -force tcltest::configure
  16. namespace import -force tcltest::testsDirectory
  17. configure -testdir [file join [pwd] [file dirname [info script]]]
  18. configure -loadfile [file join [testsDirectory] constraints.tcl]
  19. tcltest::loadTestedCommands
  20. # set up a very large buffer to test INCR retrievals
  21. set longValue ""
  22. foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
  23.     set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
  24.     append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
  25. }
  26. # Now we start the main body of the test code
  27. test clipboard-1.1 {ClipboardHandler procedure} {
  28.     clipboard clear
  29.     clipboard append "test"
  30.     clipboard get
  31. } {test}
  32. test clipboard-1.2 {ClipboardHandler procedure} {
  33.     clipboard clear
  34.     clipboard append "test"
  35.     clipboard append "ing"
  36.     clipboard get
  37. } {testing}
  38. test clipboard-1.3 {ClipboardHandler procedure} {
  39.     clipboard clear
  40.     clipboard append "t"
  41.     clipboard append "e"
  42.     clipboard append "s"
  43.     clipboard append "t"
  44.     clipboard get
  45. } {test}
  46. test clipboard-1.4 {ClipboardHandler procedure} {
  47.     clipboard clear
  48.     clipboard append $longValue
  49.     clipboard get
  50. } "$longValue"
  51. test clipboard-1.5 {ClipboardHandler procedure} {
  52.     clipboard clear
  53.     clipboard append $longValue
  54.     clipboard append "test"
  55.     clipboard get
  56. } "${longValue}test"
  57. test clipboard-1.6 {ClipboardHandler procedure} {
  58.     clipboard clear
  59.     clipboard append -t TEST $longValue
  60.     clipboard append -t STRING "test"
  61.     list [clipboard get -t STRING] 
  62. [clipboard get -t TEST]
  63. } [list test $longValue]
  64. test clipboard-1.7 {ClipboardHandler procedure} {
  65.     clipboard clear
  66.     clipboard append -t TEST [string range $longValue 1 4000]
  67.     clipboard append -t STRING "test"
  68.     list [clipboard get -t STRING] 
  69. [clipboard get -t TEST]
  70. } [list test [string range $longValue 1 4000]]
  71. test clipboard-1.8 {ClipboardHandler procedure} {
  72.     clipboard clear
  73.     clipboard append ""
  74.     clipboard get
  75. } {}
  76. test clipboard-1.9 {ClipboardHandler procedure} {
  77.     clipboard clear
  78.     clipboard append ""
  79.     clipboard append "Test"
  80.     clipboard get
  81. } {Test}
  82. ##############################################################################
  83. test clipboard-2.1 {ClipboardAppHandler procedure} {
  84.     set oldAppName [tk appname]
  85.     tk appname UnexpectedName
  86.     clipboard clear
  87.     clipboard append -type NEW_TYPE Data
  88.     set result [selection get -selection CLIPBOARD -type TK_APPLICATION]
  89.     tk appname $oldAppName
  90.     set result
  91. } {UnexpectedName}
  92. ##############################################################################
  93. test clipboard-3.1 {ClipboardWindowHandler procedure} {
  94.     set oldAppName [tk appname]
  95.     tk appname UnexpectedName
  96.     clipboard clear
  97.     clipboard append -type NEW_TYPE Data
  98.     set result [selection get -selection CLIPBOARD -type TK_WINDOW]
  99.     tk appname $oldAppName
  100.     set result
  101. } {.}
  102. ##############################################################################
  103. test clipboard-4.1 {ClipboardLostSel procedure} {
  104.     clipboard clear
  105.     clipboard append "Test"
  106.     selection clear -s CLIPBOARD
  107.     list [catch {clipboard get} msg] $msg
  108. } {1 {CLIPBOARD selection doesn't exist or form "STRING" not defined}}
  109. test clipboard-4.2 {ClipboardLostSel procedure} {
  110.     clipboard clear
  111.     clipboard append "Test"
  112.     clipboard append -t TEST "Test2"
  113.     selection clear -s CLIPBOARD
  114.     list [catch {clipboard get} msg] $msg 
  115. [catch {clipboard get -t TEST} msg] $msg
  116. } {1 {CLIPBOARD selection doesn't exist or form "STRING" not defined} 1 {CLIPBOARD selection doesn't exist or form "TEST" not defined}}
  117. test clipboard-4.3 {ClipboardLostSel procedure} {
  118.     clipboard clear
  119.     clipboard append "Test"
  120.     clipboard append -t TEST "Test2"
  121.     clipboard append "Test3"
  122.     selection clear -s CLIPBOARD
  123.     list [catch {clipboard get} msg] $msg 
  124. [catch {clipboard get -t TEST} msg] $msg
  125. } {1 {CLIPBOARD selection doesn't exist or form "STRING" not defined} 1 {CLIPBOARD selection doesn't exist or form "TEST" not defined}}
  126. ##############################################################################
  127. test clipboard-5.1 {Tk_ClipboardClear procedure} {
  128.     clipboard clear
  129.     clipboard append -t TEST "test"
  130.     set result [lsort [clipboard get TARGETS]]
  131.     clipboard clear
  132.     list $result [lsort [clipboard get TARGETS]]
  133. } {{MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
  134. test clipboard-5.2 {Tk_ClipboardClear procedure} {
  135.     clipboard clear
  136.     clipboard append -t TEST "test"
  137.     set result [lsort [clipboard get TARGETS]]
  138.     selection own -s CLIPBOARD .
  139.     lappend result [lsort [clipboard get TARGETS]]
  140.     clipboard clear
  141.     clipboard append -t TEST "test"
  142.     lappend result [lsort [clipboard get TARGETS]]
  143. } {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
  144. ##############################################################################
  145. test clipboard-6.1 {Tk_ClipboardAppend procedure} {
  146.     clipboard clear
  147.     clipboard append "first chunk"
  148.     selection own -s CLIPBOARD .
  149.     list [catch {
  150. clipboard append " second chunk"
  151. clipboard get
  152.     } msg] $msg
  153. } {0 {first chunk second chunk}}
  154. test clipboard-6.2 {Tk_ClipboardAppend procedure} {unixOnly} {
  155.     setupbg
  156.     clipboard clear
  157.     clipboard append -f INTEGER -t TEST "16"
  158.     set result [dobg {clipboard get TEST}]
  159.     cleanupbg
  160.     set result
  161. } {0x10}
  162. test clipboard-6.3 {Tk_ClipboardAppend procedure} {
  163.     clipboard clear
  164.     clipboard append -f INTEGER -t TEST "16"
  165.     list [catch {clipboard append -t TEST "test"} msg] $msg
  166. } {1 {format "STRING" does not match current format "INTEGER" for TEST}}
  167. ##############################################################################
  168. test clipboard-7.1 {Tk_ClipboardCmd procedure} {
  169.     list [catch {clipboard} msg] $msg
  170. } {1 {wrong # args: should be "clipboard option ?arg arg ...?"}}
  171. test clipboard-7.2 {Tk_ClipboardCmd procedure} {
  172.     clipboard clear
  173.     list [catch {clipboard append --} msg] $msg 
  174.     [selection get -selection CLIPBOARD]
  175. } {0 {} --}
  176. test clipboard-7.3 {Tk_ClipboardCmd procedure} {
  177.     clipboard clear
  178.     list [catch {clipboard append -- information} msg] $msg 
  179.     [selection get -selection CLIPBOARD]
  180. } {0 {} information}
  181. test clipboard-7.4 {Tk_ClipboardCmd procedure} {
  182.     list [catch {clipboard append --x a b} msg] $msg
  183. } {1 {bad option "--x": must be -displayof, -format, or -type}}
  184. test clipboard-7.5 {Tk_ClipboardCmd procedure} {
  185.     list [catch {clipboard append -- a b} msg] $msg
  186. } {1 {wrong # args: should be "clipboard append ?options? data"}}
  187. test clipboard-7.6 {Tk_ClipboardCmd procedure} {
  188.     clipboard clear
  189.     list [catch {clipboard append -format} msg] $msg 
  190.     [selection get -selection CLIPBOARD]
  191. } {0 {} -format}
  192. test clipboard-7.7 {Tk_ClipboardCmd procedure} {
  193.     list [catch {clipboard append -displayofoo f} msg] $msg
  194. } {1 {bad option "-displayofoo": must be -displayof, -format, or -type}}
  195. test clipboard-7.8 {Tk_ClipboardCmd procedure} {
  196.     list [catch {clipboard append -type TEST} msg] $msg
  197. } {1 {wrong # args: should be "clipboard append ?options? data"}}
  198. test clipboard-7.9 {Tk_ClipboardCmd procedure} {
  199.     list [catch {clipboard append -displayof foo "test"} msg] $msg
  200. } {1 {bad window path name "foo"}}
  201. test clipboard-7.10 {Tk_ClipboardCmd procedure} {
  202.     list [catch {clipboard clear -displayof} msg] $msg
  203. } {1 {wrong # args: should be "clipboard clear ?-displayof window?"}}
  204. test clipboard-7.11 {Tk_ClipboardCmd procedure} {
  205.     list [catch {clipboard clear -displayofoo f} msg] $msg
  206. } {1 {bad option "-displayofoo": must be -displayof}}
  207. test clipboard-7.12 {Tk_ClipboardCmd procedure} {
  208.     list [catch {clipboard clear foo} msg] $msg
  209. } {1 {wrong # args: should be "clipboard clear ?-displayof window?"}}
  210. test clipboard-7.13 {Tk_ClipboardCmd procedure} {
  211.     list [catch {clipboard clear -displayof foo} msg] $msg
  212. } {1 {bad window path name "foo"}}
  213. test clipboard-7.14 {Tk_ClipboardCmd procedure} {
  214.     list [catch {clipboard error} msg] $msg
  215. } {1 {bad option "error": must be append, clear, or get}}
  216. test clipboard-7.15 {Tk_ClipboardCmd procedure} {
  217.     clipboard clear
  218.     list [catch {clipboard append -displayof} msg] $msg 
  219.     [selection get -selection CLIPBOARD]
  220. } {0 {} -displayof}
  221. test clipboard-7.16 {Tk_ClipboardCmd procedure} {
  222.     clipboard clear
  223.     list [catch {clipboard append -type} msg] $msg 
  224.     [selection get -selection CLIPBOARD]
  225. } {0 {} -type}
  226. # cleanup
  227. ::tcltest::cleanupTests
  228. return