ReactOS 0.4.15-dev-7998-gdb93cb1
SHGetRestriction.c
Go to the documentation of this file.
1/*
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 SHGetRestriction
5 * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include <apitest.h>
9#include <shlwapi.h>
10
11#define REGKEY_POLICIES L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies"
12#define REGKEY_POLICIES_EXPLORER REGKEY_POLICIES L"\\Explorer"
13
14typedef DWORD (WINAPI *FN_SHGetRestriction)(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue);
16
17static DWORD
19{
21 DWORD cbValue, dwValue = 0;
22
23 if (!lpSubKey)
24 lpSubKey = REGKEY_POLICIES;
25
26 PathCombineW(szPath, lpSubKey, lpSubName);
27
28 cbValue = sizeof(dwValue);
29 if (SHGetValueW(HKEY_LOCAL_MACHINE, szPath, lpValue, NULL, &dwValue, &cbValue) == ERROR_SUCCESS)
30 return dwValue;
31
32 cbValue = sizeof(dwValue);
33 SHGetValueW(HKEY_CURRENT_USER, szPath, lpValue, NULL, &dwValue, &cbValue);
34 return dwValue;
35}
36
37typedef struct tagTEST_ENTRY
38{
42
43static const TEST_ENTRY s_Entries[] =
44{
45 { L"Explorer", L"NoRun" },
46 { L"Explorer", L"ForceActiveDesktopOn" },
47 { L"Explorer", L"NoActiveDesktop" },
48 { L"Explorer", L"NoDisconnect" },
49 { L"Explorer", L"NoRecentDocsHistory" },
50 { L"Explorer", L"NoDriveTypeAutoRun" },
51 { L"Explorer", L"NoSimpleStartMenu" },
52 { L"System", L"DontDisplayLastUserName" },
53 { L"System", L"ShutdownWithoutLogon" },
54 { L"System", L"UndockWithoutLogon" },
55};
56
57static void
59{
60 DWORD value1 = fnSHGetRestriction(NULL, entry->lpSubName, entry->lpValue);
61 DWORD value2 = Candidate_SHGetRestriction(NULL, entry->lpSubName, entry->lpValue);
62 //trace("%ld vs %ld\n", value1, value2);
63 ok_long(value1, value2);
64}
65
66#define DELETE_VALUE(hBaseKey) \
67 SHDeleteValueW((hBaseKey), REGKEY_POLICIES_EXPLORER, L"NoRun")
68
69#define SET_VALUE(hBaseKey, value) do { \
70 dwValue = (value); \
71 SHSetValueW((hBaseKey), REGKEY_POLICIES_EXPLORER, L"NoRun", \
72 REG_DWORD, &dwValue, sizeof(dwValue)); \
73} while (0)
74
75static void
77 INT iStage,
78 FN_SHGetRestriction fnSHGetRestriction)
79{
80 size_t iItem;
81 DWORD dwValue;
82
83 trace("Stage #%d\n", iStage);
84
85 switch (iStage)
86 {
87 case 0:
90 break;
91 case 1:
94 break;
95 case 2:
98 break;
99 case 3:
102 break;
103 case 4:
106 break;
107 case 5:
110 break;
111 case 6:
114 break;
115 }
116
117 for (iItem = 0; iItem < _countof(s_Entries); ++iItem)
118 {
119 TEST_DoEntry(&s_Entries[iItem], fnSHGetRestriction);
120 }
121}
122
124{
125 HMODULE hSHLWAPI = LoadLibraryW(L"shlwapi.dll");
127 INT iStage;
128
129 if (fn)
130 {
131 for (iStage = 0; iStage < 7; ++iStage)
133
136 }
137 else
138 {
139 skip("SHGetRestriction not found\n");
140 }
141
142 FreeLibrary(hSHLWAPI);
143}
EXTERN_C DWORD WINAPI SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
Definition: ordinal.c:2740
static void TEST_SHGetRestriction_Stage(INT iStage, FN_SHGetRestriction fnSHGetRestriction)
static DWORD Candidate_SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
static const TEST_ENTRY s_Entries[]
#define SET_VALUE(hBaseKey, value)
struct tagTEST_ENTRY * PTEST_ENTRY
BOOL(WINAPI * FN_SHSettingsChanged)(LPCVOID unused, LPCVOID inpRegKey)
#define REGKEY_POLICIES
struct tagTEST_ENTRY TEST_ENTRY
static void TEST_DoEntry(const TEST_ENTRY *entry, FN_SHGetRestriction fnSHGetRestriction)
DWORD(WINAPI * FN_SHGetRestriction)(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
#define DELETE_VALUE(hBaseKey)
#define ok_long(expression, result)
Definition: atltest.h:133
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
unsigned long DWORD
Definition: ntddk_ex.h:95
uint32_t entry
Definition: isohybrid.c:63
LPCWSTR szPath
Definition: env.c:37
WORD unused[29]
Definition: crypt.c:1155
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define PathCombineW
Definition: pathcch.h:317
#define _countof(array)
Definition: sndvol32.h:68
Definition: cmd.c:13
LPCWSTR lpValue
LPCWSTR lpSubName
int32_t INT
Definition: typedefs.h:58
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185