Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 9a0d213 | 2024-02-10 16:55:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 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 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 27 | #include "clock-fixture.hpp" |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 28 | |
Davide Pesavento | 9a0d213 | 2024-02-10 16:55:04 -0500 | [diff] [blame] | 29 | namespace ndn::ndns::tests { |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 30 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 31 | ClockFixture::ClockFixture() |
Davide Pesavento | 9a0d213 | 2024-02-10 16:55:04 -0500 | [diff] [blame] | 32 | : m_steadyClock(std::make_shared<time::UnitTestSteadyClock>()) |
| 33 | , m_systemClock(std::make_shared<time::UnitTestSystemClock>()) |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 34 | { |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 35 | time::setCustomClocks(m_steadyClock, m_systemClock); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 38 | ClockFixture::~ClockFixture() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 39 | { |
| 40 | time::setCustomClocks(nullptr, nullptr); |
| 41 | } |
| 42 | |
| 43 | void |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 44 | ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total) |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 45 | { |
| 46 | BOOST_ASSERT(tick > time::nanoseconds::zero()); |
| 47 | BOOST_ASSERT(total >= time::nanoseconds::zero()); |
| 48 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 49 | while (total > time::nanoseconds::zero()) { |
| 50 | auto t = std::min(tick, total); |
| 51 | m_steadyClock->advance(t); |
| 52 | m_systemClock->advance(t); |
| 53 | total -= t; |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 54 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 55 | afterTick(); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Davide Pesavento | 9a0d213 | 2024-02-10 16:55:04 -0500 | [diff] [blame] | 59 | } // namespace ndn::ndns::tests |