push 9758e6fe7ae8fbab538c98c718d6619029bb3457
[wine/hacks.git] / dlls / shell32 / tests / shelllink.c
blob710920d77c785861383f2286b222eb88cce53baf
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 filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
25 #define COBJMACROS
27 #include "initguid.h"
28 #include "windows.h"
29 #include "shlguid.h"
30 #include "shobjidl.h"
31 #include "shlobj.h"
32 #include "wine/test.h"
34 #include "shell32_test.h"
36 #ifndef SLDF_HAS_LOGO3ID
37 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
38 #endif
40 typedef void (WINAPI *fnILFree)(LPITEMIDLIST);
41 typedef BOOL (WINAPI *fnILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
42 typedef HRESULT (WINAPI *fnSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
44 static fnILFree pILFree;
45 static fnILIsEqual pILIsEqual;
46 static fnSHILCreateFromPath pSHILCreateFromPath;
48 static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR, LPSTR, DWORD);
50 static const GUID _IID_IShellLinkDataList = {
51 0x45e2b4ae, 0xb1c3, 0x11d0,
52 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
55 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
58 /* For some reason SHILCreateFromPath does not work on Win98 and
59 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
60 * get what we want on all platforms.
62 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
64 static LPITEMIDLIST path_to_pidl(const char* path)
66 LPITEMIDLIST pidl;
68 if (!pSHSimpleIDListFromPathAW)
70 HMODULE hdll=GetModuleHandleA("shell32.dll");
71 pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
72 if (!pSHSimpleIDListFromPathAW)
73 trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
76 pidl=NULL;
77 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
78 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
79 pidl=pSHSimpleIDListFromPathAW(path);
81 if (!pidl)
83 WCHAR* pathW;
84 HRESULT r;
85 int len;
87 len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
88 pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
89 MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
91 r=pSHILCreateFromPath(pathW, &pidl, NULL);
92 ok(SUCCEEDED(r), "SHILCreateFromPath failed (0x%08x)\n", r);
93 HeapFree(GetProcessHeap(), 0, pathW);
95 return pidl;
100 * Test manipulation of an IShellLink's properties.
103 static void test_get_set(void)
105 HRESULT r;
106 IShellLinkA *sl;
107 char mypath[MAX_PATH];
108 char buffer[INFOTIPSIZE];
109 LPITEMIDLIST pidl, tmp_pidl;
110 const char * str;
111 int i;
112 WORD w;
114 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
115 &IID_IShellLinkA, (LPVOID*)&sl);
116 ok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
117 if (!SUCCEEDED(r))
118 return;
120 /* Test Getting / Setting the description */
121 strcpy(buffer,"garbage");
122 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
123 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
124 ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
126 str="Some description";
127 r = IShellLinkA_SetDescription(sl, str);
128 ok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
130 strcpy(buffer,"garbage");
131 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
132 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
133 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
135 /* Test Getting / Setting the work directory */
136 strcpy(buffer,"garbage");
137 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
138 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
139 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
141 str="c:\\nonexistent\\directory";
142 r = IShellLinkA_SetWorkingDirectory(sl, str);
143 ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
145 strcpy(buffer,"garbage");
146 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
147 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
148 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
150 /* Test Getting / Setting the path */
151 strcpy(buffer,"garbage");
152 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
153 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
154 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
156 r = IShellLinkA_SetPath(sl, "");
157 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
159 strcpy(buffer,"garbage");
160 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
161 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
162 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
164 /* Win98 returns S_FALSE, but WinXP returns S_OK */
165 str="c:\\nonexistent\\file";
166 r = IShellLinkA_SetPath(sl, str);
167 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
169 strcpy(buffer,"garbage");
170 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
171 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
172 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
174 /* Get some real path to play with */
175 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
176 strcat(mypath, "\\regedit.exe");
178 /* Test the interaction of SetPath and SetIDList */
179 tmp_pidl=NULL;
180 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
181 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
182 if (SUCCEEDED(r))
184 BOOL ret;
186 strcpy(buffer,"garbage");
187 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
188 todo_wine {
189 ok(ret, "SHGetPathFromIDListA failed\n");
191 if (ret)
192 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
195 pidl=path_to_pidl(mypath);
196 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
198 if (pidl)
200 r = IShellLinkA_SetIDList(sl, pidl);
201 ok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
203 tmp_pidl=NULL;
204 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
205 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
206 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
207 "GetIDList returned an incorrect pidl\n");
209 /* tmp_pidl is owned by IShellLink so we don't free it */
210 pILFree(pidl);
212 strcpy(buffer,"garbage");
213 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
214 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
215 todo_wine
216 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
220 /* test path with quotes (Win98 IShellLinkA_SetPath returns S_FALSE, WinXP returns S_OK) */
221 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
222 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
224 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
225 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
226 ok(!lstrcmp(buffer, "C:\\nonexistent\\file"), "case doesn't match\n");
228 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
229 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
231 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
232 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
234 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
235 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
237 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
238 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
240 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
241 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
243 /* Test Getting / Setting the arguments */
244 strcpy(buffer,"garbage");
245 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
246 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
247 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
249 str="param1 \"spaced param2\"";
250 r = IShellLinkA_SetArguments(sl, str);
251 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
253 strcpy(buffer,"garbage");
254 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
255 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
256 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
258 /* Test Getting / Setting showcmd */
259 i=0xdeadbeef;
260 r = IShellLinkA_GetShowCmd(sl, &i);
261 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
262 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
264 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
265 ok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
267 i=0xdeadbeef;
268 r = IShellLinkA_GetShowCmd(sl, &i);
269 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
270 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
272 /* Test Getting / Setting the icon */
273 i=0xdeadbeef;
274 strcpy(buffer,"garbage");
275 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
276 todo_wine {
277 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
279 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
280 ok(i==0, "GetIconLocation returned %d\n", i);
282 str="c:\\nonexistent\\file";
283 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
284 ok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
286 i=0xdeadbeef;
287 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
288 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
289 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
290 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
292 /* Test Getting / Setting the hot key */
293 w=0xbeef;
294 r = IShellLinkA_GetHotkey(sl, &w);
295 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
296 ok(w==0, "GetHotkey returned %d\n", w);
298 r = IShellLinkA_SetHotkey(sl, 0x5678);
299 ok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
301 w=0xbeef;
302 r = IShellLinkA_GetHotkey(sl, &w);
303 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
304 ok(w==0x5678, "GetHotkey returned %d'\n", w);
306 IShellLinkA_Release(sl);
311 * Test saving and loading .lnk files
314 #define lok ok_(__FILE__, line)
315 #define lok_todo_4(todo_flag,a,b,c,d) \
316 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
317 else todo_wine lok((a), (b), (c), (d));
318 #define lok_todo_2(todo_flag,a,b) \
319 if ((todo & todo_flag) == 0) lok((a), (b)); \
320 else todo_wine lok((a), (b));
321 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
323 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
325 HRESULT r;
326 IShellLinkA *sl;
327 IPersistFile *pf;
329 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
330 &IID_IShellLinkA, (LPVOID*)&sl);
331 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
332 if (!SUCCEEDED(r))
333 return;
335 if (desc->description)
337 r = IShellLinkA_SetDescription(sl, desc->description);
338 lok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
340 if (desc->workdir)
342 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
343 lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
345 if (desc->path)
347 r = IShellLinkA_SetPath(sl, desc->path);
348 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
350 if (desc->pidl)
352 r = IShellLinkA_SetIDList(sl, desc->pidl);
353 lok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
355 if (desc->arguments)
357 r = IShellLinkA_SetArguments(sl, desc->arguments);
358 lok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
360 if (desc->showcmd)
362 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
363 lok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
365 if (desc->icon)
367 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
368 lok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
370 if (desc->hotkey)
372 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
373 lok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
376 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
377 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
378 if (SUCCEEDED(r))
380 r = IPersistFile_Save(pf, path, TRUE);
381 if (save_fails)
383 todo_wine {
384 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
387 else
389 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
391 IPersistFile_Release(pf);
394 IShellLinkA_Release(sl);
397 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
399 HRESULT r;
400 IShellLinkA *sl;
401 IPersistFile *pf;
402 char buffer[INFOTIPSIZE];
404 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
405 &IID_IShellLinkA, (LPVOID*)&sl);
406 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
407 if (!SUCCEEDED(r))
408 return;
410 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
411 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
412 if (!SUCCEEDED(r))
414 IShellLinkA_Release(sl);
415 return;
418 r = IPersistFile_Load(pf, path, STGM_READ);
419 lok(SUCCEEDED(r), "load failed (0x%08x)\n", r);
420 IPersistFile_Release(pf);
421 if (!SUCCEEDED(r))
423 IShellLinkA_Release(sl);
424 return;
427 if (desc->description)
429 strcpy(buffer,"garbage");
430 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
431 lok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
432 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
433 "GetDescription returned '%s' instead of '%s'\n",
434 buffer, desc->description);
436 if (desc->workdir)
438 strcpy(buffer,"garbage");
439 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
440 lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
441 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
442 "GetWorkingDirectory returned '%s' instead of '%s'\n",
443 buffer, desc->workdir);
445 if (desc->path)
447 strcpy(buffer,"garbage");
448 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
449 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
450 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
451 "GetPath returned '%s' instead of '%s'\n",
452 buffer, desc->path);
454 if (desc->pidl)
456 LPITEMIDLIST pidl=NULL;
457 r = IShellLinkA_GetIDList(sl, &pidl);
458 lok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
459 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
460 "GetIDList returned an incorrect pidl\n");
462 if (desc->showcmd)
464 int i=0xdeadbeef;
465 r = IShellLinkA_GetShowCmd(sl, &i);
466 lok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
467 lok_todo_4(0x10, i==desc->showcmd,
468 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
469 i, desc->showcmd);
471 if (desc->icon)
473 int i=0xdeadbeef;
474 strcpy(buffer,"garbage");
475 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
476 lok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
477 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
478 "GetIconLocation returned '%s' instead of '%s'\n",
479 buffer, desc->icon);
480 lok_todo_4(0x20, i==desc->icon_id,
481 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
482 i, desc->icon_id);
484 if (desc->hotkey)
486 WORD i=0xbeef;
487 r = IShellLinkA_GetHotkey(sl, &i);
488 lok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
489 lok_todo_4(0x40, i==desc->hotkey,
490 "GetHotkey returned 0x%04x instead of 0x%04x\n",
491 i, desc->hotkey);
494 IShellLinkA_Release(sl);
497 static void test_load_save(void)
499 WCHAR lnkfile[MAX_PATH];
500 static const WCHAR lnkfile_name[] = { '\\', 't', 'e', 's', 't', '.', 'l', 'n', 'k', '\0' };
502 char lnkfileA[MAX_PATH];
503 static const char lnkfileA_name[] = "\\test.lnk";
505 lnk_desc_t desc;
506 char mypath[MAX_PATH];
507 char mydir[MAX_PATH];
508 char realpath[MAX_PATH];
509 char* p;
510 HANDLE hf;
511 DWORD r;
513 if (!pGetLongPathNameA)
515 skip("GetLongPathNameA is not available\n");
516 return;
519 /* Don't used a fixed path for the test.lnk file */
520 GetTempPathW(MAX_PATH, lnkfile);
521 lstrcatW(lnkfile, lnkfile_name);
522 GetTempPathA(MAX_PATH, lnkfileA);
523 lstrcatA(lnkfileA, lnkfileA_name);
525 /* Save an empty .lnk file */
526 memset(&desc, 0, sizeof(desc));
527 create_lnk(lnkfile, &desc, 0);
529 /* It should come back as a bunch of empty strings */
530 desc.description="";
531 desc.workdir="";
532 desc.path="";
533 desc.arguments="";
534 desc.icon="";
535 check_lnk(lnkfile, &desc, 0x0);
537 /* Point a .lnk file to nonexistent files */
538 desc.description="";
539 desc.workdir="c:\\Nonexitent\\work\\directory";
540 desc.path="c:\\nonexistent\\path";
541 desc.pidl=NULL;
542 desc.arguments="";
543 desc.showcmd=0;
544 desc.icon="c:\\nonexistent\\icon\\file";
545 desc.icon_id=1234;
546 desc.hotkey=0;
547 create_lnk(lnkfile, &desc, 0);
548 check_lnk(lnkfile, &desc, 0x0);
550 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
551 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
552 strcpy(mydir, mypath);
553 p=strrchr(mydir, '\\');
554 if (p)
555 *p='\0';
557 /* IShellLink returns path in long form */
558 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
560 /* Overwrite the existing lnk file and point it to existing files */
561 desc.description="test 2";
562 desc.workdir=mydir;
563 desc.path=realpath;
564 desc.pidl=NULL;
565 desc.arguments="/option1 /option2 \"Some string\"";
566 desc.showcmd=SW_SHOWNORMAL;
567 desc.icon=mypath;
568 desc.icon_id=0;
569 desc.hotkey=0x1234;
570 create_lnk(lnkfile, &desc, 0);
571 check_lnk(lnkfile, &desc, 0x0);
573 /* Overwrite the existing lnk file and test link to a command on the path */
574 desc.description="command on path";
575 desc.workdir=mypath;
576 desc.path="rundll32.exe";
577 desc.pidl=NULL;
578 desc.arguments="/option1 /option2 \"Some string\"";
579 desc.showcmd=SW_SHOWNORMAL;
580 desc.icon=mypath;
581 desc.icon_id=0;
582 desc.hotkey=0x1234;
583 create_lnk(lnkfile, &desc, 0);
584 /* Check that link is created to proper location */
585 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
586 desc.path=realpath;
587 check_lnk(lnkfile, &desc, 0x0);
589 /* Create a temporary non-executable file */
590 r=GetTempPath(sizeof(mypath), mypath);
591 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
592 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
593 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
594 p=strrchr(mydir, '\\');
595 if (p)
596 *p='\0';
598 strcpy(mypath, mydir);
599 strcat(mypath, "\\test.txt");
600 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
601 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
602 CloseHandle(hf);
604 /* Overwrite the existing lnk file and test link to an existing non-executable file */
605 desc.description="non-executable file";
606 desc.workdir=mydir;
607 desc.path=mypath;
608 desc.pidl=NULL;
609 desc.arguments="";
610 desc.showcmd=SW_SHOWNORMAL;
611 desc.icon=mypath;
612 desc.icon_id=0;
613 desc.hotkey=0x1234;
614 create_lnk(lnkfile, &desc, 0);
615 check_lnk(lnkfile, &desc, 0x0);
617 r = DeleteFileA(mypath);
618 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
620 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
621 * represented as a path.
624 /* DeleteFileW is not implemented on Win9x */
625 r=DeleteFileA(lnkfileA);
626 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
629 static void test_datalink(void)
631 static const WCHAR lnk[] = {
632 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
633 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
634 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
635 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
636 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
637 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
638 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
639 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
640 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
641 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
642 static const WCHAR comp[] = {
643 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
644 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
645 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
646 IShellLinkDataList *dl = NULL;
647 IShellLinkW *sl = NULL;
648 HRESULT r;
649 DWORD flags = 0;
650 EXP_DARWIN_LINK *dar;
652 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
653 &IID_IShellLinkW, (LPVOID*)&sl );
654 ok( r == S_OK || r == E_NOINTERFACE, "CoCreateInstance failed (0x%08x)\n", r);
655 if (!sl)
657 skip("no shelllink\n");
658 return;
661 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
662 ok(r == S_OK, "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
664 if (!dl)
666 skip("no datalink interface\n");
667 return;
670 flags = 0;
671 r = IShellLinkDataList_GetFlags( dl, &flags );
672 ok( r == S_OK, "GetFlags failed\n");
673 ok( flags == 0, "GetFlags returned wrong flags\n");
675 dar = (void*)-1;
676 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
677 ok( r == E_FAIL, "CopyDataBlock failed\n");
678 ok( dar == NULL, "should be null\n");
680 r = IShellLinkW_SetPath(sl, lnk);
681 ok(r == S_OK, "set path failed\n");
684 * The following crashes:
685 * r = IShellLinkDataList_GetFlags( dl, NULL );
688 flags = 0;
689 r = IShellLinkDataList_GetFlags( dl, &flags );
690 ok( r == S_OK, "GetFlags failed\n");
691 ok( flags == (SLDF_HAS_DARWINID|SLDF_HAS_LOGO3ID),
692 "GetFlags returned wrong flags\n");
694 dar = NULL;
695 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
696 ok( r == S_OK, "CopyDataBlock failed\n");
698 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
699 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
701 LocalFree( dar );
703 IUnknown_Release( dl );
704 IShellLinkW_Release( sl );
707 START_TEST(shelllink)
709 HRESULT r;
710 HMODULE hmod = GetModuleHandleA("shell32.dll");
711 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
713 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
714 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
715 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
717 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
719 r = CoInitialize(NULL);
720 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
721 if (!SUCCEEDED(r))
722 return;
724 test_get_set();
725 test_load_save();
726 test_datalink();
728 CoUninitialize();