IXWebSocket/test/IXDNSLookupTest.cpp

60 lines
1.8 KiB
C++
Raw Permalink Normal View History

2019-01-05 23:40:17 +01:00
/*
* IXDNSLookupTest.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2018 Machine Zone. All rights reserved.
*/
#include "IXTest.h"
2019-09-23 19:25:23 +02:00
#include "catch.hpp"
2019-01-05 23:40:17 +01:00
#include <iostream>
2019-09-23 19:25:23 +02:00
#include <ixwebsocket/IXDNSLookup.h>
2019-01-05 23:40:17 +01:00
using namespace ix;
TEST_CASE("dns", "[net]")
{
SECTION("Test resolving a known hostname")
{
auto dnsLookup = std::make_shared<DNSLookup>("www.google.com", 80);
2019-01-05 23:40:17 +01:00
std::string errMsg;
struct addrinfo* res;
res = dnsLookup->resolve(errMsg, [] { return false; });
2019-01-05 23:40:17 +01:00
std::cerr << "Error message: " << errMsg << std::endl;
REQUIRE(res != nullptr);
2020-11-12 22:07:31 +01:00
dnsLookup->release(res);
2019-01-05 23:40:17 +01:00
}
SECTION("Test resolving a non-existing hostname")
{
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
2019-01-05 23:40:17 +01:00
std::string errMsg;
2020-04-25 00:34:00 +02:00
struct addrinfo* res = dnsLookup->resolve(errMsg,
[]
{
return false;
});
2019-01-05 23:40:17 +01:00
std::cerr << "Error message: " << errMsg << std::endl;
REQUIRE(res == nullptr);
}
SECTION("Test resolving a good hostname, with cancellation")
{
auto dnsLookup = std::make_shared<DNSLookup>("www.google.com", 80, 1);
2019-01-05 23:40:17 +01:00
std::string errMsg;
// The callback returning true means we are requesting cancellation
2020-04-25 00:34:00 +02:00
struct addrinfo* res = dnsLookup->resolve(errMsg,
[]
{
return true;
});
2019-01-05 23:40:17 +01:00
std::cerr << "Error message: " << errMsg << std::endl;
REQUIRE(res == nullptr);
}
}