source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/SleepTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 2.9 KB
Line 
1/*
2 * Copyright 2001,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19
20import org.apache.tools.ant.BuildFileTest;
21/**
22 * @created 01 May 2001
23 */
24public 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 /**
86 * inner timer class
87 */
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
Note: See TracBrowser for help on using the repository browser.