blob: b8294762dd4ceec0b773971fee914ffb81699119 [file] [log] [blame]
Yanbiao Li698f4fe2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Li698f4fe2015-08-19 16:30:16 -07004 * 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 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Yanbiao Lidf846e52016-01-30 21:53:47 -080026#ifndef NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP
27#define NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP
Yanbiao Li698f4fe2015-08-19 16:30:16 -070028
29#include "tests/test-common.hpp"
30#include "tests/identity-management-fixture.hpp"
Yanbiao Lidf846e52016-01-30 21:53:47 -080031#include "core/manager-base.hpp"
Yanbiao Li698f4fe2015-08-19 16:30:16 -070032
33#include <ndn-cxx/mgmt/dispatcher.hpp>
34#include <ndn-cxx/util/dummy-client-face.hpp>
35
36namespace nfd {
37namespace tests {
38
39/**
40 * @brief a collection of common functions shared by all manager's testing fixtures.
41 */
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000042class ManagerCommonFixture : public IdentityManagementTimeFixture
Yanbiao Li698f4fe2015-08-19 16:30:16 -070043{
44public: // initialize
45 ManagerCommonFixture();
46
47 /**
Yanbiao Lidf846e52016-01-30 21:53:47 -080048 * @brief set topPrefix to the dispatcher.
Yanbiao Li698f4fe2015-08-19 16:30:16 -070049 *
50 * after setting @param topPrefix, call advanceClocks to ensure all added filters take effects.
51 *
52 * @param topPrefix top prefix for the dispatcher
Yanbiao Li698f4fe2015-08-19 16:30:16 -070053 */
54 void
Yanbiao Lidf846e52016-01-30 21:53:47 -080055 setTopPrefix(const Name& topPrefix);
Yanbiao Li698f4fe2015-08-19 16:30:16 -070056
57public: // test
58 typedef std::function<void(shared_ptr<Interest> interest)> InterestHandler;
59
60 /**
61 * @brief create a ControlCommand request
62 *
63 * step1: append the @param parameters to the @param commandName and make an Interest.
64 * step2: call @param beforeSinging to do something with the Interest.
65 * step3: sign the generated command
66 *
67 * @param commandName the command name
68 * @param parameters the ControlParameters
69 * @param beforeSigning a callback that can modify the Interest before it's signed
70 *
71 * @return the signed ControlCommand request
72 */
73 shared_ptr<Interest>
74 makeControlCommandRequest(Name commandName,
75 const ControlParameters& parameters,
76 const InterestHandler& beforeSigning = nullptr);
77
78 /**
79 * @brief cause management to receive an Interest
80 *
81 * call DummyClientFace::receive to receive Interest and then call advanceClocks to ensure
82 * the Interest dispatched
83 *
84 * @param interest the Interest to receive
85 */
86 void
87 receiveInterest(shared_ptr<Interest> interest);
88
89public: // verify
90 ControlResponse
91 makeResponse(uint32_t code, const std::string& text,
92 const ControlParameters& parameters);
93
94 enum class CheckResponseResult
95 {
96 OK,
97 OUT_OF_BOUNDARY,
98 WRONG_NAME,
99 WRONG_CONTENT_TYPE,
100 INVALID_RESPONSE,
101 WRONG_CODE,
102 WRONG_TEXT,
103 WRONG_BODY_SIZE,
104 WRONG_BODY_VALUE
Davide Pesavento35120ea2015-11-17 21:13:18 +0100105 };
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700106
107 /**
108 * @brief check a specified response data with the expected ControlResponse
109 *
110 * @param idx the index of the specified Data in m_responses
111 * @param expectedDataName the expected name of this Data
112 * @param expectedResponse the expected ControlResponse
113 * @param expectedContentType the expected content type of this Data, use -1 to skip this check
114 *
115 * @retval OK the response at the specified index can be decoded from the response data,
116 * and its code, text and response body are all matched with the expected response
117 * @retval OUT_OF_BOUNDARY the specified index out of boundary
118 * @retval WRONG_NAME the name of the specified response data does not match
119 * @retval WRONG_CONTENT_TYPE the content type of the specified response data does not match
120 * @retval INVALID_RESPONSE the data name matches but it fails in decoding a ControlResponse from
121 * the content of the specified response data
122 * @retval WRONG_CODE a valid ControlResponse can be decoded but has a wrong code
123 * @retval WRONG_TEXT a valid ControlResponse can be decoded but has a wrong text
124 * @retval WRONG_BODY_SIZE the body size of decoded ControlResponse does not match
125 * @retval WRONT_BODY_VALUE the body value of decoded ControlResponse does not match
126 */
127 CheckResponseResult
128 checkResponse(size_t idx,
129 const Name& expectedName,
130 const ControlResponse& expectedResponse,
131 int expectedContentType = -1);
132
133 /**
134 * @brief concatenate specified response Data into a single block
135 *
136 * @param startIndex the start index in m_responses
137 * @param nResponses the number of response to concatenate
138 *
139 * @return the generated block
140 */
141 Block
142 concatenateResponses(size_t startIndex = 0, size_t nResponses = 0);
143
144protected:
Junxiao Shi221b6fe2016-07-14 18:21:56 +0000145 ndn::util::DummyClientFace m_face;
146 ndn::mgmt::Dispatcher m_dispatcher;
147 std::vector<Data>& m_responses; ///< a reference of m_face->sentData
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000148 Name m_identityName; ///< the identity to sign requests
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700149};
150
151std::ostream&
152operator<<(std::ostream &os, const ManagerCommonFixture::CheckResponseResult& result);
153
154} // namespace tests
155} // namespace nfd
156
Yanbiao Lidf846e52016-01-30 21:53:47 -0800157#endif // NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP