Branch data Line data Source code
1 : : #ifndef TIMEOUTILS_H
2 : : #define TIMEOUTILS_H
3 : :
4 : : #include <chrono>
5 : :
6 : : #ifdef LMUFFB_UNIT_TEST
7 : : // These are defined in main_test_runner.cpp
8 : : extern std::chrono::steady_clock::time_point g_mock_time;
9 : : extern bool g_use_mock_time;
10 : : #endif
11 : :
12 : : namespace TimeUtils {
13 : : /**
14 : : * @brief A simple interface for providing the current time.
15 : : * Allows for mocking in unit tests.
16 : : */
17 : 12418 : inline std::chrono::steady_clock::time_point GetTime() {
18 : : #ifdef LMUFFB_UNIT_TEST
19 [ + + ]: 12418 : if (g_use_mock_time) return g_mock_time;
20 : : #endif
21 : 2888 : return std::chrono::steady_clock::now();
22 : : }
23 : : }
24 : :
25 : : #endif // TIMEOUTILS_H
|