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 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 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); 49 StartSeh() 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); 55 56 /* NULL buffer, nonzero size */ 57 Size = 0x55555555; 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); 63 64 Size = 0x55555555; 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); 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; 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); 93 94 Size = 0; 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); 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 180 ReadRegistryValue(PCHAR ValueName, PCHAR Value) 181 { 182 INT ErrorCode; 183 HKEY ParametersKey; 184 DWORD RegType; 185 DWORD RegSize = 0; 186 187 /* Open the database path key */ 188 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 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 221 ReadRegistryComputerNameValue(PCHAR ValueName, PCHAR Value) 222 { 223 INT ErrorCode; 224 HKEY ParametersKey; 225 DWORD RegType; 226 DWORD RegSize = 0; 227 228 /* Open the database path key */ 229 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 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 262 WriteRegistryValue(PCHAR ValueName, PCHAR Value) 263 { 264 INT ErrorCode; 265 HKEY ParametersKey; 266 267 /* Open the database path key */ 268 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 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 lstrlenA(Value) + 1); 282 283 /* Close the key */ 284 RegCloseKey(ParametersKey); 285 } 286 return ErrorCode; 287 } 288 289 static 290 LSTATUS 291 DeleteRegistryValue(PCHAR ValueName) 292 { 293 INT ErrorCode; 294 HKEY ParametersKey; 295 296 /* Open the database path key */ 297 ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 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 316 TestReturnValues() 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); 370 EndSeh(STATUS_SUCCESS); 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); 381 EndSeh(STATUS_SUCCESS); 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); 392 EndSeh(STATUS_SUCCESS); 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); 403 EndSeh(STATUS_SUCCESS); 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); 414 EndSeh(STATUS_SUCCESS); 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); 425 EndSeh(STATUS_SUCCESS); 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); 441 EndSeh(STATUS_SUCCESS); 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); 452 EndSeh(STATUS_SUCCESS); 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); 463 EndSeh(STATUS_SUCCESS); 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); 474 EndSeh(STATUS_SUCCESS); 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); 485 EndSeh(STATUS_SUCCESS); 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); 496 EndSeh(STATUS_SUCCESS); 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); 521 TestReturnValues(); 522 } 523