core: ignore non-Ethernet AF_LINK addresses when enumerating NICs.
Also modernize the code with some C++11 features.
Change-Id: Ibd29b39c37fdce8f87f917ab0cf48750e631e76c
diff --git a/tests/core/network-interface.cpp b/tests/core/network-interface.cpp
index 2fb9c0b..5ac5a31 100644
--- a/tests/core/network-interface.cpp
+++ b/tests/core/network-interface.cpp
@@ -25,8 +25,6 @@
#include "core/network-interface.hpp"
#include "tests/test-common.hpp"
-#include <boost/foreach.hpp>
-
namespace nfd {
namespace tests {
@@ -34,20 +32,19 @@
BOOST_AUTO_TEST_CASE(ListNetworkInterfaces)
{
- std::list< shared_ptr<NetworkInterfaceInfo> > netifs;
+ std::vector<NetworkInterfaceInfo> netifs;
BOOST_CHECK_NO_THROW(netifs = listNetworkInterfaces());
- BOOST_FOREACH(shared_ptr<NetworkInterfaceInfo> netif, netifs)
- {
- BOOST_TEST_MESSAGE(netif->index << ": " << netif->name);
- BOOST_TEST_MESSAGE("\tether " << netif->etherAddress);
- BOOST_FOREACH(boost::asio::ip::address_v4 address, netif->ipv4Addresses)
+ for (const auto& netif : netifs) {
+ BOOST_TEST_MESSAGE(netif.index << ": " << netif.name);
+ BOOST_TEST_MESSAGE("\tether " << netif.etherAddress);
+ for (const auto& address : netif.ipv4Addresses)
BOOST_TEST_MESSAGE("\tinet " << address);
- BOOST_FOREACH(boost::asio::ip::address_v6 address, netif->ipv6Addresses)
+ for (const auto& address : netif.ipv6Addresses)
BOOST_TEST_MESSAGE("\tinet6 " << address);
- BOOST_TEST_MESSAGE("\tloopback : " << netif->isLoopback());
- BOOST_TEST_MESSAGE("\tmulticast : " << netif->isMulticastCapable());
- BOOST_TEST_MESSAGE("\tup : " << netif->isUp());
+ BOOST_TEST_MESSAGE("\tloopback : " << netif.isLoopback());
+ BOOST_TEST_MESSAGE("\tmulticast : " << netif.isMulticastCapable());
+ BOOST_TEST_MESSAGE("\tup : " << netif.isUp());
}
}
diff --git a/tests/daemon/face/ethernet.cpp b/tests/daemon/face/ethernet.cpp
index b5c0cc4..2f872f1 100644
--- a/tests/daemon/face/ethernet.cpp
+++ b/tests/daemon/face/ethernet.cpp
@@ -37,7 +37,7 @@
{
EthernetFactory factory;
- std::list<shared_ptr<const Channel> > channels = factory.getChannels();
+ auto channels = factory.getChannels();
BOOST_CHECK_EQUAL(channels.empty(), true);
}
@@ -48,27 +48,22 @@
{
EthernetFactory factory;
- std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
- for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
- i != ifs.end();
- ++i)
- {
- if (!(*i)->isLoopback() && (*i)->isUp())
- {
- try {
- factory.createMulticastFace(*i, ethernet::getBroadcastAddress());
- }
- catch (Face::Error&) {
- continue;
- }
+ for (const auto& netif : listNetworkInterfaces()) {
+ if (!netif.isLoopback() && netif.isUp()) {
+ try {
+ factory.createMulticastFace(netif, ethernet::getBroadcastAddress());
+ }
+ catch (Face::Error&) {
+ continue;
+ }
- m_interfaces.push_back(*i);
- }
+ m_interfaces.push_back(netif);
}
+ }
}
protected:
- std::list< shared_ptr<NetworkInterfaceInfo> > m_interfaces;
+ std::vector<NetworkInterfaceInfo> m_interfaces;
};
@@ -88,17 +83,15 @@
ethernet::getBroadcastAddress());
BOOST_CHECK_EQUAL(face1, face1bis);
- if (m_interfaces.size() > 1)
- {
- shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
- ethernet::getBroadcastAddress());
- BOOST_CHECK_NE(face1, face2);
- }
- else
- {
- BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
- "only one interface available");
- }
+ if (m_interfaces.size() > 1) {
+ shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
+ ethernet::getBroadcastAddress());
+ BOOST_CHECK_NE(face1, face2);
+ }
+ else {
+ BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
+ "only one interface available");
+ }
shared_ptr<EthernetFace> face3 = factory.createMulticastFace(m_interfaces.front(),
ethernet::getDefaultMulticastAddress());
@@ -117,15 +110,14 @@
shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(),
ethernet::getDefaultMulticastAddress());
-
BOOST_REQUIRE(static_cast<bool>(face));
BOOST_CHECK(!face->isOnDemand());
BOOST_CHECK_EQUAL(face->isLocal(), false);
BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
- "ether://[" + ethernet::getDefaultMulticastAddress().toString()+"]");
+ "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]");
BOOST_CHECK_EQUAL(face->getLocalUri().toString(),
- "dev://" + m_interfaces.front()->name);
+ "dev://" + m_interfaces.front().name);
shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
diff --git a/tests/daemon/face/tcp.cpp b/tests/daemon/face/tcp.cpp
index a391edc..99c2d5b 100644
--- a/tests/daemon/face/tcp.cpp
+++ b/tests/daemon/face/tcp.cpp
@@ -60,22 +60,16 @@
TcpFactory factory;
BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
- std::vector<shared_ptr<const Channel> > expectedChannels;
+ std::vector<shared_ptr<const Channel>> expectedChannels;
expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
expectedChannels.push_back(factory.createChannel("::1", "20071"));
- std::list<shared_ptr<const Channel> > channels = factory.getChannels();
- for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin();
- i != channels.end(); ++i)
- {
- std::vector<shared_ptr<const Channel> >::iterator pos =
- std::find(expectedChannels.begin(), expectedChannels.end(), *i);
-
- BOOST_REQUIRE(pos != expectedChannels.end());
- expectedChannels.erase(pos);
- }
-
+ for (const auto& ch : factory.getChannels()) {
+ auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch);
+ BOOST_REQUIRE(pos != expectedChannels.end());
+ expectedChannels.erase(pos);
+ }
BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
}
@@ -115,7 +109,6 @@
factory.createFace(FaceUri("tcp4://127.0.0.1/path"),
bind(&FaceCreateFixture::ignore, this),
bind(&FaceCreateFixture::checkError, this, _1, "Invalid URI"));
-
}
class EndToEndFixture : protected BaseFixture
@@ -254,7 +247,7 @@
std::vector<Interest> face2_receivedInterests;
std::vector<Data> face2_receivedDatas;
- std::list< shared_ptr<Face> > faces;
+ std::list<shared_ptr<Face>> faces;
};
BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
@@ -493,8 +486,6 @@
}
-
-
class SimpleEndToEndFixture : protected BaseFixture
{
public:
@@ -580,23 +571,17 @@
{
// tests with non-local Face
std::string someIpv4Address;
- std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
- for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
- i != ifs.end();
- ++i)
- {
- if (!(*i)->isLoopback() && (*i)->isUp() && !(*i)->ipv4Addresses.empty())
- {
- someIpv4Address = (*i)->ipv4Addresses[0].to_string();
- break;
- }
+ for (const auto& netif : listNetworkInterfaces()) {
+ if (!netif.isLoopback() && netif.isUp() && !netif.ipv4Addresses.empty()) {
+ someIpv4Address = netif.ipv4Addresses[0].to_string();
+ break;
}
- if (someIpv4Address.empty())
- {
- BOOST_TEST_MESSAGE("Test with non-local Face cannot be run "
- "(no non-local interface with IPv4 address available)");
- return;
- }
+ }
+ if (someIpv4Address.empty()) {
+ BOOST_TEST_MESSAGE("Test with non-local Face cannot be run "
+ "(no non-local interface with IPv4 address available)");
+ return;
+ }
TcpFactory factory;
@@ -605,7 +590,6 @@
bind(&SimpleEndToEndFixture::onConnectFailed, this, _1));
BOOST_REQUIRE_EQUAL(channel->isListening(), true);
-
DummyStreamSender<boost::asio::ip::tcp, Dataset> sender;
sender.start(Resolver<boost::asio::ip::tcp>::syncResolve(someIpv4Address, "20070"));