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
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
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
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
48 #include "wine/test.h"
50 #include "shell32_test.h"
53 static char argv0[MAX_PATH];
56 static char tmpdir[MAX_PATH];
57 static char child_file[MAX_PATH];
58 static DLLVERSIONINFO dllver;
63 * ShellExecute wrappers
66 static void dump_child(void);
69 static void init_event(const char* child_file)
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)
90 static char shell_call[2048]="";
91 static int shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
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_PTR)ShellExecute(NULL, operation, file, parameters, directory, SW_SHOWNORMAL);
119 wait_rc=WaitForSingleObject(hEvent, 5000);
120 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
122 /* The child process may have changed the result file, so let profile
123 * functions know about it
125 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
132 static int shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
133 LPCSTR parameters, LPCSTR directory)
135 SHELLEXECUTEINFO sei;
139 strcpy(shell_call, "ShellExecuteEx(");
140 strcat_param(shell_call, operation);
141 strcat(shell_call, ", ");
142 strcat_param(shell_call, file);
143 strcat(shell_call, ", ");
144 strcat_param(shell_call, parameters);
145 strcat(shell_call, ", ");
146 strcat_param(shell_call, directory);
147 strcat(shell_call, ")");
148 if (winetest_debug > 1)
149 trace("%s\n", shell_call);
151 sei.cbSize=sizeof(sei);
152 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
154 sei.lpVerb=operation;
156 sei.lpParameters=parameters;
157 sei.lpDirectory=directory;
158 sei.nShow=SW_SHOWNORMAL;
159 sei.hInstApp=NULL; /* Out */
165 sei.hProcess=NULL; /* Out */
167 DeleteFile(child_file);
168 SetLastError(0xcafebabe);
169 success=ShellExecuteEx(&sei);
170 rc=(INT_PTR)sei.hInstApp;
171 ok((success && rc > 32) || (!success && rc <= 32),
172 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call, success, rc);
177 if (sei.hProcess!=NULL)
179 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
180 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
182 wait_rc=WaitForSingleObject(hEvent, 5000);
183 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
185 /* The child process may have changed the result file, so let profile
186 * functions know about it
188 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
199 * Functions to create / delete associations wrappers
203 static BOOL create_test_association(const char* extension)
205 HKEY hkey, hkey_shell;
206 char class[MAX_PATH];
209 sprintf(class, "shlexec%s", extension);
210 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
212 if (rc != ERROR_SUCCESS)
215 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
216 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
219 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
220 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
221 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
223 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
224 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
225 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
228 CloseHandle(hkey_shell);
233 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
234 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
237 DWORD dwMaxSubkeyLen, dwMaxValueLen;
238 DWORD dwMaxLen, dwSize;
239 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
244 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
248 /* Get highest length for keys, values */
249 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
250 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
251 if (ret) goto cleanup;
255 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
256 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
258 /* Name too big: alloc a buffer for it */
259 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
261 ret = ERROR_NOT_ENOUGH_MEMORY;
267 /* Recursively delete all the subkeys */
271 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
272 NULL, NULL, NULL)) break;
274 ret = myRegDeleteTreeA(hSubKey, lpszName);
275 if (ret) goto cleanup;
279 ret = RegDeleteKeyA(hKey, lpszSubKey);
284 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
285 NULL, NULL, NULL, NULL)) break;
287 ret = RegDeleteValueA(hKey, lpszName);
288 if (ret) goto cleanup;
292 /* Free buffer if allocated */
293 if (lpszName != szNameBuf)
294 HeapFree( GetProcessHeap(), 0, lpszName);
296 RegCloseKey(hSubKey);
300 static void delete_test_association(const char* extension)
302 char class[MAX_PATH];
304 sprintf(class, "shlexec%s", extension);
305 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
306 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
309 static void create_test_verb_dde(const char* extension, const char* verb,
310 int rawcmd, const char* cmdtail, const char *ddeexec,
311 const char *application, const char *topic,
314 HKEY hkey_shell, hkey_verb, hkey_cmd;
315 char shell[MAX_PATH];
319 sprintf(shell, "shlexec%s\\shell", extension);
320 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
321 KEY_CREATE_SUB_KEY, &hkey_shell);
322 assert(rc==ERROR_SUCCESS);
323 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
324 NULL, &hkey_verb, NULL);
325 assert(rc==ERROR_SUCCESS);
326 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
327 NULL, &hkey_cmd, NULL);
328 assert(rc==ERROR_SUCCESS);
332 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
336 cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
337 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
338 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
339 assert(rc==ERROR_SUCCESS);
340 HeapFree(GetProcessHeap(), 0, cmd);
345 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
347 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
348 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
349 assert(rc==ERROR_SUCCESS);
350 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
352 assert(rc==ERROR_SUCCESS);
355 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
356 NULL, &hkey_application, NULL);
357 assert(rc==ERROR_SUCCESS);
358 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
359 strlen(application)+1);
360 assert(rc==ERROR_SUCCESS);
361 CloseHandle(hkey_application);
365 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
366 NULL, &hkey_topic, NULL);
367 assert(rc==ERROR_SUCCESS);
368 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
370 assert(rc==ERROR_SUCCESS);
371 CloseHandle(hkey_topic);
375 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
376 NULL, &hkey_ifexec, NULL);
377 assert(rc==ERROR_SUCCESS);
378 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
380 assert(rc==ERROR_SUCCESS);
381 CloseHandle(hkey_ifexec);
383 CloseHandle(hkey_ddeexec);
386 CloseHandle(hkey_shell);
387 CloseHandle(hkey_verb);
388 CloseHandle(hkey_cmd);
391 static void create_test_verb(const char* extension, const char* verb,
392 int rawcmd, const char* cmdtail)
394 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
400 * Functions to check that the child process was started just right
401 * (borrowed from dlls/kernel32/tests/process.c)
405 static const char* encodeA(const char* str)
407 static char encoded[2*1024+1];
412 len = strlen(str) + 1;
413 if (len >= sizeof(encoded)/2)
415 fprintf(stderr, "string is too long!\n");
419 for (i = 0; i < len; i++)
420 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
425 static unsigned decode_char(char c)
427 if (c >= '0' && c <= '9') return c - '0';
428 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
429 assert(c >= 'A' && c <= 'F');
433 static char* decodeA(const char* str)
435 static char decoded[1024];
439 len = strlen(str) / 2;
440 if (!len--) return NULL;
441 if (len >= sizeof(decoded))
443 fprintf(stderr, "string is too long!\n");
447 for (i = 0; i < len; i++)
448 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
453 static void childPrintf(HANDLE h, const char* fmt, ...)
459 va_start(valist, fmt);
460 vsprintf(buffer, fmt, valist);
462 WriteFile(h, buffer, strlen(buffer), &w, NULL);
465 static void doChild(int argc, char** argv)
472 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
473 if (hFile == INVALID_HANDLE_VALUE)
477 childPrintf(hFile, "[Arguments]\r\n");
478 if (winetest_debug > 2)
479 trace("argcA=%d\n", argc);
480 childPrintf(hFile, "argcA=%d\r\n", argc);
481 for (i = 0; i < argc; i++)
483 if (winetest_debug > 2)
484 trace("argvA%d=%s\n", i, argv[i]);
485 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
489 init_event(filename);
494 static char* getChildString(const char* sect, const char* key)
499 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
500 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
501 assert(!(strlen(buf) & 1));
506 static void dump_child(void)
508 if (winetest_debug > 1)
514 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
515 trace("argcA=%d\n",c);
518 sprintf(key, "argvA%d", i);
519 str=getChildString("Arguments", key);
520 trace("%s=%s\n", key, str);
525 static int StrCmpPath(const char* s1, const char* s2)
527 if (!s1 && !s2) return 0;
538 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
540 while (*s1=='/' || *s1=='\\')
542 while (*s2=='/' || *s2=='\\')
545 else if (toupper(*s1)==toupper(*s2))
562 static int _okChildString(const char* file, int line, const char* key, const char* expected)
565 result=getChildString("Arguments", key);
566 return ok_(file, line)(lstrcmpiA(result, expected) == 0,
567 "%s expected '%s', got '%s'\n", key, expected, result);
570 static int _okChildPath(const char* file, int line, const char* key, const char* expected)
573 result=getChildString("Arguments", key);
574 return ok_(file, line)(StrCmpPath(result, expected) == 0,
575 "%s expected '%s', got '%s'\n", key, expected, result);
578 static int _okChildInt(const char* file, int line, const char* key, int expected)
581 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
582 return ok_(file, line)(result == expected,
583 "%s expected %d, but got %d\n", key, expected, result);
586 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
587 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
588 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
592 * GetLongPathNameA equivalent that supports Win95 and WinNT
596 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
598 char tmplongpath[MAX_PATH];
600 DWORD sp = 0, lp = 0;
602 WIN32_FIND_DATAA wfd;
605 if (!shortpath || !shortpath[0])
608 if (shortpath[1] == ':')
610 tmplongpath[0] = shortpath[0];
611 tmplongpath[1] = ':';
615 while (shortpath[sp])
617 /* check for path delimiters and reproduce them */
618 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
620 if (!lp || tmplongpath[lp-1] != '\\')
622 /* strip double "\\" */
623 tmplongpath[lp++] = '\\';
625 tmplongpath[lp] = 0; /* terminate string */
631 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
633 tmplongpath[lp++] = *p++;
634 tmplongpath[lp++] = *p++;
636 for (; *p && *p != '/' && *p != '\\'; p++);
637 tmplen = p - (shortpath + sp);
638 lstrcpyn(tmplongpath + lp, shortpath + sp, tmplen + 1);
639 /* Check if the file exists and use the existing file name */
640 goit = FindFirstFileA(tmplongpath, &wfd);
641 if (goit == INVALID_HANDLE_VALUE)
644 strcpy(tmplongpath + lp, wfd.cFileName);
645 lp += strlen(tmplongpath + lp);
648 tmplen = strlen(shortpath) - 1;
649 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
650 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
651 tmplongpath[lp++] = shortpath[tmplen];
654 tmplen = strlen(tmplongpath) + 1;
655 if (tmplen <= longlen)
657 strcpy(longpath, tmplongpath);
658 tmplen--; /* length without 0 */
670 static const char* testfiles[]=
672 "%s\\test file.shlexec",
673 "%s\\%%nasty%% $file.shlexec",
674 "%s\\test file.noassoc",
675 "%s\\test file.noassoc.shlexec",
676 "%s\\test file.shlexec.noassoc",
677 "%s\\test_shortcut_shlexec.lnk",
678 "%s\\test_shortcut_exe.lnk",
680 "%s\\test file.shlfoo",
682 "%s\\masked file.shlexec",
693 const char* basename;
698 static filename_tests_t filename_tests[]=
700 /* Test bad / nonexistent filenames */
701 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
702 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
705 {NULL, "%s\\test file.shlexec", 0x0, 33},
706 {NULL, "%s\\test file.shlexec.", 0x0, 33},
707 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
708 {NULL, "%s/test file.shlexec", 0x0, 33},
710 /* Test filenames with no association */
711 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
713 /* Test double extensions */
714 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
715 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
717 /* Test alternate verbs */
718 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
719 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
721 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
722 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
724 /* Test file masked due to space */
725 {NULL, "%s\\masked file.shlexec", 0x1, 33},
726 /* Test if quoting prevents the masking */
727 {NULL, "%s\\masked file.shlexec", 0x40, 33},
732 static filename_tests_t noquotes_tests[]=
734 /* Test unquoted '%1' thingies */
735 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
736 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
737 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
742 static void test_filename(void)
744 char filename[MAX_PATH];
745 const filename_tests_t* test;
750 while (test->basename)
752 BOOL quotedfile = FALSE;
754 sprintf(filename, test->basename, tmpdir);
755 if (strchr(filename, '/'))
765 if ((test->todo & 0x40)==0)
767 rc=shell_execute(test->verb, filename, NULL, NULL);
771 char quoted[MAX_PATH + 2];
774 sprintf(quoted, "\"%s\"", filename);
775 rc=shell_execute(test->verb, quoted, NULL, NULL);
779 if ((test->todo & 0x1)==0)
782 broken(quotedfile && rc == 2), /* NT4 */
783 "%s failed: rc=%d err=%d\n", shell_call,
788 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
794 if ((test->todo & 0x2)==0)
796 okChildInt("argcA", 5);
800 okChildInt("argcA", 5);
802 verb=(test->verb ? test->verb : "Open");
803 if ((test->todo & 0x4)==0)
805 okChildString("argvA3", verb);
809 okChildString("argvA3", verb);
811 if ((test->todo & 0x8)==0)
813 okChildPath("argvA4", filename);
817 okChildPath("argvA4", filename);
824 while (test->basename)
826 sprintf(filename, test->basename, tmpdir);
827 rc=shell_execute(test->verb, filename, NULL, NULL);
830 if ((test->todo & 0x1)==0)
832 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
837 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
846 verb=(test->verb ? test->verb : "Open");
847 if ((test->todo & 0x4)==0)
849 okChildString("argvA3", verb);
853 okChildString("argvA3", verb);
862 space=strchr(str, ' ');
865 sprintf(attrib, "argvA%d", count);
866 if ((test->todo & 0x8)==0)
868 okChildPath(attrib, str);
872 okChildPath(attrib, str);
879 if ((test->todo & 0x2)==0)
881 okChildInt("argcA", count);
885 okChildInt("argcA", count);
891 if (dllver.dwMajorVersion != 0)
893 /* The more recent versions of shell32.dll accept quoted filenames
894 * while older ones (e.g. 4.00) don't. Still we want to test this
895 * because IE 6 depends on the new behavior.
896 * One day we may need to check the exact version of the dll but for
897 * now making sure DllGetVersion() is present is sufficient.
899 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
900 rc=shell_execute(NULL, filename, NULL, NULL);
901 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
903 okChildInt("argcA", 5);
904 okChildString("argvA3", "Open");
905 sprintf(filename, "%s\\test file.shlexec", tmpdir);
906 okChildPath("argvA4", filename);
910 static void test_find_executable(void)
912 char filename[MAX_PATH];
913 char command[MAX_PATH];
914 const filename_tests_t* test;
917 if (!create_test_association(".sfe"))
919 skip("Unable to create association for '.sfe'\n");
922 create_test_verb(".sfe", "Open", 1, "%1");
924 /* Don't test FindExecutable(..., NULL), it always crashes */
926 strcpy(command, "your word");
927 if (0) /* Can crash on Vista! */
929 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
930 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
931 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
934 strcpy(command, "your word");
935 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
936 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
937 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
939 sprintf(filename, "%s\\test file.sfe", tmpdir);
940 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
941 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
942 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
944 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
945 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
947 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
948 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %ld\n", filename, rc);
950 delete_test_association(".sfe");
952 if (!create_test_association(".shl"))
954 skip("Unable to create association for '.shl'\n");
957 create_test_verb(".shl", "Open", 0, "Open");
959 sprintf(filename, "%s\\test file.shl", tmpdir);
960 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
961 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
963 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
964 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
966 delete_test_association(".shl");
970 /* On Windows XP and 2003 FindExecutable() is completely broken.
971 * Probably what it does is convert the filename to 8.3 format,
972 * which as a side effect converts the '.shlfoo' extension to '.shl',
973 * and then tries to find an association for '.shl'. This means it
974 * will normally fail on most extensions with more than 3 characters,
976 * Also it means we cannot do any other test.
978 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
983 while (test->basename)
985 sprintf(filename, test->basename, tmpdir);
986 if (strchr(filename, '/'))
997 /* Win98 does not '\0'-terminate command! */
998 memset(command, '\0', sizeof(command));
999 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1002 if ((test->todo & 0x10)==0)
1004 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1008 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1013 equal=strcmp(command, argv0) == 0 ||
1014 /* NT4 returns an extra 0x8 character! */
1015 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
1016 if ((test->todo & 0x20)==0)
1018 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1019 filename, command, argv0);
1023 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1024 filename, command, argv0);
1032 static filename_tests_t lnk_tests[]=
1034 /* Pass bad / nonexistent filenames as a parameter */
1035 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
1036 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
1038 /* Pass regular paths as a parameter */
1039 {NULL, "%s\\test file.shlexec", 0xa, 33},
1040 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1042 /* Pass filenames with no association as a parameter */
1043 {NULL, "%s\\test file.noassoc", 0xa, 33},
1048 static void test_lnks(void)
1050 char filename[MAX_PATH];
1051 char params[MAX_PATH];
1052 const filename_tests_t* test;
1055 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1056 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1057 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1059 okChildInt("argcA", 5);
1060 okChildString("argvA3", "Open");
1061 sprintf(params, "%s\\test file.shlexec", tmpdir);
1062 get_long_path_name(params, filename, sizeof(filename));
1063 okChildPath("argvA4", filename);
1065 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1066 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1067 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1069 okChildInt("argcA", 4);
1070 okChildString("argvA3", "Lnk");
1072 if (dllver.dwMajorVersion>=6)
1075 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1076 * Older versions don't or are quite buggy in this regard.
1078 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1086 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1087 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1089 okChildInt("argcA", 4);
1090 okChildString("argvA3", "Lnk");
1093 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1095 while (test->basename)
1098 sprintf(params+1, test->basename, tmpdir);
1099 strcat(params,"\"");
1100 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1104 if ((test->todo & 0x1)==0)
1106 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1107 rc, GetLastError());
1111 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1112 rc, GetLastError());
1116 if ((test->todo & 0x2)==0)
1118 okChildInt("argcA", 5);
1122 okChildInt("argcA", 5);
1124 if ((test->todo & 0x4)==0)
1126 okChildString("argvA3", "Lnk");
1130 okChildString("argvA3", "Lnk");
1132 sprintf(params, test->basename, tmpdir);
1133 if ((test->todo & 0x8)==0)
1135 okChildPath("argvA4", params);
1139 okChildPath("argvA4", params);
1147 static void test_exes(void)
1149 char filename[MAX_PATH];
1153 sprintf(params, "shlexec \"%s\" Exec", child_file);
1155 /* We need NOZONECHECKS on Win2003 to block a dialog */
1156 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1158 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1159 okChildInt("argcA", 4);
1160 okChildString("argvA3", "Exec");
1162 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1163 if (CopyFile(argv0, filename, FALSE))
1165 rc=shell_execute(NULL, filename, params, NULL);
1167 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1172 static void test_exes_long(void)
1174 char filename[MAX_PATH];
1176 char longparam[MAX_PATH];
1179 for (rc = 0; rc < MAX_PATH; rc++)
1180 longparam[rc]='a'+rc%26;
1181 longparam[MAX_PATH-1]=0;
1184 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1186 /* We need NOZONECHECKS on Win2003 to block a dialog */
1187 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1189 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1190 okChildInt("argcA", 4);
1191 okChildString("argvA3", longparam);
1193 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1194 if (CopyFile(argv0, filename, FALSE))
1196 rc=shell_execute(NULL, filename, params, NULL);
1198 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1205 const char* command;
1206 const char* ddeexec;
1207 const char* application;
1211 const char* expectedDdeExec;
1216 static dde_tests_t dde_tests[] =
1218 /* Test passing and not passing command-line
1219 * argument, no DDE */
1220 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0, 33},
1221 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0, 33},
1223 /* Test passing and not passing command-line
1224 * argument, with DDE */
1225 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1226 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0, 33},
1228 /* Test unquoted %1 in command and ddeexec
1229 * (test filename has space) */
1230 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0, 33},
1232 /* Test ifexec precedence over ddeexec */
1233 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0, 33},
1235 /* Test default DDE topic */
1236 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1238 /* Test default DDE application */
1239 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0, 33},
1241 {NULL, NULL, NULL, NULL, NULL, 0, 0x0, 0}
1244 static DWORD ddeInst;
1245 static HSZ hszTopic;
1246 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
1247 static BOOL denyNextConnection;
1249 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
1250 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
1251 ULONG_PTR dwData1, ULONG_PTR dwData2)
1255 if (winetest_debug > 2)
1256 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
1257 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
1262 if (!DdeCmpStringHandles(hsz1, hszTopic))
1264 if (denyNextConnection)
1265 denyNextConnection = FALSE;
1268 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
1269 assert(size < MAX_PATH);
1270 return (HDDEDATA)TRUE;
1273 return (HDDEDATA)FALSE;
1276 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
1277 assert(size < MAX_PATH);
1278 DdeFreeDataHandle(hData);
1279 return (HDDEDATA)DDE_FACK;
1289 DWORD threadIdParent;
1290 } dde_thread_info_t;
1292 static DWORD CALLBACK ddeThread(LPVOID arg)
1294 dde_thread_info_t *info = arg;
1295 assert(info && info->filename);
1296 PostThreadMessage(info->threadIdParent,
1298 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
1303 /* ShellExecute won't successfully send DDE commands to console applications after starting them,
1304 * so we run a DDE server in this application, deny the first connection request to make
1305 * ShellExecute start the application, and then process the next DDE connection in this application
1306 * to see the execute command that is sent. */
1307 static void test_dde(void)
1309 char filename[MAX_PATH], defApplication[MAX_PATH];
1311 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1312 const dde_tests_t* test;
1319 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1320 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1321 assert(rc == DMLERR_NO_ERROR);
1323 sprintf(filename, "%s\\test file.sde", tmpdir);
1325 /* Default service is application name minus path and extension */
1326 strcpy(defApplication, strrchr(argv0, '\\')+1);
1327 *strchr(defApplication, '.') = 0;
1330 while (test->command)
1332 if (!create_test_association(".sde"))
1334 skip("Unable to create association for '.sfe'\n");
1337 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1338 test->application, test->topic, test->ifexec);
1339 hszApplication = DdeCreateStringHandleA(ddeInst, test->application ?
1340 test->application : defApplication, CP_WINANSI);
1341 hszTopic = DdeCreateStringHandleA(ddeInst, test->topic ? test->topic : SZDDESYS_TOPIC,
1343 assert(hszApplication && hszTopic);
1344 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER));
1345 denyNextConnection = TRUE;
1348 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
1349 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1350 rc = msg.wParam > 32 ? 33 : msg.wParam;
1351 if ((test->todo & 0x1)==0)
1353 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1354 rc, GetLastError());
1358 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1359 rc, GetLastError());
1363 if ((test->todo & 0x2)==0)
1365 okChildInt("argcA", test->expectedArgs + 3);
1369 okChildInt("argcA", test->expectedArgs + 3);
1371 if (test->expectedArgs == 1)
1373 if ((test->todo & 0x4) == 0)
1375 okChildPath("argvA3", filename);
1379 okChildPath("argvA3", filename);
1382 if ((test->todo & 0x8) == 0)
1384 sprintf(params, test->expectedDdeExec, filename);
1385 ok(StrCmpPath(params, ddeExec) == 0,
1386 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1390 sprintf(params, test->expectedDdeExec, filename);
1391 ok(StrCmpPath(params, ddeExec) == 0,
1392 "ddeexec expected '%s', got '%s'\n", params, ddeExec);
1396 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1397 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1398 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1399 delete_test_association(".sde");
1403 assert(DdeUninitialize(ddeInst));
1406 #define DDE_DEFAULT_APP_VARIANTS 2
1409 const char* command;
1410 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1412 int rc[DDE_DEFAULT_APP_VARIANTS];
1413 } dde_default_app_tests_t;
1415 static dde_default_app_tests_t dde_default_app_tests[] =
1417 /* Windows XP and 98 handle default DDE app names in different ways.
1418 * The application name we see in the first test determines the pattern
1419 * of application names and return codes we will look for. */
1421 /* Test unquoted existing filename with a space */
1422 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1423 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1425 /* Test quoted existing filename with a space */
1426 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1427 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1429 /* Test unquoted filename with a space that doesn't exist, but
1431 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1432 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1434 /* Test quoted filename with a space that does not exist */
1435 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1436 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1438 /* Test filename supplied without the extension */
1439 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1440 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1442 /* Test an unquoted nonexistent filename */
1443 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1444 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1446 /* Test an application that will be found on the path */
1447 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1448 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1450 /* Test an application that will not be found on the path */
1451 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1452 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1454 {NULL, {NULL}, 0, {0}}
1457 static void test_dde_default_app(void)
1459 char filename[MAX_PATH];
1461 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1462 const dde_default_app_tests_t* test;
1469 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1470 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1471 assert(rc == DMLERR_NO_ERROR);
1473 sprintf(filename, "%s\\test file.sde", tmpdir);
1475 /* It is strictly not necessary to register an application name here, but wine's
1476 * DdeNameService implementation complains if 0L is passed instead of
1477 * hszApplication with DNS_FILTEROFF */
1478 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1479 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1480 assert(hszApplication && hszTopic);
1481 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
1483 test = dde_default_app_tests;
1484 while (test->command)
1486 if (!create_test_association(".sde"))
1488 skip("Unable to create association for '.sde'\n");
1491 sprintf(params, test->command, tmpdir);
1492 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
1494 denyNextConnection = FALSE;
1495 ddeApplication[0] = 0;
1497 /* No application will be run as we will respond to the first DDE event,
1498 * so don't wait for it */
1501 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
1502 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1503 rc = msg.wParam > 32 ? 33 : msg.wParam;
1505 /* First test, find which set of test data we expect to see */
1506 if (test == dde_default_app_tests)
1509 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
1511 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
1517 if (i == DDE_DEFAULT_APP_VARIANTS)
1518 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1521 if ((test->todo & 0x1)==0)
1523 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1524 rc, GetLastError());
1528 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1529 rc, GetLastError());
1533 if ((test->todo & 0x2)==0)
1535 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1536 "Expected application '%s', got '%s'\n",
1537 test->expectedDdeApplication[which], ddeApplication);
1541 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1542 "Expected application '%s', got '%s'\n",
1543 test->expectedDdeApplication[which], ddeApplication);
1547 delete_test_association(".sde");
1551 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1552 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1553 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1554 assert(DdeUninitialize(ddeInst));
1557 static void init_test(void)
1560 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
1561 char filename[MAX_PATH];
1562 WCHAR lnkfile[MAX_PATH];
1564 const char* const * testfile;
1569 hdll=GetModuleHandleA("shell32.dll");
1570 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
1573 dllver.cbSize=sizeof(dllver);
1574 pDllGetVersion(&dllver);
1575 trace("major=%d minor=%d build=%d platform=%d\n",
1576 dllver.dwMajorVersion, dllver.dwMinorVersion,
1577 dllver.dwBuildNumber, dllver.dwPlatformID);
1581 memset(&dllver, 0, sizeof(dllver));
1584 r = CoInitialize(NULL);
1585 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
1589 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1590 assert(rc!=0 && rc<sizeof(argv0));
1591 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1593 strcat(argv0, ".so");
1594 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1595 "unable to find argv0!\n");
1598 GetTempPathA(sizeof(filename), filename);
1599 GetTempFileNameA(filename, "wt", 0, tmpdir);
1600 DeleteFileA( tmpdir );
1601 rc = CreateDirectoryA( tmpdir, NULL );
1602 ok( rc, "failed to create %s err %u\n", tmpdir, GetLastError() );
1603 rc = GetTempFileNameA(tmpdir, "wt", 0, child_file);
1605 init_event(child_file);
1607 /* Set up the test files */
1613 sprintf(filename, *testfile, tmpdir);
1614 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1615 FILE_ATTRIBUTE_NORMAL, NULL);
1616 if (hfile==INVALID_HANDLE_VALUE)
1618 trace("unable to create '%s': err=%d\n", filename, GetLastError());
1625 /* Setup the test shortcuts */
1626 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1627 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1628 desc.description=NULL;
1630 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1633 desc.arguments="ignored";
1638 create_lnk(lnkfile, &desc, 0);
1640 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1641 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1642 desc.description=NULL;
1646 sprintf(params, "shlexec \"%s\" Lnk", child_file);
1647 desc.arguments=params;
1652 create_lnk(lnkfile, &desc, 0);
1654 /* Create a basic association suitable for most tests */
1655 if (!create_test_association(".shlexec"))
1657 skip("Unable to create association for '.shlexec'\n");
1660 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1661 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1662 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1663 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1664 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1665 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1668 static void cleanup_test(void)
1670 char filename[MAX_PATH];
1671 const char* const * testfile;
1673 /* Delete the test files */
1677 sprintf(filename, *testfile, tmpdir);
1678 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
1679 SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
1680 DeleteFile(filename);
1683 DeleteFile(child_file);
1684 RemoveDirectoryA(tmpdir);
1686 /* Delete the test association */
1687 delete_test_association(".shlexec");
1689 CloseHandle(hEvent);
1694 static void test_commandline(void)
1696 static const WCHAR one[] = {'o','n','e',0};
1697 static const WCHAR two[] = {'t','w','o',0};
1698 static const WCHAR three[] = {'t','h','r','e','e',0};
1699 static const WCHAR four[] = {'f','o','u','r',0};
1701 static const WCHAR fmt1[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
1702 static const WCHAR fmt2[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
1703 static const WCHAR fmt3[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
1704 static const WCHAR fmt4[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
1705 static const WCHAR fmt5[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
1706 static const WCHAR fmt6[] = {0};
1708 static const WCHAR chkfmt1[] = {'%','s','=','%','s',0};
1709 static const WCHAR chkfmt2[] = {'%','s',' ','%','s',0};
1710 static const WCHAR chkfmt3[] = {'\\','\"','%','s','\"',0};
1711 static const WCHAR chkfmt4[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
1713 LPWSTR *args = (LPWSTR*)0xdeadcafe;
1716 wsprintfW(cmdline,fmt1,one,two,three,four);
1717 args=CommandLineToArgvW(cmdline,&numargs);
1718 if (args == NULL && numargs == -1)
1720 win_skip("CommandLineToArgvW not implemented, skipping\n");
1723 ok(numargs == 4, "expected 4 args, got %i\n",numargs);
1724 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1725 ok(lstrcmpW(args[1],two)==0,"arg1 is not as expected\n");
1726 ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n");
1727 ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
1729 wsprintfW(cmdline,fmt2,one,two,three,four);
1730 args=CommandLineToArgvW(cmdline,&numargs);
1731 ok(numargs == 5, "expected 5 args, got %i\n",numargs);
1732 ok(args[0][0]==0,"arg0 is not as expected\n");
1733 ok(lstrcmpW(args[1],one)==0,"arg1 is not as expected\n");
1734 ok(lstrcmpW(args[2],two)==0,"arg2 is not as expected\n");
1735 ok(lstrcmpW(args[3],three)==0,"arg3 is not as expected\n");
1736 ok(lstrcmpW(args[4],four)==0,"arg4 is not as expected\n");
1738 wsprintfW(cmdline,fmt3,one,two,three,four);
1739 args=CommandLineToArgvW(cmdline,&numargs);
1740 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1741 wsprintfW(cmdline,chkfmt1,one,two);
1742 ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1743 wsprintfW(cmdline,chkfmt1,three,four);
1744 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1746 wsprintfW(cmdline,fmt4,one,two,three,four);
1747 args=CommandLineToArgvW(cmdline,&numargs);
1748 ok(numargs == 3, "expected 3 args, got %i\n",numargs);
1749 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1750 wsprintfW(cmdline,chkfmt2,two,three);
1751 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1752 ok(lstrcmpW(args[2],four)==0,"arg2 is not as expected\n");
1754 wsprintfW(cmdline,fmt5,one,two,three,four);
1755 args=CommandLineToArgvW(cmdline,&numargs);
1756 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1757 wsprintfW(cmdline,chkfmt3,one);
1758 todo_wine ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1759 wsprintfW(cmdline,chkfmt4,two,three,four);
1760 todo_wine ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1762 wsprintfW(cmdline,fmt6);
1763 args=CommandLineToArgvW(cmdline,&numargs);
1764 ok(numargs == 1, "expected 1 args, got %i\n",numargs);
1770 myARGC = winetest_get_mainargs(&myARGV);
1773 doChild(myARGC, myARGV);
1780 test_find_executable();
1785 test_dde_default_app();