[USERENV_APITEST]: Add some simple tests for Get[AllUsers|DefaultUser|User]Profile...
[reactos.git] / rostests / apitests / userenv / GetProfileDirs.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Tests for Get[AllUsers|DefaultUser|User]Profile[s]Directory APIs.
5 * PROGRAMMERS: Hermes Belusca-Maito
6 */
7
8 #include <apitest.h>
9 #include <userenv.h>
10
11 /* The Get[AllUsers|DefaultUser|User]Profile[s]Directory have the same prototype */
12 typedef BOOL (WINAPI *GET_PROFILE_DIRS_FUNC)(LPWSTR lpProfileDir, LPDWORD lpcchSize);
13
14 typedef struct _GET_PROFILE_DIRS
15 {
16 GET_PROFILE_DIRS_FUNC pFunc;
17 LPCWSTR pFuncName;
18 } GET_PROFILE_DIRS, *PGET_PROFILE_DIRS;
19
20 GET_PROFILE_DIRS GetProfileDirsFuncsList[] =
21 {
22 {GetAllUsersProfileDirectoryW, L"GetAllUsersProfileDirectoryW"},
23 {GetDefaultUserProfileDirectoryW, L"GetDefaultUserProfileDirectoryW"},
24 {GetProfilesDirectoryW, L"GetProfilesDirectoryW"},
25 // {GetUserProfileDirectoryW, L"GetUserProfileDirectoryW"},
26 };
27
28 START_TEST(GetProfileDirs)
29 {
30 BOOL Success;
31 DWORD dwLastError;
32 DWORD cchSize;
33 WCHAR szProfileDir[MAX_PATH];
34
35 USHORT i;
36 PGET_PROFILE_DIRS GetProfileDirs;
37
38 for (i = 0; i < _countof(GetProfileDirsFuncsList); ++i)
39 {
40 GetProfileDirs = &GetProfileDirsFuncsList[i];
41
42 SetLastError(0xdeadbeef);
43 Success = GetProfileDirs->pFunc(NULL, NULL);
44 dwLastError = GetLastError();
45 ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName);
46 ok(dwLastError == ERROR_INVALID_PARAMETER, "%S: Expected error %lu, got %lu\n",
47 GetProfileDirs->pFuncName, (DWORD)ERROR_INVALID_PARAMETER, dwLastError);
48
49 SetLastError(0xdeadbeef);
50 Success = GetProfileDirs->pFunc(szProfileDir, NULL);
51 dwLastError = GetLastError();
52 ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName);
53 ok(dwLastError == ERROR_INVALID_PARAMETER, "%S: Expected error %lu, got %lu\n",
54 GetProfileDirs->pFuncName, (DWORD)ERROR_INVALID_PARAMETER, dwLastError);
55
56 cchSize = 0;
57 SetLastError(0xdeadbeef);
58 Success = GetProfileDirs->pFunc(NULL, &cchSize);
59 dwLastError = GetLastError();
60 ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName);
61 ok(dwLastError == ERROR_INSUFFICIENT_BUFFER, "%S: Expected error %lu, got %lu\n",
62 GetProfileDirs->pFuncName, (DWORD)ERROR_INSUFFICIENT_BUFFER, dwLastError);
63 ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName);
64
65 cchSize = 0;
66 SetLastError(0xdeadbeef);
67 Success = GetProfileDirs->pFunc(szProfileDir, &cchSize);
68 dwLastError = GetLastError();
69 ok(!Success, "%S: Expected failure, got success instead\n", GetProfileDirs->pFuncName);
70 ok(dwLastError == ERROR_INSUFFICIENT_BUFFER, "%S: Expected error %lu, got %lu\n",
71 GetProfileDirs->pFuncName, (DWORD)ERROR_INSUFFICIENT_BUFFER, dwLastError);
72 ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName);
73
74 cchSize = _countof(szProfileDir);
75 SetLastError(0xdeadbeef);
76 Success = GetProfileDirs->pFunc(szProfileDir, &cchSize);
77 dwLastError = GetLastError();
78 ok(Success, "%S: Expected to success, got failure instead\n", GetProfileDirs->pFuncName);
79 ok(dwLastError == 0xdeadbeef, "%S: Expected error %lu, got %lu\n",
80 GetProfileDirs->pFuncName, (DWORD)0xdeadbeef, dwLastError);
81 ok(cchSize != 0, "%S: Expected a profile directory size != 0, got 0\n", GetProfileDirs->pFuncName);
82 ok(*szProfileDir, "%S: Expected a profile directory, got nothing\n", GetProfileDirs->pFuncName);
83 }
84
85 // TODO: Add more tests!
86 }