diff options
-rw-r--r-- | tests/dns.cpp | 42 |
1 files 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); |