tests: use DummyClientFace from ndn-cxx

refs #2186

Change-Id: Ie6f959b846202f201514d757d12d96921fc19bd6
diff --git a/tests/core/notification-stream.cpp b/tests/core/notification-stream.cpp
index df3fc5b..e231427 100644
--- a/tests/core/notification-stream.cpp
+++ b/tests/core/notification-stream.cpp
@@ -27,8 +27,7 @@
 #include "simple-notification.hpp"
 
 #include "tests/test-common.hpp"
-#include "tests/dummy-client-face.hpp"
-
+#include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
 namespace tests {
@@ -37,29 +36,29 @@
 
 BOOST_AUTO_TEST_CASE(Post)
 {
-  shared_ptr<DummyClientFace> face = makeDummyClientFace();
+  shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace();
   ndn::KeyChain keyChain;
-  NotificationStream<DummyClientFace> notificationStream(*face,
+  NotificationStream<ndn::util::DummyClientFace> notificationStream(*face,
     "/localhost/nfd/NotificationStreamTest", keyChain);
 
   SimpleNotification event1("msg1");
   notificationStream.postNotification(event1);
   face->processEvents();
-  BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 1);
-  BOOST_CHECK_EQUAL(face->m_sentDatas[0].getName(),
+  BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
+  BOOST_CHECK_EQUAL(face->sentDatas[0].getName(),
                     "/localhost/nfd/NotificationStreamTest/%FE%00");
   SimpleNotification decoded1;
-  BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->m_sentDatas[0].getContent().blockFromValue()));
+  BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->sentDatas[0].getContent().blockFromValue()));
   BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
 
   SimpleNotification event2("msg2");
   notificationStream.postNotification(event2);
   face->processEvents();
-  BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 2);
-  BOOST_CHECK_EQUAL(face->m_sentDatas[1].getName(),
+  BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 2);
+  BOOST_CHECK_EQUAL(face->sentDatas[1].getName(),
                     "/localhost/nfd/NotificationStreamTest/%FE%01");
   SimpleNotification decoded2;
-  BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->m_sentDatas[1].getContent().blockFromValue()));
+  BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->sentDatas[1].getContent().blockFromValue()));
   BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2");
 }
 
diff --git a/tests/core/segment-publisher.cpp b/tests/core/segment-publisher.cpp
index 08fc226..565c314 100644
--- a/tests/core/segment-publisher.cpp
+++ b/tests/core/segment-publisher.cpp
@@ -24,13 +24,10 @@
  */
 
 #include "core/segment-publisher.hpp"
-
-#include "tests/test-common.hpp"
-#include "tests/dummy-client-face.hpp"
-
 #include <ndn-cxx/encoding/tlv.hpp>
 
