ReactOS  0.4.15-dev-1397-g19779b3
PathUnExpandEnvStrings.c File Reference
#include <apitest.h>
#include <shlwapi.h>
#include <strsafe.h>
Include dependency graph for PathUnExpandEnvStrings.c:

Go to the source code of this file.

Macros

#define DO_TEST(Res, TestStr, ExpStr)
 

Functions

 START_TEST (PathUnExpandEnvStrings)
 

Macro Definition Documentation

◆ DO_TEST

#define DO_TEST (   Res,
  TestStr,
  ExpStr 
)
Value:
do { \
BOOL ret = PathUnExpandEnvStringsW((TestStr), OutStr, _countof(OutStr)); \
ok(ret == (Res), "Tested %s, expected returned value %d, got %d\n", \
wine_dbgstr_w((TestStr)), (Res), ret); \
if (ret) \
ok(_wcsicmp(OutStr, (ExpStr)) == 0, "Tested %s, expected %s, got %s\n", \
wine_dbgstr_w((TestStr)), wine_dbgstr_w((ExpStr)), wine_dbgstr_w(OutStr)); \
} while (0)
#define TestStr
Definition: edittest.c:28
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
BOOL WINAPI PathUnExpandEnvStringsW(LPCWSTR path, LPWSTR buffer, UINT buf_len)
Definition: path.c:4170
#define _countof(array)
Definition: sndvol32.h:68
int ret
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Definition at line 12 of file PathUnExpandEnvStrings.c.

Function Documentation

◆ START_TEST()

START_TEST ( PathUnExpandEnvStrings  )

Definition at line 22 of file PathUnExpandEnvStrings.c.

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\\");
45  len = wcslen(TestStr);
46  ret = GetEnvironmentVariableW(L"COMPUTERNAME", TestStr + len, _countof(TestStr) - len);
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);
67  len = lstrlenW(TestStr);
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%\\");
82  len = lstrlenW(TestStr);
83  ret = GetEnvironmentVariableW(L"ProgramFiles", TestStr + len, _countof(TestStr) - len);
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 ");
103  len = lstrlenW(TestStr);
104  ret = GetEnvironmentVariableW(L"SystemRoot", TestStr + len, _countof(TestStr) - len);
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 TestStr
Definition: edittest.c:28
#define TRUE
Definition: types.h:120
#define lstrlenW
Definition: compat.h:609
int32_t INT
Definition: typedefs.h:58
#define DO_TEST(Res, TestStr, ExpStr)
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
#define FALSE
Definition: types.h:117
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
#define ok(value,...)
Definition: atltest.h:57
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:614
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)