1//
2// ClockTest.cpp
3//
4// Copyright (c) 2013, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "ClockTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Clock.h"
15#include "Poco/Thread.h"
16#include <iostream>
17
18
19using Poco::Clock;
20using Poco::Thread;
21
22
23ClockTest::ClockTest(const std::string& rName): CppUnit::TestCase(rName)
24{
25}
26
27
28ClockTest::~ClockTest()
29{
30}
31
32
33void ClockTest::testClock()
34{
35 Clock t1;
36 Thread::sleep(200);
37 Clock t2;
38 Clock t3 = t2;
39 assertTrue (t1 != t2);
40 assertTrue (!(t1 == t2));
41 assertTrue (t2 > t1);
42 assertTrue (t2 >= t1);
43 assertTrue (!(t1 > t2));
44 assertTrue (!(t1 >= t2));
45 assertTrue (t2 == t3);
46 assertTrue (!(t2 != t3));
47 assertTrue (t2 >= t3);
48 assertTrue (t2 <= t3);
49 Clock::ClockDiff d = (t2 - t1);
50 assertTrue (d >= 180000 && d <= 300000);
51
52 Clock::ClockDiff acc = Clock::accuracy();
53 assertTrue (acc > 0 && acc < Clock::resolution());
54 std::cout << "Clock accuracy: " << acc << std::endl;
55
56 t1.swap(t2);
57 assertTrue (t1 > t2);
58 t2.swap(t1);
59
60 Clock now;
61 Thread::sleep(201);
62 assertTrue (now.elapsed() >= 200000);
63 assertTrue (now.isElapsed(200000));
64 assertTrue (!now.isElapsed(2000000));
65}
66
67
68void ClockTest::setUp()
69{
70}
71
72
73void ClockTest::tearDown()
74{
75}
76
77
78CppUnit::Test* ClockTest::suite()
79{
80 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ClockTest");
81
82 CppUnit_addTest(pSuite, ClockTest, testClock);
83
84 return pSuite;
85}
86