740161afa250edd9f34225c99a90b0a5032a9f39
[reactos.git] / rostests / apitests / dnsapi / DnsQuery.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for DnsQuery_A
5 * PROGRAMMER: Victor Martinez Calvo <victor.martinez@reactos.org>
6 */
7
8 #include <winsock2.h>
9 #include <ws2tcpip.h>
10 #include <stdio.h>
11 #include <WinDNS.h>
12 #include <apitest.h>
13
14
15 void TestHostName(void)
16 {
17
18 DNS_STATUS dns_status = NO_ERROR;
19 char host_name[255];
20 PDNS_RECORD dp = NULL;
21 WCHAR host_nameW[255];
22
23 gethostname(host_name, sizeof(host_name));
24 mbstowcs(host_nameW, host_name, 255);
25
26 //DnsQuery_A:
27 //NULL
28 dp = InvalidPointer;
29 dns_status = DnsQuery_A(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
30 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_A failed with error %lu\n", dns_status);
31 ok(dp == InvalidPointer, "dp = %p\n", dp);
32
33 //Testing HostName
34 dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
35 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
36 DnsRecordListFree(dp, DnsFreeRecordList);
37
38 //127.0.0.1
39 dns_status = DnsQuery_A("127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
40 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
41 DnsRecordListFree(dp, DnsFreeRecordList);
42
43 //Localhost strings
44 dns_status = DnsQuery_A("LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
45 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
46 DnsRecordListFree(dp, DnsFreeRecordList);
47
48 dns_status = DnsQuery_A("Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
49 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
50 DnsRecordListFree(dp, DnsFreeRecordList);
51
52 dns_status = DnsQuery_A("localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
53 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
54 DnsRecordListFree(dp, DnsFreeRecordList);
55
56 //DnsQuery_W:
57 //NULL
58 dp = InvalidPointer;
59 dns_status = DnsQuery_W(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
60 if (dns_status == NO_ERROR)
61 {
62 /* Win2003 */
63 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
64 ok(dp != NULL && dp != InvalidPointer, "dp = %p\n", dp);
65 }
66 else
67 {
68 /* Win7 */
69 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_W failed with error %lu\n", dns_status);
70 ok(dp == InvalidPointer, "dp = %p\n", dp);
71 }
72 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
73
74 //Testing HostName
75 dns_status = DnsQuery_W(host_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
76 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
77 DnsRecordListFree(dp, DnsFreeRecordList);
78
79 //127.0.0.1
80 dns_status = DnsQuery_W(L"127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
81 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
82 DnsRecordListFree(dp, DnsFreeRecordList);
83
84 //Localhost strings
85 dns_status = DnsQuery_W(L"LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
86 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
87 DnsRecordListFree(dp, DnsFreeRecordList);
88
89 dns_status = DnsQuery_W(L"Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
90 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
91 DnsRecordListFree(dp, DnsFreeRecordList);
92
93 dns_status = DnsQuery_W(L"localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
94 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
95 DnsRecordListFree(dp, DnsFreeRecordList);
96 }
97
98 START_TEST(DnsQuery)
99 {
100 WSADATA wsaData;
101 int iResult;
102
103 // Initialize Winsock
104 iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
105 ok(iResult == 0, "WSAStartup failed: %d\n", iResult);
106 if (iResult != 0) return;
107
108 // Tests
109 TestHostName();
110
111 return;
112 }