sl@0
|
1 |
# Commands covered: none
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for Tcl_LinkVar and related
|
sl@0
|
4 |
# library procedures. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1994 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id: link.test,v 1.7 2002/06/22 04:19:47 dgp Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest 2
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
::tcltest::testConstraint testlink \
|
sl@0
|
22 |
[expr {[info commands testlink] != {}}]
|
sl@0
|
23 |
|
sl@0
|
24 |
foreach i {int real bool string} {
|
sl@0
|
25 |
catch {unset $i}
|
sl@0
|
26 |
}
|
sl@0
|
27 |
test link-1.1 {reading C variables from Tcl} {testlink} {
|
sl@0
|
28 |
testlink delete
|
sl@0
|
29 |
testlink set 43 1.23 4 - 12341234
|
sl@0
|
30 |
testlink create 1 1 1 1 1
|
sl@0
|
31 |
list $int $real $bool $string $wide
|
sl@0
|
32 |
} {43 1.23 1 NULL 12341234}
|
sl@0
|
33 |
test link-1.2 {reading C variables from Tcl} {testlink} {
|
sl@0
|
34 |
testlink delete
|
sl@0
|
35 |
testlink create 1 1 1 1 1
|
sl@0
|
36 |
testlink set -3 2 0 "A long string with spaces" 43214321
|
sl@0
|
37 |
list $int $real $bool $string $wide $int $real $bool $string $wide
|
sl@0
|
38 |
} {-3 2.0 0 {A long string with spaces} 43214321 -3 2.0 0 {A long string with spaces} 43214321}
|
sl@0
|
39 |
|
sl@0
|
40 |
test link-2.1 {writing C variables from Tcl} {testlink} {
|
sl@0
|
41 |
testlink delete
|
sl@0
|
42 |
testlink set 43 1.21 4 - 56785678
|
sl@0
|
43 |
testlink create 1 1 1 1 1
|
sl@0
|
44 |
set int "00721"
|
sl@0
|
45 |
set real -10.5
|
sl@0
|
46 |
set bool true
|
sl@0
|
47 |
set string abcdef
|
sl@0
|
48 |
set wide 135135
|
sl@0
|
49 |
concat [testlink get] $int $real $bool $string $wide
|
sl@0
|
50 |
} {465 -10.5 1 abcdef 135135 00721 -10.5 true abcdef 135135}
|
sl@0
|
51 |
test link-2.2 {writing bad values into variables} {testlink} {
|
sl@0
|
52 |
testlink delete
|
sl@0
|
53 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
54 |
testlink create 1 1 1 1 1
|
sl@0
|
55 |
list [catch {set int 09a} msg] $msg $int
|
sl@0
|
56 |
} {1 {can't set "int": variable must have integer value} 43}
|
sl@0
|
57 |
test link-2.3 {writing bad values into variables} {testlink} {
|
sl@0
|
58 |
testlink delete
|
sl@0
|
59 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
60 |
testlink create 1 1 1 1 1
|
sl@0
|
61 |
list [catch {set real 1.x3} msg] $msg $real
|
sl@0
|
62 |
} {1 {can't set "real": variable must have real value} 1.23}
|
sl@0
|
63 |
test link-2.4 {writing bad values into variables} {testlink} {
|
sl@0
|
64 |
testlink delete
|
sl@0
|
65 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
66 |
testlink create 1 1 1 1 1
|
sl@0
|
67 |
list [catch {set bool gorp} msg] $msg $bool
|
sl@0
|
68 |
} {1 {can't set "bool": variable must have boolean value} 1}
|
sl@0
|
69 |
test link-2.5 {writing bad values into variables} {testlink} {
|
sl@0
|
70 |
testlink delete
|
sl@0
|
71 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
72 |
testlink create 1 1 1 1 1
|
sl@0
|
73 |
list [catch {set wide gorp} msg] $msg $bool
|
sl@0
|
74 |
} {1 {can't set "wide": variable must have integer value} 1}
|
sl@0
|
75 |
|
sl@0
|
76 |
test link-3.1 {read-only variables} {testlink} {
|
sl@0
|
77 |
testlink delete
|
sl@0
|
78 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
79 |
testlink create 0 1 1 0 0
|
sl@0
|
80 |
list [catch {set int 4} msg] $msg $int \
|
sl@0
|
81 |
[catch {set real 10.6} msg] $msg $real \
|
sl@0
|
82 |
[catch {set bool no} msg] $msg $bool \
|
sl@0
|
83 |
[catch {set string "new value"} msg] $msg $string \
|
sl@0
|
84 |
[catch {set wide 12341234} msg] $msg $wide
|
sl@0
|
85 |
} {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 1 {can't set "wide": linked variable is read-only} 56785678}
|
sl@0
|
86 |
test link-3.2 {read-only variables} {testlink} {
|
sl@0
|
87 |
testlink delete
|
sl@0
|
88 |
testlink set 43 1.23 4 - 56785678
|
sl@0
|
89 |
testlink create 1 0 0 1 1
|
sl@0
|
90 |
list [catch {set int 4} msg] $msg $int \
|
sl@0
|
91 |
[catch {set real 10.6} msg] $msg $real \
|
sl@0
|
92 |
[catch {set bool no} msg] $msg $bool \
|
sl@0
|
93 |
[catch {set string "new value"} msg] $msg $string\
|
sl@0
|
94 |
[catch {set wide 12341234} msg] $msg $wide
|
sl@0
|
95 |
} {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} 0 12341234 12341234}
|
sl@0
|
96 |
|
sl@0
|
97 |
test link-4.1 {unsetting linked variables} {testlink} {
|
sl@0
|
98 |
testlink delete
|
sl@0
|
99 |
testlink set -6 -2.5 0 stringValue 13579
|
sl@0
|
100 |
testlink create 1 1 1 1 1
|
sl@0
|
101 |
unset int real bool string wide
|
sl@0
|
102 |
list [catch {set int} msg] $msg [catch {set real} msg] $msg \
|
sl@0
|
103 |
[catch {set bool} msg] $msg [catch {set string} msg] $msg \
|
sl@0
|
104 |
[catch {set wide} msg] $msg
|
sl@0
|
105 |
} {0 -6 0 -2.5 0 0 0 stringValue 0 13579}
|
sl@0
|
106 |
test link-4.2 {unsetting linked variables} {testlink} {
|
sl@0
|
107 |
testlink delete
|
sl@0
|
108 |
testlink set -6 -2.1 0 stringValue 97531
|
sl@0
|
109 |
testlink create 1 1 1 1 1
|
sl@0
|
110 |
unset int real bool string wide
|
sl@0
|
111 |
set int 102
|
sl@0
|
112 |
set real 16
|
sl@0
|
113 |
set bool true
|
sl@0
|
114 |
set string newValue
|
sl@0
|
115 |
set wide 333555
|
sl@0
|
116 |
testlink get
|
sl@0
|
117 |
} {102 16.0 1 newValue 333555}
|
sl@0
|
118 |
|
sl@0
|
119 |
test link-5.1 {unlinking variables} {testlink} {
|
sl@0
|
120 |
testlink delete
|
sl@0
|
121 |
testlink set -6 -2.25 0 stringValue 13579
|
sl@0
|
122 |
testlink delete
|
sl@0
|
123 |
set int xx1
|
sl@0
|
124 |
set real qrst
|
sl@0
|
125 |
set bool bogus
|
sl@0
|
126 |
set string 12345
|
sl@0
|
127 |
set wide 875421
|
sl@0
|
128 |
testlink get
|
sl@0
|
129 |
} {-6 -2.25 0 stringValue 13579}
|
sl@0
|
130 |
test link-5.2 {unlinking variables} {testlink} {
|
sl@0
|
131 |
testlink delete
|
sl@0
|
132 |
testlink set -6 -2.25 0 stringValue 97531
|
sl@0
|
133 |
testlink create 1 1 1 1 1
|
sl@0
|
134 |
testlink delete
|
sl@0
|
135 |
testlink set 25 14.7 7 - 999999
|
sl@0
|
136 |
list $int $real $bool $string $wide
|
sl@0
|
137 |
} {-6 -2.25 0 stringValue 97531}
|
sl@0
|
138 |
|
sl@0
|
139 |
test link-6.1 {errors in setting up link} {testlink} {
|
sl@0
|
140 |
testlink delete
|
sl@0
|
141 |
catch {unset int}
|
sl@0
|
142 |
set int(44) 1
|
sl@0
|
143 |
list [catch {testlink create 1 1 1 1 1} msg] $msg
|
sl@0
|
144 |
} {1 {can't set "int": variable is array}}
|
sl@0
|
145 |
catch {unset int}
|
sl@0
|
146 |
|
sl@0
|
147 |
test link-7.1 {access to linked variables via upvar} {testlink} {
|
sl@0
|
148 |
proc x {} {
|
sl@0
|
149 |
upvar int y
|
sl@0
|
150 |
unset y
|
sl@0
|
151 |
}
|
sl@0
|
152 |
testlink delete
|
sl@0
|
153 |
testlink create 1 0 0 0 0
|
sl@0
|
154 |
testlink set 14 {} {} {} {}
|
sl@0
|
155 |
x
|
sl@0
|
156 |
list [catch {set int} msg] $msg
|
sl@0
|
157 |
} {0 14}
|
sl@0
|
158 |
test link-7.2 {access to linked variables via upvar} {testlink} {
|
sl@0
|
159 |
proc x {} {
|
sl@0
|
160 |
upvar int y
|
sl@0
|
161 |
return [set y]
|
sl@0
|
162 |
}
|
sl@0
|
163 |
testlink delete
|
sl@0
|
164 |
testlink create 1 0 0 0 0
|
sl@0
|
165 |
testlink set 0 {} {} {} {}
|
sl@0
|
166 |
set int
|
sl@0
|
167 |
testlink set 23 {} {} {} {}
|
sl@0
|
168 |
x
|
sl@0
|
169 |
list [x] $int
|
sl@0
|
170 |
} {23 23}
|
sl@0
|
171 |
test link-7.3 {access to linked variables via upvar} {testlink} {
|
sl@0
|
172 |
proc x {} {
|
sl@0
|
173 |
upvar int y
|
sl@0
|
174 |
set y 44
|
sl@0
|
175 |
}
|
sl@0
|
176 |
testlink delete
|
sl@0
|
177 |
testlink create 0 0 0 0 0
|
sl@0
|
178 |
testlink set 11 {} {} {} {}
|
sl@0
|
179 |
list [catch x msg] $msg $int
|
sl@0
|
180 |
} {1 {can't set "y": linked variable is read-only} 11}
|
sl@0
|
181 |
test link-7.4 {access to linked variables via upvar} {testlink} {
|
sl@0
|
182 |
proc x {} {
|
sl@0
|
183 |
upvar int y
|
sl@0
|
184 |
set y abc
|
sl@0
|
185 |
}
|
sl@0
|
186 |
testlink delete
|
sl@0
|
187 |
testlink create 1 1 1 1 1
|
sl@0
|
188 |
testlink set -4 {} {} {} {}
|
sl@0
|
189 |
list [catch x msg] $msg $int
|
sl@0
|
190 |
} {1 {can't set "y": variable must have integer value} -4}
|
sl@0
|
191 |
test link-7.5 {access to linked variables via upvar} {testlink} {
|
sl@0
|
192 |
proc x {} {
|
sl@0
|
193 |
upvar real y
|
sl@0
|
194 |
set y abc
|
sl@0
|
195 |
}
|
sl@0
|
196 |
testlink delete
|
sl@0
|
197 |
testlink create 1 1 1 1 1
|
sl@0
|
198 |
testlink set -4 16.75 {} {} {}
|
sl@0
|
199 |
list [catch x msg] $msg $real
|
sl@0
|
200 |
} {1 {can't set "y": variable must have real value} 16.75}
|
sl@0
|
201 |
test link-7.6 {access to linked variables via upvar} {testlink} {
|
sl@0
|
202 |
proc x {} {
|
sl@0
|
203 |
upvar bool y
|
sl@0
|
204 |
set y abc
|
sl@0
|
205 |
}
|
sl@0
|
206 |
testlink delete
|
sl@0
|
207 |
testlink create 1 1 1 1 1
|
sl@0
|
208 |
testlink set -4 16.3 1 {} {}
|
sl@0
|
209 |
list [catch x msg] $msg $bool
|
sl@0
|
210 |
} {1 {can't set "y": variable must have boolean value} 1}
|
sl@0
|
211 |
test link-7.7 {access to linked variables via upvar} {testlink} {
|
sl@0
|
212 |
proc x {} {
|
sl@0
|
213 |
upvar wide y
|
sl@0
|
214 |
set y abc
|
sl@0
|
215 |
}
|
sl@0
|
216 |
testlink delete
|
sl@0
|
217 |
testlink create 1 1 1 1 1
|
sl@0
|
218 |
testlink set -4 16.3 1 {} 778899
|
sl@0
|
219 |
list [catch x msg] $msg $wide
|
sl@0
|
220 |
} {1 {can't set "y": variable must have integer value} 778899}
|
sl@0
|
221 |
|
sl@0
|
222 |
test link-8.1 {Tcl_UpdateLinkedVar procedure} {testlink} {
|
sl@0
|
223 |
proc x args {
|
sl@0
|
224 |
global x int real bool string wide
|
sl@0
|
225 |
lappend x $args $int $real $bool $string $wide
|
sl@0
|
226 |
}
|
sl@0
|
227 |
set x {}
|
sl@0
|
228 |
testlink create 1 1 1 1 1
|
sl@0
|
229 |
testlink set 14 -2.0 0 xyzzy 995511
|
sl@0
|
230 |
trace var int w x
|
sl@0
|
231 |
testlink update 32 4.0 3 abcd 113355
|
sl@0
|
232 |
trace vdelete int w x
|
sl@0
|
233 |
set x
|
sl@0
|
234 |
} {{int {} w} 32 -2.0 0 xyzzy 995511}
|
sl@0
|
235 |
test link-8.2 {Tcl_UpdateLinkedVar procedure} {testlink} {
|
sl@0
|
236 |
proc x args {
|
sl@0
|
237 |
global x int real bool string wide
|
sl@0
|
238 |
lappend x $args $int $real $bool $string $wide
|
sl@0
|
239 |
}
|
sl@0
|
240 |
set x {}
|
sl@0
|
241 |
testlink create 1 1 1 1 1
|
sl@0
|
242 |
testlink set 14 -2.0 0 xyzzy 995511
|
sl@0
|
243 |
testlink delete
|
sl@0
|
244 |
trace var int w x
|
sl@0
|
245 |
testlink update 32 4.0 6 abcd 113355
|
sl@0
|
246 |
trace vdelete int w x
|
sl@0
|
247 |
set x
|
sl@0
|
248 |
} {}
|
sl@0
|
249 |
test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} {
|
sl@0
|
250 |
testlink create 0 0 0 0 0
|
sl@0
|
251 |
list [catch {testlink update 47 {} {} {} {}} msg] $msg $int
|
sl@0
|
252 |
} {0 {} 47}
|
sl@0
|
253 |
|
sl@0
|
254 |
catch {testlink set 0 0 0 - 0}
|
sl@0
|
255 |
catch {testlink delete}
|
sl@0
|
256 |
foreach i {int real bool string wide} {
|
sl@0
|
257 |
catch {unset $i}
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
# cleanup
|
sl@0
|
261 |
::tcltest::cleanupTests
|
sl@0
|
262 |
return
|