From ac870f986dee359ad719f32d2fb680b54ad3e03e Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Thu, 29 Feb 2024 20:28:10 +0900 Subject: [PATCH] [SHLWAPI_APITEST] Add SHGetRestriction testcase (#6557) I have a plan to implement shell32!SHRestricted correctly. JIRA issue: CORE-11515 In the testcase: - Get procedure SHGetRestriction from shlwapi.dll. - Call SHGetRestriction to test and check the results. --- .../rostests/apitests/shlwapi/CMakeLists.txt | 1 + .../apitests/shlwapi/SHGetRestriction.c | 143 ++++++++++++++++++ modules/rostests/apitests/shlwapi/testlist.c | 2 + 3 files changed, 146 insertions(+) create mode 100644 modules/rostests/apitests/shlwapi/SHGetRestriction.c diff --git a/modules/rostests/apitests/shlwapi/CMakeLists.txt b/modules/rostests/apitests/shlwapi/CMakeLists.txt index 8eeb818902c..adba1083be0 100644 --- a/modules/rostests/apitests/shlwapi/CMakeLists.txt +++ b/modules/rostests/apitests/shlwapi/CMakeLists.txt @@ -12,6 +12,7 @@ list(APPEND SOURCE PathUnExpandEnvStrings.c PathUnExpandEnvStringsForUser.c SHAreIconsEqual.c + SHGetRestriction.c SHLoadIndirectString.c SHLoadRegUIString.c SHPropertyBag.cpp diff --git a/modules/rostests/apitests/shlwapi/SHGetRestriction.c b/modules/rostests/apitests/shlwapi/SHGetRestriction.c new file mode 100644 index 00000000000..316b007eda2 --- /dev/null +++ b/modules/rostests/apitests/shlwapi/SHGetRestriction.c @@ -0,0 +1,143 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Tests for SHGetRestriction + * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ + */ + +#include +#include + +#define REGKEY_POLICIES L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies" +#define REGKEY_POLICIES_EXPLORER REGKEY_POLICIES L"\\Explorer" + +typedef DWORD (WINAPI *FN_SHGetRestriction)(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue); +typedef BOOL (WINAPI *FN_SHSettingsChanged)(LPCVOID unused, LPCVOID inpRegKey); + +static DWORD +Candidate_SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue) +{ + WCHAR szPath[MAX_PATH]; + DWORD cbValue, dwValue = 0; + + if (!lpSubKey) + lpSubKey = REGKEY_POLICIES; + + PathCombineW(szPath, lpSubKey, lpSubName); + + cbValue = sizeof(dwValue); + if (SHGetValueW(HKEY_LOCAL_MACHINE, szPath, lpValue, NULL, &dwValue, &cbValue) == ERROR_SUCCESS) + return dwValue; + + cbValue = sizeof(dwValue); + SHGetValueW(HKEY_CURRENT_USER, szPath, lpValue, NULL, &dwValue, &cbValue); + return dwValue; +} + +typedef struct tagTEST_ENTRY +{ + LPCWSTR lpSubName; + LPCWSTR lpValue; +} TEST_ENTRY, *PTEST_ENTRY; + +static const TEST_ENTRY s_Entries[] = +{ + { L"Explorer", L"NoRun" }, + { L"Explorer", L"ForceActiveDesktopOn" }, + { L"Explorer", L"NoActiveDesktop" }, + { L"Explorer", L"NoDisconnect" }, + { L"Explorer", L"NoRecentDocsHistory" }, + { L"Explorer", L"NoDriveTypeAutoRun" }, + { L"Explorer", L"NoSimpleStartMenu" }, + { L"System", L"DontDisplayLastUserName" }, + { L"System", L"ShutdownWithoutLogon" }, + { L"System", L"UndockWithoutLogon" }, +}; + +static void +TEST_DoEntry(const TEST_ENTRY *entry, FN_SHGetRestriction fnSHGetRestriction) +{ + DWORD value1 = fnSHGetRestriction(NULL, entry->lpSubName, entry->lpValue); + DWORD value2 = Candidate_SHGetRestriction(NULL, entry->lpSubName, entry->lpValue); + //trace("%ld vs %ld\n", value1, value2); + ok_long(value1, value2); +} + +#define DELETE_VALUE(hBaseKey) \ + SHDeleteValueW((hBaseKey), REGKEY_POLICIES_EXPLORER, L"NoRun") + +#define SET_VALUE(hBaseKey, value) do { \ + dwValue = (value); \ + SHSetValueW((hBaseKey), REGKEY_POLICIES_EXPLORER, L"NoRun", \ + REG_DWORD, &dwValue, sizeof(dwValue)); \ +} while (0) + +static void +TEST_SHGetRestriction_Stage( + INT iStage, + FN_SHGetRestriction fnSHGetRestriction) +{ + size_t iItem; + DWORD dwValue; + + trace("Stage #%d\n", iStage); + + switch (iStage) + { + case 0: + DELETE_VALUE(HKEY_CURRENT_USER); + DELETE_VALUE(HKEY_LOCAL_MACHINE); + break; + case 1: + SET_VALUE(HKEY_CURRENT_USER, 0); + DELETE_VALUE(HKEY_LOCAL_MACHINE); + break; + case 2: + SET_VALUE(HKEY_CURRENT_USER, 1); + DELETE_VALUE(HKEY_LOCAL_MACHINE); + break; + case 3: + DELETE_VALUE(HKEY_CURRENT_USER); + SET_VALUE(HKEY_LOCAL_MACHINE, 0); + break; + case 4: + DELETE_VALUE(HKEY_CURRENT_USER); + SET_VALUE(HKEY_LOCAL_MACHINE, 1); + break; + case 5: + SET_VALUE(HKEY_CURRENT_USER, 0); + SET_VALUE(HKEY_LOCAL_MACHINE, 1); + break; + case 6: + SET_VALUE(HKEY_CURRENT_USER, 1); + SET_VALUE(HKEY_LOCAL_MACHINE, 0); + break; + } + + for (iItem = 0; iItem < _countof(s_Entries); ++iItem) + { + TEST_DoEntry(&s_Entries[iItem], fnSHGetRestriction); + } +} + +START_TEST(SHGetRestriction) +{ + HMODULE hSHLWAPI = LoadLibraryW(L"shlwapi.dll"); + FN_SHGetRestriction fn = (FN_SHGetRestriction)GetProcAddress(hSHLWAPI, MAKEINTRESOURCEA(271)); + INT iStage; + + if (fn) + { + for (iStage = 0; iStage < 7; ++iStage) + TEST_SHGetRestriction_Stage(iStage, fn); + + DELETE_VALUE(HKEY_CURRENT_USER); + DELETE_VALUE(HKEY_LOCAL_MACHINE); + } + else + { + skip("SHGetRestriction not found\n"); + } + + FreeLibrary(hSHLWAPI); +} diff --git a/modules/rostests/apitests/shlwapi/testlist.c b/modules/rostests/apitests/shlwapi/testlist.c index 08fd3c8e2be..9ec57ee2686 100644 --- a/modules/rostests/apitests/shlwapi/testlist.c +++ b/modules/rostests/apitests/shlwapi/testlist.c @@ -8,6 +8,7 @@ extern void func_isuncpathservershare(void); extern void func_PathUnExpandEnvStrings(void); extern void func_PathUnExpandEnvStringsForUser(void); extern void func_SHAreIconsEqual(void); +extern void func_SHGetRestriction(void); extern void func_SHLoadIndirectString(void); extern void func_SHLoadRegUIString(void); extern void func_SHPropertyBag(void); @@ -22,6 +23,7 @@ const struct test winetest_testlist[] = { "PathUnExpandEnvStrings", func_PathUnExpandEnvStrings }, { "PathUnExpandEnvStringsForUser", func_PathUnExpandEnvStringsForUser }, { "SHAreIconsEqual", func_SHAreIconsEqual }, + { "SHGetRestriction", func_SHGetRestriction }, { "SHLoadIndirectString", func_SHLoadIndirectString }, { "SHLoadRegUIString", func_SHLoadRegUIString }, { "SHPropertyBag", func_SHPropertyBag },