blob: 5ff903a032e56274c369b95940d7fc5a0f83e184 [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 Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2014-2022, 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
Davide Pesaventob3570c62022-02-19 19:19:00 -050032namespace ndn::tests {
Junxiao Shi2713a3b2015-06-22 16:19:05 -070033
Davide Pesavento66777622020-10-09 18:46:03 -040034/**
35 * \brief Create an Interest
Junxiao Shi7809e302016-07-23 14:11:25 +000036 */
37shared_ptr<Interest>
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060038makeInterest(const Name& name, bool canBePrefix = false,
Davide Pesavento66777622020-10-09 18:46:03 -040039 optional<time::milliseconds> lifetime = nullopt,
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040040 optional<Interest::Nonce> nonce = nullopt);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070041
Davide Pesavento66777622020-10-09 18:46:03 -040042/**
43 * \brief Create a Data with a null (i.e., empty) signature
44 *
45 * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
Junxiao Shi7809e302016-07-23 14:11:25 +000046 */
47shared_ptr<Data>
48makeData(const Name& name);
49
Davide Pesavento66777622020-10-09 18:46:03 -040050/**
51 * \brief Add a null signature to \p data
Junxiao Shi7809e302016-07-23 14:11:25 +000052 */
53Data&
54signData(Data& data);
55
Davide Pesavento66777622020-10-09 18:46:03 -040056/**
57 * \brief Add a null signature to \p data
Junxiao Shi7809e302016-07-23 14:11:25 +000058 */
Junxiao Shi2713a3b2015-06-22 16:19:05 -070059inline shared_ptr<Data>
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040060signData(shared_ptr<Data> data)
Junxiao Shi2713a3b2015-06-22 16:19:05 -070061{
Junxiao Shi7809e302016-07-23 14:11:25 +000062 signData(*data);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070063 return data;
64}
65
Davide Pesavento66777622020-10-09 18:46:03 -040066/**
67 * \brief Create a Nack
Zhuo Lib3558892016-08-12 15:51:12 -070068 */
69lp::Nack
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040070makeNack(Interest interest, lp::NackReason reason);
Zhuo Lib3558892016-08-12 15:51:12 -070071
Davide Pesavento66777622020-10-09 18:46:03 -040072/**
73 * \brief Replace a name component in a packet
74 * \param[inout] pkt the packet
75 * \param index the index of the name component to replace
76 * \param args arguments to name::Component constructor
77 */
78template<typename Packet, typename ...Args>
79void
80setNameComponent(Packet& pkt, ssize_t index, Args&& ...args)
81{
82 Name name = pkt.getName();
83 name.set(index, name::Component(std::forward<Args>(args)...));
84 pkt.setName(name);
85}
86
Davide Pesaventob3570c62022-02-19 19:19:00 -050087} // namespace ndn::tests
Junxiao Shi2713a3b2015-06-22 16:19:05 -070088
89#endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP