fw: pass parameters to Strategy subclass constructors

refs #3868

Change-Id: I1a09e7353c047d548065c4ed669d1f7993676428
diff --git a/tests/daemon/fw/access-strategy.t.cpp b/tests/daemon/fw/access-strategy.t.cpp
index a25c44c..148f5a8 100644
--- a/tests/daemon/fw/access-strategy.t.cpp
+++ b/tests/daemon/fw/access-strategy.t.cpp
@@ -60,6 +60,18 @@
   BOOST_CHECK_EQUAL(Strategy::listRegistered().count(AccessStrategy::getStrategyName()), 1);
 }
 
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(AccessStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    AccessStrategy(forwarder, AccessStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    AccessStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    AccessStrategy(forwarder, Name(AccessStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
 class TwoLaptopsFixture : public UnitTestTimeFixture
 {
 protected:
diff --git a/tests/daemon/fw/asf-strategy.t.cpp b/tests/daemon/fw/asf-strategy.t.cpp
index 97f7da7..c370cbd 100644
--- a/tests/daemon/fw/asf-strategy.t.cpp
+++ b/tests/daemon/fw/asf-strategy.t.cpp
@@ -48,6 +48,18 @@
   BOOST_CHECK_EQUAL(Strategy::listRegistered().count(AsfStrategy::getStrategyName()), 1);
 }
 
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(AsfStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    AsfStrategy(forwarder, AsfStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    AsfStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    AsfStrategy(forwarder, Name(AsfStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
 class AsfGridFixture : public UnitTestTimeFixture
 {
 protected:
diff --git a/tests/daemon/fw/best-route-strategy.t.cpp b/tests/daemon/fw/best-route-strategy.t.cpp
index 7a2db75..a28ec83 100644
--- a/tests/daemon/fw/best-route-strategy.t.cpp
+++ b/tests/daemon/fw/best-route-strategy.t.cpp
@@ -38,6 +38,29 @@
 typedef StrategyTester<BestRouteStrategy> BestRouteStrategyTester;
 NFD_REGISTER_STRATEGY(BestRouteStrategyTester);
 
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Registration)
+{
+  BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy::getStrategyName()), 1);
+}
+
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(BestRouteStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    BestRouteStrategy(forwarder, BestRouteStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    BestRouteStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    BestRouteStrategy(forwarder, Name(BestRouteStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
+
 } // namespace tests
 } // namespace fw
 } // namespace nfd
diff --git a/tests/daemon/fw/best-route-strategy2.t.cpp b/tests/daemon/fw/best-route-strategy2.t.cpp
index 29de094..6a1848e 100644
--- a/tests/daemon/fw/best-route-strategy2.t.cpp
+++ b/tests/daemon/fw/best-route-strategy2.t.cpp
@@ -81,6 +81,18 @@
   BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy2::getStrategyName()), 1);
 }
 
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(BestRouteStrategy2::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    BestRouteStrategy2(forwarder, BestRouteStrategy2::getStrategyName().getPrefix(-1)).getInstanceName(),
+    BestRouteStrategy2::getStrategyName());
+  BOOST_CHECK_THROW(
+    BestRouteStrategy2(forwarder, Name(BestRouteStrategy2::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
 BOOST_AUTO_TEST_CASE(Forward)
 {
   fib::Entry& fibEntry = *fib.insert(Name()).first;
diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp
new file mode 100644
index 0000000..b03673a
--- /dev/null
+++ b/tests/daemon/fw/client-control-strategy.t.cpp
@@ -0,0 +1,61 @@
+/* -*- 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/>.
+ */
+
+#include "fw/client-control-strategy.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace fw {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Registration)
+{
+  BOOST_CHECK_EQUAL(Strategy::listRegistered().count(ClientControlStrategy::getStrategyName()), 1);
+}
+
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(ClientControlStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    ClientControlStrategy(forwarder, ClientControlStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    ClientControlStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    ClientControlStrategy(forwarder, Name(ClientControlStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
+
+} // namespace tests
+} // namespace fw
+} // namespace nfd
diff --git a/tests/daemon/fw/dummy-strategy.hpp b/tests/daemon/fw/dummy-strategy.hpp
index 08d10b0..a6af8ac 100644
--- a/tests/daemon/fw/dummy-strategy.hpp
+++ b/tests/daemon/fw/dummy-strategy.hpp
@@ -38,13 +38,22 @@
 class DummyStrategy : public fw::Strategy
 {
 public:
+  static void
+  registerAs(const Name& name)
+  {
+    if (!fw::Strategy::canCreate(name)) {
+      fw::Strategy::registerType<DummyStrategy>(name);
+    }
+  }
+
   DummyStrategy(Forwarder& forwarder, const Name& name)
-    : Strategy(forwarder, name)
+    : Strategy(forwarder)
     , afterReceiveInterest_count(0)
     , beforeSatisfyInterest_count(0)
     , beforeExpirePendingInterest_count(0)
     , afterReceiveNack_count(0)
   {
+    this->setInstanceName(name);
   }
 
   /** \brief after receive Interest trigger
@@ -52,7 +61,7 @@
    *  If \p interestOutFace is not null, Interest is forwarded to that face via send Interest action;
    *  otherwise, reject pending Interest action is invoked.
    */
-  virtual void
+  void
   afterReceiveInterest(const Face& inFace, const Interest& interest,
                        const shared_ptr<pit::Entry>& pitEntry) override
   {
@@ -66,20 +75,20 @@
     }
   }
 
-  virtual void
+  void
   beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
                         const Face& inFace, const Data& data) override
   {
     ++beforeSatisfyInterest_count;
   }
 
-  virtual void
+  void
   beforeExpirePendingInterest(const shared_ptr<pit::Entry>& pitEntry) override
   {
     ++beforeExpirePendingInterest_count;
   }
 
-  virtual void
+  void
   afterReceiveNack(const Face& inFace, const lp::Nack& nack,
                    const shared_ptr<pit::Entry>& pitEntry) override
   {
diff --git a/tests/daemon/fw/multicast-strategy.t.cpp b/tests/daemon/fw/multicast-strategy.t.cpp
index b8c3d2f..49bf940 100644
--- a/tests/daemon/fw/multicast-strategy.t.cpp
+++ b/tests/daemon/fw/multicast-strategy.t.cpp
@@ -72,6 +72,18 @@
   BOOST_CHECK_EQUAL(Strategy::listRegistered().count(MulticastStrategy::getStrategyName()), 1);
 }
 
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(MulticastStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    MulticastStrategy(forwarder, MulticastStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    MulticastStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    MulticastStrategy(forwarder, Name(MulticastStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
 BOOST_AUTO_TEST_CASE(Forward2)
 {
   fib::Entry& fibEntry = *fib.insert(Name()).first;
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index bc482e5..bc617c7 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -48,12 +48,24 @@
   BOOST_CHECK_EQUAL(Strategy::listRegistered().count(NccStrategy::getStrategyName()), 1);
 }
 
-// NccStrategy is fairly complex.
-// The most important property is:
-// it remembers which upstream is the fastest to return Data,
-// and favors this upstream in subsequent Interests.
+BOOST_AUTO_TEST_CASE(InstanceName)
+{
+  Forwarder forwarder;
+  BOOST_REQUIRE(NccStrategy::getStrategyName().at(-1).isVersion());
+  BOOST_CHECK_EQUAL(
+    NccStrategy(forwarder, NccStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
+    NccStrategy::getStrategyName());
+  BOOST_CHECK_THROW(
+    NccStrategy(forwarder, Name(NccStrategy::getStrategyName()).append("param")),
+    std::invalid_argument);
+}
+
 BOOST_AUTO_TEST_CASE(FavorRespondingUpstream)
 {
+  // NccStrategy is fairly complex.
+  // The most important property is: it remembers which upstream is the fastest to return Data,
+  // and favors this upstream in subsequent Interests.
+
   LimitedIo limitedIo(this);
   Forwarder forwarder;
   NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder);