Bitcoin Core 28.99.0
P2P Digital Currency
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
MockableSteadyClock Struct Reference

Version of SteadyClock that is mockable in the context of tests (set the current value with SetMockTime), otherwise the system steady clock. More...

#include <time.h>

Inheritance diagram for MockableSteadyClock:
[legend]
Collaboration diagram for MockableSteadyClock:
[legend]

Public Types

using time_point = std::chrono::time_point< MockableSteadyClock >
 

Static Public Member Functions

static time_point now () noexcept
 Return current system time or mocked time, if set. More...
 
static std::time_t to_time_t (const time_point &)=delete
 
static time_point from_time_t (std::time_t)=delete
 
static void SetMockTime (std::chrono::milliseconds mock_time_in)
 Set mock time for testing. More...
 
static void ClearMockTime ()
 Clear mock time, go back to system steady clock. More...
 

Static Public Attributes

static constexpr std::chrono::milliseconds INITIAL_MOCK_TIME {1}
 

Detailed Description

Version of SteadyClock that is mockable in the context of tests (set the current value with SetMockTime), otherwise the system steady clock.

Definition at line 38 of file time.h.

Member Typedef Documentation

◆ time_point

using MockableSteadyClock::time_point = std::chrono::time_point<MockableSteadyClock>

Definition at line 39 of file time.h.

Member Function Documentation

◆ ClearMockTime()

void MockableSteadyClock::ClearMockTime ( )
static

Clear mock time, go back to system steady clock.

Definition at line 71 of file time.cpp.

Here is the caller graph for this function:

◆ from_time_t()

static time_point MockableSteadyClock::from_time_t ( std::time_t  )
staticdelete

◆ now()

MockableSteadyClock::time_point MockableSteadyClock::now ( )
staticnoexcept

Return current system time or mocked time, if set.

Definition at line 52 of file time.cpp.

◆ SetMockTime()

void MockableSteadyClock::SetMockTime ( std::chrono::milliseconds  mock_time_in)
static

Set mock time for testing.

When mocking the steady clock, start at INITIAL_MOCK_TIME and add durations to elapse time as necessary for testing. To stop mocking, call ClearMockTime().

Definition at line 65 of file time.cpp.

Here is the caller graph for this function:

◆ to_time_t()

static std::time_t MockableSteadyClock::to_time_t ( const time_point )
staticdelete

Member Data Documentation

◆ INITIAL_MOCK_TIME

constexpr std::chrono::milliseconds MockableSteadyClock::INITIAL_MOCK_TIME {1}
staticconstexpr

Definition at line 41 of file time.h.


The documentation for this struct was generated from the following files: