1//
2// StopwatchTest.cpp
3//
4// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "StopwatchTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Stopwatch.h"
15#include "Poco/Timestamp.h"
16#include "Poco/Thread.h"
17
18
19using Poco::Stopwatch;
20using Poco::Timestamp;
21using Poco::Thread;
22
23
24StopwatchTest::StopwatchTest(const std::string& rName): CppUnit::TestCase(rName)
25{
26}
27
28
29StopwatchTest::~StopwatchTest()
30{
31}
32
33
34void StopwatchTest::testStopwatch()
35{
36 Stopwatch sw;
37 sw.start();
38 Thread::sleep(200);
39 sw.stop();
40 Timestamp::TimeDiff d = sw.elapsed();
41 assertTrue (d >= 180000 && d <= 300000);
42 sw.start();
43 Thread::sleep(100);
44 d = sw.elapsed();
45 assertTrue (d >= 280000 && d <= 400000);
46 Thread::sleep(100);
47 sw.stop();
48 d = sw.elapsed();
49 assertTrue (d >= 380000 && d <= 500000);
50 sw.reset();
51 sw.start();
52 Thread::sleep(200);
53 sw.stop();
54 d = sw.elapsed();
55 assertTrue (d >= 180000 && d <= 300000);
56}
57
58
59void StopwatchTest::setUp()
60{
61}
62
63
64void StopwatchTest::tearDown()
65{
66}
67
68
69CppUnit::Test* StopwatchTest::suite()
70{
71 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("StopwatchTest");
72
73 CppUnit_addTest(pSuite, StopwatchTest, testStopwatch);
74
75 return pSuite;
76}
77