push aea352fc3df615e3f4b48daf6f897ea93ad1fffd
[wine/hacks.git] / dlls / shell32 / tests / shelllink.c
blob8db88bb1e74e529c7ab0b96710fb830efa31a384
1 /*
2 * Unit tests for shelllinks
4 * Copyright 2004 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesytem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
25 #define COBJMACROS
27 #include <windows.h>
28 #include "shlguid.h"
29 #include "shobjidl.h"
30 #include "shlobj.h"
31 #include "wine/test.h"
33 #include "shell32_test.h"
36 typedef void (WINAPI *fnILFree)(LPITEMIDLIST);
37 typedef BOOL (WINAPI *fnILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
38 typedef HRESULT (WINAPI *fnSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
40 static fnILFree pILFree;
41 static fnILIsEqual pILIsEqual;
42 static fnSHILCreateFromPath pSHILCreateFromPath;
44 static const GUID _IID_IShellLinkDataList = {
45 0x45e2b4ae, 0xb1c3, 0x11d0,
46 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
49 static const WCHAR lnkfile[]= { 'C',':','\\','t','e','s','t','.','l','n','k',0 };
50 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
53 /* For some reason SHILCreateFromPath does not work on Win98 and
54 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
55 * get what we want on all platforms.
57 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
59 static LPITEMIDLIST path_to_pidl(const char* path)
61 LPITEMIDLIST pidl;
63 if (!pSHSimpleIDListFromPathAW)
65 HMODULE hdll=LoadLibraryA("shell32.dll");
66 pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
67 if (!pSHSimpleIDListFromPathAW)
68 trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
71 pidl=NULL;
72 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
73 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
74 pidl=pSHSimpleIDListFromPathAW(path);
76 if (!pidl)
78 WCHAR* pathW;
79 HRESULT r;
80 int len;
82 len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
83 pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
84 MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
86 r=pSHILCreateFromPath(pathW, &pidl, NULL);
87 todo_wine {
88 ok(SUCCEEDED(r), "SHILCreateFromPath failed (0x%08x)\n", r);
90 HeapFree(GetProcessHeap(), 0, pathW);
92 return pidl;
97 * Test manipulation of an IShellLink's properties.
100 static void test_get_set(void)
102 HRESULT r;
103 IShellLinkA *sl;
104 char mypath[MAX_PATH];
105 char buffer[INFOTIPSIZE];
106 LPITEMIDLIST pidl, tmp_pidl;
107 const char * str;
108 int i;
109 WORD w;
111 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
112 &IID_IShellLinkA, (LPVOID*)&sl);
113 ok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
114 if (!SUCCEEDED(r))
115 return;
117 /* Test Getting / Setting the description */
118 strcpy(buffer,"garbage");
119 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
120 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
121 ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
123 str="Some description";
124 r = IShellLinkA_SetDescription(sl, str);
125 ok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
127 strcpy(buffer,"garbage");
128 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
129 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
130 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
132 /* Test Getting / Setting the work directory */
133 strcpy(buffer,"garbage");
134 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
135 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
136 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
138 str="c:\\nonexistent\\directory";
139 r = IShellLinkA_SetWorkingDirectory(sl, str);
140 ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
142 strcpy(buffer,"garbage");
143 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
144 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
145 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
147 /* Test Getting / Setting the work directory */
148 strcpy(buffer,"garbage");
149 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
150 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
151 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
153 r = IShellLinkA_SetPath(sl, "");
154 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
156 strcpy(buffer,"garbage");
157 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
158 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
159 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
161 /* Win98 returns S_FALSE, but WinXP returns S_OK */
162 str="c:\\nonexistent\\file";
163 r = IShellLinkA_SetPath(sl, str);
164 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
166 strcpy(buffer,"garbage");
167 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
168 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
169 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
171 /* Get some a real path to play with */
172 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
173 ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
175 /* Test the interaction of SetPath and SetIDList */
176 tmp_pidl=NULL;
177 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
178 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
179 if (SUCCEEDED(r))
181 strcpy(buffer,"garbage");
182 r=SHGetPathFromIDListA(tmp_pidl, buffer);
183 todo_wine {
184 ok(r, "SHGetPathFromIDListA failed\n");
186 if (r)
187 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
190 pidl=path_to_pidl(mypath);
191 todo_wine {
192 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
195 if (pidl)
197 r = IShellLinkA_SetIDList(sl, pidl);
198 ok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
200 tmp_pidl=NULL;
201 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
202 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
203 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
204 "GetIDList returned an incorrect pidl\n");
206 /* tmp_pidl is owned by IShellLink so we don't free it */
207 pILFree(pidl);
209 strcpy(buffer,"garbage");
210 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
211 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
212 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
215 /* test path with quotes (Win98 IShellLinkA_SetPath returns S_FALSE, WinXP returns S_OK) */
216 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
217 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
219 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
220 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
221 ok(!lstrcmp(buffer, "C:\\nonexistent\\file"), "case doesn't match\n");
223 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
224 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
226 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
227 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
229 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
230 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
232 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
233 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
235 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
236 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
238 /* Test Getting / Setting the arguments */
239 strcpy(buffer,"garbage");
240 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
241 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
242 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
244 str="param1 \"spaced param2\"";
245 r = IShellLinkA_SetArguments(sl, str);
246 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
248 strcpy(buffer,"garbage");
249 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
250 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
251 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
253 /* Test Getting / Setting showcmd */
254 i=0xdeadbeef;
255 r = IShellLinkA_GetShowCmd(sl, &i);
256 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
257 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
259 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
260 ok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
262 i=0xdeadbeef;
263 r = IShellLinkA_GetShowCmd(sl, &i);
264 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
265 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
267 /* Test Getting / Setting the icon */
268 i=0xdeadbeef;
269 strcpy(buffer,"garbage");
270 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
271 todo_wine {
272 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
274 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
275 ok(i==0, "GetIconLocation returned %d\n", i);
277 str="c:\\nonexistent\\file";
278 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
279 ok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
281 i=0xdeadbeef;
282 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
283 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
284 ok(lstrcmpi(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
285 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
287 /* Test Getting / Setting the hot key */
288 w=0xbeef;
289 r = IShellLinkA_GetHotkey(sl, &w);
290 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
291 ok(w==0, "GetHotkey returned %d\n", w);
293 r = IShellLinkA_SetHotkey(sl, 0x5678);
294 ok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
296 w=0xbeef;
297 r = IShellLinkA_GetHotkey(sl, &w);
298 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
299 ok(w==0x5678, "GetHotkey returned %d'\n", w);
301 IShellLinkA_Release(sl);
306 * Test saving and loading .lnk files
309 #define lok ok_(__FILE__, line)
310 #define lok_todo_4(todo_flag,a,b,c,d) \
311 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
312 else todo_wine lok((a), (b), (c), (d));
313 #define lok_todo_2(todo_flag,a,b) \
314 if ((todo & todo_flag) == 0) lok((a), (b)); \
315 else todo_wine lok((a), (b));
316 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
318 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
320 HRESULT r;
321 IShellLinkA *sl;
322 IPersistFile *pf;
324 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
325 &IID_IShellLinkA, (LPVOID*)&sl);
326 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
327 if (!SUCCEEDED(r))
328 return;
330 if (desc->description)
332 r = IShellLinkA_SetDescription(sl, desc->description);
333 lok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
335 if (desc->workdir)
337 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
338 lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
340 if (desc->path)
342 r = IShellLinkA_SetPath(sl, desc->path);
343 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
345 if (desc->pidl)
347 r = IShellLinkA_SetIDList(sl, desc->pidl);
348 lok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
350 if (desc->arguments)
352 r = IShellLinkA_SetArguments(sl, desc->arguments);
353 lok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
355 if (desc->showcmd)
357 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
358 lok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
360 if (desc->icon)
362 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
363 lok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
365 if (desc->hotkey)
367 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
368 lok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
371 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
372 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
373 if (SUCCEEDED(r))
375 r = IPersistFile_Save(pf, path, TRUE);
376 if (save_fails)
378 todo_wine {
379 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
382 else
384 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
386 IPersistFile_Release(pf);
389 IShellLinkA_Release(sl);
392 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
394 HRESULT r;
395 IShellLinkA *sl;
396 IPersistFile *pf;
397 char buffer[INFOTIPSIZE];
399 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
400 &IID_IShellLinkA, (LPVOID*)&sl);
401 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
402 if (!SUCCEEDED(r))
403 return;
405 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
406 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
407 if (!SUCCEEDED(r))
409 IShellLinkA_Release(sl);
410 return;
413 r = IPersistFile_Load(pf, path, STGM_READ);
414 lok(SUCCEEDED(r), "load failed (0x%08x)\n", r);
415 IPersistFile_Release(pf);
416 if (!SUCCEEDED(r))
418 IShellLinkA_Release(sl);
419 return;
422 if (desc->description)
424 strcpy(buffer,"garbage");
425 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
426 lok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
427 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
428 "GetDescription returned '%s' instead of '%s'\n",
429 buffer, desc->description);
431 if (desc->workdir)
433 strcpy(buffer,"garbage");
434 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
435 lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
436 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
437 "GetWorkingDirectory returned '%s' instead of '%s'\n",
438 buffer, desc->workdir);
440 if (desc->path)
442 strcpy(buffer,"garbage");
443 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
444 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
445 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
446 "GetPath returned '%s' instead of '%s'\n",
447 buffer, desc->path);
449 if (desc->pidl)
451 LPITEMIDLIST pidl=NULL;
452 r = IShellLinkA_GetIDList(sl, &pidl);
453 lok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
454 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
455 "GetIDList returned an incorrect pidl\n");
457 if (desc->showcmd)
459 int i=0xdeadbeef;
460 r = IShellLinkA_GetShowCmd(sl, &i);
461 lok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
462 lok_todo_4(0x10, i==desc->showcmd,
463 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
464 i, desc->showcmd);
466 if (desc->icon)
468 int i=0xdeadbeef;
469 strcpy(buffer,"garbage");
470 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
471 lok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
472 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
473 "GetIconLocation returned '%s' instead of '%s'\n",
474 buffer, desc->icon);
475 lok_todo_4(0x20, i==desc->icon_id,
476 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
477 i, desc->icon_id);
479 if (desc->hotkey)
481 WORD i=0xbeef;
482 r = IShellLinkA_GetHotkey(sl, &i);
483 lok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
484 lok_todo_4(0x40, i==desc->hotkey,
485 "GetHotkey returned 0x%04x instead of 0x%04x\n",
486 i, desc->hotkey);
489 IShellLinkA_Release(sl);
492 static void test_load_save(void)
494 lnk_desc_t desc;
495 char mypath[MAX_PATH];
496 char mydir[MAX_PATH];
497 char realpath[MAX_PATH];
498 char* p;
499 HANDLE hf;
500 DWORD r;
502 /* Save an empty .lnk file */
503 memset(&desc, 0, sizeof(desc));
504 create_lnk(lnkfile, &desc, 0);
506 /* It should come back as a bunch of empty strings */
507 desc.description="";
508 desc.workdir="";
509 desc.path="";
510 desc.arguments="";
511 desc.icon="";
512 check_lnk(lnkfile, &desc, 0x0);
514 /* Point a .lnk file to nonexistent files */
515 desc.description="";
516 desc.workdir="c:\\Nonexitent\\work\\directory";
517 desc.path="c:\\nonexistent\\path";
518 desc.pidl=NULL;
519 desc.arguments="";
520 desc.showcmd=0;
521 desc.icon="c:\\nonexistent\\icon\\file";
522 desc.icon_id=1234;
523 desc.hotkey=0;
524 create_lnk(lnkfile, &desc, 0);
525 check_lnk(lnkfile, &desc, 0x0);
527 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
528 ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
529 strcpy(mydir, mypath);
530 p=strrchr(mydir, '\\');
531 if (p)
532 *p='\0';
534 /* Overwrite the existing lnk file and point it to existing files */
535 desc.description="test 2";
536 desc.workdir=mydir;
537 desc.path=mypath;
538 desc.pidl=NULL;
539 desc.arguments="/option1 /option2 \"Some string\"";
540 desc.showcmd=SW_SHOWNORMAL;
541 desc.icon=mypath;
542 desc.icon_id=0;
543 desc.hotkey=0x1234;
544 create_lnk(lnkfile, &desc, 0);
545 check_lnk(lnkfile, &desc, 0x0);
547 /* Overwrite the existing lnk file and test link to a command on the path */
548 desc.description="command on path";
549 desc.workdir=mypath;
550 desc.path="rundll32.exe";
551 desc.pidl=NULL;
552 desc.arguments="/option1 /option2 \"Some string\"";
553 desc.showcmd=SW_SHOWNORMAL;
554 desc.icon=mypath;
555 desc.icon_id=0;
556 desc.hotkey=0x1234;
557 create_lnk(lnkfile, &desc, 0);
558 /* Check that link is created to proper location */
559 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
560 desc.path=realpath;
561 check_lnk(lnkfile, &desc, 0x0);
563 /* Create a temporary non-executable file */
564 r=GetTempPath(sizeof(mypath), mypath);
565 ok(r>=0 && r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
566 r=GetLongPathName(mypath, mydir, sizeof(mydir));
567 ok(r>=0 && r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
568 p=strrchr(mydir, '\\');
569 if (p)
570 *p='\0';
572 strcpy(mypath, mydir);
573 strcat(mypath, "\\test.txt");
574 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
575 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
576 CloseHandle(hf);
578 /* Overwrite the existing lnk file and test link to an existing non-executable file */
579 desc.description="non-executable file";
580 desc.workdir=mydir;
581 desc.path=mypath;
582 desc.pidl=NULL;
583 desc.arguments="";
584 desc.showcmd=SW_SHOWNORMAL;
585 desc.icon=mypath;
586 desc.icon_id=0;
587 desc.hotkey=0x1234;
588 create_lnk(lnkfile, &desc, 0);
589 check_lnk(lnkfile, &desc, 0x0);
591 r = DeleteFileA(mypath);
592 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
594 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
595 * represented as a path.
598 /* DeleteFileW is not implemented on Win9x */
599 r=DeleteFileA("c:\\test.lnk");
600 ok(r, "failed to delete link (%d)\n", GetLastError());
603 static void test_datalink(void)
605 static const WCHAR lnk[] = {
606 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
607 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
608 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
609 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
610 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
611 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
612 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
613 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
614 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
615 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
616 static const WCHAR comp[] = {
617 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
618 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
619 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
620 IShellLinkDataList *dl = NULL;
621 IShellLinkW *sl = NULL;
622 HRESULT r;
623 DWORD flags = 0;
624 EXP_DARWIN_LINK *dar;
626 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
627 &IID_IShellLinkW, (LPVOID*)&sl );
628 ok( r == S_OK || r == E_NOINTERFACE, "CoCreateInstance failed (0x%08x)\n", r);
629 if (!sl)
631 skip("no shelllink\n");
632 return;
635 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
636 ok(r == S_OK, "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
638 if (!dl)
640 skip("no datalink interface\n");
641 return;
644 flags = 0;
645 r = dl->lpVtbl->GetFlags( dl, &flags );
646 ok( r == S_OK, "GetFlags failed\n");
647 ok( flags == 0, "GetFlags returned wrong flags\n");
649 dar = (void*)-1;
650 r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
651 ok( r == E_FAIL, "CopyDataBlock failed\n");
652 ok( dar == NULL, "should be null\n");
654 r = IShellLinkW_SetPath(sl, lnk);
655 ok(r == S_OK, "set path failed\n");
658 * The following crashes:
659 * r = dl->lpVtbl->GetFlags( dl, NULL );
662 flags = 0;
663 r = dl->lpVtbl->GetFlags( dl, &flags );
664 ok( r == S_OK, "GetFlags failed\n");
665 ok( flags == (SLDF_HAS_DARWINID|SLDF_HAS_LOGO3ID),
666 "GetFlags returned wrong flags\n");
668 dar = NULL;
669 r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
670 ok( r == S_OK, "CopyDataBlock failed\n");
672 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
673 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
675 LocalFree( dar );
677 IUnknown_Release( dl );
678 IShellLinkW_Release( sl );
681 START_TEST(shelllink)
683 HRESULT r;
684 HMODULE hmod;
686 hmod = GetModuleHandle("shell32");
687 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
688 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
689 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
691 r = CoInitialize(NULL);
692 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
693 if (!SUCCEEDED(r))
694 return;
696 test_get_set();
697 test_load_save();
698 test_datalink();
700 CoUninitialize();