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);
172 skip("SetPath with NULL parameter crashes on Win9x\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 failed (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 todo_wine ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
212 strcpy(buffer,"garbage");
213 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
215 ok(ret, "SHGetPathFromIDListA failed\n");
218 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
222 pidl=path_to_pidl(mypath);
223 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
227 LPITEMIDLIST second_pidl;
229 r = IShellLinkA_SetIDList(sl, pidl);
230 ok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
233 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
234 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
235 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
236 "GetIDList returned an incorrect pidl\n");
238 r = IShellLinkA_GetIDList(sl, &second_pidl);
239 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
240 ok(second_pidl && pILIsEqual(pidl, second_pidl),
241 "GetIDList returned an incorrect pidl\n");
242 ok(second_pidl != tmp_pidl, "pidls are the same\n");
244 pILFree(second_pidl);
248 strcpy(buffer,"garbage");
249 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
250 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
252 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
256 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
257 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
258 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
260 strcpy(buffer,"garbage");
261 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
262 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
263 ok(!lstrcmp(buffer, "C:\\nonexistent\\file") ||
264 broken(!lstrcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
265 "case doesn't match\n");
267 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
268 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
270 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
271 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
273 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
274 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
276 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
277 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
279 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
280 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
282 /* Test Getting / Setting the arguments */
283 strcpy(buffer,"garbage");
284 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
285 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
286 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
288 str="param1 \"spaced param2\"";
289 r = IShellLinkA_SetArguments(sl, str);
290 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
292 strcpy(buffer,"garbage");
293 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
294 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
295 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
297 strcpy(buffer,"garbage");
298 r = IShellLinkA_SetArguments(sl, NULL);
299 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
300 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
301 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
302 ok(!buffer[0] || lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
304 strcpy(buffer,"garbage");
305 r = IShellLinkA_SetArguments(sl, "");
306 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
307 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
308 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
309 ok(!buffer[0], "GetArguments returned '%s'\n", buffer);
311 /* Test Getting / Setting showcmd */
313 r = IShellLinkA_GetShowCmd(sl, &i);
314 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
315 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
317 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
318 ok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
321 r = IShellLinkA_GetShowCmd(sl, &i);
322 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
323 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
325 /* Test Getting / Setting the icon */
327 strcpy(buffer,"garbage");
328 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
330 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
332 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
333 ok(i==0, "GetIconLocation returned %d\n", i);
335 str="c:\\nonexistent\\file";
336 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
337 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
340 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
341 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
342 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
343 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
345 /* Test Getting / Setting the hot key */
347 r = IShellLinkA_GetHotkey(sl, &w);
348 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
349 ok(w==0, "GetHotkey returned %d\n", w);
351 r = IShellLinkA_SetHotkey(sl, 0x5678);
352 ok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
355 r = IShellLinkA_GetHotkey(sl, &w);
356 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
357 ok(w==0x5678, "GetHotkey returned %d'\n", w);
359 IShellLinkA_Release(sl);
364 * Test saving and loading .lnk files
367 #define lok ok_(__FILE__, line)
368 #define lok_todo_4(todo_flag,a,b,c,d) \
369 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
370 else todo_wine lok((a), (b), (c), (d));
371 #define lok_todo_2(todo_flag,a,b) \
372 if ((todo & todo_flag) == 0) lok((a), (b)); \
373 else todo_wine lok((a), (b));
374 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
376 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
382 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
383 &IID_IShellLinkA, (LPVOID*)&sl);
384 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
388 if (desc->description)
390 r = IShellLinkA_SetDescription(sl, desc->description);
391 lok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
395 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
396 lok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
400 r = IShellLinkA_SetPath(sl, desc->path);
401 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
405 r = IShellLinkA_SetIDList(sl, desc->pidl);
406 lok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
410 r = IShellLinkA_SetArguments(sl, desc->arguments);
411 lok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
415 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
416 lok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
420 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
421 lok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
425 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
426 lok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
429 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
430 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
438 r = IPersistFile_GetCurFile(pf, NULL);
441 /* test GetCurFile before ::Save */
442 str = (LPWSTR)0xdeadbeef;
443 r = IPersistFile_GetCurFile(pf, &str);
445 broken(r == S_OK), /* shell32 < 5.0 */
447 lok(str == NULL, "got %p\n", str);
449 r = IPersistFile_Save(pf, path, TRUE);
453 lok(r == S_OK, "save failed (0x%08x)\n", r);
458 lok(r == S_OK, "save failed (0x%08x)\n", r);
461 /* test GetCurFile after ::Save */
462 r = IPersistFile_GetCurFile(pf, &str);
463 lok(r == S_OK, "got 0x%08x\n", r);
465 broken(str == NULL), /* shell32 < 5.0 */
466 "Didn't expect NULL\n");
471 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
472 wine_dbgstr_w(path), wine_dbgstr_w(str));
474 SHGetMalloc(&pmalloc);
475 IMalloc_Free(pmalloc, str);
478 win_skip("GetCurFile fails on shell32 < 5.0\n");
480 IPersistFile_Release(pf);
483 IShellLinkA_Release(sl);
486 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
491 char buffer[INFOTIPSIZE];
494 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
495 &IID_IShellLinkA, (LPVOID*)&sl);
496 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
500 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
501 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
504 IShellLinkA_Release(sl);
508 /* test GetCurFile before ::Load */
509 str = (LPWSTR)0xdeadbeef;
510 r = IPersistFile_GetCurFile(pf, &str);
512 broken(r == S_OK), /* shell32 < 5.0 */
514 lok(str == NULL, "got %p\n", str);
516 r = IPersistFile_Load(pf, path, STGM_READ);
517 lok(r == S_OK, "load failed (0x%08x)\n", r);
519 /* test GetCurFile after ::Save */
520 r = IPersistFile_GetCurFile(pf, &str);
521 lok(r == S_OK, "got 0x%08x\n", r);
523 broken(str == NULL), /* shell32 < 5.0 */
524 "Didn't expect NULL\n");
529 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
530 wine_dbgstr_w(path), wine_dbgstr_w(str));
532 SHGetMalloc(&pmalloc);
533 IMalloc_Free(pmalloc, str);
536 win_skip("GetCurFile fails on shell32 < 5.0\n");
538 IPersistFile_Release(pf);
541 IShellLinkA_Release(sl);
545 if (desc->description)
547 strcpy(buffer,"garbage");
548 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
549 lok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
550 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
551 "GetDescription returned '%s' instead of '%s'\n",
552 buffer, desc->description);
556 strcpy(buffer,"garbage");
557 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
558 lok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
559 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
560 "GetWorkingDirectory returned '%s' instead of '%s'\n",
561 buffer, desc->workdir);
565 strcpy(buffer,"garbage");
566 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
567 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
568 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
569 "GetPath returned '%s' instead of '%s'\n",
574 LPITEMIDLIST pidl=NULL;
575 r = IShellLinkA_GetIDList(sl, &pidl);
576 lok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
577 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
578 "GetIDList returned an incorrect pidl\n");
583 r = IShellLinkA_GetShowCmd(sl, &i);
584 lok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
585 lok_todo_4(0x10, i==desc->showcmd,
586 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
592 strcpy(buffer,"garbage");
593 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
594 lok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
595 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
596 "GetIconLocation returned '%s' instead of '%s'\n",
598 lok_todo_4(0x20, i==desc->icon_id,
599 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
605 r = IShellLinkA_GetHotkey(sl, &i);
606 lok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
607 lok_todo_4(0x40, i==desc->hotkey,
608 "GetHotkey returned 0x%04x instead of 0x%04x\n",
612 IShellLinkA_Release(sl);
615 static void test_load_save(void)
617 WCHAR lnkfile[MAX_PATH];
618 char lnkfileA[MAX_PATH];
619 static const char lnkfileA_name[] = "\\test.lnk";
622 char mypath[MAX_PATH];
623 char mydir[MAX_PATH];
624 char realpath[MAX_PATH];
629 if (!pGetLongPathNameA)
631 win_skip("GetLongPathNameA is not available\n");
635 /* Don't used a fixed path for the test.lnk file */
636 GetTempPathA(MAX_PATH, lnkfileA);
637 lstrcatA(lnkfileA, lnkfileA_name);
638 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
640 /* Save an empty .lnk file */
641 memset(&desc, 0, sizeof(desc));
642 create_lnk(lnkfile, &desc, 0);
644 /* It should come back as a bunch of empty strings */
650 check_lnk(lnkfile, &desc, 0x0);
652 /* Point a .lnk file to nonexistent files */
654 desc.workdir="c:\\Nonexitent\\work\\directory";
655 desc.path="c:\\nonexistent\\path";
659 desc.icon="c:\\nonexistent\\icon\\file";
662 create_lnk(lnkfile, &desc, 0);
663 check_lnk(lnkfile, &desc, 0x0);
665 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
666 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
667 strcpy(mydir, mypath);
668 p=strrchr(mydir, '\\');
672 /* IShellLink returns path in long form */
673 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
675 /* Overwrite the existing lnk file and point it to existing files */
676 desc.description="test 2";
680 desc.arguments="/option1 /option2 \"Some string\"";
681 desc.showcmd=SW_SHOWNORMAL;
685 create_lnk(lnkfile, &desc, 0);
686 check_lnk(lnkfile, &desc, 0x0);
688 /* Overwrite the existing lnk file and test link to a command on the path */
689 desc.description="command on path";
691 desc.path="rundll32.exe";
693 desc.arguments="/option1 /option2 \"Some string\"";
694 desc.showcmd=SW_SHOWNORMAL;
698 create_lnk(lnkfile, &desc, 0);
699 /* Check that link is created to proper location */
700 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
702 check_lnk(lnkfile, &desc, 0x0);
704 /* Create a temporary non-executable file */
705 r=GetTempPath(sizeof(mypath), mypath);
706 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
707 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
708 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
709 p=strrchr(mydir, '\\');
713 strcpy(mypath, mydir);
714 strcat(mypath, "\\test.txt");
715 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
716 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
719 /* Overwrite the existing lnk file and test link to an existing non-executable file */
720 desc.description="non-executable file";
725 desc.showcmd=SW_SHOWNORMAL;
729 create_lnk(lnkfile, &desc, 0);
730 check_lnk(lnkfile, &desc, 0x0);
732 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
733 strcpy(realpath, mypath);
734 strcat(realpath, "\\test.txt");
735 strcat(mypath, "\\\\test.txt");
737 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
738 desc.description="non-executable file";
743 desc.showcmd=SW_SHOWNORMAL;
747 create_lnk(lnkfile, &desc, 0);
749 check_lnk(lnkfile, &desc, 0x0);
751 r = DeleteFileA(mypath);
752 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
754 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
755 * represented as a path.
758 /* DeleteFileW is not implemented on Win9x */
759 r=DeleteFileA(lnkfileA);
760 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
763 static void test_datalink(void)
765 static const WCHAR lnk[] = {
766 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
767 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
768 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
769 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
770 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
771 '1','-',']',':',':',0 };
772 static const WCHAR comp[] = {
773 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
774 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
775 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
776 IShellLinkDataList *dl = NULL;
777 IShellLinkW *sl = NULL;
780 EXP_DARWIN_LINK *dar;
782 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
783 &IID_IShellLinkW, (LPVOID*)&sl );
785 broken(r == E_NOINTERFACE), /* Win9x */
786 "CoCreateInstance failed (0x%08x)\n", r);
789 win_skip("no shelllink\n");
793 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
795 broken(r == E_NOINTERFACE), /* NT4 */
796 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
800 win_skip("no datalink interface\n");
801 IShellLinkW_Release( sl );
806 r = IShellLinkDataList_GetFlags( dl, &flags );
807 ok( r == S_OK, "GetFlags failed\n");
808 ok( flags == 0, "GetFlags returned wrong flags\n");
811 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
812 ok( r == E_FAIL, "CopyDataBlock failed\n");
813 ok( dar == NULL, "should be null\n");
815 r = IShellLinkW_SetPath(sl, NULL);
816 ok(r == E_INVALIDARG, "set path failed\n");
818 r = IShellLinkW_SetPath(sl, lnk);
819 ok(r == S_OK, "set path failed\n");
823 /* the following crashes */
824 r = IShellLinkDataList_GetFlags( dl, NULL );
828 r = IShellLinkDataList_GetFlags( dl, &flags );
829 ok( r == S_OK, "GetFlags failed\n");
830 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
831 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
832 "GetFlags returned wrong flags\n");
835 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
836 ok( r == S_OK, "CopyDataBlock failed\n");
838 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
839 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
843 IUnknown_Release( dl );
844 IShellLinkW_Release( sl );
847 static void test_shdefextracticon(void)
849 HICON hiconlarge=NULL, hiconsmall=NULL;
852 if (!pSHDefExtractIconA)
854 win_skip("SHDefExtractIconA is unavailable\n");
858 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
859 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
860 ok(hiconlarge != NULL, "got null hiconlarge\n");
861 ok(hiconsmall != NULL, "got null hiconsmall\n");
862 DestroyIcon(hiconlarge);
863 DestroyIcon(hiconsmall);
866 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
867 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
868 ok(hiconsmall != NULL, "got null hiconsmall\n");
869 DestroyIcon(hiconsmall);
871 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
872 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
875 START_TEST(shelllink)
878 HMODULE hmod = GetModuleHandleA("shell32.dll");
879 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
881 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
882 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
883 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
884 pSHDefExtractIconA = (fnSHDefExtractIconA) GetProcAddress(hmod, "SHDefExtractIconA");
886 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
887 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
889 r = CoInitialize(NULL);
890 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
897 test_shdefextracticon();