[DNSAPI_APITEST] Add more tests for DnsQuery_A/W. By Peter Hater. ROSTESTS-242
[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 #include <iphlpapi.h>
14
15
16 void TestHostName(void)
17 {
18
19 DNS_STATUS dns_status;
20 char host_name[255];
21 char test_name[255];
22 PDNS_RECORD dp;
23 WCHAR host_nameW[255];
24 WCHAR test_nameW[255];
25 PFIXED_INFO network_info;
26 ULONG network_info_blen = 0;
27 DWORD network_info_result;
28
29 network_info_result = GetNetworkParams(NULL, &network_info_blen);
30 network_info = (PFIXED_INFO)HeapAlloc(GetProcessHeap(), 0, (size_t)network_info_blen);
31 if (NULL == network_info)
32 {
33 skip("Not enough memory. Can't continue!\n");
34 return;
35 }
36
37 network_info_result = GetNetworkParams(network_info, &network_info_blen);
38 if (network_info_result != ERROR_SUCCESS)
39 {
40 HeapFree(GetProcessHeap(), 0, network_info);
41 skip("Can't get network info. Some results may be wrong.\n");
42 return;
43 }
44 else
45 {
46 strcpy(host_name, network_info->HostName);
47 if (strlen(network_info->DomainName))
48 {
49 strcat(host_name, ".");
50 strcat(host_name, network_info->DomainName);
51 }
52 HeapFree(GetProcessHeap(), 0, network_info);
53 mbstowcs(host_nameW, host_name, 255);
54 }
55
56 //DnsQuery_A:
57 //NULL
58 dp = InvalidPointer;
59 dns_status = DnsQuery_A(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
60 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_A failed with error %lu\n", dns_status);
61 ok(dp == InvalidPointer, "dp = %p\n", dp);
62
63 //NULL dp
64 dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, NULL, 0);
65 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_A failed with error %lu\n", dns_status);
66
67 //Testing HostName
68 dp = InvalidPointer;
69 dns_status = DnsQuery_A(host_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
70 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
71 if (dp != InvalidPointer)
72 {
73 ok(strcmp(dp->pName, host_name) == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, host_name);
74 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
75 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
76 }
77 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
78 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
79
80 //127.0.0.1
81 dp = InvalidPointer;
82 dns_status = DnsQuery_A("127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
83 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
84 if (dp != InvalidPointer)
85 {
86 ok(strcmp(dp->pName, "127.0.0.1") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "127.0.0.1");
87 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
88 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
89 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
90 }
91 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
92 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
93
94 //Localhost strings
95 dp = InvalidPointer;
96 dns_status = DnsQuery_A("LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
97 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
98 if (dp != InvalidPointer)
99 {
100 /* On Windows 7 is unchanged on XP is lowercased */
101 ok(strcmp(dp->pName, "localhost") == 0 || broken(strcmp(dp->pName, "LocalHost") == 0), "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
102 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
103 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
104 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
105 }
106 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
107 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
108
109 dp = InvalidPointer;
110 dns_status = DnsQuery_A("Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
111 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
112 if (dp != InvalidPointer)
113 {
114 /* On Windows 7 is unchanged on XP is lowercased */
115 ok(strcmp(dp->pName, "localhost") == 0 || broken(strcmp(dp->pName, "Localhost") == 0), "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
116 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
117 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
118 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
119 }
120 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
121 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
122
123 dp = InvalidPointer;
124 dns_status = DnsQuery_A("localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
125 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
126 if (dp != InvalidPointer)
127 {
128 ok(strcmp(dp->pName, "localhost") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
129 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
130 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
131 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
132 }
133 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
134 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
135
136 dp = InvalidPointer;
137 dns_status = DnsQuery_A("", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
138 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
139 if (dp != InvalidPointer)
140 {
141 /* On Windows 7 is the host on XP is dot ??? */
142 ok(strcmp(dp->pName, ".") == 0 || broken(strcmp(dp->pName, host_name) == 0), "DnsQuery_A returned wrong answer '%s' expected '%s' or '.'\n", dp->pName, host_name);
143 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
144 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
145 }
146 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
147 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
148
149 dp = InvalidPointer;
150 dns_status = DnsQuery_A(" ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
151 /* On Windows 7 is DNS_ERROR_INVALID_NAME_CHAR on XP is ERROR_TIMEOUT on Win 2k3 is ERROR_INVALID_NAME*/
152 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A failed with error %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
153 if (dp != InvalidPointer && dns_status == NO_ERROR)
154 {
155 ok(strcmp(dp->pName, host_name) == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, host_name);
156 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
157 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
158 }
159 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
160 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
161
162 dp = InvalidPointer;
163 dns_status = DnsQuery_A("0.0.0.0", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
164 ok(dns_status == NO_ERROR, "DnsQuery_A failed with error %lu\n", dns_status);
165 if (dp != InvalidPointer)
166 {
167 ok(strcmp(dp->pName, "0.0.0.0") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "0.0.0.0");
168 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
169 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
170 ok(dp->Data.A.IpAddress == ntohl(INADDR_ANY), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_ANY));
171 }
172 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
173 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
174
175 dp = InvalidPointer;
176 dns_status = DnsQuery_A("0.0.0.0 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
177 /* On windows 7 fails with DNS_ERROR_INVALID_NAME_CHAR on XP no error */
178 ok(dns_status == NO_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u\n", dns_status, NO_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
179 if (dp != InvalidPointer && dns_status == NO_ERROR)
180 {
181 ok(strcmp(dp->pName, "0.0.0.0") == 0 || broken(strcmp(dp->pName, "0.0.0.0 ") == 0), "DnsQuery_A returned wrong answer '%s' expected '%s' or '%s'\n", dp->pName, "0.0.0.0", "0.0.0.0 ");
182 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
183 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
184 ok(dp->Data.A.IpAddress == ntohl(INADDR_ANY), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_ANY));
185 }
186 ok(dp != InvalidPointer || broken(dp == InvalidPointer) || broken(dp == NULL), "dp = %p\n", dp);
187 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
188
189 dp = InvalidPointer;
190 dns_status = DnsQuery_A("127.0.0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
191 /* On windows 7 fails with DNS_ERROR_INVALID_NAME_CHAR on XP no error */
192 ok(dns_status == NO_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u\n", dns_status, NO_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
193 if (dp != InvalidPointer && dns_status == NO_ERROR)
194 {
195 ok(strcmp(dp->pName, "127.0.0.1") == 0 || strcmp(dp->pName, "127.0.0.1 ") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s' or '%s'\n", dp->pName, "127.0.0.1", "127.0.0.1 ");
196 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
197 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
198 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
199 }
200 ok(dp != InvalidPointer || broken(dp == InvalidPointer) || broken(dp == NULL), "dp = %p\n", dp);
201 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
202
203 dp = InvalidPointer;
204 dns_status = DnsQuery_A(" 127.0.0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
205 ok(dns_status == DNS_ERROR_RCODE_NAME_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u\n", dns_status, DNS_ERROR_RCODE_NAME_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
206 if (dp != InvalidPointer && dns_status == NO_ERROR)
207 {
208 ok(strcmp(dp->pName, "127.0.0.1") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "127.0.0.1");
209 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
210 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
211 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
212 }
213 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
214 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
215
216 dp = InvalidPointer;
217 dns_status = DnsQuery_A(" 127.0. 0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
218 ok(dns_status == DNS_ERROR_RCODE_NAME_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u\n", dns_status, DNS_ERROR_RCODE_NAME_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
219 if (dp == InvalidPointer && dns_status == NO_ERROR)
220 {
221 ok(strcmp(dp->pName, "127.0.0.1") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "127.0.0.1");
222 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
223 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
224 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
225 }
226 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
227 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
228
229 dp = InvalidPointer;
230 dns_status = DnsQuery_A("localhost ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
231 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
232 if (dp != InvalidPointer && dns_status == NO_ERROR)
233 {
234 ok(strcmp(dp->pName, "localhost") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
235 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
236 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
237 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
238 }
239 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
240 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
241
242 dp = InvalidPointer;
243 dns_status = DnsQuery_A(" localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
244 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
245 if (dp != InvalidPointer && dns_status == NO_ERROR)
246 {
247 ok(strcmp(dp->pName, "localhost") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
248 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
249 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
250 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
251 }
252 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
253 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
254
255 dp = InvalidPointer;
256 strcpy(test_name, " local host ");
257 dns_status = DnsQuery_A(test_name, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
258 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_A wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
259 if (dp != InvalidPointer && dns_status == NO_ERROR)
260 {
261 ok(strcmp(dp->pName, "localhost") == 0, "DnsQuery_A returned wrong answer '%s' expected '%s'\n", dp->pName, "localhost");
262 ok(dp->wType == DNS_TYPE_A, "DnsQuery_A returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
263 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_A returned wrong data size %d\n", dp->wDataLength);
264 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_A returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
265 }
266 ok(dp == InvalidPointer || broken(dp == NULL), "dp = %p\n", dp);
267 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
268
269 //DnsQuery_W:
270 //NULL
271 dp = InvalidPointer;
272 dns_status = DnsQuery_W(NULL, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
273 if (dns_status == NO_ERROR)
274 {
275 /* Win2003 */
276 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
277 ok(dp != NULL && dp != InvalidPointer, "dp = %p\n", dp);
278 }
279 else
280 {
281 /* Win7 */
282 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_W failed with error %lu\n", dns_status);
283 ok(dp == InvalidPointer, "dp = %p\n", dp);
284 }
285 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
286
287 //NULL dp
288 dns_status = DnsQuery_W(host_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, NULL, 0);
289 ok(dns_status == ERROR_INVALID_PARAMETER, "DnsQuery_W failed with error %lu\n", dns_status);
290
291 //Testing HostName
292 dns_status = DnsQuery_W(host_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
293 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
294 if (dp != InvalidPointer)
295 {
296 ok(wcscmp((LPCWSTR)dp->pName, host_nameW) == 0, "DnsQuery_w returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, host_nameW);
297 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
298 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_w returned wrong data size %d\n", dp->wDataLength);
299 }
300 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
301 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
302
303 //127.0.0.1
304 dns_status = DnsQuery_W(L"127.0.0.1", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
305 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
306 if (dp != InvalidPointer)
307 {
308 ok(wcscmp((LPCWSTR)dp->pName, L"127.0.0.1") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"127.0.0.1");
309 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
310 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
311 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
312 }
313 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
314 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
315
316 //Localhost strings
317 dns_status = DnsQuery_W(L"LocalHost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
318 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
319 if (dp != InvalidPointer)
320 {
321 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0 || broken(wcscmp((LPCWSTR)dp->pName, L"LocalHost") == 0), "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
322 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
323 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
324 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
325 }
326 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
327 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
328
329 dns_status = DnsQuery_W(L"Localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
330 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
331 if (dp != InvalidPointer)
332 {
333 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0 || broken(wcscmp((LPCWSTR)dp->pName, L"Localhost") == 0), "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
334 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
335 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
336 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
337 }
338 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
339 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
340
341 dns_status = DnsQuery_W(L"localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
342 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
343 if (dp != InvalidPointer)
344 {
345 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
346 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
347 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
348 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
349 }
350 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
351 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
352
353 dns_status = DnsQuery_W(L"", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
354 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
355 if (dp != InvalidPointer)
356 {
357 /* On Windows 7 is the host on XP is dot ??? */
358 ok(wcscmp((LPCWSTR)dp->pName, L".") == 0 || broken(wcscmp((LPCWSTR)dp->pName, host_nameW) == 0), "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, host_nameW);
359 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
360 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
361 }
362 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
363 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
364
365 dp = InvalidPointer;
366 dns_status = DnsQuery_W(L" ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
367 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u or %d\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
368 if (dp != InvalidPointer && dns_status == NO_ERROR)
369 {
370 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
371 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
372 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
373 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
374 }
375 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
376 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
377
378 dns_status = DnsQuery_W(L"0.0.0.0", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
379 ok(dns_status == NO_ERROR, "DnsQuery_W failed with error %lu\n", dns_status);
380 if (dp != InvalidPointer)
381 {
382 ok(wcscmp((LPCWSTR)dp->pName, L"0.0.0.0") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"0.0.0.0");
383 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
384 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
385 ok(dp->Data.A.IpAddress == ntohl(INADDR_ANY), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_ANY));
386 }
387 ok(dp != InvalidPointer && dp != NULL, "dp = %p\n", dp);
388 if (dp != InvalidPointer) DnsRecordListFree(dp, DnsFreeRecordList);
389
390 dp = InvalidPointer;
391 dns_status = DnsQuery_W(L"0.0.0.0 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
392 ok(dns_status == NO_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u\n", dns_status, NO_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
393 if (dp != InvalidPointer && dns_status == NO_ERROR)
394 {
395 ok(wcscmp((LPCWSTR)dp->pName, L"0.0.0.0") == 0 || broken(wcscmp((LPCWSTR)dp->pName, L"0.0.0.0 ") == 0), "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"0.0.0.0");
396 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
397 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
398 ok(dp->Data.A.IpAddress == ntohl(INADDR_ANY), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_ANY));
399 }
400 ok(dp != InvalidPointer || broken(dp == InvalidPointer) || broken(dp == NULL), "dp = %p\n", dp);
401 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
402
403 dp = InvalidPointer;
404 dns_status = DnsQuery_W(L"127.0.0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
405 ok(dns_status == NO_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u\n", dns_status, NO_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
406 if (dp != InvalidPointer && dns_status == NO_ERROR)
407 {
408 ok(wcscmp((LPCWSTR)dp->pName, L"127.0.0.1") == 0 || broken(wcscmp((LPCWSTR)dp->pName, L"127.0.0.1 ") == 0), "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"127.0.0.1");
409 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
410 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
411 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
412 }
413 ok(dp != InvalidPointer || broken(dp == InvalidPointer) || broken(dp == NULL), "dp = %p\n", dp);
414 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
415
416 dp = InvalidPointer;
417 dns_status = DnsQuery_W(L" 127.0.0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
418 ok(dns_status == DNS_ERROR_RCODE_NAME_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u\n", dns_status, DNS_ERROR_RCODE_NAME_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
419 if (dp != InvalidPointer && dns_status == NO_ERROR)
420 {
421 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
422 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
423 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
424 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
425 }
426 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
427 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
428
429 dp = InvalidPointer;
430 dns_status = DnsQuery_W(L" 127.0. 0.1 ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
431 ok(dns_status == DNS_ERROR_RCODE_NAME_ERROR || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u\n", dns_status, DNS_ERROR_RCODE_NAME_ERROR, DNS_ERROR_INVALID_NAME_CHAR);
432 if (dp != InvalidPointer && dns_status == NO_ERROR)
433 {
434 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
435 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
436 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
437 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
438 }
439 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
440 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
441
442 dp = InvalidPointer;
443 dns_status = DnsQuery_W(L"localhost ", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
444 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
445 if (dp != InvalidPointer && dns_status == NO_ERROR)
446 {
447 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
448 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
449 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
450 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
451 }
452 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
453 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
454
455 dp = InvalidPointer;
456 dns_status = DnsQuery_W(L" localhost", DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
457 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
458 if (dp != InvalidPointer && dns_status == NO_ERROR)
459 {
460 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
461 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
462 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
463 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
464 }
465 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
466 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
467
468 dp = InvalidPointer;
469 wcscpy(test_nameW, L" local host ");
470 dns_status = DnsQuery_W(test_nameW, DNS_TYPE_A, DNS_QUERY_STANDARD, 0, &dp, 0);
471 ok(dns_status == ERROR_INVALID_NAME || broken(dns_status == ERROR_TIMEOUT) || broken(dns_status == DNS_ERROR_INVALID_NAME_CHAR), "DnsQuery_W wrong status %lu expected %u or %u or %u\n", dns_status, ERROR_INVALID_NAME, ERROR_TIMEOUT, DNS_ERROR_INVALID_NAME_CHAR);
472 if (dp != InvalidPointer && dns_status == NO_ERROR)
473 {
474 ok(wcscmp((LPCWSTR)dp->pName, L"localhost") == 0, "DnsQuery_W returned wrong answer '%ls' expected '%ls'\n", (LPCWSTR)dp->pName, L"localhost");
475 ok(dp->wType == DNS_TYPE_A, "DnsQuery_W returned wrong type %d expected %d\n", dp->wType, DNS_TYPE_A);
476 ok(dp->wDataLength == sizeof(IP4_ADDRESS), "DnsQuery_W returned wrong data size %d\n", dp->wDataLength);
477 ok(dp->Data.A.IpAddress == ntohl(INADDR_LOOPBACK), "DnsQuery_W returned wrong data %ld expected %ld\n", dp->Data.A.IpAddress, ntohl(INADDR_LOOPBACK));
478 }
479 ok(dp == NULL || broken(dp == InvalidPointer), "dp = %p\n", dp);
480 if (dp != InvalidPointer && dns_status == NO_ERROR) DnsRecordListFree(dp, DnsFreeRecordList);
481 }
482
483 START_TEST(DnsQuery)
484 {
485 WSADATA wsaData;
486 int iResult;
487
488 // Initialize Winsock
489 iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
490 ok(iResult == 0, "WSAStartup failed: %d\n", iResult);
491 if (iResult != 0) return;
492
493 // Tests
494 TestHostName();
495
496 WSACleanup();
497
498 return;
499 }