blob: 492cbc2d01bb7fe6c808ebf86a12e4462d34fa6b [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
4 *
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
22#ifndef NDN_TESTS_MANAGEMENT_NFD_CONTROLLER_FIXTURE_HPP
23#define NDN_TESTS_MANAGEMENT_NFD_CONTROLLER_FIXTURE_HPP
24
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000025#include "management/nfd-controller.hpp"
26#include "../../dummy-validator.hpp"
27
Junxiao Shi034c1882016-06-24 18:06:51 +000028#include "boost-test.hpp"
29#include "util/dummy-client-face.hpp"
30#include "../identity-management-time-fixture.hpp"
31
32namespace ndn {
33namespace nfd {
34namespace tests {
35
36using namespace ndn::tests;
37
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070038class ControllerFixture : public IdentityManagementTimeFixture
Junxiao Shi034c1882016-06-24 18:06:51 +000039{
40protected:
41 ControllerFixture()
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070042 : face(io, m_keyChain)
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000043 , controller(face, m_keyChain, m_validator)
Junxiao Shi034c1882016-06-24 18:06:51 +000044 , failCallback(bind(&ControllerFixture::fail, this, _1, _2))
45 {
46 Name identityName("/localhost/ControllerFixture");
47 if (this->addIdentity(identityName)) {
48 m_keyChain.setDefaultIdentity(identityName);
49 }
50 else {
51 BOOST_FAIL("cannot create identity");
52 }
53 }
54
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000055 /** \brief controls whether Controller's validator should accept or reject validation requests
56 *
57 * Initially, the validator accepts all requests.
58 * Setting \p false causes validator to reject all requests.
59 */
60 void
61 setValidationResult(bool shouldAccept)
62 {
63 m_validator.setResult(shouldAccept);
64 }
65
Junxiao Shi034c1882016-06-24 18:06:51 +000066private:
67 void
68 fail(uint32_t code, const std::string& reason)
69 {
70 failCodes.push_back(code);
71 }
72
73protected:
74 ndn::util::DummyClientFace face;
75 Controller controller;
76 Controller::CommandFailCallback failCallback;
77 std::vector<uint32_t> failCodes;
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000078
79private:
80 DummyValidator m_validator;
Junxiao Shi034c1882016-06-24 18:06:51 +000081};
82
83} // namespace tests
84} // namespace nfd
85} // namespace ndn
86
87#endif // NDN_TESTS_MANAGEMENT_NFD_CONTROLLER_FIXTURE_HPP