ping: Tests for Ping and PingServer
This commit includes minor refactoring in Ping and PingServer to support unit testing
refs #2796
Change-Id: Id0172486aa07e129a90091d72594fbccbb5dbc06
diff --git a/tools/ping/client/ping.cpp b/tools/ping/client/ping.cpp
index dbc2d45..8f1ba98 100644
--- a/tools/ping/client/ping.cpp
+++ b/tools/ping/client/ping.cpp
@@ -42,9 +42,15 @@
void
Ping::run()
{
- performPing();
+ start();
- m_face.processEvents();
+ m_face.getIoService().run();
+}
+
+void
+Ping::start()
+{
+ performPing();
}
void
diff --git a/tools/ping/client/ping.hpp b/tools/ping/client/ping.hpp
index 9d30067..3f99fd7 100644
--- a/tools/ping/client/ping.hpp
+++ b/tools/ping/client/ping.hpp
@@ -74,11 +74,17 @@
signal::Signal<Ping> afterFinish;
/**
- * Executes the pings
+ * Runs the ping client (blocking)
*/
void
run();
+ /**
+ * Runs the ping client (non-blocking)
+ */
+ void
+ start();
+
private:
/**
* Creates a ping Name from the sequence number
diff --git a/tools/ping/server/ping-server.cpp b/tools/ping/server/ping-server.cpp
index f919113..799fa8d 100644
--- a/tools/ping/server/ping-server.cpp
+++ b/tools/ping/server/ping-server.cpp
@@ -40,14 +40,20 @@
void
PingServer::run()
{
+ start();
+
+ m_face.getIoService().run();
+}
+
+void
+PingServer::start()
+{
m_name.append("ping");
m_face.setInterestFilter(m_name,
bind(&PingServer::onInterest,
this, _2),
bind(&PingServer::onRegisterFailed,
this, _2));
-
- m_face.processEvents();
}
int
diff --git a/tools/ping/server/ping-server.hpp b/tools/ping/server/ping-server.hpp
index c5e9634..242a54a 100644
--- a/tools/ping/server/ping-server.hpp
+++ b/tools/ping/server/ping-server.hpp
@@ -65,6 +65,12 @@
run();
/**
+ * @brief starts the Interest filter
+ */
+ void
+ start();
+
+ /**
* @brief gets the number of pings received
*/
int