2004-10-22 21:52:33 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for shelllinks
|
|
|
|
*
|
|
|
|
* Copyright 2004 Mike McCormack
|
|
|
|
*
|
|
|
|
* 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-10-22 21:52:33 +02:00
|
|
|
* This is a test program for the SHGet{Special}Folder{Path|Location} functions
|
|
|
|
* of shell32, that get either a filesytem path or a LPITEMIDLIST (shell
|
|
|
|
* namespace) path for a given folder (CSIDL value).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2006-08-09 12:31:26 +02:00
|
|
|
#include <windows.h>
|
2004-10-22 21:52:33 +02:00
|
|
|
#include "shlguid.h"
|
|
|
|
#include "shobjidl.h"
|
2005-02-14 12:52:29 +01:00
|
|
|
#include "shlobj.h"
|
2004-10-22 21:52:33 +02:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2005-07-24 18:26:53 +02:00
|
|
|
#include "shell32_test.h"
|
|
|
|
|
2006-08-09 12:31:26 +02:00
|
|
|
|
|
|
|
typedef void (WINAPI *fnILFree)(LPITEMIDLIST);
|
|
|
|
typedef BOOL (WINAPI *fnILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
|
|
|
|
typedef HRESULT (WINAPI *fnSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
|
|
|
|
|
|
|
|
static fnILFree pILFree;
|
|
|
|
static fnILIsEqual pILIsEqual;
|
|
|
|
static fnSHILCreateFromPath pSHILCreateFromPath;
|
|
|
|
|
|
|
|
static const GUID _IID_IShellLinkDataList = {
|
|
|
|
0x45e2b4ae, 0xb1c3, 0x11d0,
|
|
|
|
{ 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
|
|
|
|
};
|
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
static const WCHAR lnkfile[]= { 'C',':','\\','t','e','s','t','.','l','n','k',0 };
|
|
|
|
static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
|
|
|
|
|
|
|
|
|
|
|
|
/* For some reason SHILCreateFromPath does not work on Win98 and
|
|
|
|
* SHSimpleIDListFromPathA does not work on NT4. But if we call both we
|
|
|
|
* get what we want on all platforms.
|
|
|
|
*/
|
2006-02-22 12:04:02 +01:00
|
|
|
static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
static LPITEMIDLIST path_to_pidl(const char* path)
|
|
|
|
{
|
|
|
|
LPITEMIDLIST pidl;
|
|
|
|
|
2006-02-22 12:04:02 +01:00
|
|
|
if (!pSHSimpleIDListFromPathAW)
|
2005-02-14 12:52:29 +01:00
|
|
|
{
|
|
|
|
HMODULE hdll=LoadLibraryA("shell32.dll");
|
2006-02-22 12:04:02 +01:00
|
|
|
pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
|
|
|
|
if (!pSHSimpleIDListFromPathAW)
|
|
|
|
trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pidl=NULL;
|
2006-02-22 12:04:02 +01:00
|
|
|
/* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
|
|
|
|
if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
|
|
|
|
pidl=pSHSimpleIDListFromPathAW(path);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
if (!pidl)
|
|
|
|
{
|
|
|
|
WCHAR* pathW;
|
|
|
|
HRESULT r;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
|
|
|
|
pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
|
|
|
|
|
2006-08-09 12:31:26 +02:00
|
|
|
r=pSHILCreateFromPath(pathW, &pidl, NULL);
|
2005-02-14 12:52:29 +01:00
|
|
|
todo_wine {
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SHILCreateFromPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathW);
|
|
|
|
}
|
|
|
|
return pidl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test manipulation of an IShellLink's properties.
|
|
|
|
*/
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_get_set(void)
|
2004-10-22 21:52:33 +02:00
|
|
|
{
|
|
|
|
HRESULT r;
|
2005-02-14 12:52:29 +01:00
|
|
|
IShellLinkA *sl;
|
|
|
|
char mypath[MAX_PATH];
|
|
|
|
char buffer[INFOTIPSIZE];
|
|
|
|
LPITEMIDLIST pidl, tmp_pidl;
|
2005-06-01 13:04:26 +02:00
|
|
|
const char * str;
|
2005-02-14 12:52:29 +01:00
|
|
|
int i;
|
|
|
|
WORD w;
|
|
|
|
|
|
|
|
r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkA, (LPVOID*)&sl);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Test Getting / Setting the description */
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
|
|
|
|
|
|
|
|
str="Some description";
|
|
|
|
r = IShellLinkA_SetDescription(sl, str);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
/* Test Getting / Setting the work directory */
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
str="c:\\nonexistent\\directory";
|
|
|
|
r = IShellLinkA_SetWorkingDirectory(sl, str);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
|
|
|
|
|
|
|
|
/* Test Getting / Setting the work directory */
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
|
|
|
|
|
2005-02-16 17:27:42 +01:00
|
|
|
r = IShellLinkA_SetPath(sl, "");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
|
2005-02-16 17:27:42 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
|
2005-02-16 17:27:42 +01:00
|
|
|
ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
|
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
str="c:\\nonexistent\\file";
|
|
|
|
r = IShellLinkA_SetPath(sl, str);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
|
|
|
|
|
|
|
|
/* Get some a real path to play with */
|
|
|
|
r=GetModuleFileName(NULL, mypath, sizeof(mypath));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
/* Test the interaction of SetPath and SetIDList */
|
|
|
|
tmp_pidl=NULL;
|
|
|
|
r = IShellLinkA_GetIDList(sl, &tmp_pidl);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (SUCCEEDED(r))
|
2004-10-22 21:52:33 +02:00
|
|
|
{
|
2005-02-14 12:52:29 +01:00
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r=SHGetPathFromIDListA(tmp_pidl, buffer);
|
|
|
|
todo_wine {
|
|
|
|
ok(r, "SHGetPathFromIDListA failed\n");
|
|
|
|
}
|
|
|
|
if (r)
|
|
|
|
ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
|
|
|
|
}
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
pidl=path_to_pidl(mypath);
|
|
|
|
todo_wine {
|
|
|
|
ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pidl)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetIDList(sl, pidl);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
tmp_pidl=NULL;
|
|
|
|
r = IShellLinkA_GetIDList(sl, &tmp_pidl);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
|
2006-08-09 12:31:26 +02:00
|
|
|
ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
|
2005-02-14 12:52:29 +01:00
|
|
|
"GetIDList returned an incorrect pidl\n");
|
|
|
|
|
|
|
|
/* tmp_pidl is owned by IShellLink so we don't free it */
|
2006-08-09 12:31:26 +02:00
|
|
|
pILFree(pidl);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
|
|
|
|
}
|
|
|
|
|
2006-08-09 13:38:51 +02:00
|
|
|
/* test path with quotes */
|
|
|
|
r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
ok(!lstrcmp(buffer, "C:\\nonexistent\\file"), "case doesn't match\n");
|
|
|
|
|
|
|
|
r = IShellLinkA_SetPath(sl, "\"c:\\foo");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
r = IShellLinkA_SetPath(sl, "c:\\foo\"");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r==S_FALSE, "SetPath failed (0x%08x)\n", r);
|
2006-08-09 13:38:51 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
/* Test Getting / Setting the arguments */
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
|
|
|
|
|
|
|
|
str="param1 \"spaced param2\"";
|
|
|
|
r = IShellLinkA_SetArguments(sl, str);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
|
|
|
|
|
|
|
|
/* Test Getting / Setting showcmd */
|
|
|
|
i=0xdeadbeef;
|
|
|
|
r = IShellLinkA_GetShowCmd(sl, &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
|
|
|
|
|
|
|
|
r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
i=0xdeadbeef;
|
|
|
|
r = IShellLinkA_GetShowCmd(sl, &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
|
|
|
|
|
|
|
|
/* Test Getting / Setting the icon */
|
|
|
|
i=0xdeadbeef;
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
|
|
|
|
todo_wine {
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
|
|
|
|
ok(i==0, "GetIconLocation returned %d\n", i);
|
|
|
|
|
|
|
|
str="c:\\nonexistent\\file";
|
|
|
|
r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
i=0xdeadbeef;
|
|
|
|
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(lstrcmpi(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
|
|
|
|
ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
|
|
|
|
|
|
|
|
/* Test Getting / Setting the hot key */
|
|
|
|
w=0xbeef;
|
|
|
|
r = IShellLinkA_GetHotkey(sl, &w);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(w==0, "GetHotkey returned %d\n", w);
|
|
|
|
|
|
|
|
r = IShellLinkA_SetHotkey(sl, 0x5678);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
w=0xbeef;
|
|
|
|
r = IShellLinkA_GetHotkey(sl, &w);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
ok(w==0x5678, "GetHotkey returned %d'\n", w);
|
|
|
|
|
|
|
|
IShellLinkA_Release(sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test saving and loading .lnk files
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define lok ok_(__FILE__, line)
|
|
|
|
#define check_lnk(a,b) check_lnk_(__LINE__, (a), (b))
|
|
|
|
|
2005-07-24 18:26:53 +02:00
|
|
|
void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
|
2005-02-14 12:52:29 +01:00
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
IShellLinkA *sl;
|
|
|
|
IPersistFile *pf;
|
|
|
|
|
|
|
|
r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkA, (LPVOID*)&sl);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (desc->description)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetDescription(sl, desc->description);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->workdir)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->path)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetPath(sl, desc->path);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->pidl)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetIDList(sl, desc->pidl);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->arguments)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetArguments(sl, desc->arguments);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->showcmd)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->icon)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
if (desc->hotkey)
|
|
|
|
{
|
|
|
|
r = IShellLinkA_SetHotkey(sl, desc->hotkey);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (SUCCEEDED(r))
|
|
|
|
{
|
|
|
|
r = IPersistFile_Save(pf, path, TRUE);
|
|
|
|
if (save_fails)
|
2004-10-22 21:52:33 +02:00
|
|
|
{
|
2005-02-14 12:52:29 +01:00
|
|
|
todo_wine {
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-10-22 21:52:33 +02:00
|
|
|
{
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
|
2004-10-22 21:52:33 +02:00
|
|
|
}
|
2005-02-14 12:52:29 +01:00
|
|
|
IPersistFile_Release(pf);
|
|
|
|
}
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
IShellLinkA_Release(sl);
|
|
|
|
}
|
2004-10-22 21:52:33 +02:00
|
|
|
|
2005-02-14 12:52:29 +01:00
|
|
|
static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc)
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
IShellLinkA *sl;
|
|
|
|
IPersistFile *pf;
|
|
|
|
char buffer[INFOTIPSIZE];
|
|
|
|
|
|
|
|
r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkA, (LPVOID*)&sl);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
{
|
|
|
|
IShellLinkA_Release(sl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IPersistFile_Load(pf, path, STGM_READ);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "load failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
IPersistFile_Release(pf);
|
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
{
|
|
|
|
IShellLinkA_Release(sl);
|
|
|
|
return;
|
2004-10-22 21:52:33 +02:00
|
|
|
}
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
if (desc->description)
|
|
|
|
{
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(lstrcmp(buffer, desc->description)==0,
|
|
|
|
"GetDescription returned '%s' instead of '%s'\n",
|
|
|
|
buffer, desc->description);
|
|
|
|
}
|
|
|
|
if (desc->workdir)
|
|
|
|
{
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(lstrcmpi(buffer, desc->workdir)==0,
|
|
|
|
"GetWorkingDirectory returned '%s' instead of '%s'\n",
|
|
|
|
buffer, desc->workdir);
|
|
|
|
}
|
|
|
|
if (desc->path)
|
|
|
|
{
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(lstrcmpi(buffer, desc->path)==0,
|
|
|
|
"GetPath returned '%s' instead of '%s'\n",
|
|
|
|
buffer, desc->path);
|
|
|
|
}
|
|
|
|
if (desc->pidl)
|
|
|
|
{
|
|
|
|
LPITEMIDLIST pidl=NULL;
|
|
|
|
r = IShellLinkA_GetIDList(sl, &pidl);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
|
2006-08-09 12:31:26 +02:00
|
|
|
lok(pILIsEqual(pidl, desc->pidl),
|
2005-02-14 12:52:29 +01:00
|
|
|
"GetIDList returned an incorrect pidl\n");
|
|
|
|
}
|
|
|
|
if (desc->showcmd)
|
|
|
|
{
|
|
|
|
int i=0xdeadbeef;
|
|
|
|
r = IShellLinkA_GetShowCmd(sl, &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(i==desc->showcmd,
|
|
|
|
"GetShowCmd returned 0x%0x instead of 0x%0x\n",
|
|
|
|
i, desc->showcmd);
|
|
|
|
}
|
|
|
|
if (desc->icon)
|
|
|
|
{
|
|
|
|
int i=0xdeadbeef;
|
|
|
|
strcpy(buffer,"garbage");
|
|
|
|
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(lstrcmpi(buffer, desc->icon)==0,
|
|
|
|
"GetIconLocation returned '%s' instead of '%s'\n",
|
|
|
|
buffer, desc->icon);
|
|
|
|
lok(i==desc->icon_id,
|
|
|
|
"GetIconLocation returned 0x%0x instead of 0x%0x\n",
|
|
|
|
i, desc->icon_id);
|
|
|
|
}
|
|
|
|
if (desc->hotkey)
|
|
|
|
{
|
|
|
|
WORD i=0xbeef;
|
|
|
|
r = IShellLinkA_GetHotkey(sl, &i);
|
2006-10-07 20:18:17 +02:00
|
|
|
lok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
lok(i==desc->hotkey,
|
|
|
|
"GetHotkey returned 0x%04x instead of 0x%04x\n",
|
|
|
|
i, desc->hotkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
IShellLinkA_Release(sl);
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_load_save(void)
|
2005-02-14 12:52:29 +01:00
|
|
|
{
|
|
|
|
lnk_desc_t desc;
|
|
|
|
char mypath[MAX_PATH];
|
|
|
|
char mydir[MAX_PATH];
|
|
|
|
char* p;
|
|
|
|
DWORD r;
|
|
|
|
|
|
|
|
/* Save an empty .lnk file */
|
|
|
|
memset(&desc, 0, sizeof(desc));
|
2005-02-25 17:19:57 +01:00
|
|
|
create_lnk(lnkfile, &desc, 0);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
/* It should come back as a bunch of empty strings */
|
|
|
|
desc.description="";
|
|
|
|
desc.workdir="";
|
|
|
|
desc.path="";
|
|
|
|
desc.arguments="";
|
|
|
|
desc.icon="";
|
|
|
|
check_lnk(lnkfile, &desc);
|
|
|
|
|
|
|
|
/* Point a .lnk file to nonexistent files */
|
|
|
|
desc.description="";
|
|
|
|
desc.workdir="c:\\Nonexitent\\work\\directory";
|
|
|
|
desc.path="c:\\nonexistent\\path";
|
|
|
|
desc.pidl=NULL;
|
|
|
|
desc.arguments="";
|
|
|
|
desc.showcmd=0;
|
|
|
|
desc.icon="c:\\nonexistent\\icon\\file";
|
|
|
|
desc.icon_id=1234;
|
|
|
|
desc.hotkey=0;
|
|
|
|
create_lnk(lnkfile, &desc, 0);
|
|
|
|
check_lnk(lnkfile, &desc);
|
|
|
|
|
|
|
|
r=GetModuleFileName(NULL, mypath, sizeof(mypath));
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
strcpy(mydir, mypath);
|
|
|
|
p=strrchr(mydir, '\\');
|
|
|
|
if (p)
|
|
|
|
*p='\0';
|
|
|
|
|
|
|
|
/* Overwrite the existing lnk file and point it to existing files */
|
|
|
|
desc.description="test 2";
|
|
|
|
desc.workdir=mydir;
|
|
|
|
desc.path=mypath;
|
|
|
|
desc.pidl=NULL;
|
|
|
|
desc.arguments="/option1 /option2 \"Some string\"";
|
|
|
|
desc.showcmd=SW_SHOWNORMAL;
|
|
|
|
desc.icon=mypath;
|
|
|
|
desc.icon_id=0;
|
|
|
|
desc.hotkey=0x1234;
|
|
|
|
create_lnk(lnkfile, &desc, 0);
|
|
|
|
check_lnk(lnkfile, &desc);
|
|
|
|
|
|
|
|
/* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
|
|
|
|
* represented as a path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* DeleteFileW is not implemented on Win9x */
|
|
|
|
r=DeleteFileA("c:\\test.lnk");
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(r, "failed to delete link (%d)\n", GetLastError());
|
2004-10-22 21:52:33 +02:00
|
|
|
}
|
|
|
|
|
2005-11-04 12:40:58 +01:00
|
|
|
static void test_datalink(void)
|
|
|
|
{
|
|
|
|
static const WCHAR lnk[] = {
|
|
|
|
':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
|
|
|
|
'1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
|
|
|
|
'8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
|
|
|
|
'1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
|
|
|
|
'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
|
|
|
|
'-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
|
|
|
|
'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
|
|
|
|
'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
|
|
|
|
'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
|
|
|
|
'=','1','&','L','[','-','8','1','-',']',':',':',0 };
|
|
|
|
static const WCHAR comp[] = {
|
|
|
|
'2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
|
|
|
|
'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
|
|
|
|
'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
|
|
|
|
IShellLinkDataList *dl = NULL;
|
|
|
|
IShellLinkW *sl = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
DWORD flags = 0;
|
|
|
|
EXP_DARWIN_LINK *dar;
|
|
|
|
|
|
|
|
r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkW, (LPVOID*)&sl );
|
|
|
|
ok( r == S_OK, "no shelllink\n");
|
|
|
|
if (!sl)
|
|
|
|
return;
|
|
|
|
|
2006-08-09 12:31:26 +02:00
|
|
|
r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
|
2005-11-04 12:40:58 +01:00
|
|
|
ok(r == S_OK, "no datalink interface\n");
|
|
|
|
|
|
|
|
if (!dl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
r = dl->lpVtbl->GetFlags( dl, &flags );
|
|
|
|
ok( r == S_OK, "GetFlags failed\n");
|
|
|
|
ok( flags == 0, "GetFlags returned wrong flags\n");
|
|
|
|
|
|
|
|
dar = (void*)-1;
|
|
|
|
r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
|
|
|
|
ok( r == E_FAIL, "CopyDataBlock failed\n");
|
|
|
|
ok( dar == NULL, "should be null\n");
|
|
|
|
|
|
|
|
r = IShellLinkW_SetPath(sl, lnk);
|
|
|
|
ok(r == S_OK, "set path failed\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following crashes:
|
|
|
|
* r = dl->lpVtbl->GetFlags( dl, NULL );
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
r = dl->lpVtbl->GetFlags( dl, &flags );
|
|
|
|
ok( r == S_OK, "GetFlags failed\n");
|
|
|
|
ok( flags == (SLDF_HAS_DARWINID|SLDF_HAS_LOGO3ID),
|
|
|
|
"GetFlags returned wrong flags\n");
|
|
|
|
|
|
|
|
dar = NULL;
|
|
|
|
r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
|
|
|
|
ok( r == S_OK, "CopyDataBlock failed\n");
|
|
|
|
|
2006-10-03 14:12:18 +02:00
|
|
|
ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
|
2005-11-04 12:40:58 +01:00
|
|
|
ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
|
|
|
|
|
|
|
|
LocalFree( dar );
|
|
|
|
|
|
|
|
IUnknown_Release( dl );
|
|
|
|
IShellLinkW_Release( sl );
|
|
|
|
}
|
|
|
|
|
2004-10-22 21:52:33 +02:00
|
|
|
START_TEST(shelllink)
|
|
|
|
{
|
2005-02-14 12:52:29 +01:00
|
|
|
HRESULT r;
|
2006-08-09 12:31:26 +02:00
|
|
|
HMODULE hmod;
|
|
|
|
|
|
|
|
hmod = GetModuleHandle("shell32");
|
|
|
|
pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
|
|
|
|
pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
|
|
|
|
pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
r = CoInitialize(NULL);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
|
2005-02-14 12:52:29 +01:00
|
|
|
if (!SUCCEEDED(r))
|
|
|
|
return;
|
|
|
|
|
|
|
|
test_get_set();
|
|
|
|
test_load_save();
|
2005-11-04 12:40:58 +01:00
|
|
|
test_datalink();
|
2005-02-14 12:52:29 +01:00
|
|
|
|
|
|
|
CoUninitialize();
|
2004-10-22 21:52:33 +02:00
|
|
|
}
|