2 * Unit tests for shell32 SHGet{Special}Folder{Path|Location} functions.
4 * Copyright 2004 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
34 #include "wine/test.h"
36 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
37 * here is its original value.
39 #define OLD_CSIDL_MYDOCUMENTS 0x000c
42 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
45 /* from pidl.h, not included here: */
47 #define PT_GUID 0x1f /* no path */
50 #define PT_DRIVE 0x23 /* has path */
53 #define PT_DRIVE2 0x25 /* has path */
56 #define PT_SHELLEXT 0x2e /* no path */
59 #define PT_FOLDER 0x31 /* has path */
62 #define PT_FOLDERW 0x35 /* has path */
65 #define PT_WORKGRP 0x41 /* no path */
68 #define PT_YAGUID 0x70 /* no path */
70 /* FIXME: this is used for history/favorites folders; what's a better name? */
72 #define PT_IESPECIAL2 0xb1 /* has path */
75 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
77 struct shellExpectedValues {
83 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
84 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
85 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
87 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
88 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
89 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
90 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
91 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
92 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR,UINT);
93 static DLLVERSIONINFO shellVersion = { 0 };
94 static LPMALLOC pMalloc;
95 static const BYTE guidType[] = { PT_GUID };
96 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID };
97 static const BYTE folderType[] = { PT_FOLDER, PT_FOLDERW };
98 static const BYTE favoritesType[] = { PT_FOLDER, PT_FOLDERW, 0, PT_IESPECIAL2 /* Win98 */ };
99 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
100 static const BYTE personalType[] = { PT_FOLDER, PT_GUID, PT_DRIVE, 0xff /* Win9x */,
101 PT_IESPECIAL2 /* Win98 */, 0 /* Vista */ };
102 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
103 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
104 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
105 static const BYTE shellExtType[] = { PT_SHELLEXT };
106 static const BYTE workgroupType[] = { PT_WORKGRP };
107 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
108 static const struct shellExpectedValues requiredShellValues[] = {
109 DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
110 DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
111 DECLARE_TYPE(CSIDL_COOKIES, folderType),
112 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
113 DECLARE_TYPE(CSIDL_DRIVES, guidType),
114 DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
115 DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
116 /* FIXME: the following fails in Wine, returns type PT_FOLDER
117 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
119 DECLARE_TYPE(CSIDL_INTERNET, guidType),
120 DECLARE_TYPE(CSIDL_NETHOOD, folderType),
121 DECLARE_TYPE(CSIDL_NETWORK, guidType),
122 DECLARE_TYPE(CSIDL_PERSONAL, personalType),
123 DECLARE_TYPE(CSIDL_PRINTERS, printersType),
124 DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
125 DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
126 DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
127 DECLARE_TYPE(CSIDL_SENDTO, folderType),
128 DECLARE_TYPE(CSIDL_STARTMENU, folderType),
129 DECLARE_TYPE(CSIDL_STARTUP, folderType),
130 DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
132 static const struct shellExpectedValues optionalShellValues[] = {
133 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
134 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
135 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
136 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
138 /* Windows NT-only: */
139 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
140 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
141 DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
142 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
143 DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
144 DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
145 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
146 /* first appearing in shell32 version 4.71: */
147 DECLARE_TYPE(CSIDL_APPDATA, folderType),
148 /* first appearing in shell32 version 4.72: */
149 DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
150 /* first appearing in shell32 version 5.0: */
151 DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
152 DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
153 DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
154 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
155 DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
156 DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
157 DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
158 DECLARE_TYPE(CSIDL_PROFILE, folderType),
159 DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
160 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
161 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
162 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
163 DECLARE_TYPE(CSIDL_SYSTEM, folderType),
164 DECLARE_TYPE(CSIDL_WINDOWS, folderType),
165 /* first appearing in shell32 6.0: */
166 DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
167 DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
168 DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
169 DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
170 DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
171 DECLARE_TYPE(CSIDL_RESOURCES, folderType),
172 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
176 static void loadShell32(void)
178 HMODULE hShell32 = GetModuleHandleA("shell32");
180 #define GET_PROC(func) \
181 p ## func = (void*)GetProcAddress(hShell32, #func); \
183 trace("GetProcAddress(%s) failed\n", #func);
185 GET_PROC(DllGetVersion)
186 GET_PROC(SHGetFolderPathA)
187 GET_PROC(SHGetFolderLocation)
188 GET_PROC(SHGetSpecialFolderPathA)
189 GET_PROC(SHGetSpecialFolderLocation)
190 GET_PROC(ILFindLastID)
192 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
193 GET_PROC(SHFileOperationA)
194 GET_PROC(SHGetMalloc)
196 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
199 HRESULT hr = pSHGetMalloc(&pMalloc);
201 ok(SUCCEEDED(hr), "SHGetMalloc failed: 0x%08x\n", hr);
202 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
207 shellVersion.cbSize = sizeof(shellVersion);
208 pDllGetVersion(&shellVersion);
209 trace("shell32 version is %d.%d\n",
210 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
215 #ifndef CSIDL_PROFILES
216 #define CSIDL_PROFILES 0x003e
219 /* A couple utility printing functions */
220 static const char *getFolderName(int folder)
222 static char unknown[32];
224 #define CSIDL_TO_STR(x) case x: return#x;
227 CSIDL_TO_STR(CSIDL_DESKTOP);
228 CSIDL_TO_STR(CSIDL_INTERNET);
229 CSIDL_TO_STR(CSIDL_PROGRAMS);
230 CSIDL_TO_STR(CSIDL_CONTROLS);
231 CSIDL_TO_STR(CSIDL_PRINTERS);
232 CSIDL_TO_STR(CSIDL_PERSONAL);
233 CSIDL_TO_STR(CSIDL_FAVORITES);
234 CSIDL_TO_STR(CSIDL_STARTUP);
235 CSIDL_TO_STR(CSIDL_RECENT);
236 CSIDL_TO_STR(CSIDL_SENDTO);
237 CSIDL_TO_STR(CSIDL_BITBUCKET);
238 CSIDL_TO_STR(CSIDL_STARTMENU);
239 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
240 CSIDL_TO_STR(CSIDL_MYMUSIC);
241 CSIDL_TO_STR(CSIDL_MYVIDEO);
242 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
243 CSIDL_TO_STR(CSIDL_DRIVES);
244 CSIDL_TO_STR(CSIDL_NETWORK);
245 CSIDL_TO_STR(CSIDL_NETHOOD);
246 CSIDL_TO_STR(CSIDL_FONTS);
247 CSIDL_TO_STR(CSIDL_TEMPLATES);
248 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
249 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
250 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
251 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
252 CSIDL_TO_STR(CSIDL_APPDATA);
253 CSIDL_TO_STR(CSIDL_PRINTHOOD);
254 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
255 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
256 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
257 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
258 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
259 CSIDL_TO_STR(CSIDL_COOKIES);
260 CSIDL_TO_STR(CSIDL_HISTORY);
261 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
262 CSIDL_TO_STR(CSIDL_WINDOWS);
263 CSIDL_TO_STR(CSIDL_SYSTEM);
264 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
265 CSIDL_TO_STR(CSIDL_MYPICTURES);
266 CSIDL_TO_STR(CSIDL_PROFILE);
267 CSIDL_TO_STR(CSIDL_SYSTEMX86);
268 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
269 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
270 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
271 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
272 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
273 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
274 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
275 CSIDL_TO_STR(CSIDL_CONNECTIONS);
276 CSIDL_TO_STR(CSIDL_PROFILES);
277 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
278 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
279 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
280 CSIDL_TO_STR(CSIDL_RESOURCES);
281 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
282 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
283 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
284 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
287 sprintf(unknown, "unknown (0x%04x)", folder);
292 static const char *printGUID(const GUID *guid, char * guidSTR)
294 if (!guid) return NULL;
296 sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
297 guid->Data1, guid->Data2, guid->Data3,
298 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
299 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
303 static void testSHGetFolderLocationInvalidArgs(void)
308 if (!pSHGetFolderLocation) return;
310 /* check a bogus CSIDL: */
312 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
313 ok(hr == E_INVALIDARG,
314 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl) returned 0x%08x, expected E_INVALIDARG\n", hr);
316 IMalloc_Free(pMalloc, pidl);
317 /* check a bogus user token: */
319 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
320 ok(hr == E_FAIL || hr == E_HANDLE,
321 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl) returned 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
323 IMalloc_Free(pMalloc, pidl);
324 /* a NULL pidl pointer crashes, so don't test it */
327 static void testSHGetSpecialFolderLocationInvalidArgs(void)
329 LPITEMIDLIST pidl = NULL;
332 if (!pSHGetSpecialFolderLocation) return;
334 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
335 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
336 ok(hr == E_INVALIDARG,
337 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08x, "
338 "expected E_INVALIDARG\n", hr);
341 static void testSHGetFolderPathInvalidArgs(void)
346 if (!pSHGetFolderPathA) return;
348 /* expect 2's a bogus handle, especially since we didn't open it */
349 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2,
350 SHGFP_TYPE_DEFAULT, path);
352 hr == E_HANDLE || /* Windows Vista and 2008 */
353 broken(hr == S_OK), /* Windows 2000 and Me */
354 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_FAIL\n", hr);
355 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
356 ok(hr == E_INVALIDARG,
357 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_INVALIDARG\n", hr);
360 static void testSHGetSpecialFolderPathInvalidArgs(void)
365 if (!pSHGetSpecialFolderPathA) return;
368 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
370 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE) returned TRUE, expected FALSE\n");
372 /* odd but true: calling with a NULL path still succeeds if it's a real
373 * dir (on some windows platform). on winME it generates exception.
375 ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
377 "SHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE) returned FALSE, expected TRUE\n");
378 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
380 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE) returned TRUE, expected FALSE\n");
383 static void testApiParameters(void)
385 testSHGetFolderLocationInvalidArgs();
386 testSHGetSpecialFolderLocationInvalidArgs();
387 testSHGetFolderPathInvalidArgs();
388 testSHGetSpecialFolderPathInvalidArgs();
391 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
392 static BYTE testSHGetFolderLocation(int folder)
398 /* treat absence of function as success */
399 if (!pSHGetFolderLocation) return TRUE;
402 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
407 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
409 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
410 getFolderName(folder));
412 ret = pidlLast->mkid.abID[0];
413 IMalloc_Free(pMalloc, pidl);
419 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
420 static BYTE testSHGetSpecialFolderLocation(int folder)
426 /* treat absence of function as success */
427 if (!pSHGetSpecialFolderLocation) return TRUE;
430 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
435 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
438 "%s: ILFindLastID failed\n", getFolderName(folder));
440 ret = pidlLast->mkid.abID[0];
441 IMalloc_Free(pMalloc, pidl);
447 static void testSHGetFolderPath(BOOL optional, int folder)
452 if (!pSHGetFolderPathA) return;
454 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
455 ok(SUCCEEDED(hr) || optional,
456 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
459 static void testSHGetSpecialFolderPath(BOOL optional, int folder)
464 if (!pSHGetSpecialFolderPathA) return;
466 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
467 if (ret && winetest_interactive)
468 printf("%s: %s\n", getFolderName(folder), path);
470 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
471 getFolderName(folder));
474 static void testShellValues(const struct shellExpectedValues testEntries[],
475 int numEntries, BOOL optional)
479 for (i = 0; i < numEntries; i++)
483 BOOL foundTypeMatch = FALSE;
485 if (pSHGetFolderLocation)
487 type = testSHGetFolderLocation(testEntries[i].folder);
488 for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
489 if (testEntries[i].types[j] == type)
490 foundTypeMatch = TRUE;
491 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
492 "%s has unexpected type %d (0x%02x)\n",
493 getFolderName(testEntries[i].folder), type, type);
495 type = testSHGetSpecialFolderLocation(testEntries[i].folder);
496 for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
497 j < testEntries[i].numTypes; j++)
498 if (testEntries[i].types[j] == type)
499 foundTypeMatch = TRUE;
500 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
501 "%s has unexpected type %d (0x%02x)\n",
502 getFolderName(testEntries[i].folder), type, type);
509 testSHGetFolderPath(optional, testEntries[i].folder);
510 testSHGetSpecialFolderPath(optional, testEntries[i].folder);
516 /* Attempts to verify that the folder path corresponding to the folder CSIDL
517 * value has the same value as the environment variable with name envVar.
518 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
519 * set in this environment; different OS and shell version behave differently.
520 * However, if both are present, fails if envVar's value is not the same
521 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
523 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
527 if (!pSHGetSpecialFolderPathA) return;
529 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
531 char *envVal = getenv(envVar);
533 ok(!envVal || !lstrcmpiA(envVal, path),
534 "%%%s%% does not match SHGetSpecialFolderPath:\n"
535 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
536 envVar, envVar, envVal, path);
540 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
541 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
542 * fail if it isn't--that check should already have been done.
543 * Fails if the returned PIDL is a GUID whose value does not match guid.
545 static void matchGUID(int folder, const GUID *guid, const GUID *guid_alt)
550 if (!pSHGetFolderLocation) return;
554 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
557 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
559 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
560 pidlLast->mkid.abID[0] == PT_GUID))
562 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
563 char shellGuidStr[39], guidStr[39], guid_altStr[39];
566 ok(IsEqualIID(shellGuid, guid),
567 "%s: got GUID %s, expected %s\n", getFolderName(folder),
568 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr));
570 ok(IsEqualIID(shellGuid, guid) ||
571 IsEqualIID(shellGuid, guid_alt),
572 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder),
573 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr),
574 printGUID(guid_alt, guid_altStr));
576 IMalloc_Free(pMalloc, pidl);
580 static void testDesktop(void)
582 testSHGetFolderPath(FALSE, CSIDL_DESKTOP);
583 testSHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
586 /* Checks the PIDL type of all the known values. */
587 static void testPidlTypes(void)
590 testShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues),
592 testShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues),
596 /* FIXME: Should be in shobjidl.idl */
597 DEFINE_GUID(CLSID_NetworkExplorerFolder, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
599 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
600 static void testGUIDs(void)
602 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin, NULL);
603 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel, NULL);
604 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer, NULL);
605 matchGUID(CSIDL_INTERNET, &CLSID_Internet, NULL);
606 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces, &CLSID_NetworkExplorerFolder); /* Vista and higher */
607 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments, NULL);
608 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments, NULL);
611 /* Verifies various shell paths match the environment variables to which they
614 static void testEnvVars(void)
616 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
617 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
618 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
619 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
620 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
621 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON,
622 "CommonProgramFiles");
623 /* this is only set on Wine, but can't hurt to verify it: */
624 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
627 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
628 static BOOL myPathIsRootA(LPCSTR lpszPath)
630 if (lpszPath && *lpszPath &&
631 lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
632 return TRUE; /* X:\ */
635 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
641 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
642 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
648 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
649 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
650 * every shell32 version supports CSIDL_WINDOWS.
652 static void testWinDir(void)
654 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
656 if (!pSHGetSpecialFolderPathA) return;
658 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
660 myPathRemoveBackslashA(windowsShellPath);
661 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
662 myPathRemoveBackslashA(windowsDir);
663 ok(!lstrcmpiA(windowsDir, windowsShellPath),
664 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
665 windowsDir, windowsShellPath);
669 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
670 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
671 * no foul--not every shell32 version supports CSIDL_SYSTEM.
673 static void testSystemDir(void)
675 char systemShellPath[MAX_PATH], systemDir[MAX_PATH] = { 0 };
677 if (!pSHGetSpecialFolderPathA) return;
679 GetSystemDirectoryA(systemDir, sizeof(systemDir));
680 myPathRemoveBackslashA(systemDir);
681 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
683 myPathRemoveBackslashA(systemShellPath);
684 ok(!lstrcmpiA(systemDir, systemShellPath),
685 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
686 systemDir, systemShellPath);
689 if (!pGetSystemWow64DirectoryA || !pGetSystemWow64DirectoryA(systemDir, sizeof(systemDir)))
690 GetSystemDirectoryA(systemDir, sizeof(systemDir));
691 myPathRemoveBackslashA(systemDir);
692 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
694 myPathRemoveBackslashA(systemShellPath);
695 ok(!lstrcmpiA(systemDir, systemShellPath),
696 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
697 systemDir, systemShellPath);
701 /* Globals used by subprocesses */
703 static char **myARGV;
704 static char base[MAX_PATH];
705 static char selfname[MAX_PATH];
707 static int init(void)
709 myARGC = winetest_get_mainargs(&myARGV);
710 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
711 strcpy(selfname, myARGV[0]);
715 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
716 * nonexistent directory.
718 static void testNonExistentPath1(void)
722 char *p, path[MAX_PATH];
724 /* test some failure cases first: */
725 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
726 SHGFP_TYPE_CURRENT, path);
727 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
728 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
730 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0,
732 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
733 "SHGetFolderLocation returned 0x%08x\n", hr);
734 if (SUCCEEDED(hr) && pidl)
735 IMalloc_Free(pMalloc, pidl);
736 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
737 "SHGetSpecialFolderPath succeeded, expected failure\n");
739 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
740 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
741 "SHGetFolderLocation returned 0x%08x\n", hr);
742 if (SUCCEEDED(hr) && pidl)
743 IMalloc_Free(pMalloc, pidl);
744 /* now test success: */
745 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
746 SHGFP_TYPE_CURRENT, path);
751 trace("CSIDL_FAVORITES was changed to %s\n", path);
752 ret = CreateDirectoryA(path, NULL);
754 "CreateDirectoryA succeeded but should have failed "
755 "with ERROR_ALREADY_EXISTS\n");
757 ok(GetLastError() == ERROR_ALREADY_EXISTS,
758 "CreateDirectoryA failed with %d, "
759 "expected ERROR_ALREADY_EXISTS\n",
761 p = path + strlen(path);
762 strcpy(p, "\\desktop.ini");
765 SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
766 ret = RemoveDirectoryA(path);
767 ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
770 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
771 "NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", hr);
774 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
775 * original value of CSIDL_FAVORITES is restored.
777 static void testNonExistentPath2(void)
782 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
783 SHGFP_TYPE_CURRENT, path);
784 ok(SUCCEEDED(hr), "SHGetFolderPath failed: 0x%08x\n", hr);
787 static void doChild(const char *arg)
790 testNonExistentPath1();
791 else if (arg[0] == '2')
792 testNonExistentPath2();
795 /* Tests the return values from the various shell functions both with and
796 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
797 * version 5 of the shell, so don't test unless it's at least version 5.
798 * The test reads a value from the registry, modifies it, calls
799 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
800 * afterward without it. Then it restores the registry and deletes the folder
802 * One oddity with respect to restoration: shell32 caches somehow, so it needs
803 * to be reloaded in order to see the correct (restored) value.
804 * Some APIs unrelated to the ones under test may fail, but I expect they're
805 * covered by other unit tests; I just print out something about failure to
806 * help trace what's going on.
808 static void testNonExistentPath(void)
810 static const char userShellFolders[] =
811 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
812 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
815 if (!pSHGetFolderPathA) return;
816 if (!pSHGetFolderLocation) return;
817 if (!pSHGetSpecialFolderPathA) return;
818 if (!pSHGetSpecialFolderLocation) return;
819 if (!pSHFileOperationA) return;
820 if (shellVersion.dwMajorVersion < 5) return;
822 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
827 len = sizeof(originalPath);
828 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
829 (LPBYTE)&originalPath, &len))
831 size_t len = strlen(originalPath);
833 memcpy(modifiedPath, originalPath, len);
834 modifiedPath[len++] = '2';
835 modifiedPath[len++] = '\0';
836 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
837 if (!RegSetValueExA(key, "Favorites", 0, type,
838 (LPBYTE)modifiedPath, len))
840 char buffer[MAX_PATH+20];
841 STARTUPINFOA startup;
842 PROCESS_INFORMATION info;
844 sprintf(buffer, "%s tests/shellpath.c 1", selfname);
845 memset(&startup, 0, sizeof(startup));
846 startup.cb = sizeof(startup);
847 startup.dwFlags = STARTF_USESHOWWINDOW;
848 startup.dwFlags = SW_SHOWNORMAL;
849 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
851 winetest_wait_child_process( info.hProcess );
853 /* restore original values: */
854 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
855 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
856 strlen(originalPath) + 1);
859 sprintf(buffer, "%s tests/shellpath.c 2", selfname);
860 memset(&startup, 0, sizeof(startup));
861 startup.cb = sizeof(startup);
862 startup.dwFlags = STARTF_USESHOWWINDOW;
863 startup.dwFlags = SW_SHOWNORMAL;
864 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
866 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
867 "child process termination\n");
870 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
874 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
877 START_TEST(shellpath)
882 pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
883 "GetSystemWow64DirectoryA" );
889 /* Report missing functions once */
890 if (!pSHGetFolderLocation)
891 win_skip("SHGetFolderLocation is not available\n");
893 /* first test various combinations of parameters: */
896 /* check known values: */
902 testNonExistentPath();