tests: refactor common test infrastructure and fixtures

Change-Id: I597c11130eefa2cc2846ee6655c85dc04f2f22ef
diff --git a/tests/unit/util/segment-fetcher.t.cpp b/tests/unit/util/segment-fetcher.t.cpp
index 7f63db8..c58c1f9 100644
--- a/tests/unit/util/segment-fetcher.t.cpp
+++ b/tests/unit/util/segment-fetcher.t.cpp
@@ -25,10 +25,9 @@
 #include "ndn-cxx/lp/nack.hpp"
 #include "ndn-cxx/util/dummy-client-face.hpp"
 
-#include "tests/boost-test.hpp"
-#include "tests/make-interest-data.hpp"
+#include "tests/test-common.hpp"
 #include "tests/unit/dummy-validator.hpp"
-#include "tests/unit/identity-management-time-fixture.hpp"
+#include "tests/unit/io-key-chain-fixture.hpp"
 
 #include <set>
 
@@ -38,27 +37,20 @@
 
 using namespace ndn::tests;
 
-class Fixture : public IdentityManagementTimeFixture
+class SegmentFetcherFixture : public IoKeyChainFixture
 {
 public:
-  Fixture()
-    : face(io, m_keyChain)
-  {
-  }
-
   static shared_ptr<Data>
   makeDataSegment(const Name& baseName, uint64_t segment, bool isFinal)
   {
     const uint8_t buffer[] = "Hello, world!";
-
-    auto data = make_shared<Data>(Name(baseName).appendSegment(segment));
-    data->setFreshnessPeriod(1_s);
+    auto data = makeData(Name(baseName).appendSegment(segment));
     data->setContent(buffer, sizeof(buffer));
+    data->setFreshnessPeriod(1_s);
     if (isFinal) {
       data->setFinalBlock(data->getName()[-1]);
     }
-
-    return signData(data);
+    return data;
   }
 
   void
@@ -90,21 +82,20 @@
   }
 
   void
-  nackLastInterest(lp::NackReason nackReason)
+  nackLastInterest(lp::NackReason reason)
   {
     const Interest& lastInterest = face.sentInterests.back();
-    lp::Nack nack = makeNack(lastInterest, nackReason);
-    face.receive(nack);
+    face.receive(makeNack(lastInterest, reason));
     advanceClocks(10_ms);
   }
 
   void
   connectSignals(const shared_ptr<SegmentFetcher>& fetcher)
   {
-    fetcher->onInOrderData.connect(bind(&Fixture::onInOrderData, this, _1));
-    fetcher->onInOrderComplete.connect(bind(&Fixture::onInOrderComplete, this));
-    fetcher->onComplete.connect(bind(&Fixture::onComplete, this, _1));
-    fetcher->onError.connect(bind(&Fixture::onError, this, _1));
+    fetcher->onInOrderData.connect(bind(&SegmentFetcherFixture::onInOrderData, this, _1));
+    fetcher->onInOrderComplete.connect(bind(&SegmentFetcherFixture::onInOrderComplete, this));
+    fetcher->onComplete.connect(bind(&SegmentFetcherFixture::onComplete, this, _1));
+    fetcher->onError.connect(bind(&SegmentFetcherFixture::onError, this, _1));
 
     fetcher->afterSegmentReceived.connect([this] (const auto&) { ++this->nAfterSegmentReceived; });
     fetcher->afterSegmentValidated.connect([this] (const auto &) { ++this->nAfterSegmentValidated; });
@@ -133,7 +124,7 @@
 
       uniqSegmentsSent.insert(interest.getName().get(-1).toSegment());
       if (uniqSegmentsSent.size() == nSegments) {
-        io.stop();
+        m_io.stop();
       }
     }
     else {
@@ -154,7 +145,7 @@
   }
 
 public:
-  DummyClientFace face;
+  DummyClientFace face{m_io, m_keyChain};
   std::set<uint64_t> uniqSegmentsSent;
 
   int nErrors = 0;
@@ -178,7 +169,7 @@
 };
 
 BOOST_AUTO_TEST_SUITE(Util)
-BOOST_FIXTURE_TEST_SUITE(TestSegmentFetcher, Fixture)
+BOOST_FIXTURE_TEST_SUITE(TestSegmentFetcher, SegmentFetcherFixture)
 
 BOOST_AUTO_TEST_CASE(InvalidOptions)
 {
@@ -318,7 +309,7 @@
 
   shared_ptr<SegmentFetcher> fetcher = SegmentFetcher::start(face, Interest("/hello/world"),
                                                              acceptValidator);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -341,7 +332,7 @@
   sendNackInsteadOfDropping = false;
 
   auto fetcher = SegmentFetcher::start(face, Interest("/hello/world"), acceptValidator, options);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -366,7 +357,7 @@
 
   shared_ptr<SegmentFetcher> fetcher = SegmentFetcher::start(face, Interest("/hello/world"),
                                                              acceptValidator);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -390,7 +381,7 @@
   defaultSegmentToSend = 47;
 
   auto fetcher = SegmentFetcher::start(face, Interest("/hello/world"), acceptValidator, options);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -635,7 +626,7 @@
 
   shared_ptr<SegmentFetcher> fetcher = SegmentFetcher::start(face, Interest("/hello/world"),
                                                              acceptValidator);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -660,7 +651,7 @@
 
   shared_ptr<SegmentFetcher> fetcher = SegmentFetcher::start(face, Interest("/hello/world"),
                                                              acceptValidator);
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
   connectSignals(fetcher);
 
   face.processEvents(1_s);
@@ -680,7 +671,7 @@
   segmentsToDropOrNack.push(0);
   sendNackInsteadOfDropping = true;
   nackReason = lp::NackReason::NO_ROUTE;
-  face.onSendInterest.connect(bind(&Fixture::onInterest, this, _1));
+  face.onSendInterest.connect(bind(&SegmentFetcherFixture::onInterest, this, _1));
 
   shared_ptr<SegmentFetcher> fetcher = SegmentFetcher::start(face, Interest("/hello/world"),
                                                              acceptValidator);