Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame^] | 2 | /* |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [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 NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "test-common.hpp" |
| 27 | #include <ndn-cxx/security/signature-sha256-with-rsa.hpp> |
| 28 | |
| 29 | namespace nfd { |
| 30 | namespace tests { |
| 31 | |
| 32 | BaseFixture::BaseFixture() |
| 33 | : g_io(getGlobalIoService()) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | BaseFixture::~BaseFixture() |
| 38 | { |
| 39 | resetGlobalIoService(); |
| 40 | } |
| 41 | |
| 42 | UnitTestTimeFixture::UnitTestTimeFixture() |
| 43 | : steadyClock(make_shared<time::UnitTestSteadyClock>()) |
| 44 | , systemClock(make_shared<time::UnitTestSystemClock>()) |
| 45 | { |
| 46 | time::setCustomClocks(steadyClock, systemClock); |
| 47 | } |
| 48 | |
| 49 | UnitTestTimeFixture::~UnitTestTimeFixture() |
| 50 | { |
| 51 | time::setCustomClocks(nullptr, nullptr); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, size_t nTicks) |
| 56 | { |
| 57 | this->advanceClocks(tick, tick * nTicks); |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | UnitTestTimeFixture::advanceClocks(const time::nanoseconds& tick, const time::nanoseconds& total) |
| 62 | { |
| 63 | BOOST_ASSERT(tick > time::nanoseconds::zero()); |
| 64 | BOOST_ASSERT(total >= time::nanoseconds::zero()); |
| 65 | |
| 66 | time::nanoseconds remaining = total; |
| 67 | while (remaining > time::nanoseconds::zero()) { |
| 68 | if (remaining >= tick) { |
| 69 | steadyClock->advance(tick); |
| 70 | systemClock->advance(tick); |
| 71 | remaining -= tick; |
| 72 | } |
| 73 | else { |
| 74 | steadyClock->advance(remaining); |
| 75 | systemClock->advance(remaining); |
| 76 | remaining = time::nanoseconds::zero(); |
| 77 | } |
| 78 | |
| 79 | if (g_io.stopped()) |
| 80 | g_io.reset(); |
| 81 | g_io.poll(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | shared_ptr<Interest> |
| 86 | makeInterest(const Name& name, uint32_t nonce) |
| 87 | { |
| 88 | auto interest = make_shared<Interest>(name); |
| 89 | if (nonce != 0) { |
| 90 | interest->setNonce(nonce); |
| 91 | } |
| 92 | return interest; |
| 93 | } |
| 94 | |
| 95 | shared_ptr<Data> |
| 96 | makeData(const Name& name) |
| 97 | { |
| 98 | auto data = make_shared<Data>(name); |
| 99 | return signData(data); |
| 100 | } |
| 101 | |
| 102 | Data& |
| 103 | signData(Data& data) |
| 104 | { |
| 105 | ndn::SignatureSha256WithRsa fakeSignature; |
| 106 | fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); |
| 107 | data.setSignature(fakeSignature); |
| 108 | data.wireEncode(); |
| 109 | |
| 110 | return data; |
| 111 | } |
| 112 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 113 | lp::Nack |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 114 | makeNack(Interest interest, lp::NackReason reason) |
| 115 | { |
| 116 | lp::Nack nack(std::move(interest)); |
| 117 | nack.setReason(reason); |
| 118 | return nack; |
| 119 | } |
| 120 | |
| 121 | lp::Nack |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 122 | makeNack(const Name& name, uint32_t nonce, lp::NackReason reason) |
| 123 | { |
| 124 | Interest interest(name); |
| 125 | interest.setNonce(nonce); |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 126 | return makeNack(std::move(interest), reason); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | } // namespace tests |
| 130 | } // namespace nfd |