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>
12 TestGetComputerNameEx(
13 _In_ COMPUTER_NAME_FORMAT NameType
)
24 Size
= RTL_NUMBER_OF(Reference
);
25 Ret
= GetComputerNameExW(NameType
, Reference
, &Size
);
26 ok(Ret
== TRUE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
29 skip("[%d] Failed to get reference string\n", NameType
);
32 trace("[%d] Reference is %ls\n", NameType
, Reference
);
33 ReferenceLen
= lstrlenW(Reference
);
34 ok(ReferenceLen
< RTL_NUMBER_OF(Reference
),
35 "[%d] Unexpected ReferenceLen %lu\n", NameType
, ReferenceLen
);
36 if (NameType
!= ComputerNameDnsDomain
&& NameType
!= ComputerNamePhysicalDnsDomain
)
38 ok(ReferenceLen
!= 0, "[%d] Unexpected ReferenceLen %lu\n", NameType
, ReferenceLen
);
40 ok(Size
== ReferenceLen
, "[%d] Size is %lu, expected %lu\n", NameType
, Size
, ReferenceLen
);
42 /* NULL buffer, NULL size */
44 Ret
= GetComputerNameExW(NameType
, NULL
, NULL
);
45 Error
= GetLastError();
46 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
47 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
48 EndSeh(STATUS_SUCCESS
);
50 Ret
= GetComputerNameExA(NameType
, NULL
, NULL
);
51 Error
= GetLastError();
52 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
53 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
54 EndSeh(STATUS_SUCCESS
);
56 /* NULL buffer, nonzero size */
58 Ret
= GetComputerNameExW(NameType
, NULL
, &Size
);
59 Error
= GetLastError();
60 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
61 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
62 ok(Size
== 0x55555555, "[%d] Got Size %lu\n", NameType
, Size
);
65 Ret
= GetComputerNameExA(NameType
, NULL
, &Size
);
66 Error
= GetLastError();
67 ok(Ret
== FALSE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
68 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExA returned error %lu\n", NameType
, Error
);
69 ok(Size
== 0x55555555, "[%d] Got Size %lu\n", NameType
, Size
);
71 /* non-NULL buffer, NULL size */
72 RtlFillMemory(BufferW
, sizeof(BufferW
), 0x55);
73 Ret
= GetComputerNameExW(NameType
, BufferW
, NULL
);
74 Error
= GetLastError();
75 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
76 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
77 ok(BufferW
[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType
, BufferW
[0]);
79 RtlFillMemory(BufferA
, sizeof(BufferA
), 0x55);
80 Ret
= GetComputerNameExA(NameType
, BufferA
, NULL
);
81 Error
= GetLastError();
82 ok(Ret
== FALSE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
83 ok(Error
== ERROR_INVALID_PARAMETER
, "[%d] GetComputerNameExA returned error %lu\n", NameType
, Error
);
84 ok(BufferA
[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType
, BufferA
[0]);
86 /* NULL buffer, zero size */
88 Ret
= GetComputerNameExW(NameType
, NULL
, &Size
);
89 Error
= GetLastError();
90 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
91 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
92 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
95 Ret
= GetComputerNameExA(NameType
, NULL
, &Size
);
96 Error
= GetLastError();
97 ok(Ret
== FALSE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
98 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExA returned error %lu\n", NameType
, Error
);
99 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
101 /* non-NULL buffer, zero size */
102 RtlFillMemory(BufferW
, sizeof(BufferW
), 0x55);
104 Ret
= GetComputerNameExW(NameType
, BufferW
, &Size
);
105 Error
= GetLastError();
106 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
107 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
108 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
109 ok(BufferW
[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType
, BufferW
[0]);
111 RtlFillMemory(BufferA
, sizeof(BufferA
), 0x55);
113 Ret
= GetComputerNameExA(NameType
, BufferA
, &Size
);
114 Error
= GetLastError();
115 ok(Ret
== FALSE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
116 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExA returned error %lu\n", NameType
, Error
);
117 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
118 ok(BufferA
[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType
, BufferA
[0]);
120 /* non-NULL buffer, too small size */
121 RtlFillMemory(BufferW
, sizeof(BufferW
), 0x55);
123 Ret
= GetComputerNameExW(NameType
, BufferW
, &Size
);
124 Error
= GetLastError();
125 ok(Ret
== FALSE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
126 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExW returned error %lu\n", NameType
, Error
);
127 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
128 if (NameType
!= ComputerNameNetBIOS
&& NameType
!= ComputerNamePhysicalNetBIOS
)
130 if (ReferenceLen
== 0)
132 ok(BufferW
[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n",
133 NameType
, BufferW
[0]);
137 ok(BufferW
[0] == 0, "[%d] BufferW[0] = 0x%x\n",
138 NameType
, BufferW
[0]);
141 ok(BufferW
[1] == 0x5555, "[%d] BufferW[1] = 0x%x\n", NameType
, BufferW
[1]);
143 RtlFillMemory(BufferA
, sizeof(BufferA
), 0x55);
145 Ret
= GetComputerNameExA(NameType
, BufferA
, &Size
);
146 Error
= GetLastError();
147 ok(Ret
== FALSE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
148 ok(Error
== ERROR_MORE_DATA
, "[%d] GetComputerNameExA returned error %lu\n", NameType
, Error
);
149 ok(Size
== ReferenceLen
+ 1, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
150 ok(BufferA
[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType
, BufferA
[0]);
152 /* non-NULL buffer, exact size */
153 RtlFillMemory(BufferW
, sizeof(BufferW
), 0x55);
154 Size
= ReferenceLen
+ 1;
155 Ret
= GetComputerNameExW(NameType
, BufferW
, &Size
);
156 ok(Ret
== TRUE
, "[%d] GetComputerNameExW returned %d\n", NameType
, Ret
);
157 ok(Size
== ReferenceLen
, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
158 ok(BufferW
[ReferenceLen
] == 0, "[%d] BufferW[ReferenceLen] = 0x%x\n", NameType
, BufferW
[ReferenceLen
]);
159 ok(BufferW
[ReferenceLen
+ 1] == 0x5555, "[%d] BufferW[ReferenceLen + 1] = 0x%x\n", NameType
, BufferW
[ReferenceLen
+ 1]);
160 ok(!wcscmp(BufferW
, Reference
), "[%d] '%ls' != '%ls'\n", NameType
, BufferW
, Reference
);
162 RtlFillMemory(BufferA
, sizeof(BufferA
), 0x55);
163 Size
= ReferenceLen
+ 1;
164 Ret
= GetComputerNameExA(NameType
, BufferA
, &Size
);
165 ok(Ret
== TRUE
, "[%d] GetComputerNameExA returned %d\n", NameType
, Ret
);
166 ok(Size
== ReferenceLen
, "[%d] Got Size %lu, expected %lu\n", NameType
, Size
, ReferenceLen
+ 1);
167 ok(BufferA
[ReferenceLen
] == 0, "[%d] BufferA[ReferenceLen] = 0x%x\n", NameType
, BufferA
[ReferenceLen
]);
168 ok(BufferA
[ReferenceLen
+ 1] == 0x55, "[%d] BufferA[ReferenceLen + 1] = 0x%x\n", NameType
, BufferA
[ReferenceLen
+ 1]);
169 for (i
= 0; i
< ReferenceLen
; i
++)
171 if (BufferA
[i
] != Reference
[i
])
173 ok(0, "[%d] BufferA[%lu] = 0x%x, expected 0x%x\n", NameType
, i
, BufferA
[i
], Reference
[i
]);
180 ReadRegistryValue(PCHAR ValueName
, PCHAR Value
)
187 /* Open the database path key */
188 ErrorCode
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
189 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
193 if (ErrorCode
== NO_ERROR
)
195 /* Read the actual path */
196 ErrorCode
= RegQueryValueExA(ParametersKey
,
204 /* Read the actual path */
205 ErrorCode
= RegQueryValueExA(ParametersKey
,
214 RegCloseKey(ParametersKey
);
221 ReadRegistryComputerNameValue(PCHAR ValueName
, PCHAR Value
)
228 /* Open the database path key */
229 ErrorCode
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
230 "System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName",
234 if (ErrorCode
== NO_ERROR
)
236 /* Read the actual path */
237 ErrorCode
= RegQueryValueExA(ParametersKey
,
245 /* Read the actual path */
246 ErrorCode
= RegQueryValueExA(ParametersKey
,
255 RegCloseKey(ParametersKey
);
262 WriteRegistryValue(PCHAR ValueName
, PCHAR Value
)
267 /* Open the database path key */
268 ErrorCode
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
269 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
273 if (ErrorCode
== NO_ERROR
)
275 /* Read the actual path */
276 ErrorCode
= RegSetValueExA(ParametersKey
,
281 lstrlenA(Value
) + 1);
284 RegCloseKey(ParametersKey
);
291 DeleteRegistryValue(PCHAR ValueName
)
296 /* Open the database path key */
297 ErrorCode
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
298 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
302 if (ErrorCode
== NO_ERROR
)
304 /* Read the actual path */
305 ErrorCode
= RegDeleteValueA(ParametersKey
, ValueName
);
308 RegCloseKey(ParametersKey
);
313 /* If this test crashes it might end up with wrong host and/or domain name in registry! */
318 CHAR OrigNetBIOS
[128];
319 CHAR OrigHostname
[128];
320 CHAR OrigDomainName
[128];
321 CHAR OrigDhcpHostname
[128];
322 CHAR OrigDhcpDomainName
[128];
323 BOOL OrigNetBIOSExists
;
324 BOOL OrigHostnameExists
;
325 BOOL OrigDomainNameExists
;
326 BOOL OrigDhcpHostnameExists
;
327 BOOL OrigDhcpDomainNameExists
;
328 CHAR ComputerName
[128];
329 DWORD ComputerNameSize
= 0;
332 memset(OrigNetBIOS
, 0, sizeof(OrigNetBIOS
));
333 memset(OrigHostname
, 0, sizeof(OrigHostname
));
334 memset(OrigDomainName
, 0, sizeof(OrigDomainName
));
335 memset(OrigDhcpHostname
, 0, sizeof(OrigDhcpHostname
));
336 memset(OrigDhcpDomainName
, 0, sizeof(OrigDhcpDomainName
));
337 /* read current registry values */
338 ErrorCode
= ReadRegistryComputerNameValue("ComputerName", OrigNetBIOS
);
339 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to read registry key ComputerName %d\n", ErrorCode
);
340 OrigNetBIOSExists
= ErrorCode
== STATUS_SUCCESS
;
341 ErrorCode
= ReadRegistryValue("Hostname", OrigHostname
);
342 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to read registry key Hostname %d\n", ErrorCode
);
343 OrigHostnameExists
= ErrorCode
== STATUS_SUCCESS
;
344 ErrorCode
= ReadRegistryValue("Domain", OrigDomainName
);
345 ok(ErrorCode
== ERROR_SUCCESS
|| ErrorCode
== ERROR_FILE_NOT_FOUND
, "Failed to read registry key DomainName %d\n", ErrorCode
);
346 OrigDomainNameExists
= ErrorCode
== STATUS_SUCCESS
;
347 ErrorCode
= ReadRegistryValue("DhcpHostname", OrigDhcpHostname
);
348 ok(ErrorCode
== ERROR_SUCCESS
|| ErrorCode
== ERROR_FILE_NOT_FOUND
, "Failed to read registry key DhcpHostname %d\n", ErrorCode
);
349 OrigDhcpHostnameExists
= ErrorCode
== STATUS_SUCCESS
;
350 ErrorCode
= ReadRegistryValue("DhcpDomain", OrigDhcpDomainName
);
351 ok(ErrorCode
== ERROR_SUCCESS
|| ErrorCode
== ERROR_FILE_NOT_FOUND
, "Failed to read registry key DhcpDomainName %d\n", ErrorCode
);
352 OrigDhcpDomainNameExists
= ErrorCode
== STATUS_SUCCESS
;
354 trace("Starting values:\n");
355 trace("NetBIOS: %s, exists %s\n", OrigNetBIOS
, OrigNetBIOSExists
? "yes" : "no");
356 trace("Hostname: %s, exists %s\n", OrigHostname
, OrigHostnameExists
? "yes" : "no");
357 trace("Domain: %s, exists %s\n", OrigDomainName
, OrigDomainNameExists
? "yes" : "no");
358 trace("DhcpHostname: %s, exists %s\n", OrigDhcpHostnameExists
? OrigDhcpHostname
: "", OrigDhcpHostnameExists
? "yes" : "no");
359 trace("DhcpDomain: %s, exists %s\n", OrigDhcpDomainNameExists
? OrigDhcpDomainName
: "", OrigDhcpDomainNameExists
? "yes" : "no");
361 /* ComputerNamePhysicalNetBIOS */
362 ComputerNameSize
= 0;
364 GetComputerNameExA(ComputerNamePhysicalNetBIOS
, ComputerName
, &ComputerNameSize
);
365 if (ComputerNameSize
)
366 ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
368 memset(ComputerName
, 0, sizeof(ComputerName
));
369 ok(strcmp(ComputerName
, OrigNetBIOS
) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigNetBIOS
);
370 EndSeh(STATUS_SUCCESS
);
372 /* ComputerNamePhysicalDnsHostname */
373 ComputerNameSize
= 0;
375 GetComputerNameExA(ComputerNamePhysicalDnsHostname
, ComputerName
, &ComputerNameSize
);
376 if (ComputerNameSize
)
377 ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
379 memset(ComputerName
, 0, sizeof(ComputerName
));
380 ok(strcmp(ComputerName
, OrigHostname
) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigHostname
);
381 EndSeh(STATUS_SUCCESS
);
383 /* ComputerNamePhysicalDnsDomain */
384 ComputerNameSize
= 0;
386 GetComputerNameExA(ComputerNamePhysicalDnsDomain
, ComputerName
, &ComputerNameSize
);
387 if (ComputerNameSize
)
388 ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
390 memset(ComputerName
, 0, sizeof(ComputerName
));
391 ok(strcmp(ComputerName
, OrigDomainName
) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigDomainName
);
392 EndSeh(STATUS_SUCCESS
);
393 ComputerNameSize
= 0;
395 /* ComputerNameNetBIOS */
397 GetComputerNameExA(ComputerNameNetBIOS
, ComputerName
, &ComputerNameSize
);
398 if (ComputerNameSize
)
399 ok(GetComputerNameExA(ComputerNameNetBIOS
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
401 memset(ComputerName
, 0, sizeof(ComputerName
));
402 ok(strcmp(ComputerName
, OrigNetBIOS
) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigNetBIOS
);
403 EndSeh(STATUS_SUCCESS
);
405 /* ComputerNameDnsHostname */
406 ComputerNameSize
= 0;
408 GetComputerNameExA(ComputerNameDnsHostname
, ComputerName
, &ComputerNameSize
);
409 if (ComputerNameSize
)
410 ok(GetComputerNameExA(ComputerNameDnsHostname
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
412 memset(ComputerName
, 0, sizeof(ComputerName
));
413 ok(strcmp(ComputerName
, OrigHostname
) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigHostname
);
414 EndSeh(STATUS_SUCCESS
);
416 /* ComputerNameDnsDomain */
417 ComputerNameSize
= 0;
419 GetComputerNameExA(ComputerNameDnsDomain
, ComputerName
, &ComputerNameSize
);
420 if (ComputerNameSize
)
421 ok(GetComputerNameExA(ComputerNameDnsDomain
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
423 memset(ComputerName
, 0, sizeof(ComputerName
));
424 ok(strcmp(ComputerName
, OrigDomainName
) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigDomainName
);
425 EndSeh(STATUS_SUCCESS
);
427 ErrorCode
= WriteRegistryValue("DhcpHostname", "testdhcproshost");
428 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to write registry key DhcpHostname %d\n", ErrorCode
);
429 ErrorCode
= WriteRegistryValue("DhcpDomain", "testrosdomain");
430 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to write registry key DhcpDomainName %d\n", ErrorCode
);
432 /* ComputerNamePhysicalNetBIOS */
433 ComputerNameSize
= 0;
435 GetComputerNameExA(ComputerNamePhysicalNetBIOS
, ComputerName
, &ComputerNameSize
);
436 if (ComputerNameSize
)
437 ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
439 memset(ComputerName
, 0, sizeof(ComputerName
));
440 ok(strcmp(ComputerName
, OrigNetBIOS
) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigNetBIOS
);
441 EndSeh(STATUS_SUCCESS
);
443 /* ComputerNamePhysicalDnsHostname */
444 ComputerNameSize
= 0;
446 GetComputerNameExA(ComputerNamePhysicalDnsHostname
, ComputerName
, &ComputerNameSize
);
447 if (ComputerNameSize
)
448 ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
450 memset(ComputerName
, 0, sizeof(ComputerName
));
451 ok(strcmp(ComputerName
, OrigHostname
) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigHostname
);
452 EndSeh(STATUS_SUCCESS
);
454 /* ComputerNamePhysicalDnsDomain */
455 ComputerNameSize
= 0;
457 GetComputerNameExA(ComputerNamePhysicalDnsDomain
, ComputerName
, &ComputerNameSize
);
458 if (ComputerNameSize
)
459 ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
461 memset(ComputerName
, 0, sizeof(ComputerName
));
462 ok(strcmp(ComputerName
, OrigDomainName
) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigDomainName
);
463 EndSeh(STATUS_SUCCESS
);
464 ComputerNameSize
= 0;
466 /* ComputerNameNetBIOS */
468 GetComputerNameExA(ComputerNameNetBIOS
, ComputerName
, &ComputerNameSize
);
469 if (ComputerNameSize
)
470 ok(GetComputerNameExA(ComputerNameNetBIOS
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
472 memset(ComputerName
, 0, sizeof(ComputerName
));
473 ok(strcmp(ComputerName
, OrigNetBIOS
) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigNetBIOS
);
474 EndSeh(STATUS_SUCCESS
);
476 /* ComputerNameDnsHostname */
477 ComputerNameSize
= 0;
479 GetComputerNameExA(ComputerNameDnsHostname
, ComputerName
, &ComputerNameSize
);
480 if (ComputerNameSize
)
481 ok(GetComputerNameExA(ComputerNameDnsHostname
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
483 memset(ComputerName
, 0, sizeof(ComputerName
));
484 ok(strcmp(ComputerName
, OrigHostname
) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigHostname
);
485 EndSeh(STATUS_SUCCESS
);
487 /* ComputerNameDnsDomain */
488 ComputerNameSize
= 0;
490 GetComputerNameExA(ComputerNameDnsDomain
, ComputerName
, &ComputerNameSize
);
491 if (ComputerNameSize
)
492 ok(GetComputerNameExA(ComputerNameDnsDomain
, ComputerName
, &ComputerNameSize
), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
494 memset(ComputerName
, 0, sizeof(ComputerName
));
495 ok(strcmp(ComputerName
, OrigDomainName
) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName
, OrigDomainName
);
496 EndSeh(STATUS_SUCCESS
);
498 /* restore registry values */
499 if (OrigDhcpHostnameExists
)
500 ErrorCode
= WriteRegistryValue("DhcpHostname", OrigDhcpHostname
);
502 ErrorCode
= DeleteRegistryValue("DhcpHostname");
503 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to restore registry key DhcpHostname %d\n", ErrorCode
);
504 if (OrigDhcpDomainNameExists
)
505 ErrorCode
= WriteRegistryValue("DhcpDomain", OrigDhcpDomainName
);
507 ErrorCode
= DeleteRegistryValue("DhcpDomain");
508 ok(ErrorCode
== ERROR_SUCCESS
, "Failed to restore registry key DhcpDomainName %d\n", ErrorCode
);
511 START_TEST(GetComputerNameEx
)
513 TestGetComputerNameEx(ComputerNameNetBIOS
);
514 TestGetComputerNameEx(ComputerNameDnsHostname
);
515 TestGetComputerNameEx(ComputerNameDnsDomain
);
516 //TestGetComputerNameEx(ComputerNameDnsFullyQualified);
517 TestGetComputerNameEx(ComputerNamePhysicalNetBIOS
);
518 TestGetComputerNameEx(ComputerNamePhysicalDnsHostname
);
519 TestGetComputerNameEx(ComputerNamePhysicalDnsDomain
);
520 //TestGetComputerNameEx(ComputerNamePhysicalDnsFullyQualified);