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

  1. # This file is a Tcl script to test out Tk's selection management code,
  2. # especially the "selection" command.  It is organized in the standard
  3. # 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. # @(#) select.test 1.13 95/06/23 17:01:33
  11.  
  12. #
  13. # Note: Multiple display selection handling will only be tested if the
  14. # environment variable TK_ALT_DISPLAY is set to an alternate display.
  15. #
  16.  
  17. if {[string compare test [info procs test]] == 1} {
  18.     source defs
  19. }
  20.  
  21. eval destroy [winfo child .]
  22.  
  23. global longValue selValue selInfo
  24.  
  25. set selValue {}
  26. set selInfo {}
  27.  
  28. proc handler {type offset count} {
  29.     global selValue selInfo
  30.     lappend selInfo $type $offset $count
  31.     set numBytes [expr {[string length $selValue] - $offset}]
  32.     if {$numBytes <= 0} {
  33.     return ""
  34.     }
  35.     string range $selValue $offset [expr $numBytes+$offset]
  36. }
  37.  
  38. proc errIncrHandler {type offset count} {
  39.     global selValue selInfo pass
  40.     if {$offset == 4000} {
  41.     if {$pass == 0} {
  42.         # Just sizing the selection;  don't do anything here.
  43.         set pass 1
  44.     } else {
  45.         # Fetching the selection;  wait long enough to cause a timeout.
  46.         after 6000
  47.     }
  48.     }
  49.     lappend selInfo $type $offset $count
  50.     set numBytes [expr {[string length $selValue] - $offset}]
  51.     if {$numBytes <= 0} {
  52.     return ""
  53.     }
  54.     string range $selValue $offset [expr $numBytes+$offset]
  55. }
  56.  
  57. proc errHandler args {
  58.     error "selection handler aborted"
  59. }
  60.  
  61. proc badHandler {path type offset count} {
  62.     global selValue selInfo
  63.     selection handle -type $type $path {}
  64.     lappend selInfo $path $type $offset $count
  65.     set numBytes [expr {[string length $selValue] - $offset}]
  66.     if {$numBytes <= 0} {
  67.     return ""
  68.     }
  69.     string range $selValue $offset [expr $numBytes+$offset]
  70. }
  71. proc reallyBadHandler {path type offset count} {
  72.     global selValue selInfo pass
  73.     if {$offset == 4000} {
  74.     if {$pass == 0} {
  75.         set pass 1
  76.     } else {
  77.         selection handle -type $type $path {}
  78.     }
  79.     }
  80.     lappend selInfo $path $type $offset $count
  81.     set numBytes [expr {[string length $selValue] - $offset}]
  82.     if {$numBytes <= 0} {
  83.     return ""
  84.     }
  85.     string range $selValue $offset [expr $numBytes+$offset]
  86. }
  87.  
  88. # Eliminate any existing selection on the screen.  This is needed in case
  89. # there is a selection in some other application, in order to prevent races
  90. # from causing false errors in the tests below.
  91.  
  92. selection clear .
  93. after 1500
  94.  
  95. # common setup code
  96. proc setup {{path .f1} {display {}}} {
  97.     catch {destroy $path}
  98.     if {$display == {}} {
  99.     frame $path
  100.     } else {
  101.     toplevel $path -screen $display
  102.     wm geom $path +0+0
  103.     }
  104.     selection own $path
  105. }
  106.  
  107. # set up a very large buffer to test INCR retrievals
  108. set longValue ""
  109. 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} {
  110.     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
  111.     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
  112. }
  113.  
  114. # Now we start the main body of the test code
  115.  
  116. test select-1.1 {Tk_CreateSelHandler procedure} {
  117.     setup
  118.     lsort [selection get TARGETS]
  119. } {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}
  120. test select-1.2 {Tk_CreateSelHandler procedure} {
  121.     setup
  122.     selection handle .f1 {handler TEST} TEST
  123.     lsort [selection get TARGETS]
  124. } {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
  125. test select-1.3 {Tk_CreateSelHandler procedure} {
  126.     global selValue selInfo
  127.     setup
  128.     selection handle .f1 {handler TEST} TEST
  129.     set selValue "Test value"
  130.     set selInfo ""
  131.     list [selection get TEST] $selInfo
  132. } {{Test value} {TEST 0 4000}}
  133. test select-1.4 {Tk_CreateSelHandler procedure} {
  134.     setup
  135.     selection handle .f1 {handler TEST} TEST
  136.     selection handle .f1 {handler STRING}
  137.     lsort [selection get TARGETS]
  138. } {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
  139. test select-1.5 {Tk_CreateSelHandler procedure} {
  140.     global selValue selInfo
  141.     setup
  142.     selection handle .f1 {handler TEST} TEST
  143.     selection handle .f1 {handler STRING}
  144.     set selValue ""
  145.     set selInfo ""
  146.     list [selection get] $selInfo
  147. } {{} {STRING 0 4000}}
  148. test select-1.6 {Tk_CreateSelHandler procedure} {
  149.     global selValue selInfo
  150.     setup
  151.     selection handle .f1 {handler TEST} TEST
  152.     selection handle .f1 {handler STRING}
  153.     set selValue ""
  154.     set selInfo ""
  155.     selection get
  156.     selection get -type TEST
  157.     selection handle .f1 {handler TEST2} TEST
  158.     selection get -type TEST
  159.     list [set selInfo] [lsort [selection get TARGETS]]
  160. } {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
  161. test select-1.7 {Tk_CreateSelHandler procedure} {
  162.     setup
  163.     selection own -selection CLIPBOARD .f1
  164.     selection handle -selection CLIPBOARD .f1 {handler TEST} TEST
  165.     selection handle -selection PRIMARY .f1 {handler TEST2} STRING
  166.     list [lsort [selection get -selection PRIMARY TARGETS]] \
  167.     [lsort [selection get -selection CLIPBOARD TARGETS]] 
  168. } {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
  169. test select-1.8 {Tk_CreateSelHandler procedure} {
  170.     setup
  171.     selection handle -format INTEGER -type TEST .f1 {handler TEST}
  172.     lsort [selection get TARGETS]
  173. } {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
  174.  
  175. ##############################################################################
  176.  
  177. test select-2.1 {Tk_DeleteSelHandler procedure} {
  178.     setup
  179.     selection handle .f1 {handler STRING} 
  180.     selection handle -type TEST .f1 {handler TEST} 
  181.     selection handle -type USER .f1 {handler USER} 
  182.     set result [list [lsort [selection get TARGETS]]]
  183.     selection handle -type TEST .f1 {}
  184.     lappend result [lsort [selection get TARGETS]]
  185. } {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER}}
  186. test select-2.2 {Tk_DeleteSelHandler procedure} {
  187.     setup
  188.     selection handle .f1 {handler STRING} 
  189.     selection handle -type TEST .f1 {handler TEST} 
  190.     selection handle -type USER .f1 {handler USER} 
  191.     set result [list [lsort [selection get TARGETS]]]
  192.     selection handle -type USER .f1 {}
  193.     lappend result [lsort [selection get TARGETS]]
  194. } {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
  195. test select-2.3 {Tk_DeleteSelHandler procedure} {
  196.     setup
  197.     selection own -selection CLIPBOARD .f1
  198.     selection handle -selection PRIMARY .f1 {handler STRING} 
  199.     selection handle -selection CLIPBOARD .f1 {handler STRING} 
  200.     selection handle -selection CLIPBOARD .f1 {}
  201.     list [lsort [selection get TARGETS]] \
  202.     [lsort [selection get -selection CLIPBOARD TARGETS]]
  203. } {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
  204. test select-2.4 {Tk_DeleteSelHandler procedure} {
  205.     setup
  206.     selection handle .f1 {handler STRING}
  207.     list [selection handle .f1 {}] [selection handle .f1 {}]
  208. } {{} {}}   
  209.  
  210. ##############################################################################
  211.  
  212. test select-3.1 {Tk_OwnSelection procedure} {
  213.     setup
  214.     selection own
  215. } {.f1}
  216. test select-3.2 {Tk_OwnSelection procedure} {
  217.     setup .f1
  218.     set result [selection own]
  219.     setup .f2
  220.     lappend result [selection own]
  221. } {.f1 .f2}
  222. test select-3.3 {Tk_OwnSelection procedure} {
  223.     setup .f1
  224.     setup .f2
  225.     selection own -selection CLIPBOARD .f1
  226.     list [selection own] [selection own -selection CLIPBOARD]
  227. } {.f2 .f1}
  228. test select-3.4 {Tk_OwnSelection procedure} {
  229.     global lostSel
  230.     setup
  231.     set lostSel {owned}
  232.     selection own -command { set lostSel {lost} } .f1
  233.     selection clear .f1
  234.     set lostSel
  235. } {lost}
  236. test select-3.5 {Tk_OwnSelection procedure} {
  237.     global lostSel
  238.     setup .f1
  239.     setup .f2
  240.     set lostSel {owned}
  241.     selection own -command { set lostSel {lost1} } .f1
  242.     selection own -command { set lostSel {lost2} } .f2
  243.     list $lostSel [selection own]
  244. } {lost1 .f2}
  245. test select-3.6 {Tk_OwnSelection procedure} {
  246.     global lostSel
  247.     setup
  248.     set lostSel {owned}
  249.     selection own -command { set lostSel {lost1} } .f1
  250.     selection own -command { set lostSel {lost2} } .f1
  251.     set result $lostSel
  252.     selection clear .f1
  253.     lappend result $lostSel
  254. } {owned lost2}
  255. test select-3.7 {Tk_OwnSelection procedure} {
  256.     global lostSel
  257.     setup
  258.     setupbg
  259.     set lostSel {owned}
  260.     selection own -command { set lostSel {lost1} } .f1
  261.     update
  262.     set result {}
  263.     lappend result [dobg { selection own . }]
  264.     lappend result [dobg {selection own}]
  265.     update
  266.     cleanupbg
  267.     lappend result $lostSel
  268. } {{} . lost1}
  269. # check reentrancy on selection replacement
  270. test select-3.8 {Tk_OwnSelection procedure} {
  271.     setup
  272.     selection own -selection CLIPBOARD -command { destroy .f1 } .f1
  273.     selection own -selection CLIPBOARD .
  274. } {}
  275. test select-3.9 {Tk_OwnSelection procedure} {
  276.     setup .f2
  277.     setup .f1
  278.     selection own -selection CLIPBOARD -command { destroy .f2 } .f1
  279.     selection own -selection CLIPBOARD .f2
  280. } {}
  281.  
  282. # multiple display tests
  283. if {[info exists env(TK_ALT_DISPLAY)]} {
  284.  
  285.     test select-3.10 {Tk_OwnSelection procedure} {
  286.     setup .f1
  287.     setup .f2 $env(TK_ALT_DISPLAY)
  288.     list [selection own -displayof .f1] [selection own -displayof .f2]
  289.     } {.f1 .f2}
  290.     test select-3.11 {Tk_OwnSelection procedure} {
  291.     setup .f1
  292.     setup .f2 $env(TK_ALT_DISPLAY)
  293.     setupbg
  294.     update
  295.     set result ""
  296.     lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
  297.     lappend result [selection own -displayof .f1] \
  298.         [selection own -displayof .f2]
  299.     cleanupbg
  300.     set result
  301.     } {{} .f1 {}}
  302.  
  303. }
  304. ##############################################################################
  305.  
  306. test select-4.1 {Tk_ClearSelection procedure} {
  307.     setup
  308.     set result [selection own]
  309.     selection clear .f1
  310.     lappend result [selection own]
  311. } {.f1 {}}
  312. test select-4.2 {Tk_ClearSelection procedure} {
  313.     setup
  314.     selection own -selection CLIPBOARD .f1
  315.     selection clear .f1
  316.     selection own -selection CLIPBOARD
  317. } {.f1}
  318. test select-4.3 {Tk_ClearSelection procedure} {
  319.     setup
  320.     list [selection clear .f1] [selection clear .f1]
  321. } {{} {}}
  322. test select-4.4 {Tk_ClearSelection procedure} {
  323.     global lostSel
  324.     setup
  325.     setupbg
  326.     set lostSel {owned}
  327.     selection own -command { set lostSel {lost1} } .f1
  328.     update
  329.     set result {}
  330.     lappend result [dobg {selection clear; update}]
  331.     update
  332.     cleanupbg
  333.     lappend result [selection own]
  334. } {{} {}}
  335.  
  336. # multiple display tests
  337. if {[info exists env(TK_ALT_DISPLAY)]} {
  338.     test select-4.5 {Tk_ClearSelection procedure} {
  339.     global lostSel lostSel2
  340.     setup .f1
  341.     setup .f2 $env(TK_ALT_DISPLAY)
  342.     set lostSel {owned}
  343.     set lostSel2 {owned2}
  344.     selection own -command { set lostSel {lost1} } .f1
  345.     selection own -command { set lostSel2 {lost2} } .f2
  346.     update
  347.     selection clear -displayof .f2
  348.     update
  349.     list $lostSel $lostSel2
  350.     } {owned lost2}
  351.     test select-4.6 {Tk_ClearSelection procedure} {
  352.     setup .f1
  353.     setup .f2 $env(TK_ALT_DISPLAY)
  354.     setupbg
  355.     set lostSel {owned}
  356.     set lostSel2 {owned2}
  357.     selection own -command { set lostSel {lost1} } .f1
  358.     selection own -command { set lostSel2 {lost2} } .f2
  359.     update
  360.     set result ""
  361.     lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
  362.     lappend result [selection own -displayof .f1] \
  363.         [selection own -displayof .f2] $lostSel $lostSel2
  364.     cleanupbg
  365.     set result
  366.     } {{} .f1 {} owned lost2}
  367.  
  368. }
  369. ##############################################################################
  370.  
  371. test select-5.1 {Tk_GetSelection procedure} {
  372.     setup
  373.     list [catch {selection get TEST} msg] $msg
  374. } {1 {PRIMARY selection doesn't exist or form "TEST" not defined}}
  375. test select-5.2 {Tk_GetSelection procedure} {
  376.     setup
  377.     selection get TK_WINDOW
  378. } {.f1}
  379. test select-5.3 {Tk_GetSelection procedure} {
  380.     setup
  381.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  382.     set selValue "Test value"
  383.     set selInfo ""
  384.     list [selection get TEST] $selInfo
  385. } {{Test value} {TEST 0 4000}}
  386. test select-5.4 {Tk_GetSelection procedure} {
  387.     setup
  388.     selection handle .f1 ERROR errHandler
  389.     list [catch {selection get ERROR} msg] $msg
  390. } {1 {PRIMARY selection doesn't exist or form "ERROR" not defined}}
  391. test select-5.5 {Tk_GetSelection procedure} {
  392.     setup
  393.     set selValue $longValue
  394.     set selInfo ""
  395.     selection handle .f1 {handler STRING}
  396.     list [selection get] $selInfo
  397. } "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000}"
  398. test select-5.6 {Tk_GetSelection procedure} {
  399.     proc weirdHandler {type offset count} {
  400.     selection handle .f1 {}
  401.     handler $type $offset $count
  402.     }
  403.     setup
  404.     set selValue $longValue
  405.     set selInfo ""
  406.     selection handle .f1 {weirdHandler STRING}
  407.     list [catch {selection get} msg] $msg
  408. } {1 {PRIMARY selection doesn't exist or form "STRING" not defined}}
  409. test select-5.7 {Tk_GetSelection procedure} {
  410.     proc weirdHandler {type offset count} {
  411.     destroy .f1
  412.     handler $type $offset $count
  413.     }
  414.     setup
  415.     set selValue "Test Value"
  416.     set selInfo ""
  417.     selection handle .f1 {weirdHandler STRING}
  418.     list [catch {selection get} msg] $msg
  419. } {1 {PRIMARY selection doesn't exist or form "STRING" not defined}}
  420. test select-5.8 {Tk_GetSelection procedure} {
  421.     proc weirdHandler {type offset count} {
  422.     selection clear
  423.     handler $type $offset $count
  424.     }
  425.     setup
  426.     set selValue $longValue
  427.     set selInfo ""
  428.     selection handle .f1 {weirdHandler STRING}
  429.     list [selection get] $selInfo [catch {selection get} msg] $msg
  430. } "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000} 1 {PRIMARY selection doesn't exist or form \"STRING\" not defined}"
  431. test select-5.9 {Tk_GetSelection procedure} {
  432.     setup
  433.     setupbg
  434.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  435.     update
  436.     set selValue "Test value"
  437.     set selInfo ""
  438.     set result ""
  439.     lappend result [dobg {selection get TEST}]
  440.     cleanupbg
  441.     lappend result $selInfo
  442. } {{Test value} {TEST 0 4000}}
  443. test select-5.10 {Tk_GetSelection procedure} {
  444.     setup
  445.     setupbg
  446.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  447.     update
  448.     set selValue "Test value"
  449.     set selInfo ""
  450.     selection own .f1
  451.     set result ""
  452.     fileevent $fd readable {}
  453.     puts $fd {catch {selection get TEST} msg; update; puts $msg; flush stdout}
  454.     flush $fd
  455.     lappend result [gets $fd]
  456.     cleanupbg
  457.     lappend result $selInfo
  458. } {{selection owner didn't respond} {}}
  459.  
  460. # multiple display tests
  461. if {[info exists env(TK_ALT_DISPLAY)]} {
  462.     test select-5.11 {Tk_GetSelection procedure} {
  463.     setup .f1
  464.     setup .f2 $env(TK_ALT_DISPLAY)
  465.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  466.     selection handle -selection PRIMARY .f2 {handler TEST2} TEST
  467.     set selValue "Test value"
  468.     set selInfo ""
  469.     set result [list [selection get TEST] $selInfo]
  470.     set selValue "Test value2"
  471.     set selInfo ""
  472.     lappend result [selection get -displayof .f2 TEST] $selInfo
  473.     } {{Test value} {TEST 0 4000} {Test value2} {TEST2 0 4000}}
  474.     test select-5.12 {Tk_GetSelection procedure} {
  475.     global lostSel lostSel2
  476.     setup .f1
  477.     setup .f2 $env(TK_ALT_DISPLAY)
  478.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  479.     selection handle -selection PRIMARY .f2 {} TEST
  480.     set selValue "Test value"
  481.     set selInfo ""
  482.     set result [list [catch {selection get TEST} msg] $msg $selInfo]
  483.     set selValue "Test value2"
  484.     set selInfo ""
  485.     lappend result [catch {selection get -displayof .f2 TEST} msg] $msg \
  486.         $selInfo
  487.     } {0 {Test value} {TEST 0 4000} 1 {PRIMARY selection doesn't exist or form "TEST" not defined} {}}
  488.     test select-5.13 {Tk_GetSelection procedure} {
  489.     setup .f1
  490.     setup .f2 $env(TK_ALT_DISPLAY)
  491.     setupbg
  492.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  493.     selection own .f1
  494.     selection handle -selection PRIMARY .f2 {handler TEST2} TEST
  495.     selection own .f2
  496.     set selValue "Test value"
  497.     set selInfo ""
  498.     update
  499.     set result ""
  500.     lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
  501.     set selValue "Test value2"
  502.     lappend result [dobg "selection get TEST"]
  503.     cleanupbg
  504.     lappend result $selInfo
  505.     } {{Test value} {Test value2} {TEST2 0 4000 TEST 0 4000}}
  506.     test select-5.14 {Tk_GetSelection procedure} {
  507.     setup .f1
  508.     setup .f2 $env(TK_ALT_DISPLAY)
  509.     setupbg
  510.     selection handle -selection PRIMARY .f1 {handler TEST} TEST
  511.     selection own .f1
  512.     selection handle -selection PRIMARY .f2 {} TEST
  513.     selection own .f2
  514.     set selValue "Test value"
  515.     set selInfo ""
  516.     update
  517.     set result ""
  518.     lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
  519.     set selValue "Test value2"
  520.     lappend result [dobg "selection get TEST"]
  521.     cleanupbg
  522.     lappend result $selInfo
  523.     } {{PRIMARY selection doesn't exist or form "TEST" not defined} {Test value2} {TEST 0 4000}}
  524.  
  525. }
  526. ##############################################################################
  527.  
  528. test select-6.1 {Tk_SelectionCmd procedure} {
  529.     list [catch {selection} cmd] $cmd
  530. } {1 {wrong # args: should be "selection option ?arg arg ...?"}}
  531.  
  532. # selection clear
  533. test select-6.2 {Tk_SelectionCmd procedure} {
  534.     list [catch {selection clear -selection} cmd] $cmd
  535. } {1 {value for "-selection" missing}}
  536. test select-6.3 {Tk_SelectionCmd procedure} {
  537.     setup
  538.     selection own .
  539.     set result [selection own]
  540.     selection clear -displayof .f1
  541.     lappend result [selection own]
  542. } {. {}}
  543. test select-6.4 {Tk_SelectionCmd procedure} {
  544.     setup
  545.     selection own -selection CLIPBOARD .f1
  546.     set result [list [selection own] [selection own -selection CLIPBOARD]]
  547.     selection clear -selection CLIPBOARD .f1
  548.     lappend result [selection own] [selection own -selection CLIPBOARD]
  549. } {.f1 .f1 .f1 {}}
  550. test select-6.5 {Tk_SelectionCmd procedure} {
  551.     setup
  552.     selection own -selection CLIPBOARD .
  553.     set result [list [selection own] [selection own -selection CLIPBOARD]]
  554.     selection clear -selection CLIPBOARD -displayof .f1
  555.     lappend result [selection own] [selection own -selection CLIPBOARD]
  556. } {.f1 . .f1 {}}
  557. test select-6.6 {Tk_SelectionCmd procedure} {
  558.     list [catch {selection clear -badopt foo} cmd] $cmd
  559. } {1 {unknown option "-badopt"}}
  560. test select-6.7 {Tk_SelectionCmd procedure} {
  561.     list [catch {selection clear -selectionfoo foo} cmd] $cmd
  562. } {1 {unknown option "-selectionfoo"}}
  563. test select-6.8 {Tk_SelectionCmd procedure} {
  564.     catch {destroy .f2}
  565.     list [catch {selection clear -displayof .f2} cmd] $cmd
  566. } {1 {bad window path name ".f2"}}
  567. test select-6.9 {Tk_SelectionCmd procedure} {
  568.     catch {destroy .f2}
  569.     list [catch {selection clear .f2} cmd] $cmd
  570. } {1 {bad window path name ".f2"}}
  571. test select-6.10 {Tk_SelectionCmd procedure} {
  572.     setup
  573.     set result [selection own -selection PRIMARY]
  574.     selection clear
  575.     lappend result [selection own -selection PRIMARY]
  576. } {.f1 {}}
  577. test select-6.11 {Tk_SelectionCmd procedure} {
  578.     setup
  579.     selection own -selection CLIPBOARD .f1
  580.     set result [selection own -selection CLIPBOARD]
  581.     selection clear -selection CLIPBOARD
  582.     lappend result [selection own -selection CLIPBOARD]
  583. } {.f1 {}}
  584. test select-6.12 {Tk_SelectionCmd procedure} {
  585.     list [catch {selection clear foo bar} cmd] $cmd
  586. } {1 {wrong # args: should be "selection clear ?options?"}}
  587.  
  588. # selection get
  589. test select-6.13 {Tk_SelectionCmd procedure} {
  590.     list [catch {selection get -selection} cmd] $cmd
  591. } {1 {value for "-selection" missing}}
  592. test select-6.14 {Tk_SelectionCmd procedure} {
  593.     global selValue selInfo
  594.     setup
  595.     selection handle .f1 {handler TEST}
  596.     set selValue "Test value"
  597.     set selInfo ""
  598.     list [selection get -displayof .f1] $selInfo
  599. } {{Test value} {TEST 0 4000}}
  600. test select-6.15 {Tk_SelectionCmd procedure} {
  601.     global selValue selInfo
  602.     setup
  603.     selection handle .f1 {handler STRING}
  604.     selection handle -selection CLIPBOARD .f1 {handler TEST}
  605.     selection own -selection CLIPBOARD .f1
  606.     set selValue "Test value"
  607.     set selInfo ""
  608.     list [selection get -selection CLIPBOARD] $selInfo
  609. } {{Test value} {TEST 0 4000}}
  610. test select-6.16 {Tk_SelectionCmd procedure} {
  611.     global selValue selInfo
  612.     setup
  613.     selection handle -type TEST .f1 {handler TEST}
  614.     selection handle -type STRING .f1 {handler STRING}
  615.     set selValue "Test value"
  616.     set selInfo ""
  617.     list [selection get -type TEST] $selInfo
  618. } {{Test value} {TEST 0 4000}}
  619. test select-6.17 {Tk_SelectionCmd procedure} {
  620.     list [catch {selection get -badopt foo} cmd] $cmd
  621. } {1 {unknown option "-badopt"}}
  622. test select-6.18 {Tk_SelectionCmd procedure} {
  623.     list [catch {selection get -selectionfoo foo} cmd] $cmd
  624. } {1 {unknown option "-selectionfoo"}}
  625. test select-6.19 {Tk_SelectionCmd procedure} {
  626.     catch { destroy .f2 }
  627.     list [catch {selection get -displayof .f2} cmd] $cmd
  628. } {1 {bad window path name ".f2"}}
  629. test select-6.20 {Tk_SelectionCmd procedure} {
  630.     list [catch {selection get foo bar} cmd] $cmd
  631. } {1 {wrong # args: should be "selection get ?options?"}}
  632. test select-6.21 {Tk_SelectionCmd procedure} {
  633.     global selValue selInfo
  634.     setup
  635.     selection handle -type TEST .f1 {handler TEST}
  636.     selection handle -type STRING .f1 {handler STRING}
  637.     set selValue "Test value"
  638.     set selInfo ""
  639.     list [selection get TEST] $selInfo
  640. } {{Test value} {TEST 0 4000}}
  641.  
  642. # selection handle
  643. # most of the handle section has been covered earlier
  644. test select-6.22 {Tk_SelectionCmd procedure} {
  645.     list [catch {selection handle -selection} cmd] $cmd
  646. } {1 {value for "-selection" missing}}
  647. test select-6.23 {Tk_SelectionCmd procedure} {
  648.     global selValue selInfo
  649.     setup
  650.     set selValue "Test value"
  651.     set selInfo ""
  652.     list [selection handle -format INTEGER .f1 {handler TEST}] [selection get -displayof .f1] $selInfo
  653. } {{} {Test value} {TEST 0 4000}}
  654. test select-6.24 {Tk_SelectionCmd procedure} {
  655.     list [catch {selection handle -badopt foo} cmd] $cmd
  656. } {1 {unknown option "-badopt"}}
  657. test select-6.25 {Tk_SelectionCmd procedure} {
  658.     list [catch {selection handle -selectionfoo foo} cmd] $cmd
  659. } {1 {unknown option "-selectionfoo"}}
  660. test select-6.26 {Tk_SelectionCmd procedure} {
  661.     list [catch {selection handle} cmd] $cmd
  662. } {1 {wrong # args: should be "selection handle ?options? window command"}}
  663. test select-6.27 {Tk_SelectionCmd procedure} {
  664.     list [catch {selection handle .} cmd] $cmd
  665. } {1 {wrong # args: should be "selection handle ?options? window command"}}
  666. test select-6.28 {Tk_SelectionCmd procedure} {
  667.     list [catch {selection handle . foo bar baz blat} cmd] $cmd
  668. } {1 {wrong # args: should be "selection handle ?options? window command"}}
  669. test select-6.29 {Tk_SelectionCmd procedure} {
  670.     catch { destroy .f2 }
  671.     list [catch {selection handle .f2 dummy} cmd] $cmd
  672. } {1 {bad window path name ".f2"}}
  673.  
  674. # selection own
  675. test select-6.30 {Tk_SelectionCmd procedure} {
  676.     list [catch {selection own -selection} cmd] $cmd
  677. } {1 {value for "-selection" missing}}
  678. test select-6.31 {Tk_SelectionCmd procedure} {
  679.     setup
  680.     selection own .
  681.     selection own -displayof .f1
  682. } {.}
  683. test select-6.32 {Tk_SelectionCmd procedure} {
  684.     setup
  685.     selection own .
  686.     selection own -selection CLIPBOARD .f1
  687.     list [selection own] [selection own -selection CLIPBOARD]
  688. } {. .f1}
  689. test select-6.33 {Tk_SelectionCmd procedure} {
  690.     global lostSel
  691.     setup
  692.     set lostSel owned
  693.     selection own -command { set lostSel lost } .
  694.     selection own -selection CLIPBOARD .f1
  695.     set result $lostSel
  696.     selection own .f1
  697.     lappend result $lostSel
  698. } {owned lost}
  699. test select-6.34 {Tk_SelectionCmd procedure} {
  700.     list [catch {selection own -badopt foo} cmd] $cmd
  701. } {1 {unknown option "-badopt"}}
  702. test select-6.35 {Tk_SelectionCmd procedure} {
  703.     list [catch {selection own -selectionfoo foo} cmd] $cmd
  704. } {1 {unknown option "-selectionfoo"}}
  705. test select-6.36 {Tk_SelectionCmd procedure} {
  706.     catch {destroy .f2}
  707.     list [catch {selection own -displayof .f2} cmd] $cmd
  708. } {1 {bad window path name ".f2"}}
  709. test select-6.37 {Tk_SelectionCmd procedure} {
  710.     catch {destroy .f2}
  711.     list [catch {selection own .f2} cmd] $cmd
  712. } {1 {bad window path name ".f2"}}
  713. test select-6.38 {Tk_SelectionCmd procedure} {
  714.     list [catch {selection own foo bar baz} cmd] $cmd
  715. } {1 {wrong # args: should be "selection own ?options? ?window?"}}
  716.  
  717. test select-6.39 {Tk_SelectionCmd procedure} {
  718.     list [catch {selection foo} cmd] $cmd
  719. } {1 {bad option "foo":  must be clear, get, handle, or own}}
  720.  
  721. ##############################################################################
  722.  
  723. if $doNonPortableTests {
  724.     # This test is non-portable because some old X11/News servers ignore
  725.     # a selection request when the window doesn't exist, which causes a
  726.     # different error message.
  727.  
  728.     test select-7.1 {TkSelDeadWindow procedure} {
  729.     setup
  730.     selection handle .f1 { handler TEST }
  731.     set result [selection own]
  732.     destroy .f1
  733.     lappend result [selection own] [catch { selection get } msg] $msg
  734.     } {.f1 {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}
  735. }
  736.  
  737. ##############################################################################
  738.  
  739. # Check reentrancy on losing selection
  740.  
  741. test select-8.1 {TkSelEventProc procedure} {
  742.     setup
  743.     setupbg
  744.     selection own -selection CLIPBOARD -command { destroy .f1 } .f1
  745.     update
  746.     set result [dobg {selection own -selection CLIPBOARD .}]
  747.     cleanupbg
  748.     set result
  749. } {}
  750.  
  751. ##############################################################################
  752.  
  753. test select-9.1 {SelCvtToX and SelCvtFromX procedures} {
  754.     global selValue selInfo
  755.     setup
  756.     setupbg
  757.     set selValue "1024"
  758.     set selInfo ""
  759.     selection handle -selection PRIMARY -format INTEGER -type TEST \
  760.     .f1 {handler TEST}
  761.     update
  762.     set result ""
  763.     lappend result [dobg {selection get TEST}]
  764.     cleanupbg
  765.     lappend result $selInfo
  766. } {0x400 {TEST 0 4000}}
  767. test select-9.2 {SelCvtToX and SelCvtFromX procedures} {
  768.     global selValue selInfo
  769.     setup
  770.     setupbg
  771.     set selValue "1024 0xffff  2048 -2  "
  772.     set selInfo ""
  773.     selection handle -selection PRIMARY -format INTEGER -type TEST \
  774.     .f1 {handler TEST}
  775.     set result ""
  776.     lappend result [dobg {selection get TEST}]
  777.     cleanupbg
  778.     lappend result $selInfo
  779. } {{0x400 0xffff 0x800 0xfffffffe} {TEST 0 4000}}
  780. test select-9.3 {SelCvtToX and SelCvtFromX procedures} {
  781.     global selValue selInfo
  782.     setup
  783.     setupbg
  784.     set selValue "   "
  785.     set selInfo ""
  786.     selection handle -selection PRIMARY -format INTEGER -type TEST \
  787.     .f1 {handler TEST}
  788.     set result ""
  789.     lappend result [dobg {selection get TEST}]
  790.     cleanupbg
  791.     lappend result $selInfo
  792. } {{} {TEST 0 4000}}
  793. test select-9.4 {SelCvtToX and SelCvtFromX procedures} {
  794.     global selValue selInfo
  795.     setup
  796.     setupbg
  797.     set selValue "16 foobar 32"
  798.     set selInfo ""
  799.     selection handle -selection PRIMARY -format INTEGER -type TEST \
  800.     .f1 {handler TEST}
  801.     set result ""
  802.     lappend result [dobg {selection get TEST}]
  803.     cleanupbg
  804.     lappend result $selInfo
  805. } {{0x10 0x0 0x20} {TEST 0 4000}}
  806.  
  807. ##############################################################################
  808.  
  809. # note, we are not testing MULTIPLE style selections
  810.  
  811. # most control paths have been exercised above
  812. test select-10.1 {ConvertSelection procedure, race with selection clear} {
  813.     setup
  814.     setupbg
  815.     set selValue "Just a simple test"
  816.     set selInfo ""
  817.     selection handle .f1 {handler STRING}
  818.     update
  819.     puts $fd {puts "[catch {selection get} msg] $msg"; puts **DONE**; flush stdout}
  820.     flush $fd
  821.     after 200
  822.     selection own .
  823.     set bgData {}
  824.     tkwait variable bgDone
  825.     cleanupbg
  826.     list $bgData $selInfo
  827. } {{1 PRIMARY selection doesn't exist or form "STRING" not defined} {}}
  828. test select-10.2 {ConvertSelection procedure} {
  829.     setup
  830.     setupbg
  831.     set selValue [string range $longValue 0 3999]
  832.     set selInfo ""
  833.     selection handle .f1 {handler STRING}
  834.     set result ""
  835.     lappend result [dobg {selection get}]
  836.     cleanupbg
  837.     lappend result $selInfo
  838. } [list [string range $longValue 0 3999] {STRING 0 4000 STRING 4000 4000 STRING 0 4000 STRING 4000 4000}]
  839. test select-10.3 {ConvertSelection procedure} {
  840.     setup
  841.     setupbg
  842.     selection handle .f1 ERROR errHandler
  843.     set result ""
  844.     lappend result [dobg {selection get ERROR}]
  845.     cleanupbg
  846.     set result
  847. } {{PRIMARY selection doesn't exist or form "ERROR" not defined}}
  848. # testing timers
  849. test select-10.4 {ConvertSelection procedure} {
  850.     setup
  851.     setupbg
  852.     set selValue $longValue
  853.     set selInfo ""
  854.     selection handle .f1 {errIncrHandler STRING}
  855.     set result ""
  856.     set pass 0
  857.     lappend result [dobg {selection get}]
  858.     cleanupbg
  859.     lappend result $selInfo
  860. } {{selection owner didn't respond} {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000 STRING 0 4000 STRING 4000 4000}}
  861. test select-10.5 {ConvertSelection procedure, reentrancy issues} {
  862.     setup
  863.     setupbg
  864.     set selValue "Test value"
  865.     set selInfo ""
  866.     selection handle -type TEST .f1 { handler TEST }
  867.     selection handle -type STRING .f1 { badHandler .f1 STRING }
  868.     set result ""
  869.     lappend result [dobg {selection get}]
  870.     cleanupbg
  871.     lappend result $selInfo
  872. } {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000}}
  873. test select-10.6 {ConvertSelection procedure, reentrancy issues} {
  874.     proc weirdHandler {type offset count} {
  875.     destroy .f1
  876.     handler $type $offset $count
  877.     }
  878.     setup
  879.     setupbg
  880.     set selValue $longValue
  881.     set selInfo ""
  882.     selection handle .f1 {weirdHandler STRING}
  883.     set result ""
  884.     lappend result [dobg {selection get}]
  885.     cleanupbg
  886.     lappend result $selInfo
  887. } {{PRIMARY selection doesn't exist or form "STRING" not defined} {STRING 0 4000}}
  888.  
  889. ##############################################################################
  890.  
  891. # testing reentrancy
  892. test select-11.1 {TkSelPropProc procedure} {
  893.     setup
  894.     setupbg
  895.     set selValue $longValue
  896.     set selInfo ""
  897.     selection handle -type TEST .f1 { handler TEST }
  898.     selection handle -type STRING .f1 { reallyBadHandler .f1 STRING }
  899.     set result ""
  900.     set pass 0
  901.     lappend result [dobg {selection get}]
  902.     cleanupbg
  903.     lappend result $selInfo
  904. } {{selection owner didn't respond} {.f1 STRING 0 4000 .f1 STRING 4000 4000 .f1 STRING 8000 4000 .f1 STRING 12000 4000 .f1 STRING 16000 4000 .f1 STRING 0 4000 .f1 STRING 4000 4000}}
  905.  
  906. ##############################################################################
  907.  
  908. # Note, this assumes we are using CurrentTtime
  909. test select-12.1 {DefaultSelection procedure} {
  910.     setup
  911.     set result [selection get -type TIMESTAMP]
  912.     setupbg
  913.     lappend result [dobg {selection get -type TIMESTAMP}]
  914.     cleanupbg
  915.     set result
  916. } {0x0 0x0}
  917. test select-12.2 {DefaultSelection procedure} {
  918.     setup
  919.     set result [lsort [list [selection get -type TARGETS]]]
  920.     setupbg
  921.     lappend result [dobg {lsort [selection get -type TARGETS]}]
  922.     cleanupbg
  923.     set result
  924. } {{MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
  925. test select-12.3 {DefaultSelection procedure} {
  926.     setup
  927.     selection handle .f1 {handler TEST} TEST
  928.     set result [list [lsort [selection get -type TARGETS]]]
  929.     setupbg
  930.     lappend result [dobg {lsort [selection get -type TARGETS]}]
  931.     cleanupbg
  932.     set result
  933. } {{MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
  934. test select-12.4 {DefaultSelection procedure} {
  935.     setup
  936.     set result ""
  937.     lappend result [selection get -type TK_APPLICATION]
  938.     setupbg
  939.     lappend result [dobg {selection get -type TK_APPLICATION}]
  940.     cleanupbg
  941.     set result
  942. } [list [winfo name .] [winfo name .]]
  943. test select-12.5 {DefaultSelection procedure} {
  944.     setup
  945.     set result [selection get -type TK_WINDOW]
  946.     setupbg
  947.     lappend result [dobg {selection get -type TK_WINDOW}]
  948.     cleanupbg
  949.     set result
  950. } {.f1 .f1}
  951. test select-12.6 {DefaultSelection procedure} {
  952.     global selValue selInfo
  953.     setup
  954.     selection handle .f1 {handler TARGETS.f1} TARGETS
  955.     set selValue "Targets value"
  956.     set selInfo ""
  957.     set result [list [selection get TARGETS] $selInfo]
  958.     selection handle .f1 {} TARGETS
  959.     lappend result [selection get TARGETS]
  960. } {{Targets value} {TARGETS.f1 0 4000} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
  961.  
  962. test select-13.1 {SelectionSize procedure, handler deleted} {
  963.     proc badHandler {path type offset count} {
  964.     global selValue selInfo abortCount
  965.     incr abortCount -1
  966.     if {$abortCount == 0} {
  967.         selection handle -type $type $path {}
  968.     }
  969.     lappend selInfo $path $type $offset $count
  970.     set numBytes [expr {[string length $selValue] - $offset}]
  971.     if {$numBytes <= 0} {
  972.         return ""
  973.     }
  974.     string range $selValue $offset [expr $numBytes+$offset]
  975.     }
  976.     setup
  977.     setupbg
  978.     set selValue $longValue
  979.     set selInfo ""
  980.     selection handle .f1 {badHandler .f1 STRING}
  981.     set result ""
  982.     set abortCount 2
  983.     lappend result [dobg {selection get}]
  984.     cleanupbg
  985.     lappend result $selInfo
  986. } {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000 .f1 STRING 4000 4000}}
  987.  
  988. catch {rename weirdHandler {}}
  989. concat
  990.