Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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_DUMMY_TRANSPORT_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |
| 28 | |
| 29 | #include "common.hpp" |
| 30 | |
| 31 | #include "face/transport.hpp" |
| 32 | |
| 33 | namespace nfd { |
| 34 | namespace face { |
| 35 | namespace tests { |
| 36 | |
| 37 | /** \brief dummy Transport used in unit tests |
| 38 | */ |
| 39 | class DummyTransport : public Transport |
| 40 | { |
| 41 | public: |
| 42 | DummyTransport(const std::string& localUri = "dummy://", |
| 43 | const std::string& remoteUri = "dummy://", |
| 44 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 45 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 46 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT) |
| 47 | : isClosed(false) |
| 48 | { |
| 49 | this->setLocalUri(FaceUri(localUri)); |
| 50 | this->setRemoteUri(FaceUri(remoteUri)); |
| 51 | this->setScope(scope); |
| 52 | this->setPersistency(persistency); |
| 53 | this->setLinkType(linkType); |
Junxiao Shi | 5b8a2b2 | 2015-10-22 17:20:44 -0700 | [diff] [blame] | 54 | this->setMtu(MTU_UNLIMITED); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
| 58 | setState(FaceState state) |
| 59 | { |
| 60 | this->Transport::setState(state); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | receivePacket(Packet&& packet) |
| 65 | { |
| 66 | this->receive(std::move(packet)); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | receivePacket(Block block) |
| 71 | { |
| 72 | this->receive(Packet(std::move(block))); |
| 73 | } |
| 74 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame^] | 75 | protected: |
| 76 | virtual void |
| 77 | beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) DECL_OVERRIDE |
| 78 | { |
| 79 | // accept everything |
| 80 | } |
| 81 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 82 | private: |
| 83 | virtual void |
| 84 | doClose() DECL_OVERRIDE |
| 85 | { |
| 86 | isClosed = true; |
| 87 | } |
| 88 | |
| 89 | virtual void |
| 90 | doSend(Packet&& packet) DECL_OVERRIDE |
| 91 | { |
| 92 | sentPackets.push_back(std::move(packet)); |
| 93 | } |
| 94 | |
| 95 | public: |
| 96 | bool isClosed; |
| 97 | std::vector<Packet> sentPackets; |
| 98 | }; |
| 99 | |
| 100 | } // namespace tests |
| 101 | } // namespace face |
| 102 | } // namespace nfd |
| 103 | |
| 104 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |