kernel32: GlobalMemoryStatusEx: return the size of physical memory + swapsize in...
[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 BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
47 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
48 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
49 static void (WINAPI *pILFree)(LPITEMIDLIST);
50 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
51
52 static void init_function_pointers(void)
53 {
54     HMODULE hmod;
55     HRESULT hr;
56
57     hmod = GetModuleHandleA("shell32.dll");
58     if(hmod)
59     {
60         pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
61         pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
62         pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
63         pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
64         pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
65     }
66
67     hmod = GetModuleHandleA("shlwapi.dll");
68     if(hmod)
69     {
70         pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
71     }
72
73     hr = SHGetMalloc(&ppM);
74     ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
75 }
76
77 static void test_ParseDisplayName(void)
78 {
79     HRESULT hr;
80     IShellFolder *IDesktopFolder;
81     static const char *cNonExistDir1A = "c:\\nonexist_subdir";
82     static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
83     DWORD res;
84     WCHAR cTestDirW [MAX_PATH] = {0};
85     ITEMIDLIST *newPIDL;
86     BOOL bRes;
87
88     hr = SHGetDesktopFolder(&IDesktopFolder);
89     if(hr != S_OK) return;
90
91     res = GetFileAttributesA(cNonExistDir1A);
92     if(res != INVALID_FILE_ATTRIBUTES) return;
93
94     MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
95     hr = IShellFolder_ParseDisplayName(IDesktopFolder, 
96         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
97     ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL), 
98         "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
99
100     res = GetFileAttributesA(cNonExistDir2A);
101     if(res != INVALID_FILE_ATTRIBUTES) return;
102
103     MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
104     hr = IShellFolder_ParseDisplayName(IDesktopFolder, 
105         NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
106     ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG), 
107         "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
108
109     /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
110      * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
111      * out it doesn't. The magic seems to happen in the file dialogs, then. */
112     if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
113     
114     bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
115     ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
116     if (!bRes) goto finished;
117
118     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
119     ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
120     if (FAILED(hr)) goto finished;
121
122     ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
123        "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
124     IMalloc_Free(ppM, newPIDL);
125     
126 finished:
127     IShellFolder_Release(IDesktopFolder);
128 }
129
130 /* creates a file with the specified name for tests */
131 static void CreateTestFile(const CHAR *name)
132 {
133     HANDLE file;
134     DWORD written;
135
136     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
137     if (file != INVALID_HANDLE_VALUE)
138     {
139         WriteFile(file, name, strlen(name), &written, NULL);
140         WriteFile(file, "\n", strlen("\n"), &written, NULL);
141         CloseHandle(file);
142     }
143 }
144
145
146 /* initializes the tests */
147 static void CreateFilesFolders(void)
148 {
149     CreateDirectoryA(".\\testdir", NULL);
150     CreateDirectoryA(".\\testdir\\test.txt", NULL);
151     CreateTestFile  (".\\testdir\\test1.txt ");
152     CreateTestFile  (".\\testdir\\test2.txt ");
153     CreateTestFile  (".\\testdir\\test3.txt ");
154     CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
155     CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
156 }
157
158 /* cleans after tests */
159 static void Cleanup(void)
160 {
161     DeleteFileA(".\\testdir\\test1.txt");
162     DeleteFileA(".\\testdir\\test2.txt");
163     DeleteFileA(".\\testdir\\test3.txt");
164     RemoveDirectoryA(".\\testdir\\test.txt");
165     RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
166     RemoveDirectoryA(".\\testdir\\testdir2");
167     RemoveDirectoryA(".\\testdir");
168 }
169
170
171 /* perform test */
172 static void test_EnumObjects(IShellFolder *iFolder)
173 {
174     IEnumIDList *iEnumList;
175     LPITEMIDLIST newPIDL, idlArr[10];
176     ULONG NumPIDLs;
177     int i=0, j;
178     HRESULT hr;
179
180     static const WORD iResults [5][5] =
181     {
182         { 0,-1,-1,-1,-1},
183         { 1, 0,-1,-1,-1},
184         { 1, 1, 0,-1,-1},
185         { 1, 1, 1, 0,-1},
186         { 1, 1, 1, 1, 0}
187     };
188
189 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
190     /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
191     static const ULONG attrs[5] =
192     {
193         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
194         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
195         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
196         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
197         SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
198     };
199
200     hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
201     ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
202
203     /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
204      * the filesystem shellfolders return S_OK even if less than 'celt' items are
205      * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
206      * only ever returns a single entry per call. */
207     while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK) 
208         i += NumPIDLs;
209     ok (i == 5, "i: %d\n", i);
210
211     hr = IEnumIDList_Release(iEnumList);
212     ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
213     
214     /* Sort them first in case of wrong order from system */
215     for (i=0;i<5;i++) for (j=0;j<5;j++)
216         if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
217         {
218             newPIDL = idlArr[i];
219             idlArr[i] = idlArr[j];
220             idlArr[j] = newPIDL;
221         }
222             
223     for (i=0;i<5;i++) for (j=0;j<5;j++)
224     {
225         hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
226         ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
227     }
228
229
230     for (i = 0; i < 5; i++)
231     {
232         SFGAOF flags;
233         /* Native returns all flags no matter what we ask for */
234         flags = SFGAO_CANCOPY;
235         hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
236         flags &= SFGAO_testfor;
237         ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
238         ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
239
240         flags = SFGAO_testfor;
241         hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
242         flags &= SFGAO_testfor;
243         ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
244         ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
245     }
246
247     for (i=0;i<5;i++)
248         IMalloc_Free(ppM, idlArr[i]);
249 }
250
251 static void test_BindToObject(void)
252 {
253     HRESULT hr;
254     UINT cChars;
255     IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
256     SHITEMID emptyitem = { 0, { 0 } };
257     LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
258     WCHAR wszSystemDir[MAX_PATH];
259     char szSystemDir[MAX_PATH];
260     WCHAR wszMyComputer[] = { 
261         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
262         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
263
264     /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
265      * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
266      */
267     hr = SHGetDesktopFolder(&psfDesktop);
268     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
269     if (FAILED(hr)) return;
270     
271     hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
272     ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
273
274     hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
275     ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
276
277     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
278     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
279     if (FAILED(hr)) {
280         IShellFolder_Release(psfDesktop);
281         return;
282     }
283     
284     hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
285     ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
286     IShellFolder_Release(psfDesktop);
287     IMalloc_Free(ppM, pidlMyComputer);
288     if (FAILED(hr)) return;
289
290     hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
291     ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
292
293 #if 0
294     /* this call segfaults on 98SE */
295     hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
296     ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
297 #endif
298
299     cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
300     ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
301     if (cChars == 0 || cChars >= MAX_PATH) {
302         IShellFolder_Release(psfMyComputer);
303         return;
304     }
305     MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
306     
307     hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
308     ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
309     if (FAILED(hr)) {
310         IShellFolder_Release(psfMyComputer);
311         return;
312     }
313
314     hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
315     ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
316     IShellFolder_Release(psfMyComputer);
317     IMalloc_Free(ppM, pidlSystemDir);
318     if (FAILED(hr)) return;
319
320     hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
321     ok (hr == E_INVALIDARG, 
322         "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
323     
324 #if 0
325     /* this call segfaults on 98SE */
326     hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
327     ok (hr == E_INVALIDARG, 
328         "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
329 #endif
330
331     IShellFolder_Release(psfSystemDir);
332 }
333   
334 static void test_GetDisplayName(void)
335 {
336     BOOL result;
337     HRESULT hr;
338     HANDLE hTestFile;
339     WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
340     char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
341     DWORD attr;
342     STRRET strret;
343     LPSHELLFOLDER psfDesktop, psfPersonal;
344     IUnknown *psfFile;
345     SHITEMID emptyitem = { 0, { 0 } };
346     LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
347     LPCITEMIDLIST pidlLast;
348     static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
349     static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
350
351     /* I'm trying to figure if there is a functional difference between calling
352      * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
353      * binding to the shellfolder. One thing I thought of was that perhaps 
354      * SHGetPathFromIDList would be able to get the path to a file, which does
355      * not exist anymore, while the other method would'nt. It turns out there's
356      * no functional difference in this respect.
357      */
358
359     if(!pSHGetSpecialFolderPathW) return;
360
361     /* First creating a directory in MyDocuments and a file in this directory. */
362     result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
363     ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
364     if (!result) return;
365
366     PathAddBackslashW(wszTestDir);
367     lstrcatW(wszTestDir, wszDirName);
368     /* Use ANSI file functions so this works on Windows 9x */
369     WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
370     CreateDirectoryA(szTestDir, NULL);
371     attr=GetFileAttributesA(szTestDir);
372     if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
373     {
374         ok(0, "unable to create the '%s' directory\n", szTestDir);
375         return;
376     }
377
378     lstrcpyW(wszTestFile, wszTestDir);
379     PathAddBackslashW(wszTestFile);
380     lstrcatW(wszTestFile, wszFileName);
381     WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
382
383     hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
384     ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
385     if (hTestFile == INVALID_HANDLE_VALUE) return;
386     CloseHandle(hTestFile);
387
388     /* Getting an itemidlist for the file. */
389     hr = SHGetDesktopFolder(&psfDesktop);
390     ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
391     if (FAILED(hr)) return;
392
393     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
394     ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
395     if (FAILED(hr)) {
396         IShellFolder_Release(psfDesktop);
397         return;
398     }
399
400     /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
401     pidlLast = pILFindLastID(pidlTestFile);
402     ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
403     if (pidlLast->mkid.cb >= 76) {
404         ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
405             "WinXP stores the filename as a wchar-string at this position!\n");
406     }
407     
408     /* It seems as if we cannot bind to regular files on windows, but only directories. 
409      */
410     hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
411     todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
412     if (SUCCEEDED(hr)) {
413         IShellFolder_Release(psfFile);
414     }
415   
416     /* Some tests for IShellFolder::SetNameOf */
417     hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
418     ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
419     if (SUCCEEDED(hr)) {
420         /* It's ok to use this fixed path. Call will fail anyway. */
421         WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
422         LPITEMIDLIST pidlNew;
423
424         /* The pidl returned through the last parameter of SetNameOf is a simple one. */
425         hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
426         ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
427         ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0, 
428             "pidl returned from SetNameOf should be simple!\n");
429
430         /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
431          * is implemented on top of SHFileOperation in WinXP. */
432         hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename, 
433                 SHGDN_FORPARSING, NULL);
434         ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
435
436         /* Rename the file back to its original name. SetNameOf ignores the fact, that the
437          * SHGDN flags specify an absolute path. */
438         hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
439         ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
440
441         pILFree(pidlNew);
442         IShellFolder_Release(psfPersonal);
443     }
444
445     /* Deleting the file and the directory */
446     DeleteFileA(szTestFile);
447     RemoveDirectoryA(szTestDir);
448
449     /* SHGetPathFromIDListW still works, although the file is not present anymore. */
450     result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
451     ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
452     ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
453
454     if(!pSHBindToParent) return;
455
456     /* SHBindToParent fails, if called with a NULL PIDL. */
457     hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
458     ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
459
460     /* But it succeeds with an empty PIDL. */
461     hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
462     ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
463     ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
464     if (SUCCEEDED(hr)) 
465         IShellFolder_Release(psfPersonal);
466     
467     /* Binding to the folder and querying the display name of the file also works. */
468     hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast); 
469     ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
470     if (FAILED(hr)) {
471         IShellFolder_Release(psfDesktop);
472         return;
473     }
474
475     /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into 
476      * pidlTestFile (In accordance with MSDN). */
477     ok (pILFindLastID(pidlTestFile) == pidlLast, 
478                                 "SHBindToParent doesn't return the last id of the pidl param!\n");
479     
480     hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
481     ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
482     if (FAILED(hr)) {
483         IShellFolder_Release(psfDesktop);
484         IShellFolder_Release(psfPersonal);
485         return;
486     }
487
488     if (pStrRetToBufW)
489     {
490         hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
491         ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
492         ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
493     }
494     
495     IShellFolder_Release(psfDesktop);
496     IShellFolder_Release(psfPersonal);
497 }
498
499 static void test_CallForAttributes(void)
500 {
501     HKEY hKey;
502     LONG lResult;
503     HRESULT hr;
504     DWORD dwSize;
505     LPSHELLFOLDER psfDesktop;
506     LPITEMIDLIST pidlMyDocuments;
507     DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
508     static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
509     static const WCHAR wszCallForAttributes[] = { 
510         'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
511     static const WCHAR wszMyDocumentsKey[] = {
512         'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
513         '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
514         '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
515     WCHAR wszMyDocuments[] = {
516         ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
517         '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
518     
519     /* For the root of a namespace extension, the attributes are not queried by binding
520      * to the object and calling GetAttributesOf. Instead, the attributes are read from 
521      * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
522      *
523      * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
524      * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
525      * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
526      * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
527      */
528     hr = SHGetDesktopFolder(&psfDesktop);
529     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
530     if (FAILED(hr)) return;
531     
532     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL, 
533                                        &pidlMyDocuments, NULL);
534     ok (SUCCEEDED(hr), 
535         "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
536     if (FAILED(hr)) {
537         IShellFolder_Release(psfDesktop);
538         return;
539     }
540
541     dwAttributes = 0xffffffff;
542     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, 
543                                       (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
544     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
545
546     /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
547     ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
548     ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
549     ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
550
551     /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
552      * key. So the test will return at this point, if run on wine. 
553      */
554     lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
555     ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
556     if (lResult != ERROR_SUCCESS) {
557         IMalloc_Free(ppM, pidlMyDocuments);
558         IShellFolder_Release(psfDesktop);
559         return;
560     }
561     
562     /* Query MyDocuments' Attributes value, to be able to restore it later. */
563     dwSize = sizeof(DWORD);
564     lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
565     ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
566     if (lResult != ERROR_SUCCESS) {
567         RegCloseKey(hKey);
568         IMalloc_Free(ppM, pidlMyDocuments);
569         IShellFolder_Release(psfDesktop);
570         return;
571     }
572
573     /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
574     dwSize = sizeof(DWORD);
575     lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL, 
576                               (LPBYTE)&dwOrigCallForAttributes, &dwSize);
577     ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
578     if (lResult != ERROR_SUCCESS) {
579         RegCloseKey(hKey);
580         IMalloc_Free(ppM, pidlMyDocuments);
581         IShellFolder_Release(psfDesktop);
582         return;
583     }
584     
585     /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and 
586      * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
587      * SFGAO_FILESYSTEM attributes. */
588     dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
589     RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
590     dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
591     RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD, 
592                    (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
593
594     /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by 
595      * GetAttributesOf. It seems that once there is a single attribute queried, for which
596      * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
597      * the flags in Attributes are ignored. 
598      */
599     dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
600     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, 
601                                       (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
602     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
603     if (SUCCEEDED(hr)) 
604         ok (dwAttributes == SFGAO_FILESYSTEM, 
605             "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n", 
606             dwAttributes);
607
608     /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
609     RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
610     RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD, 
611                    (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
612     RegCloseKey(hKey);
613     IMalloc_Free(ppM, pidlMyDocuments);
614     IShellFolder_Release(psfDesktop);
615 }
616
617 static void test_GetAttributesOf(void) 
618 {
619     HRESULT hr;
620     LPSHELLFOLDER psfDesktop, psfMyComputer;
621     SHITEMID emptyitem = { 0, { 0 } };
622     LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
623     LPITEMIDLIST pidlMyComputer;
624     DWORD dwFlags;
625     static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
626         SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
627         SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
628     static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
629         SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
630         SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
631     WCHAR wszMyComputer[] = { 
632         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
633         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
634     char  cCurrDirA [MAX_PATH] = {0};
635     WCHAR cCurrDirW [MAX_PATH];
636     static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
637     static const WCHAR cBackSlash[] = {'\\',0};
638     IShellFolder *IDesktopFolder, *testIShellFolder;
639     ITEMIDLIST *newPIDL;
640     int len;
641
642     hr = SHGetDesktopFolder(&psfDesktop);
643     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
644     if (FAILED(hr)) return;
645
646     /* The Desktop attributes can be queried with a single empty itemidlist, .. */
647     dwFlags = 0xffffffff;
648     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
649     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
650     ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n", 
651         dwFlags, dwDesktopFlags);
652
653     /* .. or with no itemidlist at all. */
654     dwFlags = 0xffffffff;
655     hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
656     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
657     ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n", 
658         dwFlags, dwDesktopFlags);
659    
660     /* Testing the attributes of the MyComputer shellfolder */
661     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
662     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
663     if (FAILED(hr)) {
664         IShellFolder_Release(psfDesktop);
665         return;
666     }
667
668     /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop 
669      * folder object. It doesn't do this, if MyComputer is queried directly (see below).
670      * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
671      * should create a link to the original data". You can't create links on MyComputer on
672      * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
673      * depends on this bug, we probably shouldn't imitate it.
674      */
675     dwFlags = 0xffffffff;
676     hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
677     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
678     ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags, 
679                     "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
680
681     hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
682     ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
683     IShellFolder_Release(psfDesktop);
684     IMalloc_Free(ppM, pidlMyComputer);
685     if (FAILED(hr)) return;
686
687     hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
688     todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
689
690     dwFlags = 0xffffffff;
691     hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
692     ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr); 
693     todo_wine { ok (dwFlags == dwMyComputerFlags, 
694                     "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
695
696     IShellFolder_Release(psfMyComputer);
697
698     /* create test directory */
699     CreateFilesFolders();
700
701     GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
702     len = lstrlenA(cCurrDirA);
703
704     if (len == 0) {
705         trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
706         return;
707     }
708     if(cCurrDirA[len-1] == '\\')
709         cCurrDirA[len-1] = 0;
710
711     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
712  
713     hr = SHGetDesktopFolder(&IDesktopFolder);
714     ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
715
716     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
717     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
718
719     hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
720     ok(hr == S_OK, "BindToObject failed %08x\n", hr);
721
722     IMalloc_Free(ppM, newPIDL);
723
724     /* get relative PIDL */
725     hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
726     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
727
728     /* test the shell attributes of the test directory using the relative PIDL */
729     dwFlags = SFGAO_FOLDER;
730     hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
731     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
732     ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
733
734     /* free memory */
735     IMalloc_Free(ppM, newPIDL);
736
737     /* append testdirectory name to path */
738     lstrcatW(cCurrDirW, cBackSlash);
739     lstrcatW(cCurrDirW, cTestDirW);
740
741     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
742     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
743
744     /* test the shell attributes of the test directory using the absolute PIDL */
745     dwFlags = SFGAO_FOLDER;
746     hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
747     ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
748     ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
749         
750     /* free memory */
751     IMalloc_Free(ppM, newPIDL);
752
753     IShellFolder_Release(testIShellFolder);
754
755     Cleanup();
756
757     IShellFolder_Release(IDesktopFolder);
758 }    
759
760 static void test_SHGetPathFromIDList(void)
761 {
762     SHITEMID emptyitem = { 0, { 0 } };
763     LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
764     LPITEMIDLIST pidlMyComputer;
765     WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
766     BOOL result;
767     HRESULT hr;
768     LPSHELLFOLDER psfDesktop;
769     WCHAR wszMyComputer[] = { 
770         ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
771         'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
772     WCHAR wszFileName[MAX_PATH];
773     LPITEMIDLIST pidlTestFile;
774     HANDLE hTestFile;
775     STRRET strret;
776     static WCHAR wszTestFile[] = {
777         'w','i','n','e','t','e','s','t','.','f','o','o',0 };
778         HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
779         HMODULE hShell32;
780         LPITEMIDLIST pidlPrograms;
781
782     if(!pSHGetSpecialFolderPathW) return;
783
784     /* Calling SHGetPathFromIDList with no pidl should return the empty string */
785     wszPath[0] = 'a';
786     wszPath[1] = '\0';
787     result = SHGetPathFromIDListW(NULL, wszPath);
788     ok(!result, "Expected failure\n");
789     ok(!wszPath[0], "Expected empty string\n");
790
791     /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
792     result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
793     ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
794     if (!result) return;
795     
796     result = SHGetPathFromIDListW(pidlEmpty, wszPath);
797     ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
798     if (!result) return;
799     ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
800
801     /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
802     hr = SHGetDesktopFolder(&psfDesktop);
803     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
804     if (FAILED(hr)) return;
805
806     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
807     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
808     if (FAILED(hr)) {
809         IShellFolder_Release(psfDesktop);
810         return;
811     }
812
813     SetLastError(0xdeadbeef);
814     wszPath[0] = 'a';
815     wszPath[1] = '\0';
816     result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
817     ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
818     ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %u\n", GetLastError());
819     ok (!wszPath[0], "Expected empty path\n");
820     if (result) {
821         IShellFolder_Release(psfDesktop);
822         return;
823     }
824
825     IMalloc_Free(ppM, pidlMyComputer);
826
827     result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
828     ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
829     if (!result) {
830         IShellFolder_Release(psfDesktop);
831         return;
832     }
833     PathAddBackslashW(wszFileName);
834     lstrcatW(wszFileName, wszTestFile);
835     hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
836     ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
837     if (hTestFile == INVALID_HANDLE_VALUE) {
838         IShellFolder_Release(psfDesktop);
839         return;
840     }
841     CloseHandle(hTestFile);
842
843     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
844     ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
845     if (FAILED(hr)) {
846         IShellFolder_Release(psfDesktop);
847         DeleteFileW(wszFileName);
848         IMalloc_Free(ppM, pidlTestFile);
849         return;
850     }
851
852     /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
853      * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
854     hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
855     ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
856     IShellFolder_Release(psfDesktop);
857     DeleteFileW(wszFileName);
858     if (FAILED(hr)) {
859         IMalloc_Free(ppM, pidlTestFile);
860         return;
861     }
862     if (pStrRetToBufW)
863     {
864         pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
865         ok(0 == lstrcmpW(wszFileName, wszPath), 
866            "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
867            "returned incorrect path for file placed on desktop\n");
868     }
869
870     result = SHGetPathFromIDListW(pidlTestFile, wszPath);
871     ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
872     IMalloc_Free(ppM, pidlTestFile);
873     if (!result) return;
874     ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
875
876
877         /* Test if we can get the path from the start menu "program files" PIDL. */
878     hShell32 = GetModuleHandleA("shell32");
879     pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
880
881     hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
882     ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
883
884     SetLastError(0xdeadbeef);
885     result = SHGetPathFromIDListW(pidlPrograms, wszPath);
886         IMalloc_Free(ppM, pidlPrograms);
887     ok(result, "SHGetPathFromIDList failed\n");
888 }
889
890 static void test_EnumObjects_and_CompareIDs(void)
891 {
892     ITEMIDLIST *newPIDL;
893     IShellFolder *IDesktopFolder, *testIShellFolder;
894     char  cCurrDirA [MAX_PATH] = {0};
895     WCHAR cCurrDirW [MAX_PATH];
896     static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
897     int len;
898     HRESULT hr;
899
900     GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
901     len = lstrlenA(cCurrDirA);
902
903     if(len == 0) {
904         trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
905         return;
906     }
907     if(cCurrDirA[len-1] == '\\')
908         cCurrDirA[len-1] = 0;
909
910     MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
911     lstrcatW(cCurrDirW, cTestDirW);
912
913     hr = SHGetDesktopFolder(&IDesktopFolder);
914     ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
915
916     CreateFilesFolders();
917
918     hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
919     ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
920
921     hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
922     ok(hr == S_OK, "BindToObject failed %08x\n", hr);
923
924     test_EnumObjects(testIShellFolder);
925
926     IShellFolder_Release(testIShellFolder);
927
928     Cleanup();
929
930     IMalloc_Free(ppM, newPIDL);
931
932     IShellFolder_Release(IDesktopFolder);
933 }
934
935 /* A simple implementation of an IPropertyBag, which returns fixed values for
936  * 'Target' and 'Attributes' properties.
937  */
938 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
939     void **ppvObject) 
940 {
941     if (!ppvObject)
942         return E_INVALIDARG;
943
944     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
945         *ppvObject = iface;
946     } else {
947         ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
948         return E_NOINTERFACE;
949     }
950
951     IPropertyBag_AddRef(iface);
952     return S_OK;
953 }
954
955 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
956     return 2;
957 }
958
959 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
960     return 1;
961 }
962
963 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
964     VARIANT *pVar, IErrorLog *pErrorLog)
965 {
966     static const WCHAR wszTargetSpecialFolder[] = {
967         'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
968     static const WCHAR wszTarget[] = {
969         'T','a','r','g','e','t',0 };
970     static const WCHAR wszAttributes[] = {
971         'A','t','t','r','i','b','u','t','e','s',0 };
972     static const WCHAR wszResolveLinkFlags[] = {
973         'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
974        
975     if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
976         ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
977         return E_INVALIDARG;
978     }
979     
980     if (!lstrcmpW(pszPropName, wszResolveLinkFlags)) 
981     {
982         ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
983         return E_INVALIDARG;
984     }
985
986     if (!lstrcmpW(pszPropName, wszTarget)) {
987         WCHAR wszPath[MAX_PATH];
988         BOOL result;
989         
990         ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
991         if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
992
993         result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
994         ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
995         if (!result) return E_INVALIDARG;
996
997         V_BSTR(pVar) = SysAllocString(wszPath);
998         return S_OK;
999     }
1000
1001     if (!lstrcmpW(pszPropName, wszAttributes)) {
1002         ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1003         if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1004         V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1005                       SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1006         return S_OK;
1007     }
1008
1009     ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1010     return E_INVALIDARG;
1011 }
1012
1013 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1014     VARIANT *pVar)
1015 {
1016     ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1017     return E_NOTIMPL;
1018 }
1019     
1020 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1021     InitPropertyBag_IPropertyBag_QueryInterface,
1022     InitPropertyBag_IPropertyBag_AddRef,
1023     InitPropertyBag_IPropertyBag_Release,
1024     InitPropertyBag_IPropertyBag_Read,
1025     InitPropertyBag_IPropertyBag_Write
1026 };
1027
1028 static struct IPropertyBag InitPropertyBag = {
1029     &InitPropertyBag_IPropertyBagVtbl
1030 };
1031
1032 static void test_FolderShortcut(void) {
1033     IPersistPropertyBag *pPersistPropertyBag;
1034     IShellFolder *pShellFolder, *pDesktopFolder;
1035     IPersistFolder3 *pPersistFolder3;
1036     HRESULT hr;
1037     STRRET strret;
1038     WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1039     BOOL result;
1040     CLSID clsid;
1041     LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1042     HKEY hShellExtKey;
1043     WCHAR wszWineTestFolder[] = {
1044         ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1045         'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1046     WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1047         'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1048         'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1049         'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1050         'N','a','m','e','S','p','a','c','e','\\',
1051         '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1052         'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1053     
1054     WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1055     static const GUID CLSID_UnixDosFolder = 
1056         {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1057
1058     if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1059    
1060     /* These tests basically show, that CLSID_FolderShortcuts are initialized
1061      * via their IPersistPropertyBag interface. And that the target folder
1062      * is taken from the IPropertyBag's 'Target' property.
1063      */
1064     hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER, 
1065                           &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1066     ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1067     if (FAILED(hr)) return;
1068
1069     hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1070     ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1071     if (FAILED(hr)) {
1072         IPersistPropertyBag_Release(pPersistPropertyBag);
1073         return;
1074     }
1075     
1076     hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder, 
1077                                             (LPVOID*)&pShellFolder);
1078     IPersistPropertyBag_Release(pPersistPropertyBag);
1079     ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1080     if (FAILED(hr)) return;
1081
1082     hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1083     ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1084     if (FAILED(hr)) {
1085         IShellFolder_Release(pShellFolder);
1086         return;
1087     }
1088
1089     result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1090     ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1091     if (!result) return;
1092
1093     pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1094     ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1095
1096     hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1097     IShellFolder_Release(pShellFolder);
1098     ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1099     if (FAILED(hr)) return;
1100
1101     hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1102     ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1103     ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1104
1105     hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1106     ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1107     ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1108                     
1109     /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1110      * shell namespace. The target folder, read from the property bag above, remains untouched. 
1111      * The following tests show this: The itemidlist for some imaginary shellfolder object
1112      * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1113      * itemidlist, but GetDisplayNameOf still returns the path from above.
1114      */
1115     hr = SHGetDesktopFolder(&pDesktopFolder);
1116     ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1117     if (FAILED(hr)) return;
1118
1119     /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop. 
1120      * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1121     RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1122     RegCloseKey(hShellExtKey);
1123     hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1124                                        &pidlWineTestFolder, NULL);
1125     RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1126     IShellFolder_Release(pDesktopFolder);
1127     ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1128     if (FAILED(hr)) return;
1129
1130     hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1131     ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1132     if (FAILED(hr)) {
1133         IPersistFolder3_Release(pPersistFolder3);
1134         pILFree(pidlWineTestFolder);
1135         return;
1136     }
1137
1138     hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1139     ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1140     ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1141         "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1142     pILFree(pidlCurrentFolder);
1143     pILFree(pidlWineTestFolder);
1144
1145     hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1146     IPersistFolder3_Release(pPersistFolder3);
1147     ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1148     if (FAILED(hr)) return;
1149
1150     hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1151     ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1152     if (FAILED(hr)) {
1153         IShellFolder_Release(pShellFolder);
1154         return;
1155     }
1156
1157     pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1158     ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1159
1160     /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1161      * but ShellFSFolders. */
1162     PathAddBackslashW(wszDesktopPath);
1163     lstrcatW(wszDesktopPath, wszSomeSubFolder);
1164     if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1165         IShellFolder_Release(pShellFolder);
1166         return;
1167     }
1168     
1169     hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL, 
1170                                        &pidlSubFolder, NULL);
1171     RemoveDirectoryW(wszDesktopPath);
1172     ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1173     if (FAILED(hr)) {
1174         IShellFolder_Release(pShellFolder);
1175         return;
1176     }
1177
1178     hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1179                                    (LPVOID*)&pPersistFolder3);
1180     IShellFolder_Release(pShellFolder);
1181     pILFree(pidlSubFolder);
1182     ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1183     if (FAILED(hr))
1184         return;
1185
1186     /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1187      * a little bit and also allow CLSID_UnixDosFolder. */
1188     hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1189     ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1190     ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1191         "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1192
1193     IPersistFolder3_Release(pPersistFolder3);
1194 }
1195
1196 #include "pshpack1.h"
1197 struct FileStructA {
1198     BYTE  type;
1199     BYTE  dummy;
1200     DWORD dwFileSize;
1201     WORD  uFileDate;    /* In our current implementation this is */
1202     WORD  uFileTime;    /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1203     WORD  uFileAttribs;
1204     CHAR  szName[1];
1205 };
1206
1207 struct FileStructW {
1208     WORD  cbLen;        /* Length of this element. */
1209     BYTE  abFooBar1[6]; /* Beyond any recognition. */
1210     WORD  uDate;        /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1211     WORD  uTime;        /* (this is currently speculation) */
1212     WORD  uDate2;       /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1213     WORD  uTime2;       /* (this is currently speculation) */
1214     BYTE  abFooBar2[4]; /* Beyond any recognition. */
1215     WCHAR wszName[1];   /* The long filename in unicode. */
1216     /* Just for documentation: Right after the unicode string: */
1217     WORD  cbOffset;     /* FileStructW's offset from the beginning of the SHITMEID. 
1218                          * SHITEMID->cb == uOffset + cbLen */
1219 };
1220 #include "poppack.h"
1221
1222 static void test_ITEMIDLIST_format(void) {
1223     WCHAR wszPersonal[MAX_PATH];
1224     LPSHELLFOLDER psfDesktop, psfPersonal;
1225     LPITEMIDLIST pidlPersonal, pidlFile;
1226     HANDLE hFile;
1227     HRESULT hr;
1228     BOOL bResult;
1229     WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 }, 
1230         { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1231     int i;
1232     
1233     if(!pSHGetSpecialFolderPathW) return;
1234
1235     bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1236     ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1237     if (!bResult) return;
1238
1239     bResult = SetCurrentDirectoryW(wszPersonal);
1240     ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1241     if (!bResult) return;
1242
1243     hr = SHGetDesktopFolder(&psfDesktop);
1244     ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1245     if (FAILED(hr)) return;
1246
1247     hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1248     ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1249     if (FAILED(hr)) {
1250         IShellFolder_Release(psfDesktop);
1251         return;
1252     }
1253
1254     hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1255         (LPVOID*)&psfPersonal);
1256     IShellFolder_Release(psfDesktop);
1257     pILFree(pidlPersonal);
1258     ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1259     if (FAILED(hr)) return;
1260
1261     for (i=0; i<3; i++) {
1262         CHAR szFile[MAX_PATH];
1263         struct FileStructA *pFileStructA;
1264         WORD cbOffset;
1265         
1266         WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1267         
1268         hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1269         ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1270         if (hFile == INVALID_HANDLE_VALUE) {
1271             IShellFolder_Release(psfPersonal);
1272             return;
1273         }
1274         CloseHandle(hFile);
1275
1276         hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1277         DeleteFileW(wszFile[i]);
1278         ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1279         if (FAILED(hr)) {
1280             IShellFolder_Release(psfPersonal);
1281             return;
1282         }
1283
1284         pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1285         ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1286         ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1287         ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n"); 
1288
1289         if (i < 2) /* First two file names are already in valid 8.3 format */ 
1290             ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1291         else 
1292             /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1293              * can't implement this correctly, since unix filesystems don't support
1294              * this nasty short/long filename stuff. So we'll probably stay with our
1295              * current habbit of storing the long filename here, which seems to work
1296              * just fine. */
1297             todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1298
1299         if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1300             ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0', 
1301                 "Alignment byte, where there shouldn't be!\n"); 
1302         
1303         if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1304             ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0', 
1305                 "There should be an alignment byte, but isn't!\n");
1306
1307         /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1308         cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1309         ok (cbOffset >= sizeof(struct FileStructA) &&
1310             cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1311             "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1312
1313         if (cbOffset >= sizeof(struct FileStructA) &&
1314             cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW)) 
1315         {
1316             struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1317
1318             ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen, 
1319                 "FileStructW's offset and length should add up to the PIDL's length!\n");
1320
1321             if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1322                 /* Since we just created the file, time of creation,
1323                  * time of last access and time of last write access just be the same. 
1324                  * These tests seem to fail sometimes (on WinXP), if the test is run again shortly 
1325                  * after the first run. I do remember something with NTFS keeping the creation time
1326                  * if a file is deleted and then created again within a couple of seconds or so.
1327                  * Might be the reason. */
1328                 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1329                     pFileStructA->uFileTime == pFileStructW->uTime,
1330                     "Last write time should match creation time!\n");
1331     
1332                 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1333                     pFileStructA->uFileTime == pFileStructW->uTime2,
1334                     "Last write time should match last access time!\n");
1335
1336                 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1337                     "The filename should be stored in unicode at this position!\n");
1338             }
1339         }
1340
1341         pILFree(pidlFile);
1342     }
1343 }
1344
1345 START_TEST(shlfolder)
1346 {
1347     init_function_pointers();
1348     /* if OleInitialize doesn't get called, ParseDisplayName returns
1349        CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1350     OleInitialize(NULL);
1351
1352     test_ParseDisplayName();
1353     test_BindToObject();
1354     test_EnumObjects_and_CompareIDs();
1355     test_GetDisplayName();
1356     test_GetAttributesOf();
1357     test_SHGetPathFromIDList();
1358     test_CallForAttributes();
1359     test_FolderShortcut();
1360     test_ITEMIDLIST_format();
1361
1362     OleUninitialize();
1363 }