ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SystemTest.java
Revision: 1.2
Committed: Sun Sep 14 20:42:41 2003 UTC (20 years, 7 months ago) by dl
Branch: MAIN
Changes since 1.1: +43 -46 lines
Log Message:
New base class JSR166TestCase

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by members of JCP JSR-166 Expert Group and released to the
3     * public domain. Use, modify, and redistribute this code in any way
4     * without acknowledgement. Other contributors include Andrew Wright,
5     * Jeffrey Hayes, Pat Fischer, Mike Judd.
6     */
7    
8     import junit.framework.*;
9    
10 dl 1.2 public class SystemTest extends JSR166TestCase {
11 dl 1.1 public static void main(String[] args) {
12     junit.textui.TestRunner.run(suite());
13     }
14    
15     public static Test suite() {
16     return new TestSuite(SystemTest.class);
17     }
18    
19 dl 1.2 /**
20     * Nanos between readings of millis is no longer than millis.
21     * This shows only that nano timing not (much) worse than milli.
22     */
23 dl 1.1 public void testNanoTime1() {
24 dl 1.2 try {
25     long m1 = System.currentTimeMillis();
26     Thread.sleep(1);
27     long n1 = System.nanoTime();
28     Thread.sleep(SHORT_DELAY_MS);
29     long n2 = System.nanoTime();
30     Thread.sleep(1);
31     long m2 = System.currentTimeMillis();
32     long millis = m2 - m1;
33     long nanos = n2 - n1;
34    
35     assertTrue(nanos >= 0);
36     assertTrue(nanos <= millis * 1000000);
37     }
38     catch(InterruptedException ie) {
39     fail("unexpected exception");
40     }
41 dl 1.1 }
42    
43 dl 1.2 /**
44     * Millis between readings of nanos is no longer than nanos
45     * This shows only that nano timing not (much) worse than milli.
46     */
47 dl 1.1 public void testNanoTime2() {
48 dl 1.2 try {
49     long n1 = System.nanoTime();
50     Thread.sleep(1);
51     long m1 = System.currentTimeMillis();
52     Thread.sleep(SHORT_DELAY_MS);
53     long m2 = System.currentTimeMillis();
54     Thread.sleep(1);
55     long n2 = System.nanoTime();
56     long millis = m2 - m1;
57     long nanos = n2 - n1;
58    
59     assertTrue(nanos >= 0);
60     assertTrue(millis * 1000000 <= nanos);
61     }
62     catch(InterruptedException ie) {
63     fail("unexpected exception");
64     }
65 dl 1.1 }
66    
67     }
68