ndn::time::UnitTestClock< BaseClock, ClockTraits > Class Template Reference

Clock that can be used in unit tests for time-dependent tests independent of wall clock. More...

#include <ndn-cxx/util/time-unit-test-clock.hpp>

+ Inheritance diagram for ndn::time::UnitTestClock< BaseClock, ClockTraits >:
+ Collaboration diagram for ndn::time::UnitTestClock< BaseClock, ClockTraits >:

Public Member Functions

 UnitTestClock (nanoseconds startTime=ClockTraits::getDefaultStartTime())
 
void advance (nanoseconds duration)
 Advance unit test clock by duration. More...
 
BaseClock::time_point getNow () const override
 
std::string getSince () const override
 
void setNow (nanoseconds timeSinceEpoch)
 Explicitly set clock to timeSinceEpoch. More...
 
BaseClock::duration toWaitDuration (typename BaseClock::duration d) const override
 

Detailed Description

template<class BaseClock, class ClockTraits = UnitTestClockTraits<BaseClock>>
class ndn::time::UnitTestClock< BaseClock, ClockTraits >

Clock that can be used in unit tests for time-dependent tests independent of wall clock.

This clock should be explicitly advanced with UnitTestClock<BaseClock>::advance() or set with UnitTestClock<BaseClock>::setNow() methods.

Note
Default start time is determined by UnitTestClockTraits.

Definition at line 72 of file time-unit-test-clock.hpp.

Constructor & Destructor Documentation

◆ UnitTestClock()

template<class BaseClock , class ClockTraits >
ndn::time::UnitTestClock< BaseClock, ClockTraits >::UnitTestClock ( nanoseconds  startTime = ClockTraits::getDefaultStartTime())
explicit

Definition at line 31 of file time-unit-test-clock.cpp.

Member Function Documentation

◆ advance()

template<class BaseClock , class ClockTraits >
void ndn::time::UnitTestClock< BaseClock, ClockTraits >::advance ( nanoseconds  duration)

Advance unit test clock by duration.

Definition at line 59 of file time-unit-test-clock.cpp.

◆ getNow()

template<class BaseClock , class ClockTraits >
BaseClock::time_point ndn::time::UnitTestClock< BaseClock, ClockTraits >::getNow
overridevirtual

Implements ndn::time::CustomClock< BaseClock >.

Definition at line 45 of file time-unit-test-clock.cpp.

◆ getSince()

template<class BaseClock , class ClockTraits >
std::string ndn::time::UnitTestClock< BaseClock, ClockTraits >::getSince
overridevirtual

Implements ndn::time::CustomClock< BaseClock >.

Definition at line 38 of file time-unit-test-clock.cpp.

◆ setNow()

template<class BaseClock , class ClockTraits >
void ndn::time::UnitTestClock< BaseClock, ClockTraits >::setNow ( nanoseconds  timeSinceEpoch)

Explicitly set clock to timeSinceEpoch.

Definition at line 80 of file time-unit-test-clock.cpp.

◆ toWaitDuration()

template<class BaseClock , class ClockTraits >
BaseClock::duration ndn::time::UnitTestClock< BaseClock, ClockTraits >::toWaitDuration ( typename BaseClock::duration  d) const
overridevirtual

Implements ndn::time::CustomClock< BaseClock >.

Definition at line 52 of file time-unit-test-clock.cpp.