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