blob: d5770af1b87cbb3ab195e6a9ea54848116723184 [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * 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 Tan99135962014-09-20 02:18:53 -07009 *
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 Mastorakis429634f2015-02-19 17:35:33 -080025 */
Jiewen Tan99135962014-09-20 02:18:53 -070026
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 Shib1990df2015-11-05 00:14:44 +000033#include "lp/nack.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070034
35namespace ndn {
36namespace util {
37
38inline shared_ptr<Interest>
Junxiao Shib1990df2015-11-05 00:14:44 +000039makeInterest(const Name& name, uint32_t nonce = 0)
Jiewen Tan99135962014-09-20 02:18:53 -070040{
Junxiao Shib1990df2015-11-05 00:14:44 +000041 auto interest = make_shared<Interest>(name);
42 if (nonce != 0) {
43 interest->setNonce(nonce);
44 }
45 return interest;
Jiewen Tan99135962014-09-20 02:18:53 -070046}
47
48inline shared_ptr<Data>
Junxiao Shib1990df2015-11-05 00:14:44 +000049signData(shared_ptr<Data> data)
Jiewen Tan99135962014-09-20 02:18:53 -070050{
Junxiao Shib1990df2015-11-05 00:14:44 +000051 SignatureSha256WithRsa fakeSignature;
52 fakeSignature.setValue(encoding::makeEmptyBlock(tlv::SignatureValue));
Jiewen Tan99135962014-09-20 02:18:53 -070053 data->setSignature(fakeSignature);
54 data->wireEncode();
Jiewen Tan99135962014-09-20 02:18:53 -070055 return data;
56}
57
58inline shared_ptr<Data>
59makeData(const Name& name)
60{
Junxiao Shib1990df2015-11-05 00:14:44 +000061 auto data = make_shared<Data>(name);
Jiewen Tan99135962014-09-20 02:18:53 -070062 return signData(data);
63}
64
Junxiao Shib1990df2015-11-05 00:14:44 +000065inline shared_ptr<Link>
66makeLink(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
73inline lp::Nack
74makeNack(const Interest& interest, lp::NackReason reason)
75{
76 lp::Nack nack(interest);
77 nack.setReason(reason);
78 return nack;
79}
80
81inline lp::Nack
82makeNack(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 Tan99135962014-09-20 02:18:53 -070089} // namespace util
Jiewen Tan99135962014-09-20 02:18:53 -070090} // namespace ndn
91
92#endif // NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP