ReactOS 0.4.15-dev-6057-gd708c79
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) \
13do { \
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
23typedef BOOL (WINAPI *PATHUNEXPANDENVSTRINGSFORUSERW)(HANDLE hToken, LPCWSTR pszPath, LPWSTR pszUnExpanded, INT cchUnExpanded);
25
26START_TEST(PathUnExpandEnvStringsForUser)
27{
28 DWORD ret;
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% */
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 DO_TEST(Res, hToken, TestStr, ExpStr, Len)
PATHUNEXPANDENVSTRINGSFORUSERW pPathUnExpandEnvStringsForUserW
BOOL(WINAPI * PATHUNEXPANDENVSTRINGSFORUSERW)(HANDLE hToken, LPCWSTR pszPath, LPWSTR pszUnExpanded, INT cchUnExpanded)
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
static HMODULE hShlwapi
Definition: clsid.c:38
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define TestStr
Definition: edittest.c:28
unsigned long DWORD
Definition: ntddk_ex.h:95
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define LONG_PTR
Definition: treelist.c:79
int32_t INT
Definition: typedefs.h:58
int ret
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185