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).
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 */
40 typedef void (WINAPI *fnILFree)(LPITEMIDLIST);
41 typedef BOOL (WINAPI *fnILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
42 typedef HRESULT (WINAPI *fnSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
43 typedef HRESULT (WINAPI *fnSHDefExtractIconA)(LPCSTR, int, UINT, HICON*, HICON*, UINT);
45 static fnILFree pILFree;
46 static fnILIsEqual pILIsEqual;
47 static fnSHILCreateFromPath pSHILCreateFromPath;
48 static fnSHDefExtractIconA pSHDefExtractIconA;
50 static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR, LPSTR, DWORD);
51 static DWORD (WINAPI *pGetShortPathNameA)(LPCSTR, LPSTR, DWORD);
53 static const GUID _IID_IShellLinkDataList = {
54 0x45e2b4ae, 0xb1c3, 0x11d0,
55 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
58 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
61 /* For some reason SHILCreateFromPath does not work on Win98 and
62 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
63 * get what we want on all platforms.
65 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
67 static LPITEMIDLIST path_to_pidl(const char* path)
71 if (!pSHSimpleIDListFromPathAW)
73 HMODULE hdll=GetModuleHandleA("shell32.dll");
74 pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
75 if (!pSHSimpleIDListFromPathAW)
76 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
80 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
81 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
82 pidl=pSHSimpleIDListFromPathAW(path);
90 len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
91 pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
92 MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
94 r=pSHILCreateFromPath(pathW, &pidl, NULL);
95 ok(r == S_OK, "SHILCreateFromPath failed (0x%08x)\n", r);
96 HeapFree(GetProcessHeap(), 0, pathW);
103 * Test manipulation of an IShellLink's properties.
106 static void test_get_set(void)
110 IShellLinkW *slW = NULL;
111 char mypath[MAX_PATH];
112 char buffer[INFOTIPSIZE];
113 LPITEMIDLIST pidl, tmp_pidl;
118 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
119 &IID_IShellLinkA, (LPVOID*)&sl);
120 ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
124 /* Test Getting / Setting the description */
125 strcpy(buffer,"garbage");
126 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
127 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
128 ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
130 str="Some description";
131 r = IShellLinkA_SetDescription(sl, str);
132 ok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
134 strcpy(buffer,"garbage");
135 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
136 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
137 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
139 r = IShellLinkA_SetDescription(sl, NULL);
140 ok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
142 strcpy(buffer,"garbage");
143 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
144 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
145 ok(*buffer=='\0' || broken(lstrcmp(buffer,str)==0), "GetDescription returned '%s'\n", buffer); /* NT4 */
148 /* Test Getting / Setting the work directory */
149 strcpy(buffer,"garbage");
150 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
151 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
152 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
154 str="c:\\nonexistent\\directory";
155 r = IShellLinkA_SetWorkingDirectory(sl, str);
156 ok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
158 strcpy(buffer,"garbage");
159 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
160 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
161 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
163 /* Test Getting / Setting the path */
164 strcpy(buffer,"garbage");
165 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
166 todo_wine ok(r == S_FALSE || broken(r == S_OK) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r);
167 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
169 CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
170 &IID_IShellLinkW, (LPVOID*)&slW);
171 if (!slW /* Win9x */ || !pGetLongPathNameA /* NT4 */)
172 skip("SetPath with NULL parameter crashes on Win9x and some NT4\n");
175 IShellLinkW_Release(slW);
176 r = IShellLinkA_SetPath(sl, NULL);
177 ok(r==E_INVALIDARG ||
178 broken(r==S_OK), /* Some Win95 and NT4 */
179 "SetPath returned wrong error (0x%08x)\n", r);
182 r = IShellLinkA_SetPath(sl, "");
183 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
185 strcpy(buffer,"garbage");
186 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
187 todo_wine ok(r == S_FALSE, "GetPath failed (0x%08x)\n", r);
188 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
190 /* Win98 returns S_FALSE, but WinXP returns S_OK */
191 str="c:\\nonexistent\\file";
192 r = IShellLinkA_SetPath(sl, str);
193 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
195 strcpy(buffer,"garbage");
196 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
197 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
198 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
200 /* Get some real path to play with */
201 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
202 strcat(mypath, "\\regedit.exe");
204 /* Test the interaction of SetPath and SetIDList */
206 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
207 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
212 strcpy(buffer,"garbage");
213 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
214 ok(ret, "SHGetPathFromIDListA failed\n");
216 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
220 pidl=path_to_pidl(mypath);
221 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
225 LPITEMIDLIST second_pidl;
227 r = IShellLinkA_SetIDList(sl, pidl);
228 ok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
231 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
232 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
233 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
234 "GetIDList returned an incorrect pidl\n");
236 r = IShellLinkA_GetIDList(sl, &second_pidl);
237 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
238 ok(second_pidl && pILIsEqual(pidl, second_pidl),
239 "GetIDList returned an incorrect pidl\n");
240 ok(second_pidl != tmp_pidl, "pidls are the same\n");
242 pILFree(second_pidl);
246 strcpy(buffer,"garbage");
247 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
248 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
250 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
254 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
255 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
256 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
258 strcpy(buffer,"garbage");
259 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
260 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
261 ok(!lstrcmp(buffer, "C:\\nonexistent\\file") ||
262 broken(!lstrcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
263 "case doesn't match\n");
265 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
266 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
268 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
269 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
271 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
272 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
274 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
275 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
277 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
278 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
280 /* Test Getting / Setting the arguments */
281 strcpy(buffer,"garbage");
282 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
283 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
284 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
286 str="param1 \"spaced param2\"";
287 r = IShellLinkA_SetArguments(sl, str);
288 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
290 strcpy(buffer,"garbage");
291 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
292 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
293 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
295 strcpy(buffer,"garbage");
296 r = IShellLinkA_SetArguments(sl, NULL);
297 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
298 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
299 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
300 ok(!buffer[0] || lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
302 strcpy(buffer,"garbage");
303 r = IShellLinkA_SetArguments(sl, "");
304 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
305 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
306 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
307 ok(!buffer[0], "GetArguments returned '%s'\n", buffer);
309 /* Test Getting / Setting showcmd */
311 r = IShellLinkA_GetShowCmd(sl, &i);
312 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
313 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
315 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
316 ok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
319 r = IShellLinkA_GetShowCmd(sl, &i);
320 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
321 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
323 /* Test Getting / Setting the icon */
325 strcpy(buffer,"garbage");
326 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
327 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
328 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
329 ok(i==0, "GetIconLocation returned %d\n", i);
331 str="c:\\nonexistent\\file";
332 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
333 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
336 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
337 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
338 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
339 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
341 /* Test Getting / Setting the hot key */
343 r = IShellLinkA_GetHotkey(sl, &w);
344 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
345 ok(w==0, "GetHotkey returned %d\n", w);
347 r = IShellLinkA_SetHotkey(sl, 0x5678);
348 ok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
351 r = IShellLinkA_GetHotkey(sl, &w);
352 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
353 ok(w==0x5678, "GetHotkey returned %d'\n", w);
355 IShellLinkA_Release(sl);
360 * Test saving and loading .lnk files
363 #define lok ok_(__FILE__, line)
364 #define lok_todo_4(todo_flag,a,b,c,d) \
365 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
366 else todo_wine lok((a), (b), (c), (d));
367 #define lok_todo_2(todo_flag,a,b) \
368 if ((todo & todo_flag) == 0) lok((a), (b)); \
369 else todo_wine lok((a), (b));
370 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
372 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
378 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
379 &IID_IShellLinkA, (LPVOID*)&sl);
380 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
384 if (desc->description)
386 r = IShellLinkA_SetDescription(sl, desc->description);
387 lok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
391 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
392 lok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
396 r = IShellLinkA_SetPath(sl, desc->path);
397 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
401 r = IShellLinkA_SetIDList(sl, desc->pidl);
402 lok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
406 r = IShellLinkA_SetArguments(sl, desc->arguments);
407 lok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
411 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
412 lok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
416 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
417 lok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
421 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
422 lok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
425 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
426 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
434 r = IPersistFile_GetCurFile(pf, NULL);
437 /* test GetCurFile before ::Save */
438 str = (LPWSTR)0xdeadbeef;
439 r = IPersistFile_GetCurFile(pf, &str);
441 broken(r == S_OK), /* shell32 < 5.0 */
443 lok(str == NULL, "got %p\n", str);
445 r = IPersistFile_Save(pf, path, TRUE);
449 lok(r == S_OK, "save failed (0x%08x)\n", r);
454 lok(r == S_OK, "save failed (0x%08x)\n", r);
457 /* test GetCurFile after ::Save */
458 r = IPersistFile_GetCurFile(pf, &str);
459 lok(r == S_OK, "got 0x%08x\n", r);
461 broken(str == NULL), /* shell32 < 5.0 */
462 "Didn't expect NULL\n");
467 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
468 wine_dbgstr_w(path), wine_dbgstr_w(str));
470 SHGetMalloc(&pmalloc);
471 IMalloc_Free(pmalloc, str);
474 win_skip("GetCurFile fails on shell32 < 5.0\n");
476 IPersistFile_Release(pf);
479 IShellLinkA_Release(sl);
482 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
487 char buffer[INFOTIPSIZE];
490 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
491 &IID_IShellLinkA, (LPVOID*)&sl);
492 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
496 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
497 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
500 IShellLinkA_Release(sl);
504 /* test GetCurFile before ::Load */
505 str = (LPWSTR)0xdeadbeef;
506 r = IPersistFile_GetCurFile(pf, &str);
508 broken(r == S_OK), /* shell32 < 5.0 */
510 lok(str == NULL, "got %p\n", str);
512 r = IPersistFile_Load(pf, path, STGM_READ);
513 lok(r == S_OK, "load failed (0x%08x)\n", r);
515 /* test GetCurFile after ::Save */
516 r = IPersistFile_GetCurFile(pf, &str);
517 lok(r == S_OK, "got 0x%08x\n", r);
519 broken(str == NULL), /* shell32 < 5.0 */
520 "Didn't expect NULL\n");
525 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
526 wine_dbgstr_w(path), wine_dbgstr_w(str));
528 SHGetMalloc(&pmalloc);
529 IMalloc_Free(pmalloc, str);
532 win_skip("GetCurFile fails on shell32 < 5.0\n");
534 IPersistFile_Release(pf);
537 IShellLinkA_Release(sl);
541 if (desc->description)
543 strcpy(buffer,"garbage");
544 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
545 lok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
546 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
547 "GetDescription returned '%s' instead of '%s'\n",
548 buffer, desc->description);
552 strcpy(buffer,"garbage");
553 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
554 lok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
555 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
556 "GetWorkingDirectory returned '%s' instead of '%s'\n",
557 buffer, desc->workdir);
561 strcpy(buffer,"garbage");
562 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
563 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
564 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
565 "GetPath returned '%s' instead of '%s'\n",
570 LPITEMIDLIST pidl=NULL;
571 r = IShellLinkA_GetIDList(sl, &pidl);
572 lok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
573 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
574 "GetIDList returned an incorrect pidl\n");
579 r = IShellLinkA_GetShowCmd(sl, &i);
580 lok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
581 lok_todo_4(0x10, i==desc->showcmd,
582 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
588 strcpy(buffer,"garbage");
589 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
590 lok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
591 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
592 "GetIconLocation returned '%s' instead of '%s'\n",
594 lok_todo_4(0x20, i==desc->icon_id,
595 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
601 r = IShellLinkA_GetHotkey(sl, &i);
602 lok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
603 lok_todo_4(0x40, i==desc->hotkey,
604 "GetHotkey returned 0x%04x instead of 0x%04x\n",
608 IShellLinkA_Release(sl);
611 static void test_load_save(void)
613 WCHAR lnkfile[MAX_PATH];
614 char lnkfileA[MAX_PATH];
615 static const char lnkfileA_name[] = "\\test.lnk";
618 char mypath[MAX_PATH];
619 char mydir[MAX_PATH];
620 char realpath[MAX_PATH];
625 if (!pGetLongPathNameA)
627 win_skip("GetLongPathNameA is not available\n");
631 /* Don't used a fixed path for the test.lnk file */
632 GetTempPathA(MAX_PATH, lnkfileA);
633 lstrcatA(lnkfileA, lnkfileA_name);
634 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
636 /* Save an empty .lnk file */
637 memset(&desc, 0, sizeof(desc));
638 create_lnk(lnkfile, &desc, 0);
640 /* It should come back as a bunch of empty strings */
646 check_lnk(lnkfile, &desc, 0x0);
648 /* Point a .lnk file to nonexistent files */
650 desc.workdir="c:\\Nonexitent\\work\\directory";
651 desc.path="c:\\nonexistent\\path";
655 desc.icon="c:\\nonexistent\\icon\\file";
658 create_lnk(lnkfile, &desc, 0);
659 check_lnk(lnkfile, &desc, 0x0);
661 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
662 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
663 strcpy(mydir, mypath);
664 p=strrchr(mydir, '\\');
668 /* IShellLink returns path in long form */
669 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
671 /* Overwrite the existing lnk file and point it to existing files */
672 desc.description="test 2";
676 desc.arguments="/option1 /option2 \"Some string\"";
677 desc.showcmd=SW_SHOWNORMAL;
681 create_lnk(lnkfile, &desc, 0);
682 check_lnk(lnkfile, &desc, 0x0);
684 /* Overwrite the existing lnk file and test link to a command on the path */
685 desc.description="command on path";
687 desc.path="rundll32.exe";
689 desc.arguments="/option1 /option2 \"Some string\"";
690 desc.showcmd=SW_SHOWNORMAL;
694 create_lnk(lnkfile, &desc, 0);
695 /* Check that link is created to proper location */
696 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
698 check_lnk(lnkfile, &desc, 0x0);
700 /* Create a temporary non-executable file */
701 r=GetTempPath(sizeof(mypath), mypath);
702 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
703 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
704 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
705 p=strrchr(mydir, '\\');
709 strcpy(mypath, mydir);
710 strcat(mypath, "\\test.txt");
711 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
712 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
715 /* Overwrite the existing lnk file and test link to an existing non-executable file */
716 desc.description="non-executable file";
721 desc.showcmd=SW_SHOWNORMAL;
725 create_lnk(lnkfile, &desc, 0);
726 check_lnk(lnkfile, &desc, 0x0);
728 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
729 strcpy(realpath, mypath);
730 strcat(realpath, "\\test.txt");
731 strcat(mypath, "\\\\test.txt");
733 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
734 desc.description="non-executable file";
739 desc.showcmd=SW_SHOWNORMAL;
743 create_lnk(lnkfile, &desc, 0);
745 check_lnk(lnkfile, &desc, 0x0);
747 r = DeleteFileA(mypath);
748 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
750 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
751 * represented as a path.
754 /* DeleteFileW is not implemented on Win9x */
755 r=DeleteFileA(lnkfileA);
756 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
759 static void test_datalink(void)
761 static const WCHAR lnk[] = {
762 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
763 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
764 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
765 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
766 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
767 '1','-',']',':',':',0 };
768 static const WCHAR comp[] = {
769 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
770 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
771 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
772 IShellLinkDataList *dl = NULL;
773 IShellLinkW *sl = NULL;
776 EXP_DARWIN_LINK *dar;
778 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
779 &IID_IShellLinkW, (LPVOID*)&sl );
781 broken(r == E_NOINTERFACE), /* Win9x */
782 "CoCreateInstance failed (0x%08x)\n", r);
785 win_skip("no shelllink\n");
789 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
791 broken(r == E_NOINTERFACE), /* NT4 */
792 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
796 win_skip("no datalink interface\n");
797 IShellLinkW_Release( sl );
802 r = IShellLinkDataList_GetFlags( dl, &flags );
803 ok( r == S_OK, "GetFlags failed\n");
804 ok( flags == 0, "GetFlags returned wrong flags\n");
807 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
808 ok( r == E_FAIL, "CopyDataBlock failed\n");
809 ok( dar == NULL, "should be null\n");
811 if (!pGetLongPathNameA /* NT4 */)
812 skip("SetPath with NULL parameter crashes on NT4\n");
815 r = IShellLinkW_SetPath(sl, NULL);
816 ok(r == E_INVALIDARG, "SetPath returned wrong error (0x%08x)\n", r);
819 r = IShellLinkW_SetPath(sl, lnk);
820 ok(r == S_OK, "SetPath failed\n");
824 /* the following crashes */
825 r = IShellLinkDataList_GetFlags( dl, NULL );
829 r = IShellLinkDataList_GetFlags( dl, &flags );
830 ok( r == S_OK, "GetFlags failed\n");
831 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
832 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
833 "GetFlags returned wrong flags\n");
836 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
837 ok( r == S_OK, "CopyDataBlock failed\n");
839 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
840 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
844 IUnknown_Release( dl );
845 IShellLinkW_Release( sl );
848 static void test_shdefextracticon(void)
850 HICON hiconlarge=NULL, hiconsmall=NULL;
853 if (!pSHDefExtractIconA)
855 win_skip("SHDefExtractIconA is unavailable\n");
859 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
860 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
861 ok(hiconlarge != NULL, "got null hiconlarge\n");
862 ok(hiconsmall != NULL, "got null hiconsmall\n");
863 DestroyIcon(hiconlarge);
864 DestroyIcon(hiconsmall);
867 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
868 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
869 ok(hiconsmall != NULL, "got null hiconsmall\n");
870 DestroyIcon(hiconsmall);
872 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
873 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
876 static void test_GetIconLocation(void)
880 char buffer[INFOTIPSIZE], mypath[MAX_PATH];
885 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
886 &IID_IShellLinkA, (LPVOID*)&sl);
887 ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
892 strcpy(buffer, "garbage");
893 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
894 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
895 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
896 ok(i == 0, "GetIconLocation returned %d\n", i);
898 str = "c:\\some\\path";
899 r = IShellLinkA_SetPath(sl, str);
900 ok(r == S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
903 strcpy(buffer, "garbage");
904 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
905 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
906 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
907 ok(i == 0, "GetIconLocation returned %d\n", i);
909 GetWindowsDirectoryA(mypath, sizeof(mypath) - 12);
910 strcat(mypath, "\\regedit.exe");
911 pidl = path_to_pidl(mypath);
912 r = IShellLinkA_SetIDList(sl, pidl);
913 ok(r == S_OK, "SetPath failed (0x%08x)\n", r);
916 strcpy(buffer, "garbage");
917 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
918 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
919 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
920 ok(i == 0, "GetIconLocation returned %d\n", i);
922 str = "c:\\nonexistent\\file";
923 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
924 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
927 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
928 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
929 ok(lstrcmpi(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
930 ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
932 IShellLinkA_Release(sl);
935 START_TEST(shelllink)
938 HMODULE hmod = GetModuleHandleA("shell32.dll");
939 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
941 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
942 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
943 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
944 pSHDefExtractIconA = (fnSHDefExtractIconA) GetProcAddress(hmod, "SHDefExtractIconA");
946 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
947 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
949 r = CoInitialize(NULL);
950 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
957 test_shdefextracticon();
958 test_GetIconLocation();