sl@0
|
1 |
# This file contains tests for tclUnixNotfy.c.
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. 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) 1997 by Sun Microsystems, Inc.
|
sl@0
|
8 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
11 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# RCS: @(#) $Id: unixNotfy.test,v 1.11.2.4 2005/05/14 20:52:31 das Exp $
|
sl@0
|
14 |
|
sl@0
|
15 |
# The tests should not be run if you have a notifier which is unable to
|
sl@0
|
16 |
# detect infinite vwaits, as the tests below will hang. The presence of
|
sl@0
|
17 |
# the "testthread" command indicates that this is the case.
|
sl@0
|
18 |
|
sl@0
|
19 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
20 |
package require tcltest 2
|
sl@0
|
21 |
namespace import -force ::tcltest::*
|
sl@0
|
22 |
}
|
sl@0
|
23 |
|
sl@0
|
24 |
if {[info exists tk_version]} {
|
sl@0
|
25 |
puts "When run in a Tk shell, these tests run hang. Skipping tests ..."
|
sl@0
|
26 |
::tcltest::cleanupTests
|
sl@0
|
27 |
return
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
set ::tcltest::testConstraints(testthread) \
|
sl@0
|
31 |
[expr {[info commands testthread] != {}}]
|
sl@0
|
32 |
# Darwin always uses a threaded notifier
|
sl@0
|
33 |
testConstraint unthreaded [expr {
|
sl@0
|
34 |
(![info exist tcl_platform(threaded)] || !$tcl_platform(threaded))
|
sl@0
|
35 |
&& $tcl_platform(os) ne "Darwin"
|
sl@0
|
36 |
}]
|
sl@0
|
37 |
|
sl@0
|
38 |
# The next two tests will hang if threads are enabled because the notifier
|
sl@0
|
39 |
# will not necessarily wait for ever in this case, so it does not generate
|
sl@0
|
40 |
# an error.
|
sl@0
|
41 |
|
sl@0
|
42 |
test unixNotfy-1.1 {Tcl_DeleteFileHandler} \
|
sl@0
|
43 |
-constraints {unixOnly && unthreaded} \
|
sl@0
|
44 |
-body {
|
sl@0
|
45 |
catch {vwait x}
|
sl@0
|
46 |
set f [open [makeFile "" foo] w]
|
sl@0
|
47 |
fileevent $f writable {set x 1}
|
sl@0
|
48 |
vwait x
|
sl@0
|
49 |
close $f
|
sl@0
|
50 |
list [catch {vwait x} msg] $msg
|
sl@0
|
51 |
} \
|
sl@0
|
52 |
-result {1 {can't wait for variable "x": would wait forever}} \
|
sl@0
|
53 |
-cleanup {
|
sl@0
|
54 |
catch { close $f }
|
sl@0
|
55 |
catch { removeFile foo }
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
test unixNotfy-1.2 {Tcl_DeleteFileHandler} \
|
sl@0
|
59 |
-constraints {unixOnly && unthreaded} \
|
sl@0
|
60 |
-body {
|
sl@0
|
61 |
catch {vwait x}
|
sl@0
|
62 |
set f1 [open [makeFile "" foo] w]
|
sl@0
|
63 |
set f2 [open [makeFile "" foo2] w]
|
sl@0
|
64 |
fileevent $f1 writable {set x 1}
|
sl@0
|
65 |
fileevent $f2 writable {set y 1}
|
sl@0
|
66 |
vwait x
|
sl@0
|
67 |
close $f1
|
sl@0
|
68 |
vwait y
|
sl@0
|
69 |
close $f2
|
sl@0
|
70 |
list [catch {vwait x} msg] $msg
|
sl@0
|
71 |
} \
|
sl@0
|
72 |
-result {1 {can't wait for variable "x": would wait forever}} \
|
sl@0
|
73 |
-cleanup {
|
sl@0
|
74 |
catch { close $f1 }
|
sl@0
|
75 |
catch { close $f2 }
|
sl@0
|
76 |
catch { removeFile foo }
|
sl@0
|
77 |
catch { removeFile foo2 }
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
test unixNotfy-2.1 {Tcl_DeleteFileHandler} \
|
sl@0
|
81 |
-constraints {unixOnly testthread} \
|
sl@0
|
82 |
-body {
|
sl@0
|
83 |
update
|
sl@0
|
84 |
set f [open [makeFile "" foo] w]
|
sl@0
|
85 |
fileevent $f writable {set x 1}
|
sl@0
|
86 |
vwait x
|
sl@0
|
87 |
close $f
|
sl@0
|
88 |
testthread create "testthread send [testthread id] {set x ok}"
|
sl@0
|
89 |
vwait x
|
sl@0
|
90 |
threadReap
|
sl@0
|
91 |
set x
|
sl@0
|
92 |
} \
|
sl@0
|
93 |
-result {ok} \
|
sl@0
|
94 |
-cleanup {
|
sl@0
|
95 |
catch { close $f }
|
sl@0
|
96 |
catch { removeFile foo }
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
test unixNotfy-2.2 {Tcl_DeleteFileHandler} \
|
sl@0
|
100 |
-constraints {unixOnly testthread} \
|
sl@0
|
101 |
-body {
|
sl@0
|
102 |
update
|
sl@0
|
103 |
set f1 [open [makeFile "" foo] w]
|
sl@0
|
104 |
set f2 [open [makeFile "" foo2] w]
|
sl@0
|
105 |
fileevent $f1 writable {set x 1}
|
sl@0
|
106 |
fileevent $f2 writable {set y 1}
|
sl@0
|
107 |
vwait x
|
sl@0
|
108 |
close $f1
|
sl@0
|
109 |
vwait y
|
sl@0
|
110 |
close $f2
|
sl@0
|
111 |
testthread create "testthread send [testthread id] {set x ok}"
|
sl@0
|
112 |
vwait x
|
sl@0
|
113 |
threadReap
|
sl@0
|
114 |
set x
|
sl@0
|
115 |
} \
|
sl@0
|
116 |
-result {ok} \
|
sl@0
|
117 |
-cleanup {
|
sl@0
|
118 |
catch { close $f1 }
|
sl@0
|
119 |
catch { close $f2 }
|
sl@0
|
120 |
catch { removeFile foo }
|
sl@0
|
121 |
catch { removeFile foo2 }
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
# cleanup
|
sl@0
|
125 |
::tcltest::cleanupTests
|
sl@0
|
126 |
return
|