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(SUCCEEDED(r), "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(SUCCEEDED(r), "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(SUCCEEDED(r), "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(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
134 strcpy(buffer,"garbage");
135 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
136 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
137 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
139 /* Test Getting / Setting the work directory */
140 strcpy(buffer,"garbage");
141 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
142 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
143 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
145 str="c:\\nonexistent\\directory";
146 r = IShellLinkA_SetWorkingDirectory(sl, str);
147 ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
149 strcpy(buffer,"garbage");
150 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
151 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
152 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
154 /* Test Getting / Setting the path */
155 strcpy(buffer,"garbage");
156 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
157 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
158 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
160 CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
161 &IID_IShellLinkW, (LPVOID*)&slW);
163 skip("SetPath with NULL parameter crashes on Win9x\n");
166 IShellLinkW_Release(slW);
167 r = IShellLinkA_SetPath(sl, NULL);
168 ok(r==E_INVALIDARG ||
169 broken(r==S_OK), /* Some Win95 and NT4 */
170 "SetPath failed (0x%08x)\n", r);
173 r = IShellLinkA_SetPath(sl, "");
174 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
176 strcpy(buffer,"garbage");
177 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
178 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
179 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
181 /* Win98 returns S_FALSE, but WinXP returns S_OK */
182 str="c:\\nonexistent\\file";
183 r = IShellLinkA_SetPath(sl, str);
184 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
186 strcpy(buffer,"garbage");
187 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
188 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
189 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
191 /* Get some real path to play with */
192 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
193 strcat(mypath, "\\regedit.exe");
195 /* Test the interaction of SetPath and SetIDList */
197 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
198 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
203 strcpy(buffer,"garbage");
204 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
206 ok(ret, "SHGetPathFromIDListA failed\n");
209 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
213 pidl=path_to_pidl(mypath);
214 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
218 LPITEMIDLIST second_pidl;
220 r = IShellLinkA_SetIDList(sl, pidl);
221 ok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
224 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
225 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
226 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
227 "GetIDList returned an incorrect pidl\n");
229 r = IShellLinkA_GetIDList(sl, &second_pidl);
230 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
231 ok(second_pidl && pILIsEqual(pidl, second_pidl),
232 "GetIDList returned an incorrect pidl\n");
233 ok(second_pidl != tmp_pidl, "pidls are the same\n");
235 pILFree(second_pidl);
239 strcpy(buffer,"garbage");
240 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
241 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
243 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
247 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
248 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
249 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
251 strcpy(buffer,"garbage");
252 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
253 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
254 ok(!lstrcmp(buffer, "C:\\nonexistent\\file") ||
255 broken(!lstrcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
256 "case doesn't match\n");
258 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
259 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
261 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
262 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
264 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
265 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
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 /* Test Getting / Setting the arguments */
274 strcpy(buffer,"garbage");
275 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
276 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
277 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
279 str="param1 \"spaced param2\"";
280 r = IShellLinkA_SetArguments(sl, str);
281 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
283 strcpy(buffer,"garbage");
284 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
285 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
286 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
288 strcpy(buffer,"garbage");
289 r = IShellLinkA_SetArguments(sl, NULL);
290 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
291 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
292 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
293 ok(!buffer[0] || lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
295 strcpy(buffer,"garbage");
296 r = IShellLinkA_SetArguments(sl, "");
297 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
298 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
299 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
300 ok(!buffer[0], "GetArguments returned '%s'\n", buffer);
302 /* Test Getting / Setting showcmd */
304 r = IShellLinkA_GetShowCmd(sl, &i);
305 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
306 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
308 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
309 ok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
312 r = IShellLinkA_GetShowCmd(sl, &i);
313 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
314 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
316 /* Test Getting / Setting the icon */
318 strcpy(buffer,"garbage");
319 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
321 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
323 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
324 ok(i==0, "GetIconLocation returned %d\n", i);
326 str="c:\\nonexistent\\file";
327 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
328 ok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
331 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
332 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
333 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
334 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
336 /* Test Getting / Setting the hot key */
338 r = IShellLinkA_GetHotkey(sl, &w);
339 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
340 ok(w==0, "GetHotkey returned %d\n", w);
342 r = IShellLinkA_SetHotkey(sl, 0x5678);
343 ok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
346 r = IShellLinkA_GetHotkey(sl, &w);
347 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
348 ok(w==0x5678, "GetHotkey returned %d'\n", w);
350 IShellLinkA_Release(sl);
355 * Test saving and loading .lnk files
358 #define lok ok_(__FILE__, line)
359 #define lok_todo_4(todo_flag,a,b,c,d) \
360 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
361 else todo_wine lok((a), (b), (c), (d));
362 #define lok_todo_2(todo_flag,a,b) \
363 if ((todo & todo_flag) == 0) lok((a), (b)); \
364 else todo_wine lok((a), (b));
365 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
367 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
373 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
374 &IID_IShellLinkA, (LPVOID*)&sl);
375 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
379 if (desc->description)
381 r = IShellLinkA_SetDescription(sl, desc->description);
382 lok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
386 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
387 lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
391 r = IShellLinkA_SetPath(sl, desc->path);
392 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
396 r = IShellLinkA_SetIDList(sl, desc->pidl);
397 lok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
401 r = IShellLinkA_SetArguments(sl, desc->arguments);
402 lok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
406 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
407 lok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
411 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
412 lok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
416 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
417 lok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
420 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
421 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
424 CHAR buff[MAX_PATH], buff2[MAX_PATH];
431 r = IPersistFile_GetCurFile(pf, NULL);
434 /* test GetCurFile before ::Save */
435 str = (LPWSTR)0xdeadbeef;
436 r = IPersistFile_GetCurFile(pf, &str);
437 lok(r == S_FALSE, "got 0x%08x\n", r);
438 ok(str == NULL, "got %p\n", str);
440 r = IPersistFile_Save(pf, path, TRUE);
444 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
449 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
452 /* test GetCurFile after ::Save */
453 r = IPersistFile_GetCurFile(pf, &str);
454 lok(r == S_OK, "got 0x%08x\n", r);
456 WideCharToMultiByte( CP_ACP, 0, str, -1, buff, sizeof(buff), NULL, NULL );
457 WideCharToMultiByte( CP_ACP, 0, path, -1, buff2, sizeof(buff2), NULL, NULL );
459 lok(!strcmp(buff, buff2), "Expected %s, got %s\n", buff2, buff);
461 SHGetMalloc(&pmalloc);
462 IMalloc_Free(pmalloc, str);
463 IPersistFile_Release(pf);
466 IShellLinkA_Release(sl);
469 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
474 char buffer[INFOTIPSIZE];
475 CHAR buff[MAX_PATH], buff2[MAX_PATH];
479 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
480 &IID_IShellLinkA, (LPVOID*)&sl);
481 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
485 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
486 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
489 IShellLinkA_Release(sl);
493 SHGetMalloc(&pmalloc);
495 /* test GetCurFile before ::Load */
496 str = (LPWSTR)0xdeadbeef;
497 r = IPersistFile_GetCurFile(pf, &str);
498 lok(r == S_FALSE, "got 0x%08x\n", r);
499 lok(str == NULL, "got %p\n", str);
501 r = IPersistFile_Load(pf, path, STGM_READ);
502 lok(SUCCEEDED(r), "load failed (0x%08x)\n", r);
504 /* test GetCurFile after ::Save */
505 r = IPersistFile_GetCurFile(pf, &str);
506 lok(r == S_OK, "got 0x%08x\n", r);
508 WideCharToMultiByte( CP_ACP, 0, str, -1, buff, sizeof(buff), NULL, NULL );
509 WideCharToMultiByte( CP_ACP, 0, path, -1, buff2, sizeof(buff2), NULL, NULL );
511 lok(!strcmp(buff, buff2), "Expected %s, got %s\n", buff2, buff);
513 IMalloc_Free(pmalloc, str);
515 IPersistFile_Release(pf);
518 IShellLinkA_Release(sl);
522 if (desc->description)
524 strcpy(buffer,"garbage");
525 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
526 lok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
527 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
528 "GetDescription returned '%s' instead of '%s'\n",
529 buffer, desc->description);
533 strcpy(buffer,"garbage");
534 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
535 lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
536 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
537 "GetWorkingDirectory returned '%s' instead of '%s'\n",
538 buffer, desc->workdir);
542 strcpy(buffer,"garbage");
543 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
544 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
545 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
546 "GetPath returned '%s' instead of '%s'\n",
551 LPITEMIDLIST pidl=NULL;
552 r = IShellLinkA_GetIDList(sl, &pidl);
553 lok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
554 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
555 "GetIDList returned an incorrect pidl\n");
560 r = IShellLinkA_GetShowCmd(sl, &i);
561 lok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
562 lok_todo_4(0x10, i==desc->showcmd,
563 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
569 strcpy(buffer,"garbage");
570 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
571 lok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
572 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
573 "GetIconLocation returned '%s' instead of '%s'\n",
575 lok_todo_4(0x20, i==desc->icon_id,
576 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
582 r = IShellLinkA_GetHotkey(sl, &i);
583 lok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
584 lok_todo_4(0x40, i==desc->hotkey,
585 "GetHotkey returned 0x%04x instead of 0x%04x\n",
589 IShellLinkA_Release(sl);
592 static void test_load_save(void)
594 WCHAR lnkfile[MAX_PATH];
595 char lnkfileA[MAX_PATH];
596 static const char lnkfileA_name[] = "\\test.lnk";
599 char mypath[MAX_PATH];
600 char mydir[MAX_PATH];
601 char realpath[MAX_PATH];
606 if (!pGetLongPathNameA)
608 win_skip("GetLongPathNameA is not available\n");
612 /* Don't used a fixed path for the test.lnk file */
613 GetTempPathA(MAX_PATH, lnkfileA);
614 lstrcatA(lnkfileA, lnkfileA_name);
615 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
617 /* Save an empty .lnk file */
618 memset(&desc, 0, sizeof(desc));
619 create_lnk(lnkfile, &desc, 0);
621 /* It should come back as a bunch of empty strings */
627 check_lnk(lnkfile, &desc, 0x0);
629 /* Point a .lnk file to nonexistent files */
631 desc.workdir="c:\\Nonexitent\\work\\directory";
632 desc.path="c:\\nonexistent\\path";
636 desc.icon="c:\\nonexistent\\icon\\file";
639 create_lnk(lnkfile, &desc, 0);
640 check_lnk(lnkfile, &desc, 0x0);
642 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
643 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
644 strcpy(mydir, mypath);
645 p=strrchr(mydir, '\\');
649 /* IShellLink returns path in long form */
650 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
652 /* Overwrite the existing lnk file and point it to existing files */
653 desc.description="test 2";
657 desc.arguments="/option1 /option2 \"Some string\"";
658 desc.showcmd=SW_SHOWNORMAL;
662 create_lnk(lnkfile, &desc, 0);
663 check_lnk(lnkfile, &desc, 0x0);
665 /* Overwrite the existing lnk file and test link to a command on the path */
666 desc.description="command on path";
668 desc.path="rundll32.exe";
670 desc.arguments="/option1 /option2 \"Some string\"";
671 desc.showcmd=SW_SHOWNORMAL;
675 create_lnk(lnkfile, &desc, 0);
676 /* Check that link is created to proper location */
677 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
679 check_lnk(lnkfile, &desc, 0x0);
681 /* Create a temporary non-executable file */
682 r=GetTempPath(sizeof(mypath), mypath);
683 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
684 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
685 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
686 p=strrchr(mydir, '\\');
690 strcpy(mypath, mydir);
691 strcat(mypath, "\\test.txt");
692 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
693 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
696 /* Overwrite the existing lnk file and test link to an existing non-executable file */
697 desc.description="non-executable file";
702 desc.showcmd=SW_SHOWNORMAL;
706 create_lnk(lnkfile, &desc, 0);
707 check_lnk(lnkfile, &desc, 0x0);
709 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
710 strcpy(realpath, mypath);
711 strcat(realpath, "\\test.txt");
712 strcat(mypath, "\\\\test.txt");
714 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
715 desc.description="non-executable file";
720 desc.showcmd=SW_SHOWNORMAL;
724 create_lnk(lnkfile, &desc, 0);
726 check_lnk(lnkfile, &desc, 0x0);
728 r = DeleteFileA(mypath);
729 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
731 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
732 * represented as a path.
735 /* DeleteFileW is not implemented on Win9x */
736 r=DeleteFileA(lnkfileA);
737 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
740 static void test_datalink(void)
742 static const WCHAR lnk[] = {
743 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
744 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
745 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
746 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
747 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
748 '1','-',']',':',':',0 };
749 static const WCHAR comp[] = {
750 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
751 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
752 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
753 IShellLinkDataList *dl = NULL;
754 IShellLinkW *sl = NULL;
757 EXP_DARWIN_LINK *dar;
759 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
760 &IID_IShellLinkW, (LPVOID*)&sl );
762 broken(r == E_NOINTERFACE), /* Win9x */
763 "CoCreateInstance failed (0x%08x)\n", r);
766 win_skip("no shelllink\n");
770 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
772 broken(r == E_NOINTERFACE), /* NT4 */
773 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
777 win_skip("no datalink interface\n");
778 IShellLinkW_Release( sl );
783 r = IShellLinkDataList_GetFlags( dl, &flags );
784 ok( r == S_OK, "GetFlags failed\n");
785 ok( flags == 0, "GetFlags returned wrong flags\n");
788 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
789 ok( r == E_FAIL, "CopyDataBlock failed\n");
790 ok( dar == NULL, "should be null\n");
792 r = IShellLinkW_SetPath(sl, NULL);
793 ok(r == E_INVALIDARG, "set path failed\n");
795 r = IShellLinkW_SetPath(sl, lnk);
796 ok(r == S_OK, "set path failed\n");
800 /* the following crashes */
801 r = IShellLinkDataList_GetFlags( dl, NULL );
805 r = IShellLinkDataList_GetFlags( dl, &flags );
806 ok( r == S_OK, "GetFlags failed\n");
807 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
808 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
809 "GetFlags returned wrong flags\n");
812 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
813 ok( r == S_OK, "CopyDataBlock failed\n");
815 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
816 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
820 IUnknown_Release( dl );
821 IShellLinkW_Release( sl );
824 static void test_shdefextracticon(void)
826 HICON hiconlarge=NULL, hiconsmall=NULL;
829 if (!pSHDefExtractIconA)
831 win_skip("SHDefExtractIconA is unavailable\n");
835 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
836 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
837 ok(hiconlarge != NULL, "got null hiconlarge\n");
838 ok(hiconsmall != NULL, "got null hiconsmall\n");
839 DestroyIcon(hiconlarge);
840 DestroyIcon(hiconsmall);
843 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
844 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
845 ok(hiconsmall != NULL, "got null hiconsmall\n");
846 DestroyIcon(hiconsmall);
848 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
849 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
852 START_TEST(shelllink)
855 HMODULE hmod = GetModuleHandleA("shell32.dll");
856 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
858 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
859 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
860 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
861 pSHDefExtractIconA = (fnSHDefExtractIconA) GetProcAddress(hmod, "SHDefExtractIconA");
863 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
864 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
866 r = CoInitialize(NULL);
867 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
874 test_shdefextracticon();