blob: 8dea8bf8647942af28ea6d29f4e9dee4117645a0 [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi85d90832016-08-04 03:19:46 +00003 * Copyright (c) 2013-2016 Regents of the University of California.
Jiewen Tan99135962014-09-20 02:18:53 -07004 *
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 Mastorakis429634f2015-02-19 17:35:33 -080020 */
Jiewen Tan99135962014-09-20 02:18:53 -070021
22#ifndef NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP
23#define NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP
24
Junxiao Shi85d90832016-08-04 03:19:46 +000025#include "interest.hpp"
26#include "data.hpp"
27#include "link.hpp"
Junxiao Shib1990df2015-11-05 00:14:44 +000028#include "lp/nack.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070029
30namespace ndn {
Junxiao Shi85d90832016-08-04 03:19:46 +000031namespace tests {
Jiewen Tan99135962014-09-20 02:18:53 -070032
Junxiao Shi85d90832016-08-04 03:19:46 +000033/** \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 */
38shared_ptr<Interest>
39makeInterest(const Name& name, uint32_t nonce = 0);
Jiewen Tan99135962014-09-20 02:18:53 -070040
Junxiao Shi85d90832016-08-04 03:19:46 +000041/** \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 */
45shared_ptr<Data>
46makeData(const Name& name);
47
48/** \brief add a fake signature to Data
49 */
50Data&
51signData(Data& data);
52
53/** \brief add a fake signature to Data
54 */
Jiewen Tan99135962014-09-20 02:18:53 -070055inline shared_ptr<Data>
Junxiao Shib1990df2015-11-05 00:14:44 +000056signData(shared_ptr<Data> data)
Jiewen Tan99135962014-09-20 02:18:53 -070057{
Junxiao Shi85d90832016-08-04 03:19:46 +000058 signData(*data);
Jiewen Tan99135962014-09-20 02:18:53 -070059 return data;
60}
61
Junxiao Shi85d90832016-08-04 03:19:46 +000062/** \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 */
66shared_ptr<Link>
67makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations);
Jiewen Tan99135962014-09-20 02:18:53 -070068
Junxiao Shi85d90832016-08-04 03:19:46 +000069/** \brief create a Nack
70 * \param interest Interest
71 * \param reason Nack reason
72 */
73lp::Nack
74makeNack(const Interest& interest, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000075
Junxiao Shi85d90832016-08-04 03:19:46 +000076/** \brief create a Nack
77 * \param name Interest name
78 * \param nonce Interest nonce
79 * \param reason Nack reason
80 */
81lp::Nack
82makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000083
Junxiao Shi198c3812016-08-12 19:24:18 +000084/** \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 */
89template<typename...A>
90void
91setNameComponent(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
99template<typename PKT, typename...A>
100void
101setNameComponent(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 Shi85d90832016-08-04 03:19:46 +0000108} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -0700109} // namespace ndn
110
111#endif // NDN_TESTS_UNIT_TESTS_MAKE_INTEREST_DATA_HPP