1# This file is a Tcl script to test out Tk's Windows specific
2# clipboard code.  It is organized in the standard fashion for Tcl
3# tests.
4#
5# This file contains a collection of tests for one or more of the Tcl
6# built-in commands.  Sourcing this file into Tcl runs the tests and
7# generates output for errors.  No output means no errors were found.
8#
9# Copyright (c) 1997 by Sun Microsystems, Inc.
10# Copyright (c) 1998-2000 by Scriptics Corporation.
11# All rights reserved.
12#
13# RCS: @(#) $Id: winClipboard.test,v 1.11 2002/07/13 20:28:36 dgp Exp $
14
15package require tcltest 2.1
16namespace import -force tcltest::configure
17namespace import -force tcltest::testsDirectory
18configure -testdir [file join [pwd] [file dirname [info script]]]
19configure -loadfile [file join [testsDirectory] constraints.tcl]
20tcltest::loadTestedCommands
21
22namespace import -force tcltest::bytestring
23
24# Note that these tests may fail if another application is grabbing the
25# clipboard (e.g. an X server)
26
27testConstraint testclipboard [llength [info commands testclipboard]]
28
29test winClipboard-1.1 {TkSelGetSelection} {pcOnly} {
30    clipboard clear
31    catch {selection get -selection CLIPBOARD} msg
32    set msg
33} {CLIPBOARD selection doesn't exist or form "STRING" not defined}
34test winClipboard-1.2 {TkSelGetSelection} {pcOnly testclipboard} {
35    clipboard clear
36    clipboard append {}
37    catch {selection get -selection CLIPBOARD} r1
38    catch {testclipboard} r2
39    list $r1 $r2
40} {{} {}}
41test winClipboard-1.3 {TkSelGetSelection & TkWinClipboardRender} {pcOnly testclipboard} {
42    clipboard clear
43    clipboard append abcd
44    update
45    catch {selection get -selection CLIPBOARD} r1
46    catch {testclipboard} r2
47    list $r1 $r2
48} {abcd abcd}
49test winClipboard-1.4 {TkSelGetSelection & TkWinClipboardRender} {pcOnly testclipboard} {
50    clipboard clear
51    clipboard append "line 1\nline 2"
52    catch {selection get -selection CLIPBOARD} r1
53    catch {testclipboard} r2
54    list $r1 $r2
55} [list "line 1\nline 2" "line 1\r\nline 2"]
56test winClipboard-1.5 {TkSelGetSelection & TkWinClipboardRender} {pcOnly testclipboard} {
57    clipboard clear
58    clipboard append "line 1\u00c7\nline 2"
59    catch {selection get -selection CLIPBOARD} r1
60    catch {testclipboard} r2
61    list $r1 $r2
62} [list "line 1\u00c7\nline 2" [bytestring "line 1\u00c7\r\nline 2"]]
63
64test winClipboard-2.1 {TkSelUpdateClipboard reentrancy problem} {pcOnly testclipboard} {
65    clipboard clear
66    clipboard append -type OUR_ACTION "action data"
67    clipboard append "string data"
68    update
69    catch {selection get -selection CLIPBOARD -type OUR_ACTION} r1
70    catch {testclipboard} r2
71    list $r1 $r2
72} [list "action data" "string data"]
73test winClipboard-2.2 {TkSelUpdateClipboard reentrancy problem} {pcOnly testclipboard} {
74    clipboard clear
75    clipboard append -type OUR_ACTION "new data"
76    clipboard append "more data in string"
77    update
78    catch {testclipboard} r1
79    catch {selection get -selection CLIPBOARD -type OUR_ACTION} r2
80    list $r1 $r2
81} [list "more data in string" "new data"]
82
83# cleanup
84::tcltest::cleanupTests
85return
86