Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California, |
| 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 |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 9 | * |
| 10 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 11 | * |
| 12 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 13 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 14 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 18 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 21 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 22 | * <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 25 | */ |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 26 | |
| 27 | #ifndef NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |
| 28 | #define NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |
| 29 | |
| 30 | #include "boost-test.hpp" |
| 31 | |
| 32 | #include "security/key-chain.hpp" |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 33 | #include "lp/nack.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ndn { |
| 36 | namespace util { |
| 37 | |
| 38 | inline shared_ptr<Interest> |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 39 | makeInterest(const Name& name, uint32_t nonce = 0) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 40 | { |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 41 | auto interest = make_shared<Interest>(name); |
| 42 | if (nonce != 0) { |
| 43 | interest->setNonce(nonce); |
| 44 | } |
| 45 | return interest; |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | inline shared_ptr<Data> |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 49 | signData(shared_ptr<Data> data) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 50 | { |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 51 | SignatureSha256WithRsa fakeSignature; |
| 52 | fakeSignature.setValue(encoding::makeEmptyBlock(tlv::SignatureValue)); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 53 | data->setSignature(fakeSignature); |
| 54 | data->wireEncode(); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 55 | return data; |
| 56 | } |
| 57 | |
| 58 | inline shared_ptr<Data> |
| 59 | makeData(const Name& name) |
| 60 | { |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 61 | auto data = make_shared<Data>(name); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 62 | return signData(data); |
| 63 | } |
| 64 | |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 65 | inline shared_ptr<Link> |
| 66 | makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations) |
| 67 | { |
| 68 | auto link = make_shared<Link>(name, delegations); |
| 69 | signData(link); |
| 70 | return link; |
| 71 | } |
| 72 | |
| 73 | inline lp::Nack |
| 74 | makeNack(const Interest& interest, lp::NackReason reason) |
| 75 | { |
| 76 | lp::Nack nack(interest); |
| 77 | nack.setReason(reason); |
| 78 | return nack; |
| 79 | } |
| 80 | |
| 81 | inline lp::Nack |
| 82 | makeNack(const Name& name, uint32_t nonce, lp::NackReason reason) |
| 83 | { |
| 84 | Interest interest(name); |
| 85 | interest.setNonce(nonce); |
| 86 | return makeNack(interest, reason); |
| 87 | } |
| 88 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 89 | } // namespace util |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 90 | } // namespace ndn |
| 91 | |
| 92 | #endif // NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP |