23 #include "ndn-cxx/util/impl/steady-timer.hpp" 31 template<
class BaseClock,
class ClockTraits>
33 : m_currentTime(startTime)
37 template<
class BaseClock,
class ClockTraits>
41 return " since unit test beginning";
44 template<
class BaseClock,
class ClockTraits>
45 typename BaseClock::time_point
48 return typename BaseClock::time_point(duration_cast<typename BaseClock::duration>(m_currentTime));
51 template<
class BaseClock,
class ClockTraits>
52 typename BaseClock::duration
55 return typename BaseClock::duration(1);
58 template<
class BaseClock,
class ClockTraits>
62 m_currentTime += duration;
74 std::this_thread::sleep_for(std::chrono::nanoseconds(duration_cast<nanoseconds>(
75 boost::asio::wait_traits<steady_clock>::to_wait_duration(duration) +
76 typename BaseClock::duration(1)).count()));
79 template<
class BaseClock,
class ClockTraits>
83 BOOST_ASSERT(!BaseClock::is_steady || timeSinceEpoch >= m_currentTime);
85 m_currentTime = timeSinceEpoch;
88 auto delta = timeSinceEpoch - m_currentTime;
89 std::this_thread::sleep_for(std::chrono::nanoseconds(duration_cast<nanoseconds>(
90 boost::asio::wait_traits<steady_clock>::to_wait_duration(delta) +
91 typename BaseClock::duration(1)).count()));
void setNow(nanoseconds timeSinceEpoch)
Explicitly set clock to timeSinceEpoch.
void advance(nanoseconds duration)
Advance unit test clock by duration.
UnitTestClock(nanoseconds startTime=ClockTraits::getDefaultStartTime())
Clock that can be used in unit tests for time-dependent tests independent of wall clock...
BaseClock::time_point getNow() const override
BaseClock::duration toWaitDuration(typename BaseClock::duration d) const override
std::string getSince() const override