summaryrefslogtreecommitdiffstats
path: root/tests/winDde.test
blob: a1a8dab2c5a31aa07919325d495b95ee5cc039d5 (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
# This file tests the tclWinDde.c file.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: winDde.test,v 1.15 2003/05/16 17:29:49 patthoyts Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import -force ::tcltest::*
}

if {$tcl_platform(platform) == "windows"} {
    if [catch {
	set lib [lindex [glob -directory [file join [pwd] [file dirname \
		[info nameofexecutable]]] tcldde*.dll] 0]
	load $lib dde
    }] {
	puts "WARNING: Unable to find the dde package. Skipping dde tests."
	::tcltest::cleanupTests
	return
    }
}

# -------------------------------------------------------------------------
# Setup a script for a test server
#

set scriptName [makeFile {} script1.tcl]

proc createChildProcess { ddeServerName } {
    file delete -force $::scriptName

    set f [open $::scriptName w+]
    puts $f {
        # DDE child server -
        #
	if {[lsearch [namespace children] ::tcltest] == -1} {
	    package require tcltest
	    namespace import -force ::tcltest::*
	}
        # Load the dde package to test.
	if [catch {
	    set lib [lindex [glob -directory \
		    [file join [pwd] [file dirname [info nameofexecutable]]] \
		    tcldde*.dll] 0]
	    load $lib dde
	}] {
	    puts "Unable to find the dde package. Skipping dde tests."
	    ::tcltest::cleanupTests
	    return
	}
        
        # If an error occurs during the tests, this process may end up not
        # being closed down. To deal with this we create a 30s timeout.
        proc DoTimeout {} {
            global done
            puts stderr "winDde.test child process $ddeServerName timed out."
            set done 1
        }
        set timeout [after 30000 DoTimeout]
    }
    # set the dde server name to the supplied argument.
    puts $f [list dde servername $ddeServerName]
    puts $f {
        # run the server and handle final cleanup.
	puts ready
        flush stdout
	vwait done
	update
	exit
    }
    close $f
    
    # run the child server script.
    set f [open |[list [interpreter] $::scriptName] r]
    fconfigure $f -buffering line
    gets $f line
    return $f
}

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

test winDde-1.1 {Settings the server's topic name} {pcOnly} {
    list [dde servername foobar] [dde servername] [dde servername self]
}  {foobar foobar self}

test winDde-2.1 {Checking for other services} {pcOnly} {
    expr [llength [dde services {} {}]] >= 0
} 1

test winDde-2.2 {Checking for existence, with service and topic specified} \
	{pcOnly} {
    llength [dde services TclEval self]
} 1

test winDde-2.3 {Checking for existence, with only the service specified} \
	{pcOnly} {
    expr [llength [dde services TclEval {}]] >= 1
} 1

test winDde-2.4 {Checking for existence, with only the topic specified} \
	{pcOnly} {
    expr [llength [dde services {} self]] >= 1
} 1

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

test winDde-3.1 {DDE execute locally} {pcOnly} {
    set a ""
    dde execute TclEval self {set a "foo"}
    set a
} foo

test winDde-3.2 {DDE execute -async locally} {pcOnly} {
    set a ""
    dde execute -async TclEval self {set a "foo"}
    update
    set a
} foo

test winDde-3.3 {DDE request locally} {pcOnly} {
    set a ""
    dde execute TclEval self {set a "foo"}
    dde request TclEval self a
} foo

test winDde-3.4 {DDE eval locally} {pcOnly} {
    set a ""
    dde eval self set a "foo"
} foo

test winDde-3.5 {DDE request locally} {pcOnly} {
    set a ""
    dde execute TclEval self {set a "foo"}
    dde request -binary TclEval self a
} "foo\x00"

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

test winDde-4.1 {DDE execute remotely} {stdio pcOnly} {
    set a ""
    set name child-4.1
    set child [createChildProcess $name]
    dde execute TclEval $name {set a "foo"}
    dde execute TclEval $name {set done 1}
    update
    set a
} ""

test winDde-4.2 {DDE execute async remotely} {stdio pcOnly} {
    set a ""
    set name child-4.2
    set child [createChildProcess $name]
    dde execute -async TclEval $name {set a "foo"}
    dde execute TclEval $name {set done 1}
    update
    set a
} ""

