Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | |
| 22 | #ifndef NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |
| 23 | #define NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |
| 24 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 25 | #include "interest.hpp" |
| 26 | #include "data.hpp" |
| 27 | #include "link.hpp" |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 28 | #include "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 |
| 35 | * \param nonce if non-zero, set Nonce to this value |
| 36 | * (useful for creating Nack with same Nonce) |
| 37 | */ |
| 38 | shared_ptr<Interest> |
| 39 | makeInterest(const Name& name, uint32_t nonce = 0); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 41 | /** \brief create a Data with fake signature |
| 42 | * \note Data may be modified afterwards without losing the fake signature. |
| 43 | * If a real signature is desired, sign again with KeyChain. |
| 44 | */ |
| 45 | shared_ptr<Data> |
| 46 | makeData(const Name& name); |
| 47 | |
| 48 | /** \brief add a fake signature to Data |
| 49 | */ |
| 50 | Data& |
| 51 | signData(Data& data); |
| 52 | |
| 53 | /** \brief add a fake signature to Data |
| 54 | */ |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 55 | inline shared_ptr<Data> |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 56 | signData(shared_ptr<Data> data) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 57 | { |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 58 | signData(*data); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 59 | return data; |
| 60 | } |
| 61 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 62 | /** \brief create a Link object with fake signature |
| 63 | * \note Link may be modified afterwards without losing the fake signature. |
| 64 | * If a real signature is desired, sign again with KeyChain. |
| 65 | */ |
| 66 | shared_ptr<Link> |
| 67 | makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 69 | /** \brief create a Nack |
| 70 | * \param interest Interest |
| 71 | * \param reason Nack reason |
| 72 | */ |
| 73 | lp::Nack |
| 74 | makeNack(const Interest& interest, lp::NackReason reason); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 75 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 76 | /** \brief create a Nack |
| 77 | * \param name Interest name |
| 78 | * \param nonce Interest nonce |
| 79 | * \param reason Nack reason |
| 80 | */ |
| 81 | lp::Nack |
| 82 | makeNack(const Name& name, uint32_t nonce, lp::NackReason reason); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 83 | |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 84 | /** \brief replace a name component |
| 85 | * \param[inout] name name |
| 86 | * \param index name component index |
| 87 | * \param a arguments to name::Component constructor |
| 88 | */ |
| 89 | template<typename...A> |
| 90 | void |
| 91 | setNameComponent(Name& name, ssize_t index, const A& ...a) |
| 92 | { |
| 93 | Name name2 = name.getPrefix(index); |
| 94 | name2.append(name::Component(a...)); |
| 95 | name2.append(name.getSubName(name2.size())); |
| 96 | name = name2; |
| 97 | } |
| 98 | |
| 99 | template<typename PKT, typename...A> |
| 100 | void |
| 101 | setNameComponent(PKT& pkt, ssize_t index, const A& ...a) |
| 102 | { |
| 103 | Name name = pkt.getName(); |
| 104 | setNameComponent(name, index, a...); |
| 105 | pkt.setName(name); |
| 106 | } |
| 107 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 108 | } // namespace tests |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 109 | } // namespace ndn |
| 110 | |
| 111 | #endif // NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |