Avoid deprecated Boost.Asio interfaces
Change-Id: I00d285893ff61619f49dff8a8a55d0d0e2c309a7
diff --git a/tests/unit/net/dns.t.cpp b/tests/unit/net/dns.t.cpp
index ac734dd..17c5438 100644
--- a/tests/unit/net/dns.t.cpp
+++ b/tests/unit/net/dns.t.cpp
@@ -24,20 +24,19 @@
#include "tests/boost-test.hpp"
#include "tests/unit/net/network-configuration-detector.hpp"
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
namespace ndn::tests {
using namespace ndn::dns;
-using boost::asio::ip::address_v4;
-using boost::asio::ip::address_v6;
+namespace ip = boost::asio::ip;
class DnsFixture
{
public:
void
- onSuccess(const IpAddress& resolvedAddress,
- const IpAddress& expectedAddress,
+ onSuccess(const boost::asio::ip::address& resolvedAddress,
+ const boost::asio::ip::address& expectedAddress,
bool isValid,
bool shouldCheckAddress = false)
{
@@ -66,105 +65,95 @@
protected:
int m_nFailures = 0;
int m_nSuccesses = 0;
- boost::asio::io_service m_ioService;
+ boost::asio::io_context m_ioCtx;
};
BOOST_AUTO_TEST_SUITE(Net)
BOOST_FIXTURE_TEST_SUITE(TestDns, DnsFixture)
-BOOST_AUTO_TEST_CASE(Asynchronous)
+BOOST_AUTO_TEST_CASE(Failure)
{
SKIP_IF_IP_UNAVAILABLE();
asyncResolve("nothost.nothost.nothost.arpa",
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), false, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v4(), false, false),
[this] (auto&&...) { onFailure(true); },
- m_ioService); // should fail
+ m_ioCtx); // should fail
- m_ioService.run();
+ m_ioCtx.run();
BOOST_CHECK_EQUAL(m_nFailures, 1);
BOOST_CHECK_EQUAL(m_nSuccesses, 0);
}
-BOOST_AUTO_TEST_CASE(AsynchronousV4)
+BOOST_AUTO_TEST_CASE(Ipv4)
{
SKIP_IF_IPV4_UNAVAILABLE();
asyncResolve("192.0.2.1",
- std::bind(&DnsFixture::onSuccess, this, _1,
- IpAddress(address_v4::from_string("192.0.2.1")), true, true),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::make_address_v4("192.0.2.1"), true, true),
[this] (auto&&...) { onFailure(false); },
- m_ioService);
+ m_ioCtx);
- m_ioService.run();
+ m_ioCtx.run();
BOOST_CHECK_EQUAL(m_nFailures, 0);
BOOST_CHECK_EQUAL(m_nSuccesses, 1);
}
-BOOST_AUTO_TEST_CASE(AsynchronousV6)
+BOOST_AUTO_TEST_CASE(Ipv6)
{
SKIP_IF_IPV6_UNAVAILABLE();
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v6(), true, false),
[this] (auto&&...) { onFailure(false); },
- m_ioService);
+ m_ioCtx);
asyncResolve("2001:db8:3f9:0:3025:ccc5:eeeb:86d3",
std::bind(&DnsFixture::onSuccess, this, _1,
- IpAddress(address_v6::from_string("2001:db8:3f9:0:3025:ccc5:eeeb:86d3")),
- true, true),
+ ip::make_address_v6("2001:db8:3f9:0:3025:ccc5:eeeb:86d3"), true, true),
[this] (auto&&...) { onFailure(false); },
- m_ioService);
+ m_ioCtx);
- m_ioService.run();
+ m_ioCtx.run();
BOOST_CHECK_EQUAL(m_nFailures, 0);
BOOST_CHECK_EQUAL(m_nSuccesses, 2);
}
-BOOST_AUTO_TEST_CASE(AsynchronousV4AndV6)
+BOOST_AUTO_TEST_CASE(WithAddressSelector)
{
SKIP_IF_IPV4_UNAVAILABLE();
SKIP_IF_IPV6_UNAVAILABLE();
asyncResolve("named-data.net",
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v4(), true, false),
[this] (auto&&...) { onFailure(false); },
- m_ioService, Ipv4Only());
+ m_ioCtx, Ipv4Only());
asyncResolve("a.root-servers.net",
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v4(), true, false),
[this] (auto&&...) { onFailure(false); },
- m_ioService, Ipv4Only()); // request IPv4 address
+ m_ioCtx, Ipv4Only()); // request IPv4 address
asyncResolve("a.root-servers.net",
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v6(), true, false),
[this] (auto&&...) { onFailure(false); },
- m_ioService, Ipv6Only()); // request IPv6 address
+ m_ioCtx, Ipv6Only()); // request IPv6 address
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v6(), true, false),
[this] (auto&&...) { onFailure(false); },
- m_ioService, Ipv6Only());
+ m_ioCtx, Ipv6Only());
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), false, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, ip::address_v6(), false, false),
[this] (auto&&...) { onFailure(true); },
- m_ioService, Ipv4Only()); // should fail
+ m_ioCtx, Ipv4Only()); // should fail
- m_ioService.run();
+ m_ioCtx.run();
BOOST_CHECK_EQUAL(m_nFailures, 1);
BOOST_CHECK_EQUAL(m_nSuccesses, 4);
}
-BOOST_AUTO_TEST_CASE(Synchronous)
-{
- SKIP_IF_IP_UNAVAILABLE();
-
- IpAddress address = syncResolve("named-data.net", m_ioService);
- BOOST_CHECK(address.is_v4() || address.is_v6());
-}
-
BOOST_AUTO_TEST_SUITE_END() // TestDns
BOOST_AUTO_TEST_SUITE_END() // Net
diff --git a/tests/unit/net/face-uri.t.cpp b/tests/unit/net/face-uri.t.cpp
index 78e712a..36883bf 100644
--- a/tests/unit/net/face-uri.t.cpp
+++ b/tests/unit/net/face-uri.t.cpp
@@ -94,7 +94,7 @@
shared_ptr<const net::NetworkInterface> m_netif;
private:
- boost::asio::io_service m_io;
+ boost::asio::io_context m_io;
};
BOOST_AUTO_TEST_CASE(ParseInternal)
@@ -147,11 +147,11 @@
namespace ip = boost::asio::ip;
- ip::udp::endpoint endpoint4(ip::address_v4::from_string("192.0.2.1"), 7777);
+ ip::udp::endpoint endpoint4(ip::make_address_v4("192.0.2.1"), 7777);
uri = FaceUri(endpoint4);
BOOST_CHECK_EQUAL(uri.toString(), "udp4://192.0.2.1:7777");
- ip::udp::endpoint endpoint6(ip::address_v6::from_string("2001:DB8::1"), 7777);
+ ip::udp::endpoint endpoint6(ip::make_address_v6("2001:DB8::1"), 7777);
uri = FaceUri(endpoint6);
BOOST_CHECK_EQUAL(uri.toString(), "udp6://[2001:db8::1]:7777");
@@ -285,14 +285,14 @@
namespace ip = boost::asio::ip;
- ip::tcp::endpoint endpoint4(ip::address_v4::from_string("192.0.2.1"), 7777);
+ ip::tcp::endpoint endpoint4(ip::make_address_v4("192.0.2.1"), 7777);
uri = FaceUri(endpoint4);
BOOST_CHECK_EQUAL(uri.toString(), "tcp4://192.0.2.1:7777");
uri = FaceUri(endpoint4, "wsclient");
BOOST_CHECK_EQUAL(uri.toString(), "wsclient://192.0.2.1:7777");
- ip::tcp::endpoint endpoint6(ip::address_v6::from_string("2001:DB8::1"), 7777);
+ ip::tcp::endpoint endpoint6(ip::make_address_v6("2001:DB8::1"), 7777);
uri = FaceUri(endpoint6);
BOOST_CHECK_EQUAL(uri.toString(), "tcp6://[2001:db8::1]:7777");
@@ -553,7 +553,7 @@
BOOST_AUTO_TEST_CASE(CanonizeEmptyCallback)
{
- boost::asio::io_service io;
+ boost::asio::io_context io;
// unsupported scheme
FaceUri("null://").canonize(nullptr, nullptr, io, 1_ms);
diff --git a/tests/unit/net/network-configuration-detector.cpp b/tests/unit/net/network-configuration-detector.cpp
index f8a8816..44cae39 100644
--- a/tests/unit/net/network-configuration-detector.cpp
+++ b/tests/unit/net/network-configuration-detector.cpp
@@ -21,11 +21,9 @@
#include "tests/unit/net/network-configuration-detector.hpp"
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/address.hpp>
-#include <boost/asio/ip/basic_resolver.hpp>
#include <boost/asio/ip/udp.hpp>
-#include <boost/range/iterator_range_core.hpp>
namespace ndn::tests {
@@ -50,31 +48,23 @@
void
NetworkConfigurationDetector::detect()
{
- using BoostResolver = boost::asio::ip::basic_resolver<boost::asio::ip::udp>;
+ boost::asio::io_context io;
+ boost::asio::ip::udp::resolver resolver(io);
- boost::asio::io_service ioService;
- BoostResolver resolver(ioService);
+ boost::system::error_code ec;
+ // The specified hostname must have both A and AAAA records
+ auto results = resolver.resolve("a.root-servers.net", "", ec);
- // The specified hostname must contain both A and AAAA records
- BoostResolver::query query("a.root-servers.net", "");
-
- boost::system::error_code errorCode;
- BoostResolver::iterator begin = resolver.resolve(query, errorCode);
- if (errorCode) {
- s_isInitialized = true;
- return;
- }
- BoostResolver::iterator end;
-
- for (const auto& i : boost::make_iterator_range(begin, end)) {
- if (i.endpoint().address().is_v4()) {
- s_hasIpv4 = true;
- }
- else if (i.endpoint().address().is_v6()) {
- s_hasIpv6 = true;
+ if (!ec) {
+ for (const auto& i : results) {
+ if (i.endpoint().address().is_v4()) {
+ s_hasIpv4 = true;
+ }
+ else if (i.endpoint().address().is_v6()) {
+ s_hasIpv6 = true;
+ }
}
}
-
s_isInitialized = true;
}
diff --git a/tests/unit/net/network-monitor.t.cpp b/tests/unit/net/network-monitor.t.cpp
index 4515258..50c04c7 100644
--- a/tests/unit/net/network-monitor.t.cpp
+++ b/tests/unit/net/network-monitor.t.cpp
@@ -23,7 +23,8 @@
#include "tests/boost-test.hpp"
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/post.hpp>
namespace ndn::tests {
@@ -42,7 +43,7 @@
BOOST_AUTO_TEST_CASE(DestructWithoutRun)
{
- boost::asio::io_service io;
+ boost::asio::io_context io;
auto nm = make_unique<NetworkMonitor>(io);
nm.reset();
BOOST_CHECK(true); // if we got this far, the test passed
@@ -50,16 +51,16 @@
BOOST_AUTO_TEST_CASE(DestructWhileEnumerating)
{
- boost::asio::io_service io;
+ boost::asio::io_context io;
auto nm = make_unique<NetworkMonitor>(io);
NM_REQUIRE_CAP(ENUM);
nm->onInterfaceAdded.connect([&] (const shared_ptr<const NetworkInterface>&) {
- io.post([&] { nm.reset(); });
+ boost::asio::post(io, [&] { nm.reset(); });
});
nm->onEnumerationCompleted.connect([&] {
// make sure the test case terminates even if we have zero interfaces
- io.post([&] { nm.reset(); });
+ boost::asio::post(io, [&] { nm.reset(); });
});
io.run();