blob: 6ed7d467e704ab54961091e01e989ecaafbcfedd [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shi08d07a72014-06-09 23:17:57 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
Junxiao Shi08d07a72014-06-09 23:17:57 -070026#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP
27#define NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070028
29#include "face/face.hpp"
30
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
Junxiao Shi0de23a22015-12-03 20:07:02 +000034/** \brief a Face for unit testing
Junxiao Shicbba04c2014-01-26 14:21:22 -070035 */
Junxiao Shi0de23a22015-12-03 20:07:02 +000036class DummyFace : public Face
Junxiao Shicbba04c2014-01-26 14:21:22 -070037{
38public:
Junxiao Shi0de23a22015-12-03 20:07:02 +000039 explicit
40 DummyFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://",
41 bool isLocal = false)
42 : Face(FaceUri(remoteUri), FaceUri(localUri), isLocal)
Chengyu Fan320d2332014-10-29 16:40:33 -060043 {
44 }
45
Davide Pesavento66ff0982015-01-29 22:39:00 +010046 void
47 sendInterest(const Interest& interest) DECL_OVERRIDE
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 {
Junxiao Shic099ddb2014-12-25 20:53:20 -070049 this->emitSignal(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
Davide Pesavento66ff0982015-01-29 22:39:00 +010054 void
55 sendData(const Data& data) DECL_OVERRIDE
Junxiao Shicbba04c2014-01-26 14:21:22 -070056 {
Junxiao Shic099ddb2014-12-25 20:53:20 -070057 this->emitSignal(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
Davide Pesavento66ff0982015-01-29 22:39:00 +010062 void
63 close() DECL_OVERRIDE
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080064 {
Junxiao Shic099ddb2014-12-25 20:53:20 -070065 this->fail("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 {
Junxiao Shic099ddb2014-12-25 20:53:20 -070071 this->emitSignal(onReceiveInterest, interest);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070072 }
73
74 void
75 receiveData(const Data& data)
76 {
Junxiao Shic099ddb2014-12-25 20:53:20 -070077 this->emitSignal(onReceiveData, data);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070078 }
79
Junxiao Shi0de23a22015-12-03 20:07:02 +000080 signal::Signal<DummyFace> 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
Junxiao Shi0de23a22015-12-03 20:07:02 +000087class DummyLocalFace : public DummyFace
88{
89public:
90 explicit
91 DummyLocalFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://")
92 : DummyFace(remoteUri, localUri, true)
93 {
94 }
95};
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080096
Junxiao Shid9ee45c2014-02-27 15:38:11 -070097} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080098} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070099
Junxiao Shi08d07a72014-06-09 23:17:57 -0700100#endif // NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP