From c7e4fc1386b7992c33ea912bf3bfcfcff5d85758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 25 Jul 2016 14:59:25 +0200 Subject: Test the resolving of multiple hostnames at the same time --- tests/dns.cpp | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/dns.cpp b/tests/dns.cpp index 4ec1b96..c3eda7b 100644 --- a/tests/dns.cpp +++ b/tests/dns.cpp @@ -9,6 +9,8 @@ TEST_CASE("DNS resolver") { Resolver resolver; + Resolver resolver2; + Resolver resolver3; /** * If we are using cares, we need to run a poller loop until each @@ -36,38 +38,50 @@ TEST_CASE("DNS resolver") bool success = true; - auto error_cb = [&success, &hostname, &port](const char* msg) - { - INFO("Failed to resolve " << hostname << ":" << port << ": " << msg); - success = false; - }; - auto success_cb = [&success, &hostname, &port](const struct addrinfo* addr) - { - INFO("Successfully resolved " << hostname << ":" << port << ": " << addr_to_string(addr)); - success = true; - }; + const auto error_cb = [&success](const std::string& hostname) + { + return [&success, hostname](const char *msg) + { + INFO("Failed to resolve " << hostname << ":" << msg); + success = false; + }; + }; + const auto success_cb = [&success](const std::string& hostname) + { + return [&success, hostname](const struct addrinfo *addr) + { + INFO("Successfully resolved " << hostname << ": " << addr_to_string(addr)); + success = true; + }; + }; hostname = "example.com"; resolver.resolve(hostname, port, - success_cb, error_cb); + success_cb(hostname), error_cb(hostname)); + hostname = "poez.io"; + resolver2.resolve(hostname, port, + success_cb(hostname), error_cb(hostname)); + hostname = "louiz.org"; + resolver3.resolve(hostname, port, + success_cb(hostname), error_cb(hostname)); loop(); CHECK(success); hostname = "this.should.fail.because.it.is..misformatted"; resolver.resolve(hostname, port, - success_cb, error_cb); + success_cb(hostname), error_cb(hostname)); loop(); CHECK(!success); hostname = "this.should.fail.because.it.is.does.not.exist.invalid"; resolver.resolve(hostname, port, - success_cb, error_cb); + success_cb(hostname), error_cb(hostname)); loop(); CHECK(!success); hostname = "localhost"; resolver.resolve(hostname, port, - success_cb, error_cb); + success_cb(hostname), error_cb(hostname)); loop(); CHECK(success); -- cgit v1.2.3