tests: refactor EthernetFixture

Also, use BOOST_TEST_INFO_SCOPE in a few places.

Change-Id: I113f326207825949ed9d3d22ade0654976d49b76
diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp
index b6d2516..0ee4562 100644
--- a/tests/daemon/face/ethernet-factory.t.cpp
+++ b/tests/daemon/face/ethernet-factory.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -49,22 +49,20 @@
   {
     std::set<std::string> uris;
     std::transform(netifs.begin(), netifs.end(), std::inserter(uris, uris.end()),
-                   [] (const auto& netif) {
-                     return FaceUri::fromDev(netif->getName()).toString();
-                   });
+                   [] (const auto& netif) { return FaceUri::fromDev(netif->getName()).toString(); });
     return uris;
   }
 
   std::vector<const Face*>
   listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listFacesByScheme("ether", linkType);
+    return listFacesByScheme("ether", linkType);
   }
 
   size_t
   countEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listEtherMcastFaces(linkType).size();
+    return listEtherMcastFaces(linkType).size();
   }
 };
 
@@ -303,10 +301,9 @@
   auto etherMcastFaces = this->listEtherMcastFaces();
   BOOST_CHECK_EQUAL(etherMcastFaces.size(), netifs.size() - 1);
   BOOST_CHECK(std::none_of(etherMcastFaces.begin(), etherMcastFaces.end(),
-    [ifname] (const nfd::Face* face) {
-      return face->getLocalUri() == FaceUri::fromDev(ifname);
-    }
-  ));
+                           [uri = FaceUri::fromDev(ifname)] (const auto* face) {
+                             return face->getLocalUri() == uri;
+                           }));
 }
 
 BOOST_AUTO_TEST_CASE(Omitted)
@@ -438,6 +435,7 @@
 BOOST_AUTO_TEST_CASE(GetChannels)
 {
   BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
+
   SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
 
   factory.createChannel(netifs.front(), 1_min);
diff --git a/tests/daemon/face/ethernet-fixture.hpp b/tests/daemon/face/ethernet-fixture.hpp
index dfd5615..45ce00d 100644
--- a/tests/daemon/face/ethernet-fixture.hpp
+++ b/tests/daemon/face/ethernet-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -27,17 +27,12 @@
 #define NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP
 
 #include "face/multicast-ethernet-transport.hpp"
-#include "face/unicast-ethernet-transport.hpp"
 
-#include "tests/daemon/limited-io.hpp"
+#include "tests/daemon/global-io-fixture.hpp"
 #include "test-netif.hpp"
 
 namespace nfd::tests {
 
-using face::EthernetTransport;
-using face::MulticastEthernetTransport;
-using face::UnicastEthernetTransport;
-
 /**
  * \brief Fixture providing a list of EthernetTransport-capable network interfaces.
  */
@@ -47,79 +42,25 @@
   EthernetFixture()
   {
     for (const auto& netif : collectNetworkInterfaces()) {
-      if (!netif->isLoopback() && netif->isUp()) {
+      // similar filtering logic to EthernetFactory::applyMcastConfigToNetif()
+      if (netif->isUp() && !netif->isLoopback() && netif->canMulticast()) {
         try {
-          MulticastEthernetTransport t(*netif, ethernet::getBroadcastAddress(),
-                                       ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+          face::MulticastEthernetTransport t(*netif, ethernet::getBroadcastAddress(),
+                                             ndn::nfd::LINK_TYPE_MULTI_ACCESS);
           netifs.push_back(netif);
         }
-        catch (const EthernetTransport::Error&) {
+        catch (const face::EthernetTransport::Error&) {
           // ignore
         }
       }
     }
-    if (!netifs.empty()) {
-      defaultNetif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
-    }
-  }
-
-  /** \brief Returns the first running interface.
-   */
-  shared_ptr<ndn::net::NetworkInterface>
-  getRunningNetif() const
-  {
-    for (const auto& netif : netifs) {
-      if (netif->getState() == ndn::net::InterfaceState::RUNNING) {
-        return const_pointer_cast<ndn::net::NetworkInterface>(netif);
-      }
-    }
-
-    return nullptr;
-  }
-
-  /** \brief Create a UnicastEthernetTransport.
-   */
-  void
-  initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
-                    ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
-                    ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
-  {
-    if (!netif) {
-      netif = defaultNetif;
-    }
-
-    localEp = netif->getName();
-    remoteEp = remoteAddr;
-    transport = make_unique<UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
-  }
-
-  /** \brief Create a MulticastEthernetTransport.
-   */
-  void
-  initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
-                      ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
-                      ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
-  {
-    if (!netif) {
-      netif = defaultNetif;
-    }
-
-    localEp = netif->getName();
-    remoteEp = mcastGroup;
-    transport = make_unique<MulticastEthernetTransport>(*netif, remoteEp, linkType);
   }
 
 protected:
-  LimitedIo limitedIo;
-
-  /** \brief EthernetTransport-capable network interfaces.
+  /**
+   * \brief EthernetTransport-capable network interfaces.
    */
   std::vector<shared_ptr<const ndn::net::NetworkInterface>> netifs;
-
-  shared_ptr<ndn::net::NetworkInterface> defaultNetif;
-  unique_ptr<EthernetTransport> transport;
-  std::string localEp;
-  ethernet::Address remoteEp;
 };
 
 } // namespace nfd::tests
@@ -133,13 +74,4 @@
     } \
   } while (false)
 
-#define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \
-  do { \
-    if (!this->getRunningNetif()) { \
-      BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \
-                                "EthernetTransport-capable network interface"); \
-      return; \
-    } \
-  } while (false)
-
 #endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP
diff --git a/tests/daemon/face/ethernet-transport-fixture.hpp b/tests/daemon/face/ethernet-transport-fixture.hpp
new file mode 100644
index 0000000..ab73795
--- /dev/null
+++ b/tests/daemon/face/ethernet-transport-fixture.hpp
@@ -0,0 +1,115 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2023,  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_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP
+#define NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP
+
+#include "face/multicast-ethernet-transport.hpp"
+#include "face/unicast-ethernet-transport.hpp"
+
+#include "tests/daemon/limited-io.hpp"
+#include "ethernet-fixture.hpp"
+
+namespace nfd::tests {
+
+class EthernetTransportFixture : public EthernetFixture
+{
+protected:
+  EthernetTransportFixture()
+  {
+    if (!netifs.empty()) {
+      defaultNetif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
+    }
+  }
+
+  /**
+   * \brief Returns the first running interface.
+   */
+  shared_ptr<ndn::net::NetworkInterface>
+  getRunningNetif() const
+  {
+    for (const auto& netif : netifs) {
+      if (netif->getState() == ndn::net::InterfaceState::RUNNING) {
+        return const_pointer_cast<ndn::net::NetworkInterface>(netif);
+      }
+    }
+
+    return nullptr;
+  }
+
+  /**
+   * \brief Create a UnicastEthernetTransport.
+   */
+  void
+  initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
+                    ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+                    ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
+  {
+    if (!netif) {
+      netif = defaultNetif;
+    }
+
+    localEp = netif->getName();
+    remoteEp = remoteAddr;
+    transport = make_unique<face::UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
+  }
+
+  /**
+   * \brief Create a MulticastEthernetTransport.
+   */
+  void
+  initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
+                      ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
+                      ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
+  {
+    if (!netif) {
+      netif = defaultNetif;
+    }
+
+    localEp = netif->getName();
+    remoteEp = mcastGroup;
+    transport = make_unique<face::MulticastEthernetTransport>(*netif, remoteEp, linkType);
+  }
+
+protected:
+  LimitedIo limitedIo;
+  shared_ptr<ndn::net::NetworkInterface> defaultNetif;
+  unique_ptr<face::EthernetTransport> transport;
+  std::string localEp;
+  ethernet::Address remoteEp;
+};
+
+} // namespace nfd::tests
+
+#define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \
+  do { \
+    if (!this->getRunningNetif()) { \
+      BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \
+                                "EthernetTransport-capable network interface"); \
+      return; \
+    } \
+  } while (false)
+
+#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP
diff --git a/tests/daemon/face/multicast-ethernet-transport.t.cpp b/tests/daemon/face/multicast-ethernet-transport.t.cpp
index 2791ca7..2694e00 100644
--- a/tests/daemon/face/multicast-ethernet-transport.t.cpp
+++ b/tests/daemon/face/multicast-ethernet-transport.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -23,7 +23,7 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "ethernet-fixture.hpp"
+#include "ethernet-transport-fixture.hpp"
 
 #include "common/global.hpp"
 
@@ -34,7 +34,7 @@
 using namespace nfd::face;
 
 BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestMulticastEthernetTransport, EthernetFixture)
+BOOST_FIXTURE_TEST_SUITE(TestMulticastEthernetTransport, EthernetTransportFixture)
 
 BOOST_AUTO_TEST_CASE(StaticProperties)
 {
diff --git a/tests/daemon/face/transport-test-common.hpp b/tests/daemon/face/transport-test-common.hpp
index c257a04..4a90c77 100644
--- a/tests/daemon/face/transport-test-common.hpp
+++ b/tests/daemon/face/transport-test-common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -32,25 +32,27 @@
 
 namespace nfd::tests {
 
-/** \brief Check that a transport has all its static properties set after initialization
+/**
+ * \brief Check that a transport has all its static properties set after initialization.
  *
- *  This check shall be inserted to the StaticProperties test case for each transport,
- *  in addition to checking the values of properties.
- *  When a new static property is defined, this test case shall be updated.
- *  Thus, if a transport forgets to set a static property, this check would fail.
+ * This check shall be inserted to the StaticProperties test case for each transport,
+ * in addition to checking the values of properties.
+ * When a new static property is defined, this test case shall be updated.
+ * Thus, if a transport forgets to set a static property, this check would fail.
  */
 inline void
 checkStaticPropertiesInitialized(const face::Transport& transport)
 {
-  BOOST_CHECK(!transport.getLocalUri().getScheme().empty());
-  BOOST_CHECK(!transport.getRemoteUri().getScheme().empty());
-  BOOST_CHECK_NE(transport.getScope(), ndn::nfd::FACE_SCOPE_NONE);
-  BOOST_CHECK_NE(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_NONE);
-  BOOST_CHECK_NE(transport.getLinkType(), ndn::nfd::LINK_TYPE_NONE);
-  BOOST_CHECK_NE(transport.getMtu(), face::MTU_INVALID);
+  BOOST_TEST(transport.getLocalUri().getScheme().empty() == false);
+  BOOST_TEST(transport.getRemoteUri().getScheme().empty() == false);
+  BOOST_TEST(transport.getScope() != ndn::nfd::FACE_SCOPE_NONE);
+  BOOST_TEST(transport.getPersistency() != ndn::nfd::FACE_PERSISTENCY_NONE);
+  BOOST_TEST(transport.getLinkType() != ndn::nfd::LINK_TYPE_NONE);
+  BOOST_TEST(transport.getMtu() != face::MTU_INVALID);
 }
 
-/** \brief Generic wrapper for transport fixtures that require an IP address
+/**
+ * \brief Generic wrapper for transport fixtures that require an IP address.
  */
 template<typename TransportFixtureBase,
          AddressFamily AF = AddressFamily::Any,
diff --git a/tests/daemon/face/transport.t.cpp b/tests/daemon/face/transport.t.cpp
index e3e427c..d405e68 100644
--- a/tests/daemon/face/transport.t.cpp
+++ b/tests/daemon/face/transport.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  Regents of the University of California,
+ * Copyright (c) 2014-2023,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -145,7 +145,7 @@
 
   auto from = static_cast<TransportState>(T::first::value);
   auto to = static_cast<TransportState>(T::second::value);
-  BOOST_TEST_MESSAGE("SetState " << from << " -> " << to);
+  BOOST_TEST_INFO_SCOPE(from << " -> " << to);
 
   // enter from state
   using Steps = typename mpl::at<StateEntering, mpl::int_<T::first::value>>::type;
@@ -155,12 +155,11 @@
   BOOST_REQUIRE_EQUAL(transport->getState(), from);
 
   bool hasSignal = false;
-  transport->afterStateChange.connect(
-    [from, to, &hasSignal] (TransportState oldState, TransportState newState) {
-      hasSignal = true;
-      BOOST_CHECK_EQUAL(oldState, from);
-      BOOST_CHECK_EQUAL(newState, to);
-    });
+  transport->afterStateChange.connect([&] (TransportState oldState, TransportState newState) {
+    hasSignal = true;
+    BOOST_CHECK_EQUAL(oldState, from);
+    BOOST_CHECK_EQUAL(newState, to);
+  });
 
   // do transition
   bool isValid = from == to ||
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index 106ba0b..fd83656 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -69,7 +69,7 @@
         }
       }
     }
-    this->copyRealNetifsToNetmon();
+    copyRealNetifsToNetmon();
   }
 
   shared_ptr<Face>
@@ -106,16 +106,17 @@
   std::vector<const Face*>
   listUdp4McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listFacesByScheme("udp4", linkType);
+    return listFacesByScheme("udp4", linkType);
   }
 
   std::vector<const Face*>
   listUdp6McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listFacesByScheme("udp6", linkType);
+    return listFacesByScheme("udp6", linkType);
   }
 
-  /** \brief Determine whether \p netif has at least one IP address of the given family.
+  /**
+   * \brief Determine whether \p netif has at least one IP address of the given family.
    */
   static bool
   hasAddressFamily(const NetworkInterface& netif, ndn::net::AddressFamily af)
@@ -124,7 +125,8 @@
                        [af] (const auto& a) { return a.getFamily() == af; });
   }
 
-  /** \brief Determine whether a UDP multicast face is created on \p netif.
+  /**
+   * \brief Determine whether a UDP multicast face is created on \p netif.
    */
   static bool
   isFaceOnNetif(const Face& face, const NetworkInterface& netif)
diff --git a/tests/daemon/face/unicast-ethernet-transport.t.cpp b/tests/daemon/face/unicast-ethernet-transport.t.cpp
index 373bcc3..83e4b54 100644
--- a/tests/daemon/face/unicast-ethernet-transport.t.cpp
+++ b/tests/daemon/face/unicast-ethernet-transport.t.cpp
@@ -23,7 +23,7 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "ethernet-fixture.hpp"
+#include "ethernet-transport-fixture.hpp"
 
 #include "common/global.hpp"
 
@@ -34,7 +34,7 @@
 using namespace nfd::face;
 
 BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUnicastEthernetTransport, EthernetFixture)
+BOOST_FIXTURE_TEST_SUITE(TestUnicastEthernetTransport, EthernetTransportFixture)
 
 BOOST_AUTO_TEST_CASE(StaticProperties)
 {