tests: resetGlobalIoService for every test

All tests must use BaseFixture or a fixture derived from it to get this feature.

This commit also fixes a few warnings in tests/mgmt, and moves test cases into nfd::tests namespace.

refs #1290

Change-Id: I891441a5abce170e35648d463f7157b18429f79f
diff --git a/daemon/table/fib-nexthop.cpp b/daemon/table/fib-nexthop.cpp
index 178d853..6fec93f 100644
--- a/daemon/table/fib-nexthop.cpp
+++ b/daemon/table/fib-nexthop.cpp
@@ -26,12 +26,12 @@
 }
 
 void
-NextHop::setCost(int32_t cost)
+NextHop::setCost(uint32_t cost)
 {
   m_cost = cost;
 }
 
-int32_t
+uint32_t
 NextHop::getCost() const
 {
   return m_cost;
diff --git a/daemon/table/fib-nexthop.hpp b/daemon/table/fib-nexthop.hpp
index 41c121b..4dc2b65 100644
--- a/daemon/table/fib-nexthop.hpp
+++ b/daemon/table/fib-nexthop.hpp
@@ -29,14 +29,14 @@
   getFace() const;
   
   void
-  setCost(int32_t cost);
+  setCost(uint32_t cost);
   
-  int32_t
+  uint32_t
   getCost() const;
 
 private:
   shared_ptr<Face> m_face;
-  int32_t m_cost;
+  uint32_t m_cost;
 };
 
 } // namespace fib
