1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import org.apache.tools.ant.BuildFileTest; 21 24 public class SleepTest extends BuildFileTest { 25 26 27 private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; 28 private final static boolean TRACE=false; 29 private final static int ERROR_RANGE=1000; 30 31 public SleepTest(String name) { 32 super(name); 33 } 34 35 public void setUp() { 36 configureProject(TASKDEFS_DIR + "sleep.xml"); 37 } 38 39 public void test1() { 40 Timer timer=new Timer(); 41 executeTarget("test1"); 42 timer.stop(); 43 if(TRACE) System.out.println(" test1 elapsed time="+timer.time()); 44 assertTrue(timer.time()>=0); 45 } 46 47 public void test2() { 48 Timer timer=new Timer(); 49 executeTarget("test2"); 50 timer.stop(); 51 if(TRACE) System.out.println(" test2 elapsed time="+timer.time()); 52 assertTrue(timer.time()>=0); 53 } 54 55 public void test3() { 56 Timer timer=new Timer(); 57 executeTarget("test3"); 58 timer.stop(); 59 if(TRACE) System.out.println(" test3 elapsed time="+timer.time()); 60 assertTrue(timer.time()>=(2000-ERROR_RANGE)); 61 } 62 63 public void test4() { 64 Timer timer=new Timer(); 65 executeTarget("test3"); 66 timer.stop(); 67 if(TRACE) System.out.println(" test4 elapsed time="+timer.time()); 68 assertTrue(timer.time()>=(2000-ERROR_RANGE) && timer.time()<60000); 69 } 70 71 public void test5() { 72 expectBuildException("test5", 73 "Negative sleep periods are not supported"); 74 } 75 76 public void test6() { 77 Timer timer=new Timer(); 78 executeTarget("test6"); 79 timer.stop(); 80 if(TRACE) System.out.println(" test6 elapsed time="+timer.time()); 81 assertTrue(timer.time()<2000); 82 } 83 84 85 88 private static class Timer { 89 long start=0; 90 long stop=0; 91 92 public Timer() { 93 start(); 94 } 95 96 public void start() { 97 start=System.currentTimeMillis(); 98 } 99 100 public void stop() { 101 stop=System.currentTimeMillis(); 102 } 103 104 public long time() { 105 return stop-start; 106 } 107 } 108 109 } 110 111 | Popular Tags |