blob: b9a9aec741e38edec1852cb0151806ce07ebf498 [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/*
Junxiao Shib55e5d32018-07-18 13:32:00 -06003 * Copyright (c) 2013-2018 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
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/data.hpp"
26#include "ndn-cxx/interest.hpp"
27#include "ndn-cxx/link.hpp"
28#include "ndn-cxx/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
Junxiao Shib55e5d32018-07-18 13:32:00 -060035 * \param canBePrefix CanBePrefix setting
36 * \param lifetime InterestLifetime
37 * \param nonce if non-zero, set Nonce to this value (useful for creating Nack with same Nonce)
Junxiao Shi85d90832016-08-04 03:19:46 +000038 */
39shared_ptr<Interest>
Junxiao Shib55e5d32018-07-18 13:32:00 -060040makeInterest(const Name& name, bool canBePrefix = false,
41 time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME, uint32_t nonce = 0);
Jiewen Tan99135962014-09-20 02:18:53 -070042
Junxiao Shi85d90832016-08-04 03:19:46 +000043/** \brief create a Data with fake signature
44 * \note Data may be modified afterwards without losing the fake signature.
45 * If a real signature is desired, sign again with KeyChain.
46 */
47shared_ptr<Data>
48makeData(const Name& name);
49
50/** \brief add a fake signature to Data
51 */
52Data&
53signData(Data& data);
54
55/** \brief add a fake signature to Data
56 */
Jiewen Tan99135962014-09-20 02:18:53 -070057inline shared_ptr<Data>
Junxiao Shib1990df2015-11-05 00:14:44 +000058signData(shared_ptr<Data> data)
Jiewen Tan99135962014-09-20 02:18:53 -070059{
Junxiao Shi85d90832016-08-04 03:19:46 +000060 signData(*data);
Jiewen Tan99135962014-09-20 02:18:53 -070061 return data;
62}
63
Junxiao Shi85d90832016-08-04 03:19:46 +000064/** \brief create a Nack
65 * \param interest Interest
66 * \param reason Nack reason
67 */
68lp::Nack
69makeNack(const Interest& interest, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000070
Junxiao Shi198c3812016-08-12 19:24:18 +000071/** \brief replace a name component
72 * \param[inout] name name
73 * \param index name component index
74 * \param a arguments to name::Component constructor
75 */
76template<typename...A>
77void
78setNameComponent(Name& name, ssize_t index, const A& ...a)
79{
80 Name name2 = name.getPrefix(index);
81 name2.append(name::Component(a...));
82 name2.append(name.getSubName(name2.size()));
83 name = name2;
84}
85
86template<typename PKT, typename...A>
87void
88setNameComponent(PKT& pkt, ssize_t index, const A& ...a)
89{
90 Name name = pkt.getName();
91 setNameComponent(name, index, a...);
92 pkt.setName(name);
93}
94
Junxiao Shi85d90832016-08-04 03:19:46 +000095} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -070096} // namespace ndn
97
Junxiao Shi2bea5c42017-08-14 20:10:32 +000098#endif // NDN_TESTS_MAKE_INTEREST_DATA_HPP