blob: 472e48998c3b3b8b0a7e8cc43dce8f5a6a7f9548 [file] [log] [blame]
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventobdd88c12020-11-26 00:35:08 -05002/*
3 * Copyright (c) 2014-2020, Regents of the University of California,
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08004 * 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
Davide Pesaventobdd88c12020-11-26 00:35:08 -050027#include "clock-fixture.hpp"
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080028
29namespace ndn {
30namespace ndns {
31namespace tests {
32
Davide Pesaventobdd88c12020-11-26 00:35:08 -050033ClockFixture::ClockFixture()
34 : m_steadyClock(make_shared<time::UnitTestSteadyClock>())
35 , m_systemClock(make_shared<time::UnitTestSystemClock>())
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080036{
Davide Pesaventobdd88c12020-11-26 00:35:08 -050037 time::setCustomClocks(m_steadyClock, m_systemClock);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080038}
39
Davide Pesaventobdd88c12020-11-26 00:35:08 -050040ClockFixture::~ClockFixture()
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080041{
42 time::setCustomClocks(nullptr, nullptr);
43}
44
45void
Davide Pesaventobdd88c12020-11-26 00:35:08 -050046ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total)
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080047{
48 BOOST_ASSERT(tick > time::nanoseconds::zero());
49 BOOST_ASSERT(total >= time::nanoseconds::zero());
50
Davide Pesaventobdd88c12020-11-26 00:35:08 -050051 while (total > time::nanoseconds::zero()) {
52 auto t = std::min(tick, total);
53 m_steadyClock->advance(t);
54 m_systemClock->advance(t);
55 total -= t;
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080056
Davide Pesaventobdd88c12020-11-26 00:35:08 -050057 afterTick();
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080058 }
59}
60
61} // namespace tests
62} // namespace ndns
63} // namespace ndn