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