Changeset View
Changeset View
Standalone View
Standalone View
src/test/util_tests.cpp
Show First 20 Lines • Show All 1,477 Lines • ▼ Show 20 Lines | |||||
BOOST_AUTO_TEST_CASE(gettime) { | BOOST_AUTO_TEST_CASE(gettime) { | ||||
BOOST_CHECK((GetTime() & ~0xFFFFFFFFLL) == 0); | BOOST_CHECK((GetTime() & ~0xFFFFFFFFLL) == 0); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(util_time_GetTime) { | BOOST_AUTO_TEST_CASE(util_time_GetTime) { | ||||
SetMockTime(111); | SetMockTime(111); | ||||
// Check that mock time does not change after a sleep | // Check that mock time does not change after a sleep | ||||
for (const auto &num_sleep : {0, 1}) { | for (const auto &num_sleep : {0, 1}) { | ||||
MilliSleep(num_sleep); | UninterruptibleSleep(std::chrono::milliseconds{num_sleep}); | ||||
BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter | BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter | ||||
BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count()); | BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count()); | ||||
BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count()); | BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count()); | ||||
BOOST_CHECK_EQUAL(111000000, | BOOST_CHECK_EQUAL(111000000, | ||||
GetTime<std::chrono::microseconds>().count()); | GetTime<std::chrono::microseconds>().count()); | ||||
} | } | ||||
SetMockTime(0); | SetMockTime(0); | ||||
// Check that system time changes after a sleep | // Check that system time changes after a sleep | ||||
const auto ms_0 = GetTime<std::chrono::milliseconds>(); | const auto ms_0 = GetTime<std::chrono::milliseconds>(); | ||||
const auto us_0 = GetTime<std::chrono::microseconds>(); | const auto us_0 = GetTime<std::chrono::microseconds>(); | ||||
MilliSleep(1); | UninterruptibleSleep(std::chrono::milliseconds{1}); | ||||
BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>()); | BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>()); | ||||
BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>()); | BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_IsDigit) { | BOOST_AUTO_TEST_CASE(test_IsDigit) { | ||||
BOOST_CHECK_EQUAL(IsDigit('0'), true); | BOOST_CHECK_EQUAL(IsDigit('0'), true); | ||||
BOOST_CHECK_EQUAL(IsDigit('1'), true); | BOOST_CHECK_EQUAL(IsDigit('1'), true); | ||||
BOOST_CHECK_EQUAL(IsDigit('8'), true); | BOOST_CHECK_EQUAL(IsDigit('8'), true); | ||||
▲ Show 20 Lines • Show All 567 Lines • Show Last 20 Lines |