[cvs] / jsr166 / src / test / tck / SystemTest.java Repository:
ViewVC logotype

Annotation of /jsr166/src/test/tck/SystemTest.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download)

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 : tim 1.4 junit.textui.TestRunner.run(suite());
13 : dl 1.1 }
14 :    
15 :     public static Test suite() {
16 : tim 1.4 return new TestSuite(SystemTest.class);
17 : dl 1.1 }
18 :    
19 : dl 1.2 /**
20 : tim 1.4 * Nanos between readings of millis is no longer than millis (plus
21 :     * one milli to allow for rounding).
22 : dl 1.2 * This shows only that nano timing not (much) worse than milli.
23 :     */
24 : dl 1.1 public void testNanoTime1() {
25 : dl 1.2 try {
26 :     long m1 = System.currentTimeMillis();
27 :     Thread.sleep(1);
28 :     long n1 = System.nanoTime();
29 :     Thread.sleep(SHORT_DELAY_MS);
30 :     long n2 = System.nanoTime();
31 :     Thread.sleep(1);
32 :     long m2 = System.currentTimeMillis();
33 :     long millis = m2 - m1;
34 :     long nanos = n2 - n1;
35 :    
36 :     assertTrue(nanos >= 0);
37 : tim 1.4 assertTrue(nanos < (millis+1) * 1000000);
38 : dl 1.2 }
39 :     catch(InterruptedException ie) {
40 : dl 1.3 unexpectedException();
41 : dl 1.2 }
42 : dl 1.1 }
43 :    
44 : dl 1.2 /**
45 :     * Millis between readings of nanos is no longer than nanos
46 :     * This shows only that nano timing not (much) worse than milli.
47 :     */
48 : dl 1.1 public void testNanoTime2() {
49 : dl 1.2 try {
50 :     long n1 = System.nanoTime();
51 :     Thread.sleep(1);
52 :     long m1 = System.currentTimeMillis();
53 :     Thread.sleep(SHORT_DELAY_MS);
54 :     long m2 = System.currentTimeMillis();
55 :     Thread.sleep(1);
56 :     long n2 = System.nanoTime();
57 :     long millis = m2 - m1;
58 :     long nanos = n2 - n1;
59 :    
60 :     assertTrue(nanos >= 0);
61 :     assertTrue(millis * 1000000 <= nanos);
62 :     }
63 :     catch(InterruptedException ie) {
64 : dl 1.3 unexpectedException();
65 : dl 1.2 }
66 : dl 1.1 }
67 :    
68 :     }
69 :    

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8