blob: 6553b7fdc805d55862ec4e1e5edbea39fc827604 [file] [log] [blame]
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
3 * Copyright (c) 2014-2017, Regents of the University of California.
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08004 *
Yumin Xia2c509c22017-02-09 14:37:36 -08005 * This file is part of NDNS (Named Data Networking Domain Name Service).
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08006 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NDNS_TESTS_TEST_COMMON_HPP
21#define NDNS_TESTS_TEST_COMMON_HPP
22
23#include "logger.hpp"
Yumin Xia2c509c22017-02-09 14:37:36 -080024#include "boost-test.hpp"
25#include "unit-test-common-fixtures.hpp"
26#include "identity-management-fixture.hpp"
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080027
28#include <ndn-cxx/name.hpp>
29#include <ndn-cxx/data.hpp>
30#include <ndn-cxx/interest.hpp>
31#include <ndn-cxx/link.hpp>
32#include <ndn-cxx/lp/nack.hpp>
33#include <ndn-cxx/util/dummy-client-face.hpp>
Yumin Xia2c509c22017-02-09 14:37:36 -080034#include <ndn-cxx/security/signing-helpers.hpp>
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080035
36#include <boost/version.hpp>
37#include <boost/asio.hpp>
38#include <boost/filesystem.hpp>
39
40#include <fstream>
41
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080042namespace ndn {
43namespace ndns {
44namespace tests {
45
Yumin Xia2c509c22017-02-09 14:37:36 -080046using ndn::security::v2::KeyChain;
47using ndn::security::Identity;
48using ndn::security::pib::Key;
49using ndn::security::v2::Certificate;
50
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080051/** \brief create an Interest
52 * \param name Interest name
53 * \param nonce if non-zero, set Nonce to this value
54 * (useful for creating Nack with same Nonce)
55 */
56shared_ptr<Interest>
57makeInterest(const Name& name, uint32_t nonce = 0);
58
59/** \brief create a Data with fake signature
60 * \note Data may be modified afterwards without losing the fake signature.
61 * If a real signature is desired, sign again with KeyChain.
62 */
63shared_ptr<Data>
64makeData(const Name& name);
65
66/** \brief add a fake signature to Data
67 */
68Data&
69signData(Data& data);
70
71/** \brief add a fake signature to Data
72 */
73inline shared_ptr<Data>
74signData(shared_ptr<Data> data)
75{
76 signData(*data);
77 return data;
78}
79
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080080/** \brief create a Nack
81 * \param name Interest name
82 * \param nonce Interest nonce
83 * \param reason Nack reason
84 */
85lp::Nack
86makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
87
88/** \brief replace a name component
89 * \param[inout] name name
90 * \param index name component index
91 * \param a arguments to name::Component constructor
92 */
93template<typename...A>
94void
95setNameComponent(Name& name, ssize_t index, const A& ...a)
96{
97 Name name2 = name.getPrefix(index);
98 name2.append(name::Component(a...));
99 name2.append(name.getSubName(name2.size()));
100 name = name2;
101}
102
103template<typename Packet, typename...A>
104void
105setNameComponent(Packet& packet, ssize_t index, const A& ...a)
106{
107 Name name = packet.getName();
108 setNameComponent(name, index, a...);
109 packet.setName(name);
110}
111
112} // namespace tests
113} // namespace ndns
114} // namespace ndn
115
Yumin Xia2c509c22017-02-09 14:37:36 -0800116#endif // NDNS_TESTS_TEST_COMMON_HPP