blob: 9c7252c201259cb40df6ac79fe09e0adc15899dc [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()
Junxiao Shi79494162014-04-02 18:25:11 -070024 : FaceBase(FaceUri("dummy://"), FaceUri("dummy://"))
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000025 {
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 {
Junxiao Shic542b2b2014-03-16 21:45:52 -070047 this->onFail("close");
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080048 }
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -080049
Junxiao Shi9b27bd22014-02-26 20:29:58 -070050 void
51 receiveInterest(const Interest& interest)
52 {
53 this->onReceiveInterest(interest);
54 }
55
56 void
57 receiveData(const Data& data)
58 {
59 this->onReceiveData(data);
60 }
61
Junxiao Shid9ee45c2014-02-27 15:38:11 -070062 EventEmitter<> afterSend;
Junxiao Shi9b27bd22014-02-26 20:29:58 -070063
64public:
65 std::vector<Interest> m_sentInterests;
66 std::vector<Data> m_sentDatas;
Junxiao Shicbba04c2014-01-26 14:21:22 -070067};
68
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080069typedef DummyFaceImpl<Face> DummyFace;
70typedef DummyFaceImpl<LocalFace> DummyLocalFace;
71
Junxiao Shid9ee45c2014-02-27 15:38:11 -070072} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080073} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070074
75#endif // TEST_FACE_DUMMY_FACE_HPP