IXDNSLookup. Uses weak pointer + smart_ptr + shared_from_this instead of static sets + mutex to handle object going away before dns lookup has resolved
This commit is contained in:
@ -17,33 +17,33 @@ TEST_CASE("dns", "[net]")
|
||||
{
|
||||
SECTION("Test resolving a known hostname")
|
||||
{
|
||||
DNSLookup dnsLookup("www.google.com", 80);
|
||||
auto dnsLookup = std::make_shared<DNSLookup>("www.google.com", 80);
|
||||
|
||||
std::string errMsg;
|
||||
struct addrinfo* res;
|
||||
|
||||
res = dnsLookup.resolve(errMsg, [] { return false; });
|
||||
res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||
std::cerr << "Error message: " << errMsg << std::endl;
|
||||
REQUIRE(res != nullptr);
|
||||
}
|
||||
|
||||
SECTION("Test resolving a non-existing hostname")
|
||||
{
|
||||
DNSLookup dnsLookup("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
||||
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
||||
|
||||
std::string errMsg;
|
||||
struct addrinfo* res = dnsLookup.resolve(errMsg, [] { return false; });
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||
std::cerr << "Error message: " << errMsg << std::endl;
|
||||
REQUIRE(res == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Test resolving a good hostname, with cancellation")
|
||||
{
|
||||
DNSLookup dnsLookup("www.google.com", 80, 1);
|
||||
auto dnsLookup = std::make_shared<DNSLookup>("www.google.com", 80, 1);
|
||||
|
||||
std::string errMsg;
|
||||
// The callback returning true means we are requesting cancellation
|
||||
struct addrinfo* res = dnsLookup.resolve(errMsg, [] { return true; });
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; });
|
||||
std::cerr << "Error message: " << errMsg << std::endl;
|
||||
REQUIRE(res == nullptr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user