table: StrategyChoice uses unique_ptr instead of shared_ptr

refs #3164

Change-Id: Id3110f72aab83982b0768e596a04bad9f7336975
diff --git a/tests/daemon/fw/asf-strategy.t.cpp b/tests/daemon/fw/asf-strategy.t.cpp
index 687b0e2..af584cf 100644
--- a/tests/daemon/fw/asf-strategy.t.cpp
+++ b/tests/daemon/fw/asf-strategy.t.cpp
@@ -87,7 +87,7 @@
   runConsumer()
   {
     topo.addIntervalConsumer(consumer->getClientFace(), PRODUCER_PREFIX, time::seconds(1), 30);
-    this->advanceClocks(time::milliseconds(1), time::seconds(30));
+    this->advanceClocks(time::milliseconds(10), time::seconds(30));
   }
 
 protected:
@@ -143,7 +143,7 @@
   linkAB->recover();
 
   // Advance time to ensure probing is due
-  this->advanceClocks(time::milliseconds(1), time::seconds(10));
+  this->advanceClocks(time::milliseconds(10), time::seconds(10));
 
   runConsumer();
 
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index 7f2bc41..ad2877e 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -26,6 +26,7 @@
 #include "fw/forwarder.hpp"
 #include "tests/daemon/face/dummy-face.hpp"
 #include "dummy-strategy.hpp"
+#include "install-strategy.hpp"
 
 #include "tests/test-common.hpp"
 
@@ -386,39 +387,32 @@
   forwarder.addFace(face1);
   forwarder.addFace(face2);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
-                                        ref(forwarder), "ndn:/strategyP");
-  shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
-                                        ref(forwarder), "ndn:/strategyQ");
-  strategyChoice.install(strategyP);
-  strategyChoice.install(strategyQ);
-  strategyChoice.insert("ndn:/" , strategyP->getName());
-  strategyChoice.insert("ndn:/B", strategyQ->getName());
+  DummyStrategy& strategyP = choose<DummyStrategy>(forwarder, "ndn:/", "ndn:/strategyP");
+  DummyStrategy& strategyQ = choose<DummyStrategy>(forwarder, "ndn:/B", "ndn:/strategyQ");
 
   shared_ptr<Interest> interest1 = makeInterest("ndn:/A/1");
-  strategyP->afterReceiveInterest_count = 0;
-  strategyP->interestOutFace = face2;
+  strategyP.afterReceiveInterest_count = 0;
+  strategyP.interestOutFace = face2;
   forwarder.startProcessInterest(*face1, *interest1);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveInterest_count, 1);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveInterest_count, 1);
 
   shared_ptr<Interest> interest2 = makeInterest("ndn:/B/2");
-  strategyQ->afterReceiveInterest_count = 0;
-  strategyQ->interestOutFace = face2;
+  strategyQ.afterReceiveInterest_count = 0;
+  strategyQ.interestOutFace = face2;
   forwarder.startProcessInterest(*face1, *interest2);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveInterest_count, 1);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveInterest_count, 1);
 
   this->advanceClocks(time::milliseconds(1), time::milliseconds(5));
 
   shared_ptr<Data> data1 = makeData("ndn:/A/1/a");
-  strategyP->beforeSatisfyInterest_count = 0;
+  strategyP.beforeSatisfyInterest_count = 0;
   forwarder.startProcessData(*face2, *data1);
-  BOOST_CHECK_EQUAL(strategyP->beforeSatisfyInterest_count, 1);
+  BOOST_CHECK_EQUAL(strategyP.beforeSatisfyInterest_count, 1);
 
   shared_ptr<Data> data2 = makeData("ndn:/B/2/b");
-  strategyQ->beforeSatisfyInterest_count = 0;
+  strategyQ.beforeSatisfyInterest_count = 0;
   forwarder.startProcessData(*face2, *data2);
-  BOOST_CHECK_EQUAL(strategyQ->beforeSatisfyInterest_count, 1);
+  BOOST_CHECK_EQUAL(strategyQ.beforeSatisfyInterest_count, 1);
 
   shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3");
   interest3->setInterestLifetime(time::milliseconds(30));
@@ -427,11 +421,11 @@
   interest4->setInterestLifetime(time::milliseconds(5000));
   forwarder.startProcessInterest(*face1, *interest4);
 
-  strategyP->beforeExpirePendingInterest_count = 0;
-  strategyQ->beforeExpirePendingInterest_count = 0;
+  strategyP.beforeExpirePendingInterest_count = 0;
+  strategyQ.beforeExpirePendingInterest_count = 0;
   this->advanceClocks(time::milliseconds(10), time::milliseconds(100));
-  BOOST_CHECK_EQUAL(strategyP->beforeExpirePendingInterest_count, 1);
-  BOOST_CHECK_EQUAL(strategyQ->beforeExpirePendingInterest_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.beforeExpirePendingInterest_count, 1);
+  BOOST_CHECK_EQUAL(strategyQ.beforeExpirePendingInterest_count, 0);
 }
 
 BOOST_AUTO_TEST_CASE(IncomingData)
@@ -482,15 +476,8 @@
   forwarder.addFace(face2);
   forwarder.addFace(face3);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
-                                        ref(forwarder), "ndn:/strategyP");
-  shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
-                                        ref(forwarder), "ndn:/strategyQ");
-  strategyChoice.install(strategyP);
-  strategyChoice.install(strategyQ);
-  strategyChoice.insert("ndn:/" , strategyP->getName());
-  strategyChoice.insert("ndn:/B", strategyQ->getName());
+  DummyStrategy& strategyP = choose<DummyStrategy>(forwarder, "ndn:/", "ndn:/strategyP");
+  DummyStrategy& strategyQ = choose<DummyStrategy>(forwarder, "ndn:/B", "ndn:/strategyQ");
 
   Pit& pit = forwarder.getPit();
 
@@ -503,18 +490,18 @@
   pit2->insertOrUpdateOutRecord(face1, *interest2);
 
   lp::Nack nack1 = makeNack("/A/AYJqayrzF", 562, lp::NackReason::CONGESTION);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face1, nack1);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 1);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 1);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0);
 
   lp::Nack nack2 = makeNack("/B/EVyP73ru", 221, lp::NackReason::CONGESTION);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face1, nack2);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 1);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 1);
 
   // record Nack on PIT out-record
   pit::OutRecordCollection::iterator outRecord1 = pit1->getOutRecord(*face1);
@@ -524,11 +511,11 @@
 
   // drop if no PIT entry
   lp::Nack nack3 = makeNack("/yEcw5HhdM", 243, lp::NackReason::CONGESTION);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face1, nack3);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0);
 
   // drop if no out-record
   shared_ptr<Interest> interest4 = makeInterest("/Etab4KpY", 157);
@@ -536,27 +523,27 @@
   pit4->insertOrUpdateOutRecord(face1, *interest4);
 
   lp::Nack nack4a = makeNack("/Etab4KpY", 157, lp::NackReason::CONGESTION);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face2, nack4a);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0);
 
   // drop if Nonce does not match out-record
   lp::Nack nack4b = makeNack("/Etab4KpY", 294, lp::NackReason::CONGESTION);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face1, nack4b);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0);
 
   // drop if inFace is multi-access
   pit4->insertOrUpdateOutRecord(face3, *interest4);
-  strategyP->afterReceiveNack_count = 0;
-  strategyQ->afterReceiveNack_count = 0;
+  strategyP.afterReceiveNack_count = 0;
+  strategyQ.afterReceiveNack_count = 0;
   forwarder.onIncomingNack(*face3, nack4a);
-  BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
-  BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0);
+  BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0);
 }
 
 BOOST_AUTO_TEST_CASE(OutgoingNack)
