https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8aeb6a920ac68474a5118b778e7162f53ab17d4e

commit 8aeb6a920ac68474a5118b778e7162f53ab17d4e
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Sat May 25 21:15:24 2019 +0900
Commit:     GitHub <[email protected]>
CommitDate: Sat May 25 21:15:24 2019 +0900

    [KERNEL32_APITEST] Add SetComputerNameExW testcase (#1578)
    
    Add testcase of kernel32!SetComputerNameExW function. ROSTESTS-227
---
 modules/rostests/apitests/kernel32/CMakeLists.txt  |   1 +
 .../apitests/kernel32/SetComputerNameExW.c         | 113 +++++++++++++++++++++
 modules/rostests/apitests/kernel32/testlist.c      |   3 +-
 3 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/modules/rostests/apitests/kernel32/CMakeLists.txt 
b/modules/rostests/apitests/kernel32/CMakeLists.txt
index 1b8c8314c86..da3ea911884 100644
--- a/modules/rostests/apitests/kernel32/CMakeLists.txt
+++ b/modules/rostests/apitests/kernel32/CMakeLists.txt
@@ -27,6 +27,7 @@ list(APPEND SOURCE
     Mailslot.c
     MultiByteToWideChar.c
     PrivMoveFileIdentityW.c
+    SetComputerNameExW.c
     SetConsoleWindowInfo.c
     SetCurrentDirectory.c
     SetUnhandledExceptionFilter.c
diff --git a/modules/rostests/apitests/kernel32/SetComputerNameExW.c 
b/modules/rostests/apitests/kernel32/SetComputerNameExW.c
new file mode 100644
index 00000000000..658e74e8a44
--- /dev/null
+++ b/modules/rostests/apitests/kernel32/SetComputerNameExW.c
@@ -0,0 +1,113 @@
+/*
+ * PROJECT:     ReactOS api tests
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     Tests for the SetComputerNameExW API
+ * COPYRIGHT:   Victor Martinez Calvo ([email protected])
+ *              Katayama Hirofumi MZ ([email protected])
+ */
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <stdio.h>
+#include <ndk/rtltypes.h>
+
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0600
+#include <winreg.h>
+
+static HKEY OpenHostNameKey(void)
+{
+    static const WCHAR
+        RegHostNameKey[] = 
L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters";
+    HKEY hKey = NULL;
+    LONG Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegHostNameKey, 0, 
KEY_ALL_ACCESS, &hKey);
+    if (!Error)
+        return hKey;
+    return NULL;
+}
+
+static HKEY OpenComputerNameKey(void)
+{
+    static const WCHAR
+        RegComputerNameKey[] = 
L"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
+    HKEY hKey = NULL;
+    LONG Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegComputerNameKey, 0, 
KEY_ALL_ACCESS, &hKey);
+    if (!Error)
+        return hKey;
+    return NULL;
+}
+
+START_TEST(SetComputerNameExW)
+{
+    LONG Error;
+    BOOL ret;
+    HKEY hKeyHN, hKeyCN;
+    DWORD cbData;
+    WCHAR szHostNameOld[MAX_PATH], szHostNameNew[MAX_PATH];
+    WCHAR szComputerNameOld[MAX_PATH], szComputerNameNew[MAX_PATH];
+    static const WCHAR szNewName[] = L"SRVROSTEST";
+
+    /* Open keys */
+    hKeyHN = OpenHostNameKey();
+    hKeyCN = OpenComputerNameKey();
+    if (!hKeyHN || !hKeyCN)
+    {
+        if (hKeyHN)
+            RegCloseKey(hKeyHN);
+        if (hKeyCN)
+            RegCloseKey(hKeyCN);
+        skip("Unable to open keys (%p, %p).\n", hKeyHN, hKeyCN);
+        return;
+    }
+
+    /* Get Old Hostname */
+    szHostNameOld[0] = UNICODE_NULL;
+    cbData = sizeof(szHostNameOld);
+    Error = RegQueryValueExW(hKeyHN, L"Hostname", NULL, NULL, 
(LPBYTE)szHostNameOld, &cbData);
+    ok_long(Error, ERROR_SUCCESS);
+    ok(szHostNameOld[0], "szHostNameOld is %S", szHostNameOld);
+
+    /* Get Old Computer Name */
+    szComputerNameOld[0] = UNICODE_NULL;
+    cbData = sizeof(szComputerNameOld);
+    Error = RegQueryValueExW(hKeyCN, L"ComputerName", NULL, NULL, 
(LPBYTE)szComputerNameOld, &cbData);
+    ok_long(Error, ERROR_SUCCESS);
+    ok(szComputerNameOld[0], "szHostNameOld is %S", szComputerNameOld);
+
+    /* Change the value */
+    ret = SetComputerNameExW(ComputerNamePhysicalDnsHostname, szNewName);
+    ok_int(ret, TRUE);
+
+    /* Get New Hostname */
+    szHostNameNew[0] = UNICODE_NULL;
+    cbData = sizeof(szHostNameNew);
+    Error = RegQueryValueExW(hKeyHN, L"Hostname", NULL, NULL, 
(LPBYTE)szHostNameNew, &cbData);
+    ok_long(Error, ERROR_SUCCESS);
+    ok(szHostNameNew[0], "szHostNameNew was empty.\n");
+    ok(lstrcmpW(szHostNameNew, szHostNameOld) == 0,
+       "szHostNameNew '%S' should be szHostNameOld '%S'.\n", szHostNameNew, 
szHostNameOld);
+
+    /* Get New Computer Name */
+    szComputerNameNew[0] = UNICODE_NULL;
+    cbData = sizeof(szComputerNameNew);
+    Error = RegQueryValueExW(hKeyCN, L"ComputerName", NULL, NULL, 
(LPBYTE)szComputerNameNew, &cbData);
+    ok_long(Error, ERROR_SUCCESS);
+    ok(szComputerNameNew[0], "szComputerNameNew was empty.\n");
+    ok(lstrcmpW(szComputerNameNew, szNewName) == 0,
+       "szComputerNameNew '%S' should be szNewName '%S'.\n", 
szComputerNameNew, szNewName);
+
+    /* Restore the registry values */
+    cbData = (lstrlenW(szHostNameOld) + 1) * sizeof(WCHAR);
+    Error = RegSetValueExW(hKeyHN, L"Hostname", 0, REG_SZ, 
(LPBYTE)szHostNameOld, cbData);
+    ok_long(Error, ERROR_SUCCESS);
+
+    cbData = (lstrlenW(szComputerNameOld) + 1) * sizeof(WCHAR);
+    Error = RegSetValueExW(hKeyCN, L"ComputerName", 0, REG_SZ, 
(LPBYTE)szComputerNameOld, cbData);
+    ok_long(Error, ERROR_SUCCESS);
+
+    /* Close keys */
+    Error = RegCloseKey(hKeyHN);
+    ok_long(Error, ERROR_SUCCESS);
+    Error = RegCloseKey(hKeyCN);
+    ok_long(Error, ERROR_SUCCESS);
+}
diff --git a/modules/rostests/apitests/kernel32/testlist.c 
b/modules/rostests/apitests/kernel32/testlist.c
index 1a15572f98e..19217012a9b 100644
--- a/modules/rostests/apitests/kernel32/testlist.c
+++ b/modules/rostests/apitests/kernel32/testlist.c
@@ -26,6 +26,7 @@ extern void func_lstrlen(void);
 extern void func_Mailslot(void);
 extern void func_MultiByteToWideChar(void);
 extern void func_PrivMoveFileIdentityW(void);
+extern void func_SetComputerNameExW(void);
 extern void func_SetConsoleWindowInfo(void);
 extern void func_SetCurrentDirectory(void);
 extern void func_SetUnhandledExceptionFilter(void);
@@ -59,6 +60,7 @@ const struct test winetest_testlist[] =
     { "MailslotRead",                func_Mailslot },
     { "MultiByteToWideChar",         func_MultiByteToWideChar },
     { "PrivMoveFileIdentityW",       func_PrivMoveFileIdentityW },
+    { "SetComputerNameExW",          func_SetComputerNameExW },
     { "SetConsoleWindowInfo",        func_SetConsoleWindowInfo },
     { "SetCurrentDirectory",         func_SetCurrentDirectory },
     { "SetUnhandledExceptionFilter", func_SetUnhandledExceptionFilter },
@@ -68,4 +70,3 @@ const struct test winetest_testlist[] =
     { "WideCharToMultiByte",         func_WideCharToMultiByte },
     { 0, 0 }
 };
-

Reply via email to