xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
beast
beast_abstract_clock_test.cpp
1
// MODULES: ../impl/chrono_io.cpp
2
3
#include <xrpl/beast/clock/abstract_clock.h>
4
#include <xrpl/beast/clock/manual_clock.h>
5
#include <xrpl/beast/unit_test/suite.h>
6
7
#include <
chrono
>
8
#include <
ostream
>
9
#include <
string
>
10
#include <
thread
>
11
12
namespace
beast
{
13
14
class
abstract_clock_test
:
public
unit_test::Suite
15
{
16
public
:
17
template
<
class
Clock>
18
void
19
test
(
std::string
name,
AbstractClock<Clock>
& c)
20
{
21
testcase
(name);
22
23
auto
const
t1(c.
now
());
24
std::this_thread::sleep_for
(
std::chrono::milliseconds
(1500));
25
auto
const
t2(c.
now
());
26
27
log
<<
"t1= "
<< t1.time_since_epoch().count() <<
", t2= "
<< t2.time_since_epoch().count()
28
<<
", elapsed= "
<< (t2 - t1).count() <<
std::endl
;
29
30
pass
();
31
}
32
33
void
34
testManual
()
35
{
36
testcase
(
"manual"
);
37
38
using
ClockType =
ManualClock<std::chrono::steady_clock>
;
39
ClockType c;
40
41
auto
c1 = c.
now
().time_since_epoch();
42
c.set(ClockType::time_point(
std::chrono::seconds
(1)));
43
auto
c2 = c.now().time_since_epoch();
44
c.set(ClockType::time_point(
std::chrono::seconds
(2)));
45
auto
c3 = c.now().time_since_epoch();
46
47
log
<<
"["
<< c1.count() <<
","
<< c2.count() <<
","
<< c3.count() <<
"]"
<<
std::endl
;
48
49
pass
();
50
}
51
52
void
53
run
()
override
54
{
55
test
(
"steady_clock"
,
getAbstractClock<std::chrono::steady_clock>
());
56
test
(
"system_clock"
,
getAbstractClock<std::chrono::system_clock>
());
57
test
(
"high_resolution_clock"
,
getAbstractClock<std::chrono::high_resolution_clock>
());
58
59
testManual
();
60
}
61
};
62
63
BEAST_DEFINE_TESTSUITE_MANUAL
(abstract_clock,
beast
,
beast
);
64
65
}
// namespace beast
std::string
chrono
beast::AbstractClock
Abstract interface to a clock.
Definition
abstract_clock.h:36
beast::AbstractClock::now
virtual time_point now() const =0
Returns the current time.
beast::ManualClock
Manual clock implementation.
Definition
manual_clock.h:22
beast::abstract_clock_test
Definition
beast_abstract_clock_test.cpp:15
beast::abstract_clock_test::test
void test(std::string name, AbstractClock< Clock > &c)
Definition
beast_abstract_clock_test.cpp:19
beast::abstract_clock_test::run
void run() override
Runs the suite.
Definition
beast_abstract_clock_test.cpp:53
beast::abstract_clock_test::testManual
void testManual()
Definition
beast_abstract_clock_test.cpp:34
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::pass
void pass()
Record a successful test condition.
Definition
suite.h:532
beast::unit_test::Suite::log
LogOs< char > log
Logging output stream.
Definition
suite.h:150
beast::unit_test::Suite::testcase
TestcaseT testcase
Memberspace for declaring test cases.
Definition
suite.h:155
std::chrono::milliseconds
std::endl
T endl(T... args)
beast
Definition
base_uint.h:697
beast::getAbstractClock
AbstractClock< Facade > & getAbstractClock()
Returns a global instance of an abstract clock.
Definition
abstract_clock.h:88
beast::BEAST_DEFINE_TESTSUITE_MANUAL
BEAST_DEFINE_TESTSUITE_MANUAL(abstract_clock, beast, beast)
ostream
std::this_thread::sleep_for
T sleep_for(T... args)
string
thread
Generated by
1.17.0