File: tie_rarray.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (331 lines) | stat: -rw-r--r-- 10,519 bytes parent folder | download | duplicates (3)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# Tests for the tie module.                              -*- tcl -*- 
#
# Copyright (c) 2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: tie_rarray.test,v 1.7 2006/10/09 21:41:42 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 1.0

support {
    use      snit/snit.tcl snit
    useLocal tie.tcl       tie
}
testing {
    useLocal tie_rarray.tcl tie::std::rarray
}

# -------------------------------------------------------------------------

proc mysend {args} {
    # A fake send command, also local receiver, in a way.
    # args = options?... id cmd arg...
    # Options used is -async. Id is irrelevant here.

    set async [expr {[lindex $args 0] eq "-async"}]
    if {$async} {set args [lrange $args 1 end]}
    set args [lrange $args 1 end]
    set cmd [linsert $args 0 uplevel 1]
    #puts stderr ||<<[join $cmd {>> <<}]>>||
    set code [catch $cmd msg]
    if {$async} return
    return -code $code $msg
}

# -------------------------------------------------------------------------
# Creation of remote array data sources
# Errors: Undefined variable, scalar, local variable

test tie-rarray-1.0 {remote array creation, wrong#args} {
    catch {tie::std::rarray} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::rarray::Snit_constructor type selfns win self rvar cmdpfx id"}

test tie-rarray-1.1 {remote array creation, wrong#args} {
    catch {tie::std::rarray x} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::rarray::Snit_constructor type selfns win self rvar cmdpfx id"}

test tie-rarray-1.2 {remote array creation, wrong#args} {
    catch {tie::std::rarray x y} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::rarray::Snit_constructor type selfns win self rvar cmdpfx id"}

test tie-rarray-1.3 {remote array creation, wrong#args} {
    catch {tie::std::rarray x y z} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::rarray::Snit_constructor type selfns win self rvar cmdpfx id"}

test tie-rarray-1.4 {remote array creation, wrong#args} {
    catch {tie::std::rarray x y z a b} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::rarray::Snit_constructor type selfns win self rvar cmdpfx id"}


test tie-rarray-1.5 {remote array creation, fixed name, undefined array acceptable} {
    catch {tie::std::rarray x y mysend _DUMMY_ID_} msg
    set msg
} {Error in constructor: Undefined source array variable "y"}

test tie-rarray-1.6 {remote array creation, bad send command} {
    unset -nocomplain av ; set av {}
    catch {tie::std::rarray x av foosend _DUMMY_ID_} msg
    set msg
} {Error in constructor: invalid command name "foosend"}

test tie-rarray-1.7 {remote array creation, fixed name, scalar variable} {
    unset -nocomplain av ; set av SCALAR
    catch {tie::std::rarray x av mysend _DUMMY_ID_} msg
    set msg
} {Error in constructor: Undefined source array variable "av"}


test tie-rarray-1.8 {remote array creation, fixed name, array} {
    unset -nocomplain av ; array set av {}
    set msg [tie::std::rarray x av mysend _DUMMY_ID_]
    x destroy
    set msg
} {::x}

test tie-rarray-1.9 {remote array creation, %AUTO%} {
    unset -nocomplain av ; array set av {}
    set msg [tie::std::rarray %AUTO% av mysend _DUMMY_ID_]
    $msg destroy
    set msg
} {::rarray11}

# -------------------------------------------------------------------------
## Methods

test tie-rarray-2.0 {remote array get, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    catch {x get a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodget type selfns win self"}

test tie-rarray-2.1 {remote array get} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    set res [dictsort [x get]]
    x destroy
    set res
} {a 1 b 2}


test tie-rarray-3.0 {remote array set, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x set} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodset type selfns win self dict"}

test tie-rarray-3.1 {remote array set, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x set a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodset type selfns win self dict"}

test tie-rarray-3.2 {remote array set} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x set {c 3 b 2 a 1}]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {a 1 b 2 c 3}}


test tie-rarray-4.0 {remote array names, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    catch {x names a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodnames type selfns win self"}

test tie-rarray-4.1 {remote array names} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    set res [lsort [x names]]
    x destroy
    set res
} {a b}


test tie-rarray-5.0 {remote array size, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    catch {x size a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodsize type selfns win self"}

test tie-rarray-5.1 {remote array size} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::rarray x av mysend _DUMMY_ID_
    set res [x size]
    x destroy
    set res
} 2


test tie-rarray-6.0 {remote array unset, wrong#args} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x unset a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodunset type selfns win self ?pattern?"}

test tie-rarray-6.1 {remote array unset, default pattern} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x unset]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {}}

test tie-rarray-6.2 {remote array unset, by pattern} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x unset f*]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {a 3}}


test tie-rarray-7.0 {remote array getv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x getv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodgetv type selfns win self index"}

test tie-rarray-7.1 {remote array getv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x getv a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodgetv type selfns win self index"}

test tie-rarray-7.2 {remote array getv} {
    unset -nocomplain av ; array set av {a 3 b 4}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x getv a]
    x destroy
    set res
} 3


test tie-rarray-8.0 {remote array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x setv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodsetv type selfns win self index value"}

test tie-rarray-8.1 {remote array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x setv a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodsetv type selfns win self index value"}

test tie-rarray-8.2 {remote array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x setv a b c} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodsetv type selfns win self index value"}

test tie-rarray-8.3 {remote array setv} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x setv fox snarf]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {fox snarf}}

test tie-rarray-8.4 {remote array setv, value containing space} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x setv fox {snarf it}]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {fox {snarf it}}}

test tie-rarray-8.5 {remote array setv, varname containing space} {
    unset -nocomplain {a v} ; array set {a v} {}
    tie::std::rarray x {a v} mysend _DUMMY_ID_
    set     res {}
    lappend res [x setv fox {snarf it}]
    lappend res [dictsort [array get {a v}]]
    x destroy
    set res
} {{} {fox {snarf it}}}

test tie-rarray-9.0 {remote array unsetv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x unsetv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodunsetv type selfns win self index"}

test tie-rarray-9.1 {remote array unsetv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    catch {x unsetv a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::rarray::Snit_methodunsetv type selfns win self index"}

test tie-rarray-9.2 {remote array unsetv} {
    unset -nocomplain av ; array set av {a 3 b 4}
    tie::std::rarray x av mysend _DUMMY_ID_
    set     res {}
    lappend res [x unsetv a]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {b 4}}

testsuiteCleanup
return