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/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