sl@0
|
1 |
# Commands covered: none
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for Tcl_AsyncCreate and related
|
sl@0
|
4 |
# library procedures. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id: async.test,v 1.5 2000/04/10 17:18:56 ericm Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
if {[info commands testasync] == {}} {
|
sl@0
|
22 |
puts "This application hasn't been compiled with the \"testasync\""
|
sl@0
|
23 |
puts "command, so I can't test Tcl_AsyncCreate et al."
|
sl@0
|
24 |
::tcltest::cleanupTests
|
sl@0
|
25 |
return
|
sl@0
|
26 |
}
|
sl@0
|
27 |
|
sl@0
|
28 |
proc async1 {result code} {
|
sl@0
|
29 |
global aresult acode
|
sl@0
|
30 |
set aresult $result
|
sl@0
|
31 |
set acode $code
|
sl@0
|
32 |
return "new result"
|
sl@0
|
33 |
}
|
sl@0
|
34 |
proc async2 {result code} {
|
sl@0
|
35 |
global aresult acode
|
sl@0
|
36 |
set aresult $result
|
sl@0
|
37 |
set acode $code
|
sl@0
|
38 |
return -code error "xyzzy"
|
sl@0
|
39 |
}
|
sl@0
|
40 |
proc async3 {result code} {
|
sl@0
|
41 |
global aresult
|
sl@0
|
42 |
set aresult "test pattern"
|
sl@0
|
43 |
return -code $code $result
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
set handler1 [testasync create async1]
|
sl@0
|
47 |
set handler2 [testasync create async2]
|
sl@0
|
48 |
set handler3 [testasync create async3]
|
sl@0
|
49 |
test async-1.1 {basic async handlers} {
|
sl@0
|
50 |
set aresult xxx
|
sl@0
|
51 |
set acode yyy
|
sl@0
|
52 |
list [catch {testasync mark $handler1 "original" 0} msg] $msg \
|
sl@0
|
53 |
$acode $aresult
|
sl@0
|
54 |
} {0 {new result} 0 original}
|
sl@0
|
55 |
test async-1.2 {basic async handlers} {
|
sl@0
|
56 |
set aresult xxx
|
sl@0
|
57 |
set acode yyy
|
sl@0
|
58 |
list [catch {testasync mark $handler1 "original" 1} msg] $msg \
|
sl@0
|
59 |
$acode $aresult
|
sl@0
|
60 |
} {0 {new result} 1 original}
|
sl@0
|
61 |
test async-1.3 {basic async handlers} {
|
sl@0
|
62 |
set aresult xxx
|
sl@0
|
63 |
set acode yyy
|
sl@0
|
64 |
list [catch {testasync mark $handler2 "old" 0} msg] $msg \
|
sl@0
|
65 |
$acode $aresult
|
sl@0
|
66 |
} {1 xyzzy 0 old}
|
sl@0
|
67 |
test async-1.4 {basic async handlers} {
|
sl@0
|
68 |
set aresult xxx
|
sl@0
|
69 |
set acode yyy
|
sl@0
|
70 |
list [catch {testasync mark $handler2 "old" 3} msg] $msg \
|
sl@0
|
71 |
$acode $aresult
|
sl@0
|
72 |
} {1 xyzzy 3 old}
|
sl@0
|
73 |
test async-1.5 {basic async handlers} {
|
sl@0
|
74 |
set aresult xxx
|
sl@0
|
75 |
list [catch {testasync mark $handler3 "foobar" 0} msg] $msg $aresult
|
sl@0
|
76 |
} {0 foobar {test pattern}}
|
sl@0
|
77 |
test async-1.6 {basic async handlers} {
|
sl@0
|
78 |
set aresult xxx
|
sl@0
|
79 |
list [catch {testasync mark $handler3 "foobar" 1} msg] $msg $aresult
|
sl@0
|
80 |
} {1 foobar {test pattern}}
|
sl@0
|
81 |
|
sl@0
|
82 |
proc mult1 {result code} {
|
sl@0
|
83 |
global x
|
sl@0
|
84 |
lappend x mult1
|
sl@0
|
85 |
return -code 7 mult1
|
sl@0
|
86 |
}
|
sl@0
|
87 |
set hm1 [testasync create mult1]
|
sl@0
|
88 |
proc mult2 {result code} {
|
sl@0
|
89 |
global x
|
sl@0
|
90 |
lappend x mult2
|
sl@0
|
91 |
return -code 9 mult2
|
sl@0
|
92 |
}
|
sl@0
|
93 |
set hm2 [testasync create mult2]
|
sl@0
|
94 |
proc mult3 {result code} {
|
sl@0
|
95 |
global x hm1 hm2
|
sl@0
|
96 |
lappend x [catch {testasync mark $hm2 serial2 0}]
|
sl@0
|
97 |
lappend x [catch {testasync mark $hm1 serial1 0}]
|
sl@0
|
98 |
lappend x mult3
|
sl@0
|
99 |
return -code 11 mult3
|
sl@0
|
100 |
}
|
sl@0
|
101 |
set hm3 [testasync create mult3]
|
sl@0
|
102 |
|
sl@0
|
103 |
test async-2.1 {multiple handlers} {
|
sl@0
|
104 |
set x {}
|
sl@0
|
105 |
list [catch {testasync mark $hm3 "foobar" 5} msg] $msg $x
|
sl@0
|
106 |
} {9 mult2 {0 0 mult3 mult1 mult2}}
|
sl@0
|
107 |
|
sl@0
|
108 |
proc del1 {result code} {
|
sl@0
|
109 |
global x hm1 hm2 hm3 hm4
|
sl@0
|
110 |
lappend x [catch {testasync mark $hm3 serial2 0}]
|
sl@0
|
111 |
lappend x [catch {testasync mark $hm1 serial1 0}]
|
sl@0
|
112 |
lappend x [catch {testasync mark $hm4 serial1 0}]
|
sl@0
|
113 |
testasync delete $hm1
|
sl@0
|
114 |
testasync delete $hm2
|
sl@0
|
115 |
testasync delete $hm3
|
sl@0
|
116 |
lappend x del1
|
sl@0
|
117 |
return -code 13 del1
|
sl@0
|
118 |
}
|
sl@0
|
119 |
proc del2 {result code} {
|
sl@0
|
120 |
global x
|
sl@0
|
121 |
lappend x del2
|
sl@0
|
122 |
return -code 3 del2
|
sl@0
|
123 |
}
|
sl@0
|
124 |
testasync delete $handler1
|
sl@0
|
125 |
testasync delete $hm2
|
sl@0
|
126 |
testasync delete $hm3
|
sl@0
|
127 |
set hm2 [testasync create del1]
|
sl@0
|
128 |
set hm3 [testasync create mult2]
|
sl@0
|
129 |
set hm4 [testasync create del2]
|
sl@0
|
130 |
|
sl@0
|
131 |
test async-3.1 {deleting handlers} {
|
sl@0
|
132 |
set x {}
|
sl@0
|
133 |
list [catch {testasync mark $hm2 "foobar" 5} msg] $msg $x
|
sl@0
|
134 |
} {3 del2 {0 0 0 del1 del2}}
|
sl@0
|
135 |
|
sl@0
|
136 |
# cleanup
|
sl@0
|
137 |
testasync delete
|
sl@0
|
138 |
::tcltest::cleanupTests
|
sl@0
|
139 |
return
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
|
sl@0
|
144 |
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
|
sl@0
|
151 |
|