Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -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_FW_STRATEGY_TESTER_HPP |
| 8 | #define NFD_TEST_FW_STRATEGY_TESTER_HPP |
| 9 | |
| 10 | #include <boost/tuple/tuple_comparison.hpp> |
| 11 | #include "fw/strategy.hpp" |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | /** \class StrategyTester |
| 16 | * \brief extends strategy S for unit testing |
| 17 | * |
| 18 | * Actions invoked by S are recorded but not passed to forwarder |
| 19 | */ |
| 20 | template<typename S> |
| 21 | class StrategyTester : public S |
| 22 | { |
| 23 | public: |
| 24 | explicit |
| 25 | StrategyTester(Forwarder& forwarder) |
| 26 | : S(forwarder) |
| 27 | { |
| 28 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 29 | |
| 30 | /// fires after each Action |
| 31 | EventEmitter<> onAction; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 32 | |
| 33 | protected: |
| 34 | virtual void |
| 35 | sendInterest(shared_ptr<pit::Entry> pitEntry,shared_ptr<Face> outFace); |
| 36 | |
| 37 | virtual void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 38 | rejectPendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 39 | |
| 40 | public: |
| 41 | typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face> > SendInterestArgs; |
| 42 | std::vector<SendInterestArgs> m_sendInterestHistory; |
| 43 | |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 44 | typedef boost::tuple<shared_ptr<pit::Entry> > RejectPendingInterestArgs; |
| 45 | std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | |
| 49 | template<typename S> |
| 50 | inline void |
| 51 | StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 52 | shared_ptr<Face> outFace) |
| 53 | { |
| 54 | m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 55 | pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest()); |
| 56 | onAction(); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | template<typename S> |
| 60 | inline void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 61 | StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 62 | { |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 63 | m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 64 | onAction(); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | } // namespace nfd |
| 69 | |
| 70 | #endif // TEST_FW_STRATEGY_TESTER_HPP |