2 * Unit tests for shell32 SHGet{Special}Folder{Path|Location} functions.
4 * Copyright 2004 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
33 #include "wine/test.h"
35 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
36 * here is its original value.
38 #define OLD_CSIDL_MYDOCUMENTS 0x000c
41 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
44 /* from pidl.h, not included here: */
46 #define PT_GUID 0x1f /* no path */
49 #define PT_DRIVE 0x23 /* has path */
52 #define PT_DRIVE2 0x25 /* has path */
55 #define PT_SHELLEXT 0x2e /* no path */
58 #define PT_FOLDER 0x31 /* has path */
61 #define PT_WORKGRP 0x41 /* no path */
64 #define PT_YAGUID 0x70 /* no path */
66 /* FIXME: this is used for history/favorites folders; what's a better name? */
68 #define PT_IESPECIAL2 0xb1 /* has path */
71 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
73 struct shellExpectedValues
{
79 static HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
80 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
81 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
83 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
84 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
85 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
86 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
87 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
88 static DLLVERSIONINFO shellVersion
= { 0 };
89 static LPMALLOC pMalloc
;
90 static const BYTE guidType
[] = { PT_GUID
};
91 static const BYTE controlPanelType
[] = { PT_SHELLEXT
, PT_GUID
};
92 static const BYTE folderType
[] = { PT_FOLDER
};
93 static const BYTE favoritesType
[] = { PT_FOLDER
, 0, PT_IESPECIAL2
/* Win98 */ };
94 static const BYTE folderOrSpecialType
[] = { PT_FOLDER
, PT_IESPECIAL2
};
95 static const BYTE personalType
[] = { PT_FOLDER
, PT_GUID
, PT_DRIVE
, 0xff /* Win9x */,
96 PT_IESPECIAL2
/* Win98 */, 0 /* Vista */ };
97 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
98 static const BYTE printersType
[] = { PT_YAGUID
, PT_SHELLEXT
, 0x71 };
99 static const BYTE ieSpecialType
[] = { PT_IESPECIAL2
};
100 static const BYTE shellExtType
[] = { PT_SHELLEXT
};
101 static const BYTE workgroupType
[] = { PT_WORKGRP
};
102 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
103 static const struct shellExpectedValues requiredShellValues
[] = {
104 DECLARE_TYPE(CSIDL_BITBUCKET
, guidType
),
105 DECLARE_TYPE(CSIDL_CONTROLS
, controlPanelType
),
106 DECLARE_TYPE(CSIDL_COOKIES
, folderType
),
107 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY
, folderType
),
108 DECLARE_TYPE(CSIDL_DRIVES
, guidType
),
109 DECLARE_TYPE(CSIDL_FAVORITES
, favoritesType
),
110 DECLARE_TYPE(CSIDL_FONTS
, folderOrSpecialType
),
111 /* FIXME: the following fails in Wine, returns type PT_FOLDER
112 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
114 DECLARE_TYPE(CSIDL_INTERNET
, guidType
),
115 DECLARE_TYPE(CSIDL_NETHOOD
, folderType
),
116 DECLARE_TYPE(CSIDL_NETWORK
, guidType
),
117 DECLARE_TYPE(CSIDL_PERSONAL
, personalType
),
118 DECLARE_TYPE(CSIDL_PRINTERS
, printersType
),
119 DECLARE_TYPE(CSIDL_PRINTHOOD
, folderType
),
120 DECLARE_TYPE(CSIDL_PROGRAMS
, folderType
),
121 DECLARE_TYPE(CSIDL_RECENT
, folderOrSpecialType
),
122 DECLARE_TYPE(CSIDL_SENDTO
, folderType
),
123 DECLARE_TYPE(CSIDL_STARTMENU
, folderType
),
124 DECLARE_TYPE(CSIDL_STARTUP
, folderType
),
125 DECLARE_TYPE(CSIDL_TEMPLATES
, folderType
),
127 static const struct shellExpectedValues optionalShellValues
[] = {
128 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
129 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
130 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
131 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
133 /* Windows NT-only: */
134 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY
, folderType
),
135 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS
, shellExtType
),
136 DECLARE_TYPE(CSIDL_COMMON_FAVORITES
, folderType
),
137 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS
, folderType
),
138 DECLARE_TYPE(CSIDL_COMMON_STARTMENU
, folderType
),
139 DECLARE_TYPE(CSIDL_COMMON_STARTUP
, folderType
),
140 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES
, folderType
),
141 /* first appearing in shell32 version 4.71: */
142 DECLARE_TYPE(CSIDL_APPDATA
, folderType
),
143 /* first appearing in shell32 version 4.72: */
144 DECLARE_TYPE(CSIDL_INTERNET_CACHE
, ieSpecialType
),
145 /* first appearing in shell32 version 5.0: */
146 DECLARE_TYPE(CSIDL_ADMINTOOLS
, folderType
),
147 DECLARE_TYPE(CSIDL_COMMON_APPDATA
, folderType
),
148 DECLARE_TYPE(CSIDL_LOCAL_APPDATA
, folderType
),
149 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS
, folderType
),
150 DECLARE_TYPE(CSIDL_MYMUSIC
, folderType
),
151 DECLARE_TYPE(CSIDL_MYPICTURES
, folderType
),
152 DECLARE_TYPE(CSIDL_MYVIDEO
, folderType
),
153 DECLARE_TYPE(CSIDL_PROFILE
, folderType
),
154 DECLARE_TYPE(CSIDL_PROGRAM_FILES
, folderType
),
155 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86
, folderType
),
156 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON
, folderType
),
157 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86
, folderType
),
158 DECLARE_TYPE(CSIDL_SYSTEM
, folderType
),
159 DECLARE_TYPE(CSIDL_WINDOWS
, folderType
),
160 /* first appearing in shell32 6.0: */
161 DECLARE_TYPE(CSIDL_CDBURN_AREA
, folderType
),
162 DECLARE_TYPE(CSIDL_COMMON_MUSIC
, folderType
),
163 DECLARE_TYPE(CSIDL_COMMON_PICTURES
, folderType
),
164 DECLARE_TYPE(CSIDL_COMMON_VIDEO
, folderType
),
165 DECLARE_TYPE(CSIDL_COMPUTERSNEARME
, workgroupType
),
166 DECLARE_TYPE(CSIDL_RESOURCES
, folderType
),
167 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED
, folderType
),
171 static void loadShell32(void)
173 HMODULE hShell32
= GetModuleHandleA("shell32");
175 #define GET_PROC(func) \
176 p ## func = (void*)GetProcAddress(hShell32, #func); \
178 trace("GetProcAddress(%s) failed\n", #func);
180 GET_PROC(DllGetVersion
)
181 GET_PROC(SHGetFolderPathA
)
182 GET_PROC(SHGetFolderLocation
)
183 GET_PROC(SHGetSpecialFolderPathA
)
184 GET_PROC(SHGetSpecialFolderLocation
)
185 GET_PROC(ILFindLastID
)
187 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
188 GET_PROC(SHFileOperationA
)
189 GET_PROC(SHGetMalloc
)
191 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
194 HRESULT hr
= pSHGetMalloc(&pMalloc
);
196 ok(SUCCEEDED(hr
), "SHGetMalloc failed: 0x%08x\n", hr
);
197 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
202 shellVersion
.cbSize
= sizeof(shellVersion
);
203 pDllGetVersion(&shellVersion
);
204 trace("shell32 version is %d.%d\n",
205 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
210 #ifndef CSIDL_PROFILES
211 #define CSIDL_PROFILES 0x003e
214 /* A couple utility printing functions */
215 static const char *getFolderName(int folder
)
217 static char unknown
[32];
219 #define CSIDL_TO_STR(x) case x: return#x;
222 CSIDL_TO_STR(CSIDL_DESKTOP
);
223 CSIDL_TO_STR(CSIDL_INTERNET
);
224 CSIDL_TO_STR(CSIDL_PROGRAMS
);
225 CSIDL_TO_STR(CSIDL_CONTROLS
);
226 CSIDL_TO_STR(CSIDL_PRINTERS
);
227 CSIDL_TO_STR(CSIDL_PERSONAL
);
228 CSIDL_TO_STR(CSIDL_FAVORITES
);
229 CSIDL_TO_STR(CSIDL_STARTUP
);
230 CSIDL_TO_STR(CSIDL_RECENT
);
231 CSIDL_TO_STR(CSIDL_SENDTO
);
232 CSIDL_TO_STR(CSIDL_BITBUCKET
);
233 CSIDL_TO_STR(CSIDL_STARTMENU
);
234 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS
);
235 CSIDL_TO_STR(CSIDL_MYMUSIC
);
236 CSIDL_TO_STR(CSIDL_MYVIDEO
);
237 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
238 CSIDL_TO_STR(CSIDL_DRIVES
);
239 CSIDL_TO_STR(CSIDL_NETWORK
);
240 CSIDL_TO_STR(CSIDL_NETHOOD
);
241 CSIDL_TO_STR(CSIDL_FONTS
);
242 CSIDL_TO_STR(CSIDL_TEMPLATES
);
243 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
244 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
245 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
246 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
247 CSIDL_TO_STR(CSIDL_APPDATA
);
248 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
249 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
250 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
251 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
252 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
253 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
254 CSIDL_TO_STR(CSIDL_COOKIES
);
255 CSIDL_TO_STR(CSIDL_HISTORY
);
256 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
257 CSIDL_TO_STR(CSIDL_WINDOWS
);
258 CSIDL_TO_STR(CSIDL_SYSTEM
);
259 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
260 CSIDL_TO_STR(CSIDL_MYPICTURES
);
261 CSIDL_TO_STR(CSIDL_PROFILE
);
262 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
263 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
264 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
265 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
266 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
267 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
268 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
269 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
270 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
271 CSIDL_TO_STR(CSIDL_PROFILES
);
272 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
273 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
274 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
275 CSIDL_TO_STR(CSIDL_RESOURCES
);
276 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
277 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
278 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
279 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
282 sprintf(unknown
, "unknown (0x%04x)", folder
);
287 static const char *printGUID(const GUID
*guid
, char * guidSTR
)
289 if (!guid
) return NULL
;
291 sprintf(guidSTR
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
292 guid
->Data1
, guid
->Data2
, guid
->Data3
,
293 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
294 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
298 static void testSHGetFolderLocationInvalidArgs(void)
303 if (!pSHGetFolderLocation
) return;
305 /* check a bogus CSIDL: */
307 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
308 ok(hr
== E_INVALIDARG
,
309 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl) returned 0x%08x, expected E_INVALIDARG\n", hr
);
311 IMalloc_Free(pMalloc
, pidl
);
312 /* check a bogus user token: */
314 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
315 ok(hr
== E_FAIL
|| hr
== E_HANDLE
,
316 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl) returned 0x%08x, expected E_FAIL or E_HANDLE\n", hr
);
318 IMalloc_Free(pMalloc
, pidl
);
319 /* a NULL pidl pointer crashes, so don't test it */
322 static void testSHGetSpecialFolderLocationInvalidArgs(void)
324 LPITEMIDLIST pidl
= NULL
;
327 if (!pSHGetSpecialFolderLocation
) return;
329 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
330 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
331 ok(hr
== E_INVALIDARG
,
332 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08x, "
333 "expected E_INVALIDARG\n", hr
);
336 static void testSHGetFolderPathInvalidArgs(void)
341 if (!pSHGetFolderPathA
) return;
343 /* expect 2's a bogus handle, especially since we didn't open it */
344 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2,
345 SHGFP_TYPE_DEFAULT
, path
);
347 hr
== E_HANDLE
|| /* Windows Vista and 2008 */
348 broken(hr
== S_OK
), /* Windows 2000 and Me */
349 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_FAIL\n", hr
);
350 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
351 ok(hr
== E_INVALIDARG
,
352 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_INVALIDARG\n", hr
);
355 static void testSHGetSpecialFolderPathInvalidArgs(void)
360 if (!pSHGetSpecialFolderPathA
) return;
363 ret
= pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_BITBUCKET
, FALSE
);
365 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE) returned TRUE, expected FALSE\n");
367 /* odd but true: calling with a NULL path still succeeds if it's a real
368 * dir (on some windows platform). on winME it generates exception.
370 ret
= pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_PROGRAMS
, FALSE
);
372 "SHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE) returned FALSE, expected TRUE\n");
373 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
375 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE) returned TRUE, expected FALSE\n");
378 static void testApiParameters(void)
380 testSHGetFolderLocationInvalidArgs();
381 testSHGetSpecialFolderLocationInvalidArgs();
382 testSHGetFolderPathInvalidArgs();
383 testSHGetSpecialFolderPathInvalidArgs();
386 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
387 static BYTE
testSHGetFolderLocation(int folder
)
393 /* treat absence of function as success */
394 if (!pSHGetFolderLocation
) return TRUE
;
397 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
402 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
404 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
405 getFolderName(folder
));
407 ret
= pidlLast
->mkid
.abID
[0];
408 IMalloc_Free(pMalloc
, pidl
);
414 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
415 static BYTE
testSHGetSpecialFolderLocation(int folder
)
421 /* treat absence of function as success */
422 if (!pSHGetSpecialFolderLocation
) return TRUE
;
425 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
430 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
433 "%s: ILFindLastID failed\n", getFolderName(folder
));
435 ret
= pidlLast
->mkid
.abID
[0];
436 IMalloc_Free(pMalloc
, pidl
);
442 static void testSHGetFolderPath(BOOL optional
, int folder
)
447 if (!pSHGetFolderPathA
) return;
449 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
450 ok(SUCCEEDED(hr
) || optional
,
451 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder
), hr
);
454 static void testSHGetSpecialFolderPath(BOOL optional
, int folder
)
459 if (!pSHGetSpecialFolderPathA
) return;
461 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
462 if (ret
&& winetest_interactive
)
463 printf("%s: %s\n", getFolderName(folder
), path
);
465 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
466 getFolderName(folder
));
469 static void testShellValues(const struct shellExpectedValues testEntries
[],
470 int numEntries
, BOOL optional
)
474 for (i
= 0; i
< numEntries
; i
++)
478 BOOL foundTypeMatch
= FALSE
;
480 if (pSHGetFolderLocation
)
482 type
= testSHGetFolderLocation(testEntries
[i
].folder
);
483 for (j
= 0; !foundTypeMatch
&& j
< testEntries
[i
].numTypes
; j
++)
484 if (testEntries
[i
].types
[j
] == type
)
485 foundTypeMatch
= TRUE
;
486 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
487 "%s has unexpected type %d (0x%02x)\n",
488 getFolderName(testEntries
[i
].folder
), type
, type
);
490 type
= testSHGetSpecialFolderLocation(testEntries
[i
].folder
);
491 for (j
= 0, foundTypeMatch
= FALSE
; !foundTypeMatch
&&
492 j
< testEntries
[i
].numTypes
; j
++)
493 if (testEntries
[i
].types
[j
] == type
)
494 foundTypeMatch
= TRUE
;
495 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
496 "%s has unexpected type %d (0x%02x)\n",
497 getFolderName(testEntries
[i
].folder
), type
, type
);
504 testSHGetFolderPath(optional
, testEntries
[i
].folder
);
505 testSHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
511 /* Attempts to verify that the folder path corresponding to the folder CSIDL
512 * value has the same value as the environment variable with name envVar.
513 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
514 * set in this environment; different OS and shell version behave differently.
515 * However, if both are present, fails if envVar's value is not the same
516 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
518 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
522 if (!pSHGetSpecialFolderPathA
) return;
524 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
526 char *envVal
= getenv(envVar
);
528 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
529 "%%%s%% does not match SHGetSpecialFolderPath:\n"
530 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
531 envVar
, envVar
, envVal
, path
);
535 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
536 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
537 * fail if it isn't--that check should already have been done.
538 * Fails if the returned PIDL is a GUID whose value does not match guid.
540 static void matchGUID(int folder
, const GUID
*guid
)
545 if (!pSHGetFolderLocation
) return;
549 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
552 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
554 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
555 pidlLast
->mkid
.abID
[0] == PT_GUID
))
557 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
558 char shellGuidStr
[39], guidStr
[39];
560 ok(IsEqualIID(shellGuid
, guid
),
561 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
562 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
));
564 IMalloc_Free(pMalloc
, pidl
);
568 static void testDesktop(void)
570 testSHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
571 testSHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
574 /* Checks the PIDL type of all the known values. */
575 static void testPidlTypes(void)
578 testShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
),
580 testShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
),
584 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
585 static void testGUIDs(void)
587 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
);
588 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
);
589 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
);
590 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
);
591 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
);
592 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
);
593 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
);
596 /* Verifies various shell paths match the environment variables to which they
599 static void testEnvVars(void)
601 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
602 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
603 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
604 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
605 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
606 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
,
607 "CommonProgramFiles");
608 /* this is only set on Wine, but can't hurt to verify it: */
609 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
612 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
613 static BOOL
myPathIsRootA(LPCSTR lpszPath
)
615 if (lpszPath
&& *lpszPath
&&
616 lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
617 return TRUE
; /* X:\ */
620 static LPSTR
myPathRemoveBackslashA( LPSTR lpszPath
)
626 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
627 if (!myPathIsRootA(lpszPath
) && *szTemp
== '\\')
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 myPathRemoveBackslashA(windowsShellPath
);
646 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
647 myPathRemoveBackslashA(windowsDir
);
648 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
649 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
650 windowsDir
, windowsShellPath
);
654 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
655 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
656 * no foul--not every shell32 version supports CSIDL_SYSTEM.
658 static void testSystemDir(void)
660 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
] = { 0 };
662 if (!pSHGetSpecialFolderPathA
) return;
664 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
665 myPathRemoveBackslashA(systemDir
);
666 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
668 myPathRemoveBackslashA(systemShellPath
);
669 ok(!lstrcmpiA(systemDir
, systemShellPath
),
670 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
671 systemDir
, systemShellPath
);
673 /* CSIDL_SYSTEMX86 isn't checked in the same way, since it's different
674 * on Win64 (and non-x86 Windows systems, if there are any still in
675 * existence) than on Win32.
679 /* Globals used by subprocesses */
681 static char **myARGV
;
682 static char base
[MAX_PATH
];
683 static char selfname
[MAX_PATH
];
685 static int init(void)
687 myARGC
= winetest_get_mainargs(&myARGV
);
688 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
689 strcpy(selfname
, myARGV
[0]);
693 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
694 * nonexistent directory.
696 static void testNonExistentPath1(void)
700 char *p
, path
[MAX_PATH
];
702 /* test some failure cases first: */
703 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
704 SHGFP_TYPE_CURRENT
, path
);
705 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
706 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr
);
708 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0,
710 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
711 "SHGetFolderLocation returned 0x%08x\n", hr
);
712 if (SUCCEEDED(hr
) && pidl
)
713 IMalloc_Free(pMalloc
, pidl
);
714 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
715 "SHGetSpecialFolderPath succeeded, expected failure\n");
717 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
718 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
719 "SHGetFolderLocation returned 0x%08x\n", hr
);
720 if (SUCCEEDED(hr
) && pidl
)
721 IMalloc_Free(pMalloc
, pidl
);
722 /* now test success: */
723 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
724 SHGFP_TYPE_CURRENT
, path
);
729 trace("CSIDL_FAVORITES was changed to %s\n", path
);
730 ret
= CreateDirectoryA(path
, NULL
);
732 "CreateDirectoryA succeeded but should have failed "
733 "with ERROR_ALREADY_EXISTS\n");
735 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
736 "CreateDirectoryA failed with %d, "
737 "expected ERROR_ALREADY_EXISTS\n",
739 p
= path
+ strlen(path
);
740 strcpy(p
, "\\desktop.ini");
743 SetFileAttributesA( path
, FILE_ATTRIBUTE_NORMAL
);
744 ret
= RemoveDirectoryA(path
);
745 ok( ret
, "failed to remove %s error %u\n", path
, GetLastError() );
748 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
749 "NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", hr
);
752 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
753 * original value of CSIDL_FAVORITES is restored.
755 static void testNonExistentPath2(void)
760 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
761 SHGFP_TYPE_CURRENT
, path
);
762 ok(SUCCEEDED(hr
), "SHGetFolderPath failed: 0x%08x\n", hr
);
765 static void doChild(const char *arg
)
768 testNonExistentPath1();
769 else if (arg
[0] == '2')
770 testNonExistentPath2();
773 /* Tests the return values from the various shell functions both with and
774 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
775 * version 5 of the shell, so don't test unless it's at least version 5.
776 * The test reads a value from the registry, modifies it, calls
777 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
778 * afterward without it. Then it restores the registry and deletes the folder
780 * One oddity with respect to restoration: shell32 caches somehow, so it needs
781 * to be reloaded in order to see the correct (restored) value.
782 * Some APIs unrelated to the ones under test may fail, but I expect they're
783 * covered by other unit tests; I just print out something about failure to
784 * help trace what's going on.
786 static void testNonExistentPath(void)
788 static const char userShellFolders
[] =
789 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
790 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
793 if (!pSHGetFolderPathA
) return;
794 if (!pSHGetFolderLocation
) return;
795 if (!pSHGetSpecialFolderPathA
) return;
796 if (!pSHGetSpecialFolderLocation
) return;
797 if (!pSHFileOperationA
) return;
798 if (shellVersion
.dwMajorVersion
< 5) return;
800 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
805 len
= sizeof(originalPath
);
806 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
807 (LPBYTE
)&originalPath
, &len
))
809 size_t len
= strlen(originalPath
);
811 memcpy(modifiedPath
, originalPath
, len
);
812 modifiedPath
[len
++] = '2';
813 modifiedPath
[len
++] = '\0';
814 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
815 if (!RegSetValueExA(key
, "Favorites", 0, type
,
816 (LPBYTE
)modifiedPath
, len
))
818 char buffer
[MAX_PATH
+20];
819 STARTUPINFOA startup
;
820 PROCESS_INFORMATION info
;
822 sprintf(buffer
, "%s tests/shellpath.c 1", selfname
);
823 memset(&startup
, 0, sizeof(startup
));
824 startup
.cb
= sizeof(startup
);
825 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
826 startup
.dwFlags
= SW_SHOWNORMAL
;
827 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
829 winetest_wait_child_process( info
.hProcess
);
831 /* restore original values: */
832 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
833 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
834 strlen(originalPath
) + 1);
837 sprintf(buffer
, "%s tests/shellpath.c 2", selfname
);
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");
848 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
852 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders
);
855 START_TEST(shellpath
)
865 /* Report missing functions once */
866 if (!pSHGetFolderLocation
)
867 win_skip("SHGetFolderLocation is not available\n");
869 /* first test various combinations of parameters: */
872 /* check known values: */
878 testNonExistentPath();