blob: a28a1bb0f1d0afddabec0f150757e56d4a4a7eb1 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_TEST_FACE_DUMMY_FACE_HPP
8#define NFD_TEST_FACE_DUMMY_FACE_HPP
9
10#include "face/face.hpp"
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080011#include "face/local-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070012
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080013namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070014namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070015
16/** \class DummyFace
Junxiao Shi9b27bd22014-02-26 20:29:58 -070017 * \brief a Face for unit testing
Junxiao Shicbba04c2014-01-26 14:21:22 -070018 */
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080019template<class FaceBase>
20class DummyFaceImpl : public FaceBase
Junxiao Shicbba04c2014-01-26 14:21:22 -070021{
22public:
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000023 DummyFaceImpl()
24 : FaceBase(FaceUri("dummy://"))
25 {
26 }
27
Junxiao Shicbba04c2014-01-26 14:21:22 -070028 virtual void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070029 sendInterest(const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -070030 {
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000031 this->onSendInterest(interest);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070032 m_sentInterests.push_back(interest);
33 this->afterSend();
Junxiao Shicbba04c2014-01-26 14:21:22 -070034 }
Junxiao Shi9b27bd22014-02-26 20:29:58 -070035
Junxiao Shicbba04c2014-01-26 14:21:22 -070036 virtual void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037 sendData(const Data& data)
Junxiao Shicbba04c2014-01-26 14:21:22 -070038 {
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000039 this->onSendData(data);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070040 m_sentDatas.push_back(data);
41 this->afterSend();
Junxiao Shicbba04c2014-01-26 14:21:22 -070042 }
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080043
44 virtual void
45 close()
46 {
47 }
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -080048
Junxiao Shi9b27bd22014-02-26 20:29:58 -070049 void
50 receiveInterest(const Interest& interest)
51 {
52 this->onReceiveInterest(interest);
53 }
54
55 void
56 receiveData(const Data& data)
57 {
58 this->onReceiveData(data);
59 }
60
Junxiao Shid9ee45c2014-02-27 15:38:11 -070061 EventEmitter<> afterSend;
Junxiao Shi9b27bd22014-02-26 20:29:58 -070062
63public:
64 std::vector<Interest> m_sentInterests;
65 std::vector<Data> m_sentDatas;
Junxiao Shicbba04c2014-01-26 14:21:22 -070066};
67
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080068typedef DummyFaceImpl<Face> DummyFace;
69typedef DummyFaceImpl<LocalFace> DummyLocalFace;
70
Junxiao Shid9ee45c2014-02-27 15:38:11 -070071} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080072} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070073
74#endif // TEST_FACE_DUMMY_FACE_HPP