blob: d50f22fa7f276c8d9d5f80c1e88a15ff8af0695a [file] [log] [blame]
spirosmastorakisa46eee42016-04-05 14:24:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3* Copyright (c) 2016 Regents of the University of California.
4*
5* This file is part of the nTorrent codebase.
6*
7* nTorrent 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* nTorrent 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 nTorrent, e.g., in COPYING.md file. If not, see
17* <http://www.gnu.org/licenses/>.
18*
19* See AUTHORS for complete list of nTorrent authors and contributors.
20*/
21
22#ifndef NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
23#define NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
24
25#include <ndn-cxx/util/time-unit-test-clock.hpp>
26
27#include <boost/asio/io_service.hpp>
28
29namespace ndn {
30namespace ntorrent {
31namespace tests {
32
33class UnitTestTimeFixture
34{
35public:
36 UnitTestTimeFixture()
37 : steadyClock(make_shared<time::UnitTestSteadyClock>())
38 , systemClock(make_shared<time::UnitTestSystemClock>())
39 {
40 time::setCustomClocks(steadyClock, systemClock);
41 }
42
43 ~UnitTestTimeFixture()
44 {
45 time::setCustomClocks(nullptr, nullptr);
46 }
47
48 void
49 advanceClocks(const time::nanoseconds& tick, size_t nTicks = 1)
50 {
51 for (size_t i = 0; i < nTicks; ++i) {
52 steadyClock->advance(tick);
53 systemClock->advance(tick);
54
55 if (io.stopped())
56 io.reset();
57 io.poll();
58 }
59 }
60
61public:
62 shared_ptr<time::UnitTestSteadyClock> steadyClock;
63 shared_ptr<time::UnitTestSystemClock> systemClock;
64 boost::asio::io_service io;
65};
66
67} // namespace tests
68} // namespace ntorrent
69} // namespace ndn
70
71#endif // NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP