blob: 8f94a0977c9949bdc5cfc82936551d5f0793ef3a [file] [log] [blame]
Davide Pesavento9a00fab2016-09-27 11:22:46 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento19779d82019-02-14 13:40:04 -05002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Davide Pesavento9a00fab2016-09-27 11:22:46 +02004 * 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_CHANNEL_FIXTURE_HPP
27#define NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP
28
29#include "face/channel.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060030
31#include "tests/daemon/limited-io.hpp"
Davide Pesavento9a00fab2016-09-27 11:22:46 +020032
33#include <type_traits>
34
35namespace nfd {
Davide Pesavento8fd15e62017-04-06 19:58:54 -040036namespace face {
Davide Pesavento9a00fab2016-09-27 11:22:46 +020037namespace tests {
38
Davide Pesavento8fd15e62017-04-06 19:58:54 -040039using namespace nfd::tests;
40
Davide Pesavento9a00fab2016-09-27 11:22:46 +020041template<class ChannelT, class EndpointT>
42class ChannelFixture : public BaseFixture
43{
44 static_assert(std::is_base_of<Channel, ChannelT>::value,
45 "ChannelFixture must be instantiated with a type derived from Channel");
46
47public:
48 virtual
49 ~ChannelFixture() = default;
50
51 static void
52 unexpectedFailure(uint32_t status, const std::string& reason)
53 {
54 BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]");
55 }
56
57protected:
58 uint16_t
59 getNextPort()
60 {
61 return m_nextPort++;
62 }
63
64 virtual unique_ptr<ChannelT>
65 makeChannel()
66 {
Davide Pesavento19779d82019-02-14 13:40:04 -050067 BOOST_FAIL("Unimplemented");
68 return nullptr;
Davide Pesavento9a00fab2016-09-27 11:22:46 +020069 }
70
Davide Pesavento9a00fab2016-09-27 11:22:46 +020071 virtual unique_ptr<ChannelT>
Davide Pesavento19779d82019-02-14 13:40:04 -050072 makeChannel(const boost::asio::ip::address&, uint16_t port = 0)
Davide Pesavento9a00fab2016-09-27 11:22:46 +020073 {
Davide Pesavento19779d82019-02-14 13:40:04 -050074 BOOST_FAIL("Unimplemented");
75 return nullptr;
Davide Pesavento9a00fab2016-09-27 11:22:46 +020076 }
77
78 void
79 listen(const boost::asio::ip::address& addr)
80 {
81 listenerEp = EndpointT{addr, 7030};
82 listenerChannel = makeChannel(addr, 7030);
83 listenerChannel->listen(
84 [this] (const shared_ptr<Face>& newFace) {
85 BOOST_REQUIRE(newFace != nullptr);
86 connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); });
87 listenerFaces.push_back(newFace);
88 limitedIo.afterOp();
89 },
90 ChannelFixture::unexpectedFailure);
91 }
92
93 virtual void
94 connect(ChannelT&)
95 {
Davide Pesavento19779d82019-02-14 13:40:04 -050096 BOOST_FAIL("Unimplemented");
Davide Pesavento9a00fab2016-09-27 11:22:46 +020097 }
98
99protected:
100 LimitedIo limitedIo;
101 EndpointT listenerEp;
102 unique_ptr<ChannelT> listenerChannel;
103 std::vector<shared_ptr<Face>> listenerFaces;
104
105private:
106 uint16_t m_nextPort = 7050;
107};
108
109} // namespace tests
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400110} // namespace face
Davide Pesavento9a00fab2016-09-27 11:22:46 +0200111} // namespace nfd
112
113#endif // NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP