mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
util: Add type safe GetTime
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user