diff options
author | MarcoFalke <falke.marco@gmail.com> | 2019-05-18 17:44:39 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2019-05-23 14:12:32 -0400 |
commit | fa013664ae23d0682a195b9bded85bc19c99536e (patch) | |
tree | d9b4ecfc48d4f8889498e20d1ffe802cd09c56a3 /src/test | |
parent | 277abed604a81be8036458573d052eaa293b6cf8 (diff) |
util: Add type safe GetTime
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/util_tests.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 51dd25ed1c..8fee66d6c3 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1068,6 +1068,27 @@ BOOST_AUTO_TEST_CASE(gettime) BOOST_CHECK((GetTime() & ~0xFFFFFFFFLL) == 0); } +BOOST_AUTO_TEST_CASE(util_time_GetTime) +{ + SetMockTime(111); + // Check that mock time does not change after a sleep + for (const auto& num_sleep : {0, 1}) { + MilliSleep(num_sleep); + BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter + BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count()); + BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count()); + BOOST_CHECK_EQUAL(111000000, GetTime<std::chrono::microseconds>().count()); + } + + SetMockTime(0); + // Check that system time changes after a sleep + const auto ms_0 = GetTime<std::chrono::milliseconds>(); + const auto us_0 = GetTime<std::chrono::microseconds>(); + MilliSleep(1); + BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>()); + BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>()); +} + BOOST_AUTO_TEST_CASE(test_IsDigit) { BOOST_CHECK_EQUAL(IsDigit('0'), true); |