os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/link.test
Update contrib.
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.
14 # RCS: @(#) $Id: link.test,v 1.7 2002/06/22 04:19:47 dgp Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest 2
18 namespace import -force ::tcltest::*
21 ::tcltest::testConstraint testlink \
22 [expr {[info commands testlink] != {}}]
24 foreach i {int real bool string} {
27 test link-1.1 {reading C variables from Tcl} {testlink} {
29 testlink set 43 1.23 4 - 12341234
30 testlink create 1 1 1 1 1
31 list $int $real $bool $string $wide
32 } {43 1.23 1 NULL 12341234}
33 test link-1.2 {reading C variables from Tcl} {testlink} {
35 testlink create 1 1 1 1 1
36 testlink set -3 2 0 "A long string with spaces" 43214321
37 list $int $real $bool $string $wide $int $real $bool $string $wide
38 } {-3 2.0 0 {A long string with spaces} 43214321 -3 2.0 0 {A long string with spaces} 43214321}
40 test link-2.1 {writing C variables from Tcl} {testlink} {
42 testlink set 43 1.21 4 - 56785678
43 testlink create 1 1 1 1 1
49 concat [testlink get] $int $real $bool $string $wide
50 } {465 -10.5 1 abcdef 135135 00721 -10.5 true abcdef 135135}
51 test link-2.2 {writing bad values into variables} {testlink} {
53 testlink set 43 1.23 4 - 56785678
54 testlink create 1 1 1 1 1
55 list [catch {set int 09a} msg] $msg $int
56 } {1 {can't set "int": variable must have integer value} 43}
57 test link-2.3 {writing bad values into variables} {testlink} {
59 testlink set 43 1.23 4 - 56785678
60 testlink create 1 1 1 1 1
61 list [catch {set real 1.x3} msg] $msg $real
62 } {1 {can't set "real": variable must have real value} 1.23}
63 test link-2.4 {writing bad values into variables} {testlink} {
65 testlink set 43 1.23 4 - 56785678
66 testlink create 1 1 1 1 1
67 list [catch {set bool gorp} msg] $msg $bool
68 } {1 {can't set "bool": variable must have boolean value} 1}
69 test link-2.5 {writing bad values into variables} {testlink} {
71 testlink set 43 1.23 4 - 56785678
72 testlink create 1 1 1 1 1
73 list [catch {set wide gorp} msg] $msg $bool
74 } {1 {can't set "wide": variable must have integer value} 1}
76 test link-3.1 {read-only variables} {testlink} {
78 testlink set 43 1.23 4 - 56785678
79 testlink create 0 1 1 0 0
80 list [catch {set int 4} msg] $msg $int \
81 [catch {set real 10.6} msg] $msg $real \
82 [catch {set bool no} msg] $msg $bool \
83 [catch {set string "new value"} msg] $msg $string \
84 [catch {set wide 12341234} msg] $msg $wide
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}
86 test link-3.2 {read-only variables} {testlink} {
88 testlink set 43 1.23 4 - 56785678
89 testlink create 1 0 0 1 1
90 list [catch {set int 4} msg] $msg $int \
91 [catch {set real 10.6} msg] $msg $real \
92 [catch {set bool no} msg] $msg $bool \
93 [catch {set string "new value"} msg] $msg $string\
94 [catch {set wide 12341234} msg] $msg $wide
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}
97 test link-4.1 {unsetting linked variables} {testlink} {
99 testlink set -6 -2.5 0 stringValue 13579
100 testlink create 1 1 1 1 1
101 unset int real bool string wide
102 list [catch {set int} msg] $msg [catch {set real} msg] $msg \
103 [catch {set bool} msg] $msg [catch {set string} msg] $msg \
104 [catch {set wide} msg] $msg
105 } {0 -6 0 -2.5 0 0 0 stringValue 0 13579}
106 test link-4.2 {unsetting linked variables} {testlink} {
108 testlink set -6 -2.1 0 stringValue 97531
109 testlink create 1 1 1 1 1
110 unset int real bool string wide
117 } {102 16.0 1 newValue 333555}
119 test link-5.1 {unlinking variables} {testlink} {
121 testlink set -6 -2.25 0 stringValue 13579
129 } {-6 -2.25 0 stringValue 13579}
130 test link-5.2 {unlinking variables} {testlink} {
132 testlink set -6 -2.25 0 stringValue 97531
133 testlink create 1 1 1 1 1
135 testlink set 25 14.7 7 - 999999
136 list $int $real $bool $string $wide
137 } {-6 -2.25 0 stringValue 97531}
139 test link-6.1 {errors in setting up link} {testlink} {
143 list [catch {testlink create 1 1 1 1 1} msg] $msg
144 } {1 {can't set "int": variable is array}}
147 test link-7.1 {access to linked variables via upvar} {testlink} {
153 testlink create 1 0 0 0 0
154 testlink set 14 {} {} {} {}
156 list [catch {set int} msg] $msg
158 test link-7.2 {access to linked variables via upvar} {testlink} {
164 testlink create 1 0 0 0 0
165 testlink set 0 {} {} {} {}
167 testlink set 23 {} {} {} {}
171 test link-7.3 {access to linked variables via upvar} {testlink} {
177 testlink create 0 0 0 0 0
178 testlink set 11 {} {} {} {}
179 list [catch x msg] $msg $int
180 } {1 {can't set "y": linked variable is read-only} 11}
181 test link-7.4 {access to linked variables via upvar} {testlink} {
187 testlink create 1 1 1 1 1
188 testlink set -4 {} {} {} {}
189 list [catch x msg] $msg $int
190 } {1 {can't set "y": variable must have integer value} -4}
191 test link-7.5 {access to linked variables via upvar} {testlink} {
197 testlink create 1 1 1 1 1
198 testlink set -4 16.75 {} {} {}
199 list [catch x msg] $msg $real
200 } {1 {can't set "y": variable must have real value} 16.75}
201 test link-7.6 {access to linked variables via upvar} {testlink} {
207 testlink create 1 1 1 1 1
208 testlink set -4 16.3 1 {} {}
209 list [catch x msg] $msg $bool
210 } {1 {can't set "y": variable must have boolean value} 1}
211 test link-7.7 {access to linked variables via upvar} {testlink} {
217 testlink create 1 1 1 1 1
218 testlink set -4 16.3 1 {} 778899
219 list [catch x msg] $msg $wide
220 } {1 {can't set "y": variable must have integer value} 778899}
222 test link-8.1 {Tcl_UpdateLinkedVar procedure} {testlink} {
224 global x int real bool string wide
225 lappend x $args $int $real $bool $string $wide
228 testlink create 1 1 1 1 1
229 testlink set 14 -2.0 0 xyzzy 995511
231 testlink update 32 4.0 3 abcd 113355
232 trace vdelete int w x
234 } {{int {} w} 32 -2.0 0 xyzzy 995511}
235 test link-8.2 {Tcl_UpdateLinkedVar procedure} {testlink} {
237 global x int real bool string wide
238 lappend x $args $int $real $bool $string $wide
241 testlink create 1 1 1 1 1
242 testlink set 14 -2.0 0 xyzzy 995511
245 testlink update 32 4.0 6 abcd 113355
246 trace vdelete int w x
249 test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} {
250 testlink create 0 0 0 0 0
251 list [catch {testlink update 47 {} {} {} {}} msg] $msg $int
254 catch {testlink set 0 0 0 - 0}
255 catch {testlink delete}
256 foreach i {int real bool string wide} {
261 ::tcltest::cleanupTests