-#include <boost/foreach.hpp>
+#include "tests/test-common.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
 namespace tests {
@@ -38,10 +35,10 @@
 NFD_LOG_INIT("SegmentPublisherTest");
 
 template<int64_t N=10000>
-class TestSegmentPublisher : public SegmentPublisher<DummyClientFace>
+class TestSegmentPublisher : public SegmentPublisher<ndn::util::DummyClientFace>
 {
 public:
-  TestSegmentPublisher(DummyClientFace& face,
+  TestSegmentPublisher(ndn::util::DummyClientFace& face,
                        const Name& prefix,
                        ndn::KeyChain& keyChain)
     : SegmentPublisher(face, prefix, keyChain)
@@ -90,7 +87,7 @@
 {
 public:
   SegmentPublisherFixture()
-    : m_face(makeDummyClientFace())
+    : m_face(ndn::util::makeDummyClientFace())
     , m_publisher(*m_face, "/localhost/nfd/SegmentPublisherFixture", m_keyChain)
   {
   }
@@ -134,7 +131,7 @@
   }
 
 protected:
-  shared_ptr<DummyClientFace> m_face;
+  shared_ptr<ndn::util::DummyClientFace> m_face;
   TestSegmentPublisher<N> m_publisher;
   ndn::EncodingBuffer m_buffer;
   ndn::KeyChain m_keyChain;
@@ -151,13 +148,13 @@
   this->m_face->processEvents();
 
   size_t nSegments = this->m_publisher.getTotalPayloadLength() /
-                       this->m_publisher.getMaxSegmentSize();
+                     this->m_publisher.getMaxSegmentSize();
   if (this->m_publisher.getTotalPayloadLength() % this->m_publisher.getMaxSegmentSize() != 0 ||
       nSegments == 0)
     ++nSegments;
 
-  BOOST_CHECK_EQUAL(this->m_face->m_sentDatas.size(), nSegments);
-  BOOST_FOREACH(const Data& data, this->m_face->m_sentDatas) {
+  BOOST_CHECK_EQUAL(this->m_face->sentDatas.size(), nSegments);
+  for (const Data& data : this->m_face->sentDatas) {
     this->validate(data);
   }
 }
diff --git a/tests/dummy-client-face.hpp b/tests/dummy-client-face.hpp
deleted file mode 100644
index 2e8781d..0000000
--- a/tests/dummy-client-face.hpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_TESTS_DUMMY_CLIENT_FACE_HPP
-#define NFD_TESTS_DUMMY_CLIENT_FACE_HPP
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/transport/transport.hpp>
-
-namespace nfd {
-namespace tests {
-
-class DummyClientTransport : public ndn::Transport
-{
-public:
-  void
-  receive(const Block& block)
-  {
-    if (static_cast<bool>(m_receiveCallback))
-      m_receiveCallback(block);
-  }
-
-  virtual void
-  close()
-  {
-  }
-
-  virtual void
-  pause()
-  {
-  }
-
-  virtual void
-  resume()
-  {
-  }
-
-  virtual void
-  send(const Block& wire)
-  {
-    if (wire.type() == tlv::Interest) {
-      m_sentInterests->push_back(Interest(wire));
-    }
-    else if (wire.type() == tlv::Data) {
-      m_sentDatas->push_back(Data(wire));
-    }
-  }
-
-  virtual void
-  send(const Block& header, const Block& payload)
-  {
-    this->send(payload);
-  }
-
-public:
-  std::vector<Interest>* m_sentInterests;
-  std::vector<Data>*     m_sentDatas;
-};
-
-
-/** \brief a client-side face for unit testing
- */
-class DummyClientFace : public ndn::Face
-{
-public:
-  explicit
-  DummyClientFace(shared_ptr<DummyClientTransport> transport)
-    : Face(transport)
-    , m_transport(transport)
-  {
-    m_transport->m_sentInterests = &m_sentInterests;
-    m_transport->m_sentDatas     = &m_sentDatas;
-  }
-
-  /** \brief cause the Face to receive a packet
-   */
-  template<typename Packet>
-  void
-  receive(const Packet& packet)
-  {
-    m_transport->receive(packet.wireEncode());
-  }
-
-public:
-  /** \brief sent Interests
-   *  \note After .expressInterest, .processEvents must be called before
-   *        the Interest would show up here.
-   */
-  std::vector<Interest> m_sentInterests;
-  /** \brief sent Datas
-   *  \note After .put, .processEvents must be called before
-   *        the Interest would show up here.
-   */
-  std::vector<Data>     m_sentDatas;
-
-private:
-  shared_ptr<DummyClientTransport> m_transport;
-};
-
-inline shared_ptr<DummyClientFace>
-makeDummyClientFace()
-{
-  return make_shared<DummyClientFace>(make_shared<DummyClientTransport>());
-}
-
-} // namespace tests
-} // namespace nfd
-
-#endif // NFD_TESTS_DUMMY_CLIENT_FACE_HPP
diff --git a/tests/rib/rib-manager.cpp b/tests/rib/rib-manager.cpp
index b47e3ab..afef2f3 100644
--- a/tests/rib/rib-manager.cpp
+++ b/tests/rib/rib-manager.cpp
@@ -24,14 +24,12 @@
  */
 
 #include "rib/rib-manager.hpp"
-
-#include "tests/test-common.hpp"
-#include "tests/dummy-client-face.hpp"
-#include "tests/limited-io.hpp"
-
+#include <ndn-cxx/management/nfd-face-status.hpp>
 #include "rib/rib-status-publisher-common.hpp"
 
-#include <ndn-cxx/management/nfd-face-status.hpp>
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
 namespace rib {
@@ -45,13 +43,13 @@
     , ADD_NEXTHOP_VERB("add-nexthop")
     , REMOVE_NEXTHOP_VERB("remove-nexthop")
   {
-    face = nfd::tests::makeDummyClientFace();
+    face = ndn::util::makeDummyClientFace();
 
     manager = make_shared<RibManager>(ndn::ref(*face));
     manager->registerWithNfd();
 
     face->processEvents(time::milliseconds(1));
-    face->m_sentInterests.clear();
+    face->sentInterests.clear();
   }
 
   ~RibManagerFixture()
@@ -83,7 +81,7 @@
 
 public:
   shared_ptr<RibManager> manager;
-  shared_ptr<nfd::tests::DummyClientFace> face;
+  shared_ptr<ndn::util::DummyClientFace> face;
 
   const Name COMMAND_PREFIX;
   const Name::Component ADD_NEXTHOP_VERB;
@@ -133,7 +131,7 @@
 
   receiveCommandInterest(commandName, parameters);
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 1);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
 }
 
 BOOST_FIXTURE_TEST_CASE(Register, AuthorizedRibManager)
@@ -151,9 +149,9 @@
 
   receiveCommandInterest(commandName, parameters);
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 1);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
 
-  Interest& request = face->m_sentInterests[0];
+  Interest& request = face->sentInterests[0];
 
   ControlParameters extractedParameters;
   Name::Component verb;
@@ -179,7 +177,7 @@
   Name registerName("/localhost/nfd/rib/register");
 
   receiveCommandInterest(registerName, addParameters);
-  face->m_sentInterests.clear();
+  face->sentInterests.clear();
 
   ControlParameters removeParameters;
   removeParameters
@@ -191,9 +189,9 @@
 
   receiveCommandInterest(unregisterName, removeParameters);
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 1);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
 
