shell32: Microsoft's EXP_DARWIN_LINK structure does not have a dbh
[wine] / dlls / shell32 / tests / shelllink.c
1 /*
2  * Unit tests for shelllinks
3  *
4  * Copyright 2004 Mike McCormack
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20  * of shell32, that get either a filesytem path or a LPITEMIDLIST (shell
21  * namespace) path for a given folder (CSIDL value).
22  *
23  */
24
25 #define COBJMACROS
26
27 #include <windows.h>
28 #include "shlguid.h"
29 #include "shobjidl.h"
30 #include "shlobj.h"
31 #include "wine/test.h"
32
33 #include "shell32_test.h"
34
35
36 typedef void (WINAPI *fnILFree)(LPITEMIDLIST);
37 typedef BOOL (WINAPI *fnILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
38 typedef HRESULT (WINAPI *fnSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
39
40 static fnILFree pILFree;
41 static fnILIsEqual pILIsEqual;
42 static fnSHILCreateFromPath pSHILCreateFromPath;
43
44 static const GUID _IID_IShellLinkDataList = {
45     0x45e2b4ae, 0xb1c3, 0x11d0,
46     { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
47 };
48
49 static const WCHAR lnkfile[]= { 'C',':','\\','t','e','s','t','.','l','n','k',0 };
50 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
51
52
53 /* For some reason SHILCreateFromPath does not work on Win98 and
54  * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
55  * get what we want on all platforms.
56  */
57 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
58
59 static LPITEMIDLIST path_to_pidl(const char* path)
60 {
61     LPITEMIDLIST pidl;
62
63     if (!pSHSimpleIDListFromPathAW)
64     {
65         HMODULE hdll=LoadLibraryA("shell32.dll");
66         pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
67         if (!pSHSimpleIDListFromPathAW)
68             trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
69     }
70
71     pidl=NULL;
72     /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
73     if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
74         pidl=pSHSimpleIDListFromPathAW(path);
75
76     if (!pidl)
77     {
78         WCHAR* pathW;
79         HRESULT r;
80         int len;
81
82         len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
83         pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
84         MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
85
86         r=pSHILCreateFromPath(pathW, &pidl, NULL);
87         todo_wine {
88         ok(SUCCEEDED(r), "SHILCreateFromPath failed (0x%08lx)\n", r);
89         }
90         HeapFree(GetProcessHeap(), 0, pathW);
91     }
92     return pidl;
93 }
94
95
96 /*
97  * Test manipulation of an IShellLink's properties.
98  */
99
100 static void test_get_set(void)
101 {
102     HRESULT r;
103     IShellLinkA *sl;
104     char mypath[MAX_PATH];
105     char buffer[INFOTIPSIZE];
106     LPITEMIDLIST pidl, tmp_pidl;
107     const char * str;
108     int i;
109     WORD w;
110
111     r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
112                          &IID_IShellLinkA, (LPVOID*)&sl);
113     ok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08lx)\n", r);
114     if (!SUCCEEDED(r))
115         return;
116
117     /* Test Getting / Setting the description */
118     strcpy(buffer,"garbage");
119     r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
120     ok(SUCCEEDED(r), "GetDescription failed (0x%08lx)\n", r);
121     ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
122
123     str="Some description";
124     r = IShellLinkA_SetDescription(sl, str);
125     ok(SUCCEEDED(r), "SetDescription failed (0x%08lx)\n", r);
126
127     strcpy(buffer,"garbage");
128     r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
129     ok(SUCCEEDED(r), "GetDescription failed (0x%08lx)\n", r);
130     ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
131
132     /* Test Getting / Setting the work directory */
133     strcpy(buffer,"garbage");
134     r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
135     ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08lx)\n", r);
136     ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
137
138     str="c:\\nonexistent\\directory";
139     r = IShellLinkA_SetWorkingDirectory(sl, str);
140     ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08lx)\n", r);
141
142     strcpy(buffer,"garbage");
143     r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
144     ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08lx)\n", r);
145     ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
146
147     /* Test Getting / Setting the work directory */
148     strcpy(buffer,"garbage");
149     r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
150     ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r);
151     ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
152
153     r = IShellLinkA_SetPath(sl, "");
154     ok(r==S_OK, "SetPath failed (0x%08lx)\n", r);
155
156     strcpy(buffer,"garbage");
157     r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
158     ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r);
159     ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
160
161     str="c:\\nonexistent\\file";
162     r = IShellLinkA_SetPath(sl, str);
163     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
164
165     strcpy(buffer,"garbage");
166     r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
167     ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r);
168     ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
169
170     /* Get some a real path to play with */
171     r=GetModuleFileName(NULL, mypath, sizeof(mypath));
172     ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%ld)\n", r);
173
174     /* Test the interaction of SetPath and SetIDList */
175     tmp_pidl=NULL;
176     r = IShellLinkA_GetIDList(sl, &tmp_pidl);
177     ok(SUCCEEDED(r), "GetIDList failed (0x%08lx)\n", r);
178     if (SUCCEEDED(r))
179     {
180         strcpy(buffer,"garbage");
181         r=SHGetPathFromIDListA(tmp_pidl, buffer);
182         todo_wine {
183         ok(r, "SHGetPathFromIDListA failed\n");
184         }
185         if (r)
186             ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
187     }
188
189     pidl=path_to_pidl(mypath);
190     todo_wine {
191     ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
192     }
193
194     if (pidl)
195     {
196         r = IShellLinkA_SetIDList(sl, pidl);
197         ok(SUCCEEDED(r), "SetIDList failed (0x%08lx)\n", r);
198
199         tmp_pidl=NULL;
200         r = IShellLinkA_GetIDList(sl, &tmp_pidl);
201         ok(SUCCEEDED(r), "GetIDList failed (0x%08lx)\n", r);
202         ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
203            "GetIDList returned an incorrect pidl\n");
204
205         /* tmp_pidl is owned by IShellLink so we don't free it */
206         pILFree(pidl);
207
208         strcpy(buffer,"garbage");
209         r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
210         ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r);
211         ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
212     }
213
214     /* test path with quotes */
215     r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
216     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
217
218     r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
219     ok(r==S_OK, "GetPath failed (0x%08lx)\n", r);
220     ok(!lstrcmp(buffer, "C:\\nonexistent\\file"), "case doesn't match\n");
221
222     r = IShellLinkA_SetPath(sl, "\"c:\\foo");
223     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
224
225     r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
226     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
227
228     r = IShellLinkA_SetPath(sl, "c:\\foo\"");
229     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
230
231     r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
232     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
233
234     r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
235     ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r);
236
237     /* Test Getting / Setting the arguments */
238     strcpy(buffer,"garbage");
239     r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
240     ok(SUCCEEDED(r), "GetArguments failed (0x%08lx)\n", r);
241     ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
242
243     str="param1 \"spaced param2\"";
244     r = IShellLinkA_SetArguments(sl, str);
245     ok(SUCCEEDED(r), "SetArguments failed (0x%08lx)\n", r);
246
247     strcpy(buffer,"garbage");
248     r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
249     ok(SUCCEEDED(r), "GetArguments failed (0x%08lx)\n", r);
250     ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
251
252     /* Test Getting / Setting showcmd */
253     i=0xdeadbeef;
254     r = IShellLinkA_GetShowCmd(sl, &i);
255     ok(SUCCEEDED(r), "GetShowCmd failed (0x%08lx)\n", r);
256     ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
257
258     r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
259     ok(SUCCEEDED(r), "SetShowCmd failed (0x%08lx)\n", r);
260
261     i=0xdeadbeef;
262     r = IShellLinkA_GetShowCmd(sl, &i);
263     ok(SUCCEEDED(r), "GetShowCmd failed (0x%08lx)\n", r);
264     ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
265
266     /* Test Getting / Setting the icon */
267     i=0xdeadbeef;
268     strcpy(buffer,"garbage");
269     r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
270     todo_wine {
271     ok(SUCCEEDED(r), "GetIconLocation failed (0x%08lx)\n", r);
272     }
273     ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
274     ok(i==0, "GetIconLocation returned %d\n", i);
275
276     str="c:\\nonexistent\\file";
277     r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
278     ok(SUCCEEDED(r), "SetIconLocation failed (0x%08lx)\n", r);
279
280     i=0xdeadbeef;
281     r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
282     ok(SUCCEEDED(r), "GetIconLocation failed (0x%08lx)\n", r);
283     ok(lstrcmpi(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
284     ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
285
286     /* Test Getting / Setting the hot key */
287     w=0xbeef;
288     r = IShellLinkA_GetHotkey(sl, &w);
289     ok(SUCCEEDED(r), "GetHotkey failed (0x%08lx)\n", r);
290     ok(w==0, "GetHotkey returned %d\n", w);
291
292     r = IShellLinkA_SetHotkey(sl, 0x5678);
293     ok(SUCCEEDED(r), "SetHotkey failed (0x%08lx)\n", r);
294
295     w=0xbeef;
296     r = IShellLinkA_GetHotkey(sl, &w);
297     ok(SUCCEEDED(r), "GetHotkey failed (0x%08lx)\n", r);
298     ok(w==0x5678, "GetHotkey returned %d'\n", w);
299
300     IShellLinkA_Release(sl);
301 }
302
303
304 /*
305  * Test saving and loading .lnk files
306  */
307
308 #define lok                   ok_(__FILE__, line)
309 #define check_lnk(a,b)        check_lnk_(__LINE__, (a), (b))
310
311 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
312 {
313     HRESULT r;
314     IShellLinkA *sl;
315     IPersistFile *pf;
316
317     r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
318                          &IID_IShellLinkA, (LPVOID*)&sl);
319     lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08lx)\n", r);
320     if (!SUCCEEDED(r))
321         return;
322
323     if (desc->description)
324     {
325         r = IShellLinkA_SetDescription(sl, desc->description);
326         lok(SUCCEEDED(r), "SetDescription failed (0x%08lx)\n", r);
327     }
328     if (desc->workdir)
329     {
330         r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
331         lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08lx)\n", r);
332     }
333     if (desc->path)
334     {
335         r = IShellLinkA_SetPath(sl, desc->path);
336         lok(SUCCEEDED(r), "SetPath failed (0x%08lx)\n", r);
337     }
338     if (desc->pidl)
339     {
340         r = IShellLinkA_SetIDList(sl, desc->pidl);
341         lok(SUCCEEDED(r), "SetIDList failed (0x%08lx)\n", r);
342     }
343     if (desc->arguments)
344     {
345         r = IShellLinkA_SetArguments(sl, desc->arguments);
346         lok(SUCCEEDED(r), "SetArguments failed (0x%08lx)\n", r);
347     }
348     if (desc->showcmd)
349     {
350         r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
351         lok(SUCCEEDED(r), "SetShowCmd failed (0x%08lx)\n", r);
352     }
353     if (desc->icon)
354     {
355         r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
356         lok(SUCCEEDED(r), "SetIconLocation failed (0x%08lx)\n", r);
357     }
358     if (desc->hotkey)
359     {
360         r = IShellLinkA_SetHotkey(sl, desc->hotkey);
361         lok(SUCCEEDED(r), "SetHotkey failed (0x%08lx)\n", r);
362     }
363
364     r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
365     lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08lx)\n", r);
366     if (SUCCEEDED(r))
367     {
368         r = IPersistFile_Save(pf, path, TRUE);
369         if (save_fails)
370         {
371             todo_wine {
372             lok(SUCCEEDED(r), "save failed (0x%08lx)\n", r);
373             }
374         }
375         else
376         {
377             lok(SUCCEEDED(r), "save failed (0x%08lx)\n", r);
378         }
379         IPersistFile_Release(pf);
380     }
381
382     IShellLinkA_Release(sl);
383 }
384
385 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc)
386 {
387     HRESULT r;
388     IShellLinkA *sl;
389     IPersistFile *pf;
390     char buffer[INFOTIPSIZE];
391
392     r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
393                          &IID_IShellLinkA, (LPVOID*)&sl);
394     lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08lx)\n", r);
395     if (!SUCCEEDED(r))
396         return;
397
398     r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
399     lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08lx)\n", r);
400     if (!SUCCEEDED(r))
401     {
402         IShellLinkA_Release(sl);
403         return;
404     }
405
406     r = IPersistFile_Load(pf, path, STGM_READ);
407     lok(SUCCEEDED(r), "load failed (0x%08lx)\n", r);
408     IPersistFile_Release(pf);
409     if (!SUCCEEDED(r))
410     {
411         IShellLinkA_Release(sl);
412         return;
413     }
414
415     if (desc->description)
416     {
417         strcpy(buffer,"garbage");
418         r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
419         lok(SUCCEEDED(r), "GetDescription failed (0x%08lx)\n", r);
420         lok(lstrcmp(buffer, desc->description)==0,
421            "GetDescription returned '%s' instead of '%s'\n",
422            buffer, desc->description);
423     }
424     if (desc->workdir)
425     {
426         strcpy(buffer,"garbage");
427         r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
428         lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08lx)\n", r);
429         lok(lstrcmpi(buffer, desc->workdir)==0,
430            "GetWorkingDirectory returned '%s' instead of '%s'\n",
431            buffer, desc->workdir);
432     }
433     if (desc->path)
434     {
435         strcpy(buffer,"garbage");
436         r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
437         lok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r);
438         lok(lstrcmpi(buffer, desc->path)==0,
439            "GetPath returned '%s' instead of '%s'\n",
440            buffer, desc->path);
441     }
442     if (desc->pidl)
443     {
444         LPITEMIDLIST pidl=NULL;
445         r = IShellLinkA_GetIDList(sl, &pidl);
446         lok(SUCCEEDED(r), "GetIDList failed (0x%08lx)\n", r);
447         lok(pILIsEqual(pidl, desc->pidl),
448            "GetIDList returned an incorrect pidl\n");
449     }
450     if (desc->showcmd)
451     {
452         int i=0xdeadbeef;
453         r = IShellLinkA_GetShowCmd(sl, &i);
454         lok(SUCCEEDED(r), "GetShowCmd failed (0x%08lx)\n", r);
455         lok(i==desc->showcmd,
456            "GetShowCmd returned 0x%0x instead of 0x%0x\n",
457            i, desc->showcmd);
458     }
459     if (desc->icon)
460     {
461         int i=0xdeadbeef;
462         strcpy(buffer,"garbage");
463         r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
464         lok(SUCCEEDED(r), "GetIconLocation failed (0x%08lx)\n", r);
465         lok(lstrcmpi(buffer, desc->icon)==0,
466            "GetIconLocation returned '%s' instead of '%s'\n",
467            buffer, desc->icon);
468         lok(i==desc->icon_id,
469            "GetIconLocation returned 0x%0x instead of 0x%0x\n",
470            i, desc->icon_id);
471     }
472     if (desc->hotkey)
473     {
474         WORD i=0xbeef;
475         r = IShellLinkA_GetHotkey(sl, &i);
476         lok(SUCCEEDED(r), "GetHotkey failed (0x%08lx)\n", r);
477         lok(i==desc->hotkey,
478            "GetHotkey returned 0x%04x instead of 0x%04x\n",
479            i, desc->hotkey);
480     }
481
482     IShellLinkA_Release(sl);
483 }
484
485 static void test_load_save(void)
486 {
487     lnk_desc_t desc;
488     char mypath[MAX_PATH];
489     char mydir[MAX_PATH];
490     char* p;
491     DWORD r;
492
493     /* Save an empty .lnk file */
494     memset(&desc, 0, sizeof(desc));
495     create_lnk(lnkfile, &desc, 0);
496
497     /* It should come back as a bunch of empty strings */
498     desc.description="";
499     desc.workdir="";
500     desc.path="";
501     desc.arguments="";
502     desc.icon="";
503     check_lnk(lnkfile, &desc);
504
505     /* Point a .lnk file to nonexistent files */
506     desc.description="";
507     desc.workdir="c:\\Nonexitent\\work\\directory";
508     desc.path="c:\\nonexistent\\path";
509     desc.pidl=NULL;
510     desc.arguments="";
511     desc.showcmd=0;
512     desc.icon="c:\\nonexistent\\icon\\file";
513     desc.icon_id=1234;
514     desc.hotkey=0;
515     create_lnk(lnkfile, &desc, 0);
516     check_lnk(lnkfile, &desc);
517
518     r=GetModuleFileName(NULL, mypath, sizeof(mypath));
519     ok(r>=0 && r<sizeof(mypath), "GetModuleFileName failed (%ld)\n", r);
520     strcpy(mydir, mypath);
521     p=strrchr(mydir, '\\');
522     if (p)
523         *p='\0';
524
525     /* Overwrite the existing lnk file and point it to existing files */
526     desc.description="test 2";
527     desc.workdir=mydir;
528     desc.path=mypath;
529     desc.pidl=NULL;
530     desc.arguments="/option1 /option2 \"Some string\"";
531     desc.showcmd=SW_SHOWNORMAL;
532     desc.icon=mypath;
533     desc.icon_id=0;
534     desc.hotkey=0x1234;
535     create_lnk(lnkfile, &desc, 0);
536     check_lnk(lnkfile, &desc);
537
538     /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
539      * represented as a path.
540      */
541
542     /* DeleteFileW is not implemented on Win9x */
543     r=DeleteFileA("c:\\test.lnk");
544     ok(r, "failed to delete link (%ld)\n", GetLastError());
545 }
546
547 static void test_datalink(void)
548 {
549     static const WCHAR lnk[] = {
550       ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
551       '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
552       '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
553       '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
554       'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
555       '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
556       'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
557       'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
558       'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
559       '=','1','&','L','[','-','8','1','-',']',':',':',0 };
560     static const WCHAR comp[] = {
561       '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
562       'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
563       'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
564     IShellLinkDataList *dl = NULL;
565     IShellLinkW *sl = NULL;
566     HRESULT r;
567     DWORD flags = 0;
568     EXP_DARWIN_LINK *dar;
569
570     r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
571                             &IID_IShellLinkW, (LPVOID*)&sl );
572     ok( r == S_OK, "no shelllink\n");
573     if (!sl)
574         return;
575
576     r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
577     ok(r == S_OK, "no datalink interface\n");
578
579     if (!dl)
580         return;
581
582     flags = 0;
583     r = dl->lpVtbl->GetFlags( dl, &flags );
584     ok( r == S_OK, "GetFlags failed\n");
585     ok( flags == 0, "GetFlags returned wrong flags\n");
586
587     dar = (void*)-1;
588     r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
589     ok( r == E_FAIL, "CopyDataBlock failed\n");
590     ok( dar == NULL, "should be null\n");
591
592     r = IShellLinkW_SetPath(sl, lnk);
593     ok(r == S_OK, "set path failed\n");
594
595     /*
596      * The following crashes:
597      * r = dl->lpVtbl->GetFlags( dl, NULL );
598      */
599
600     flags = 0;
601     r = dl->lpVtbl->GetFlags( dl, &flags );
602     ok( r == S_OK, "GetFlags failed\n");
603     ok( flags == (SLDF_HAS_DARWINID|SLDF_HAS_LOGO3ID),
604         "GetFlags returned wrong flags\n");
605
606     dar = NULL;
607     r = dl->lpVtbl->CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
608     ok( r == S_OK, "CopyDataBlock failed\n");
609
610     ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
611     ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
612
613     LocalFree( dar );
614
615     IUnknown_Release( dl );
616     IShellLinkW_Release( sl );
617 }
618
619 START_TEST(shelllink)
620 {
621     HRESULT r;
622     HMODULE hmod;
623
624     hmod = GetModuleHandle("shell32");
625     pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
626     pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
627     pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
628
629     r = CoInitialize(NULL);
630     ok(SUCCEEDED(r), "CoInitialize failed (0x%08lx)\n", r);
631     if (!SUCCEEDED(r))
632         return;
633
634     test_get_set();
635     test_load_save();
636     test_datalink();
637
638     CoUninitialize();
639 }