2004-09-14 01:25:09 +02:00
|
|
|
/*
|
|
|
|
* Unit test of the IShellFolder functions.
|
|
|
|
*
|
|
|
|
* Copyright 2004 Vitaliy Margolen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-09-14 01:25:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-10-07 04:59:11 +02:00
|
|
|
#define COBJMACROS
|
2006-09-29 12:45:44 +02:00
|
|
|
#define CONST_VTABLE
|
2004-10-07 04:59:11 +02:00
|
|
|
|
2004-09-14 01:25:09 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wtypes.h"
|
|
|
|
#include "shellapi.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "shlguid.h"
|
|
|
|
#include "shlobj.h"
|
|
|
|
#include "shobjidl.h"
|
2005-06-14 19:21:25 +02:00
|
|
|
#include "shlwapi.h"
|
2005-08-23 11:37:59 +02:00
|
|
|
#include "ocidl.h"
|
|
|
|
#include "oleauto.h"
|
2004-09-14 01:25:09 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
|
2005-06-07 22:30:30 +02:00
|
|
|
static IMalloc *ppM;
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-06-20 12:31:14 +02:00
|
|
|
static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
|
2007-12-18 10:01:05 +01:00
|
|
|
static BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST,LPWSTR);
|
2005-06-20 12:31:14 +02:00
|
|
|
static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
|
2005-08-16 21:29:40 +02:00
|
|
|
static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
|
2005-09-06 16:05:07 +02:00
|
|
|
static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
|
2007-02-09 12:38:11 +01:00
|
|
|
static void (WINAPI *pILFree)(LPITEMIDLIST);
|
|
|
|
static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
|
2005-06-20 12:31:14 +02:00
|
|
|
|
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
2005-08-16 21:29:40 +02:00
|
|
|
HMODULE hmod;
|
2005-06-29 13:00:59 +02:00
|
|
|
HRESULT hr;
|
2005-06-20 12:31:14 +02:00
|
|
|
|
2005-08-16 21:29:40 +02:00
|
|
|
hmod = GetModuleHandleA("shell32.dll");
|
2007-03-28 10:00:28 +02:00
|
|
|
pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
|
2007-12-18 10:01:05 +01:00
|
|
|
pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
|
2007-03-28 10:00:28 +02:00
|
|
|
pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
|
|
|
|
pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
|
|
|
|
pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
|
|
|
|
pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
|
2005-06-29 13:00:59 +02:00
|
|
|
|
2005-08-16 21:29:40 +02:00
|
|
|
hmod = GetModuleHandleA("shlwapi.dll");
|
2007-03-28 10:00:28 +02:00
|
|
|
pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
|
2005-08-16 21:29:40 +02:00
|
|
|
|
2005-06-29 13:00:59 +02:00
|
|
|
hr = SHGetMalloc(&ppM);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
|
2005-06-20 12:31:14 +02:00
|
|
|
}
|
|
|
|
|
2005-08-02 16:41:51 +02:00
|
|
|
static void test_ParseDisplayName(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IShellFolder *IDesktopFolder;
|
|
|
|
static const char *cNonExistDir1A = "c:\\nonexist_subdir";
|
|
|
|
static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
|
|
|
|
DWORD res;
|
|
|
|
WCHAR cTestDirW [MAX_PATH] = {0};
|
|
|
|
ITEMIDLIST *newPIDL;
|
2006-02-24 22:24:12 +01:00
|
|
|
BOOL bRes;
|
2005-08-02 16:41:51 +02:00
|
|
|
|
|
|
|
hr = SHGetDesktopFolder(&IDesktopFolder);
|
|
|
|
if(hr != S_OK) return;
|
|
|
|
|
|
|
|
res = GetFileAttributesA(cNonExistDir1A);
|
|
|
|
if(res != INVALID_FILE_ATTRIBUTES) return;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
|
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder,
|
|
|
|
NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
|
2005-08-08 13:04:30 +02:00
|
|
|
ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
|
2006-10-07 20:18:17 +02:00
|
|
|
"ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
|
2005-08-02 16:41:51 +02:00
|
|
|
|
|
|
|
res = GetFileAttributesA(cNonExistDir2A);
|
|
|
|
if(res != INVALID_FILE_ATTRIBUTES) return;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
|
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder,
|
|
|
|
NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
|
2005-08-15 11:40:45 +02:00
|
|
|
ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
|
2006-10-07 20:18:17 +02:00
|
|
|
"ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
2006-02-24 22:24:12 +01:00
|
|
|
/* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
|
|
|
|
* path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
|
|
|
|
* out it doesn't. The magic seems to happen in the file dialogs, then. */
|
|
|
|
if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
|
|
|
|
|
|
|
|
bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
|
2006-02-24 22:24:12 +01:00
|
|
|
if (!bRes) goto finished;
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
|
2006-02-24 22:24:12 +01:00
|
|
|
if (FAILED(hr)) goto finished;
|
|
|
|
|
|
|
|
ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
|
|
|
|
"PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
|
|
|
|
IMalloc_Free(ppM, newPIDL);
|
|
|
|
|
|
|
|
finished:
|
|
|
|
IShellFolder_Release(IDesktopFolder);
|
2005-08-02 16:41:51 +02:00
|
|
|
}
|
|
|
|
|
2004-09-14 01:25:09 +02:00
|
|
|
/* creates a file with the specified name for tests */
|
2005-06-07 22:30:30 +02:00
|
|
|
static void CreateTestFile(const CHAR *name)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
DWORD written;
|
|
|
|
|
|
|
|
file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
WriteFile(file, name, strlen(name), &written, NULL);
|
|
|
|
WriteFile(file, "\n", strlen("\n"), &written, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* initializes the tests */
|
2005-06-07 22:30:30 +02:00
|
|
|
static void CreateFilesFolders(void)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
|
|
|
CreateDirectoryA(".\\testdir", NULL);
|
|
|
|
CreateDirectoryA(".\\testdir\\test.txt", NULL);
|
|
|
|
CreateTestFile (".\\testdir\\test1.txt ");
|
|
|
|
CreateTestFile (".\\testdir\\test2.txt ");
|
|
|
|
CreateTestFile (".\\testdir\\test3.txt ");
|
|
|
|
CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
|
2005-04-11 20:50:01 +02:00
|
|
|
CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
|
2004-09-14 01:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cleans after tests */
|
2005-06-07 22:30:30 +02:00
|
|
|
static void Cleanup(void)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
|
|
|
DeleteFileA(".\\testdir\\test1.txt");
|
|
|
|
DeleteFileA(".\\testdir\\test2.txt");
|
|
|
|
DeleteFileA(".\\testdir\\test3.txt");
|
|
|
|
RemoveDirectoryA(".\\testdir\\test.txt");
|
2005-04-11 20:50:01 +02:00
|
|
|
RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
|
2004-09-14 01:25:09 +02:00
|
|
|
RemoveDirectoryA(".\\testdir\\testdir2");
|
|
|
|
RemoveDirectoryA(".\\testdir");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* perform test */
|
2005-06-07 22:30:30 +02:00
|
|
|
static void test_EnumObjects(IShellFolder *iFolder)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
|
|
|
IEnumIDList *iEnumList;
|
2005-07-08 13:30:18 +02:00
|
|
|
LPITEMIDLIST newPIDL, idlArr[10];
|
2004-09-14 01:25:09 +02:00
|
|
|
ULONG NumPIDLs;
|
|
|
|
int i=0, j;
|
2005-04-11 20:50:01 +02:00
|
|
|
HRESULT hr;
|
2004-09-14 01:25:09 +02:00
|
|
|
|
|
|
|
static const WORD iResults [5][5] =
|
|
|
|
{
|
|
|
|
{ 0,-1,-1,-1,-1},
|
2004-10-11 21:52:23 +02:00
|
|
|
{ 1, 0,-1,-1,-1},
|
|
|
|
{ 1, 1, 0,-1,-1},
|
|
|
|
{ 1, 1, 1, 0,-1},
|
|
|
|
{ 1, 1, 1, 1, 0}
|
2004-09-14 01:25:09 +02:00
|
|
|
};
|
|
|
|
|
2005-11-03 10:56:07 +01:00
|
|
|
#define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
|
|
|
|
/* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
|
2005-04-11 20:50:01 +02:00
|
|
|
static const ULONG attrs[5] =
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
2005-11-03 10:56:07 +01:00
|
|
|
SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
|
|
|
|
SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
|
|
|
|
SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
|
|
|
|
SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
|
|
|
|
SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
|
2005-04-11 20:50:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
|
2005-04-11 20:50:01 +02:00
|
|
|
|
2005-07-11 12:59:41 +02:00
|
|
|
/* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
|
|
|
|
* the filesystem shellfolders return S_OK even if less than 'celt' items are
|
2005-07-08 13:30:18 +02:00
|
|
|
* returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
|
|
|
|
* only ever returns a single entry per call. */
|
|
|
|
while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
|
|
|
|
i += NumPIDLs;
|
|
|
|
ok (i == 5, "i: %d\n", i);
|
2005-04-11 20:50:01 +02:00
|
|
|
|
|
|
|
hr = IEnumIDList_Release(iEnumList);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
/* Sort them first in case of wrong order from system */
|
|
|
|
for (i=0;i<5;i++) for (j=0;j<5;j++)
|
|
|
|
if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
2005-04-11 20:50:01 +02:00
|
|
|
newPIDL = idlArr[i];
|
|
|
|
idlArr[i] = idlArr[j];
|
|
|
|
idlArr[j] = newPIDL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0;i<5;i++) for (j=0;j<5;j++)
|
|
|
|
{
|
|
|
|
hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
|
2005-04-11 20:50:01 +02:00
|
|
|
}
|
|
|
|
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
SFGAOF flags;
|
2005-11-03 10:56:07 +01:00
|
|
|
/* Native returns all flags no matter what we ask for */
|
|
|
|
flags = SFGAO_CANCOPY;
|
2005-04-11 20:50:01 +02:00
|
|
|
hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
|
2005-11-03 10:56:07 +01:00
|
|
|
flags &= SFGAO_testfor;
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
|
|
|
|
ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
|
2005-11-03 10:56:07 +01:00
|
|
|
|
|
|
|
flags = SFGAO_testfor;
|
|
|
|
hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
|
|
|
|
flags &= SFGAO_testfor;
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
|
|
|
|
ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
|
2004-09-14 01:25:09 +02:00
|
|
|
}
|
2005-04-11 20:50:01 +02:00
|
|
|
|
|
|
|
for (i=0;i<5;i++)
|
|
|
|
IMalloc_Free(ppM, idlArr[i]);
|
2004-09-14 01:25:09 +02:00
|
|
|
}
|
|
|
|
|
2005-06-07 22:30:30 +02:00
|
|
|
static void test_BindToObject(void)
|
2005-06-06 12:04:15 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT cChars;
|
|
|
|
IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
|
|
|
|
SHITEMID emptyitem = { 0, { 0 } };
|
|
|
|
LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
|
|
|
|
WCHAR wszSystemDir[MAX_PATH];
|
2005-08-22 11:14:35 +02:00
|
|
|
char szSystemDir[MAX_PATH];
|
2005-06-06 12:04:15 +02:00
|
|
|
WCHAR wszMyComputer[] = {
|
|
|
|
':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
|
|
|
|
'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
|
|
|
|
|
|
|
|
/* The following tests shows that BindToObject should fail with E_INVALIDARG if called
|
|
|
|
* with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
|
|
|
|
*/
|
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
|
2005-06-27 11:41:48 +02:00
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
|
2005-06-27 11:41:48 +02:00
|
|
|
|
2005-06-06 12:04:15 +02:00
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyComputer);
|
2005-06-06 12:04:15 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
|
2005-11-09 11:30:15 +01:00
|
|
|
#if 0
|
|
|
|
/* this call segfaults on 98SE */
|
2005-06-27 11:41:48 +02:00
|
|
|
hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
|
2005-11-09 11:30:15 +01:00
|
|
|
#endif
|
2005-06-27 11:41:48 +02:00
|
|
|
|
2005-08-22 11:14:35 +02:00
|
|
|
cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
|
2005-06-06 12:04:15 +02:00
|
|
|
if (cChars == 0 || cChars >= MAX_PATH) {
|
|
|
|
IShellFolder_Release(psfMyComputer);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-22 11:14:35 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
|
2005-06-06 12:04:15 +02:00
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfMyComputer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
IShellFolder_Release(psfMyComputer);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlSystemDir);
|
2005-06-06 12:04:15 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
|
|
|
ok (hr == E_INVALIDARG,
|
2006-10-07 20:18:17 +02:00
|
|
|
"FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
|
2005-06-06 12:04:15 +02:00
|
|
|
|
2005-11-09 11:30:15 +01:00
|
|
|
#if 0
|
|
|
|
/* this call segfaults on 98SE */
|
2005-06-27 11:41:48 +02:00
|
|
|
hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
|
|
|
|
ok (hr == E_INVALIDARG,
|
2006-10-07 20:18:17 +02:00
|
|
|
"FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
|
2005-11-09 11:30:15 +01:00
|
|
|
#endif
|
2005-06-27 11:41:48 +02:00
|
|
|
|
2005-06-06 12:04:15 +02:00
|
|
|
IShellFolder_Release(psfSystemDir);
|
|
|
|
}
|
2007-12-18 10:00:47 +01:00
|
|
|
|
|
|
|
/* Based on PathAddBackslashW from dlls/shlwapi/path.c */
|
|
|
|
static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
|
|
|
|
{
|
|
|
|
size_t iLen;
|
|
|
|
|
|
|
|
if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (iLen)
|
|
|
|
{
|
|
|
|
lpszPath += iLen;
|
|
|
|
if (lpszPath[-1] != '\\')
|
|
|
|
{
|
|
|
|
*lpszPath++ = '\\';
|
|
|
|
*lpszPath = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lpszPath;
|
|
|
|
}
|
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
static void test_GetDisplayName(void)
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hTestFile;
|
|
|
|
WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
|
2005-08-22 11:14:35 +02:00
|
|
|
char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
|
2007-02-09 12:41:08 +01:00
|
|
|
DWORD attr;
|
2005-06-14 19:21:25 +02:00
|
|
|
STRRET strret;
|
|
|
|
LPSHELLFOLDER psfDesktop, psfPersonal;
|
2005-06-14 20:10:24 +02:00
|
|
|
IUnknown *psfFile;
|
2005-09-07 11:22:49 +02:00
|
|
|
SHITEMID emptyitem = { 0, { 0 } };
|
|
|
|
LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
|
2005-06-14 19:21:25 +02:00
|
|
|
LPCITEMIDLIST pidlLast;
|
|
|
|
static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
|
|
|
|
static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
|
|
|
|
|
|
|
|
/* I'm trying to figure if there is a functional difference between calling
|
2007-12-18 10:01:05 +01:00
|
|
|
* SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
|
2005-06-14 19:21:25 +02:00
|
|
|
* binding to the shellfolder. One thing I thought of was that perhaps
|
2007-12-18 10:01:05 +01:00
|
|
|
* SHGetPathFromIDListW would be able to get the path to a file, which does
|
|
|
|
* not exist anymore, while the other method wouldn't. It turns out there's
|
2005-06-14 19:21:25 +02:00
|
|
|
* no functional difference in this respect.
|
|
|
|
*/
|
|
|
|
|
2005-06-20 12:31:14 +02:00
|
|
|
if(!pSHGetSpecialFolderPathW) return;
|
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
/* First creating a directory in MyDocuments and a file in this directory. */
|
2005-06-20 12:31:14 +02:00
|
|
|
result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
|
2005-06-14 19:21:25 +02:00
|
|
|
if (!result) return;
|
|
|
|
|
2007-12-18 10:00:47 +01:00
|
|
|
myPathAddBackslashW(wszTestDir);
|
2005-06-14 19:21:25 +02:00
|
|
|
lstrcatW(wszTestDir, wszDirName);
|
2007-02-09 12:41:08 +01:00
|
|
|
/* Use ANSI file functions so this works on Windows 9x */
|
2005-08-22 11:14:35 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
|
2007-02-09 12:41:08 +01:00
|
|
|
CreateDirectoryA(szTestDir, NULL);
|
|
|
|
attr=GetFileAttributesA(szTestDir);
|
|
|
|
if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
{
|
|
|
|
ok(0, "unable to create the '%s' directory\n", szTestDir);
|
|
|
|
return;
|
|
|
|
}
|
2005-06-14 19:21:25 +02:00
|
|
|
|
|
|
|
lstrcpyW(wszTestFile, wszTestDir);
|
2007-12-18 10:00:47 +01:00
|
|
|
myPathAddBackslashW(wszTestFile);
|
2005-06-14 19:21:25 +02:00
|
|
|
lstrcatW(wszTestFile, wszFileName);
|
2005-08-22 11:14:35 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
|
2005-06-14 19:21:25 +02:00
|
|
|
|
2005-08-22 11:14:35 +02:00
|
|
|
hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
|
2005-06-14 19:21:25 +02:00
|
|
|
if (hTestFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
CloseHandle(hTestFile);
|
|
|
|
|
2005-06-17 22:59:49 +02:00
|
|
|
/* Getting an itemidlist for the file. */
|
2005-06-14 19:21:25 +02:00
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-06-14 19:21:25 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
|
2005-06-14 19:21:25 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:25:18 +01:00
|
|
|
/* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
|
2005-12-12 18:13:14 +01:00
|
|
|
pidlLast = pILFindLastID(pidlTestFile);
|
2006-01-03 13:23:59 +01:00
|
|
|
ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
|
2005-12-02 11:25:18 +01:00
|
|
|
if (pidlLast->mkid.cb >= 76) {
|
|
|
|
ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
|
|
|
|
"WinXP stores the filename as a wchar-string at this position!\n");
|
|
|
|
}
|
|
|
|
|
2005-06-17 22:59:49 +02:00
|
|
|
/* It seems as if we cannot bind to regular files on windows, but only directories.
|
2005-06-14 20:10:24 +02:00
|
|
|
*/
|
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
|
2006-10-07 20:18:17 +02:00
|
|
|
todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
|
2005-06-14 20:10:24 +02:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
IShellFolder_Release(psfFile);
|
|
|
|
}
|
2006-01-16 20:37:51 +01:00
|
|
|
|
|
|
|
/* Some tests for IShellFolder::SetNameOf */
|
|
|
|
hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
|
2006-01-16 20:37:51 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
/* It's ok to use this fixed path. Call will fail anyway. */
|
|
|
|
WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
|
|
|
|
LPITEMIDLIST pidlNew;
|
|
|
|
|
|
|
|
/* The pidl returned through the last parameter of SetNameOf is a simple one. */
|
|
|
|
hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
|
2006-01-16 20:37:51 +01:00
|
|
|
ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
|
|
|
|
"pidl returned from SetNameOf should be simple!\n");
|
|
|
|
|
|
|
|
/* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
|
|
|
|
* is implemented on top of SHFileOperation in WinXP. */
|
|
|
|
hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
|
|
|
|
SHGDN_FORPARSING, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
|
2007-02-14 16:22:07 +01:00
|
|
|
|
|
|
|
/* Rename the file back to its original name. SetNameOf ignores the fact, that the
|
2006-01-16 20:37:51 +01:00
|
|
|
* SHGDN flags specify an absolute path. */
|
|
|
|
hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
|
2006-01-16 20:37:51 +01:00
|
|
|
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlNew);
|
2006-01-16 20:37:51 +01:00
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
}
|
2007-02-09 12:38:11 +01:00
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
/* Deleting the file and the directory */
|
2005-08-22 11:14:35 +02:00
|
|
|
DeleteFileA(szTestFile);
|
|
|
|
RemoveDirectoryA(szTestDir);
|
2005-06-14 19:21:25 +02:00
|
|
|
|
|
|
|
/* SHGetPathFromIDListW still works, although the file is not present anymore. */
|
2007-12-18 10:01:05 +01:00
|
|
|
if (pSHGetPathFromIDListW)
|
|
|
|
{
|
|
|
|
result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
|
|
|
|
ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
|
|
|
|
ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
|
|
|
|
}
|
2005-06-14 19:21:25 +02:00
|
|
|
|
2005-06-20 12:31:14 +02:00
|
|
|
if(!pSHBindToParent) return;
|
|
|
|
|
2005-09-07 11:22:49 +02:00
|
|
|
/* SHBindToParent fails, if called with a NULL PIDL. */
|
|
|
|
hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
|
|
|
|
ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
|
|
|
|
|
|
|
|
/* But it succeeds with an empty PIDL. */
|
|
|
|
hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
|
2005-09-07 11:22:49 +02:00
|
|
|
ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
/* Binding to the folder and querying the display name of the file also works. */
|
2005-06-20 12:31:14 +02:00
|
|
|
hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
|
2005-06-14 19:21:25 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-29 23:45:49 +02:00
|
|
|
/* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
|
|
|
|
* pidlTestFile (In accordance with MSDN). */
|
2005-09-07 11:22:49 +02:00
|
|
|
ok (pILFindLastID(pidlTestFile) == pidlLast,
|
|
|
|
"SHBindToParent doesn't return the last id of the pidl param!\n");
|
2005-08-29 23:45:49 +02:00
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
|
2005-06-14 19:21:25 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-16 21:29:40 +02:00
|
|
|
|
|
|
|
if (pStrRetToBufW)
|
|
|
|
{
|
|
|
|
hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
|
2005-08-16 21:29:40 +02:00
|
|
|
ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
|
|
|
|
}
|
2005-04-11 20:50:01 +02:00
|
|
|
|
2005-06-14 19:21:25 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
}
|
|
|
|
|
2005-06-24 13:33:35 +02:00
|
|
|
static void test_CallForAttributes(void)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
LONG lResult;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD dwSize;
|
|
|
|
LPSHELLFOLDER psfDesktop;
|
|
|
|
LPITEMIDLIST pidlMyDocuments;
|
|
|
|
DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
|
|
|
|
static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
|
|
|
|
static const WCHAR wszCallForAttributes[] = {
|
|
|
|
'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
|
|
|
|
static const WCHAR wszMyDocumentsKey[] = {
|
|
|
|
'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
|
|
|
|
'1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
|
|
|
|
'\\','S','h','e','l','l','F','o','l','d','e','r',0 };
|
|
|
|
WCHAR wszMyDocuments[] = {
|
|
|
|
':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
|
|
|
|
'9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
|
|
|
|
|
|
|
|
/* For the root of a namespace extension, the attributes are not queried by binding
|
|
|
|
* to the object and calling GetAttributesOf. Instead, the attributes are read from
|
|
|
|
* the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
|
|
|
|
*
|
|
|
|
* The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
|
|
|
|
* value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
|
|
|
|
* the shell does bind to the folder object and calls GetAttributesOf. This is not documented
|
|
|
|
* on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
|
|
|
|
*/
|
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
|
|
|
|
&pidlMyDocuments, NULL);
|
|
|
|
ok (SUCCEEDED(hr),
|
2006-10-07 20:18:17 +02:00
|
|
|
"Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwAttributes = 0xffffffff;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
|
|
|
|
(LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
|
2005-06-24 13:33:35 +02:00
|
|
|
|
|
|
|
/* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
|
2005-09-07 15:28:49 +02:00
|
|
|
ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
|
2005-06-24 13:33:35 +02:00
|
|
|
ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
|
|
|
|
ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
|
|
|
|
|
|
|
|
/* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
|
|
|
|
* key. So the test will return at this point, if run on wine.
|
|
|
|
*/
|
|
|
|
lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (lResult != ERROR_SUCCESS) {
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyDocuments);
|
2005-06-24 13:33:35 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query MyDocuments' Attributes value, to be able to restore it later. */
|
|
|
|
dwSize = sizeof(DWORD);
|
|
|
|
lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (lResult != ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hKey);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyDocuments);
|
2005-06-24 13:33:35 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
|
|
|
|
dwSize = sizeof(DWORD);
|
|
|
|
lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
|
|
|
|
(LPBYTE)&dwOrigCallForAttributes, &dwSize);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (lResult != ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hKey);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyDocuments);
|
2005-06-24 13:33:35 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
|
|
|
|
* SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
|
|
|
|
* SFGAO_FILESYSTEM attributes. */
|
|
|
|
dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
|
|
|
|
RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
|
|
|
|
dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
|
|
|
|
RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
|
|
|
|
(LPBYTE)&dwCallForAttributes, sizeof(DWORD));
|
|
|
|
|
|
|
|
/* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
|
|
|
|
* GetAttributesOf. It seems that once there is a single attribute queried, for which
|
|
|
|
* CallForAttributes is set, all flags are taken from the GetAttributesOf call and
|
|
|
|
* the flags in Attributes are ignored.
|
|
|
|
*/
|
|
|
|
dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
|
|
|
|
(LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
|
2005-06-24 13:33:35 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
ok (dwAttributes == SFGAO_FILESYSTEM,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
|
2005-06-24 13:33:35 +02:00
|
|
|
dwAttributes);
|
|
|
|
|
|
|
|
/* Restore MyDocuments' original Attributes and CallForAttributes registry values */
|
|
|
|
RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
|
|
|
|
RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
|
|
|
|
(LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
|
|
|
|
RegCloseKey(hKey);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyDocuments);
|
2005-06-24 13:33:35 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
}
|
|
|
|
|
2005-06-14 20:10:24 +02:00
|
|
|
static void test_GetAttributesOf(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2005-06-16 11:44:50 +02:00
|
|
|
LPSHELLFOLDER psfDesktop, psfMyComputer;
|
2005-06-14 20:10:24 +02:00
|
|
|
SHITEMID emptyitem = { 0, { 0 } };
|
|
|
|
LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
|
2005-06-16 11:44:50 +02:00
|
|
|
LPITEMIDLIST pidlMyComputer;
|
2005-06-14 20:10:24 +02:00
|
|
|
DWORD dwFlags;
|
2005-10-06 13:38:45 +02:00
|
|
|
static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
|
2005-08-11 12:33:21 +02:00
|
|
|
SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
|
2005-06-14 20:10:24 +02:00
|
|
|
SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
|
2005-10-06 13:38:45 +02:00
|
|
|
static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
|
2005-06-16 11:44:50 +02:00
|
|
|
SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
|
|
|
|
SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
|
|
|
|
WCHAR wszMyComputer[] = {
|
|
|
|
':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
|
|
|
|
'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
|
2006-02-11 12:16:56 +01:00
|
|
|
char cCurrDirA [MAX_PATH] = {0};
|
|
|
|
WCHAR cCurrDirW [MAX_PATH];
|
2006-10-29 10:36:57 +01:00
|
|
|
static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
|
2006-02-11 12:16:56 +01:00
|
|
|
static const WCHAR cBackSlash[] = {'\\',0};
|
|
|
|
IShellFolder *IDesktopFolder, *testIShellFolder;
|
|
|
|
ITEMIDLIST *newPIDL;
|
|
|
|
int len;
|
2005-06-16 11:44:50 +02:00
|
|
|
|
2005-06-14 20:10:24 +02:00
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-06-14 20:10:24 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
/* The Desktop attributes can be queried with a single empty itemidlist, .. */
|
|
|
|
dwFlags = 0xffffffff;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
|
|
|
|
ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
|
2005-06-14 20:10:24 +02:00
|
|
|
dwFlags, dwDesktopFlags);
|
|
|
|
|
|
|
|
/* .. or with no itemidlist at all. */
|
|
|
|
dwFlags = 0xffffffff;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
|
|
|
|
ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
|
2005-06-14 20:10:24 +02:00
|
|
|
dwFlags, dwDesktopFlags);
|
2005-06-16 11:44:50 +02:00
|
|
|
|
|
|
|
/* Testing the attributes of the MyComputer shellfolder */
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
|
2005-06-16 11:44:50 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
|
|
|
|
* folder object. It doesn't do this, if MyComputer is queried directly (see below).
|
|
|
|
* SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
|
|
|
|
* should create a link to the original data". You can't create links on MyComputer on
|
|
|
|
* Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
|
|
|
|
* depends on this bug, we probably shouldn't imitate it.
|
|
|
|
*/
|
|
|
|
dwFlags = 0xffffffff;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
|
2005-11-28 10:38:06 +01:00
|
|
|
ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
|
2005-06-16 11:44:50 +02:00
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
|
2005-06-14 20:10:24 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyComputer);
|
2005-06-16 11:44:50 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
|
2005-06-16 11:44:50 +02:00
|
|
|
|
|
|
|
dwFlags = 0xffffffff;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
|
2005-06-16 11:44:50 +02:00
|
|
|
todo_wine { ok (dwFlags == dwMyComputerFlags,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
|
2005-06-16 11:44:50 +02:00
|
|
|
|
|
|
|
IShellFolder_Release(psfMyComputer);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
/* create test directory */
|
|
|
|
CreateFilesFolders();
|
|
|
|
|
|
|
|
GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
|
|
|
|
len = lstrlenA(cCurrDirA);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(cCurrDirA[len-1] == '\\')
|
|
|
|
cCurrDirA[len-1] = 0;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
|
|
|
|
|
|
|
|
hr = SHGetDesktopFolder(&IDesktopFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "BindToObject failed %08x\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
IMalloc_Free(ppM, newPIDL);
|
|
|
|
|
|
|
|
/* get relative PIDL */
|
2006-10-29 10:36:57 +01:00
|
|
|
hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
/* test the shell attributes of the test directory using the relative PIDL */
|
|
|
|
dwFlags = SFGAO_FOLDER;
|
|
|
|
hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
|
|
|
|
ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
/* free memory */
|
|
|
|
IMalloc_Free(ppM, newPIDL);
|
|
|
|
|
|
|
|
/* append testdirectory name to path */
|
2006-05-24 18:05:09 +02:00
|
|
|
lstrcatW(cCurrDirW, cBackSlash);
|
|
|
|
lstrcatW(cCurrDirW, cTestDirW);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
/* test the shell attributes of the test directory using the absolute PIDL */
|
|
|
|
dwFlags = SFGAO_FOLDER;
|
|
|
|
hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
|
|
|
|
ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
/* free memory */
|
|
|
|
IMalloc_Free(ppM, newPIDL);
|
|
|
|
|
2006-02-24 22:24:12 +01:00
|
|
|
IShellFolder_Release(testIShellFolder);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
|
|
|
Cleanup();
|
|
|
|
|
2006-02-24 22:24:12 +01:00
|
|
|
IShellFolder_Release(IDesktopFolder);
|
2005-06-14 20:10:24 +02:00
|
|
|
}
|
|
|
|
|
2005-06-15 20:07:55 +02:00
|
|
|
static void test_SHGetPathFromIDList(void)
|
|
|
|
{
|
|
|
|
SHITEMID emptyitem = { 0, { 0 } };
|
|
|
|
LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
|
|
|
|
LPITEMIDLIST pidlMyComputer;
|
|
|
|
WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
|
|
|
|
BOOL result;
|
|
|
|
HRESULT hr;
|
|
|
|
LPSHELLFOLDER psfDesktop;
|
|
|
|
WCHAR wszMyComputer[] = {
|
|
|
|
':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
|
|
|
|
'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
|
2005-08-15 11:40:45 +02:00
|
|
|
WCHAR wszFileName[MAX_PATH];
|
|
|
|
LPITEMIDLIST pidlTestFile;
|
|
|
|
HANDLE hTestFile;
|
|
|
|
STRRET strret;
|
|
|
|
static WCHAR wszTestFile[] = {
|
|
|
|
'w','i','n','e','t','e','s','t','.','f','o','o',0 };
|
2005-11-28 10:38:06 +01:00
|
|
|
HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
|
|
|
|
HMODULE hShell32;
|
|
|
|
LPITEMIDLIST pidlPrograms;
|
2005-06-15 20:07:55 +02:00
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
|
|
|
|
{
|
|
|
|
skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-06-20 12:31:14 +02:00
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
/* Calling SHGetPathFromIDListW with no pidl should return the empty string */
|
2006-07-11 05:11:09 +02:00
|
|
|
wszPath[0] = 'a';
|
|
|
|
wszPath[1] = '\0';
|
2007-12-18 10:01:05 +01:00
|
|
|
result = pSHGetPathFromIDListW(NULL, wszPath);
|
2006-07-11 05:11:09 +02:00
|
|
|
ok(!result, "Expected failure\n");
|
|
|
|
ok(!wszPath[0], "Expected empty string\n");
|
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
/* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
|
2005-06-20 12:31:14 +02:00
|
|
|
result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
|
2005-06-15 20:07:55 +02:00
|
|
|
if (!result) return;
|
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
|
2005-06-15 20:07:55 +02:00
|
|
|
if (!result) return;
|
2007-12-18 10:01:05 +01:00
|
|
|
ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
|
2005-06-15 20:07:55 +02:00
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
/* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
|
2005-06-15 20:07:55 +02:00
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-06-15 20:07:55 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
|
2005-08-15 11:40:45 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
2005-06-15 20:07:55 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-07-11 05:11:09 +02:00
|
|
|
wszPath[0] = 'a';
|
|
|
|
wszPath[1] = '\0';
|
2007-12-18 10:01:05 +01:00
|
|
|
result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
|
|
|
|
ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
|
|
|
|
ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDListW shouldn't set last error! Last error: %u\n", GetLastError());
|
2006-07-11 05:11:09 +02:00
|
|
|
ok (!wszPath[0], "Expected empty path\n");
|
2005-08-15 11:40:45 +02:00
|
|
|
if (result) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
2005-06-15 20:07:55 +02:00
|
|
|
|
2005-06-29 13:00:59 +02:00
|
|
|
IMalloc_Free(ppM, pidlMyComputer);
|
2005-08-15 11:40:45 +02:00
|
|
|
|
|
|
|
result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
|
2005-08-15 11:40:45 +02:00
|
|
|
if (!result) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-18 10:00:47 +01:00
|
|
|
myPathAddBackslashW(wszFileName);
|
2005-08-15 11:40:45 +02:00
|
|
|
lstrcatW(wszFileName, wszTestFile);
|
|
|
|
hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
|
2005-08-15 11:40:45 +02:00
|
|
|
if (hTestFile == INVALID_HANDLE_VALUE) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CloseHandle(hTestFile);
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
|
2005-08-15 11:40:45 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
DeleteFileW(wszFileName);
|
|
|
|
IMalloc_Free(ppM, pidlTestFile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
|
|
|
|
* path for files placed on the desktop, if called with SHGDN_FORPARSING. */
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
|
2005-08-15 11:40:45 +02:00
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
DeleteFileW(wszFileName);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
IMalloc_Free(ppM, pidlTestFile);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-16 21:29:40 +02:00
|
|
|
if (pStrRetToBufW)
|
|
|
|
{
|
|
|
|
pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
|
|
|
|
ok(0 == lstrcmpW(wszFileName, wszPath),
|
|
|
|
"Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
|
|
|
|
"returned incorrect path for file placed on desktop\n");
|
|
|
|
}
|
2005-08-15 11:40:45 +02:00
|
|
|
|
2007-12-18 10:01:05 +01:00
|
|
|
result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
|
2005-08-15 11:40:45 +02:00
|
|
|
IMalloc_Free(ppM, pidlTestFile);
|
|
|
|
if (!result) return;
|
|
|
|
ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
|
2005-11-28 10:38:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Test if we can get the path from the start menu "program files" PIDL. */
|
|
|
|
hShell32 = GetModuleHandleA("shell32");
|
2006-03-02 18:03:32 +01:00
|
|
|
pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
|
2005-11-28 10:38:06 +01:00
|
|
|
|
|
|
|
hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
|
2005-11-28 10:38:06 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-18 10:01:05 +01:00
|
|
|
result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
|
2005-11-28 10:38:06 +01:00
|
|
|
IMalloc_Free(ppM, pidlPrograms);
|
2007-12-18 10:01:05 +01:00
|
|
|
ok(result, "SHGetPathFromIDListW failed\n");
|
2005-06-15 20:07:55 +02:00
|
|
|
}
|
|
|
|
|
2005-06-21 22:04:17 +02:00
|
|
|
static void test_EnumObjects_and_CompareIDs(void)
|
2004-09-14 01:25:09 +02:00
|
|
|
{
|
|
|
|
ITEMIDLIST *newPIDL;
|
|
|
|
IShellFolder *IDesktopFolder, *testIShellFolder;
|
2005-06-09 14:05:50 +02:00
|
|
|
char cCurrDirA [MAX_PATH] = {0};
|
2004-09-14 01:25:09 +02:00
|
|
|
WCHAR cCurrDirW [MAX_PATH];
|
|
|
|
static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
|
2005-08-08 20:03:47 +02:00
|
|
|
int len;
|
2005-04-11 20:50:01 +02:00
|
|
|
HRESULT hr;
|
2005-06-20 12:31:14 +02:00
|
|
|
|
2005-06-09 14:05:50 +02:00
|
|
|
GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
|
2005-08-08 20:03:47 +02:00
|
|
|
len = lstrlenA(cCurrDirA);
|
|
|
|
|
|
|
|
if(len == 0) {
|
|
|
|
trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(cCurrDirA[len-1] == '\\')
|
|
|
|
cCurrDirA[len-1] = 0;
|
|
|
|
|
2005-06-09 14:05:50 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
|
2006-05-24 18:05:09 +02:00
|
|
|
lstrcatW(cCurrDirW, cTestDirW);
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
hr = SHGetDesktopFolder(&IDesktopFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-06-22 20:04:04 +02:00
|
|
|
CreateFilesFolders();
|
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
|
2004-09-14 01:25:09 +02:00
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(hr == S_OK, "BindToObject failed %08x\n", hr);
|
2005-06-22 20:04:04 +02:00
|
|
|
|
2005-04-11 20:50:01 +02:00
|
|
|
test_EnumObjects(testIShellFolder);
|
|
|
|
|
2006-02-24 22:24:12 +01:00
|
|
|
IShellFolder_Release(testIShellFolder);
|
2005-04-11 20:50:01 +02:00
|
|
|
|
2004-09-14 01:25:09 +02:00
|
|
|
Cleanup();
|
2005-06-22 20:04:04 +02:00
|
|
|
|
|
|
|
IMalloc_Free(ppM, newPIDL);
|
2006-02-11 12:16:56 +01:00
|
|
|
|
2006-02-24 22:24:12 +01:00
|
|
|
IShellFolder_Release(IDesktopFolder);
|
2004-09-14 01:25:09 +02:00
|
|
|
}
|
2005-06-21 22:04:17 +02:00
|
|
|
|
2005-08-23 11:37:59 +02:00
|
|
|
/* A simple implementation of an IPropertyBag, which returns fixed values for
|
|
|
|
* 'Target' and 'Attributes' properties.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
if (!ppvObject)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
|
|
|
|
*ppvObject = iface;
|
|
|
|
} else {
|
|
|
|
ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPropertyBag_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
|
|
|
|
VARIANT *pVar, IErrorLog *pErrorLog)
|
|
|
|
{
|
|
|
|
static const WCHAR wszTargetSpecialFolder[] = {
|
|
|
|
'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
|
|
|
|
static const WCHAR wszTarget[] = {
|
|
|
|
'T','a','r','g','e','t',0 };
|
|
|
|
static const WCHAR wszAttributes[] = {
|
|
|
|
'A','t','t','r','i','b','u','t','e','s',0 };
|
|
|
|
static const WCHAR wszResolveLinkFlags[] = {
|
|
|
|
'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
|
2005-11-03 13:04:24 +01:00
|
|
|
|
|
|
|
if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
|
|
|
|
ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
|
2005-08-23 11:37:59 +02:00
|
|
|
{
|
2005-11-03 13:04:24 +01:00
|
|
|
ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
|
2005-08-23 11:37:59 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lstrcmpW(pszPropName, wszTarget)) {
|
|
|
|
WCHAR wszPath[MAX_PATH];
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
|
|
|
|
if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
|
|
|
|
|
|
|
|
result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
|
2005-08-23 11:37:59 +02:00
|
|
|
if (!result) return E_INVALIDARG;
|
|
|
|
|
|
|
|
V_BSTR(pVar) = SysAllocString(wszPath);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lstrcmpW(pszPropName, wszAttributes)) {
|
|
|
|
ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
|
|
|
|
if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
|
|
|
|
V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
|
|
|
|
SFGAO_CANRENAME|SFGAO_FILESYSTEM;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
|
|
|
|
VARIANT *pVar)
|
|
|
|
{
|
|
|
|
ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
|
|
|
|
InitPropertyBag_IPropertyBag_QueryInterface,
|
|
|
|
InitPropertyBag_IPropertyBag_AddRef,
|
|
|
|
InitPropertyBag_IPropertyBag_Release,
|
|
|
|
InitPropertyBag_IPropertyBag_Read,
|
|
|
|
InitPropertyBag_IPropertyBag_Write
|
|
|
|
};
|
|
|
|
|
2006-12-10 16:51:26 +01:00
|
|
|
static struct IPropertyBag InitPropertyBag = {
|
2005-08-23 11:37:59 +02:00
|
|
|
&InitPropertyBag_IPropertyBagVtbl
|
|
|
|
};
|
|
|
|
|
2006-12-10 16:51:26 +01:00
|
|
|
static void test_FolderShortcut(void) {
|
2005-08-23 11:37:59 +02:00
|
|
|
IPersistPropertyBag *pPersistPropertyBag;
|
2005-11-03 13:04:24 +01:00
|
|
|
IShellFolder *pShellFolder, *pDesktopFolder;
|
2005-08-23 11:37:59 +02:00
|
|
|
IPersistFolder3 *pPersistFolder3;
|
|
|
|
HRESULT hr;
|
|
|
|
STRRET strret;
|
2005-11-03 13:04:24 +01:00
|
|
|
WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
|
2005-08-23 11:37:59 +02:00
|
|
|
BOOL result;
|
|
|
|
CLSID clsid;
|
2005-11-03 13:04:24 +01:00
|
|
|
LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
|
2005-12-20 11:57:44 +01:00
|
|
|
HKEY hShellExtKey;
|
2005-11-03 13:04:24 +01:00
|
|
|
WCHAR wszWineTestFolder[] = {
|
|
|
|
':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
|
|
|
|
'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
|
2005-12-20 11:57:44 +01:00
|
|
|
WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
|
|
|
|
'N','a','m','e','S','p','a','c','e','\\',
|
|
|
|
'{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
|
|
|
|
'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
|
|
|
|
|
2005-11-03 13:04:24 +01:00
|
|
|
WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
|
2005-11-05 11:44:28 +01:00
|
|
|
static const GUID CLSID_UnixDosFolder =
|
|
|
|
{0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
|
|
|
|
|
2005-08-23 11:37:59 +02:00
|
|
|
if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
|
|
|
|
|
|
|
|
/* These tests basically show, that CLSID_FolderShortcuts are initialized
|
|
|
|
* via their IPersistPropertyBag interface. And that the target folder
|
|
|
|
* is taken from the IPropertyBag's 'Target' property.
|
|
|
|
*/
|
|
|
|
hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IPersistPropertyBag_Release(pPersistPropertyBag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
|
|
|
|
(LPVOID*)&pShellFolder);
|
|
|
|
IPersistPropertyBag_Release(pPersistPropertyBag);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(pShellFolder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-03 13:04:24 +01:00
|
|
|
result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
|
2005-08-23 11:37:59 +02:00
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
|
2005-11-03 13:04:24 +01:00
|
|
|
ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
|
2005-08-23 11:37:59 +02:00
|
|
|
|
|
|
|
hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
|
|
|
|
IShellFolder_Release(pShellFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
|
|
|
|
|
|
|
|
hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
|
2005-08-23 11:37:59 +02:00
|
|
|
ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
|
|
|
|
|
2005-11-03 13:04:24 +01:00
|
|
|
/* For FolderShortcut objects, the Initialize method initialized the folder's position in the
|
|
|
|
* shell namespace. The target folder, read from the property bag above, remains untouched.
|
|
|
|
* The following tests show this: The itemidlist for some imaginary shellfolder object
|
|
|
|
* is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
|
|
|
|
* itemidlist, but GetDisplayNameOf still returns the path from above.
|
|
|
|
*/
|
|
|
|
hr = SHGetDesktopFolder(&pDesktopFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2005-12-20 11:57:44 +01:00
|
|
|
/* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
|
|
|
|
* Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
|
|
|
|
RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
|
|
|
|
RegCloseKey(hShellExtKey);
|
2005-11-03 13:04:24 +01:00
|
|
|
hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
|
|
|
|
&pidlWineTestFolder, NULL);
|
2005-12-20 11:57:44 +01:00
|
|
|
RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
|
2005-11-03 13:04:24 +01:00
|
|
|
IShellFolder_Release(pDesktopFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IPersistFolder3_Release(pPersistFolder3);
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlWineTestFolder);
|
2005-11-03 13:04:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-02-09 12:38:11 +01:00
|
|
|
|
2005-11-03 13:04:24 +01:00
|
|
|
hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
|
2007-02-09 12:38:11 +01:00
|
|
|
ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
|
2005-11-03 13:04:24 +01:00
|
|
|
"IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlCurrentFolder);
|
|
|
|
pILFree(pidlWineTestFolder);
|
|
|
|
|
2005-11-03 13:04:24 +01:00
|
|
|
hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
|
|
|
|
IPersistFolder3_Release(pPersistFolder3);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(pShellFolder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
|
|
|
|
ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
|
|
|
|
|
|
|
|
/* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
|
|
|
|
* but ShellFSFolders. */
|
2007-12-18 10:00:47 +01:00
|
|
|
myPathAddBackslashW(wszDesktopPath);
|
2005-11-03 13:04:24 +01:00
|
|
|
lstrcatW(wszDesktopPath, wszSomeSubFolder);
|
|
|
|
if (!CreateDirectoryW(wszDesktopPath, NULL)) {
|
|
|
|
IShellFolder_Release(pShellFolder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
|
|
|
|
&pidlSubFolder, NULL);
|
2005-11-05 11:44:28 +01:00
|
|
|
RemoveDirectoryW(wszDesktopPath);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
|
2005-11-03 13:04:24 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(pShellFolder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-09 12:38:11 +01:00
|
|
|
hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
|
2005-11-03 13:04:24 +01:00
|
|
|
(LPVOID*)&pPersistFolder3);
|
|
|
|
IShellFolder_Release(pShellFolder);
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlSubFolder);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
|
2007-02-09 12:38:11 +01:00
|
|
|
if (FAILED(hr))
|
2005-11-03 13:04:24 +01:00
|
|
|
return;
|
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
/* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
|
|
|
|
* a little bit and also allow CLSID_UnixDosFolder. */
|
2005-11-03 13:04:24 +01:00
|
|
|
hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
|
2005-11-05 11:44:28 +01:00
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
|
|
|
|
"IPersistFolder3::GetClassID returned unexpected CLSID!\n");
|
2005-11-03 13:04:24 +01:00
|
|
|
|
2005-08-23 11:37:59 +02:00
|
|
|
IPersistFolder3_Release(pPersistFolder3);
|
|
|
|
}
|
|
|
|
|
2005-12-22 17:16:11 +01:00
|
|
|
#include "pshpack1.h"
|
|
|
|
struct FileStructA {
|
|
|
|
BYTE type;
|
|
|
|
BYTE dummy;
|
|
|
|
DWORD dwFileSize;
|
|
|
|
WORD uFileDate; /* In our current implementation this is */
|
|
|
|
WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
|
|
|
|
WORD uFileAttribs;
|
|
|
|
CHAR szName[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FileStructW {
|
|
|
|
WORD cbLen; /* Length of this element. */
|
|
|
|
BYTE abFooBar1[6]; /* Beyond any recognition. */
|
|
|
|
WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
|
|
|
|
WORD uTime; /* (this is currently speculation) */
|
|
|
|
WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
|
|
|
|
WORD uTime2; /* (this is currently speculation) */
|
|
|
|
BYTE abFooBar2[4]; /* Beyond any recognition. */
|
|
|
|
WCHAR wszName[1]; /* The long filename in unicode. */
|
|
|
|
/* Just for documentation: Right after the unicode string: */
|
|
|
|
WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
|
|
|
|
* SHITEMID->cb == uOffset + cbLen */
|
|
|
|
};
|
|
|
|
#include "poppack.h"
|
|
|
|
|
2006-12-10 16:51:26 +01:00
|
|
|
static void test_ITEMIDLIST_format(void) {
|
2005-12-22 17:16:11 +01:00
|
|
|
WCHAR wszPersonal[MAX_PATH];
|
|
|
|
LPSHELLFOLDER psfDesktop, psfPersonal;
|
|
|
|
LPITEMIDLIST pidlPersonal, pidlFile;
|
|
|
|
HANDLE hFile;
|
|
|
|
HRESULT hr;
|
|
|
|
BOOL bResult;
|
|
|
|
WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
|
|
|
|
{ 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!pSHGetSpecialFolderPathW) return;
|
|
|
|
|
|
|
|
bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
|
2005-12-22 17:16:11 +01:00
|
|
|
if (!bResult) return;
|
|
|
|
|
|
|
|
bResult = SetCurrentDirectoryW(wszPersonal);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
|
2005-12-22 17:16:11 +01:00
|
|
|
if (!bResult) return;
|
|
|
|
|
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
|
2005-12-22 17:16:11 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
|
2005-12-22 17:16:11 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfDesktop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-09 12:38:11 +01:00
|
|
|
hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
|
2005-12-22 17:16:11 +01:00
|
|
|
(LPVOID*)&psfPersonal);
|
|
|
|
IShellFolder_Release(psfDesktop);
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlPersonal);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
|
2005-12-22 17:16:11 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
CHAR szFile[MAX_PATH];
|
|
|
|
struct FileStructA *pFileStructA;
|
|
|
|
WORD cbOffset;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
|
|
|
|
|
|
|
|
hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
|
2007-01-05 21:48:19 +01:00
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
|
2005-12-22 17:16:11 +01:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
|
|
|
|
DeleteFileW(wszFile[i]);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
|
2005-12-22 17:16:11 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IShellFolder_Release(psfPersonal);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
|
|
|
|
ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
|
|
|
|
ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
|
|
|
|
ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
|
|
|
|
|
|
|
|
if (i < 2) /* First two file names are already in valid 8.3 format */
|
|
|
|
ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
|
|
|
|
else
|
|
|
|
/* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
|
|
|
|
* can't implement this correctly, since unix filesystems don't support
|
|
|
|
* this nasty short/long filename stuff. So we'll probably stay with our
|
|
|
|
* current habbit of storing the long filename here, which seems to work
|
|
|
|
* just fine. */
|
|
|
|
todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
|
|
|
|
|
|
|
|
if (i == 0) /* First file name has an even number of chars. No need for alignment. */
|
2006-01-03 13:23:59 +01:00
|
|
|
ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
|
|
|
|
"Alignment byte, where there shouldn't be!\n");
|
2005-12-22 17:16:11 +01:00
|
|
|
|
|
|
|
if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
|
|
|
|
ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
|
|
|
|
"There should be an alignment byte, but isn't!\n");
|
|
|
|
|
|
|
|
/* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
|
|
|
|
cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
|
2006-01-03 13:23:59 +01:00
|
|
|
ok (cbOffset >= sizeof(struct FileStructA) &&
|
2005-12-22 17:16:11 +01:00
|
|
|
cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
|
2006-01-03 13:23:59 +01:00
|
|
|
"Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
|
2005-12-22 17:16:11 +01:00
|
|
|
|
|
|
|
if (cbOffset >= sizeof(struct FileStructA) &&
|
|
|
|
cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
|
|
|
|
{
|
|
|
|
struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
|
|
|
|
|
|
|
|
ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
|
|
|
|
"FileStructW's offset and length should add up to the PIDL's length!\n");
|
|
|
|
|
|
|
|
if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
|
|
|
|
/* Since we just created the file, time of creation,
|
|
|
|
* time of last access and time of last write access just be the same.
|
|
|
|
* These tests seem to fail sometimes (on WinXP), if the test is run again shortly
|
|
|
|
* after the first run. I do remember something with NTFS keeping the creation time
|
|
|
|
* if a file is deleted and then created again within a couple of seconds or so.
|
|
|
|
* Might be the reason. */
|
|
|
|
ok (pFileStructA->uFileDate == pFileStructW->uDate &&
|
|
|
|
pFileStructA->uFileTime == pFileStructW->uTime,
|
|
|
|
"Last write time should match creation time!\n");
|
|
|
|
|
|
|
|
ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
|
|
|
|
pFileStructA->uFileTime == pFileStructW->uTime2,
|
|
|
|
"Last write time should match last access time!\n");
|
|
|
|
|
|
|
|
ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
|
|
|
|
"The filename should be stored in unicode at this position!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-09 12:38:11 +01:00
|
|
|
pILFree(pidlFile);
|
2005-12-22 17:16:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-21 22:04:17 +02:00
|
|
|
START_TEST(shlfolder)
|
|
|
|
{
|
2005-06-22 20:04:04 +02:00
|
|
|
init_function_pointers();
|
2005-06-30 12:23:14 +02:00
|
|
|
/* if OleInitialize doesn't get called, ParseDisplayName returns
|
|
|
|
CO_E_NOTINITIALIZED for malformed directory names on win2k. */
|
|
|
|
OleInitialize(NULL);
|
2005-06-22 20:04:04 +02:00
|
|
|
|
2005-08-02 16:41:51 +02:00
|
|
|
test_ParseDisplayName();
|
2005-06-21 22:04:17 +02:00
|
|
|
test_BindToObject();
|
2005-06-30 12:23:14 +02:00
|
|
|
test_EnumObjects_and_CompareIDs();
|
2005-06-21 22:04:17 +02:00
|
|
|
test_GetDisplayName();
|
|
|
|
test_GetAttributesOf();
|
|
|
|
test_SHGetPathFromIDList();
|
2005-06-24 13:33:35 +02:00
|
|
|
test_CallForAttributes();
|
2005-08-23 11:37:59 +02:00
|
|
|
test_FolderShortcut();
|
2005-12-22 17:16:11 +01:00
|
|
|
test_ITEMIDLIST_format();
|
2005-06-30 12:23:14 +02:00
|
|
|
|
|
|
|
OleUninitialize();
|
2005-06-21 22:04:17 +02:00
|
|
|
}
|