table: clear StrategyInfo during strategy change

refs #1234

Change-Id: Idd5383a5f8bc706aceea5a630b93cd4ab9bd2c3a
diff --git a/tests/table/strategy-choice.cpp b/tests/table/strategy-choice.cpp
index c198db8..31df7f0 100644
--- a/tests/table/strategy-choice.cpp
+++ b/tests/table/strategy-choice.cpp
@@ -5,7 +5,7 @@
  */
 
 #include "table/strategy-choice.hpp"
-#include "fw/strategy.hpp"
+#include "tests/fw/dummy-strategy.hpp"
 
 #include "tests/test-common.hpp"
 
@@ -16,38 +16,14 @@
 
 using fw::Strategy;
 
-class StrategyChoiceTestDummyStrategy : public Strategy
-{
-public:
-  StrategyChoiceTestDummyStrategy(Forwarder& forwarder, const Name& name)
-    : Strategy(forwarder, name)
-  {
-  }
-
-  virtual
-  ~StrategyChoiceTestDummyStrategy()
-  {
-  }
-
-  virtual void
-  afterReceiveInterest(const Face& inFace,
-                       const Interest& interest,
-                       shared_ptr<fib::Entry> fibEntry,
-                       shared_ptr<pit::Entry> pitEntry)
-  {
-  }
-};
-
 BOOST_AUTO_TEST_CASE(Effective)
 {
   Forwarder forwarder;
   Name nameP("ndn:/strategy/P");
   Name nameQ("ndn:/strategy/Q");
   Name nameZ("ndn:/strategy/Z");
-  shared_ptr<Strategy> strategyP = make_shared<StrategyChoiceTestDummyStrategy>(
-                                   boost::ref(forwarder), nameP);
-  shared_ptr<Strategy> strategyQ = make_shared<StrategyChoiceTestDummyStrategy>(
-                                   boost::ref(forwarder), nameQ);
+  shared_ptr<Strategy> strategyP = make_shared<DummyStrategy>(boost::ref(forwarder), nameP);
+  shared_ptr<Strategy> strategyQ = make_shared<DummyStrategy>(boost::ref(forwarder), nameQ);
 
   StrategyChoice& table = forwarder.getStrategyChoice();
 
@@ -56,14 +32,14 @@
   BOOST_CHECK_EQUAL(table.install(strategyQ), true);
   BOOST_CHECK_EQUAL(table.install(strategyQ), false);
 
-  BOOST_CHECK(table.insert("ndn:/", "ndn:/strategy/P"));
+  BOOST_CHECK(table.insert("ndn:/", nameP));
   // { '/'=>P }
 
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/")   .getName(), nameP);
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A")  .getName(), nameP);
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
 
-  BOOST_CHECK(table.insert("ndn:/A/B", "ndn:/strategy/P"));
+  BOOST_CHECK(table.insert("ndn:/A/B", nameP));
   // { '/'=>P, '/A/B'=>P }
 
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/")   .getName(), nameP);
@@ -81,7 +57,7 @@
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A")  .getName(), nameP);
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
 
-  BOOST_CHECK(table.insert("ndn:/A", "ndn:/strategy/Q"));
+  BOOST_CHECK(table.insert("ndn:/A", nameQ));
   // { '/'=>P, '/A/B'=>P, '/A'=>Q }
 
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/")   .getName(), nameP);
@@ -95,10 +71,10 @@
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A")  .getName(), nameQ);
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameQ);
 
-  BOOST_CHECK(!table.insert("ndn:/", "ndn:/strategy/Z")); // non existent strategy
+  BOOST_CHECK(!table.insert("ndn:/", nameZ)); // non existent strategy
 
-  BOOST_CHECK(table.insert("ndn:/", "ndn:/strategy/Q"));
-  BOOST_CHECK(table.insert("ndn:/A", "ndn:/strategy/P"));
+  BOOST_CHECK(table.insert("ndn:/", nameQ));
+  BOOST_CHECK(table.insert("ndn:/A", nameP));
   // { '/'=>Q, '/A'=>P }
 
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/")   .getName(), nameQ);
@@ -107,6 +83,54 @@
   BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/D")  .getName(), nameQ);
 }
 
+class PStrategyInfo : public fw::StrategyInfo
+{
+};
+
+BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
+{
+  Forwarder forwarder;
+  Name nameP("ndn:/strategy/P");
+  Name nameQ("ndn:/strategy/Q");
+  shared_ptr<Strategy> strategyP = make_shared<DummyStrategy>(boost::ref(forwarder), nameP);
+  shared_ptr<Strategy> strategyQ = make_shared<DummyStrategy>(boost::ref(forwarder), nameQ);
+
+  StrategyChoice& table = forwarder.getStrategyChoice();
+  Measurements& measurements = forwarder.getMeasurements();
+
+  // install
+  table.install(strategyP);
+  table.install(strategyQ);
+
+  BOOST_CHECK(table.insert("ndn:/", nameP));
+  // { '/'=>P }
+  measurements.get("ndn:/")     ->getOrCreateStrategyInfo<PStrategyInfo>();
+  measurements.get("ndn:/A")    ->getOrCreateStrategyInfo<PStrategyInfo>();
+  measurements.get("ndn:/A/B")  ->getOrCreateStrategyInfo<PStrategyInfo>();
+  measurements.get("ndn:/A/C")  ->getOrCreateStrategyInfo<PStrategyInfo>();
+
+  BOOST_CHECK(table.insert("ndn:/A/B", nameP));
+  // { '/'=>P, '/A/B'=>P }
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>()));
+
+  BOOST_CHECK(table.insert("ndn:/A", nameQ));
+  // { '/'=>P, '/A/B'=>P, '/A'=>Q }
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>()));
+
+  table.erase("ndn:/A/B");
+  // { '/'=>P, '/A'=>Q }
+  BOOST_CHECK( static_cast<bool>(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>()));
+  BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>()));
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace tests