blob: 38b44fdeb91d4d9ffb2056348d2b94312de21bdc [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08002/*
Davide Pesavento187e9f92023-03-20 22:46:22 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Junxiao Shi034c1882016-06-24 18:06:51 +00004 *
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
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050022#ifndef NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
23#define NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
Junxiao Shi034c1882016-06-24 18:06:51 +000024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/mgmt/nfd/controller.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050026#include "ndn-cxx/util/dummy-client-face.hpp"
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000027
Davide Pesavento7e780642018-11-24 15:51:34 -050028#include "tests/unit/dummy-validator.hpp"
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050029#include "tests/unit/io-key-chain-fixture.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000030
31namespace ndn {
32namespace nfd {
33namespace tests {
34
35using namespace ndn::tests;
36
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050037class ControllerFixture : public IoKeyChainFixture
Junxiao Shi034c1882016-06-24 18:06:51 +000038{
39protected:
40 ControllerFixture()
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050041 : face(m_io, m_keyChain)
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080042 , m_validator(true)
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000043 , controller(face, m_keyChain, m_validator)
Davide Pesavento2e481fc2021-07-02 18:20:03 -040044 , commandFailCallback([this] (const auto& resp) { failCodes.push_back(resp.getCode()); })
45 , datasetFailCallback([this] (auto code, const auto&) { failCodes.push_back(code); })
Junxiao Shi034c1882016-06-24 18:06:51 +000046 {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050047 m_keyChain.setDefaultIdentity(m_keyChain.createIdentity("/localhost/ControllerFixture"));
Junxiao Shi034c1882016-06-24 18:06:51 +000048 }
49
Davide Pesaventoc860bd12022-10-04 03:23:43 -040050 /** \brief Controls whether Controller's validator should accept or reject validation requests.
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000051 *
52 * Initially, the validator accepts all requests.
53 * Setting \p false causes validator to reject all requests.
54 */
55 void
56 setValidationResult(bool shouldAccept)
57 {
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080058 m_validator.getPolicy().setResult(shouldAccept);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000059 }
60
Junxiao Shi034c1882016-06-24 18:06:51 +000061protected:
62 ndn::util::DummyClientFace face;
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080063 DummyValidator m_validator;
Junxiao Shi034c1882016-06-24 18:06:51 +000064 Controller controller;
Davide Pesavento09103432023-03-24 20:30:41 -040065 CommandFailureCallback commandFailCallback;
66 DatasetFailureCallback datasetFailCallback;
Junxiao Shi034c1882016-06-24 18:06:51 +000067 std::vector<uint32_t> failCodes;
Junxiao Shi034c1882016-06-24 18:06:51 +000068};
69
70} // namespace tests
71} // namespace nfd
72} // namespace ndn
73
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050074#endif // NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP