1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# Commands covered: none
#
# This file contains a collection of tests for Tcl_LinkVar and related
# library procedures. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1993 The Regents of the University of California.
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
# $Header: /user6/ouster/tcl/tests/RCS/link.test,v 1.5 93/07/28 15:05:32 ouster Exp $ (Berkeley)
if {[info commands testlink] == {}} {
puts "This application hasn't been compiled with the \"testlink\""
puts "command, so I can't test Tcl_LinkVar et al."
return
}
if {[string compare test [info procs test]] == 1} then {source defs}
foreach i {int real bool string} {
catch {unset $i}
}
test link-1.1 {reading C variables from Tcl} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 1 1 1
list $int $real $bool $string
} {43 1.23 1 NULL}
test link-1.2 {reading C variables from Tcl} {
testlink delete
testlink create 1 1 1 1
testlink set -3 2 0 "A long string with spaces"
list $int $real $bool $string $int $real $bool $string
} {-3 2.0 0 {A long string with spaces} -3 2.0 0 {A long string with spaces}}
test link-2.1 {writing C variables from Tcl} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 1 1 1
set int "00721"
set real -8e13
set bool true
set string abcdef
concat [testlink get] $int $real $bool $string
} {465 -8e+13 1 abcdef 00721 -8e13 true abcdef}
test link-2.2 {writing bad values into variables} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 1 1 1
list [catch {set int 09a} msg] $msg $int
} {1 {can't set "int": variable must have integer value} 43}
test link-2.3 {writing bad values into variables} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 1 1 1
list [catch {set real 1.x3} msg] $msg $real
} {1 {can't set "real": variable must have real value} 1.23}
test link-2.4 {writing bad values into variables} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 1 1 1
list [catch {set bool gorp} msg] $msg $bool
} {1 {can't set "bool": variable must have boolean value} 1}
test link-3.1 {read-only variables} {
testlink delete
testlink set 43 1.23 4 -
testlink create 0 1 1 0
list [catch {set int 4} msg] $msg $int \
[catch {set real 10.6} msg] $msg $real \
[catch {set bool no} msg] $msg $bool \
[catch {set string "new value"} msg] $msg $string
} {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}
test link-3.2 {read-only variables} {
testlink delete
testlink set 43 1.23 4 -
testlink create 1 0 0 1
list [catch {set int 4} msg] $msg $int \
[catch {set real 10.6} msg] $msg $real \
[catch {set bool no} msg] $msg $bool \
[catch {set string "new value"} msg] $msg $string
} {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}}
test link-4.1 {unsetting linked variables} {
testlink delete
testlink set -6 -2.1 0 stringValue
testlink create 1 1 1 1
unset int real bool string
list [catch {set int} msg] $msg [catch {set real} msg] $msg \
[catch {set bool} msg] $msg [catch {set string} msg] $msg
} {0 -6 0 -2.1 0 0 0 stringValue}
test link-4.2 {unsetting linked variables} {
testlink delete
testlink set -6 -2.1 0 stringValue
testlink create 1 1 1 1
unset int real bool string
set int 102
set real 16
set bool true
set string newValue
testlink get
} {102 16.0 1 newValue}
test link-5.1 {unlinking variables} {
testlink delete
testlink set -6 -2.1 0 stringValue
testlink delete
set int xx1
set real qrst
set bool bogus
set string 12345
testlink get
} {-6 -2.1 0 stringValue}
test link-5.2 {unlinking variables} {
testlink delete
testlink set -6 -2.1 0 stringValue
testlink create 1 1 1 1
testlink delete
testlink set 25 14.7 7 -
list $int $real $bool $string
} {-6 -2.1 0 stringValue}
test link-6.1 {errors in setting up link} {
testlink delete
catch {unset int}
set int(44) 1
list [catch {testlink create 1 1 1 1} msg] $msg
} {1 {can't set "int": variable is array}}
testlink delete
unset int real bool string
|