blob: 0b4e04a6dff2c6649cd39e78897e253d904b8769 [file] [log] [blame]
Davide Pesaventof91d1df2020-11-25 14:50:41 -05001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013-2020 Regents of the University of California
4 * The University of Memphis
5 *
6 * This file is part of PSync.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU Lesser General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License along with
17 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "tests/clock-fixture.hpp"
21
22namespace ndn {
23namespace tests {
24
25ClockFixture::ClockFixture()
26 : m_steadyClock(make_shared<time::UnitTestSteadyClock>())
27 , m_systemClock(make_shared<time::UnitTestSystemClock>())
28{
29 time::setCustomClocks(m_steadyClock, m_systemClock);
30}
31
32ClockFixture::~ClockFixture()
33{
34 time::setCustomClocks(nullptr, nullptr);
35}
36
37void
38ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total)
39{
40 BOOST_ASSERT(tick > time::nanoseconds::zero());
41 BOOST_ASSERT(total >= time::nanoseconds::zero());
42
43 while (total > time::nanoseconds::zero()) {
44 auto t = std::min(tick, total);
45 m_steadyClock->advance(t);
46 m_systemClock->advance(t);
47 total -= t;
48
49 afterTick();
50 }
51}
52
53} // namespace tests
54} // namespace ndn