-  Interest& request = face->m_sentInterests[0];
+  Interest& request = face->sentInterests[0];
 
   ControlParameters extractedParameters;
   Name::Component verb;
@@ -217,11 +215,11 @@
 
   Name commandName("/localhost/nfd/rib/register");
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 0);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
 
   receiveCommandInterest(commandName, parameters);
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 0);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
 }
 
 BOOST_FIXTURE_TEST_CASE(RibStatusRequest, AuthorizedRibManager)
@@ -244,17 +242,17 @@
 
   Name commandName("/localhost/nfd/rib/register");
 
-  BOOST_REQUIRE_EQUAL(face->m_sentInterests.size(), 0);
+  BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
 
   receiveCommandInterest(commandName, parameters);
-  face->m_sentInterests.clear();
-  face->m_sentDatas.clear();
+  face->sentInterests.clear();
+  face->sentDatas.clear();
 
   face->receive(Interest("/localhost/nfd/rib/list"));
   face->processEvents(time::milliseconds(1));
 
-  BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 1);
-  RibStatusPublisherFixture::decodeRibEntryBlock(face->m_sentDatas[0], name, entry);
+  BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
+  RibStatusPublisherFixture::decodeRibEntryBlock(face->sentDatas[0], name, entry);
 }
 
 BOOST_FIXTURE_TEST_CASE(CancelExpirationEvent, AuthorizedRibManager)
@@ -272,7 +270,7 @@
   Name registerName("/localhost/nfd/rib/register");
 
   receiveCommandInterest(registerName, addParameters);
-  face->m_sentInterests.clear();
+  face->sentInterests.clear();
 
   // Unregister face
   ControlParameters removeParameters;
diff --git a/tests/rib/rib-status-publisher.cpp b/tests/rib/rib-status-publisher.cpp
index 5253bba..b1414cc 100644
--- a/tests/rib/rib-status-publisher.cpp
+++ b/tests/rib/rib-status-publisher.cpp
@@ -24,9 +24,10 @@
  */
 
 #include "rib/rib-status-publisher.hpp"
-
 #include "rib-status-publisher-common.hpp"
-#include "tests/dummy-client-face.hpp"
+
+#include "tests/test-common.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
 namespace rib {
@@ -47,14 +48,14 @@
   rib.insert(name, entry);
 
   ndn::KeyChain keyChain;
-  shared_ptr<nfd::tests::DummyClientFace> face = nfd::tests::makeDummyClientFace();
+  shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace();
   RibStatusPublisher publisher(rib, *face, "/localhost/nfd/rib/list", keyChain);
 
   publisher.publish();
   face->processEvents(time::milliseconds(1));
 
-  BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 1);
-  decodeRibEntryBlock(face->m_sentDatas[0], name, entry);
+  BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
+  decodeRibEntryBlock(face->sentDatas[0], name, entry);
 }