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 "knownfolders.h"
35 #include "wine/test.h"
39 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
40 * here is its original value.
42 #define OLD_CSIDL_MYDOCUMENTS 0x000c
44 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
47 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
50 /* from pidl.h, not included here: */
51 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
52 #define PT_CPL 0x01 /* no path */
55 #define PT_GUID 0x1f /* no path */
58 #define PT_DRIVE 0x23 /* has path */
61 #define PT_DRIVE2 0x25 /* has path */
64 #define PT_SHELLEXT 0x2e /* no path */
67 #define PT_FOLDER 0x31 /* has path */
70 #define PT_FOLDERW 0x35 /* has path */
73 #define PT_WORKGRP 0x41 /* no path */
76 #define PT_YAGUID 0x70 /* no path */
78 /* FIXME: this is used for history/favorites folders; what's a better name? */
80 #define PT_IESPECIAL2 0xb1 /* has path */
83 static GUID CLSID_CommonDocuments
= { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
85 struct shellExpectedValues
{
91 static HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
92 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
93 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
, int, HANDLE
, DWORD
,
95 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
96 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
97 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
98 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
99 static HRESULT (WINAPI
*pSHGetMalloc
)(LPMALLOC
*);
100 static UINT (WINAPI
*pGetSystemWow64DirectoryA
)(LPSTR
,UINT
);
101 static HRESULT (WINAPI
*pSHGetKnownFolderPath
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, PWSTR
*);
102 static HRESULT (WINAPI
*pSHSetKnownFolderPath
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, PWSTR
);
103 static HRESULT (WINAPI
*pSHGetFolderPathEx
)(REFKNOWNFOLDERID
, DWORD
, HANDLE
, LPWSTR
, DWORD
);
105 static DLLVERSIONINFO shellVersion
= { 0 };
106 static LPMALLOC pMalloc
;
107 static const BYTE guidType
[] = { PT_GUID
};
108 static const BYTE controlPanelType
[] = { PT_SHELLEXT
, PT_GUID
, PT_CPL
};
109 static const BYTE folderType
[] = { PT_FOLDER
, PT_FOLDERW
};
110 static const BYTE favoritesType
[] = { PT_FOLDER
, PT_FOLDERW
, 0, PT_IESPECIAL2
/* Win98 */ };
111 static const BYTE folderOrSpecialType
[] = { PT_FOLDER
, PT_IESPECIAL2
};
112 static const BYTE personalType
[] = { PT_FOLDER
, PT_GUID
, PT_DRIVE
, 0xff /* Win9x */,
113 PT_IESPECIAL2
/* Win98 */, 0 /* Vista */ };
114 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
115 static const BYTE printersType
[] = { PT_YAGUID
, PT_SHELLEXT
, 0x71 };
116 static const BYTE ieSpecialType
[] = { PT_IESPECIAL2
};
117 static const BYTE shellExtType
[] = { PT_SHELLEXT
};
118 static const BYTE workgroupType
[] = { PT_WORKGRP
};
119 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
120 static const struct shellExpectedValues requiredShellValues
[] = {
121 DECLARE_TYPE(CSIDL_BITBUCKET
, guidType
),
122 DECLARE_TYPE(CSIDL_CONTROLS
, controlPanelType
),
123 DECLARE_TYPE(CSIDL_COOKIES
, folderType
),
124 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY
, folderType
),
125 DECLARE_TYPE(CSIDL_DRIVES
, guidType
),
126 DECLARE_TYPE(CSIDL_FAVORITES
, favoritesType
),
127 DECLARE_TYPE(CSIDL_FONTS
, folderOrSpecialType
),
128 /* FIXME: the following fails in Wine, returns type PT_FOLDER
129 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
131 DECLARE_TYPE(CSIDL_INTERNET
, guidType
),
132 DECLARE_TYPE(CSIDL_NETHOOD
, folderType
),
133 DECLARE_TYPE(CSIDL_NETWORK
, guidType
),
134 DECLARE_TYPE(CSIDL_PERSONAL
, personalType
),
135 DECLARE_TYPE(CSIDL_PRINTERS
, printersType
),
136 DECLARE_TYPE(CSIDL_PRINTHOOD
, folderType
),
137 DECLARE_TYPE(CSIDL_PROGRAMS
, folderType
),
138 DECLARE_TYPE(CSIDL_RECENT
, folderOrSpecialType
),
139 DECLARE_TYPE(CSIDL_SENDTO
, folderType
),
140 DECLARE_TYPE(CSIDL_STARTMENU
, folderType
),
141 DECLARE_TYPE(CSIDL_STARTUP
, folderType
),
142 DECLARE_TYPE(CSIDL_TEMPLATES
, folderType
),
144 static const struct shellExpectedValues optionalShellValues
[] = {
145 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
146 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
147 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
148 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
150 /* Windows NT-only: */
151 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY
, folderType
),
152 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS
, shellExtType
),
153 DECLARE_TYPE(CSIDL_COMMON_FAVORITES
, folderType
),
154 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS
, folderType
),
155 DECLARE_TYPE(CSIDL_COMMON_STARTMENU
, folderType
),
156 DECLARE_TYPE(CSIDL_COMMON_STARTUP
, folderType
),
157 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES
, folderType
),
158 /* first appearing in shell32 version 4.71: */
159 DECLARE_TYPE(CSIDL_APPDATA
, folderType
),
160 /* first appearing in shell32 version 4.72: */
161 DECLARE_TYPE(CSIDL_INTERNET_CACHE
, ieSpecialType
),
162 /* first appearing in shell32 version 5.0: */
163 DECLARE_TYPE(CSIDL_ADMINTOOLS
, folderType
),
164 DECLARE_TYPE(CSIDL_COMMON_APPDATA
, folderType
),
165 DECLARE_TYPE(CSIDL_LOCAL_APPDATA
, folderType
),
166 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS
, folderType
),
167 DECLARE_TYPE(CSIDL_MYMUSIC
, folderType
),
168 DECLARE_TYPE(CSIDL_MYPICTURES
, folderType
),
169 DECLARE_TYPE(CSIDL_MYVIDEO
, folderType
),
170 DECLARE_TYPE(CSIDL_PROFILE
, folderType
),
171 DECLARE_TYPE(CSIDL_PROGRAM_FILES
, folderType
),
172 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86
, folderType
),
173 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON
, folderType
),
174 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86
, folderType
),
175 DECLARE_TYPE(CSIDL_SYSTEM
, folderType
),
176 DECLARE_TYPE(CSIDL_WINDOWS
, folderType
),
177 /* first appearing in shell32 6.0: */
178 DECLARE_TYPE(CSIDL_CDBURN_AREA
, folderType
),
179 DECLARE_TYPE(CSIDL_COMMON_MUSIC
, folderType
),
180 DECLARE_TYPE(CSIDL_COMMON_PICTURES
, folderType
),
181 DECLARE_TYPE(CSIDL_COMMON_VIDEO
, folderType
),
182 DECLARE_TYPE(CSIDL_COMPUTERSNEARME
, workgroupType
),
183 DECLARE_TYPE(CSIDL_RESOURCES
, folderType
),
184 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED
, folderType
),
188 static void loadShell32(void)
190 HMODULE hShell32
= GetModuleHandleA("shell32");
192 #define GET_PROC(func) \
193 p ## func = (void*)GetProcAddress(hShell32, #func); \
195 trace("GetProcAddress(%s) failed\n", #func);
197 GET_PROC(DllGetVersion
)
198 GET_PROC(SHGetFolderPathA
)
199 GET_PROC(SHGetFolderPathEx
)
200 GET_PROC(SHGetFolderLocation
)
201 GET_PROC(SHGetKnownFolderPath
)
202 GET_PROC(SHSetKnownFolderPath
)
203 GET_PROC(SHGetSpecialFolderPathA
)
204 GET_PROC(SHGetSpecialFolderLocation
)
205 GET_PROC(ILFindLastID
)
207 pILFindLastID
= (void *)GetProcAddress(hShell32
, (LPCSTR
)16);
208 GET_PROC(SHFileOperationA
)
209 GET_PROC(SHGetMalloc
)
211 ok(pSHGetMalloc
!= NULL
, "shell32 is missing SHGetMalloc\n");
214 HRESULT hr
= pSHGetMalloc(&pMalloc
);
216 ok(hr
== S_OK
, "SHGetMalloc failed: 0x%08x\n", hr
);
217 ok(pMalloc
!= NULL
, "SHGetMalloc returned a NULL IMalloc\n");
222 shellVersion
.cbSize
= sizeof(shellVersion
);
223 pDllGetVersion(&shellVersion
);
224 trace("shell32 version is %d.%d\n",
225 shellVersion
.dwMajorVersion
, shellVersion
.dwMinorVersion
);
230 #ifndef CSIDL_PROFILES
231 #define CSIDL_PROFILES 0x003e
234 /* A couple utility printing functions */
235 static const char *getFolderName(int folder
)
237 static char unknown
[32];
239 #define CSIDL_TO_STR(x) case x: return#x;
242 CSIDL_TO_STR(CSIDL_DESKTOP
);
243 CSIDL_TO_STR(CSIDL_INTERNET
);
244 CSIDL_TO_STR(CSIDL_PROGRAMS
);
245 CSIDL_TO_STR(CSIDL_CONTROLS
);
246 CSIDL_TO_STR(CSIDL_PRINTERS
);
247 CSIDL_TO_STR(CSIDL_PERSONAL
);
248 CSIDL_TO_STR(CSIDL_FAVORITES
);
249 CSIDL_TO_STR(CSIDL_STARTUP
);
250 CSIDL_TO_STR(CSIDL_RECENT
);
251 CSIDL_TO_STR(CSIDL_SENDTO
);
252 CSIDL_TO_STR(CSIDL_BITBUCKET
);
253 CSIDL_TO_STR(CSIDL_STARTMENU
);
254 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS
);
255 CSIDL_TO_STR(CSIDL_MYMUSIC
);
256 CSIDL_TO_STR(CSIDL_MYVIDEO
);
257 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY
);
258 CSIDL_TO_STR(CSIDL_DRIVES
);
259 CSIDL_TO_STR(CSIDL_NETWORK
);
260 CSIDL_TO_STR(CSIDL_NETHOOD
);
261 CSIDL_TO_STR(CSIDL_FONTS
);
262 CSIDL_TO_STR(CSIDL_TEMPLATES
);
263 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU
);
264 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS
);
265 CSIDL_TO_STR(CSIDL_COMMON_STARTUP
);
266 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY
);
267 CSIDL_TO_STR(CSIDL_APPDATA
);
268 CSIDL_TO_STR(CSIDL_PRINTHOOD
);
269 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA
);
270 CSIDL_TO_STR(CSIDL_ALTSTARTUP
);
271 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP
);
272 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES
);
273 CSIDL_TO_STR(CSIDL_INTERNET_CACHE
);
274 CSIDL_TO_STR(CSIDL_COOKIES
);
275 CSIDL_TO_STR(CSIDL_HISTORY
);
276 CSIDL_TO_STR(CSIDL_COMMON_APPDATA
);
277 CSIDL_TO_STR(CSIDL_WINDOWS
);
278 CSIDL_TO_STR(CSIDL_SYSTEM
);
279 CSIDL_TO_STR(CSIDL_PROGRAM_FILES
);
280 CSIDL_TO_STR(CSIDL_MYPICTURES
);
281 CSIDL_TO_STR(CSIDL_PROFILE
);
282 CSIDL_TO_STR(CSIDL_SYSTEMX86
);
283 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86
);
284 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON
);
285 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86
);
286 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES
);
287 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS
);
288 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS
);
289 CSIDL_TO_STR(CSIDL_ADMINTOOLS
);
290 CSIDL_TO_STR(CSIDL_CONNECTIONS
);
291 CSIDL_TO_STR(CSIDL_PROFILES
);
292 CSIDL_TO_STR(CSIDL_COMMON_MUSIC
);
293 CSIDL_TO_STR(CSIDL_COMMON_PICTURES
);
294 CSIDL_TO_STR(CSIDL_COMMON_VIDEO
);
295 CSIDL_TO_STR(CSIDL_RESOURCES
);
296 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED
);
297 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS
);
298 CSIDL_TO_STR(CSIDL_CDBURN_AREA
);
299 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME
);
302 sprintf(unknown
, "unknown (0x%04x)", folder
);
307 static const char *printGUID(const GUID
*guid
, char * guidSTR
)
309 if (!guid
) return NULL
;
311 sprintf(guidSTR
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
312 guid
->Data1
, guid
->Data2
, guid
->Data3
,
313 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
314 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
318 static void test_parameters(void)
320 LPITEMIDLIST pidl
= NULL
;
324 if (pSHGetFolderLocation
)
326 /* check a bogus CSIDL: */
328 hr
= pSHGetFolderLocation(NULL
, 0xeeee, NULL
, 0, &pidl
);
329 ok(hr
== E_INVALIDARG
, "got 0x%08x, expected E_INVALIDARG\n", hr
);
330 if (hr
== S_OK
) IMalloc_Free(pMalloc
, pidl
);
332 /* check a bogus user token: */
334 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, (HANDLE
)2, 0, &pidl
);
335 ok(hr
== E_FAIL
|| hr
== E_HANDLE
, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr
);
336 if (hr
== S_OK
) IMalloc_Free(pMalloc
, pidl
);
338 /* a NULL pidl pointer crashes, so don't test it */
341 if (pSHGetSpecialFolderLocation
)
345 SHGetSpecialFolderLocation(NULL
, 0, NULL
);
347 hr
= pSHGetSpecialFolderLocation(NULL
, 0xeeee, &pidl
);
348 ok(hr
== E_INVALIDARG
, "got returned 0x%08x\n", hr
);
351 if (pSHGetFolderPathA
)
353 /* expect 2's a bogus handle, especially since we didn't open it */
354 hr
= pSHGetFolderPathA(NULL
, CSIDL_DESKTOP
, (HANDLE
)2, SHGFP_TYPE_DEFAULT
, path
);
355 ok(hr
== E_FAIL
|| hr
== E_HANDLE
|| /* Vista and 2k8 */
356 broken(hr
== S_OK
), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr
);
358 hr
= pSHGetFolderPathA(NULL
, 0xeeee, NULL
, SHGFP_TYPE_DEFAULT
, path
);
359 ok(hr
== E_INVALIDARG
, "got 0x%08x, expected E_INVALIDARG\n", hr
);
362 if (pSHGetSpecialFolderPathA
)
367 pSHGetSpecialFolderPathA(NULL
, NULL
, CSIDL_BITBUCKET
, FALSE
);
369 /* odd but true: calling with a NULL path still succeeds if it's a real
370 * dir (on some windows platform). on winME it generates exception.
372 ret
= pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_PROGRAMS
, FALSE
);
373 ok(ret
, "got %d\n", ret
);
375 ret
= pSHGetSpecialFolderPathA(NULL
, path
, 0xeeee, FALSE
);
376 ok(!ret
, "got %d\n", ret
);
380 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
381 static BYTE
testSHGetFolderLocation(int folder
)
387 /* treat absence of function as success */
388 if (!pSHGetFolderLocation
) return TRUE
;
391 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
396 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
398 ok(pidlLast
!= NULL
, "%s: ILFindLastID failed\n",
399 getFolderName(folder
));
401 ret
= pidlLast
->mkid
.abID
[0];
402 IMalloc_Free(pMalloc
, pidl
);
408 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
409 static BYTE
testSHGetSpecialFolderLocation(int folder
)
415 /* treat absence of function as success */
416 if (!pSHGetSpecialFolderLocation
) return TRUE
;
419 hr
= pSHGetSpecialFolderLocation(NULL
, folder
, &pidl
);
424 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
427 "%s: ILFindLastID failed\n", getFolderName(folder
));
429 ret
= pidlLast
->mkid
.abID
[0];
430 IMalloc_Free(pMalloc
, pidl
);
436 static void test_SHGetFolderPath(BOOL optional
, int folder
)
441 if (!pSHGetFolderPathA
) return;
443 hr
= pSHGetFolderPathA(NULL
, folder
, NULL
, SHGFP_TYPE_CURRENT
, path
);
444 ok(hr
== S_OK
|| optional
,
445 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder
), hr
);
448 static void test_SHGetSpecialFolderPath(BOOL optional
, int folder
)
453 if (!pSHGetSpecialFolderPathA
) return;
455 ret
= pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
);
456 if (ret
&& winetest_interactive
)
457 printf("%s: %s\n", getFolderName(folder
), path
);
459 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
460 getFolderName(folder
));
463 static void test_ShellValues(const struct shellExpectedValues testEntries
[],
464 int numEntries
, BOOL optional
)
468 for (i
= 0; i
< numEntries
; i
++)
472 BOOL foundTypeMatch
= FALSE
;
474 if (pSHGetFolderLocation
)
476 type
= testSHGetFolderLocation(testEntries
[i
].folder
);
477 for (j
= 0; !foundTypeMatch
&& j
< testEntries
[i
].numTypes
; j
++)
478 if (testEntries
[i
].types
[j
] == type
)
479 foundTypeMatch
= TRUE
;
480 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
481 "%s has unexpected type %d (0x%02x)\n",
482 getFolderName(testEntries
[i
].folder
), type
, type
);
484 type
= testSHGetSpecialFolderLocation(testEntries
[i
].folder
);
485 for (j
= 0, foundTypeMatch
= FALSE
; !foundTypeMatch
&&
486 j
< testEntries
[i
].numTypes
; j
++)
487 if (testEntries
[i
].types
[j
] == type
)
488 foundTypeMatch
= TRUE
;
489 ok(foundTypeMatch
|| optional
|| broken(type
== 0xff) /* Win9x */,
490 "%s has unexpected type %d (0x%02x)\n",
491 getFolderName(testEntries
[i
].folder
), type
, type
);
498 test_SHGetFolderPath(optional
, testEntries
[i
].folder
);
499 test_SHGetSpecialFolderPath(optional
, testEntries
[i
].folder
);
505 /* Attempts to verify that the folder path corresponding to the folder CSIDL
506 * value has the same value as the environment variable with name envVar.
507 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
508 * set in this environment; different OS and shell version behave differently.
509 * However, if both are present, fails if envVar's value is not the same
510 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
512 static void matchSpecialFolderPathToEnv(int folder
, const char *envVar
)
516 if (!pSHGetSpecialFolderPathA
) return;
518 if (pSHGetSpecialFolderPathA(NULL
, path
, folder
, FALSE
))
520 char *envVal
= getenv(envVar
);
522 ok(!envVal
|| !lstrcmpiA(envVal
, path
),
523 "%%%s%% does not match SHGetSpecialFolderPath:\n"
524 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
525 envVar
, envVar
, envVal
, path
);
529 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
530 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
531 * fail if it isn't--that check should already have been done.
532 * Fails if the returned PIDL is a GUID whose value does not match guid.
534 static void matchGUID(int folder
, const GUID
*guid
, const GUID
*guid_alt
)
539 if (!pSHGetFolderLocation
) return;
543 hr
= pSHGetFolderLocation(NULL
, folder
, NULL
, 0, &pidl
);
546 LPITEMIDLIST pidlLast
= pILFindLastID(pidl
);
548 if (pidlLast
&& (pidlLast
->mkid
.abID
[0] == PT_SHELLEXT
||
549 pidlLast
->mkid
.abID
[0] == PT_GUID
))
551 GUID
*shellGuid
= (GUID
*)(pidlLast
->mkid
.abID
+ 2);
552 char shellGuidStr
[39], guidStr
[39], guid_altStr
[39];
555 ok(IsEqualIID(shellGuid
, guid
),
556 "%s: got GUID %s, expected %s\n", getFolderName(folder
),
557 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
));
559 ok(IsEqualIID(shellGuid
, guid
) ||
560 IsEqualIID(shellGuid
, guid_alt
),
561 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder
),
562 printGUID(shellGuid
, shellGuidStr
), printGUID(guid
, guidStr
),
563 printGUID(guid_alt
, guid_altStr
));
565 IMalloc_Free(pMalloc
, pidl
);
569 /* Checks the PIDL type of all the known values. */
570 static void test_PidlTypes(void)
573 test_SHGetFolderPath(FALSE
, CSIDL_DESKTOP
);
574 test_SHGetSpecialFolderPath(FALSE
, CSIDL_DESKTOP
);
576 test_ShellValues(requiredShellValues
, ARRAY_SIZE(requiredShellValues
), FALSE
);
577 test_ShellValues(optionalShellValues
, ARRAY_SIZE(optionalShellValues
), TRUE
);
580 /* FIXME: Should be in shobjidl.idl */
581 DEFINE_GUID(CLSID_NetworkExplorerFolder
, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
583 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
584 static void test_GUIDs(void)
586 matchGUID(CSIDL_BITBUCKET
, &CLSID_RecycleBin
, NULL
);
587 matchGUID(CSIDL_CONTROLS
, &CLSID_ControlPanel
, NULL
);
588 matchGUID(CSIDL_DRIVES
, &CLSID_MyComputer
, NULL
);
589 matchGUID(CSIDL_INTERNET
, &CLSID_Internet
, NULL
);
590 matchGUID(CSIDL_NETWORK
, &CLSID_NetworkPlaces
, &CLSID_NetworkExplorerFolder
); /* Vista and higher */
591 matchGUID(CSIDL_PERSONAL
, &CLSID_MyDocuments
, NULL
);
592 matchGUID(CSIDL_COMMON_DOCUMENTS
, &CLSID_CommonDocuments
, NULL
);
593 matchGUID(CSIDL_PRINTERS
, &CLSID_Printers
, NULL
);
596 /* Verifies various shell paths match the environment variables to which they
599 static void test_EnvVars(void)
601 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES
, "ProgramFiles");
602 matchSpecialFolderPathToEnv(CSIDL_APPDATA
, "APPDATA");
603 matchSpecialFolderPathToEnv(CSIDL_PROFILE
, "USERPROFILE");
604 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "SystemRoot");
605 matchSpecialFolderPathToEnv(CSIDL_WINDOWS
, "windir");
606 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON
, "CommonProgramFiles");
607 /* this is only set on Wine, but can't hurt to verify it: */
608 matchSpecialFolderPathToEnv(CSIDL_SYSTEM
, "winsysdir");
611 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
612 static BOOL
myPathIsRootA(LPCSTR lpszPath
)
614 if (lpszPath
&& *lpszPath
&&
615 lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
616 return TRUE
; /* X:\ */
619 static LPSTR
myPathRemoveBackslashA( LPSTR lpszPath
)
625 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
626 if (!myPathIsRootA(lpszPath
) && *szTemp
== '\\')
632 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
633 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
634 * every shell32 version supports CSIDL_WINDOWS.
636 static void testWinDir(void)
638 char windowsShellPath
[MAX_PATH
], windowsDir
[MAX_PATH
] = { 0 };
640 if (!pSHGetSpecialFolderPathA
) return;
642 if (pSHGetSpecialFolderPathA(NULL
, windowsShellPath
, CSIDL_WINDOWS
, FALSE
))
644 myPathRemoveBackslashA(windowsShellPath
);
645 GetWindowsDirectoryA(windowsDir
, sizeof(windowsDir
));
646 myPathRemoveBackslashA(windowsDir
);
647 ok(!lstrcmpiA(windowsDir
, windowsShellPath
),
648 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
649 windowsDir
, windowsShellPath
);
653 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
654 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
655 * no foul--not every shell32 version supports CSIDL_SYSTEM.
657 static void testSystemDir(void)
659 char systemShellPath
[MAX_PATH
], systemDir
[MAX_PATH
], systemDirx86
[MAX_PATH
];
661 if (!pSHGetSpecialFolderPathA
) return;
663 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
664 myPathRemoveBackslashA(systemDir
);
665 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEM
, FALSE
))
667 myPathRemoveBackslashA(systemShellPath
);
668 ok(!lstrcmpiA(systemDir
, systemShellPath
),
669 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
670 systemDir
, systemShellPath
);
673 if (!pGetSystemWow64DirectoryA
|| !pGetSystemWow64DirectoryA(systemDirx86
, sizeof(systemDirx86
)))
674 GetSystemDirectoryA(systemDirx86
, sizeof(systemDirx86
));
675 myPathRemoveBackslashA(systemDirx86
);
676 if (pSHGetSpecialFolderPathA(NULL
, systemShellPath
, CSIDL_SYSTEMX86
, FALSE
))
678 myPathRemoveBackslashA(systemShellPath
);
679 ok(!lstrcmpiA(systemDirx86
, systemShellPath
) || broken(!lstrcmpiA(systemDir
, systemShellPath
)),
680 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
681 systemDir
, systemShellPath
);
685 /* Globals used by subprocesses */
687 static char **myARGV
;
688 static char base
[MAX_PATH
];
689 static char selfname
[MAX_PATH
];
691 static BOOL
init(void)
693 myARGC
= winetest_get_mainargs(&myARGV
);
694 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return FALSE
;
695 strcpy(selfname
, myARGV
[0]);
699 static void doChild(const char *arg
)
709 /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
711 /* test some failure cases first: */
712 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
, NULL
, SHGFP_TYPE_CURRENT
, path
);
713 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
714 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr
);
717 hr
= pSHGetFolderLocation(NULL
, CSIDL_FAVORITES
, NULL
, 0, &pidl
);
718 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
719 "SHGetFolderLocation returned 0x%08x\n", hr
);
720 if (hr
== S_OK
&& pidl
) IMalloc_Free(pMalloc
, pidl
);
722 ok(!pSHGetSpecialFolderPathA(NULL
, path
, CSIDL_FAVORITES
, FALSE
),
723 "SHGetSpecialFolderPath succeeded, expected failure\n");
726 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_FAVORITES
, &pidl
);
727 ok(hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
728 "SHGetFolderLocation returned 0x%08x\n", hr
);
730 if (hr
== S_OK
&& pidl
) IMalloc_Free(pMalloc
, pidl
);
732 /* now test success: */
733 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
734 SHGFP_TYPE_CURRENT
, path
);
735 ok (hr
== S_OK
, "got 0x%08x\n", hr
);
740 trace("CSIDL_FAVORITES was changed to %s\n", path
);
741 ret
= CreateDirectoryA(path
, NULL
);
742 ok(!ret
, "expected failure with ERROR_ALREADY_EXISTS\n");
744 ok(GetLastError() == ERROR_ALREADY_EXISTS
,
745 "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
747 p
= path
+ strlen(path
);
748 strcpy(p
, "\\desktop.ini");
751 SetFileAttributesA( path
, FILE_ATTRIBUTE_NORMAL
);
752 ret
= RemoveDirectoryA(path
);
753 ok( ret
, "failed to remove %s error %u\n", path
, GetLastError() );
756 else if (arg
[0] == '2')
758 /* make sure SHGetFolderPath still succeeds when the
759 original value of CSIDL_FAVORITES is restored. */
760 hr
= pSHGetFolderPathA(NULL
, CSIDL_FAVORITES
| CSIDL_FLAG_CREATE
, NULL
,
761 SHGFP_TYPE_CURRENT
, path
);
762 ok(hr
== S_OK
, "SHGetFolderPath failed: 0x%08x\n", hr
);
766 /* Tests the return values from the various shell functions both with and
767 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
768 * version 5 of the shell, so don't test unless it's at least version 5.
769 * The test reads a value from the registry, modifies it, calls
770 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
771 * afterward without it. Then it restores the registry and deletes the folder
773 * One oddity with respect to restoration: shell32 caches somehow, so it needs
774 * to be reloaded in order to see the correct (restored) value.
775 * Some APIs unrelated to the ones under test may fail, but I expect they're
776 * covered by other unit tests; I just print out something about failure to
777 * help trace what's going on.
779 static void test_NonExistentPath(void)
781 static const char userShellFolders
[] =
782 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
783 char originalPath
[MAX_PATH
], modifiedPath
[MAX_PATH
];
786 if (!pSHGetFolderPathA
) return;
787 if (!pSHGetFolderLocation
) return;
788 if (!pSHGetSpecialFolderPathA
) return;
789 if (!pSHGetSpecialFolderLocation
) return;
790 if (!pSHFileOperationA
) return;
791 if (shellVersion
.dwMajorVersion
< 5) return;
793 if (!RegOpenKeyExA(HKEY_CURRENT_USER
, userShellFolders
, 0, KEY_ALL_ACCESS
,
798 len
= sizeof(originalPath
);
799 if (!RegQueryValueExA(key
, "Favorites", NULL
, &type
,
800 (LPBYTE
)&originalPath
, &len
))
802 size_t len
= strlen(originalPath
);
804 memcpy(modifiedPath
, originalPath
, len
);
805 modifiedPath
[len
++] = '2';
806 modifiedPath
[len
++] = '\0';
807 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath
);
808 if (!RegSetValueExA(key
, "Favorites", 0, type
,
809 (LPBYTE
)modifiedPath
, len
))
811 char buffer
[MAX_PATH
+20];
812 STARTUPINFOA startup
;
813 PROCESS_INFORMATION info
;
815 sprintf(buffer
, "%s tests/shellpath.c 1", selfname
);
816 memset(&startup
, 0, sizeof(startup
));
817 startup
.cb
= sizeof(startup
);
818 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
819 startup
.dwFlags
= SW_SHOWNORMAL
;
820 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
822 winetest_wait_child_process( info
.hProcess
);
824 /* restore original values: */
825 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath
);
826 RegSetValueExA(key
, "Favorites", 0, type
, (LPBYTE
) originalPath
,
827 strlen(originalPath
) + 1);
830 sprintf(buffer
, "%s tests/shellpath.c 2", selfname
);
831 memset(&startup
, 0, sizeof(startup
));
832 startup
.cb
= sizeof(startup
);
833 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
834 startup
.dwFlags
= SW_SHOWNORMAL
;
835 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
,
837 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
,
838 "child process termination\n");
841 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
845 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders
);
848 static void test_SHGetFolderPathEx(void)
851 WCHAR buffer
[MAX_PATH
], *path
;
854 if (!pSHGetKnownFolderPath
|| !pSHGetFolderPathEx
)
856 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
860 if (0) { /* crashes */
861 hr
= pSHGetKnownFolderPath(&FOLDERID_Desktop
, 0, NULL
, NULL
);
862 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
864 /* non-existent folder id */
865 path
= (void *)0xdeadbeef;
866 hr
= pSHGetKnownFolderPath(&IID_IOleObject
, 0, NULL
, &path
);
867 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "got 0x%08x\n", hr
);
868 ok(path
== NULL
, "got %p\n", path
);
871 hr
= pSHGetKnownFolderPath(&FOLDERID_Desktop
, 0, NULL
, &path
);
872 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
873 ok(path
!= NULL
, "expected path != NULL\n");
875 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, MAX_PATH
);
876 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
877 ok(!lstrcmpiW(path
, buffer
), "expected equal paths\n");
878 len
= lstrlenW(buffer
);
881 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, 0);
882 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
884 if (0) { /* crashes */
885 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, NULL
, len
+ 1);
886 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
888 hr
= pSHGetFolderPathEx(NULL
, 0, NULL
, buffer
, MAX_PATH
);
889 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
891 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, len
);
892 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
), "expected 0x8007007a, got 0x%08x\n", hr
);
894 hr
= pSHGetFolderPathEx(&FOLDERID_Desktop
, 0, NULL
, buffer
, len
+ 1);
895 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
898 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
899 #define NO_CSIDL 0x10000
900 #define CSIDL_TODO_WINE 0x20000
901 #define KNOWN_FOLDER(id, csidl, name, category, parent, relative_path, parsing_name, attributes, definitionFlags) \
902 { &id, # id, csidl, # csidl, name, category, &parent, # parent, relative_path, parsing_name, attributes, definitionFlags, __LINE__ }
904 /* non-published known folders test */
905 static const GUID _FOLDERID_CryptoKeys
= {0xB88F4DAA, 0xE7BD, 0x49A9, {0xB7, 0x4D, 0x02, 0x88, 0x5A, 0x5D, 0xC7, 0x65} };
906 static const GUID _FOLDERID_DpapiKeys
= {0x10C07CD0, 0xEF91, 0x4567, {0xB8, 0x50, 0x44, 0x8B, 0x77, 0xCB, 0x37, 0xF9} };
907 static const GUID _FOLDERID_SystemCertificates
= {0x54EED2E0, 0xE7CA, 0x4FDB, {0x91, 0x48, 0x0F, 0x42, 0x47, 0x29, 0x1C, 0xFA} };
908 static const GUID _FOLDERID_CredentialManager
= {0x915221FB, 0x9EFE, 0x4BDA, {0x8F, 0xD7, 0xF7, 0x8D, 0xCA, 0x77, 0x4F, 0x87} };
910 struct knownFolderDef
{
911 const KNOWNFOLDERID
*folderId
;
912 const char *sFolderId
;
916 const KF_CATEGORY category
;
917 const KNOWNFOLDERID
*fidParent
;
919 const char *sRelativePath
;
920 const char *sParsingName
;
921 const DWORD attributes
;
922 const KF_DEFINITION_FLAGS definitionFlags
;
926 /* Note: content of parsing name may vary between Windows versions.
927 * As a base, values from 6.0 (Vista) were used. Some entries may contain
928 * alternative values. In that case, Windows version where the value was
931 * The list of values for parsing name was encoded as a number of null-
932 * terminated strings placed one by one (separated by null byte only).
933 * End of list is marked by two consecutive null bytes.
935 static const struct knownFolderDef known_folders
[] = {
936 KNOWN_FOLDER(FOLDERID_AddNewPrograms
,
938 "AddNewProgramsFolder",
942 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0"
943 "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0\0" /* 6.1 */,
946 KNOWN_FOLDER(FOLDERID_AdminTools
,
948 "Administrative Tools",
951 "Administrative Tools",
953 FILE_ATTRIBUTE_READONLY
,
955 KNOWN_FOLDER(FOLDERID_AppUpdates
,
961 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0"
962 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0\0" /* 6.1 */,
965 KNOWN_FOLDER(FOLDERID_CDBurning
,
969 FOLDERID_LocalAppData
,
970 "Microsoft\\Windows\\Burn\\Burn",
972 FILE_ATTRIBUTE_READONLY
,
973 KFDF_LOCAL_REDIRECT_ONLY
),
974 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms
,
976 "ChangeRemoveProgramsFolder",
980 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0"
981 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0\0" /* 6.1 */,
984 KNOWN_FOLDER(FOLDERID_CommonAdminTools
,
985 CSIDL_COMMON_ADMINTOOLS
,
986 "Common Administrative Tools",
988 FOLDERID_CommonPrograms
,
989 "Administrative Tools",
991 FILE_ATTRIBUTE_READONLY
,
993 KNOWN_FOLDER(FOLDERID_CommonOEMLinks
,
994 CSIDL_COMMON_OEM_LINKS
,"OEM Links",
996 FOLDERID_ProgramData
,
1001 KNOWN_FOLDER(FOLDERID_CommonPrograms
,
1002 CSIDL_COMMON_PROGRAMS
,
1005 FOLDERID_CommonStartMenu
,
1008 FILE_ATTRIBUTE_READONLY
,
1010 KNOWN_FOLDER(FOLDERID_CommonStartMenu
,
1011 CSIDL_COMMON_STARTMENU
,
1012 "Common Start Menu",
1014 FOLDERID_ProgramData
,
1015 "Microsoft\\Windows\\Start Menu",
1017 FILE_ATTRIBUTE_READONLY
,
1019 KNOWN_FOLDER(FOLDERID_CommonStartup
,
1020 CSIDL_COMMON_STARTUP
,
1023 FOLDERID_CommonPrograms
,
1026 FILE_ATTRIBUTE_READONLY
,
1028 KNOWN_FOLDER(FOLDERID_CommonTemplates
,
1029 CSIDL_COMMON_TEMPLATES
,
1032 FOLDERID_ProgramData
,
1033 "Microsoft\\Windows\\Templates",
1037 KNOWN_FOLDER(FOLDERID_ComputerFolder
,
1040 KF_CATEGORY_VIRTUAL
,
1043 "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\0\0",
1046 KNOWN_FOLDER(FOLDERID_ConflictFolder
,
1049 KF_CATEGORY_VIRTUAL
,
1052 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0"
1053 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0\0" /* 6.1 */,
1056 KNOWN_FOLDER(FOLDERID_ConnectionsFolder
,
1058 "ConnectionsFolder",
1059 KF_CATEGORY_VIRTUAL
,
1062 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0"
1063 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0\0" /* 6.1 */,
1066 KNOWN_FOLDER(FOLDERID_Contacts
,
1069 KF_CATEGORY_PERUSER
,
1072 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{56784854-C6CB-462B-8169-88E350ACB882}\0\0",
1073 FILE_ATTRIBUTE_READONLY
,
1074 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1075 KNOWN_FOLDER(FOLDERID_ControlPanelFolder
,
1077 "ControlPanelFolder",
1078 KF_CATEGORY_VIRTUAL
,
1081 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\0"
1082 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\0\0" /* 6.1 */,
1085 KNOWN_FOLDER(FOLDERID_Cookies
,
1088 KF_CATEGORY_PERUSER
,
1089 FOLDERID_RoamingAppData
,
1090 "Microsoft\\Windows\\Cookies",
1094 KNOWN_FOLDER(FOLDERID_Desktop
,
1097 KF_CATEGORY_PERUSER
,
1101 FILE_ATTRIBUTE_READONLY
,
1102 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1103 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore
,
1105 "Device Metadata Store",
1107 FOLDERID_ProgramData
,
1108 "Microsoft\\Windows\\DeviceMetadataStore",
1112 KNOWN_FOLDER(FOLDERID_Documents
,
1115 KF_CATEGORY_PERUSER
,
1118 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{FDD39AD0-238F-46AF-ADB4-6C85480369C7}\0\0",
1119 FILE_ATTRIBUTE_READONLY
,
1120 KFDF_ROAMABLE
| KFDF_PRECREATE
),
1121 KNOWN_FOLDER(FOLDERID_DocumentsLibrary
,
1124 KF_CATEGORY_PERUSER
,
1126 "Documents.library-ms",
1127 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{7b0db17d-9cd2-4a93-9733-46cc89022e7c}\0\0",
1129 KFDF_PRECREATE
| KFDF_STREAM
),
1130 KNOWN_FOLDER(FOLDERID_Downloads
,
1133 KF_CATEGORY_PERUSER
,
1137 FILE_ATTRIBUTE_READONLY
,
1138 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1139 KNOWN_FOLDER(FOLDERID_Favorites
,
1142 KF_CATEGORY_PERUSER
,
1146 FILE_ATTRIBUTE_READONLY
,
1147 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1148 KNOWN_FOLDER(FOLDERID_Fonts
,
1157 KNOWN_FOLDER(FOLDERID_Games
,
1160 KF_CATEGORY_VIRTUAL
,
1163 "::{ED228FDF-9EA8-4870-83b1-96b02CFE0D52}\0\0",
1166 KNOWN_FOLDER(FOLDERID_GameTasks
,
1169 KF_CATEGORY_PERUSER
,
1170 FOLDERID_LocalAppData
,
1171 "Microsoft\\Windows\\GameExplorer",
1174 KFDF_LOCAL_REDIRECT_ONLY
),
1175 KNOWN_FOLDER(FOLDERID_History
,
1178 KF_CATEGORY_PERUSER
,
1179 FOLDERID_LocalAppData
,
1180 "Microsoft\\Windows\\History",
1183 KFDF_LOCAL_REDIRECT_ONLY
),
1184 KNOWN_FOLDER(FOLDERID_HomeGroup
,
1187 KF_CATEGORY_VIRTUAL
,
1190 "::{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}\0\0",
1193 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts
,
1195 "ImplicitAppShortcuts",
1196 KF_CATEGORY_PERUSER
,
1197 FOLDERID_UserPinned
,
1198 "ImplicitAppShortcuts",
1202 KNOWN_FOLDER(FOLDERID_InternetCache
,
1203 CSIDL_INTERNET_CACHE
,
1205 KF_CATEGORY_PERUSER
,
1206 FOLDERID_LocalAppData
,
1207 "Microsoft\\Windows\\Temporary Internet Files",
1210 KFDF_LOCAL_REDIRECT_ONLY
),
1211 KNOWN_FOLDER(FOLDERID_InternetFolder
,
1214 KF_CATEGORY_VIRTUAL
,
1217 "::{871C5380-42A0-1069-A2EA-08002B30309D}\0\0",
1220 KNOWN_FOLDER(FOLDERID_Libraries
,
1223 KF_CATEGORY_PERUSER
,
1224 FOLDERID_RoamingAppData
,
1225 "Microsoft\\Windows\\Libraries",
1228 KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1229 KNOWN_FOLDER(FOLDERID_Links
,
1232 KF_CATEGORY_PERUSER
,
1235 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}\0\0",
1236 FILE_ATTRIBUTE_READONLY
,
1237 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1238 KNOWN_FOLDER(FOLDERID_LocalAppData
,
1239 CSIDL_LOCAL_APPDATA
,
1241 KF_CATEGORY_PERUSER
,
1246 KFDF_LOCAL_REDIRECT_ONLY
| KFDF_PUBLISHEXPANDEDPATH
),
1247 KNOWN_FOLDER(FOLDERID_LocalAppDataLow
,
1250 KF_CATEGORY_PERUSER
,
1252 "AppData\\LocalLow",
1254 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
,
1255 KFDF_LOCAL_REDIRECT_ONLY
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1256 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir
,
1257 CSIDL_RESOURCES_LOCALIZED
,
1258 "LocalizedResourcesDir",
1265 KNOWN_FOLDER(FOLDERID_Music
,
1268 KF_CATEGORY_PERUSER
,
1271 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4BD8D571-6D19-48D3-BE97-422220080E43}\0\0",
1272 FILE_ATTRIBUTE_READONLY
,
1273 KFDF_ROAMABLE
| KFDF_PRECREATE
),
1274 KNOWN_FOLDER(FOLDERID_MusicLibrary
,
1277 KF_CATEGORY_PERUSER
,
1280 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{2112AB0A-C86A-4ffe-A368-0DE96E47012E}\0\0",
1282 KFDF_PRECREATE
| KFDF_STREAM
),
1283 KNOWN_FOLDER(FOLDERID_NetHood
,
1286 KF_CATEGORY_PERUSER
,
1287 FOLDERID_RoamingAppData
,
1288 "Microsoft\\Windows\\Network Shortcuts",
1292 KNOWN_FOLDER(FOLDERID_NetworkFolder
,
1294 "NetworkPlacesFolder",
1295 KF_CATEGORY_VIRTUAL
,
1298 "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}\0\0",
1301 KNOWN_FOLDER(FOLDERID_OriginalImages
,
1304 KF_CATEGORY_PERUSER
,
1305 FOLDERID_LocalAppData
,
1306 "Microsoft\\Windows Photo Gallery\\Original Images",
1310 KNOWN_FOLDER(FOLDERID_PhotoAlbums
,
1313 KF_CATEGORY_PERUSER
,
1317 FILE_ATTRIBUTE_READONLY
,
1319 KNOWN_FOLDER(FOLDERID_Pictures
,
1322 KF_CATEGORY_PERUSER
,
1325 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{33E28130-4E1E-4676-835A-98395C3BC3BB}\0\0",
1326 FILE_ATTRIBUTE_READONLY
,
1327 KFDF_ROAMABLE
| KFDF_PRECREATE
),
1328 KNOWN_FOLDER(FOLDERID_PicturesLibrary
,
1331 KF_CATEGORY_PERUSER
,
1333 "Pictures.library-ms",
1334 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{A990AE9F-A03B-4e80-94BC-9912D7504104}\0\0",
1336 KFDF_PRECREATE
| KFDF_STREAM
),
1337 KNOWN_FOLDER(FOLDERID_Playlists
,
1340 KF_CATEGORY_PERUSER
,
1344 FILE_ATTRIBUTE_READONLY
,
1346 KNOWN_FOLDER(FOLDERID_PrintersFolder
,
1349 KF_CATEGORY_VIRTUAL
,
1352 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}\0\0",
1355 KNOWN_FOLDER(FOLDERID_PrintHood
,
1358 KF_CATEGORY_PERUSER
,
1359 FOLDERID_RoamingAppData
,
1360 "Microsoft\\Windows\\Printer Shortcuts",
1364 KNOWN_FOLDER(FOLDERID_Profile
,
1373 KNOWN_FOLDER(FOLDERID_ProgramData
,
1374 CSIDL_COMMON_APPDATA
,
1382 KNOWN_FOLDER(FOLDERID_ProgramFiles
,
1383 CSIDL_PROGRAM_FILES
,
1389 FILE_ATTRIBUTE_READONLY
,
1392 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon
,
1393 CSIDL_PROGRAM_FILES_COMMON
,
1394 "ProgramFilesCommon",
1401 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX64
,
1403 "ProgramFilesCommonX64",
1410 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86
,
1412 "ProgramFilesCommonX86",
1419 KNOWN_FOLDER(FOLDERID_ProgramFilesX64
,
1428 KNOWN_FOLDER(FOLDERID_ProgramFilesX86
,
1429 CSIDL_PROGRAM_FILESX86
,
1435 FILE_ATTRIBUTE_READONLY
,
1437 KNOWN_FOLDER(FOLDERID_Programs
,
1440 KF_CATEGORY_PERUSER
,
1444 FILE_ATTRIBUTE_READONLY
,
1446 KNOWN_FOLDER(FOLDERID_Public
,
1452 "::{4336a54d-038b-4685-ab02-99bb52d3fb8b}\0"
1453 "(null)\0\0" /* 6.1 */,
1454 FILE_ATTRIBUTE_READONLY
,
1456 KNOWN_FOLDER(FOLDERID_PublicDesktop
,
1457 CSIDL_COMMON_DESKTOPDIRECTORY
,
1463 FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
,
1465 KNOWN_FOLDER(FOLDERID_PublicDocuments
,
1466 CSIDL_COMMON_DOCUMENTS
,
1472 FILE_ATTRIBUTE_READONLY
,
1474 KNOWN_FOLDER(FOLDERID_PublicDownloads
,
1481 FILE_ATTRIBUTE_READONLY
,
1483 KNOWN_FOLDER(FOLDERID_PublicGameTasks
,
1487 FOLDERID_ProgramData
,
1488 "Microsoft\\Windows\\GameExplorer",
1491 KFDF_LOCAL_REDIRECT_ONLY
),
1492 KNOWN_FOLDER(FOLDERID_PublicLibraries
,
1499 FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
,
1501 KNOWN_FOLDER(FOLDERID_PublicMusic
,
1508 FILE_ATTRIBUTE_READONLY
,
1510 KNOWN_FOLDER(FOLDERID_PublicPictures
,
1511 CSIDL_COMMON_PICTURES
,
1517 FILE_ATTRIBUTE_READONLY
,
1519 KNOWN_FOLDER(FOLDERID_PublicRingtones
,
1523 FOLDERID_ProgramData
,
1524 "Microsoft\\Windows\\Ringtones",
1528 KNOWN_FOLDER(FOLDERID_PublicVideos
,
1535 FILE_ATTRIBUTE_READONLY
,
1537 KNOWN_FOLDER(FOLDERID_QuickLaunch
,
1540 KF_CATEGORY_PERUSER
,
1541 FOLDERID_RoamingAppData
,
1542 "Microsoft\\Internet Explorer\\Quick Launch",
1546 KNOWN_FOLDER(FOLDERID_Recent
,
1549 KF_CATEGORY_PERUSER
,
1550 FOLDERID_RoamingAppData
,
1551 "Microsoft\\Windows\\Recent",
1553 FILE_ATTRIBUTE_READONLY
,
1555 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary
,
1557 "RecordedTVLibrary",
1559 FOLDERID_PublicLibraries
,
1560 "RecordedTV.library-ms",
1563 KFDF_PRECREATE
| KFDF_STREAM
),
1564 KNOWN_FOLDER(FOLDERID_RecycleBinFolder
,
1567 KF_CATEGORY_VIRTUAL
,
1570 "::{645FF040-5081-101B-9F08-00AA002F954E}\0\0",
1573 KNOWN_FOLDER(FOLDERID_ResourceDir
,
1582 KNOWN_FOLDER(FOLDERID_Ringtones
,
1585 KF_CATEGORY_PERUSER
,
1586 FOLDERID_LocalAppData
,
1587 "Microsoft\\Windows\\Ringtones",
1591 KNOWN_FOLDER(FOLDERID_RoamingAppData
,
1594 KF_CATEGORY_PERUSER
,
1600 KNOWN_FOLDER(FOLDERID_SampleMusic
,
1604 FOLDERID_PublicMusic
,
1607 FILE_ATTRIBUTE_READONLY
,
1609 KNOWN_FOLDER(FOLDERID_SamplePictures
,
1613 FOLDERID_PublicPictures
,
1616 FILE_ATTRIBUTE_READONLY
,
1618 KNOWN_FOLDER(FOLDERID_SamplePlaylists
,
1622 FOLDERID_PublicMusic
,
1625 FILE_ATTRIBUTE_READONLY
,
1627 KNOWN_FOLDER(FOLDERID_SampleVideos
,
1631 FOLDERID_PublicVideos
,
1634 FILE_ATTRIBUTE_READONLY
,
1636 KNOWN_FOLDER(FOLDERID_SavedGames
,
1639 KF_CATEGORY_PERUSER
,
1642 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}\0\0",
1643 FILE_ATTRIBUTE_READONLY
,
1644 KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1645 KNOWN_FOLDER(FOLDERID_SavedSearches
,
1648 KF_CATEGORY_PERUSER
,
1651 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{7d1d3a04-debb-4115-95cf-2f29da2920da}\0\0",
1652 FILE_ATTRIBUTE_READONLY
,
1653 KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
),
1654 KNOWN_FOLDER(FOLDERID_SEARCH_CSC
,
1657 KF_CATEGORY_VIRTUAL
,
1660 "shell:::{BD7A2E7B-21CB-41b2-A086-B309680C6B7E}\\*\0\0",
1663 KNOWN_FOLDER(FOLDERID_SearchHome
,
1666 KF_CATEGORY_VIRTUAL
,
1669 "::{9343812e-1c37-4a49-a12e-4b2d810d956b}\0\0",
1672 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI
,
1675 KF_CATEGORY_VIRTUAL
,
1678 "shell:::{89D83576-6BD1-4C86-9454-BEB04E94C819}\\*\0\0",
1681 KNOWN_FOLDER(FOLDERID_SendTo
,
1684 KF_CATEGORY_PERUSER
,
1685 FOLDERID_RoamingAppData
,
1686 "Microsoft\\Windows\\SendTo",
1690 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts
,
1694 FOLDERID_ProgramFiles
,
1695 "Windows Sidebar\\Gadgets",
1699 KNOWN_FOLDER(FOLDERID_SidebarParts
,
1702 KF_CATEGORY_PERUSER
,
1703 FOLDERID_LocalAppData
,
1704 "Microsoft\\Windows Sidebar\\Gadgets",
1708 KNOWN_FOLDER(FOLDERID_StartMenu
,
1711 KF_CATEGORY_PERUSER
,
1712 FOLDERID_RoamingAppData
,
1713 "Microsoft\\Windows\\Start Menu",
1715 FILE_ATTRIBUTE_READONLY
,
1717 KNOWN_FOLDER(FOLDERID_Startup
,
1720 KF_CATEGORY_PERUSER
,
1724 FILE_ATTRIBUTE_READONLY
,
1726 KNOWN_FOLDER(FOLDERID_SyncManagerFolder
,
1729 KF_CATEGORY_VIRTUAL
,
1732 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0"
1733 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0\0" /* 6.1 */,
1736 KNOWN_FOLDER(FOLDERID_SyncResultsFolder
,
1738 "SyncResultsFolder",
1739 KF_CATEGORY_VIRTUAL
,
1742 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0"
1743 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0\0",
1746 KNOWN_FOLDER(FOLDERID_SyncSetupFolder
,
1749 KF_CATEGORY_VIRTUAL
,
1752 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0"
1753 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0\0" /* 6.1 */,
1756 KNOWN_FOLDER(FOLDERID_System
,
1765 KNOWN_FOLDER(FOLDERID_SystemX86
,
1774 KNOWN_FOLDER(FOLDERID_Templates
,
1777 KF_CATEGORY_PERUSER
,
1778 FOLDERID_RoamingAppData
,
1779 "Microsoft\\Windows\\Templates",
1783 KNOWN_FOLDER(FOLDERID_UserPinned
,
1786 KF_CATEGORY_PERUSER
,
1787 FOLDERID_QuickLaunch
,
1790 FILE_ATTRIBUTE_HIDDEN
,
1792 KNOWN_FOLDER(FOLDERID_UserProfiles
,
1799 FILE_ATTRIBUTE_READONLY
,
1801 KNOWN_FOLDER(FOLDERID_UserProgramFiles
,
1804 KF_CATEGORY_PERUSER
,
1805 FOLDERID_LocalAppData
,
1810 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon
,
1812 "UserProgramFilesCommon",
1813 KF_CATEGORY_PERUSER
,
1814 FOLDERID_UserProgramFiles
,
1819 KNOWN_FOLDER(FOLDERID_UsersFiles
,
1822 KF_CATEGORY_VIRTUAL
,
1825 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\0\0",
1828 KNOWN_FOLDER(FOLDERID_UsersLibraries
,
1830 "UsersLibrariesFolder",
1831 KF_CATEGORY_VIRTUAL
,
1834 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\0\0",
1837 KNOWN_FOLDER(FOLDERID_Videos
,
1840 KF_CATEGORY_PERUSER
,
1843 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{18989B1D-99B5-455B-841C-AB7C74E4DDFC}\0\0",
1844 FILE_ATTRIBUTE_READONLY
,
1845 KFDF_ROAMABLE
| KFDF_PRECREATE
),
1846 KNOWN_FOLDER(FOLDERID_VideosLibrary
,
1849 KF_CATEGORY_PERUSER
,
1851 "Videos.library-ms",
1852 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{491E922F-5643-4af4-A7EB-4E7A138D8174}\0\0",
1854 KFDF_PRECREATE
| KFDF_STREAM
),
1855 KNOWN_FOLDER(FOLDERID_Windows
,
1864 KNOWN_FOLDER(_FOLDERID_CredentialManager
,
1866 "CredentialManager",
1873 KNOWN_FOLDER(_FOLDERID_CryptoKeys
,
1882 KNOWN_FOLDER(_FOLDERID_DpapiKeys
,
1891 KNOWN_FOLDER(_FOLDERID_SystemCertificates
,
1893 "SystemCertificates",
1900 { NULL
, NULL
, 0, NULL
, NULL
, 0, 0 }
1903 BOOL known_folder_found
[sizeof(known_folders
)/sizeof(known_folders
[0])-1];
1905 static void check_known_folder(IKnownFolderManager
*mgr
, KNOWNFOLDERID
*folderId
)
1908 const struct knownFolderDef
*known_folder
= &known_folders
[0];
1909 int csidl
, expectedCsidl
, ret
;
1910 KNOWNFOLDER_DEFINITION kfd
;
1911 IKnownFolder
*folder
;
1912 WCHAR sName
[1024], sRelativePath
[MAX_PATH
], sParsingName
[MAX_PATH
];
1914 char sParentGuid
[39];
1915 BOOL
*current_known_folder_found
= &known_folder_found
[0];
1917 const char *srcParsingName
;
1919 while(known_folder
->folderId
!= NULL
)
1921 if(IsEqualGUID(known_folder
->folderId
, folderId
))
1923 *current_known_folder_found
= TRUE
;
1926 if(known_folder
->csidl
!= NO_CSIDL
)
1928 expectedCsidl
= known_folder
->csidl
& (~CSIDL_TODO_WINE
);
1930 hr
= IKnownFolderManager_FolderIdToCsidl(mgr
, folderId
, &csidl
);
1931 ok_(__FILE__
, known_folder
->line
)(hr
== S_OK
, "cannot retrieve CSIDL for folder %s\n", known_folder
->sFolderId
);
1933 if(known_folder
->csidl
& CSIDL_TODO_WINE
)
1934 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
);
1936 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
);
1939 hr
= IKnownFolderManager_GetFolder(mgr
, folderId
, &folder
);
1940 ok_(__FILE__
, known_folder
->line
)(hr
== S_OK
, "cannot get known folder for %s\n", known_folder
->sFolderId
);
1943 hr
= IKnownFolder_GetFolderDefinition(folder
, &kfd
);
1945 ok_(__FILE__
, known_folder
->line
)(hr
== S_OK
, "cannot get known folder definition for %s\n", known_folder
->sFolderId
);
1948 ret
= MultiByteToWideChar(CP_ACP
, 0, known_folder
->sName
, -1, sName
, sizeof(sName
)/sizeof(sName
[0]));
1949 ok_(__FILE__
, known_folder
->line
)(ret
!= 0, "cannot convert known folder name \"%s\" to wide characters\n", known_folder
->sName
);
1952 ok_(__FILE__
, known_folder
->line
)(lstrcmpW(kfd
.pszName
, sName
)==0, "invalid known folder name returned for %s: %s expected, but %s retrieved\n", known_folder
->sFolderId
, wine_dbgstr_w(sName
), wine_dbgstr_w(kfd
.pszName
));
1954 ok_(__FILE__
, known_folder
->line
)(kfd
.category
== known_folder
->category
, "invalid known folder category for %s: %d expected, but %d retrieved\n", known_folder
->sFolderId
, known_folder
->category
, kfd
.category
);
1956 printGUID(&kfd
.fidParent
, sParentGuid
);
1957 ok_(__FILE__
, known_folder
->line
)(IsEqualGUID(known_folder
->fidParent
, &kfd
.fidParent
), "invalid known folder parent for %s: %s expected, but %s retrieved\n", known_folder
->sFolderId
, known_folder
->sParent
, sParentGuid
);
1959 if(!known_folder
->sRelativePath
)
1960 validPath
= (kfd
.pszRelativePath
==NULL
);
1963 ret
= MultiByteToWideChar(CP_ACP
, 0, known_folder
->sRelativePath
, -1, sRelativePath
, sizeof(sRelativePath
)/sizeof(sRelativePath
[0]));
1964 ok_(__FILE__
, known_folder
->line
)(ret
!= 0, "cannot convert known folder path \"%s\" to wide characters\n", known_folder
->sRelativePath
);
1966 validPath
= (lstrcmpW(kfd
.pszRelativePath
, sRelativePath
)==0);
1969 ok_(__FILE__
, known_folder
->line
)(validPath
, "invalid known folder relative path returned for %s: %s expected, but %s retrieved\n", known_folder
->sFolderId
, known_folder
->sRelativePath
, wine_dbgstr_w(kfd
.pszRelativePath
));
1971 /* to check parsing name, we need to iterate list */
1972 srcParsingName
= known_folder
->sParsingName
;
1974 /* if we expect NULL, then we don't even check the list */
1975 validPath
= (srcParsingName
==NULL
) && (kfd
.pszParsingName
==NULL
);
1978 while(*srcParsingName
&& !validPath
)
1980 /* when NULL is only one of possible value, we mark path as valid */
1981 validPath
= (strcmp(srcParsingName
, "(null)")==0) && (kfd
.pszParsingName
==NULL
);
1983 /* in the other case, we compare string from list with retrieved value */
1986 ret
= MultiByteToWideChar(CP_ACP
, 0, srcParsingName
, -1, sParsingName
, sizeof(sParsingName
)/sizeof(sParsingName
[0]));
1987 ok_(__FILE__
, known_folder
->line
)(ret
!= 0, "cannot convert known folder path \"%s\" to wide characters\n", srcParsingName
);
1989 validPath
= (lstrcmpW(kfd
.pszParsingName
, sParsingName
)==0);
1992 srcParsingName
+= strlen(srcParsingName
)+1;
1995 ok_(__FILE__
, known_folder
->line
)(validPath
, "invalid known folder parsing name returned for %s: %s retrieved\n", known_folder
->sFolderId
, wine_dbgstr_w(kfd
.pszParsingName
));
1997 ok_(__FILE__
, known_folder
->line
)(known_folder
->attributes
== kfd
.dwAttributes
, "invalid known folder attributes for %s: 0x%08x expected, but 0x%08x retrieved\n", known_folder
->sFolderId
, known_folder
->attributes
, kfd
.dwAttributes
);
1999 ok_(__FILE__
, known_folder
->line
)(!(kfd
.kfdFlags
& (~known_folder
->definitionFlags
)), "invalid known folder flags for %s: 0x%08x expected, but 0x%08x retrieved\n", known_folder
->sFolderId
, known_folder
->definitionFlags
, kfd
.kfdFlags
);
2001 FreeKnownFolderDefinitionFields(&kfd
);
2004 IKnownFolder_Release(folder
);
2010 current_known_folder_found
++;
2015 printGUID(folderId
, sParentGuid
);
2016 trace("unknown known folder found: %s\n", sParentGuid
);
2018 hr
= IKnownFolderManager_GetFolder(mgr
, folderId
, &folder
);
2019 ok(hr
== S_OK
, "cannot get known folder for %s\n", sParentGuid
);
2022 hr
= IKnownFolder_GetFolderDefinition(folder
, &kfd
);
2024 ok(hr
== S_OK
, "cannot get known folder definition for %s\n", sParentGuid
);
2027 trace(" category: %d\n", kfd
.category
);
2028 trace(" name: %s\n", wine_dbgstr_w(kfd
.pszName
));
2029 trace(" description: %s\n", wine_dbgstr_w(kfd
.pszDescription
));
2030 printGUID(&kfd
.fidParent
, sParentGuid
);
2031 trace(" parent: %s\n", sParentGuid
);
2032 trace(" relative path: %s\n", wine_dbgstr_w(kfd
.pszRelativePath
));
2033 trace(" parsing name: %s\n", wine_dbgstr_w(kfd
.pszParsingName
));
2034 trace(" tooltip: %s\n", wine_dbgstr_w(kfd
.pszTooltip
));
2035 trace(" localized name: %s\n", wine_dbgstr_w(kfd
.pszLocalizedName
));
2036 trace(" icon: %s\n", wine_dbgstr_w(kfd
.pszIcon
));
2037 trace(" security: %s\n", wine_dbgstr_w(kfd
.pszSecurity
));
2038 trace(" attributes: 0x%08x\n", kfd
.dwAttributes
);
2039 trace(" flags: 0x%08x\n", kfd
.kfdFlags
);
2040 printGUID(&kfd
.ftidType
, sParentGuid
);
2041 trace(" type: %s\n", sParentGuid
);
2042 FreeKnownFolderDefinitionFields(&kfd
);
2045 IKnownFolder_Release(folder
);
2050 #undef CSIDL_TODO_WINE
2052 static void test_knownFolders(void)
2054 static const WCHAR sWindows
[] = {'W','i','n','d','o','w','s',0};
2055 static const WCHAR sExample
[] = {'E','x','a','m','p','l','e',0};
2056 static const WCHAR sExample2
[] = {'E','x','a','m','p','l','e','2',0};
2057 static const WCHAR sSubFolder
[] = {'S','u','b','F','o','l','d','e','r',0};
2058 static const WCHAR sBackslash
[] = {'\\',0};
2059 static const KNOWNFOLDERID newFolderId
= {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
2060 static const KNOWNFOLDERID subFolderId
= {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
2062 IKnownFolderManager
*mgr
= NULL
;
2063 IKnownFolder
*folder
= NULL
, *subFolder
= NULL
;
2064 KNOWNFOLDERID folderId
, *folders
;
2065 KF_CATEGORY cat
= 0;
2066 KNOWNFOLDER_DEFINITION kfDefinition
, kfSubDefinition
;
2069 LPWSTR folderPath
, errorMsg
;
2070 KF_REDIRECTION_CAPABILITIES redirectionCapabilities
= 1;
2071 WCHAR sWinDir
[MAX_PATH
], sExamplePath
[MAX_PATH
], sExample2Path
[MAX_PATH
], sSubFolderPath
[MAX_PATH
], sSubFolder2Path
[MAX_PATH
];
2075 GetWindowsDirectoryW( sWinDir
, MAX_PATH
);
2077 GetTempPathW(sizeof(sExamplePath
)/sizeof(sExamplePath
[0]), sExamplePath
);
2078 lstrcatW(sExamplePath
, sExample
);
2080 GetTempPathW(sizeof(sExample2Path
)/sizeof(sExample2Path
[0]), sExample2Path
);
2081 lstrcatW(sExample2Path
, sExample2
);
2083 lstrcpyW(sSubFolderPath
, sExamplePath
);
2084 lstrcatW(sSubFolderPath
, sBackslash
);
2085 lstrcatW(sSubFolderPath
, sSubFolder
);
2087 lstrcpyW(sSubFolder2Path
, sExample2Path
);
2088 lstrcatW(sSubFolder2Path
, sBackslash
);
2089 lstrcatW(sSubFolder2Path
, sSubFolder
);
2093 hr
= CoCreateInstance(&CLSID_KnownFolderManager
, NULL
, CLSCTX_INPROC_SERVER
,
2094 &IID_IKnownFolderManager
, (LPVOID
*)&mgr
);
2095 if(hr
== REGDB_E_CLASSNOTREG
)
2096 win_skip("IKnownFolderManager unavailable\n");
2099 ok(hr
== S_OK
, "failed to create KnownFolderManager instance: 0x%08x\n", hr
);
2101 hr
= IKnownFolderManager_FolderIdFromCsidl(mgr
, CSIDL_WINDOWS
, &folderId
);
2102 ok(hr
== S_OK
, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr
);
2103 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
2105 hr
= IKnownFolderManager_FolderIdToCsidl(mgr
, &FOLDERID_Windows
, &csidl
);
2106 ok(hr
== S_OK
, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr
);
2107 ok(csidl
== CSIDL_WINDOWS
, "invalid CSIDL returned\n");
2109 hr
= IKnownFolderManager_GetFolder(mgr
, &FOLDERID_Windows
, &folder
);
2110 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
2113 hr
= IKnownFolder_GetCategory(folder
, &cat
);
2115 ok(hr
== S_OK
, "failed to get folder category: 0x%08x\n", hr
);
2117 ok(cat
==KF_CATEGORY_FIXED
, "invalid folder category: %d\n", cat
);
2119 hr
= IKnownFolder_GetId(folder
, &folderId
);
2120 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
2121 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
2123 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2124 ok(lstrcmpiW(sWinDir
, folderPath
)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sWinDir
));
2125 CoTaskMemFree(folderPath
);
2127 hr
= IKnownFolder_GetRedirectionCapabilities(folder
, &redirectionCapabilities
);
2129 ok(hr
== S_OK
, "failed to get redirection capabilities: 0x%08x\n", hr
);
2131 ok(redirectionCapabilities
==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities
);
2133 hr
= IKnownFolder_SetPath(folder
, 0, sWinDir
);
2135 ok(hr
== E_INVALIDARG
, "unexpected value from SetPath: 0x%08x\n", hr
);
2137 hr
= IKnownFolder_GetFolderDefinition(folder
, &kfDefinition
);
2139 ok(hr
== S_OK
, "failed to get folder definition: 0x%08x\n", hr
);
2143 ok(kfDefinition
.category
==KF_CATEGORY_FIXED
, "invalid folder category: 0x%08x\n", kfDefinition
.category
);
2145 ok(lstrcmpW(kfDefinition
.pszName
, sWindows
)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition
.pszName
));
2147 ok(kfDefinition
.dwAttributes
==0, "invalid folder attributes: %d\n", kfDefinition
.dwAttributes
);
2148 FreeKnownFolderDefinitionFields(&kfDefinition
);
2151 hr
= IKnownFolder_Release(folder
);
2152 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
2155 hr
= IKnownFolderManager_GetFolderByName(mgr
, sWindows
, &folder
);
2157 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
2160 hr
= IKnownFolder_GetId(folder
, &folderId
);
2161 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
2162 ok(IsEqualGUID(&folderId
, &FOLDERID_Windows
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
2164 hr
= IKnownFolder_Release(folder
);
2165 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
2168 for(i
=0; i
<sizeof(known_folder_found
)/sizeof(known_folder_found
[0]); ++i
)
2169 known_folder_found
[i
] = FALSE
;
2171 hr
= IKnownFolderManager_GetFolderIds(mgr
, &folders
, &nCount
);
2172 ok(hr
== S_OK
, "failed to get known folders: 0x%08x\n", hr
);
2173 for(i
=0;i
<nCount
;++i
)
2174 check_known_folder(mgr
, &folders
[i
]);
2176 for(i
=0; i
<sizeof(known_folder_found
)/sizeof(known_folder_found
[0]); ++i
)
2177 if(!known_folder_found
[i
])
2178 trace("Known folder %s not found on current platform\n", known_folders
[i
].sFolderId
);
2180 CoTaskMemFree(folders
);
2182 /* test of registering new known folders */
2183 bRes
= CreateDirectoryW(sExamplePath
, NULL
);
2184 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath
));
2185 bRes
= CreateDirectoryW(sExample2Path
, NULL
);
2186 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path
));
2187 bRes
= CreateDirectoryW(sSubFolderPath
, NULL
);
2188 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath
));
2190 ZeroMemory(&kfDefinition
, sizeof(kfDefinition
));
2191 kfDefinition
.category
= KF_CATEGORY_PERUSER
;
2192 kfDefinition
.pszName
= CoTaskMemAlloc(sizeof(sExample
));
2193 lstrcpyW(kfDefinition
.pszName
, sExample
);
2194 kfDefinition
.pszDescription
= CoTaskMemAlloc(sizeof(sExample
));
2195 lstrcpyW(kfDefinition
.pszDescription
, sExample
);
2196 kfDefinition
.pszRelativePath
= CoTaskMemAlloc(sizeof(sExamplePath
));
2197 lstrcpyW(kfDefinition
.pszRelativePath
, sExamplePath
);
2199 hr
= IKnownFolderManager_RegisterFolder(mgr
, &newFolderId
, &kfDefinition
);
2200 if(hr
== HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED
))
2201 win_skip("No permissions required to register custom known folder\n");
2204 ok(hr
== S_OK
, "failed to register known folder: 0x%08x\n", hr
);
2207 hr
= IKnownFolderManager_GetFolder(mgr
, &newFolderId
, &folder
);
2208 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
2211 hr
= IKnownFolder_GetCategory(folder
, &cat
);
2212 ok(hr
== S_OK
, "failed to get folder category: hr=0x%0x\n", hr
);
2213 ok(cat
== KF_CATEGORY_PERUSER
, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat
, KF_CATEGORY_PERUSER
);
2215 hr
= IKnownFolder_GetId(folder
, &folderId
);
2216 ok(hr
== S_OK
, "failed to get folder id: 0x%08x\n", hr
);
2217 ok(IsEqualGUID(&folderId
, &newFolderId
)==TRUE
, "invalid KNOWNFOLDERID returned\n");
2219 /* current path should be Temp\Example */
2220 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2221 ok(hr
== S_OK
, "failed to get path from known folder: 0x%08x\n", hr
);
2222 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2223 CoTaskMemFree(folderPath
);
2225 /* register sub-folder and mark it as child of Example folder */
2226 ZeroMemory(&kfSubDefinition
, sizeof(kfSubDefinition
));
2227 kfSubDefinition
.category
= KF_CATEGORY_PERUSER
;
2228 kfSubDefinition
.pszName
= CoTaskMemAlloc(sizeof(sSubFolder
));
2229 lstrcpyW(kfSubDefinition
.pszName
, sSubFolder
);
2230 kfSubDefinition
.pszDescription
= CoTaskMemAlloc(sizeof(sSubFolder
));
2231 lstrcpyW(kfSubDefinition
.pszDescription
, sSubFolder
);
2232 kfSubDefinition
.pszRelativePath
= CoTaskMemAlloc(sizeof(sSubFolder
));
2233 lstrcpyW(kfSubDefinition
.pszRelativePath
, sSubFolder
);
2234 kfSubDefinition
.fidParent
= newFolderId
;
2236 hr
= IKnownFolderManager_RegisterFolder(mgr
, &subFolderId
, &kfSubDefinition
);
2237 ok(hr
== S_OK
, "failed to register known folder: 0x%08x\n", hr
);
2241 hr
= IKnownFolderManager_GetFolder(mgr
, &subFolderId
, &subFolder
);
2242 ok(hr
== S_OK
, "failed to get known folder: 0x%08x\n", hr
);
2245 /* check sub folder path */
2246 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2247 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2248 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
2249 CoTaskMemFree(folderPath
);
2252 /* try to redirect Example to Temp\Example2 */
2253 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 0, NULL
, &errorMsg
);
2254 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2257 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2258 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2259 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
2260 CoTaskMemFree(folderPath
);
2262 /* verify sub folder - it should fail now, as we redirected it's parent folder, but we have no sub folder in new location */
2263 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2264 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "unexpected value from GetPath(): 0x%08x\n", hr
);
2265 ok(folderPath
==NULL
, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath
));
2266 CoTaskMemFree(folderPath
);
2269 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
2270 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
2271 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
2274 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2275 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2276 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2277 CoTaskMemFree(folderPath
);
2280 /* create sub folder in Temp\Example2 */
2281 bRes
= CreateDirectoryW(sSubFolder2Path
, NULL
);
2282 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path
));
2284 /* again perform that same redirection */
2285 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 0, NULL
, &errorMsg
);
2286 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2288 /* verify sub folder. It should succeed now, as the required sub folder exists */
2289 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2290 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2291 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
2292 CoTaskMemFree(folderPath
);
2294 /* remove newly created directory */
2295 RemoveDirectoryW(sSubFolder2Path
);
2297 /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
2298 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2300 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2302 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
2303 CoTaskMemFree(folderPath
);
2306 /* set Example path to original */
2307 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
2308 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
2311 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2312 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2313 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2314 CoTaskMemFree(folderPath
);
2316 /* verify sub folder */
2317 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2318 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2319 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
2320 CoTaskMemFree(folderPath
);
2323 /* create sub folder in Temp\Example2 */
2324 bRes
= CreateDirectoryW(sSubFolder2Path
, NULL
);
2325 ok(bRes
, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path
));
2327 /* do that same redirection, but try to exclude sub-folder */
2328 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, 0, sExample2Path
, 1, &subFolderId
, &errorMsg
);
2329 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2332 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2333 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2334 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
2335 CoTaskMemFree(folderPath
);
2337 /* 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 */
2338 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2339 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2340 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
2341 CoTaskMemFree(folderPath
);
2343 /* remove newly created directory */
2344 RemoveDirectoryW(sSubFolder2Path
);
2347 /* set Example path to original */
2348 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
2349 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
2352 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2353 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2354 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2355 CoTaskMemFree(folderPath
);
2357 /* verify sub folder */
2358 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2359 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2360 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
2361 CoTaskMemFree(folderPath
);
2364 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
2365 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
, sExample2Path
, 0, NULL
, &errorMsg
);
2366 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2369 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2370 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2371 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
2372 CoTaskMemFree(folderPath
);
2374 /* verify sub folder */
2375 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2376 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2377 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
2378 CoTaskMemFree(folderPath
);
2380 /* remove copied directory */
2381 RemoveDirectoryW(sSubFolder2Path
);
2384 /* set Example path to original */
2385 hr
= IKnownFolder_SetPath(folder
, 0, sExamplePath
);
2386 ok(hr
== S_OK
, "SetPath() failed: 0x%08x\n", hr
);
2389 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2390 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2391 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2392 CoTaskMemFree(folderPath
);
2394 /* verify sub folder */
2395 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2396 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2397 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
2398 CoTaskMemFree(folderPath
);
2401 /* redirect again, set it to copy content and remove originals */
2402 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
| KF_REDIRECT_DEL_SOURCE_CONTENTS
, sExample2Path
, 0, NULL
, &errorMsg
);
2403 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2406 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2407 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2408 ok(lstrcmpiW(folderPath
, sExample2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExample2Path
));
2409 CoTaskMemFree(folderPath
);
2411 /* verify sub folder */
2412 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2413 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2414 ok(lstrcmpiW(folderPath
, sSubFolder2Path
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolder2Path
));
2415 CoTaskMemFree(folderPath
);
2417 /* check if original directory was really removed */
2418 dwAttributes
= GetFileAttributesW(sExamplePath
);
2419 ok(dwAttributes
==INVALID_FILE_ATTRIBUTES
, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes
);
2422 /* redirect (with copy) to original path */
2423 hr
= IKnownFolderManager_Redirect(mgr
, &newFolderId
, NULL
, KF_REDIRECT_COPY_CONTENTS
, sExamplePath
, 0, NULL
, &errorMsg
);
2424 ok(hr
== S_OK
, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr
, wine_dbgstr_w(errorMsg
));
2427 hr
= IKnownFolder_GetPath(folder
, 0, &folderPath
);
2428 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2429 ok(lstrcmpiW(folderPath
, sExamplePath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sExamplePath
));
2430 CoTaskMemFree(folderPath
);
2432 /* verify sub folder */
2433 hr
= IKnownFolder_GetPath(subFolder
, 0, &folderPath
);
2434 ok(hr
== S_OK
, "failed to get known folder path: 0x%08x\n", hr
);
2435 ok(lstrcmpiW(folderPath
, sSubFolderPath
)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath
), wine_dbgstr_w(sSubFolderPath
));
2436 CoTaskMemFree(folderPath
);
2438 /* check shell utility functions */
2439 if(!pSHGetKnownFolderPath
|| !pSHSetKnownFolderPath
)
2441 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
2444 /* try to get current known folder path */
2445 hr
= pSHGetKnownFolderPath(&newFolderId
, 0, NULL
, &folderPath
);
2447 ok(hr
==S_OK
, "cannot get known folder path: hr=0x%0x\n", hr
);
2449 ok(lstrcmpW(folderPath
, sExamplePath
)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath
));
2451 /* set it to new value */
2452 hr
= pSHSetKnownFolderPath(&newFolderId
, 0, NULL
, sExample2Path
);
2454 ok(hr
==S_OK
, "cannot set known folder path: hr=0x%0x\n", hr
);
2456 /* check if it changed */
2457 hr
= pSHGetKnownFolderPath(&newFolderId
, 0, NULL
, &folderPath
);
2459 ok(hr
==S_OK
, "cannot get known folder path: hr=0x%0x\n", hr
);
2461 ok(lstrcmpW(folderPath
, sExample2Path
)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath
));
2464 hr
= pSHSetKnownFolderPath(&newFolderId
, 0, NULL
, sExamplePath
);
2466 ok(hr
==S_OK
, "cannot set known folder path: hr=0x%0x\n", hr
);
2469 IKnownFolder_Release(subFolder
);
2472 hr
= IKnownFolderManager_UnregisterFolder(mgr
, &subFolderId
);
2473 ok(hr
== S_OK
, "failed to unregister folder: 0x%08x\n", hr
);
2476 FreeKnownFolderDefinitionFields(&kfSubDefinition
);
2478 hr
= IKnownFolder_Release(folder
);
2479 ok(hr
== S_OK
, "failed to release KnownFolder instance: 0x%08x\n", hr
);
2482 hr
= IKnownFolderManager_UnregisterFolder(mgr
, &newFolderId
);
2483 ok(hr
== S_OK
, "failed to unregister folder: 0x%08x\n", hr
);
2486 FreeKnownFolderDefinitionFields(&kfDefinition
);
2488 RemoveDirectoryW(sSubFolder2Path
);
2489 RemoveDirectoryW(sSubFolderPath
);
2490 RemoveDirectoryW(sExamplePath
);
2491 RemoveDirectoryW(sExample2Path
);
2493 hr
= IKnownFolderManager_Release(mgr
);
2494 ok(hr
== S_OK
, "failed to release KnownFolderManager instance: 0x%08x\n", hr
);
2500 static void test_DoEnvironmentSubst(void)
2502 WCHAR expectedW
[MAX_PATH
];
2503 WCHAR bufferW
[MAX_PATH
];
2504 CHAR expectedA
[MAX_PATH
];
2505 CHAR bufferA
[MAX_PATH
];
2510 static const WCHAR does_not_existW
[] = {'%','D','O','E','S','_','N','O','T','_','E','X','I','S','T','%',0};
2511 static const CHAR does_not_existA
[] = "%DOES_NOT_EXIST%";
2512 static const CHAR
*names
[] = {
2513 /* interactive apps and services (works on all windows versions) */
2514 "%ALLUSERSPROFILE%", "%APPDATA%", "%LOCALAPPDATA%",
2515 "%NUMBER_OF_PROCESSORS%", "%OS%", "%PROCESSOR_ARCHITECTURE%",
2516 "%PROCESSOR_IDENTIFIER%", "%PROCESSOR_LEVEL%", "%PROCESSOR_REVISION%",
2517 "%ProgramFiles%", "%SystemDrive%",
2518 "%SystemRoot%", "%USERPROFILE%", "%windir%",
2519 /* todo_wine: "%COMPUTERNAME%", "%ProgramData%", "%PUBLIC%", */
2521 /* replace more than one var is allowed */
2522 "%HOMEDRIVE%%HOMEPATH%",
2523 "%OS% %windir%"}; /* always the last entry in the table */
2525 for (i
= 0; i
< (sizeof(names
)/sizeof(LPSTR
)); i
++)
2527 memset(bufferA
, '#', MAX_PATH
- 1);
2528 bufferA
[MAX_PATH
- 1] = 0;
2529 lstrcpyA(bufferA
, names
[i
]);
2530 MultiByteToWideChar(CP_ACP
, 0, bufferA
, MAX_PATH
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
));
2532 res2
= ExpandEnvironmentStringsA(names
[i
], expectedA
, MAX_PATH
);
2533 res
= DoEnvironmentSubstA(bufferA
, MAX_PATH
);
2535 /* is the space for the terminating 0 included? */
2536 if (!i
&& HIWORD(res
) && (LOWORD(res
) == (lstrlenA(bufferA
))))
2538 win_skip("DoEnvironmentSubstA/W are broken on NT 4\n");
2541 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2542 "%d: got %d/%d (expected TRUE/%d)\n", i
, HIWORD(res
), LOWORD(res
), res2
);
2543 ok(!lstrcmpA(bufferA
, expectedA
),
2544 "%d: got %s (expected %s)\n", i
, bufferA
, expectedA
);
2546 res2
= ExpandEnvironmentStringsW(bufferW
, expectedW
, MAX_PATH
);
2547 res
= DoEnvironmentSubstW(bufferW
, MAX_PATH
);
2548 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2549 "%d: got %d/%d (expected TRUE/%d)\n", i
, HIWORD(res
), LOWORD(res
), res2
);
2550 ok(!lstrcmpW(bufferW
, expectedW
),
2551 "%d: got %s (expected %s)\n", i
, wine_dbgstr_w(bufferW
), wine_dbgstr_w(expectedW
));
2554 i
--; /* reuse data in the last table entry */
2555 len
= LOWORD(res
); /* needed length */
2557 /* one character extra is fine */
2558 memset(bufferA
, '#', MAX_PATH
- 1);
2559 bufferA
[len
+ 2] = 0;
2560 lstrcpyA(bufferA
, names
[i
]);
2561 MultiByteToWideChar(CP_ACP
, 0, bufferA
, MAX_PATH
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
));
2563 res2
= ExpandEnvironmentStringsA(bufferA
, expectedA
, MAX_PATH
);
2564 res
= DoEnvironmentSubstA(bufferA
, len
+ 1);
2565 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2566 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res
), LOWORD(res
), res2
);
2567 ok(!lstrcmpA(bufferA
, expectedA
),
2568 "+1: got %s (expected %s)\n", bufferA
, expectedA
);
2570 res2
= ExpandEnvironmentStringsW(bufferW
, expectedW
, MAX_PATH
);
2571 res
= DoEnvironmentSubstW(bufferW
, len
+ 1);
2572 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2573 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res
), LOWORD(res
), res2
);
2574 ok(!lstrcmpW(bufferW
, expectedW
),
2575 "+1: got %s (expected %s)\n", wine_dbgstr_w(bufferW
), wine_dbgstr_w(expectedW
));
2578 /* minimal buffer length (result string and terminating 0) */
2579 memset(bufferA
, '#', MAX_PATH
- 1);
2580 bufferA
[len
+ 2] = 0;
2581 lstrcpyA(bufferA
, names
[i
]);
2582 MultiByteToWideChar(CP_ACP
, 0, bufferA
, MAX_PATH
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
));
2584 /* ANSI version failed without an extra byte, as documented on msdn */
2585 res
= DoEnvironmentSubstA(bufferA
, len
);
2586 ok(!HIWORD(res
) && (LOWORD(res
) == len
),
2587 " 0: got %d/%d (expected FALSE/%d)\n", HIWORD(res
), LOWORD(res
), len
);
2588 ok(!lstrcmpA(bufferA
, names
[i
]),
2589 " 0: got %s (expected %s)\n", bufferA
, names
[i
]);
2591 /* DoEnvironmentSubstW works as expected */
2592 res2
= ExpandEnvironmentStringsW(bufferW
, expectedW
, MAX_PATH
);
2593 res
= DoEnvironmentSubstW(bufferW
, len
);
2594 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2595 " 0: got %d/%d (expected TRUE/%d)\n", HIWORD(res
), LOWORD(res
), res2
);
2596 ok(!lstrcmpW(bufferW
, expectedW
),
2597 " 0: got %s (expected %s)\n", wine_dbgstr_w(bufferW
), wine_dbgstr_w(expectedW
));
2600 /* Buffer too small */
2601 /* result: FALSE / provided buffer length / the buffer is untouched */
2602 memset(bufferA
, '#', MAX_PATH
- 1);
2603 bufferA
[len
+ 2] = 0;
2604 lstrcpyA(bufferA
, names
[i
]);
2605 MultiByteToWideChar(CP_ACP
, 0, bufferA
, MAX_PATH
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
));
2607 res
= DoEnvironmentSubstA(bufferA
, len
- 1);
2608 ok(!HIWORD(res
) && (LOWORD(res
) == (len
- 1)),
2609 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res
), LOWORD(res
), len
- 1);
2610 ok(!lstrcmpA(bufferA
, names
[i
]),
2611 "-1: got %s (expected %s)\n", bufferA
, names
[i
]);
2613 lstrcpyW(expectedW
, bufferW
);
2614 res
= DoEnvironmentSubstW(bufferW
, len
- 1);
2615 ok(!HIWORD(res
) && (LOWORD(res
) == (len
- 1)),
2616 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res
), LOWORD(res
), len
- 1);
2617 ok(!lstrcmpW(bufferW
, expectedW
),
2618 "-1: got %s (expected %s)\n", wine_dbgstr_w(bufferW
), wine_dbgstr_w(expectedW
));
2621 /* unknown variable */
2622 /* result: TRUE / string length including terminating 0 / the buffer is untouched */
2623 memset(bufferA
, '#', MAX_PATH
- 1);
2624 bufferA
[MAX_PATH
- 1] = 0;
2625 lstrcpyA(bufferA
, does_not_existA
);
2626 MultiByteToWideChar(CP_ACP
, 0, bufferA
, MAX_PATH
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
));
2628 res2
= lstrlenA(does_not_existA
) + 1;
2629 res
= DoEnvironmentSubstA(bufferA
, MAX_PATH
);
2630 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2631 "%d: got %d/%d (expected TRUE/%d)\n", i
, HIWORD(res
), LOWORD(res
), res2
);
2632 ok(!lstrcmpA(bufferA
, does_not_existA
),
2633 "%d: got %s (expected %s)\n", i
, bufferA
, does_not_existA
);
2635 res
= DoEnvironmentSubstW(bufferW
, MAX_PATH
);
2636 ok(HIWORD(res
) && (LOWORD(res
) == res2
),
2637 "%d: got %d/%d (expected TRUE/%d)\n", i
, HIWORD(res
), LOWORD(res
), res2
);
2638 ok(!lstrcmpW(bufferW
, does_not_existW
),
2639 "%d: got %s (expected %s)\n", i
, wine_dbgstr_w(bufferW
), wine_dbgstr_w(does_not_existW
));
2644 /* NULL crashes on windows */
2645 res
= DoEnvironmentSubstA(NULL
, MAX_PATH
);
2646 res
= DoEnvironmentSubstW(NULL
, MAX_PATH
);
2650 START_TEST(shellpath
)
2652 if (!init()) return;
2655 pGetSystemWow64DirectoryA
= (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
2656 "GetSystemWow64DirectoryA" );
2661 /* Report missing functions once */
2662 if (!pSHGetFolderLocation
)
2663 win_skip("SHGetFolderLocation is not available\n");
2665 /* first test various combinations of parameters: */
2668 /* check known values: */
2674 test_NonExistentPath();
2675 test_SHGetFolderPathEx();
2676 test_knownFolders();
2677 test_DoEnvironmentSubst();