blob: f001ef7b24a4322fd95c6d261556a67bb0f20b11 [file] [log] [blame]
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, Regents of the University of California
4 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#include "tests-common.hpp"
21
22namespace ndn {
23namespace nac {
24namespace tests {
25
26BaseFixture::BaseFixture()
27{
28}
29
30UnitTestTimeFixture::UnitTestTimeFixture()
31 : steadyClock(make_shared<time::UnitTestSteadyClock>())
32 , systemClock(make_shared<time::UnitTestSystemClock>())
33{
34 time::setCustomClocks(steadyClock, systemClock);
35}
36
37UnitTestTimeFixture::~UnitTestTimeFixture()
38{
39 time::setCustomClocks(nullptr, nullptr);
40}
41
42void
43UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, size_t nTicks)
44{
45 this->advanceClocks(tick, tick * nTicks);
46}
47
48void
49UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, const time::nanoseconds& total)
50{
51 BOOST_ASSERT(tick > time::nanoseconds::zero());
52 BOOST_ASSERT(total >= time::nanoseconds::zero());
53
54 time::nanoseconds remaining = total;
55 while (remaining > time::nanoseconds::zero()) {
56 if (remaining >= tick) {
57 steadyClock->advance(tick);
58 systemClock->advance(tick);
59 remaining -= tick;
60 }
61 else {
62 steadyClock->advance(remaining);
63 systemClock->advance(remaining);
64 remaining = time::nanoseconds::zero();
65 }
66
67 if (m_io.stopped())
68 m_io.reset();
69 m_io.poll();
70 }
71}
72
73} // namespace tests
74} // namespace nac
75} // namespace ndn