📄 select.test
字号:
# This file is a Tcl script to test out Tk's selection management code,# especially the "selection" command. It is organized in the standard# fashion for Tcl tests.## Copyright (c) 1994 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## SCCS: @(#) select.test 1.17 96/12/09 17:25:48## Note: Multiple display selection handling will only be tested if the# environment variable TK_ALT_DISPLAY is set to an alternate display.#if {[string compare test [info procs test]] == 1} { source defs}eval destroy [winfo child .]global longValue selValue selInfoset selValue {}set selInfo {}proc handler {type offset count} { global selValue selInfo lappend selInfo $type $offset $count set numBytes [expr {[string length $selValue] - $offset}] if {$numBytes <= 0} { return "" } string range $selValue $offset [expr $numBytes+$offset]}proc errIncrHandler {type offset count} { global selValue selInfo pass if {$offset == 4000} { if {$pass == 0} { # Just sizing the selection; don't do anything here. set pass 1 } else { # Fetching the selection; wait long enough to cause a timeout. after 6000 } } lappend selInfo $type $offset $count set numBytes [expr {[string length $selValue] - $offset}] if {$numBytes <= 0} { return "" } string range $selValue $offset [expr $numBytes+$offset]}proc errHandler args { error "selection handler aborted"}proc badHandler {path type offset count} { global selValue selInfo selection handle -type $type $path {} lappend selInfo $path $type $offset $count set numBytes [expr {[string length $selValue] - $offset}] if {$numBytes <= 0} { return "" } string range $selValue $offset [expr $numBytes+$offset]}proc reallyBadHandler {path type offset count} { global selValue selInfo pass if {$offset == 4000} { if {$pass == 0} { set pass 1 } else { selection handle -type $type $path {} } } lappend selInfo $path $type $offset $count set numBytes [expr {[string length $selValue] - $offset}] if {$numBytes <= 0} { return "" } string range $selValue $offset [expr $numBytes+$offset]}# Eliminate any existing selection on the screen. This is needed in case# there is a selection in some other application, in order to prevent races# from causing false errors in the tests below.selection clear .after 1500# common setup codeproc setup {{path .f1} {display {}}} { catch {destroy $path} if {$display == {}} { frame $path } else { toplevel $path -screen $display wm geom $path +0+0 } selection own $path}# set up a very large buffer to test INCR retrievalsset longValue ""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} { 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 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}# Now we start the main body of the test codetest select-1.1 {Tk_CreateSelHandler procedure} { setup lsort [selection get TARGETS]} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}test select-1.2 {Tk_CreateSelHandler procedure} { setup selection handle .f1 {handler TEST} TEST lsort [selection get TARGETS]} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}test select-1.3 {Tk_CreateSelHandler procedure} { global selValue selInfo setup selection handle .f1 {handler TEST} TEST set selValue "Test value" set selInfo "" list [selection get TEST] $selInfo} {{Test value} {TEST 0 4000}}test select-1.4 {Tk_CreateSelHandler procedure} { setup selection handle .f1 {handler TEST} TEST selection handle .f1 {handler STRING} lsort [selection get TARGETS]} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}test select-1.5 {Tk_CreateSelHandler procedure} { global selValue selInfo setup selection handle .f1 {handler TEST} TEST selection handle .f1 {handler STRING} set selValue "" set selInfo "" list [selection get] $selInfo} {{} {STRING 0 4000}}test select-1.6 {Tk_CreateSelHandler procedure} { global selValue selInfo setup selection handle .f1 {handler TEST} TEST selection handle .f1 {handler STRING} set selValue "" set selInfo "" selection get selection get -type TEST selection handle .f1 {handler TEST2} TEST selection get -type TEST list [set selInfo] [lsort [selection get TARGETS]]} {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}test select-1.7 {Tk_CreateSelHandler procedure} { setup selection own -selection CLIPBOARD .f1 selection handle -selection CLIPBOARD .f1 {handler TEST} TEST selection handle -selection PRIMARY .f1 {handler TEST2} STRING list [lsort [selection get -selection PRIMARY TARGETS]] \ [lsort [selection get -selection CLIPBOARD TARGETS]] } {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}test select-1.8 {Tk_CreateSelHandler procedure} { setup selection handle -format INTEGER -type TEST .f1 {handler TEST} lsort [selection get TARGETS]} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}##############################################################################test select-2.1 {Tk_DeleteSelHandler procedure} { setup selection handle .f1 {handler STRING} selection handle -type TEST .f1 {handler TEST} selection handle -type USER .f1 {handler USER} set result [list [lsort [selection get TARGETS]]] selection handle -type TEST .f1 {} lappend result [lsort [selection get TARGETS]]} {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER}}test select-2.2 {Tk_DeleteSelHandler procedure} { setup selection handle .f1 {handler STRING} selection handle -type TEST .f1 {handler TEST} selection handle -type USER .f1 {handler USER} set result [list [lsort [selection get TARGETS]]] selection handle -type USER .f1 {} lappend result [lsort [selection get TARGETS]]} {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}test select-2.3 {Tk_DeleteSelHandler procedure} { setup selection own -selection CLIPBOARD .f1 selection handle -selection PRIMARY .f1 {handler STRING} selection handle -selection CLIPBOARD .f1 {handler STRING} selection handle -selection CLIPBOARD .f1 {} list [lsort [selection get TARGETS]] \ [lsort [selection get -selection CLIPBOARD TARGETS]]} {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}test select-2.4 {Tk_DeleteSelHandler procedure} { setup selection handle .f1 {handler STRING} list [selection handle .f1 {}] [selection handle .f1 {}]} {{} {}} ##############################################################################test select-3.1 {Tk_OwnSelection procedure} { setup selection own} {.f1}test select-3.2 {Tk_OwnSelection procedure} { setup .f1 set result [selection own] setup .f2 lappend result [selection own]} {.f1 .f2}test select-3.3 {Tk_OwnSelection procedure} { setup .f1 setup .f2 selection own -selection CLIPBOARD .f1 list [selection own] [selection own -selection CLIPBOARD]} {.f2 .f1}test select-3.4 {Tk_OwnSelection procedure} { global lostSel setup set lostSel {owned} selection own -command { set lostSel {lost} } .f1 selection clear .f1 set lostSel} {lost}test select-3.5 {Tk_OwnSelection procedure} { global lostSel setup .f1 setup .f2 set lostSel {owned} selection own -command { set lostSel {lost1} } .f1 selection own -command { set lostSel {lost2} } .f2 list $lostSel [selection own]} {lost1 .f2}test select-3.6 {Tk_OwnSelection procedure} { global lostSel setup set lostSel {owned} selection own -command { set lostSel {lost1} } .f1 selection own -command { set lostSel {lost2} } .f1 set result $lostSel selection clear .f1 lappend result $lostSel} {owned lost2}test select-3.7 {Tk_OwnSelection procedure} {unixOnly} { global lostSel setup setupbg set lostSel {owned} selection own -command { set lostSel {lost1} } .f1 update set result {} lappend result [dobg { selection own . }] lappend result [dobg {selection own}] update cleanupbg lappend result $lostSel} {{} . lost1}# check reentrancy on selection replacementtest select-3.8 {Tk_OwnSelection procedure} { setup selection own -selection CLIPBOARD -command { destroy .f1 } .f1 selection own -selection CLIPBOARD .} {}test select-3.9 {Tk_OwnSelection procedure} { setup .f2 setup .f1 selection own -selection CLIPBOARD -command { destroy .f2 } .f1 selection own -selection CLIPBOARD .f2} {}# multiple display testsif {[info exists env(TK_ALT_DISPLAY)]} { test select-3.10 {Tk_OwnSelection procedure} { setup .f1 setup .f2 $env(TK_ALT_DISPLAY) list [selection own -displayof .f1] [selection own -displayof .f2] } {.f1 .f2} test select-3.11 {Tk_OwnSelection procedure} { setup .f1 setup .f2 $env(TK_ALT_DISPLAY) setupbg update set result "" lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"] lappend result [selection own -displayof .f1] \ [selection own -displayof .f2] cleanupbg set result } {{} .f1 {}}}##############################################################################test select-4.1 {Tk_ClearSelection procedure} { setup set result [selection own] selection clear .f1 lappend result [selection own]} {.f1 {}}test select-4.2 {Tk_ClearSelection procedure} { setup selection own -selection CLIPBOARD .f1 selection clear .f1 selection own -selection CLIPBOARD} {.f1}test select-4.3 {Tk_ClearSelection procedure} { setup list [selection clear .f1] [selection clear .f1]} {{} {}}test select-4.4 {Tk_ClearSelection procedure} {unixOnly} { global lostSel setup setupbg set lostSel {owned} selection own -command { set lostSel {lost1} } .f1 update set result {} lappend result [dobg {selection clear; update}]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -