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.
36 #include "wine/test.h"
39 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
42 /* from pidl.h, not included here: */
44 #define PT_GUID 0x1f /* no path */
47 #define PT_DRIVE 0x23 /* has path */
50 #define PT_DRIVE2 0x25 /* has path */
53 #define PT_SHELLEXT 0x2e /* no path */
56 #define PT_FOLDER 0x31 /* has path */
59 #define PT_WORKGRP 0x41 /* no path */
62 #define PT_YAGUID 0x70 /* no path */
64 /* FIXME: this is used for history/favorites folders; what's a better name? */
66 #define PT_IESPECIAL2 0xb1 /* has path */
69 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
71 struct shellExpectedValues
{
76 static HMODULE hShell32
;
77 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
78 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
80 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
81 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
82 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
83 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
84 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
85 static DLLVERSIONINFO shellVersion
= { 0 };
86 static LPMALLOC pMalloc
;
87 static const struct shellExpectedValues requiredShellValues
[] = {
88 { CSIDL_BITBUCKET
, PT_GUID
},
89 { CSIDL_CONTROLS
, PT_SHELLEXT
},
90 { CSIDL_COOKIES
, PT_FOLDER
},
91 { CSIDL_DESKTOPDIRECTORY
, PT_FOLDER
},
92 { CSIDL_DRIVES
, PT_GUID
},
93 { CSIDL_FAVORITES
, PT_FOLDER
},
94 { CSIDL_FONTS
, PT_FOLDER
},
95 /* FIXME: the following fails in Wine, returns type PT_FOLDER
96 { CSIDL_HISTORY, PT_IESPECIAL2 },
98 { CSIDL_INTERNET
, PT_GUID
},
99 { CSIDL_NETHOOD
, PT_FOLDER
},
100 { CSIDL_NETWORK
, PT_GUID
},
101 { CSIDL_PRINTERS
, PT_YAGUID
},
102 { CSIDL_PRINTHOOD
, PT_FOLDER
},
103 { CSIDL_PROGRAMS
, PT_FOLDER
},
104 { CSIDL_RECENT
, PT_FOLDER
},
105 { CSIDL_SENDTO
, PT_FOLDER
},
106 { CSIDL_STARTMENU
, PT_FOLDER
},
107 { CSIDL_STARTUP
, PT_FOLDER
},
108 { CSIDL_TEMPLATES
, PT_FOLDER
},
110 static const struct shellExpectedValues optionalShellValues
[] = {
111 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
112 { CSIDL_ALTSTARTUP, PT_FOLDER },
113 { CSIDL_COMMON_ALTSTARTUP, PT_FOLDER },
114 { CSIDL_COMMON_OEM_LINKS, PT_FOLDER },
116 /* Windows NT-only: */
117 { CSIDL_COMMON_DESKTOPDIRECTORY
, PT_FOLDER
},
118 { CSIDL_COMMON_DOCUMENTS
, PT_SHELLEXT
},
119 { CSIDL_COMMON_FAVORITES
, PT_FOLDER
},
120 { CSIDL_COMMON_PROGRAMS
, PT_FOLDER
},
121 { CSIDL_COMMON_STARTMENU
, PT_FOLDER
},
122 { CSIDL_COMMON_STARTUP
, PT_FOLDER
},
123 { CSIDL_COMMON_TEMPLATES
, PT_FOLDER
},
124 /* first appearing in shell32 version 4.71: */
125 { CSIDL_APPDATA
, PT_FOLDER
},
126 /* first appearing in shell32 version 4.72: */
127 { CSIDL_INTERNET_CACHE
, PT_IESPECIAL2
},
128 /* first appearing in shell32 version 5.0: */
129 { CSIDL_ADMINTOOLS
, PT_FOLDER
},
130 { CSIDL_COMMON_APPDATA
, PT_FOLDER
},
131 { CSIDL_LOCAL_APPDATA
, PT_FOLDER
},
132 { CSIDL_MYDOCUMENTS
, PT_FOLDER
},
133 { CSIDL_MYMUSIC
, PT_FOLDER
},
134 { CSIDL_MYPICTURES
, PT_FOLDER
},
135 { CSIDL_MYVIDEO
, PT_FOLDER
},
136 { CSIDL_PROFILE
, PT_FOLDER
},
137 { CSIDL_PROGRAM_FILES
, PT_FOLDER
},
138 { CSIDL_PROGRAM_FILESX86
, PT_FOLDER
},
139 { CSIDL_PROGRAM_FILES_COMMON
, PT_FOLDER
},
140 { CSIDL_PROGRAM_FILES_COMMONX86
, PT_FOLDER
},
141 { CSIDL_SYSTEM
, PT_FOLDER
},
142 { CSIDL_WINDOWS
, PT_FOLDER
},
143 /* first appearing in shell32 6.0: */
144 { CSIDL_CDBURN_AREA
, PT_FOLDER
},
145 { CSIDL_COMMON_MUSIC
, PT_FOLDER
},
146 { CSIDL_COMMON_PICTURES
, PT_FOLDER
},
147 { CSIDL_COMMON_VIDEO
, PT_FOLDER
},
148 { CSIDL_COMPUTERSNEARME
, PT_WORKGRP
},
149 { CSIDL_RESOURCES
, PT_FOLDER
},
150 { CSIDL_RESOURCES_LOCALIZED
, PT_FOLDER
},
153 static void loadShell32(void)
155 hShell32
= LoadLibraryA("shell32");
158 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
160 pSHGetFolderPathA
= (void *)GetProcAddress(hShell32
,
162 pSHGetFolderLocation
= (void *)GetProcAddress(hShell32
,
163 "SHGetFolderLocation");
164 pSHGetSpecialFolderPathA
= (void *)GetProcAddress(hShell32
,
165 "SHGetSpecialFolderPathA");
166 pSHGetSpecialFolderLocation
= (void *)GetProcAddress(hShell32
,
167 "SHGetSpecialFolderLocation");
168 pDllGetVersion
= (void *)GetProcAddress(hShell32
, "DllGetVersion");
169 pILFindLastID
= (void *)GetProcAddress(hShell32
, "ILFindLastID");
171 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
172 pSHFileOperationA
= (void *)GetProcAddress(hShell32
,
174 pSHGetMalloc
= (void *)GetProcAddress(hShell32
, "SHGetMalloc");
176 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
179 HRESULT hr
= pSHGetMalloc(&pMalloc
);
181 ok(SUCCEEDED(hr
), "SHGetMalloc failed: 0x%08lx\n", hr
);
182 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
187 shellVersion
.cbSize
= sizeof(shellVersion
);
188 pDllGetVersion(&shellVersion
);
189 if (winetest_interactive
)
190 printf("shell32 version is %ld.%ld\n",
191 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
196 #ifndef CSIDL_PROFILES
197 #define CSIDL_PROFILES 0x003e
200 /* A couple utility printing functions */
201 static const char *getFolderName(int folder
)
203 static char unknown
[17];
205 #define CSIDL_TO_STR(x) case x: return#x;
208 CSIDL_TO_STR(CSIDL_DESKTOP
);
209 CSIDL_TO_STR(CSIDL_INTERNET
);
210 CSIDL_TO_STR(CSIDL_PROGRAMS
);
211 CSIDL_TO_STR(CSIDL_CONTROLS
);
212 CSIDL_TO_STR(CSIDL_PRINTERS
);
213 CSIDL_TO_STR(CSIDL_PERSONAL
);
214 CSIDL_TO_STR(CSIDL_FAVORITES
);
215 CSIDL_TO_STR(CSIDL_STARTUP
);
216 CSIDL_TO_STR(CSIDL_RECENT
);
217 CSIDL_TO_STR(CSIDL_SENDTO
);
218 CSIDL_TO_STR(CSIDL_BITBUCKET
);
219 CSIDL_TO_STR(CSIDL_STARTMENU
);
220 CSIDL_TO_STR(CSIDL_MYDOCUMENTS
);
221 CSIDL_TO_STR(CSIDL_MYMUSIC
);
222 CSIDL_TO_STR(CSIDL_MYVIDEO
);
223 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
224 CSIDL_TO_STR(CSIDL_DRIVES
);
225 CSIDL_TO_STR(CSIDL_NETWORK
);
226 CSIDL_TO_STR(CSIDL_NETHOOD
);
227 CSIDL_TO_STR(CSIDL_FONTS
);
228 CSIDL_TO_STR(CSIDL_TEMPLATES
);
229 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
230 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
231 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
232 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
233 CSIDL_TO_STR(CSIDL_APPDATA
);
234 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
235 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
236 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
237 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
238 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
239 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
240 CSIDL_TO_STR(CSIDL_COOKIES
);
241 CSIDL_TO_STR(CSIDL_HISTORY
);
242 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
243 CSIDL_TO_STR(CSIDL_WINDOWS
);
244 CSIDL_TO_STR(CSIDL_SYSTEM
);
245 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
246 CSIDL_TO_STR(CSIDL_MYPICTURES
);
247 CSIDL_TO_STR(CSIDL_PROFILE
);
248 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
249 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
250 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
251 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
252 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
253 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
254 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
255 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
256 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
257 CSIDL_TO_STR(CSIDL_PROFILES
);
258 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
259 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
260 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
261 CSIDL_TO_STR(CSIDL_RESOURCES
);
262 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
263 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
264 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
265 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
268 wnsprintfA(unknown
, sizeof(unknown
), "unknown (0x%04x)", folder
);
273 static const char *printGUID(const GUID
*guid
)
275 static char guidSTR
[39];
277 if (!guid
) return NULL
;
279 wnsprintfA(guidSTR
, sizeof(guidSTR
),
280 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
281 guid
->Data1
, guid
->Data2
, guid
->Data3
,
282 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
283 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
287 static void testSHGetFolderLocationInvalidArgs(void)
292 if (!pSHGetFolderLocation
) return;
294 /* check a bogus CSIDL: */
296 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
297 ok(hr
== E_INVALIDARG
,
298 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl)\n"
299 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
301 IMalloc_Free(pMalloc
, pidl
);
302 /* check a bogus user token: */
304 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
306 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl)\n"
307 "returned 0x%08lx, expected E_FAIL\n", hr
);
309 IMalloc_Free(pMalloc
, pidl
);
310 /* check reserved is not zero: */
312 hr
= pSHGetFolderLocation(NULL
, CSIDL_DESKTOP
, NULL
, 1, &pidl
);
313 ok(hr
== E_INVALIDARG
,
314 "SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl)\n"
315 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
317 IMalloc_Free(pMalloc
, pidl
);
318 /* a NULL pidl pointer crashes, so don't test it */
321 static void testSHGetSpecialFolderLocationInvalidArgs(void)
323 LPITEMIDLIST pidl
= NULL
;
326 if (!pSHGetSpecialFolderLocation
) return;
328 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
329 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
330 ok(hr
== E_INVALIDARG
,
331 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08lx, "
332 "expected E_INVALIDARG\n", hr
);
335 static void testSHGetFolderPathInvalidArgs(void)
340 if (!pSHGetFolderPathA
) return;
342 /* expect 2's a bogus handle, especially since we didn't open it */
343 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2,
344 SHGFP_TYPE_DEFAULT
, path
);
346 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path)\n"
347 "returned 0x%08lx, expected E_FAIL\n", hr
);
348 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
349 ok(hr
== E_INVALIDARG
,
350 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path)\n"
351 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
354 static void testSHGetSpecialFolderPathInvalidArgs(void)
359 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");
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)\n"
373 "returned FALSE, expected TRUE\n");
374 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
376 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE)\n"
377 "returned TRUE, expected FALSE\n");
380 static void testApiParameters(void)
382 testSHGetFolderLocationInvalidArgs();
383 testSHGetSpecialFolderLocationInvalidArgs();
384 testSHGetFolderPathInvalidArgs();
385 testSHGetSpecialFolderPathInvalidArgs();
388 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
389 static BYTE
testSHGetFolderLocation(BOOL optional
, int folder
)
395 /* treat absence of function as success */
396 if (!pSHGetFolderLocation
) return TRUE
;
399 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
400 ok(SUCCEEDED(hr
) || optional
,
401 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
402 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
406 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
407 "succeeded, but returned pidl is NULL\n", getFolderName(folder
));
410 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
412 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
413 getFolderName(folder
));
415 ret
= pidlLast
->mkid
.abID
[0];
416 IMalloc_Free(pMalloc
, pidl
);
422 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
423 static BYTE
testSHGetSpecialFolderLocation(BOOL optional
, int folder
)
429 /* treat absence of function as success */
430 if (!pSHGetSpecialFolderLocation
) return TRUE
;
433 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
434 ok(SUCCEEDED(hr
) || optional
,
435 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
436 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
440 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
441 "succeeded, but returned pidl is NULL\n", getFolderName(folder
));
444 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
447 "%s: ILFindLastID failed\n", getFolderName(folder
));
449 ret
= pidlLast
->mkid
.abID
[0];
450 IMalloc_Free(pMalloc
, pidl
);
456 static void testSHGetFolderPath(BOOL optional
, int folder
)
461 if (!pSHGetFolderPathA
) return;
463 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
464 ok(SUCCEEDED(hr
) || optional
,
465 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path)\n"
466 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
469 static void testSHGetSpecialFolderPath(BOOL optional
, int folder
)
474 if (!pSHGetSpecialFolderPathA
) return;
476 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
477 if (ret
&& winetest_interactive
)
478 printf("%s: %s\n", getFolderName(folder
), path
);
480 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
481 getFolderName(folder
));
484 static void testShellValues(const struct shellExpectedValues testEntries
[],
485 int numEntries
, BOOL optional
)
489 for (i
= 0; i
< numEntries
; i
++)
493 type
= testSHGetFolderLocation(optional
, testEntries
[i
].folder
);
494 ok(type
== testEntries
[i
].pidlType
|| optional
,
495 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
496 getFolderName(testEntries
[i
].folder
), type
, type
,
497 testEntries
[i
].pidlType
, testEntries
[i
].pidlType
);
498 type
= testSHGetSpecialFolderLocation(optional
, testEntries
[i
].folder
);
499 ok(type
== testEntries
[i
].pidlType
|| optional
,
500 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
501 getFolderName(testEntries
[i
].folder
), type
, type
,
502 testEntries
[i
].pidlType
, testEntries
[i
].pidlType
);
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
)
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);
564 ok(IsEqualIID(shellGuid
, guid
),
565 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
566 printGUID(shellGuid
), printGUID(guid
));
568 IMalloc_Free(pMalloc
, pidl
);
572 static void testDesktop(void)
574 testSHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
575 testSHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
576 /* Test the desktop; even though SHITEMID should always contain abID of at
577 * least one type, when cb is 0 its value is undefined. So don't check
578 * what the returned type is, just make sure it exists.
580 testSHGetFolderLocation(FALSE
, CSIDL_DESKTOP
);
581 testSHGetSpecialFolderLocation(FALSE
, CSIDL_DESKTOP
);
584 static void testPersonal(void)
588 /* The pidl may be a real folder, or a virtual directory, or a drive if the
589 * home directory is set to the root directory of a drive.
591 type
= testSHGetFolderLocation(FALSE
, CSIDL_PERSONAL
);
592 ok(type
== PT_FOLDER
|| type
== PT_GUID
|| type
== PT_DRIVE
,
593 "CSIDL_PERSONAL returned invalid type 0x%02x, "
594 "expected PT_FOLDER or PT_GUID\n", type
);
595 if (type
== PT_FOLDER
)
596 testSHGetFolderPath(FALSE
, CSIDL_PERSONAL
);
597 type
= testSHGetSpecialFolderLocation(FALSE
, CSIDL_PERSONAL
);
598 ok(type
== PT_FOLDER
|| type
== PT_GUID
|| type
== PT_DRIVE
,
599 "CSIDL_PERSONAL returned invalid type 0x%02x, "
600 "expected PT_FOLDER or PT_GUID\n", type
);
601 if (type
== PT_FOLDER
)
602 testSHGetSpecialFolderPath(FALSE
, CSIDL_PERSONAL
);
605 /* Checks the PIDL type of all the known values. */
606 static void testPidlTypes(void)
610 testShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
),
612 testShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
),
616 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
617 static void testGUIDs(void)
619 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
);
620 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
);
621 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
);
622 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
);
623 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
);
624 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
);
625 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
);
628 /* Verifies various shell paths match the environment variables to which they
631 static void testEnvVars(void)
633 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
634 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
635 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
636 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
637 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
638 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
,
639 "CommonProgramFiles");
640 /* this is only set on Wine, but can't hurt to verify it: */
641 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
644 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
645 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
646 * every shell32 version supports CSIDL_WINDOWS.
648 static void testWinDir(void)
650 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
652 if (!pSHGetSpecialFolderPathA
) return;
654 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
656 PathRemoveBackslashA(windowsShellPath
);
657 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
658 PathRemoveBackslashA(windowsDir
);
659 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
660 "GetWindowsDirectory does not match SHGetSpecialFolderPath:\n"
661 "GetWindowsDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
662 windowsDir
, windowsShellPath
);
666 /* Verifies the shell path for CSIDL_SYSTEM and CSIDL_SYSTEMX86 matches the
667 * return from GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
668 * no foul--not every shell32 version supports CSIDL_SYSTEM.
670 static void testSystemDir(void)
672 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
] = { 0 };
674 if (!pSHGetSpecialFolderPathA
) return;
676 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
677 PathRemoveBackslashA(systemDir
);
678 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
680 PathRemoveBackslashA(systemShellPath
);
681 ok(!lstrcmpiA(systemDir
, systemShellPath
),
682 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
683 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
684 systemDir
, systemShellPath
);
686 /* check CSIDL_SYSTEMX86; note that this isn't always present, so don't
689 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEMX86
, FALSE
))
691 PathRemoveBackslashA(systemShellPath
);
692 ok(!lstrcmpiA(systemDir
, systemShellPath
),
693 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
694 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
695 systemDir
, systemShellPath
);
699 /* Globals used by subprocesses */
701 static char **myARGV
;
702 static char base
[MAX_PATH
];
703 static char selfname
[MAX_PATH
];
705 static int init(void)
707 myARGC
= winetest_get_mainargs(&myARGV
);
708 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
709 strcpy(selfname
, myARGV
[0]);
713 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
714 * nonexistent directory.
716 static void testNonExistentPath1(void)
722 /* test some failure cases first: */
723 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
724 SHGFP_TYPE_CURRENT
, path
);
725 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
726 "SHGetFolderPath returned 0x%08lx, expected 0x80070002\n", hr
);
728 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0,
731 "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n", hr
);
732 if (SUCCEEDED(hr
) && pidl
)
733 IMalloc_Free(pMalloc
, pidl
);
734 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
735 "SHGetSpecialFolderPath succeeded, expected failure\n");
737 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
738 ok(hr
== E_FAIL
, "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n",
740 if (SUCCEEDED(hr
) && pidl
)
741 IMalloc_Free(pMalloc
, pidl
);
742 /* now test success: */
743 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
744 SHGFP_TYPE_CURRENT
, path
);
749 if (winetest_interactive
)
750 printf("CSIDL_FAVORITES was changed to %s\n", path
);
751 ret
= CreateDirectoryA(path
, NULL
);
753 "CreateDirectoryA succeeded but should have failed "
754 "with ERROR_ALREADY_EXISTS\n");
756 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
757 "CreateDirectoryA failed with %ld, "
758 "expected ERROR_ALREADY_EXISTS\n",
762 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
763 "NULL, SHGFP_TYPE_CURRENT, path)\nfailed: 0x%08lx\n", hr
);
766 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
767 * original value of CSIDL_FAVORITES is restored.
769 static void testNonExistentPath2(void)
774 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
775 SHGFP_TYPE_CURRENT
, path
);
776 ok(SUCCEEDED(hr
), "SHGetFolderPath failed: 0x%08lx\n", hr
);
779 static void doChild(const char *arg
)
782 testNonExistentPath1();
783 else if (arg
[0] == '2')
784 testNonExistentPath2();
787 /* Tests the return values from the various shell functions both with and
788 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
789 * version 5 of the shell, so don't test unless it's at least version 5.
790 * The test reads a value from the registry, modifies it, calls
791 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
792 * afterward without it. Then it restores the registry and deletes the folder
794 * One oddity with respect to restoration: shell32 caches somehow, so it needs
795 * to be reloaded in order to see the correct (restored) value.
796 * Some APIs unrelated to the ones under test may fail, but I expect they're
797 * covered by other unit tests; I just print out something about failure to
798 * help trace what's going on.
800 static void testNonExistentPath(void)
802 static const char userShellFolders
[] =
803 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
804 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
807 if (!pSHGetFolderPathA
) return;
808 if (!pSHGetFolderLocation
) return;
809 if (!pSHGetSpecialFolderPathA
) return;
810 if (!pSHGetSpecialFolderLocation
) return;
811 if (!pSHFileOperationA
) return;
812 if (shellVersion
.dwMajorVersion
< 5) return;
814 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
819 len
= sizeof(originalPath
);
820 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
821 (LPBYTE
)&originalPath
, &len
))
823 size_t len
= strlen(originalPath
);
825 memcpy(modifiedPath
, originalPath
, len
);
826 modifiedPath
[len
++] = '2';
827 modifiedPath
[len
++] = '\0';
828 if (winetest_interactive
)
829 printf("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
830 if (!RegSetValueExA(key
, "Favorites", 0, type
,
831 (LPBYTE
)modifiedPath
, len
))
833 char buffer
[MAX_PATH
];
834 STARTUPINFOA startup
;
835 PROCESS_INFORMATION info
;
838 wnsprintfA(buffer
, sizeof(buffer
), "%s tests/shellpath.c 1",
840 memset(&startup
, 0, sizeof(startup
));
841 startup
.cb
= sizeof(startup
);
842 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
843 startup
.dwFlags
= SW_SHOWNORMAL
;
844 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
846 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
847 "child process termination\n");
849 /* Query the path to be able to delete it below */
850 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
851 SHGFP_TYPE_CURRENT
, modifiedPath
);
852 ok(SUCCEEDED(hr
), "SHGetFolderPathA failed: 0x%08lx\n", hr
);
854 /* restore original values: */
855 if (winetest_interactive
)
856 printf("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
857 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
858 strlen(originalPath
) + 1);
861 wnsprintfA(buffer
, sizeof(buffer
), "%s tests/shellpath.c 2",
863 memset(&startup
, 0, sizeof(startup
));
864 startup
.cb
= sizeof(startup
);
865 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
866 startup
.dwFlags
= SW_SHOWNORMAL
;
867 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
869 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
870 "child process termination\n");
872 strcpy(buffer
, modifiedPath
);
873 strcat(buffer
, "\\desktop.ini");
875 RemoveDirectoryA(modifiedPath
);
878 else if (winetest_interactive
)
879 printf("RegQueryValueExA(key, Favorites, ...) failed\n");
883 else if (winetest_interactive
)
884 printf("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n",
888 START_TEST(shellpath
)
893 if (!hShell32
) return;
899 /* first test various combinations of parameters: */
902 /* check known values: */
908 testNonExistentPath();