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