Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 4 | * 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 Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 30 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 32 | #include "tests/daemon/limited-io.hpp" |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 33 | |
| 34 | #include <type_traits> |
| 35 | |
| 36 | namespace nfd { |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 37 | namespace face { |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 38 | namespace tests { |
| 39 | |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 40 | using namespace nfd::tests; |
| 41 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 42 | template<class ChannelT, class EndpointT> |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 43 | class ChannelFixture : public GlobalIoFixture |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 44 | { |
| 45 | static_assert(std::is_base_of<Channel, ChannelT>::value, |
| 46 | "ChannelFixture must be instantiated with a type derived from Channel"); |
| 47 | |
| 48 | public: |
| 49 | virtual |
| 50 | ~ChannelFixture() = default; |
| 51 | |
| 52 | static void |
| 53 | unexpectedFailure(uint32_t status, const std::string& reason) |
| 54 | { |
| 55 | BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]"); |
| 56 | } |
| 57 | |
| 58 | protected: |
| 59 | uint16_t |
| 60 | getNextPort() |
| 61 | { |
| 62 | return m_nextPort++; |
| 63 | } |
| 64 | |
| 65 | virtual unique_ptr<ChannelT> |
| 66 | makeChannel() |
| 67 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 68 | BOOST_FAIL("Unimplemented"); |
| 69 | return nullptr; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 72 | virtual unique_ptr<ChannelT> |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 73 | makeChannel(const boost::asio::ip::address&, uint16_t port = 0) |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 74 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 75 | BOOST_FAIL("Unimplemented"); |
| 76 | return nullptr; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void |
| 80 | listen(const boost::asio::ip::address& addr) |
| 81 | { |
| 82 | listenerEp = EndpointT{addr, 7030}; |
| 83 | listenerChannel = makeChannel(addr, 7030); |
| 84 | listenerChannel->listen( |
| 85 | [this] (const shared_ptr<Face>& newFace) { |
| 86 | BOOST_REQUIRE(newFace != nullptr); |
| 87 | connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); }); |
| 88 | listenerFaces.push_back(newFace); |
| 89 | limitedIo.afterOp(); |
| 90 | }, |
| 91 | ChannelFixture::unexpectedFailure); |
| 92 | } |
| 93 | |
| 94 | virtual void |
| 95 | connect(ChannelT&) |
| 96 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 97 | BOOST_FAIL("Unimplemented"); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | protected: |
| 101 | LimitedIo limitedIo; |
| 102 | EndpointT listenerEp; |
| 103 | unique_ptr<ChannelT> listenerChannel; |
| 104 | std::vector<shared_ptr<Face>> listenerFaces; |
| 105 | |
| 106 | private: |
| 107 | uint16_t m_nextPort = 7050; |
| 108 | }; |
| 109 | |
| 110 | } // namespace tests |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 111 | } // namespace face |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 112 | } // namespace nfd |
| 113 | |
| 114 | #endif // NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP |