blob: 0ec477027a8efe6f7566de9fa05940114a1890fd [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- 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
13namespace 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 */
20template<typename S>
21class StrategyTester : public S
22{
23public:
24 explicit
25 StrategyTester(Forwarder& forwarder)
26 : S(forwarder)
27 {
28 }
29
30protected:
31 virtual void
32 sendInterest(shared_ptr<pit::Entry> pitEntry,shared_ptr<Face> outFace);
33
34 virtual void
Junxiao Shi09498f02014-02-26 19:41:08 -070035 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shi727ed292014-02-19 23:26:45 -070036
37public:
38 typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face> > SendInterestArgs;
39 std::vector<SendInterestArgs> m_sendInterestHistory;
40
Junxiao Shi09498f02014-02-26 19:41:08 -070041 typedef boost::tuple<shared_ptr<pit::Entry> > RejectPendingInterestArgs;
42 std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
Junxiao Shi727ed292014-02-19 23:26:45 -070043};
44
45
46template<typename S>
47inline void
48StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry,
49 shared_ptr<Face> outFace)
50{
51 m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
52}
53
54template<typename S>
55inline void
Junxiao Shi09498f02014-02-26 19:41:08 -070056StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
Junxiao Shi727ed292014-02-19 23:26:45 -070057{
Junxiao Shi09498f02014-02-26 19:41:08 -070058 m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
Junxiao Shi727ed292014-02-19 23:26:45 -070059}
60
61
62} // namespace nfd
63
64#endif // TEST_FW_STRATEGY_TESTER_HPP