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 | /* |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 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 | |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 22 | #ifndef NDN_TESTS_MAKE_INTEREST_DATA_HPP |
| 23 | #define NDN_TESTS_MAKE_INTEREST_DATA_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" |
| 27 | #include "ndn-cxx/link.hpp" |
| 28 | #include "ndn-cxx/lp/nack.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 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 33 | /** \brief create an Interest |
| 34 | * \param name Interest name |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 35 | * \param canBePrefix CanBePrefix setting |
| 36 | * \param lifetime InterestLifetime |
| 37 | * \param nonce if non-zero, set Nonce to this value (useful for creating Nack with same Nonce) |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 38 | */ |
| 39 | shared_ptr<Interest> |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 40 | makeInterest(const Name& name, bool canBePrefix = false, |
| 41 | time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME, uint32_t nonce = 0); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 42 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 43 | /** \brief create a Data with fake signature |
| 44 | * \note Data may be modified afterwards without losing the fake signature. |
| 45 | * If a real signature is desired, sign again with KeyChain. |
| 46 | */ |
| 47 | shared_ptr<Data> |
| 48 | makeData(const Name& name); |
| 49 | |
| 50 | /** \brief add a fake signature to Data |
| 51 | */ |
| 52 | Data& |
| 53 | signData(Data& data); |
| 54 | |
| 55 | /** \brief add a fake signature to Data |
| 56 | */ |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 57 | inline shared_ptr<Data> |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 58 | signData(shared_ptr<Data> data) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 59 | { |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 60 | signData(*data); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 61 | return data; |
| 62 | } |
| 63 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 64 | /** \brief create a Nack |
| 65 | * \param interest Interest |
| 66 | * \param reason Nack reason |
| 67 | */ |
| 68 | lp::Nack |
| 69 | makeNack(const Interest& interest, lp::NackReason reason); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 70 | |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 71 | /** \brief replace a name component |
| 72 | * \param[inout] name name |
| 73 | * \param index name component index |
| 74 | * \param a arguments to name::Component constructor |
| 75 | */ |
| 76 | template<typename...A> |
| 77 | void |
| 78 | setNameComponent(Name& name, ssize_t index, const A& ...a) |
| 79 | { |
| 80 | Name name2 = name.getPrefix(index); |
| 81 | name2.append(name::Component(a...)); |
| 82 | name2.append(name.getSubName(name2.size())); |
| 83 | name = name2; |
| 84 | } |
| 85 | |
| 86 | template<typename PKT, typename...A> |
| 87 | void |
| 88 | setNameComponent(PKT& pkt, ssize_t index, const A& ...a) |
| 89 | { |
| 90 | Name name = pkt.getName(); |
| 91 | setNameComponent(name, index, a...); |
| 92 | pkt.setName(name); |
| 93 | } |
| 94 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 95 | } // namespace tests |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 96 | } // namespace ndn |
| 97 | |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 98 | #endif // NDN_TESTS_MAKE_INTEREST_DATA_HPP |