wined3d: Handle the sampler type shift in the frontend.
[wine] / dlls / shell32 / tests / shlfolder.c
1 /*
2  * Unit test of the IShellFolder functions.
3  *
4  * Copyright 2004 Vitaliy Margolen
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  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25 #define CONST_VTABLE
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "shellapi.h"
31
32
33 #include "shlguid.h"
34 #include "shlobj.h"
35 #include "shobjidl.h"
36 #include "shlwapi.h"
37 #include "ocidl.h"
38 #include "oleauto.h"
39
40 #include "wine/test.h"
41
42
43 static IMalloc *ppM;
44
45 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
46 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
47 static HRESULT (WINAPI *pSHGetFolderPathAndSubDirA)(HWND, int, HANDLE, DWORD, LPCSTR, LPSTR);
48 static BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST,LPWSTR);
49 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
50 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
51 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
52 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
53 static void (WINAPI *pILFree)(LPITEMIDLIST);
54 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
55
56 static void init_function_pointers(void)
57 {
58     HMODULE hmod;
59     HRESULT hr;
60
61     hmod = GetModuleHandleA("shell32.dll");
62     pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
63     pSHGetFolderPathA = (void*)GetProcAddress(hmod, "SHGetFolderPathA");
64     pSHGetFolderPathAndSubDirA = (void*)GetProcAddress(hmod, "SHGetFolderPathAndSubDirA");
65     pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
66     pSHGetSpecialFolderPathA = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathA");
67     pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
68     pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
69     pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
70     pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
71
72     hmod = GetModuleHandleA("shlwapi.dll");
73     pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
74
75     hr = SHGetMalloc(&ppM);
76     ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
77 }
78
79 static void test_ParseDisplayName(void)
80 {
81     HRESULT hr;
82     IShellFolder *IDesktopFolder;
83     static const char *cNonExistDir1A = "c:\\nonexist_subdir";
84     static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
85     static const char *cInetTestA = "http:\\yyy";
86     static const char *cInetTest2A = "xx:yyy";
87     DWORD res;
88     WCHAR cTestDirW [MAX_PATH] = {0};
89     ITEMIDLIST *newPIDL;
90     BOOL bRes;
91
92     hr = SHGetDesktopFolder(&IDesktopFolder);
93     if(hr != S_OK) return;
94
95     MultiByteToWideChar(CP_ACP, 0, cInetTestA, -1, cTestDirW, MAX_PATH);
96     hr = IShellFolder_ParseDisplayName(IDesktopFolder,
97         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
98     todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
99         "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
100     if (SUCCEEDED(hr))
101     {
102         ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
103            "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
104         IMalloc_Free(ppM, newPIDL);
105     }
106
107     MultiByteToWideChar(CP_ACP, 0, cInetTest2A, -1, cTestDirW, MAX_PATH);
108     hr = IShellFolder_ParseDisplayName(IDesktopFolder,
109         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
110     todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
111         "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
112     if (SUCCEEDED(hr))
113     {
114         ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
115            "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
116         IMalloc_Free(ppM, newPIDL);
117     }
118
119     res = GetFileAttributesA(cNonExistDir1A);
120     if(res != INVALID_FILE_ATTRIBUTES) return;
121
122     MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
123     hr = IShellFolder_ParseDisplayName(IDesktopFolder, 
124         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
125     ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL), 
126         "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
127
128     res = GetFileAttributesA(cNonExistDir2A);
129     if(res != INVALID_FILE_ATTRIBUTES) return;
130
131     MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
132     hr = IShellFolder_ParseDisplayName(IDesktopFolder, 
133         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
134     ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG), 
135         "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
136
137     /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
138      * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
139      * out it doesn't. The magic seems to happen in the file dialogs, then. */
140     if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
141     
142     bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
143     ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
144     if (!bRes) goto finished;
145
146     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
147     ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
148     if (FAILED(hr)) goto finished;
149
150     ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31 ||
151        pILFindLastID(newPIDL)->mkid.abID[0] == 0xb1, /* Win98 */
152        "Last pidl should be of type PT_FOLDER or PT_IESPECIAL2, but is: %02x\n",
153        pILFindLastID(newPIDL)->mkid.abID[0]);
154     IMalloc_Free(ppM, newPIDL);
155     
156 finished:
157     IShellFolder_Release(IDesktopFolder);
158 }
159
160 /* creates a file with the specified name for tests */
161 static void CreateTestFile(const CHAR *name)
162 {
163     HANDLE file;
164     DWORD written;
165
166     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
167     if (file != INVALID_HANDLE_VALUE)
168     {
169         WriteFile(file, name, strlen(name), &written, NULL);
170         WriteFile(file, "\n", strlen("\n"), &written, NULL);
171         CloseHandle(file);
172     }
173 }
174
175
176 /* initializes the tests */
177 static void CreateFilesFolders(void)
178 {
179     CreateDirectoryA(".\\testdir", NULL);
180     CreateDirectoryA(".\\testdir\\test.txt", NULL);
181     CreateTestFile  (".\\testdir\\test1.txt ");
182     CreateTestFile  (".\\testdir\\test2.txt ");
183     CreateTestFile  (".\\testdir\\test3.txt ");
184     CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
185     CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
186 }
187
188 /* cleans after tests */
189 static void Cleanup(void)
190 {
191     DeleteFileA(".\\testdir\\test1.txt");
192     DeleteFileA(".\\testdir\\test2.txt");
193     DeleteFileA(".\\testdir\\test3.txt");
194     RemoveDirectoryA(".\\testdir\\test.txt");
195     RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
196     RemoveDirectoryA(".\\testdir\\testdir2");
197     RemoveDirectoryA(".\\testdir");
198 }
199
200
201 /* perform test */
202 static void test_EnumObjects(IShellFolder *iFolder)
203 {
204     IEnumIDList *iEnumList;
205     LPITEMIDLIST newPIDL, idlArr[10];
206     ULONG NumPIDLs;
207     int i=0, j;
208     HRESULT hr;
209
210     static const WORD iResults [5][5] =
211     {
212         { 0,-1,-1,-1,-1},
213         { 1, 0,-1,-1,-1},
214         { 1, 1, 0,-1,-1},
215         { 1, 1, 1, 0,-1},
216         { 1, 1, 1, 1, 0}
217     };
218
219 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
220     /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
221     static const ULONG attrs[5] =
222     {
223         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
224         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
225         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
226         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
227         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
228     };
229
230     hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
231     ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
232
233     /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
234      * the filesystem shellfolders return S_OK even if less than 'celt' items are
235      * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
236      * only ever returns a single entry per call. */
237     while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK) 
238         i += NumPIDLs;
239     ok (i == 5, "i: %d\n", i);
240
241     hr = IEnumIDList_Release(iEnumList);
242     ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
243     
244     /* Sort them first in case of wrong order from system */
245     for (i=0;i<5;i++) for (j=0;j<5;j++)
246         if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
247         {
248             newPIDL = idlArr[i];
249             idlArr[i] = idlArr[j];
250             idlArr[j] = newPIDL;
251         }
252             
253     for (i=0;i<5;i++) for (j=0;j<5;j++)
254     {
255         hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
256         ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
257     }
258
259
260     for (i = 0; i < 5; i++)
261     {
262         SFGAOF flags;
263         /* Native returns all flags no matter what we ask for */
264         flags = SFGAO_CANCOPY;
265         hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
266         flags &= SFGAO_testfor;
267         ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
268         ok(flags == (attrs[i]) ||
269            flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR), /* Win9x, NT4 */
270            "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
271
272         flags = SFGAO_testfor;
273         hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
274         flags &= SFGAO_testfor;
275         ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
276         ok(flags == attrs[i] ||
277            flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR), /* Win9x, NT4 */
278            "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
279     }
280
281     for (i=0;i<5;i++)
282         IMalloc_Free(ppM, idlArr[i]);
283 }
284
285 static void test_BindToObject(void)
286 {
287     HRESULT hr;
288     UINT cChars;
289     IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
290     SHITEMID emptyitem = { 0, { 0 } };
291     LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
292     WCHAR wszSystemDir[MAX_PATH];
293     char szSystemDir[MAX_PATH];
294     WCHAR wszMyComputer[] = { 
295         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
296         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
297
298     /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
299      * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
300      */
301     hr = SHGetDesktopFolder(&psfDesktop);
302     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
303     if (FAILED(hr)) return;
304     
305     hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
306     ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
307
308     hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
309     ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
310
311     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
312     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
313     if (FAILED(hr)) {
314         IShellFolder_Release(psfDesktop);
315         return;
316     }
317     
318     hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
319     ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
320     IShellFolder_Release(psfDesktop);
321     IMalloc_Free(ppM, pidlMyComputer);
322     if (FAILED(hr)) return;
323
324     hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
325     ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
326
327 #if 0
328     /* this call segfaults on 98SE */
329     hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
330     ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
331 #endif
332
333     cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
334     ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
335     if (cChars == 0 || cChars >= MAX_PATH) {
336         IShellFolder_Release(psfMyComputer);
337         return;
338     }
339     MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
340     
341     hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
342     ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
343     if (FAILED(hr)) {
344         IShellFolder_Release(psfMyComputer);
345         return;
346     }
347
348     hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
349     ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
350     IShellFolder_Release(psfMyComputer);
351     IMalloc_Free(ppM, pidlSystemDir);
352     if (FAILED(hr)) return;
353
354     hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
355     ok (hr == E_INVALIDARG, 
356         "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
357     
358 #if 0
359     /* this call segfaults on 98SE */
360     hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
361     ok (hr == E_INVALIDARG, 
362         "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
363 #endif
364
365     IShellFolder_Release(psfSystemDir);
366 }
367
368 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
369 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
370 {
371   size_t iLen;
372
373   if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
374     return NULL;
375
376   if (iLen)
377   {
378     lpszPath += iLen;
379     if (lpszPath[-1] != '\\')
380     {
381       *lpszPath++ = '\\';
382       *lpszPath = '\0';
383     }
384   }
385   return lpszPath;
386 }
387
388 static void test_GetDisplayName(void)
389 {
390     BOOL result;
391     HRESULT hr;
392     HANDLE hTestFile;
393     WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH];
394     char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
395     DWORD attr;
396     STRRET strret;
397     LPSHELLFOLDER psfDesktop, psfPersonal;
398     IUnknown *psfFile;
399     SHITEMID emptyitem = { 0, { 0 } };
400     LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
401     LPCITEMIDLIST pidlLast;
402     static const CHAR szFileName[] = "winetest.foo";
403     static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
404     static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
405
406     /* I'm trying to figure if there is a functional difference between calling
407      * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
408      * binding to the shellfolder. One thing I thought of was that perhaps 
409      * SHGetPathFromIDListW would be able to get the path to a file, which does
410      * not exist anymore, while the other method wouldn't. It turns out there's
411      * no functional difference in this respect.
412      */
413
414     if(!pSHGetSpecialFolderPathA) {
415         win_skip("SHGetSpecialFolderPathA is not available\n");
416         return;
417     }
418
419     /* First creating a directory in MyDocuments and a file in this directory. */
420     result = pSHGetSpecialFolderPathA(NULL, szTestDir, CSIDL_PERSONAL, FALSE);
421     ok(result, "SHGetSpecialFolderPathA failed! Last error: %u\n", GetLastError());
422     if (!result) return;
423
424     /* Use ANSI file functions so this works on Windows 9x */
425     lstrcatA(szTestDir, "\\winetest");
426     CreateDirectoryA(szTestDir, NULL);
427     attr=GetFileAttributesA(szTestDir);
428     if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
429     {
430         ok(0, "unable to create the '%s' directory\n", szTestDir);
431         return;
432     }
433
434     lstrcpyA(szTestFile, szTestDir);
435     lstrcatA(szTestFile, "\\");
436     lstrcatA(szTestFile, szFileName);
437     hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
438     ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
439     if (hTestFile == INVALID_HANDLE_VALUE) return;
440     CloseHandle(hTestFile);
441
442     /* Getting an itemidlist for the file. */
443     hr = SHGetDesktopFolder(&psfDesktop);
444     ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
445     if (FAILED(hr)) return;
446
447     MultiByteToWideChar(CP_ACP, 0, szTestFile, -1, wszTestFile, MAX_PATH);
448
449     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
450     ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
451     if (FAILED(hr)) {
452         IShellFolder_Release(psfDesktop);
453         return;
454     }
455
456     pidlLast = pILFindLastID(pidlTestFile);
457     ok(pidlLast->mkid.cb >=76 ||
458         broken(pidlLast->mkid.cb == 28) || /* W2K */
459         broken(pidlLast->mkid.cb == 40), /* Win9x, WinME */
460         "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
461     if (pidlLast->mkid.cb >= 28) {
462         ok(!lstrcmpA((CHAR*)&pidlLast->mkid.abID[12], szFileName),
463             "Filename should be stored as ansi-string at this position!\n");
464     }
465     /* WinXP and up store the filenames as both ANSI and UNICODE in the pidls */
466     if (pidlLast->mkid.cb >= 76) {
467         ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
468             "Filename should be stored as wchar-string at this position!\n");
469     }
470     
471     /* It seems as if we cannot bind to regular files on windows, but only directories. 
472      */
473     hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
474     todo_wine
475     ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
476         broken(SUCCEEDED(hr)), /* Win9x, W2K */
477         "hr = %08x\n", hr);
478     if (SUCCEEDED(hr)) {
479         IShellFolder_Release(psfFile);
480     }
481
482     if (!pSHBindToParent)
483     {
484         win_skip("SHBindToParent is missing\n");
485         DeleteFileA(szTestFile);
486         RemoveDirectoryA(szTestDir);
487         return;
488     }
489   
490     /* Some tests for IShellFolder::SetNameOf */
491     if (pSHGetFolderPathAndSubDirA)
492     {
493         hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
494         ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
495         if (SUCCEEDED(hr)) {
496             /* It's ok to use this fixed path. Call will fail anyway. */
497             WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
498             LPITEMIDLIST pidlNew;
499
500             /* The pidl returned through the last parameter of SetNameOf is a simple one. */
501             hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
502             ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
503             if (hr == S_OK)
504             {
505                 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
506                     "pidl returned from SetNameOf should be simple!\n");
507
508                 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
509                  * is implemented on top of SHFileOperation in WinXP. */
510                 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
511                         SHGDN_FORPARSING, NULL);
512                 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
513
514                 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
515                  * SHGDN flags specify an absolute path. */
516                 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
517                 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
518
519                 pILFree(pidlNew);
520             }
521
522             IShellFolder_Release(psfPersonal);
523         }
524     }
525     else
526         win_skip("Avoid needs of interaction on Win2k\n");
527
528     /* Deleting the file and the directory */
529     DeleteFileA(szTestFile);
530     RemoveDirectoryA(szTestDir);
531
532     /* SHGetPathFromIDListW still works, although the file is not present anymore. */
533     if (pSHGetPathFromIDListW)
534     {
535         result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
536         ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
537         ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
538     }
539
540     /* SHBindToParent fails, if called with a NULL PIDL. */
541     hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
542     ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
543
544     /* But it succeeds with an empty PIDL. */
545     hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
546     ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
547     ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
548     if (SUCCEEDED(hr)) 
549         IShellFolder_Release(psfPersonal);
550     
551     /* Binding to the folder and querying the display name of the file also works. */
552     hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast); 
553     ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
554     if (FAILED(hr)) {
555         IShellFolder_Release(psfDesktop);
556         return;
557     }
558
559     /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into 
560      * pidlTestFile (In accordance with MSDN). */
561     ok (pILFindLastID(pidlTestFile) == pidlLast, 
562                                 "SHBindToParent doesn't return the last id of the pidl param!\n");
563     
564     hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
565     ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
566     if (FAILED(hr)) {
567         IShellFolder_Release(psfDesktop);
568         IShellFolder_Release(psfPersonal);
569         return;
570     }
571
572     if (pStrRetToBufW)
573     {
574         hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
575         ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
576         ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
577     }
578     
579     IShellFolder_Release(psfDesktop);
580     IShellFolder_Release(psfPersonal);
581 }
582
583 static void test_CallForAttributes(void)
584 {
585     HKEY hKey;
586     LONG lResult;
587     HRESULT hr;
588     DWORD dwSize;
589     LPSHELLFOLDER psfDesktop;
590     LPITEMIDLIST pidlMyDocuments;
591     DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
592     static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
593     static const WCHAR wszCallForAttributes[] = { 
594         'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
595     static const WCHAR wszMyDocumentsKey[] = {
596         'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
597         '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
598         '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
599     WCHAR wszMyDocuments[] = {
600         ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
601         '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
602     
603     /* For the root of a namespace extension, the attributes are not queried by binding
604      * to the object and calling GetAttributesOf. Instead, the attributes are read from 
605      * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
606      *
607      * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
608      * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
609      * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
610      * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
611      */
612     hr = SHGetDesktopFolder(&psfDesktop);
613     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
614     if (FAILED(hr)) return;
615     
616     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL, 
617                                        &pidlMyDocuments, NULL);
618     ok (SUCCEEDED(hr) ||
619         broken(hr == E_INVALIDARG), /* Win95, NT4 */
620         "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
621     if (FAILED(hr)) {
622         IShellFolder_Release(psfDesktop);
623         return;
624     }
625
626     dwAttributes = 0xffffffff;
627     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, 
628                                       (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
629     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
630
631     /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
632     ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
633     ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
634     ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
635
636     /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
637      * key. So the test will return at this point, if run on wine. 
638      */
639     lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
640     ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
641     if (lResult != ERROR_SUCCESS) {
642         IMalloc_Free(ppM, pidlMyDocuments);
643         IShellFolder_Release(psfDesktop);
644         return;
645     }
646     
647     /* Query MyDocuments' Attributes value, to be able to restore it later. */
648     dwSize = sizeof(DWORD);
649     lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
650     ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
651     if (lResult != ERROR_SUCCESS) {
652         RegCloseKey(hKey);
653         IMalloc_Free(ppM, pidlMyDocuments);
654         IShellFolder_Release(psfDesktop);
655         return;
656     }
657
658     /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
659     dwSize = sizeof(DWORD);
660     lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL, 
661                               (LPBYTE)&dwOrigCallForAttributes, &dwSize);
662     ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
663     if (lResult != ERROR_SUCCESS) {
664         RegCloseKey(hKey);
665         IMalloc_Free(ppM, pidlMyDocuments);
666         IShellFolder_Release(psfDesktop);
667         return;
668     }
669     
670     /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and 
671      * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
672      * SFGAO_FILESYSTEM attributes. */
673     dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
674     RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
675     dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
676     RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD, 
677                    (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
678
679     /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by 
680      * GetAttributesOf. It seems that once there is a single attribute queried, for which
681      * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
682      * the flags in Attributes are ignored. 
683      */
684     dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
685     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, 
686                                       (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
687     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
688     if (SUCCEEDED(hr)) 
689         ok (dwAttributes == SFGAO_FILESYSTEM, 
690             "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n", 
691             dwAttributes);
692
693     /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
694     RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
695     RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD, 
696                    (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
697     RegCloseKey(hKey);
698     IMalloc_Free(ppM, pidlMyDocuments);
699     IShellFolder_Release(psfDesktop);
700 }
701
702 static void test_GetAttributesOf(void) 
703 {
704     HRESULT hr;
705     LPSHELLFOLDER psfDesktop, psfMyComputer;
706     SHITEMID emptyitem = { 0, { 0 } };
707     LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
708     LPITEMIDLIST pidlMyComputer;
709     DWORD dwFlags;
710     static const DWORD desktopFlags[] = {
711         /* WinXP */
712         SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR | SFGAO_FILESYSANCESTOR |
713         SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
714         /* Win2k */
715         SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_STREAM | SFGAO_FILESYSANCESTOR |
716         SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
717         /* WinMe, Win9x, WinNT*/
718         SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_FILESYSANCESTOR |
719         SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
720     };
721     static const DWORD myComputerFlags[] = {
722         /* WinXP */
723         SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET |
724         SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
725         /* Win2k */
726         SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_STREAM |
727         SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
728         /* WinMe, Win9x, WinNT */
729         SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
730         SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
731         /* Win95, WinNT when queried directly */
732         SFGAO_CANLINK | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
733         SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
734     };
735     WCHAR wszMyComputer[] = { 
736         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
737         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
738     char  cCurrDirA [MAX_PATH] = {0};
739     WCHAR cCurrDirW [MAX_PATH];
740     static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
741     IShellFolder *IDesktopFolder, *testIShellFolder;
742     ITEMIDLIST *newPIDL;
743     int len, i;
744     BOOL foundFlagsMatch;
745
746     hr = SHGetDesktopFolder(&psfDesktop);
747     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
748     if (FAILED(hr)) return;
749
750     /* The Desktop attributes can be queried with a single empty itemidlist, .. */
751     dwFlags = 0xffffffff;
752     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
753     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
754     for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
755          i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
756     {
757         if (desktopFlags[i] == dwFlags)
758             foundFlagsMatch = TRUE;
759     }
760     ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
761
762     /* .. or with no itemidlist at all. */
763     dwFlags = 0xffffffff;
764     hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
765     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
766     for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
767          i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
768     {
769         if (desktopFlags[i] == dwFlags)
770             foundFlagsMatch = TRUE;
771     }
772     ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
773    
774     /* Testing the attributes of the MyComputer shellfolder */
775     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
776     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
777     if (FAILED(hr)) {
778         IShellFolder_Release(psfDesktop);
779         return;
780     }
781
782     /* Windows sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
783      * folder object. It doesn't do this, if MyComputer is queried directly (see below).
784      */
785     dwFlags = 0xffffffff;
786     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
787     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
788     for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
789          i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
790     {
791         if ((myComputerFlags[i] | SFGAO_CANLINK) == dwFlags)
792             foundFlagsMatch = TRUE;
793     }
794     todo_wine
795     ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
796
797     hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
798     ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
799     IShellFolder_Release(psfDesktop);
800     IMalloc_Free(ppM, pidlMyComputer);
801     if (FAILED(hr)) return;
802
803     hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
804     todo_wine
805     ok (hr == E_INVALIDARG ||
806         broken(SUCCEEDED(hr)), /* W2K and earlier */
807         "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr);
808
809     dwFlags = 0xffffffff;
810     hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
811     ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr); 
812     for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
813          i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
814     {
815         if (myComputerFlags[i] == dwFlags)
816             foundFlagsMatch = TRUE;
817     }
818     todo_wine
819     ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
820
821     IShellFolder_Release(psfMyComputer);
822
823     GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
824     len = lstrlenA(cCurrDirA);
825
826     if (len == 0) {
827         win_skip("GetCurrentDirectoryA returned empty string. Skipping test_GetAttributesOf\n");
828         return;
829     }
830     if (len > 3 && cCurrDirA[len-1] == '\\')
831         cCurrDirA[len-1] = 0;
832
833     /* create test directory */
834     CreateFilesFolders();
835
836     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
837  
838     hr = SHGetDesktopFolder(&IDesktopFolder);
839     ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
840
841     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
842     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
843
844     hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
845     ok(hr == S_OK, "BindToObject failed %08x\n", hr);
846
847     IMalloc_Free(ppM, newPIDL);
848
849     /* get relative PIDL */
850     hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
851     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
852
853     /* test the shell attributes of the test directory using the relative PIDL */
854     dwFlags = SFGAO_FOLDER;
855     hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
856     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
857     ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
858
859     /* free memory */
860     IMalloc_Free(ppM, newPIDL);
861
862     /* append testdirectory name to path */
863     if (cCurrDirA[len-1] == '\\')
864         cCurrDirA[len-1] = 0;
865     lstrcatA(cCurrDirA, "\\testdir");
866     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
867
868     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
869     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
870
871     /* test the shell attributes of the test directory using the absolute PIDL */
872     dwFlags = SFGAO_FOLDER;
873     hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
874     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
875     ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
876
877     /* free memory */
878     IMalloc_Free(ppM, newPIDL);
879
880     IShellFolder_Release(testIShellFolder);
881
882     Cleanup();
883
884     IShellFolder_Release(IDesktopFolder);
885 }
886
887 static void test_SHGetPathFromIDList(void)
888 {
889     SHITEMID emptyitem = { 0, { 0 } };
890     LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
891     LPITEMIDLIST pidlMyComputer;
892     WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
893     BOOL result;
894     HRESULT hr;
895     LPSHELLFOLDER psfDesktop;
896     WCHAR wszMyComputer[] = { 
897         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
898         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
899     WCHAR wszFileName[MAX_PATH];
900     LPITEMIDLIST pidlTestFile;
901     HANDLE hTestFile;
902     STRRET strret;
903     static WCHAR wszTestFile[] = {
904         'w','i','n','e','t','e','s','t','.','f','o','o',0 };
905         HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
906         HMODULE hShell32;
907         LPITEMIDLIST pidlPrograms;
908
909     if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
910     {
911         win_skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
912         return;
913     }
914
915     /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
916     wszPath[0] = 'a';
917     wszPath[1] = '\0';
918     result = pSHGetPathFromIDListW(NULL, wszPath);
919     ok(!result, "Expected failure\n");
920     ok(!wszPath[0], "Expected empty string\n");
921
922     /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
923     result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
924     ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
925     if (!result) return;
926
927     /* Check if we are on Win9x */
928     SetLastError(0xdeadbeef);
929     lstrcmpiW(wszDesktop, wszDesktop);
930     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
931     {
932         win_skip("Most W-calls are not implemented\n");
933         return;
934     }
935
936     result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
937     ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
938     if (!result) return;
939     ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
940
941     /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
942     hr = SHGetDesktopFolder(&psfDesktop);
943     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
944     if (FAILED(hr)) return;
945
946     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
947     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
948     if (FAILED(hr)) {
949         IShellFolder_Release(psfDesktop);
950         return;
951     }
952
953     SetLastError(0xdeadbeef);
954     wszPath[0] = 'a';
955     wszPath[1] = '\0';
956     result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
957     ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
958     ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDListW shouldn't set last error! Last error: %u\n", GetLastError());
959     ok (!wszPath[0], "Expected empty path\n");
960     if (result) {
961         IShellFolder_Release(psfDesktop);
962         return;
963     }
964
965     IMalloc_Free(ppM, pidlMyComputer);
966
967     result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
968     ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
969     if (!result) {
970         IShellFolder_Release(psfDesktop);
971         return;
972     }
973     myPathAddBackslashW(wszFileName);
974     lstrcatW(wszFileName, wszTestFile);
975     hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
976     ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
977     if (hTestFile == INVALID_HANDLE_VALUE) {
978         IShellFolder_Release(psfDesktop);
979         return;
980     }
981     CloseHandle(hTestFile);
982
983     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
984     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
985     if (FAILED(hr)) {
986         IShellFolder_Release(psfDesktop);
987         DeleteFileW(wszFileName);
988         IMalloc_Free(ppM, pidlTestFile);
989         return;
990     }
991
992     /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
993      * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
994     hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
995     ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
996     IShellFolder_Release(psfDesktop);
997     DeleteFileW(wszFileName);
998     if (FAILED(hr)) {
999         IMalloc_Free(ppM, pidlTestFile);
1000         return;
1001     }
1002     if (pStrRetToBufW)
1003     {
1004         pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
1005         ok(0 == lstrcmpW(wszFileName, wszPath), 
1006            "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
1007            "returned incorrect path for file placed on desktop\n");
1008     }
1009
1010     result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
1011     ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
1012     IMalloc_Free(ppM, pidlTestFile);
1013     if (!result) return;
1014     ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
1015
1016
1017         /* Test if we can get the path from the start menu "program files" PIDL. */
1018     hShell32 = GetModuleHandleA("shell32");
1019     pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
1020
1021     hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
1022     ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
1023
1024     SetLastError(0xdeadbeef);
1025     result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
1026         IMalloc_Free(ppM, pidlPrograms);
1027     ok(result, "SHGetPathFromIDListW failed\n");
1028 }
1029
1030 static void test_EnumObjects_and_CompareIDs(void)
1031 {
1032     ITEMIDLIST *newPIDL;
1033     IShellFolder *IDesktopFolder, *testIShellFolder;
1034     char  cCurrDirA [MAX_PATH] = {0};
1035     static const CHAR cTestDirA[] = "\\testdir";
1036     WCHAR cTestDirW[MAX_PATH];
1037     int len;
1038     HRESULT hr;
1039
1040     GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1041     len = lstrlenA(cCurrDirA);
1042
1043     if(len == 0) {
1044         win_skip("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
1045         return;
1046     }
1047     if(cCurrDirA[len-1] == '\\')
1048         cCurrDirA[len-1] = 0;
1049
1050     lstrcatA(cCurrDirA, cTestDirA);
1051     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cTestDirW, MAX_PATH);
1052
1053     hr = SHGetDesktopFolder(&IDesktopFolder);
1054     ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1055
1056     CreateFilesFolders();
1057
1058     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
1059     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1060
1061     hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1062     ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1063
1064     test_EnumObjects(testIShellFolder);
1065
1066     IShellFolder_Release(testIShellFolder);
1067
1068     Cleanup();
1069
1070     IMalloc_Free(ppM, newPIDL);
1071
1072     IShellFolder_Release(IDesktopFolder);
1073 }
1074
1075 /* A simple implementation of an IPropertyBag, which returns fixed values for
1076  * 'Target' and 'Attributes' properties.
1077  */
1078 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
1079     void **ppvObject) 
1080 {
1081     if (!ppvObject)
1082         return E_INVALIDARG;
1083
1084     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
1085         *ppvObject = iface;
1086     } else {
1087         ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
1088         return E_NOINTERFACE;
1089     }
1090
1091     IPropertyBag_AddRef(iface);
1092     return S_OK;
1093 }
1094
1095 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
1096     return 2;
1097 }
1098
1099 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
1100     return 1;
1101 }
1102
1103 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
1104     VARIANT *pVar, IErrorLog *pErrorLog)
1105 {
1106     static const WCHAR wszTargetSpecialFolder[] = {
1107         'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1108     static const WCHAR wszTarget[] = {
1109         'T','a','r','g','e','t',0 };
1110     static const WCHAR wszAttributes[] = {
1111         'A','t','t','r','i','b','u','t','e','s',0 };
1112     static const WCHAR wszResolveLinkFlags[] = {
1113         'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1114        
1115     if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
1116         ok(V_VT(pVar) == VT_I4 ||
1117            broken(V_VT(pVar) == VT_BSTR),   /* Win2k */
1118            "Wrong variant type for 'TargetSpecialFolder' property!\n");
1119         return E_INVALIDARG;
1120     }
1121     
1122     if (!lstrcmpW(pszPropName, wszResolveLinkFlags)) 
1123     {
1124         ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1125         return E_INVALIDARG;
1126     }
1127
1128     if (!lstrcmpW(pszPropName, wszTarget)) {
1129         WCHAR wszPath[MAX_PATH];
1130         BOOL result;
1131         
1132         ok(V_VT(pVar) == VT_BSTR ||
1133            broken(V_VT(pVar) == VT_EMPTY),  /* Win2k */
1134            "Wrong variant type for 'Target' property!\n");
1135         if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
1136
1137         result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1138         ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1139         if (!result) return E_INVALIDARG;
1140
1141         V_BSTR(pVar) = SysAllocString(wszPath);
1142         return S_OK;
1143     }
1144
1145     if (!lstrcmpW(pszPropName, wszAttributes)) {
1146         ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1147         if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1148         V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1149                       SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1150         return S_OK;
1151     }
1152
1153     ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1154     return E_INVALIDARG;
1155 }
1156
1157 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1158     VARIANT *pVar)
1159 {
1160     ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1161     return E_NOTIMPL;
1162 }
1163     
1164 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1165     InitPropertyBag_IPropertyBag_QueryInterface,
1166     InitPropertyBag_IPropertyBag_AddRef,
1167     InitPropertyBag_IPropertyBag_Release,
1168     InitPropertyBag_IPropertyBag_Read,
1169     InitPropertyBag_IPropertyBag_Write
1170 };
1171
1172 static struct IPropertyBag InitPropertyBag = {
1173     &InitPropertyBag_IPropertyBagVtbl
1174 };
1175
1176 static void test_FolderShortcut(void) {
1177     IPersistPropertyBag *pPersistPropertyBag;
1178     IShellFolder *pShellFolder, *pDesktopFolder;
1179     IPersistFolder3 *pPersistFolder3;
1180     HRESULT hr;
1181     STRRET strret;
1182     WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1183     BOOL result;
1184     CLSID clsid;
1185     LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1186     HKEY hShellExtKey;
1187     WCHAR wszWineTestFolder[] = {
1188         ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1189         'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1190     WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1191         'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1192         'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1193         'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1194         'N','a','m','e','S','p','a','c','e','\\',
1195         '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1196         'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1197     
1198     WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1199     static const GUID CLSID_UnixDosFolder = 
1200         {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1201
1202     if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) {
1203         win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1204         return;
1205     }
1206
1207     if (!pSHGetFolderPathAndSubDirA)
1208     {
1209         win_skip("FolderShortcut test doesn't work on Win2k\n");
1210         return;
1211     }
1212
1213     /* These tests basically show, that CLSID_FolderShortcuts are initialized
1214      * via their IPersistPropertyBag interface. And that the target folder
1215      * is taken from the IPropertyBag's 'Target' property.
1216      */
1217     hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER, 
1218                           &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1219     if (hr == REGDB_E_CLASSNOTREG) {
1220         win_skip("CLSID_FolderShortcut is not implemented\n");
1221         return;
1222     }
1223     ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1224     if (FAILED(hr)) return;
1225
1226     hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1227     ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1228     if (FAILED(hr)) {
1229         IPersistPropertyBag_Release(pPersistPropertyBag);
1230         return;
1231     }
1232
1233     hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder, 
1234                                             (LPVOID*)&pShellFolder);
1235     IPersistPropertyBag_Release(pPersistPropertyBag);
1236     ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1237     if (FAILED(hr)) return;
1238
1239     hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1240     ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1241     if (FAILED(hr)) {
1242         IShellFolder_Release(pShellFolder);
1243         return;
1244     }
1245
1246     result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1247     ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1248     if (!result) return;
1249
1250     pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1251     ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1252
1253     hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1254     IShellFolder_Release(pShellFolder);
1255     ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1256     if (FAILED(hr)) return;
1257
1258     hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1259     ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1260     ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1261
1262     hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1263     ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1264     ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1265                     
1266     /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1267      * shell namespace. The target folder, read from the property bag above, remains untouched. 
1268      * The following tests show this: The itemidlist for some imaginary shellfolder object
1269      * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1270      * itemidlist, but GetDisplayNameOf still returns the path from above.
1271      */
1272     hr = SHGetDesktopFolder(&pDesktopFolder);
1273     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1274     if (FAILED(hr)) return;
1275
1276     /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop. 
1277      * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1278     RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1279     RegCloseKey(hShellExtKey);
1280     hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1281                                        &pidlWineTestFolder, NULL);
1282     RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1283     IShellFolder_Release(pDesktopFolder);
1284     ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1285     if (FAILED(hr)) return;
1286
1287     hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1288     ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1289     if (FAILED(hr)) {
1290         IPersistFolder3_Release(pPersistFolder3);
1291         pILFree(pidlWineTestFolder);
1292         return;
1293     }
1294
1295     hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1296     ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1297     ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1298         "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1299     pILFree(pidlCurrentFolder);
1300     pILFree(pidlWineTestFolder);
1301
1302     hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1303     IPersistFolder3_Release(pPersistFolder3);
1304     ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1305     if (FAILED(hr)) return;
1306
1307     hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1308     ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1309     if (FAILED(hr)) {
1310         IShellFolder_Release(pShellFolder);
1311         return;
1312     }
1313
1314     pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1315     ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1316
1317     /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1318      * but ShellFSFolders. */
1319     myPathAddBackslashW(wszDesktopPath);
1320     lstrcatW(wszDesktopPath, wszSomeSubFolder);
1321     if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1322         IShellFolder_Release(pShellFolder);
1323         return;
1324     }
1325     
1326     hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL, 
1327                                        &pidlSubFolder, NULL);
1328     RemoveDirectoryW(wszDesktopPath);
1329     ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1330     if (FAILED(hr)) {
1331         IShellFolder_Release(pShellFolder);
1332         return;
1333     }
1334
1335     hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1336                                    (LPVOID*)&pPersistFolder3);
1337     IShellFolder_Release(pShellFolder);
1338     pILFree(pidlSubFolder);
1339     ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1340     if (FAILED(hr))
1341         return;
1342
1343     /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1344      * a little bit and also allow CLSID_UnixDosFolder. */
1345     hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1346     ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1347     ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1348         "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1349
1350     IPersistFolder3_Release(pPersistFolder3);
1351 }
1352
1353 #include "pshpack1.h"
1354 struct FileStructA {
1355     BYTE  type;
1356     BYTE  dummy;
1357     DWORD dwFileSize;
1358     WORD  uFileDate;    /* In our current implementation this is */
1359     WORD  uFileTime;    /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1360     WORD  uFileAttribs;
1361     CHAR  szName[1];
1362 };
1363
1364 struct FileStructW {
1365     WORD  cbLen;        /* Length of this element. */
1366     BYTE  abFooBar1[6]; /* Beyond any recognition. */
1367     WORD  uDate;        /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1368     WORD  uTime;        /* (this is currently speculation) */
1369     WORD  uDate2;       /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1370     WORD  uTime2;       /* (this is currently speculation) */
1371     BYTE  abFooBar2[4]; /* Beyond any recognition. */
1372     WCHAR wszName[1];   /* The long filename in unicode. */
1373     /* Just for documentation: Right after the unicode string: */
1374     WORD  cbOffset;     /* FileStructW's offset from the beginning of the SHITMEID. 
1375                          * SHITEMID->cb == uOffset + cbLen */
1376 };
1377 #include "poppack.h"
1378
1379 static void test_ITEMIDLIST_format(void) {
1380     WCHAR wszPersonal[MAX_PATH];
1381     LPSHELLFOLDER psfDesktop, psfPersonal;
1382     LPITEMIDLIST pidlPersonal, pidlFile;
1383     HANDLE hFile;
1384     HRESULT hr;
1385     BOOL bResult;
1386     WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1387         { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1388     int i;
1389
1390     if (!pSHGetSpecialFolderPathW) return;
1391
1392     bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1393     ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1394     if (!bResult) return;
1395
1396     SetLastError(0xdeadbeef);
1397     bResult = SetCurrentDirectoryW(wszPersonal);
1398     if (!bResult && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
1399         win_skip("Most W-calls are not implemented\n");
1400         return;
1401     }
1402     ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1403     if (!bResult) return;
1404
1405     hr = SHGetDesktopFolder(&psfDesktop);
1406     ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1407     if (FAILED(hr)) return;
1408
1409     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1410     ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1411     if (FAILED(hr)) {
1412         IShellFolder_Release(psfDesktop);
1413         return;
1414     }
1415
1416     hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1417         (LPVOID*)&psfPersonal);
1418     IShellFolder_Release(psfDesktop);
1419     pILFree(pidlPersonal);
1420     ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1421     if (FAILED(hr)) return;
1422
1423     for (i=0; i<3; i++) {
1424         CHAR szFile[MAX_PATH];
1425         struct FileStructA *pFileStructA;
1426         WORD cbOffset;
1427
1428         WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1429
1430         hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1431         ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1432         if (hFile == INVALID_HANDLE_VALUE) {
1433             IShellFolder_Release(psfPersonal);
1434             return;
1435         }
1436         CloseHandle(hFile);
1437
1438         hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1439         DeleteFileW(wszFile[i]);
1440         ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1441         if (FAILED(hr)) {
1442             IShellFolder_Release(psfPersonal);
1443             return;
1444         }
1445
1446         pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1447         ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1448         ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1449         ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1450
1451         if (i < 2) /* First two file names are already in valid 8.3 format */
1452             ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1453         else
1454             /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1455              * can't implement this correctly, since unix filesystems don't support
1456              * this nasty short/long filename stuff. So we'll probably stay with our
1457              * current habbit of storing the long filename here, which seems to work
1458              * just fine. */
1459             todo_wine
1460             ok(pidlFile->mkid.abID[18] == '~' ||
1461                broken(pidlFile->mkid.abID[34] == '~'),  /* Win2k */
1462                "Should be derived 8.3 name!\n");
1463
1464         if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1465             ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0' ||
1466                broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1),    /* Win2k */
1467                 "Alignment byte, where there shouldn't be!\n");
1468
1469         if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1470             ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1471                 "There should be an alignment byte, but isn't!\n");
1472
1473         /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1474         cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1475         ok ((cbOffset >= sizeof(struct FileStructA) &&
1476             cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW)) ||
1477             broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1) ||     /* Win2k on short names */
1478             broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 12 + 1),  /* Win2k on long names */
1479             "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1480
1481         if (cbOffset >= sizeof(struct FileStructA) &&
1482             cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1483         {
1484             struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1485
1486             ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1487                 "FileStructW's offset and length should add up to the PIDL's length!\n");
1488
1489             if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1490                 /* Since we just created the file, time of creation,
1491                  * time of last access and time of last write access just be the same.
1492                  * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1493                  * after the first run. I do remember something with NTFS keeping the creation time
1494                  * if a file is deleted and then created again within a couple of seconds or so.
1495                  * Might be the reason. */
1496                 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1497                     pFileStructA->uFileTime == pFileStructW->uTime,
1498                     "Last write time should match creation time!\n");
1499
1500                 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1501                     pFileStructA->uFileTime == pFileStructW->uTime2,
1502                     "Last write time should match last access time!\n");
1503
1504                 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName) ||
1505                     !lstrcmpW(wszFile[i], (WCHAR *)(pFileStructW->abFooBar2 + 22)), /* Vista */
1506                     "The filename should be stored in unicode at this position!\n");
1507             }
1508         }
1509
1510         pILFree(pidlFile);
1511     }
1512 }
1513
1514 static void testSHGetFolderPathAndSubDirA(void)
1515 {
1516     HRESULT ret;
1517     BOOL delret;
1518     DWORD dwret;
1519     int i;
1520     static char wine[] = "wine";
1521     static char winetemp[] = "wine\\temp";
1522     static char appdata[MAX_PATH];
1523     static char testpath[MAX_PATH];
1524     static char toolongpath[MAX_PATH+1];
1525
1526     if(!pSHGetFolderPathA) {
1527         skip("SHGetFolderPathA not present!\n");
1528         return;
1529     }
1530     if(FAILED(pSHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata)))
1531     {
1532         skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1533         return;
1534     }
1535
1536     sprintf(testpath, "%s\\%s", appdata, winetemp);
1537     delret = RemoveDirectoryA(testpath);
1538     if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) ) {
1539         skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1540         return;
1541     }
1542
1543     sprintf(testpath, "%s\\%s", appdata, wine);
1544     delret = RemoveDirectoryA(testpath);
1545     if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) && (ERROR_FILE_NOT_FOUND != GetLastError())) {
1546         skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1547         return;
1548     }
1549     for(i=0; i< MAX_PATH; i++)
1550         toolongpath[i] = '0' + i % 10;
1551     toolongpath[MAX_PATH] = '\0';
1552
1553     /* test invalid second parameter */
1554     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | 0xff, NULL, SHGFP_TYPE_CURRENT, wine, testpath);
1555     ok(E_INVALIDARG == ret, "expected E_INVALIDARG, got  %x\n", ret);
1556
1557     /* test invalid forth parameter */
1558     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, 2, wine, testpath);
1559     switch(ret) {
1560         case S_OK: /* winvista */
1561             ok(!strncmp(appdata, testpath, strlen(appdata)),
1562                 "expected %s to start with %s\n", testpath, appdata);
1563             ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1564                 "expected %s to end with %s\n", testpath, winetemp);
1565             break;
1566         case E_INVALIDARG: /* winxp, win2k3 */
1567             break;
1568         default:
1569             ok(0, "expected S_OK or E_INVALIDARG, got  %x\n", ret);
1570     }
1571
1572     /* test fifth parameter */
1573     testpath[0] = '\0';
1574     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, NULL, testpath);
1575     ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1576     ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1577
1578     testpath[0] = '\0';
1579     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "", testpath);
1580     ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1581     ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1582
1583     testpath[0] = '\0';
1584     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "\\", testpath);
1585     ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1586     ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1587
1588     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, toolongpath, testpath);
1589     ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) == ret,
1590         "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), ret);
1591
1592     testpath[0] = '\0';
1593     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wine, NULL);
1594     ok((S_OK == ret) || (E_INVALIDARG == ret), "expected S_OK or E_INVALIDARG, got %x\n", ret);
1595
1596     /* test a not existing path */
1597     testpath[0] = '\0';
1598     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1599     ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == ret,
1600         "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), ret);
1601
1602     /* create a directory inside a not existing directory */
1603     testpath[0] = '\0';
1604     ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1605     ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1606     ok(!strncmp(appdata, testpath, strlen(appdata)),
1607         "expected %s to start with %s\n", testpath, appdata);
1608     ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1609         "expected %s to end with %s\n", testpath, winetemp);
1610     dwret = GetFileAttributes(testpath);
1611     ok(FILE_ATTRIBUTE_DIRECTORY | dwret, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret);
1612
1613     /* cleanup */
1614     sprintf(testpath, "%s\\%s", appdata, winetemp);
1615     RemoveDirectoryA(testpath);
1616     sprintf(testpath, "%s\\%s", appdata, wine);
1617     RemoveDirectoryA(testpath);
1618 }
1619
1620 static const char *wine_dbgstr_w(LPCWSTR str)
1621 {
1622     static char buf[512];
1623     if (!str)
1624         return "(null)";
1625     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
1626     return buf;
1627 }
1628
1629 static void test_LocalizedNames(void)
1630 {
1631     static char cCurrDirA[MAX_PATH];
1632     WCHAR cCurrDirW[MAX_PATH], tempbufW[25];
1633     IShellFolder *IDesktopFolder, *testIShellFolder;
1634     ITEMIDLIST *newPIDL;
1635     int len;
1636     HRESULT hr;
1637     static char resourcefile[MAX_PATH];
1638     DWORD res;
1639     HANDLE file;
1640     STRRET strret;
1641
1642     static const char desktopini_contents1[] =
1643         "[.ShellClassInfo]\r\n"
1644         "LocalizedResourceName=@";
1645     static const char desktopini_contents2[] =
1646         ",-1\r\n";
1647     static WCHAR foldernameW[] = {'t','e','s','t','f','o','l','d','e','r',0};
1648     static const WCHAR folderdisplayW[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1649
1650     /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1651     CreateDirectoryA(".\\testfolder", NULL);
1652
1653     SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM);
1654
1655     GetModuleFileNameA(NULL, resourcefile, MAX_PATH);
1656
1657     file = CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE, 0, NULL,
1658                          CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1659     ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %i\n", GetLastError());
1660     ok(WriteFile(file, desktopini_contents1, strlen(desktopini_contents1), &res, NULL) &&
1661        WriteFile(file, resourcefile, strlen(resourcefile), &res, NULL) &&
1662        WriteFile(file, desktopini_contents2, strlen(desktopini_contents2), &res, NULL),
1663        "WriteFile failed %i\n", GetLastError());
1664     CloseHandle(file);
1665
1666     /* get IShellFolder for parent */
1667     GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1668     len = lstrlenA(cCurrDirA);
1669
1670     if (len == 0) {
1671         trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1672         goto cleanup;
1673     }
1674     if(cCurrDirA[len-1] == '\\')
1675         cCurrDirA[len-1] = 0;
1676
1677     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
1678
1679     hr = SHGetDesktopFolder(&IDesktopFolder);
1680     ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1681
1682     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
1683     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1684
1685     hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1686     ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1687
1688     IMalloc_Free(ppM, newPIDL);
1689
1690     /* windows reads the display name from the resource */
1691     hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, foldernameW, NULL, &newPIDL, 0);
1692     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1693
1694     hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER, &strret);
1695     ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1696
1697     if (SUCCEEDED(hr) && pStrRetToBufW)
1698     {
1699         hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1700         ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1701         todo_wine
1702         ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1703             broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1704             "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1705     }
1706
1707     /* editing name is also read from the resource */
1708     hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FOREDITING, &strret);
1709     ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1710
1711     if (SUCCEEDED(hr) && pStrRetToBufW)
1712     {
1713         hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1714         ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1715         todo_wine
1716         ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1717             broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1718             "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1719     }
1720
1721     /* parsing name is unchanged */
1722     hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FORPARSING, &strret);
1723     ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1724
1725     if (SUCCEEDED(hr) && pStrRetToBufW)
1726     {
1727         hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1728         ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1729         ok (!lstrcmpiW(tempbufW, foldernameW), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1730     }
1731
1732     IShellFolder_Release(IDesktopFolder);
1733     IShellFolder_Release(testIShellFolder);
1734
1735     IMalloc_Free(ppM, newPIDL);
1736
1737 cleanup:
1738     DeleteFileA(".\\testfolder\\desktop.ini");
1739     SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM);
1740     RemoveDirectoryA(".\\testfolder");
1741 }
1742
1743
1744 START_TEST(shlfolder)
1745 {
1746     init_function_pointers();
1747     /* if OleInitialize doesn't get called, ParseDisplayName returns
1748        CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1749     OleInitialize(NULL);
1750
1751     test_ParseDisplayName();
1752     test_BindToObject();
1753     test_EnumObjects_and_CompareIDs();
1754     test_GetDisplayName();
1755     test_GetAttributesOf();
1756     test_SHGetPathFromIDList();
1757     test_CallForAttributes();
1758     test_FolderShortcut();
1759     test_ITEMIDLIST_format();
1760     if(pSHGetFolderPathAndSubDirA)
1761         testSHGetFolderPathAndSubDirA();
1762     else
1763         skip("SHGetFolderPathAndSubDirA not present\n");
1764     test_LocalizedNames();
1765
1766     OleUninitialize();
1767 }