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_DRIVE2 0x25 /* has path */
48 #define PT_SHELLEXT 0x2e /* no path */
51 #define PT_FOLDER 0x31 /* has path */
54 #define PT_WORKGRP 0x41 /* no path */
57 #define PT_YAGUID 0x70 /* no path */
59 /* FIXME: this is used for history/favorites folders; what's a better name? */
61 #define PT_IESPECIAL2 0xb1 /* has path */
64 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
66 struct shellExpectedValues
{
71 static HMODULE hShell32
;
72 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
73 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
75 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
76 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
77 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
78 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
79 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
80 static DLLVERSIONINFO shellVersion
= { 0 };
81 static LPMALLOC pMalloc
;
82 static const struct shellExpectedValues requiredShellValues
[] = {
83 { CSIDL_BITBUCKET
, PT_GUID
},
84 { CSIDL_CONTROLS
, PT_SHELLEXT
},
85 { CSIDL_COOKIES
, PT_FOLDER
},
86 { CSIDL_DESKTOPDIRECTORY
, PT_FOLDER
},
87 { CSIDL_DRIVES
, PT_GUID
},
88 { CSIDL_FAVORITES
, PT_FOLDER
},
89 { CSIDL_FONTS
, PT_FOLDER
},
90 /* FIXME: the following fails in Wine, returns type PT_FOLDER
91 { CSIDL_HISTORY, PT_IESPECIAL2 },
93 { CSIDL_INTERNET
, PT_GUID
},
94 { CSIDL_NETHOOD
, PT_FOLDER
},
95 { CSIDL_NETWORK
, PT_GUID
},
96 { CSIDL_PRINTERS
, PT_YAGUID
},
97 { CSIDL_PRINTHOOD
, PT_FOLDER
},
98 { CSIDL_PROGRAMS
, PT_FOLDER
},
99 { CSIDL_RECENT
, PT_FOLDER
},
100 { CSIDL_SENDTO
, PT_FOLDER
},
101 { CSIDL_STARTMENU
, PT_FOLDER
},
102 { CSIDL_STARTUP
, PT_FOLDER
},
103 { CSIDL_TEMPLATES
, PT_FOLDER
},
105 static const struct shellExpectedValues optionalShellValues
[] = {
106 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
107 { CSIDL_ALTSTARTUP, PT_FOLDER },
108 { CSIDL_COMMON_ALTSTARTUP, PT_FOLDER },
109 { CSIDL_COMMON_OEM_LINKS, PT_FOLDER },
111 /* Windows NT-only: */
112 { CSIDL_COMMON_DESKTOPDIRECTORY
, PT_FOLDER
},
113 { CSIDL_COMMON_DOCUMENTS
, PT_SHELLEXT
},
114 { CSIDL_COMMON_FAVORITES
, PT_FOLDER
},
115 { CSIDL_COMMON_PROGRAMS
, PT_FOLDER
},
116 { CSIDL_COMMON_STARTMENU
, PT_FOLDER
},
117 { CSIDL_COMMON_STARTUP
, PT_FOLDER
},
118 { CSIDL_COMMON_TEMPLATES
, PT_FOLDER
},
119 /* first appearing in shell32 version 4.71: */
120 { CSIDL_APPDATA
, PT_FOLDER
},
121 /* first appearing in shell32 version 4.72: */
122 { CSIDL_INTERNET_CACHE
, PT_IESPECIAL2
},
123 /* first appearing in shell32 version 5.0: */
124 { CSIDL_ADMINTOOLS
, PT_FOLDER
},
125 { CSIDL_COMMON_APPDATA
, PT_FOLDER
},
126 { CSIDL_LOCAL_APPDATA
, PT_FOLDER
},
127 { CSIDL_MYDOCUMENTS
, PT_FOLDER
},
128 { CSIDL_MYMUSIC
, PT_FOLDER
},
129 { CSIDL_MYPICTURES
, PT_FOLDER
},
130 { CSIDL_MYVIDEO
, PT_FOLDER
},
131 { CSIDL_PROFILE
, PT_FOLDER
},
132 { CSIDL_PROGRAM_FILES
, PT_FOLDER
},
133 { CSIDL_PROGRAM_FILESX86
, PT_FOLDER
},
134 { CSIDL_PROGRAM_FILES_COMMON
, PT_FOLDER
},
135 { CSIDL_PROGRAM_FILES_COMMONX86
, PT_FOLDER
},
136 { CSIDL_SYSTEM
, PT_FOLDER
},
137 { CSIDL_WINDOWS
, PT_FOLDER
},
138 /* first appearing in shell32 6.0: */
139 { CSIDL_CDBURN_AREA
, PT_FOLDER
},
140 { CSIDL_COMMON_MUSIC
, PT_FOLDER
},
141 { CSIDL_COMMON_PICTURES
, PT_FOLDER
},
142 { CSIDL_COMMON_VIDEO
, PT_FOLDER
},
143 { CSIDL_COMPUTERSNEARME
, PT_WORKGRP
},
144 { CSIDL_RESOURCES
, PT_FOLDER
},
145 { CSIDL_RESOURCES_LOCALIZED
, PT_FOLDER
},
148 static void loadShell32(void)
150 hShell32
= LoadLibraryA("shell32");
153 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
155 pSHGetFolderPathA
= (void *)GetProcAddress(hShell32
,
157 pSHGetFolderLocation
= (void *)GetProcAddress(hShell32
,
158 "SHGetFolderLocation");
159 pSHGetSpecialFolderPathA
= (void *)GetProcAddress(hShell32
,
160 "SHGetSpecialFolderPathA");
161 pSHGetSpecialFolderLocation
= (void *)GetProcAddress(hShell32
,
162 "SHGetSpecialFolderLocation");
163 pDllGetVersion
= (void *)GetProcAddress(hShell32
, "DllGetVersion");
164 pILFindLastID
= (void *)GetProcAddress(hShell32
, "ILFindLastID");
166 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
167 pSHFileOperationA
= (void *)GetProcAddress(hShell32
,
169 pSHGetMalloc
= (void *)GetProcAddress(hShell32
, "SHGetMalloc");
171 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
174 HRESULT hr
= pSHGetMalloc(&pMalloc
);
176 ok(SUCCEEDED(hr
), "SHGetMalloc failed: 0x%08lx\n", hr
);
177 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
182 shellVersion
.cbSize
= sizeof(shellVersion
);
183 pDllGetVersion(&shellVersion
);
184 if (winetest_interactive
)
185 printf("shell32 version is %ld.%ld\n",
186 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
191 #ifndef CSIDL_PROFILES
192 #define CSIDL_PROFILES 0x003e
195 /* A couple utility printing functions */
196 static const char *getFolderName(int folder
)
198 static char unknown
[17];
200 #define CSIDL_TO_STR(x) case x: return#x;
203 CSIDL_TO_STR(CSIDL_DESKTOP
);
204 CSIDL_TO_STR(CSIDL_INTERNET
);
205 CSIDL_TO_STR(CSIDL_PROGRAMS
);
206 CSIDL_TO_STR(CSIDL_CONTROLS
);
207 CSIDL_TO_STR(CSIDL_PRINTERS
);
208 CSIDL_TO_STR(CSIDL_PERSONAL
);
209 CSIDL_TO_STR(CSIDL_FAVORITES
);
210 CSIDL_TO_STR(CSIDL_STARTUP
);
211 CSIDL_TO_STR(CSIDL_RECENT
);
212 CSIDL_TO_STR(CSIDL_SENDTO
);
213 CSIDL_TO_STR(CSIDL_BITBUCKET
);
214 CSIDL_TO_STR(CSIDL_STARTMENU
);
215 CSIDL_TO_STR(CSIDL_MYDOCUMENTS
);
216 CSIDL_TO_STR(CSIDL_MYMUSIC
);
217 CSIDL_TO_STR(CSIDL_MYVIDEO
);
218 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
219 CSIDL_TO_STR(CSIDL_DRIVES
);
220 CSIDL_TO_STR(CSIDL_NETWORK
);
221 CSIDL_TO_STR(CSIDL_NETHOOD
);
222 CSIDL_TO_STR(CSIDL_FONTS
);
223 CSIDL_TO_STR(CSIDL_TEMPLATES
);
224 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
225 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
226 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
227 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
228 CSIDL_TO_STR(CSIDL_APPDATA
);
229 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
230 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
231 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
232 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
233 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
234 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
235 CSIDL_TO_STR(CSIDL_COOKIES
);
236 CSIDL_TO_STR(CSIDL_HISTORY
);
237 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
238 CSIDL_TO_STR(CSIDL_WINDOWS
);
239 CSIDL_TO_STR(CSIDL_SYSTEM
);
240 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
241 CSIDL_TO_STR(CSIDL_MYPICTURES
);
242 CSIDL_TO_STR(CSIDL_PROFILE
);
243 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
244 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
245 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
246 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
247 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
248 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
249 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
250 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
251 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
252 CSIDL_TO_STR(CSIDL_PROFILES
);
253 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
254 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
255 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
256 CSIDL_TO_STR(CSIDL_RESOURCES
);
257 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
258 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
259 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
260 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
263 wnsprintfA(unknown
, sizeof(unknown
), "unknown (0x%04x)", folder
);
268 static const char *printGUID(const GUID
*guid
)
270 static char guidSTR
[39];
272 if (!guid
) return NULL
;
274 wnsprintfA(guidSTR
, sizeof(guidSTR
),
275 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
276 guid
->Data1
, guid
->Data2
, guid
->Data3
,
277 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
278 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
282 static void testSHGetFolderLocationInvalidArgs(void)
287 if (!pSHGetFolderLocation
) return;
289 /* check a bogus CSIDL: */
291 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
292 ok(hr
== E_INVALIDARG
,
293 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl)\n"
294 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
296 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
297 /* check a bogus user token: */
299 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
301 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl)\n"
302 "returned 0x%08lx, expected E_FAIL\n", hr
);
304 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
305 /* check reserved is not zero: */
307 hr
= pSHGetFolderLocation(NULL
, CSIDL_DESKTOP
, NULL
, 1, &pidl
);
308 ok(hr
== E_INVALIDARG
,
309 "SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 1, &pidl)\n"
310 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
312 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
313 /* a NULL pidl pointer crashes, so don't test it */
316 static void testSHGetSpecialFolderLocationInvalidArgs(void)
318 LPITEMIDLIST pidl
= NULL
;
321 if (!pSHGetSpecialFolderLocation
) return;
323 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
324 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
325 ok(hr
== E_INVALIDARG
,
326 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08lx, "
327 "expected E_INVALIDARG\n", hr
);
330 static void testSHGetFolderPathInvalidArgs(void)
335 if (!pSHGetFolderPathA
) return;
337 /* expect 2's a bogus handle, especially since we didn't open it */
338 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2,
339 SHGFP_TYPE_DEFAULT
, path
);
341 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path)\n"
342 "returned 0x%08lx, expected E_FAIL\n", hr
);
343 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
344 ok(hr
== E_INVALIDARG
,
345 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path)\n"
346 "returned 0x%08lx, expected E_INVALIDARG\n", hr
);
349 static void testSHGetSpecialFolderPathInvalidArgs(void)
354 if (!pSHGetSpecialFolderPathA
) return;
356 ret
= pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_BITBUCKET
, FALSE
);
358 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE)\n"
359 "returned TRUE, expected FALSE\n");
360 /* odd but true: calling with a NULL path still succeeds if it's a real
363 ret
= pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_PROGRAMS
, FALSE
);
365 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_PROGRAMS, FALSE)\n"
366 "returned FALSE, expected TRUE\n");
367 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
369 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE)\n"
370 "returned TRUE, expected FALSE\n");
373 static void testApiParameters(void)
375 testSHGetFolderLocationInvalidArgs();
376 testSHGetSpecialFolderLocationInvalidArgs();
377 testSHGetFolderPathInvalidArgs();
378 testSHGetSpecialFolderPathInvalidArgs();
381 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
382 static BYTE
testSHGetFolderLocation(BOOL optional
, int folder
)
388 /* treat absence of function as success */
389 if (!pSHGetFolderLocation
) return TRUE
;
392 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
393 ok(SUCCEEDED(hr
) || optional
,
394 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
395 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
399 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl)\n"
400 "succeeded, but returned pidl is NULL\n", getFolderName(folder
));
403 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
405 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
406 getFolderName(folder
));
408 ret
= pidlLast
->mkid
.abID
[0];
409 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
415 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
416 static BYTE
testSHGetSpecialFolderLocation(BOOL optional
, int folder
)
422 /* treat absence of function as success */
423 if (!pSHGetSpecialFolderLocation
) return TRUE
;
426 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
427 ok(SUCCEEDED(hr
) || optional
,
428 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
429 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
433 "SHGetSpecialFolderLocation(NULL, %s, &pidl)\n"
434 "succeeded, but returned pidl is NULL\n", getFolderName(folder
));
437 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
440 "%s: ILFindLastID failed\n", getFolderName(folder
));
442 ret
= pidlLast
->mkid
.abID
[0];
443 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
449 static void testSHGetFolderPath(BOOL optional
, int folder
)
454 if (!pSHGetFolderPathA
) return;
456 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
457 ok(SUCCEEDED(hr
) || optional
,
458 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path)\n"
459 "failed: 0x%08lx\n", getFolderName(folder
), hr
);
462 static void testSHGetSpecialFolderPath(BOOL optional
, int folder
)
467 if (!pSHGetSpecialFolderPathA
) return;
469 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
470 if (ret
&& winetest_interactive
)
471 printf("%s: %s\n", getFolderName(folder
), path
);
473 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
474 getFolderName(folder
));
477 static void testShellValues(const struct shellExpectedValues testEntries
[],
478 int numEntries
, BOOL optional
)
482 for (i
= 0; i
< numEntries
; i
++)
486 type
= testSHGetFolderLocation(optional
, testEntries
[i
].folder
);
487 ok(type
== testEntries
[i
].pidlType
|| optional
,
488 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
489 getFolderName(testEntries
[i
].folder
), type
, type
,
490 testEntries
[i
].pidlType
, testEntries
[i
].pidlType
);
491 type
= testSHGetSpecialFolderLocation(optional
, testEntries
[i
].folder
);
492 ok(type
== testEntries
[i
].pidlType
|| optional
,
493 "%s has type %d (0x%02x), expected %d (0x%02x)\n",
494 getFolderName(testEntries
[i
].folder
), type
, type
,
495 testEntries
[i
].pidlType
, testEntries
[i
].pidlType
);
501 testSHGetFolderPath(optional
, testEntries
[i
].folder
);
502 testSHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
508 /* Attempts to verify that the folder path corresponding to the folder CSIDL
509 * value has the same value as the environment variable with name envVar.
510 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
511 * set in this environment; different OS and shell version behave differently.
512 * However, if both are present, fails if envVar's value is not the same
513 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
515 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
519 if (!pSHGetSpecialFolderPathA
) return;
521 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
523 char *envVal
= getenv(envVar
);
525 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
526 "%%%s%% does not match SHGetSpecialFolderPath:\n"
527 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
528 envVar
, envVar
, envVal
, path
);
532 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
533 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
534 * fail if it isn't--that check should already have been done.
535 * Fails if the returned PIDL is a GUID whose value does not match guid.
537 static void matchGUID(int folder
, const GUID
*guid
)
542 if (!pSHGetFolderLocation
) return;
546 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
549 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
551 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
552 pidlLast
->mkid
.abID
[0] == PT_GUID
))
554 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
556 ok(IsEqualIID(shellGuid
, guid
),
557 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
558 printGUID(shellGuid
), printGUID(guid
));
560 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
564 static void testDesktop(void)
566 testSHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
567 testSHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
568 /* Test the desktop; even though SHITEMID should always contain abID of at
569 * least one type, when cb is 0 its value is undefined. So don't check
570 * what the returned type is, just make sure it exists.
572 testSHGetFolderLocation(FALSE
, CSIDL_DESKTOP
);
573 testSHGetSpecialFolderLocation(FALSE
, CSIDL_DESKTOP
);
576 static void testPersonal(void)
580 type
= testSHGetFolderLocation(FALSE
, CSIDL_PERSONAL
);
581 ok(type
== PT_FOLDER
|| type
== PT_GUID
,
582 "CSIDL_PERSONAL returned invalid type 0x%02x, "
583 "expected PT_FOLDER or PT_GUID\n", type
);
584 if (type
== PT_FOLDER
)
585 testSHGetFolderPath(FALSE
, CSIDL_PERSONAL
);
586 type
= testSHGetSpecialFolderLocation(FALSE
, CSIDL_PERSONAL
);
587 ok(type
== PT_FOLDER
|| type
== PT_GUID
,
588 "CSIDL_PERSONAL returned invalid type 0x%02x, "
589 "expected PT_FOLDER or PT_GUID\n", type
);
590 if (type
== PT_FOLDER
)
591 testSHGetSpecialFolderPath(FALSE
, CSIDL_PERSONAL
);
594 /* Checks the PIDL type of all the known values. */
595 static void testPidlTypes(void)
599 testShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
),
601 testShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
),
605 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
606 static void testGUIDs(void)
608 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
);
609 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
);
610 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
);
611 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
);
612 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
);
613 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
);
614 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
);
617 /* Verifies various shell paths match the environment variables to which they
620 static void testEnvVars(void)
622 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
623 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
624 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
625 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
626 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
627 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
,
628 "CommonProgramFiles");
629 /* this is only set on Wine, but can't hurt to verify it: */
630 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
633 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
634 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
635 * every shell32 version supports CSIDL_WINDOWS.
637 static void testWinDir(void)
639 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
641 if (!pSHGetSpecialFolderPathA
) return;
643 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
645 PathRemoveBackslashA(windowsShellPath
);
646 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
647 PathRemoveBackslashA(windowsDir
);
648 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
649 "GetWindowsDirectory does not match SHGetSpecialFolderPath:\n"
650 "GetWindowsDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
651 windowsDir
, windowsShellPath
);
655 /* Verifies the shell path for CSIDL_SYSTEM and CSIDL_SYSTEMX86 matches the
656 * return from GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
657 * no foul--not every shell32 version supports CSIDL_SYSTEM.
659 static void testSystemDir(void)
661 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
] = { 0 };
663 if (!pSHGetSpecialFolderPathA
) return;
665 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
666 PathRemoveBackslashA(systemDir
);
667 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
669 PathRemoveBackslashA(systemShellPath
);
670 ok(!lstrcmpiA(systemDir
, systemShellPath
),
671 "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
672 "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
673 systemDir
, systemShellPath
);
675 /* check CSIDL_SYSTEMX86; note that this isn't always present, so don't
678 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEMX86
, 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
);
688 /* Globals used by subprocesses */
690 static char **myARGV
;
691 static char base
[MAX_PATH
];
692 static char selfname
[MAX_PATH
];
694 static int init(void)
696 myARGC
= winetest_get_mainargs(&myARGV
);
697 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
698 strcpy(selfname
, myARGV
[0]);
702 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
703 * nonexistent directory.
705 static void testNonExistentPath1(void)
711 /* test some failure cases first: */
712 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
713 SHGFP_TYPE_CURRENT
, NULL
);
714 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
715 "SHGetFolderPath returned 0x%08lx, expected 0x80070002\n", hr
);
717 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0,
720 "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n", hr
);
721 if (SUCCEEDED(hr
) && pidl
)
722 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
723 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
724 "SHGetSpecialFolderPath succeeded, expected failure\n");
726 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
727 ok(hr
== E_FAIL
, "SHGetFolderLocation returned 0x%08lx, expected E_FAIL\n",
729 if (SUCCEEDED(hr
) && pidl
)
730 pMalloc
->lpVtbl
->Free(pMalloc
, pidl
);
731 /* now test success: */
732 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
733 SHGFP_TYPE_CURRENT
, path
);
738 if (winetest_interactive
)
739 printf("CSIDL_FAVORITES was changed to %s\n", path
);
740 ret
= CreateDirectoryA(path
, NULL
);
742 "CreateDirectoryA succeeded but should have failed "
743 "with ERROR_ALREADY_EXISTS\n");
745 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
746 "CreateDirectoryA failed with %ld, "
747 "expected ERROR_ALREADY_EXISTS\n",
751 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
752 "NULL, SHGFP_TYPE_CURRENT, path)\nfailed: 0x%08lx\n", hr
);
755 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
756 * original value of CSIDL_FAVORITES is restored.
758 static void testNonExistentPath2(void)
762 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
763 SHGFP_TYPE_CURRENT
, NULL
);
764 ok(SUCCEEDED(hr
), "SHGetFolderPath failed: 0x%08lx\n", hr
);
767 static void doChild(const char *arg
)
770 testNonExistentPath1();
771 else if (arg
[0] == '2')
772 testNonExistentPath2();
775 /* Tests the return values from the various shell functions both with and
776 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
777 * version 5 of the shell, so don't test unless it's at least version 5.
778 * The test reads a value from the registry, modifies it, calls
779 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
780 * afterward without it. Then it restores the registry and deletes the folder
782 * One oddity with respect to restoration: shell32 caches somehow, so it needs
783 * to be reloaded in order to see the correct (restored) value.
784 * Some APIs unrelated to the ones under test may fail, but I expect they're
785 * covered by other unit tests; I just print out something about failure to
786 * help trace what's going on.
788 static void testNonExistentPath(void)
790 static const char userShellFolders
[] =
791 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
792 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
795 if (!pSHGetFolderPathA
) return;
796 if (!pSHGetFolderLocation
) return;
797 if (!pSHGetSpecialFolderPathA
) return;
798 if (!pSHGetSpecialFolderLocation
) return;
799 if (!pSHFileOperationA
) return;
800 if (shellVersion
.dwMajorVersion
< 5) return;
802 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
807 len
= sizeof(originalPath
);
808 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
809 (LPBYTE
)&originalPath
, &len
))
811 size_t len
= strlen(originalPath
);
813 memcpy(modifiedPath
, originalPath
, len
);
814 modifiedPath
[len
++] = '2';
815 modifiedPath
[len
++] = '\0';
816 if (winetest_interactive
)
817 printf("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
818 if (!RegSetValueExA(key
, "Favorites", 0, type
, modifiedPath
, len
))
820 char buffer
[MAX_PATH
];
821 STARTUPINFOA startup
;
822 PROCESS_INFORMATION info
;
826 wnsprintfA(buffer
, sizeof(buffer
), "%s tests/shellpath.c 1",
828 memset(&startup
, 0, sizeof(startup
));
829 startup
.cb
= sizeof(startup
);
830 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
831 startup
.dwFlags
= SW_SHOWNORMAL
;
832 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
834 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
835 "child process termination\n");
837 /* Query the path to be able to delete it below */
838 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
839 SHGFP_TYPE_CURRENT
, modifiedPath
);
840 ok(SUCCEEDED(hr
), "SHGetFolderPathA failed: 0x%08lx\n", hr
);
842 /* restore original values: */
843 if (winetest_interactive
)
844 printf("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
845 RegSetValueExA(key
, "Favorites", 0, type
, originalPath
,
846 strlen(originalPath
) + 1);
849 wnsprintfA(buffer
, sizeof(buffer
), "%s tests/shellpath.c 2",
851 memset(&startup
, 0, sizeof(startup
));
852 startup
.cb
= sizeof(startup
);
853 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
854 startup
.dwFlags
= SW_SHOWNORMAL
;
855 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
857 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
858 "child process termination\n");
860 ret
= RemoveDirectoryA(modifiedPath
);
861 ok( ret
, "RemoveDirectoryA failed: %ld\n", GetLastError());
864 else if (winetest_interactive
)
865 printf("RegQueryValueExA(key, Favorites, ...) failed\n");
869 else if (winetest_interactive
)
870 printf("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n",
874 START_TEST(shellpath
)
879 if (!hShell32
) return;
885 /* first test various combinations of parameters: */
888 /* check known values: */
894 testNonExistentPath();