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(BOOL optional
, int folder
)
393 /* treat absence of function as success */
394 if (!pSHGetFolderLocation
) return TRUE
;
397 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
398 ok(SUCCEEDED(hr
) || optional
,
399 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl) failed: 0x%08x\n", getFolderName(folder
), hr
);
403 "SHGetFolderLocation(NULL, %s, NULL, 0, &pidl) succeeded, but returned pidl is NULL\n", getFolderName(folder
));
406 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
408 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
409 getFolderName(folder
));
411 ret
= pidlLast
->mkid
.abID
[0];
412 IMalloc_Free(pMalloc
, pidl
);
418 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
419 static BYTE
testSHGetSpecialFolderLocation(BOOL optional
, int folder
)
425 /* treat absence of function as success */
426 if (!pSHGetSpecialFolderLocation
) return TRUE
;
429 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
430 ok(SUCCEEDED(hr
) || optional
||
431 broken((folder
== CSIDL_COOKIES
|| folder
== CSIDL_INTERNET
) &&
432 hr
== E_INVALIDARG
) /* NT4 */,
433 "SHGetSpecialFolderLocation(NULL, %s, &pidl) failed: 0x%08x\n", getFolderName(folder
), hr
);
437 "SHGetSpecialFolderLocation(NULL, %s, &pidl) succeeded, but returned pidl is NULL\n", getFolderName(folder
));
440 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
443 "%s: ILFindLastID failed\n", getFolderName(folder
));
445 ret
= pidlLast
->mkid
.abID
[0];
446 IMalloc_Free(pMalloc
, pidl
);
452 static void testSHGetFolderPath(BOOL optional
, int folder
)
457 if (!pSHGetFolderPathA
) return;
459 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
460 ok(SUCCEEDED(hr
) || optional
,
461 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder
), hr
);
464 static void testSHGetSpecialFolderPath(BOOL optional
, int folder
)
469 if (!pSHGetSpecialFolderPathA
) return;
471 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
472 if (ret
&& winetest_interactive
)
473 printf("%s: %s\n", getFolderName(folder
), path
);
475 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
476 getFolderName(folder
));
479 static void testShellValues(const struct shellExpectedValues testEntries
[],
480 int numEntries
, BOOL optional
)
484 for (i
= 0; i
< numEntries
; i
++)
488 BOOL foundTypeMatch
= FALSE
;
490 if (pSHGetFolderLocation
)
492 type
= testSHGetFolderLocation(optional
, testEntries
[i
].folder
);
493 for (j
= 0; !foundTypeMatch
&& j
< testEntries
[i
].numTypes
; j
++)
494 if (testEntries
[i
].types
[j
] == type
)
495 foundTypeMatch
= TRUE
;
496 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
497 "%s has unexpected type %d (0x%02x)\n",
498 getFolderName(testEntries
[i
].folder
), type
, type
);
500 type
= testSHGetSpecialFolderLocation(optional
, testEntries
[i
].folder
);
501 for (j
= 0, foundTypeMatch
= FALSE
; !foundTypeMatch
&&
502 j
< testEntries
[i
].numTypes
; j
++)
503 if (testEntries
[i
].types
[j
] == type
)
504 foundTypeMatch
= TRUE
;
505 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
506 "%s has unexpected type %d (0x%02x)\n",
507 getFolderName(testEntries
[i
].folder
), type
, type
);
514 testSHGetFolderPath(optional
, testEntries
[i
].folder
);
515 testSHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
521 /* Attempts to verify that the folder path corresponding to the folder CSIDL
522 * value has the same value as the environment variable with name envVar.
523 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
524 * set in this environment; different OS and shell version behave differently.
525 * However, if both are present, fails if envVar's value is not the same
526 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
528 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
532 if (!pSHGetSpecialFolderPathA
) return;
534 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
536 char *envVal
= getenv(envVar
);
538 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
539 "%%%s%% does not match SHGetSpecialFolderPath:\n"
540 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
541 envVar
, envVar
, envVal
, path
);
545 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
546 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
547 * fail if it isn't--that check should already have been done.
548 * Fails if the returned PIDL is a GUID whose value does not match guid.
550 static void matchGUID(int folder
, const GUID
*guid
)
555 if (!pSHGetFolderLocation
) return;
559 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
562 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
564 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
565 pidlLast
->mkid
.abID
[0] == PT_GUID
))
567 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
568 char shellGuidStr
[39], guidStr
[39];
570 ok(IsEqualIID(shellGuid
, guid
),
571 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
572 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
));
574 IMalloc_Free(pMalloc
, pidl
);
578 static void testDesktop(void)
580 testSHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
581 testSHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
582 /* Test the desktop; even though SHITEMID should always contain abID of at
583 * least one type, when cb is 0 its value is undefined. So don't check
584 * what the returned type is, just make sure it exists.
586 testSHGetFolderLocation(FALSE
, CSIDL_DESKTOP
);
587 testSHGetSpecialFolderLocation(FALSE
, CSIDL_DESKTOP
);
590 /* Checks the PIDL type of all the known values. */
591 static void testPidlTypes(void)
594 testShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
),
596 testShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
),
600 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
601 static void testGUIDs(void)
603 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
);
604 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
);
605 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
);
606 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
);
607 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
);
608 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
);
609 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
);
612 /* Verifies various shell paths match the environment variables to which they
615 static void testEnvVars(void)
617 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
618 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
619 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
620 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
621 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
622 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
,
623 "CommonProgramFiles");
624 /* this is only set on Wine, but can't hurt to verify it: */
625 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
628 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
629 static BOOL
myPathIsRootA(LPCSTR lpszPath
)
631 if (lpszPath
&& *lpszPath
&&
632 lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
633 return TRUE
; /* X:\ */
636 static LPSTR
myPathRemoveBackslashA( LPSTR lpszPath
)
642 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
643 if (!myPathIsRootA(lpszPath
) && *szTemp
== '\\')
649 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
650 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
651 * every shell32 version supports CSIDL_WINDOWS.
653 static void testWinDir(void)
655 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
657 if (!pSHGetSpecialFolderPathA
) return;
659 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
661 myPathRemoveBackslashA(windowsShellPath
);
662 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
663 myPathRemoveBackslashA(windowsDir
);
664 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
665 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
666 windowsDir
, windowsShellPath
);
670 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
671 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
672 * no foul--not every shell32 version supports CSIDL_SYSTEM.
674 static void testSystemDir(void)
676 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
] = { 0 };
678 if (!pSHGetSpecialFolderPathA
) return;
680 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
681 myPathRemoveBackslashA(systemDir
);
682 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
684 myPathRemoveBackslashA(systemShellPath
);
685 ok(!lstrcmpiA(systemDir
, systemShellPath
),
686 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
687 systemDir
, systemShellPath
);
689 /* CSIDL_SYSTEMX86 isn't checked in the same way, since it's different
690 * on Win64 (and non-x86 Windows systems, if there are any still in
691 * existence) than on Win32.
695 /* Globals used by subprocesses */
697 static char **myARGV
;
698 static char base
[MAX_PATH
];
699 static char selfname
[MAX_PATH
];
701 static int init(void)
703 myARGC
= winetest_get_mainargs(&myARGV
);
704 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
705 strcpy(selfname
, myARGV
[0]);
709 /* Subprocess helper 1: test what happens when CSIDL_FAVORITES is set to a
710 * nonexistent directory.
712 static void testNonExistentPath1(void)
716 char *p
, path
[MAX_PATH
];
718 /* test some failure cases first: */
719 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
,
720 SHGFP_TYPE_CURRENT
, path
);
721 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
722 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr
);
724 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0,
726 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
727 "SHGetFolderLocation returned 0x%08x\n", hr
);
728 if (SUCCEEDED(hr
) && pidl
)
729 IMalloc_Free(pMalloc
, pidl
);
730 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
731 "SHGetSpecialFolderPath succeeded, expected failure\n");
733 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
734 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
735 "SHGetFolderLocation returned 0x%08x\n", hr
);
736 if (SUCCEEDED(hr
) && pidl
)
737 IMalloc_Free(pMalloc
, pidl
);
738 /* now test success: */
739 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
740 SHGFP_TYPE_CURRENT
, path
);
745 trace("CSIDL_FAVORITES was changed to %s\n", path
);
746 ret
= CreateDirectoryA(path
, NULL
);
748 "CreateDirectoryA succeeded but should have failed "
749 "with ERROR_ALREADY_EXISTS\n");
751 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
752 "CreateDirectoryA failed with %d, "
753 "expected ERROR_ALREADY_EXISTS\n",
755 p
= path
+ strlen(path
);
756 strcpy(p
, "\\desktop.ini");
759 SetFileAttributesA( path
, FILE_ATTRIBUTE_NORMAL
);
760 ret
= RemoveDirectoryA(path
);
761 ok( ret
, "failed to remove %s error %u\n", path
, GetLastError() );
764 "SHGetFolderPath(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, "
765 "NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", hr
);
768 /* Subprocess helper 2: make sure SHGetFolderPath still succeeds when the
769 * original value of CSIDL_FAVORITES is restored.
771 static void testNonExistentPath2(void)
776 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
777 SHGFP_TYPE_CURRENT
, path
);
778 ok(SUCCEEDED(hr
), "SHGetFolderPath failed: 0x%08x\n", hr
);
781 static void doChild(const char *arg
)
784 testNonExistentPath1();
785 else if (arg
[0] == '2')
786 testNonExistentPath2();
789 /* Tests the return values from the various shell functions both with and
790 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
791 * version 5 of the shell, so don't test unless it's at least version 5.
792 * The test reads a value from the registry, modifies it, calls
793 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
794 * afterward without it. Then it restores the registry and deletes the folder
796 * One oddity with respect to restoration: shell32 caches somehow, so it needs
797 * to be reloaded in order to see the correct (restored) value.
798 * Some APIs unrelated to the ones under test may fail, but I expect they're
799 * covered by other unit tests; I just print out something about failure to
800 * help trace what's going on.
802 static void testNonExistentPath(void)
804 static const char userShellFolders
[] =
805 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
806 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
809 if (!pSHGetFolderPathA
) return;
810 if (!pSHGetFolderLocation
) return;
811 if (!pSHGetSpecialFolderPathA
) return;
812 if (!pSHGetSpecialFolderLocation
) return;
813 if (!pSHFileOperationA
) return;
814 if (shellVersion
.dwMajorVersion
< 5) return;
816 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
821 len
= sizeof(originalPath
);
822 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
823 (LPBYTE
)&originalPath
, &len
))
825 size_t len
= strlen(originalPath
);
827 memcpy(modifiedPath
, originalPath
, len
);
828 modifiedPath
[len
++] = '2';
829 modifiedPath
[len
++] = '\0';
830 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
831 if (!RegSetValueExA(key
, "Favorites", 0, type
,
832 (LPBYTE
)modifiedPath
, len
))
834 char buffer
[MAX_PATH
+20];
835 STARTUPINFOA startup
;
836 PROCESS_INFORMATION info
;
838 sprintf(buffer
, "%s tests/shellpath.c 1", selfname
);
839 memset(&startup
, 0, sizeof(startup
));
840 startup
.cb
= sizeof(startup
);
841 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
842 startup
.dwFlags
= SW_SHOWNORMAL
;
843 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
845 winetest_wait_child_process( info
.hProcess
);
847 /* restore original values: */
848 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
849 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
850 strlen(originalPath
) + 1);
853 sprintf(buffer
, "%s tests/shellpath.c 2", selfname
);
854 memset(&startup
, 0, sizeof(startup
));
855 startup
.cb
= sizeof(startup
);
856 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
857 startup
.dwFlags
= SW_SHOWNORMAL
;
858 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
860 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
861 "child process termination\n");
864 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
868 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders
);
871 START_TEST(shellpath
)
881 /* Report missing functions once */
882 if (!pSHGetFolderLocation
)
883 skip("SHGetFolderLocation is not available\n");
885 /* first test various combinations of parameters: */
888 /* check known values: */
894 testNonExistentPath();