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