push decde5eed3d79f9d889b4d757f73e86ce6ff9241
[wine/hacks.git] / dlls / shell32 / tests / shlexec.c
blob644d611c11a42dc8c1ef3d532e7297d474f815c5
1 /*
2 * Unit test of the ShellExecute function.
4 * Copyright 2005 Francois Gouget for CodeWeavers
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
21 /* TODO:
22 * - test the default verb selection
23 * - test selection of an alternate class
24 * - try running executables in more ways
25 * - try passing arguments to executables
26 * - ShellExecute("foo.shlexec") with no path should work if foo.shlexec is
27 * in the PATH
28 * - test associations that use %l, %L or "%1" instead of %1
29 * - we may want to test ShellExecuteEx() instead of ShellExecute()
30 * and then we could also check its return value
31 * - ShellExecuteEx() also calls SetLastError() with meaningful values which
32 * we could check
35 #include <stdio.h>
36 #include <assert.h>
38 /* Needed to get SEE_MASK_NOZONECHECKS with the PSDK */
39 #define NTDDI_WINXPSP1 0x05010100
40 #define NTDDI_VERSION NTDDI_WINXPSP1
41 #define _WIN32_WINNT 0x0501
43 #include "wtypes.h"
44 #include "winbase.h"
45 #include "windef.h"
46 #include "shellapi.h"
47 #include "shlwapi.h"
48 #include "wine/test.h"
50 #include "shell32_test.h"
53 static char argv0[MAX_PATH];
54 static int myARGC;
55 static char** myARGV;
56 static char tmpdir[MAX_PATH];
57 static char child_file[MAX_PATH];
58 static DLLVERSIONINFO dllver;
61 /***
63 * ShellExecute wrappers
65 ***/
66 static void dump_child(void);
68 static HANDLE hEvent;
69 static void init_event(const char* child_file)
71 char* event_name;
72 event_name=strrchr(child_file, '\\')+1;
73 hEvent=CreateEvent(NULL, FALSE, FALSE, event_name);
76 static void strcat_param(char* str, const char* param)
78 if (param!=NULL)
80 strcat(str, "\"");
81 strcat(str, param);
82 strcat(str, "\"");
84 else
86 strcat(str, "null");
90 static char shell_call[2048]="";
91 static int shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
93 int rc;
95 strcpy(shell_call, "ShellExecute(");
96 strcat_param(shell_call, operation);
97 strcat(shell_call, ", ");
98 strcat_param(shell_call, file);
99 strcat(shell_call, ", ");
100 strcat_param(shell_call, parameters);
101 strcat(shell_call, ", ");
102 strcat_param(shell_call, directory);
103 strcat(shell_call, ")");
104 if (winetest_debug > 1)
105 trace("%s\n", shell_call);
107 DeleteFile(child_file);
108 SetLastError(0xcafebabe);
110 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
111 * association it displays the 'Open With' dialog and I could not find
112 * a flag to prevent this.
114 rc=(int)ShellExecute(NULL, operation, file, parameters, directory,
115 SW_SHOWNORMAL);
117 if (rc > 32)
119 int wait_rc;
120 wait_rc=WaitForSingleObject(hEvent, 5000);
121 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
123 /* The child process may have changed the result file, so let profile
124 * functions know about it
126 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
127 if (rc > 32)
128 dump_child();
130 return rc;
133 static int shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
134 LPCSTR parameters, LPCSTR directory)
136 SHELLEXECUTEINFO sei;
137 BOOL success;
138 int rc;
140 strcpy(shell_call, "ShellExecuteEx(");
141 strcat_param(shell_call, operation);
142 strcat(shell_call, ", ");
143 strcat_param(shell_call, file);
144 strcat(shell_call, ", ");
145 strcat_param(shell_call, parameters);
146 strcat(shell_call, ", ");
147 strcat_param(shell_call, directory);
148 strcat(shell_call, ")");
149 if (winetest_debug > 1)
150 trace("%s\n", shell_call);
152 sei.cbSize=sizeof(sei);
153 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
154 sei.hwnd=NULL;
155 sei.lpVerb=operation;
156 sei.lpFile=file;
157 sei.lpParameters=parameters;
158 sei.lpDirectory=directory;
159 sei.nShow=SW_SHOWNORMAL;
160 sei.hInstApp=NULL; /* Out */
161 sei.lpIDList=NULL;
162 sei.lpClass=NULL;
163 sei.hkeyClass=NULL;
164 sei.dwHotKey=0;
165 U(sei).hIcon=NULL;
166 sei.hProcess=NULL; /* Out */
168 DeleteFile(child_file);
169 SetLastError(0xcafebabe);
170 success=ShellExecuteEx(&sei);
171 rc=(int)sei.hInstApp;
172 ok((success && rc > 32) || (!success && rc <= 32),
173 "%s rc=%d and hInstApp=%d is not allowed\n", shell_call, success, rc);
175 if (rc > 32)
177 int wait_rc;
178 if (sei.hProcess!=NULL)
180 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
181 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
183 wait_rc=WaitForSingleObject(hEvent, 5000);
184 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
186 /* The child process may have changed the result file, so let profile
187 * functions know about it
189 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
190 if (rc > 32)
191 dump_child();
193 return rc;
198 /***
200 * Functions to create / delete associations wrappers
202 ***/
204 static BOOL create_test_association(const char* extension)
206 HKEY hkey, hkey_shell;
207 char class[MAX_PATH];
208 LONG rc;
210 sprintf(class, "shlexec%s", extension);
211 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
212 NULL, &hkey, NULL);
213 if (rc != ERROR_SUCCESS)
214 return FALSE;
216 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
217 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
218 CloseHandle(hkey);
220 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
221 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
222 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
224 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
225 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
226 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
228 CloseHandle(hkey);
229 CloseHandle(hkey_shell);
231 return TRUE;
234 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
235 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
237 LONG ret;
238 DWORD dwMaxSubkeyLen, dwMaxValueLen;
239 DWORD dwMaxLen, dwSize;
240 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
241 HKEY hSubKey = hKey;
243 if(lpszSubKey)
245 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
246 if (ret) return ret;
249 /* Get highest length for keys, values */
250 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
251 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
252 if (ret) goto cleanup;
254 dwMaxSubkeyLen++;
255 dwMaxValueLen++;
256 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
257 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
259 /* Name too big: alloc a buffer for it */
260 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
262 ret = ERROR_NOT_ENOUGH_MEMORY;
263 goto cleanup;
268 /* Recursively delete all the subkeys */
269 while (TRUE)
271 dwSize = dwMaxLen;
272 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
273 NULL, NULL, NULL)) break;
275 ret = myRegDeleteTreeA(hSubKey, lpszName);
276 if (ret) goto cleanup;
279 if (lpszSubKey)
280 ret = RegDeleteKeyA(hKey, lpszSubKey);
281 else
282 while (TRUE)
284 dwSize = dwMaxLen;
285 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
286 NULL, NULL, NULL, NULL)) break;
288 ret = RegDeleteValueA(hKey, lpszName);
289 if (ret) goto cleanup;
292 cleanup:
293 /* Free buffer if allocated */
294 if (lpszName != szNameBuf)
295 HeapFree( GetProcessHeap(), 0, lpszName);
296 if(lpszSubKey)
297 RegCloseKey(hSubKey);
298 return ret;
301 static void delete_test_association(const char* extension)
303 char class[MAX_PATH];
305 sprintf(class, "shlexec%s", extension);
306 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
307 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
310 static void create_test_verb_dde(const char* extension, const char* verb,
311 int rawcmd, const char* cmdtail, const char *ddeexec,
312 const char *application, const char *topic,
313 const char *ifexec)
315 HKEY hkey_shell, hkey_verb, hkey_cmd;
316 char shell[MAX_PATH];
317 char* cmd;
318 LONG rc;
320 sprintf(shell, "shlexec%s\\shell", extension);
321 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
322 KEY_CREATE_SUB_KEY, &hkey_shell);
323 assert(rc==ERROR_SUCCESS);
324 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
325 NULL, &hkey_verb, NULL);
326 assert(rc==ERROR_SUCCESS);
327 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
328 NULL, &hkey_cmd, NULL);
329 assert(rc==ERROR_SUCCESS);
331 if (rawcmd)
333 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
335 else
337 cmd=malloc(strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
338 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
339 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
340 assert(rc==ERROR_SUCCESS);
341 free(cmd);
344 if (ddeexec)
346 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
348 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
349 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
350 assert(rc==ERROR_SUCCESS);
351 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
352 strlen(ddeexec)+1);
353 assert(rc==ERROR_SUCCESS);
354 if (application)
356 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
357 NULL, &hkey_application, NULL);
358 assert(rc==ERROR_SUCCESS);
359 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
360 strlen(application)+1);
361 assert(rc==ERROR_SUCCESS);
362 CloseHandle(hkey_application);
364 if (topic)
366 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
367 NULL, &hkey_topic, NULL);
368 assert(rc==ERROR_SUCCESS);
369 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
370 strlen(topic)+1);
371 assert(rc==ERROR_SUCCESS);
372 CloseHandle(hkey_topic);
374 if (ifexec)
376 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
377 NULL, &hkey_ifexec, NULL);
378 assert(rc==ERROR_SUCCESS);
379 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
380 strlen(ifexec)+1);
381 assert(rc==ERROR_SUCCESS);
382 CloseHandle(hkey_ifexec);
384 CloseHandle(hkey_ddeexec);
387 CloseHandle(hkey_shell);
388 CloseHandle(hkey_verb);
389 CloseHandle(hkey_cmd);
392 static void create_test_verb(const char* extension, const char* verb,
393 int rawcmd, const char* cmdtail)
395 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
396 NULL, NULL);
399 /***
401 * Functions to check that the child process was started just right
402 * (borrowed from dlls/kernel32/tests/process.c)
404 ***/
406 static const char* encodeA(const char* str)
408 static char encoded[2*1024+1];
409 char* ptr;
410 size_t len,i;
412 if (!str) return "";
413 len = strlen(str) + 1;
414 if (len >= sizeof(encoded)/2)
416 fprintf(stderr, "string is too long!\n");
417 assert(0);
419 ptr = encoded;
420 for (i = 0; i < len; i++)
421 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
422 ptr[2 * len] = '\0';
423 return ptr;
426 static unsigned decode_char(char c)
428 if (c >= '0' && c <= '9') return c - '0';
429 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
430 assert(c >= 'A' && c <= 'F');
431 return c - 'A' + 10;
434 static char* decodeA(const char* str)
436 static char decoded[1024];
437 char* ptr;
438 size_t len,i;
440 len = strlen(str) / 2;
441 if (!len--) return NULL;
442 if (len >= sizeof(decoded))
444 fprintf(stderr, "string is too long!\n");
445 assert(0);
447 ptr = decoded;
448 for (i = 0; i < len; i++)
449 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
450 ptr[len] = '\0';
451 return ptr;
454 static void childPrintf(HANDLE h, const char* fmt, ...)
456 va_list valist;
457 char buffer[1024];
458 DWORD w;
460 va_start(valist, fmt);
461 vsprintf(buffer, fmt, valist);
462 va_end(valist);
463 WriteFile(h, buffer, strlen(buffer), &w, NULL);
466 static void doChild(int argc, char** argv)
468 char* filename;
469 HANDLE hFile;
470 int i;
472 filename=argv[2];
473 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
474 if (hFile == INVALID_HANDLE_VALUE)
475 return;
477 /* Arguments */
478 childPrintf(hFile, "[Arguments]\r\n");
479 if (winetest_debug > 2)
480 trace("argcA=%d\n", argc);
481 childPrintf(hFile, "argcA=%d\r\n", argc);
482 for (i = 0; i < argc; i++)
484 if (winetest_debug > 2)
485 trace("argvA%d=%s\n", i, argv[i]);
486 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
488 CloseHandle(hFile);
490 init_event(filename);
491 SetEvent(hEvent);
492 CloseHandle(hEvent);
495 static char* getChildString(const char* sect, const char* key)
497 char buf[1024];
498 char* ret;
500 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
501 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
502 assert(!(strlen(buf) & 1));
503 ret = decodeA(buf);
504 return ret;
507 static void dump_child(void)
509 if (winetest_debug > 1)
511 char key[18];
512 char* str;
513 int i, c;
515 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
516 trace("argcA=%d\n",c);
517 for (i=0;i<c;i++)
519 sprintf(key, "argvA%d", i);
520 str=getChildString("Arguments", key);
521 trace("%s=%s\n", key, str);
526 static int StrCmpPath(const char* s1, const char* s2)
528 if (!s1 && !s2) return 0;
529 if (!s2) return 1;
530 if (!s1) return -1;
531 while (*s1)
533 if (!*s2)
535 if (*s1=='.')
536 s1++;
537 return (*s1-*s2);
539 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
541 while (*s1=='/' || *s1=='\\')
542 s1++;
543 while (*s2=='/' || *s2=='\\')
544 s2++;
546 else if (toupper(*s1)==toupper(*s2))
548 s1++;
549 s2++;
551 else
553 return (*s1-*s2);
556 if (*s2=='.')
557 s2++;
558 if (*s2)
559 return -1;
560 return 0;
563 static int _okChildString(const char* file, int line, const char* key, const char* expected)
565 char* result;
566 result=getChildString("Arguments", key);
567 return ok_(file, line)(lstrcmpiA(result, expected) == 0,
568 "%s expected '%s', got '%s'\n", key, expected, result);
571 static int _okChildPath(const char* file, int line, const char* key, const char* expected)
573 char* result;
574 result=getChildString("Arguments", key);
575 return ok_(file, line)(StrCmpPath(result, expected) == 0,
576 "%s expected '%s', got '%s'\n", key, expected, result);
579 static int _okChildInt(const char* file, int line, const char* key, int expected)
581 INT result;
582 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
583 return ok_(file, line)(result == expected,
584 "%s expected %d, but got %d\n", key, expected, result);
587 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
588 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
589 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
593 /***
595 * Tests
597 ***/
599 static const char* testfiles[]=
601 "%s\\test file.shlexec",
602 "%s\\%%nasty%% $file.shlexec",
603 "%s\\test file.noassoc",
604 "%s\\test file.noassoc.shlexec",
605 "%s\\test file.shlexec.noassoc",
606 "%s\\test_shortcut_shlexec.lnk",
607 "%s\\test_shortcut_exe.lnk",
608 "%s\\test file.shl",
609 "%s\\test file.shlfoo",
610 "%s\\test file.sfe",
611 "%s\\masked file.shlexec",
612 "%s\\masked",
613 "%s\\test file.sde",
614 "%s\\test file.exe",
615 "%s\\test2.exe",
616 NULL
619 typedef struct
621 const char* verb;
622 const char* basename;
623 int todo;
624 int rc;
625 } filename_tests_t;
627 static filename_tests_t filename_tests[]=
629 /* Test bad / nonexistent filenames */
630 {NULL, "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
631 {NULL, "%s\\nonexistent.noassoc", 0x11, SE_ERR_FNF},
633 /* Standard tests */
634 {NULL, "%s\\test file.shlexec", 0x0, 33},
635 {NULL, "%s\\test file.shlexec.", 0x0, 33},
636 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
637 {NULL, "%s/test file.shlexec", 0x0, 33},
639 /* Test filenames with no association */
640 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
642 /* Test double extensions */
643 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
644 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
646 /* Test alternate verbs */
647 {"LowerL", "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
648 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
650 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
651 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
653 /* Test file masked due to space */
654 {NULL, "%s\\masked file.shlexec", 0x1, 33},
655 /* Test if quoting prevents the masking */
656 {NULL, "%s\\masked file.shlexec", 0x40, 33},
658 {NULL, NULL, 0}
661 static filename_tests_t noquotes_tests[]=
663 /* Test unquoted '%1' thingies */
664 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
665 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
666 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
668 {NULL, NULL, 0}
671 static void test_filename(void)
673 char filename[MAX_PATH];
674 const filename_tests_t* test;
675 char* c;
676 int rc;
678 test=filename_tests;
679 while (test->basename)
681 sprintf(filename, test->basename, tmpdir);
682 if (strchr(filename, '/'))
684 c=filename;
685 while (*c)
687 if (*c=='\\')
688 *c='/';
689 c++;
692 if ((test->todo & 0x40)==0)
694 rc=shell_execute(test->verb, filename, NULL, NULL);
696 else
698 char quoted[MAX_PATH + 2];
699 sprintf(quoted, "\"%s\"", filename);
700 rc=shell_execute(test->verb, quoted, NULL, NULL);
702 if (rc > 32)
703 rc=33;
704 if ((test->todo & 0x1)==0)
706 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
707 rc, GetLastError());
709 else todo_wine
711 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
712 rc, GetLastError());
714 if (rc == 33)
716 const char* verb;
717 if ((test->todo & 0x2)==0)
719 okChildInt("argcA", 5);
721 else todo_wine
723 okChildInt("argcA", 5);
725 verb=(test->verb ? test->verb : "Open");
726 if ((test->todo & 0x4)==0)
728 okChildString("argvA3", verb);
730 else todo_wine
732 okChildString("argvA3", verb);
734 if ((test->todo & 0x8)==0)
736 okChildPath("argvA4", filename);
738 else todo_wine
740 okChildPath("argvA4", filename);
743 test++;
746 test=noquotes_tests;
747 while (test->basename)
749 sprintf(filename, test->basename, tmpdir);
750 rc=shell_execute(test->verb, filename, NULL, NULL);
751 if (rc > 32)
752 rc=33;
753 if ((test->todo & 0x1)==0)
755 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
756 rc, GetLastError());
758 else todo_wine
760 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
761 rc, GetLastError());
763 if (rc==0)
765 int count;
766 const char* verb;
767 char* str;
769 verb=(test->verb ? test->verb : "Open");
770 if ((test->todo & 0x4)==0)
772 okChildString("argvA3", verb);
774 else todo_wine
776 okChildString("argvA3", verb);
779 count=4;
780 str=filename;
781 while (1)
783 char attrib[18];
784 char* space;
785 space=strchr(str, ' ');
786 if (space)
787 *space='\0';
788 sprintf(attrib, "argvA%d", count);
789 if ((test->todo & 0x8)==0)
791 okChildPath(attrib, str);
793 else todo_wine
795 okChildPath(attrib, str);
797 count++;
798 if (!space)
799 break;
800 str=space+1;
802 if ((test->todo & 0x2)==0)
804 okChildInt("argcA", count);
806 else todo_wine
808 okChildInt("argcA", count);
811 test++;
814 if (dllver.dwMajorVersion != 0)
816 /* The more recent versions of shell32.dll accept quoted filenames
817 * while older ones (e.g. 4.00) don't. Still we want to test this
818 * because IE 6 depends on the new behavior.
819 * One day we may need to check the exact version of the dll but for
820 * now making sure DllGetVersion() is present is sufficient.
822 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
823 rc=shell_execute(NULL, filename, NULL, NULL);
824 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
825 GetLastError());
826 okChildInt("argcA", 5);
827 okChildString("argvA3", "Open");
828 sprintf(filename, "%s\\test file.shlexec", tmpdir);
829 okChildPath("argvA4", filename);
833 static void test_find_executable(void)
835 char filename[MAX_PATH];
836 char command[MAX_PATH];
837 const filename_tests_t* test;
838 int rc;
840 if (!create_test_association(".sfe"))
842 skip("Unable to create association for '.sfe'\n");
843 return;
845 create_test_verb(".sfe", "Open", 1, "%1");
847 /* Don't test FindExecutable(..., NULL), it always crashes */
849 strcpy(command, "your word");
850 rc=(int)FindExecutableA(NULL, NULL, command);
851 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %d\n", rc);
852 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
854 strcpy(command, "your word");
855 rc=(int)FindExecutableA(tmpdir, NULL, command);
856 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %d\n", rc);
857 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
859 sprintf(filename, "%s\\test file.sfe", tmpdir);
860 rc=(int)FindExecutableA(filename, NULL, command);
861 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
862 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
864 rc=(int)FindExecutableA("test file.sfe", tmpdir, command);
865 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
867 rc=(int)FindExecutableA("test file.sfe", NULL, command);
868 todo_wine ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %d\n", filename, rc);
870 delete_test_association(".sfe");
872 if (!create_test_association(".shl"))
874 skip("Unable to create association for '.shl'\n");
875 return;
877 create_test_verb(".shl", "Open", 0, "Open");
879 sprintf(filename, "%s\\test file.shl", tmpdir);
880 rc=(int)FindExecutableA(filename, NULL, command);
881 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
883 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
884 rc=(int)FindExecutableA(filename, NULL, command);
886 delete_test_association(".shl");
888 if (rc > 32)
890 /* On Windows XP and 2003 FindExecutable() is completely broken.
891 * Probably what it does is convert the filename to 8.3 format,
892 * which as a side effect converts the '.shlfoo' extension to '.shl',
893 * and then tries to find an association for '.shl'. This means it
894 * will normally fail on most extensions with more than 3 characters,
895 * like '.mpeg', etc.
896 * Also it means we cannot do any other test.
898 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
899 return;
902 test=filename_tests;
903 while (test->basename)
905 sprintf(filename, test->basename, tmpdir);
906 if (strchr(filename, '/'))
908 char* c;
909 c=filename;
910 while (*c)
912 if (*c=='\\')
913 *c='/';
914 c++;
917 /* Win98 does not '\0'-terminate command! */
918 memset(command, '\0', sizeof(command));
919 rc=(int)FindExecutableA(filename, NULL, command);
920 if (rc > 32)
921 rc=33;
922 if ((test->todo & 0x10)==0)
924 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
926 else todo_wine
928 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
930 if (rc > 32)
932 int equal;
933 equal=strcmp(command, argv0) == 0 ||
934 /* NT4 returns an extra 0x8 character! */
935 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
936 if ((test->todo & 0x20)==0)
938 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
939 filename, command, argv0);
941 else todo_wine
943 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
944 filename, command, argv0);
947 test++;
952 static filename_tests_t lnk_tests[]=
954 /* Pass bad / nonexistent filenames as a parameter */
955 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
956 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
958 /* Pass regular paths as a parameter */
959 {NULL, "%s\\test file.shlexec", 0xa, 33},
960 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
962 /* Pass filenames with no association as a parameter */
963 {NULL, "%s\\test file.noassoc", 0xa, 33},
965 {NULL, NULL, 0}
968 static void test_lnks(void)
970 char filename[MAX_PATH];
971 char params[MAX_PATH];
972 const filename_tests_t* test;
973 int rc;
975 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
976 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
977 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
978 GetLastError());
979 okChildInt("argcA", 5);
980 okChildString("argvA3", "Open");
981 sprintf(filename, "%s\\test file.shlexec", tmpdir);
982 okChildPath("argvA4", filename);
984 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
985 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
986 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
987 GetLastError());
988 okChildInt("argcA", 4);
989 okChildString("argvA3", "Lnk");
991 if (dllver.dwMajorVersion>=6)
993 char* c;
994 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
995 * Older versions don't or are quite buggy in this regard.
997 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
998 c=filename;
999 while (*c)
1001 if (*c=='\\')
1002 *c='/';
1003 c++;
1005 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1006 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1007 GetLastError());
1008 okChildInt("argcA", 4);
1009 okChildString("argvA3", "Lnk");
1012 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1013 test=lnk_tests;
1014 while (test->basename)
1016 params[0]='\"';
1017 sprintf(params+1, test->basename, tmpdir);
1018 strcat(params,"\"");
1019 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1020 NULL);
1021 if (rc > 32)
1022 rc=33;
1023 if ((test->todo & 0x1)==0)
1025 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1026 rc, GetLastError());
1028 else todo_wine
1030 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1031 rc, GetLastError());
1033 if (rc==0)
1035 if ((test->todo & 0x2)==0)
1037 okChildInt("argcA", 5);
1039 else
1041 okChildInt("argcA", 5);
1043 if ((test->todo & 0x4)==0)
1045 okChildString("argvA3", "Lnk");
1047 else todo_wine
1049 okChildString("argvA3", "Lnk");
1051 sprintf(params, test->basename, tmpdir);
1052 if ((test->todo & 0x8)==0)
1054 okChildPath("argvA4", params);
1056 else
1058 okChildPath("argvA4", params);
1061 test++;
1066 static void test_exes(void)
1068 char filename[MAX_PATH];
1069 char params[1024];
1070 int rc;
1072 sprintf(params, "shlexec \"%s\" Exec", child_file);
1074 /* We need NOZONECHECKS on Win2003 to block a dialog */
1075 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1076 NULL);
1077 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1078 okChildInt("argcA", 4);
1079 okChildString("argvA3", "Exec");
1081 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1082 if (CopyFile(argv0, filename, FALSE))
1084 rc=shell_execute(NULL, filename, params, NULL);
1085 todo_wine {
1086 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1091 static void test_exes_long(void)
1093 char filename[MAX_PATH];
1094 char params[2024];
1095 char longparam[MAX_PATH];
1096 int rc;
1098 for (rc = 0; rc < MAX_PATH; rc++)
1099 longparam[rc]='a'+rc%26;
1100 longparam[MAX_PATH-1]=0;
1103 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1105 /* We need NOZONECHECKS on Win2003 to block a dialog */
1106 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1107 NULL);
1108 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1109 okChildInt("argcA", 4);
1110 okChildString("argvA3", longparam);
1112 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1113 if (CopyFile(argv0, filename, FALSE))
1115 rc=shell_execute(NULL, filename, params, NULL);
1116 todo_wine {
1117 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1122 typedef struct
1124 const char* command;
1125 const char* ddeexec;
1126 const char* application;
1127 const char* topic;
1128 const char* ifexec;
1129 int expectedArgs;
1130 const char* expectedDdeExec;
1131 int todo;
1132 int rc;
1133 } dde_tests_t;
1135 static dde_tests_t dde_tests[] =
1137 /* Test passing and not passing command-line
1138 * argument, no DDE */
1139 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0, 33},
1140 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0, 33},
1142 /* Test passing and not passing command-line
1143 * argument, with DDE */
1144 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1145 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0, 33},
1147 /* Test unquoted %1 in command and ddeexec
1148 * (test filename has space) */
1149 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0, 33},
1151 /* Test ifexec precedence over ddeexec */
1152 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0, 33},
1154 /* Test default DDE topic */
1155 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1157 /* Test default DDE application */
1158 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1160 {NULL, NULL, NULL, NULL, NULL, 0, 0x0, 0}
1163 static DWORD ddeInst;
1164 static HSZ hszTopic;
1165 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
1166 static BOOL denyNextConnection;
1168 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
1169 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
1170 ULONG_PTR dwData1, ULONG_PTR dwData2)
1172 DWORD size = 0;
1174 if (winetest_debug > 2)
1175 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
1176 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
1178 switch (uType)
1180 case XTYP_CONNECT:
1181 if (!DdeCmpStringHandles(hsz1, hszTopic))
1183 if (denyNextConnection)
1184 denyNextConnection = FALSE;
1185 else
1187 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
1188 assert(size < MAX_PATH);
1189 return (HDDEDATA)TRUE;
1192 return (HDDEDATA)FALSE;
1194 case XTYP_EXECUTE:
1195 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
1196 assert(size < MAX_PATH);
1197 DdeFreeDataHandle(hData);
1198 return (HDDEDATA)DDE_FACK;
1200 default:
1201 return NULL;
1205 typedef struct
1207 char *filename;
1208 DWORD threadIdParent;
1209 } dde_thread_info_t;
1211 static DWORD CALLBACK ddeThread(LPVOID arg)
1213 dde_thread_info_t *info = (dde_thread_info_t *)arg;
1214 assert(info && info->filename);
1215 PostThreadMessage(info->threadIdParent,
1216 WM_QUIT,
1217 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
1218 0L);
1219 ExitThread(0);
1222 /* ShellExecute won't successfully send DDE commands to console applications after starting them,
1223 * so we run a DDE server in this application, deny the first connection request to make
1224 * ShellExecute start the application, and then process the next DDE connection in this application
1225 * to see the execute command that is sent. */
1226 static void test_dde(void)
1228 char filename[MAX_PATH], defApplication[MAX_PATH];
1229 HSZ hszApplication;
1230 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1231 const dde_tests_t* test;
1232 char params[1024];
1233 DWORD threadId;
1234 MSG msg;
1235 int rc;
1237 ddeInst = 0;
1238 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1239 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1240 assert(rc == DMLERR_NO_ERROR);
1242 sprintf(filename, "%s\\test file.sde", tmpdir);
1244 /* Default service is application name minus path and extension */
1245 strcpy(defApplication, strrchr(argv0, '\\')+1);
1246 *strchr(defApplication, '.') = 0;
1248 test = dde_tests;
1249 while (test->command)
1251 if (!create_test_association(".sde"))
1253 skip("Unable to create association for '.sfe'\n");
1254 return;
1256 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1257 test->application, test->topic, test->ifexec);
1258 hszApplication = DdeCreateStringHandleA(ddeInst, test->application ?
1259 test->application : defApplication, CP_WINANSI);
1260 hszTopic = DdeCreateStringHandleA(ddeInst, test->topic ? test->topic : SZDDESYS_TOPIC,
1261 CP_WINANSI);
1262 assert(hszApplication && hszTopic);
1263 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER));
1264 denyNextConnection = TRUE;
1265 ddeExec[0] = 0;
1267 assert(CreateThread(NULL, 0, ddeThread, (LPVOID)&info, 0, &threadId));
1268 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1269 rc = msg.wParam > 32 ? 33 : msg.wParam;
1270 if ((test->todo & 0x1)==0)
1272 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1273 rc, GetLastError());
1275 else todo_wine
1277 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1278 rc, GetLastError());
1280 if (rc == 33)
1282 if ((test->todo & 0x2)==0)
1284 okChildInt("argcA", test->expectedArgs + 3);
1286 else todo_wine
1288 okChildInt("argcA", test->expectedArgs + 3);
1290 if (test->expectedArgs == 1)
1292 if ((test->todo & 0x4) == 0)
1294 okChildPath("argvA3", filename);
1296 else todo_wine
1298 okChildPath("argvA3", filename);
1301 if ((test->todo & 0x8) == 0)
1303 sprintf(params, test->expectedDdeExec, filename);
1304 ok(StrCmpPath(params, ddeExec) == 0,
1305 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1307 else todo_wine
1309 sprintf(params, test->expectedDdeExec, filename);
1310 ok(StrCmpPath(params, ddeExec) == 0,
1311 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1315 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1316 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1317 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1318 delete_test_association(".sde");
1319 test++;
1322 assert(DdeUninitialize(ddeInst));
1325 #define DDE_DEFAULT_APP_VARIANTS 2
1326 typedef struct
1328 const char* command;
1329 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1330 int todo;
1331 int rc[DDE_DEFAULT_APP_VARIANTS];
1332 } dde_default_app_tests_t;
1334 static dde_default_app_tests_t dde_default_app_tests[] =
1336 /* Windows XP and 98 handle default DDE app names in different ways.
1337 * The application name we see in the first test determines the pattern
1338 * of application names and return codes we will look for. */
1340 /* Test unquoted existing filename with a space */
1341 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1342 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1344 /* Test quoted existing filename with a space */
1345 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1346 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1348 /* Test unquoted filename with a space that doesn't exist, but
1349 * test2.exe does */
1350 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1351 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1353 /* Test quoted filename with a space that does not exist */
1354 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1355 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1357 /* Test filename supplied without the extension */
1358 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1359 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1361 /* Test an unquoted nonexistent filename */
1362 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1363 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1365 /* Test an application that will be found on the path */
1366 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1367 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1369 /* Test an application that will not be found on the path */
1370 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1371 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1373 {NULL, {NULL}, 0, {0}}
1376 static void test_dde_default_app(void)
1378 char filename[MAX_PATH];
1379 HSZ hszApplication;
1380 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1381 const dde_default_app_tests_t* test;
1382 char params[1024];
1383 DWORD threadId;
1384 MSG msg;
1385 int rc, which = 0;
1387 ddeInst = 0;
1388 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1389 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1390 assert(rc == DMLERR_NO_ERROR);
1392 sprintf(filename, "%s\\test file.sde", tmpdir);
1394 /* It is strictly not necessary to register an application name here, but wine's
1395 * DdeNameService implementation complains if 0L is passed instead of
1396 * hszApplication with DNS_FILTEROFF */
1397 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1398 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1399 assert(hszApplication && hszTopic);
1400 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
1402 test = dde_default_app_tests;
1403 while (test->command)
1405 if (!create_test_association(".sde"))
1407 skip("Unable to create association for '.sde'\n");
1408 return;
1410 sprintf(params, test->command, tmpdir);
1411 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
1412 "shlexec", NULL);
1413 denyNextConnection = FALSE;
1414 ddeApplication[0] = 0;
1416 /* No application will be run as we will respond to the first DDE event,
1417 * so don't wait for it */
1418 SetEvent(hEvent);
1420 assert(CreateThread(NULL, 0, ddeThread, (LPVOID)&info, 0, &threadId));
1421 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1422 rc = msg.wParam > 32 ? 33 : msg.wParam;
1424 /* First test, find which set of test data we expect to see */
1425 if (test == dde_default_app_tests)
1427 int i;
1428 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
1430 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
1432 which = i;
1433 break;
1436 if (i == DDE_DEFAULT_APP_VARIANTS)
1437 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1440 if ((test->todo & 0x1)==0)
1442 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1443 rc, GetLastError());
1445 else todo_wine
1447 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1448 rc, GetLastError());
1450 if (rc == 33)
1452 if ((test->todo & 0x2)==0)
1454 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1455 "Expected application '%s', got '%s'\n",
1456 test->expectedDdeApplication[which], ddeApplication);
1458 else todo_wine
1460 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1461 "Expected application '%s', got '%s'\n",
1462 test->expectedDdeApplication[which], ddeApplication);
1466 delete_test_association(".sde");
1467 test++;
1470 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1471 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1472 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1473 assert(DdeUninitialize(ddeInst));
1476 static void init_test(void)
1478 HMODULE hdll;
1479 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
1480 char filename[MAX_PATH];
1481 WCHAR lnkfile[MAX_PATH];
1482 char params[1024];
1483 const char* const * testfile;
1484 lnk_desc_t desc;
1485 DWORD rc;
1486 HRESULT r;
1488 hdll=GetModuleHandleA("shell32.dll");
1489 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
1490 if (pDllGetVersion)
1492 dllver.cbSize=sizeof(dllver);
1493 pDllGetVersion(&dllver);
1494 trace("major=%d minor=%d build=%d platform=%d\n",
1495 dllver.dwMajorVersion, dllver.dwMinorVersion,
1496 dllver.dwBuildNumber, dllver.dwPlatformID);
1498 else
1500 memset(&dllver, 0, sizeof(dllver));
1503 r = CoInitialize(NULL);
1504 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
1505 if (!SUCCEEDED(r))
1506 exit(1);
1508 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1509 assert(rc!=0 && rc<sizeof(argv0));
1510 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1512 strcat(argv0, ".so");
1513 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1514 "unable to find argv0!\n");
1517 GetTempPathA(sizeof(tmpdir)/sizeof(*tmpdir), tmpdir);
1518 assert(GetTempFileNameA(tmpdir, "wt", 0, child_file)!=0);
1519 init_event(child_file);
1521 /* Set up the test files */
1522 testfile=testfiles;
1523 while (*testfile)
1525 HANDLE hfile;
1527 sprintf(filename, *testfile, tmpdir);
1528 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1529 FILE_ATTRIBUTE_NORMAL, NULL);
1530 if (hfile==INVALID_HANDLE_VALUE)
1532 trace("unable to create '%s': err=%d\n", filename, GetLastError());
1533 assert(0);
1535 CloseHandle(hfile);
1536 testfile++;
1539 /* Setup the test shortcuts */
1540 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1541 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1542 desc.description=NULL;
1543 desc.workdir=NULL;
1544 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1545 desc.path=filename;
1546 desc.pidl=NULL;
1547 desc.arguments="ignored";
1548 desc.showcmd=0;
1549 desc.icon=NULL;
1550 desc.icon_id=0;
1551 desc.hotkey=0;
1552 create_lnk(lnkfile, &desc, 0);
1554 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1555 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1556 desc.description=NULL;
1557 desc.workdir=NULL;
1558 desc.path=argv0;
1559 desc.pidl=NULL;
1560 sprintf(params, "shlexec \"%s\" Lnk", child_file);
1561 desc.arguments=params;
1562 desc.showcmd=0;
1563 desc.icon=NULL;
1564 desc.icon_id=0;
1565 desc.hotkey=0;
1566 create_lnk(lnkfile, &desc, 0);
1568 /* Create a basic association suitable for most tests */
1569 if (!create_test_association(".shlexec"))
1571 skip("Unable to create association for '.shlexec'\n");
1572 return;
1574 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1575 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1576 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1577 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1578 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1579 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1582 static void cleanup_test(void)
1584 char filename[MAX_PATH];
1585 const char* const * testfile;
1587 /* Delete the test files */
1588 testfile=testfiles;
1589 while (*testfile)
1591 sprintf(filename, *testfile, tmpdir);
1592 DeleteFile(filename);
1593 testfile++;
1595 DeleteFile(child_file);
1597 /* Delete the test association */
1598 delete_test_association(".shlexec");
1600 CloseHandle(hEvent);
1602 CoUninitialize();
1605 START_TEST(shlexec)
1608 myARGC = winetest_get_mainargs(&myARGV);
1609 if (myARGC >= 3)
1611 doChild(myARGC, myARGV);
1612 exit(0);
1615 init_test();
1617 test_filename();
1618 test_find_executable();
1619 test_lnks();
1620 test_exes();
1621 test_exes_long();
1622 test_dde();
1623 test_dde_default_app();
1625 cleanup_test();