summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-07-25 14:59:25 +0200
committerlouiz’ <louiz@louiz.org>2016-07-25 14:59:25 +0200
commitc7e4fc1386b7992c33ea912bf3bfcfcff5d85758 (patch)
tree3ef4ec5bd11fdb4f9349728337ba3e6974609460 /tests
parentdb503b23e86d1cb390d12298875eb0eaffdbfa3c (diff)
downloadbiboumi-c7e4fc1386b7992c33ea912bf3bfcfcff5d85758.tar.gz
biboumi-c7e4fc1386b7992c33ea912bf3bfcfcff5d85758.tar.bz2
biboumi-c7e4fc1386b7992c33ea912bf3bfcfcff5d85758.tar.xz
biboumi-c7e4fc1386b7992c33ea912bf3bfcfcff5d85758.zip
Test the resolving of multiple hostnames at the same time
Diffstat (limited to 'tests')
-rw-r--r--tests/dns.cpp42
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);