diff --git a/tests/core/event-emitter.cpp b/tests/core/event-emitter.cpp
index c44b6d2..b6ee048 100644
--- a/tests/core/event-emitter.cpp
+++ b/tests/core/event-emitter.cpp
@@ -6,9 +6,12 @@
 
 #include "core/event-emitter.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(UtilEventEmitter, BaseFixture)
 
 class EventEmitterTester : noncopyable
 {
@@ -117,8 +120,6 @@
 EventEmitterTest_RefObject_byRef(const EventEmitterTest_RefObject& a1) {}
 
 
-BOOST_AUTO_TEST_SUITE(UtilEventEmitter)
-
 BOOST_AUTO_TEST_CASE(ZeroListener)
 {
   EventEmitter<> ee;
@@ -228,4 +229,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/core/limited-io.cpp b/tests/core/limited-io.cpp
index 5752685..ea19585 100644
--- a/tests/core/limited-io.cpp
+++ b/tests/core/limited-io.cpp
@@ -7,6 +7,7 @@
 #include "limited-io.hpp"
 
 namespace nfd {
+namespace tests {
 
 const int LimitedIo::UNLIMITED_OPS = std::numeric_limits<int>::max();
 const time::Duration LimitedIo::UNLIMITED_TIME = time::nanoseconds(-1);
@@ -15,7 +16,6 @@
   : m_isRunning(false)
   , m_nOpsRemaining(0)
 {
-  resetGlobalIoService();
 }
 
 LimitedIo::StopReason
@@ -55,4 +55,5 @@
   getGlobalIoService().stop();
 }
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/core/limited-io.hpp b/tests/core/limited-io.hpp
index 14dadd7..7fb4f70 100644
--- a/tests/core/limited-io.hpp
+++ b/tests/core/limited-io.hpp
@@ -10,6 +10,7 @@
 #include "core/scheduler.hpp"
 
 namespace nfd {
+namespace tests {
 
 class LimitedIo
 {
@@ -44,6 +45,7 @@
   StopReason m_reason;
 };
 
+} // namespace tests
 } // namespace nfd
 
 #endif // NFD_TEST_CORE_LIMITED_IO_HPP
diff --git a/tests/core/logger.cpp b/tests/core/logger.cpp
index 6694ece..0530dcc 100644
--- a/tests/core/logger.cpp
+++ b/tests/core/logger.cpp
@@ -10,12 +10,14 @@
 #include <boost/test/unit_test.hpp>
 #include <iostream>
 
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(CoreLogger)
+BOOST_FIXTURE_TEST_SUITE(CoreLogger, BaseFixture)
 
-struct LoggerFixture
+struct LoggerFixture : protected BaseFixture
 {
   LoggerFixture()
     : m_savedBuf(std::cerr.rdbuf())
@@ -151,4 +153,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/core/scheduler.cpp b/tests/core/scheduler.cpp
index d6b51fa..806c982 100644
--- a/tests/core/scheduler.cpp
+++ b/tests/core/scheduler.cpp
@@ -6,13 +6,14 @@
 
 #include "core/scheduler.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(CoreScheduler)
+BOOST_FIXTURE_TEST_SUITE(CoreScheduler, BaseFixture)
 
-struct SchedulerFixture
+struct SchedulerFixture : protected BaseFixture
 {
   SchedulerFixture()
     : count1(0)
@@ -56,8 +57,6 @@
 
 BOOST_FIXTURE_TEST_CASE(Events, SchedulerFixture)
 {
-  resetGlobalIoService();
-
   scheduler::schedule(time::seconds(0.5), bind(&SchedulerFixture::event1, this));
 
   EventId i = scheduler::schedule(time::seconds(1.0), bind(&SchedulerFixture::event2, this));
@@ -72,7 +71,7 @@
   i = scheduler::getGlobalScheduler().schedulePeriodicEvent(time::seconds(0.3), time::seconds(0.1), bind(&SchedulerFixture::event4, this));
   scheduler::schedule(time::seconds(1), bind(&scheduler::cancel, i));
 
-  getGlobalIoService().run();
+  g_io.run();
 
   BOOST_CHECK_EQUAL(count1, 1);
   BOOST_CHECK_EQUAL(count2, 0);
@@ -86,7 +85,7 @@
   scheduler::cancel(i);
 }
 
-struct SelfCancelFixture
+struct SelfCancelFixture : protected BaseFixture
 {
   void
   cancelSelf()
@@ -99,14 +98,13 @@
 
 BOOST_FIXTURE_TEST_CASE(SelfCancel, SelfCancelFixture)
 {
-  resetGlobalIoService();
-
   m_selfEventId = scheduler::schedule(time::seconds(0.1),
                                       bind(&SelfCancelFixture::cancelSelf, this));
 
-  BOOST_REQUIRE_NO_THROW(getGlobalIoService().run());
+  BOOST_REQUIRE_NO_THROW(g_io.run());
 }
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/face/dummy-face.hpp b/tests/face/dummy-face.hpp
index 45a3d43..969053a 100644
--- a/tests/face/dummy-face.hpp
+++ b/tests/face/dummy-face.hpp
@@ -11,6 +11,7 @@
 #include "face/local-face.hpp"
 
 namespace nfd {
+namespace tests {
 
 /** \class DummyFace
  *  \brief a Face for unit testing
@@ -50,11 +51,7 @@
     this->onReceiveData(data);
   }
 
-protected:
-  virtual void
-  afterSend()
-  {
-  }
+  EventEmitter<> afterSend;
 
 public:
   std::vector<Interest> m_sentInterests;
@@ -64,6 +61,7 @@
 typedef DummyFaceImpl<Face> DummyFace;
 typedef DummyFaceImpl<LocalFace> DummyLocalFace;
 
+} // namespace tests
 } // namespace nfd
 
 #endif // TEST_FACE_DUMMY_FACE_HPP
diff --git a/tests/face/ethernet.cpp b/tests/face/ethernet.cpp
index 6803a1a..cd84008 100644
--- a/tests/face/ethernet.cpp
+++ b/tests/face/ethernet.cpp
@@ -5,14 +5,14 @@
  */
 
 #include "face/ethernet-channel-factory.hpp"
-
 #include <ndn-cpp-dev/security/key-chain.hpp>
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FaceEthernet)
+BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(MulticastFacesMap)
 {
@@ -104,4 +104,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/face/face.cpp b/tests/face/face.cpp
index 5f8ab6e..d48ed70 100644
--- a/tests/face/face.cpp
+++ b/tests/face/face.cpp
@@ -8,11 +8,12 @@
 #include "face/local-face.hpp"
 #include "dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FaceFace)
+BOOST_FIXTURE_TEST_SUITE(FaceFace, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(Description)
 {
@@ -52,4 +53,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/face/ndnlp.cpp b/tests/face/ndnlp.cpp
index 77e99e2..77ac7e9 100644
--- a/tests/face/ndnlp.cpp
+++ b/tests/face/ndnlp.cpp
@@ -8,11 +8,12 @@
 #include "face/ndnlp-slicer.hpp"
 #include "face/ndnlp-partial-message-store.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FaceNdnlp)
+BOOST_FIXTURE_TEST_SUITE(FaceNdnlp, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(SequenceBlock)
 {
@@ -129,7 +130,7 @@
   BOOST_CHECK_EQUAL(totalPayloadSize, block.size());
 }
 
-class ReassembleFixture
+class ReassembleFixture : protected BaseFixture
 {
 protected:
   ReassembleFixture()
@@ -210,4 +211,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index cfe0ba5..5990ab4 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -6,14 +6,14 @@
 
 #include "face/tcp-channel-factory.hpp"
 #include "core/scheduler.hpp"
-
 #include <ndn-cpp-dev/security/key-chain.hpp>
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FaceTcp)
+BOOST_FIXTURE_TEST_SUITE(FaceTcp, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(ChannelMap)
 {
@@ -28,7 +28,7 @@
   BOOST_CHECK_NE(channel1, channel2);
 }
 
-class EndToEndFixture
+class EndToEndFixture : protected BaseFixture
 {
 public:
   void
@@ -373,4 +373,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index 9d6a6cf..8fba080 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -6,16 +6,16 @@
 
 #include "face/unix-stream-channel-factory.hpp"
 #include "core/scheduler.hpp"
-
 #include <ndn-cpp-dev/security/key-chain.hpp>
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
 
 using namespace boost::asio::local;
 
-namespace nfd {
-
-BOOST_AUTO_TEST_SUITE(FaceUnixStream)
+BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(ChannelMap)
 {
@@ -30,7 +30,7 @@
   BOOST_CHECK_NE(channel1, channel2);
 }
 
-class EndToEndFixture
+class EndToEndFixture : protected BaseFixture
 {
 public:
   void
@@ -444,4 +444,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/fw/broadcast-strategy.cpp b/tests/fw/broadcast-strategy.cpp
index 26d0687..b256432 100644
--- a/tests/fw/broadcast-strategy.cpp
+++ b/tests/fw/broadcast-strategy.cpp
@@ -6,17 +6,17 @@
 
 #include "fw/broadcast-strategy.hpp"
 #include "strategy-tester.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FwBroadcastStrategy)
+BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(ForwardTwo)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
   typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
   BroadcastStrategyTester strategy(forwarder);
@@ -60,7 +60,6 @@
 
 BOOST_AUTO_TEST_CASE(Reject)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
   typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
   BroadcastStrategyTester strategy(forwarder);
@@ -85,4 +84,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/fw/forwarder.cpp b/tests/fw/forwarder.cpp
index 6607766..0a30852 100644
--- a/tests/fw/forwarder.cpp
+++ b/tests/fw/forwarder.cpp
@@ -5,17 +5,17 @@
  */
 
 #include "fw/forwarder.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FwForwarder)
+BOOST_FIXTURE_TEST_SUITE(FwForwarder, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(AddRemoveFace)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
 
   shared_ptr<Face> face1 = make_shared<DummyFace>();
@@ -38,18 +38,8 @@
   BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID);
 }
 
-class ForwarderTestFace : public DummyFace {
-public:
-  virtual void
-  afterSend()
-  {
-    getGlobalIoService().stop();
-  }
-};
-
 BOOST_AUTO_TEST_CASE(SimpleExchange)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
 
   Name nameA  ("ndn:/A");
@@ -59,8 +49,10 @@
   interestAB.setInterestLifetime(4000);
   Data dataABC(nameABC);
 
-  shared_ptr<ForwarderTestFace> face1 = make_shared<ForwarderTestFace>();
-  shared_ptr<ForwarderTestFace> face2 = make_shared<ForwarderTestFace>();
+  shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
+  shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
+  face1->afterSend += bind(&boost::asio::io_service::stop, &g_io);
+  face2->afterSend += bind(&boost::asio::io_service::stop, &g_io);
   forwarder.addFace(face1);
   forwarder.addFace(face2);
 
@@ -71,15 +63,15 @@
   fibEntry->addNextHop(face2, 0);
 
   face1->receiveInterest(interestAB);
-  getGlobalIoService().run();
-  getGlobalIoService().reset();
+  g_io.run();
+  g_io.reset();
   BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1);
   BOOST_CHECK(face2->m_sentInterests[0].getName().equals(nameAB));
   BOOST_CHECK_EQUAL(face2->m_sentInterests[0].getIncomingFaceId(), face1->getId());
 
   face2->receiveData(dataABC);
-  getGlobalIoService().run();
-  getGlobalIoService().reset();
+  g_io.run();
+  g_io.reset();
   BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
   BOOST_CHECK(face1->m_sentDatas[0].getName().equals(nameABC));
   BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getIncomingFaceId(), face2->getId());
@@ -115,7 +107,6 @@
 
 BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
 {
-  resetGlobalIoService();
   ScopeLocalhostIncomingTestForwarder forwarder;
   shared_ptr<Face> face1 = make_shared<DummyLocalFace>();
   shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -165,7 +156,6 @@
 
 BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
   shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
   shared_ptr<DummyFace>      face2 = make_shared<DummyFace>();
@@ -230,4 +220,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/fw/ncc-strategy.cpp b/tests/fw/ncc-strategy.cpp
index a258b83..2709913 100644
--- a/tests/fw/ncc-strategy.cpp
+++ b/tests/fw/ncc-strategy.cpp
@@ -6,14 +6,15 @@
 
 #include "fw/ncc-strategy.hpp"
 #include "strategy-tester.hpp"
-#include "../face/dummy-face.hpp"
-#include "../core/limited-io.hpp"
+#include "tests/face/dummy-face.hpp"
+#include "tests/core/limited-io.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(FwNccStrategy)
+BOOST_FIXTURE_TEST_SUITE(FwNccStrategy, BaseFixture)
 
 // NccStrategy is fairly complex.
 // The most important property is:
@@ -84,4 +85,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/fw/strategy-tester.hpp b/tests/fw/strategy-tester.hpp
index f8e0848..571492c 100644
--- a/tests/fw/strategy-tester.hpp
+++ b/tests/fw/strategy-tester.hpp
@@ -11,6 +11,7 @@
 #include "fw/strategy.hpp"
 
 namespace nfd {
+namespace tests {
 
 /** \class StrategyTester
  *  \brief extends strategy S for unit testing
@@ -64,7 +65,7 @@
   onAction();
 }
 
-
+} // namespace tests
 } // namespace nfd
 
 #endif // TEST_FW_STRATEGY_TESTER_HPP
diff --git a/tests/mgmt/config-file.cpp b/tests/mgmt/config-file.cpp
index bf275e4..ca89aec 100644
--- a/tests/mgmt/config-file.cpp
+++ b/tests/mgmt/config-file.cpp
@@ -7,13 +7,14 @@
 
 #include "mgmt/config-file.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 NFD_LOG_INIT("ConfigFileTest");
 
-BOOST_AUTO_TEST_SUITE(MgmtConfigFile)
+BOOST_FIXTURE_TEST_SUITE(MgmtConfigFile, BaseFixture)
 
 // a
 // {
@@ -342,6 +343,7 @@
   BOOST_CHECK(subB.allCallbacksFired());
 }
 
-} // namespace nfd
-
 BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/mgmt/fib-manager.cpp b/tests/mgmt/fib-manager.cpp
index 2352f53..00043d2 100644
--- a/tests/mgmt/fib-manager.cpp
+++ b/tests/mgmt/fib-manager.cpp
@@ -9,17 +9,16 @@
 #include "table/fib-nexthop.hpp"
 #include "face/face.hpp"
 #include "mgmt/internal-face.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <algorithm>
-
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 NFD_LOG_INIT("FibManagerTest");
 
-class FibManagerFixture
+class FibManagerFixture : protected BaseFixture
 {
 public:
 
@@ -32,9 +31,9 @@
   shared_ptr<Face>
   getFace(FaceId id)
   {
-    if (id > 0 && id <= m_faces.size())
+    if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
       {
-        return m_faces[id-1];
+        return m_faces[id - 1];
       }
     NFD_LOG_DEBUG("No face found returning NULL");
     return shared_ptr<DummyFace>();
@@ -120,10 +119,7 @@
   bool m_callbackFired;
 };
 
-
-BOOST_AUTO_TEST_SUITE(MgmtFibManager)
-
-
+BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, FibManagerFixture)
 
 bool
 foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
@@ -167,7 +163,7 @@
   return false;
 }
 
-BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -186,7 +182,7 @@
   BOOST_REQUIRE(didCallbackFire());
 }
 
-BOOST_FIXTURE_TEST_CASE(MalformedCommmand, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(MalformedCommmand)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -207,7 +203,7 @@
   BOOST_REQUIRE(didCallbackFire());
 }
 
-BOOST_FIXTURE_TEST_CASE(UnsupportedVerb, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(UnsupportedVerb)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -236,7 +232,7 @@
   BOOST_REQUIRE(didCallbackFire());
 }
 
-BOOST_FIXTURE_TEST_CASE(UnsignedCommand, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(UnsignedCommand)
 {
   addFace(make_shared<DummyFace>());
 
@@ -270,7 +266,7 @@
   BOOST_REQUIRE(!addedNextHopWithCost(fib, "/hello", 0, 101));
 }
 
-BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(UnauthorizedCommand)
 {
   addFace(make_shared<DummyFace>());
 
@@ -304,7 +300,7 @@
   BOOST_REQUIRE(!addedNextHopWithCost(fib, "/hello", 0, 101));
 }
 
-BOOST_FIXTURE_TEST_CASE(BadOptionParse, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(BadOptionParse)
 {
   addFace(make_shared<DummyFace>());
 
@@ -328,7 +324,7 @@
   BOOST_REQUIRE(didCallbackFire());
 }
 
-BOOST_FIXTURE_TEST_CASE(UnknownFaceId, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(UnknownFaceId)
 {
   addFace(make_shared<DummyFace>());
 
@@ -360,7 +356,7 @@
   BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101) == false);
 }
 
-BOOST_FIXTURE_TEST_CASE(TestImplicitFaceId, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
 {
   addFace(make_shared<DummyFace>());
 
@@ -402,7 +398,7 @@
   BOOST_REQUIRE(addedNextHopWithFace(fib, "/hello", 0, 101, getFace(1)));
 }
 
-BOOST_FIXTURE_TEST_CASE(AddNextHopVerbInitialAdd, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
 {
   addFace(make_shared<DummyFace>());
 
@@ -436,7 +432,7 @@
   BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101));
 }
 
-BOOST_FIXTURE_TEST_CASE(AddNextHopVerbAddToExisting, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
 {
   addFace(make_shared<DummyFace>());
 
@@ -490,9 +486,8 @@
     }
 }
 
-BOOST_FIXTURE_TEST_CASE(AddNextHopVerbUpdateFaceCost, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
 {
-  FibManagerFixture fixture;
   addFace(make_shared<DummyFace>());
 
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
@@ -568,7 +563,7 @@
     }
 }
 
-BOOST_FIXTURE_TEST_CASE(Insert, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(Insert)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -666,7 +661,7 @@
   face->onReceiveData.clear();
 }
 
-BOOST_FIXTURE_TEST_CASE(Delete, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(Delete)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -752,7 +747,7 @@
   face->onReceiveData.clear();
 }
 
-BOOST_FIXTURE_TEST_CASE(RemoveNextHop, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(RemoveNextHop)
 {
   shared_ptr<Face> face1 = make_shared<DummyFace>();
   shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -790,7 +785,7 @@
 
 }
 
-BOOST_FIXTURE_TEST_CASE(RemoveNoFace, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(RemoveNoFace)
 {
   shared_ptr<InternalFace> face(make_shared<InternalFace>());
   Fib fib;
@@ -818,7 +813,7 @@
   BOOST_REQUIRE(didCallbackFire());
 }
 
-BOOST_FIXTURE_TEST_CASE(RemoveNoPrefix, FibManagerFixture)
+BOOST_AUTO_TEST_CASE(RemoveNoPrefix)
 {
   addFace(make_shared<DummyFace>());
 
@@ -850,4 +845,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/mgmt/internal-face.cpp b/tests/mgmt/internal-face.cpp
index 52eaa23..f4d51ca 100644
--- a/tests/mgmt/internal-face.cpp
+++ b/tests/mgmt/internal-face.cpp
@@ -5,15 +5,16 @@
  */
 
 #include "mgmt/internal-face.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 NFD_LOG_INIT("InternalFaceTest");
 
-class InternalFaceFixture
+class InternalFaceFixture : protected BaseFixture
 {
 public:
 
@@ -72,7 +73,7 @@
   bool m_noOnInterestFired;
 };
 
-BOOST_AUTO_TEST_SUITE(MgmtInternalFace)
+BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture)
 
 void
 validatePutData(bool& called, const Name& expectedName, const Data& data)
@@ -81,7 +82,7 @@
   BOOST_CHECK_EQUAL(expectedName, data.getName());
 }
 
-BOOST_FIXTURE_TEST_CASE(PutData, InternalFaceFixture)
+BOOST_AUTO_TEST_CASE(PutData)
 {
   addFace(make_shared<DummyFace>());
 
@@ -100,7 +101,7 @@
   BOOST_CHECK_THROW(face->close(), InternalFace::Error);
 }
 
-BOOST_FIXTURE_TEST_CASE(SendInterestHitEnd, InternalFaceFixture)
+BOOST_AUTO_TEST_CASE(SendInterestHitEnd)
 {
   addFace(make_shared<DummyFace>());
 
@@ -122,9 +123,7 @@
   BOOST_REQUIRE(didNoOnInterestFire() == false);
 }
 
-
-
-BOOST_FIXTURE_TEST_CASE(SendInterestHitBegin, InternalFaceFixture)
+BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
 {
   addFace(make_shared<DummyFace>());
 
@@ -145,9 +144,7 @@
   BOOST_REQUIRE(didNoOnInterestFire() == false);
 }
 
-
-
-BOOST_FIXTURE_TEST_CASE(SendInterestHitExact, InternalFaceFixture)
+BOOST_AUTO_TEST_CASE(SendInterestHitExact)
 {
   addFace(make_shared<DummyFace>());
 
@@ -176,9 +173,7 @@
   BOOST_REQUIRE(didNoOnInterestFire() == false);
 }
 
-
-
-BOOST_FIXTURE_TEST_CASE(SendInterestHitPrevious, InternalFaceFixture)
+BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
 {
   addFace(make_shared<DummyFace>());
 
@@ -205,4 +200,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/mgmt/local-control-header-manager.cpp b/tests/mgmt/local-control-header-manager.cpp
index b7fdf58..43a649d 100644
--- a/tests/mgmt/local-control-header-manager.cpp
+++ b/tests/mgmt/local-control-header-manager.cpp
@@ -5,20 +5,17 @@
  */
 
 #include "mgmt/local-control-header-manager.hpp"
-#include "face/face.hpp"
-#include "face/local-face.hpp"
 #include "mgmt/internal-face.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <algorithm>
-
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 NFD_LOG_INIT("LocalControlHeaderManagerTest");
 
-class LocalControlHeaderManagerFixture
+class LocalControlHeaderManagerFixture : protected BaseFixture
 {
 public:
 
@@ -31,9 +28,9 @@
   shared_ptr<Face>
   getFace(FaceId id)
   {
-    if (id > 0 && id <= m_faces.size())
+    if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
       {
-        return m_faces[id-1];
+        return m_faces[id - 1];
       }
     NFD_LOG_DEBUG("No face found returning NULL");
     return shared_ptr<DummyFace>();
@@ -90,10 +87,9 @@
   bool m_callbackFired;
 };
 
+BOOST_FIXTURE_TEST_SUITE(MgmtLocalControlHeaderManager, LocalControlHeaderManagerFixture)
 
-BOOST_AUTO_TEST_SUITE(MgmtLocalControlHeaderManager)
-
-BOOST_FIXTURE_TEST_CASE(InFaceId, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(InFaceId)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -135,7 +131,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(NextHopFaceId, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(NextHopFaceId)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -178,7 +174,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(ShortCommand, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(ShortCommand)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -203,7 +199,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(ShortCommandModule, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(ShortCommandModule)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -228,7 +224,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(UnsupportedModule, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(UnsupportedModule)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -253,7 +249,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(InFaceIdUnsupportedVerb, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(InFaceIdUnsupportedVerb)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -278,7 +274,7 @@
   BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
 }
 
-BOOST_FIXTURE_TEST_CASE(NextHopFaceIdUnsupportedVerb, LocalControlHeaderManagerFixture)
+BOOST_AUTO_TEST_CASE(NextHopFaceIdUnsupportedVerb)
 {
   shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
   addFace(dummy);
@@ -305,4 +301,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/mgmt/manager-base.cpp b/tests/mgmt/manager-base.cpp
index feca0da..f6ddcb7 100644
--- a/tests/mgmt/manager-base.cpp
+++ b/tests/mgmt/manager-base.cpp
@@ -7,15 +7,14 @@
 #include "mgmt/manager-base.hpp"
 #include "mgmt/internal-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 NFD_LOG_INIT("ManagerBaseTest");
 
-BOOST_AUTO_TEST_SUITE(MgmtManagerBase)
-
-class ManagerBaseTest : public ManagerBase
+class ManagerBaseTest : public ManagerBase, protected BaseFixture
 {
 
 public:
@@ -90,7 +89,9 @@
 
 };
 
-BOOST_FIXTURE_TEST_CASE(SetResponse, ManagerBaseTest)
+BOOST_FIXTURE_TEST_SUITE(MgmtManagerBase, ManagerBaseTest)
+
+BOOST_AUTO_TEST_CASE(SetResponse)
 {
   ControlResponse response(200, "OK");
 
@@ -104,7 +105,7 @@
 }
 
 
-BOOST_FIXTURE_TEST_CASE(SendResponse3Arg, ManagerBaseTest)
+BOOST_AUTO_TEST_CASE(SendResponse3Arg)
 {
   getInternalFace()->onReceiveData +=
     bind(&ManagerBaseTest::validateControlResponse, this, _1,
@@ -115,7 +116,7 @@
 }
 
 
-BOOST_FIXTURE_TEST_CASE(SendResponse2Arg, ManagerBaseTest)
+BOOST_AUTO_TEST_CASE(SendResponse2Arg)
 {
   getInternalFace()->onReceiveData +=
     bind(&ManagerBaseTest::validateControlResponse, this, _1,
@@ -129,11 +130,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
-
-
-
-
-
-
-
diff --git a/tests/table/cs.cpp b/tests/table/cs.cpp
index b7bdbb8..eeca6b5 100644
--- a/tests/table/cs.cpp
+++ b/tests/table/cs.cpp
@@ -6,11 +6,12 @@
 
 #include "table/cs.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(TableCs)
+BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(FakeInsertFind)
 {
@@ -25,4 +26,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/table/fib.cpp b/tests/table/fib.cpp
index d1fe068..1615876 100644
--- a/tests/table/fib.cpp
+++ b/tests/table/fib.cpp
@@ -5,13 +5,14 @@
  */
 
 #include "table/fib.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(TableFib)
+BOOST_FIXTURE_TEST_SUITE(TableFib, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(Entry)
 {
@@ -302,4 +303,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/table/measurements-accessor.cpp b/tests/table/measurements-accessor.cpp
index 9738701..3d7e24f 100644
--- a/tests/table/measurements-accessor.cpp
+++ b/tests/table/measurements-accessor.cpp
@@ -7,11 +7,12 @@
 #include "table/measurements-accessor.hpp"
 #include "fw/forwarder.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(TableMeasurementsAccessor)
+BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture)
 
 class MeasurementsAccessorTestStrategy : public fw::Strategy
 {
@@ -47,7 +48,6 @@
 
 BOOST_AUTO_TEST_CASE(Access)
 {
-  resetGlobalIoService();
   Forwarder forwarder;
 
   shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
@@ -87,4 +87,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/table/measurements.cpp b/tests/table/measurements.cpp
index 4643fb8..69e2506 100644
--- a/tests/table/measurements.cpp
+++ b/tests/table/measurements.cpp
@@ -6,15 +6,15 @@
 
 #include "table/measurements.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(TableMeasurements)
+BOOST_FIXTURE_TEST_SUITE(TableMeasurements, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(Get_Parent)
 {
-  resetGlobalIoService();
   Measurements measurements;
 
   Name name0;
@@ -38,4 +38,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/table/name-tree.cpp b/tests/table/name-tree.cpp
index bc34c15..4411fd2 100644
--- a/tests/table/name-tree.cpp
+++ b/tests/table/name-tree.cpp
@@ -5,15 +5,17 @@
  */
 
 #include "table/name-tree.hpp"
-#include <boost/test/unit_test.hpp>
+
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 using name_tree::Entry;
 
-BOOST_AUTO_TEST_SUITE(TableNameTree)
+BOOST_FIXTURE_TEST_SUITE(TableNameTree, BaseFixture)
 
-BOOST_AUTO_TEST_CASE (Entry)
+BOOST_AUTO_TEST_CASE(Entry)
 {
   Name prefix("ndn:/named-data/research/abc/def/ghi");
 
@@ -99,7 +101,7 @@
   erasePitEntry(PitEntry2), false);
 }
 
-BOOST_AUTO_TEST_CASE (NameTreeBasic)
+BOOST_AUTO_TEST_CASE(NameTreeBasic)
 {
   size_t nBuckets = 16;
   NameTree nt(nBuckets);
@@ -266,6 +268,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
-
-
diff --git a/tests/table/pit.cpp b/tests/table/pit.cpp
index 916db81..f366ea2 100644
--- a/tests/table/pit.cpp
+++ b/tests/table/pit.cpp
@@ -5,13 +5,14 @@
  */
 
 #include "table/pit.hpp"
-#include "../face/dummy-face.hpp"
+#include "tests/face/dummy-face.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
-BOOST_AUTO_TEST_SUITE(TablePit)
+BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(EntryInOutRecords)
 {
@@ -288,4 +289,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/table/strategy-info-host.cpp b/tests/table/strategy-info-host.cpp
index af3351e..b2d1f07 100644
--- a/tests/table/strategy-info-host.cpp
+++ b/tests/table/strategy-info-host.cpp
@@ -6,9 +6,10 @@
 
 #include "table/strategy-info-host.hpp"
 
-#include <boost/test/unit_test.hpp>
+#include "tests/test-common.hpp"
 
 namespace nfd {
+namespace tests {
 
 static int g_DummyStrategyInfo_count = 0;
 
@@ -29,7 +30,7 @@
   int m_id;
 };
 
-BOOST_AUTO_TEST_SUITE(TableStrategyInfoHost)
+BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(SetGetClear)
 {
@@ -56,4 +57,5 @@
 
 BOOST_AUTO_TEST_SUITE_END()
 
+} // namespace tests
 } // namespace nfd
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
new file mode 100644
index 0000000..c17607c
--- /dev/null
+++ b/tests/test-common.hpp
@@ -0,0 +1,42 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_TEST_COMMON_HPP
+#define NFD_TEST_COMMON_HPP
+
+#include <boost/test/unit_test.hpp>
+#include "core/global-io.hpp"
+
+namespace nfd {
+namespace tests {
+
+/** \brief base test fixture
+ *
+ *  Every test case should be based on this fixture,
+ *  to have per test case io_service initialization.
+ */
+class BaseFixture
+{
+protected:
+  BaseFixture()
+    : g_io(getGlobalIoService())
+  {
+  }
+  
+  ~BaseFixture()
+  {
+    resetGlobalIoService();
+  }
+
+protected:
+  /// reference to global io_service
+  boost::asio::io_service& g_io;
+};
+
+} // namespace tests
+} // namespace nfd
+
+#endif // NFD_TEST_COMMON_HPP
diff --git a/tests/test-skeleton.cpp b/tests/test-skeleton.cpp
index 35548be..acd44ed 100644
--- a/tests/test-skeleton.cpp
+++ b/tests/test-skeleton.cpp
@@ -4,11 +4,19 @@
  * See COPYING for copyright and distribution information.
  */
 
-#include <boost/test/unit_test.hpp>
+// #include "unit-under-test.hpp"
+// Unit being tested MUST be included first, to ensure header compiles on its own.
 
-BOOST_AUTO_TEST_SUITE(TestSkeleton)
+#include "tests/test-common.hpp"
 
-BOOST_AUTO_TEST_CASE (Test1)
+namespace nfd {
+namespace tests {
+// Unit tests SHOULD go inside nfd::tests namespace.
+
+// Test suite SHOULD use BaseFixture or a subclass of it.
+BOOST_FIXTURE_TEST_SUITE(TestSkeleton, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Test1)
 {
   int i = 0;
   /**
@@ -19,4 +27,19 @@
   BOOST_REQUIRE_EQUAL(i, 1);
 }
 
+// Custom fixture SHOULD derive from BaseFixture.
+class Test2Fixture : protected BaseFixture
+{
+};
+
+BOOST_FIXTURE_TEST_CASE(Test2, Test2Fixture)
+{
+  // g_io is a shorthand of getGlobalIoService()
+  // resetGlobalIoService() is automatically called after each test case
+  g_io.run();
+}
+
 BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd