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 | /* |
| 3 | * Copyright (c) 2014-2020, 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 | |
| 29 | namespace ndn { |
| 30 | namespace ndns { |
| 31 | namespace tests { |
| 32 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 33 | ClockFixture::ClockFixture() |
| 34 | : m_steadyClock(make_shared<time::UnitTestSteadyClock>()) |
| 35 | , m_systemClock(make_shared<time::UnitTestSystemClock>()) |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 36 | { |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 37 | time::setCustomClocks(m_steadyClock, m_systemClock); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 40 | ClockFixture::~ClockFixture() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 41 | { |
| 42 | time::setCustomClocks(nullptr, nullptr); |
| 43 | } |
| 44 | |
| 45 | void |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 46 | ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total) |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 47 | { |
| 48 | BOOST_ASSERT(tick > time::nanoseconds::zero()); |
| 49 | BOOST_ASSERT(total >= time::nanoseconds::zero()); |
| 50 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 51 | 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 Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 56 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 57 | afterTick(); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | } // namespace tests |
| 62 | } // namespace ndns |
| 63 | } // namespace ndn |