summaryrefslogtreecommitdiffstats
path: root/tests/winSend.test
blob: a4fab431e2b6fba3f0fd335fd4ea3c1376b17dbf (plain)
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# This file is a Tcl script to test out the "send" command and the
# other procedures in the file tkSend.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# SCCS: @(#) winSend.test 1.3 98/02/11 18:05:48

if {$tcl_platform(platform) != "windows"} {
    return
}

if {[info procs test] != "test"} {
    source defs
}

foreach i [winfo children .] {
    destroy $i
}
wm geometry . {}
raise .

set currentInterps [winfo interps]

if {[catch {exec tktest &}] == 1} {
    puts "Could not run winSend.test because another instance of tktest could not be loaded."
    return;
}

# Compute a script that will load Tk into a child interpreter.

foreach pkg [info loaded] {
    if {[lindex $pkg 1] == "Tk"} {
	set loadTk "load $pkg"
	break
    }
}

# Procedure to create a new application with a given name and class.

proc newApp {name {safe {}}} {
    global loadTk
    if {[string compare $safe "-safe"] == 0} {
	interp create -safe $name
    } else {
	interp create $name
    }
    $name eval [list set argv [list -name $name]]
    catch {eval $loadTk $name}
}

# Wait until the child application has launched.

while {[llength [winfo interps]] == [llength $currentInterps]} {
}

# Now find an interp to send to
set newInterps [winfo interps]
foreach interp $newInterps {
    if {[lsearch -exact $currentInterps $interp] < 0} {
	break
    }
}

# Now we have found our interpreter we are going to send to. Make sure that
# it works first.
if {[catch {send $interp {console hide; update}}] == 1} {
    puts "Could not send to child interpreter $interp"
    return
}

# setting up dde server is done when the first interp is created and
# cannot be tested very easily.
test winSend-1.1 {Tk_SetAppName - changing name of interp} {
    newApp testApp
    list [testApp eval tk appname testApp2] [interp delete testApp]
} {testApp2 {}}
test winSend-1.2 {Tk_SetAppName - changing name - not front of linked list} {
    newApp testApp
    newApp testApp2
    list [testApp eval tk appname testApp3] [interp delete testApp] [interp delete testApp2]
} {testApp3 {} {}}
test winSend-1.3 {Tk_SetAppName - unique name - no conflicts} {
    newApp testApp
    list [testApp eval tk appname testApp] [interp delete testApp]
} {testApp {}}
test winSend-1.4 {Tk_SetAppName - unique name - one conflict} {
    newApp testApp
    newApp foobar
    list [foobar eval tk appname testApp] [interp delete foobar] [interp delete testApp]
} {{testApp #2} {} {}}
test winSend-1.5 {Tk_SetAppName - unique name - one conflict} {
    newApp testApp
    newApp foobar
    newApp blaz
    foobar eval tk appname testApp
    list [blaz eval tk appname testApp] [interp delete foobar] [interp delete testApp] [interp delete blaz]
} {{testApp #3} {} {} {}}
test winSend-1.6 {Tk_SetAppName - safe interps} {
    newApp testApp -safe
    list [catch {testApp eval send testApp {set foo a}} msg] $msg [interp delete testApp]
} {1 {invalid command name "send"} {}}

test winSend-2.1 {Tk_SendObjCmd - # of args} {
    list [catch {send tktest} msg] $msg
} {1 {wrong # args: should be "send ?options? interpName arg ?arg ...?"}}
test winSend-2.1 {Tk_SendObjCmd: arguments} {
    list [catch {send -bogus tktest} msg] $msg
} {1 {bad option "-bogus": must be -async, -displayof, or --}}
test winSend-2.1 {Tk_SendObjCmd: arguments} {
    list [catch {send -async bogus foo} msg] $msg
} {1 {no registered server named "bogus"}}
test winSend-2.1 {Tk_SendObjCmd: arguments} {
    list [catch {send -displayof . bogus foo} msg] $msg
} {1 {no registered server named "bogus"}}
test winSend-2.1 {Tk_SendObjCmd: arguments} {
    list [catch {send -- -bogus foo} msg] $msg
} {1 {no registered server named "-bogus"}}
test winSend-2.2 {Tk_SendObjCmd - sending to ourselves} {
    list [send [tk appname] {set foo a}]
} {a}
test winSend-2.3 {Tk_SendObjCmd - sending to ourselves in a different interpreter} {
    newApp testApp
    list [catch {send testApp {set foo b}} msg] $msg [interp delete testApp]
} {0 b {}}
test winSend-2.4 {Tk_SendObjCmd - sending to ourselves in a different interp with errors} {
    newApp testApp
    list [catch {send testApp {expr 2 / 0}} msg] $msg $errorCode $errorInfo [interp delete testApp]
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr 2 / 0\"\n    invoked from within\n\"send testApp {expr 2 / 0}\"} {}"
test winSend-2.5 {Tk_SendObjCmd - sending to another app async} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send -async $interp {set foo a}} msg] $msg
} {0 {}}
test winSend-2.6 {Tk_SendObjCmd - sending to another app sync - no error} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send $interp {set foo a}} msg] $msg
} {0 a}
test winSend-2.7 {Tk_SendObjCmd - sending to another app - error} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send $interp {expr 2 / 0}} msg] $msg $errorCode $errorInfo
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr 2 / 0\"\n    invoked from within\n\"send \$interp {expr 2 / 0}\"}"

