blob: dcfc5421064568f0b92679a91a7ec7a5677a0df4 [file] [log] [blame]
Zhiyi Zhang5f133622015-10-17 08:49:54 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9091d832018-04-18 17:21:08 -04003 * Copyright (c) 2014-2018, Regents of the University of California
Zhiyi Zhang5f133622015-10-17 08:49:54 +08004 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
Zhiyi Zhang5f133622015-10-17 08:49:54 +08007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Zhiyi Zhang5f133622015-10-17 08:49:54 +08009 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Zhiyi Zhang5f133622015-10-17 08:49:54 +080013 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
Alexander Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Zhiyi Zhang5f133622015-10-17 08:49:54 +080018 */
19
Alexander Afanasyev9091d832018-04-18 17:21:08 -040020#ifndef NDN_NAC_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
21#define NDN_NAC_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
Zhiyi Zhang5f133622015-10-17 08:49:54 +080022
23#include <ndn-cxx/util/time-unit-test-clock.hpp>
24#include <boost/asio.hpp>
25
26namespace ndn {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040027namespace nac {
Zhiyi Zhang5f133622015-10-17 08:49:54 +080028namespace tests {
29
30class UnitTestTimeFixture
31{
32public:
33 UnitTestTimeFixture()
34 : steadyClock(make_shared<time::UnitTestSteadyClock>())
35 , systemClock(make_shared<time::UnitTestSystemClock>())
36 {
37 time::setCustomClocks(steadyClock, systemClock);
38 }
39
40 ~UnitTestTimeFixture()
41 {
42 time::setCustomClocks(nullptr, nullptr);
43 }
44
45 void
46 advanceClocks(const time::nanoseconds& tick, size_t nTicks = 1)
47 {
48 for (size_t i = 0; i < nTicks; ++i) {
49 steadyClock->advance(tick);
50 systemClock->advance(tick);
51
52 if (io.stopped())
53 io.reset();
54 io.poll();
55 }
56 }
57
58public:
59 shared_ptr<time::UnitTestSteadyClock> steadyClock;
60 shared_ptr<time::UnitTestSystemClock> systemClock;
61 boost::asio::io_service io;
62};
63
64} // namespace tests
Alexander Afanasyev9091d832018-04-18 17:21:08 -040065} // namespace nac
Zhiyi Zhang5f133622015-10-17 08:49:54 +080066} // namespace ndn
67
Alexander Afanasyev9091d832018-04-18 17:21:08 -040068#endif // NDN_NAC_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP