blob: 5fa2a8d3e4ec54525f45a889dca2599a6687ad2b [file] [log] [blame]
Junxiao Shi2713a3b2015-06-22 16:19:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento60f8cc12018-05-10 22:05:21 -04002/*
Davide Pesavento4ab5eed2020-03-12 20:50:04 -04003 * Copyright (c) 2014-2020, Regents of the University of California,
Junxiao Shi2713a3b2015-06-22 16:19:05 -07004 * 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,
9 * The University of Memphis.
10 *
11 * This file is part of ndn-tools (Named Data Networking Essential Tools).
12 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
13 *
14 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NDN_TOOLS_TESTS_TEST_COMMON_HPP
27#define NDN_TOOLS_TESTS_TEST_COMMON_HPP
28
Davide Pesavento60f8cc12018-05-10 22:05:21 -040029#include "core/common.hpp"
Davide Pesavento66777622020-10-09 18:46:03 -040030#include "tests/boost-test.hpp"
Junxiao Shi2713a3b2015-06-22 16:19:05 -070031
Junxiao Shi2713a3b2015-06-22 16:19:05 -070032namespace ndn {
33namespace tests {
34
Davide Pesavento66777622020-10-09 18:46:03 -040035/**
36 * \brief Create an Interest
Junxiao Shi7809e302016-07-23 14:11:25 +000037 */
38shared_ptr<Interest>
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060039makeInterest(const Name& name, bool canBePrefix = false,
Davide Pesavento66777622020-10-09 18:46:03 -040040 optional<time::milliseconds> lifetime = nullopt,
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040041 optional<Interest::Nonce> nonce = nullopt);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070042
Davide Pesavento66777622020-10-09 18:46:03 -040043/**
44 * \brief Create a Data with a null (i.e., empty) signature
45 *
46 * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
Junxiao Shi7809e302016-07-23 14:11:25 +000047 */
48shared_ptr<Data>
49makeData(const Name& name);
50
Davide Pesavento66777622020-10-09 18:46:03 -040051/**
52 * \brief Add a null signature to \p data
Junxiao Shi7809e302016-07-23 14:11:25 +000053 */
54Data&
55signData(Data& data);
56
Davide Pesavento66777622020-10-09 18:46:03 -040057/**
58 * \brief Add a null signature to \p data
Junxiao Shi7809e302016-07-23 14:11:25 +000059 */
Junxiao Shi2713a3b2015-06-22 16:19:05 -070060inline shared_ptr<Data>
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040061signData(shared_ptr<Data> data)
Junxiao Shi2713a3b2015-06-22 16:19:05 -070062{
Junxiao Shi7809e302016-07-23 14:11:25 +000063 signData(*data);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070064 return data;
65}
66
Davide Pesavento66777622020-10-09 18:46:03 -040067/**
68 * \brief Create a Nack
Zhuo Lib3558892016-08-12 15:51:12 -070069 */
70lp::Nack
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040071makeNack(Interest interest, lp::NackReason reason);
Zhuo Lib3558892016-08-12 15:51:12 -070072
Davide Pesavento66777622020-10-09 18:46:03 -040073/**
74 * \brief Replace a name component in a packet
75 * \param[inout] pkt the packet
76 * \param index the index of the name component to replace
77 * \param args arguments to name::Component constructor
78 */
79template<typename Packet, typename ...Args>
80void
81setNameComponent(Packet& pkt, ssize_t index, Args&& ...args)
82{
83 Name name = pkt.getName();
84 name.set(index, name::Component(std::forward<Args>(args)...));
85 pkt.setName(name);
86}
87
Junxiao Shi2713a3b2015-06-22 16:19:05 -070088} // namespace tests
89} // namespace ndn
90
91#endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP