shell32: Add support of KF_REDIRECT_COPY_CONTENTS flag to redirection.
[wine/multimedia.git] / dlls / shell32 / tests / shellpath.c
blob0be43f43597fbd280519c72766dd358f6653965c
1 /*
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).
24 #define COBJMACROS
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "shlguid.h"
31 #include "shlobj.h"
32 #include "shlwapi.h"
33 #include "initguid.h"
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
42 #ifndef ARRAY_SIZE
43 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
44 #endif
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 */
49 #endif
50 #ifndef PT_GUID
51 #define PT_GUID 0x1f /* no path */
52 #endif
53 #ifndef PT_DRIVE
54 #define PT_DRIVE 0x23 /* has path */
55 #endif
56 #ifndef PT_DRIVE2
57 #define PT_DRIVE2 0x25 /* has path */
58 #endif
59 #ifndef PT_SHELLEXT
60 #define PT_SHELLEXT 0x2e /* no path */
61 #endif
62 #ifndef PT_FOLDER
63 #define PT_FOLDER 0x31 /* has path */
64 #endif
65 #ifndef PT_FOLDERW
66 #define PT_FOLDERW 0x35 /* has path */
67 #endif
68 #ifndef PT_WORKGRP
69 #define PT_WORKGRP 0x41 /* no path */
70 #endif
71 #ifndef PT_YAGUID
72 #define PT_YAGUID 0x70 /* no path */
73 #endif
74 /* FIXME: this is used for history/favorites folders; what's a better name? */
75 #ifndef PT_IESPECIAL2
76 #define PT_IESPECIAL2 0xb1 /* has path */
77 #endif
79 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
81 struct shellExpectedValues {
82 int folder;
83 int numTypes;
84 const BYTE *types;
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,
90 LPITEMIDLIST *);
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),
182 #undef DECLARE_TYPE
184 static void loadShell32(void)
186 HMODULE hShell32 = GetModuleHandleA("shell32");
188 #define GET_PROC(func) \
189 p ## func = (void*)GetProcAddress(hShell32, #func); \
190 if(!p ## 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)
202 if (!pILFindLastID)
203 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
204 GET_PROC(SHFileOperationA)
205 GET_PROC(SHGetMalloc)
207 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
208 if (pSHGetMalloc)
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");
216 if (pDllGetVersion)
218 shellVersion.cbSize = sizeof(shellVersion);
219 pDllGetVersion(&shellVersion);
220 trace("shell32 version is %d.%d\n",
221 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
223 #undef GET_PROC
226 #ifndef CSIDL_PROFILES
227 #define CSIDL_PROFILES 0x003e
228 #endif
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;
236 switch (folder)
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);
296 #undef CSIDL_TO_STR
297 default:
298 sprintf(unknown, "unknown (0x%04x)", folder);
299 return unknown;
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]);
311 return guidSTR;
314 static void test_parameters(void)
316 LPITEMIDLIST pidl = NULL;
317 char path[MAX_PATH];
318 HRESULT hr;
320 if (pSHGetFolderLocation)
322 /* check a bogus CSIDL: */
323 pidl = NULL;
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: */
329 pidl = NULL;
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)
339 if (0)
340 /* crashes */
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)
360 BOOL ret;
362 if (0)
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)
379 LPITEMIDLIST pidl;
380 HRESULT hr;
381 BYTE ret = 0xff;
383 /* treat absence of function as success */
384 if (!pSHGetFolderLocation) return TRUE;
386 pidl = NULL;
387 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
388 if (hr == S_OK)
390 if (pidl)
392 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
394 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
395 getFolderName(folder));
396 if (pidlLast)
397 ret = pidlLast->mkid.abID[0];
398 IMalloc_Free(pMalloc, pidl);
401 return ret;
404 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
405 static BYTE testSHGetSpecialFolderLocation(int folder)
407 LPITEMIDLIST pidl;
408 HRESULT hr;
409 BYTE ret = 0xff;
411 /* treat absence of function as success */
412 if (!pSHGetSpecialFolderLocation) return TRUE;
414 pidl = NULL;
415 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
416 if (hr == S_OK)
418 if (pidl)
420 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
422 ok(pidlLast != NULL,
423 "%s: ILFindLastID failed\n", getFolderName(folder));
424 if (pidlLast)
425 ret = pidlLast->mkid.abID[0];
426 IMalloc_Free(pMalloc, pidl);
429 return ret;
432 static void test_SHGetFolderPath(BOOL optional, int folder)
434 char path[MAX_PATH];
435 HRESULT hr;
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)
446 char path[MAX_PATH];
447 BOOL ret;
449 if (!pSHGetSpecialFolderPathA) return;
451 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
452 if (ret && winetest_interactive)
453 printf("%s: %s\n", getFolderName(folder), path);
454 ok(ret || optional,
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)
462 int i;
464 for (i = 0; i < numEntries; i++)
466 BYTE type;
467 int j;
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);
488 switch (type)
490 case PT_FOLDER:
491 case PT_DRIVE:
492 case PT_DRIVE2:
493 case PT_IESPECIAL2:
494 test_SHGetFolderPath(optional, testEntries[i].folder);
495 test_SHGetSpecialFolderPath(optional, testEntries[i].folder);
496 break;
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)
510 char path[MAX_PATH];
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)
532 LPITEMIDLIST pidl;
533 HRESULT hr;
535 if (!pSHGetFolderLocation) return;
536 if (!guid) return;
538 pidl = NULL;
539 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
540 if (hr == S_OK)
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];
550 if (!guid_alt)
551 ok(IsEqualIID(shellGuid, guid),
552 "%s: got GUID %s, expected %s\n", getFolderName(folder),
553 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr));
554 else
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)
568 /* Desktop */
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
593 * correspond.
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:\ */
613 return FALSE;
615 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
617 LPSTR szTemp = NULL;
619 if(lpszPath)
621 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
622 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
623 *szTemp = '\0';
625 return 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 */
682 static int myARGC;
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]);
692 return 1;
695 static void doChild(const char *arg)
697 char path[MAX_PATH];
698 HRESULT hr;
700 if (arg[0] == '1')
702 LPITEMIDLIST pidl;
703 char *p;
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);
712 pidl = NULL;
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");
721 pidl = NULL;
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);
732 if (hr == S_OK)
734 BOOL ret;
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");
739 if (!ret)
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");
745 DeleteFileA(path);
746 *p = 0;
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
768 * that was created.
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];
780 HKEY key;
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,
790 &key))
792 DWORD len, type;
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,
817 &startup, &info);
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);
824 RegFlushKey(key);
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,
832 &startup, &info);
833 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
834 "child process termination\n");
837 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
838 if (key)
839 RegCloseKey(key);
841 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
844 static void test_SHGetFolderPathEx(void)
846 HRESULT hr;
847 WCHAR buffer[MAX_PATH], *path;
848 DWORD len;
850 if (!pSHGetKnownFolderPath || !pSHGetFolderPathEx)
852 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
853 return;
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);
860 path = NULL;
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);
869 CoTaskMemFree(path);
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;
897 const int csidl;
898 const char *sCsidl;
899 const int line;
902 static const struct knownFolderDef known_folders[] = {
903 KNOWN_FOLDER(FOLDERID_AddNewPrograms, NO_CSIDL),
904 KNOWN_FOLDER(FOLDERID_AddNewPrograms, NO_CSIDL),
905 KNOWN_FOLDER(FOLDERID_AdminTools, CSIDL_ADMINTOOLS),
906 KNOWN_FOLDER(FOLDERID_AppUpdates, NO_CSIDL),
907 KNOWN_FOLDER(FOLDERID_CDBurning, CSIDL_CDBURN_AREA),
908 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms, NO_CSIDL),
909 KNOWN_FOLDER(FOLDERID_CommonAdminTools, CSIDL_COMMON_ADMINTOOLS),
910 KNOWN_FOLDER(FOLDERID_CommonOEMLinks, CSIDL_COMMON_OEM_LINKS),
911 KNOWN_FOLDER(FOLDERID_CommonPrograms, CSIDL_COMMON_PROGRAMS),
912 KNOWN_FOLDER(FOLDERID_CommonStartMenu, CSIDL_COMMON_STARTMENU),
913 KNOWN_FOLDER(FOLDERID_CommonStartup, CSIDL_COMMON_STARTUP),
914 KNOWN_FOLDER(FOLDERID_CommonTemplates, CSIDL_COMMON_TEMPLATES),
915 KNOWN_FOLDER(FOLDERID_ComputerFolder, CSIDL_DRIVES),
916 KNOWN_FOLDER(FOLDERID_ConflictFolder, NO_CSIDL),
917 KNOWN_FOLDER(FOLDERID_ConnectionsFolder, CSIDL_CONNECTIONS),
918 KNOWN_FOLDER(FOLDERID_Contacts, NO_CSIDL),
919 KNOWN_FOLDER(FOLDERID_ControlPanelFolder, CSIDL_CONTROLS),
920 KNOWN_FOLDER(FOLDERID_Cookies, CSIDL_COOKIES),
921 KNOWN_FOLDER(FOLDERID_Desktop, CSIDL_DESKTOP),
922 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore, NO_CSIDL),
923 KNOWN_FOLDER(FOLDERID_Documents, CSIDL_MYDOCUMENTS | CSIDL_TODO_WINE),
924 KNOWN_FOLDER(FOLDERID_DocumentsLibrary, NO_CSIDL),
925 KNOWN_FOLDER(FOLDERID_Downloads, NO_CSIDL),
926 KNOWN_FOLDER(FOLDERID_Favorites, CSIDL_FAVORITES),
927 KNOWN_FOLDER(FOLDERID_Fonts, CSIDL_FONTS),
928 KNOWN_FOLDER(FOLDERID_Games, NO_CSIDL),
929 KNOWN_FOLDER(FOLDERID_GameTasks, NO_CSIDL),
930 KNOWN_FOLDER(FOLDERID_History, CSIDL_HISTORY),
931 KNOWN_FOLDER(FOLDERID_HomeGroup, NO_CSIDL),
932 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts, NO_CSIDL),
933 KNOWN_FOLDER(FOLDERID_InternetCache, CSIDL_INTERNET_CACHE),
934 KNOWN_FOLDER(FOLDERID_InternetFolder, CSIDL_INTERNET),
935 KNOWN_FOLDER(FOLDERID_Libraries, NO_CSIDL),
936 KNOWN_FOLDER(FOLDERID_Links, NO_CSIDL),
937 KNOWN_FOLDER(FOLDERID_LocalAppData, CSIDL_LOCAL_APPDATA),
938 KNOWN_FOLDER(FOLDERID_LocalAppDataLow, NO_CSIDL),
939 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir, CSIDL_RESOURCES_LOCALIZED),
940 KNOWN_FOLDER(FOLDERID_Music, CSIDL_MYMUSIC),
941 KNOWN_FOLDER(FOLDERID_MusicLibrary, NO_CSIDL),
942 KNOWN_FOLDER(FOLDERID_NetHood, CSIDL_NETHOOD),
943 KNOWN_FOLDER(FOLDERID_NetworkFolder, CSIDL_NETWORK),
944 KNOWN_FOLDER(FOLDERID_OriginalImages, NO_CSIDL),
945 KNOWN_FOLDER(FOLDERID_PhotoAlbums, NO_CSIDL),
946 KNOWN_FOLDER(FOLDERID_Pictures, CSIDL_MYPICTURES),
947 KNOWN_FOLDER(FOLDERID_PicturesLibrary, NO_CSIDL),
948 KNOWN_FOLDER(FOLDERID_Playlists, NO_CSIDL),
949 KNOWN_FOLDER(FOLDERID_PrintersFolder, CSIDL_PRINTERS),
950 KNOWN_FOLDER(FOLDERID_PrintHood, CSIDL_PRINTHOOD),
951 KNOWN_FOLDER(FOLDERID_Profile, CSIDL_PROFILE),
952 KNOWN_FOLDER(FOLDERID_ProgramData, CSIDL_COMMON_APPDATA),
953 KNOWN_FOLDER(FOLDERID_ProgramFiles, CSIDL_PROGRAM_FILES),
954 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon, CSIDL_PROGRAM_FILES_COMMON),
955 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86, NO_CSIDL),
956 KNOWN_FOLDER(FOLDERID_ProgramFilesX86, CSIDL_PROGRAM_FILESX86),
957 KNOWN_FOLDER(FOLDERID_Programs, CSIDL_PROGRAMS),
958 KNOWN_FOLDER(FOLDERID_Public, NO_CSIDL),
959 KNOWN_FOLDER(FOLDERID_PublicDesktop, CSIDL_COMMON_DESKTOPDIRECTORY),
960 KNOWN_FOLDER(FOLDERID_PublicDocuments, CSIDL_COMMON_DOCUMENTS),
961 KNOWN_FOLDER(FOLDERID_PublicDownloads, NO_CSIDL),
962 KNOWN_FOLDER(FOLDERID_PublicGameTasks, NO_CSIDL),
963 KNOWN_FOLDER(FOLDERID_PublicLibraries, NO_CSIDL),
964 KNOWN_FOLDER(FOLDERID_PublicMusic, CSIDL_COMMON_MUSIC),
965 KNOWN_FOLDER(FOLDERID_PublicPictures, CSIDL_COMMON_PICTURES),
966 KNOWN_FOLDER(FOLDERID_PublicRingtones, NO_CSIDL),
967 KNOWN_FOLDER(FOLDERID_PublicVideos, CSIDL_COMMON_VIDEO),
968 KNOWN_FOLDER(FOLDERID_QuickLaunch, NO_CSIDL),
969 KNOWN_FOLDER(FOLDERID_Recent, CSIDL_RECENT),
970 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary, NO_CSIDL),
971 KNOWN_FOLDER(FOLDERID_RecycleBinFolder, CSIDL_BITBUCKET),
972 KNOWN_FOLDER(FOLDERID_ResourceDir, CSIDL_RESOURCES),
973 KNOWN_FOLDER(FOLDERID_Ringtones, NO_CSIDL),
974 KNOWN_FOLDER(FOLDERID_RoamingAppData, CSIDL_APPDATA),
975 KNOWN_FOLDER(FOLDERID_SampleMusic, NO_CSIDL),
976 KNOWN_FOLDER(FOLDERID_SamplePictures, NO_CSIDL),
977 KNOWN_FOLDER(FOLDERID_SamplePlaylists, NO_CSIDL),
978 KNOWN_FOLDER(FOLDERID_SampleVideos, NO_CSIDL),
979 KNOWN_FOLDER(FOLDERID_SavedGames, NO_CSIDL),
980 KNOWN_FOLDER(FOLDERID_SavedSearches, NO_CSIDL),
981 KNOWN_FOLDER(FOLDERID_SEARCH_CSC, NO_CSIDL),
982 KNOWN_FOLDER(FOLDERID_SearchHome, NO_CSIDL),
983 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI, NO_CSIDL),
984 KNOWN_FOLDER(FOLDERID_SendTo, CSIDL_SENDTO),
985 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts, NO_CSIDL),
986 KNOWN_FOLDER(FOLDERID_SidebarParts, NO_CSIDL),
987 KNOWN_FOLDER(FOLDERID_StartMenu, CSIDL_STARTMENU),
988 KNOWN_FOLDER(FOLDERID_Startup, CSIDL_STARTUP),
989 KNOWN_FOLDER(FOLDERID_SyncManagerFolder, NO_CSIDL),
990 KNOWN_FOLDER(FOLDERID_SyncResultsFolder, NO_CSIDL),
991 KNOWN_FOLDER(FOLDERID_SyncSetupFolder, NO_CSIDL),
992 KNOWN_FOLDER(FOLDERID_System, CSIDL_SYSTEM),
993 KNOWN_FOLDER(FOLDERID_SystemX86, CSIDL_SYSTEMX86),
994 KNOWN_FOLDER(FOLDERID_Templates, CSIDL_TEMPLATES),
995 KNOWN_FOLDER(FOLDERID_UserPinned, NO_CSIDL),
996 KNOWN_FOLDER(FOLDERID_UserProfiles, NO_CSIDL),
997 KNOWN_FOLDER(FOLDERID_UserProgramFiles, NO_CSIDL),
998 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon, NO_CSIDL),
999 KNOWN_FOLDER(FOLDERID_UsersFiles, NO_CSIDL),
1000 KNOWN_FOLDER(FOLDERID_UsersLibraries, NO_CSIDL),
1001 KNOWN_FOLDER(FOLDERID_Videos, CSIDL_MYVIDEO),
1002 KNOWN_FOLDER(FOLDERID_VideosLibrary, NO_CSIDL),
1003 KNOWN_FOLDER(FOLDERID_Windows, CSIDL_WINDOWS),
1004 { NULL, NULL, 0, NULL }
1006 #undef KNOWN_FOLDER
1008 static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId)
1010 HRESULT hr;
1011 const struct knownFolderDef *known_folder = &known_folders[0];
1012 int csidl, expectedCsidl;
1014 while(known_folder->folderId != NULL)
1016 if(IsEqualGUID(known_folder->folderId, folderId))
1018 /* verify CSIDL */
1019 if(known_folder->csidl != NO_CSIDL)
1021 expectedCsidl = known_folder->csidl & (~CSIDL_TODO_WINE);
1023 hr = IKnownFolderManager_FolderIdToCsidl(mgr, folderId, &csidl);
1024 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot retrieve CSIDL for folder %s\n", known_folder->sFolderId);
1026 if(known_folder->csidl & CSIDL_TODO_WINE)
1027 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 else
1029 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);
1032 break;
1034 known_folder++;
1037 #undef NO_CSIDL
1038 #undef CSIDL_TODO_WINE
1040 static void test_knownFolders(void)
1042 static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
1043 static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
1044 static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
1045 static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
1046 static const WCHAR sBackslash[] = {'\\',0};
1047 static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
1048 static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
1049 HRESULT hr;
1050 IKnownFolderManager *mgr = NULL;
1051 IKnownFolder *folder = NULL, *subFolder = NULL;
1052 KNOWNFOLDERID folderId, *folders;
1053 KF_CATEGORY cat = 0;
1054 KNOWNFOLDER_DEFINITION kfDefinition, kfSubDefinition;
1055 int csidl, i;
1056 UINT nCount = 0;
1057 LPWSTR folderPath, errorMsg;
1058 KF_REDIRECTION_CAPABILITIES redirectionCapabilities = 1;
1059 WCHAR sWinDir[MAX_PATH], sExamplePath[MAX_PATH], sExample2Path[MAX_PATH], sSubFolderPath[MAX_PATH], sSubFolder2Path[MAX_PATH];
1060 BOOL bRes;
1061 DWORD dwAttributes;
1063 GetWindowsDirectoryW( sWinDir, MAX_PATH );
1065 GetTempPathW(sizeof(sExamplePath)/sizeof(sExamplePath[0]), sExamplePath);
1066 lstrcatW(sExamplePath, sExample);
1068 GetTempPathW(sizeof(sExample2Path)/sizeof(sExample2Path[0]), sExample2Path);
1069 lstrcatW(sExample2Path, sExample2);
1071 lstrcpyW(sSubFolderPath, sExamplePath);
1072 lstrcatW(sSubFolderPath, sBackslash);
1073 lstrcatW(sSubFolderPath, sSubFolder);
1075 lstrcpyW(sSubFolder2Path, sExample2Path);
1076 lstrcatW(sSubFolder2Path, sBackslash);
1077 lstrcatW(sSubFolder2Path, sSubFolder);
1079 CoInitialize(NULL);
1081 hr = CoCreateInstance(&CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER,
1082 &IID_IKnownFolderManager, (LPVOID*)&mgr);
1083 if(hr == REGDB_E_CLASSNOTREG)
1084 win_skip("IKnownFolderManager unavailable\n");
1085 else
1087 ok(hr == S_OK, "failed to create KnownFolderManager instance: 0x%08x\n", hr);
1089 hr = IKnownFolderManager_FolderIdFromCsidl(mgr, CSIDL_WINDOWS, &folderId);
1090 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
1091 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1093 hr = IKnownFolderManager_FolderIdToCsidl(mgr, &FOLDERID_Windows, &csidl);
1094 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
1095 ok(csidl == CSIDL_WINDOWS, "invalid CSIDL returned\n");
1097 hr = IKnownFolderManager_GetFolder(mgr, &FOLDERID_Windows, &folder);
1098 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1099 if(SUCCEEDED(hr))
1101 hr = IKnownFolder_GetCategory(folder, &cat);
1102 todo_wine
1103 ok(hr == S_OK, "failed to get folder category: 0x%08x\n", hr);
1104 todo_wine
1105 ok(cat==KF_CATEGORY_FIXED, "invalid folder category: %d\n", cat);
1107 hr = IKnownFolder_GetId(folder, &folderId);
1108 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1109 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1111 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1112 ok(lstrcmpiW(sWinDir, folderPath)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sWinDir));
1113 CoTaskMemFree(folderPath);
1115 hr = IKnownFolder_GetRedirectionCapabilities(folder, &redirectionCapabilities);
1116 todo_wine
1117 ok(hr == S_OK, "failed to get redirection capabilities: 0x%08x\n", hr);
1118 todo_wine
1119 ok(redirectionCapabilities==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities);
1121 hr = IKnownFolder_SetPath(folder, 0, sWinDir);
1122 todo_wine
1123 ok(hr == E_INVALIDARG, "unexpected value from SetPath: 0x%08x\n", hr);
1125 hr = IKnownFolder_GetFolderDefinition(folder, &kfDefinition);
1126 todo_wine
1127 ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
1128 if(SUCCEEDED(hr))
1130 todo_wine
1131 ok(kfDefinition.category==KF_CATEGORY_FIXED, "invalid folder category: 0x%08x\n", kfDefinition.category);
1132 todo_wine
1133 ok(lstrcmpW(kfDefinition.pszName, sWindows)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition.pszName));
1134 todo_wine
1135 ok(kfDefinition.dwAttributes==0, "invalid folder attributes: %d\n", kfDefinition.dwAttributes);
1136 FreeKnownFolderDefinitionFields(&kfDefinition);
1139 hr = IKnownFolder_Release(folder);
1140 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1143 hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
1144 todo_wine
1145 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1146 if(SUCCEEDED(hr))
1148 hr = IKnownFolder_GetId(folder, &folderId);
1149 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1150 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1152 hr = IKnownFolder_Release(folder);
1153 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1156 hr = IKnownFolderManager_GetFolderIds(mgr, &folders, &nCount);
1157 ok(hr == S_OK, "failed to get known folders: 0x%08x\n", hr);
1158 for(i=0;i<nCount;++i)
1159 check_known_folder(mgr, &folders[i]);
1161 CoTaskMemFree(folders);
1163 /* test of registering new known folders */
1164 bRes = CreateDirectoryW(sExamplePath, NULL);
1165 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath));
1166 bRes = CreateDirectoryW(sExample2Path, NULL);
1167 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path));
1168 bRes = CreateDirectoryW(sSubFolderPath, NULL);
1169 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath));
1171 ZeroMemory(&kfDefinition, sizeof(kfDefinition));
1172 kfDefinition.category = KF_CATEGORY_PERUSER;
1173 kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample));
1174 lstrcpyW(kfDefinition.pszName, sExample);
1175 kfDefinition.pszDescription = CoTaskMemAlloc(sizeof(sExample));
1176 lstrcpyW(kfDefinition.pszDescription, sExample);
1177 kfDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sExamplePath));
1178 lstrcpyW(kfDefinition.pszRelativePath, sExamplePath);
1180 hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
1181 if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
1182 win_skip("No permissions required to register custom known folder\n");
1183 else
1185 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
1186 if(SUCCEEDED(hr))
1188 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
1189 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1190 if(SUCCEEDED(hr))
1192 hr = IKnownFolder_GetCategory(folder, &cat);
1193 ok(hr == S_OK, "failed to get folder category: hr=0x%0x\n", hr);
1194 ok(cat == KF_CATEGORY_PERUSER, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat, KF_CATEGORY_PERUSER);
1196 hr = IKnownFolder_GetId(folder, &folderId);
1197 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1198 ok(IsEqualGUID(&folderId, &newFolderId)==TRUE, "invalid KNOWNFOLDERID returned\n");
1200 /* current path should be Temp\Example */
1201 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1202 ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
1203 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1204 CoTaskMemFree(folderPath);
1206 /* register sub-folder and mark it as child of Example folder */
1207 ZeroMemory(&kfSubDefinition, sizeof(kfSubDefinition));
1208 kfSubDefinition.category = KF_CATEGORY_PERUSER;
1209 kfSubDefinition.pszName = CoTaskMemAlloc(sizeof(sSubFolder));
1210 lstrcpyW(kfSubDefinition.pszName, sSubFolder);
1211 kfSubDefinition.pszDescription = CoTaskMemAlloc(sizeof(sSubFolder));
1212 lstrcpyW(kfSubDefinition.pszDescription, sSubFolder);
1213 kfSubDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sSubFolder));
1214 lstrcpyW(kfSubDefinition.pszRelativePath, sSubFolder);
1215 kfSubDefinition.fidParent = newFolderId;
1217 hr = IKnownFolderManager_RegisterFolder(mgr, &subFolderId, &kfSubDefinition);
1218 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
1219 if(SUCCEEDED(hr))
1222 hr = IKnownFolderManager_GetFolder(mgr, &subFolderId, &subFolder);
1223 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1224 if(SUCCEEDED(hr))
1226 /* check sub folder path */
1227 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1228 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1229 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1230 CoTaskMemFree(folderPath);
1233 /* try to redirect Example to Temp\Example2 */
1234 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
1235 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1237 /* verify */
1238 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1239 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1240 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1241 CoTaskMemFree(folderPath);
1243 /* verify sub folder - it should fail now, as we redirected it's parent folder, but we have no sub folder in new location */
1244 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1245 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "unexpected value from GetPath(): 0x%08x\n", hr);
1246 ok(folderPath==NULL, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath));
1247 CoTaskMemFree(folderPath);
1250 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
1251 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1252 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1254 /* verify */
1255 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1256 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1257 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1258 CoTaskMemFree(folderPath);
1261 /* create sub folder in Temp\Example2 */
1262 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
1263 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
1265 /* again perform that same redirection */
1266 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
1267 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1269 /* verify sub folder. It should succeed now, as the required sub folder exists */
1270 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1271 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1272 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1273 CoTaskMemFree(folderPath);
1275 /* remove newly created directory */
1276 RemoveDirectoryW(sSubFolder2Path);
1278 /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
1279 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1280 todo_wine
1281 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1282 todo_wine
1283 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1284 CoTaskMemFree(folderPath);
1287 /* set Example path to original */
1288 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1289 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1291 /* verify */
1292 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1293 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1294 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1295 CoTaskMemFree(folderPath);
1297 /* verify sub folder */
1298 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1299 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1300 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1301 CoTaskMemFree(folderPath);
1304 /* create sub folder in Temp\Example2 */
1305 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
1306 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
1308 /* do that same redirection, but try to exclude sub-folder */
1309 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 1, &subFolderId, &errorMsg);
1310 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1312 /* verify */
1313 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1314 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1315 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1316 CoTaskMemFree(folderPath);
1318 /* 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 */
1319 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1320 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1321 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1322 CoTaskMemFree(folderPath);
1324 /* remove newly created directory */
1325 RemoveDirectoryW(sSubFolder2Path);
1328 /* set Example path to original */
1329 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1330 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1332 /* verify */
1333 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1334 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1335 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1336 CoTaskMemFree(folderPath);
1338 /* verify sub folder */
1339 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1340 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1341 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1342 CoTaskMemFree(folderPath);
1345 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
1346 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
1347 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1349 /* verify */
1350 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1351 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1352 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1353 CoTaskMemFree(folderPath);
1355 /* verify sub folder */
1356 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1357 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1358 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1359 CoTaskMemFree(folderPath);
1361 /* remove copied directory */
1362 RemoveDirectoryW(sSubFolder2Path);
1365 /* set Example path to original */
1366 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1367 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1369 /* verify */
1370 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1371 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1372 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1373 CoTaskMemFree(folderPath);
1375 /* verify sub folder */
1376 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1377 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1378 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1379 CoTaskMemFree(folderPath);
1382 /* redirect again, set it to copy content and remove originals */
1383 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS | KF_REDIRECT_DEL_SOURCE_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
1384 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1386 /* verify */
1387 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1388 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1389 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1390 CoTaskMemFree(folderPath);
1392 /* verify sub folder */
1393 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1394 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1395 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1396 CoTaskMemFree(folderPath);
1398 /* check if original directory was really removed */
1399 dwAttributes = GetFileAttributesW(sExamplePath);
1400 todo_wine
1401 ok(dwAttributes==INVALID_FILE_ATTRIBUTES, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes );
1404 /* redirect (with copy) to original path */
1405 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExamplePath, 0, NULL, &errorMsg);
1406 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1408 /* verify */
1409 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1410 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1411 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1412 CoTaskMemFree(folderPath);
1414 /* verify sub folder */
1415 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1416 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1417 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1418 CoTaskMemFree(folderPath);
1420 /* check shell utility functions */
1421 if(!pSHGetKnownFolderPath || !pSHSetKnownFolderPath)
1422 todo_wine
1423 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
1424 else
1426 /* try to get current known folder path */
1427 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
1428 todo_wine
1429 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
1430 todo_wine
1431 ok(lstrcmpW(folderPath, sExamplePath)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
1433 /* set it to new value */
1434 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExample2Path);
1435 todo_wine
1436 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
1438 /* check if it changed */
1439 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
1440 todo_wine
1441 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
1442 todo_wine
1443 ok(lstrcmpW(folderPath, sExample2Path)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
1445 /* set it back */
1446 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExamplePath);
1447 todo_wine
1448 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
1451 IKnownFolder_Release(subFolder);
1454 hr = IKnownFolderManager_UnregisterFolder(mgr, &subFolderId);
1455 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
1458 FreeKnownFolderDefinitionFields(&kfSubDefinition);
1460 hr = IKnownFolder_Release(folder);
1461 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1464 hr = IKnownFolderManager_UnregisterFolder(mgr, &newFolderId);
1465 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
1468 FreeKnownFolderDefinitionFields(&kfDefinition);
1470 RemoveDirectoryW(sSubFolder2Path);
1471 RemoveDirectoryW(sSubFolderPath);
1472 RemoveDirectoryW(sExamplePath);
1473 RemoveDirectoryW(sExample2Path);
1475 hr = IKnownFolderManager_Release(mgr);
1476 ok(hr == S_OK, "failed to release KnownFolderManager instance: 0x%08x\n", hr);
1478 CoUninitialize();
1481 START_TEST(shellpath)
1483 if (!init()) return;
1485 loadShell32();
1486 pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
1487 "GetSystemWow64DirectoryA" );
1488 if (myARGC >= 3)
1489 doChild(myARGV[2]);
1490 else
1492 /* Report missing functions once */
1493 if (!pSHGetFolderLocation)
1494 win_skip("SHGetFolderLocation is not available\n");
1496 /* first test various combinations of parameters: */
1497 test_parameters();
1499 /* check known values: */
1500 test_PidlTypes();
1501 test_GUIDs();
1502 test_EnvVars();
1503 testWinDir();
1504 testSystemDir();
1505 test_NonExistentPath();
1506 test_SHGetFolderPathEx();
1507 test_knownFolders();