Debian Codegraph @

tests/winTime.test

raw
1 # This file tests the tclWinTime.c file.
2 #
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
6 #
7 # Copyright (c) 1997 Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
9 #
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
13 if {"::tcltest" ni [namespace children]} {
14 package require tcltest 2.5
15 namespace import -force ::tcltest::*
16 }
17
18 ::tcltest::loadTestedCommands
19 catch [list package require -exact Tcltest [info patchlevel]]
20
21 testConstraint testwinclock [llength [info commands testwinclock]]
22
23 # The next two tests will crash on Windows if the check for negative
24 # clock values is not done properly.
25
26 test winTime-1.1 {TclpGetDate} {win} {
27 set ::env(TZ) JST-9
28 set result [clock format -1 -format %Y]
29 unset ::env(TZ)
30 set result
31 } {1970}
32 test winTime-1.2 {TclpGetDate} {win} {
33 set ::env(TZ) PST8
34 set result [clock format 1 -format %Y]
35 unset ::env(TZ)
36 set result
37 } {1969}
38
39 # Next test tries to make sure that the Tcl clock stays in step
40 # with the Windows clock. 30 sec really isn't enough,
41 # but how much time does a tester have patience for?
42
43 test winTime-2.1 {Synchronization of Tcl and Windows clocks} testwinclock {
44 # May fail due to OS/hardware discrepancies. See:
45 # http://support.microsoft.com/default.aspx?scid=kb;en-us;274323
46 set failed {}
47 set ok 1
48 foreach start_sec [testwinclock] break
49 while { 1 } {
50 foreach { sys_sec sys_usec tcl_sec tcl_usec } [testwinclock] break
51 set diff [expr { $tcl_sec - $sys_sec
52 + 1.0e-6 * ( $tcl_usec - $sys_usec ) }]
53 if { abs($diff) > 0.1 } {
54 set failed "Tcl clock differs from system clock by $diff sec"
55 break
56 } else {
57 testwinsleep 1
58 }
59 if { $sys_sec - $start_sec >= 30 } break
60 }
61 set failed
62 } {}
63
64 # cleanup
65 ::tcltest::cleanupTests
66 return