blob: 6e669333533ab831d5aea31d53dd94bc0ba4a6e0 [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 Pesavento5748e822024-01-26 18:40:22 -05003 * Copyright (c) 2014-2024, 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 Pesavento5748e822024-01-26 18:40:22 -050032#include <ndn-cxx/lp/nack.hpp>
33#include <optional>
34
Davide Pesaventob3570c62022-02-19 19:19:00 -050035namespace ndn::tests {
Junxiao Shi2713a3b2015-06-22 16:19:05 -070036
Davide Pesavento66777622020-10-09 18:46:03 -040037/**
Davide Pesavento5748e822024-01-26 18:40:22 -050038 * \brief Create an Interest.
Junxiao Shi7809e302016-07-23 14:11:25 +000039 */
Davide Pesavento5748e822024-01-26 18:40:22 -050040std::shared_ptr<Interest>
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060041makeInterest(const Name& name, bool canBePrefix = false,
Davide Pesavento3653dae2023-03-13 17:44:22 -040042 std::optional<time::milliseconds> lifetime = std::nullopt,
43 std::optional<Interest::Nonce> nonce = std::nullopt);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070044
Davide Pesavento66777622020-10-09 18:46:03 -040045/**
Davide Pesavento5748e822024-01-26 18:40:22 -050046 * \brief Create a Data with a null (i.e., empty) signature.
Davide Pesavento66777622020-10-09 18:46:03 -040047 *
48 * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
Junxiao Shi7809e302016-07-23 14:11:25 +000049 */
Davide Pesavento5748e822024-01-26 18:40:22 -050050std::shared_ptr<Data>
Junxiao Shi7809e302016-07-23 14:11:25 +000051makeData(const Name& name);
52
Davide Pesavento66777622020-10-09 18:46:03 -040053/**
Davide Pesavento5748e822024-01-26 18:40:22 -050054 * \brief Add a null signature to \p data.
Junxiao Shi7809e302016-07-23 14:11:25 +000055 */
56Data&
57signData(Data& data);
58
Davide Pesavento66777622020-10-09 18:46:03 -040059/**
Davide Pesavento5748e822024-01-26 18:40:22 -050060 * \brief Add a null signature to \p data.
Junxiao Shi7809e302016-07-23 14:11:25 +000061 */
Davide Pesavento5748e822024-01-26 18:40:22 -050062inline std::shared_ptr<Data>
63signData(std::shared_ptr<Data> data)
Junxiao Shi2713a3b2015-06-22 16:19:05 -070064{
Junxiao Shi7809e302016-07-23 14:11:25 +000065 signData(*data);
Junxiao Shi2713a3b2015-06-22 16:19:05 -070066 return data;
67}
68
Davide Pesavento66777622020-10-09 18:46:03 -040069/**
Davide Pesavento5748e822024-01-26 18:40:22 -050070 * \brief Create a Nack.
Zhuo Lib3558892016-08-12 15:51:12 -070071 */
72lp::Nack
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040073makeNack(Interest interest, lp::NackReason reason);
Zhuo Lib3558892016-08-12 15:51:12 -070074
Davide Pesavento66777622020-10-09 18:46:03 -040075/**
Davide Pesavento5748e822024-01-26 18:40:22 -050076 * \brief Replace a name component in a packet.
Davide Pesavento3653dae2023-03-13 17:44:22 -040077 * \param[in,out] pkt the packet
Davide Pesavento66777622020-10-09 18:46:03 -040078 * \param index the index of the name component to replace
79 * \param args arguments to name::Component constructor
80 */
81template<typename Packet, typename ...Args>
82void
83setNameComponent(Packet& pkt, ssize_t index, Args&& ...args)
84{
85 Name name = pkt.getName();
86 name.set(index, name::Component(std::forward<Args>(args)...));
87 pkt.setName(name);
88}
89
Davide Pesaventob3570c62022-02-19 19:19:00 -050090} // namespace ndn::tests
Junxiao Shi2713a3b2015-06-22 16:19:05 -070091
92#endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP