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 "knownfolders.h"
35 #include "wine/test.h"
37 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
38 * here is its original value.
40 #define OLD_CSIDL_MYDOCUMENTS 0x000c
43 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
46 /* from pidl.h, not included here: */
47 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
48 #define PT_CPL 0x01 /* no path */
51 #define PT_GUID 0x1f /* no path */
54 #define PT_DRIVE 0x23 /* has path */
57 #define PT_DRIVE2 0x25 /* has path */
60 #define PT_SHELLEXT 0x2e /* no path */
63 #define PT_FOLDER 0x31 /* has path */
66 #define PT_FOLDERW 0x35 /* has path */
69 #define PT_WORKGRP 0x41 /* no path */
72 #define PT_YAGUID 0x70 /* no path */
74 /* FIXME: this is used for history/favorites folders; what's a better name? */
76 #define PT_IESPECIAL2 0xb1 /* has path */
79 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
81 struct shellExpectedValues
{
87 static HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
88 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
89 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
91 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
92 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
93 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
94 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
95 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
96 static UINT (WINAPI
*pGetSystemWow64DirectoryA
)(LPSTR
,UINT
);
97 static HRESULT (WINAPI
*pSHGetKnownFolderPath
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, PWSTR
*);
98 static HRESULT (WINAPI
*pSHSetKnownFolderPath
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, PWSTR
);
99 static HRESULT (WINAPI
*pSHGetFolderPathEx
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, LPWSTR
, DWORD
);
101 static DLLVERSIONINFO shellVersion
= { 0 };
102 static LPMALLOC pMalloc
;
103 static const BYTE guidType
[] = { PT_GUID
};
104 static const BYTE controlPanelType
[] = { PT_SHELLEXT
, PT_GUID
, PT_CPL
};
105 static const BYTE folderType
[] = { PT_FOLDER
, PT_FOLDERW
};
106 static const BYTE favoritesType
[] = { PT_FOLDER
, PT_FOLDERW
, 0, PT_IESPECIAL2
/* Win98 */ };
107 static const BYTE folderOrSpecialType
[] = { PT_FOLDER
, PT_IESPECIAL2
};
108 static const BYTE personalType
[] = { PT_FOLDER
, PT_GUID
, PT_DRIVE
, 0xff /* Win9x */,
109 PT_IESPECIAL2
/* Win98 */, 0 /* Vista */ };
110 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
111 static const BYTE printersType
[] = { PT_YAGUID
, PT_SHELLEXT
, 0x71 };
112 static const BYTE ieSpecialType
[] = { PT_IESPECIAL2
};
113 static const BYTE shellExtType
[] = { PT_SHELLEXT
};
114 static const BYTE workgroupType
[] = { PT_WORKGRP
};
115 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
116 static const struct shellExpectedValues requiredShellValues
[] = {
117 DECLARE_TYPE(CSIDL_BITBUCKET
, guidType
),
118 DECLARE_TYPE(CSIDL_CONTROLS
, controlPanelType
),
119 DECLARE_TYPE(CSIDL_COOKIES
, folderType
),
120 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY
, folderType
),
121 DECLARE_TYPE(CSIDL_DRIVES
, guidType
),
122 DECLARE_TYPE(CSIDL_FAVORITES
, favoritesType
),
123 DECLARE_TYPE(CSIDL_FONTS
, folderOrSpecialType
),
124 /* FIXME: the following fails in Wine, returns type PT_FOLDER
125 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
127 DECLARE_TYPE(CSIDL_INTERNET
, guidType
),
128 DECLARE_TYPE(CSIDL_NETHOOD
, folderType
),
129 DECLARE_TYPE(CSIDL_NETWORK
, guidType
),
130 DECLARE_TYPE(CSIDL_PERSONAL
, personalType
),
131 DECLARE_TYPE(CSIDL_PRINTERS
, printersType
),
132 DECLARE_TYPE(CSIDL_PRINTHOOD
, folderType
),
133 DECLARE_TYPE(CSIDL_PROGRAMS
, folderType
),
134 DECLARE_TYPE(CSIDL_RECENT
, folderOrSpecialType
),
135 DECLARE_TYPE(CSIDL_SENDTO
, folderType
),
136 DECLARE_TYPE(CSIDL_STARTMENU
, folderType
),
137 DECLARE_TYPE(CSIDL_STARTUP
, folderType
),
138 DECLARE_TYPE(CSIDL_TEMPLATES
, folderType
),
140 static const struct shellExpectedValues optionalShellValues
[] = {
141 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
142 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
143 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
144 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
146 /* Windows NT-only: */
147 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY
, folderType
),
148 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS
, shellExtType
),
149 DECLARE_TYPE(CSIDL_COMMON_FAVORITES
, folderType
),
150 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS
, folderType
),
151 DECLARE_TYPE(CSIDL_COMMON_STARTMENU
, folderType
),
152 DECLARE_TYPE(CSIDL_COMMON_STARTUP
, folderType
),
153 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES
, folderType
),
154 /* first appearing in shell32 version 4.71: */
155 DECLARE_TYPE(CSIDL_APPDATA
, folderType
),
156 /* first appearing in shell32 version 4.72: */
157 DECLARE_TYPE(CSIDL_INTERNET_CACHE
, ieSpecialType
),
158 /* first appearing in shell32 version 5.0: */
159 DECLARE_TYPE(CSIDL_ADMINTOOLS
, folderType
),
160 DECLARE_TYPE(CSIDL_COMMON_APPDATA
, folderType
),
161 DECLARE_TYPE(CSIDL_LOCAL_APPDATA
, folderType
),
162 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS
, folderType
),
163 DECLARE_TYPE(CSIDL_MYMUSIC
, folderType
),
164 DECLARE_TYPE(CSIDL_MYPICTURES
, folderType
),
165 DECLARE_TYPE(CSIDL_MYVIDEO
, folderType
),
166 DECLARE_TYPE(CSIDL_PROFILE
, folderType
),
167 DECLARE_TYPE(CSIDL_PROGRAM_FILES
, folderType
),
168 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86
, folderType
),
169 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON
, folderType
),
170 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86
, folderType
),
171 DECLARE_TYPE(CSIDL_SYSTEM
, folderType
),
172 DECLARE_TYPE(CSIDL_WINDOWS
, folderType
),
173 /* first appearing in shell32 6.0: */
174 DECLARE_TYPE(CSIDL_CDBURN_AREA
, folderType
),
175 DECLARE_TYPE(CSIDL_COMMON_MUSIC
, folderType
),
176 DECLARE_TYPE(CSIDL_COMMON_PICTURES
, folderType
),
177 DECLARE_TYPE(CSIDL_COMMON_VIDEO
, folderType
),
178 DECLARE_TYPE(CSIDL_COMPUTERSNEARME
, workgroupType
),
179 DECLARE_TYPE(CSIDL_RESOURCES
, folderType
),
180 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED
, folderType
),
184 static void loadShell32(void)
186 HMODULE hShell32
= GetModuleHandleA("shell32");
188 #define GET_PROC(func) \
189 p ## func = (void*)GetProcAddress(hShell32, #func); \
191 trace("GetProcAddress(%s) failed\n", #func);
193 GET_PROC(DllGetVersion
)
194 GET_PROC(SHGetFolderPathA
)
195 GET_PROC(SHGetFolderPathEx
)
196 GET_PROC(SHGetFolderLocation
)
197 GET_PROC(SHGetKnownFolderPath
)
198 GET_PROC(SHSetKnownFolderPath
)
199 GET_PROC(SHGetSpecialFolderPathA
)
200 GET_PROC(SHGetSpecialFolderLocation
)
201 GET_PROC(ILFindLastID
)
203 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
204 GET_PROC(SHFileOperationA
)
205 GET_PROC(SHGetMalloc
)
207 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
210 HRESULT hr
= pSHGetMalloc(&pMalloc
);
212 ok(hr
== S_OK
, "SHGetMalloc failed: 0x%08x\n", hr
);
213 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
218 shellVersion
.cbSize
= sizeof(shellVersion
);
219 pDllGetVersion(&shellVersion
);
220 trace("shell32 version is %d.%d\n",
221 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
226 #ifndef CSIDL_PROFILES
227 #define CSIDL_PROFILES 0x003e
230 /* A couple utility printing functions */
231 static const char *getFolderName(int folder
)
233 static char unknown
[32];
235 #define CSIDL_TO_STR(x) case x: return#x;
238 CSIDL_TO_STR(CSIDL_DESKTOP
);
239 CSIDL_TO_STR(CSIDL_INTERNET
);
240 CSIDL_TO_STR(CSIDL_PROGRAMS
);
241 CSIDL_TO_STR(CSIDL_CONTROLS
);
242 CSIDL_TO_STR(CSIDL_PRINTERS
);
243 CSIDL_TO_STR(CSIDL_PERSONAL
);
244 CSIDL_TO_STR(CSIDL_FAVORITES
);
245 CSIDL_TO_STR(CSIDL_STARTUP
);
246 CSIDL_TO_STR(CSIDL_RECENT
);
247 CSIDL_TO_STR(CSIDL_SENDTO
);
248 CSIDL_TO_STR(CSIDL_BITBUCKET
);
249 CSIDL_TO_STR(CSIDL_STARTMENU
);
250 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS
);
251 CSIDL_TO_STR(CSIDL_MYMUSIC
);
252 CSIDL_TO_STR(CSIDL_MYVIDEO
);
253 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
254 CSIDL_TO_STR(CSIDL_DRIVES
);
255 CSIDL_TO_STR(CSIDL_NETWORK
);
256 CSIDL_TO_STR(CSIDL_NETHOOD
);
257 CSIDL_TO_STR(CSIDL_FONTS
);
258 CSIDL_TO_STR(CSIDL_TEMPLATES
);
259 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
260 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
261 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
262 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
263 CSIDL_TO_STR(CSIDL_APPDATA
);
264 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
265 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
266 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
267 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
268 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
269 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
270 CSIDL_TO_STR(CSIDL_COOKIES
);
271 CSIDL_TO_STR(CSIDL_HISTORY
);
272 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
273 CSIDL_TO_STR(CSIDL_WINDOWS
);
274 CSIDL_TO_STR(CSIDL_SYSTEM
);
275 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
276 CSIDL_TO_STR(CSIDL_MYPICTURES
);
277 CSIDL_TO_STR(CSIDL_PROFILE
);
278 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
279 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
280 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
281 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
282 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
283 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
284 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
285 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
286 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
287 CSIDL_TO_STR(CSIDL_PROFILES
);
288 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
289 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
290 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
291 CSIDL_TO_STR(CSIDL_RESOURCES
);
292 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
293 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
294 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
295 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
298 sprintf(unknown
, "unknown (0x%04x)", folder
);
303 static const char *printGUID(const GUID
*guid
, char * guidSTR
)
305 if (!guid
) return NULL
;
307 sprintf(guidSTR
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
308 guid
->Data1
, guid
->Data2
, guid
->Data3
,
309 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
310 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
314 static void test_parameters(void)
316 LPITEMIDLIST pidl
= NULL
;
320 if (pSHGetFolderLocation
)
322 /* check a bogus CSIDL: */
324 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
325 ok(hr
== E_INVALIDARG
, "got 0x%08x, expected E_INVALIDARG\n", hr
);
326 if (hr
== S_OK
) IMalloc_Free(pMalloc
, pidl
);
328 /* check a bogus user token: */
330 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
331 ok(hr
== E_FAIL
|| hr
== E_HANDLE
, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr
);
332 if (hr
== S_OK
) IMalloc_Free(pMalloc
, pidl
);
334 /* a NULL pidl pointer crashes, so don't test it */
337 if (pSHGetSpecialFolderLocation
)
341 SHGetSpecialFolderLocation(NULL
, 0, NULL
);
343 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
344 ok(hr
== E_INVALIDARG
, "got returned 0x%08x\n", hr
);
347 if (pSHGetFolderPathA
)
349 /* expect 2's a bogus handle, especially since we didn't open it */
350 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2, SHGFP_TYPE_DEFAULT
, path
);
351 ok(hr
== E_FAIL
|| hr
== E_HANDLE
|| /* Vista and 2k8 */
352 broken(hr
== S_OK
), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr
);
354 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
355 ok(hr
== E_INVALIDARG
, "got 0x%08x, expected E_INVALIDARG\n", hr
);
358 if (pSHGetSpecialFolderPathA
)
363 pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_BITBUCKET
, FALSE
);
365 /* odd but true: calling with a NULL path still succeeds if it's a real
366 * dir (on some windows platform). on winME it generates exception.
368 ret
= pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_PROGRAMS
, FALSE
);
369 ok(ret
, "got %d\n", ret
);
371 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
372 ok(!ret
, "got %d\n", ret
);
376 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
377 static BYTE
testSHGetFolderLocation(int folder
)
383 /* treat absence of function as success */
384 if (!pSHGetFolderLocation
) return TRUE
;
387 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
392 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
394 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
395 getFolderName(folder
));
397 ret
= pidlLast
->mkid
.abID
[0];
398 IMalloc_Free(pMalloc
, pidl
);
404 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
405 static BYTE
testSHGetSpecialFolderLocation(int folder
)
411 /* treat absence of function as success */
412 if (!pSHGetSpecialFolderLocation
) return TRUE
;
415 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
420 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
423 "%s: ILFindLastID failed\n", getFolderName(folder
));
425 ret
= pidlLast
->mkid
.abID
[0];
426 IMalloc_Free(pMalloc
, pidl
);
432 static void test_SHGetFolderPath(BOOL optional
, int folder
)
437 if (!pSHGetFolderPathA
) return;
439 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
440 ok(hr
== S_OK
|| optional
,
441 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder
), hr
);
444 static void test_SHGetSpecialFolderPath(BOOL optional
, int folder
)
449 if (!pSHGetSpecialFolderPathA
) return;
451 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
452 if (ret
&& winetest_interactive
)
453 printf("%s: %s\n", getFolderName(folder
), path
);
455 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
456 getFolderName(folder
));
459 static void test_ShellValues(const struct shellExpectedValues testEntries
[],
460 int numEntries
, BOOL optional
)
464 for (i
= 0; i
< numEntries
; i
++)
468 BOOL foundTypeMatch
= FALSE
;
470 if (pSHGetFolderLocation
)
472 type
= testSHGetFolderLocation(testEntries
[i
].folder
);
473 for (j
= 0; !foundTypeMatch
&& j
< testEntries
[i
].numTypes
; j
++)
474 if (testEntries
[i
].types
[j
] == type
)
475 foundTypeMatch
= TRUE
;
476 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
477 "%s has unexpected type %d (0x%02x)\n",
478 getFolderName(testEntries
[i
].folder
), type
, type
);
480 type
= testSHGetSpecialFolderLocation(testEntries
[i
].folder
);
481 for (j
= 0, foundTypeMatch
= FALSE
; !foundTypeMatch
&&
482 j
< testEntries
[i
].numTypes
; j
++)
483 if (testEntries
[i
].types
[j
] == type
)
484 foundTypeMatch
= TRUE
;
485 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
486 "%s has unexpected type %d (0x%02x)\n",
487 getFolderName(testEntries
[i
].folder
), type
, type
);
494 test_SHGetFolderPath(optional
, testEntries
[i
].folder
);
495 test_SHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
501 /* Attempts to verify that the folder path corresponding to the folder CSIDL
502 * value has the same value as the environment variable with name envVar.
503 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
504 * set in this environment; different OS and shell version behave differently.
505 * However, if both are present, fails if envVar's value is not the same
506 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
508 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
512 if (!pSHGetSpecialFolderPathA
) return;
514 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
516 char *envVal
= getenv(envVar
);
518 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
519 "%%%s%% does not match SHGetSpecialFolderPath:\n"
520 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
521 envVar
, envVar
, envVal
, path
);
525 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
526 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
527 * fail if it isn't--that check should already have been done.
528 * Fails if the returned PIDL is a GUID whose value does not match guid.
530 static void matchGUID(int folder
, const GUID
*guid
, const GUID
*guid_alt
)
535 if (!pSHGetFolderLocation
) return;
539 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
542 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
544 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
545 pidlLast
->mkid
.abID
[0] == PT_GUID
))
547 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
548 char shellGuidStr
[39], guidStr
[39], guid_altStr
[39];
551 ok(IsEqualIID(shellGuid
, guid
),
552 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
553 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
));
555 ok(IsEqualIID(shellGuid
, guid
) ||
556 IsEqualIID(shellGuid
, guid_alt
),
557 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder
),
558 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
),
559 printGUID(guid_alt
, guid_altStr
));
561 IMalloc_Free(pMalloc
, pidl
);
565 /* Checks the PIDL type of all the known values. */
566 static void test_PidlTypes(void)
569 test_SHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
570 test_SHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
572 test_ShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
), FALSE
);
573 test_ShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
), TRUE
);
576 /* FIXME: Should be in shobjidl.idl */
577 DEFINE_GUID(CLSID_NetworkExplorerFolder
, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
579 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
580 static void test_GUIDs(void)
582 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
, NULL
);
583 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
, NULL
);
584 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
, NULL
);
585 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
, NULL
);
586 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
, &CLSID_NetworkExplorerFolder
); /* Vista and higher */
587 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
, NULL
);
588 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
, NULL
);
589 matchGUID(CSIDL_PRINTERS
, &CLSID_Printers
, NULL
);
592 /* Verifies various shell paths match the environment variables to which they
595 static void test_EnvVars(void)
597 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
598 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
599 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
600 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
601 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
602 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
, "CommonProgramFiles");
603 /* this is only set on Wine, but can't hurt to verify it: */
604 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
607 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
608 static BOOL
myPathIsRootA(LPCSTR lpszPath
)
610 if (lpszPath
&& *lpszPath
&&
611 lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
612 return TRUE
; /* X:\ */
615 static LPSTR
myPathRemoveBackslashA( LPSTR lpszPath
)
621 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
622 if (!myPathIsRootA(lpszPath
) && *szTemp
== '\\')
628 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
629 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
630 * every shell32 version supports CSIDL_WINDOWS.
632 static void testWinDir(void)
634 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
636 if (!pSHGetSpecialFolderPathA
) return;
638 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
640 myPathRemoveBackslashA(windowsShellPath
);
641 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
642 myPathRemoveBackslashA(windowsDir
);
643 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
644 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
645 windowsDir
, windowsShellPath
);
649 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
650 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
651 * no foul--not every shell32 version supports CSIDL_SYSTEM.
653 static void testSystemDir(void)
655 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
], systemDirx86
[MAX_PATH
];
657 if (!pSHGetSpecialFolderPathA
) return;
659 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
660 myPathRemoveBackslashA(systemDir
);
661 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
663 myPathRemoveBackslashA(systemShellPath
);
664 ok(!lstrcmpiA(systemDir
, systemShellPath
),
665 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
666 systemDir
, systemShellPath
);
669 if (!pGetSystemWow64DirectoryA
|| !pGetSystemWow64DirectoryA(systemDirx86
, sizeof(systemDirx86
)))
670 GetSystemDirectoryA(systemDirx86
, sizeof(systemDirx86
));
671 myPathRemoveBackslashA(systemDirx86
);
672 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEMX86
, FALSE
))
674 myPathRemoveBackslashA(systemShellPath
);
675 ok(!lstrcmpiA(systemDirx86
, systemShellPath
) || broken(!lstrcmpiA(systemDir
, systemShellPath
)),
676 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
677 systemDir
, systemShellPath
);
681 /* Globals used by subprocesses */
683 static char **myARGV
;
684 static char base
[MAX_PATH
];
685 static char selfname
[MAX_PATH
];
687 static int init(void)
689 myARGC
= winetest_get_mainargs(&myARGV
);
690 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
691 strcpy(selfname
, myARGV
[0]);
695 static void doChild(const char *arg
)
705 /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
707 /* test some failure cases first: */
708 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
, SHGFP_TYPE_CURRENT
, path
);
709 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
710 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr
);
713 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0, &pidl
);
714 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
715 "SHGetFolderLocation returned 0x%08x\n", hr
);
716 if (hr
== S_OK
&& pidl
) IMalloc_Free(pMalloc
, pidl
);
718 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
719 "SHGetSpecialFolderPath succeeded, expected failure\n");
722 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
723 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
724 "SHGetFolderLocation returned 0x%08x\n", hr
);
726 if (hr
== S_OK
&& pidl
) IMalloc_Free(pMalloc
, pidl
);
728 /* now test success: */
729 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
730 SHGFP_TYPE_CURRENT
, path
);
731 ok (hr
== S_OK
, "got 0x%08x\n", hr
);
736 trace("CSIDL_FAVORITES was changed to %s\n", path
);
737 ret
= CreateDirectoryA(path
, NULL
);
738 ok(!ret
, "expected failure with ERROR_ALREADY_EXISTS\n");
740 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
741 "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
743 p
= path
+ strlen(path
);
744 strcpy(p
, "\\desktop.ini");
747 SetFileAttributesA( path
, FILE_ATTRIBUTE_NORMAL
);
748 ret
= RemoveDirectoryA(path
);
749 ok( ret
, "failed to remove %s error %u\n", path
, GetLastError() );
752 else if (arg
[0] == '2')
754 /* make sure SHGetFolderPath still succeeds when the
755 original value of CSIDL_FAVORITES is restored. */
756 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
757 SHGFP_TYPE_CURRENT
, path
);
758 ok(hr
== S_OK
, "SHGetFolderPath failed: 0x%08x\n", hr
);
762 /* Tests the return values from the various shell functions both with and
763 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
764 * version 5 of the shell, so don't test unless it's at least version 5.
765 * The test reads a value from the registry, modifies it, calls
766 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
767 * afterward without it. Then it restores the registry and deletes the folder
769 * One oddity with respect to restoration: shell32 caches somehow, so it needs
770 * to be reloaded in order to see the correct (restored) value.
771 * Some APIs unrelated to the ones under test may fail, but I expect they're
772 * covered by other unit tests; I just print out something about failure to
773 * help trace what's going on.
775 static void test_NonExistentPath(void)
777 static const char userShellFolders
[] =
778 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
779 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
782 if (!pSHGetFolderPathA
) return;
783 if (!pSHGetFolderLocation
) return;
784 if (!pSHGetSpecialFolderPathA
) return;
785 if (!pSHGetSpecialFolderLocation
) return;
786 if (!pSHFileOperationA
) return;
787 if (shellVersion
.dwMajorVersion
< 5) return;
789 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
794 len
= sizeof(originalPath
);
795 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
796 (LPBYTE
)&originalPath
, &len
))
798 size_t len
= strlen(originalPath
);
800 memcpy(modifiedPath
, originalPath
, len
);
801 modifiedPath
[len
++] = '2';
802 modifiedPath
[len
++] = '\0';
803 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
804 if (!RegSetValueExA(key
, "Favorites", 0, type
,
805 (LPBYTE
)modifiedPath
, len
))
807 char buffer
[MAX_PATH
+20];
808 STARTUPINFOA startup
;
809 PROCESS_INFORMATION info
;
811 sprintf(buffer
, "%s tests/shellpath.c 1", selfname
);
812 memset(&startup
, 0, sizeof(startup
));
813 startup
.cb
= sizeof(startup
);
814 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
815 startup
.dwFlags
= SW_SHOWNORMAL
;
816 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
818 winetest_wait_child_process( info
.hProcess
);
820 /* restore original values: */
821 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
822 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
823 strlen(originalPath
) + 1);
826 sprintf(buffer
, "%s tests/shellpath.c 2", selfname
);
827 memset(&startup
, 0, sizeof(startup
));
828 startup
.cb
= sizeof(startup
);
829 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
830 startup
.dwFlags
= SW_SHOWNORMAL
;
831 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
833 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
834 "child process termination\n");
837 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
841 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders
);
844 static void test_SHGetFolderPathEx(void)
847 WCHAR buffer
[MAX_PATH
], *path
;
850 if (!pSHGetKnownFolderPath
|| !pSHGetFolderPathEx
)
852 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
856 if (0) { /* crashes */
857 hr
= pSHGetKnownFolderPath(&FOLDERID_Desktop
, 0, NULL
, NULL
);
858 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
861 hr
= pSHGetKnownFolderPath(&FOLDERID_Desktop
, 0, NULL
, &path
);
862 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
863 ok(path
!= NULL
, "expected path != NULL\n");
865 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, MAX_PATH
);
866 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
867 ok(!lstrcmpiW(path
, buffer
), "expected equal paths\n");
868 len
= lstrlenW(buffer
);
871 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, 0);
872 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
874 if (0) { /* crashes */
875 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, NULL
, len
+ 1);
876 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
878 hr
= pSHGetFolderPathEx(NULL
, 0, NULL
, buffer
, MAX_PATH
);
879 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
881 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, len
);
882 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
), "expected 0x8007007a, got 0x%08x\n", hr
);
884 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, len
+ 1);
885 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
888 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
889 #define NO_CSIDL 0x10000
890 #define CSIDL_TODO_WINE 0x20000
891 #define KNOWN_FOLDER(id, csidl) \
892 { &id, # id, csidl, # csidl, __LINE__ }
894 struct knownFolderDef
{
895 const KNOWNFOLDERID
*folderId
;
896 const char *sFolderId
;
902 static const struct knownFolderDef known_folders
[] = {
903 KNOWN_FOLDER(FOLDERID_AddNewPrograms
, NO_CSIDL
),
904 KNOWN_FOLDER(FOLDERID_AdminTools
, CSIDL_ADMINTOOLS
),
905 KNOWN_FOLDER(FOLDERID_AppUpdates
, NO_CSIDL
),
906 KNOWN_FOLDER(FOLDERID_CDBurning
, CSIDL_CDBURN_AREA
),
907 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms
, NO_CSIDL
),
908 KNOWN_FOLDER(FOLDERID_CommonAdminTools
, CSIDL_COMMON_ADMINTOOLS
),
909 KNOWN_FOLDER(FOLDERID_CommonOEMLinks
, CSIDL_COMMON_OEM_LINKS
),
910 KNOWN_FOLDER(FOLDERID_CommonPrograms
, CSIDL_COMMON_PROGRAMS
),
911 KNOWN_FOLDER(FOLDERID_CommonStartMenu
, CSIDL_COMMON_STARTMENU
),
912 KNOWN_FOLDER(FOLDERID_CommonStartup
, CSIDL_COMMON_STARTUP
),
913 KNOWN_FOLDER(FOLDERID_CommonTemplates
, CSIDL_COMMON_TEMPLATES
),
914 KNOWN_FOLDER(FOLDERID_ComputerFolder
, CSIDL_DRIVES
),
915 KNOWN_FOLDER(FOLDERID_ConflictFolder
, NO_CSIDL
),
916 KNOWN_FOLDER(FOLDERID_ConnectionsFolder
, CSIDL_CONNECTIONS
),
917 KNOWN_FOLDER(FOLDERID_Contacts
, NO_CSIDL
),
918 KNOWN_FOLDER(FOLDERID_ControlPanelFolder
, CSIDL_CONTROLS
),
919 KNOWN_FOLDER(FOLDERID_Cookies
, CSIDL_COOKIES
),
920 KNOWN_FOLDER(FOLDERID_Desktop
, CSIDL_DESKTOP
),
921 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore
, NO_CSIDL
),
922 KNOWN_FOLDER(FOLDERID_Documents
, CSIDL_MYDOCUMENTS
| CSIDL_TODO_WINE
),
923 KNOWN_FOLDER(FOLDERID_DocumentsLibrary
, NO_CSIDL
),
924 KNOWN_FOLDER(FOLDERID_Downloads
, NO_CSIDL
),
925 KNOWN_FOLDER(FOLDERID_Favorites
, CSIDL_FAVORITES
),
926 KNOWN_FOLDER(FOLDERID_Fonts
, CSIDL_FONTS
),
927 KNOWN_FOLDER(FOLDERID_Games
, NO_CSIDL
),
928 KNOWN_FOLDER(FOLDERID_GameTasks
, NO_CSIDL
),
929 KNOWN_FOLDER(FOLDERID_History
, CSIDL_HISTORY
),
930 KNOWN_FOLDER(FOLDERID_HomeGroup
, NO_CSIDL
),
931 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts
, NO_CSIDL
),
932 KNOWN_FOLDER(FOLDERID_InternetCache
, CSIDL_INTERNET_CACHE
),
933 KNOWN_FOLDER(FOLDERID_InternetFolder
, CSIDL_INTERNET
),
934 KNOWN_FOLDER(FOLDERID_Libraries
, NO_CSIDL
),
935 KNOWN_FOLDER(FOLDERID_Links
, NO_CSIDL
),
936 KNOWN_FOLDER(FOLDERID_LocalAppData
, CSIDL_LOCAL_APPDATA
),
937 KNOWN_FOLDER(FOLDERID_LocalAppDataLow
, NO_CSIDL
),
938 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir
, CSIDL_RESOURCES_LOCALIZED
),
939 KNOWN_FOLDER(FOLDERID_Music
, CSIDL_MYMUSIC
),
940 KNOWN_FOLDER(FOLDERID_MusicLibrary
, NO_CSIDL
),
941 KNOWN_FOLDER(FOLDERID_NetHood
, CSIDL_NETHOOD
),
942 KNOWN_FOLDER(FOLDERID_NetworkFolder
, CSIDL_NETWORK
),
943 KNOWN_FOLDER(FOLDERID_OriginalImages
, NO_CSIDL
),
944 KNOWN_FOLDER(FOLDERID_PhotoAlbums
, NO_CSIDL
),
945 KNOWN_FOLDER(FOLDERID_Pictures
, CSIDL_MYPICTURES
),
946 KNOWN_FOLDER(FOLDERID_PicturesLibrary
, NO_CSIDL
),
947 KNOWN_FOLDER(FOLDERID_Playlists
, NO_CSIDL
),
948 KNOWN_FOLDER(FOLDERID_PrintersFolder
, CSIDL_PRINTERS
),
949 KNOWN_FOLDER(FOLDERID_PrintHood
, CSIDL_PRINTHOOD
),
950 KNOWN_FOLDER(FOLDERID_Profile
, CSIDL_PROFILE
),
951 KNOWN_FOLDER(FOLDERID_ProgramData
, CSIDL_COMMON_APPDATA
),
952 KNOWN_FOLDER(FOLDERID_ProgramFiles
, CSIDL_PROGRAM_FILES
),
953 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon
, CSIDL_PROGRAM_FILES_COMMON
),
954 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86
, NO_CSIDL
),
955 KNOWN_FOLDER(FOLDERID_ProgramFilesX86
, CSIDL_PROGRAM_FILESX86
),
956 KNOWN_FOLDER(FOLDERID_Programs
, CSIDL_PROGRAMS
),
957 KNOWN_FOLDER(FOLDERID_Public
, NO_CSIDL
),
958 KNOWN_FOLDER(FOLDERID_PublicDesktop
, CSIDL_COMMON_DESKTOPDIRECTORY
),
959 KNOWN_FOLDER(FOLDERID_PublicDocuments
, CSIDL_COMMON_DOCUMENTS
),
960 KNOWN_FOLDER(FOLDERID_PublicDownloads
, NO_CSIDL
),
961 KNOWN_FOLDER(FOLDERID_PublicGameTasks
, NO_CSIDL
),
962 KNOWN_FOLDER(FOLDERID_PublicLibraries
, NO_CSIDL
),
963 KNOWN_FOLDER(FOLDERID_PublicMusic
, CSIDL_COMMON_MUSIC
),
964 KNOWN_FOLDER(FOLDERID_PublicPictures
, CSIDL_COMMON_PICTURES
),
965 KNOWN_FOLDER(FOLDERID_PublicRingtones
, NO_CSIDL
),
966 KNOWN_FOLDER(FOLDERID_PublicVideos
, CSIDL_COMMON_VIDEO
),
967 KNOWN_FOLDER(FOLDERID_QuickLaunch
, NO_CSIDL
),
968 KNOWN_FOLDER(FOLDERID_Recent
, CSIDL_RECENT
),
969 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary
, NO_CSIDL
),
970 KNOWN_FOLDER(FOLDERID_RecycleBinFolder
, CSIDL_BITBUCKET
),
971 KNOWN_FOLDER(FOLDERID_ResourceDir
, CSIDL_RESOURCES
),
972 KNOWN_FOLDER(FOLDERID_Ringtones
, NO_CSIDL
),
973 KNOWN_FOLDER(FOLDERID_RoamingAppData
, CSIDL_APPDATA
),
974 KNOWN_FOLDER(FOLDERID_SampleMusic
, NO_CSIDL
),
975 KNOWN_FOLDER(FOLDERID_SamplePictures
, NO_CSIDL
),
976 KNOWN_FOLDER(FOLDERID_SamplePlaylists
, NO_CSIDL
),
977 KNOWN_FOLDER(FOLDERID_SampleVideos
, NO_CSIDL
),
978 KNOWN_FOLDER(FOLDERID_SavedGames
, NO_CSIDL
),
979 KNOWN_FOLDER(FOLDERID_SavedSearches
, NO_CSIDL
),
980 KNOWN_FOLDER(FOLDERID_SEARCH_CSC
, NO_CSIDL
),
981 KNOWN_FOLDER(FOLDERID_SearchHome
, NO_CSIDL
),
982 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI
, NO_CSIDL
),
983 KNOWN_FOLDER(FOLDERID_SendTo
, CSIDL_SENDTO
),
984 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts
, NO_CSIDL
),
985 KNOWN_FOLDER(FOLDERID_SidebarParts
, NO_CSIDL
),
986 KNOWN_FOLDER(FOLDERID_StartMenu
, CSIDL_STARTMENU
),
987 KNOWN_FOLDER(FOLDERID_Startup
, CSIDL_STARTUP
),
988 KNOWN_FOLDER(FOLDERID_SyncManagerFolder
, NO_CSIDL
),
989 KNOWN_FOLDER(FOLDERID_SyncResultsFolder
, NO_CSIDL
),
990 KNOWN_FOLDER(FOLDERID_SyncSetupFolder
, NO_CSIDL
),
991 KNOWN_FOLDER(FOLDERID_System
, CSIDL_SYSTEM
),
992 KNOWN_FOLDER(FOLDERID_SystemX86
, CSIDL_SYSTEMX86
),
993 KNOWN_FOLDER(FOLDERID_Templates
, CSIDL_TEMPLATES
),
994 KNOWN_FOLDER(FOLDERID_UserPinned
, NO_CSIDL
),
995 KNOWN_FOLDER(FOLDERID_UserProfiles
, NO_CSIDL
),
996 KNOWN_FOLDER(FOLDERID_UserProgramFiles
, NO_CSIDL
),
997 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon
, NO_CSIDL
),
998 KNOWN_FOLDER(FOLDERID_UsersFiles
, NO_CSIDL
),
999 KNOWN_FOLDER(FOLDERID_UsersLibraries
, NO_CSIDL
),
1000 KNOWN_FOLDER(FOLDERID_Videos
, CSIDL_MYVIDEO
),
1001 KNOWN_FOLDER(FOLDERID_VideosLibrary
, NO_CSIDL
),
1002 KNOWN_FOLDER(FOLDERID_Windows
, CSIDL_WINDOWS
),
1003 { NULL
, NULL
, 0, NULL
}
1007 static void check_known_folder(IKnownFolderManager
*mgr
, KNOWNFOLDERID
*folderId
)
1010 const struct knownFolderDef
*known_folder
= &known_folders
[0];
1011 int csidl
, expectedCsidl
;
1013 while(known_folder
->folderId
!= NULL
)
1015 if(IsEqualGUID(known_folder
->folderId
, folderId
))
1018 if(known_folder
->csidl
!= NO_CSIDL
)
1020 expectedCsidl
= known_folder
->csidl
& (~CSIDL_TODO_WINE
);
1022 hr
= IKnownFolderManager_FolderIdToCsidl(mgr
, folderId
, &csidl
);
1023 ok_(__FILE__
, known_folder
->line
)(hr
== S_OK
, "cannot retrieve CSIDL for folder %s\n", known_folder
->sFolderId
);
1025 if(known_folder
->csidl
& CSIDL_TODO_WINE
)
1026 todo_wine
ok_(__FILE__
, known_folder
->line
)(csidl
== expectedCsidl
, "invalid CSIDL retrieved for folder %s. %d (%s) expected, but %d found\n", known_folder
->sFolderId
, expectedCsidl
, known_folder
->sCsidl
, csidl
);
1028 ok_(__FILE__
, known_folder
->line
)(csidl
== expectedCsidl
, "invalid CSIDL retrieved for folder %s. %d (%s) expected, but %d found\n", known_folder
->sFolderId
, expectedCsidl
, known_folder
->sCsidl
, csidl
);
1037 #undef CSIDL_TODO_WINE
1039 static void test_knownFolders(void)
1041 static const WCHAR sWindows
[] = {'W','i','n','d','o','w','s',0};
1042 static const WCHAR sExample
[] = {'E','x','a','m','p','l','e',0};
1043 static const WCHAR sExample2
[] = {'E','x','a','m','p','l','e','2',0};
1044 static const WCHAR sSubFolder
[] = {'S','u','b','F','o','l','d','e','r',0};
1045 static const WCHAR sBackslash
[] = {'\\',0};
1046 static const KNOWNFOLDERID newFolderId
= {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
1047 static const KNOWNFOLDERID subFolderId
= {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
1049 IKnownFolderManager
*mgr
= NULL
;
1050 IKnownFolder
*folder
= NULL
, *subFolder
= NULL
;
1051 KNOWNFOLDERID folderId
, *folders
;
1052 KF_CATEGORY cat
= 0;
1053 KNOWNFOLDER_DEFINITION kfDefinition
, kfSubDefinition
;
1056 LPWSTR folderPath
, errorMsg
;
1057 KF_REDIRECTION_CAPABILITIES redirectionCapabilities
= 1;
1058 WCHAR sWinDir
[MAX_PATH
], sExamplePath
[MAX_PATH
], sExample2Path
[MAX_PATH
], sSubFolderPath
[MAX_PATH
], sSubFolder2Path
[MAX_PATH
];
1062 GetWindowsDirectoryW( sWinDir
, MAX_PATH
);
1064 GetTempPathW(sizeof(sExamplePath
)/sizeof(sExamplePath
[0]), sExamplePath
);
1065 lstrcatW(sExamplePath
, sExample
);
1067 GetTempPathW(sizeof(sExample2Path
)/sizeof(sExample2Path
[0]), sExample2Path
);
1068 lstrcatW(sExample2Path
, sExample2
);
1070 lstrcpyW(sSubFolderPath
, sExamplePath
);
1071 lstrcatW(sSubFolderPath
, sBackslash
);
1072 lstrcatW(sSubFolderPath
, sSubFolder
);
1074 lstrcpyW(sSubFolder2Path
, sExample2Path
);
1075 lstrcatW(sSubFolder2Path
, sBackslash
);
1076 lstrcatW(sSubFolder2Path
, sSubFolder
);
1080 hr
= CoCreateInstance(&CLSID_KnownFolderManager
, NULL
, CLSCTX_INPROC_SERVER
,
1081 &IID_IKnownFolderManager
, (LPVOID
*)&mgr
);
1082 if(hr
== REGDB_E_CLASSNOTREG
)
1083 win_skip("IKnownFolderManager unavailable\n");
1086 ok(hr
== S_OK
, "failed to create KnownFolderManager instance: 0x%08x\n", hr
);
1088 hr
= IKnownFolderManager_FolderIdFromCsidl(mgr
, CSIDL_WINDOWS
, &folderId
);
1089 ok(hr
== S_OK
, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr
);
1090 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
1092 hr
= IKnownFolderManager_FolderIdToCsidl(mgr
, &FOLDERID_Windows
, &csidl
);
1093 ok(hr
== S_OK
, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr
);
1094 ok(csidl
== CSIDL_WINDOWS
, "invalid CSIDL returned\n");
1096 hr
= IKnownFolderManager_GetFolder(mgr
, &FOLDERID_Windows
, &folder
);
1097 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
1100 hr
= IKnownFolder_GetCategory(folder
, &cat
);
1102 ok(hr
== S_OK
, "failed to get folder category: 0x%08x\n", hr
);
1104 ok(cat
==KF_CATEGORY_FIXED
, "invalid folder category: %d\n", cat
);
1106 hr
= IKnownFolder_GetId(folder
, &folderId
);
1107 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
1108 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
1110 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1111 ok(lstrcmpiW(sWinDir
, folderPath
)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sWinDir
));
1112 CoTaskMemFree(folderPath
);
1114 hr
= IKnownFolder_GetRedirectionCapabilities(folder
, &redirectionCapabilities
);
1116 ok(hr
== S_OK
, "failed to get redirection capabilities: 0x%08x\n", hr
);
1118 ok(redirectionCapabilities
==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities
);
1120 hr
= IKnownFolder_SetPath(folder
, 0, sWinDir
);
1122 ok(hr
== E_INVALIDARG
, "unexpected value from SetPath: 0x%08x\n", hr
);
1124 hr
= IKnownFolder_GetFolderDefinition(folder
, &kfDefinition
);
1126 ok(hr
== S_OK
, "failed to get folder definition: 0x%08x\n", hr
);
1130 ok(kfDefinition
.category
==KF_CATEGORY_FIXED
, "invalid folder category: 0x%08x\n", kfDefinition
.category
);
1132 ok(lstrcmpW(kfDefinition
.pszName
, sWindows
)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition
.pszName
));
1134 ok(kfDefinition
.dwAttributes
==0, "invalid folder attributes: %d\n", kfDefinition
.dwAttributes
);
1135 FreeKnownFolderDefinitionFields(&kfDefinition
);
1138 hr
= IKnownFolder_Release(folder
);
1139 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
1142 hr
= IKnownFolderManager_GetFolderByName(mgr
, sWindows
, &folder
);
1144 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
1147 hr
= IKnownFolder_GetId(folder
, &folderId
);
1148 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
1149 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
1151 hr
= IKnownFolder_Release(folder
);
1152 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
1155 hr
= IKnownFolderManager_GetFolderIds(mgr
, &folders
, &nCount
);
1156 ok(hr
== S_OK
, "failed to get known folders: 0x%08x\n", hr
);
1157 for(i
=0;i
<nCount
;++i
)
1158 check_known_folder(mgr
, &folders
[i
]);
1160 CoTaskMemFree(folders
);
1162 /* test of registering new known folders */
1163 bRes
= CreateDirectoryW(sExamplePath
, NULL
);
1164 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath
));
1165 bRes
= CreateDirectoryW(sExample2Path
, NULL
);
1166 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path
));
1167 bRes
= CreateDirectoryW(sSubFolderPath
, NULL
);
1168 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath
));
1170 ZeroMemory(&kfDefinition
, sizeof(kfDefinition
));
1171 kfDefinition
.category
= KF_CATEGORY_PERUSER
;
1172 kfDefinition
.pszName
= CoTaskMemAlloc(sizeof(sExample
));
1173 lstrcpyW(kfDefinition
.pszName
, sExample
);
1174 kfDefinition
.pszDescription
= CoTaskMemAlloc(sizeof(sExample
));
1175 lstrcpyW(kfDefinition
.pszDescription
, sExample
);
1176 kfDefinition
.pszRelativePath
= CoTaskMemAlloc(sizeof(sExamplePath
));
1177 lstrcpyW(kfDefinition
.pszRelativePath
, sExamplePath
);
1179 hr
= IKnownFolderManager_RegisterFolder(mgr
, &newFolderId
, &kfDefinition
);
1180 if(hr
== HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED
))
1181 win_skip("No permissions required to register custom known folder\n");
1184 ok(hr
== S_OK
, "failed to register known folder: 0x%08x\n", hr
);
1187 hr
= IKnownFolderManager_GetFolder(mgr
, &newFolderId
, &folder
);
1188 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
1191 hr
= IKnownFolder_GetCategory(folder
, &cat
);
1192 ok(hr
== S_OK
, "failed to get folder category: hr=0x%0x\n", hr
);
1193 ok(cat
== KF_CATEGORY_PERUSER
, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat
, KF_CATEGORY_PERUSER
);
1195 hr
= IKnownFolder_GetId(folder
, &folderId
);
1196 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
1197 ok(IsEqualGUID(&folderId
, &newFolderId
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
1199 /* current path should be Temp\Example */
1200 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1201 ok(hr
== S_OK
, "failed to get path from known folder: 0x%08x\n", hr
);
1202 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1203 CoTaskMemFree(folderPath
);
1205 /* register sub-folder and mark it as child of Example folder */
1206 ZeroMemory(&kfSubDefinition
, sizeof(kfSubDefinition
));
1207 kfSubDefinition
.category
= KF_CATEGORY_PERUSER
;
1208 kfSubDefinition
.pszName
= CoTaskMemAlloc(sizeof(sSubFolder
));
1209 lstrcpyW(kfSubDefinition
.pszName
, sSubFolder
);
1210 kfSubDefinition
.pszDescription
= CoTaskMemAlloc(sizeof(sSubFolder
));
1211 lstrcpyW(kfSubDefinition
.pszDescription
, sSubFolder
);
1212 kfSubDefinition
.pszRelativePath
= CoTaskMemAlloc(sizeof(sSubFolder
));
1213 lstrcpyW(kfSubDefinition
.pszRelativePath
, sSubFolder
);
1214 kfSubDefinition
.fidParent
= newFolderId
;
1216 hr
= IKnownFolderManager_RegisterFolder(mgr
, &subFolderId
, &kfSubDefinition
);
1217 ok(hr
== S_OK
, "failed to register known folder: 0x%08x\n", hr
);
1221 hr
= IKnownFolderManager_GetFolder(mgr
, &subFolderId
, &subFolder
);
1222 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
1225 /* check sub folder path */
1226 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1227 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1228 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
1229 CoTaskMemFree(folderPath
);
1232 /* try to redirect Example to Temp\Example2 */
1233 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 0, NULL
, &errorMsg
);
1234 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1237 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1238 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1239 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
1240 CoTaskMemFree(folderPath
);
1242 /* verify sub folder - it should fail now, as we redirected it's parent folder, but we have no sub folder in new location */
1243 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1244 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "unexpected value from GetPath(): 0x%08x\n", hr
);
1245 ok(folderPath
==NULL
, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath
));
1246 CoTaskMemFree(folderPath
);
1249 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
1250 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
1251 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
1254 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1255 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1256 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1257 CoTaskMemFree(folderPath
);
1260 /* create sub folder in Temp\Example2 */
1261 bRes
= CreateDirectoryW(sSubFolder2Path
, NULL
);
1262 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path
));
1264 /* again perform that same redirection */
1265 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 0, NULL
, &errorMsg
);
1266 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1268 /* verify sub folder. It should succeed now, as the required sub folder exists */
1269 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1270 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1271 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
1272 CoTaskMemFree(folderPath
);
1274 /* remove newly created directory */
1275 RemoveDirectoryW(sSubFolder2Path
);
1277 /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
1278 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1280 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1282 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
1283 CoTaskMemFree(folderPath
);
1286 /* set Example path to original */
1287 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
1288 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
1291 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1292 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1293 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1294 CoTaskMemFree(folderPath
);
1296 /* verify sub folder */
1297 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1298 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1299 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
1300 CoTaskMemFree(folderPath
);
1303 /* create sub folder in Temp\Example2 */
1304 bRes
= CreateDirectoryW(sSubFolder2Path
, NULL
);
1305 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path
));
1307 /* do that same redirection, but try to exclude sub-folder */
1308 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 1, &subFolderId
, &errorMsg
);
1309 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1312 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1313 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1314 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
1315 CoTaskMemFree(folderPath
);
1317 /* verify sub folder. Unexpectedly, this path was also changed. So, exclusion seems to be ignored (Windows bug)? This test however will let us know, if this behavior is changed */
1318 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1319 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1320 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
1321 CoTaskMemFree(folderPath
);
1323 /* remove newly created directory */
1324 RemoveDirectoryW(sSubFolder2Path
);
1327 /* set Example path to original */
1328 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
1329 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
1332 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1333 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1334 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1335 CoTaskMemFree(folderPath
);
1337 /* verify sub folder */
1338 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1339 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1340 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
1341 CoTaskMemFree(folderPath
);
1344 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
1345 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
, sExample2Path
, 0, NULL
, &errorMsg
);
1346 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1349 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1350 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1351 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
1352 CoTaskMemFree(folderPath
);
1354 /* verify sub folder */
1355 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1356 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1357 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
1358 CoTaskMemFree(folderPath
);
1360 /* remove copied directory */
1361 RemoveDirectoryW(sSubFolder2Path
);
1364 /* set Example path to original */
1365 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
1366 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
1369 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1370 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1371 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1372 CoTaskMemFree(folderPath
);
1374 /* verify sub folder */
1375 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1376 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1377 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
1378 CoTaskMemFree(folderPath
);
1381 /* redirect again, set it to copy content and remove originals */
1382 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
| KF_REDIRECT_DEL_SOURCE_CONTENTS
, sExample2Path
, 0, NULL
, &errorMsg
);
1383 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1386 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1387 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1388 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
1389 CoTaskMemFree(folderPath
);
1391 /* verify sub folder */
1392 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1393 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1394 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
1395 CoTaskMemFree(folderPath
);
1397 /* check if original directory was really removed */
1398 dwAttributes
= GetFileAttributesW(sExamplePath
);
1399 ok(dwAttributes
==INVALID_FILE_ATTRIBUTES
, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes
);
1402 /* redirect (with copy) to original path */
1403 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
, sExamplePath
, 0, NULL
, &errorMsg
);
1404 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
1407 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
1408 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1409 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
1410 CoTaskMemFree(folderPath
);
1412 /* verify sub folder */
1413 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
1414 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
1415 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
1416 CoTaskMemFree(folderPath
);
1418 /* check shell utility functions */
1419 if(!pSHGetKnownFolderPath
|| !pSHSetKnownFolderPath
)
1421 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
1424 /* try to get current known folder path */
1425 hr
= pSHGetKnownFolderPath(&newFolderId
, 0, NULL
, &folderPath
);
1427 ok(hr
==S_OK
, "cannot get known folder path: hr=0x%0x\n", hr
);
1429 ok(lstrcmpW(folderPath
, sExamplePath
)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath
));
1431 /* set it to new value */
1432 hr
= pSHSetKnownFolderPath(&newFolderId
, 0, NULL
, sExample2Path
);
1434 ok(hr
==S_OK
, "cannot set known folder path: hr=0x%0x\n", hr
);
1436 /* check if it changed */
1437 hr
= pSHGetKnownFolderPath(&newFolderId
, 0, NULL
, &folderPath
);
1439 ok(hr
==S_OK
, "cannot get known folder path: hr=0x%0x\n", hr
);
1441 ok(lstrcmpW(folderPath
, sExample2Path
)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath
));
1444 hr
= pSHSetKnownFolderPath(&newFolderId
, 0, NULL
, sExamplePath
);
1446 ok(hr
==S_OK
, "cannot set known folder path: hr=0x%0x\n", hr
);
1449 IKnownFolder_Release(subFolder
);
1452 hr
= IKnownFolderManager_UnregisterFolder(mgr
, &subFolderId
);
1453 ok(hr
== S_OK
, "failed to unregister folder: 0x%08x\n", hr
);
1456 FreeKnownFolderDefinitionFields(&kfSubDefinition
);
1458 hr
= IKnownFolder_Release(folder
);
1459 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
1462 hr
= IKnownFolderManager_UnregisterFolder(mgr
, &newFolderId
);
1463 ok(hr
== S_OK
, "failed to unregister folder: 0x%08x\n", hr
);
1466 FreeKnownFolderDefinitionFields(&kfDefinition
);
1468 RemoveDirectoryW(sSubFolder2Path
);
1469 RemoveDirectoryW(sSubFolderPath
);
1470 RemoveDirectoryW(sExamplePath
);
1471 RemoveDirectoryW(sExample2Path
);
1473 hr
= IKnownFolderManager_Release(mgr
);
1474 ok(hr
== S_OK
, "failed to release KnownFolderManager instance: 0x%08x\n", hr
);
1479 START_TEST(shellpath
)
1481 if (!init()) return;
1484 pGetSystemWow64DirectoryA
= (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
1485 "GetSystemWow64DirectoryA" );
1490 /* Report missing functions once */
1491 if (!pSHGetFolderLocation
)
1492 win_skip("SHGetFolderLocation is not available\n");
1494 /* first test various combinations of parameters: */
1497 /* check known values: */
1503 test_NonExistentPath();
1504 test_SHGetFolderPathEx();
1505 test_knownFolders();