tests: introduce ClockFixture
Identical to UnitTestTimeFixture, except that it does not derive
from BaseFixture, and thus does not depend on a global io_service.
Refs: #4528
Change-Id: Ia2e6c4835a1e461c73281e103109d5cc85be355e
diff --git a/tests/tools/mock-nfd-mgmt-fixture.hpp b/tests/tools/mock-nfd-mgmt-fixture.hpp
index 9e8bd53..1e1d592 100644
--- a/tests/tools/mock-nfd-mgmt-fixture.hpp
+++ b/tests/tools/mock-nfd-mgmt-fixture.hpp
@@ -26,8 +26,9 @@
#ifndef NFD_TESTS_TOOLS_MOCK_NFD_MGMT_FIXTURE_HPP
#define NFD_TESTS_TOOLS_MOCK_NFD_MGMT_FIXTURE_HPP
-#include "tests/test-common.hpp"
+#include "tests/clock-fixture.hpp"
#include "tests/key-chain-fixture.hpp"
+#include "tests/test-common.hpp"
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
#include <ndn-cxx/mgmt/nfd/control-response.hpp>
@@ -40,27 +41,23 @@
using namespace nfd::tests;
using ndn::nfd::ControlParameters;
-/** \brief fixture to emulate NFD management
+/** \brief Fixture to emulate NFD management.
*/
-class MockNfdMgmtFixture : public UnitTestTimeFixture, public KeyChainFixture
+class MockNfdMgmtFixture : public ClockFixture, public KeyChainFixture
{
protected:
MockNfdMgmtFixture()
- : face(g_io, m_keyChain,
+ : ClockFixture(m_io)
+ , face(m_io, m_keyChain,
{true, false, bind(&MockNfdMgmtFixture::processEventsOverride, this, _1)})
{
- face.onSendInterest.connect([=] (const Interest& interest) {
- g_io.post([=] {
- if (processInterest != nullptr) {
- processInterest(interest);
- }
- });
+ face.onSendInterest.connect([this] (const Interest& interest) {
+ if (processInterest) {
+ m_io.post([=] { processInterest(interest); });
+ }
});
}
- virtual
- ~MockNfdMgmtFixture() = default;
-
protected: // ControlCommand
/** \brief check the Interest is a command with specified prefix
* \retval nullopt last Interest is not the expected command
@@ -206,6 +203,9 @@
signData(data);
}
+private:
+ boost::asio::io_service m_io;
+
protected:
ndn::util::DummyClientFace face;
std::function<void(const Interest&)> processInterest;
diff --git a/tests/tools/nfdc/status-report.t.cpp b/tests/tools/nfdc/status-report.t.cpp
index 6b1cd20..7c8e32c 100644
--- a/tests/tools/nfdc/status-report.t.cpp
+++ b/tests/tools/nfdc/status-report.t.cpp
@@ -120,11 +120,12 @@
std::function<void()> processEventsFunc;
};
-class StatusReportModulesFixture : public UnitTestTimeFixture, public KeyChainFixture
+class StatusReportModulesFixture : public ClockFixture, public KeyChainFixture
{
protected:
StatusReportModulesFixture()
- : face(g_io, m_keyChain)
+ : ClockFixture(m_io)
+ , face(m_io, m_keyChain)
, controller(face, m_keyChain, validator)
, res(0)
{
@@ -133,7 +134,7 @@
DummyModule&
addModule(const std::string& moduleName)
{
- report.sections.push_back(make_unique<DummyModule>(moduleName, g_io));
+ report.sections.push_back(make_unique<DummyModule>(moduleName, m_io));
return static_cast<DummyModule&>(*report.sections.back());
}
@@ -153,6 +154,9 @@
}
}
+private:
+ boost::asio::io_service m_io;
+
protected:
ndn::util::DummyClientFace face;
ValidatorNull validator;
@@ -164,7 +168,6 @@
output_test_stream statusText;
};
-
BOOST_AUTO_TEST_SUITE(Nfdc)
BOOST_FIXTURE_TEST_SUITE(TestStatusReport, StatusReportModulesFixture)