ReactOS 0.4.17-dev-1133-gc25e4fd
RegenerateUserEnvironment.cpp File Reference
#include "shelltest.h"
#include <userenv.h>
#include <debug.h>
Include dependency graph for RegenerateUserEnvironment.cpp:

Go to the source code of this file.

Macros

#define NDEBUG
 

Typedefs

typedef BOOL(WINAPI * PFN_REGENERATE_USER_ENVIRONMENT) (PVOID *pPrevEnv, BOOL bSetCurrentEnv)
 

Functions

static BOOL IsValidEnvBlock (PVOID pEnv)
 
static void Test_BasicCall (void)
 
static void Test_PreviousEnvironmentReturned (void)
 
static void Test_RegistryVariablePickedUp (void)
 
 START_TEST (RegenerateUserEnvironment)
 

Variables

static PFN_REGENERATE_USER_ENVIRONMENT pRegenerateUserEnvironment = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file RegenerateUserEnvironment.cpp.

Typedef Documentation

◆ PFN_REGENERATE_USER_ENVIRONMENT

typedef BOOL(WINAPI * PFN_REGENERATE_USER_ENVIRONMENT) (PVOID *pPrevEnv, BOOL bSetCurrentEnv)

Definition at line 14 of file RegenerateUserEnvironment.cpp.

Function Documentation

◆ IsValidEnvBlock()

static BOOL IsValidEnvBlock ( PVOID  pEnv)
static

Definition at line 17 of file RegenerateUserEnvironment.cpp.

18{
19 LPWCH p = (LPWCH)pEnv;
20
21 if (!p || *p == L'\0')
22 return FALSE;
23
24 /* Walk the block but bail out early if it looks corrupted */
25 while (*p != L'\0')
26 {
27 SIZE_T len = wcslen(p);
28 if (len == 0)
29 return FALSE;
30 p += len + 1;
31 }
32
33 return TRUE;
34}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
#define L(x)
Definition: resources.c:13
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
WCHAR * LPWCH
Definition: ntbasedef.h:422
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by Test_PreviousEnvironmentReturned().

◆ START_TEST()

START_TEST ( RegenerateUserEnvironment  )

Definition at line 135 of file RegenerateUserEnvironment.cpp.

136{
137 HMODULE hShell32 = GetModuleHandleW(L"shell32.dll");
138
139 if (!hShell32)
140 hShell32 = LoadLibraryW(L"shell32.dll");
141
143 (PFN_REGENERATE_USER_ENVIRONMENT)GetProcAddress(hShell32, "RegenerateUserEnvironment");
144
146 {
147 skip("RegenerateUserEnvironment not found in shell32.dll\n");
148 return;
149 }
150
154}
static PFN_REGENERATE_USER_ENVIRONMENT pRegenerateUserEnvironment
BOOL(WINAPI * PFN_REGENERATE_USER_ENVIRONMENT)(PVOID *pPrevEnv, BOOL bSetCurrentEnv)
static void Test_PreviousEnvironmentReturned(void)
static void Test_BasicCall(void)
static void Test_RegistryVariablePickedUp(void)
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:753
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static HMODULE hShell32
Definition: string.c:34

◆ Test_BasicCall()

static void Test_BasicCall ( void  )
static

Definition at line 36 of file RegenerateUserEnvironment.cpp.

37{
38 PVOID pEnv = NULL;
39 BOOL ret;
40
42 ok(ret != FALSE,
43 "RegenerateUserEnvironment(&pEnv, TRUE) failed with last error %lu\n",
44 GetLastError());
45
46 pEnv = NULL;
48 ok(ret != FALSE,
49 "RegenerateUserEnvironment(&pEnv, FALSE) failed with last error %lu\n",
50 GetLastError());
51 if (pEnv)
53}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:725
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ Test_PreviousEnvironmentReturned()

static void Test_PreviousEnvironmentReturned ( void  )
static

Definition at line 55 of file RegenerateUserEnvironment.cpp.

56{
57 PVOID pPrev = NULL;
58 BOOL ret;
59
61 ok(ret != FALSE,
62 "RegenerateUserEnvironment(&pPrev, FALSE) failed with last error %lu\n",
63 GetLastError());
64
65 if (!ret)
66 {
67 skip("RegenerateUserEnvironment failed; skipping pPrev checks.\n");
68 return;
69 }
70
71 ok(pPrev != NULL,
72 "pPrev must not be NULL when bSetCurrentEnv is FALSE\n");
73
74 if (!pPrev)
75 return;
76
77 ok(IsValidEnvBlock(pPrev),
78 "pPrev does not point to a valid environment block\n");
79
81}
static BOOL IsValidEnvBlock(PVOID pEnv)

Referenced by START_TEST().

◆ Test_RegistryVariablePickedUp()

static void Test_RegistryVariablePickedUp ( void  )
static

Definition at line 83 of file RegenerateUserEnvironment.cpp.

84{
85 static const WCHAR szKey[] = L"Environment";
86 static const WCHAR szVarName[] = L"__REGEN_TEST_VAR__";
87 static const WCHAR szVarValue[]= L"ReactOS_RegenerateTest";
88
89 HKEY hKey;
90 LONG lRet;
91 BOOL ret;
92 WCHAR szBuf[64];
93
95 if (lRet != ERROR_SUCCESS)
96 {
97 skip("Cannot open HKCU\\Environment (error %ld); skipping registry test.\n", lRet);
98 return;
99 }
100
101 /* Write canary value */
102 lRet = RegSetValueExW(hKey, szVarName, 0, REG_SZ,
103 (const BYTE *)szVarValue,
104 (DWORD)((wcslen(szVarValue) + 1) * sizeof(WCHAR)));
105 ok(lRet == ERROR_SUCCESS,
106 "RegSetValueExW failed: %ld\n", lRet);
107
108 if (lRet != ERROR_SUCCESS)
109 {
111 return;
112 }
113
114 /* Regenerate and apply to current process */
115 PVOID pEnv = NULL;
117 ok(ret != FALSE,
118 "RegenerateUserEnvironment failed: %lu\n", GetLastError());
119
120 /* The canary should be visible with GetEnvironmentVariableW */
121 szBuf[0] = L'\0';
122 GetEnvironmentVariableW(szVarName, szBuf, _countof(szBuf));
123 ok(wcscmp(szBuf, szVarValue) == 0,
124 "Expected env var '%ls' = '%ls', got '%ls'\n",
125 szVarName, szVarValue, szBuf);
126
127 /* Remove canary from registry */
128 RegDeleteValueW(hKey, szVarName);
130
131 PVOID pEnv2 = NULL;
133}
#define REG_SZ
Definition: layer.c:22
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_SET_VALUE
Definition: nt_native.h:1020
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
#define _countof(array)
Definition: sndvol32.h:70
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

Variable Documentation

◆ pRegenerateUserEnvironment