tests: test IP transports under various combos of address family/scope
In particular, link-local addresses are now tested as well.
Additionally, WebSocketTransport send/receive tests are extended
to check transport counters.
Change-Id: I5b35f498a5d8d70cb1f7a2bea3ce99d22370e050
Refs: #1428
diff --git a/tests/daemon/face/unicast-udp-transport.t.cpp b/tests/daemon/face/unicast-udp-transport.t.cpp
index e66dc8b..075194b 100644
--- a/tests/daemon/face/unicast-udp-transport.t.cpp
+++ b/tests/daemon/face/unicast-udp-transport.t.cpp
@@ -27,86 +27,38 @@
#include "unicast-udp-transport-fixture.hpp"
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/vector_c.hpp>
+
namespace nfd {
namespace face {
namespace tests {
BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUnicastUdpTransport, UnicastUdpTransportFixture)
+BOOST_FIXTURE_TEST_SUITE(TestUnicastUdpTransport, IpTransportFixture<UnicastUdpTransportFixture>)
-BOOST_AUTO_TEST_CASE(StaticPropertiesLocalIpv4)
+using UnicastUdpTransportFixtures = boost::mpl::vector<
+ GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(UnicastUdpTransportFixture)
+>;
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, UnicastUdpTransportFixtures, T)
{
- auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address);
+ TRANSPORT_TEST_INIT();
- checkStaticPropertiesInitialized(*transport);
+ checkStaticPropertiesInitialized(*this->transport);
- BOOST_CHECK_EQUAL(transport->getLocalUri(), FaceUri("udp4://127.0.0.1:" + to_string(localEp.port())));
- BOOST_CHECK_EQUAL(transport->getRemoteUri(), FaceUri("udp4://127.0.0.1:7070"));
- BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); // UDP is never local
- BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
- BOOST_CHECK_EQUAL(transport->getMtu(), 65535 - 60 - 8);
-}
-
-BOOST_AUTO_TEST_CASE(StaticPropertiesLocalIpv6)
-{
- auto address = getTestIp(AddressFamily::V6, AddressScope::Loopback);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address);
-
- checkStaticPropertiesInitialized(*transport);
-
- BOOST_CHECK_EQUAL(transport->getLocalUri(), FaceUri("udp6://[::1]:" + to_string(localEp.port())));
- BOOST_CHECK_EQUAL(transport->getRemoteUri(), FaceUri("udp6://[::1]:7070"));
- BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); // UDP is never local
- BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
- BOOST_CHECK_EQUAL(transport->getMtu(), 65535 - 8);
-}
-
-BOOST_AUTO_TEST_CASE(StaticPropertiesNonLocalIpv4)
-{
- auto address = getTestIp(AddressFamily::V4, AddressScope::Global);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address);
-
- checkStaticPropertiesInitialized(*transport);
-
- BOOST_CHECK_EQUAL(transport->getLocalUri(),
- FaceUri("udp4://" + address.to_string() + ":" + to_string(localEp.port())));
- BOOST_CHECK_EQUAL(transport->getRemoteUri(),
- FaceUri("udp4://" + address.to_string() + ":7070"));
- BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
- BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
- BOOST_CHECK_EQUAL(transport->getMtu(), 65535 - 60 - 8);
-}
-
-BOOST_AUTO_TEST_CASE(StaticPropertiesNonLocalIpv6)
-{
- auto address = getTestIp(AddressFamily::V6, AddressScope::Global);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address);
-
- checkStaticPropertiesInitialized(*transport);
-
- BOOST_CHECK_EQUAL(transport->getLocalUri(),
- FaceUri("udp6://[" + address.to_string() + "]:" + to_string(localEp.port())));
- BOOST_CHECK_EQUAL(transport->getRemoteUri(),
- FaceUri("udp6://[" + address.to_string() + "]:7070"));
- BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
- BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
- BOOST_CHECK_EQUAL(transport->getMtu(), 65535 - 8);
+ BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(udp::endpoint(this->address, this->localEp.port())));
+ BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(udp::endpoint(this->address, 7070)));
+ BOOST_CHECK_EQUAL(this->transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); // UDP is never local
+ BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
+ BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ BOOST_CHECK_EQUAL(this->transport->getMtu(),
+ this->addressFamily == AddressFamily::V4 ? (65535 - 60 - 8) : (65535 - 8));
}
BOOST_AUTO_TEST_CASE(PersistencyChange)
{
- auto address = getTestIp(AddressFamily::V4);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address);
+ TRANSPORT_TEST_INIT();
BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), true);
BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), true);
@@ -115,9 +67,7 @@
BOOST_AUTO_TEST_CASE(ExpirationTime)
{
- auto address = getTestIp(AddressFamily::V4);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ TRANSPORT_TEST_INIT(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
BOOST_CHECK_NE(transport->getExpirationTime(), time::steady_clock::TimePoint::max());
transport->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
@@ -129,9 +79,7 @@
BOOST_AUTO_TEST_CASE(IdleClose)
{
- auto address = getTestIp(AddressFamily::V4);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ TRANSPORT_TEST_INIT(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
int nStateChanges = 0;
transport->afterStateChange.connect(
@@ -156,15 +104,15 @@
BOOST_CHECK_EQUAL(nStateChanges, 2);
}
-using OnDemand = std::integral_constant<ndn::nfd::FacePersistency, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND>;
-using Persistent = std::integral_constant<ndn::nfd::FacePersistency, ndn::nfd::FACE_PERSISTENCY_PERSISTENT>;
-using RemoteClosePersistencies = boost::mpl::vector<OnDemand, Persistent>;
+using RemoteCloseFixture = IpTransportFixture<UnicastUdpTransportFixture,
+ AddressFamily::Any, AddressScope::Loopback>;
+using RemoteClosePersistencies = boost::mpl::vector_c<ndn::nfd::FacePersistency,
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT>;
-BOOST_AUTO_TEST_CASE_TEMPLATE(RemoteClose, Persistency, RemoteClosePersistencies)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(RemoteClose, Persistency, RemoteClosePersistencies, RemoteCloseFixture)
{
- auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address, Persistency::value);
+ TRANSPORT_TEST_INIT(Persistency::value);
transport->afterStateChange.connectSingleShot([this] (TransportState oldState, TransportState newState) {
BOOST_CHECK_EQUAL(oldState, TransportState::UP);
@@ -186,11 +134,9 @@
BOOST_REQUIRE_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
}
-BOOST_AUTO_TEST_CASE(RemoteClosePermanent)
+BOOST_FIXTURE_TEST_CASE(RemoteClosePermanent, RemoteCloseFixture)
{
- auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback);
- SKIP_IF_IP_UNAVAILABLE(address);
- initialize(address, ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ TRANSPORT_TEST_INIT(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
remoteSocket.close();