diff --git a/tests/daemon/fw/install-strategy.hpp b/tests/daemon/fw/install-strategy.hpp
new file mode 100644
index 0000000..ec3c848
--- /dev/null
+++ b/tests/daemon/fw/install-strategy.hpp
@@ -0,0 +1,88 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP
+#define NFD_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP
+
+namespace nfd {
+namespace fw {
+class Strategy;
+} // namespace fw
+
+namespace tests {
+
+/** \brief install a strategy to forwarder
+ *  \tparam S strategy type
+ *  \param forwarder the forwarder
+ *  \param args arguments to strategy constructor
+ *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
+ *                       and has an incompatible type
+ *  \return a reference to the strategy
+ */
+template<typename S, typename ...Args>
+typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
+install(Forwarder& forwarder, Args&&... args)
+{
+  auto strategy = make_unique<S>(ref(forwarder), std::forward<Args>(args)...);
+  fw::Strategy* installed = forwarder.getStrategyChoice().install(std::move(strategy)).second;
+  return dynamic_cast<S&>(*installed);
+}
+
+/** \brief install a strategy to forwarder, and choose the strategy for a namespace
+ *  \tparam S strategy type
+ *  \param forwarder the forwarder
+ *  \param prefix namespace to choose the strategy for
+ *  \param args arguments to strategy constructor
+ *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
+ *                       and has an incompatible type
+ *  \return a reference to the strategy
+ */
+template<typename S, typename ...Args>
+typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
+choose(Forwarder& forwarder, const Name& prefix, Args&&... args)
+{
+  S& strategy = install<S>(forwarder, std::forward<Args>(args)...);
+  forwarder.getStrategyChoice().insert(prefix, strategy.getName());
+  return strategy;
+}
+
+/** \brief install a strategy to forwarder, and choose the strategy as default
+ *  \tparam S strategy type
+ *  \param forwarder the forwarder
+ *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
+ *                       and has an incompatible type
+ *  \return a reference to the strategy
+ */
+template<typename S>
+typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
+choose(Forwarder& forwarder)
+{
+  return choose<S>(forwarder, "ndn:/");
+}
+
+} // namespace tests
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index b624c74..251e3d6 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -50,9 +50,8 @@
 {
   LimitedIo limitedIo(this);
   Forwarder forwarder;
-  typedef StrategyTester<NccStrategy> NccStrategyTester;
-  shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
-  strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+  StrategyTester<NccStrategy>& strategy = choose<StrategyTester<NccStrategy>>(forwarder);
+  strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
 
   shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
   shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -66,10 +65,6 @@
   fibEntry.addNextHop(*face1, 10);
   fibEntry.addNextHop(*face2, 20);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  strategyChoice.install(strategy);
-  strategyChoice.insert(Name(), strategy->getName());
-
   Pit& pit = forwarder.getPit();
 
   // first Interest: strategy knows nothing and follows routing
@@ -79,22 +74,22 @@
   shared_ptr<pit::Entry> pitEntry1 = pit.insert(interest1).first;
 
   pitEntry1->insertOrUpdateInRecord(face3, interest1);
-  strategy->afterReceiveInterest(*face3, interest1, pitEntry1);
+  strategy.afterReceiveInterest(*face3, interest1, pitEntry1);
 
   // forwards to face1 because routing says it's best
   // (no io run here: afterReceiveInterest has already sent the Interest)
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
 
   // forwards to face2 because face1 doesn't respond
   limitedIo.run(1, time::milliseconds(500), time::milliseconds(10));
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId());
 
   // face2 responds
   shared_ptr<Data> data1p = makeData("ndn:/0Jm1ajrW/%00");
   Data& data1 = *data1p;
-  strategy->beforeSatisfyInterest(pitEntry1, *face2, data1);
+  strategy.beforeSatisfyInterest(pitEntry1, *face2, data1);
   this->advanceClocks(time::milliseconds(10), time::milliseconds(500));
 
   // second Interest: strategy knows face2 is best
@@ -104,19 +99,18 @@
   shared_ptr<pit::Entry> pitEntry2 = pit.insert(interest2).first;
 
   pitEntry2->insertOrUpdateInRecord(face3, interest2);
-  strategy->afterReceiveInterest(*face3, interest2, pitEntry2);
+  strategy.afterReceiveInterest(*face3, interest2, pitEntry2);
 
   // forwards to face2 because it responds previously
   this->advanceClocks(time::milliseconds(1));
-  BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face2->getId());
+  BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 3);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face2->getId());
 }
 
 BOOST_AUTO_TEST_CASE(Bug1853)
 {
   Forwarder forwarder;
-  typedef StrategyTester<NccStrategy> NccStrategyTester;
-  shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
+  StrategyTester<NccStrategy>& strategy = choose<StrategyTester<NccStrategy>>(forwarder);
 
   shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
   shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -129,10 +123,6 @@
   fib::Entry& fibEntry = *fib.insert(Name()).first;
   fibEntry.addNextHop(*face1, 10);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  strategyChoice.install(strategy);
-  strategyChoice.insert(Name(), strategy->getName());
-
   Pit& pit = forwarder.getPit();
 
   // first Interest: strategy follows routing and forwards to face1
@@ -141,15 +131,15 @@
   shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
 
   pitEntry1->insertOrUpdateInRecord(face3, *interest1);
-  strategy->afterReceiveInterest(*face3, *interest1, pitEntry1);
+  strategy.afterReceiveInterest(*face3, *interest1, pitEntry1);
 
   this->advanceClocks(time::milliseconds(1));
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
 
   // face1 responds
   shared_ptr<Data> data1 = makeData("ndn:/nztwIvHX/%00");
-  strategy->beforeSatisfyInterest(pitEntry1, *face1, *data1);
+  strategy.beforeSatisfyInterest(pitEntry1, *face1, *data1);
   this->advanceClocks(time::milliseconds(10), time::milliseconds(500));
 
   // second Interest: bestFace is face1, nUpstreams becomes 0,
@@ -159,7 +149,7 @@
   shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
 
   pitEntry2->insertOrUpdateInRecord(face3, *interest2);
-  strategy->afterReceiveInterest(*face3, *interest2, pitEntry2);
+  strategy.afterReceiveInterest(*face3, *interest2, pitEntry2);
 
   // FIB entry is changed before doPropagate executes
   fibEntry.addNextHop(*face2, 20);
@@ -170,9 +160,8 @@
 {
   LimitedIo limitedIo(this);
   Forwarder forwarder;
-  typedef StrategyTester<NccStrategy> NccStrategyTester;
-  shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
-  strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+  StrategyTester<NccStrategy>& strategy = choose<StrategyTester<NccStrategy>>(forwarder);
+  strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
 
   shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
   shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -186,10 +175,6 @@
   fibEntry.addNextHop(*face1, 10);
   fibEntry.addNextHop(*face2, 20);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  strategyChoice.install(strategy);
-  strategyChoice.insert(Name(), strategy->getName());
-
   Pit& pit = forwarder.getPit();
 
   // first Interest: strategy forwards to face1 and face2
@@ -198,20 +183,20 @@
   shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
 
   pitEntry1->insertOrUpdateInRecord(face3, *interest1);
-  strategy->afterReceiveInterest(*face3, *interest1, pitEntry1);
-  limitedIo.run(2 - strategy->sendInterestHistory.size(),
+  strategy.afterReceiveInterest(*face3, *interest1, pitEntry1);
+  limitedIo.run(2 - strategy.sendInterestHistory.size(),
                 time::milliseconds(2000), time::milliseconds(10));
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId());
 
   // face1 responds
   shared_ptr<Data> data1 = makeData("ndn:/seRMz5a6/%00");
-  strategy->beforeSatisfyInterest(pitEntry1, *face1, *data1);
+  strategy.beforeSatisfyInterest(pitEntry1, *face1, *data1);
   pitEntry1->clearInRecords();
   this->advanceClocks(time::milliseconds(10));
   // face2 also responds
-  strategy->beforeSatisfyInterest(pitEntry1, *face2, *data1);
+  strategy.beforeSatisfyInterest(pitEntry1, *face2, *data1);
   this->advanceClocks(time::milliseconds(10));
 
   // second Interest: bestFace should be face 1
@@ -220,21 +205,20 @@
   shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
 
   pitEntry2->insertOrUpdateInRecord(face3, *interest2);
-  strategy->afterReceiveInterest(*face3, *interest2, pitEntry2);
-  limitedIo.run(3 - strategy->sendInterestHistory.size(),
+  strategy.afterReceiveInterest(*face3, *interest2, pitEntry2);
+  limitedIo.run(3 - strategy.sendInterestHistory.size(),
                 time::milliseconds(2000), time::milliseconds(10));
 
-  BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face1->getId());
+  BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 3);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face1->getId());
 }
 
 BOOST_AUTO_TEST_CASE(Bug1971)
 {
   LimitedIo limitedIo(this);
   Forwarder forwarder;
-  typedef StrategyTester<NccStrategy> NccStrategyTester;
-  shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
-  strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+  StrategyTester<NccStrategy>& strategy = choose<StrategyTester<NccStrategy>>(forwarder);
+  strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
 
   shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
   shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -245,10 +229,6 @@
   fib::Entry& fibEntry = *fib.insert(Name()).first;
   fibEntry.addNextHop(*face2, 10);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  strategyChoice.install(strategy);
-  strategyChoice.insert(Name(), strategy->getName());
-
   Pit& pit = forwarder.getPit();
 
   // first Interest: strategy forwards to face2
@@ -257,34 +237,33 @@
   shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
 
   pitEntry1->insertOrUpdateInRecord(face1, *interest1);
-  strategy->afterReceiveInterest(*face1, *interest1, pitEntry1);
-  limitedIo.run(1 - strategy->sendInterestHistory.size(),
+  strategy.afterReceiveInterest(*face1, *interest1, pitEntry1);
+  limitedIo.run(1 - strategy.sendInterestHistory.size(),
                 time::milliseconds(2000), time::milliseconds(10));
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
 
   // face2 responds
   shared_ptr<Data> data1 = makeData("ndn:/M4mBXCsd");
   data1->setFreshnessPeriod(time::milliseconds(5));
-  strategy->beforeSatisfyInterest(pitEntry1, *face2, *data1);
+  strategy.beforeSatisfyInterest(pitEntry1, *face2, *data1);
   pitEntry1->deleteOutRecord(*face2);
   pitEntry1->clearInRecords();
   this->advanceClocks(time::milliseconds(10));
 
   // similar Interest: strategy should still forward it
   pitEntry1->insertOrUpdateInRecord(face1, *interest1);
-  strategy->afterReceiveInterest(*face1, *interest1, pitEntry1);
-  limitedIo.run(2 - strategy->sendInterestHistory.size(),
+  strategy.afterReceiveInterest(*face1, *interest1, pitEntry1);
+  limitedIo.run(2 - strategy.sendInterestHistory.size(),
                 time::milliseconds(2000), time::milliseconds(10));
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId());
 }
 
 BOOST_AUTO_TEST_CASE(Bug1998)
 {
   Forwarder forwarder;
-  typedef StrategyTester<NccStrategy> NccStrategyTester;
-  shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
+  StrategyTester<NccStrategy>& strategy = choose<StrategyTester<NccStrategy>>(forwarder);
 
   shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
   shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -296,10 +275,6 @@
   fibEntry.addNextHop(*face1, 10); // face1 is top-ranked nexthop
   fibEntry.addNextHop(*face2, 20);
 
-  StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-  strategyChoice.install(strategy);
-  strategyChoice.insert(Name(), strategy->getName());
-
   Pit& pit = forwarder.getPit();
 
   // Interest comes from face1, which is sole downstream
@@ -307,11 +282,11 @@
   shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
   pitEntry1->insertOrUpdateInRecord(face1, *interest1);
 
-  strategy->afterReceiveInterest(*face1, *interest1, pitEntry1);
+  strategy.afterReceiveInterest(*face1, *interest1, pitEntry1);
 
   // Interest shall go to face2, not loop back to face1
-  BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
-  BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
+  BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+  BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
 }
 
 BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(PredictionAdjustment, 1)
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index abb053d..329244b 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -34,6 +34,7 @@
 #include "face/internal-transport.hpp"
 #include "face/face.hpp"
 #include "fw/strategy.hpp"
+#include "install-strategy.hpp"
 #include "tests/test-common.hpp"
 
 namespace nfd {
@@ -175,7 +176,7 @@
   }
 
   /** \brief sets strategy on forwarder \p i
-   *  \tparam the strategy type
+   *  \tparam S the strategy type
    *  \note Test scenario can also access StrategyChoice table directly.
    */
   template<typename S>
@@ -183,10 +184,7 @@
   setStrategy(TopologyNode i, Name prefix = Name("ndn:/"))
   {
     Forwarder& forwarder = this->getForwarder(i);
-    StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
-    shared_ptr<S> strategy = make_shared<S>(ref(forwarder));
-    strategyChoice.install(strategy);
-    strategyChoice.insert(prefix, strategy->getName());
+    choose<S>(forwarder, prefix);
   }
 
   /** \brief makes a link that interconnects two or more forwarders