ReactOS  0.4.15-dev-1632-g4e289ce
PathUnExpandEnvStringsForUser.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Tests for PathUnExpandEnvStringsForUser
5  * PROGRAMMERS: Katayama Hirofumi MZ
6  */
7 
8 #include <apitest.h>
9 #include <shlwapi.h>
10 #include <strsafe.h>
11 
12 #define DO_TEST(Res, hToken, TestStr, ExpStr, Len) \
13 do { \
14  BOOL ret = PathUnExpandEnvStringsForUserW((hToken), (TestStr), OutStr, Len); \
15  ok(ret == (Res), "Tested %s, expected returned value %d, got %d\n", \
16  wine_dbgstr_w((TestStr)), (Res), ret); \
17  if (ret) \
18  ok(_wcsicmp(OutStr, (ExpStr)) == 0, "Tested %s, expected %s, got %s\n", \
19  wine_dbgstr_w((TestStr)), wine_dbgstr_w((ExpStr)), wine_dbgstr_w(OutStr)); \
20 } while (0)
21 
22 // PathUnExpandEnvStringsForUserW
23 typedef BOOL (WINAPI *PATHUNEXPANDENVSTRINGSFORUSERW)(HANDLE hToken, LPCWSTR pszPath, LPWSTR pszUnExpanded, INT cchUnExpanded);
25 
26 START_TEST(PathUnExpandEnvStringsForUser)
27 {
28  DWORD ret;
29  WCHAR OutStr[MAX_PATH], TestStr[MAX_PATH];
31 
32  hShlwapi = GetModuleHandleW(L"shlwapi");
33  if (hShlwapi == NULL)
34  {
35  skip("shlwapi.dll was not loaded\n");
36  return;
37  }
38 
40  (PATHUNEXPANDENVSTRINGSFORUSERW)GetProcAddress(hShlwapi, "PathUnExpandEnvStringsForUserW");
41 
43  {
44  trace("PathUnExpandEnvStringsForUserW is not public\n");
47  }
49  {
50  skip("PathUnExpandEnvStringsForUserW was not found\n");
51  return;
52  }
53 
54 #define PathUnExpandEnvStringsForUserW (*pPathUnExpandEnvStringsForUserW)
55 
56  /* empty string */
57  DO_TEST(FALSE, NULL, L"", L"", 0);
58  DO_TEST(FALSE, NULL, L"", L"", -1);
59  DO_TEST(FALSE, NULL, L"", L"", 2);
60  DO_TEST(FALSE, NULL, L"", L"", MAX_PATH);
61 
62  /* No unexpansion possible */
63  DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", 0);
64  DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", -1);
65  DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", 2);
66  DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", MAX_PATH);
67 
68  /* %APPDATA% */
70  ok(ret, "got %lu\n", ret);
71  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", 0);
72  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", -1);
73  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", 2);
74  DO_TEST(TRUE, NULL, TestStr, L"%APPDATA%", MAX_PATH);
75  StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
76  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", 0);
77  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", -1);
78  DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", 2);
79  DO_TEST(TRUE, NULL, TestStr, L"%APPDATA%\\TEST", MAX_PATH);
80 
81  /* %USERPROFILE% */
83  ok(ret, "got %lu\n", ret);
84  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", 0);
85  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", -1);
86  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", 2);
87  DO_TEST(TRUE, NULL, TestStr, L"%USERPROFILE%", MAX_PATH);
88  StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
89  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", 0);
90  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", -1);
91  DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", 2);
92  DO_TEST(TRUE, NULL, TestStr, L"%USERPROFILE%\\TEST", MAX_PATH);
93 
94  /* %ALLUSERSPROFILE% */
95  ret = GetEnvironmentVariableW(L"ALLUSERSPROFILE", TestStr, _countof(TestStr));
96  ok(ret, "got %lu\n", ret);
97  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", 0);
98  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", -1);
99  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", 2);
100  DO_TEST(TRUE, NULL, TestStr, L"%ALLUSERSPROFILE%", MAX_PATH);
101  StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
102  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", 0);
103  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", -1);
104  DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", 2);
105  DO_TEST(TRUE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", MAX_PATH);
106 
107  /* %ProgramFiles% */
108  ret = GetEnvironmentVariableW(L"ProgramFiles", TestStr, _countof(TestStr));
109  ok(ret, "got %lu\n", ret);
110  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", 0);
111  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", -1);
112  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", 2);
113  DO_TEST(TRUE, NULL, TestStr, L"%ProgramFiles%", MAX_PATH);
114  StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
115  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", 0);
116  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", -1);
117  DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", 2);
118  DO_TEST(TRUE, NULL, TestStr, L"%ProgramFiles%\\TEST", MAX_PATH);
119 }
#define LONG_PTR
Definition: treelist.c:79
#define TestStr
Definition: edittest.c:28
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define DO_TEST(Res, hToken, TestStr, ExpStr, Len)
#define BOOL
Definition: nt_native.h:43
int32_t INT
Definition: typedefs.h:58
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
static HMODULE hShlwapi
Definition: clsid.c:38
#define FALSE
Definition: types.h:117
const char * LPCSTR
Definition: xmlstorage.h:183
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
BOOL(WINAPI * PATHUNEXPANDENVSTRINGSFORUSERW)(HANDLE hToken, LPCWSTR pszPath, LPWSTR pszUnExpanded, INT cchUnExpanded)
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define GetProcAddress(x, y)
Definition: compat.h:612
WCHAR * LPWSTR
Definition: xmlstorage.h:184
START_TEST(PathUnExpandEnvStringsForUser)
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:614
PATHUNEXPANDENVSTRINGSFORUSERW pPathUnExpandEnvStringsForUserW