1 # Commands covered: none
3 # This file contains a collection of tests for Tcl_LinkVar and related
4 # library procedures. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
21 if {[info commands testlink] == {}} {
22 puts "This application hasn't been compiled with the \"testlink\""
23 puts "command, so I can't test Tcl_LinkVar et al."
24 ::tcltest::cleanupTests
28 foreach i {int real bool string} {
31 test link-1.1 {reading C variables from Tcl} {
33 testlink set 43 1.23 4 -
34 testlink create 1 1 1 1
35 list $int $real $bool $string
37 test link-1.2 {reading C variables from Tcl} {
39 testlink create 1 1 1 1
40 testlink set -3 2 0 "A long string with spaces"
41 list $int $real $bool $string $int $real $bool $string
42 } {-3 2.0 0 {A long string with spaces} -3 2.0 0 {A long string with spaces}}
44 test link-2.1 {writing C variables from Tcl} {
46 testlink set 43 1.21 4 -
47 testlink create 1 1 1 1
52 concat [testlink get] $int $real $bool $string
53 } {465 -10.5 1 abcdef 00721 -10.5 true abcdef}
54 test link-2.2 {writing bad values into variables} {
56 testlink set 43 1.23 4 -
57 testlink create 1 1 1 1
58 list [catch {set int 09a} msg] $msg $int
59 } {1 {can't set "int": variable must have integer value} 43}
60 test link-2.3 {writing bad values into variables} {
62 testlink set 43 1.23 4 -
63 testlink create 1 1 1 1
64 list [catch {set real 1.x3} msg] $msg $real
65 } {1 {can't set "real": variable must have real value} 1.23}
66 test link-2.4 {writing bad values into variables} {
68 testlink set 43 1.23 4 -
69 testlink create 1 1 1 1
70 list [catch {set bool gorp} msg] $msg $bool
71 } {1 {can't set "bool": variable must have boolean value} 1}
73 test link-3.1 {read-only variables} {
75 testlink set 43 1.23 4 -
76 testlink create 0 1 1 0
77 list [catch {set int 4} msg] $msg $int \
78 [catch {set real 10.6} msg] $msg $real \
79 [catch {set bool no} msg] $msg $bool \
80 [catch {set string "new value"} msg] $msg $string
81 } {1 {can't set "int": linked variable is read-only} 43 0 10.6 10.6 0 no no 1 {can't set "string": linked variable is read-only} NULL}
82 test link-3.2 {read-only variables} {
84 testlink set 43 1.23 4 -
85 testlink create 1 0 0 1
86 list [catch {set int 4} msg] $msg $int \
87 [catch {set real 10.6} msg] $msg $real \
88 [catch {set bool no} msg] $msg $bool \
89 [catch {set string "new value"} msg] $msg $string
90 } {0 4 4 1 {can't set "real": linked variable is read-only} 1.23 1 {can't set "bool": linked variable is read-only} 1 0 {new value} {new value}}
92 test link-4.1 {unsetting linked variables} {
94 testlink set -6 -2.5 0 stringValue
95 testlink create 1 1 1 1
96 unset int real bool string
97 list [catch {set int} msg] $msg [catch {set real} msg] $msg \
98 [catch {set bool} msg] $msg [catch {set string} msg] $msg
99 } {0 -6 0 -2.5 0 0 0 stringValue}
100 test link-4.2 {unsetting linked variables} {
102 testlink set -6 -2.1 0 stringValue
103 testlink create 1 1 1 1
104 unset int real bool string
110 } {102 16.0 1 newValue}
112 test link-5.1 {unlinking variables} {
114 testlink set -6 -2.25 0 stringValue
121 } {-6 -2.25 0 stringValue}
122 test link-5.2 {unlinking variables} {
124 testlink set -6 -2.25 0 stringValue
125 testlink create 1 1 1 1
127 testlink set 25 14.7 7 -
128 list $int $real $bool $string
129 } {-6 -2.25 0 stringValue}
131 test link-6.1 {errors in setting up link} {
135 list [catch {testlink create 1 1 1 1} msg] $msg
136 } {1 {can't set "int": variable is array}}
139 test link-7.1 {access to linked variables via upvar} {
145 testlink create 1 0 0 0
146 testlink set 14 {} {} {}
148 list [catch {set int} msg] $msg
150 test link-7.2 {access to linked variables via upvar} {
156 testlink create 1 0 0 0
157 testlink set 0 {} {} {}
159 testlink set 23 {} {} {}
163 test link-7.3 {access to linked variables via upvar} {
169 testlink create 0 0 0 0
170 testlink set 11 {} {} {}
171 list [catch x msg] $msg $int
172 } {1 {can't set "y": linked variable is read-only} 11}
173 test link-7.4 {access to linked variables via upvar} {
179 testlink create 1 1 1 1
180 testlink set -4 {} {} {}
181 list [catch x msg] $msg $int
182 } {1 {can't set "y": variable must have integer value} -4}
183 test link-7.5 {access to linked variables via upvar} {
189 testlink create 1 1 1 1
190 testlink set -4 16.75 {} {}
191 list [catch x msg] $msg $real
192 } {1 {can't set "y": variable must have real value} 16.75}
193 test link-7.6 {access to linked variables via upvar} {
199 testlink create 1 1 1 1
200 testlink set -4 16.3 1 {}
201 list [catch x msg] $msg $bool
202 } {1 {can't set "y": variable must have boolean value} 1}
204 test link-8.1 {Tcl_UpdateLinkedVar procedure} {
206 global x int real bool string
207 lappend x $args $int $real $bool $string
210 testlink create 1 1 1 1
211 testlink set 14 -2.0 0 xyzzy
213 testlink update 32 4.0 3 abcd
214 trace vdelete int w x
216 } {{int {} w} 32 -2.0 0 xyzzy}
217 test link-8.2 {Tcl_UpdateLinkedVar procedure} {
219 global x int real bool string
220 lappend x $args $int $real $bool $string
223 testlink create 1 1 1 1
224 testlink set 14 -2.0 0 xyzzy
227 testlink update 32 4.0 6 abcd
228 trace vdelete int w x
231 test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {
232 testlink create 0 0 0 0
233 list [catch {testlink update 47 {} {} {}} msg] $msg $int
238 foreach i {int real bool string} {
243 ::tcltest::cleanupTests