https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6f82659da626d647f4477…
commit 6f82659da626d647f44779b3e194f05507497bcd
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Jun 22 23:44:58 2018 +0900
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Fri Jun 22 16:44:58 2018 +0200
[SHLWAPI][APITESTS] Add test for PathUnExpandEnvStringsForUser (#602)
ROSTESTS-308
---
dll/win32/shlwapi/shlwapi.spec | 2 +-
modules/rostests/apitests/shlwapi/CMakeLists.txt | 1 +
.../shlwapi/PathUnExpandEnvStringsForUser.c | 119 +++++++++++++++++++++
modules/rostests/apitests/shlwapi/testlist.c | 2 +
4 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/dll/win32/shlwapi/shlwapi.spec b/dll/win32/shlwapi/shlwapi.spec
index 0f5707c8d4..a369d974b8 100644
--- a/dll/win32/shlwapi/shlwapi.spec
+++ b/dll/win32/shlwapi/shlwapi.spec
@@ -463,7 +463,7 @@
463 stdcall -noname SHExpandEnvironmentStringsForUserA(ptr str ptr long)
userenv.ExpandEnvironmentStringsForUserA
464 stdcall -noname SHExpandEnvironmentStringsForUserW(ptr wstr ptr long)
userenv.ExpandEnvironmentStringsForUserW
465 stub -noname PathUnExpandEnvStringsForUserA
-466 stub -noname PathUnExpandEnvStringsForUserW
+466 stdcall -stub -noname PathUnExpandEnvStringsForUserW(ptr wstr ptr long)
467 stub -ordinal SHRunIndirectRegClientCommand
468 stub -noname RunIndirectRegCommand
469 stub -noname RunRegCommand
diff --git a/modules/rostests/apitests/shlwapi/CMakeLists.txt
b/modules/rostests/apitests/shlwapi/CMakeLists.txt
index da4c6a808f..a7d4e05d4f 100644
--- a/modules/rostests/apitests/shlwapi/CMakeLists.txt
+++ b/modules/rostests/apitests/shlwapi/CMakeLists.txt
@@ -5,6 +5,7 @@ list(APPEND SOURCE
PathIsUNCServer.c
PathIsUNCServerShare.c
PathUnExpandEnvStrings.c
+ PathUnExpandEnvStringsForUser.c
SHAreIconsEqual.c
StrFormatByteSizeW.c
testdata.rc
diff --git a/modules/rostests/apitests/shlwapi/PathUnExpandEnvStringsForUser.c
b/modules/rostests/apitests/shlwapi/PathUnExpandEnvStringsForUser.c
new file mode 100644
index 0000000000..3e70278fa1
--- /dev/null
+++ b/modules/rostests/apitests/shlwapi/PathUnExpandEnvStringsForUser.c
@@ -0,0 +1,119 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE: Tests for PathUnExpandEnvStringsForUser
+ * PROGRAMMERS: Katayama Hirofumi MZ
+ */
+
+#include <apitest.h>
+#include <shlwapi.h>
+#include <strsafe.h>
+
+#define DO_TEST(Res, hToken, TestStr, ExpStr, Len) \
+do { \
+ BOOL ret = PathUnExpandEnvStringsForUserW((hToken), (TestStr), OutStr, Len); \
+ 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)
+
+// PathUnExpandEnvStringsForUserW
+typedef BOOL (WINAPI *PATHUNEXPANDENVSTRINGSFORUSERW)(HANDLE hToken, LPCWSTR pszPath,
LPWSTR pszUnExpanded, INT cchUnExpanded);
+PATHUNEXPANDENVSTRINGSFORUSERW pPathUnExpandEnvStringsForUserW = NULL;
+
+START_TEST(PathUnExpandEnvStringsForUser)
+{
+ DWORD ret;
+ WCHAR OutStr[MAX_PATH], TestStr[MAX_PATH];
+ HINSTANCE hShlwapi;
+
+ hShlwapi = GetModuleHandleW(L"shlwapi");
+ if (hShlwapi == NULL)
+ {
+ skip("shlwapi.dll was not loaded\n");
+ return;
+ }
+
+ pPathUnExpandEnvStringsForUserW =
+ (PATHUNEXPANDENVSTRINGSFORUSERW)GetProcAddress(hShlwapi,
"PathUnExpandEnvStringsForUserW");
+
+ if (pPathUnExpandEnvStringsForUserW == NULL)
+ {
+ trace("PathUnExpandEnvStringsForUserW is not public\n");
+ pPathUnExpandEnvStringsForUserW =
+ (PATHUNEXPANDENVSTRINGSFORUSERW)GetProcAddress(hShlwapi,
(LPCSTR)(LONG_PTR)466);
+ }
+ if (pPathUnExpandEnvStringsForUserW == NULL)
+ {
+ skip("PathUnExpandEnvStringsForUserW was not found\n");
+ return;
+ }
+
+#define PathUnExpandEnvStringsForUserW (*pPathUnExpandEnvStringsForUserW)
+
+ /* empty string */
+ DO_TEST(FALSE, NULL, L"", L"", 0);
+ DO_TEST(FALSE, NULL, L"", L"", -1);
+ DO_TEST(FALSE, NULL, L"", L"", 2);
+ DO_TEST(FALSE, NULL, L"", L"", MAX_PATH);
+
+ /* No unexpansion possible */
+ DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", 0);
+ DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", -1);
+ DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", 2);
+ DO_TEST(FALSE, NULL, L"ZZ:\\foobar\\directory", L"", MAX_PATH);
+
+ /* %APPDATA% */
+ ret = GetEnvironmentVariableW(L"APPDATA", TestStr, _countof(TestStr));
+ ok(ret, "got %lu\n", ret);
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%APPDATA%", MAX_PATH);
+ StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%APPDATA%\\TEST", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%APPDATA%\\TEST", MAX_PATH);
+
+ /* %USERPROFILE% */
+ ret = GetEnvironmentVariableW(L"USERPROFILE", TestStr, _countof(TestStr));
+ ok(ret, "got %lu\n", ret);
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%USERPROFILE%", MAX_PATH);
+ StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%USERPROFILE%\\TEST", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%USERPROFILE%\\TEST", MAX_PATH);
+
+ /* %ALLUSERSPROFILE% */
+ ret = GetEnvironmentVariableW(L"ALLUSERSPROFILE", TestStr,
_countof(TestStr));
+ ok(ret, "got %lu\n", ret);
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%ALLUSERSPROFILE%", MAX_PATH);
+ StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%ALLUSERSPROFILE%\\TEST", MAX_PATH);
+
+ /* %ProgramFiles% */
+ ret = GetEnvironmentVariableW(L"ProgramFiles", TestStr,
_countof(TestStr));
+ ok(ret, "got %lu\n", ret);
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%ProgramFiles%", MAX_PATH);
+ StringCbCatW(TestStr, sizeof(TestStr), L"\\TEST");
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", 0);
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", -1);
+ DO_TEST(FALSE, NULL, TestStr, L"%ProgramFiles%\\TEST", 2);
+ DO_TEST(TRUE, NULL, TestStr, L"%ProgramFiles%\\TEST", MAX_PATH);
+}
diff --git a/modules/rostests/apitests/shlwapi/testlist.c
b/modules/rostests/apitests/shlwapi/testlist.c
index 793385e1a2..1ad20a3bf8 100644
--- a/modules/rostests/apitests/shlwapi/testlist.c
+++ b/modules/rostests/apitests/shlwapi/testlist.c
@@ -6,6 +6,7 @@ extern void func_isuncpath(void);
extern void func_isuncpathserver(void);
extern void func_isuncpathservershare(void);
extern void func_PathUnExpandEnvStrings(void);
+extern void func_PathUnExpandEnvStringsForUser(void);
extern void func_SHAreIconsEqual(void);
extern void func_StrFormatByteSizeW(void);
@@ -16,6 +17,7 @@ const struct test winetest_testlist[] =
{ "PathIsUNCServer", func_isuncpathserver },
{ "PathIsUNCServerShare", func_isuncpathservershare },
{ "PathUnExpandEnvStrings", func_PathUnExpandEnvStrings },
+ { "PathUnExpandEnvStringsForUser", func_PathUnExpandEnvStringsForUser },
{ "SHAreIconsEqual", func_SHAreIconsEqual },
{ "StrFormatByteSizeW", func_StrFormatByteSizeW },
{ 0, 0 }