blob: 68dabbfe0271d9f35e7bf1449ab0f02626e3565c [file] [log] [blame]
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2020 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_CXX_TESTS_UNIT_CLOCK_FIXTURE_HPP
23#define NDN_CXX_TESTS_UNIT_CLOCK_FIXTURE_HPP
24
25#include "ndn-cxx/util/time-unit-test-clock.hpp"
26
27namespace ndn {
28namespace tests {
29
30/** \brief A test fixture that overrides steady clock and system clock.
31 */
32class ClockFixture
33{
34public:
35 virtual
36 ~ClockFixture();
37
38 /** \brief Advance steady and system clocks.
39 *
40 * Clocks are advanced in increments of \p tick for \p nTicks ticks.
41 * afterTick() is called after each tick.
42 *
43 * Exceptions thrown during I/O events are propagated to the caller.
44 * Clock advancement will stop in the event of an exception.
45 */
46 void
47 advanceClocks(time::nanoseconds tick, size_t nTicks = 1)
48 {
49 advanceClocks(tick, tick * nTicks);
50 }
51
52 /** \brief Advance steady and system clocks.
53 *
54 * Clocks are advanced in increments of \p tick for \p total time.
55 * The last increment might be shorter than \p tick.
56 * afterTick() is called after each tick.
57 *
58 * Exceptions thrown during I/O events are propagated to the caller.
59 * Clock advancement will stop in the event of an exception.
60 */
61 void
62 advanceClocks(time::nanoseconds tick, time::nanoseconds total);
63
64protected:
65 ClockFixture();
66
67private:
68 /** \brief Called by advanceClocks() after each clock advancement (tick).
69 *
70 * The base class implementation is a no-op.
71 */
72 virtual void
73 afterTick()
74 {
75 }
76
77protected:
78 shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
79 shared_ptr<time::UnitTestSystemClock> m_systemClock;
80};
81
82} // namespace tests
83} // namespace ndn
84
85#endif // NDN_CXX_TESTS_UNIT_CLOCK_FIXTURE_HPP