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.
34 #include "wine/test.h"
37 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
40 /* from pidl.h, not included here: */
42 #define PT_GUID 0x1f /* no path */
45 #define PT_DRIVE 0x23 /* has path */
48 #define PT_DRIVE2 0x25 /* has path */
51 #define PT_SHELLEXT 0x2e /* no path */
54 #define PT_FOLDER 0x31 /* has path */
57 #define PT_WORKGRP 0x41 /* no path */
60 #define PT_YAGUID 0x70 /* no path */
62 /* FIXME: this is used for history/favorites folders; what's a better name? */
64 #define PT_IESPECIAL2 0xb1 /* has path */
67 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
69 struct shellExpectedValues {
74 static HMODULE hShell32;
75 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
76 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
78 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
79 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
80 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
81 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
82 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
83 static DLLVERSIONINFO shellVersion = { 0 };
84 static LPMALLOC pMalloc;
85 static const struct shellExpectedValues requiredShellValues[] = {
86 { CSIDL_BITBUCKET, PT_GUID },
87 { CSIDL_CONTROLS, PT_SHELLEXT },
88 { CSIDL_COOKIES, PT_FOLDER },
89 { CSIDL_DESKTOPDIRECTORY, PT_FOLDER },
90 { CSIDL_DRIVES, PT_GUID },
91 { CSIDL_FAVORITES, PT_FOLDER },
92 { CSIDL_FONTS, PT_FOLDER },
93 /* FIXME: the following fails in Wine, returns type PT_FOLDER
94 { CSIDL_HISTORY, PT_IESPECIAL2 },
96 { CSIDL_INTERNET, PT_GUID },
97 { CSIDL_NETHOOD, PT_FOLDER },
98 { CSIDL_NETWORK, PT_GUID },
99 { CSIDL_PRINTERS, PT_YAGUID },
100 { CSIDL_PRINTHOOD, PT_FOLDER },
101 { CSIDL_PROGRAMS, PT_FOLDER },
102 { CSIDL_RECENT, PT_FOLDER },
103 { CSIDL_SENDTO, PT_FOLDER },
104 { CSIDL_STARTMENU, PT_FOLDER },
105 { CSIDL_STARTUP, PT_FOLDER },
106 { CSIDL_TEMPLATES, PT_FOLDER },
108 static const struct shellExpectedValues optionalShellValues[] = {
109 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
110 { CSIDL_ALTSTARTUP, PT_FOLDER },
111 { CSIDL_COMMON_ALTSTARTUP, PT_FOLDER },
112 { CSIDL_COMMON_OEM_LINKS, PT_FOLDER },
114 /* Windows NT-only: */
115 { CSIDL_COMMON_DESKTOPDIRECTORY, PT_FOLDER },
116 { CSIDL_COMMON_DOCUMENTS, PT_SHELLEXT },
117 { CSIDL_COMMON_FAVORITES, PT_FOLDER },
118 { CSIDL_COMMON_PROGRAMS, PT_FOLDER },
119 { CSIDL_COMMON_STARTMENU, PT_FOLDER },
120 { CSIDL_COMMON_STARTUP, PT_FOLDER },
121 { CSIDL_COMMON_TEMPLATES, PT_FOLDER },
122 /* first appearing in shell32 version 4.71: */
123 { CSIDL_APPDATA, PT_FOLDER },
124 /* first appearing in shell32 version 4.72: */
125 { CSIDL_INTERNET_CACHE, PT_IESPECIAL2 },
126 /* first appearing in shell32 version 5.0: */
127 { CSIDL_ADMINTOOLS, PT_FOLDER },
128 { CSIDL_COMMON_APPDATA, PT_FOLDER },
129 { CSIDL_LOCAL_APPDATA, PT_FOLDER },
130 { CSIDL_MYDOCUMENTS, PT_FOLDER },
131 { CSIDL_MYMUSIC, PT_FOLDER },
132 { CSIDL_MYPICTURES, PT_FOLDER },
133 { CSIDL_MYVIDEO, PT_FOLDER },
134 { CSIDL_PROFILE, PT_FOLDER },
135 { CSIDL_PROGRAM_FILES, PT_FOLDER },
136 { CSIDL_PROGRAM_FILESX86, PT_FOLDER },
137 { CSIDL_PROGRAM_FILES_COMMON, PT_FOLDER },
138 { CSIDL_PROGRAM_FILES_COMMONX86, PT_FOLDER },
139 { CSIDL_SYSTEM, PT_FOLDER },
140 { CSIDL_WINDOWS, PT_FOLDER },
141 /* first appearing in shell32 6.0: */
142 { CSIDL_CDBURN_AREA, PT_FOLDER },
143 { CSIDL_COMMON_MUSIC, PT_FOLDER },
144 { CSIDL_COMMON_PICTURES, PT_FOLDER },
145 { CSIDL_COMMON_VIDEO, PT_FOLDER },
146 { CSIDL_COMPUTERSNEARME, PT_WORKGRP },
147 { CSIDL_RESOURCES, PT_FOLDER },
148 { CSIDL_RESOURCES_LOCALIZED, PT_FOLDER },
151 static void loadShell32(void)
153 hShell32 = LoadLibraryA("shell32");
156 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
158 pSHGetFolderPathA = (void *)GetProcAddress(hShell32,
160 pSHGetFolderLocation = (void *)GetProcAddress(hShell32,
161 "SHGetFolderLocation");
162 pSHGetSpecialFolderPathA = (void *)GetProcAddress(hShell32,
163 "SHGetSpecialFolderPathA");
164 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32,
165 "SHGetSpecialFolderLocation");
166 pDllGetVersion = (void *)GetProcAddress(hShell32, "DllGetVersion");
167 pILFindLastID = (void *)GetProcAddress(hShell32, "ILFindLastID");
169 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
170 pSHFileOperationA = (void *)GetProcAddress(hShell32,
172 pSHGetMalloc = (void *)GetProcAddress(hShell32, "SHGetMalloc");
174 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
177 HRESULT hr = pSHGetMalloc(&pMalloc);
179 ok(SUCCEEDED(hr), "SHGetMalloc failed: 0x%08lx\n", hr);
180 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
185 shellVersion.cbSize = sizeof(shellVersion);
186 pDllGetVersion(&shellVersion);
187 if (winetest_interactive)
188 printf("shell32 version is %ld.%ld\n",
189 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
194 #ifndef CSIDL_PROFILES
195 #define CSIDL_PROFILES 0x003e
198 /* A couple utility printing functions */
199 static const char *getFolderName(int folder)
201 static char unknown[17];
203 #define CSIDL_TO_STR(x) case x: return#x;
206 CSIDL_TO_STR(CSIDL_DESKTOP);
207 CSIDL_TO_STR(CSIDL_INTERNET);
208 CSIDL_TO_STR(CSIDL_PROGRAMS);
209 CSIDL_TO_STR(CSIDL_CONTROLS);
210 CSIDL_TO_STR(CSIDL_PRINTERS);
211 CSIDL_TO_STR(CSIDL_PERSONAL);
212 CSIDL_TO_STR(CSIDL_FAVORITES);
213 CSIDL_TO_STR(CSIDL_STARTUP);
214 CSIDL_TO_STR(CSIDL_RECENT);
215 CSIDL_TO_STR(CSIDL_SENDTO);
216 CSIDL_TO_STR(CSIDL_BITBUCKET);
217 CSIDL_TO_STR(CSIDL_STARTMENU);
218 CSIDL_TO_STR(CSIDL_MYDOCUMENTS);
219 CSIDL_TO_STR(CSIDL_MYMUSIC);
220 CSIDL_TO_STR(CSIDL_MYVIDEO);
221 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
222 CSIDL_TO_STR(CSIDL_DRIVES);
223 CSIDL_TO_STR(CSIDL_NETWORK);
224 CSIDL_TO_STR(CSIDL_NETHOOD);
225 CSIDL_TO_STR(CSIDL_FONTS);
226 CSIDL_TO_STR(CSIDL_TEMPLATES);
227 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
228 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
229 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
230 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
231 CSIDL_TO_STR(CSIDL_APPDATA);
232 CSIDL_TO_STR(CSIDL_PRINTHOOD);
233 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
234 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
235 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
236 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
237 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
238 CSIDL_TO_STR(CSIDL_COOKIES);
239 CSIDL_TO_STR(CSIDL_HISTORY);
240 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
241 CSIDL_TO_STR(CSIDL_WINDOWS);
242 CSIDL_TO_STR(CSIDL_SYSTEM);
243 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
244 CSIDL_TO_STR(CSIDL_MYPICTURES);
245 CSIDL_TO_STR(CSIDL_PROFILE);
246 CSIDL_TO_STR(CSIDL_SYSTEMX86);
247 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
248 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
249 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
250 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
251 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
252 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
253 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
254 CSIDL_TO_STR(CSIDL_CONNECTIONS);
255 CSIDL_TO_STR(CSIDL_PROFILES);
256 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
257 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
258 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
259 CSIDL_TO_STR(CSIDL_RESOURCES);
260 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
261 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
262 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
263 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
266 wnsprintfA(unknown, sizeof(unknown), "unknown (0x%04x)", folder);
271 static const char *printGUID(const GUID *guid)
273 static char guidSTR[39];
275 if (!guid) return NULL;
277 wnsprintfA(guidSTR, sizeof(guidSTR),
278 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
279 guid->Data1, guid->Data2, guid->Data3,
280 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
281 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
285 static void testSHGetFolderLocationInvalidArgs(void)
290 if (!pSHGetFolderLocation) return;
292 /* check a bogus CSIDL: */
294 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
295 ok(hr == E_INVALIDARG,
296 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl)\n"
297 "returned 0x%08lx, expected E_INVALIDARG\n", hr);
299 pMalloc->lpVtbl->Free(pMalloc, pidl);
300 /* check a bogus user token: */
302 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
304 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl)\n"
305 "returned 0x%08lx, expected E_FAIL\n", hr);
307 pMalloc->lpVtbl->Free(pMalloc, pidl);
308 /* check reserved is not zero: */
310 hr = pSHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl);
311 ok(hr == E_INVALIDARG,
312 "SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl)\n"
313 "returned 0x%08lx, expected E_INVALIDARG\n", hr);
315 pMalloc->lpVtbl->Free(pMalloc, pidl);
316 /* a NULL pidl pointer crashes, so don't test it */
319 static void testSHGetSpecialFolderLocationInvalidArgs(void)
321 LPITEMIDLIST pidl = NULL;
324 if (!pSHGetSpecialFolderLocation) return;
326 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
327 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
328 ok(hr == E_INVALIDARG,
329 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08lx, "
330 "expected E_INVALIDARG\n", hr);
333 static void testSHGetFolderPathInvalidArgs(void)
338 if (!pSHGetFolderPathA) return;
340 /* expect 2's a bogus handle, especially since we didn't open it */
341 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2,
342 SHGFP_TYPE_DEFAULT, path);
344 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path)\n"
345 "returned 0x%08lx, expected E_FAIL\n", hr);
346 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
347 ok(hr == E_INVALIDARG,
348 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path)\n"
349 "returned 0x%08lx, expected E_INVALIDARG\n", hr);
352 static void testSHGetSpecialFolderPathInvalidArgs(void)
357 if (!pSHGetSpecialFolderPathA) return;
359 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
361 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE)\n"
362 "returned TRUE, expected FALSE\n");
363 /* odd but true: calling with a NULL path still succeeds if it's a real
366 ret = pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_PROGRAMS, FALSE);
368 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_PROGRAMS, FALSE)\n"
369 "returned FALSE, expected TRUE\n");
370 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
372 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE)\n"
373 "returned TRUE, expected FALSE\n");
376 static void testApiParameters(void)
378 testSHGetFolderLocationInvalidArgs();
379 testSHGetSpecialFolderLocationInvalidArgs();
380 testSHGetFolderPathInvalidArgs();
381 testSHGetSpecialFolderPathInvalidArgs();
384 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
385 static BYTE testSHGetFolderLocation(BOOL optional, int folder)
391 /* treat absence of function as success */
392 if (!pSHGetFolderLocation) return TRUE;
395 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
396 ok(SUCCEEDED(hr) || optional,
397 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
398 "failed: 0x%08lx\n", getFolderName(folder), hr);
402 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
403 "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 pMalloc->lpVtbl->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 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
432 "failed: 0x%08lx\n", getFolderName(folder), hr);
436 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
437 "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 pMalloc->lpVtbl->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)\n"
462 "failed: 0x%08lx\n", getFolderName(folder), hr);
465 static void testSHGetSpecialFolderPath(BOOL optional, int folder)
470 if (!pSHGetSpecialFolderPathA) return;
472 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
473 if (ret && winetest_interactive)
474 printf("%s: %s\n", getFolderName(folder), path);
476 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
477 getFolderName(folder));
480 static void testShellValues(const struct shellExpectedValues testEntries[],
481 int numEntries, BOOL optional)
485 for (i = 0; i < numEntries; i++)
489 type = testSHGetFolderLocation(optional, testEntries[i].folder);
490 ok(type == testEntries[i].pidlType || optional,
491 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
492 getFolderName(testEntries[i].folder), type, type,
493 testEntries[i].pidlType, testEntries[i].pidlType);
494 type = testSHGetSpecialFolderLocation(optional, testEntries[i].folder);
495 ok(type == testEntries[i].pidlType || optional,
496 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
497 getFolderName(testEntries[i].folder), type, type,
498 testEntries[i].pidlType, testEntries[i].pidlType);
505 testSHGetFolderPath(optional, testEntries[i].folder);
506 testSHGetSpecialFolderPath(optional, testEntries[i].folder);
512 /* Attempts to verify that the folder path corresponding to the folder CSIDL
513 * value has the same value as the environment variable with name envVar.
514 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
515 * set in this environment; different OS and shell version behave differently.
516 * However, if both are present, fails if envVar's value is not the same
517 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
519 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
523 if (!pSHGetSpecialFolderPathA) return;
525 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
527 char *envVal = getenv(envVar);
529 ok(!envVal || !lstrcmpiA(envVal, path),
530 "%%%s%% does not match SHGetSpecialFolderPath:\n"
531 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
532 envVar, envVar, envVal, path);
536 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
537 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
538 * fail if it isn't--that check should already have been done.
539 * Fails if the returned PIDL is a GUID whose value does not match guid.
541 static void matchGUID(int folder, const GUID *guid)
546 if (!pSHGetFolderLocation) return;
550 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
553 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
555 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
556 pidlLast->mkid.abID[0] == PT_GUID))
558 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
560 ok(IsEqualIID(shellGuid, guid),
561 "%s: got GUID %s, expected %s\n", getFolderName(folder),
562 printGUID(shellGuid), printGUID(guid));
564 pMalloc->lpVtbl->Free(pMalloc, pidl);
568 static void testDesktop(void)
570 testSHGetFolderPath(FALSE, CSIDL_DESKTOP);
571 testSHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
572 /* Test the desktop; even though SHITEMID should always contain abID of at
573 * least one type, when cb is 0 its value is undefined. So don't check
574 * what the returned type is, just make sure it exists.
576 testSHGetFolderLocation(FALSE, CSIDL_DESKTOP);
577 testSHGetSpecialFolderLocation(FALSE, CSIDL_DESKTOP);
580 static void testPersonal(void)
584 /* The pidl may be a real folder, or a virtual directory, or a drive if the
585 * home directory is set to the root directory of a drive.
587 type = testSHGetFolderLocation(FALSE, CSIDL_PERSONAL);
588 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE,
589 "CSIDL_PERSONAL returned invalid type 0x%02x, "
590 "expected PT_FOLDER or PT_GUID\n", type);
591 if (type == PT_FOLDER)
592 testSHGetFolderPath(FALSE, CSIDL_PERSONAL);
593 type = testSHGetSpecialFolderLocation(FALSE, CSIDL_PERSONAL);
594 ok(type == PT_FOLDER || type == PT_GUID || type == PT_DRIVE,
595 "CSIDL_PERSONAL returned invalid type 0x%02x, "
596 "expected PT_FOLDER or PT_GUID\n", type);
597 if (type == PT_FOLDER)
598 testSHGetSpecialFolderPath(FALSE, CSIDL_PERSONAL);
601 /* Checks the PIDL type of all the known values. */
602 static void testPidlTypes(void)
606 testShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues),
608 testShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues),
612 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
613 static void testGUIDs(void)
615 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin);
616 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel);
617 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer);
618 matchGUID(CSIDL_INTERNET, &CLSID_Internet);
619 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces);
620 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments);
621 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments);
624 /* Verifies various shell paths match the environment variables to which they
627 static void testEnvVars(void)
629 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
630 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
631 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
632 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
633 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
634 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON,
635 "CommonProgramFiles");
636 /* this is only set on Wine, but can't hurt to verify it: */
637 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
640 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
641 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
642 * every shell32 version supports CSIDL_WINDOWS.
644 static void testWinDir(void)
646 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
648 if (!pSHGetSpecialFolderPathA) return;
650 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
652 PathRemoveBackslashA(windowsShellPath);
653 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
654 PathRemoveBackslashA(windowsDir);
655 ok(!lstrcmpiA(windowsDir, windowsShellPath),
656 "GetWindowsDirectory does not match SHGetSpecialFolderPath:\n"
657 "GetWindowsDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
658 windowsDir, windowsShellPath);
662 /* Verifies the shell path for CSIDL_SYSTEM and CSIDL_SYSTEMX86 matches the
663 * return from GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
664 * no foul--not every shell32 version supports CSIDL_SYSTEM.
666 static void testSystemDir(void)
668 char systemShellPath[MAX_PATH], systemDir[MAX_PATH] = { 0 };
670 if (!pSHGetSpecialFolderPathA) return;
672 GetSystemDirectoryA(systemDir, sizeof(systemDir));
673 PathRemoveBackslashA(systemDir);
674 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
676 PathRemoveBackslashA(systemShellPath);
677 ok(!lstrcmpiA(systemDir, systemShellPath),
678 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
679 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
680 systemDir, systemShellPath);
682 /* check CSIDL_SYSTEMX86; note that this isn't always present, so don't
685 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
687 PathRemoveBackslashA(systemShellPath);
688 ok(!lstrcmpiA(systemDir, systemShellPath),
689 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
690 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
691 systemDir, systemShellPath);
695 /* Globals used by subprocesses */
697 static char **myARGV;
698 static char base[MAX_PATH];
699 static char selfname[MAX_PATH];
701 static int init(void)
703 myARGC = winetest_get_mainargs(&myARGV);
704 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
705 strcpy(selfname, myARGV[0]);
709 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
710 * nonexistent directory.
712 static void testNonExistentPath1(void)
718 /* test some failure cases first: */
719 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
720 SHGFP_TYPE_CURRENT, NULL);
721 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
722 "SHGetFolderPath returned 0x%08lx, expected 0x80070002\n", hr);
724 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0,
727 "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n", hr);
728 if (SUCCEEDED(hr) && pidl)
729 pMalloc->lpVtbl->Free(pMalloc, pidl);
730 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
731 "SHGetSpecialFolderPath succeeded, expected failure\n");
733 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
734 ok(hr == E_FAIL, "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n",
736 if (SUCCEEDED(hr) && pidl)
737 pMalloc->lpVtbl->Free(pMalloc, pidl);
738 /* now test success: */
739 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
740 SHGFP_TYPE_CURRENT, path);
745 if (winetest_interactive)
746 printf("CSIDL_FAVORITES was changed to %s\n", path);
747 ret = CreateDirectoryA(path, NULL);
749 "CreateDirectoryA succeeded but should have failed "
750 "with ERROR_ALREADY_EXISTS\n");
752 ok(GetLastError() == ERROR_ALREADY_EXISTS,
753 "CreateDirectoryA failed with %ld, "
754 "expected ERROR_ALREADY_EXISTS\n",
758 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
759 "NULL, SHGFP_TYPE_CURRENT, path)\nfailed: 0x%08lx\n", hr);
762 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
763 * original value of CSIDL_FAVORITES is restored.
765 static void testNonExistentPath2(void)
769 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
770 SHGFP_TYPE_CURRENT, NULL);
771 ok(SUCCEEDED(hr), "SHGetFolderPath failed: 0x%08lx\n", hr);
774 static void doChild(const char *arg)
777 testNonExistentPath1();
778 else if (arg[0] == '2')
779 testNonExistentPath2();
782 /* Tests the return values from the various shell functions both with and
783 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
784 * version 5 of the shell, so don't test unless it's at least version 5.
785 * The test reads a value from the registry, modifies it, calls
786 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
787 * afterward without it. Then it restores the registry and deletes the folder
789 * One oddity with respect to restoration: shell32 caches somehow, so it needs
790 * to be reloaded in order to see the correct (restored) value.
791 * Some APIs unrelated to the ones under test may fail, but I expect they're
792 * covered by other unit tests; I just print out something about failure to
793 * help trace what's going on.
795 static void testNonExistentPath(void)
797 static const char userShellFolders[] =
798 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
799 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
802 if (!pSHGetFolderPathA) return;
803 if (!pSHGetFolderLocation) return;
804 if (!pSHGetSpecialFolderPathA) return;
805 if (!pSHGetSpecialFolderLocation) return;
806 if (!pSHFileOperationA) return;
807 if (shellVersion.dwMajorVersion < 5) return;
809 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
814 len = sizeof(originalPath);
815 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
816 (LPBYTE)&originalPath, &len))
818 size_t len = strlen(originalPath);
820 memcpy(modifiedPath, originalPath, len);
821 modifiedPath[len++] = '2';
822 modifiedPath[len++] = '\0';
823 if (winetest_interactive)
824 printf("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
825 if (!RegSetValueExA(key, "Favorites", 0, type, modifiedPath, len))
827 char buffer[MAX_PATH];
828 STARTUPINFOA startup;
829 PROCESS_INFORMATION info;
833 wnsprintfA(buffer, sizeof(buffer), "%s tests/shellpath.c 1",
835 memset(&startup, 0, sizeof(startup));
836 startup.cb = sizeof(startup);
837 startup.dwFlags = STARTF_USESHOWWINDOW;
838 startup.dwFlags = SW_SHOWNORMAL;
839 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
841 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
842 "child process termination\n");
844 /* Query the path to be able to delete it below */
845 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL,
846 SHGFP_TYPE_CURRENT, modifiedPath);
847 ok(SUCCEEDED(hr), "SHGetFolderPathA failed: 0x%08lx\n", hr);
849 /* restore original values: */
850 if (winetest_interactive)
851 printf("Restoring CSIDL_FAVORITES to %s\n", originalPath);
852 RegSetValueExA(key, "Favorites", 0, type, originalPath,
853 strlen(originalPath) + 1);
856 wnsprintfA(buffer, sizeof(buffer), "%s tests/shellpath.c 2",
858 memset(&startup, 0, sizeof(startup));
859 startup.cb = sizeof(startup);
860 startup.dwFlags = STARTF_USESHOWWINDOW;
861 startup.dwFlags = SW_SHOWNORMAL;
862 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
864 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
865 "child process termination\n");
867 ret = RemoveDirectoryA(modifiedPath);
868 ok( ret, "RemoveDirectoryA failed: %ld\n", GetLastError());
871 else if (winetest_interactive)
872 printf("RegQueryValueExA(key, Favorites, ...) failed\n");
876 else if (winetest_interactive)
877 printf("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n",
881 START_TEST(shellpath)
886 if (!hShell32) return;
892 /* first test various combinations of parameters: */
895 /* check known values: */
901 testNonExistentPath();