blob: 73fda1d55d73c2d00d4c00769b90519b8bfa6ee1 [file] [log] [blame]
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, Regents of the University of California
4 *
5 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
8 *
9 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22
23#ifndef NDN_DELOREAN_TESTS_TEST_COMMON_HPP
24#define NDN_DELOREAN_TESTS_TEST_COMMON_HPP
25
26#include "logger.hpp"
27
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>
34#include <ndn-cxx/security/key-chain.hpp>
35
36#include <boost/version.hpp>
37#include <boost/asio.hpp>
38#include <boost/filesystem.hpp>
39
40#include <fstream>
41
42#include "boost-test.hpp"
43// #include "unit-test-common-fixtures.hpp"
44// #include "identity-management-fixture.hpp"
45
46namespace ndn {
47namespace delorean {
48namespace tests {
49
50/** \brief create an Interest
51 * \param name Interest name
52 * \param nonce if non-zero, set Nonce to this value
53 * (useful for creating Nack with same Nonce)
54 */
55shared_ptr<Interest>
56makeInterest(const Name& name, uint32_t nonce = 0);
57
58/** \brief create a Data with fake signature
59 * \note Data may be modified afterwards without losing the fake signature.
60 * If a real signature is desired, sign again with KeyChain.
61 */
62shared_ptr<Data>
63makeData(const Name& name);
64
65/** \brief add a fake signature to Data
66 */
67Data&
68signData(Data& data);
69
70/** \brief add a fake signature to Data
71 */
72inline shared_ptr<Data>
73signData(shared_ptr<Data> data)
74{
75 signData(*data);
76 return data;
77}
78
79/** \brief create a Link object with fake signature
80 * \note Link may be modified afterwards without losing the fake signature.
81 * If a real signature is desired, sign again with KeyChain.
82 */
83shared_ptr<Link>
84makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations);
85
86/** \brief create a Nack
87 * \param name Interest name
88 * \param nonce Interest nonce
89 * \param reason Nack reason
90 */
91lp::Nack
92makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
93
94/** \brief replace a name component
95 * \param[inout] name name
96 * \param index name component index
97 * \param a arguments to name::Component constructor
98 */
99template<typename...A>
100void
101setNameComponent(Name& name, ssize_t index, const A& ...a)
102{
103 Name name2 = name.getPrefix(index);
104 name2.append(name::Component(a...));
105 name2.append(name.getSubName(name2.size()));
106 name = name2;
107}
108
109template<typename Packet, typename...A>
110void
111setNameComponent(Packet& packet, ssize_t index, const A& ...a)
112{
113 Name name = packet.getName();
114 setNameComponent(name, index, a...);
115 packet.setName(name);
116}
117
118} // namespace tests
119} // namespace delorean
120} // namespace ndn
121
122#endif // NDN_DELOREAN_TESTS_TEST_COMMON_HPP