Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2017 University of California, Los Angeles |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 4 | * |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 7 | * |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 11 | * |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 12 | * ChronoSync 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 General Public License for more details. |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP |
| 21 | #define NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP |
| 22 | |
| 23 | #include <ndn-cxx/util/time-unit-test-clock.hpp> |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame^] | 24 | |
Qiuhan Ding | d71a08a | 2014-12-30 18:56:15 -0800 | [diff] [blame] | 25 | #include <boost/asio.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace tests { |
| 29 | |
| 30 | class UnitTestTimeFixture |
| 31 | { |
| 32 | public: |
| 33 | UnitTestTimeFixture() |
| 34 | : steadyClock(make_shared<time::UnitTestSteadyClock>()) |
| 35 | , systemClock(make_shared<time::UnitTestSystemClock>()) |
| 36 | { |
| 37 | time::setCustomClocks(steadyClock, systemClock); |
| 38 | } |
| 39 | |
| 40 | ~UnitTestTimeFixture() |
| 41 | { |
| 42 | time::setCustomClocks(nullptr, nullptr); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | advanceClocks(const time::nanoseconds& tick, size_t nTicks = 1) |
| 47 | { |
| 48 | for (size_t i = 0; i < nTicks; ++i) { |
| 49 | steadyClock->advance(tick); |
| 50 | systemClock->advance(tick); |
| 51 | |
| 52 | if (io.stopped()) |
| 53 | io.reset(); |
| 54 | io.poll(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public: |
| 59 | shared_ptr<time::UnitTestSteadyClock> steadyClock; |
| 60 | shared_ptr<time::UnitTestSystemClock> systemClock; |
| 61 | boost::asio::io_service io; |
| 62 | }; |
| 63 | |
| 64 | } // namespace tests |
| 65 | } // namespace ndn |
| 66 | |
| 67 | #endif // NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP |