blob: f16e0271fc41726d58f0f1493c3e3af552ccbfc3 [file] [log] [blame]
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NDNS (Named Data Networking Domain Name Service) and is
12 * based on the code written as part of NFD (Named Data Networking Daemon).
13 * See AUTHORS.md for complete list of NDNS authors and contributors.
14 *
15 * NDNS is free software: you can redistribute it and/or modify it under the terms
16 * of the GNU General Public License as published by the Free Software Foundation,
17 * either version 3 of the License, or (at your option) any later version.
18 *
19 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 * PURPOSE. See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along with
24 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27#include "test-common.hpp"
28
29namespace ndn {
30namespace ndns {
31namespace tests {
32
33BaseFixture::BaseFixture()
34{
35}
36
37UnitTestTimeFixture::UnitTestTimeFixture()
38 : steadyClock(make_shared<time::UnitTestSteadyClock>())
39 , systemClock(make_shared<time::UnitTestSystemClock>())
40{
41 time::setCustomClocks(steadyClock, systemClock);
42}
43
44UnitTestTimeFixture::~UnitTestTimeFixture()
45{
46 time::setCustomClocks(nullptr, nullptr);
47}
48
49void
50UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, size_t nTicks)
51{
52 this->advanceClocks(tick, tick * nTicks);
53}
54
55void
56UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, const time::nanoseconds& total)
57{
58 BOOST_ASSERT(tick > time::nanoseconds::zero());
59 BOOST_ASSERT(total >= time::nanoseconds::zero());
60
61 time::nanoseconds remaining = total;
62 while (remaining > time::nanoseconds::zero()) {
63 if (remaining >= tick) {
64 steadyClock->advance(tick);
65 systemClock->advance(tick);
66 remaining -= tick;
67 }
68 else {
69 steadyClock->advance(remaining);
70 systemClock->advance(remaining);
71 remaining = time::nanoseconds::zero();
72 }
73
74 if (m_io.stopped())
75 m_io.reset();
76 m_io.poll();
77 }
78}
79
80} // namespace tests
81} // namespace ndns
82} // namespace ndn