Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, 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 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 26 | #ifndef NFD_TESTS_DUMMY_CLIENT_FACE_HPP |
| 27 | #define NFD_TESTS_DUMMY_CLIENT_FACE_HPP |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 28 | |
| 29 | #include <ndn-cxx/face.hpp> |
| 30 | #include <ndn-cxx/transport/transport.hpp> |
| 31 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 32 | namespace nfd { |
| 33 | namespace tests { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 34 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 35 | class DummyClientTransport : public ndn::Transport |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 36 | { |
| 37 | public: |
| 38 | void |
| 39 | receive(const Block& block) |
| 40 | { |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 41 | if (static_cast<bool>(m_receiveCallback)) |
| 42 | m_receiveCallback(block); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | virtual void |
| 46 | close() |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | virtual void |
| 51 | pause() |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | virtual void |
| 56 | resume() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | virtual void |
| 61 | send(const Block& wire) |
| 62 | { |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 63 | if (wire.type() == tlv::Interest) { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 64 | m_sentInterests->push_back(Interest(wire)); |
| 65 | } |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 66 | else if (wire.type() == tlv::Data) { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 67 | m_sentDatas->push_back(Data(wire)); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | virtual void |
| 72 | send(const Block& header, const Block& payload) |
| 73 | { |
| 74 | this->send(payload); |
| 75 | } |
| 76 | |
| 77 | public: |
| 78 | std::vector<Interest>* m_sentInterests; |
| 79 | std::vector<Data>* m_sentDatas; |
| 80 | }; |
| 81 | |
| 82 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 83 | /** \brief a client-side face for unit testing |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 84 | */ |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 85 | class DummyClientFace : public ndn::Face |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 86 | { |
| 87 | public: |
| 88 | explicit |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 89 | DummyClientFace(shared_ptr<DummyClientTransport> transport) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 90 | : Face(transport) |
| 91 | , m_transport(transport) |
| 92 | { |
| 93 | m_transport->m_sentInterests = &m_sentInterests; |
| 94 | m_transport->m_sentDatas = &m_sentDatas; |
| 95 | } |
| 96 | |
| 97 | /** \brief cause the Face to receive a packet |
| 98 | */ |
| 99 | template<typename Packet> |
| 100 | void |
| 101 | receive(const Packet& packet) |
| 102 | { |
| 103 | m_transport->receive(packet.wireEncode()); |
| 104 | } |
| 105 | |
| 106 | public: |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 107 | /** \brief sent Interests |
| 108 | * \note After .expressInterest, .processEvents must be called before |
| 109 | * the Interest would show up here. |
| 110 | */ |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 111 | std::vector<Interest> m_sentInterests; |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 112 | /** \brief sent Datas |
| 113 | * \note After .put, .processEvents must be called before |
| 114 | * the Interest would show up here. |
| 115 | */ |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 116 | std::vector<Data> m_sentDatas; |
| 117 | |
| 118 | private: |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 119 | shared_ptr<DummyClientTransport> m_transport; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 120 | }; |
| 121 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 122 | inline shared_ptr<DummyClientFace> |
| 123 | makeDummyClientFace() |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 124 | { |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 125 | return make_shared<DummyClientFace>(make_shared<DummyClientTransport>()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 128 | } // namespace tests |
| 129 | } // namespace nfd |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 130 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 131 | #endif // NFD_TESTS_DUMMY_CLIENT_FACE_HPP |