add dns lookup test
This commit is contained in:
parent
e892b21872
commit
80a877ddab
@ -18,15 +18,25 @@ include_directories(
|
|||||||
${PROJECT_SOURCE_DIR}/Catch2/single_include
|
${PROJECT_SOURCE_DIR}/Catch2/single_include
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(ixwebsocket_unittest
|
# Shared sources
|
||||||
|
set (SOURCES
|
||||||
test_runner.cpp
|
test_runner.cpp
|
||||||
cmd_websocket_chat.cpp
|
IXDNSLookupTest.cpp
|
||||||
IXWebSocketServerTest.cpp
|
|
||||||
IXSocketTest.cpp
|
|
||||||
IXTest.cpp
|
IXTest.cpp
|
||||||
msgpack11.cpp
|
msgpack11.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Some unittest don't work on windows yet
|
||||||
|
if (NOT WIN32)
|
||||||
|
list(APPEND SOURCES
|
||||||
|
IXWebSocketServerTest.cpp
|
||||||
|
cmd_websocket_chat.cpp
|
||||||
|
IXSocketTest.cpp
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(ixwebsocket_unittest ${SOURCES})
|
||||||
|
|
||||||
if (APPLE AND USE_TLS)
|
if (APPLE AND USE_TLS)
|
||||||
target_link_libraries(ixwebsocket_unittest "-framework foundation" "-framework security")
|
target_link_libraries(ixwebsocket_unittest "-framework foundation" "-framework security")
|
||||||
endif()
|
endif()
|
||||||
|
50
test/IXDNSLookupTest.cpp
Normal file
50
test/IXDNSLookupTest.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* IXDNSLookupTest.cpp
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2018 Machine Zone. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include "IXTest.h"
|
||||||
|
#include <ixwebsocket/IXDNSLookup.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace ix;
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("dns", "[net]")
|
||||||
|
{
|
||||||
|
SECTION("Test resolving a known hostname")
|
||||||
|
{
|
||||||
|
DNSLookup dnsLookup("www.google.com", 80);
|
||||||
|
|
||||||
|
std::string errMsg;
|
||||||
|
struct addrinfo* res;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
std::string errMsg;
|
||||||
|
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);
|
||||||
|
|
||||||
|
std::string errMsg;
|
||||||
|
// The callback returning true means we are requesting cancellation
|
||||||
|
struct addrinfo* res = dnsLookup.resolve(errMsg, [] { return true; });
|
||||||
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
|
REQUIRE(res == nullptr);
|
||||||
|
}
|
||||||
|
}
|
@ -57,7 +57,5 @@ shutil.copy(os.path.join(
|
|||||||
'bin',
|
'bin',
|
||||||
'zlib.dll'), '.')
|
'zlib.dll'), '.')
|
||||||
|
|
||||||
# unittest broken on Windows
|
testCommand = '{} {}'.format(testBinary, os.getenv('TEST', ''))
|
||||||
if osName != 'Windows':
|
os.system(testCommand)
|
||||||
testCommand = '{} {}'.format(testBinary, os.getenv('TEST', ''))
|
|
||||||
os.system(testCommand)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user