blob: 7039286289e4fed0f9ff42e33a86bc10d56fd3f8 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shicbba04c2014-01-26 14:21:22 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP
26#define NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070027
28#include "face/face.hpp"
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080029#include "face/local-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070033
34/** \class DummyFace
Junxiao Shi9b27bd22014-02-26 20:29:58 -070035 * \brief a Face for unit testing
Junxiao Shicbba04c2014-01-26 14:21:22 -070036 */
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080037template<class FaceBase>
38class DummyFaceImpl : public FaceBase
Junxiao Shicbba04c2014-01-26 14:21:22 -070039{
40public:
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000041 DummyFaceImpl()
Junxiao Shi79494162014-04-02 18:25:11 -070042 : FaceBase(FaceUri("dummy://"), FaceUri("dummy://"))
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000043 {
44 }
45
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 virtual void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070047 sendInterest(const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 {
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000049 this->onSendInterest(interest);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070050 m_sentInterests.push_back(interest);
51 this->afterSend();
Junxiao Shicbba04c2014-01-26 14:21:22 -070052 }
Junxiao Shi9b27bd22014-02-26 20:29:58 -070053
Junxiao Shicbba04c2014-01-26 14:21:22 -070054 virtual void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055 sendData(const Data& data)
Junxiao Shicbba04c2014-01-26 14:21:22 -070056 {
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000057 this->onSendData(data);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070058 m_sentDatas.push_back(data);
59 this->afterSend();
Junxiao Shicbba04c2014-01-26 14:21:22 -070060 }
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080061
62 virtual void
63 close()
64 {
Junxiao Shic542b2b2014-03-16 21:45:52 -070065 this->onFail("close");
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080066 }
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -080067
Junxiao Shi9b27bd22014-02-26 20:29:58 -070068 void
69 receiveInterest(const Interest& interest)
70 {
71 this->onReceiveInterest(interest);
72 }
73
74 void
75 receiveData(const Data& data)
76 {
77 this->onReceiveData(data);
78 }
79
Junxiao Shid9ee45c2014-02-27 15:38:11 -070080 EventEmitter<> afterSend;
Junxiao Shi9b27bd22014-02-26 20:29:58 -070081
82public:
83 std::vector<Interest> m_sentInterests;
84 std::vector<Data> m_sentDatas;
Junxiao Shicbba04c2014-01-26 14:21:22 -070085};
86
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080087typedef DummyFaceImpl<Face> DummyFace;
88typedef DummyFaceImpl<LocalFace> DummyLocalFace;
89
Junxiao Shid9ee45c2014-02-27 15:38:11 -070090} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080091} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070092
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070093#endif // NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP