ReactOS  0.4.14-dev-358-gbef841c
GetComputerNameEx.c
Go to the documentation of this file.
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
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 = wcslen(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()
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);
49  StartSeh()
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);
55 
56  /* NULL buffer, nonzero size */
57  Size = 0x55555555;
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);
63 
64  Size = 0x55555555;
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);
70 
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]);
78 
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]);
85 
86  /* NULL buffer, zero size */
87  Size = 0;
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);
93 
94  Size = 0;
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);
100 
101  /* non-NULL buffer, zero size */
102  RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
103  Size = 0;
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]);
110 
111  RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
112  Size = 0;
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]);
119 
120  /* non-NULL buffer, too small size */
121  RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
122  Size = ReferenceLen;
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)
129  {
130  if (ReferenceLen == 0)
131  {
132  ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n",
133  NameType, BufferW[0]);
134  }
135  else
136  {
137  ok(BufferW[0] == 0, "[%d] BufferW[0] = 0x%x\n",
138  NameType, BufferW[0]);
139  }
140  }
141  ok(BufferW[1] == 0x5555, "[%d] BufferW[1] = 0x%x\n", NameType, BufferW[1]);
142 
143  RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
144  Size = ReferenceLen;
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]);
151 
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);
161 
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++)
170  {
171  if (BufferA[i] != Reference[i])
172  {
173  ok(0, "[%d] BufferA[%lu] = 0x%x, expected 0x%x\n", NameType, i, BufferA[i], Reference[i]);
174  }
175  }
176 }
177 
178 static
179 LSTATUS
181 {
182  INT ErrorCode;
183  HKEY ParametersKey;
184  DWORD RegType;
185  DWORD RegSize = 0;
186 
187  /* Open the database path key */
189  "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
190  0,
191  KEY_READ,
192  &ParametersKey);
193  if (ErrorCode == NO_ERROR)
194  {
195  /* Read the actual path */
196  ErrorCode = RegQueryValueExA(ParametersKey,
197  ValueName,
198  NULL,
199  &RegType,
200  NULL,
201  &RegSize);
202  if (RegSize)
203  {
204  /* Read the actual path */
205  ErrorCode = RegQueryValueExA(ParametersKey,
206  ValueName,
207  NULL,
208  &RegType,
209  (LPBYTE)Value,
210  &RegSize);
211  }
212 
213  /* Close the key */
214  RegCloseKey(ParametersKey);
215  }
216  return ErrorCode;
217 }
218 
219 static
220 LSTATUS
222 {
223  INT ErrorCode;
224  HKEY ParametersKey;
225  DWORD RegType;
226  DWORD RegSize = 0;
227 
228  /* Open the database path key */
230  "System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName",
231  0,
232  KEY_READ,
233  &ParametersKey);
234  if (ErrorCode == NO_ERROR)
235  {
236  /* Read the actual path */
237  ErrorCode = RegQueryValueExA(ParametersKey,
238  ValueName,
239  NULL,
240  &RegType,
241  NULL,
242  &RegSize);
243  if (RegSize)
244  {
245  /* Read the actual path */
246  ErrorCode = RegQueryValueExA(ParametersKey,
247  ValueName,
248  NULL,
249  &RegType,
250  (LPBYTE)Value,
251  &RegSize);
252  }
253 
254  /* Close the key */
255  RegCloseKey(ParametersKey);
256  }
257  return ErrorCode;
258 }
259 
260 static
261 LSTATUS
263 {
264  INT ErrorCode;
265  HKEY ParametersKey;
266 
267  /* Open the database path key */
269  "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
270  0,
271  KEY_WRITE,
272  &ParametersKey);
273  if (ErrorCode == NO_ERROR)
274  {
275  /* Read the actual path */
276  ErrorCode = RegSetValueExA(ParametersKey,
277  ValueName,
278  0,
279  REG_SZ,
280  (LPBYTE)Value,
281  strlen(Value) + 1);
282 
283  /* Close the key */
284  RegCloseKey(ParametersKey);
285  }
286  return ErrorCode;
287 }
288 
289 static
290 LSTATUS
292 {
293  INT ErrorCode;
294  HKEY ParametersKey;
295 
296  /* Open the database path key */
298  "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
299  0,
300  KEY_WRITE,
301  &ParametersKey);
302  if (ErrorCode == NO_ERROR)
303  {
304  /* Read the actual path */
305  ErrorCode = RegDeleteValueA(ParametersKey, ValueName);
306 
307  /* Close the key */
308  RegCloseKey(ParametersKey);
309  }
310  return ErrorCode;
311 }
312 
313 /* If this test crashes it might end up with wrong host and/or domain name in registry! */
314 static
315 VOID
317 {
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;
330  INT ErrorCode;
331 
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;
353 
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");
360 
361  /* ComputerNamePhysicalNetBIOS */
362  ComputerNameSize = 0;
363  StartSeh()
364  GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
365  if (ComputerNameSize)
366  ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
367  else
368  memset(ComputerName, 0, sizeof(ComputerName));
369  ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
371 
372  /* ComputerNamePhysicalDnsHostname */
373  ComputerNameSize = 0;
374  StartSeh()
375  GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
376  if (ComputerNameSize)
377  ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
378  else
379  memset(ComputerName, 0, sizeof(ComputerName));
380  ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
382 
383  /* ComputerNamePhysicalDnsDomain */
384  ComputerNameSize = 0;
385  StartSeh()
386  GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
387  if (ComputerNameSize)
388  ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
389  else
390  memset(ComputerName, 0, sizeof(ComputerName));
391  ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
393  ComputerNameSize = 0;
394 
395  /* ComputerNameNetBIOS */
396  StartSeh()
397  GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
398  if (ComputerNameSize)
399  ok(GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
400  else
401  memset(ComputerName, 0, sizeof(ComputerName));
402  ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
404 
405  /* ComputerNameDnsHostname */
406  ComputerNameSize = 0;
407  StartSeh()
408  GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
409  if (ComputerNameSize)
410  ok(GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
411  else
412  memset(ComputerName, 0, sizeof(ComputerName));
413  ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
415 
416  /* ComputerNameDnsDomain */
417  ComputerNameSize = 0;
418  StartSeh()
419  GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
420  if (ComputerNameSize)
421  ok(GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
422  else
423  memset(ComputerName, 0, sizeof(ComputerName));
424  ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
426 
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);
431 
432  /* ComputerNamePhysicalNetBIOS */
433  ComputerNameSize = 0;
434  StartSeh()
435  GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
436  if (ComputerNameSize)
437  ok(GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
438  else
439  memset(ComputerName, 0, sizeof(ComputerName));
440  ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
442 
443  /* ComputerNamePhysicalDnsHostname */
444  ComputerNameSize = 0;
445  StartSeh()
446  GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
447  if (ComputerNameSize)
448  ok(GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
449  else
450  memset(ComputerName, 0, sizeof(ComputerName));
451  ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
453 
454  /* ComputerNamePhysicalDnsDomain */
455  ComputerNameSize = 0;
456  StartSeh()
457  GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
458  if (ComputerNameSize)
459  ok(GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
460  else
461  memset(ComputerName, 0, sizeof(ComputerName));
462  ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
464  ComputerNameSize = 0;
465 
466  /* ComputerNameNetBIOS */
467  StartSeh()
468  GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
469  if (ComputerNameSize)
470  ok(GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
471  else
472  memset(ComputerName, 0, sizeof(ComputerName));
473  ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
475 
476  /* ComputerNameDnsHostname */
477  ComputerNameSize = 0;
478  StartSeh()
479  GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
480  if (ComputerNameSize)
481  ok(GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
482  else
483  memset(ComputerName, 0, sizeof(ComputerName));
484  ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
486 
487  /* ComputerNameDnsDomain */
488  ComputerNameSize = 0;
489  StartSeh()
490  GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
491  if (ComputerNameSize)
492  ok(GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize), "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
493  else
494  memset(ComputerName, 0, sizeof(ComputerName));
495  ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
497 
498  /* restore registry values */
499  if (OrigDhcpHostnameExists)
500  ErrorCode = WriteRegistryValue("DhcpHostname", OrigDhcpHostname);
501  else
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);
506  else
507  ErrorCode = DeleteRegistryValue("DhcpDomain");
508  ok(ErrorCode == ERROR_SUCCESS, "Failed to restore registry key DhcpDomainName %d\n", ErrorCode);
509 }
510 
511 START_TEST(GetComputerNameEx)
512 {
513  TestGetComputerNameEx(ComputerNameNetBIOS);
514  TestGetComputerNameEx(ComputerNameDnsHostname);
515  TestGetComputerNameEx(ComputerNameDnsDomain);
516  //TestGetComputerNameEx(ComputerNameDnsFullyQualified);
517  TestGetComputerNameEx(ComputerNamePhysicalNetBIOS);
518  TestGetComputerNameEx(ComputerNamePhysicalDnsHostname);
519  TestGetComputerNameEx(ComputerNamePhysicalDnsDomain);
520  //TestGetComputerNameEx(ComputerNamePhysicalDnsFullyQualified);
522 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
signed char * PCHAR
Definition: retypes.h:7
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KEY_READ
Definition: nt_native.h:1023
static VOID TestGetComputerNameEx(_In_ COMPUTER_NAME_FORMAT NameType)
char CHAR
Definition: xmlstorage.h:175
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT, LPSTR, LPDWORD)
Definition: compname.c:370
#define NO_ERROR
Definition: dderror.h:5
#define StartSeh()
Definition: _sntprintf.h:16
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:213
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
static LSTATUS ReadRegistryValue(PCHAR ValueName, PCHAR Value)
smooth NULL
Definition: ftsmooth.c:416
static LSTATUS DeleteRegistryValue(PCHAR ValueName)
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_WRITE
Definition: nt_native.h:1031
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
static VOID TestReturnValues()
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define ERROR_MORE_DATA
Definition: dderror.h:13
static LSTATUS WriteRegistryValue(PCHAR ValueName, PCHAR Value)
#define _In_
Definition: no_sal2.h:204
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define ok(value,...)
Definition: atltest.h:57
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2319
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
START_TEST(GetComputerNameEx)
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4812
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static LSTATUS ReadRegistryComputerNameValue(PCHAR ValueName, PCHAR Value)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define REG_SZ
Definition: layer.c:22