blob: 56ef8caa1ade5e16b1872d500901947246c7ab04 [file] [log] [blame]
Vince Lehman904c2412014-09-23 19:36:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 **/
21
22#ifndef NLSR_TEST_DUMMY_FACE_HPP
23#define NLSR_TEST_DUMMY_FACE_HPP
24
25#include <ndn-cxx/face.hpp>
26#include <ndn-cxx/transport/transport.hpp>
27
28namespace ndn {
29
30class DummyTransport : public Transport
31{
32public:
33 void
34 receive(const Block& block)
35 {
36 m_receiveCallback(block);
37 }
38
39 virtual void
40 close()
41 {
42 }
43
44 virtual void
45 pause()
46 {
47 }
48
49 virtual void
50 resume()
51 {
52 }
53
54 virtual void
55 send(const Block& wire)
56 {
Junxiao Shi92e5ffb2014-10-19 09:45:55 -070057 if (wire.type() == tlv::Interest) {
Vince Lehman904c2412014-09-23 19:36:11 -050058 m_sentInterests->push_back(Interest(wire));
59 }
Junxiao Shi92e5ffb2014-10-19 09:45:55 -070060 else if (wire.type() == tlv::Data) {
Vince Lehman904c2412014-09-23 19:36:11 -050061 m_sentDatas->push_back(Data(wire));
62 }
63 }
64
65 virtual void
66 send(const Block& header, const Block& payload)
67 {
68 this->send(payload);
69 }
70
71public:
72 std::vector<Interest>* m_sentInterests;
73 std::vector<Data>* m_sentDatas;
74};
75
76
77/** \brief a Face for unit testing
78 */
79class DummyFace : public Face
80{
81public:
82 explicit
83 DummyFace(shared_ptr<DummyTransport> transport)
84 : Face(transport)
85 , m_transport(transport)
86 {
87 m_transport->m_sentInterests = &m_sentInterests;
88 m_transport->m_sentDatas = &m_sentDatas;
89 }
90
91 /** \brief cause the Face to receive a packet
92 */
93 template<typename Packet>
94 void
95 receive(const Packet& packet)
96 {
97 m_transport->receive(packet.wireEncode());
98 }
99
100public:
101 std::vector<Interest> m_sentInterests;
102 std::vector<Data> m_sentDatas;
103
104private:
105 shared_ptr<DummyTransport> m_transport;
106};
107
108inline shared_ptr<DummyFace>
109makeDummyFace()
110{
111 return make_shared<DummyFace>(make_shared<DummyTransport>());
112}
113
114} // namespace ndn
115
Junxiao Shi92e5ffb2014-10-19 09:45:55 -0700116#endif // NLSR_TEST_DUMMY_FACE_HPP