Bitcoin Core  31.0.0
P2P Digital Currency
time.h
Go to the documentation of this file.
1 // Copyright (c) The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_TEST_UTIL_TIME_H
6 #define BITCOIN_TEST_UTIL_TIME_H
7 
8 #include <util/check.h>
9 #include <util/time.h>
10 
11 
15 {
16  MockableSteadyClock::mock_time_point::duration t{MockableSteadyClock::INITIAL_MOCK_TIME};
17 
18 public:
20  explicit SteadyClockContext() { (*this) += 0s; }
21 
24 
25  SteadyClockContext(const SteadyClockContext&) = delete;
27 
29  void operator+=(std::chrono::milliseconds d)
30  {
31  Assert(d >= 0s); // Steady time can only increase monotonically.
32  t += d;
34  }
35 };
36 
37 #endif // BITCOIN_TEST_UTIL_TIME_H
static void SetMockTime(mock_time_point::duration mock_time_in)
Set mock time for testing.
Definition: time.cpp:70
static void ClearMockTime()
Clear mock time, go back to system steady clock.
Definition: time.cpp:76
MockableSteadyClock::mock_time_point::duration t
Definition: time.h:16
Helper to initialize the global MockableSteadyClock, let a duration elapse, and reset it after use in...
Definition: time.h:14
void operator+=(std::chrono::milliseconds d)
Change mocktime by the given duration delta.
Definition: time.h:29
static constexpr mock_time_point::duration INITIAL_MOCK_TIME
Definition: time.h:42
SteadyClockContext & operator=(const SteadyClockContext &)=delete
SteadyClockContext()
Initialize with INITIAL_MOCK_TIME.
Definition: time.h:20
~SteadyClockContext()
Unset mocktime.
Definition: time.h:23
#define Assert(val)
Identity function.
Definition: check.h:113