001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildFileTest;
022:
023: /**
024: * @created 01 May 2001
025: */
026: public class SleepTest extends BuildFileTest {
027:
028: private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/";
029: private final static boolean TRACE = false;
030: private final static int ERROR_RANGE = 1000;
031:
032: public SleepTest(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: configureProject(TASKDEFS_DIR + "sleep.xml");
038: }
039:
040: public void test1() {
041: Timer timer = new Timer();
042: executeTarget("test1");
043: timer.stop();
044: if (TRACE)
045: System.out.println(" test1 elapsed time=" + timer.time());
046: assertTrue(timer.time() >= 0);
047: }
048:
049: public void test2() {
050: Timer timer = new Timer();
051: executeTarget("test2");
052: timer.stop();
053: if (TRACE)
054: System.out.println(" test2 elapsed time=" + timer.time());
055: assertTrue(timer.time() >= 0);
056: }
057:
058: public void test3() {
059: Timer timer = new Timer();
060: executeTarget("test3");
061: timer.stop();
062: if (TRACE)
063: System.out.println(" test3 elapsed time=" + timer.time());
064: assertTrue(timer.time() >= (2000 - ERROR_RANGE));
065: }
066:
067: public void test4() {
068: Timer timer = new Timer();
069: executeTarget("test3");
070: timer.stop();
071: if (TRACE)
072: System.out.println(" test4 elapsed time=" + timer.time());
073: assertTrue(timer.time() >= (2000 - ERROR_RANGE)
074: && timer.time() < 60000);
075: }
076:
077: public void test5() {
078: expectBuildException("test5",
079: "Negative sleep periods are not supported");
080: }
081:
082: public void test6() {
083: Timer timer = new Timer();
084: executeTarget("test6");
085: timer.stop();
086: if (TRACE)
087: System.out.println(" test6 elapsed time=" + timer.time());
088: assertTrue(timer.time() < 2000);
089: }
090:
091: /**
092: * inner timer class
093: */
094: private static class Timer {
095: long start = 0;
096: long stop = 0;
097:
098: public Timer() {
099: start();
100: }
101:
102: public void start() {
103: start = System.currentTimeMillis();
104: }
105:
106: public void stop() {
107: stop = System.currentTimeMillis();
108: }
109:
110: public long time() {
111: return stop - start;
112: }
113: }
114:
115: }
|