blob: 9b876d9a168d6c2dd1075b2a40c04a588ca7dba1 [file] [log] [blame]
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
Junxiao Shif3c07812014-03-11 21:48:49 -07007#ifndef NFD_TEST_MGMT_VALIDATION_COMMON_HPP
8#define NFD_TEST_MGMT_VALIDATION_COMMON_HPP
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07009
Junxiao Shif3c07812014-03-11 21:48:49 -070010#include "common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070011#include <ndn-cpp-dev/util/command-interest-generator.hpp>
12
13namespace nfd {
14namespace tests {
15
16// class ValidatedManagementFixture
17// {
18// public:
19// ValidatedManagementFixture()
20// : m_validator(make_shared<ndn::CommandInterestValidator>())
21// {
22// }
23
24// virtual
25// ~ValidatedManagementFixture()
26// {
27// }
28
29// protected:
30// shared_ptr<ndn::CommandInterestValidator> m_validator;
31// };
32
Junxiao Shif3c07812014-03-11 21:48:49 -070033/// a global fixture that holds the identity for CommandFixture
34class CommandIdentityGlobalFixture
35{
36public:
37 CommandIdentityGlobalFixture();
38
39 ~CommandIdentityGlobalFixture();
40
41 static const Name& getIdentityName()
42 {
43 return s_identityName;
44 }
45
46 static shared_ptr<ndn::IdentityCertificate> getCertificate()
47 {
48 BOOST_ASSERT(static_cast<bool>(s_certificate));
49 return s_certificate;
50 }
51
52private:
53 ndn::KeyChain m_keys;
54 static const Name s_identityName;
55 static shared_ptr<ndn::IdentityCertificate> s_certificate;
56};
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070057
58template<typename T>
59class CommandFixture : public T
60{
61public:
62 virtual
63 ~CommandFixture()
64 {
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070065 }
66
67 void
68 generateCommand(Interest& interest)
69 {
Junxiao Shif3c07812014-03-11 21:48:49 -070070 m_generator.generateWithIdentity(interest, getIdentityName());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070071 }
72
73 const Name&
74 getIdentityName() const
75 {
Junxiao Shif3c07812014-03-11 21:48:49 -070076 return CommandIdentityGlobalFixture::getIdentityName();
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070077 }
78
79protected:
80 CommandFixture()
Junxiao Shif3c07812014-03-11 21:48:49 -070081 : m_certificate(CommandIdentityGlobalFixture::getCertificate())
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070082 {
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070083 }
84
85protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070086 shared_ptr<ndn::IdentityCertificate> m_certificate;
87 ndn::CommandInterestGenerator m_generator;
88};
89
90template <typename T>
91class UnauthorizedCommandFixture : public CommandFixture<T>
92{
93public:
94 UnauthorizedCommandFixture()
95 {
96 }
97
98 virtual
99 ~UnauthorizedCommandFixture()
100 {
101 }
102};
103
Junxiao Shif3c07812014-03-11 21:48:49 -0700104} // namespace tests
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700105} // namespace nfd
106
Junxiao Shif3c07812014-03-11 21:48:49 -0700107#endif // NFD_TEST_MGMT_VALIDATION_COMMON_HPP