test winDde-4.3 {DDE request remotely} {stdio pcOnly} {
    set a ""
    set name chile-4.3
    set child [createChildProcess $name]
    dde execute TclEval $name {set a "foo"}
    set a [dde request TclEval $name a]
    dde execute TclEval $name {set done 1}
    update
    set a
} foo

test winDde-4.4 {DDE eval remotely} {stdio pcOnly} {
    set a ""
    set name child-4.4
    set child [createChildProcess $name]
    set a [dde eval $name set a "foo"]
    dde execute TclEval $name {set done 1}
    update
    set a
} foo

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

test winDde-5.1 {check for bad arguments} {pcOnly} {
    catch {dde execute "" "" "" ""} result
    set result
} {wrong # args: should be "dde execute ?-async? serviceName topicName value"}

test winDde-5.2 {check for bad arguments} {pcOnly} {
    catch {dde execute "" "" ""} result
    set result
} {cannot execute null data}

test winDde-5.3 {check for bad arguments} {pcOnly} {
    catch {dde execute -foo "" "" ""} result
    set result
} {wrong # args: should be "dde execute ?-async? serviceName topicName value"}

test winDde-5.4 {DDE eval bad arguments} {pcOnly} {
    list [catch {dde eval "" "foo"} msg] $msg
} {1 {invalid service name ""}}

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

test winDde-6.1 {DDE servername bad arguments} {pcOnly} {
    list [catch {dde servername -z -z -z} msg] $msg
} {1 {wrong # args: should be "dde servername ?-exact? ?--? ?serverName?"}}
    
test winDde-6.2 {DDE servername set name} {pcOnly} {
    list [catch {dde servername -- winDde-6.2} msg] $msg
} {0 winDde-6.2}

test winDde-6.3 {DDE servername set exact name} {pcOnly} {
    list [catch {dde servername -exact winDde-6.3} msg] $msg
} {0 winDde-6.3}

test winDde-6.4 {DDE servername set exact name} {pcOnly} {
    list [catch {dde servername -exact -- winDde-6.4} msg] $msg
} {0 winDde-6.4}

test winDde-6.5 {DDE remote servername collision} {stdio pcOnly} {
    set a ""
    set name child-6.5
    set child [createChildProcess $name]
    list [catch {
        set a [dde servername -- $name]
        dde execute TclEval $name {set done 1}
        update
        set a
    } r] $r
} {0 {child-6.5 #2}}

test winDde-6.6 {DDE remote servername collision force} {stdio pcOnly} {
    set a ""
    set name child-6.6
    set child [createChildProcess $name]
    list [catch {
        set a [dde servername -exact -- $name]
        dde execute TclEval $name {set done 1}
        update
        set a
    } r] $r
} {0 child-6.6}

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

test winDde-7.1 {DDE in slave interpreter} {pcOnly} {
    global slave
    set name slave-7.1
    list [catch {
        set slave [interp create $name]
        $slave eval [list load $lib dde]
        $slave eval [list dde servername $name]
    } msg] $msg
} {0 slave-7.1}

test winDde-7.2 {DDE present in slave interp} {pcOnly} {
    global slave
    list [catch {
        dde services TclEval $slave
    } msg] $msg
} [list 0 [list [list TclEval $slave]]]

test winDde-7.3 {DDE slave servername collision force} {pcOnly} {
    global slave
    list [catch {dde servername -exact -- $slave} msg] $msg
} [list 0 $slave]

test winDde-7.4 {DDE slave servername collision} {pcOnly} {
    global slave
    list [catch {dde servername -- $slave} msg] $msg
} [list 0 [list $slave "#2"]]

test winDde-7.5 {DDE slave cleanup} {pcOnly} {
    global slave
    list [catch {
        interp delete $slave
        set s [dde services TclEval {}]
        set m [list [list TclEval $slave]]
        if {[lsearch -exact $s $m] != -1} {
            set s
        }
    } msg] $msg
} {0 {}}

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

#cleanup
catch {interp delete $slave};           # ensure we clean up the slave.
file delete -force $::scriptName
::tcltest::cleanupTests
return

# Local Variables:
# mode: tcl
# End: