From 2d22483bef8f6eb850df4d2c33a1953a133c493b Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Fri, 1 Jul 2016 14:44:55 +0000 Subject: [PATCH] =?utf8?q?[DNSAPI=5FAPITEST]=20-=20Add=20a=20test=20for=20?= =?utf8?q?DnsQuery.=20Patch=20by=20V=C3=ADctor=20Mart=C3=ADnez=20Calvo,=20?= =?utf8?q?with=20additional=20tests=20and=20fixes=20by=20me.=20ROSTESTS-22?= =?utf8?q?6=20#resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit svn path=/trunk/; revision=71709 --- rostests/apitests/CMakeLists.txt | 1 + rostests/apitests/dnsapi/CMakeLists.txt | 10 +++ rostests/apitests/dnsapi/DnsQuery.c | 112 ++++++++++++++++++++++++ rostests/apitests/dnsapi/testlist.c | 10 +++ 4 files changed, 133 insertions(+) create mode 100644 rostests/apitests/dnsapi/CMakeLists.txt create mode 100644 rostests/apitests/dnsapi/DnsQuery.c create mode 100644 rostests/apitests/dnsapi/testlist.c diff --git a/rostests/apitests/CMakeLists.txt b/rostests/apitests/CMakeLists.txt index ab2c36da2d3..3a9bdfa9403 100644 --- a/rostests/apitests/CMakeLists.txt +++ b/rostests/apitests/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory(browseui) add_subdirectory(com) add_subdirectory(crt) add_subdirectory(dciman32) +add_subdirectory(dnsapi) add_subdirectory(gdi32) add_subdirectory(gditools) add_subdirectory(iphlpapi) diff --git a/rostests/apitests/dnsapi/CMakeLists.txt b/rostests/apitests/dnsapi/CMakeLists.txt new file mode 100644 index 00000000000..b9ddc127d28 --- /dev/null +++ b/rostests/apitests/dnsapi/CMakeLists.txt @@ -0,0 +1,10 @@ + +list(APPEND SOURCE + DnsQuery.c + testlist.c) + +add_executable(dnsapi_apitest ${SOURCE}) +target_link_libraries(dnsapi_apitest wine) +set_module_type(dnsapi_apitest win32cui) +add_importlibs(dnsapi_apitest ws2_32 dnsapi msvcrt kernel32 ntdll) +add_cd_file(TARGET dnsapi_apitest DESTINATION reactos/bin FOR all) diff --git a/rostests/apitests/dnsapi/DnsQuery.c b/rostests/apitests/dnsapi/DnsQuery.c new file mode 100644 index 00000000000..740161afa25 --- /dev/null +++ b/rostests/apitests/dnsapi/DnsQuery.c @@ -0,0 +1,112 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for DnsQuery_A + * PROGRAMMER: Victor Martinez Calvo + */ + +#include +#include +#include +#include +#include + + +void TestHostName(void) +{ + + DNS_STATUS dns_status = NO_ERROR; + char host_name[255]; + PDNS_RECORD dp = NULL; + WCHAR host_nameW[255]; + + gethostname(host_name, sizeof(host_name)); + mbstowcs(host_nameW, host_name, 255); + + //DnsQuery_A: + //NULL + dp = InvalidPointer; + dns_status = DnsQuery_A(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_A failed with error %lu\n", dns_status); + ok(dp == InvalidPointer, "dp = %p\n", dp); + + //Testing HostName + dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + //127.0.0.1 + dns_status = DnsQuery_A("127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + //Localhost strings + dns_status = DnsQuery_A("LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + dns_status = DnsQuery_A("Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + dns_status = DnsQuery_A("localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + //DnsQuery_W: + //NULL + dp = InvalidPointer; + dns_status = DnsQuery_W(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + if (dns_status == NO_ERROR) + { + /* Win2003 */ + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + ok(dp != NULL && dp != InvalidPointer, "dp = %p\n", dp); + } + else + { + /* Win7 */ + ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_W failed with error %lu\n", dns_status); + ok(dp == InvalidPointer, "dp = %p\n", dp); + } + if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList); + + //Testing HostName + dns_status = DnsQuery_W(host_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + //127.0.0.1 + dns_status = DnsQuery_W(L"127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + //Localhost strings + dns_status = DnsQuery_W(L"LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + dns_status = DnsQuery_W(L"Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); + + dns_status = DnsQuery_W(L"localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0); + ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status); + DnsRecordListFree(dp, DnsFreeRecordList); +} + +START_TEST(DnsQuery) +{ + WSADATA wsaData; + int iResult; + + // Initialize Winsock + iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); + ok(iResult == 0, "WSAStartup failed: %d\n", iResult); + if (iResult != 0) return; + + // Tests + TestHostName(); + + return; +} diff --git a/rostests/apitests/dnsapi/testlist.c b/rostests/apitests/dnsapi/testlist.c new file mode 100644 index 00000000000..30639088d77 --- /dev/null +++ b/rostests/apitests/dnsapi/testlist.c @@ -0,0 +1,10 @@ +#define STANDALONE +#include + +extern void func_DnsQuery(void); + +const struct test winetest_testlist[] = +{ + { "DnsQuery", func_DnsQuery }, + { 0, 0 } +}; -- 2.17.1