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* name, const char* param)
82 if (str[strlen(str)-1] == '"')
91 static char shell_call[2048]="";
92 static int bad_shellexecute = 0;
93 static INT_PTR shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
95 INT_PTR rc, rcEmpty = 0;
98 rcEmpty = shell_execute("", file, parameters, directory);
100 strcpy(shell_call, "ShellExecute(");
101 strcat_param(shell_call, "verb", operation);
102 strcat_param(shell_call, "file", file);
103 strcat_param(shell_call, "params", parameters);
104 strcat_param(shell_call, "dir", 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, "%s WaitForSingleObject returned %d\n", shell_call, 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);
144 if (rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */
145 bad_shellexecute = 1;
146 ok(rc == rcEmpty || broken(rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */,
147 "%s Got different return value with empty string: %lu %lu\n", shell_call, rc, rcEmpty);
153 static INT_PTR shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
154 LPCSTR parameters, LPCSTR directory)
156 SHELLEXECUTEINFO sei;
160 strcpy(shell_call, "ShellExecuteEx(");
164 sprintf(smask, "0x%x", mask);
165 strcat_param(shell_call, "mask", smask);
167 strcat_param(shell_call, "verb", operation);
168 strcat_param(shell_call, "file", file);
169 strcat_param(shell_call, "params", parameters);
170 strcat_param(shell_call, "dir", directory);
171 strcat(shell_call, ")");
172 if (winetest_debug > 1)
173 trace("%s\n", shell_call);
175 sei.cbSize=sizeof(sei);
176 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
178 sei.lpVerb=operation;
180 sei.lpParameters=parameters;
181 sei.lpDirectory=directory;
182 sei.nShow=SW_SHOWNORMAL;
183 sei.hInstApp=NULL; /* Out */
189 sei.hProcess=NULL; /* Out */
191 DeleteFile(child_file);
192 SetLastError(0xcafebabe);
193 success=ShellExecuteEx(&sei);
194 rc=(INT_PTR)sei.hInstApp;
195 ok((success && rc > 32) || (!success && rc <= 32),
196 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call, success, rc);
201 if (sei.hProcess!=NULL)
203 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
204 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
206 wait_rc=WaitForSingleObject(hEvent, 5000);
207 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
209 /* The child process may have changed the result file, so let profile
210 * functions know about it
212 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
223 * Functions to create / delete associations wrappers
227 static BOOL create_test_association(const char* extension)
229 HKEY hkey, hkey_shell;
230 char class[MAX_PATH];
233 sprintf(class, "shlexec%s", extension);
234 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
236 if (rc != ERROR_SUCCESS)
239 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
240 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
243 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
244 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
245 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
247 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
248 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
249 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
252 CloseHandle(hkey_shell);
257 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
258 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
261 DWORD dwMaxSubkeyLen, dwMaxValueLen;
262 DWORD dwMaxLen, dwSize;
263 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
268 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
272 /* Get highest length for keys, values */
273 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
274 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
275 if (ret) goto cleanup;
279 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
280 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
282 /* Name too big: alloc a buffer for it */
283 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
285 ret = ERROR_NOT_ENOUGH_MEMORY;
291 /* Recursively delete all the subkeys */
295 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
296 NULL, NULL, NULL)) break;
298 ret = myRegDeleteTreeA(hSubKey, lpszName);
299 if (ret) goto cleanup;
303 ret = RegDeleteKeyA(hKey, lpszSubKey);
308 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
309 NULL, NULL, NULL, NULL)) break;
311 ret = RegDeleteValueA(hKey, lpszName);
312 if (ret) goto cleanup;
316 /* Free buffer if allocated */
317 if (lpszName != szNameBuf)
318 HeapFree( GetProcessHeap(), 0, lpszName);
320 RegCloseKey(hSubKey);
324 static void delete_test_association(const char* extension)
326 char class[MAX_PATH];
328 sprintf(class, "shlexec%s", extension);
329 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
330 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
333 static void create_test_verb_dde(const char* extension, const char* verb,
334 int rawcmd, const char* cmdtail, const char *ddeexec,
335 const char *application, const char *topic,
338 HKEY hkey_shell, hkey_verb, hkey_cmd;
339 char shell[MAX_PATH];
343 sprintf(shell, "shlexec%s\\shell", extension);
344 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
345 KEY_CREATE_SUB_KEY, &hkey_shell);
346 assert(rc==ERROR_SUCCESS);
347 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
348 NULL, &hkey_verb, NULL);
349 assert(rc==ERROR_SUCCESS);
350 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
351 NULL, &hkey_cmd, NULL);
352 assert(rc==ERROR_SUCCESS);
356 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
360 cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
361 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
362 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
363 assert(rc==ERROR_SUCCESS);
364 HeapFree(GetProcessHeap(), 0, cmd);
369 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
371 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
372 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
373 assert(rc==ERROR_SUCCESS);
374 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
376 assert(rc==ERROR_SUCCESS);
379 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
380 NULL, &hkey_application, NULL);
381 assert(rc==ERROR_SUCCESS);
382 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
383 strlen(application)+1);
384 assert(rc==ERROR_SUCCESS);
385 CloseHandle(hkey_application);
389 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
390 NULL, &hkey_topic, NULL);
391 assert(rc==ERROR_SUCCESS);
392 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
394 assert(rc==ERROR_SUCCESS);
395 CloseHandle(hkey_topic);
399 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
400 NULL, &hkey_ifexec, NULL);
401 assert(rc==ERROR_SUCCESS);
402 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
404 assert(rc==ERROR_SUCCESS);
405 CloseHandle(hkey_ifexec);
407 CloseHandle(hkey_ddeexec);
410 CloseHandle(hkey_shell);
411 CloseHandle(hkey_verb);
412 CloseHandle(hkey_cmd);
415 static void create_test_verb(const char* extension, const char* verb,
416 int rawcmd, const char* cmdtail)
418 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
424 * Functions to check that the child process was started just right
425 * (borrowed from dlls/kernel32/tests/process.c)
429 static const char* encodeA(const char* str)
431 static char encoded[2*1024+1];
436 len = strlen(str) + 1;
437 if (len >= sizeof(encoded)/2)
439 fprintf(stderr, "string is too long!\n");
443 for (i = 0; i < len; i++)
444 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
449 static unsigned decode_char(char c)
451 if (c >= '0' && c <= '9') return c - '0';
452 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
453 assert(c >= 'A' && c <= 'F');
457 static char* decodeA(const char* str)
459 static char decoded[1024];
463 len = strlen(str) / 2;
464 if (!len--) return NULL;
465 if (len >= sizeof(decoded))
467 fprintf(stderr, "string is too long!\n");
471 for (i = 0; i < len; i++)
472 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
477 static void childPrintf(HANDLE h, const char* fmt, ...)
483 va_start(valist, fmt);
484 vsprintf(buffer, fmt, valist);
486 WriteFile(h, buffer, strlen(buffer), &w, NULL);
489 static DWORD ddeInst;
491 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
492 static BOOL post_quit_on_execute;
494 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
495 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
496 ULONG_PTR dwData1, ULONG_PTR dwData2)
500 if (winetest_debug > 2)
501 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
502 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
507 if (!DdeCmpStringHandles(hsz1, hszTopic))
509 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
510 assert(size < MAX_PATH);
511 return (HDDEDATA)TRUE;
513 return (HDDEDATA)FALSE;
516 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
517 assert(size < MAX_PATH);
518 DdeFreeDataHandle(hData);
519 if (post_quit_on_execute)
521 return (HDDEDATA)DDE_FACK;
529 * This is just to make sure the child won't run forever stuck in a GetMessage()
530 * loop when DDE fails for some reason.
532 static void CALLBACK childTimeout(HWND wnd, UINT msg, UINT_PTR timer, DWORD time)
534 trace("childTimeout called\n");
539 static void doChild(int argc, char** argv)
541 char *filename, longpath[MAX_PATH] = "";
552 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
553 if (hFile == INVALID_HANDLE_VALUE)
557 childPrintf(hFile, "[Arguments]\r\n");
558 if (winetest_debug > 2)
559 trace("argcA=%d\n", argc);
560 childPrintf(hFile, "argcA=%d\r\n", argc);
561 for (i = 0; i < argc; i++)
563 if (winetest_debug > 2)
564 trace("argvA%d=%s\n", i, argv[i]);
565 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
567 GetModuleFileNameA(GetModuleHandleA(NULL), longpath, MAX_PATH);
568 childPrintf(hFile, "longPath=%s\r\n", encodeA(longpath));
570 map = OpenFileMappingA(FILE_MAP_READ, FALSE, "winetest_shlexec_dde_map");
573 shared_block = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 4096);
575 if (shared_block[0] != '\0' || shared_block[1] != '\0')
577 post_quit_on_execute = TRUE;
579 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
580 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
581 assert(rc == DMLERR_NO_ERROR);
582 hszApplication = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
583 hszTopic = DdeCreateStringHandleA(ddeInst, shared_block + strlen(shared_block) + 1, CP_WINANSI);
584 assert(hszApplication && hszTopic);
585 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
587 timer = SetTimer(NULL, 0, 2500, childTimeout);
589 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
591 CloseHandle(dde_ready);
593 while (GetMessage(&msg, NULL, 0, 0))
594 DispatchMessage(&msg);
597 KillTimer(NULL, timer);
598 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
599 assert(DdeFreeStringHandle(ddeInst, hszTopic));
600 assert(DdeFreeStringHandle(ddeInst, hszApplication));
601 assert(DdeUninitialize(ddeInst));
605 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
607 CloseHandle(dde_ready);
610 UnmapViewOfFile(shared_block);
612 childPrintf(hFile, "ddeExec=%s\r\n", encodeA(ddeExec));
617 init_event(filename);
622 static char* getChildString(const char* sect, const char* key)
627 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
628 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
629 assert(!(strlen(buf) & 1));
634 static void dump_child(void)
636 if (winetest_debug > 1)
642 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
643 trace("argcA=%d\n",c);
646 sprintf(key, "argvA%d", i);
647 str=getChildString("Arguments", key);
648 trace("%s=%s\n", key, str);
653 static int StrCmpPath(const char* s1, const char* s2)
655 if (!s1 && !s2) return 0;
666 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
668 while (*s1=='/' || *s1=='\\')
670 while (*s2=='/' || *s2=='\\')
673 else if (toupper(*s1)==toupper(*s2))
690 static void _okChildString(const char* file, int line, const char* key, const char* expected)
693 result=getChildString("Arguments", key);
696 ok_(file, line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
699 ok_(file, line)(lstrcmpiA(result, expected) == 0,
700 "%s expected '%s', got '%s'\n", key, expected, result);
703 static void _okChildPath(const char* file, int line, const char* key, const char* expected)
706 result=getChildString("Arguments", key);
709 ok_(file, line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
712 ok_(file, line)(StrCmpPath(result, expected) == 0,
713 "%s expected '%s', got '%s'\n", key, expected, result);
716 static void _okChildInt(const char* file, int line, const char* key, int expected)
719 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
720 ok_(file, line)(result == expected,
721 "%s expected %d, but got %d\n", key, expected, result);
724 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
725 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
726 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
730 * GetLongPathNameA equivalent that supports Win95 and WinNT
734 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
736 char tmplongpath[MAX_PATH];
738 DWORD sp = 0, lp = 0;
740 WIN32_FIND_DATAA wfd;
743 if (!shortpath || !shortpath[0])
746 if (shortpath[1] == ':')
748 tmplongpath[0] = shortpath[0];
749 tmplongpath[1] = ':';
753 while (shortpath[sp])
755 /* check for path delimiters and reproduce them */
756 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
758 if (!lp || tmplongpath[lp-1] != '\\')
760 /* strip double "\\" */
761 tmplongpath[lp++] = '\\';
763 tmplongpath[lp] = 0; /* terminate string */
769 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
771 tmplongpath[lp++] = *p++;
772 tmplongpath[lp++] = *p++;
774 for (; *p && *p != '/' && *p != '\\'; p++);
775 tmplen = p - (shortpath + sp);
776 lstrcpyn(tmplongpath + lp, shortpath + sp, tmplen + 1);
777 /* Check if the file exists and use the existing file name */
778 goit = FindFirstFileA(tmplongpath, &wfd);
779 if (goit == INVALID_HANDLE_VALUE)
782 strcpy(tmplongpath + lp, wfd.cFileName);
783 lp += strlen(tmplongpath + lp);
786 tmplen = strlen(shortpath) - 1;
787 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
788 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
789 tmplongpath[lp++] = shortpath[tmplen];
792 tmplen = strlen(tmplongpath) + 1;
793 if (tmplen <= longlen)
795 strcpy(longpath, tmplongpath);
796 tmplen--; /* length without 0 */
804 * PathFindFileNameA equivalent that supports WinNT
808 static LPSTR path_find_file_name(LPCSTR lpszPath)
810 LPCSTR lastSlash = lpszPath;
812 while (lpszPath && *lpszPath)
814 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
815 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
816 lastSlash = lpszPath + 1;
817 lpszPath = CharNext(lpszPath);
819 return (LPSTR)lastSlash;
828 static const char* testfiles[]=
830 "%s\\test file.shlexec",
831 "%s\\%%nasty%% $file.shlexec",
832 "%s\\test file.noassoc",
833 "%s\\test file.noassoc.shlexec",
834 "%s\\test file.shlexec.noassoc",
835 "%s\\test_shortcut_shlexec.lnk",
836 "%s\\test_shortcut_exe.lnk",
838 "%s\\test file.shlfoo",
840 "%s\\masked file.shlexec",
845 "%s\\simple.shlexec",
846 "%s\\drawback_file.noassoc",
847 "%s\\drawback_file.noassoc foo.shlexec",
848 "%s\\drawback_nonexist.noassoc foo.shlexec",
855 const char* basename;
860 static filename_tests_t filename_tests[]=
862 /* Test bad / nonexistent filenames */
863 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
864 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
867 {NULL, "%s\\test file.shlexec", 0x0, 33},
868 {NULL, "%s\\test file.shlexec.", 0x0, 33},
869 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
870 {NULL, "%s/test file.shlexec", 0x0, 33},
872 /* Test filenames with no association */
873 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
875 /* Test double extensions */
876 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
877 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
879 /* Test alternate verbs */
880 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
881 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
883 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
884 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
886 /* Test file masked due to space */
887 {NULL, "%s\\masked file.shlexec", 0x1, 33},
888 /* Test if quoting prevents the masking */
889 {NULL, "%s\\masked file.shlexec", 0x40, 33},
894 static filename_tests_t noquotes_tests[]=
896 /* Test unquoted '%1' thingies */
897 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
898 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
899 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
904 static void test_lpFile_parsed(void)
906 char fileA[MAX_PATH];
909 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
910 sprintf(fileA, "%s\\drawback_file.noassoc foo.shlexec", tmpdir);
911 rc=shell_execute(NULL, fileA, NULL, NULL);
912 todo_wine ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
914 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
915 sprintf(fileA, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir);
916 rc=shell_execute(NULL, fileA, NULL, NULL);
917 ok(rc > 32 || broken(rc == SE_ERR_FNF) /* Win95/NT4 */,
918 "%s failed: rc=%lu\n", shell_call, rc);
920 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
921 sprintf(fileA, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir);
922 rc=shell_execute(NULL, fileA, NULL, NULL);
923 ok(rc == SE_ERR_FNF, "%s succeeded: rc=%lu\n", shell_call, rc);
925 /* ""command"" not works on wine (and real win9x and w2k) */
926 sprintf(fileA, "\"\"%s\\simple.shlexec\"\"", tmpdir);
927 rc=shell_execute(NULL, fileA, NULL, NULL);
928 todo_wine ok(rc > 32 || broken(rc == SE_ERR_FNF) /* Win9x/2000 */,
929 "%s failed: rc=%lu\n", shell_call, rc);
931 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
932 sprintf(fileA, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir);
933 rc=shell_execute(NULL, fileA, NULL, NULL);
934 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
936 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
937 rc=shell_execute(NULL, "%TMPDIR%\\simple.shlexec", NULL, NULL);
938 todo_wine ok(rc == SE_ERR_FNF, "%s succeeded: rc=%lu\n", shell_call, rc);
941 rc=shell_execute(NULL, "\"%TMPDIR%\\simple.shlexec\"", NULL, NULL);
942 todo_wine ok(rc == SE_ERR_FNF, "%s succeeded: rc=%lu\n", shell_call, rc);
944 /* test SEE_MASK_DOENVSUBST works */
945 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI,
946 NULL, "%TMPDIR%\\simple.shlexec", NULL, NULL);
947 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
949 /* quoted lpFile does not work on real win95 and nt4 */
950 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI,
951 NULL, "\"%TMPDIR%\\simple.shlexec\"", NULL, NULL);
952 ok(rc > 32 || broken(rc == SE_ERR_FNF) /* Win95/NT4 */,
953 "%s failed: rc=%lu\n", shell_call, rc);
959 const char* args[11];
963 static const cmdline_tests_t cmdline_tests[] =
965 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
966 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL}, 0},
968 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
969 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL}, 0},
971 {"exe arg\"one\" \"second\"arg thirdarg ",
972 {"exe", "argone", "secondarg", "thirdarg", NULL}, 0},
974 /* cmd's metacharacters have no special meaning */
975 {"exe \"one^\" \"arg\"&two three|four",
976 {"exe", "one^", "arg&two", "three|four", NULL}, 0},
978 /* Environment variables are not interpreted either */
980 {"exe", "%TMPDIR%", "%2", NULL}, 0},
982 /* If not followed by a quote, backslashes go through as is */
983 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
984 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL}, 0},
986 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
987 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL}, 0},
989 /* When followed by a quote their number is halved and the remainder
992 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
993 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL}, 0},
995 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
996 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL}, 0},
998 /* One can put a quote in an unquoted string by tripling it, that is in
999 * effect quoting it like so """ -> ". The general rule is as follows:
1000 * 3n quotes -> n quotes
1001 * 3n+1 quotes -> n quotes plus start of a quoted string
1002 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1003 * Nicely, when n is 0 we get the standard rules back.
1005 {"exe two\"\"quotes next",
1006 {"exe", "twoquotes", "next", NULL}, 0},
1008 {"exe three\"\"\"quotes next",
1009 {"exe", "three\"quotes", "next", NULL}, 0x21},
1011 {"exe four\"\"\"\" quotes\" next 4%3=1",
1012 {"exe", "four\" quotes", "next", "4%3=1", NULL}, 0x61},
1014 {"exe five\"\"\"\"\"quotes next",
1015 {"exe", "five\"quotes", "next", NULL}, 0x21},
1017 {"exe six\"\"\"\"\"\"quotes next",
1018 {"exe", "six\"\"quotes", "next", NULL}, 0x20},
1020 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1021 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL}, 0x20},
1023 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1024 {"exe", "twelve\"\"\"\"quotes", "next", NULL}, 0x20},
1026 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1027 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL}, 0x20},
1029 /* Inside a quoted string the opening quote is added to the set of
1030 * consecutive quotes to get the effective quotes count. This gives:
1031 * 1+3n quotes -> n quotes
1032 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1033 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1035 {"exe \"two\"\"quotes next",
1036 {"exe", "two\"quotes", "next", NULL}, 0x21},
1038 {"exe \"two\"\" next",
1039 {"exe", "two\"", "next", NULL}, 0x21},
1041 {"exe \"three\"\"\" quotes\" next 4%3=1",
1042 {"exe", "three\" quotes", "next", "4%3=1", NULL}, 0x61},
1044 {"exe \"four\"\"\"\"quotes next",
1045 {"exe", "four\"quotes", "next", NULL}, 0x21},
1047 {"exe \"five\"\"\"\"\"quotes next",
1048 {"exe", "five\"\"quotes", "next", NULL}, 0x20},
1050 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1051 {"exe", "six\"\" quotes", "next", "7%3=1", NULL}, 0x20},
1053 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1054 {"exe", "eleven\"\"\"\"quotes", "next", NULL}, 0x20},
1056 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1057 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL}, 0x20},
1059 /* The executable path has its own rules!!!
1060 * - Backslashes have no special meaning.
1061 * - If the first character is a quote, then the second quote ends the
1063 * - The previous rule holds even if the next character is not a space!
1064 * - If the first character is not a quote, then quotes have no special
1065 * meaning either and the executable path stops at the first space.
1066 * - The consecutive quotes rules don't apply either.
1067 * - Even if there is no space between the executable path and the first
1068 * argument, the latter is parsed using the regular rules.
1070 {"exe\"file\"path arg1",
1071 {"exe\"file\"path", "arg1", NULL}, 0x30},
1073 {"exe\"path\\ arg1",
1074 {"exe\"path\\", "arg1", NULL}, 0x31},
1076 {"\\\"exe \"arg one\"",
1077 {"\\\"exe", "arg one", NULL}, 0x10},
1079 {"\"spaced exe\" \"next arg\"",
1080 {"spaced exe", "next arg", NULL}, 0},
1082 {"\"exe\"arg\" one\" argtwo",
1083 {"exe", "arg one", "argtwo", NULL}, 0x31},
1085 {"\"spaced exe\\\"arg1 arg2",
1086 {"spaced exe\\", "arg1", "arg2", NULL}, 0x11},
1089 {"two", " arg1 ", NULL}, 0x21},
1091 {"\"three\"\"\" arg2",
1092 {"three", "", "arg2", NULL}, 0x61},
1094 {"\"four\"\"\"\"arg1",
1095 {"four", "\"arg1", NULL}, 0x21},
1097 /* If the first character is a space then the executable path is empty */
1098 {" \"arg\"one argtwo",
1099 {"", "argone", "argtwo", NULL}, 0},
1104 static BOOL test_one_cmdline(const cmdline_tests_t* test)
1106 WCHAR cmdW[MAX_PATH], argW[MAX_PATH];
1112 /* trace("----- cmd='%s'\n", test->cmd); */
1113 MultiByteToWideChar(CP_ACP, 0, test->cmd, -1, cmdW, sizeof(cmdW)/sizeof(*cmdW));
1114 argsW = cl2a = CommandLineToArgvW(cmdW, &cl2a_count);
1115 if (argsW == NULL && cl2a_count == -1)
1117 win_skip("CommandLineToArgvW not implemented, skipping\n");
1122 while (test->args[count])
1124 if ((test->todo & 0x1) == 0)
1125 ok(cl2a_count == count, "%s: expected %d arguments, but got %d\n", test->cmd, count, cl2a_count);
1127 ok(cl2a_count == count, "%s: expected %d arguments, but got %d\n", test->cmd, count, cl2a_count);
1129 for (i = 0; i < cl2a_count - 1; i++)
1133 MultiByteToWideChar(CP_ACP, 0, test->args[i], -1, argW, sizeof(argW)/sizeof(*argW));
1134 if ((test->todo & (1 << (i+4))) == 0)
1135 ok(!lstrcmpW(*argsW, argW), "%s: arg[%d] expected %s but got %s\n", test->cmd, i, wine_dbgstr_w(argW), wine_dbgstr_w(*argsW));
1137 ok(!lstrcmpW(*argsW, argW), "%s: arg[%d] expected %s but got %s\n", test->cmd, i, wine_dbgstr_w(argW), wine_dbgstr_w(*argsW));
1139 else if ((test->todo & 0x1) == 0)
1140 ok(0, "%s: got extra arg[%d]=%s\n", test->cmd, i, wine_dbgstr_w(*argsW));
1142 ok(0, "%s: got extra arg[%d]=%s\n", test->cmd, i, wine_dbgstr_w(*argsW));
1149 static void test_commandline2argv(void)
1151 static const WCHAR exeW[] = {'e','x','e',0};
1152 const cmdline_tests_t* test;
1153 WCHAR strW[MAX_PATH];
1158 test = cmdline_tests;
1161 if (!test_one_cmdline(test))
1166 SetLastError(0xdeadbeef);
1167 args = CommandLineToArgvW(exeW, NULL);
1168 le = GetLastError();
1169 ok(args == NULL && le == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args, le);
1171 SetLastError(0xdeadbeef);
1172 args = CommandLineToArgvW(NULL, NULL);
1173 le = GetLastError();
1174 ok(args == NULL && le == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args, le);
1177 args = CommandLineToArgvW(strW, &numargs);
1178 ok(numargs == 1, "expected 1 args, got %d\n", numargs);
1181 GetModuleFileNameW(NULL, strW, sizeof(strW)/sizeof(*strW));
1182 ok(!lstrcmpW(args[0], strW), "wrong path to the current executable: %s instead of %s\n", wine_dbgstr_w(args[0]), wine_dbgstr_w(strW));
1184 if (args) LocalFree(args);
1187 static void test_argify(void)
1189 char fileA[MAX_PATH];
1192 sprintf(fileA, "%s\\test file.shlexec", tmpdir);
1195 rc=shell_execute("NoQuotesParam2", fileA, "a b", NULL);
1196 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1199 okChildInt("argcA", 5);
1200 okChildString("argvA4", "a");
1204 /* '"a"""' -> 'a"' */
1205 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\"\"some string\"\"\"", NULL);
1206 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1209 okChildInt("argcA", 5);
1211 okChildString("argvA4", "a:some string");
1216 /* backslash isn't escape char
1217 * '"a\""' -> '"a\""' */
1218 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\\\"some string\\\"\"", NULL);
1219 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1222 okChildInt("argcA", 5);
1224 okChildString("argvA4", "a:\\");
1229 /* \t isn't whitespace */
1230 rc=shell_execute("QuotedParam2", fileA, "a\tb c", NULL);
1231 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1234 okChildInt("argcA", 5);
1236 okChildString("argvA4", "a\tb");
1241 rc=shell_execute("NoQuotesAllParams", fileA, "a b c d e f g h", NULL);
1242 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1246 okChildInt("argcA", 12);
1247 okChildString("argvA4", "a");
1248 okChildString("argvA11", "h");
1252 /* %* can sometimes contain only whitespaces and no args */
1253 rc=shell_execute("QuotedAllParams", fileA, " ", NULL);
1254 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1258 okChildInt("argcA", 5);
1259 okChildString("argvA4", " ");
1264 rc=shell_execute("NoQuotesParams345etc", fileA, "a b c d e f g h", NULL);
1265 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1269 okChildInt("argcA", 11);
1270 okChildString("argvA4", "b");
1271 okChildString("argvA10", "h");
1275 /* %~3 is rest of command line starting with whitespaces after 2nd arg */
1276 rc=shell_execute("QuotedParams345etc", fileA, "a ", NULL);
1277 ok(rc > 32, "%s failed: rc=%lu\n", shell_call, rc);
1280 okChildInt("argcA", 5);
1282 okChildString("argvA4", " ");
1288 static void test_filename(void)
1290 char filename[MAX_PATH];
1291 const filename_tests_t* test;
1295 test=filename_tests;
1296 while (test->basename)
1298 BOOL quotedfile = FALSE;
1300 if (skip_noassoc_tests && test->rc == SE_ERR_NOASSOC)
1302 win_skip("Skipping shellexecute of file with unassociated extension\n");
1307 sprintf(filename, test->basename, tmpdir);
1308 if (strchr(filename, '/'))
1318 if ((test->todo & 0x40)==0)
1320 rc=shell_execute(test->verb, filename, NULL, NULL);
1324 char quoted[MAX_PATH + 2];
1327 sprintf(quoted, "\"%s\"", filename);
1328 rc=shell_execute(test->verb, quoted, NULL, NULL);
1332 if ((test->todo & 0x1)==0)
1335 broken(quotedfile && rc == SE_ERR_FNF), /* NT4 */
1336 "%s failed: rc=%ld err=%u\n", shell_call,
1337 rc, GetLastError());
1341 ok(rc==test->rc, "%s failed: rc=%ld err=%u\n", shell_call,
1342 rc, GetLastError());
1347 if ((test->todo & 0x2)==0)
1349 okChildInt("argcA", 5);
1353 okChildInt("argcA", 5);
1355 verb=(test->verb ? test->verb : "Open");
1356 if ((test->todo & 0x4)==0)
1358 okChildString("argvA3", verb);
1362 okChildString("argvA3", verb);
1364 if ((test->todo & 0x8)==0)
1366 okChildPath("argvA4", filename);
1370 okChildPath("argvA4", filename);
1376 test=noquotes_tests;
1377 while (test->basename)
1379 sprintf(filename, test->basename, tmpdir);
1380 rc=shell_execute(test->verb, filename, NULL, NULL);
1383 if ((test->todo & 0x1)==0)
1385 ok(rc==test->rc, "%s failed: rc=%ld err=%u\n", shell_call,
1386 rc, GetLastError());
1390 ok(rc==test->rc, "%s failed: rc=%ld err=%u\n", shell_call,
1391 rc, GetLastError());
1399 verb=(test->verb ? test->verb : "Open");
1400 if ((test->todo & 0x4)==0)
1402 okChildString("argvA3", verb);
1406 okChildString("argvA3", verb);
1415 space=strchr(str, ' ');
1418 sprintf(attrib, "argvA%d", count);
1419 if ((test->todo & 0x8)==0)
1421 okChildPath(attrib, str);
1425 okChildPath(attrib, str);
1432 if ((test->todo & 0x2)==0)
1434 okChildInt("argcA", count);
1438 okChildInt("argcA", count);
1444 if (dllver.dwMajorVersion != 0)
1446 /* The more recent versions of shell32.dll accept quoted filenames
1447 * while older ones (e.g. 4.00) don't. Still we want to test this
1448 * because IE 6 depends on the new behavior.
1449 * One day we may need to check the exact version of the dll but for
1450 * now making sure DllGetVersion() is present is sufficient.
1452 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
1453 rc=shell_execute(NULL, filename, NULL, NULL);
1454 ok(rc > 32, "%s failed: rc=%ld err=%u\n", shell_call, rc,
1456 okChildInt("argcA", 5);
1457 okChildString("argvA3", "Open");
1458 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1459 okChildPath("argvA4", filename);
1465 const char* urlprefix;
1466 const char* basename;
1471 #define URL_SUCCESS 0x1
1472 #define USE_COLON 0x2
1473 #define USE_BSLASH 0x4
1475 static fileurl_tests_t fileurl_tests[]=
1477 /* How many slashes does it take... */
1478 {"file:", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1479 {"file:/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1480 {"file://", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1481 {"file:///", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1482 {"File:///", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1483 {"file:////", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1484 {"file://///", "%s\\test file.shlexec", 0, 0x1},
1486 /* Test with Windows-style paths */
1487 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_COLON, 0x1},
1488 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_BSLASH, 0x1},
1490 /* Check handling of hostnames */
1491 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1492 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0x1},
1493 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1494 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0x1},
1495 {"file://::1/", "%s\\test file.shlexec", 0, 0x1},
1496 {"file://notahost/", "%s\\test file.shlexec", 0, 0x1},
1498 /* Environment variables are not expanded in URLs */
1499 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1500 {"file:///", "%s\\%%urlenvvar%% file.shlexec", 0, 0x1},
1505 static void test_fileurl(void)
1507 char filename[MAX_PATH], fileurl[MAX_PATH], longtmpdir[MAX_PATH];
1508 char command[MAX_PATH];
1509 const fileurl_tests_t* test;
1513 rc = (INT_PTR)ShellExecute(NULL, NULL, "file:///nosuchfile.shlexec", NULL, NULL, SW_SHOWNORMAL);
1516 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1520 get_long_path_name(tmpdir, longtmpdir, sizeof(longtmpdir)/sizeof(*longtmpdir));
1521 SetEnvironmentVariable("urlprefix", "file:///");
1522 SetEnvironmentVariable("urlenvvar", "test");
1525 while (test->basename)
1527 /* Build the file URL */
1528 sprintf(filename, test->basename, longtmpdir);
1529 strcpy(fileurl, test->urlprefix);
1530 strcat(fileurl, filename);
1531 s = fileurl + strlen(test->urlprefix);
1534 if (!(test->flags & USE_COLON) && *s == ':')
1536 else if (!(test->flags & USE_BSLASH) && *s == '\\')
1541 /* Test it first with FindExecutable() */
1542 rc = (INT_PTR)FindExecutableA(fileurl, NULL, command);
1543 ok(rc == SE_ERR_FNF, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl, rc);
1545 /* Then ShellExecute() */
1546 rc = shell_execute(NULL, fileurl, NULL, NULL);
1547 if (bad_shellexecute)
1549 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1552 if (test->flags & URL_SUCCESS)
1554 if ((test->todo & 0x1) == 0)
1555 ok(rc > 32, "%s failed: bad rc=%lu\n", shell_call, rc);
1557 ok(rc > 32, "%s failed: bad rc=%lu\n", shell_call, rc);
1561 if ((test->todo & 0x1) == 0)
1562 ok(rc == SE_ERR_FNF || rc == SE_ERR_PNF ||
1563 broken(rc == SE_ERR_ACCESSDENIED) /* win2000 */,
1564 "%s failed: bad rc=%lu\n", shell_call, rc);
1566 ok(rc == SE_ERR_FNF || rc == SE_ERR_PNF ||
1567 broken(rc == SE_ERR_ACCESSDENIED) /* win2000 */,
1568 "%s failed: bad rc=%lu\n", shell_call, rc);
1572 if ((test->todo & 0x2) == 0)
1573 okChildInt("argcA", 5);
1575 okChildInt("argcA", 5);
1577 if ((test->todo & 0x4) == 0)
1578 okChildString("argvA3", "Open");
1580 okChildString("argvA3", "Open");
1582 if ((test->todo & 0x8) == 0)
1583 okChildPath("argvA4", filename);
1585 okChildPath("argvA4", filename);
1590 SetEnvironmentVariable("urlprefix", NULL);
1591 SetEnvironmentVariable("urlenvvar", NULL);
1594 static void test_find_executable(void)
1596 char notepad_path[MAX_PATH];
1597 char filename[MAX_PATH];
1598 char command[MAX_PATH];
1599 const filename_tests_t* test;
1602 if (!create_test_association(".sfe"))
1604 skip("Unable to create association for '.sfe'\n");
1607 create_test_verb(".sfe", "Open", 1, "%1");
1609 /* Don't test FindExecutable(..., NULL), it always crashes */
1611 strcpy(command, "your word");
1612 if (0) /* Can crash on Vista! */
1614 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
1615 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1616 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1619 GetSystemDirectoryA( notepad_path, MAX_PATH );
1620 strcat( notepad_path, "\\notepad.exe" );
1622 /* Search for something that should be in the system-wide search path (no default directory) */
1623 strcpy(command, "your word");
1624 rc=(INT_PTR)FindExecutableA("notepad.exe", NULL, command);
1625 ok(rc > 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc);
1626 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
1628 /* Search for something that should be in the system-wide search path (with default directory) */
1629 strcpy(command, "your word");
1630 rc=(INT_PTR)FindExecutableA("notepad.exe", tmpdir, command);
1631 ok(rc > 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc);
1632 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
1634 strcpy(command, "your word");
1635 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
1636 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1637 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1639 sprintf(filename, "%s\\test file.sfe", tmpdir);
1640 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1641 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1642 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1644 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
1645 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1647 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
1648 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %ld\n", filename, rc);
1650 delete_test_association(".sfe");
1652 if (!create_test_association(".shl"))
1654 skip("Unable to create association for '.shl'\n");
1657 create_test_verb(".shl", "Open", 0, "Open");
1659 sprintf(filename, "%s\\test file.shl", tmpdir);
1660 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1661 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1663 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
1664 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1666 delete_test_association(".shl");
1670 /* On Windows XP and 2003 FindExecutable() is completely broken.
1671 * Probably what it does is convert the filename to 8.3 format,
1672 * which as a side effect converts the '.shlfoo' extension to '.shl',
1673 * and then tries to find an association for '.shl'. This means it
1674 * will normally fail on most extensions with more than 3 characters,
1675 * like '.mpeg', etc.
1676 * Also it means we cannot do any other test.
1678 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
1682 test=filename_tests;
1683 while (test->basename)
1685 sprintf(filename, test->basename, tmpdir);
1686 if (strchr(filename, '/'))
1697 /* Win98 does not '\0'-terminate command! */
1698 memset(command, '\0', sizeof(command));
1699 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1702 if ((test->todo & 0x10)==0)
1704 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1708 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1713 equal=strcmp(command, argv0) == 0 ||
1714 /* NT4 returns an extra 0x8 character! */
1715 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
1716 if ((test->todo & 0x20)==0)
1718 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1719 filename, command, argv0);
1723 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1724 filename, command, argv0);
1732 static filename_tests_t lnk_tests[]=
1734 /* Pass bad / nonexistent filenames as a parameter */
1735 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
1736 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
1738 /* Pass regular paths as a parameter */
1739 {NULL, "%s\\test file.shlexec", 0xa, 33},
1740 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1742 /* Pass filenames with no association as a parameter */
1743 {NULL, "%s\\test file.noassoc", 0xa, 33},
1748 static void test_lnks(void)
1750 char filename[MAX_PATH];
1751 char params[MAX_PATH];
1752 const filename_tests_t* test;
1755 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1756 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1757 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1759 okChildInt("argcA", 5);
1760 okChildString("argvA3", "Open");
1761 sprintf(params, "%s\\test file.shlexec", tmpdir);
1762 get_long_path_name(params, filename, sizeof(filename));
1763 okChildPath("argvA4", filename);
1765 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1766 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1767 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1769 okChildInt("argcA", 4);
1770 okChildString("argvA3", "Lnk");
1772 if (dllver.dwMajorVersion>=6)
1775 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1776 * Older versions don't or are quite buggy in this regard.
1778 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1786 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1787 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1789 okChildInt("argcA", 4);
1790 okChildString("argvA3", "Lnk");
1793 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1795 while (test->basename)
1798 sprintf(params+1, test->basename, tmpdir);
1799 strcat(params,"\"");
1800 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1804 if ((test->todo & 0x1)==0)
1806 ok(rc==test->rc, "%s failed: rc=%lu err=%u\n", shell_call,
1807 rc, GetLastError());
1811 ok(rc==test->rc, "%s failed: rc=%lu err=%u\n", shell_call,
1812 rc, GetLastError());
1816 if ((test->todo & 0x2)==0)
1818 okChildInt("argcA", 5);
1822 okChildInt("argcA", 5);
1824 if ((test->todo & 0x4)==0)
1826 okChildString("argvA3", "Lnk");
1830 okChildString("argvA3", "Lnk");
1832 sprintf(params, test->basename, tmpdir);
1833 if ((test->todo & 0x8)==0)
1835 okChildPath("argvA4", params);
1839 okChildPath("argvA4", params);
1847 static void test_exes(void)
1849 char filename[MAX_PATH];
1853 sprintf(params, "shlexec \"%s\" Exec", child_file);
1855 /* We need NOZONECHECKS on Win2003 to block a dialog */
1856 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1858 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
1859 okChildInt("argcA", 4);
1860 okChildString("argvA3", "Exec");
1862 if (! skip_noassoc_tests)
1864 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1865 if (CopyFile(argv0, filename, FALSE))
1867 rc=shell_execute(NULL, filename, params, NULL);
1869 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%lu\n", shell_call, rc);
1875 win_skip("Skipping shellexecute of file with unassociated extension\n");
1879 static void test_exes_long(void)
1881 char filename[MAX_PATH];
1883 char longparam[MAX_PATH];
1886 for (rc = 0; rc < MAX_PATH; rc++)
1887 longparam[rc]='a'+rc%26;
1888 longparam[MAX_PATH-1]=0;
1891 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1893 /* We need NOZONECHECKS on Win2003 to block a dialog */
1894 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1896 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
1897 okChildInt("argcA", 4);
1898 okChildString("argvA3", longparam);
1900 if (! skip_noassoc_tests)
1902 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1903 if (CopyFile(argv0, filename, FALSE))
1905 rc=shell_execute(NULL, filename, params, NULL);
1907 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%lu\n", shell_call, rc);
1913 win_skip("Skipping shellexecute of file with unassociated extension\n");
1919 const char* command;
1920 const char* ddeexec;
1921 const char* application;
1925 const char* expectedDdeExec;
1929 static dde_tests_t dde_tests[] =
1931 /* Test passing and not passing command-line
1932 * argument, no DDE */
1933 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0},
1934 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0},
1936 /* Test passing and not passing command-line
1937 * argument, with DDE */
1938 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1939 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0},
1941 /* Test unquoted %1 in command and ddeexec
1942 * (test filename has space) */
1943 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0},
1945 /* Test ifexec precedence over ddeexec */
1946 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0},
1948 /* Test default DDE topic */
1949 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0},
1951 /* Test default DDE application */
1952 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1954 {NULL, NULL, NULL, NULL, NULL, 0, 0x0}
1957 static DWORD WINAPI hooked_WaitForInputIdle(HANDLE process, DWORD timeout)
1959 return WaitForSingleObject(dde_ready_event, timeout);
1963 * WaitForInputIdle() will normally return immediately for console apps. That's
1964 * a problem for us because ShellExecute will assume that an app is ready to
1965 * receive DDE messages after it has called WaitForInputIdle() on that app.
1966 * To work around that we install our own version of WaitForInputIdle() that
1967 * will wait for the child to explicitly tell us that it is ready. We do that
1968 * by changing the entry for WaitForInputIdle() in the shell32 import address
1971 static void hook_WaitForInputIdle(DWORD (WINAPI *new_func)(HANDLE, DWORD))
1974 PIMAGE_NT_HEADERS nt_headers;
1975 DWORD import_directory_rva;
1976 PIMAGE_IMPORT_DESCRIPTOR import_descriptor;
1978 base = (char *) GetModuleHandleA("shell32.dll");
1979 nt_headers = (PIMAGE_NT_HEADERS)(base + ((PIMAGE_DOS_HEADER) base)->e_lfanew);
1980 import_directory_rva = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
1982 /* Search for the correct imported module by walking the import descriptors */
1983 import_descriptor = (PIMAGE_IMPORT_DESCRIPTOR)(base + import_directory_rva);
1984 while (U(*import_descriptor).OriginalFirstThunk != 0)
1986 char *import_module_name;
1988 import_module_name = base + import_descriptor->Name;
1989 if (lstrcmpiA(import_module_name, "user32.dll") == 0 ||
1990 lstrcmpiA(import_module_name, "user32") == 0)
1992 PIMAGE_THUNK_DATA int_entry;
1993 PIMAGE_THUNK_DATA iat_entry;
1995 /* The import name table and import address table are two parallel
1996 * arrays. We need the import name table to find the imported
1997 * routine and the import address table to patch the address, so
1998 * walk them side by side */
1999 int_entry = (PIMAGE_THUNK_DATA)(base + U(*import_descriptor).OriginalFirstThunk);
2000 iat_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->FirstThunk);
2001 while (int_entry->u1.Ordinal != 0)
2003 if (! IMAGE_SNAP_BY_ORDINAL(int_entry->u1.Ordinal))
2005 PIMAGE_IMPORT_BY_NAME import_by_name;
2006 import_by_name = (PIMAGE_IMPORT_BY_NAME)(base + int_entry->u1.AddressOfData);
2007 if (lstrcmpA((char *) import_by_name->Name, "WaitForInputIdle") == 0)
2009 /* Found the correct routine in the correct imported module. Patch it. */
2011 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), PAGE_READWRITE, &old_prot);
2012 iat_entry->u1.Function = (ULONG_PTR) new_func;
2013 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), old_prot, &old_prot);
2023 import_descriptor++;
2027 static void test_dde(void)
2029 char filename[MAX_PATH], defApplication[MAX_PATH];
2030 const dde_tests_t* test;
2036 hook_WaitForInputIdle(hooked_WaitForInputIdle);
2038 sprintf(filename, "%s\\test file.sde", tmpdir);
2040 /* Default service is application name minus path and extension */
2041 strcpy(defApplication, strrchr(argv0, '\\')+1);
2042 *strchr(defApplication, '.') = 0;
2044 map = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
2045 4096, "winetest_shlexec_dde_map");
2046 shared_block = MapViewOfFile(map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 4096);
2049 while (test->command)
2051 if (!create_test_association(".sde"))
2053 skip("Unable to create association for '.sde'\n");
2056 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
2057 test->application, test->topic, test->ifexec);
2059 if (test->application != NULL || test->topic != NULL)
2061 strcpy(shared_block, test->application ? test->application : defApplication);
2062 strcpy(shared_block + strlen(shared_block) + 1, test->topic ? test->topic : SZDDESYS_TOPIC);
2066 shared_block[0] = '\0';
2067 shared_block[1] = '\0';
2071 dde_ready_event = CreateEventA(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
2072 rc = shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, filename, NULL, NULL);
2073 CloseHandle(dde_ready_event);
2074 if ((test->todo & 0x1)==0)
2076 ok(32 < rc, "%s failed: rc=%lu err=%u\n", shell_call,
2077 rc, GetLastError());
2081 ok(32 < rc, "%s failed: rc=%lu err=%u\n", shell_call,
2082 rc, GetLastError());
2086 if ((test->todo & 0x2)==0)
2088 okChildInt("argcA", test->expectedArgs + 3);
2092 okChildInt("argcA", test->expectedArgs + 3);
2094 if (test->expectedArgs == 1)
2096 if ((test->todo & 0x4) == 0)
2098 okChildPath("argvA3", filename);
2102 okChildPath("argvA3", filename);
2105 if ((test->todo & 0x8) == 0)
2107 sprintf(params, test->expectedDdeExec, filename);
2108 okChildPath("ddeExec", params);
2112 sprintf(params, test->expectedDdeExec, filename);
2113 okChildPath("ddeExec", params);
2117 delete_test_association(".sde");
2121 UnmapViewOfFile(shared_block);
2123 hook_WaitForInputIdle((void *) WaitForInputIdle);
2126 #define DDE_DEFAULT_APP_VARIANTS 2
2129 const char* command;
2130 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
2132 int rc[DDE_DEFAULT_APP_VARIANTS];
2133 } dde_default_app_tests_t;
2135 static dde_default_app_tests_t dde_default_app_tests[] =
2137 /* Windows XP and 98 handle default DDE app names in different ways.
2138 * The application name we see in the first test determines the pattern
2139 * of application names and return codes we will look for. */
2141 /* Test unquoted existing filename with a space */
2142 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
2143 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
2145 /* Test quoted existing filename with a space */
2146 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
2147 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
2149 /* Test unquoted filename with a space that doesn't exist, but
2151 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
2152 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
2154 /* Test quoted filename with a space that does not exist */
2155 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
2156 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
2158 /* Test filename supplied without the extension */
2159 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
2160 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
2162 /* Test an unquoted nonexistent filename */
2163 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
2164 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
2166 /* Test an application that will be found on the path */
2167 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
2168 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
2170 /* Test an application that will not be found on the path */
2171 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2172 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2174 {NULL, {NULL}, 0, {0}}
2180 DWORD threadIdParent;
2181 } dde_thread_info_t;
2183 static DWORD CALLBACK ddeThread(LPVOID arg)
2185 dde_thread_info_t *info = arg;
2186 assert(info && info->filename);
2187 PostThreadMessage(info->threadIdParent,
2189 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
2194 static void test_dde_default_app(void)
2196 char filename[MAX_PATH];
2198 dde_thread_info_t info = { filename, GetCurrentThreadId() };
2199 const dde_default_app_tests_t* test;
2206 post_quit_on_execute = FALSE;
2208 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
2209 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
2210 assert(rc == DMLERR_NO_ERROR);
2212 sprintf(filename, "%s\\test file.sde", tmpdir);
2214 /* It is strictly not necessary to register an application name here, but wine's
2215 * DdeNameService implementation complains if 0L is passed instead of
2216 * hszApplication with DNS_FILTEROFF */
2217 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2218 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2219 assert(hszApplication && hszTopic);
2220 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
2222 test = dde_default_app_tests;
2223 while (test->command)
2225 if (!create_test_association(".sde"))
2227 skip("Unable to create association for '.sde'\n");
2230 sprintf(params, test->command, tmpdir);
2231 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
2233 ddeApplication[0] = 0;
2235 /* No application will be run as we will respond to the first DDE event,
2236 * so don't wait for it */
2239 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
2240 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
2241 rc = msg.wParam > 32 ? 33 : msg.wParam;
2243 /* First test, find which set of test data we expect to see */
2244 if (test == dde_default_app_tests)
2247 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
2249 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
2255 if (i == DDE_DEFAULT_APP_VARIANTS)
2256 skip("Default DDE application test does not match any available results, using first expected data set.\n");
2259 if ((test->todo & 0x1)==0)
2261 ok(rc==test->rc[which], "%s failed: rc=%lu err=%u\n", shell_call,
2262 rc, GetLastError());
2266 ok(rc==test->rc[which], "%s failed: rc=%lu err=%u\n", shell_call,
2267 rc, GetLastError());
2271 if ((test->todo & 0x2)==0)
2273 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
2274 "Expected application '%s', got '%s'\n",
2275 test->expectedDdeApplication[which], ddeApplication);
2279 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
2280 "Expected application '%s', got '%s'\n",
2281 test->expectedDdeApplication[which], ddeApplication);
2285 delete_test_association(".sde");
2289 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
2290 assert(DdeFreeStringHandle(ddeInst, hszTopic));
2291 assert(DdeFreeStringHandle(ddeInst, hszApplication));
2292 assert(DdeUninitialize(ddeInst));
2295 static void init_test(void)
2298 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
2299 char filename[MAX_PATH];
2300 WCHAR lnkfile[MAX_PATH];
2302 const char* const * testfile;
2307 hdll=GetModuleHandleA("shell32.dll");
2308 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
2311 dllver.cbSize=sizeof(dllver);
2312 pDllGetVersion(&dllver);
2313 trace("major=%d minor=%d build=%d platform=%d\n",
2314 dllver.dwMajorVersion, dllver.dwMinorVersion,
2315 dllver.dwBuildNumber, dllver.dwPlatformID);
2319 memset(&dllver, 0, sizeof(dllver));
2322 r = CoInitialize(NULL);
2323 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
2327 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
2328 assert(rc!=0 && rc<sizeof(argv0));
2329 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
2331 strcat(argv0, ".so");
2332 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
2333 "unable to find argv0!\n");
2336 GetTempPathA(sizeof(filename), filename);
2337 GetTempFileNameA(filename, "wt", 0, tmpdir);
2338 DeleteFileA( tmpdir );
2339 rc = CreateDirectoryA( tmpdir, NULL );
2340 ok( rc, "failed to create %s err %u\n", tmpdir, GetLastError() );
2341 /* Set %TMPDIR% for the tests */
2342 SetEnvironmentVariableA("TMPDIR", tmpdir);
2344 rc = GetTempFileNameA(tmpdir, "wt", 0, child_file);
2346 init_event(child_file);
2348 /* Set up the test files */
2354 sprintf(filename, *testfile, tmpdir);
2355 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2356 FILE_ATTRIBUTE_NORMAL, NULL);
2357 if (hfile==INVALID_HANDLE_VALUE)
2359 trace("unable to create '%s': err=%u\n", filename, GetLastError());
2366 /* Setup the test shortcuts */
2367 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
2368 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2369 desc.description=NULL;
2371 sprintf(filename, "%s\\test file.shlexec", tmpdir);
2374 desc.arguments="ignored";
2379 create_lnk(lnkfile, &desc, 0);
2381 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2382 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2383 desc.description=NULL;
2387 sprintf(params, "shlexec \"%s\" Lnk", child_file);
2388 desc.arguments=params;
2393 create_lnk(lnkfile, &desc, 0);
2395 /* Create a basic association suitable for most tests */
2396 if (!create_test_association(".shlexec"))
2398 skip("Unable to create association for '.shlexec'\n");
2401 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2402 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2403 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2404 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2405 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2406 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2408 create_test_verb(".shlexec", "NoQuotesParam2", 0, "NoQuotesParam2 %2");
2409 create_test_verb(".shlexec", "QuotedParam2", 0, "QuotedParam2 \"%2\"");
2411 create_test_verb(".shlexec", "NoQuotesAllParams", 0, "NoQuotesAllParams %*");
2412 create_test_verb(".shlexec", "QuotedAllParams", 0, "QuotedAllParams \"%*\"");
2414 create_test_verb(".shlexec", "NoQuotesParams345etc", 0, "NoQuotesParams345etc %~3");
2415 create_test_verb(".shlexec", "QuotedParams345etc", 0, "QuotedParams345etc \"%~3\"");
2418 static void cleanup_test(void)
2420 char filename[MAX_PATH];
2421 const char* const * testfile;
2423 /* Delete the test files */
2427 sprintf(filename, *testfile, tmpdir);
2428 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2429 SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
2430 DeleteFile(filename);
2433 DeleteFile(child_file);
2434 RemoveDirectoryA(tmpdir);
2436 /* Delete the test association */
2437 delete_test_association(".shlexec");
2439 CloseHandle(hEvent);
2444 static void test_directory(void)
2446 char path[MAX_PATH], newdir[MAX_PATH];
2450 /* copy this executable to a new folder and cd to it */
2451 sprintf(newdir, "%s\\newfolder", tmpdir);
2452 rc = CreateDirectoryA( newdir, NULL );
2453 ok( rc, "failed to create %s err %u\n", newdir, GetLastError() );
2454 sprintf(path, "%s\\%s", newdir, path_find_file_name(argv0));
2455 CopyFileA(argv0, path, FALSE);
2456 SetCurrentDirectory(tmpdir);
2458 sprintf(params, "shlexec \"%s\" Exec", child_file);
2460 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2461 NULL, path_find_file_name(argv0), params, NULL);
2462 todo_wine ok(rc == SE_ERR_FNF, "%s returned %lu\n", shell_call, rc);
2464 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2465 NULL, path_find_file_name(argv0), params, newdir);
2466 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
2467 okChildInt("argcA", 4);
2468 okChildString("argvA3", "Exec");
2469 todo_wine okChildPath("longPath", path);
2472 RemoveDirectoryA(newdir);
2478 myARGC = winetest_get_mainargs(&myARGV);
2481 doChild(myARGC, myARGV);
2487 test_commandline2argv();
2489 test_lpFile_parsed();
2492 test_find_executable();
2497 test_dde_default_app();