Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 11 | #include "face/local-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 13 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 14 | namespace tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 15 | |
16 | /** \class DummyFace | ||||
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 17 | * \brief a Face for unit testing |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 18 | */ |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 19 | template<class FaceBase> |
20 | class DummyFaceImpl : public FaceBase | ||||
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 21 | { |
22 | public: | ||||
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 23 | DummyFaceImpl() |
24 | : FaceBase(FaceUri("dummy://")) | ||||
25 | { | ||||
26 | } | ||||
27 | |||||
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | virtual void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 29 | sendInterest(const Interest& interest) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 30 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 31 | this->onSendInterest(interest); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 32 | m_sentInterests.push_back(interest); |
33 | this->afterSend(); | ||||
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 34 | } |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 36 | virtual void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | sendData(const Data& data) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 38 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 39 | this->onSendData(data); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 40 | m_sentDatas.push_back(data); |
41 | this->afterSend(); | ||||
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 42 | } |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 43 | |
44 | virtual void | ||||
45 | close() | ||||
46 | { | ||||
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 47 | this->onFail("close"); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 48 | } |
Alexander Afanasyev | 93ce75e | 2014-02-18 19:45:34 -0800 | [diff] [blame] | 49 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 50 | 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 Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 62 | EventEmitter<> afterSend; |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 63 | |
64 | public: | ||||
65 | std::vector<Interest> m_sentInterests; | ||||
66 | std::vector<Data> m_sentDatas; | ||||
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 67 | }; |
68 | |||||
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 69 | typedef DummyFaceImpl<Face> DummyFace; |
70 | typedef DummyFaceImpl<LocalFace> DummyLocalFace; | ||||
71 | |||||
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 72 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 73 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 74 | |
75 | #endif // TEST_FACE_DUMMY_FACE_HPP |