blob: c268a8e9f4e57bdaaf758294fd87c976bcc32d1f [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shi727ed292014-02-19 23:26:45 -070024
25#ifndef NFD_TEST_FW_STRATEGY_TESTER_HPP
26#define NFD_TEST_FW_STRATEGY_TESTER_HPP
27
28#include <boost/tuple/tuple_comparison.hpp>
29#include "fw/strategy.hpp"
30
31namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070033
34/** \class StrategyTester
35 * \brief extends strategy S for unit testing
36 *
37 * Actions invoked by S are recorded but not passed to forwarder
38 */
39template<typename S>
40class StrategyTester : public S
41{
42public:
43 explicit
44 StrategyTester(Forwarder& forwarder)
Junxiao Shif3c07812014-03-11 21:48:49 -070045 : S(forwarder, Name(S::STRATEGY_NAME).append("tester"))
Junxiao Shi727ed292014-02-19 23:26:45 -070046 {
47 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070048
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070049 /// fires after each Action
50 EventEmitter<> onAction;
Junxiao Shi727ed292014-02-19 23:26:45 -070051
52protected:
53 virtual void
54 sendInterest(shared_ptr<pit::Entry> pitEntry,shared_ptr<Face> outFace);
55
56 virtual void
Junxiao Shi09498f02014-02-26 19:41:08 -070057 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shi727ed292014-02-19 23:26:45 -070058
59public:
60 typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face> > SendInterestArgs;
61 std::vector<SendInterestArgs> m_sendInterestHistory;
62
Junxiao Shi09498f02014-02-26 19:41:08 -070063 typedef boost::tuple<shared_ptr<pit::Entry> > RejectPendingInterestArgs;
64 std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
Junxiao Shi727ed292014-02-19 23:26:45 -070065};
66
67
68template<typename S>
69inline void
70StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry,
71 shared_ptr<Face> outFace)
72{
73 m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070074 pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
75 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070076}
77
78template<typename S>
79inline void
Junxiao Shi09498f02014-02-26 19:41:08 -070080StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
Junxiao Shi727ed292014-02-19 23:26:45 -070081{
Junxiao Shi09498f02014-02-26 19:41:08 -070082 m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070083 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070084}
85
Junxiao Shid9ee45c2014-02-27 15:38:11 -070086} // namespace tests
Junxiao Shi727ed292014-02-19 23:26:45 -070087} // namespace nfd
88
89#endif // TEST_FW_STRATEGY_TESTER_HPP