stash
[wine/wine64.git] / dlls / shell32 / tests / shlexec.c
blob4ea855ac57662d3fa1217212afeb9a6cb89935a0
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 /* Needed to get SEE_MASK_NOZONECHECKS with the PSDK */
36 #define NTDDI_WINXPSP1 0x05010100
37 #define NTDDI_VERSION NTDDI_WINXPSP1
38 #define _WIN32_WINNT 0x0501
40 #include <stdio.h>
41 #include <assert.h>
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", 0x0, SE_ERR_FNF},
631 {NULL, "%s\\nonexistent.noassoc", 0x0, 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", 0x0, 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 if (0) /* Can crash on Vista! */
852 rc=(int)FindExecutableA(NULL, NULL, command);
853 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %d\n", rc);
854 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
857 strcpy(command, "your word");
858 rc=(int)FindExecutableA(tmpdir, NULL, command);
859 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %d\n", rc);
860 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
862 sprintf(filename, "%s\\test file.sfe", tmpdir);
863 rc=(int)FindExecutableA(filename, NULL, command);
864 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
865 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
867 rc=(int)FindExecutableA("test file.sfe", tmpdir, command);
868 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
870 rc=(int)FindExecutableA("test file.sfe", NULL, command);
871 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %d\n", filename, rc);
873 delete_test_association(".sfe");
875 if (!create_test_association(".shl"))
877 skip("Unable to create association for '.shl'\n");
878 return;
880 create_test_verb(".shl", "Open", 0, "Open");
882 sprintf(filename, "%s\\test file.shl", tmpdir);
883 rc=(int)FindExecutableA(filename, NULL, command);
884 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
886 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
887 rc=(int)FindExecutableA(filename, NULL, command);
889 delete_test_association(".shl");
891 if (rc > 32)
893 /* On Windows XP and 2003 FindExecutable() is completely broken.
894 * Probably what it does is convert the filename to 8.3 format,
895 * which as a side effect converts the '.shlfoo' extension to '.shl',
896 * and then tries to find an association for '.shl'. This means it
897 * will normally fail on most extensions with more than 3 characters,
898 * like '.mpeg', etc.
899 * Also it means we cannot do any other test.
901 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
902 return;
905 test=filename_tests;
906 while (test->basename)
908 sprintf(filename, test->basename, tmpdir);
909 if (strchr(filename, '/'))
911 char* c;
912 c=filename;
913 while (*c)
915 if (*c=='\\')
916 *c='/';
917 c++;
920 /* Win98 does not '\0'-terminate command! */
921 memset(command, '\0', sizeof(command));
922 rc=(int)FindExecutableA(filename, NULL, command);
923 if (rc > 32)
924 rc=33;
925 if ((test->todo & 0x10)==0)
927 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
929 else todo_wine
931 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
933 if (rc > 32)
935 int equal;
936 equal=strcmp(command, argv0) == 0 ||
937 /* NT4 returns an extra 0x8 character! */
938 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
939 if ((test->todo & 0x20)==0)
941 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
942 filename, command, argv0);
944 else todo_wine
946 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
947 filename, command, argv0);
950 test++;
955 static filename_tests_t lnk_tests[]=
957 /* Pass bad / nonexistent filenames as a parameter */
958 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
959 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
961 /* Pass regular paths as a parameter */
962 {NULL, "%s\\test file.shlexec", 0xa, 33},
963 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
965 /* Pass filenames with no association as a parameter */
966 {NULL, "%s\\test file.noassoc", 0xa, 33},
968 {NULL, NULL, 0}
971 static void test_lnks(void)
973 char filename[MAX_PATH];
974 char params[MAX_PATH];
975 const filename_tests_t* test;
976 int rc;
978 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
979 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
980 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
981 GetLastError());
982 okChildInt("argcA", 5);
983 okChildString("argvA3", "Open");
984 sprintf(filename, "%s\\test file.shlexec", tmpdir);
985 okChildPath("argvA4", filename);
987 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
988 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
989 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
990 GetLastError());
991 okChildInt("argcA", 4);
992 okChildString("argvA3", "Lnk");
994 if (dllver.dwMajorVersion>=6)
996 char* c;
997 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
998 * Older versions don't or are quite buggy in this regard.
1000 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1001 c=filename;
1002 while (*c)
1004 if (*c=='\\')
1005 *c='/';
1006 c++;
1008 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1009 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1010 GetLastError());
1011 okChildInt("argcA", 4);
1012 okChildString("argvA3", "Lnk");
1015 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1016 test=lnk_tests;
1017 while (test->basename)
1019 params[0]='\"';
1020 sprintf(params+1, test->basename, tmpdir);
1021 strcat(params,"\"");
1022 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1023 NULL);
1024 if (rc > 32)
1025 rc=33;
1026 if ((test->todo & 0x1)==0)
1028 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1029 rc, GetLastError());
1031 else todo_wine
1033 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1034 rc, GetLastError());
1036 if (rc==0)
1038 if ((test->todo & 0x2)==0)
1040 okChildInt("argcA", 5);
1042 else
1044 okChildInt("argcA", 5);
1046 if ((test->todo & 0x4)==0)
1048 okChildString("argvA3", "Lnk");
1050 else todo_wine
1052 okChildString("argvA3", "Lnk");
1054 sprintf(params, test->basename, tmpdir);
1055 if ((test->todo & 0x8)==0)
1057 okChildPath("argvA4", params);
1059 else
1061 okChildPath("argvA4", params);
1064 test++;
1069 static void test_exes(void)
1071 char filename[MAX_PATH];
1072 char params[1024];
1073 int rc;
1075 sprintf(params, "shlexec \"%s\" Exec", child_file);
1077 /* We need NOZONECHECKS on Win2003 to block a dialog */
1078 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1079 NULL);
1080 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1081 okChildInt("argcA", 4);
1082 okChildString("argvA3", "Exec");
1084 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1085 if (CopyFile(argv0, filename, FALSE))
1087 rc=shell_execute(NULL, filename, params, NULL);
1088 todo_wine {
1089 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1094 static void test_exes_long(void)
1096 char filename[MAX_PATH];
1097 char params[2024];
1098 char longparam[MAX_PATH];
1099 int rc;
1101 for (rc = 0; rc < MAX_PATH; rc++)
1102 longparam[rc]='a'+rc%26;
1103 longparam[MAX_PATH-1]=0;
1106 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1108 /* We need NOZONECHECKS on Win2003 to block a dialog */
1109 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1110 NULL);
1111 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1112 okChildInt("argcA", 4);
1113 okChildString("argvA3", longparam);
1115 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1116 if (CopyFile(argv0, filename, FALSE))
1118 rc=shell_execute(NULL, filename, params, NULL);
1119 todo_wine {
1120 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1125 typedef struct
1127 const char* command;
1128 const char* ddeexec;
1129 const char* application;
1130 const char* topic;
1131 const char* ifexec;
1132 int expectedArgs;
1133 const char* expectedDdeExec;
1134 int todo;
1135 int rc;
1136 } dde_tests_t;
1138 static dde_tests_t dde_tests[] =
1140 /* Test passing and not passing command-line
1141 * argument, no DDE */
1142 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0, 33},
1143 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0, 33},
1145 /* Test passing and not passing command-line
1146 * argument, with DDE */
1147 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1148 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0, 33},
1150 /* Test unquoted %1 in command and ddeexec
1151 * (test filename has space) */
1152 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0, 33},
1154 /* Test ifexec precedence over ddeexec */
1155 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0, 33},
1157 /* Test default DDE topic */
1158 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1160 /* Test default DDE application */
1161 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1163 {NULL, NULL, NULL, NULL, NULL, 0, 0x0, 0}
1166 static DWORD ddeInst;
1167 static HSZ hszTopic;
1168 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
1169 static BOOL denyNextConnection;
1171 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
1172 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
1173 ULONG_PTR dwData1, ULONG_PTR dwData2)
1175 DWORD size = 0;
1177 if (winetest_debug > 2)
1178 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
1179 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
1181 switch (uType)
1183 case XTYP_CONNECT:
1184 if (!DdeCmpStringHandles(hsz1, hszTopic))
1186 if (denyNextConnection)
1187 denyNextConnection = FALSE;
1188 else
1190 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
1191 assert(size < MAX_PATH);
1192 return (HDDEDATA)TRUE;
1195 return (HDDEDATA)FALSE;
1197 case XTYP_EXECUTE:
1198 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
1199 assert(size < MAX_PATH);
1200 DdeFreeDataHandle(hData);
1201 return (HDDEDATA)DDE_FACK;
1203 default:
1204 return NULL;
1208 typedef struct
1210 char *filename;
1211 DWORD threadIdParent;
1212 } dde_thread_info_t;
1214 static DWORD CALLBACK ddeThread(LPVOID arg)
1216 dde_thread_info_t *info = (dde_thread_info_t *)arg;
1217 assert(info && info->filename);
1218 PostThreadMessage(info->threadIdParent,
1219 WM_QUIT,
1220 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
1221 0L);
1222 ExitThread(0);
1225 /* ShellExecute won't successfully send DDE commands to console applications after starting them,
1226 * so we run a DDE server in this application, deny the first connection request to make
1227 * ShellExecute start the application, and then process the next DDE connection in this application
1228 * to see the execute command that is sent. */
1229 static void test_dde(void)
1231 char filename[MAX_PATH], defApplication[MAX_PATH];
1232 HSZ hszApplication;
1233 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1234 const dde_tests_t* test;
1235 char params[1024];
1236 DWORD threadId;
1237 MSG msg;
1238 int rc;
1240 ddeInst = 0;
1241 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1242 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1243 assert(rc == DMLERR_NO_ERROR);
1245 sprintf(filename, "%s\\test file.sde", tmpdir);
1247 /* Default service is application name minus path and extension */
1248 strcpy(defApplication, strrchr(argv0, '\\')+1);
1249 *strchr(defApplication, '.') = 0;
1251 test = dde_tests;
1252 while (test->command)
1254 if (!create_test_association(".sde"))
1256 skip("Unable to create association for '.sfe'\n");
1257 return;
1259 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1260 test->application, test->topic, test->ifexec);
1261 hszApplication = DdeCreateStringHandleA(ddeInst, test->application ?
1262 test->application : defApplication, CP_WINANSI);
1263 hszTopic = DdeCreateStringHandleA(ddeInst, test->topic ? test->topic : SZDDESYS_TOPIC,
1264 CP_WINANSI);
1265 assert(hszApplication && hszTopic);
1266 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER));
1267 denyNextConnection = TRUE;
1268 ddeExec[0] = 0;
1270 assert(CreateThread(NULL, 0, ddeThread, (LPVOID)&info, 0, &threadId));
1271 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1272 rc = msg.wParam > 32 ? 33 : msg.wParam;
1273 if ((test->todo & 0x1)==0)
1275 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1276 rc, GetLastError());
1278 else todo_wine
1280 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1281 rc, GetLastError());
1283 if (rc == 33)
1285 if ((test->todo & 0x2)==0)
1287 okChildInt("argcA", test->expectedArgs + 3);
1289 else todo_wine
1291 okChildInt("argcA", test->expectedArgs + 3);
1293 if (test->expectedArgs == 1)
1295 if ((test->todo & 0x4) == 0)
1297 okChildPath("argvA3", filename);
1299 else todo_wine
1301 okChildPath("argvA3", filename);
1304 if ((test->todo & 0x8) == 0)
1306 sprintf(params, test->expectedDdeExec, filename);
1307 ok(StrCmpPath(params, ddeExec) == 0,
1308 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1310 else todo_wine
1312 sprintf(params, test->expectedDdeExec, filename);
1313 ok(StrCmpPath(params, ddeExec) == 0,
1314 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1318 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1319 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1320 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1321 delete_test_association(".sde");
1322 test++;
1325 assert(DdeUninitialize(ddeInst));
1328 #define DDE_DEFAULT_APP_VARIANTS 2
1329 typedef struct
1331 const char* command;
1332 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1333 int todo;
1334 int rc[DDE_DEFAULT_APP_VARIANTS];
1335 } dde_default_app_tests_t;
1337 static dde_default_app_tests_t dde_default_app_tests[] =
1339 /* Windows XP and 98 handle default DDE app names in different ways.
1340 * The application name we see in the first test determines the pattern
1341 * of application names and return codes we will look for. */
1343 /* Test unquoted existing filename with a space */
1344 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1345 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1347 /* Test quoted existing filename with a space */
1348 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1349 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1351 /* Test unquoted filename with a space that doesn't exist, but
1352 * test2.exe does */
1353 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1354 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1356 /* Test quoted filename with a space that does not exist */
1357 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1358 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1360 /* Test filename supplied without the extension */
1361 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1362 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1364 /* Test an unquoted nonexistent filename */
1365 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1366 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1368 /* Test an application that will be found on the path */
1369 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1370 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1372 /* Test an application that will not be found on the path */
1373 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1374 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1376 {NULL, {NULL}, 0, {0}}
1379 static void test_dde_default_app(void)
1381 char filename[MAX_PATH];
1382 HSZ hszApplication;
1383 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1384 const dde_default_app_tests_t* test;
1385 char params[1024];
1386 DWORD threadId;
1387 MSG msg;
1388 int rc, which = 0;
1390 ddeInst = 0;
1391 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1392 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1393 assert(rc == DMLERR_NO_ERROR);
1395 sprintf(filename, "%s\\test file.sde", tmpdir);
1397 /* It is strictly not necessary to register an application name here, but wine's
1398 * DdeNameService implementation complains if 0L is passed instead of
1399 * hszApplication with DNS_FILTEROFF */
1400 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1401 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1402 assert(hszApplication && hszTopic);
1403 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
1405 test = dde_default_app_tests;
1406 while (test->command)
1408 if (!create_test_association(".sde"))
1410 skip("Unable to create association for '.sde'\n");
1411 return;
1413 sprintf(params, test->command, tmpdir);
1414 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
1415 "shlexec", NULL);
1416 denyNextConnection = FALSE;
1417 ddeApplication[0] = 0;
1419 /* No application will be run as we will respond to the first DDE event,
1420 * so don't wait for it */
1421 SetEvent(hEvent);
1423 assert(CreateThread(NULL, 0, ddeThread, (LPVOID)&info, 0, &threadId));
1424 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1425 rc = msg.wParam > 32 ? 33 : msg.wParam;
1427 /* First test, find which set of test data we expect to see */
1428 if (test == dde_default_app_tests)
1430 int i;
1431 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
1433 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
1435 which = i;
1436 break;
1439 if (i == DDE_DEFAULT_APP_VARIANTS)
1440 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1443 if ((test->todo & 0x1)==0)
1445 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1446 rc, GetLastError());
1448 else todo_wine
1450 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1451 rc, GetLastError());
1453 if (rc == 33)
1455 if ((test->todo & 0x2)==0)
1457 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1458 "Expected application '%s', got '%s'\n",
1459 test->expectedDdeApplication[which], ddeApplication);
1461 else todo_wine
1463 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1464 "Expected application '%s', got '%s'\n",
1465 test->expectedDdeApplication[which], ddeApplication);
1469 delete_test_association(".sde");
1470 test++;
1473 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1474 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1475 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1476 assert(DdeUninitialize(ddeInst));
1479 static void init_test(void)
1481 HMODULE hdll;
1482 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
1483 char filename[MAX_PATH];
1484 WCHAR lnkfile[MAX_PATH];
1485 char params[1024];
1486 const char* const * testfile;
1487 lnk_desc_t desc;
1488 DWORD rc;
1489 HRESULT r;
1491 hdll=GetModuleHandleA("shell32.dll");
1492 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
1493 if (pDllGetVersion)
1495 dllver.cbSize=sizeof(dllver);
1496 pDllGetVersion(&dllver);
1497 trace("major=%d minor=%d build=%d platform=%d\n",
1498 dllver.dwMajorVersion, dllver.dwMinorVersion,
1499 dllver.dwBuildNumber, dllver.dwPlatformID);
1501 else
1503 memset(&dllver, 0, sizeof(dllver));
1506 r = CoInitialize(NULL);
1507 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
1508 if (FAILED(r))
1509 exit(1);
1511 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1512 assert(rc!=0 && rc<sizeof(argv0));
1513 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1515 strcat(argv0, ".so");
1516 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1517 "unable to find argv0!\n");
1520 GetTempPathA(sizeof(tmpdir)/sizeof(*tmpdir), tmpdir);
1521 assert(GetTempFileNameA(tmpdir, "wt", 0, child_file)!=0);
1522 init_event(child_file);
1524 /* Set up the test files */
1525 testfile=testfiles;
1526 while (*testfile)
1528 HANDLE hfile;
1530 sprintf(filename, *testfile, tmpdir);
1531 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1532 FILE_ATTRIBUTE_NORMAL, NULL);
1533 if (hfile==INVALID_HANDLE_VALUE)
1535 trace("unable to create '%s': err=%d\n", filename, GetLastError());
1536 assert(0);
1538 CloseHandle(hfile);
1539 testfile++;
1542 /* Setup the test shortcuts */
1543 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1544 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1545 desc.description=NULL;
1546 desc.workdir=NULL;
1547 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1548 desc.path=filename;
1549 desc.pidl=NULL;
1550 desc.arguments="ignored";
1551 desc.showcmd=0;
1552 desc.icon=NULL;
1553 desc.icon_id=0;
1554 desc.hotkey=0;
1555 create_lnk(lnkfile, &desc, 0);
1557 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1558 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1559 desc.description=NULL;
1560 desc.workdir=NULL;
1561 desc.path=argv0;
1562 desc.pidl=NULL;
1563 sprintf(params, "shlexec \"%s\" Lnk", child_file);
1564 desc.arguments=params;
1565 desc.showcmd=0;
1566 desc.icon=NULL;
1567 desc.icon_id=0;
1568 desc.hotkey=0;
1569 create_lnk(lnkfile, &desc, 0);
1571 /* Create a basic association suitable for most tests */
1572 if (!create_test_association(".shlexec"))
1574 skip("Unable to create association for '.shlexec'\n");
1575 return;
1577 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1578 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1579 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1580 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1581 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1582 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1585 static void cleanup_test(void)
1587 char filename[MAX_PATH];
1588 const char* const * testfile;
1590 /* Delete the test files */
1591 testfile=testfiles;
1592 while (*testfile)
1594 sprintf(filename, *testfile, tmpdir);
1595 DeleteFile(filename);
1596 testfile++;
1598 DeleteFile(child_file);
1600 /* Delete the test association */
1601 delete_test_association(".shlexec");
1603 CloseHandle(hEvent);
1605 CoUninitialize();
1608 static void test_commandline(void)
1610 static const WCHAR one[] = {'o','n','e',0};
1611 static const WCHAR two[] = {'t','w','o',0};
1612 static const WCHAR three[] = {'t','h','r','e','e',0};
1613 static const WCHAR four[] = {'f','o','u','r',0};
1615 static const WCHAR fmt1[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
1616 static const WCHAR fmt2[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
1617 static const WCHAR fmt3[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
1618 static const WCHAR fmt4[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
1619 static const WCHAR fmt5[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
1621 static const WCHAR chkfmt1[] = {'%','s','=','%','s',0};
1622 static const WCHAR chkfmt2[] = {'%','s',' ','%','s',0};
1623 static const WCHAR chkfmt3[] = {'\\','\"','%','s','\"',0};
1624 static const WCHAR chkfmt4[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
1625 WCHAR cmdline[255];
1626 LPWSTR *args = (LPWSTR*)0xdeadcafe;
1627 INT numargs = -1;
1629 wsprintfW(cmdline,fmt1,one,two,three,four);
1630 args=CommandLineToArgvW(cmdline,&numargs);
1631 if (args == NULL && numargs == -1)
1633 win_skip("CommandLineToArgvW not implemented, skipping\n");
1634 return;
1636 ok(numargs == 4, "expected 4 args, got %i\n",numargs);
1637 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1638 ok(lstrcmpW(args[1],two)==0,"arg1 is not as expected\n");
1639 ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n");
1640 ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
1642 wsprintfW(cmdline,fmt2,one,two,three,four);
1643 args=CommandLineToArgvW(cmdline,&numargs);
1644 ok(numargs == 5, "expected 5 args, got %i\n",numargs);
1645 ok(args[0][0]==0,"arg0 is not as expected\n");
1646 ok(lstrcmpW(args[1],one)==0,"arg1 is not as expected\n");
1647 ok(lstrcmpW(args[2],two)==0,"arg2 is not as expected\n");
1648 ok(lstrcmpW(args[3],three)==0,"arg3 is not as expected\n");
1649 ok(lstrcmpW(args[4],four)==0,"arg4 is not as expected\n");
1651 wsprintfW(cmdline,fmt3,one,two,three,four);
1652 args=CommandLineToArgvW(cmdline,&numargs);
1653 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1654 wsprintfW(cmdline,chkfmt1,one,two);
1655 ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1656 wsprintfW(cmdline,chkfmt1,three,four);
1657 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1659 wsprintfW(cmdline,fmt4,one,two,three,four);
1660 args=CommandLineToArgvW(cmdline,&numargs);
1661 ok(numargs == 3, "expected 3 args, got %i\n",numargs);
1662 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1663 wsprintfW(cmdline,chkfmt2,two,three);
1664 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1665 ok(lstrcmpW(args[2],four)==0,"arg2 is not as expected\n");
1667 wsprintfW(cmdline,fmt5,one,two,three,four);
1668 args=CommandLineToArgvW(cmdline,&numargs);
1669 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1670 wsprintfW(cmdline,chkfmt3,one);
1671 todo_wine ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1672 wsprintfW(cmdline,chkfmt4,two,three,four);
1673 todo_wine ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1676 START_TEST(shlexec)
1679 myARGC = winetest_get_mainargs(&myARGV);
1680 if (myARGC >= 3)
1682 doChild(myARGC, myARGV);
1683 exit(0);
1686 init_test();
1688 test_filename();
1689 test_find_executable();
1690 test_lnks();
1691 test_exes();
1692 test_exes_long();
1693 test_dde();
1694 test_dde_default_app();
1695 test_commandline();
1697 cleanup_test();