blob: 1c7252e9fa3e53de7dc6ca32a76344edbc7f2d22 [file] [log] [blame]
Eric Newberry42602412016-08-27 09:33:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry944f38b2017-07-20 20:54:22 -04002/*
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Eric Newberry42602412016-08-27 09:33:18 -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
26#ifndef NFD_TESTS_DAEMON_FACE_FACTORY_TEST_COMMON_HPP
27#define NFD_TESTS_DAEMON_FACE_FACTORY_TEST_COMMON_HPP
28
29#include "face/protocol-factory.hpp"
30
31#include "tests/test-common.hpp"
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::tests {
Eric Newberry42602412016-08-27 09:33:18 -070034
35struct CreateFaceExpectedResult
36{
37 enum { FAILURE, SUCCESS } result;
38 uint32_t status;
39 std::string reason;
40};
41
42inline void
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040043createFace(face::ProtocolFactory& factory,
Eric Newberry78e32b02017-04-01 14:34:44 +000044 const FaceUri& remoteUri,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040045 const std::optional<FaceUri>& localUri,
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040046 const face::FaceParams& params,
Alexander Afanasyevded17422018-04-03 19:00:23 -040047 const CreateFaceExpectedResult& expected,
48 const std::function<void(const Face&)>& extraChecks = nullptr)
Eric Newberry42602412016-08-27 09:33:18 -070049{
Davide Pesavento15b55052018-01-27 19:09:28 -050050 factory.createFace({remoteUri, localUri, params},
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040051 [result = expected.result, extraChecks] (const auto& face) {
52 BOOST_CHECK_EQUAL(CreateFaceExpectedResult::SUCCESS, result);
Alexander Afanasyevded17422018-04-03 19:00:23 -040053 if (extraChecks) {
54 extraChecks(*face);
55 }
Eric Newberry42602412016-08-27 09:33:18 -070056 },
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040057 [expected] (uint32_t actualStatus, const auto& actualReason) {
Eric Newberry42602412016-08-27 09:33:18 -070058 BOOST_CHECK_EQUAL(CreateFaceExpectedResult::FAILURE, expected.result);
59 BOOST_CHECK_EQUAL(actualStatus, expected.status);
60 BOOST_CHECK_EQUAL(actualReason, expected.reason);
61 });
62}
63
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040064/**
65 * \brief Check that channels in a factory equal given channel URIs
Junxiao Shi3409cd32017-01-18 15:31:27 +000066 */
67inline void
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040068checkChannelListEqual(const face::ProtocolFactory& factory, std::set<std::string> expectedUris)
Junxiao Shi3409cd32017-01-18 15:31:27 +000069{
Junxiao Shi3409cd32017-01-18 15:31:27 +000070 for (const auto& channel : factory.getChannels()) {
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040071 auto uri = channel->getUri().toString();
72 if (expectedUris.erase(uri) == 0) {
Junxiao Shi3409cd32017-01-18 15:31:27 +000073 BOOST_ERROR("Unexpected channel " << uri);
74 }
75 }
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040076 for (const auto& uri : expectedUris) {
Junxiao Shi3409cd32017-01-18 15:31:27 +000077 BOOST_ERROR("Missing channel " << uri);
78 }
79}
80
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040081} // namespace nfd::tests
Eric Newberry42602412016-08-27 09:33:18 -070082
83#endif // NFD_TESTS_DAEMON_FACE_FACTORY_TEST_COMMON_HPP