Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_TESTS_NFD_FW_STRATEGY_TESTER_HPP |
| 27 | #define NFD_TESTS_NFD_FW_STRATEGY_TESTER_HPP |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 28 | |
| 29 | #include <boost/tuple/tuple_comparison.hpp> |
| 30 | #include "fw/strategy.hpp" |
| 31 | |
| 32 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 33 | namespace fw { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | namespace tests { |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 35 | |
| 36 | /** \class StrategyTester |
| 37 | * \brief extends strategy S for unit testing |
| 38 | * |
| 39 | * Actions invoked by S are recorded but not passed to forwarder |
| 40 | */ |
| 41 | template<typename S> |
| 42 | class StrategyTester : public S |
| 43 | { |
| 44 | public: |
| 45 | explicit |
| 46 | StrategyTester(Forwarder& forwarder) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 47 | : S(forwarder, Name(S::STRATEGY_NAME).append("tester")) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 48 | { |
| 49 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 51 | /// fires after each Action |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 52 | signal::Signal<StrategyTester<S>> onAction; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | virtual void |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 56 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 57 | shared_ptr<Face> outFace, |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame] | 58 | bool wantNewNonce = false) DECL_OVERRIDE; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 59 | |
| 60 | virtual void |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame] | 61 | rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 62 | |
| 63 | public: |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame] | 64 | typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face>> SendInterestArgs; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 65 | std::vector<SendInterestArgs> m_sendInterestHistory; |
| 66 | |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame] | 67 | typedef boost::tuple<shared_ptr<pit::Entry>> RejectPendingInterestArgs; |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 68 | std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory; |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | |
| 72 | template<typename S> |
| 73 | inline void |
| 74 | StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry, |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 75 | shared_ptr<Face> outFace, |
| 76 | bool wantNewNonce) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 77 | { |
| 78 | m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 79 | pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest()); |
| 80 | onAction(); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | template<typename S> |
| 84 | inline void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 85 | StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 86 | { |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 87 | m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 88 | onAction(); |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 91 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 92 | } // namespace fw |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 93 | } // namespace nfd |
| 94 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 95 | #endif // NFD_TESTS_NFD_FW_STRATEGY_TESTER_HPP |