From: Hermès Bélusca-Maïto Date: Fri, 13 Jan 2017 14:51:25 +0000 (+0000) Subject: [SHLWAPI_APITEST]: Commit few tests for PathUnExpandEnvStrings. X-Git-Tag: ReactOS-0.4.4-FOSDEM2017~8^2~63 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=a20fc53659834f8bb3dfd193159f5b6a156dd704;hp=d5122b7e7bda4b0758a26f0117870f1128de5279 [SHLWAPI_APITEST]: Commit few tests for PathUnExpandEnvStrings. svn path=/trunk/; revision=73536 --- diff --git a/rostests/apitests/shlwapi/CMakeLists.txt b/rostests/apitests/shlwapi/CMakeLists.txt index f447e0e22a2..c0d9f649629 100644 --- a/rostests/apitests/shlwapi/CMakeLists.txt +++ b/rostests/apitests/shlwapi/CMakeLists.txt @@ -1,5 +1,10 @@ -add_executable(shlwapi_apitest PathIsUNC.c testlist.c) +list(APPEND SOURCE + PathIsUNC.c + PathUnExpandEnvStrings.c + testlist.c) + +add_executable(shlwapi_apitest ${SOURCE}) set_module_type(shlwapi_apitest win32cui) -add_importlibs(shlwapi_apitest msvcrt kernel32) +add_importlibs(shlwapi_apitest shlwapi msvcrt kernel32) add_cd_file(TARGET shlwapi_apitest DESTINATION reactos/bin FOR all) diff --git a/rostests/apitests/shlwapi/PathUnExpandEnvStrings.c b/rostests/apitests/shlwapi/PathUnExpandEnvStrings.c new file mode 100644 index 00000000000..c7da336ee42 --- /dev/null +++ b/rostests/apitests/shlwapi/PathUnExpandEnvStrings.c @@ -0,0 +1,119 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Tests for PathUnExpandEnvStrings + * PROGRAMMERS: Hermes Belusca-Maito + */ + +#include +#include +#include + +#define DO_TEST(Res, TestStr, ExpStr) \ +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) + +START_TEST(PathUnExpandEnvStrings) +{ + INT len; + DWORD ret; + WCHAR TestStr[MAX_PATH]; + WCHAR ExpStr[MAX_PATH]; + WCHAR OutStr[MAX_PATH]; + + /* + * We expect here that the following standard environment variables: + * %COMPUTERNAME%, %ProgramFiles%, %SystemRoot% and %SystemDrive% + * are correctly defined. + */ + + /* No unexpansion possible */ + DO_TEST(FALSE, L"ZZ:\\foobar\\directory", L""); + + /* Contrary to what MSDN says, %COMPUTERNAME% does not seeem to be unexpanded... */ + ret = GetEnvironmentVariableW(L"COMPUTERNAME", TestStr, _countof(TestStr)); + ok(ret, "got %lu\n", ret); + DO_TEST(FALSE, TestStr, L"%COMPUTERNAME%"); +#if 0 + StringCchCopyW(TestStr, _countof(TestStr), L"ZZ:\\foobar\\"); + len = wcslen(TestStr); + ret = GetEnvironmentVariableW(L"COMPUTERNAME", TestStr + len, _countof(TestStr) - len); + ok(ret, "got %lu\n", ret); + StringCchCatW(TestStr, _countof(TestStr), L"\\directory"); + DO_TEST(TRUE, TestStr, L"ZZ:\\foobar\\%COMPUTERNAME%\\directory"); +#endif + + /* + * L"%SystemRoot%\\%SystemRoot%" to L"%SystemRoot%\\%SystemRoot%" (no expansion) + * Unexpansion fails. + * This shows that given a path string, if PathUnExpandEnvStrings fails, + * the string could have been already unexpanded... + */ + DO_TEST(FALSE, L"%SystemRoot%\\%SystemRoot%", L"%SystemRoot%\\%SystemRoot%"); + + /* + * L"" to L"%SystemRoot%" + * example: L"C:\\WindowsC:\\Windows" + * Unexpansion succeeds only on the first path. + */ + ret = GetEnvironmentVariableW(L"SystemRoot", TestStr, _countof(TestStr)); + ok(ret, "got %lu\n", ret); + len = wcslen(TestStr); + ret = GetEnvironmentVariableW(L"SystemRoot", TestStr + len, _countof(TestStr) - len); + ok(ret, "got %lu\n", ret); + + StringCchCopyW(ExpStr, _countof(ExpStr), L"%SystemRoot%"); + len = wcslen(ExpStr); + ret = GetEnvironmentVariableW(L"SystemRoot", ExpStr + len, _countof(ExpStr) - len); + ok(ret, "got %lu\n", ret); + DO_TEST(TRUE, TestStr, ExpStr); + + /* + * L"%SystemRoot%\\" to L"%SystemRoot%\\%ProgramFiles%" + * Unexpansion fails. + */ + StringCchCopyW(TestStr, _countof(TestStr), L"%SystemRoot%\\"); + len = wcslen(TestStr); + ret = GetEnvironmentVariableW(L"ProgramFiles", TestStr + len, _countof(TestStr) - len); + ok(ret, "got %lu\n", ret); + DO_TEST(FALSE, TestStr, L"%SystemRoot%\\%ProgramFiles%"); + + /* + * L"\\%ProgramFiles%" to L"%SystemRoot%\\%ProgramFiles%" + * Unexpansion succeeds. + */ + ret = GetEnvironmentVariableW(L"SystemRoot", TestStr, _countof(TestStr)); + ok(ret, "got %lu\n", ret); + StringCchCatW(TestStr, _countof(TestStr), L"\\%ProgramFiles%"); + DO_TEST(TRUE, TestStr, L"%SystemRoot%\\%ProgramFiles%"); + + /* + * L"\\notepad.exe \\file.txt" to L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt" + * Unexpansion succeeds only on the first path, therefore the obtained string is not the one naively expected. + */ + ret = GetEnvironmentVariableW(L"SystemRoot", TestStr, _countof(TestStr)); + ok(ret, "got %lu\n", ret); + StringCchCatW(TestStr, _countof(TestStr), L"\\notepad.exe "); + len = wcslen(TestStr); + ret = GetEnvironmentVariableW(L"SystemRoot", TestStr + len, _countof(TestStr) - len); + ok(ret, "got %lu\n", ret); + StringCchCatW(TestStr, _countof(TestStr), L"\\file.txt"); + // DO_TEST(TRUE, TestStr, L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt"); + + /* + * L"\\notepad.exe \\file.txt" to L"%SystemRoot%\\notepad.exe \\file.txt" + * Unexpansion succeeds only on the first path. + */ + StringCchCopyW(ExpStr, _countof(ExpStr), L"%SystemRoot%\\notepad.exe "); + len = wcslen(ExpStr); + ret = GetEnvironmentVariableW(L"SystemRoot", ExpStr + len, _countof(ExpStr) - len); + ok(ret, "got %lu\n", ret); + StringCchCatW(ExpStr, _countof(ExpStr), L"\\file.txt"); + DO_TEST(TRUE, TestStr, ExpStr); +} diff --git a/rostests/apitests/shlwapi/testlist.c b/rostests/apitests/shlwapi/testlist.c index 1aba16cbb60..fc4559c6272 100644 --- a/rostests/apitests/shlwapi/testlist.c +++ b/rostests/apitests/shlwapi/testlist.c @@ -2,9 +2,11 @@ #include extern void func_isuncpath(void); +extern void func_PathUnExpandEnvStrings(void); const struct test winetest_testlist[] = { { "PathIsUNC", func_isuncpath }, + { "PathUnExpandEnvStrings", func_PathUnExpandEnvStrings }, { 0, 0 } };