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