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 | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 32 | namespace ndn::tests { |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 33 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 34 | /** |
| 35 | * \brief Create an Interest |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 36 | */ |
| 37 | shared_ptr<Interest> |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 38 | makeInterest(const Name& name, bool canBePrefix = false, |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 39 | optional<time::milliseconds> lifetime = nullopt, |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 40 | optional<Interest::Nonce> nonce = nullopt); |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 41 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 42 | /** |
| 43 | * \brief Create a Data with a null (i.e., empty) signature |
| 44 | * |
| 45 | * 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] | 46 | */ |
| 47 | shared_ptr<Data> |
| 48 | makeData(const Name& name); |
| 49 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 50 | /** |
| 51 | * \brief Add a null signature to \p data |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 52 | */ |
| 53 | Data& |
| 54 | signData(Data& data); |
| 55 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 56 | /** |
| 57 | * \brief Add a null signature to \p data |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 58 | */ |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 59 | inline shared_ptr<Data> |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 60 | signData(shared_ptr<Data> data) |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 61 | { |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 62 | signData(*data); |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 63 | return data; |
| 64 | } |
| 65 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 66 | /** |
| 67 | * \brief Create a Nack |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 68 | */ |
| 69 | lp::Nack |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame] | 70 | makeNack(Interest interest, lp::NackReason reason); |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 72 | /** |
| 73 | * \brief Replace a name component in a packet |
| 74 | * \param[inout] pkt the packet |
| 75 | * \param index the index of the name component to replace |
| 76 | * \param args arguments to name::Component constructor |
| 77 | */ |
| 78 | template<typename Packet, typename ...Args> |
| 79 | void |
| 80 | setNameComponent(Packet& pkt, ssize_t index, Args&& ...args) |
| 81 | { |
| 82 | Name name = pkt.getName(); |
| 83 | name.set(index, name::Component(std::forward<Args>(args)...)); |
| 84 | pkt.setName(name); |
| 85 | } |
| 86 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 87 | } // namespace ndn::tests |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 88 | |
| 89 | #endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP |