blob: 4fde76f2e99fe19a5fc1eab5e4a67ab827f44f43 [file] [log] [blame]
Vince Lehman72446ec2014-07-09 10:50:02 -05001/* -*- 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
26#ifndef RIB_TESTS_UNIT_TESTS_TRANSPORT_DUMMY_FACE_HPP
27#define RIB_TESTS_UNIT_TESTS_TRANSPORT_DUMMY_FACE_HPP
28
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/transport/transport.hpp>
31
32namespace ndn {
33
34class DummyTransport : public Transport
35{
36public:
37 void
38 receive(const Block& block)
39 {
40 m_receiveCallback(block);
41 }
42
43 virtual void
44 close()
45 {
46 }
47
48 virtual void
49 pause()
50 {
51 }
52
53 virtual void
54 resume()
55 {
56 }
57
58 virtual void
59 send(const Block& wire)
60 {
61 if (wire.type() == Tlv::Interest) {
62 m_sentInterests->push_back(Interest(wire));
63 }
64 else if (wire.type() == Tlv::Data) {
65 m_sentDatas->push_back(Data(wire));
66 }
67 }
68
69 virtual void
70 send(const Block& header, const Block& payload)
71 {
72 this->send(payload);
73 }
74
75public:
76 std::vector<Interest>* m_sentInterests;
77 std::vector<Data>* m_sentDatas;
78};
79
80
81/** \brief a Face for unit testing
82 */
83class DummyFace : public Face
84{
85public:
86 explicit
87 DummyFace(shared_ptr<DummyTransport> transport)
88 : Face(transport)
89 , m_transport(transport)
90 {
91 m_transport->m_sentInterests = &m_sentInterests;
92 m_transport->m_sentDatas = &m_sentDatas;
93 }
94
95 /** \brief cause the Face to receive a packet
96 */
97 template<typename Packet>
98 void
99 receive(const Packet& packet)
100 {
101 m_transport->receive(packet.wireEncode());
102 }
103
104public:
105 std::vector<Interest> m_sentInterests;
106 std::vector<Data> m_sentDatas;
107
108private:
109 shared_ptr<DummyTransport> m_transport;
110};
111
112inline shared_ptr<DummyFace>
113makeDummyFace()
114{
115 return make_shared<DummyFace>(make_shared<DummyTransport>());
116}
117
118} // namespace ndn
119
120#endif // RIB_TESTS_UNIT_TESTS_TRANSPORT_DUMMY_FACE_HPP