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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesytem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
24 * - Need to verify on more systems.
37 #include "wine/test.h"
40 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
43 /* from pidl.h, not included here: */
45 #define PT_GUID 0x1f /* no path */
48 #define PT_DRIVE 0x23 /* has path */
51 #define PT_DRIVE2 0x25 /* has path */
54 #define PT_SHELLEXT 0x2e /* no path */
57 #define PT_FOLDER 0x31 /* has path */
60 #define PT_WORKGRP 0x41 /* no path */
63 #define PT_YAGUID 0x70 /* no path */
65 /* FIXME: this is used for history/favorites folders; what's a better name? */
67 #define PT_IESPECIAL2 0xb1 /* has path */
70 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
72 struct shellExpectedValues {
77 static HMODULE hShell32;
78 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
79 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
81 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
82 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
83 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
84 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
85 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
86 static DLLVERSIONINFO shellVersion = { 0 };
87 static LPMALLOC pMalloc;
88 static const struct shellExpectedValues requiredShellValues[] = {
89 { CSIDL_BITBUCKET, PT_GUID },
90 { CSIDL_CONTROLS, PT_SHELLEXT },
91 { CSIDL_COOKIES, PT_FOLDER },
92 { CSIDL_DESKTOPDIRECTORY, PT_FOLDER },
93 { CSIDL_DRIVES, PT_GUID },
94 { CSIDL_FAVORITES, PT_FOLDER },
95 { CSIDL_FONTS, PT_FOLDER },
96 /* FIXME: the following fails in Wine, returns type PT_FOLDER
97 { CSIDL_HISTORY, PT_IESPECIAL2 },
99 { CSIDL_INTERNET, PT_GUID },
100 { CSIDL_NETHOOD, PT_FOLDER },
101 { CSIDL_NETWORK, PT_GUID },
102 { CSIDL_PRINTERS, PT_YAGUID },
103 { CSIDL_PRINTHOOD, PT_FOLDER },
104 { CSIDL_PROGRAMS, PT_FOLDER },
105 { CSIDL_RECENT, PT_FOLDER },
106 { CSIDL_SENDTO, PT_FOLDER },
107 { CSIDL_STARTMENU, PT_FOLDER },
108 { CSIDL_STARTUP, PT_FOLDER },
109 { CSIDL_TEMPLATES, PT_FOLDER },
111 static const struct shellExpectedValues optionalShellValues[] = {
112 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
113 { CSIDL_ALTSTARTUP, PT_FOLDER },
114 { CSIDL_COMMON_ALTSTARTUP, PT_FOLDER },
115 { CSIDL_COMMON_OEM_LINKS, PT_FOLDER },
117 /* Windows NT-only: */
118 { CSIDL_COMMON_DESKTOPDIRECTORY, PT_FOLDER },
119 { CSIDL_COMMON_DOCUMENTS, PT_SHELLEXT },
120 { CSIDL_COMMON_FAVORITES, PT_FOLDER },
121 { CSIDL_COMMON_PROGRAMS, PT_FOLDER },
122 { CSIDL_COMMON_STARTMENU, PT_FOLDER },
123 { CSIDL_COMMON_STARTUP, PT_FOLDER },
124 { CSIDL_COMMON_TEMPLATES, PT_FOLDER },
125 /* first appearing in shell32 version 4.71: */
126 { CSIDL_APPDATA, PT_FOLDER },
127 /* first appearing in shell32 version 4.72: */
128 { CSIDL_INTERNET_CACHE, PT_IESPECIAL2 },
129 /* first appearing in shell32 version 5.0: */
130 { CSIDL_ADMINTOOLS, PT_FOLDER },
131 { CSIDL_COMMON_APPDATA, PT_FOLDER },
132 { CSIDL_LOCAL_APPDATA, PT_FOLDER },
133 { CSIDL_MYDOCUMENTS, PT_FOLDER },
134 { CSIDL_MYMUSIC, PT_FOLDER },
135 { CSIDL_MYPICTURES, PT_FOLDER },
136 { CSIDL_MYVIDEO, PT_FOLDER },
137 { CSIDL_PROFILE, PT_FOLDER },
138 { CSIDL_PROGRAM_FILES, PT_FOLDER },
139 { CSIDL_PROGRAM_FILESX86, PT_FOLDER },
140 { CSIDL_PROGRAM_FILES_COMMON, PT_FOLDER },
141 { CSIDL_PROGRAM_FILES_COMMONX86, PT_FOLDER },
142 { CSIDL_SYSTEM, PT_FOLDER },
143 { CSIDL_WINDOWS, PT_FOLDER },
144 /* first appearing in shell32 6.0: */
145 { CSIDL_CDBURN_AREA, PT_FOLDER },
146 { CSIDL_COMMON_MUSIC, PT_FOLDER },
147 { CSIDL_COMMON_PICTURES, PT_FOLDER },
148 { CSIDL_COMMON_VIDEO, PT_FOLDER },
149 { CSIDL_COMPUTERSNEARME, PT_WORKGRP },
150 { CSIDL_RESOURCES, PT_FOLDER },
151 { CSIDL_RESOURCES_LOCALIZED, PT_FOLDER },
154 static void loadShell32(void)
156 hShell32 = LoadLibraryA("shell32");
159 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
161 pSHGetFolderPathA = (void *)GetProcAddress(hShell32,
163 pSHGetFolderLocation = (void *)GetProcAddress(hShell32,
164 "SHGetFolderLocation");
165 pSHGetSpecialFolderPathA = (void *)GetProcAddress(hShell32,
166 "SHGetSpecialFolderPathA");
167 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32,
168 "SHGetSpecialFolderLocation");
169 pDllGetVersion = (void *)GetProcAddress(hShell32, "DllGetVersion");
170 pILFindLastID = (void *)GetProcAddress(hShell32, "ILFindLastID");
172 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
173 pSHFileOperationA = (void *)GetProcAddress(hShell32,
175 pSHGetMalloc = (void *)GetProcAddress(hShell32, "SHGetMalloc");
177 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
180 HRESULT hr = pSHGetMalloc(&pMalloc);
182 ok(SUCCEEDED(hr), "SHGetMalloc failed: 0x%08lx\n", hr);
183 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
188 shellVersion.cbSize = sizeof(shellVersion);
189 pDllGetVersion(&shellVersion);
190 if (winetest_interactive)
191 printf("shell32 version is %ld.%ld\n",
192 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
197 #ifndef CSIDL_PROFILES
198 #define CSIDL_PROFILES 0x003e
201 /* A couple utility printing functions */
202 static const char *getFolderName(int folder)
204 static char unknown[17];
206 #define CSIDL_TO_STR(x) case x: return#x;
209 CSIDL_TO_STR(CSIDL_DESKTOP);
210 CSIDL_TO_STR(CSIDL_INTERNET);
211 CSIDL_TO_STR(CSIDL_PROGRAMS);
212 CSIDL_TO_STR(CSIDL_CONTROLS);
213 CSIDL_TO_STR(CSIDL_PRINTERS);
214 CSIDL_TO_STR(CSIDL_PERSONAL);
215 CSIDL_TO_STR(CSIDL_FAVORITES);
216 CSIDL_TO_STR(CSIDL_STARTUP);
217 CSIDL_TO_STR(CSIDL_RECENT);
218 CSIDL_TO_STR(CSIDL_SENDTO);
219 CSIDL_TO_STR(CSIDL_BITBUCKET);
220 CSIDL_TO_STR(CSIDL_STARTMENU);
221 CSIDL_TO_STR(CSIDL_MYDOCUMENTS);
222 CSIDL_TO_STR(CSIDL_MYMUSIC);
223 CSIDL_TO_STR(CSIDL_MYVIDEO);
224 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
225 CSIDL_TO_STR(CSIDL_DRIVES);
226 CSIDL_TO_STR(CSIDL_NETWORK);
227 CSIDL_TO_STR(CSIDL_NETHOOD);
228 CSIDL_TO_STR(CSIDL_FONTS);
229 CSIDL_TO_STR(CSIDL_TEMPLATES);
230 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
231 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
232 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
233 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
234 CSIDL_TO_STR(CSIDL_APPDATA);
235 CSIDL_TO_STR(CSIDL_PRINTHOOD);
236 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
237 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
238 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
239 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
240 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
241 CSIDL_TO_STR(CSIDL_COOKIES);
242 CSIDL_TO_STR(CSIDL_HISTORY);
243 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
244 CSIDL_TO_STR(CSIDL_WINDOWS);
245 CSIDL_TO_STR(CSIDL_SYSTEM);
246 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
247 CSIDL_TO_STR(CSIDL_MYPICTURES);
248 CSIDL_TO_STR(CSIDL_PROFILE);
249 CSIDL_TO_STR(CSIDL_SYSTEMX86);
250 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
251 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
252 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
253 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
254 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
255 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
256 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
257 CSIDL_TO_STR(CSIDL_CONNECTIONS);
258 CSIDL_TO_STR(CSIDL_PROFILES);
259 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
260 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
261 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
262 CSIDL_TO_STR(CSIDL_RESOURCES);
263 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
264 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
265 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
266 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
269 wnsprintfA(unknown, sizeof(unknown), "unknown (0x%04x)", folder);
274 static const char *printGUID(const GUID *guid)
276 static char guidSTR[39];
278 if (!guid) return NULL;
280 wnsprintfA(guidSTR, sizeof(guidSTR),
281 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
282 guid->Data1, guid->Data2, guid->Data3,
283 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
284 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
288 static void testSHGetFolderLocationInvalidArgs(void)
293 if (!pSHGetFolderLocation) return;
295 /* check a bogus CSIDL: */
297 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
298 ok(hr == E_INVALIDARG,
299 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl)\n"
300 "returned 0x%08lx, expected E_INVALIDARG\n", hr);
302 IMalloc_Free(pMalloc, pidl);
303 /* check a bogus user token: */
305 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
307 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl)\n"
308 "returned 0x%08lx, expected E_FAIL\n", hr);
310 IMalloc_Free(pMalloc, pidl);
311 /* check reserved is not zero: */
313 hr = pSHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl);
314 ok(hr == E_INVALIDARG,
315 "SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl)\n"
316 "returned 0x%08lx, expected E_INVALIDARG\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%08lx, "
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 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path)\n"
348 "returned 0x%08lx, expected E_FAIL\n", hr);
349 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
350 ok(hr == E_INVALIDARG,
351 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path)\n"
352 "returned 0x%08lx, expected E_INVALIDARG\n", hr);
355 static void testSHGetSpecialFolderPathInvalidArgs(void)
360 if (!pSHGetSpecialFolderPathA) return;
362 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
364 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE)\n"
365 "returned TRUE, expected FALSE\n");
366 /* odd but true: calling with a NULL path still succeeds if it's a real
369 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_PROGRAMS, FALSE);
371 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_PROGRAMS, FALSE)\n"
372 "returned FALSE, expected TRUE\n");
373 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
375 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE)\n"
376 "returned TRUE, expected FALSE\n");
379 static void testApiParameters(void)
381 testSHGetFolderLocationInvalidArgs();
382 testSHGetSpecialFolderLocationInvalidArgs();
383 testSHGetFolderPathInvalidArgs();
384 testSHGetSpecialFolderPathInvalidArgs();
387 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
388 static BYTE testSHGetFolderLocation(BOOL optional, int folder)
394 /* treat absence of function as success */
395 if (!pSHGetFolderLocation) return TRUE;
398 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
399 ok(SUCCEEDED(hr) || optional,
400 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
401 "failed: 0x%08lx\n", getFolderName(folder), hr);
405 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
406 "succeeded, but returned pidl is NULL\n", getFolderName(folder));
409 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
411 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
412 getFolderName(folder));
414 ret = pidlLast->mkid.abID[0];
415 IMalloc_Free(pMalloc, pidl);
421 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
422 static BYTE testSHGetSpecialFolderLocation(BOOL optional, int folder)
428 /* treat absence of function as success */
429 if (!pSHGetSpecialFolderLocation) return TRUE;
432 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
433 ok(SUCCEEDED(hr) || optional,
434 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
435 "failed: 0x%08lx\n", getFolderName(folder), hr);
439 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
440 "succeeded, but returned pidl is NULL\n", getFolderName(folder));
443 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
446 "%s: ILFindLastID failed\n", getFolderName(folder));
448 ret = pidlLast->mkid.abID[0];
449 IMalloc_Free(pMalloc, pidl);
455 static void testSHGetFolderPath(BOOL optional, int folder)
460 if (!pSHGetFolderPathA) return;
462 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
463 ok(SUCCEEDED(hr) || optional,
464 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path)\n"
465 "failed: 0x%08lx\n", getFolderName(folder), hr);
468 static void testSHGetSpecialFolderPath(BOOL optional, int folder)
473 if (!pSHGetSpecialFolderPathA) return;
475 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
476 if (ret && winetest_interactive)
477 printf("%s: %s\n", getFolderName(folder), path);
479 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
480 getFolderName(folder));
483 static void testShellValues(const struct shellExpectedValues testEntries[],
484 int numEntries, BOOL optional)
488 for (i = 0; i < numEntries; i++)
492 type = testSHGetFolderLocation(optional, testEntries[i].folder);
493 ok(type == testEntries[i].pidlType || optional,
494 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
495 getFolderName(testEntries[i].folder), type, type,
496 testEntries[i].pidlType, testEntries[i].pidlType);
497 type = testSHGetSpecialFolderLocation(optional, testEntries[i].folder);
498 ok(type == testEntries[i].pidlType || optional,
499 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
500 getFolderName(testEntries[i].folder), type, type,
501 testEntries[i].pidlType, testEntries[i].pidlType);
508 testSHGetFolderPath(optional, testEntries[i].folder);
509 testSHGetSpecialFolderPath(optional, testEntries[i].folder);
515 /* Attempts to verify that the folder path corresponding to the folder CSIDL
516 * value has the same value as the environment variable with name envVar.
517 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
518 * set in this environment; different OS and shell version behave differently.
519 * However, if both are present, fails if envVar's value is not the same
520 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
522 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
526 if (!pSHGetSpecialFolderPathA) return;
528 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
530 char *envVal = getenv(envVar);
532 ok(!envVal || !lstrcmpiA(envVal, path),
533 "%%%s%% does not match SHGetSpecialFolderPath:\n"
534 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
535 envVar, envVar, envVal, path);
539 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
540 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
541 * fail if it isn't--that check should already have been done.
542 * Fails if the returned PIDL is a GUID whose value does not match guid.
544 static void matchGUID(int folder, const GUID *guid)
549 if (!pSHGetFolderLocation) return;
553 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
556 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
558 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
559 pidlLast->mkid.abID[0] == PT_GUID))
561 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
563 ok(IsEqualIID(shellGuid, guid),
564 "%s: got GUID %s, expected %s\n", getFolderName(folder),
565 printGUID(shellGuid), printGUID(guid));
567 IMalloc_Free(pMalloc, pidl);
571 static void testDesktop(void)
573 testSHGetFolderPath(FALSE, CSIDL_DESKTOP);
574 testSHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
575 /* Test the desktop; even though SHITEMID should always contain abID of at
576 * least one type, when cb is 0 its value is undefined. So don't check
577 * what the returned type is, just make sure it exists.
579 testSHGetFolderLocation(FALSE, CSIDL_DESKTOP);
580 testSHGetSpecialFolderLocation(FALSE, CSIDL_DESKTOP);
583 static void testPersonal(void)
587 /* The pidl may be a real folder, or a virtual directory, or a drive if the
588 * home directory is set to the root directory of a drive.
590 type = testSHGetFolderLocation(FALSE, CSIDL_PERSONAL);
591 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE,
592 "CSIDL_PERSONAL returned invalid type 0x%02x, "
593 "expected PT_FOLDER or PT_GUID\n", type);
594 if (type == PT_FOLDER)
595 testSHGetFolderPath(FALSE, CSIDL_PERSONAL);
596 type = testSHGetSpecialFolderLocation(FALSE, CSIDL_PERSONAL);
597 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE,
598 "CSIDL_PERSONAL returned invalid type 0x%02x, "
599 "expected PT_FOLDER or PT_GUID\n", type);
600 if (type == PT_FOLDER)
601 testSHGetSpecialFolderPath(FALSE, CSIDL_PERSONAL);
604 /* Checks the PIDL type of all the known values. */
605 static void testPidlTypes(void)
609 testShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues),
611 testShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues),
615 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
616 static void testGUIDs(void)
618 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin);
619 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel);
620 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer);
621 matchGUID(CSIDL_INTERNET, &CLSID_Internet);
622 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces);
623 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments);
624 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments);
627 /* Verifies various shell paths match the environment variables to which they
630 static void testEnvVars(void)
632 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
633 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
634 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
635 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
636 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
637 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON,
638 "CommonProgramFiles");
639 /* this is only set on Wine, but can't hurt to verify it: */
640 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
643 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
644 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
645 * every shell32 version supports CSIDL_WINDOWS.
647 static void testWinDir(void)
649 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
651 if (!pSHGetSpecialFolderPathA) return;
653 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
655 PathRemoveBackslashA(windowsShellPath);
656 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
657 PathRemoveBackslashA(windowsDir);
658 ok(!lstrcmpiA(windowsDir, windowsShellPath),
659 "GetWindowsDirectory does not match SHGetSpecialFolderPath:\n"
660 "GetWindowsDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
661 windowsDir, windowsShellPath);
665 /* Verifies the shell path for CSIDL_SYSTEM and CSIDL_SYSTEMX86 matches the
666 * return from GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
667 * no foul--not every shell32 version supports CSIDL_SYSTEM.
669 static void testSystemDir(void)
671 char systemShellPath[MAX_PATH], systemDir[MAX_PATH] = { 0 };
673 if (!pSHGetSpecialFolderPathA) return;
675 GetSystemDirectoryA(systemDir, sizeof(systemDir));
676 PathRemoveBackslashA(systemDir);
677 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
679 PathRemoveBackslashA(systemShellPath);
680 ok(!lstrcmpiA(systemDir, systemShellPath),
681 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
682 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
683 systemDir, systemShellPath);
685 /* check CSIDL_SYSTEMX86; note that this isn't always present, so don't
688 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
690 PathRemoveBackslashA(systemShellPath);
691 ok(!lstrcmpiA(systemDir, systemShellPath),
692 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
693 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
694 systemDir, systemShellPath);
698 /* Globals used by subprocesses */
700 static char **myARGV;
701 static char base[MAX_PATH];
702 static char selfname[MAX_PATH];
704 static int init(void)
706 myARGC = winetest_get_mainargs(&myARGV);
707 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
708 strcpy(selfname, myARGV[0]);
712 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
713 * nonexistent directory.
715 static void testNonExistentPath1(void)
721 /* test some failure cases first: */
722 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
723 SHGFP_TYPE_CURRENT, NULL);
724 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
725 "SHGetFolderPath returned 0x%08lx, expected 0x80070002\n", hr);
727 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0,
730 "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n", hr);
731 if (SUCCEEDED(hr) && pidl)
732 IMalloc_Free(pMalloc, pidl);
733 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
734 "SHGetSpecialFolderPath succeeded, expected failure\n");
736 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
737 ok(hr == E_FAIL, "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n",
739 if (SUCCEEDED(hr) && pidl)
740 IMalloc_Free(pMalloc, pidl);
741 /* now test success: */
742 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
743 SHGFP_TYPE_CURRENT, path);
748 if (winetest_interactive)
749 printf("CSIDL_FAVORITES was changed to %s\n", path);
750 ret = CreateDirectoryA(path, NULL);
752 "CreateDirectoryA succeeded but should have failed "
753 "with ERROR_ALREADY_EXISTS\n");
755 ok(GetLastError() == ERROR_ALREADY_EXISTS,
756 "CreateDirectoryA failed with %ld, "
757 "expected ERROR_ALREADY_EXISTS\n",
761 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
762 "NULL, SHGFP_TYPE_CURRENT, path)\nfailed: 0x%08lx\n", hr);
765 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
766 * original value of CSIDL_FAVORITES is restored.
768 static void testNonExistentPath2(void)
772 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
773 SHGFP_TYPE_CURRENT, NULL);
774 ok(SUCCEEDED(hr), "SHGetFolderPath failed: 0x%08lx\n", hr);
777 static void doChild(const char *arg)
780 testNonExistentPath1();
781 else if (arg[0] == '2')
782 testNonExistentPath2();
785 /* Tests the return values from the various shell functions both with and
786 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
787 * version 5 of the shell, so don't test unless it's at least version 5.
788 * The test reads a value from the registry, modifies it, calls
789 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
790 * afterward without it. Then it restores the registry and deletes the folder
792 * One oddity with respect to restoration: shell32 caches somehow, so it needs
793 * to be reloaded in order to see the correct (restored) value.
794 * Some APIs unrelated to the ones under test may fail, but I expect they're
795 * covered by other unit tests; I just print out something about failure to
796 * help trace what's going on.
798 static void testNonExistentPath(void)
800 static const char userShellFolders[] =
801 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
802 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
805 if (!pSHGetFolderPathA) return;
806 if (!pSHGetFolderLocation) return;
807 if (!pSHGetSpecialFolderPathA) return;
808 if (!pSHGetSpecialFolderLocation) return;
809 if (!pSHFileOperationA) return;
810 if (shellVersion.dwMajorVersion < 5) return;
812 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
817 len = sizeof(originalPath);
818 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
819 (LPBYTE)&originalPath, &len))
821 size_t len = strlen(originalPath);
823 memcpy(modifiedPath, originalPath, len);
824 modifiedPath[len++] = '2';
825 modifiedPath[len++] = '\0';
826 if (winetest_interactive)
827 printf("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
828 if (!RegSetValueExA(key, "Favorites", 0, type, modifiedPath, len))
830 char buffer[MAX_PATH];
831 STARTUPINFOA startup;
832 PROCESS_INFORMATION info;
836 wnsprintfA(buffer, sizeof(buffer), "%s tests/shellpath.c 1",
838 memset(&startup, 0, sizeof(startup));
839 startup.cb = sizeof(startup);
840 startup.dwFlags = STARTF_USESHOWWINDOW;
841 startup.dwFlags = SW_SHOWNORMAL;
842 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
844 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
845 "child process termination\n");
847 /* Query the path to be able to delete it below */
848 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
849 SHGFP_TYPE_CURRENT, modifiedPath);
850 ok(SUCCEEDED(hr), "SHGetFolderPathA failed: 0x%08lx\n", hr);
852 /* restore original values: */
853 if (winetest_interactive)
854 printf("Restoring CSIDL_FAVORITES to %s\n", originalPath);
855 RegSetValueExA(key, "Favorites", 0, type, originalPath,
856 strlen(originalPath) + 1);
859 wnsprintfA(buffer, sizeof(buffer), "%s tests/shellpath.c 2",
861 memset(&startup, 0, sizeof(startup));
862 startup.cb = sizeof(startup);
863 startup.dwFlags = STARTF_USESHOWWINDOW;
864 startup.dwFlags = SW_SHOWNORMAL;
865 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
867 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
868 "child process termination\n");
870 ret = RemoveDirectoryA(modifiedPath);
871 ok( ret, "RemoveDirectoryA failed: %ld\n", GetLastError());
874 else if (winetest_interactive)
875 printf("RegQueryValueExA(key, Favorites, ...) failed\n");
879 else if (winetest_interactive)
880 printf("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n",
884 START_TEST(shellpath)
889 if (!hShell32) return;
895 /* first test various combinations of parameters: */
898 /* check known values: */
904 testNonExistentPath();