blob: 2d120116f11add3e68cbf80b27e69f3e09e99b44 [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/*
Davide Pesavento53533942020-03-04 23:10:06 -05003 * Copyright (c) 2013-2020 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"
Davide Pesavento7e780642018-11-24 15:51:34 -050027#include "ndn-cxx/lp/nack.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070028
29namespace ndn {
Junxiao Shi85d90832016-08-04 03:19:46 +000030namespace tests {
Jiewen Tan99135962014-09-20 02:18:53 -070031
Junxiao Shi85d90832016-08-04 03:19:46 +000032/** \brief create an Interest
Junxiao Shi85d90832016-08-04 03:19:46 +000033 */
34shared_ptr<Interest>
Junxiao Shib55e5d32018-07-18 13:32:00 -060035makeInterest(const Name& name, bool canBePrefix = false,
Davide Pesavento53533942020-03-04 23:10:06 -050036 time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME,
37 optional<Interest::Nonce> nonce = nullopt);
Jiewen Tan99135962014-09-20 02:18:53 -070038
Junxiao Shi85d90832016-08-04 03:19:46 +000039/** \brief create a Data with fake signature
40 * \note Data may be modified afterwards without losing the fake signature.
41 * If a real signature is desired, sign again with KeyChain.
42 */
43shared_ptr<Data>
44makeData(const Name& name);
45
46/** \brief add a fake signature to Data
47 */
48Data&
49signData(Data& data);
50
51/** \brief add a fake signature to Data
52 */
Jiewen Tan99135962014-09-20 02:18:53 -070053inline shared_ptr<Data>
Junxiao Shib1990df2015-11-05 00:14:44 +000054signData(shared_ptr<Data> data)
Jiewen Tan99135962014-09-20 02:18:53 -070055{
Junxiao Shi85d90832016-08-04 03:19:46 +000056 signData(*data);
Jiewen Tan99135962014-09-20 02:18:53 -070057 return data;
58}
59
Junxiao Shi85d90832016-08-04 03:19:46 +000060/** \brief create a Nack
Junxiao Shi85d90832016-08-04 03:19:46 +000061 */
62lp::Nack
Davide Pesavento53533942020-03-04 23:10:06 -050063makeNack(Interest interest, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000064
Davide Pesaventoadc9aa22019-06-30 19:00:20 -040065/** \brief replace a name component in a packet
66 * \param[inout] pkt the packet
67 * \param index the index of the name component to replace
68 * \param args arguments to name::Component constructor
Junxiao Shi198c3812016-08-12 19:24:18 +000069 */
Davide Pesaventoadc9aa22019-06-30 19:00:20 -040070template<typename Packet, typename ...Args>
Junxiao Shi198c3812016-08-12 19:24:18 +000071void
Davide Pesaventoadc9aa22019-06-30 19:00:20 -040072setNameComponent(Packet& pkt, ssize_t index, Args&& ...args)
Junxiao Shi198c3812016-08-12 19:24:18 +000073{
74 Name name = pkt.getName();
Davide Pesaventoadc9aa22019-06-30 19:00:20 -040075 name.set(index, name::Component(std::forward<Args>(args)...));
Junxiao Shi198c3812016-08-12 19:24:18 +000076 pkt.setName(name);
77}
78
Junxiao Shi85d90832016-08-04 03:19:46 +000079} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -070080} // namespace ndn
81
Junxiao Shi2bea5c42017-08-14 20:10:32 +000082#endif // NDN_TESTS_MAKE_INTEREST_DATA_HPP