blob: 8fc55453ba990784b31ff50caa33f150cd4a0bfb [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shid701e5b2017-07-26 01:30:41 +00002/*
3 * Copyright (c) 2013-2017 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
Junxiao Shi2bea5c42017-08-14 20:10:32 +000022#ifndef NDN_TESTS_MAKE_INTEREST_DATA_HPP
23#define NDN_TESTS_MAKE_INTEREST_DATA_HPP
Jiewen Tan99135962014-09-20 02:18:53 -070024
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 Nack
63 * \param interest Interest
64 * \param reason Nack reason
65 */
66lp::Nack
67makeNack(const Interest& interest, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000068
Junxiao Shi85d90832016-08-04 03:19:46 +000069/** \brief create a Nack
70 * \param name Interest name
71 * \param nonce Interest nonce
72 * \param reason Nack reason
73 */
74lp::Nack
75makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000076
Junxiao Shi198c3812016-08-12 19:24:18 +000077/** \brief replace a name component
78 * \param[inout] name name
79 * \param index name component index
80 * \param a arguments to name::Component constructor
81 */
82template<typename...A>
83void
84setNameComponent(Name& name, ssize_t index, const A& ...a)
85{
86 Name name2 = name.getPrefix(index);
87 name2.append(name::Component(a...));
88 name2.append(name.getSubName(name2.size()));
89 name = name2;
90}
91
92template<typename PKT, typename...A>
93void
94setNameComponent(PKT& pkt, ssize_t index, const A& ...a)
95{
96 Name name = pkt.getName();
97 setNameComponent(name, index, a...);
98 pkt.setName(name);
99}
100
Junxiao Shi85d90832016-08-04 03:19:46 +0000101} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -0700102} // namespace ndn
103
Junxiao Shi2bea5c42017-08-14 20:10:32 +0000104#endif // NDN_TESTS_MAKE_INTEREST_DATA_HPP