blob: 9aa2e28940aee448c534b6c5cdf32ee14481f451 [file] [log] [blame]
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_TESTS_NFD_MGMT_VALIDATION_COMMON_HPP
26#define NFD_TESTS_NFD_MGMT_VALIDATION_COMMON_HPP
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070027
Junxiao Shif3c07812014-03-11 21:48:49 -070028#include "common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070029#include <ndn-cpp-dev/util/command-interest-generator.hpp>
30
31namespace nfd {
32namespace tests {
33
34// class ValidatedManagementFixture
35// {
36// public:
37// ValidatedManagementFixture()
38// : m_validator(make_shared<ndn::CommandInterestValidator>())
39// {
40// }
41
42// virtual
43// ~ValidatedManagementFixture()
44// {
45// }
46
47// protected:
48// shared_ptr<ndn::CommandInterestValidator> m_validator;
49// };
50
Junxiao Shif3c07812014-03-11 21:48:49 -070051/// a global fixture that holds the identity for CommandFixture
52class CommandIdentityGlobalFixture
53{
54public:
55 CommandIdentityGlobalFixture();
56
57 ~CommandIdentityGlobalFixture();
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070058
Junxiao Shif3c07812014-03-11 21:48:49 -070059 static const Name& getIdentityName()
60 {
61 return s_identityName;
62 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070063
Junxiao Shif3c07812014-03-11 21:48:49 -070064 static shared_ptr<ndn::IdentityCertificate> getCertificate()
65 {
66 BOOST_ASSERT(static_cast<bool>(s_certificate));
67 return s_certificate;
68 }
69
70private:
71 ndn::KeyChain m_keys;
72 static const Name s_identityName;
73 static shared_ptr<ndn::IdentityCertificate> s_certificate;
74};
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070075
76template<typename T>
77class CommandFixture : public T
78{
79public:
80 virtual
81 ~CommandFixture()
82 {
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070083 }
84
85 void
86 generateCommand(Interest& interest)
87 {
Junxiao Shif3c07812014-03-11 21:48:49 -070088 m_generator.generateWithIdentity(interest, getIdentityName());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070089 }
90
91 const Name&
92 getIdentityName() const
93 {
Junxiao Shif3c07812014-03-11 21:48:49 -070094 return CommandIdentityGlobalFixture::getIdentityName();
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070095 }
96
97protected:
98 CommandFixture()
Junxiao Shif3c07812014-03-11 21:48:49 -070099 : m_certificate(CommandIdentityGlobalFixture::getCertificate())
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700100 {
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700101 }
102
103protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700104 shared_ptr<ndn::IdentityCertificate> m_certificate;
105 ndn::CommandInterestGenerator m_generator;
106};
107
108template <typename T>
109class UnauthorizedCommandFixture : public CommandFixture<T>
110{
111public:
112 UnauthorizedCommandFixture()
113 {
114 }
115
116 virtual
117 ~UnauthorizedCommandFixture()
118 {
119 }
120};
121
Junxiao Shif3c07812014-03-11 21:48:49 -0700122} // namespace tests
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700123} // namespace nfd
124
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700125#endif // NFD_TESTS_NFD_MGMT_VALIDATION_COMMON_HPP