Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 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/clock-fixture.hpp" |
| 21 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 22 | namespace ndn::nac::tests { |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 23 | |
| 24 | ClockFixture::ClockFixture() |
| 25 | : m_steadyClock(make_shared<time::UnitTestSteadyClock>()) |
| 26 | , m_systemClock(make_shared<time::UnitTestSystemClock>()) |
| 27 | { |
| 28 | time::setCustomClocks(m_steadyClock, m_systemClock); |
| 29 | } |
| 30 | |
| 31 | ClockFixture::~ClockFixture() |
| 32 | { |
| 33 | time::setCustomClocks(nullptr, nullptr); |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total) |
| 38 | { |
| 39 | BOOST_ASSERT(tick > time::nanoseconds::zero()); |
| 40 | BOOST_ASSERT(total >= time::nanoseconds::zero()); |
| 41 | |
| 42 | while (total > time::nanoseconds::zero()) { |
| 43 | auto t = std::min(tick, total); |
| 44 | m_steadyClock->advance(t); |
| 45 | m_systemClock->advance(t); |
| 46 | total -= t; |
| 47 | |
| 48 | afterTick(); |
| 49 | } |
| 50 | } |
| 51 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 52 | } // namespace ndn::nac::tests |