Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 1 | /* -*- 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 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame^] | 22 | #ifndef NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP |
| 23 | #define NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 24 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame^] | 25 | #include "mgmt/nfd/controller.hpp" |
| 26 | #include "../../../dummy-validator.hpp" |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 27 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 28 | #include "boost-test.hpp" |
| 29 | #include "util/dummy-client-face.hpp" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame^] | 30 | #include "../../identity-management-time-fixture.hpp" |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 31 | |
| 32 | namespace ndn { |
| 33 | namespace nfd { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace ndn::tests; |
| 37 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 38 | class ControllerFixture : public IdentityManagementTimeFixture |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 39 | { |
| 40 | protected: |
| 41 | ControllerFixture() |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 42 | : face(io, m_keyChain) |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 43 | , controller(face, m_keyChain, m_validator) |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 44 | , commandFailCallback(bind(&ControllerFixture::recordCommandFail, this, _1)) |
| 45 | , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2)) |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 46 | { |
| 47 | Name identityName("/localhost/ControllerFixture"); |
| 48 | if (this->addIdentity(identityName)) { |
| 49 | m_keyChain.setDefaultIdentity(identityName); |
| 50 | } |
| 51 | else { |
| 52 | BOOST_FAIL("cannot create identity"); |
| 53 | } |
| 54 | } |
| 55 | |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 56 | /** \brief controls whether Controller's validator should accept or reject validation requests |
| 57 | * |
| 58 | * Initially, the validator accepts all requests. |
| 59 | * Setting \p false causes validator to reject all requests. |
| 60 | */ |
| 61 | void |
| 62 | setValidationResult(bool shouldAccept) |
| 63 | { |
| 64 | m_validator.setResult(shouldAccept); |
| 65 | } |
| 66 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 67 | private: |
| 68 | void |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 69 | recordCommandFail(const ControlResponse& response) |
| 70 | { |
| 71 | failCodes.push_back(response.getCode()); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | recordDatasetFail(uint32_t code, const std::string& reason) |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 76 | { |
| 77 | failCodes.push_back(code); |
| 78 | } |
| 79 | |
| 80 | protected: |
| 81 | ndn::util::DummyClientFace face; |
| 82 | Controller controller; |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 83 | Controller::CommandFailCallback commandFailCallback; |
| 84 | Controller::DatasetFailCallback datasetFailCallback; |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 85 | std::vector<uint32_t> failCodes; |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | DummyValidator m_validator; |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace nfd |
| 93 | } // namespace ndn |
| 94 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame^] | 95 | #endif // NDN_TESTS_MGMT_NFD_CONTROLLER_FIXTURE_HPP |