Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 20 | */ |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 21 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 22 | #ifndef NDN_CXX_TESTS_TEST_COMMON_HPP |
| 23 | #define NDN_CXX_TESTS_TEST_COMMON_HPP |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "ndn-cxx/data.hpp" |
| 26 | #include "ndn-cxx/interest.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 27 | #include "ndn-cxx/lp/nack.hpp" |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 28 | #include "tests/boost-test.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 31 | namespace tests { |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 33 | /** |
| 34 | * \brief Create an Interest |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 35 | */ |
| 36 | shared_ptr<Interest> |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 37 | makeInterest(const Name& name, bool canBePrefix = false, |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 38 | std::optional<time::milliseconds> lifetime = std::nullopt, |
| 39 | std::optional<Interest::Nonce> nonce = std::nullopt); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 40 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 41 | /** |
| 42 | * \brief Create a Data with a null (i.e., empty) signature |
| 43 | * |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 44 | * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`. |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 45 | */ |
| 46 | shared_ptr<Data> |
| 47 | makeData(const Name& name); |
| 48 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 49 | /** |
| 50 | * \brief Add a null signature to \p data |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 51 | */ |
| 52 | Data& |
| 53 | signData(Data& data); |
| 54 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 55 | /** |
| 56 | * \brief Add a null signature to \p data |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 57 | */ |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 58 | inline shared_ptr<Data> |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 59 | signData(shared_ptr<Data> data) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 60 | { |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 61 | signData(*data); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 62 | return data; |
| 63 | } |
| 64 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 65 | /** |
| 66 | * \brief Create a Nack |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 67 | */ |
| 68 | lp::Nack |
Davide Pesavento | 5353394 | 2020-03-04 23:10:06 -0500 | [diff] [blame] | 69 | makeNack(Interest interest, lp::NackReason reason); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 70 | |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 71 | /** |
| 72 | * \brief Replace a name component in a packet |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 73 | * \param[in,out] pkt the packet |
Davide Pesavento | 287a7fa | 2020-10-01 22:46:43 -0400 | [diff] [blame] | 74 | * \param index the index of the name component to replace |
| 75 | * \param args arguments to name::Component constructor |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 76 | */ |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 77 | template<typename Packet, typename ...Args> |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 78 | void |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 79 | setNameComponent(Packet& pkt, ssize_t index, Args&& ...args) |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 80 | { |
| 81 | Name name = pkt.getName(); |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 82 | name.set(index, name::Component(std::forward<Args>(args)...)); |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 83 | pkt.setName(name); |
| 84 | } |
| 85 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 86 | } // namespace tests |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 87 | } // namespace ndn |
| 88 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 89 | #endif // NDN_CXX_TESTS_TEST_COMMON_HPP |