[KERNEL32_APITEST] Add tests that reveal how the GetComputerNameEx fix in r72722...
[reactos.git] / rostests / apitests / kernel32 / GetComputerNameEx.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for GetComputerNameEx
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <stdio.h>
12 #include <ndk/rtltypes.h>
13 #include <winreg.h>
14
15 static
16 VOID
17 TestGetComputerNameEx(
18 _In_ COMPUTER_NAME_FORMAT NameType)
19 {
20 WCHAR Reference[128];
21 DWORD ReferenceLen;
22 WCHAR BufferW[128];
23 CHAR BufferA[128];
24 BOOL Ret;
25 DWORD Size;
26 DWORD Error;
27 ULONG i;
28
29 Size = RTL_NUMBER_OF(Reference);
30 Ret = GetComputerNameExW(NameType, Reference, &Size);
31 ok(Ret == TRUE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
32 if (!Ret)
33 {
34 skip("[%d] Failed to get reference string\n", NameType);
35 return;
36 }
37 trace("[%d] Reference is %ls\n", NameType, Reference);
38 ReferenceLen = wcslen(Reference);
39 ok(ReferenceLen < RTL_NUMBER_OF(Reference),
40 "[%d] Unexpected ReferenceLen %lu\n", NameType, ReferenceLen);
41 if (NameType != ComputerNameDnsDomain && NameType != ComputerNamePhysicalDnsDomain)
42 {
43 ok(ReferenceLen != 0, "[%d] Unexpected ReferenceLen %lu\n", NameType, ReferenceLen);
44 }
45 ok(Size == ReferenceLen, "[%d] Size is %lu, expected %lu\n", NameType, Size, ReferenceLen);
46
47 /* NULL buffer, NULL size */
48 StartSeh()
49 Ret = GetComputerNameExW(NameType, NULL, NULL);
50 Error = GetLastError();
51 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
52 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
53 EndSeh(STATUS_SUCCESS);
54 StartSeh()
55 Ret = GetComputerNameExA(NameType, NULL, NULL);
56 Error = GetLastError();
57 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
58 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
59 EndSeh(STATUS_SUCCESS);
60
61 /* NULL buffer, nonzero size */
62 Size = 0x55555555;
63 Ret = GetComputerNameExW(NameType, NULL, &Size);
64 Error = GetLastError();
65 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
66 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
67 ok(Size == 0x55555555, "[%d] Got Size %lu\n", NameType, Size);
68
69 Size = 0x55555555;
70 Ret = GetComputerNameExA(NameType, NULL, &Size);
71 Error = GetLastError();
72 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
73 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
74 ok(Size == 0x55555555, "[%d] Got Size %lu\n", NameType, Size);
75
76 /* non-NULL buffer, NULL size */
77 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
78 Ret = GetComputerNameExW(NameType, BufferW, NULL);
79 Error = GetLastError();
80 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
81 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
82 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType, BufferW[0]);
83
84 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
85 Ret = GetComputerNameExA(NameType, BufferA, NULL);
86 Error = GetLastError();
87 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
88 ok(Error == ERROR_INVALID_PARAMETER, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
89 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
90
91 /* NULL buffer, zero size */
92 Size = 0;
93 Ret = GetComputerNameExW(NameType, NULL, &Size);
94 Error = GetLastError();
95 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
96 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
97 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
98
99 Size = 0;
100 Ret = GetComputerNameExA(NameType, NULL, &Size);
101 Error = GetLastError();
102 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
103 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
104 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
105
106 /* non-NULL buffer, zero size */
107 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
108 Size = 0;
109 Ret = GetComputerNameExW(NameType, BufferW, &Size);
110 Error = GetLastError();
111 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
112 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
113 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
114 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType, BufferW[0]);
115
116 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
117 Size = 0;
118 Ret = GetComputerNameExA(NameType, BufferA, &Size);
119 Error = GetLastError();
120 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
121 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
122 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
123 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
124
125 /* non-NULL buffer, too small size */
126 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
127 Size = ReferenceLen;
128 Ret = GetComputerNameExW(NameType, BufferW, &Size);
129 Error = GetLastError();
130 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
131 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExW returned error %lu\n", NameType, Error);
132 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
133 if (NameType != ComputerNameNetBIOS && NameType != ComputerNamePhysicalNetBIOS)
134 {
135 if (ReferenceLen == 0)
136 {
137 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n",
138 NameType, BufferW[0]);
139 }
140 else
141 {
142 ok(BufferW[0] == 0, "[%d] BufferW[0] = 0x%x\n",
143 NameType, BufferW[0]);
144 }
145 }
146 ok(BufferW[1] == 0x5555, "[%d] BufferW[1] = 0x%x\n", NameType, BufferW[1]);
147
148 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
149 Size = ReferenceLen;
150 Ret = GetComputerNameExA(NameType, BufferA, &Size);
151 Error = GetLastError();
152 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
153 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
154 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
155 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
156
157 /* non-NULL buffer, exact size */
158 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
159 Size = ReferenceLen + 1;
160 Ret = GetComputerNameExW(NameType, BufferW, &Size);
161 ok(Ret == TRUE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
162 ok(Size == ReferenceLen, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
163 ok(BufferW[ReferenceLen] == 0, "[%d] BufferW[ReferenceLen] = 0x%x\n", NameType, BufferW[ReferenceLen]);
164 ok(BufferW[ReferenceLen + 1] == 0x5555, "[%d] BufferW[ReferenceLen + 1] = 0x%x\n", NameType, BufferW[ReferenceLen + 1]);
165 ok(!wcscmp(BufferW, Reference), "[%d] '%ls' != '%ls'\n", NameType, BufferW, Reference);
166
167 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
168 Size = ReferenceLen + 1;
169 Ret = GetComputerNameExA(NameType, BufferA, &Size);
170 ok(Ret == TRUE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
171 ok(Size == ReferenceLen, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
172 ok(BufferA[ReferenceLen] == 0, "[%d] BufferA[ReferenceLen] = 0x%x\n", NameType, BufferA[ReferenceLen]);
173 ok(BufferA[ReferenceLen + 1] == 0x55, "[%d] BufferA[ReferenceLen + 1] = 0x%x\n", NameType, BufferA[ReferenceLen + 1]);
174 for (i = 0; i < ReferenceLen; i++)
175 {
176 if (BufferA[i] != Reference[i])
177 {
178 ok(0, "[%d] BufferA[%lu] = 0x%x, expected 0x%x\n", NameType, i, BufferA[i], Reference[i]);
179 }
180 }
181 }
182
183 static
184 LSTATUS
185 ReadRegistryValue(PCHAR ValueName, PCHAR Value)
186 {
187 INT ErrorCode;
188 HKEY ParametersKey;
189 DWORD RegType;
190 DWORD RegSize = 0;
191
192 /* Open the database path key */
193 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
194 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
195 0,
196 KEY_READ,
197 &ParametersKey);
198 if (ErrorCode == NO_ERROR)
199 {
200 /* Read the actual path */
201 ErrorCode = RegQueryValueExA(ParametersKey,
202 ValueName,
203 NULL,
204 &RegType,
205 NULL,
206 &RegSize);
207 if (RegSize)
208 {
209 /* Read the actual path */
210 ErrorCode = RegQueryValueExA(ParametersKey,
211 ValueName,
212 NULL,
213 &RegType,
214 (LPBYTE)Value,
215 &RegSize);
216 }
217
218 /* Close the key */
219 RegCloseKey(ParametersKey);
220 }
221 return ErrorCode;
222 }
223
224 static
225 LSTATUS
226 ReadRegistryComputerNameValue(PCHAR ValueName, PCHAR Value)
227 {
228 INT ErrorCode;
229 HKEY ParametersKey;
230 DWORD RegType;
231 DWORD RegSize = 0;
232
233 /* Open the database path key */
234 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
235 "System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName",
236 0,
237 KEY_READ,
238 &ParametersKey);
239 if (ErrorCode == NO_ERROR)
240 {
241 /* Read the actual path */
242 ErrorCode = RegQueryValueExA(ParametersKey,
243 ValueName,
244 NULL,
245 &RegType,
246 NULL,
247 &RegSize);
248 if (RegSize)
249 {
250 /* Read the actual path */
251 ErrorCode = RegQueryValueExA(ParametersKey,
252 ValueName,
253 NULL,
254 &RegType,
255 (LPBYTE)Value,
256 &RegSize);
257 }
258
259 /* Close the key */
260 RegCloseKey(ParametersKey);
261 }
262 return ErrorCode;
263 }
264
265 static
266 LSTATUS
267 WriteRegistryValue(PCHAR ValueName, PCHAR Value)
268 {
269 INT ErrorCode;
270 HKEY ParametersKey;
271
272 /* Open the database path key */
273 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
274 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
275 0,
276 KEY_WRITE,
277 &ParametersKey);
278 if (ErrorCode == NO_ERROR)
279 {
280 /* Read the actual path */
281 ErrorCode = RegSetValueExA(ParametersKey,
282 ValueName,
283 0,
284 REG_SZ,
285 (LPBYTE)Value,
286 strlen(Value) + 1);
287
288 /* Close the key */
289 RegCloseKey(ParametersKey);
290 }
291 return ErrorCode;
292 }
293
294 static
295 LSTATUS
296 DeleteRegistryValue(PCHAR ValueName)
297 {
298 INT ErrorCode;
299 HKEY ParametersKey;
300
301 /* Open the database path key */
302 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
303 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
304 0,
305 KEY_WRITE,
306 &ParametersKey);
307 if (ErrorCode == NO_ERROR)
308 {
309 /* Read the actual path */
310 ErrorCode = RegDeleteValueA(ParametersKey, ValueName);
311
312 /* Close the key */
313 RegCloseKey(ParametersKey);
314 }
315 return ErrorCode;
316 }
317
318 /* If this test crashes it might end up with wrong host and/or domain name in registry! */
319 static
320 VOID
321 TestReturnValues()
322 {
323 CHAR OrigNetBIOS[128];
324 CHAR OrigHostname[128];
325 CHAR OrigDomainName[128];
326 CHAR OrigDhcpHostname[128];
327 CHAR OrigDhcpDomainName[128];
328 BOOL OrigNetBIOSExists;
329 BOOL OrigHostnameExists;
330 BOOL OrigDomainNameExists;
331 BOOL OrigDhcpHostnameExists;
332 BOOL OrigDhcpDomainNameExists;
333 CHAR ComputerName[128];
334 DWORD ComputerNameSize = 0;
335 INT ErrorCode;
336
337 memset(OrigNetBIOS, 0, sizeof(OrigNetBIOS));
338 memset(OrigHostname, 0, sizeof(OrigHostname));
339 memset(OrigDomainName, 0, sizeof(OrigDomainName));
340 memset(OrigDhcpHostname, 0, sizeof(OrigDhcpHostname));
341 memset(OrigDhcpDomainName, 0, sizeof(OrigDhcpDomainName));
342 /* read current registry values */
343 ErrorCode = ReadRegistryComputerNameValue("ComputerName", OrigNetBIOS);
344 ok(ErrorCode == ERROR_SUCCESS, "Failed to read registry key ComputerName %d\n", ErrorCode);
345 OrigNetBIOSExists = ErrorCode == STATUS_SUCCESS;
346 ErrorCode = ReadRegistryValue("Hostname", OrigHostname);
347 ok(ErrorCode == ERROR_SUCCESS, "Failed to read registry key Hostname %d\n", ErrorCode);
348 OrigHostnameExists = ErrorCode == STATUS_SUCCESS;
349 ErrorCode = ReadRegistryValue("Domain", OrigDomainName);
350 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DomainName %d\n", ErrorCode);
351 OrigDomainNameExists = ErrorCode == STATUS_SUCCESS;
352 ErrorCode = ReadRegistryValue("DhcpHostname", OrigDhcpHostname);
353 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpHostname %d\n", ErrorCode);
354 OrigDhcpHostnameExists = ErrorCode == STATUS_SUCCESS;
355 ErrorCode = ReadRegistryValue("DhcpDomain", OrigDhcpDomainName);
356 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpDomainName %d\n", ErrorCode);
357 OrigDhcpDomainNameExists = ErrorCode == STATUS_SUCCESS;
358
359 trace("Starting values:\n");
360 trace("NetBIOS: %s, exists %s\n", OrigNetBIOS, OrigNetBIOSExists ? "yes" : "no");
361 trace("Hostname: %s, exists %s\n", OrigHostname, OrigHostnameExists ? "yes" : "no");
362 trace("Domain: %s, exists %s\n", OrigDomainName, OrigDomainNameExists ? "yes" : "no");
363 trace("DhcpHostname: %s, exists %s\n", OrigDhcpHostnameExists ? OrigDhcpHostname : "", OrigDhcpHostnameExists ? "yes" : "no");
364 trace("DhcpDomain: %s, exists %s\n", OrigDhcpDomainNameExists ? OrigDhcpDomainName : "", OrigDhcpDomainNameExists ? "yes" : "no");
365
366 /* ComputerNamePhysicalNetBIOS */
367 ComputerNameSize = 0;
368 StartSeh()
369 GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
370 if (ComputerNameSize)
371 ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
372 else
373 memset(ComputerName, 0, sizeof(ComputerName));
374 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
375 EndSeh(STATUS_SUCCESS);
376
377 /* ComputerNamePhysicalDnsHostname */
378 ComputerNameSize = 0;
379 StartSeh()
380 GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
381 if (ComputerNameSize)
382 ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
383 else
384 memset(ComputerName, 0, sizeof(ComputerName));
385 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
386 EndSeh(STATUS_SUCCESS);
387
388 /* ComputerNamePhysicalDnsDomain */
389 ComputerNameSize = 0;
390 StartSeh()
391 GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
392 if (ComputerNameSize)
393 ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
394 else
395 memset(ComputerName, 0, sizeof(ComputerName));
396 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
397 EndSeh(STATUS_SUCCESS);
398 ComputerNameSize = 0;
399
400 /* ComputerNameNetBIOS */
401 StartSeh()
402 GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
403 if (ComputerNameSize)
404 ok(GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
405 else
406 memset(ComputerName, 0, sizeof(ComputerName));
407 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
408 EndSeh(STATUS_SUCCESS);
409
410 /* ComputerNameDnsHostname */
411 ComputerNameSize = 0;
412 StartSeh()
413 GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
414 if (ComputerNameSize)
415 ok(GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
416 else
417 memset(ComputerName, 0, sizeof(ComputerName));
418 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
419 EndSeh(STATUS_SUCCESS);
420
421 /* ComputerNameDnsDomain */
422 ComputerNameSize = 0;
423 StartSeh()
424 GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
425 if (ComputerNameSize)
426 ok(GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
427 else
428 memset(ComputerName, 0, sizeof(ComputerName));
429 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
430 EndSeh(STATUS_SUCCESS);
431
432 ErrorCode = WriteRegistryValue("DhcpHostname", "testdhcproshost");
433 ok(ErrorCode == ERROR_SUCCESS, "Failed to write registry key DhcpHostname %d\n", ErrorCode);
434 ErrorCode = WriteRegistryValue("DhcpDomain", "testrosdomain");
435 ok(ErrorCode == ERROR_SUCCESS, "Failed to write registry key DhcpDomainName %d\n", ErrorCode);
436
437 /* ComputerNamePhysicalNetBIOS */
438 ComputerNameSize = 0;
439 StartSeh()
440 GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
441 if (ComputerNameSize)
442 ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
443 else
444 memset(ComputerName, 0, sizeof(ComputerName));
445 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
446 EndSeh(STATUS_SUCCESS);
447
448 /* ComputerNamePhysicalDnsHostname */
449 ComputerNameSize = 0;
450 StartSeh()
451 GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
452 if (ComputerNameSize)
453 ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
454 else
455 memset(ComputerName, 0, sizeof(ComputerName));
456 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
457 EndSeh(STATUS_SUCCESS);
458
459 /* ComputerNamePhysicalDnsDomain */
460 ComputerNameSize = 0;
461 StartSeh()
462 GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
463 if (ComputerNameSize)
464 ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
465 else
466 memset(ComputerName, 0, sizeof(ComputerName));
467 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
468 EndSeh(STATUS_SUCCESS);
469 ComputerNameSize = 0;
470
471 /* ComputerNameNetBIOS */
472 StartSeh()
473 GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
474 if (ComputerNameSize)
475 ok(GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
476 else
477 memset(ComputerName, 0, sizeof(ComputerName));
478 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
479 EndSeh(STATUS_SUCCESS);
480
481 /* ComputerNameDnsHostname */
482 ComputerNameSize = 0;
483 StartSeh()
484 GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
485 if (ComputerNameSize)
486 ok(GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
487 else
488 memset(ComputerName, 0, sizeof(ComputerName));
489 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
490 EndSeh(STATUS_SUCCESS);
491
492 /* ComputerNameDnsDomain */
493 ComputerNameSize = 0;
494 StartSeh()
495 GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
496 if (ComputerNameSize)
497 ok(GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
498 else
499 memset(ComputerName, 0, sizeof(ComputerName));
500 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
501 EndSeh(STATUS_SUCCESS);
502
503 /* restore registry values */
504 if (OrigDhcpHostnameExists)
505 ErrorCode = WriteRegistryValue("DhcpHostname", OrigDhcpHostname);
506 else
507 ErrorCode = DeleteRegistryValue("DhcpHostname");
508 ok(ErrorCode == ERROR_SUCCESS, "Failed to restore registry key DhcpHostname %d\n", ErrorCode);
509 if (OrigDhcpDomainNameExists)
510 ErrorCode = WriteRegistryValue("DhcpDomain", OrigDhcpDomainName);
511 else
512 ErrorCode = DeleteRegistryValue("DhcpDomain");
513 ok(ErrorCode == ERROR_SUCCESS, "Failed to restore registry key DhcpDomainName %d\n", ErrorCode);
514 }
515
516 START_TEST(GetComputerNameEx)
517 {
518 TestGetComputerNameEx(ComputerNameNetBIOS);
519 TestGetComputerNameEx(ComputerNameDnsHostname);
520 TestGetComputerNameEx(ComputerNameDnsDomain);
521 //TestGetComputerNameEx(ComputerNameDnsFullyQualified);
522 TestGetComputerNameEx(ComputerNamePhysicalNetBIOS);
523 TestGetComputerNameEx(ComputerNamePhysicalDnsHostname);
524 TestGetComputerNameEx(ComputerNamePhysicalDnsDomain);
525 //TestGetComputerNameEx(ComputerNamePhysicalDnsFullyQualified);
526 TestReturnValues();
527 }