[DNSAPI_APITEST] Add more tests for DnsQuery_A/W. By Peter Hater. ROSTESTS-242
authorAmine Khaldi <amine.khaldi@reactos.org>
Fri, 30 Sep 2016 15:23:25 +0000 (15:23 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Fri, 30 Sep 2016 15:23:25 +0000 (15:23 +0000)
svn path=/trunk/; revision=72868

rostests/apitests/dnsapi/CMakeLists.txt
rostests/apitests/dnsapi/DnsQuery.c

index b9ddc12..9692c06 100644 (file)
@@ -6,5 +6,5 @@ list(APPEND SOURCE
 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_importlibs(dnsapi_apitest ws2_32 dnsapi iphlpapi msvcrt kernel32 ntdll)
 add_cd_file(TARGET dnsapi_apitest DESTINATION reactos/bin FOR all)
index 78fca24..a659154 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <windns.h>
 #include <apitest.h>
+#include <iphlpapi.h>
 
 
 void TestHostName(void)
@@ -17,22 +18,40 @@ void TestHostName(void)
 
     DNS_STATUS dns_status;
     char host_name[255];
-    char domain_name[255];
     char test_name[255];
     PDNS_RECORD dp;
     WCHAR host_nameW[255];
     WCHAR test_nameW[255];
-    DWORD size = sizeof(host_name);
+    PFIXED_INFO network_info;
+    ULONG network_info_blen = 0;
+    DWORD network_info_result;
 
-    GetComputerNameEx(ComputerNameDnsHostname, host_name, &size);
-    size = sizeof(domain_name);
-    GetComputerNameEx(ComputerNameDnsDomain, domain_name, &size);
-    if (strlen(domain_name))
+    network_info_result = GetNetworkParams(NULL, &network_info_blen);
+    network_info = (PFIXED_INFO)HeapAlloc(GetProcessHeap(), 0, (size_t)network_info_blen);
+    if (NULL == network_info)
     {
-        strcat(host_name, ".");
-        strcat(host_name, domain_name);
+        skip("Not enough memory. Can't continue!\n");
+        return;
+    }
+
+    network_info_result = GetNetworkParams(network_info, &network_info_blen);
+    if (network_info_result != ERROR_SUCCESS)
+    {
+        HeapFree(GetProcessHeap(), 0, network_info);
+        skip("Can't get network info. Some results may be wrong.\n");
+        return;
+    }
+    else
+    {
+        strcpy(host_name, network_info->HostName);
+        if (strlen(network_info->DomainName))
+        {
+            strcat(host_name, ".");
+            strcat(host_name, network_info->DomainName);
+        }
+        HeapFree(GetProcessHeap(), 0, network_info);
+        mbstowcs(host_nameW, host_name, 255);
     }
-    mbstowcs(host_nameW, host_name, 255);
 
     //DnsQuery_A:
     //NULL
@@ -40,7 +59,11 @@ void TestHostName(void)
     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);
-    
+
+    //NULL dp
+    dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, NULL, 0);
+    ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_A failed with error %lu\n", dns_status);
+
     //Testing HostName 
     dp = InvalidPointer;
     dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
@@ -261,6 +284,10 @@ void TestHostName(void)
     }
     if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
 
+    //NULL dp
+    dns_status = DnsQuery_W(host_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, NULL, 0);
+    ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_W failed with error %lu\n", dns_status);
+
     //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);