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
43 #include "wine/test.h"
45 #include "shell32_test.h"
48 static char argv0[MAX_PATH];
51 static char tmpdir[MAX_PATH];
52 static char child_file[MAX_PATH];
53 static DLLVERSIONINFO dllver;
58 * ShellExecute wrappers
61 static void dump_child(void);
64 static void init_event(const char* child_file)
67 event_name=strrchr(child_file, '\\')+1;
68 hEvent=CreateEvent(NULL, FALSE, FALSE, event_name);
71 static void strcat_param(char* str, const char* param)
85 static char shell_call[2048]="";
86 static int shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
90 strcpy(shell_call, "ShellExecute(");
91 strcat_param(shell_call, operation);
92 strcat(shell_call, ", ");
93 strcat_param(shell_call, file);
94 strcat(shell_call, ", ");
95 strcat_param(shell_call, parameters);
96 strcat(shell_call, ", ");
97 strcat_param(shell_call, directory);
98 strcat(shell_call, ")");
99 if (winetest_debug > 1)
100 trace("%s\n", shell_call);
102 DeleteFile(child_file);
103 SetLastError(0xcafebabe);
105 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
106 * association it displays the 'Open With' dialog and I could not find
107 * a flag to prevent this.
109 rc=(int)ShellExecute(NULL, operation, file, parameters, directory,
115 wait_rc=WaitForSingleObject(hEvent, 5000);
116 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
118 /* The child process may have changed the result file, so let profile
119 * functions know about it
121 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
128 static int shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
129 LPCSTR parameters, LPCSTR directory)
131 SHELLEXECUTEINFO sei;
135 strcpy(shell_call, "ShellExecuteEx(");
136 strcat_param(shell_call, operation);
137 strcat(shell_call, ", ");
138 strcat_param(shell_call, file);
139 strcat(shell_call, ", ");
140 strcat_param(shell_call, parameters);
141 strcat(shell_call, ", ");
142 strcat_param(shell_call, directory);
143 strcat(shell_call, ")");
144 if (winetest_debug > 1)
145 trace("%s\n", shell_call);
147 sei.cbSize=sizeof(sei);
148 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
150 sei.lpVerb=operation;
152 sei.lpParameters=parameters;
153 sei.lpDirectory=directory;
154 sei.nShow=SW_SHOWNORMAL;
155 sei.hInstApp=NULL; /* Out */
161 sei.hProcess=NULL; /* Out */
163 DeleteFile(child_file);
164 SetLastError(0xcafebabe);
165 success=ShellExecuteEx(&sei);
166 rc=(int)sei.hInstApp;
167 ok((success && rc > 32) || (!success && rc <= 32),
168 "%s rc=%d and hInstApp=%d is not allowed\n", shell_call, success, rc);
173 if (sei.hProcess!=NULL)
175 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
176 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
178 wait_rc=WaitForSingleObject(hEvent, 5000);
179 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
181 /* The child process may have changed the result file, so let profile
182 * functions know about it
184 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
195 * Functions to create / delete associations wrappers
199 static void create_test_association(const char* extension)
201 HKEY hkey, hkey_shell;
202 char class[MAX_PATH];
205 sprintf(class, "shlexec%s", extension);
206 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
208 assert(rc==ERROR_SUCCESS);
209 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
210 assert(rc==ERROR_SUCCESS);
213 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
214 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
215 assert(rc==ERROR_SUCCESS);
216 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
217 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
218 assert(rc==ERROR_SUCCESS);
220 CloseHandle(hkey_shell);
223 static void delete_test_association(const char* extension)
225 char class[MAX_PATH];
227 sprintf(class, "shlexec%s", extension);
228 SHDeleteKey(HKEY_CLASSES_ROOT, class);
229 SHDeleteKey(HKEY_CLASSES_ROOT, extension);
232 static void create_test_verb(const char* extension, const char* verb,
233 int rawcmd, const char* cmdtail)
235 HKEY hkey_shell, hkey_verb, hkey_cmd;
236 char shell[MAX_PATH];
240 sprintf(shell, "shlexec%s\\shell", extension);
241 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
242 KEY_CREATE_SUB_KEY, &hkey_shell);
243 assert(rc==ERROR_SUCCESS);
244 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
245 NULL, &hkey_verb, NULL);
246 assert(rc==ERROR_SUCCESS);
247 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
248 NULL, &hkey_cmd, NULL);
249 assert(rc==ERROR_SUCCESS);
253 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
257 cmd=malloc(strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
258 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
259 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
260 assert(rc==ERROR_SUCCESS);
264 CloseHandle(hkey_shell);
265 CloseHandle(hkey_verb);
266 CloseHandle(hkey_cmd);
273 * Functions to check that the child process was started just right
274 * (borrowed from dlls/kernel32/tests/process.c)
278 static const char* encodeA(const char* str)
280 static char encoded[2*1024+1];
285 len = strlen(str) + 1;
286 if (len >= sizeof(encoded)/2)
288 fprintf(stderr, "string is too long!\n");
292 for (i = 0; i < len; i++)
293 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
298 static unsigned decode_char(char c)
300 if (c >= '0' && c <= '9') return c - '0';
301 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
302 assert(c >= 'A' && c <= 'F');
306 static char* decodeA(const char* str)
308 static char decoded[1024];
312 len = strlen(str) / 2;
313 if (!len--) return NULL;
314 if (len >= sizeof(decoded))
316 fprintf(stderr, "string is too long!\n");
320 for (i = 0; i < len; i++)
321 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
326 static void childPrintf(HANDLE h, const char* fmt, ...)
332 va_start(valist, fmt);
333 vsprintf(buffer, fmt, valist);
335 WriteFile(h, buffer, strlen(buffer), &w, NULL);
338 static void doChild(int argc, char** argv)
345 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
346 if (hFile == INVALID_HANDLE_VALUE)
350 childPrintf(hFile, "[Arguments]\r\n");
351 if (winetest_debug > 2)
352 trace("argcA=%d\n", argc);
353 childPrintf(hFile, "argcA=%d\r\n", argc);
354 for (i = 0; i < argc; i++)
356 if (winetest_debug > 2)
357 trace("argvA%d=%s\n", i, argv[i]);
358 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
362 init_event(filename);
367 static char* getChildString(const char* sect, const char* key)
372 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
373 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
374 assert(!(strlen(buf) & 1));
379 static void dump_child(void)
381 if (winetest_debug > 1)
387 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
388 trace("argcA=%d\n",c);
391 sprintf(key, "argvA%d", i);
392 str=getChildString("Arguments", key);
393 trace("%s=%s\n", key, str);
398 static int StrCmpPath(const char* s1, const char* s2)
400 if (!s1 && !s2) return 0;
411 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
413 while (*s1=='/' || *s1=='\\')
415 while (*s2=='/' || *s2=='\\')
418 else if (toupper(*s1)==toupper(*s2))
435 static int _okChildString(const char* file, int line, const char* key, const char* expected)
438 result=getChildString("Arguments", key);
439 return ok_(file, line)(lstrcmpiA(result, expected) == 0,
440 "%s expected '%s', got '%s'\n", key, expected, result);
443 static int _okChildPath(const char* file, int line, const char* key, const char* expected)
446 result=getChildString("Arguments", key);
447 return ok_(file, line)(StrCmpPath(result, expected) == 0,
448 "%s expected '%s', got '%s'\n", key, expected, result);
451 static int _okChildInt(const char* file, int line, const char* key, int expected)
454 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
455 return ok_(file, line)(result == expected,
456 "%s expected %d, but got %d\n", key, expected, result);
459 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
460 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
461 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
471 static const char* testfiles[]=
473 "%s\\test file.shlexec",
474 "%s\\%%nasty%% $file.shlexec",
475 "%s\\test file.noassoc",
476 "%s\\test file.noassoc.shlexec",
477 "%s\\test file.shlexec.noassoc",
478 "%s\\test_shortcut_shlexec.lnk",
479 "%s\\test_shortcut_exe.lnk",
481 "%s\\test file.shlfoo",
489 const char* basename;
494 static filename_tests_t filename_tests[]=
496 /* Test bad / nonexistent filenames */
497 {NULL, "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
498 {NULL, "%s\\nonexistent.noassoc", 0x11, SE_ERR_FNF},
501 {NULL, "%s\\test file.shlexec", 0x0, 33},
502 {NULL, "%s\\test file.shlexec.", 0x0, 33},
503 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
504 {NULL, "%s/test file.shlexec", 0x0, 33},
506 /* Test filenames with no association */
507 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
509 /* Test double extensions */
510 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
511 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
513 /* Test alternate verbs */
514 {"LowerL", "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
515 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
517 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
518 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
523 static filename_tests_t noquotes_tests[]=
525 /* Test unquoted '%1' thingies */
526 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
527 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
528 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
533 static void test_filename(void)
535 char filename[MAX_PATH];
536 const filename_tests_t* test;
541 while (test->basename)
543 sprintf(filename, test->basename, tmpdir);
544 if (strchr(filename, '/'))
554 rc=shell_execute(test->verb, filename, NULL, NULL);
557 if ((test->todo & 0x1)==0)
559 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
564 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
570 if ((test->todo & 0x2)==0)
572 okChildInt("argcA", 5);
576 okChildInt("argcA", 5);
578 verb=(test->verb ? test->verb : "Open");
579 if ((test->todo & 0x4)==0)
581 okChildString("argvA3", verb);
585 okChildString("argvA3", verb);
587 if ((test->todo & 0x8)==0)
589 okChildPath("argvA4", filename);
593 okChildPath("argvA4", filename);
600 while (test->basename)
602 sprintf(filename, test->basename, tmpdir);
603 rc=shell_execute(test->verb, filename, NULL, NULL);
606 if ((test->todo & 0x1)==0)
608 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
613 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
622 verb=(test->verb ? test->verb : "Open");
623 if ((test->todo & 0x4)==0)
625 okChildString("argvA3", verb);
629 okChildString("argvA3", verb);
638 space=strchr(str, ' ');
641 sprintf(attrib, "argvA%d", count);
642 if ((test->todo & 0x8)==0)
644 okChildPath(attrib, str);
648 okChildPath(attrib, str);
655 if ((test->todo & 0x2)==0)
657 okChildInt("argcA", count);
661 okChildInt("argcA", count);
667 if (dllver.dwMajorVersion != 0)
669 /* The more recent versions of shell32.dll accept quoted filenames
670 * while older ones (e.g. 4.00) don't. Still we want to test this
671 * because IE 6 depends on the new behavior.
672 * One day we may need to check the exact version of the dll but for
673 * now making sure DllGetVersion() is present is sufficient.
675 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
676 rc=shell_execute(NULL, filename, NULL, NULL);
677 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
679 okChildInt("argcA", 5);
680 okChildString("argvA3", "Open");
681 sprintf(filename, "%s\\test file.shlexec", tmpdir);
682 okChildPath("argvA4", filename);
686 static void test_find_executable(void)
688 char filename[MAX_PATH];
689 char command[MAX_PATH];
690 const filename_tests_t* test;
693 create_test_association(".sfe");
694 create_test_verb(".sfe", "Open", 1, "%1");
696 /* Don't test FindExecutable(..., NULL), it always crashes */
698 strcpy(command, "your word");
699 rc=(int)FindExecutableA(NULL, NULL, command);
700 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %d\n", rc);
701 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
703 strcpy(command, "your word");
704 rc=(int)FindExecutableA(tmpdir, NULL, command);
705 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %d\n", rc);
706 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
708 sprintf(filename, "%s\\test file.sfe", tmpdir);
709 rc=(int)FindExecutableA(filename, NULL, command);
710 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
711 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
713 rc=(int)FindExecutableA("test file.sfe", tmpdir, command);
714 ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
716 rc=(int)FindExecutableA("test file.sfe", NULL, command);
717 todo_wine ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %d\n", filename, rc);
719 delete_test_association(".sfe");
721 create_test_association(".shl");
722 create_test_verb(".shl", "Open", 0, "Open");
724 sprintf(filename, "%s\\test file.shl", tmpdir);
725 rc=(int)FindExecutableA(filename, NULL, command);
726 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
728 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
729 rc=(int)FindExecutableA(filename, NULL, command);
731 delete_test_association(".shl");
735 /* On Windows XP and 2003 FindExecutable() is completely broken.
736 * Probably what it does is convert the filename to 8.3 format,
737 * which as a side effect converts the '.shlfoo' extension to '.shl',
738 * and then tries to find an association for '.shl'. This means it
739 * will normally fail on most extensions with more than 3 characters,
741 * Also it means we cannot do any other test.
743 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
748 while (test->basename)
750 sprintf(filename, test->basename, tmpdir);
751 if (strchr(filename, '/'))
762 /* Win98 does not '\0'-terminate command! */
763 memset(command, '\0', sizeof(command));
764 rc=(int)FindExecutableA(filename, NULL, command);
767 if ((test->todo & 0x10)==0)
769 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
773 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
778 equal=strcmp(command, argv0) == 0 ||
779 /* NT4 returns an extra 0x8 character! */
780 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
781 if ((test->todo & 0x20)==0)
783 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
784 filename, command, argv0);
788 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
789 filename, command, argv0);
797 static filename_tests_t lnk_tests[]=
799 /* Pass bad / nonexistent filenames as a parameter */
800 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
801 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
803 /* Pass regular paths as a parameter */
804 {NULL, "%s\\test file.shlexec", 0xa, 33},
805 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
807 /* Pass filenames with no association as a parameter */
808 {NULL, "%s\\test file.noassoc", 0xa, 33},
813 static void test_lnks(void)
815 char filename[MAX_PATH];
816 char params[MAX_PATH];
817 const filename_tests_t* test;
820 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
821 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
822 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
824 okChildInt("argcA", 5);
825 okChildString("argvA3", "Open");
826 sprintf(filename, "%s\\test file.shlexec", tmpdir);
827 okChildPath("argvA4", filename);
829 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
830 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
831 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
833 okChildInt("argcA", 4);
834 okChildString("argvA3", "Lnk");
836 if (dllver.dwMajorVersion>=6)
839 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
840 * Older versions don't or are quite buggy in this regard.
842 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
850 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
851 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
853 okChildInt("argcA", 4);
854 okChildString("argvA3", "Lnk");
857 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
859 while (test->basename)
862 sprintf(params+1, test->basename, tmpdir);
864 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
868 if ((test->todo & 0x1)==0)
870 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
875 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
880 if ((test->todo & 0x2)==0)
882 okChildInt("argcA", 5);
886 okChildInt("argcA", 5);
888 if ((test->todo & 0x4)==0)
890 okChildString("argvA3", "Lnk");
894 okChildString("argvA3", "Lnk");
896 sprintf(params, test->basename, tmpdir);
897 if ((test->todo & 0x8)==0)
899 okChildPath("argvA4", params);
903 okChildPath("argvA4", params);
911 static void test_exes(void)
913 char filename[MAX_PATH];
917 sprintf(params, "shlexec \"%s\" Exec", child_file);
919 /* We need NOZONECHECKS on Win2003 to block a dialog */
920 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
922 ok(rc > 32, "%s returned %d\n", shell_call, rc);
923 okChildInt("argcA", 4);
924 okChildString("argvA3", "Exec");
926 sprintf(filename, "%s\\test file.noassoc", tmpdir);
927 if (CopyFile(argv0, filename, FALSE))
929 rc=shell_execute(NULL, filename, params, NULL);
931 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
936 static void test_exes_long(void)
938 char filename[MAX_PATH];
940 char longparam[MAX_PATH];
943 for (rc = 0; rc < MAX_PATH; rc++)
944 longparam[rc]='a'+rc%26;
945 longparam[MAX_PATH-1]=0;
948 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
950 /* We need NOZONECHECKS on Win2003 to block a dialog */
951 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
953 ok(rc > 32, "%s returned %d\n", shell_call, rc);
954 okChildInt("argcA", 4);
955 okChildString("argvA3", longparam);
957 sprintf(filename, "%s\\test file.noassoc", tmpdir);
958 if (CopyFile(argv0, filename, FALSE))
960 rc=shell_execute(NULL, filename, params, NULL);
962 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
968 static void init_test(void)
971 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
972 char filename[MAX_PATH];
973 WCHAR lnkfile[MAX_PATH];
975 const char* const * testfile;
980 hdll=GetModuleHandleA("shell32.dll");
981 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
984 dllver.cbSize=sizeof(dllver);
985 pDllGetVersion(&dllver);
986 trace("major=%d minor=%d build=%d platform=%d\n",
987 dllver.dwMajorVersion, dllver.dwMinorVersion,
988 dllver.dwBuildNumber, dllver.dwPlatformID);
992 memset(&dllver, 0, sizeof(dllver));
995 r = CoInitialize(NULL);
996 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
1000 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1001 assert(rc!=0 && rc<sizeof(argv0));
1002 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1004 strcat(argv0, ".so");
1005 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1006 "unable to find argv0!\n");
1009 GetTempPathA(sizeof(tmpdir)/sizeof(*tmpdir), tmpdir);
1010 assert(GetTempFileNameA(tmpdir, "wt", 0, child_file)!=0);
1011 init_event(child_file);
1013 /* Set up the test files */
1019 sprintf(filename, *testfile, tmpdir);
1020 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1021 FILE_ATTRIBUTE_NORMAL, NULL);
1022 if (hfile==INVALID_HANDLE_VALUE)
1024 trace("unable to create '%s': err=%d\n", filename, GetLastError());
1031 /* Setup the test shortcuts */
1032 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1033 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1034 desc.description=NULL;
1036 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1039 desc.arguments="ignored";
1044 create_lnk(lnkfile, &desc, 0);
1046 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1047 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1048 desc.description=NULL;
1052 sprintf(params, "shlexec \"%s\" Lnk", child_file);
1053 desc.arguments=params;
1058 create_lnk(lnkfile, &desc, 0);
1060 /* Create a basic association suitable for most tests */
1061 create_test_association(".shlexec");
1062 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1063 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1064 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1065 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1066 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1067 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1070 static void cleanup_test(void)
1072 char filename[MAX_PATH];
1073 const char* const * testfile;
1075 /* Delete the test files */
1079 sprintf(filename, *testfile, tmpdir);
1080 DeleteFile(filename);
1083 DeleteFile(child_file);
1085 /* Delete the test association */
1086 delete_test_association(".shlexec");
1088 CloseHandle(hEvent);
1096 myARGC = winetest_get_mainargs(&myARGV);
1099 doChild(myARGC, myARGV);
1106 test_find_executable();