Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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_TCP_CHANNEL_FIXTURE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_TCP_CHANNEL_FIXTURE_HPP |
| 28 | |
| 29 | #include "face/tcp-channel.hpp" |
| 30 | |
| 31 | #include "channel-fixture.hpp" |
| 32 | |
| 33 | namespace nfd { |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 34 | namespace face { |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
| 37 | class TcpChannelFixture : public ChannelFixture<TcpChannel, tcp::Endpoint> |
| 38 | { |
| 39 | protected: |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 40 | unique_ptr<TcpChannel> |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 41 | makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final |
| 42 | { |
| 43 | if (port == 0) |
| 44 | port = getNextPort(); |
| 45 | |
| 46 | return make_unique<TcpChannel>(tcp::Endpoint(addr, port)); |
| 47 | } |
| 48 | |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 49 | void |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 50 | connect(TcpChannel& channel) final |
| 51 | { |
| 52 | g_io.post([&] { |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 53 | channel.connect(listenerEp, ndn::nfd::FACE_PERSISTENCY_PERSISTENT, false, false, |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 54 | [this] (const shared_ptr<Face>& newFace) { |
| 55 | BOOST_REQUIRE(newFace != nullptr); |
| 56 | connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); }); |
| 57 | clientFaces.push_back(newFace); |
| 58 | limitedIo.afterOp(); |
| 59 | }, |
| 60 | ChannelFixture::unexpectedFailure); |
| 61 | }); |
| 62 | } |
| 63 | |
| 64 | protected: |
| 65 | std::vector<shared_ptr<Face>> clientFaces; |
| 66 | }; |
| 67 | |
| 68 | } // namespace tests |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 69 | } // namespace face |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 70 | } // namespace nfd |
| 71 | |
| 72 | #endif // NFD_TESTS_DAEMON_FACE_TCP_CHANNEL_FIXTURE_HPP |