rippled
Loading...
Searching...
No Matches
beast_abstract_clock_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20// MODULES: ../impl/chrono_io.cpp
21
22#include <xrpl/beast/clock/abstract_clock.h>
23#include <xrpl/beast/clock/manual_clock.h>
24#include <xrpl/beast/unit_test.h>
25#include <sstream>
26#include <string>
27#include <thread>
28
29namespace beast {
30
32{
33public:
34 template <class Clock>
35 void
37 {
38 testcase(name);
39
40 auto const t1(c.now());
42 auto const t2(c.now());
43
44 log << "t1= " << t1.time_since_epoch().count()
45 << ", t2= " << t2.time_since_epoch().count()
46 << ", elapsed= " << (t2 - t1).count() << std::endl;
47
48 pass();
49 }
50
51 void
53 {
54 testcase("manual");
55
57 clock_type c;
58
60
61 auto c1 = c.now().time_since_epoch();
62 c.set(clock_type::time_point(std::chrono::seconds(1)));
63 auto c2 = c.now().time_since_epoch();
64 c.set(clock_type::time_point(std::chrono::seconds(2)));
65 auto c3 = c.now().time_since_epoch();
66
67 log << "[" << c1.count() << "," << c2.count() << "," << c3.count()
68 << "]" << std::endl;
69
70 pass();
71 }
72
73 void
74 run() override
75 {
76 test("steady_clock", get_abstract_clock<std::chrono::steady_clock>());
77 test("system_clock", get_abstract_clock<std::chrono::system_clock>());
78 test(
79 "high_resolution_clock",
80 get_abstract_clock<std::chrono::high_resolution_clock>());
81
83 }
84};
85
86BEAST_DEFINE_TESTSUITE_MANUAL(abstract_clock, chrono, beast);
87
88} // namespace beast
void run() override
Runs the suite.
void test(std::string name, abstract_clock< Clock > &c)
Abstract interface to a clock.
virtual time_point now() const =0
Returns the current time.
Manual clock implementation.
Definition: manual_clock.h:39
A testsuite class.
Definition: suite.h:53
log_os< char > log
Logging output stream.
Definition: suite.h:150
void pass()
Record a successful test condition.
Definition: suite.h:509
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
T endl(T... args)
T sleep_for(T... args)