1 package org.tanukisoftware.wrapper; 2 3 27 28 import junit.framework.TestCase; 29 30 35 public class WrapperManagerSystemTimeTestCase 36 extends TestCase 37 { 38 private final int TICK_MS = 100; 39 40 43 public WrapperManagerSystemTimeTestCase( String name ) 44 { 45 super( name ); 46 } 47 48 51 private int getSystemTicks( long time ) 52 { 53 return (int)( time / TICK_MS ); 58 } 59 60 private long getTickAge( int start, int end ) 61 { 62 return (long)( end - start ) * TICK_MS; 65 } 66 67 public void doTest( long time, int expectedTicks, int negTicks, int posTicks ) 68 { 69 int ticks = getSystemTicks( time ); 70 assertEquals( "getSystemTicks( " + time + " ) failed", expectedTicks, ticks ); 71 72 long posAge = getTickAge( posTicks, expectedTicks ); 73 assertEquals( "getTickAge( " + posTicks + ", " + expectedTicks + " )", 1000L, posAge ); 74 75 long negAge = getTickAge( negTicks, expectedTicks ); 76 assertEquals( "getTickAge( " + negTicks + ", " + expectedTicks + " )", -1000L, negAge ); 77 } 78 79 82 public void testSimple() 83 { 84 doTest( 0L, 0, 10, -10 ); 85 doTest( 1L, 0, 10, -10 ); 86 doTest( 2L, 0, 10, -10 ); 87 doTest( 99L, 0, 10, -10 ); 88 doTest( 100L, 1, 11, -9 ); 89 doTest( 101L, 1, 11, -9 ); 90 doTest( 199L, 1, 11, -9 ); 91 doTest( 200L, 2, 12, -8 ); 92 } 93 94 public void testOverflow() 95 { 96 doTest( 214748363700L, 2147483637, 2147483647, 2147483627 ); 97 doTest( 214748363800L, 2147483638, -2147483648, 2147483628 ); 98 doTest( 214748363900L, 2147483639, -2147483647, 2147483629 ); 99 doTest( 214748364000L, 2147483640, -2147483646, 2147483630 ); 100 doTest( 214748364100L, 2147483641, -2147483645, 2147483631 ); 101 doTest( 214748364200L, 2147483642, -2147483644, 2147483632 ); 102 doTest( 214748364300L, 2147483643, -2147483643, 2147483633 ); 103 doTest( 214748364400L, 2147483644, -2147483642, 2147483634 ); 104 doTest( 214748364500L, 2147483645, -2147483641, 2147483635 ); 105 doTest( 214748364600L, 2147483646, -2147483640, 2147483636 ); 106 doTest( 214748364700L, 2147483647, -2147483639, 2147483637 ); 107 doTest( 214748364800L, -2147483648, -2147483638, 2147483638 ); 108 doTest( 214748364900L, -2147483647, -2147483637, 2147483639 ); 109 doTest( 214748365000L, -2147483646, -2147483636, 2147483640 ); 110 doTest( 214748365100L, -2147483645, -2147483635, 2147483641 ); 111 doTest( 214748365200L, -2147483644, -2147483634, 2147483642 ); 112 doTest( 214748365300L, -2147483643, -2147483633, 2147483643 ); 113 doTest( 214748365400L, -2147483642, -2147483632, 2147483644 ); 114 doTest( 214748365500L, -2147483641, -2147483631, 2147483645 ); 115 doTest( 214748365600L, -2147483640, -2147483630, 2147483646 ); 116 doTest( 214748365700L, -2147483639, -2147483629, 2147483647 ); 117 doTest( 214748365800L, -2147483638, -2147483628, -2147483648 ); 118 119 doTest( 429496729300L, -3, 7, -13 ); 120 doTest( 429496729400L, -2, 8, -12 ); 121 doTest( 429496729500L, -1, 9, -11 ); 122 doTest( 429496729600L, 0, 10, -10 ); 123 doTest( 429496729700L, 1, 11, -9 ); 124 doTest( 429496729800L, 2, 12, -8 ); 125 doTest( 429496729900L, 3, 13, -7 ); 126 } 127 } 128 | Popular Tags |