test winSend-3.1 {TkGetInterpNames} {
    set origLength [llength $currentInterps]
    set newLength [llength [winfo interps]]
    expr {($newLength - 2) == $origLength}
} {1}

test winSend-4.1 {DeleteProc - changing name of app} {
    newApp a
    list [a eval tk appname foo] [interp delete a]
} {foo {}}
test winSend-4.2 {DeleteProc - normal} {
    newApp a
    list [interp delete a]
} {{}}

test winSend-5.1 {ExecuteRemoteObject - no error} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [send $interp {send [tk appname] {expr 2 / 1}}]
} {2}
test winSend-5.2 {ExecuteRemoteObject - error} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send $interp {send [tk appname] {expr 2 / 0}}} msg] $msg
} {1 {divide by zero}}

test winSend-6.1 {SendDDEServer - XTYP_CONNECT} {
    set foo "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde request Tk [tk appname] foo"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 {Hello, World}}
test winSend-6.2 {SendDDEServer - XTYP_CONNECT_CONFIRM} {
    set foo "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde request Tk [tk appname] foo"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 {Hello, World}}
test winSend-6.3 {SendDDEServer - XTYP_DISCONNECT} {
    set foo "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde request Tk [tk appname] foo"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 {Hello, World}}
test winSend-6.4 {SendDDEServer - XTYP_REQUEST variable} {
    set foo "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde request Tk [tk appname] foo"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 {Hello, World}}
test winSend-6.5 {SendDDEServer - XTYP_REQUEST array} {
    catch {unset foo}
    set foo(test) "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde request Tk [tk appname] foo(test)"
    list [catch "send \{$interp\} \{$command\}" msg] $msg [catch {unset foo}]
} {0 {Hello, World} 0}
test winSend-6.6 {SendDDEServer - XTYP_REQUEST return results} {
    set foo 3
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "send [tk appname] {expr $foo + 1}"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 4}
test winSend-6.7 {SendDDEServer - XTYP_EXECUTE} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "send [tk appname] {expr 4 / 2}"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 2}
test winSend-6.8 {SendDDEServer - XTYP_WILDCONNECT} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde services Tk {}"
    list [catch "send \{$interp\} \{$command\}"]
} {0}

test winSend-7.1 {DDEExitProc} {
    newApp testApp
    list [interp delete testApp]
} {{}}

test winSend-8.1 {SendDdeConnect} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [send $interp {set tk foo}]
} {foo}

