tests: UnixStreamTransport test suite improvements

refs #3305

Change-Id: I6c6ca52a5e80266920ded811ff45fc568c3e59b9
diff --git a/tests/daemon/face/unix-stream-transport.t.cpp b/tests/daemon/face/unix-stream-transport.t.cpp
index a74b760..2ff73be 100644
--- a/tests/daemon/face/unix-stream-transport.t.cpp
+++ b/tests/daemon/face/unix-stream-transport.t.cpp
@@ -23,81 +23,30 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "face/unix-stream-transport.hpp"
-#include "transport-test-common.hpp"
-
-#include <boost/filesystem.hpp>
+#include "unix-stream-transport-fixture.hpp"
 
 namespace nfd {
 namespace face {
 namespace tests {
 
-using namespace nfd::tests;
-typedef boost::asio::local::stream_protocol unix_stream;
-
 BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUnixStreamTransport, BaseFixture)
 
-/** \brief automatically unlinks the socket file of a Unix stream acceptor
- */
-class AcceptorWithCleanup : public unix_stream::acceptor
-{
-public:
-  AcceptorWithCleanup(const std::string& path = "")
-    : unix_stream::acceptor(getGlobalIoService())
-  {
-    this->open();
-    if (path.empty()) {
-      this->bind("unix-stream-acceptor." + to_string(time::system_clock::now().time_since_epoch().count()) + ".sock");
-    }
-    else {
-      this->bind(path);
-    }
-    this->listen(1);
-  }
-
-  ~AcceptorWithCleanup()
-  {
-    std::string path = this->local_endpoint().path();
-
-    boost::system::error_code ec;
-    this->close(ec);
-    boost::filesystem::remove(path, ec);
-  }
-};
-
-bool
-connectToAcceptor(unix_stream::acceptor& acceptor, unix_stream::socket& sock1, unix_stream::socket& sock2)
-{
-  bool isAccepted = false;
-  acceptor.async_accept(sock1, bind([&isAccepted] { isAccepted = true; }));
-
-  bool isConnected = false;
-  sock2.async_connect(acceptor.local_endpoint(), bind([&isConnected] { isConnected = true; }));
-
-  getGlobalIoService().poll();
-
-  return isAccepted && isConnected;
-}
+BOOST_FIXTURE_TEST_SUITE(TestUnixStreamTransport, UnixStreamTransportFixture)
 
 BOOST_AUTO_TEST_CASE(StaticProperties)
 {
-  AcceptorWithCleanup acceptor1;
-  unix_stream::socket sock1(getGlobalIoService());
-  unix_stream::socket sock2(getGlobalIoService());
-  BOOST_CHECK(connectToAcceptor(acceptor1, sock1, sock2));
+  initialize();
 
-  UnixStreamTransport transport(std::move(sock1));
-  checkStaticPropertiesInitialized(transport);
+  checkStaticPropertiesInitialized(*transport);
 
-  BOOST_CHECK_EQUAL(transport.getLocalUri().getScheme(), "unix");
-  BOOST_CHECK_EQUAL(transport.getLocalUri().getHost(), "");
-  BOOST_CHECK_EQUAL(transport.getLocalUri().getPath(), acceptor1.local_endpoint().path());
-  BOOST_CHECK_EQUAL(transport.getRemoteUri().getScheme(), "fd");
-  BOOST_CHECK_EQUAL(transport.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
-  BOOST_CHECK_EQUAL(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
-  BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
-  BOOST_CHECK_EQUAL(transport.getMtu(), MTU_UNLIMITED);
+  BOOST_CHECK_EQUAL(transport->getLocalUri().getScheme(), "unix");
+  BOOST_CHECK_EQUAL(transport->getLocalUri().getHost(), "");
+  BOOST_CHECK_EQUAL(transport->getLocalUri().getPath(), localEp.path());
+  BOOST_CHECK_EQUAL(transport->getRemoteUri().getScheme(), "fd");
+  BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
+  BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+  BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+  BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED);
 }
 
 BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamTransport