blob: fbf76c69b0fff5d977829aff595078531c28ac71 [file] [log] [blame]
Davide Pesavento829aff62022-05-15 20:30:34 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2022 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 NDNCERT_TESTS_CLOCK_FIXTURE_HPP
23#define NDNCERT_TESTS_CLOCK_FIXTURE_HPP
24
25#include <ndn-cxx/util/time-unit-test-clock.hpp>
26
27namespace ndncert::tests {
28
29namespace time = ndn::time;
30
31/** \brief A test fixture that overrides steady clock and system clock.
32 */
33class ClockFixture
34{
35public:
36 virtual
37 ~ClockFixture();
38
39 /** \brief Advance steady and system clocks.
40 *
41 * Clocks are advanced in increments of \p tick for \p nTicks ticks.
42 * afterTick() is called after each tick.
43 *
44 * Exceptions thrown during I/O events are propagated to the caller.
45 * Clock advancement will stop in the event of an exception.
46 */
47 void
48 advanceClocks(time::nanoseconds tick, size_t nTicks = 1)
49 {
50 advanceClocks(tick, tick * nTicks);
51 }
52
53 /** \brief Advance steady and system clocks.
54 *
55 * Clocks are advanced in increments of \p tick for \p total time.
56 * The last increment might be shorter than \p tick.
57 * afterTick() is called after each tick.
58 *
59 * Exceptions thrown during I/O events are propagated to the caller.
60 * Clock advancement will stop in the event of an exception.
61 */
62 void
63 advanceClocks(time::nanoseconds tick, time::nanoseconds total);
64
65protected:
66 ClockFixture();
67
68private:
69 /** \brief Called by advanceClocks() after each clock advancement (tick).
70 *
71 * The base class implementation is a no-op.
72 */
73 virtual void
74 afterTick()
75 {
76 }
77
78protected:
79 std::shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
80 std::shared_ptr<time::UnitTestSystemClock> m_systemClock;
81};
82
83} // namespace ndncert::tests
84
85#endif // NDNCERT_TESTS_CLOCK_FIXTURE_HPP