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
26#include <sstream>
27#include <string>
28#include <thread>
29
30namespace beast {
31
33{
34public:
35 template <class Clock>
36 void
38 {
39 testcase(name);
40
41 auto const t1(c.now());
43 auto const t2(c.now());
44
45 log << "t1= " << t1.time_since_epoch().count()
46 << ", t2= " << t2.time_since_epoch().count()
47 << ", elapsed= " << (t2 - t1).count() << std::endl;
48
49 pass();
50 }
51
52 void
54 {
55 testcase("manual");
56
58 clock_type c;
59
61
62 auto c1 = c.now().time_since_epoch();
63 c.set(clock_type::time_point(std::chrono::seconds(1)));
64 auto c2 = c.now().time_since_epoch();
65 c.set(clock_type::time_point(std::chrono::seconds(2)));
66 auto c3 = c.now().time_since_epoch();
67
68 log << "[" << c1.count() << "," << c2.count() << "," << c3.count()
69 << "]" << std::endl;
70
71 pass();
72 }
73
74 void
75 run() override
76 {
77 test("steady_clock", get_abstract_clock<std::chrono::steady_clock>());
78 test("system_clock", get_abstract_clock<std::chrono::system_clock>());
79 test(
80 "high_resolution_clock",
81 get_abstract_clock<std::chrono::high_resolution_clock>());
82
84 }
85};
86
87BEAST_DEFINE_TESTSUITE_MANUAL(abstract_clock, beast, beast);
88
89} // 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.
A testsuite class.
Definition suite.h:55
log_os< char > log
Logging output stream.
Definition suite.h:152
void pass()
Record a successful test condition.
Definition suite.h:511
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
T endl(T... args)
T sleep_for(T... args)