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).
34 #include "wine/test.h"
36 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
37 * here is its original value.
39 #define OLD_CSIDL_MYDOCUMENTS 0x000c
42 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
45 /* from pidl.h, not included here: */
46 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
47 #define PT_CPL 0x01 /* no path */
50 #define PT_GUID 0x1f /* no path */
53 #define PT_DRIVE 0x23 /* has path */
56 #define PT_DRIVE2 0x25 /* has path */
59 #define PT_SHELLEXT 0x2e /* no path */
62 #define PT_FOLDER 0x31 /* has path */
65 #define PT_FOLDERW 0x35 /* has path */
68 #define PT_WORKGRP 0x41 /* no path */
71 #define PT_YAGUID 0x70 /* no path */
73 /* FIXME: this is used for history/favorites folders; what's a better name? */
75 #define PT_IESPECIAL2 0xb1 /* has path */
78 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
80 struct shellExpectedValues
{
86 static HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
87 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
88 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
90 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
91 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
92 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
93 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
94 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
95 static UINT (WINAPI
*pGetSystemWow64DirectoryA
)(LPSTR
,UINT
);
96 static DLLVERSIONINFO shellVersion
= { 0 };
97 static LPMALLOC pMalloc
;
98 static const BYTE guidType
[] = { PT_GUID
};
99 static const BYTE controlPanelType
[] = { PT_SHELLEXT
, PT_GUID
, PT_CPL
};
100 static const BYTE folderType
[] = { PT_FOLDER
, PT_FOLDERW
};
101 static const BYTE favoritesType
[] = { PT_FOLDER
, PT_FOLDERW
, 0, PT_IESPECIAL2
/* Win98 */ };
102 static const BYTE folderOrSpecialType
[] = { PT_FOLDER
, PT_IESPECIAL2
};
103 static const BYTE personalType
[] = { PT_FOLDER
, PT_GUID
, PT_DRIVE
, 0xff /* Win9x */,
104 PT_IESPECIAL2
/* Win98 */, 0 /* Vista */ };
105 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
106 static const BYTE printersType
[] = { PT_YAGUID
, PT_SHELLEXT
, 0x71 };
107 static const BYTE ieSpecialType
[] = { PT_IESPECIAL2
};
108 static const BYTE shellExtType
[] = { PT_SHELLEXT
};
109 static const BYTE workgroupType
[] = { PT_WORKGRP
};
110 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
111 static const struct shellExpectedValues requiredShellValues
[] = {
112 DECLARE_TYPE(CSIDL_BITBUCKET
, guidType
),
113 DECLARE_TYPE(CSIDL_CONTROLS
, controlPanelType
),
114 DECLARE_TYPE(CSIDL_COOKIES
, folderType
),
115 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY
, folderType
),
116 DECLARE_TYPE(CSIDL_DRIVES
, guidType
),
117 DECLARE_TYPE(CSIDL_FAVORITES
, favoritesType
),
118 DECLARE_TYPE(CSIDL_FONTS
, folderOrSpecialType
),
119 /* FIXME: the following fails in Wine, returns type PT_FOLDER
120 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
122 DECLARE_TYPE(CSIDL_INTERNET
, guidType
),
123 DECLARE_TYPE(CSIDL_NETHOOD
, folderType
),
124 DECLARE_TYPE(CSIDL_NETWORK
, guidType
),
125 DECLARE_TYPE(CSIDL_PERSONAL
, personalType
),
126 DECLARE_TYPE(CSIDL_PRINTERS
, printersType
),
127 DECLARE_TYPE(CSIDL_PRINTHOOD
, folderType
),
128 DECLARE_TYPE(CSIDL_PROGRAMS
, folderType
),
129 DECLARE_TYPE(CSIDL_RECENT
, folderOrSpecialType
),
130 DECLARE_TYPE(CSIDL_SENDTO
, folderType
),
131 DECLARE_TYPE(CSIDL_STARTMENU
, folderType
),
132 DECLARE_TYPE(CSIDL_STARTUP
, folderType
),
133 DECLARE_TYPE(CSIDL_TEMPLATES
, folderType
),
135 static const struct shellExpectedValues optionalShellValues
[] = {
136 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
137 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
138 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
139 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
141 /* Windows NT-only: */
142 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY
, folderType
),
143 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS
, shellExtType
),
144 DECLARE_TYPE(CSIDL_COMMON_FAVORITES
, folderType
),
145 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS
, folderType
),
146 DECLARE_TYPE(CSIDL_COMMON_STARTMENU
, folderType
),
147 DECLARE_TYPE(CSIDL_COMMON_STARTUP
, folderType
),
148 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES
, folderType
),
149 /* first appearing in shell32 version 4.71: */
150 DECLARE_TYPE(CSIDL_APPDATA
, folderType
),
151 /* first appearing in shell32 version 4.72: */
152 DECLARE_TYPE(CSIDL_INTERNET_CACHE
, ieSpecialType
),
153 /* first appearing in shell32 version 5.0: */
154 DECLARE_TYPE(CSIDL_ADMINTOOLS
, folderType
),
155 DECLARE_TYPE(CSIDL_COMMON_APPDATA
, folderType
),
156 DECLARE_TYPE(CSIDL_LOCAL_APPDATA
, folderType
),
157 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS
, folderType
),
158 DECLARE_TYPE(CSIDL_MYMUSIC
, folderType
),
159 DECLARE_TYPE(CSIDL_MYPICTURES
, folderType
),
160 DECLARE_TYPE(CSIDL_MYVIDEO
, folderType
),
161 DECLARE_TYPE(CSIDL_PROFILE
, folderType
),
162 DECLARE_TYPE(CSIDL_PROGRAM_FILES
, folderType
),
163 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86
, folderType
),
164 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON
, folderType
),
165 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86
, folderType
),
166 DECLARE_TYPE(CSIDL_SYSTEM
, folderType
),
167 DECLARE_TYPE(CSIDL_WINDOWS
, folderType
),
168 /* first appearing in shell32 6.0: */
169 DECLARE_TYPE(CSIDL_CDBURN_AREA
, folderType
),
170 DECLARE_TYPE(CSIDL_COMMON_MUSIC
, folderType
),
171 DECLARE_TYPE(CSIDL_COMMON_PICTURES
, folderType
),
172 DECLARE_TYPE(CSIDL_COMMON_VIDEO
, folderType
),
173 DECLARE_TYPE(CSIDL_COMPUTERSNEARME
, workgroupType
),
174 DECLARE_TYPE(CSIDL_RESOURCES
, folderType
),
175 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED
, folderType
),
179 static void loadShell32(void)
181 HMODULE hShell32
= GetModuleHandleA("shell32");
183 #define GET_PROC(func) \
184 p ## func = (void*)GetProcAddress(hShell32, #func); \
186 trace("GetProcAddress(%s) failed\n", #func);
188 GET_PROC(DllGetVersion
)
189 GET_PROC(SHGetFolderPathA
)
190 GET_PROC(SHGetFolderLocation
)
191 GET_PROC(SHGetSpecialFolderPathA
)
192 GET_PROC(SHGetSpecialFolderLocation
)
193 GET_PROC(ILFindLastID
)
195 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
196 GET_PROC(SHFileOperationA
)
197 GET_PROC(SHGetMalloc
)
199 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
202 HRESULT hr
= pSHGetMalloc(&pMalloc
);
204 ok(SUCCEEDED(hr
), "SHGetMalloc failed: 0x%08x\n", hr
);
205 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
210 shellVersion
.cbSize
= sizeof(shellVersion
);
211 pDllGetVersion(&shellVersion
);
212 trace("shell32 version is %d.%d\n",
213 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
218 #ifndef CSIDL_PROFILES
219 #define CSIDL_PROFILES 0x003e
222 /* A couple utility printing functions */
223 static const char *getFolderName(int folder
)
225 static char unknown
[32];
227 #define CSIDL_TO_STR(x) case x: return#x;
230 CSIDL_TO_STR(CSIDL_DESKTOP
);
231 CSIDL_TO_STR(CSIDL_INTERNET
);
232 CSIDL_TO_STR(CSIDL_PROGRAMS
);
233 CSIDL_TO_STR(CSIDL_CONTROLS
);
234 CSIDL_TO_STR(CSIDL_PRINTERS
);
235 CSIDL_TO_STR(CSIDL_PERSONAL
);
236 CSIDL_TO_STR(CSIDL_FAVORITES
);
237 CSIDL_TO_STR(CSIDL_STARTUP
);
238 CSIDL_TO_STR(CSIDL_RECENT
);
239 CSIDL_TO_STR(CSIDL_SENDTO
);
240 CSIDL_TO_STR(CSIDL_BITBUCKET
);
241 CSIDL_TO_STR(CSIDL_STARTMENU
);
242 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS
);
243 CSIDL_TO_STR(CSIDL_MYMUSIC
);
244 CSIDL_TO_STR(CSIDL_MYVIDEO
);
245 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
246 CSIDL_TO_STR(CSIDL_DRIVES
);
247 CSIDL_TO_STR(CSIDL_NETWORK
);
248 CSIDL_TO_STR(CSIDL_NETHOOD
);
249 CSIDL_TO_STR(CSIDL_FONTS
);
250 CSIDL_TO_STR(CSIDL_TEMPLATES
);
251 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
252 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
253 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
254 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
255 CSIDL_TO_STR(CSIDL_APPDATA
);
256 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
257 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
258 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
259 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
260 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
261 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
262 CSIDL_TO_STR(CSIDL_COOKIES
);
263 CSIDL_TO_STR(CSIDL_HISTORY
);
264 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
265 CSIDL_TO_STR(CSIDL_WINDOWS
);
266 CSIDL_TO_STR(CSIDL_SYSTEM
);
267 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
268 CSIDL_TO_STR(CSIDL_MYPICTURES
);
269 CSIDL_TO_STR(CSIDL_PROFILE
);
270 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
271 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
272 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
273 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
274 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
275 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
276 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
277 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
278 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
279 CSIDL_TO_STR(CSIDL_PROFILES
);
280 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
281 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
282 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
283 CSIDL_TO_STR(CSIDL_RESOURCES
);
284 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
285 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
286 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
287 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
290 sprintf(unknown
, "unknown (0x%04x)", folder
);
295 static const char *printGUID(const GUID
*guid
, char * guidSTR
)
297 if (!guid
) return NULL
;
299 sprintf(guidSTR
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
300 guid
->Data1
, guid
->Data2
, guid
->Data3
,
301 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
302 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
306 static void testSHGetFolderLocationInvalidArgs(void)
311 if (!pSHGetFolderLocation
) return;
313 /* check a bogus CSIDL: */
315 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
316 ok(hr
== E_INVALIDARG
,
317 "SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl) returned 0x%08x, expected E_INVALIDARG\n", hr
);
319 IMalloc_Free(pMalloc
, pidl
);
320 /* check a bogus user token: */
322 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
323 ok(hr
== E_FAIL
|| hr
== E_HANDLE
,
324 "SHGetFolderLocation(NULL, CSIDL_FAVORITES, 2, 0, &pidl) returned 0x%08x, expected E_FAIL or E_HANDLE\n", hr
);
326 IMalloc_Free(pMalloc
, pidl
);
327 /* a NULL pidl pointer crashes, so don't test it */
330 static void testSHGetSpecialFolderLocationInvalidArgs(void)
332 LPITEMIDLIST pidl
= NULL
;
335 if (!pSHGetSpecialFolderLocation
) return;
337 /* SHGetSpecialFolderLocation(NULL, 0, NULL) crashes */
338 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
339 ok(hr
== E_INVALIDARG
,
340 "SHGetSpecialFolderLocation(NULL, 0xeeee, &pidl) returned 0x%08x, "
341 "expected E_INVALIDARG\n", hr
);
344 static void testSHGetFolderPathInvalidArgs(void)
349 if (!pSHGetFolderPathA
) return;
351 /* expect 2's a bogus handle, especially since we didn't open it */
352 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2,
353 SHGFP_TYPE_DEFAULT
, path
);
355 hr
== E_HANDLE
|| /* Windows Vista and 2008 */
356 broken(hr
== S_OK
), /* Windows 2000 and Me */
357 "SHGetFolderPathA(NULL, CSIDL_DESKTOP, 2, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_FAIL\n", hr
);
358 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
359 ok(hr
== E_INVALIDARG
,
360 "SHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path) returned 0x%08x, expected E_INVALIDARG\n", hr
);
363 static void testSHGetSpecialFolderPathInvalidArgs(void)
368 if (!pSHGetSpecialFolderPathA
) return;
371 ret
= pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_BITBUCKET
, FALSE
);
373 "SHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE) returned TRUE, expected FALSE\n");
375 /* odd but true: calling with a NULL path still succeeds if it's a real
376 * dir (on some windows platform). on winME it generates exception.
378 ret
= pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_PROGRAMS
, FALSE
);
380 "SHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE) returned FALSE, expected TRUE\n");
381 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
383 "SHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE) returned TRUE, expected FALSE\n");
386 static void testApiParameters(void)
388 testSHGetFolderLocationInvalidArgs();
389 testSHGetSpecialFolderLocationInvalidArgs();
390 testSHGetFolderPathInvalidArgs();
391 testSHGetSpecialFolderPathInvalidArgs();
394 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
395 static BYTE
testSHGetFolderLocation(int folder
)
401 /* treat absence of function as success */
402 if (!pSHGetFolderLocation
) return TRUE
;
405 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
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(int folder
)
429 /* treat absence of function as success */
430 if (!pSHGetSpecialFolderLocation
) return TRUE
;
433 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
438 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
441 "%s: ILFindLastID failed\n", getFolderName(folder
));
443 ret
= pidlLast
->mkid
.abID
[0];
444 IMalloc_Free(pMalloc
, pidl
);
450 static void testSHGetFolderPath(BOOL optional
, int folder
)
455 if (!pSHGetFolderPathA
) return;
457 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
458 ok(SUCCEEDED(hr
) || optional
,
459 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\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 BOOL foundTypeMatch
= FALSE
;
488 if (pSHGetFolderLocation
)
490 type
= testSHGetFolderLocation(testEntries
[i
].folder
);
491 for (j
= 0; !foundTypeMatch
&& j
< testEntries
[i
].numTypes
; j
++)
492 if (testEntries
[i
].types
[j
] == type
)
493 foundTypeMatch
= TRUE
;
494 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
495 "%s has unexpected type %d (0x%02x)\n",
496 getFolderName(testEntries
[i
].folder
), type
, type
);
498 type
= testSHGetSpecialFolderLocation(testEntries
[i
].folder
);
499 for (j
= 0, foundTypeMatch
= FALSE
; !foundTypeMatch
&&
500 j
< testEntries
[i
].numTypes
; j
++)
501 if (testEntries
[i
].types
[j
] == type
)
502 foundTypeMatch
= TRUE
;
503 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
504 "%s has unexpected type %d (0x%02x)\n",
505 getFolderName(testEntries
[i
].folder
), type
, type
);
512 testSHGetFolderPath(optional
, testEntries
[i
].folder
);
513 testSHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
519 /* Attempts to verify that the folder path corresponding to the folder CSIDL
520 * value has the same value as the environment variable with name envVar.
521 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
522 * set in this environment; different OS and shell version behave differently.
523 * However, if both are present, fails if envVar's value is not the same
524 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
526 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
530 if (!pSHGetSpecialFolderPathA
) return;
532 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
534 char *envVal
= getenv(envVar
);
536 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
537 "%%%s%% does not match SHGetSpecialFolderPath:\n"
538 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
539 envVar
, envVar
, envVal
, path
);
543 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
544 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
545 * fail if it isn't--that check should already have been done.
546 * Fails if the returned PIDL is a GUID whose value does not match guid.
548 static void matchGUID(int folder
, const GUID
*guid
, const GUID
*guid_alt
)
553 if (!pSHGetFolderLocation
) return;
557 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
560 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
562 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
563 pidlLast
->mkid
.abID
[0] == PT_GUID
))
565 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
566 char shellGuidStr
[39], guidStr
[39], guid_altStr
[39];
569 ok(IsEqualIID(shellGuid
, guid
),
570 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
571 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
));
573 ok(IsEqualIID(shellGuid
, guid
) ||
574 IsEqualIID(shellGuid
, guid_alt
),
575 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder
),
576 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
),
577 printGUID(guid_alt
, guid_altStr
));
579 IMalloc_Free(pMalloc
, pidl
);
583 static void testDesktop(void)
585 testSHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
586 testSHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
589 /* Checks the PIDL type of all the known values. */
590 static void testPidlTypes(void)
593 testShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
),
595 testShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
),
599 /* FIXME: Should be in shobjidl.idl */
600 DEFINE_GUID(CLSID_NetworkExplorerFolder
, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
602 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
603 static void testGUIDs(void)
605 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
, NULL
);
606 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
, NULL
);
607 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
, NULL
);
608 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
, NULL
);
609 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
, &CLSID_NetworkExplorerFolder
); /* Vista and higher */
610 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
, NULL
);
611 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
, NULL
);
614 /* Verifies various shell paths match the environment variables to which they
617 static void testEnvVars(void)
619 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
620 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
621 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
622 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
623 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
624 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
,
625 "CommonProgramFiles");
626 /* this is only set on Wine, but can't hurt to verify it: */
627 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
630 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
631 static BOOL
myPathIsRootA(LPCSTR lpszPath
)
633 if (lpszPath
&& *lpszPath
&&
634 lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
635 return TRUE
; /* X:\ */
638 static LPSTR
myPathRemoveBackslashA( LPSTR lpszPath
)
644 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
645 if (!myPathIsRootA(lpszPath
) && *szTemp
== '\\')
651 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
652 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
653 * every shell32 version supports CSIDL_WINDOWS.
655 static void testWinDir(void)
657 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
659 if (!pSHGetSpecialFolderPathA
) return;
661 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
663 myPathRemoveBackslashA(windowsShellPath
);
664 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
665 myPathRemoveBackslashA(windowsDir
);
666 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
667 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
668 windowsDir
, windowsShellPath
);
672 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
673 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
674 * no foul--not every shell32 version supports CSIDL_SYSTEM.
676 static void testSystemDir(void)
678 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
], systemDirx86
[MAX_PATH
];
680 if (!pSHGetSpecialFolderPathA
) return;
682 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
683 myPathRemoveBackslashA(systemDir
);
684 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
686 myPathRemoveBackslashA(systemShellPath
);
687 ok(!lstrcmpiA(systemDir
, systemShellPath
),
688 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
689 systemDir
, systemShellPath
);
692 if (!pGetSystemWow64DirectoryA
|| !pGetSystemWow64DirectoryA(systemDirx86
, sizeof(systemDirx86
)))
693 GetSystemDirectoryA(systemDirx86
, sizeof(systemDirx86
));
694 myPathRemoveBackslashA(systemDirx86
);
695 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEMX86
, FALSE
))
697 myPathRemoveBackslashA(systemShellPath
);
698 ok(!lstrcmpiA(systemDirx86
, systemShellPath
) || broken(!lstrcmpiA(systemDir
, systemShellPath
)),
699 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
700 systemDir
, systemShellPath
);
704 /* Globals used by subprocesses */
706 static char **myARGV
;
707 static char base
[MAX_PATH
];
708 static char selfname
[MAX_PATH
];
710 static int init(void)
712 myARGC
= winetest_get_mainargs(&myARGV
);
713 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
714 strcpy(selfname
, myARGV
[0]);
718 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
719 * nonexistent directory.
721 static void testNonExistentPath1(void)
725 char *p
, path
[MAX_PATH
];
727 /* test some failure cases first: */
728 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
729 SHGFP_TYPE_CURRENT
, path
);
730 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
731 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr
);
733 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0,
735 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
736 "SHGetFolderLocation returned 0x%08x\n", hr
);
737 if (SUCCEEDED(hr
) && pidl
)
738 IMalloc_Free(pMalloc
, pidl
);
739 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
740 "SHGetSpecialFolderPath succeeded, expected failure\n");
742 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
743 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
744 "SHGetFolderLocation returned 0x%08x\n", hr
);
745 if (SUCCEEDED(hr
) && pidl
)
746 IMalloc_Free(pMalloc
, pidl
);
747 /* now test success: */
748 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
749 SHGFP_TYPE_CURRENT
, path
);
754 trace("CSIDL_FAVORITES was changed to %s\n", path
);
755 ret
= CreateDirectoryA(path
, NULL
);
757 "CreateDirectoryA succeeded but should have failed "
758 "with ERROR_ALREADY_EXISTS\n");
760 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
761 "CreateDirectoryA failed with %d, "
762 "expected ERROR_ALREADY_EXISTS\n",
764 p
= path
+ strlen(path
);
765 strcpy(p
, "\\desktop.ini");
768 SetFileAttributesA( path
, FILE_ATTRIBUTE_NORMAL
);
769 ret
= RemoveDirectoryA(path
);
770 ok( ret
, "failed to remove %s error %u\n", path
, GetLastError() );
773 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
774 "NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", hr
);
777 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
778 * original value of CSIDL_FAVORITES is restored.
780 static void testNonExistentPath2(void)
785 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
786 SHGFP_TYPE_CURRENT
, path
);
787 ok(SUCCEEDED(hr
), "SHGetFolderPath failed: 0x%08x\n", hr
);
790 static void doChild(const char *arg
)
793 testNonExistentPath1();
794 else if (arg
[0] == '2')
795 testNonExistentPath2();
798 /* Tests the return values from the various shell functions both with and
799 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
800 * version 5 of the shell, so don't test unless it's at least version 5.
801 * The test reads a value from the registry, modifies it, calls
802 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
803 * afterward without it. Then it restores the registry and deletes the folder
805 * One oddity with respect to restoration: shell32 caches somehow, so it needs
806 * to be reloaded in order to see the correct (restored) value.
807 * Some APIs unrelated to the ones under test may fail, but I expect they're
808 * covered by other unit tests; I just print out something about failure to
809 * help trace what's going on.
811 static void testNonExistentPath(void)
813 static const char userShellFolders
[] =
814 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
815 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
818 if (!pSHGetFolderPathA
) return;
819 if (!pSHGetFolderLocation
) return;
820 if (!pSHGetSpecialFolderPathA
) return;
821 if (!pSHGetSpecialFolderLocation
) return;
822 if (!pSHFileOperationA
) return;
823 if (shellVersion
.dwMajorVersion
< 5) return;
825 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
830 len
= sizeof(originalPath
);
831 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
832 (LPBYTE
)&originalPath
, &len
))
834 size_t len
= strlen(originalPath
);
836 memcpy(modifiedPath
, originalPath
, len
);
837 modifiedPath
[len
++] = '2';
838 modifiedPath
[len
++] = '\0';
839 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
840 if (!RegSetValueExA(key
, "Favorites", 0, type
,
841 (LPBYTE
)modifiedPath
, len
))
843 char buffer
[MAX_PATH
+20];
844 STARTUPINFOA startup
;
845 PROCESS_INFORMATION info
;
847 sprintf(buffer
, "%s tests/shellpath.c 1", selfname
);
848 memset(&startup
, 0, sizeof(startup
));
849 startup
.cb
= sizeof(startup
);
850 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
851 startup
.dwFlags
= SW_SHOWNORMAL
;
852 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
854 winetest_wait_child_process( info
.hProcess
);
856 /* restore original values: */
857 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
858 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
859 strlen(originalPath
) + 1);
862 sprintf(buffer
, "%s tests/shellpath.c 2", selfname
);
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");
873 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
877 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders
);
880 START_TEST(shellpath
)
885 pGetSystemWow64DirectoryA
= (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
886 "GetSystemWow64DirectoryA" );
892 /* Report missing functions once */
893 if (!pSHGetFolderLocation
)
894 win_skip("SHGetFolderLocation is not available\n");
896 /* first test various combinations of parameters: */
899 /* check known values: */
905 testNonExistentPath();