Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 4 | * |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS 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, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NDNS_TESTS_TEST_COMMON_HPP |
| 21 | #define NDNS_TESTS_TEST_COMMON_HPP |
| 22 | |
| 23 | #include "logger.hpp" |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 24 | #include "boost-test.hpp" |
| 25 | #include "unit-test-common-fixtures.hpp" |
| 26 | #include "identity-management-fixture.hpp" |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 27 | |
| 28 | #include <ndn-cxx/name.hpp> |
| 29 | #include <ndn-cxx/data.hpp> |
| 30 | #include <ndn-cxx/interest.hpp> |
| 31 | #include <ndn-cxx/link.hpp> |
| 32 | #include <ndn-cxx/lp/nack.hpp> |
| 33 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 34 | #include <ndn-cxx/security/signing-helpers.hpp> |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 35 | |
| 36 | #include <boost/version.hpp> |
| 37 | #include <boost/asio.hpp> |
| 38 | #include <boost/filesystem.hpp> |
| 39 | |
| 40 | #include <fstream> |
| 41 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 42 | namespace ndn { |
| 43 | namespace ndns { |
| 44 | namespace tests { |
| 45 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 46 | using ndn::security::v2::KeyChain; |
| 47 | using ndn::security::Identity; |
| 48 | using ndn::security::pib::Key; |
| 49 | using ndn::security::v2::Certificate; |
| 50 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 51 | /** \brief create an Interest |
| 52 | * \param name Interest name |
| 53 | * \param nonce if non-zero, set Nonce to this value |
| 54 | * (useful for creating Nack with same Nonce) |
| 55 | */ |
| 56 | shared_ptr<Interest> |
| 57 | makeInterest(const Name& name, uint32_t nonce = 0); |
| 58 | |
| 59 | /** \brief create a Data with fake signature |
| 60 | * \note Data may be modified afterwards without losing the fake signature. |
| 61 | * If a real signature is desired, sign again with KeyChain. |
| 62 | */ |
| 63 | shared_ptr<Data> |
| 64 | makeData(const Name& name); |
| 65 | |
| 66 | /** \brief add a fake signature to Data |
| 67 | */ |
| 68 | Data& |
| 69 | signData(Data& data); |
| 70 | |
| 71 | /** \brief add a fake signature to Data |
| 72 | */ |
| 73 | inline shared_ptr<Data> |
| 74 | signData(shared_ptr<Data> data) |
| 75 | { |
| 76 | signData(*data); |
| 77 | return data; |
| 78 | } |
| 79 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 80 | /** \brief create a Nack |
| 81 | * \param name Interest name |
| 82 | * \param nonce Interest nonce |
| 83 | * \param reason Nack reason |
| 84 | */ |
| 85 | lp::Nack |
| 86 | makeNack(const Name& name, uint32_t nonce, lp::NackReason reason); |
| 87 | |
| 88 | /** \brief replace a name component |
| 89 | * \param[inout] name name |
| 90 | * \param index name component index |
| 91 | * \param a arguments to name::Component constructor |
| 92 | */ |
| 93 | template<typename...A> |
| 94 | void |
| 95 | setNameComponent(Name& name, ssize_t index, const A& ...a) |
| 96 | { |
| 97 | Name name2 = name.getPrefix(index); |
| 98 | name2.append(name::Component(a...)); |
| 99 | name2.append(name.getSubName(name2.size())); |
| 100 | name = name2; |
| 101 | } |
| 102 | |
| 103 | template<typename Packet, typename...A> |
| 104 | void |
| 105 | setNameComponent(Packet& packet, ssize_t index, const A& ...a) |
| 106 | { |
| 107 | Name name = packet.getName(); |
| 108 | setNameComponent(name, index, a...); |
| 109 | packet.setName(name); |
| 110 | } |
| 111 | |
| 112 | } // namespace tests |
| 113 | } // namespace ndns |
| 114 | } // namespace ndn |
| 115 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 116 | #endif // NDNS_TESTS_TEST_COMMON_HPP |