table: don't use shared_ptr in Measurements

refs #3164

Change-Id: I7705d00ac155b15b5db69809610b68e96360a0ae
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index 251e3d6..9adc6ab 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -343,7 +343,7 @@
 
   auto getMeInfo = [&] () -> shared_ptr<NccStrategy::MeasurementsEntryInfo> {
     Measurements& measurements = topo.getForwarder(nodeA).getMeasurements();
-    shared_ptr<measurements::Entry> me = measurements.findExactMatch("ndn:/P");
+    measurements::Entry* me = measurements.findExactMatch("ndn:/P");
     return me == nullptr ? nullptr : me->getStrategyInfo<NccStrategy::MeasurementsEntryInfo>();
   };
 
diff --git a/tests/daemon/table/fib.t.cpp b/tests/daemon/table/fib.t.cpp
index 7071c19..46a3bca 100644
--- a/tests/daemon/table/fib.t.cpp
+++ b/tests/daemon/table/fib.t.cpp
@@ -207,11 +207,11 @@
   fib.insert("/A/B/C");
 
   Measurements measurements(nameTree);
-  shared_ptr<measurements::Entry> mAB = measurements.get("/A/B");
-  shared_ptr<measurements::Entry> mABCD = measurements.get("/A/B/C/D");
+  measurements::Entry& mAB = measurements.get("/A/B");
+  measurements::Entry& mABCD = measurements.get("/A/B/C/D");
 
-  BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*mAB).getPrefix(), "/A");
-  BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*mABCD).getPrefix(), "/A/B/C");
+  BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mAB).getPrefix(), "/A");
+  BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mABCD).getPrefix(), "/A/B/C");
 }
 
 BOOST_AUTO_TEST_CASE(RemoveNextHopFromAllEntries)
diff --git a/tests/daemon/table/measurements-accessor.t.cpp b/tests/daemon/table/measurements-accessor.t.cpp
index cab1dbb..292c5a6 100644
--- a/tests/daemon/table/measurements-accessor.t.cpp
+++ b/tests/daemon/table/measurements-accessor.t.cpp
@@ -31,9 +31,10 @@
 #include "../fw/install-strategy.hpp"
 
 namespace nfd {
+namespace measurements {
 namespace tests {
 
-using measurements::Entry;
+using namespace nfd::tests;
 
 class MeasurementsAccessorTestStrategy : public DummyStrategy
 {
@@ -81,7 +82,8 @@
   MeasurementsAccessor& accessor2;
 };
 
-BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, MeasurementsAccessorFixture)
+BOOST_AUTO_TEST_SUITE(Table)
+BOOST_FIXTURE_TEST_SUITE(TestMeasurementsAccessor, MeasurementsAccessorFixture)
 
 BOOST_AUTO_TEST_CASE(Get)
 {
@@ -100,17 +102,17 @@
 
 BOOST_AUTO_TEST_CASE(GetParent)
 {
-  shared_ptr<Entry> entryRoot = measurements.get("/");
-  BOOST_CHECK(accessor1.getParent(*entryRoot) == nullptr);
-  BOOST_CHECK(accessor2.getParent(*entryRoot) == nullptr);
+  Entry& entryRoot = measurements.get("/");
+  BOOST_CHECK(accessor1.getParent(entryRoot) == nullptr);
+  BOOST_CHECK(accessor2.getParent(entryRoot) == nullptr);
 
-  shared_ptr<Entry> entryABC = measurements.get("/A/B/C");
-  BOOST_CHECK(accessor1.getParent(*entryABC) != nullptr);
-  BOOST_CHECK(accessor2.getParent(*entryABC) == nullptr);
+  Entry& entryABC = measurements.get("/A/B/C");
+  BOOST_CHECK(accessor1.getParent(entryABC) != nullptr);
+  BOOST_CHECK(accessor2.getParent(entryABC) == nullptr);
 
-  shared_ptr<Entry> entryAB = measurements.get("/A/B");
-  BOOST_CHECK(accessor1.getParent(*entryAB) == nullptr);
-  // whether accessor2.getParent(*entryAB) can return an Entry is undefined,
+  Entry& entryAB = measurements.get("/A/B");
+  BOOST_CHECK(accessor1.getParent(entryAB) == nullptr);
+  // whether accessor2.getParent(entryAB) can return an Entry is undefined,
   // because strategy2 shouldn't obtain entryAB in the first place
 }
 
@@ -153,7 +155,9 @@
   BOOST_CHECK(accessor2.findExactMatch("/F"    ) == nullptr);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestMeasurementsAccessor
+BOOST_AUTO_TEST_SUITE_END() // Table
 
 } // namespace tests
+} // namespace measurements
 } // namespace nfd
diff --git a/tests/daemon/table/measurements.t.cpp b/tests/daemon/table/measurements.t.cpp
index c8b2e27..79b2b94 100644
--- a/tests/daemon/table/measurements.t.cpp
+++ b/tests/daemon/table/measurements.t.cpp
@@ -30,8 +30,11 @@
 #include "tests/test-common.hpp"
 
 namespace nfd {
+namespace measurements {
 namespace tests {
 
+using namespace nfd::tests;
+
 BOOST_AUTO_TEST_SUITE(Table)
 
 class MeasurementsFixture : public UnitTestTimeFixture
@@ -51,19 +54,19 @@
 
 BOOST_AUTO_TEST_CASE(Get_Parent)
 {
-  shared_ptr<measurements::Entry> entryAB = measurements.get("/A/B");
-  BOOST_REQUIRE(entryAB != nullptr);
-  BOOST_CHECK_EQUAL(entryAB->getName(), "/A/B");
+  Entry& entryAB = measurements.get("/A/B");
+  BOOST_CHECK_EQUAL(entryAB.getName(), "/A/B");
 
-  shared_ptr<measurements::Entry> entry0 = measurements.get("/");
-  BOOST_REQUIRE(entry0 != nullptr);
+  Entry& entry0 = measurements.get("/");
+  BOOST_CHECK_EQUAL(entry0.getName(), "/");
 
-  shared_ptr<measurements::Entry> entryA = measurements.getParent(*entryAB);
+  Entry* entryA = measurements.getParent(entryAB);
   BOOST_REQUIRE(entryA != nullptr);
   BOOST_CHECK_EQUAL(entryA->getName(), "/A");
 
-  shared_ptr<measurements::Entry> entry0c = measurements.getParent(*entryA);
-  BOOST_CHECK_EQUAL(entry0, entry0c);
+  Entry* entry0c = measurements.getParent(*entryA);
+  BOOST_REQUIRE(entry0c != nullptr);
+  BOOST_CHECK_EQUAL(&entry0, entry0c);
 }
 
 BOOST_AUTO_TEST_CASE(GetWithFibEntry)
@@ -73,13 +76,11 @@
   const fib::Entry* fibA = fib.insert("/A").first;
   const fib::Entry* fibAB = fib.insert("/A/B").first;
 
-  shared_ptr<measurements::Entry> entryA = measurements.get(*fibA);
-  BOOST_REQUIRE(entryA != nullptr);
-  BOOST_CHECK_EQUAL(entryA->getName(), "/A");
+  Entry& entryA = measurements.get(*fibA);
+  BOOST_CHECK_EQUAL(entryA.getName(), "/A");
 
-  shared_ptr<measurements::Entry> entryAB = measurements.get(*fibAB);
-  BOOST_REQUIRE(entryAB != nullptr);
-  BOOST_CHECK_EQUAL(entryAB->getName(), "/A/B");
+  Entry& entryAB = measurements.get(*fibAB);
+  BOOST_CHECK_EQUAL(entryAB.getName(), "/A/B");
 }
 
 BOOST_AUTO_TEST_CASE(GetWithEmptyFibEntry) // Bug 3275
@@ -88,9 +89,8 @@
 
   const fib::Entry& fib0 = fib.findLongestPrefixMatch("/");
 
-  shared_ptr<measurements::Entry> entry0 = measurements.get(fib0);
-  BOOST_REQUIRE(entry0 != nullptr);
-  BOOST_CHECK_EQUAL(entry0->getName(), "/");
+  Entry& entry0 = measurements.get(fib0);
+  BOOST_CHECK_EQUAL(entry0.getName(), "/");
 }
 
 BOOST_AUTO_TEST_CASE(GetWithPitEntry)
@@ -104,13 +104,11 @@
   shared_ptr<Interest> interestFull = makeInterest(fullName);
   shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first;
 
-  shared_ptr<measurements::Entry> entryA = measurements.get(*pitA);
-  BOOST_REQUIRE(entryA != nullptr);
-  BOOST_CHECK_EQUAL(entryA->getName(), "/A");
+  Entry& entryA = measurements.get(*pitA);
+  BOOST_CHECK_EQUAL(entryA.getName(), "/A");
 
-  shared_ptr<measurements::Entry> entryFull = measurements.get(*pitFull);
-  BOOST_REQUIRE(entryFull != nullptr);
-  BOOST_CHECK_EQUAL(entryFull->getName(), fullName);
+  Entry& entryFull = measurements.get(*pitFull);
+  BOOST_CHECK_EQUAL(entryFull.getName(), fullName);
 }
 
 class DummyStrategyInfo1 : public fw::StrategyInfo
@@ -136,20 +134,20 @@
 BOOST_AUTO_TEST_CASE(FindLongestPrefixMatch)
 {
   measurements.get("/A");
-  measurements.get("/A/B/C")->getOrCreateStrategyInfo<DummyStrategyInfo1>();
+  measurements.get("/A/B/C").getOrCreateStrategyInfo<DummyStrategyInfo1>();
   measurements.get("/A/B/C/D");
 
-  shared_ptr<measurements::Entry> found1 = measurements.findLongestPrefixMatch("/A/B/C/D/E");
+  Entry* found1 = measurements.findLongestPrefixMatch("/A/B/C/D/E");
   BOOST_REQUIRE(found1 != nullptr);
   BOOST_CHECK_EQUAL(found1->getName(), "/A/B/C/D");
 
-  shared_ptr<measurements::Entry> found2 = measurements.findLongestPrefixMatch("/A/B/C/D/E",
-      measurements::EntryWithStrategyInfo<DummyStrategyInfo1>());
+  Entry* found2 = measurements.findLongestPrefixMatch("/A/B/C/D/E",
+      EntryWithStrategyInfo<DummyStrategyInfo1>());
   BOOST_REQUIRE(found2 != nullptr);
   BOOST_CHECK_EQUAL(found2->getName(), "/A/B/C");
 
-  shared_ptr<measurements::Entry> found3 = measurements.findLongestPrefixMatch("/A/B/C/D/E",
-      measurements::EntryWithStrategyInfo<DummyStrategyInfo2>());
+  Entry* found3 = measurements.findLongestPrefixMatch("/A/B/C/D/E",
+      EntryWithStrategyInfo<DummyStrategyInfo2>());
   BOOST_CHECK(found3 == nullptr);
 }
 
@@ -158,23 +156,23 @@
   Pit pit(nameTree);
 
   measurements.get("/A");
-  measurements.get("/A/B/C")->getOrCreateStrategyInfo<DummyStrategyInfo1>();
+  measurements.get("/A/B/C").getOrCreateStrategyInfo<DummyStrategyInfo1>();
   measurements.get("/A/B/C/D");
 
   shared_ptr<Interest> interest = makeInterest("/A/B/C/D/E");
   shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
 
-  shared_ptr<measurements::Entry> found1 = measurements.findLongestPrefixMatch(*pitEntry);
+  Entry* found1 = measurements.findLongestPrefixMatch(*pitEntry);
   BOOST_REQUIRE(found1 != nullptr);
   BOOST_CHECK_EQUAL(found1->getName(), "/A/B/C/D");
 
-  shared_ptr<measurements::Entry> found2 = measurements.findLongestPrefixMatch(*pitEntry,
-      measurements::EntryWithStrategyInfo<DummyStrategyInfo1>());
+  Entry* found2 = measurements.findLongestPrefixMatch(*pitEntry,
+      EntryWithStrategyInfo<DummyStrategyInfo1>());
   BOOST_REQUIRE(found2 != nullptr);
   BOOST_CHECK_EQUAL(found2->getName(), "/A/B/C");
 
-  shared_ptr<measurements::Entry> found3 = measurements.findLongestPrefixMatch(*pitEntry,
-      measurements::EntryWithStrategyInfo<DummyStrategyInfo2>());
+  Entry* found3 = measurements.findLongestPrefixMatch(*pitEntry,
+      EntryWithStrategyInfo<DummyStrategyInfo2>());
   BOOST_CHECK(found3 == nullptr);
 }
 
@@ -186,9 +184,9 @@
 
   BOOST_CHECK_EQUAL(measurements.size(), 0);
 
-  shared_ptr<measurements::Entry> entryA = measurements.get(nameA);
-  shared_ptr<measurements::Entry> entryB = measurements.get(nameB);
-  shared_ptr<measurements::Entry> entryC = measurements.get(nameC);
+  Entry& entryA = measurements.get(nameA);
+  measurements.get(nameB);
+  Entry& entryC = measurements.get(nameC);
   BOOST_CHECK_EQUAL(measurements.size(), 3);
 
   const time::nanoseconds EXTEND_A = time::seconds(2);
@@ -202,15 +200,12 @@
   BOOST_ASSERT(CHECK2 < EXTEND_C);
   BOOST_ASSERT(EXTEND_C < CHECK3);
 
-  measurements.extendLifetime(*entryA, EXTEND_A);
-  measurements.extendLifetime(*entryC, EXTEND_C);
+  measurements.extendLifetime(entryA, EXTEND_A);
+  measurements.extendLifetime(entryC, EXTEND_C);
   // remaining lifetime:
   //   A = initial lifetime, because it's extended by less duration
   //   B = initial lifetime
   //   C = EXTEND_C
-  entryA.reset();
-  entryB.reset();
-  entryC.reset();
 
   this->advanceClocks(time::milliseconds(100), CHECK1);
   BOOST_CHECK(measurements.findExactMatch(nameA) != nullptr);
@@ -235,7 +230,9 @@
 {
   size_t nNameTreeEntriesBefore = nameTree.size();
 
-  shared_ptr<measurements::Entry> entry = measurements.get("/A");
+  measurements.get("/A");
+  BOOST_CHECK_EQUAL(measurements.size(), 1);
+
   this->advanceClocks(Measurements::getInitialLifetime() + time::milliseconds(10));
   BOOST_CHECK_EQUAL(measurements.size(), 0);
   BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
@@ -245,4 +242,5 @@
 BOOST_AUTO_TEST_SUITE_END() // Table
 
 } // namespace tests
+} // namespace measurements
 } // namespace nfd
diff --git a/tests/daemon/table/strategy-choice.t.cpp b/tests/daemon/table/strategy-choice.t.cpp
index 5897981..42a36b0 100644
--- a/tests/daemon/table/strategy-choice.t.cpp
+++ b/tests/daemon/table/strategy-choice.t.cpp
@@ -157,11 +157,11 @@
   BOOST_CHECK(table.insert("/A/B/C", nameQ));
 
   Measurements& measurements = forwarder.getMeasurements();
-  shared_ptr<measurements::Entry> mAB = measurements.get("/A/B");
-  shared_ptr<measurements::Entry> mABCD = measurements.get("/A/B/C/D");
+  measurements::Entry& mAB = measurements.get("/A/B");
+  measurements::Entry& mABCD = measurements.get("/A/B/C/D");
 
-  BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*mAB).getName(), nameP);
-  BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*mABCD).getName(), nameQ);
+  BOOST_CHECK_EQUAL(table.findEffectiveStrategy(mAB).getName(), nameP);
+  BOOST_CHECK_EQUAL(table.findEffectiveStrategy(mABCD).getName(), nameQ);
 }
 
 //XXX BOOST_CONCEPT_ASSERT((ForwardIterator<std::vector<int>::iterator>))
@@ -222,31 +222,31 @@
 
   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>();
+  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(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() != nullptr);
 
   BOOST_CHECK(table.insert("ndn:/A", nameQ));
   // { '/'=>P, '/A/B'=>P, '/A'=>Q }
-  BOOST_CHECK(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>() == nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() == nullptr);
+  BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
 
   table.erase("ndn:/A/B");
   // { '/'=>P, '/A'=>Q }
-  BOOST_CHECK(measurements.get("ndn:/")   ->getStrategyInfo<PStrategyInfo>() != nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A")  ->getStrategyInfo<PStrategyInfo>() == nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() == nullptr);
-  BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() == nullptr);
+  BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() == nullptr);
+  BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
 }
 
 BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)