ole32: Specify the PSFactoryBuffer class in the idl files.
[wine] / dlls / shell32 / tests / shellpath.c
1 /*
2  * Unit tests for shell32 SHGet{Special}Folder{Path|Location} functions.
3  *
4  * Copyright 2004 Juan Lang
5  *
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.
10  *
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.
15  *
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).
22  */
23
24 #define COBJMACROS
25
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"
36
37 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
38  * here is its original value.
39  */
40 #define OLD_CSIDL_MYDOCUMENTS  0x000c
41
42 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
43
44 #ifndef ARRAY_SIZE
45 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
46 #endif
47
48 /* from pidl.h, not included here: */
49 #ifndef PT_CPL             /* Guess, Win7 uses this for CSIDL_CONTROLS */
50 #define PT_CPL        0x01 /* no path */
51 #endif
52 #ifndef PT_GUID
53 #define PT_GUID       0x1f /* no path */
54 #endif
55 #ifndef PT_DRIVE 
56 #define PT_DRIVE      0x23 /* has path */
57 #endif
58 #ifndef PT_DRIVE2
59 #define PT_DRIVE2     0x25 /* has path */
60 #endif
61 #ifndef PT_SHELLEXT
62 #define PT_SHELLEXT   0x2e /* no path */
63 #endif
64 #ifndef PT_FOLDER
65 #define PT_FOLDER     0x31 /* has path */
66 #endif
67 #ifndef PT_FOLDERW
68 #define PT_FOLDERW    0x35 /* has path */
69 #endif
70 #ifndef PT_WORKGRP
71 #define PT_WORKGRP    0x41 /* no path */
72 #endif
73 #ifndef PT_YAGUID
74 #define PT_YAGUID     0x70 /* no path */
75 #endif
76 /* FIXME: this is used for history/favorites folders; what's a better name? */
77 #ifndef PT_IESPECIAL2
78 #define PT_IESPECIAL2 0xb1 /* has path */
79 #endif
80
81 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
82
83 struct shellExpectedValues {
84     int folder;
85     int numTypes;
86     const BYTE *types;
87 };
88
89 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
90 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
91 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
92  LPITEMIDLIST *);
93 static BOOL    (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
94 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
95 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
96 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
97 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
98 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR,UINT);
99 static HRESULT (WINAPI *pSHGetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *);
100 static HRESULT (WINAPI *pSHSetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR);
101 static HRESULT (WINAPI *pSHGetFolderPathEx)(REFKNOWNFOLDERID, DWORD, HANDLE, LPWSTR, DWORD);
102
103 static DLLVERSIONINFO shellVersion = { 0 };
104 static LPMALLOC pMalloc;
105 static const BYTE guidType[] = { PT_GUID };
106 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID, PT_CPL };
107 static const BYTE folderType[] = { PT_FOLDER, PT_FOLDERW };
108 static const BYTE favoritesType[] = { PT_FOLDER, PT_FOLDERW, 0, PT_IESPECIAL2 /* Win98 */ };
109 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
110 static const BYTE personalType[] = { PT_FOLDER, PT_GUID, PT_DRIVE, 0xff /* Win9x */,
111  PT_IESPECIAL2 /* Win98 */, 0 /* Vista */ };
112 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
113 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
114 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
115 static const BYTE shellExtType[] = { PT_SHELLEXT };
116 static const BYTE workgroupType[] = { PT_WORKGRP };
117 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
118 static const struct shellExpectedValues requiredShellValues[] = {
119  DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
120  DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
121  DECLARE_TYPE(CSIDL_COOKIES, folderType),
122  DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
123  DECLARE_TYPE(CSIDL_DRIVES, guidType),
124  DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
125  DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
126 /* FIXME: the following fails in Wine, returns type PT_FOLDER
127  DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
128  */
129  DECLARE_TYPE(CSIDL_INTERNET, guidType),
130  DECLARE_TYPE(CSIDL_NETHOOD, folderType),
131  DECLARE_TYPE(CSIDL_NETWORK, guidType),
132  DECLARE_TYPE(CSIDL_PERSONAL, personalType),
133  DECLARE_TYPE(CSIDL_PRINTERS, printersType),
134  DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
135  DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
136  DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
137  DECLARE_TYPE(CSIDL_SENDTO, folderType),
138  DECLARE_TYPE(CSIDL_STARTMENU, folderType),
139  DECLARE_TYPE(CSIDL_STARTUP, folderType),
140  DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
141 };
142 static const struct shellExpectedValues optionalShellValues[] = {
143 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
144  DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
145  DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
146  DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
147  */
148 /* Windows NT-only: */
149  DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
150  DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
151  DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
152  DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
153  DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
154  DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
155  DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
156 /* first appearing in shell32 version 4.71: */
157  DECLARE_TYPE(CSIDL_APPDATA, folderType),
158 /* first appearing in shell32 version 4.72: */
159  DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
160 /* first appearing in shell32 version 5.0: */
161  DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
162  DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
163  DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
164  DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
165  DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
166  DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
167  DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
168  DECLARE_TYPE(CSIDL_PROFILE, folderType),
169  DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
170  DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
171  DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
172  DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
173  DECLARE_TYPE(CSIDL_SYSTEM, folderType),
174  DECLARE_TYPE(CSIDL_WINDOWS, folderType),
175 /* first appearing in shell32 6.0: */
176  DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
177  DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
178  DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
179  DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
180  DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
181  DECLARE_TYPE(CSIDL_RESOURCES, folderType),
182  DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
183 };
184 #undef DECLARE_TYPE
185
186 static void loadShell32(void)
187 {
188     HMODULE hShell32 = GetModuleHandleA("shell32");
189
190 #define GET_PROC(func) \
191     p ## func = (void*)GetProcAddress(hShell32, #func); \
192     if(!p ## func) \
193       trace("GetProcAddress(%s) failed\n", #func);
194
195     GET_PROC(DllGetVersion)
196     GET_PROC(SHGetFolderPathA)
197     GET_PROC(SHGetFolderPathEx)
198     GET_PROC(SHGetFolderLocation)
199     GET_PROC(SHGetKnownFolderPath)
200     GET_PROC(SHSetKnownFolderPath)
201     GET_PROC(SHGetSpecialFolderPathA)
202     GET_PROC(SHGetSpecialFolderLocation)
203     GET_PROC(ILFindLastID)
204     if (!pILFindLastID)
205         pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
206     GET_PROC(SHFileOperationA)
207     GET_PROC(SHGetMalloc)
208
209     ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
210     if (pSHGetMalloc)
211     {
212         HRESULT hr = pSHGetMalloc(&pMalloc);
213
214         ok(hr == S_OK, "SHGetMalloc failed: 0x%08x\n", hr);
215         ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
216     }
217
218     if (pDllGetVersion)
219     {
220         shellVersion.cbSize = sizeof(shellVersion);
221         pDllGetVersion(&shellVersion);
222         trace("shell32 version is %d.%d\n",
223               shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
224     }
225 #undef GET_PROC
226 }
227
228 #ifndef CSIDL_PROFILES
229 #define CSIDL_PROFILES          0x003e
230 #endif
231
232 /* A couple utility printing functions */
233 static const char *getFolderName(int folder)
234 {
235     static char unknown[32];
236
237 #define CSIDL_TO_STR(x) case x: return#x;
238     switch (folder)
239     {
240     CSIDL_TO_STR(CSIDL_DESKTOP);
241     CSIDL_TO_STR(CSIDL_INTERNET);
242     CSIDL_TO_STR(CSIDL_PROGRAMS);
243     CSIDL_TO_STR(CSIDL_CONTROLS);
244     CSIDL_TO_STR(CSIDL_PRINTERS);
245     CSIDL_TO_STR(CSIDL_PERSONAL);
246     CSIDL_TO_STR(CSIDL_FAVORITES);
247     CSIDL_TO_STR(CSIDL_STARTUP);
248     CSIDL_TO_STR(CSIDL_RECENT);
249     CSIDL_TO_STR(CSIDL_SENDTO);
250     CSIDL_TO_STR(CSIDL_BITBUCKET);
251     CSIDL_TO_STR(CSIDL_STARTMENU);
252     CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
253     CSIDL_TO_STR(CSIDL_MYMUSIC);
254     CSIDL_TO_STR(CSIDL_MYVIDEO);
255     CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
256     CSIDL_TO_STR(CSIDL_DRIVES);
257     CSIDL_TO_STR(CSIDL_NETWORK);
258     CSIDL_TO_STR(CSIDL_NETHOOD);
259     CSIDL_TO_STR(CSIDL_FONTS);
260     CSIDL_TO_STR(CSIDL_TEMPLATES);
261     CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
262     CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
263     CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
264     CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
265     CSIDL_TO_STR(CSIDL_APPDATA);
266     CSIDL_TO_STR(CSIDL_PRINTHOOD);
267     CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
268     CSIDL_TO_STR(CSIDL_ALTSTARTUP);
269     CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
270     CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
271     CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
272     CSIDL_TO_STR(CSIDL_COOKIES);
273     CSIDL_TO_STR(CSIDL_HISTORY);
274     CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
275     CSIDL_TO_STR(CSIDL_WINDOWS);
276     CSIDL_TO_STR(CSIDL_SYSTEM);
277     CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
278     CSIDL_TO_STR(CSIDL_MYPICTURES);
279     CSIDL_TO_STR(CSIDL_PROFILE);
280     CSIDL_TO_STR(CSIDL_SYSTEMX86);
281     CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
282     CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
283     CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
284     CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
285     CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
286     CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
287     CSIDL_TO_STR(CSIDL_ADMINTOOLS);
288     CSIDL_TO_STR(CSIDL_CONNECTIONS);
289     CSIDL_TO_STR(CSIDL_PROFILES);
290     CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
291     CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
292     CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
293     CSIDL_TO_STR(CSIDL_RESOURCES);
294     CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
295     CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
296     CSIDL_TO_STR(CSIDL_CDBURN_AREA);
297     CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
298 #undef CSIDL_TO_STR
299     default:
300         sprintf(unknown, "unknown (0x%04x)", folder);
301         return unknown;
302     }
303 }
304
305 static const char *printGUID(const GUID *guid, char * guidSTR)
306 {
307     if (!guid) return NULL;
308
309     sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
310      guid->Data1, guid->Data2, guid->Data3,
311      guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
312      guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
313     return guidSTR;
314 }
315
316 static void test_parameters(void)
317 {
318     LPITEMIDLIST pidl = NULL;
319     char path[MAX_PATH];
320     HRESULT hr;
321
322     if (pSHGetFolderLocation)
323     {
324         /* check a bogus CSIDL: */
325         pidl = NULL;
326         hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
327         ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
328         if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
329
330         /* check a bogus user token: */
331         pidl = NULL;
332         hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
333         ok(hr == E_FAIL || hr == E_HANDLE, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
334         if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
335
336         /* a NULL pidl pointer crashes, so don't test it */
337     }
338
339     if (pSHGetSpecialFolderLocation)
340     {
341         if (0)
342             /* crashes */
343             SHGetSpecialFolderLocation(NULL, 0, NULL);
344
345         hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
346         ok(hr == E_INVALIDARG, "got returned 0x%08x\n", hr);
347     }
348
349     if (pSHGetFolderPathA)
350     {
351         /* expect 2's a bogus handle, especially since we didn't open it */
352         hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2, SHGFP_TYPE_DEFAULT, path);
353         ok(hr == E_FAIL || hr == E_HANDLE || /* Vista and 2k8 */
354            broken(hr == S_OK), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr);
355
356         hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
357         ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
358     }
359
360     if (pSHGetSpecialFolderPathA)
361     {
362         BOOL ret;
363
364         if (0)
365            pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
366
367         /* odd but true: calling with a NULL path still succeeds if it's a real
368          * dir (on some windows platform).  on winME it generates exception.
369          */
370         ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
371         ok(ret, "got %d\n", ret);
372
373         ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
374         ok(!ret, "got %d\n", ret);
375     }
376 }
377
378 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
379 static BYTE testSHGetFolderLocation(int folder)
380 {
381     LPITEMIDLIST pidl;
382     HRESULT hr;
383     BYTE ret = 0xff;
384
385     /* treat absence of function as success */
386     if (!pSHGetFolderLocation) return TRUE;
387
388     pidl = NULL;
389     hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
390     if (hr == S_OK)
391     {
392         if (pidl)
393         {
394             LPITEMIDLIST pidlLast = pILFindLastID(pidl);
395
396             ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
397              getFolderName(folder));
398             if (pidlLast)
399                 ret = pidlLast->mkid.abID[0];
400             IMalloc_Free(pMalloc, pidl);
401         }
402     }
403     return ret;
404 }
405
406 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
407 static BYTE testSHGetSpecialFolderLocation(int folder)
408 {
409     LPITEMIDLIST pidl;
410     HRESULT hr;
411     BYTE ret = 0xff;
412
413     /* treat absence of function as success */
414     if (!pSHGetSpecialFolderLocation) return TRUE;
415
416     pidl = NULL;
417     hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
418     if (hr == S_OK)
419     {
420         if (pidl)
421         {
422             LPITEMIDLIST pidlLast = pILFindLastID(pidl);
423
424             ok(pidlLast != NULL,
425                 "%s: ILFindLastID failed\n", getFolderName(folder));
426             if (pidlLast)
427                 ret = pidlLast->mkid.abID[0];
428             IMalloc_Free(pMalloc, pidl);
429         }
430     }
431     return ret;
432 }
433
434 static void test_SHGetFolderPath(BOOL optional, int folder)
435 {
436     char path[MAX_PATH];
437     HRESULT hr;
438
439     if (!pSHGetFolderPathA) return;
440
441     hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
442     ok(hr == S_OK || optional,
443      "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
444 }
445
446 static void test_SHGetSpecialFolderPath(BOOL optional, int folder)
447 {
448     char path[MAX_PATH];
449     BOOL ret;
450
451     if (!pSHGetSpecialFolderPathA) return;
452
453     ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
454     if (ret && winetest_interactive)
455         printf("%s: %s\n", getFolderName(folder), path);
456     ok(ret || optional,
457      "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
458      getFolderName(folder));
459 }
460
461 static void test_ShellValues(const struct shellExpectedValues testEntries[],
462  int numEntries, BOOL optional)
463 {
464     int i;
465
466     for (i = 0; i < numEntries; i++)
467     {
468         BYTE type;
469         int j;
470         BOOL foundTypeMatch = FALSE;
471
472         if (pSHGetFolderLocation)
473         {
474             type = testSHGetFolderLocation(testEntries[i].folder);
475             for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
476                 if (testEntries[i].types[j] == type)
477                     foundTypeMatch = TRUE;
478             ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
479              "%s has unexpected type %d (0x%02x)\n",
480              getFolderName(testEntries[i].folder), type, type);
481         }
482         type = testSHGetSpecialFolderLocation(testEntries[i].folder);
483         for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
484          j < testEntries[i].numTypes; j++)
485             if (testEntries[i].types[j] == type)
486                 foundTypeMatch = TRUE;
487         ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
488          "%s has unexpected type %d (0x%02x)\n",
489          getFolderName(testEntries[i].folder), type, type);
490         switch (type)
491         {
492             case PT_FOLDER:
493             case PT_DRIVE:
494             case PT_DRIVE2:
495             case PT_IESPECIAL2:
496                 test_SHGetFolderPath(optional, testEntries[i].folder);
497                 test_SHGetSpecialFolderPath(optional, testEntries[i].folder);
498                 break;
499         }
500     }
501 }
502
503 /* Attempts to verify that the folder path corresponding to the folder CSIDL
504  * value has the same value as the environment variable with name envVar.
505  * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
506  * set in this environment; different OS and shell version behave differently.
507  * However, if both are present, fails if envVar's value is not the same
508  * (byte-for-byte) as what SHGetSpecialFolderPath returns.
509  */
510 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
511 {
512     char path[MAX_PATH];
513
514     if (!pSHGetSpecialFolderPathA) return;
515
516     if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
517     {
518         char *envVal = getenv(envVar);
519
520         ok(!envVal || !lstrcmpiA(envVal, path),
521          "%%%s%% does not match SHGetSpecialFolderPath:\n"
522          "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
523          envVar, envVar, envVal, path);
524     }
525 }
526
527 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
528  * GUID.  Assumes the type of the returned PIDL is in fact a GUID, but doesn't
529  * fail if it isn't--that check should already have been done.
530  * Fails if the returned PIDL is a GUID whose value does not match guid.
531  */
532 static void matchGUID(int folder, const GUID *guid, const GUID *guid_alt)
533 {
534     LPITEMIDLIST pidl;
535     HRESULT hr;
536
537     if (!pSHGetFolderLocation) return;
538     if (!guid) return;
539
540     pidl = NULL;
541     hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
542     if (hr == S_OK)
543     {
544         LPITEMIDLIST pidlLast = pILFindLastID(pidl);
545
546         if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
547          pidlLast->mkid.abID[0] == PT_GUID))
548         {
549             GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
550             char shellGuidStr[39], guidStr[39], guid_altStr[39];
551
552             if (!guid_alt)
553              ok(IsEqualIID(shellGuid, guid),
554               "%s: got GUID %s, expected %s\n", getFolderName(folder),
555               printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr));
556             else
557              ok(IsEqualIID(shellGuid, guid) ||
558               IsEqualIID(shellGuid, guid_alt),
559               "%s: got GUID %s, expected %s or %s\n", getFolderName(folder),
560               printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr),
561               printGUID(guid_alt, guid_altStr));
562         }
563         IMalloc_Free(pMalloc, pidl);
564     }
565 }
566
567 /* Checks the PIDL type of all the known values. */
568 static void test_PidlTypes(void)
569 {
570     /* Desktop */
571     test_SHGetFolderPath(FALSE, CSIDL_DESKTOP);
572     test_SHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
573
574     test_ShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues), FALSE);
575     test_ShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues), TRUE);
576 }
577
578 /* FIXME: Should be in shobjidl.idl */
579 DEFINE_GUID(CLSID_NetworkExplorerFolder, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
580
581 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
582 static void test_GUIDs(void)
583 {
584     matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin, NULL);
585     matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel, NULL);
586     matchGUID(CSIDL_DRIVES, &CLSID_MyComputer, NULL);
587     matchGUID(CSIDL_INTERNET, &CLSID_Internet, NULL);
588     matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces, &CLSID_NetworkExplorerFolder); /* Vista and higher */
589     matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments, NULL);
590     matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments, NULL);
591     matchGUID(CSIDL_PRINTERS, &CLSID_Printers, NULL);
592 }
593
594 /* Verifies various shell paths match the environment variables to which they
595  * correspond.
596  */
597 static void test_EnvVars(void)
598 {
599     matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
600     matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
601     matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
602     matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
603     matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
604     matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON, "CommonProgramFiles");
605     /* this is only set on Wine, but can't hurt to verify it: */
606     matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
607 }
608
609 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
610 static BOOL myPathIsRootA(LPCSTR lpszPath)
611 {
612   if (lpszPath && *lpszPath &&
613       lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
614       return TRUE; /* X:\ */
615   return FALSE;
616 }
617 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
618 {
619   LPSTR szTemp = NULL;
620
621   if(lpszPath)
622   {
623     szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
624     if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
625       *szTemp = '\0';
626   }
627   return szTemp;
628 }
629
630 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
631  * GetWindowsDirectory.  If SHGetSpecialFolderPath fails, no harm, no foul--not
632  * every shell32 version supports CSIDL_WINDOWS.
633  */
634 static void testWinDir(void)
635 {
636     char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
637
638     if (!pSHGetSpecialFolderPathA) return;
639
640     if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
641     {
642         myPathRemoveBackslashA(windowsShellPath);
643         GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
644         myPathRemoveBackslashA(windowsDir);
645         ok(!lstrcmpiA(windowsDir, windowsShellPath),
646          "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
647          windowsDir, windowsShellPath);
648     }
649 }
650
651 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
652  * GetSystemDirectory.  If SHGetSpecialFolderPath fails, no harm,
653  * no foul--not every shell32 version supports CSIDL_SYSTEM.
654  */
655 static void testSystemDir(void)
656 {
657     char systemShellPath[MAX_PATH], systemDir[MAX_PATH], systemDirx86[MAX_PATH];
658
659     if (!pSHGetSpecialFolderPathA) return;
660
661     GetSystemDirectoryA(systemDir, sizeof(systemDir));
662     myPathRemoveBackslashA(systemDir);
663     if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
664     {
665         myPathRemoveBackslashA(systemShellPath);
666         ok(!lstrcmpiA(systemDir, systemShellPath),
667          "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
668          systemDir, systemShellPath);
669     }
670
671     if (!pGetSystemWow64DirectoryA || !pGetSystemWow64DirectoryA(systemDirx86, sizeof(systemDirx86)))
672         GetSystemDirectoryA(systemDirx86, sizeof(systemDirx86));
673     myPathRemoveBackslashA(systemDirx86);
674     if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
675     {
676         myPathRemoveBackslashA(systemShellPath);
677         ok(!lstrcmpiA(systemDirx86, systemShellPath) || broken(!lstrcmpiA(systemDir, systemShellPath)),
678          "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
679          systemDir, systemShellPath);
680     }
681 }
682
683 /* Globals used by subprocesses */
684 static int    myARGC;
685 static char **myARGV;
686 static char   base[MAX_PATH];
687 static char   selfname[MAX_PATH];
688
689 static int init(void)
690 {
691     myARGC = winetest_get_mainargs(&myARGV);
692     if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
693     strcpy(selfname, myARGV[0]);
694     return 1;
695 }
696
697 static void doChild(const char *arg)
698 {
699     char path[MAX_PATH];
700     HRESULT hr;
701
702     if (arg[0] == '1')
703     {
704         LPITEMIDLIST pidl;
705         char *p;
706
707         /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
708
709         /* test some failure cases first: */
710         hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path);
711         ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
712             "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
713
714         pidl = NULL;
715         hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0, &pidl);
716         ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
717             "SHGetFolderLocation returned 0x%08x\n", hr);
718         if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
719
720         ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
721             "SHGetSpecialFolderPath succeeded, expected failure\n");
722
723         pidl = NULL;
724         hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
725         ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
726             "SHGetFolderLocation returned 0x%08x\n", hr);
727
728         if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
729
730         /* now test success: */
731         hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
732                                SHGFP_TYPE_CURRENT, path);
733         ok (hr == S_OK, "got 0x%08x\n", hr);
734         if (hr == S_OK)
735         {
736             BOOL ret;
737
738             trace("CSIDL_FAVORITES was changed to %s\n", path);
739             ret = CreateDirectoryA(path, NULL);
740             ok(!ret, "expected failure with ERROR_ALREADY_EXISTS\n");
741             if (!ret)
742                 ok(GetLastError() == ERROR_ALREADY_EXISTS,
743                   "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
744
745             p = path + strlen(path);
746             strcpy(p, "\\desktop.ini");
747             DeleteFileA(path);
748             *p = 0;
749             SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
750             ret = RemoveDirectoryA(path);
751             ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
752         }
753     }
754     else if (arg[0] == '2')
755     {
756         /* make sure SHGetFolderPath still succeeds when the
757            original value of CSIDL_FAVORITES is restored. */
758         hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
759             SHGFP_TYPE_CURRENT, path);
760         ok(hr == S_OK, "SHGetFolderPath failed: 0x%08x\n", hr);
761     }
762 }
763
764 /* Tests the return values from the various shell functions both with and
765  * without the use of the CSIDL_FLAG_CREATE flag.  This flag only appeared in
766  * version 5 of the shell, so don't test unless it's at least version 5.
767  * The test reads a value from the registry, modifies it, calls
768  * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
769  * afterward without it.  Then it restores the registry and deletes the folder
770  * that was created.
771  * One oddity with respect to restoration: shell32 caches somehow, so it needs
772  * to be reloaded in order to see the correct (restored) value.
773  * Some APIs unrelated to the ones under test may fail, but I expect they're
774  * covered by other unit tests; I just print out something about failure to
775  * help trace what's going on.
776  */
777 static void test_NonExistentPath(void)
778 {
779     static const char userShellFolders[] = 
780      "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
781     char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
782     HKEY key;
783
784     if (!pSHGetFolderPathA) return;
785     if (!pSHGetFolderLocation) return;
786     if (!pSHGetSpecialFolderPathA) return;
787     if (!pSHGetSpecialFolderLocation) return;
788     if (!pSHFileOperationA) return;
789     if (shellVersion.dwMajorVersion < 5) return;
790
791     if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
792      &key))
793     {
794         DWORD len, type;
795
796         len = sizeof(originalPath);
797         if (!RegQueryValueExA(key, "Favorites", NULL, &type,
798          (LPBYTE)&originalPath, &len))
799         {
800             size_t len = strlen(originalPath);
801
802             memcpy(modifiedPath, originalPath, len);
803             modifiedPath[len++] = '2';
804             modifiedPath[len++] = '\0';
805             trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
806             if (!RegSetValueExA(key, "Favorites", 0, type,
807              (LPBYTE)modifiedPath, len))
808             {
809                 char buffer[MAX_PATH+20];
810                 STARTUPINFOA startup;
811                 PROCESS_INFORMATION info;
812
813                 sprintf(buffer, "%s tests/shellpath.c 1", selfname);
814                 memset(&startup, 0, sizeof(startup));
815                 startup.cb = sizeof(startup);
816                 startup.dwFlags = STARTF_USESHOWWINDOW;
817                 startup.dwFlags = SW_SHOWNORMAL;
818                 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
819                  &startup, &info);
820                 winetest_wait_child_process( info.hProcess );
821
822                 /* restore original values: */
823                 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
824                 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
825                  strlen(originalPath) + 1);
826                 RegFlushKey(key);
827
828                 sprintf(buffer, "%s tests/shellpath.c 2", selfname);
829                 memset(&startup, 0, sizeof(startup));
830                 startup.cb = sizeof(startup);
831                 startup.dwFlags = STARTF_USESHOWWINDOW;
832                 startup.dwFlags = SW_SHOWNORMAL;
833                 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
834                  &startup, &info);
835                 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
836                  "child process termination\n");
837             }
838         }
839         else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
840         if (key)
841             RegCloseKey(key);
842     }
843     else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
844 }
845
846 static void test_SHGetFolderPathEx(void)
847 {
848     HRESULT hr;
849     WCHAR buffer[MAX_PATH], *path;
850     DWORD len;
851
852     if (!pSHGetKnownFolderPath || !pSHGetFolderPathEx)
853     {
854         win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
855         return;
856     }
857
858 if (0) { /* crashes */
859     hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, NULL);
860     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
861 }
862     path = NULL;
863     hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, &path);
864     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
865     ok(path != NULL, "expected path != NULL\n");
866
867     hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, MAX_PATH);
868     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
869     ok(!lstrcmpiW(path, buffer), "expected equal paths\n");
870     len = lstrlenW(buffer);
871     CoTaskMemFree(path);
872
873     hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, 0);
874     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
875
876 if (0) { /* crashes */
877     hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, NULL, len + 1);
878     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
879
880     hr = pSHGetFolderPathEx(NULL, 0, NULL, buffer, MAX_PATH);
881     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
882 }
883     hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len);
884     ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "expected 0x8007007a, got 0x%08x\n", hr);
885
886     hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len + 1);
887     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
888 }
889
890 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
891 #define NO_CSIDL 0x10000
892 #define CSIDL_TODO_WINE 0x20000
893 #define KNOWN_FOLDER(id, csidl, name, category, parent, relative_path) \
894     { &id, # id, csidl, # csidl, name, category, &parent, # parent, relative_path, __LINE__ }
895
896 /* non-published known folders test */
897 static const GUID _FOLDERID_CryptoKeys =            {0xB88F4DAA, 0xE7BD, 0x49A9, {0xB7, 0x4D, 0x02, 0x88, 0x5A, 0x5D, 0xC7, 0x65} };
898 static const GUID _FOLDERID_DpapiKeys =             {0x10C07CD0, 0xEF91, 0x4567, {0xB8, 0x50, 0x44, 0x8B, 0x77, 0xCB, 0x37, 0xF9} };
899 static const GUID _FOLDERID_SystemCertificates =    {0x54EED2E0, 0xE7CA, 0x4FDB, {0x91, 0x48, 0x0F, 0x42, 0x47, 0x29, 0x1C, 0xFA} };
900 static const GUID _FOLDERID_CredentialManager =     {0x915221FB, 0x9EFE, 0x4BDA, {0x8F, 0xD7, 0xF7, 0x8D, 0xCA, 0x77, 0x4F, 0x87} };
901
902 struct knownFolderDef {
903     const KNOWNFOLDERID *folderId;
904     const char *sFolderId;
905     const int csidl;
906     const char *sCsidl;
907     const char *sName;
908     const KF_CATEGORY category;
909     const KNOWNFOLDERID *fidParent;
910     const char *sParent;
911     const char *sRelativePath;
912     const int line;
913 };
914
915 static const struct knownFolderDef known_folders[] = {
916     KNOWN_FOLDER(FOLDERID_AddNewPrograms,             NO_CSIDL,                             "AddNewProgramsFolder",         KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
917     KNOWN_FOLDER(FOLDERID_AdminTools,                 CSIDL_ADMINTOOLS,                     "Administrative Tools",         KF_CATEGORY_PERUSER,  FOLDERID_Programs,            "Administrative Tools"),
918     KNOWN_FOLDER(FOLDERID_AppUpdates,                 NO_CSIDL,                             "AppUpdatesFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
919     KNOWN_FOLDER(FOLDERID_CDBurning,                  CSIDL_CDBURN_AREA,                    "CD Burning",                   KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows\\Burn\\Burn"),
920     KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms,       NO_CSIDL,                             "ChangeRemoveProgramsFolder",   KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
921     KNOWN_FOLDER(FOLDERID_CommonAdminTools,           CSIDL_COMMON_ADMINTOOLS,              "Common Administrative Tools",  KF_CATEGORY_COMMON,   FOLDERID_CommonPrograms,      "Administrative Tools"),
922     KNOWN_FOLDER(FOLDERID_CommonOEMLinks,             CSIDL_COMMON_OEM_LINKS,               "OEM Links",                    KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "OEM Links"),
923     KNOWN_FOLDER(FOLDERID_CommonPrograms,             CSIDL_COMMON_PROGRAMS,                "Common Programs",              KF_CATEGORY_COMMON,   FOLDERID_CommonStartMenu,     "Programs"),
924     KNOWN_FOLDER(FOLDERID_CommonStartMenu,            CSIDL_COMMON_STARTMENU,               "Common Start Menu",            KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "Microsoft\\Windows\\Start Menu"),
925     KNOWN_FOLDER(FOLDERID_CommonStartup,              CSIDL_COMMON_STARTUP,                 "Common Startup",               KF_CATEGORY_COMMON,   FOLDERID_CommonPrograms,      "StartUp"),
926     KNOWN_FOLDER(FOLDERID_CommonTemplates,            CSIDL_COMMON_TEMPLATES,               "Common Templates",             KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "Microsoft\\Windows\\Templates"),
927     KNOWN_FOLDER(FOLDERID_ComputerFolder,             CSIDL_DRIVES,                         "MyComputerFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
928     KNOWN_FOLDER(FOLDERID_ConflictFolder,             NO_CSIDL,                             "ConflictFolder",               KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
929     KNOWN_FOLDER(FOLDERID_ConnectionsFolder,          CSIDL_CONNECTIONS,                    "ConnectionsFolder",            KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
930     KNOWN_FOLDER(FOLDERID_Contacts,                   NO_CSIDL,                             "Contacts",                     KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Contacts"),
931     KNOWN_FOLDER(FOLDERID_ControlPanelFolder,         CSIDL_CONTROLS,                       "ControlPanelFolder",           KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
932     KNOWN_FOLDER(FOLDERID_Cookies,                    CSIDL_COOKIES,                        "Cookies",                      KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Cookies"),
933     KNOWN_FOLDER(FOLDERID_Desktop,                    CSIDL_DESKTOP,                        "Desktop",                      KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Desktop"),
934     KNOWN_FOLDER(FOLDERID_DeviceMetadataStore,        NO_CSIDL,                             "Device Metadata Store",        KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "Microsoft\\Windows\\DeviceMetadataStore"),
935     KNOWN_FOLDER(FOLDERID_Documents,                  CSIDL_MYDOCUMENTS,                    "Personal",                     KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Documents"),
936     KNOWN_FOLDER(FOLDERID_DocumentsLibrary,           NO_CSIDL,                             "DocumentsLibrary",             KF_CATEGORY_PERUSER,  FOLDERID_Libraries,           "Documents.library-ms"),
937     KNOWN_FOLDER(FOLDERID_Downloads,                  NO_CSIDL,                             "Downloads",                    KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Downloads"),
938     KNOWN_FOLDER(FOLDERID_Favorites,                  CSIDL_FAVORITES,                      "Favorites",                    KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Favorites"),
939     KNOWN_FOLDER(FOLDERID_Fonts,                      CSIDL_FONTS,                          "Fonts",                        KF_CATEGORY_FIXED,    FOLDERID_Windows,             NULL),
940     KNOWN_FOLDER(FOLDERID_Games,                      NO_CSIDL,                             "Games",                        KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
941     KNOWN_FOLDER(FOLDERID_GameTasks,                  NO_CSIDL,                             "GameTasks",                    KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows\\GameExplorer"),
942     KNOWN_FOLDER(FOLDERID_History,                    CSIDL_HISTORY,                        "History",                      KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows\\History"),
943     KNOWN_FOLDER(FOLDERID_HomeGroup,                  NO_CSIDL,                             "HomeGroupFolder",              KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
944     KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts,       NO_CSIDL,                             "ImplicitAppShortcuts",         KF_CATEGORY_PERUSER,  FOLDERID_UserPinned,          "ImplicitAppShortcuts"),
945     KNOWN_FOLDER(FOLDERID_InternetCache,              CSIDL_INTERNET_CACHE,                 "Cache",                        KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows\\Temporary Internet Files"),
946     KNOWN_FOLDER(FOLDERID_InternetFolder,             CSIDL_INTERNET,                       "InternetFolder",               KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
947     KNOWN_FOLDER(FOLDERID_Libraries,                  NO_CSIDL,                             "Libraries",                    KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Libraries"),
948     KNOWN_FOLDER(FOLDERID_Links,                      NO_CSIDL,                             "Links",                        KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Links"),
949     KNOWN_FOLDER(FOLDERID_LocalAppData,               CSIDL_LOCAL_APPDATA,                  "Local AppData",                KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "AppData\\Local"),
950     KNOWN_FOLDER(FOLDERID_LocalAppDataLow,            NO_CSIDL,                             "LocalAppDataLow",              KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "AppData\\LocalLow"),
951     KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir,      CSIDL_RESOURCES_LOCALIZED,            "LocalizedResourcesDir",        KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
952     KNOWN_FOLDER(FOLDERID_Music,                      CSIDL_MYMUSIC,                        "My Music",                     KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Music"),
953     KNOWN_FOLDER(FOLDERID_MusicLibrary,               NO_CSIDL,                             "MusicLibrary",                 KF_CATEGORY_PERUSER,  FOLDERID_Libraries,           "Music.library-ms"),
954     KNOWN_FOLDER(FOLDERID_NetHood,                    CSIDL_NETHOOD,                        "NetHood",                      KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Network Shortcuts"),
955     KNOWN_FOLDER(FOLDERID_NetworkFolder,              CSIDL_NETWORK,                        "NetworkPlacesFolder",          KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
956     KNOWN_FOLDER(FOLDERID_OriginalImages,             NO_CSIDL,                             "Original Images",              KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows Photo Gallery\\Original Images"),
957     KNOWN_FOLDER(FOLDERID_PhotoAlbums,                NO_CSIDL,                             "PhotoAlbums",                  KF_CATEGORY_PERUSER,  FOLDERID_Pictures,            "Slide Shows"),
958     KNOWN_FOLDER(FOLDERID_Pictures,                   CSIDL_MYPICTURES,                     "My Pictures",                  KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Pictures"),
959     KNOWN_FOLDER(FOLDERID_PicturesLibrary,            NO_CSIDL,                             "PicturesLibrary",              KF_CATEGORY_PERUSER,  FOLDERID_Libraries,           "Pictures.library-ms"),
960     KNOWN_FOLDER(FOLDERID_Playlists,                  NO_CSIDL,                             "Playlists",                    KF_CATEGORY_PERUSER,  FOLDERID_Music,               "Playlists"),
961     KNOWN_FOLDER(FOLDERID_PrintersFolder,             CSIDL_PRINTERS,                       "PrintersFolder",               KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
962     KNOWN_FOLDER(FOLDERID_PrintHood,                  CSIDL_PRINTHOOD,                      "PrintHood",                    KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Printer Shortcuts"),
963     KNOWN_FOLDER(FOLDERID_Profile,                    CSIDL_PROFILE,                        "Profile",                      KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
964     KNOWN_FOLDER(FOLDERID_ProgramData,                CSIDL_COMMON_APPDATA,                 "Common AppData",               KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
965     KNOWN_FOLDER(FOLDERID_ProgramFiles,               CSIDL_PROGRAM_FILES,                  "ProgramFiles",                 KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
966     KNOWN_FOLDER(FOLDERID_ProgramFilesCommon,         CSIDL_PROGRAM_FILES_COMMON,           "ProgramFilesCommon",           KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
967     KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86,      NO_CSIDL,                             "ProgramFilesCommonX86",        KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
968     KNOWN_FOLDER(FOLDERID_ProgramFilesX86,            CSIDL_PROGRAM_FILESX86,               "ProgramFilesX86",              KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
969     KNOWN_FOLDER(FOLDERID_Programs,                   CSIDL_PROGRAMS,                       "Programs",                     KF_CATEGORY_PERUSER,  FOLDERID_StartMenu,           "Programs"),
970     KNOWN_FOLDER(FOLDERID_Public,                     NO_CSIDL,                             "Public",                       KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
971     KNOWN_FOLDER(FOLDERID_PublicDesktop,              CSIDL_COMMON_DESKTOPDIRECTORY,        "Common Desktop",               KF_CATEGORY_COMMON,   FOLDERID_Public,              "Desktop"),
972     KNOWN_FOLDER(FOLDERID_PublicDocuments,            CSIDL_COMMON_DOCUMENTS,               "Common Documents",             KF_CATEGORY_COMMON,   FOLDERID_Public,              "Documents"),
973     KNOWN_FOLDER(FOLDERID_PublicDownloads,            NO_CSIDL,                             "CommonDownloads",              KF_CATEGORY_COMMON,   FOLDERID_Public,              "Downloads"),
974     KNOWN_FOLDER(FOLDERID_PublicGameTasks,            NO_CSIDL,                             "PublicGameTasks",              KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "Microsoft\\Windows\\GameExplorer"),
975     KNOWN_FOLDER(FOLDERID_PublicLibraries,            NO_CSIDL,                             "PublicLibraries",              KF_CATEGORY_COMMON,   FOLDERID_Public,              "Libraries"),
976     KNOWN_FOLDER(FOLDERID_PublicMusic,                CSIDL_COMMON_MUSIC,                   "CommonMusic",                  KF_CATEGORY_COMMON,   FOLDERID_Public,              "Music"),
977     KNOWN_FOLDER(FOLDERID_PublicPictures,             CSIDL_COMMON_PICTURES,                "CommonPictures",               KF_CATEGORY_COMMON,   FOLDERID_Public,              "Pictures"),
978     KNOWN_FOLDER(FOLDERID_PublicRingtones,            NO_CSIDL,                             "CommonRingtones",              KF_CATEGORY_COMMON,   FOLDERID_ProgramData,         "Microsoft\\Windows\\Ringtones"),
979     KNOWN_FOLDER(FOLDERID_PublicVideos,               CSIDL_COMMON_VIDEO,                   "CommonVideo",                  KF_CATEGORY_COMMON,   FOLDERID_Public,              "Videos"),
980     KNOWN_FOLDER(FOLDERID_QuickLaunch,                NO_CSIDL,                             "Quick Launch",                 KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Internet Explorer\\Quick Launch"),
981     KNOWN_FOLDER(FOLDERID_Recent,                     CSIDL_RECENT,                         "Recent",                       KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Recent"),
982     KNOWN_FOLDER(FOLDERID_RecordedTVLibrary,          NO_CSIDL,                             "RecordedTVLibrary",            KF_CATEGORY_COMMON,   FOLDERID_PublicLibraries,     "RecordedTV.library-ms"),
983     KNOWN_FOLDER(FOLDERID_RecycleBinFolder,           CSIDL_BITBUCKET,                      "RecycleBinFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
984     KNOWN_FOLDER(FOLDERID_ResourceDir,                CSIDL_RESOURCES,                      "ResourceDir",                  KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
985     KNOWN_FOLDER(FOLDERID_Ringtones,                  NO_CSIDL,                             "Ringtones",                    KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows\\Ringtones"),
986     KNOWN_FOLDER(FOLDERID_RoamingAppData,             CSIDL_APPDATA,                        "AppData",                      KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "AppData\\Roaming"),
987     KNOWN_FOLDER(FOLDERID_SampleMusic,                NO_CSIDL,                             "SampleMusic",                  KF_CATEGORY_COMMON,   FOLDERID_PublicMusic,         "Sample Music"),
988     KNOWN_FOLDER(FOLDERID_SamplePictures,             NO_CSIDL,                             "SamplePictures",               KF_CATEGORY_COMMON,   FOLDERID_PublicPictures,      "Sample Pictures"),
989     KNOWN_FOLDER(FOLDERID_SamplePlaylists,            NO_CSIDL,                             "SamplePlaylists",              KF_CATEGORY_COMMON,   FOLDERID_PublicMusic,         "Sample Playlists"),
990     KNOWN_FOLDER(FOLDERID_SampleVideos,               NO_CSIDL,                             "SampleVideos",                 KF_CATEGORY_COMMON,   FOLDERID_PublicVideos,        "Sample Videos"),
991     KNOWN_FOLDER(FOLDERID_SavedGames,                 NO_CSIDL,                             "SavedGames",                   KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Saved Games"),
992     KNOWN_FOLDER(FOLDERID_SavedSearches,              NO_CSIDL,                             "Searches",                     KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Searches"),
993     KNOWN_FOLDER(FOLDERID_SEARCH_CSC,                 NO_CSIDL,                             "CSCFolder",                    KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
994     KNOWN_FOLDER(FOLDERID_SearchHome,                 NO_CSIDL,                             "SearchHomeFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
995     KNOWN_FOLDER(FOLDERID_SEARCH_MAPI,                NO_CSIDL,                             "MAPIFolder",                   KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
996     KNOWN_FOLDER(FOLDERID_SendTo,                     CSIDL_SENDTO,                         "SendTo",                       KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\SendTo"),
997     KNOWN_FOLDER(FOLDERID_SidebarDefaultParts,        NO_CSIDL,                             "Default Gadgets",              KF_CATEGORY_COMMON,   FOLDERID_ProgramFiles,        "Windows Sidebar\\Gadgets"),
998     KNOWN_FOLDER(FOLDERID_SidebarParts,               NO_CSIDL,                             "Gadgets",                      KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Microsoft\\Windows Sidebar\\Gadgets"),
999     KNOWN_FOLDER(FOLDERID_StartMenu,                  CSIDL_STARTMENU,                      "Start Menu",                   KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Start Menu"),
1000     KNOWN_FOLDER(FOLDERID_Startup,                    CSIDL_STARTUP,                        "Startup",                      KF_CATEGORY_PERUSER,  FOLDERID_Programs,            "StartUp"),
1001     KNOWN_FOLDER(FOLDERID_SyncManagerFolder,          NO_CSIDL,                             "SyncCenterFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
1002     KNOWN_FOLDER(FOLDERID_SyncResultsFolder,          NO_CSIDL,                             "SyncResultsFolder",            KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
1003     KNOWN_FOLDER(FOLDERID_SyncSetupFolder,            NO_CSIDL,                             "SyncSetupFolder",              KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
1004     KNOWN_FOLDER(FOLDERID_System,                     CSIDL_SYSTEM,                         "System",                       KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1005     KNOWN_FOLDER(FOLDERID_SystemX86,                  CSIDL_SYSTEMX86,                      "SystemX86",                    KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1006     KNOWN_FOLDER(FOLDERID_Templates,                  CSIDL_TEMPLATES,                      "Templates",                    KF_CATEGORY_PERUSER,  FOLDERID_RoamingAppData,      "Microsoft\\Windows\\Templates"),
1007     KNOWN_FOLDER(FOLDERID_UserPinned,                 NO_CSIDL,                             "User Pinned",                  KF_CATEGORY_PERUSER,  FOLDERID_QuickLaunch,         "User Pinned"),
1008     KNOWN_FOLDER(FOLDERID_UserProfiles,               NO_CSIDL,                             "UserProfiles",                 KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1009     KNOWN_FOLDER(FOLDERID_UserProgramFiles,           NO_CSIDL,                             "UserProgramFiles",             KF_CATEGORY_PERUSER,  FOLDERID_LocalAppData,        "Programs"),
1010     KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon,     NO_CSIDL,                             "UserProgramFilesCommon",       KF_CATEGORY_PERUSER,  FOLDERID_UserProgramFiles,    "Common"),
1011     KNOWN_FOLDER(FOLDERID_UsersFiles,                 NO_CSIDL,                             "UsersFilesFolder",             KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
1012     KNOWN_FOLDER(FOLDERID_UsersLibraries,             NO_CSIDL,                             "UsersLibrariesFolder",         KF_CATEGORY_VIRTUAL,  GUID_NULL,                    NULL),
1013     KNOWN_FOLDER(FOLDERID_Videos,                     CSIDL_MYVIDEO,                        "My Video",                     KF_CATEGORY_PERUSER,  FOLDERID_Profile,             "Videos"),
1014     KNOWN_FOLDER(FOLDERID_VideosLibrary,              NO_CSIDL,                             "VideosLibrary",                KF_CATEGORY_PERUSER,  FOLDERID_Libraries,           "Videos.library-ms"),
1015     KNOWN_FOLDER(FOLDERID_Windows,                    CSIDL_WINDOWS,                        "Windows",                      KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1016     KNOWN_FOLDER(_FOLDERID_CredentialManager,         NO_CSIDL,                             "CredentialManager",            KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1017     KNOWN_FOLDER(_FOLDERID_CryptoKeys,                NO_CSIDL,                             "CryptoKeys",                   KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1018     KNOWN_FOLDER(_FOLDERID_DpapiKeys,                 NO_CSIDL,                             "DpapiKeys",                    KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1019     KNOWN_FOLDER(_FOLDERID_SystemCertificates,        NO_CSIDL,                             "SystemCertificates",           KF_CATEGORY_FIXED,    GUID_NULL,                    NULL),
1020     { NULL, NULL, 0, NULL, NULL, 0, 0 }
1021 };
1022 #undef KNOWN_FOLDER
1023 BOOL known_folder_found[sizeof(known_folders)/sizeof(known_folders[0])-1];
1024
1025 static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId)
1026 {
1027     HRESULT hr;
1028     const struct knownFolderDef *known_folder = &known_folders[0];
1029     int csidl, expectedCsidl, ret;
1030     KNOWNFOLDER_DEFINITION kfd;
1031     IKnownFolder *folder;
1032     WCHAR sName[1024], sRelativePath[MAX_PATH];
1033     BOOL validPath;
1034     char sParentGuid[39];
1035     BOOL *current_known_folder_found = &known_folder_found[0];
1036     BOOL found = FALSE;
1037
1038     while(known_folder->folderId != NULL)
1039     {
1040         if(IsEqualGUID(known_folder->folderId, folderId))
1041         {
1042             *current_known_folder_found = TRUE;
1043             found = TRUE;
1044             /* verify CSIDL */
1045             if(known_folder->csidl != NO_CSIDL)
1046             {
1047                 expectedCsidl = known_folder->csidl & (~CSIDL_TODO_WINE);
1048
1049                 hr = IKnownFolderManager_FolderIdToCsidl(mgr, folderId, &csidl);
1050                 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot retrieve CSIDL for folder %s\n", known_folder->sFolderId);
1051
1052                 if(known_folder->csidl & CSIDL_TODO_WINE)
1053                     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);
1054                 else
1055                     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);
1056             }
1057
1058             hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
1059             ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder for %s\n", known_folder->sFolderId);
1060             if(SUCCEEDED(hr))
1061             {
1062                 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
1063                 todo_wine
1064                 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder definition for %s\n", known_folder->sFolderId);
1065                 if(SUCCEEDED(hr))
1066                 {
1067                     ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sName, -1,  sName, sizeof(sName)/sizeof(sName[0]));
1068                     ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder name \"%s\" to wide characters\n", known_folder->sName);
1069
1070                     todo_wine
1071                     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));
1072
1073                     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);
1074
1075                     printGUID(&kfd.fidParent, sParentGuid);
1076                     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);
1077
1078                     if(!known_folder->sRelativePath)
1079                         validPath = (kfd.pszRelativePath==NULL);
1080                     else
1081                     {
1082                         ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sRelativePath, -1, sRelativePath, sizeof(sRelativePath)/sizeof(sRelativePath[0]));
1083                         ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder path \"%s\" to wide characters\n", known_folder->sRelativePath);
1084
1085                         validPath = (lstrcmpW(kfd.pszRelativePath, sRelativePath)==0);
1086                     }
1087
1088                     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));
1089
1090                     FreeKnownFolderDefinitionFields(&kfd);
1091                 }
1092
1093             IKnownFolder_Release(folder);
1094             }
1095
1096             break;
1097         }
1098         known_folder++;
1099         current_known_folder_found++;
1100     }
1101
1102     if(!found)
1103     {
1104         printGUID(folderId, sParentGuid);
1105         trace("unknown known folder found: %s\n", sParentGuid);
1106
1107         hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
1108         ok(hr == S_OK, "cannot get known folder for %s\n", sParentGuid);
1109         if(SUCCEEDED(hr))
1110         {
1111             hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
1112             todo_wine
1113             ok(hr == S_OK, "cannot get known folder definition for %s\n", sParentGuid);
1114             if(SUCCEEDED(hr))
1115             {
1116                 trace("  category: %d\n", kfd.category);
1117                 trace("  name: %s\n", wine_dbgstr_w(kfd.pszName));
1118                 trace("  description: %s\n", wine_dbgstr_w(kfd.pszDescription));
1119                 printGUID(&kfd.fidParent, sParentGuid);
1120                 trace("  parent: %s\n", sParentGuid);
1121                 trace("  relative path: %s\n", wine_dbgstr_w(kfd.pszRelativePath));
1122                 trace("  parsing name: %s\n", wine_dbgstr_w(kfd.pszParsingName));
1123                 trace("  tooltip: %s\n", wine_dbgstr_w(kfd.pszTooltip));
1124                 trace("  localized name: %s\n", wine_dbgstr_w(kfd.pszLocalizedName));
1125                 trace("  icon: %s\n", wine_dbgstr_w(kfd.pszIcon));
1126                 trace("  security: %s\n", wine_dbgstr_w(kfd.pszSecurity));
1127                 trace("  attributes: 0x%08x\n", kfd.dwAttributes);
1128                 trace("  flags: 0x%08x\n", kfd.kfdFlags);
1129                 printGUID(&kfd.ftidType, sParentGuid);
1130                 trace("  type: %s\n", sParentGuid);
1131                 FreeKnownFolderDefinitionFields(&kfd);
1132             }
1133
1134             IKnownFolder_Release(folder);
1135         }
1136     }
1137 }
1138 #undef NO_CSIDL
1139 #undef CSIDL_TODO_WINE
1140
1141 static void test_knownFolders(void)
1142 {
1143     static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
1144     static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
1145     static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
1146     static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
1147     static const WCHAR sBackslash[] = {'\\',0};
1148     static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
1149     static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
1150     HRESULT hr;
1151     IKnownFolderManager *mgr = NULL;
1152     IKnownFolder *folder = NULL, *subFolder = NULL;
1153     KNOWNFOLDERID folderId, *folders;
1154     KF_CATEGORY cat = 0;
1155     KNOWNFOLDER_DEFINITION kfDefinition, kfSubDefinition;
1156     int csidl, i;
1157     UINT nCount = 0;
1158     LPWSTR folderPath, errorMsg;
1159     KF_REDIRECTION_CAPABILITIES redirectionCapabilities = 1;
1160     WCHAR sWinDir[MAX_PATH], sExamplePath[MAX_PATH], sExample2Path[MAX_PATH], sSubFolderPath[MAX_PATH], sSubFolder2Path[MAX_PATH];
1161     BOOL bRes;
1162     DWORD dwAttributes;
1163
1164     GetWindowsDirectoryW( sWinDir, MAX_PATH );
1165
1166     GetTempPathW(sizeof(sExamplePath)/sizeof(sExamplePath[0]), sExamplePath);
1167     lstrcatW(sExamplePath, sExample);
1168
1169     GetTempPathW(sizeof(sExample2Path)/sizeof(sExample2Path[0]), sExample2Path);
1170     lstrcatW(sExample2Path, sExample2);
1171
1172     lstrcpyW(sSubFolderPath, sExamplePath);
1173     lstrcatW(sSubFolderPath, sBackslash);
1174     lstrcatW(sSubFolderPath, sSubFolder);
1175
1176     lstrcpyW(sSubFolder2Path, sExample2Path);
1177     lstrcatW(sSubFolder2Path, sBackslash);
1178     lstrcatW(sSubFolder2Path, sSubFolder);
1179
1180     CoInitialize(NULL);
1181
1182     hr = CoCreateInstance(&CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER,
1183                           &IID_IKnownFolderManager, (LPVOID*)&mgr);
1184     if(hr == REGDB_E_CLASSNOTREG)
1185         win_skip("IKnownFolderManager unavailable\n");
1186     else
1187     {
1188         ok(hr == S_OK, "failed to create KnownFolderManager instance: 0x%08x\n", hr);
1189
1190         hr = IKnownFolderManager_FolderIdFromCsidl(mgr, CSIDL_WINDOWS, &folderId);
1191         ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
1192         ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1193
1194         hr = IKnownFolderManager_FolderIdToCsidl(mgr, &FOLDERID_Windows, &csidl);
1195         ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
1196         ok(csidl == CSIDL_WINDOWS, "invalid CSIDL returned\n");
1197
1198         hr = IKnownFolderManager_GetFolder(mgr, &FOLDERID_Windows, &folder);
1199         ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1200         if(SUCCEEDED(hr))
1201         {
1202             hr = IKnownFolder_GetCategory(folder, &cat);
1203             todo_wine
1204             ok(hr == S_OK, "failed to get folder category: 0x%08x\n", hr);
1205             todo_wine
1206             ok(cat==KF_CATEGORY_FIXED, "invalid folder category: %d\n", cat);
1207
1208             hr = IKnownFolder_GetId(folder, &folderId);
1209             ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1210             ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1211
1212             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1213             ok(lstrcmpiW(sWinDir, folderPath)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sWinDir));
1214             CoTaskMemFree(folderPath);
1215
1216             hr = IKnownFolder_GetRedirectionCapabilities(folder, &redirectionCapabilities);
1217             todo_wine
1218             ok(hr == S_OK, "failed to get redirection capabilities: 0x%08x\n", hr);
1219             todo_wine
1220             ok(redirectionCapabilities==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities);
1221
1222             hr = IKnownFolder_SetPath(folder, 0, sWinDir);
1223             todo_wine
1224             ok(hr == E_INVALIDARG, "unexpected value from SetPath: 0x%08x\n", hr);
1225
1226             hr = IKnownFolder_GetFolderDefinition(folder, &kfDefinition);
1227             todo_wine
1228             ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
1229             if(SUCCEEDED(hr))
1230             {
1231                 todo_wine
1232                 ok(kfDefinition.category==KF_CATEGORY_FIXED, "invalid folder category: 0x%08x\n", kfDefinition.category);
1233                 todo_wine
1234                 ok(lstrcmpW(kfDefinition.pszName, sWindows)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition.pszName));
1235                 todo_wine
1236                 ok(kfDefinition.dwAttributes==0, "invalid folder attributes: %d\n", kfDefinition.dwAttributes);
1237                 FreeKnownFolderDefinitionFields(&kfDefinition);
1238             }
1239
1240             hr = IKnownFolder_Release(folder);
1241             ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1242         }
1243
1244         hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
1245         todo_wine
1246         ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1247         if(SUCCEEDED(hr))
1248         {
1249             hr = IKnownFolder_GetId(folder, &folderId);
1250             ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1251             ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
1252
1253             hr = IKnownFolder_Release(folder);
1254             ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1255         }
1256
1257         for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
1258             known_folder_found[i] = FALSE;
1259
1260         hr = IKnownFolderManager_GetFolderIds(mgr, &folders, &nCount);
1261         ok(hr == S_OK, "failed to get known folders: 0x%08x\n", hr);
1262         for(i=0;i<nCount;++i)
1263             check_known_folder(mgr, &folders[i]);
1264
1265         for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
1266             if(!known_folder_found[i])
1267                 trace("Known folder %s not found on current platform\n", known_folders[i].sFolderId);
1268
1269         CoTaskMemFree(folders);
1270
1271         /* test of registering new known folders */
1272         bRes = CreateDirectoryW(sExamplePath, NULL);
1273         ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath));
1274         bRes = CreateDirectoryW(sExample2Path, NULL);
1275         ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path));
1276         bRes = CreateDirectoryW(sSubFolderPath, NULL);
1277         ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath));
1278
1279         ZeroMemory(&kfDefinition, sizeof(kfDefinition));
1280         kfDefinition.category = KF_CATEGORY_PERUSER;
1281         kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample));
1282         lstrcpyW(kfDefinition.pszName, sExample);
1283         kfDefinition.pszDescription = CoTaskMemAlloc(sizeof(sExample));
1284         lstrcpyW(kfDefinition.pszDescription, sExample);
1285         kfDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sExamplePath));
1286         lstrcpyW(kfDefinition.pszRelativePath, sExamplePath);
1287
1288         hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
1289         if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
1290             win_skip("No permissions required to register custom known folder\n");
1291         else
1292         {
1293             ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
1294             if(SUCCEEDED(hr))
1295             {
1296                 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
1297                 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1298                 if(SUCCEEDED(hr))
1299                 {
1300                     hr = IKnownFolder_GetCategory(folder, &cat);
1301                     ok(hr == S_OK, "failed to get folder category: hr=0x%0x\n", hr);
1302                     ok(cat == KF_CATEGORY_PERUSER, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat, KF_CATEGORY_PERUSER);
1303
1304                     hr = IKnownFolder_GetId(folder, &folderId);
1305                     ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
1306                     ok(IsEqualGUID(&folderId, &newFolderId)==TRUE, "invalid KNOWNFOLDERID returned\n");
1307
1308                     /* current path should be Temp\Example */
1309                     hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1310                     ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
1311                     ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1312                     CoTaskMemFree(folderPath);
1313
1314                     /* register sub-folder and mark it as child of Example folder */
1315                     ZeroMemory(&kfSubDefinition, sizeof(kfSubDefinition));
1316                     kfSubDefinition.category = KF_CATEGORY_PERUSER;
1317                     kfSubDefinition.pszName = CoTaskMemAlloc(sizeof(sSubFolder));
1318                     lstrcpyW(kfSubDefinition.pszName, sSubFolder);
1319                     kfSubDefinition.pszDescription = CoTaskMemAlloc(sizeof(sSubFolder));
1320                     lstrcpyW(kfSubDefinition.pszDescription, sSubFolder);
1321                     kfSubDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sSubFolder));
1322                     lstrcpyW(kfSubDefinition.pszRelativePath, sSubFolder);
1323                     kfSubDefinition.fidParent = newFolderId;
1324
1325                     hr = IKnownFolderManager_RegisterFolder(mgr, &subFolderId, &kfSubDefinition);
1326                     ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
1327                     if(SUCCEEDED(hr))
1328                     {
1329
1330                         hr = IKnownFolderManager_GetFolder(mgr, &subFolderId, &subFolder);
1331                         ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
1332                         if(SUCCEEDED(hr))
1333                         {
1334                             /* check sub folder path */
1335                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1336                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1337                             ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1338                             CoTaskMemFree(folderPath);
1339
1340
1341                             /* try to redirect Example to Temp\Example2  */
1342                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
1343                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1344
1345                             /* verify */
1346                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1347                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1348                             ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1349                             CoTaskMemFree(folderPath);
1350
1351                             /* verify sub folder - it should fail now, as we redirected it's parent folder, but we have no sub folder in new location */
1352                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1353                             ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "unexpected value from GetPath(): 0x%08x\n", hr);
1354                             ok(folderPath==NULL, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath));
1355                             CoTaskMemFree(folderPath);
1356
1357
1358                             /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
1359                             hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1360                             ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1361
1362                             /* verify */
1363                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1364                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1365                             ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1366                             CoTaskMemFree(folderPath);
1367
1368
1369                             /* create sub folder in Temp\Example2 */
1370                             bRes = CreateDirectoryW(sSubFolder2Path, NULL);
1371                             ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
1372
1373                             /* again perform that same redirection */
1374                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
1375                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1376
1377                             /* verify sub folder. It should succeed now, as the required sub folder exists */
1378                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1379                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1380                             ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1381                             CoTaskMemFree(folderPath);
1382
1383                             /* remove newly created directory */
1384                             RemoveDirectoryW(sSubFolder2Path);
1385
1386                             /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
1387                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1388                             todo_wine
1389                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1390                             todo_wine
1391                             ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1392                             CoTaskMemFree(folderPath);
1393
1394
1395                             /* set Example path to original */
1396                             hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1397                             ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1398
1399                             /* verify */
1400                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1401                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1402                             ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1403                             CoTaskMemFree(folderPath);
1404
1405                             /* verify sub folder */
1406                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1407                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1408                             ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1409                             CoTaskMemFree(folderPath);
1410
1411
1412                             /* create sub folder in Temp\Example2 */
1413                             bRes = CreateDirectoryW(sSubFolder2Path, NULL);
1414                             ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
1415
1416                             /* do that same redirection, but try to exclude sub-folder */
1417                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 1, &subFolderId, &errorMsg);
1418                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1419
1420                             /* verify */
1421                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1422                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1423                             ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1424                             CoTaskMemFree(folderPath);
1425
1426                             /* 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 */
1427                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1428                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1429                             ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1430                             CoTaskMemFree(folderPath);
1431
1432                             /* remove newly created directory */
1433                             RemoveDirectoryW(sSubFolder2Path);
1434
1435
1436                             /* set Example path to original */
1437                             hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1438                             ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1439
1440                             /* verify */
1441                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1442                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1443                             ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1444                             CoTaskMemFree(folderPath);
1445
1446                             /* verify sub folder */
1447                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1448                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1449                             ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1450                             CoTaskMemFree(folderPath);
1451
1452
1453                             /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
1454                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
1455                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1456
1457                             /* verify */
1458                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1459                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1460                             ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1461                             CoTaskMemFree(folderPath);
1462
1463                             /* verify sub folder */
1464                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1465                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1466                             ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1467                             CoTaskMemFree(folderPath);
1468
1469                             /* remove copied directory */
1470                             RemoveDirectoryW(sSubFolder2Path);
1471
1472
1473                             /* set Example path to original */
1474                             hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
1475                             ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
1476
1477                             /* verify */
1478                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1479                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1480                             ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1481                             CoTaskMemFree(folderPath);
1482
1483                             /* verify sub folder */
1484                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1485                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1486                             ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1487                             CoTaskMemFree(folderPath);
1488
1489
1490                             /* redirect again, set it to copy content and remove originals */
1491                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS | KF_REDIRECT_DEL_SOURCE_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
1492                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1493
1494                             /* verify */
1495                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1496                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1497                             ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
1498                             CoTaskMemFree(folderPath);
1499
1500                             /* verify sub folder */
1501                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1502                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1503                             ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
1504                             CoTaskMemFree(folderPath);
1505
1506                             /* check if original directory was really removed */
1507                             dwAttributes = GetFileAttributesW(sExamplePath);
1508                             ok(dwAttributes==INVALID_FILE_ATTRIBUTES, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes );
1509
1510
1511                             /* redirect (with copy) to original path */
1512                             hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS,  sExamplePath, 0, NULL, &errorMsg);
1513                             ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
1514
1515                             /* verify */
1516                             hr = IKnownFolder_GetPath(folder, 0, &folderPath);
1517                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1518                             ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
1519                             CoTaskMemFree(folderPath);
1520
1521                             /* verify sub folder */
1522                             hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
1523                             ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
1524                             ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
1525                             CoTaskMemFree(folderPath);
1526
1527                             /* check shell utility functions */
1528                             if(!pSHGetKnownFolderPath || !pSHSetKnownFolderPath)
1529                                 todo_wine
1530                                 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
1531                             else
1532                             {
1533                                 /* try to get current known folder path */
1534                                 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
1535                                 todo_wine
1536                                 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
1537                                 todo_wine
1538                                 ok(lstrcmpW(folderPath, sExamplePath)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
1539
1540                                 /* set it to new value */
1541                                 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExample2Path);
1542                                 todo_wine
1543                                 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
1544
1545                                 /* check if it changed */
1546                                 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
1547                                 todo_wine
1548                                 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
1549                                 todo_wine
1550                                 ok(lstrcmpW(folderPath, sExample2Path)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
1551
1552                                 /* set it back */
1553                                 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExamplePath);
1554                                 todo_wine
1555                                 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
1556                             }
1557
1558                             IKnownFolder_Release(subFolder);
1559                         }
1560
1561                         hr = IKnownFolderManager_UnregisterFolder(mgr, &subFolderId);
1562                         ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
1563                     }
1564
1565                     FreeKnownFolderDefinitionFields(&kfSubDefinition);
1566
1567                     hr = IKnownFolder_Release(folder);
1568                     ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
1569                 }
1570
1571                 hr = IKnownFolderManager_UnregisterFolder(mgr, &newFolderId);
1572                 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
1573             }
1574         }
1575         FreeKnownFolderDefinitionFields(&kfDefinition);
1576
1577         RemoveDirectoryW(sSubFolder2Path);
1578         RemoveDirectoryW(sSubFolderPath);
1579         RemoveDirectoryW(sExamplePath);
1580         RemoveDirectoryW(sExample2Path);
1581
1582         hr = IKnownFolderManager_Release(mgr);
1583         ok(hr == S_OK, "failed to release KnownFolderManager instance: 0x%08x\n", hr);
1584     }
1585     CoUninitialize();
1586 }
1587
1588 START_TEST(shellpath)
1589 {
1590     if (!init()) return;
1591
1592     loadShell32();
1593     pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
1594                                                         "GetSystemWow64DirectoryA" );
1595     if (myARGC >= 3)
1596         doChild(myARGV[2]);
1597     else
1598     {
1599         /* Report missing functions once */
1600         if (!pSHGetFolderLocation)
1601             win_skip("SHGetFolderLocation is not available\n");
1602
1603         /* first test various combinations of parameters: */
1604         test_parameters();
1605
1606         /* check known values: */
1607         test_PidlTypes();
1608         test_GUIDs();
1609         test_EnvVars();
1610         testWinDir();
1611         testSystemDir();
1612         test_NonExistentPath();
1613         test_SHGetFolderPathEx();
1614         test_knownFolders();
1615     }
1616 }