Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/link.test @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

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