sl@0: # This file contains tests for tclUnixNotfy.c. sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1997 by Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: unixNotfy.test,v 1.11.2.4 2005/05/14 20:52:31 das Exp $ sl@0: sl@0: # The tests should not be run if you have a notifier which is unable to sl@0: # detect infinite vwaits, as the tests below will hang. The presence of sl@0: # the "testthread" command indicates that this is the case. sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest 2 sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: if {[info exists tk_version]} { sl@0: puts "When run in a Tk shell, these tests run hang. Skipping tests ..." sl@0: ::tcltest::cleanupTests sl@0: return sl@0: } sl@0: sl@0: set ::tcltest::testConstraints(testthread) \ sl@0: [expr {[info commands testthread] != {}}] sl@0: # Darwin always uses a threaded notifier sl@0: testConstraint unthreaded [expr { sl@0: (![info exist tcl_platform(threaded)] || !$tcl_platform(threaded)) sl@0: && $tcl_platform(os) ne "Darwin" sl@0: }] sl@0: sl@0: # The next two tests will hang if threads are enabled because the notifier sl@0: # will not necessarily wait for ever in this case, so it does not generate sl@0: # an error. sl@0: sl@0: test unixNotfy-1.1 {Tcl_DeleteFileHandler} \ sl@0: -constraints {unixOnly && unthreaded} \ sl@0: -body { sl@0: catch {vwait x} sl@0: set f [open [makeFile "" foo] w] sl@0: fileevent $f writable {set x 1} sl@0: vwait x sl@0: close $f sl@0: list [catch {vwait x} msg] $msg sl@0: } \ sl@0: -result {1 {can't wait for variable "x": would wait forever}} \ sl@0: -cleanup { sl@0: catch { close $f } sl@0: catch { removeFile foo } sl@0: } sl@0: sl@0: test unixNotfy-1.2 {Tcl_DeleteFileHandler} \ sl@0: -constraints {unixOnly && unthreaded} \ sl@0: -body { sl@0: catch {vwait x} sl@0: set f1 [open [makeFile "" foo] w] sl@0: set f2 [open [makeFile "" foo2] w] sl@0: fileevent $f1 writable {set x 1} sl@0: fileevent $f2 writable {set y 1} sl@0: vwait x sl@0: close $f1 sl@0: vwait y sl@0: close $f2 sl@0: list [catch {vwait x} msg] $msg sl@0: } \ sl@0: -result {1 {can't wait for variable "x": would wait forever}} \ sl@0: -cleanup { sl@0: catch { close $f1 } sl@0: catch { close $f2 } sl@0: catch { removeFile foo } sl@0: catch { removeFile foo2 } sl@0: } sl@0: sl@0: test unixNotfy-2.1 {Tcl_DeleteFileHandler} \ sl@0: -constraints {unixOnly testthread} \ sl@0: -body { sl@0: update sl@0: set f [open [makeFile "" foo] w] sl@0: fileevent $f writable {set x 1} sl@0: vwait x sl@0: close $f sl@0: testthread create "testthread send [testthread id] {set x ok}" sl@0: vwait x sl@0: threadReap sl@0: set x sl@0: } \ sl@0: -result {ok} \ sl@0: -cleanup { sl@0: catch { close $f } sl@0: catch { removeFile foo } sl@0: } sl@0: sl@0: test unixNotfy-2.2 {Tcl_DeleteFileHandler} \ sl@0: -constraints {unixOnly testthread} \ sl@0: -body { sl@0: update sl@0: set f1 [open [makeFile "" foo] w] sl@0: set f2 [open [makeFile "" foo2] w] sl@0: fileevent $f1 writable {set x 1} sl@0: fileevent $f2 writable {set y 1} sl@0: vwait x sl@0: close $f1 sl@0: vwait y sl@0: close $f2 sl@0: testthread create "testthread send [testthread id] {set x ok}" sl@0: vwait x sl@0: threadReap sl@0: set x sl@0: } \ sl@0: -result {ok} \ sl@0: -cleanup { sl@0: catch { close $f1 } sl@0: catch { close $f2 } sl@0: catch { removeFile foo } sl@0: catch { removeFile foo2 } sl@0: } sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return