test winSend-9.1 {SetDDEError} {
    list [catch {dde execute Tk foo {set foo hello}} msg] $msg
} {1 {dde command failed}}

test winSend-10.1 {Tk_DDEObjCmd - wrong num args} {
    list [catch {dde} msg] $msg
} {1 {wrong # args: should be "dde ?-async? serviceName topicName value"}}
test winSend-10.2 {Tk_DDEObjCmd - unknown subcommand} {
    list [catch {dde foo} msg] $msg
} {1 {bad command "foo": must be execute, request, or services}}
test winSend-10.3 {Tk_DDEObjCmd - execute - wrong num args} {
    list [catch {dde execute} msg] $msg
} {1 {wrong # args: should be "dde execute ?-async? serviceName topicName value"}}
test winSend-10.4 {Tk_DDEObjCmd - execute - wrong num args} {
    list [catch {dde execute 3 4 5 6 7} msg] $msg
} {1 {wrong # args: should be "dde execute ?-async? serviceName topicName value"}}
test winSend-10.5 {Tk_DDEObjCmd - execute async - wrong num args} {
    list [catch {dde execute -async} msg] $msg
} {1 {wrong # args: should be "dde execute ?-async? serviceName topicName value"}}
test winSend-10.6 {Tk_DDEObjCmd - request - wrong num args} {
    list [catch {dde request} msg] $msg
} {1 {wrong # args: should be "dde request serviceName topicName value"}}
test winSend-10.7 {Tk_DDEObjCmd - services wrong num args} {
    list [catch {dde services} msg] $msg
} {1 {wrong # args: should be "dde services serviceName topicName"}}
test winSend-10.8 {Tk_DDEObjCmd - null service name} {
    list [catch {dde services {} {tktest #2}}]
} {0}
test winSend-10.9 {Tk_DDEObjCmd - null topic name} {
    list [catch {dde services {Tk} {}}]
} {0}
test winSend-10.10 {Tk_DDEObjCmd - execute - nothing to execute} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {dde execute Tk $interp {}} msg] $msg
} {1 {cannot execute null data}}
test winSend-10.11 {Tk_DDEObjCmd - execute - no such conversation} {
    list [catch {dde execute Tk foo {set foo hello}} msg] $msg
} {1 {dde command failed}}
test winSend-10.12 {Tk_DDEObjCmd - execute - async} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {dde execute -async Tk $interp {set foo hello}} msg] $msg
} {0 {}}
test winSend-10.13 {Tk_DDEObjCmd - execute} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {dde execute Tk $interp {set foo goodbye}} msg] $msg
} {0 {}}
test winSend-10.14 {Tk_DDEObjCmd - request - nothing to request} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {dde request Tk $interp {}} msg] $msg
} {1 {cannot request value of null data}}
test winSend-10.15 {Tk_DDEObjCmd - request - invalid interp} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {dde request Tk foo foo} msg] $msg
} {1 {dde command failed}}
test winSend-10.16 {Tk_DDEObjCmd - invalid variable} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    send $interp {unset foo}
    list [catch {dde request Tk $interp foo} msg] $msg
} {1 {remote server cannot handle this command}}
test winSend-10.17 {Tk_DDEObjCmd - valid variable} {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    send $interp {set foo winSend-10.17}
    list [catch {dde request Tk $interp foo} msg] $msg
} {0 winSend-10.17}
test winSend-10.18 {Tk_DDEObjCmd - services} {
    set currentService [list Tk [tk appname]]
    list [catch {dde services Tk {}} msg] [expr [lsearch $msg $currentService] >= 0]
} {0 1}

# Get rid of the other app and all of its interps

set newInterps [winfo interps]
while {[llength $newInterps] != [llength $currentInterps]} {
    foreach interp $newInterps {
	if {[lsearch -exact $currentInterps $interp] < 0} {
	    catch {send $interp exit}
	    set newInterps [winfo interps]
	    break
	}
    }
}