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