blob: 571492ca57e2953c28af70a5156b3a66727a1367 [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 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070014namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070015
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 */
21template<typename S>
22class StrategyTester : public S
23{
24public:
25 explicit
26 StrategyTester(Forwarder& forwarder)
27 : S(forwarder)
28 {
29 }
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070030
31 /// fires after each Action
32 EventEmitter<> onAction;
Junxiao Shi727ed292014-02-19 23:26:45 -070033
34protected:
35 virtual void
36 sendInterest(shared_ptr<pit::Entry> pitEntry,shared_ptr<Face> outFace);
37
38 virtual void
Junxiao Shi09498f02014-02-26 19:41:08 -070039 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shi727ed292014-02-19 23:26:45 -070040
41public:
42 typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face> > SendInterestArgs;
43 std::vector<SendInterestArgs> m_sendInterestHistory;
44
Junxiao Shi09498f02014-02-26 19:41:08 -070045 typedef boost::tuple<shared_ptr<pit::Entry> > RejectPendingInterestArgs;
46 std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
Junxiao Shi727ed292014-02-19 23:26:45 -070047};
48
49
50template<typename S>
51inline void
52StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry,
53 shared_ptr<Face> outFace)
54{
55 m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070056 pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
57 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070058}
59
60template<typename S>
61inline void
Junxiao Shi09498f02014-02-26 19:41:08 -070062StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
Junxiao Shi727ed292014-02-19 23:26:45 -070063{
Junxiao Shi09498f02014-02-26 19:41:08 -070064 m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070065 onAction();
Junxiao Shi727ed292014-02-19 23:26:45 -070066}
67
Junxiao Shid9ee45c2014-02-27 15:38:11 -070068} // namespace tests
Junxiao Shi727ed292014-02-19 23:26:45 -070069} // namespace nfd
70
71#endif // TEST_FW_STRATEGY_TESTER_HPP