blob: 202fb188b546eabee449032cd7b3a574acb6e402 [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 Pesaventof6b45892023-03-13 15:00:51 -04003 * Copyright (c) 2013-2023 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
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050022#ifndef NDN_CXX_TESTS_TEST_COMMON_HPP
23#define NDN_CXX_TESTS_TEST_COMMON_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"
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050028#include "tests/boost-test.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070029
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040030namespace ndn::tests {
Jiewen Tan99135962014-09-20 02:18:53 -070031
Davide Pesavento287a7fa2020-10-01 22:46:43 -040032/**
33 * \brief Create an Interest
Junxiao Shi85d90832016-08-04 03:19:46 +000034 */
35shared_ptr<Interest>
Junxiao Shib55e5d32018-07-18 13:32:00 -060036makeInterest(const Name& name, bool canBePrefix = false,
Davide Pesaventof6b45892023-03-13 15:00:51 -040037 std::optional<time::milliseconds> lifetime = std::nullopt,
38 std::optional<Interest::Nonce> nonce = std::nullopt);
Jiewen Tan99135962014-09-20 02:18:53 -070039
Davide Pesavento287a7fa2020-10-01 22:46:43 -040040/**
41 * \brief Create a Data with a null (i.e., empty) signature
42 *
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050043 * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
Junxiao Shi85d90832016-08-04 03:19:46 +000044 */
45shared_ptr<Data>
46makeData(const Name& name);
47
Davide Pesavento287a7fa2020-10-01 22:46:43 -040048/**
49 * \brief Add a null signature to \p data
Junxiao Shi85d90832016-08-04 03:19:46 +000050 */
51Data&
52signData(Data& data);
53
Davide Pesavento287a7fa2020-10-01 22:46:43 -040054/**
55 * \brief Add a null signature to \p data
Junxiao Shi85d90832016-08-04 03:19:46 +000056 */
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
Davide Pesavento287a7fa2020-10-01 22:46:43 -040064/**
65 * \brief Create a Nack
Junxiao Shi85d90832016-08-04 03:19:46 +000066 */
67lp::Nack
Davide Pesavento53533942020-03-04 23:10:06 -050068makeNack(Interest interest, lp::NackReason reason);
Junxiao Shib1990df2015-11-05 00:14:44 +000069
Davide Pesavento287a7fa2020-10-01 22:46:43 -040070/**
71 * \brief Replace a name component in a packet
Davide Pesaventof6b45892023-03-13 15:00:51 -040072 * \param[in,out] pkt the packet
Davide Pesavento287a7fa2020-10-01 22:46:43 -040073 * \param index the index of the name component to replace
74 * \param args arguments to name::Component constructor
Junxiao Shi198c3812016-08-12 19:24:18 +000075 */
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040076template<typename Packet, typename... Args>
Junxiao Shi198c3812016-08-12 19:24:18 +000077void
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040078setNameComponent(Packet& pkt, ssize_t index, Args&&... args)
Junxiao Shi198c3812016-08-12 19:24:18 +000079{
80 Name name = pkt.getName();
Davide Pesaventoadc9aa22019-06-30 19:00:20 -040081 name.set(index, name::Component(std::forward<Args>(args)...));
Junxiao Shi198c3812016-08-12 19:24:18 +000082 pkt.setName(name);
83}
84
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040085} // namespace ndn::tests
Jiewen Tan99135962014-09-20 02:18:53 -070086
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050087#endif // NDN_CXX_TESTS_TEST_COMMON_HPP