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).
24 * - Need to verify on more systems.
36 #include "wine/test.h"
38 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
39 * here is its original value.
41 #define OLD_CSIDL_MYDOCUMENTS 0x000c
44 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
47 /* from pidl.h, not included here: */
49 #define PT_GUID 0x1f /* no path */
52 #define PT_DRIVE 0x23 /* has path */
55 #define PT_DRIVE2 0x25 /* has path */
58 #define PT_SHELLEXT 0x2e /* no path */
61 #define PT_FOLDER 0x31 /* has path */
64 #define PT_WORKGRP 0x41 /* no path */
67 #define PT_YAGUID 0x70 /* no path */
69 /* FIXME: this is used for history/favorites folders; what's a better name? */
71 #define PT_IESPECIAL2 0xb1 /* has path */
74 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
76 struct shellExpectedValues {
82 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
83 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
84 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
86 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
87 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
88 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
89 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
90 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
91 static DLLVERSIONINFO shellVersion = { 0 };
92 static LPMALLOC pMalloc;
93 static const BYTE guidType[] = { PT_GUID };
94 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID };
95 static const BYTE folderType[] = { PT_FOLDER };
96 static const BYTE favoritesType[] = { PT_FOLDER, 0 };
97 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
98 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
99 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
100 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
101 static const BYTE shellExtType[] = { PT_SHELLEXT };
102 static const BYTE workgroupType[] = { PT_WORKGRP };
103 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
104 static const struct shellExpectedValues requiredShellValues[] = {
105 DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
106 DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
107 DECLARE_TYPE(CSIDL_COOKIES, folderType),
108 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
109 DECLARE_TYPE(CSIDL_DRIVES, guidType),
110 DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
111 DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
112 /* FIXME: the following fails in Wine, returns type PT_FOLDER
113 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
115 DECLARE_TYPE(CSIDL_INTERNET, guidType),
116 DECLARE_TYPE(CSIDL_NETHOOD, folderType),
117 DECLARE_TYPE(CSIDL_NETWORK, guidType),
118 DECLARE_TYPE(CSIDL_PRINTERS, printersType),
119 DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
120 DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
121 DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
122 DECLARE_TYPE(CSIDL_SENDTO, folderType),
123 DECLARE_TYPE(CSIDL_STARTMENU, folderType),
124 DECLARE_TYPE(CSIDL_STARTUP, folderType),
125 DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
127 static const struct shellExpectedValues optionalShellValues[] = {
128 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
129 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
130 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
131 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
133 /* Windows NT-only: */
134 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
135 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
136 DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
137 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
138 DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
139 DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
140 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
141 /* first appearing in shell32 version 4.71: */
142 DECLARE_TYPE(CSIDL_APPDATA, folderType),
143 /* first appearing in shell32 version 4.72: */
144 DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
145 /* first appearing in shell32 version 5.0: */
146 DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
147 DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
148 DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
149 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
150 DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
151 DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
152 DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
153 DECLARE_TYPE(CSIDL_PROFILE, folderType),
154 DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
155 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
156 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
157 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
158 DECLARE_TYPE(CSIDL_SYSTEM, folderType),
159 DECLARE_TYPE(CSIDL_WINDOWS, folderType),
160 /* first appearing in shell32 6.0: */
161 DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
162 DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
163 DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
164 DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
165 DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
166 DECLARE_TYPE(CSIDL_RESOURCES, folderType),
167 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
171 static void loadShell32(void)
173 HMODULE hShell32 = GetModuleHandleA("shell32");
175 #define GET_PROC(func) \
176 p ## func = (void*)GetProcAddress(hShell32, #func); \
178 trace("GetProcAddress(%s) failed\n", #func);
180 GET_PROC(DllGetVersion)
181 GET_PROC(SHGetFolderPathA)
182 GET_PROC(SHGetFolderLocation)
183 GET_PROC(SHGetSpecialFolderPathA)
184 GET_PROC(SHGetSpecialFolderLocation)
185 GET_PROC(ILFindLastID)
187 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
188 GET_PROC(SHFileOperationA)
189 GET_PROC(SHGetMalloc)
191 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
194 HRESULT hr = pSHGetMalloc(&pMalloc);
196 ok(SUCCEEDED(hr), "SHGetMalloc failed: 0x%08x\n", hr);
197 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
202 shellVersion.cbSize = sizeof(shellVersion);
203 pDllGetVersion(&shellVersion);
204 trace("shell32 version is %d.%d\n",
205 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
210 #ifndef CSIDL_PROFILES
211 #define CSIDL_PROFILES 0x003e
214 /* A couple utility printing functions */
215 static const char *getFolderName(int folder)
217 static char unknown[32];
219 #define CSIDL_TO_STR(x) case x: return#x;
222 CSIDL_TO_STR(CSIDL_DESKTOP);
223 CSIDL_TO_STR(CSIDL_INTERNET);
224 CSIDL_TO_STR(CSIDL_PROGRAMS);
225 CSIDL_TO_STR(CSIDL_CONTROLS);
226 CSIDL_TO_STR(CSIDL_PRINTERS);
227 CSIDL_TO_STR(CSIDL_PERSONAL);
228 CSIDL_TO_STR(CSIDL_FAVORITES);
229 CSIDL_TO_STR(CSIDL_STARTUP);
230 CSIDL_TO_STR(CSIDL_RECENT);
231 CSIDL_TO_STR(CSIDL_SENDTO);
232 CSIDL_TO_STR(CSIDL_BITBUCKET);
233 CSIDL_TO_STR(CSIDL_STARTMENU);
234 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
235 CSIDL_TO_STR(CSIDL_MYMUSIC);
236 CSIDL_TO_STR(CSIDL_MYVIDEO);
237 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
238 CSIDL_TO_STR(CSIDL_DRIVES);
239 CSIDL_TO_STR(CSIDL_NETWORK);
240 CSIDL_TO_STR(CSIDL_NETHOOD);
241 CSIDL_TO_STR(CSIDL_FONTS);
242 CSIDL_TO_STR(CSIDL_TEMPLATES);
243 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
244 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
245 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
246 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
247 CSIDL_TO_STR(CSIDL_APPDATA);
248 CSIDL_TO_STR(CSIDL_PRINTHOOD);
249 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
250 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
251 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
252 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
253 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
254 CSIDL_TO_STR(CSIDL_COOKIES);
255 CSIDL_TO_STR(CSIDL_HISTORY);
256 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
257 CSIDL_TO_STR(CSIDL_WINDOWS);
258 CSIDL_TO_STR(CSIDL_SYSTEM);
259 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
260 CSIDL_TO_STR(CSIDL_MYPICTURES);
261 CSIDL_TO_STR(CSIDL_PROFILE);
262 CSIDL_TO_STR(CSIDL_SYSTEMX86);
263 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
264 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
265 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
266 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
267 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
268 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
269 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
270 CSIDL_TO_STR(CSIDL_CONNECTIONS);
271 CSIDL_TO_STR(CSIDL_PROFILES);
272 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
273 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
274 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
275 CSIDL_TO_STR(CSIDL_RESOURCES);
276 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
277 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
278 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
279 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
282 sprintf(unknown, "unknown (0x%04x)", folder);
287 static const char *printGUID(const GUID *guid, char * guidSTR)
289 if (!guid) return NULL;
291 sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
292 guid->Data1, guid->Data2, guid->Data3,
293 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
294 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
298 static void testSHGetFolderLocationInvalidArgs(void)
303 if (!pSHGetFolderLocation) return;
305 /* check a bogus CSIDL: */
307 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
308 ok(hr == E_INVALIDARG,
309 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl) returned 0x%08x, expected E_INVALIDARG\n", hr);
311 IMalloc_Free(pMalloc, pidl);
312 /* check a bogus user token: */
314 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
315 ok(hr == E_FAIL || hr == E_HANDLE,
316 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl) returned 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
318 IMalloc_Free(pMalloc, pidl);
319 /* a NULL pidl pointer crashes, so don't test it */
322 static void testSHGetSpecialFolderLocationInvalidArgs(void)
324 LPITEMIDLIST pidl = NULL;
327 if (!pSHGetSpecialFolderLocation) return;
329 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
330 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
331 ok(hr == E_INVALIDARG,
332 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08x, "
333 "expected E_INVALIDARG\n", hr);
336 static void testSHGetFolderPathInvalidArgs(void)
341 if (!pSHGetFolderPathA) return;
343 /* expect 2's a bogus handle, especially since we didn't open it */
344 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2,
345 SHGFP_TYPE_DEFAULT, path);
347 hr == E_HANDLE || /* Windows Vista and 2008 */
348 broken(hr == S_OK), /* Windows 2000 and Me */
349 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_FAIL\n", hr);
350 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
351 ok(hr == E_INVALIDARG,
352 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_INVALIDARG\n", hr);
355 static void testSHGetSpecialFolderPathInvalidArgs(void)
360 if (!pSHGetSpecialFolderPathA) return;
363 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
365 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE) returned TRUE, expected FALSE\n");
367 /* odd but true: calling with a NULL path still succeeds if it's a real
368 * dir (on some windows platform). on winME it generates exception.
370 ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
372 "SHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE) returned FALSE, expected TRUE\n");
373 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
375 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE) returned TRUE, expected FALSE\n");
378 static void testApiParameters(void)
380 testSHGetFolderLocationInvalidArgs();
381 testSHGetSpecialFolderLocationInvalidArgs();
382 testSHGetFolderPathInvalidArgs();
383 testSHGetSpecialFolderPathInvalidArgs();
386 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
387 static BYTE testSHGetFolderLocation(BOOL optional, int folder)
393 /* treat absence of function as success */
394 if (!pSHGetFolderLocation) return TRUE;
397 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
398 ok(SUCCEEDED(hr) || optional,
399 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl) failed: 0x%08x\n", getFolderName(folder), hr);
403 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl) succeeded, but returned pidl is NULL\n", getFolderName(folder));
406 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
408 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
409 getFolderName(folder));
411 ret = pidlLast->mkid.abID[0];
412 IMalloc_Free(pMalloc, pidl);
418 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
419 static BYTE testSHGetSpecialFolderLocation(BOOL optional, int folder)
425 /* treat absence of function as success */
426 if (!pSHGetSpecialFolderLocation) return TRUE;
429 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
430 ok(SUCCEEDED(hr) || optional ||
431 broken((folder == CSIDL_COOKIES || folder == CSIDL_INTERNET) &&
432 hr == E_INVALIDARG) /* NT4 */,
433 "SHGetSpecialFolderLocation(NULL, %s, &pidl) failed: 0x%08x\n", getFolderName(folder), hr);
437 "SHGetSpecialFolderLocation(NULL, %s, &pidl) succeeded, but returned pidl is NULL\n", getFolderName(folder));
440 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
443 "%s: ILFindLastID failed\n", getFolderName(folder));
445 ret = pidlLast->mkid.abID[0];
446 IMalloc_Free(pMalloc, pidl);
452 static void testSHGetFolderPath(BOOL optional, int folder)
457 if (!pSHGetFolderPathA) return;
459 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
460 ok(SUCCEEDED(hr) || optional,
461 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
464 static void testSHGetSpecialFolderPath(BOOL optional, int folder)
469 if (!pSHGetSpecialFolderPathA) return;
471 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
472 if (ret && winetest_interactive)
473 printf("%s: %s\n", getFolderName(folder), path);
475 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
476 getFolderName(folder));
479 static void testShellValues(const struct shellExpectedValues testEntries[],
480 int numEntries, BOOL optional)
484 for (i = 0; i < numEntries; i++)
488 BOOL foundTypeMatch = FALSE;
490 if (pSHGetFolderLocation)
492 type = testSHGetFolderLocation(optional, testEntries[i].folder);
493 for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
494 if (testEntries[i].types[j] == type)
495 foundTypeMatch = TRUE;
496 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
497 "%s has unexpected type %d (0x%02x)\n",
498 getFolderName(testEntries[i].folder), type, type);
500 type = testSHGetSpecialFolderLocation(optional, testEntries[i].folder);
501 for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
502 j < testEntries[i].numTypes; j++)
503 if (testEntries[i].types[j] == type)
504 foundTypeMatch = TRUE;
505 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
506 "%s has unexpected type %d (0x%02x)\n",
507 getFolderName(testEntries[i].folder), type, type);
514 testSHGetFolderPath(optional, testEntries[i].folder);
515 testSHGetSpecialFolderPath(optional, testEntries[i].folder);
521 /* Attempts to verify that the folder path corresponding to the folder CSIDL
522 * value has the same value as the environment variable with name envVar.
523 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
524 * set in this environment; different OS and shell version behave differently.
525 * However, if both are present, fails if envVar's value is not the same
526 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
528 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
532 if (!pSHGetSpecialFolderPathA) return;
534 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
536 char *envVal = getenv(envVar);
538 ok(!envVal || !lstrcmpiA(envVal, path),
539 "%%%s%% does not match SHGetSpecialFolderPath:\n"
540 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
541 envVar, envVar, envVal, path);
545 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
546 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
547 * fail if it isn't--that check should already have been done.
548 * Fails if the returned PIDL is a GUID whose value does not match guid.
550 static void matchGUID(int folder, const GUID *guid)
555 if (!pSHGetFolderLocation) return;
559 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
562 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
564 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
565 pidlLast->mkid.abID[0] == PT_GUID))
567 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
568 char shellGuidStr[39], guidStr[39];
570 ok(IsEqualIID(shellGuid, guid),
571 "%s: got GUID %s, expected %s\n", getFolderName(folder),
572 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr));
574 IMalloc_Free(pMalloc, pidl);
578 static void testDesktop(void)
580 testSHGetFolderPath(FALSE, CSIDL_DESKTOP);
581 testSHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
582 /* Test the desktop; even though SHITEMID should always contain abID of at
583 * least one type, when cb is 0 its value is undefined. So don't check
584 * what the returned type is, just make sure it exists.
586 testSHGetFolderLocation(FALSE, CSIDL_DESKTOP);
587 testSHGetSpecialFolderLocation(FALSE, CSIDL_DESKTOP);
590 static void testPersonal(void)
594 /* The pidl may be a real folder, or a virtual directory, or a drive if the
595 * home directory is set to the root directory of a drive.
597 if (pSHGetFolderLocation)
599 type = testSHGetFolderLocation(FALSE, CSIDL_PERSONAL);
600 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE ||
601 broken(type == 0xff) /* Win9x */,
602 "CSIDL_PERSONAL returned invalid type 0x%02x, "
603 "expected PT_FOLDER or PT_GUID or PT_DRIVE\n", type);
604 if (type == PT_FOLDER)
605 testSHGetFolderPath(FALSE, CSIDL_PERSONAL);
607 type = testSHGetSpecialFolderLocation(FALSE, CSIDL_PERSONAL);
608 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE,
609 "CSIDL_PERSONAL returned invalid type 0x%02x, "
610 "expected PT_FOLDER or PT_GUID\n", type);
611 if (type == PT_FOLDER)
612 testSHGetSpecialFolderPath(FALSE, CSIDL_PERSONAL);
615 /* Checks the PIDL type of all the known values. */
616 static void testPidlTypes(void)
620 testShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues),
622 testShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues),
626 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
627 static void testGUIDs(void)
629 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin);
630 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel);
631 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer);
632 matchGUID(CSIDL_INTERNET, &CLSID_Internet);
633 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces);
634 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments);
635 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments);
638 /* Verifies various shell paths match the environment variables to which they
641 static void testEnvVars(void)
643 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
644 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
645 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
646 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
647 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
648 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON,
649 "CommonProgramFiles");
650 /* this is only set on Wine, but can't hurt to verify it: */
651 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
654 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
655 static BOOL myPathIsRootA(LPCSTR lpszPath)
657 if (lpszPath && *lpszPath &&
658 lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
659 return TRUE; /* X:\ */
662 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
668 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
669 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
675 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
676 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
677 * every shell32 version supports CSIDL_WINDOWS.
679 static void testWinDir(void)
681 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
683 if (!pSHGetSpecialFolderPathA) return;
685 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
687 myPathRemoveBackslashA(windowsShellPath);
688 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
689 myPathRemoveBackslashA(windowsDir);
690 ok(!lstrcmpiA(windowsDir, windowsShellPath),
691 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
692 windowsDir, windowsShellPath);
696 /* Verifies the shell path for CSIDL_SYSTEM and CSIDL_SYSTEMX86 matches the
697 * return from GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
698 * no foul--not every shell32 version supports CSIDL_SYSTEM.
700 static void testSystemDir(void)
702 char systemShellPath[MAX_PATH], systemDir[MAX_PATH] = { 0 };
704 if (!pSHGetSpecialFolderPathA) return;
706 GetSystemDirectoryA(systemDir, sizeof(systemDir));
707 myPathRemoveBackslashA(systemDir);
708 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
710 myPathRemoveBackslashA(systemShellPath);
711 ok(!lstrcmpiA(systemDir, systemShellPath),
712 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
713 systemDir, systemShellPath);
715 /* check CSIDL_SYSTEMX86; note that this isn't always present, so don't
718 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
720 myPathRemoveBackslashA(systemShellPath);
721 ok(!lstrcmpiA(systemDir, systemShellPath),
722 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
723 systemDir, systemShellPath);
727 /* Globals used by subprocesses */
729 static char **myARGV;
730 static char base[MAX_PATH];
731 static char selfname[MAX_PATH];
733 static int init(void)
735 myARGC = winetest_get_mainargs(&myARGV);
736 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
737 strcpy(selfname, myARGV[0]);
741 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
742 * nonexistent directory.
744 static void testNonExistentPath1(void)
748 char *p, path[MAX_PATH];
750 /* test some failure cases first: */
751 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
752 SHGFP_TYPE_CURRENT, path);
753 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
754 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
756 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0,
758 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
759 "SHGetFolderLocation returned 0x%08x\n", hr);
760 if (SUCCEEDED(hr) && pidl)
761 IMalloc_Free(pMalloc, pidl);
762 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
763 "SHGetSpecialFolderPath succeeded, expected failure\n");
765 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
766 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
767 "SHGetFolderLocation returned 0x%08x\n", hr);
768 if (SUCCEEDED(hr) && pidl)
769 IMalloc_Free(pMalloc, pidl);
770 /* now test success: */
771 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
772 SHGFP_TYPE_CURRENT, path);
777 trace("CSIDL_FAVORITES was changed to %s\n", path);
778 ret = CreateDirectoryA(path, NULL);
780 "CreateDirectoryA succeeded but should have failed "
781 "with ERROR_ALREADY_EXISTS\n");
783 ok(GetLastError() == ERROR_ALREADY_EXISTS,
784 "CreateDirectoryA failed with %d, "
785 "expected ERROR_ALREADY_EXISTS\n",
787 p = path + strlen(path);
788 strcpy(p, "\\desktop.ini");
791 SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
792 ret = RemoveDirectoryA(path);
793 ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
796 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
797 "NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", hr);
800 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
801 * original value of CSIDL_FAVORITES is restored.
803 static void testNonExistentPath2(void)
808 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
809 SHGFP_TYPE_CURRENT, path);
810 ok(SUCCEEDED(hr), "SHGetFolderPath failed: 0x%08x\n", hr);
813 static void doChild(const char *arg)
816 testNonExistentPath1();
817 else if (arg[0] == '2')
818 testNonExistentPath2();
821 /* Tests the return values from the various shell functions both with and
822 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
823 * version 5 of the shell, so don't test unless it's at least version 5.
824 * The test reads a value from the registry, modifies it, calls
825 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
826 * afterward without it. Then it restores the registry and deletes the folder
828 * One oddity with respect to restoration: shell32 caches somehow, so it needs
829 * to be reloaded in order to see the correct (restored) value.
830 * Some APIs unrelated to the ones under test may fail, but I expect they're
831 * covered by other unit tests; I just print out something about failure to
832 * help trace what's going on.
834 static void testNonExistentPath(void)
836 static const char userShellFolders[] =
837 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
838 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
841 if (!pSHGetFolderPathA) return;
842 if (!pSHGetFolderLocation) return;
843 if (!pSHGetSpecialFolderPathA) return;
844 if (!pSHGetSpecialFolderLocation) return;
845 if (!pSHFileOperationA) return;
846 if (shellVersion.dwMajorVersion < 5) return;
848 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
853 len = sizeof(originalPath);
854 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
855 (LPBYTE)&originalPath, &len))
857 size_t len = strlen(originalPath);
859 memcpy(modifiedPath, originalPath, len);
860 modifiedPath[len++] = '2';
861 modifiedPath[len++] = '\0';
862 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
863 if (!RegSetValueExA(key, "Favorites", 0, type,
864 (LPBYTE)modifiedPath, len))
866 char buffer[MAX_PATH+20];
867 STARTUPINFOA startup;
868 PROCESS_INFORMATION info;
870 sprintf(buffer, "%s tests/shellpath.c 1", selfname);
871 memset(&startup, 0, sizeof(startup));
872 startup.cb = sizeof(startup);
873 startup.dwFlags = STARTF_USESHOWWINDOW;
874 startup.dwFlags = SW_SHOWNORMAL;
875 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
877 winetest_wait_child_process( info.hProcess );
879 /* restore original values: */
880 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
881 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
882 strlen(originalPath) + 1);
885 sprintf(buffer, "%s tests/shellpath.c 2", selfname);
886 memset(&startup, 0, sizeof(startup));
887 startup.cb = sizeof(startup);
888 startup.dwFlags = STARTF_USESHOWWINDOW;
889 startup.dwFlags = SW_SHOWNORMAL;
890 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
892 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
893 "child process termination\n");
896 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
900 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
903 START_TEST(shellpath)
913 /* Report missing functions once */
914 if (!pSHGetFolderLocation)
915 skip("SHGetFolderLocation is not available\n");
917 /* first test various combinations of parameters: */
920 /* check known values: */
926 testNonExistentPath();