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;
59 static BOOL skip_noassoc_tests = FALSE;
60 static HANDLE dde_ready_event;
65 * ShellExecute wrappers
68 static void dump_child(void);
71 static void init_event(const char* child_file)
74 event_name=strrchr(child_file, '\\')+1;
75 hEvent=CreateEvent(NULL, FALSE, FALSE, event_name);
78 static void strcat_param(char* str, const char* param)
92 static char shell_call[2048]="";
93 static int shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
97 strcpy(shell_call, "ShellExecute(");
98 strcat_param(shell_call, operation);
99 strcat(shell_call, ", ");
100 strcat_param(shell_call, file);
101 strcat(shell_call, ", ");
102 strcat_param(shell_call, parameters);
103 strcat(shell_call, ", ");
104 strcat_param(shell_call, directory);
105 strcat(shell_call, ")");
106 if (winetest_debug > 1)
107 trace("%s\n", shell_call);
109 DeleteFile(child_file);
110 SetLastError(0xcafebabe);
112 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
113 * association it displays the 'Open With' dialog and I could not find
114 * a flag to prevent this.
116 rc=(INT_PTR)ShellExecute(NULL, operation, file, parameters, directory, SW_SHOWNORMAL);
121 wait_rc=WaitForSingleObject(hEvent, 5000);
122 if (wait_rc == WAIT_TIMEOUT)
124 HWND wnd = FindWindowA("#32770", "Windows");
127 SendMessage(wnd, WM_CLOSE, 0, 0);
128 win_skip("Skipping shellexecute of file with unassociated extension\n");
129 skip_noassoc_tests = TRUE;
133 ok(wait_rc==WAIT_OBJECT_0 || rc <= 32, "WaitForSingleObject returned %d\n", wait_rc);
135 /* The child process may have changed the result file, so let profile
136 * functions know about it
138 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
145 static int shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
146 LPCSTR parameters, LPCSTR directory)
148 SHELLEXECUTEINFO sei;
152 strcpy(shell_call, "ShellExecuteEx(");
153 strcat_param(shell_call, operation);
154 strcat(shell_call, ", ");
155 strcat_param(shell_call, file);
156 strcat(shell_call, ", ");
157 strcat_param(shell_call, parameters);
158 strcat(shell_call, ", ");
159 strcat_param(shell_call, directory);
160 strcat(shell_call, ")");
161 if (winetest_debug > 1)
162 trace("%s\n", shell_call);
164 sei.cbSize=sizeof(sei);
165 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
167 sei.lpVerb=operation;
169 sei.lpParameters=parameters;
170 sei.lpDirectory=directory;
171 sei.nShow=SW_SHOWNORMAL;
172 sei.hInstApp=NULL; /* Out */
178 sei.hProcess=NULL; /* Out */
180 DeleteFile(child_file);
181 SetLastError(0xcafebabe);
182 success=ShellExecuteEx(&sei);
183 rc=(INT_PTR)sei.hInstApp;
184 ok((success && rc > 32) || (!success && rc <= 32),
185 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call, success, rc);
190 if (sei.hProcess!=NULL)
192 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
193 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
195 wait_rc=WaitForSingleObject(hEvent, 5000);
196 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
198 /* The child process may have changed the result file, so let profile
199 * functions know about it
201 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
212 * Functions to create / delete associations wrappers
216 static BOOL create_test_association(const char* extension)
218 HKEY hkey, hkey_shell;
219 char class[MAX_PATH];
222 sprintf(class, "shlexec%s", extension);
223 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
225 if (rc != ERROR_SUCCESS)
228 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
229 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
232 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
233 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
234 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
236 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
237 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
238 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
241 CloseHandle(hkey_shell);
246 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
247 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
250 DWORD dwMaxSubkeyLen, dwMaxValueLen;
251 DWORD dwMaxLen, dwSize;
252 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
257 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
261 /* Get highest length for keys, values */
262 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
263 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
264 if (ret) goto cleanup;
268 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
269 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
271 /* Name too big: alloc a buffer for it */
272 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
274 ret = ERROR_NOT_ENOUGH_MEMORY;
280 /* Recursively delete all the subkeys */
284 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
285 NULL, NULL, NULL)) break;
287 ret = myRegDeleteTreeA(hSubKey, lpszName);
288 if (ret) goto cleanup;
292 ret = RegDeleteKeyA(hKey, lpszSubKey);
297 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
298 NULL, NULL, NULL, NULL)) break;
300 ret = RegDeleteValueA(hKey, lpszName);
301 if (ret) goto cleanup;
305 /* Free buffer if allocated */
306 if (lpszName != szNameBuf)
307 HeapFree( GetProcessHeap(), 0, lpszName);
309 RegCloseKey(hSubKey);
313 static void delete_test_association(const char* extension)
315 char class[MAX_PATH];
317 sprintf(class, "shlexec%s", extension);
318 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
319 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
322 static void create_test_verb_dde(const char* extension, const char* verb,
323 int rawcmd, const char* cmdtail, const char *ddeexec,
324 const char *application, const char *topic,
327 HKEY hkey_shell, hkey_verb, hkey_cmd;
328 char shell[MAX_PATH];
332 sprintf(shell, "shlexec%s\\shell", extension);
333 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
334 KEY_CREATE_SUB_KEY, &hkey_shell);
335 assert(rc==ERROR_SUCCESS);
336 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
337 NULL, &hkey_verb, NULL);
338 assert(rc==ERROR_SUCCESS);
339 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
340 NULL, &hkey_cmd, NULL);
341 assert(rc==ERROR_SUCCESS);
345 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
349 cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
350 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
351 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
352 assert(rc==ERROR_SUCCESS);
353 HeapFree(GetProcessHeap(), 0, cmd);
358 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
360 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
361 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
362 assert(rc==ERROR_SUCCESS);
363 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
365 assert(rc==ERROR_SUCCESS);
368 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
369 NULL, &hkey_application, NULL);
370 assert(rc==ERROR_SUCCESS);
371 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
372 strlen(application)+1);
373 assert(rc==ERROR_SUCCESS);
374 CloseHandle(hkey_application);
378 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
379 NULL, &hkey_topic, NULL);
380 assert(rc==ERROR_SUCCESS);
381 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
383 assert(rc==ERROR_SUCCESS);
384 CloseHandle(hkey_topic);
388 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
389 NULL, &hkey_ifexec, NULL);
390 assert(rc==ERROR_SUCCESS);
391 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
393 assert(rc==ERROR_SUCCESS);
394 CloseHandle(hkey_ifexec);
396 CloseHandle(hkey_ddeexec);
399 CloseHandle(hkey_shell);
400 CloseHandle(hkey_verb);
401 CloseHandle(hkey_cmd);
404 static void create_test_verb(const char* extension, const char* verb,
405 int rawcmd, const char* cmdtail)
407 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
413 * Functions to check that the child process was started just right
414 * (borrowed from dlls/kernel32/tests/process.c)
418 static const char* encodeA(const char* str)
420 static char encoded[2*1024+1];
425 len = strlen(str) + 1;
426 if (len >= sizeof(encoded)/2)
428 fprintf(stderr, "string is too long!\n");
432 for (i = 0; i < len; i++)
433 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
438 static unsigned decode_char(char c)
440 if (c >= '0' && c <= '9') return c - '0';
441 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
442 assert(c >= 'A' && c <= 'F');
446 static char* decodeA(const char* str)
448 static char decoded[1024];
452 len = strlen(str) / 2;
453 if (!len--) return NULL;
454 if (len >= sizeof(decoded))
456 fprintf(stderr, "string is too long!\n");
460 for (i = 0; i < len; i++)
461 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
466 static void childPrintf(HANDLE h, const char* fmt, ...)
472 va_start(valist, fmt);
473 vsprintf(buffer, fmt, valist);
475 WriteFile(h, buffer, strlen(buffer), &w, NULL);
478 static DWORD ddeInst;
480 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
481 static BOOL post_quit_on_execute;
483 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
484 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
485 ULONG_PTR dwData1, ULONG_PTR dwData2)
489 if (winetest_debug > 2)
490 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
491 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
496 if (!DdeCmpStringHandles(hsz1, hszTopic))
498 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
499 assert(size < MAX_PATH);
500 return (HDDEDATA)TRUE;
502 return (HDDEDATA)FALSE;
505 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
506 assert(size < MAX_PATH);
507 DdeFreeDataHandle(hData);
508 if (post_quit_on_execute)
510 return (HDDEDATA)DDE_FACK;
518 * This is just to make sure the child won't run forever stuck in a GetMessage()
519 * loop when DDE fails for some reason.
521 static void CALLBACK childTimeout(HWND wnd, UINT msg, UINT_PTR timer, DWORD time)
523 trace("childTimeout called\n");
528 static void doChild(int argc, char** argv)
541 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
542 if (hFile == INVALID_HANDLE_VALUE)
546 childPrintf(hFile, "[Arguments]\r\n");
547 if (winetest_debug > 2)
548 trace("argcA=%d\n", argc);
549 childPrintf(hFile, "argcA=%d\r\n", argc);
550 for (i = 0; i < argc; i++)
552 if (winetest_debug > 2)
553 trace("argvA%d=%s\n", i, argv[i]);
554 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
557 map = OpenFileMappingA(FILE_MAP_READ, FALSE, "winetest_shlexec_dde_map");
560 shared_block = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 4096);
562 if (shared_block[0] != '\0' || shared_block[1] != '\0')
564 post_quit_on_execute = TRUE;
566 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
567 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
568 assert(rc == DMLERR_NO_ERROR);
569 hszApplication = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
570 hszTopic = DdeCreateStringHandleA(ddeInst, shared_block + strlen(shared_block) + 1, CP_WINANSI);
571 assert(hszApplication && hszTopic);
572 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
574 timer = SetTimer(NULL, 0, 2500, childTimeout);
576 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
578 CloseHandle(dde_ready);
580 while (GetMessage(&msg, NULL, 0, 0))
581 DispatchMessage(&msg);
584 KillTimer(NULL, timer);
585 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
586 assert(DdeFreeStringHandle(ddeInst, hszTopic));
587 assert(DdeFreeStringHandle(ddeInst, hszApplication));
588 assert(DdeUninitialize(ddeInst));
592 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
594 CloseHandle(dde_ready);
597 UnmapViewOfFile(shared_block);
599 childPrintf(hFile, "ddeExec=%s\r\n", encodeA(ddeExec));
604 init_event(filename);
609 static char* getChildString(const char* sect, const char* key)
614 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
615 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
616 assert(!(strlen(buf) & 1));
621 static void dump_child(void)
623 if (winetest_debug > 1)
629 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
630 trace("argcA=%d\n",c);
633 sprintf(key, "argvA%d", i);
634 str=getChildString("Arguments", key);
635 trace("%s=%s\n", key, str);
640 static int StrCmpPath(const char* s1, const char* s2)
642 if (!s1 && !s2) return 0;
653 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
655 while (*s1=='/' || *s1=='\\')
657 while (*s2=='/' || *s2=='\\')
660 else if (toupper(*s1)==toupper(*s2))
677 static void _okChildString(const char* file, int line, const char* key, const char* expected)
680 result=getChildString("Arguments", key);
681 ok_(file, line)(lstrcmpiA(result, expected) == 0,
682 "%s expected '%s', got '%s'\n", key, expected, result);
685 static void _okChildPath(const char* file, int line, const char* key, const char* expected)
688 result=getChildString("Arguments", key);
689 ok_(file, line)(StrCmpPath(result, expected) == 0,
690 "%s expected '%s', got '%s'\n", key, expected, result);
693 static void _okChildInt(const char* file, int line, const char* key, int expected)
696 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
697 ok_(file, line)(result == expected,
698 "%s expected %d, but got %d\n", key, expected, result);
701 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
702 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
703 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
707 * GetLongPathNameA equivalent that supports Win95 and WinNT
711 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
713 char tmplongpath[MAX_PATH];
715 DWORD sp = 0, lp = 0;
717 WIN32_FIND_DATAA wfd;
720 if (!shortpath || !shortpath[0])
723 if (shortpath[1] == ':')
725 tmplongpath[0] = shortpath[0];
726 tmplongpath[1] = ':';
730 while (shortpath[sp])
732 /* check for path delimiters and reproduce them */
733 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
735 if (!lp || tmplongpath[lp-1] != '\\')
737 /* strip double "\\" */
738 tmplongpath[lp++] = '\\';
740 tmplongpath[lp] = 0; /* terminate string */
746 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
748 tmplongpath[lp++] = *p++;
749 tmplongpath[lp++] = *p++;
751 for (; *p && *p != '/' && *p != '\\'; p++);
752 tmplen = p - (shortpath + sp);
753 lstrcpyn(tmplongpath + lp, shortpath + sp, tmplen + 1);
754 /* Check if the file exists and use the existing file name */
755 goit = FindFirstFileA(tmplongpath, &wfd);
756 if (goit == INVALID_HANDLE_VALUE)
759 strcpy(tmplongpath + lp, wfd.cFileName);
760 lp += strlen(tmplongpath + lp);
763 tmplen = strlen(shortpath) - 1;
764 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
765 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
766 tmplongpath[lp++] = shortpath[tmplen];
769 tmplen = strlen(tmplongpath) + 1;
770 if (tmplen <= longlen)
772 strcpy(longpath, tmplongpath);
773 tmplen--; /* length without 0 */
785 static const char* testfiles[]=
787 "%s\\test file.shlexec",
788 "%s\\%%nasty%% $file.shlexec",
789 "%s\\test file.noassoc",
790 "%s\\test file.noassoc.shlexec",
791 "%s\\test file.shlexec.noassoc",
792 "%s\\test_shortcut_shlexec.lnk",
793 "%s\\test_shortcut_exe.lnk",
795 "%s\\test file.shlfoo",
797 "%s\\masked file.shlexec",
802 "%s\\simple.shlexec",
803 "%s\\drawback_file.noassoc",
804 "%s\\drawback_file.noassoc foo.shlexec",
805 "%s\\drawback_nonexist.noassoc foo.shlexec",
812 const char* basename;
817 static filename_tests_t filename_tests[]=
819 /* Test bad / nonexistent filenames */
820 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
821 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
824 {NULL, "%s\\test file.shlexec", 0x0, 33},
825 {NULL, "%s\\test file.shlexec.", 0x0, 33},
826 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
827 {NULL, "%s/test file.shlexec", 0x0, 33},
829 /* Test filenames with no association */
830 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
832 /* Test double extensions */
833 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
834 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
836 /* Test alternate verbs */
837 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
838 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
840 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
841 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
843 /* Test file masked due to space */
844 {NULL, "%s\\masked file.shlexec", 0x1, 33},
845 /* Test if quoting prevents the masking */
846 {NULL, "%s\\masked file.shlexec", 0x40, 33},
851 static filename_tests_t noquotes_tests[]=
853 /* Test unquoted '%1' thingies */
854 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
855 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
856 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
861 static void test_lpFile_parsed(void)
863 /* basename tmpdir */
864 const char* shorttmpdir;
866 const char *testfile;
867 char fileA[MAX_PATH];
871 GetTempPathA(sizeof(fileA), fileA);
872 shorttmpdir = tmpdir + strlen(fileA);
874 /* ensure tmpdir is in %TEMP%: GetTempPath() can succeed even if TEMP is undefined */
875 SetEnvironmentVariableA("TEMP", fileA);
877 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
878 testfile = "%s\\drawback_file.noassoc foo.shlexec";
879 sprintf(fileA, testfile, tmpdir);
880 rc=shell_execute(NULL, fileA, NULL, NULL);
883 "expected success (33), got %s (%d), lpFile: %s\n",
884 rc > 32 ? "success" : "failure", rc, fileA
888 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
889 testfile = "\"%s\\drawback_file.noassoc foo.shlexec\"";
890 sprintf(fileA, testfile, tmpdir);
891 rc=shell_execute(NULL, fileA, NULL, NULL);
892 ok(rc>32 || broken(rc == 2) /* Win95/NT4 */,
893 "expected success (33), got %s (%d), lpFile: %s\n",
894 rc > 32 ? "success" : "failure", rc, fileA
897 /* error should be 2, not 31 */
898 testfile = "\"%s\\drawback_file.noassoc\" foo.shlexec";
899 sprintf(fileA, testfile, tmpdir);
900 rc=shell_execute(NULL, fileA, NULL, NULL);
902 "expected failure (2), got %s (%d), lpFile: %s\n",
903 rc > 32 ? "success" : "failure", rc, fileA
906 /* ""command"" not works on wine (and real win9x and w2k) */
907 testfile = "\"\"%s\\simple.shlexec\"\"";
908 sprintf(fileA, testfile, tmpdir);
909 rc=shell_execute(NULL, fileA, NULL, NULL);
911 ok(rc>32 || broken(rc == 2) /* Win9x/2000 */,
912 "expected success (33), got %s (%d), lpFile: %s\n",
913 rc > 32 ? "success" : "failure", rc, fileA
917 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
918 testfile = "%s\\drawback_nonexist.noassoc foo.shlexec";
919 sprintf(fileA, testfile, tmpdir);
920 rc=shell_execute(NULL, fileA, NULL, NULL);
922 "expected success (33), got %s (%d), lpFile: %s\n",
923 rc > 32 ? "success" : "failure", rc, fileA
926 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
927 testfile = "%%TEMP%%\\%s\\simple.shlexec";
928 sprintf(fileA, testfile, shorttmpdir);
929 rc=shell_execute(NULL, fileA, NULL, NULL);
932 "expected failure (2), got %s (%d), lpFile: %s\n",
933 rc > 32 ? "success" : "failure", rc, fileA
938 testfile = "\"%%TEMP%%\\%s\\simple.shlexec\"";
939 sprintf(fileA, testfile, shorttmpdir);
940 rc=shell_execute(NULL, fileA, NULL, NULL);
943 "expected failure (2), got %s (%d), lpFile: %s\n",
944 rc > 32 ? "success" : "failure", rc, fileA
948 /* test SEE_MASK_DOENVSUBST works */
949 testfile = "%%TEMP%%\\%s\\simple.shlexec";
950 sprintf(fileA, testfile, shorttmpdir);
951 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI, NULL, fileA, NULL, NULL);
953 "expected success (33), got %s (%d), lpFile: %s\n",
954 rc > 32 ? "success" : "failure", rc, fileA
957 /* quoted lpFile not works only on real win95 and nt4 */
958 testfile = "\"%%TEMP%%\\%s\\simple.shlexec\"";
959 sprintf(fileA, testfile, shorttmpdir);
960 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI, NULL, fileA, NULL, NULL);
961 ok(rc>32 || broken(rc == 2) /* Win95/NT4 */,
962 "expected success (33), got %s (%d), lpFile: %s\n",
963 rc > 32 ? "success" : "failure", rc, fileA
968 static void test_argify(void)
970 char fileA[MAX_PATH];
974 sprintf(fileA, "%s\\test file.shlexec", tmpdir);
977 rc=shell_execute("NoQuotesParam2", fileA, "a b", NULL);
979 "expected success (33), got %s (%d), lpFile: %s\n",
980 rc > 32 ? "success" : "failure", rc, fileA
984 okChildInt("argcA", 5);
985 okChildString("argvA4", "a");
989 /* '"a"""' -> 'a"' */
990 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\"\"some string\"\"\"", NULL);
992 "expected success (33), got %s (%d), lpFile: %s\n",
993 rc > 32 ? "success" : "failure", rc, fileA
997 okChildInt("argcA", 5);
999 okChildString("argvA4", "a:some string");
1004 /* backslash isn't escape char
1005 * '"a\""' -> '"a\""' */
1006 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\\\"some string\\\"\"", NULL);
1008 "expected success (33), got %s (%d), lpFile: %s\n",
1009 rc > 32 ? "success" : "failure", rc, fileA
1013 okChildInt("argcA", 5);
1015 okChildString("argvA4", "a:\\");
1020 /* \t isn't whitespace */
1021 rc=shell_execute("QuotedParam2", fileA, "a\tb c", NULL);
1023 "expected success (33), got %s (%d), lpFile: %s\n",
1024 rc > 32 ? "success" : "failure", rc, fileA
1028 okChildInt("argcA", 5);
1030 okChildString("argvA4", "a\tb");
1035 rc=shell_execute("NoQuotesAllParams", fileA, "a b c d e f g h", NULL);
1037 "expected success (33), got %s (%d), lpFile: %s\n",
1038 rc > 32 ? "success" : "failure", rc, fileA
1043 okChildInt("argcA", 12);
1044 okChildString("argvA4", "a");
1045 okChildString("argvA11", "h");
1049 /* %* can sometimes contain only whitespaces and no args */
1050 rc=shell_execute("QuotedAllParams", fileA, " ", NULL);
1052 "expected success (33), got %s (%d), lpFile: %s\n",
1053 rc > 32 ? "success" : "failure", rc, fileA
1058 okChildInt("argcA", 5);
1059 okChildString("argvA4", " ");
1064 rc=shell_execute("NoQuotesParams345etc", fileA, "a b c d e f g h", NULL);
1066 "expected success (33), got %s (%d), lpFile: %s\n",
1067 rc > 32 ? "success" : "failure", rc, fileA
1072 okChildInt("argcA", 11);
1073 okChildString("argvA4", "b");
1074 okChildString("argvA10", "h");
1078 /* %~3 is rest of command line starting with whitespaces after 2nd arg */
1079 rc=shell_execute("QuotedParams345etc", fileA, "a ", NULL);
1081 "expected success (33), got %s (%d), lpFile: %s\n",
1082 rc > 32 ? "success" : "failure", rc, fileA
1086 okChildInt("argcA", 5);
1088 okChildString("argvA4", " ");
1094 static void test_filename(void)
1096 char filename[MAX_PATH];
1097 const filename_tests_t* test;
1101 test=filename_tests;
1102 while (test->basename)
1104 BOOL quotedfile = FALSE;
1106 if (skip_noassoc_tests && test->rc == SE_ERR_NOASSOC)
1108 win_skip("Skipping shellexecute of file with unassociated extension\n");
1113 sprintf(filename, test->basename, tmpdir);
1114 if (strchr(filename, '/'))
1124 if ((test->todo & 0x40)==0)
1126 rc=shell_execute(test->verb, filename, NULL, NULL);
1130 char quoted[MAX_PATH + 2];
1133 sprintf(quoted, "\"%s\"", filename);
1134 rc=shell_execute(test->verb, quoted, NULL, NULL);
1138 if ((test->todo & 0x1)==0)
1141 broken(quotedfile && rc == 2), /* NT4 */
1142 "%s failed: rc=%d err=%d\n", shell_call,
1143 rc, GetLastError());
1147 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1148 rc, GetLastError());
1153 if ((test->todo & 0x2)==0)
1155 okChildInt("argcA", 5);
1159 okChildInt("argcA", 5);
1161 verb=(test->verb ? test->verb : "Open");
1162 if ((test->todo & 0x4)==0)
1164 okChildString("argvA3", verb);
1168 okChildString("argvA3", verb);
1170 if ((test->todo & 0x8)==0)
1172 okChildPath("argvA4", filename);
1176 okChildPath("argvA4", filename);
1182 test=noquotes_tests;
1183 while (test->basename)
1185 sprintf(filename, test->basename, tmpdir);
1186 rc=shell_execute(test->verb, filename, NULL, NULL);
1189 if ((test->todo & 0x1)==0)
1191 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1192 rc, GetLastError());
1196 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1197 rc, GetLastError());
1205 verb=(test->verb ? test->verb : "Open");
1206 if ((test->todo & 0x4)==0)
1208 okChildString("argvA3", verb);
1212 okChildString("argvA3", verb);
1221 space=strchr(str, ' ');
1224 sprintf(attrib, "argvA%d", count);
1225 if ((test->todo & 0x8)==0)
1227 okChildPath(attrib, str);
1231 okChildPath(attrib, str);
1238 if ((test->todo & 0x2)==0)
1240 okChildInt("argcA", count);
1244 okChildInt("argcA", count);
1250 if (dllver.dwMajorVersion != 0)
1252 /* The more recent versions of shell32.dll accept quoted filenames
1253 * while older ones (e.g. 4.00) don't. Still we want to test this
1254 * because IE 6 depends on the new behavior.
1255 * One day we may need to check the exact version of the dll but for
1256 * now making sure DllGetVersion() is present is sufficient.
1258 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
1259 rc=shell_execute(NULL, filename, NULL, NULL);
1260 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1262 okChildInt("argcA", 5);
1263 okChildString("argvA3", "Open");
1264 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1265 okChildPath("argvA4", filename);
1269 static void test_find_executable(void)
1271 char filename[MAX_PATH];
1272 char command[MAX_PATH];
1273 const filename_tests_t* test;
1276 if (!create_test_association(".sfe"))
1278 skip("Unable to create association for '.sfe'\n");
1281 create_test_verb(".sfe", "Open", 1, "%1");
1283 /* Don't test FindExecutable(..., NULL), it always crashes */
1285 strcpy(command, "your word");
1286 if (0) /* Can crash on Vista! */
1288 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
1289 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1290 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1293 strcpy(command, "your word");
1294 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
1295 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1296 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1298 sprintf(filename, "%s\\test file.sfe", tmpdir);
1299 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1300 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1301 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1303 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
1304 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1306 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
1307 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %ld\n", filename, rc);
1309 delete_test_association(".sfe");
1311 if (!create_test_association(".shl"))
1313 skip("Unable to create association for '.shl'\n");
1316 create_test_verb(".shl", "Open", 0, "Open");
1318 sprintf(filename, "%s\\test file.shl", tmpdir);
1319 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1320 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1322 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
1323 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1325 delete_test_association(".shl");
1329 /* On Windows XP and 2003 FindExecutable() is completely broken.
1330 * Probably what it does is convert the filename to 8.3 format,
1331 * which as a side effect converts the '.shlfoo' extension to '.shl',
1332 * and then tries to find an association for '.shl'. This means it
1333 * will normally fail on most extensions with more than 3 characters,
1334 * like '.mpeg', etc.
1335 * Also it means we cannot do any other test.
1337 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
1341 test=filename_tests;
1342 while (test->basename)
1344 sprintf(filename, test->basename, tmpdir);
1345 if (strchr(filename, '/'))
1356 /* Win98 does not '\0'-terminate command! */
1357 memset(command, '\0', sizeof(command));
1358 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1361 if ((test->todo & 0x10)==0)
1363 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1367 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1372 equal=strcmp(command, argv0) == 0 ||
1373 /* NT4 returns an extra 0x8 character! */
1374 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
1375 if ((test->todo & 0x20)==0)
1377 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1378 filename, command, argv0);
1382 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1383 filename, command, argv0);
1391 static filename_tests_t lnk_tests[]=
1393 /* Pass bad / nonexistent filenames as a parameter */
1394 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
1395 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
1397 /* Pass regular paths as a parameter */
1398 {NULL, "%s\\test file.shlexec", 0xa, 33},
1399 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1401 /* Pass filenames with no association as a parameter */
1402 {NULL, "%s\\test file.noassoc", 0xa, 33},
1407 static void test_lnks(void)
1409 char filename[MAX_PATH];
1410 char params[MAX_PATH];
1411 const filename_tests_t* test;
1414 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1415 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1416 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1418 okChildInt("argcA", 5);
1419 okChildString("argvA3", "Open");
1420 sprintf(params, "%s\\test file.shlexec", tmpdir);
1421 get_long_path_name(params, filename, sizeof(filename));
1422 okChildPath("argvA4", filename);
1424 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1425 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1426 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1428 okChildInt("argcA", 4);
1429 okChildString("argvA3", "Lnk");
1431 if (dllver.dwMajorVersion>=6)
1434 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1435 * Older versions don't or are quite buggy in this regard.
1437 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1445 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1446 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1448 okChildInt("argcA", 4);
1449 okChildString("argvA3", "Lnk");
1452 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1454 while (test->basename)
1457 sprintf(params+1, test->basename, tmpdir);
1458 strcat(params,"\"");
1459 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1463 if ((test->todo & 0x1)==0)
1465 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1466 rc, GetLastError());
1470 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1471 rc, GetLastError());
1475 if ((test->todo & 0x2)==0)
1477 okChildInt("argcA", 5);
1481 okChildInt("argcA", 5);
1483 if ((test->todo & 0x4)==0)
1485 okChildString("argvA3", "Lnk");
1489 okChildString("argvA3", "Lnk");
1491 sprintf(params, test->basename, tmpdir);
1492 if ((test->todo & 0x8)==0)
1494 okChildPath("argvA4", params);
1498 okChildPath("argvA4", params);
1506 static void test_exes(void)
1508 char filename[MAX_PATH];
1512 sprintf(params, "shlexec \"%s\" Exec", child_file);
1514 /* We need NOZONECHECKS on Win2003 to block a dialog */
1515 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1517 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1518 okChildInt("argcA", 4);
1519 okChildString("argvA3", "Exec");
1521 if (! skip_noassoc_tests)
1523 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1524 if (CopyFile(argv0, filename, FALSE))
1526 rc=shell_execute(NULL, filename, params, NULL);
1528 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1534 win_skip("Skipping shellexecute of file with unassociated extension\n");
1538 static void test_exes_long(void)
1540 char filename[MAX_PATH];
1542 char longparam[MAX_PATH];
1545 for (rc = 0; rc < MAX_PATH; rc++)
1546 longparam[rc]='a'+rc%26;
1547 longparam[MAX_PATH-1]=0;
1550 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1552 /* We need NOZONECHECKS on Win2003 to block a dialog */
1553 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1555 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1556 okChildInt("argcA", 4);
1557 okChildString("argvA3", longparam);
1559 if (! skip_noassoc_tests)
1561 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1562 if (CopyFile(argv0, filename, FALSE))
1564 rc=shell_execute(NULL, filename, params, NULL);
1566 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1572 win_skip("Skipping shellexecute of file with unassociated extension\n");
1578 const char* command;
1579 const char* ddeexec;
1580 const char* application;
1584 const char* expectedDdeExec;
1588 static dde_tests_t dde_tests[] =
1590 /* Test passing and not passing command-line
1591 * argument, no DDE */
1592 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0},
1593 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0},
1595 /* Test passing and not passing command-line
1596 * argument, with DDE */
1597 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1598 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0},
1600 /* Test unquoted %1 in command and ddeexec
1601 * (test filename has space) */
1602 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0},
1604 /* Test ifexec precedence over ddeexec */
1605 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0},
1607 /* Test default DDE topic */
1608 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0},
1610 /* Test default DDE application */
1611 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1613 {NULL, NULL, NULL, NULL, NULL, 0, 0x0}
1616 static DWORD WINAPI hooked_WaitForInputIdle(HANDLE process, DWORD timeout)
1618 return WaitForSingleObject(dde_ready_event, timeout);
1622 * WaitForInputIdle() will normally return immediately for console apps. That's
1623 * a problem for us because ShellExecute will assume that an app is ready to
1624 * receive DDE messages after it has called WaitForInputIdle() on that app.
1625 * To work around that we install our own version of WaitForInputIdle() that
1626 * will wait for the child to explicitly tell us that it is ready. We do that
1627 * by changing the entry for WaitForInputIdle() in the shell32 import address
1630 static void hook_WaitForInputIdle(void *new_func)
1633 PIMAGE_NT_HEADERS nt_headers;
1634 DWORD import_directory_rva;
1635 PIMAGE_IMPORT_DESCRIPTOR import_descriptor;
1637 base = (char *) GetModuleHandleA("shell32.dll");
1638 nt_headers = (PIMAGE_NT_HEADERS)(base + ((PIMAGE_DOS_HEADER) base)->e_lfanew);
1639 import_directory_rva = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
1641 /* Search for the correct imported module by walking the import descriptors */
1642 import_descriptor = (PIMAGE_IMPORT_DESCRIPTOR)(base + import_directory_rva);
1643 while (U(*import_descriptor).OriginalFirstThunk != 0)
1645 char *import_module_name;
1647 import_module_name = base + import_descriptor->Name;
1648 if (lstrcmpiA(import_module_name, "user32.dll") == 0 ||
1649 lstrcmpiA(import_module_name, "user32") == 0)
1651 PIMAGE_THUNK_DATA int_entry;
1652 PIMAGE_THUNK_DATA iat_entry;
1654 /* The import name table and import address table are two parallel
1655 * arrays. We need the import name table to find the imported
1656 * routine and the import address table to patch the address, so
1657 * walk them side by side */
1658 int_entry = (PIMAGE_THUNK_DATA)(base + U(*import_descriptor).OriginalFirstThunk);
1659 iat_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->FirstThunk);
1660 while (int_entry->u1.Ordinal != 0)
1662 if (! IMAGE_SNAP_BY_ORDINAL(int_entry->u1.Ordinal))
1664 PIMAGE_IMPORT_BY_NAME import_by_name;
1665 import_by_name = (PIMAGE_IMPORT_BY_NAME)(base + int_entry->u1.AddressOfData);
1666 if (lstrcmpA((char *) import_by_name->Name, "WaitForInputIdle") == 0)
1668 /* Found the correct routine in the correct imported module. Patch it. */
1670 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), PAGE_READWRITE, &old_prot);
1671 iat_entry->u1.Function = (ULONG_PTR) new_func;
1672 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), old_prot, &old_prot);
1682 import_descriptor++;
1686 static void test_dde(void)
1688 char filename[MAX_PATH], defApplication[MAX_PATH];
1689 const dde_tests_t* test;
1695 hook_WaitForInputIdle((void *) hooked_WaitForInputIdle);
1697 sprintf(filename, "%s\\test file.sde", tmpdir);
1699 /* Default service is application name minus path and extension */
1700 strcpy(defApplication, strrchr(argv0, '\\')+1);
1701 *strchr(defApplication, '.') = 0;
1703 map = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
1704 4096, "winetest_shlexec_dde_map");
1705 shared_block = MapViewOfFile(map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 4096);
1708 while (test->command)
1710 if (!create_test_association(".sde"))
1712 skip("Unable to create association for '.sde'\n");
1715 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1716 test->application, test->topic, test->ifexec);
1718 if (test->application != NULL || test->topic != NULL)
1720 strcpy(shared_block, test->application ? test->application : defApplication);
1721 strcpy(shared_block + strlen(shared_block) + 1, test->topic ? test->topic : SZDDESYS_TOPIC);
1725 shared_block[0] = '\0';
1726 shared_block[1] = '\0';
1730 dde_ready_event = CreateEventA(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
1731 rc = shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, filename, NULL, NULL);
1732 CloseHandle(dde_ready_event);
1733 if ((test->todo & 0x1)==0)
1735 ok(32 < rc, "%s failed: rc=%d err=%d\n", shell_call,
1736 rc, GetLastError());
1740 ok(32 < rc, "%s failed: rc=%d err=%d\n", shell_call,
1741 rc, GetLastError());
1745 if ((test->todo & 0x2)==0)
1747 okChildInt("argcA", test->expectedArgs + 3);
1751 okChildInt("argcA", test->expectedArgs + 3);
1753 if (test->expectedArgs == 1)
1755 if ((test->todo & 0x4) == 0)
1757 okChildPath("argvA3", filename);
1761 okChildPath("argvA3", filename);
1764 if ((test->todo & 0x8) == 0)
1766 sprintf(params, test->expectedDdeExec, filename);
1767 okChildPath("ddeExec", params);
1771 sprintf(params, test->expectedDdeExec, filename);
1772 okChildPath("ddeExec", params);
1776 delete_test_association(".sde");
1780 UnmapViewOfFile(shared_block);
1782 hook_WaitForInputIdle((void *) WaitForInputIdle);
1785 #define DDE_DEFAULT_APP_VARIANTS 2
1788 const char* command;
1789 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1791 int rc[DDE_DEFAULT_APP_VARIANTS];
1792 } dde_default_app_tests_t;
1794 static dde_default_app_tests_t dde_default_app_tests[] =
1796 /* Windows XP and 98 handle default DDE app names in different ways.
1797 * The application name we see in the first test determines the pattern
1798 * of application names and return codes we will look for. */
1800 /* Test unquoted existing filename with a space */
1801 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1802 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1804 /* Test quoted existing filename with a space */
1805 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1806 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1808 /* Test unquoted filename with a space that doesn't exist, but
1810 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1811 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1813 /* Test quoted filename with a space that does not exist */
1814 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1815 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1817 /* Test filename supplied without the extension */
1818 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1819 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1821 /* Test an unquoted nonexistent filename */
1822 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1823 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1825 /* Test an application that will be found on the path */
1826 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1827 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1829 /* Test an application that will not be found on the path */
1830 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1831 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1833 {NULL, {NULL}, 0, {0}}
1839 DWORD threadIdParent;
1840 } dde_thread_info_t;
1842 static DWORD CALLBACK ddeThread(LPVOID arg)
1844 dde_thread_info_t *info = arg;
1845 assert(info && info->filename);
1846 PostThreadMessage(info->threadIdParent,
1848 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
1853 static void test_dde_default_app(void)
1855 char filename[MAX_PATH];
1857 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1858 const dde_default_app_tests_t* test;
1864 post_quit_on_execute = FALSE;
1866 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1867 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1868 assert(rc == DMLERR_NO_ERROR);
1870 sprintf(filename, "%s\\test file.sde", tmpdir);
1872 /* It is strictly not necessary to register an application name here, but wine's
1873 * DdeNameService implementation complains if 0L is passed instead of
1874 * hszApplication with DNS_FILTEROFF */
1875 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1876 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1877 assert(hszApplication && hszTopic);
1878 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
1880 test = dde_default_app_tests;
1881 while (test->command)
1883 if (!create_test_association(".sde"))
1885 skip("Unable to create association for '.sde'\n");
1888 sprintf(params, test->command, tmpdir);
1889 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
1891 ddeApplication[0] = 0;
1893 /* No application will be run as we will respond to the first DDE event,
1894 * so don't wait for it */
1897 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
1898 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1899 rc = msg.wParam > 32 ? 33 : msg.wParam;
1901 /* First test, find which set of test data we expect to see */
1902 if (test == dde_default_app_tests)
1905 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
1907 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
1913 if (i == DDE_DEFAULT_APP_VARIANTS)
1914 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1917 if ((test->todo & 0x1)==0)
1919 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1920 rc, GetLastError());
1924 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1925 rc, GetLastError());
1929 if ((test->todo & 0x2)==0)
1931 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1932 "Expected application '%s', got '%s'\n",
1933 test->expectedDdeApplication[which], ddeApplication);
1937 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1938 "Expected application '%s', got '%s'\n",
1939 test->expectedDdeApplication[which], ddeApplication);
1943 delete_test_association(".sde");
1947 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1948 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1949 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1950 assert(DdeUninitialize(ddeInst));
1953 static void init_test(void)
1956 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
1957 char filename[MAX_PATH];
1958 WCHAR lnkfile[MAX_PATH];
1960 const char* const * testfile;
1965 hdll=GetModuleHandleA("shell32.dll");
1966 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
1969 dllver.cbSize=sizeof(dllver);
1970 pDllGetVersion(&dllver);
1971 trace("major=%d minor=%d build=%d platform=%d\n",
1972 dllver.dwMajorVersion, dllver.dwMinorVersion,
1973 dllver.dwBuildNumber, dllver.dwPlatformID);
1977 memset(&dllver, 0, sizeof(dllver));
1980 r = CoInitialize(NULL);
1981 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
1985 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1986 assert(rc!=0 && rc<sizeof(argv0));
1987 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1989 strcat(argv0, ".so");
1990 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1991 "unable to find argv0!\n");
1994 GetTempPathA(sizeof(filename), filename);
1995 GetTempFileNameA(filename, "wt", 0, tmpdir);
1996 DeleteFileA( tmpdir );
1997 rc = CreateDirectoryA( tmpdir, NULL );
1998 ok( rc, "failed to create %s err %u\n", tmpdir, GetLastError() );
1999 rc = GetTempFileNameA(tmpdir, "wt", 0, child_file);
2001 init_event(child_file);
2003 /* Set up the test files */
2009 sprintf(filename, *testfile, tmpdir);
2010 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2011 FILE_ATTRIBUTE_NORMAL, NULL);
2012 if (hfile==INVALID_HANDLE_VALUE)
2014 trace("unable to create '%s': err=%d\n", filename, GetLastError());
2021 /* Setup the test shortcuts */
2022 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
2023 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2024 desc.description=NULL;
2026 sprintf(filename, "%s\\test file.shlexec", tmpdir);
2029 desc.arguments="ignored";
2034 create_lnk(lnkfile, &desc, 0);
2036 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2037 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2038 desc.description=NULL;
2042 sprintf(params, "shlexec \"%s\" Lnk", child_file);
2043 desc.arguments=params;
2048 create_lnk(lnkfile, &desc, 0);
2050 /* Create a basic association suitable for most tests */
2051 if (!create_test_association(".shlexec"))
2053 skip("Unable to create association for '.shlexec'\n");
2056 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2057 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2058 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2059 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2060 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2061 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2063 create_test_verb(".shlexec", "NoQuotesParam2", 0, "NoQuotesParam2 %2");
2064 create_test_verb(".shlexec", "QuotedParam2", 0, "QuotedParam2 \"%2\"");
2066 create_test_verb(".shlexec", "NoQuotesAllParams", 0, "NoQuotesAllParams %*");
2067 create_test_verb(".shlexec", "QuotedAllParams", 0, "QuotedAllParams \"%*\"");
2069 create_test_verb(".shlexec", "NoQuotesParams345etc", 0, "NoQuotesParams345etc %~3");
2070 create_test_verb(".shlexec", "QuotedParams345etc", 0, "QuotedParams345etc \"%~3\"");
2073 static void cleanup_test(void)
2075 char filename[MAX_PATH];
2076 const char* const * testfile;
2078 /* Delete the test files */
2082 sprintf(filename, *testfile, tmpdir);
2083 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2084 SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
2085 DeleteFile(filename);
2088 DeleteFile(child_file);
2089 RemoveDirectoryA(tmpdir);
2091 /* Delete the test association */
2092 delete_test_association(".shlexec");
2094 CloseHandle(hEvent);
2099 static void test_commandline(void)
2101 static const WCHAR one[] = {'o','n','e',0};
2102 static const WCHAR two[] = {'t','w','o',0};
2103 static const WCHAR three[] = {'t','h','r','e','e',0};
2104 static const WCHAR four[] = {'f','o','u','r',0};
2106 static const WCHAR fmt1[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
2107 static const WCHAR fmt2[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
2108 static const WCHAR fmt3[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
2109 static const WCHAR fmt4[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
2110 static const WCHAR fmt5[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
2111 static const WCHAR fmt6[] = {0};
2113 static const WCHAR chkfmt1[] = {'%','s','=','%','s',0};
2114 static const WCHAR chkfmt2[] = {'%','s',' ','%','s',0};
2115 static const WCHAR chkfmt3[] = {'\\','\"','%','s','\"',0};
2116 static const WCHAR chkfmt4[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
2118 LPWSTR *args = (LPWSTR*)0xdeadcafe, pbuf;
2122 wsprintfW(cmdline,fmt1,one,two,three,four);
2123 args=CommandLineToArgvW(cmdline,&numargs);
2124 if (args == NULL && numargs == -1)
2126 win_skip("CommandLineToArgvW not implemented, skipping\n");
2129 ok(numargs == 4, "expected 4 args, got %i\n",numargs);
2130 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
2131 ok(lstrcmpW(args[1],two)==0,"arg1 is not as expected\n");
2132 ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n");
2133 ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
2135 wsprintfW(cmdline,fmt2,one,two,three,four);
2136 args=CommandLineToArgvW(cmdline,&numargs);
2137 ok(numargs == 5, "expected 5 args, got %i\n",numargs);
2138 ok(args[0][0]==0,"arg0 is not as expected\n");
2139 ok(lstrcmpW(args[1],one)==0,"arg1 is not as expected\n");
2140 ok(lstrcmpW(args[2],two)==0,"arg2 is not as expected\n");
2141 ok(lstrcmpW(args[3],three)==0,"arg3 is not as expected\n");
2142 ok(lstrcmpW(args[4],four)==0,"arg4 is not as expected\n");
2144 wsprintfW(cmdline,fmt3,one,two,three,four);
2145 args=CommandLineToArgvW(cmdline,&numargs);
2146 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
2147 wsprintfW(cmdline,chkfmt1,one,two);
2148 ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
2149 wsprintfW(cmdline,chkfmt1,three,four);
2150 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2152 wsprintfW(cmdline,fmt4,one,two,three,four);
2153 args=CommandLineToArgvW(cmdline,&numargs);
2154 ok(numargs == 3, "expected 3 args, got %i\n",numargs);
2155 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
2156 wsprintfW(cmdline,chkfmt2,two,three);
2157 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2158 ok(lstrcmpW(args[2],four)==0,"arg2 is not as expected\n");
2160 wsprintfW(cmdline,fmt5,one,two,three,four);
2161 args=CommandLineToArgvW(cmdline,&numargs);
2162 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
2163 wsprintfW(cmdline,chkfmt3,one);
2164 todo_wine ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
2165 wsprintfW(cmdline,chkfmt4,two,three,four);
2166 todo_wine ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2168 wsprintfW(cmdline,fmt6);
2169 args=CommandLineToArgvW(cmdline,&numargs);
2170 ok(numargs == 1, "expected 1 args, got %i\n",numargs);
2172 buflen = max(lstrlenW(args[0])+1,256);
2173 pbuf = HeapAlloc(GetProcessHeap(), 0, buflen*sizeof(pbuf[0]));
2174 GetModuleFileNameW(NULL, pbuf, buflen);
2176 /* check args[0] is module file name */
2177 ok(lstrcmpW(args[0],pbuf)==0, "wrong path to the current executable\n");
2178 HeapFree(GetProcessHeap(), 0, pbuf);
2185 myARGC = winetest_get_mainargs(&myARGV);
2188 doChild(myARGC, myARGV);
2195 test_lpFile_parsed();
2197 test_find_executable();
2202 test_dde_default_app();