ReactOS 0.4.16-dev-338-g34e76ad
PathUnExpandEnvStrings.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 PathUnExpandEnvStrings
5 * PROGRAMMERS: Hermes Belusca-Maito
6 */
7
8#include <apitest.h>
9#include <shlwapi.h>
10#include <strsafe.h>
11
12#define DO_TEST(Res, TestStr, ExpStr) \
13do { \
14 BOOL ret = PathUnExpandEnvStringsW((TestStr), OutStr, _countof(OutStr)); \
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
23{
24 INT len;
25 DWORD ret;
27 WCHAR ExpStr[MAX_PATH];
28 WCHAR OutStr[MAX_PATH];
29
30 /*
31 * We expect here that the following standard environment variables:
32 * %COMPUTERNAME%, %ProgramFiles%, %SystemRoot% and %SystemDrive%
33 * are correctly defined.
34 */
35
36 /* No unexpansion possible */
37 DO_TEST(FALSE, L"ZZ:\\foobar\\directory", L"");
38
39 /* Contrary to what MSDN says, %COMPUTERNAME% does not seeem to be unexpanded... */
41 ok(ret, "got %lu\n", ret);
42 DO_TEST(FALSE, TestStr, L"%COMPUTERNAME%");
43#if 0
44 StringCchCopyW(TestStr, _countof(TestStr), L"ZZ:\\foobar\\");
47 ok(ret, "got %lu\n", ret);
48 StringCchCatW(TestStr, _countof(TestStr), L"\\directory");
49 DO_TEST(TRUE, TestStr, L"ZZ:\\foobar\\%COMPUTERNAME%\\directory");
50#endif
51
52 /*
53 * L"%SystemRoot%\\%SystemRoot%" to L"%SystemRoot%\\%SystemRoot%" (no expansion)
54 * Unexpansion fails.
55 * This shows that given a path string, if PathUnExpandEnvStrings fails,
56 * the string could have been already unexpanded...
57 */
58 DO_TEST(FALSE, L"%SystemRoot%\\%SystemRoot%", L"%SystemRoot%\\%SystemRoot%");
59
60 /*
61 * L"<real_SystemRoot><real_SystemRoot>" to L"%SystemRoot%<real_SystemRoot>"
62 * example: L"C:\\WindowsC:\\Windows"
63 * Unexpansion succeeds only on the first path.
64 */
66 ok(ret, "got %lu\n", ret);
69 ok(ret, "got %lu\n", ret);
70
71 StringCchCopyW(ExpStr, _countof(ExpStr), L"%SystemRoot%");
72 len = lstrlenW(ExpStr);
73 ret = GetEnvironmentVariableW(L"SystemRoot", ExpStr + len, _countof(ExpStr) - len);
74 ok(ret, "got %lu\n", ret);
75 DO_TEST(TRUE, TestStr, ExpStr);
76
77 /*
78 * L"%SystemRoot%\<real_Program_Files>" to L"%SystemRoot%\\%ProgramFiles%"
79 * Unexpansion fails.
80 */
81 StringCchCopyW(TestStr, _countof(TestStr), L"%SystemRoot%\\");
84 ok(ret, "got %lu\n", ret);
85 DO_TEST(FALSE, TestStr, L"%SystemRoot%\\%ProgramFiles%");
86
87 /*
88 * L"<real_SystemRoot>\\%ProgramFiles%" to L"%SystemRoot%\\%ProgramFiles%"
89 * Unexpansion succeeds.
90 */
92 ok(ret, "got %lu\n", ret);
93 StringCchCatW(TestStr, _countof(TestStr), L"\\%ProgramFiles%");
94 DO_TEST(TRUE, TestStr, L"%SystemRoot%\\%ProgramFiles%");
95
96 /*
97 * L"<real_SystemRoot>\\notepad.exe <real_SystemRoot>\\file.txt" to L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt"
98 * Unexpansion succeeds only on the first path, therefore the obtained string is not the one naively expected.
99 */
101 ok(ret, "got %lu\n", ret);
102 StringCchCatW(TestStr, _countof(TestStr), L"\\notepad.exe ");
105 ok(ret, "got %lu\n", ret);
106 StringCchCatW(TestStr, _countof(TestStr), L"\\file.txt");
107 // DO_TEST(TRUE, TestStr, L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt");
108
109 /*
110 * L"<real_SystemRoot>\\notepad.exe <real_SystemRoot>\\file.txt" to L"%SystemRoot%\\notepad.exe <real_SystemRoot>\\file.txt"
111 * Unexpansion succeeds only on the first path.
112 */
113 StringCchCopyW(ExpStr, _countof(ExpStr), L"%SystemRoot%\\notepad.exe ");
114 len = lstrlenW(ExpStr);
115 ret = GetEnvironmentVariableW(L"SystemRoot", ExpStr + len, _countof(ExpStr) - len);
116 ok(ret, "got %lu\n", ret);
117 StringCchCatW(ExpStr, _countof(ExpStr), L"\\file.txt");
118 DO_TEST(TRUE, TestStr, ExpStr);
119}
#define DO_TEST(Res, TestStr, ExpStr)
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define MAX_PATH
Definition: compat.h:34
#define lstrlenW
Definition: compat.h:750
#define TestStr
Definition: edittest.c:28
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define L(x)
Definition: ntvdm.h:50
#define PathUnExpandEnvStrings
Definition: shlwapi.h:1167
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
int32_t INT
Definition: typedefs.h:58
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180