diff --git a/rostests/apitests/userenv/CMakeLists.txt b/rostests/apitests/userenv/CMakeLists.txt index a66cdf08016..0de58bee6a0 100644 --- a/rostests/apitests/userenv/CMakeLists.txt +++ b/rostests/apitests/userenv/CMakeLists.txt @@ -1,5 +1,6 @@ list(APPEND SOURCE + GetProfileDirs.c LoadUserProfile.c testlist.c) diff --git a/rostests/apitests/userenv/GetProfileDirs.c b/rostests/apitests/userenv/GetProfileDirs.c new file mode 100644 index 00000000000..eae422461d9 --- /dev/null +++ b/rostests/apitests/userenv/GetProfileDirs.c @@ -0,0 +1,86 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Tests for Get[AllUsers|DefaultUser|User]Profile[s]Directory APIs. + * PROGRAMMERS: Hermes Belusca-Maito + */ + +#include +#include + +/* The Get[AllUsers|DefaultUser|User]Profile[s]Directory have the same prototype */ +typedef BOOL (WINAPI *GET_PROFILE_DIRS_FUNC)(LPWSTR lpProfileDir, LPDWORD lpcchSize); + +typedef struct _GET_PROFILE_DIRS +{ + GET_PROFILE_DIRS_FUNC pFunc; + LPCWSTR pFuncName; +} GET_PROFILE_DIRS, *PGET_PROFILE_DIRS; + +GET_PROFILE_DIRS GetProfileDirsFuncsList[] = +{ + {GetAllUsersProfileDirectoryW, L"GetAllUsersProfileDirectoryW"}, + {GetDefaultUserProfileDirectoryW, L"GetDefaultUserProfileDirectoryW"}, + {GetProfilesDirectoryW, L"GetProfilesDirectoryW"}, +// {GetUserProfileDirectoryW, L"GetUserProfileDirectoryW"}, +}; + +START_TEST(GetProfileDirs) +{ + BOOL Success; + DWORD dwLastError; + DWORD cchSize; + WCHAR szProfileDir[MAX_PATH]; + + USHORT i; + PGET_PROFILE_DIRS GetProfileDirs; + + for (i = 0; i < _countof(GetProfileDirsFuncsList); ++i) + { + GetProfileDirs = &GetProfileDirsFuncsList[i]; + + SetLastError(0xdeadbeef); + Success = GetProfileDirs->pFunc(NULL, NULL); + dwLastError = GetLastError(); + ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName); + ok(dwLastError == ERROR_INVALID_PARAMETER, "%S: Expected error %lu, got %lu\n", + GetProfileDirs->pFuncName, (DWORD)ERROR_INVALID_PARAMETER, dwLastError); + + SetLastError(0xdeadbeef); + Success = GetProfileDirs->pFunc(szProfileDir, NULL); + dwLastError = GetLastError(); + ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName); + ok(dwLastError == ERROR_INVALID_PARAMETER, "%S: Expected error %lu, got %lu\n", + GetProfileDirs->pFuncName, (DWORD)ERROR_INVALID_PARAMETER, dwLastError); + + cchSize = 0; + SetLastError(0xdeadbeef); + Success = GetProfileDirs->pFunc(NULL, &cchSize); + dwLastError = GetLastError(); + ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName); + ok(dwLastError == ERROR_INSUFFICIENT_BUFFER, "%S: Expected error %lu, got %lu\n", + GetProfileDirs->pFuncName, (DWORD)ERROR_INSUFFICIENT_BUFFER, dwLastError); + ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName); + + cchSize = 0; + SetLastError(0xdeadbeef); + Success = GetProfileDirs->pFunc(szProfileDir, &cchSize); + dwLastError = GetLastError(); + ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName); + ok(dwLastError == ERROR_INSUFFICIENT_BUFFER, "%S: Expected error %lu, got %lu\n", + GetProfileDirs->pFuncName, (DWORD)ERROR_INSUFFICIENT_BUFFER, dwLastError); + ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName); + + cchSize = _countof(szProfileDir); + SetLastError(0xdeadbeef); + Success = GetProfileDirs->pFunc(szProfileDir, &cchSize); + dwLastError = GetLastError(); + ok(Success, "%S: Expected to success, got failure instead\n", GetProfileDirs->pFuncName); + ok(dwLastError == 0xdeadbeef, "%S: Expected error %lu, got %lu\n", + GetProfileDirs->pFuncName, (DWORD)0xdeadbeef, dwLastError); + ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName); + ok(*szProfileDir, "%S: Expected a profile directory, got nothing\n", GetProfileDirs->pFuncName); + } + + // TODO: Add more tests! +} diff --git a/rostests/apitests/userenv/testlist.c b/rostests/apitests/userenv/testlist.c index 5ff527e0155..1e861483608 100644 --- a/rostests/apitests/userenv/testlist.c +++ b/rostests/apitests/userenv/testlist.c @@ -3,10 +3,12 @@ #define STANDALONE #include +extern void func_GetProfileDirs(void); extern void func_LoadUserProfile(void); const struct test winetest_testlist[] = { + { "GetProfileDirs", func_GetProfileDirs }, { "LoadUserProfile", func_LoadUserProfile }, { 0, 0 } };