2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for the SetComputerNameExW API
5 * COPYRIGHT: Victor Martinez Calvo (victor.martinez@reactos.org)
6 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
10 #define WIN32_NO_STATUS
12 #include <ndk/rtltypes.h>
15 #define _WIN32_WINNT 0x0600
18 static HKEY
OpenHostNameKey(void)
21 RegHostNameKey
[] = L
"System\\CurrentControlSet\\Services\\Tcpip\\Parameters";
23 LONG Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, RegHostNameKey
, 0, KEY_ALL_ACCESS
, &hKey
);
29 static HKEY
OpenComputerNameKey(void)
32 RegComputerNameKey
[] = L
"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
34 LONG Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, RegComputerNameKey
, 0, KEY_ALL_ACCESS
, &hKey
);
40 START_TEST(SetComputerNameExW
)
46 WCHAR szHostNameOld
[MAX_PATH
], szHostNameNew
[MAX_PATH
];
47 WCHAR szComputerNameOld
[MAX_PATH
], szComputerNameNew
[MAX_PATH
];
48 static const WCHAR szNewName
[] = L
"SRVROSTEST";
51 hKeyHN
= OpenHostNameKey();
52 hKeyCN
= OpenComputerNameKey();
53 if (!hKeyHN
|| !hKeyCN
)
59 skip("Unable to open keys (%p, %p).\n", hKeyHN
, hKeyCN
);
63 /* Get Old Hostname */
64 szHostNameOld
[0] = UNICODE_NULL
;
65 cbData
= sizeof(szHostNameOld
);
66 Error
= RegQueryValueExW(hKeyHN
, L
"Hostname", NULL
, NULL
, (LPBYTE
)szHostNameOld
, &cbData
);
67 ok_long(Error
, ERROR_SUCCESS
);
68 ok(szHostNameOld
[0], "szHostNameOld is %S", szHostNameOld
);
70 /* Get Old Computer Name */
71 szComputerNameOld
[0] = UNICODE_NULL
;
72 cbData
= sizeof(szComputerNameOld
);
73 Error
= RegQueryValueExW(hKeyCN
, L
"ComputerName", NULL
, NULL
, (LPBYTE
)szComputerNameOld
, &cbData
);
74 ok_long(Error
, ERROR_SUCCESS
);
75 ok(szComputerNameOld
[0], "szHostNameOld is %S", szComputerNameOld
);
77 /* Change the value */
78 ret
= SetComputerNameExW(ComputerNamePhysicalDnsHostname
, szNewName
);
81 /* Get New Hostname */
82 szHostNameNew
[0] = UNICODE_NULL
;
83 cbData
= sizeof(szHostNameNew
);
84 Error
= RegQueryValueExW(hKeyHN
, L
"Hostname", NULL
, NULL
, (LPBYTE
)szHostNameNew
, &cbData
);
85 ok_long(Error
, ERROR_SUCCESS
);
86 ok(szHostNameNew
[0], "szHostNameNew was empty.\n");
87 ok(lstrcmpW(szHostNameNew
, szHostNameOld
) == 0,
88 "szHostNameNew '%S' should be szHostNameOld '%S'.\n", szHostNameNew
, szHostNameOld
);
90 /* Get New Computer Name */
91 szComputerNameNew
[0] = UNICODE_NULL
;
92 cbData
= sizeof(szComputerNameNew
);
93 Error
= RegQueryValueExW(hKeyCN
, L
"ComputerName", NULL
, NULL
, (LPBYTE
)szComputerNameNew
, &cbData
);
94 ok_long(Error
, ERROR_SUCCESS
);
95 ok(szComputerNameNew
[0], "szComputerNameNew was empty.\n");
96 ok(lstrcmpW(szComputerNameNew
, szNewName
) == 0,
97 "szComputerNameNew '%S' should be szNewName '%S'.\n", szComputerNameNew
, szNewName
);
99 /* Restore the registry values */
100 cbData
= (lstrlenW(szHostNameOld
) + 1) * sizeof(WCHAR
);
101 Error
= RegSetValueExW(hKeyHN
, L
"Hostname", 0, REG_SZ
, (LPBYTE
)szHostNameOld
, cbData
);
102 ok_long(Error
, ERROR_SUCCESS
);
104 cbData
= (lstrlenW(szComputerNameOld
) + 1) * sizeof(WCHAR
);
105 Error
= RegSetValueExW(hKeyCN
, L
"ComputerName", 0, REG_SZ
, (LPBYTE
)szComputerNameOld
, cbData
);
106 ok_long(Error
, ERROR_SUCCESS
);
109 Error
= RegCloseKey(hKeyHN
);
110 ok_long(Error
, ERROR_SUCCESS
);
111 Error
= RegCloseKey(hKeyCN
);
112 ok_long(Error
, ERROR_SUCCESS
);