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