blob: 704140637785b728e1848f3a499cb03d743a0612 [file] [log] [blame]
Junxiao Shi85d90832016-08-04 03:19:46 +00001/* -*- 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.
Junxiao Shi85d90832016-08-04 03:19:46 +00004 *
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.
20 */
21
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050022#include "tests/test-common.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050023
Junxiao Shi85d90832016-08-04 03:19:46 +000024namespace ndn {
25namespace tests {
26
27shared_ptr<Interest>
Davide Pesavento287a7fa2020-10-01 22:46:43 -040028makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime,
Davide Pesavento53533942020-03-04 23:10:06 -050029 optional<Interest::Nonce> nonce)
Junxiao Shi85d90832016-08-04 03:19:46 +000030{
Davide Pesavento287a7fa2020-10-01 22:46:43 -040031 auto interest = std::make_shared<Interest>(name);
Junxiao Shib55e5d32018-07-18 13:32:00 -060032 interest->setCanBePrefix(canBePrefix);
Davide Pesavento287a7fa2020-10-01 22:46:43 -040033 if (lifetime) {
34 interest->setInterestLifetime(*lifetime);
35 }
Davide Pesavento53533942020-03-04 23:10:06 -050036 interest->setNonce(nonce);
Junxiao Shi85d90832016-08-04 03:19:46 +000037 return interest;
38}
39
40shared_ptr<Data>
41makeData(const Name& name)
42{
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040043 auto data = std::make_shared<Data>(name);
Junxiao Shi85d90832016-08-04 03:19:46 +000044 return signData(data);
45}
46
47Data&
48signData(Data& data)
49{
Davide Pesavento287a7fa2020-10-01 22:46:43 -040050 data.setSignatureInfo(SignatureInfo(tlv::NullSignature));
Davide Pesavento14c56cd2020-05-21 01:44:03 -040051 data.setSignatureValue(std::make_shared<Buffer>());
Junxiao Shi85d90832016-08-04 03:19:46 +000052 data.wireEncode();
53 return data;
54}
55
Junxiao Shi85d90832016-08-04 03:19:46 +000056lp::Nack
Davide Pesavento53533942020-03-04 23:10:06 -050057makeNack(Interest interest, lp::NackReason reason)
Junxiao Shi85d90832016-08-04 03:19:46 +000058{
Davide Pesavento53533942020-03-04 23:10:06 -050059 lp::Nack nack(std::move(interest));
Junxiao Shi85d90832016-08-04 03:19:46 +000060 nack.setReason(reason);
61 return nack;
62}
63
Junxiao Shi85d90832016-08-04 03:19:46 +000064} // namespace tests
65} // namespace ndn