Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 60f8cc1 | 2018-05-10 22:05:21 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [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 ndn-tools (Named Data Networking Essential Tools). |
| 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 13 | * |
| 14 | * ndn-tools 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 | * ndn-tools 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 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NDN_TOOLS_TESTS_TEST_COMMON_HPP |
| 27 | #define NDN_TOOLS_TESTS_TEST_COMMON_HPP |
| 28 | |
Davide Pesavento | 60f8cc1 | 2018-05-10 22:05:21 -0400 | [diff] [blame] | 29 | #include "core/common.hpp" |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 30 | #include "tests/boost-test.hpp" |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 32 | namespace ndn { |
| 33 | namespace tests { |
| 34 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 35 | /** |
| 36 | * \brief Create an Interest |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 37 | */ |
| 38 | shared_ptr<Interest> |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 39 | makeInterest(const Name& name, bool canBePrefix = false, |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 40 | optional<time::milliseconds> lifetime = nullopt, |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 41 | optional<Interest::Nonce> nonce = nullopt); |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 42 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 43 | /** |
| 44 | * \brief Create a Data with a null (i.e., empty) signature |
| 45 | * |
| 46 | * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`. |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 47 | */ |
| 48 | shared_ptr<Data> |
| 49 | makeData(const Name& name); |
| 50 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 51 | /** |
| 52 | * \brief Add a null signature to \p data |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 53 | */ |
| 54 | Data& |
| 55 | signData(Data& data); |
| 56 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 57 | /** |
| 58 | * \brief Add a null signature to \p data |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 59 | */ |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 60 | inline shared_ptr<Data> |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 61 | signData(shared_ptr<Data> data) |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 62 | { |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 63 | signData(*data); |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 64 | return data; |
| 65 | } |
| 66 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 67 | /** |
| 68 | * \brief Create a Nack |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 69 | */ |
| 70 | lp::Nack |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 71 | makeNack(Interest interest, lp::NackReason reason); |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 73 | /** |
| 74 | * \brief Replace a name component in a packet |
| 75 | * \param[inout] pkt the packet |
| 76 | * \param index the index of the name component to replace |
| 77 | * \param args arguments to name::Component constructor |
| 78 | */ |
| 79 | template<typename Packet, typename ...Args> |
| 80 | void |
| 81 | setNameComponent(Packet& pkt, ssize_t index, Args&& ...args) |
| 82 | { |
| 83 | Name name = pkt.getName(); |
| 84 | name.set(index, name::Component(std::forward<Args>(args)...)); |
| 85 | pkt.setName(name); |
| 86 | } |
| 87 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 88 | } // namespace tests |
| 89 | } // namespace ndn |
| 90 | |
| 91 | #endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP |