sl@0
|
1 |
# This file tests the tclWinTime.c file.
|
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 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: winTime.test,v 1.8.2.1 2003/04/12 20:11:34 kennykb Exp $
|
sl@0
|
14 |
|
sl@0
|
15 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
16 |
package require tcltest
|
sl@0
|
17 |
namespace import -force ::tcltest::*
|
sl@0
|
18 |
}
|
sl@0
|
19 |
|
sl@0
|
20 |
testConstraint testwinclock [llength [info commands testwinclock]]
|
sl@0
|
21 |
|
sl@0
|
22 |
# The next two tests will crash on Windows if the check for negative
|
sl@0
|
23 |
# clock values is not done properly.
|
sl@0
|
24 |
|
sl@0
|
25 |
test winTime-1.1 {TclpGetDate} {pcOnly} {
|
sl@0
|
26 |
set ::env(TZ) JST-9
|
sl@0
|
27 |
set result [clock format -1 -format %Y]
|
sl@0
|
28 |
unset ::env(TZ)
|
sl@0
|
29 |
set result
|
sl@0
|
30 |
} {1970}
|
sl@0
|
31 |
test winTime-1.2 {TclpGetDate} {pcOnly} {
|
sl@0
|
32 |
set ::env(TZ) PST8
|
sl@0
|
33 |
set result [clock format 1 -format %Y]
|
sl@0
|
34 |
unset ::env(TZ)
|
sl@0
|
35 |
set result
|
sl@0
|
36 |
} {1969}
|
sl@0
|
37 |
|
sl@0
|
38 |
# Next test tries to make sure that the Tcl clock stays in step
|
sl@0
|
39 |
# with the Windows clock. 30 sec really isn't enough,
|
sl@0
|
40 |
# but how much time does a tester have patience for?
|
sl@0
|
41 |
|
sl@0
|
42 |
test winTime-2.1 {Synchronization of Tcl and Windows clocks} {testwinclock} {
|
sl@0
|
43 |
# May fail due to OS/hardware discrepancies. See:
|
sl@0
|
44 |
# http://support.microsoft.com/default.aspx?scid=kb;en-us;274323
|
sl@0
|
45 |
set failed {}
|
sl@0
|
46 |
set ok 1
|
sl@0
|
47 |
foreach start_sec [testwinclock] break
|
sl@0
|
48 |
while { 1 } {
|
sl@0
|
49 |
foreach { sys_sec sys_usec tcl_sec tcl_usec } [testwinclock] break
|
sl@0
|
50 |
set diff [expr { $tcl_sec - $sys_sec
|
sl@0
|
51 |
+ 1.0e-6 * ( $tcl_usec - $sys_usec ) }]
|
sl@0
|
52 |
if { abs($diff) > 0.06 } {
|
sl@0
|
53 |
set failed "Tcl clock differs from system clock by $diff sec"
|
sl@0
|
54 |
break
|
sl@0
|
55 |
} else {
|
sl@0
|
56 |
testwinsleep 1
|
sl@0
|
57 |
}
|
sl@0
|
58 |
if { $sys_sec - $start_sec >= 30 } break
|
sl@0
|
59 |
}
|
sl@0
|
60 |
set failed
|
sl@0
|
61 |
} {}
|
sl@0
|
62 |
|
sl@0
|
63 |
# cleanup
|
sl@0
|
64 |
::tcltest::cleanupTests
|
sl@0
|
65 |
return
|