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