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 bad_shellexecute = 0;
94 static INT_PTR shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
96 INT_PTR rc, rcEmpty = 0;
99 rcEmpty = shell_execute("", file, parameters, directory);
101 strcpy(shell_call, "ShellExecute(");
102 strcat_param(shell_call, operation);
103 strcat(shell_call, ", ");
104 strcat_param(shell_call, file);
105 strcat(shell_call, ", ");
106 strcat_param(shell_call, parameters);
107 strcat(shell_call, ", ");
108 strcat_param(shell_call, directory);
109 strcat(shell_call, ")");
110 if (winetest_debug > 1)
111 trace("%s\n", shell_call);
113 DeleteFile(child_file);
114 SetLastError(0xcafebabe);
116 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
117 * association it displays the 'Open With' dialog and I could not find
118 * a flag to prevent this.
120 rc=(INT_PTR)ShellExecute(NULL, operation, file, parameters, directory, SW_SHOWNORMAL);
125 wait_rc=WaitForSingleObject(hEvent, 5000);
126 if (wait_rc == WAIT_TIMEOUT)
128 HWND wnd = FindWindowA("#32770", "Windows");
131 SendMessage(wnd, WM_CLOSE, 0, 0);
132 win_skip("Skipping shellexecute of file with unassociated extension\n");
133 skip_noassoc_tests = TRUE;
137 ok(wait_rc==WAIT_OBJECT_0 || rc <= 32, "%s WaitForSingleObject returned %d\n", shell_call, wait_rc);
139 /* The child process may have changed the result file, so let profile
140 * functions know about it
142 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
148 if (rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */
149 bad_shellexecute = 1;
150 ok(rc == rcEmpty || broken(rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */,
151 "%s Got different return value with empty string: %lu %lu\n", shell_call, rc, rcEmpty);
157 static INT_PTR shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
158 LPCSTR parameters, LPCSTR directory)
160 SHELLEXECUTEINFO sei;
164 strcpy(shell_call, "ShellExecuteEx(");
165 strcat_param(shell_call, operation);
166 strcat(shell_call, ", ");
167 strcat_param(shell_call, file);
168 strcat(shell_call, ", ");
169 strcat_param(shell_call, parameters);
170 strcat(shell_call, ", ");
171 strcat_param(shell_call, directory);
172 strcat(shell_call, ")");
173 if (winetest_debug > 1)
174 trace("%s\n", shell_call);
176 sei.cbSize=sizeof(sei);
177 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
179 sei.lpVerb=operation;
181 sei.lpParameters=parameters;
182 sei.lpDirectory=directory;
183 sei.nShow=SW_SHOWNORMAL;
184 sei.hInstApp=NULL; /* Out */
190 sei.hProcess=NULL; /* Out */
192 DeleteFile(child_file);
193 SetLastError(0xcafebabe);
194 success=ShellExecuteEx(&sei);
195 rc=(INT_PTR)sei.hInstApp;
196 ok((success && rc > 32) || (!success && rc <= 32),
197 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call, success, rc);
202 if (sei.hProcess!=NULL)
204 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
205 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
207 wait_rc=WaitForSingleObject(hEvent, 5000);
208 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
210 /* The child process may have changed the result file, so let profile
211 * functions know about it
213 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
224 * Functions to create / delete associations wrappers
228 static BOOL create_test_association(const char* extension)
230 HKEY hkey, hkey_shell;
231 char class[MAX_PATH];
234 sprintf(class, "shlexec%s", extension);
235 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
237 if (rc != ERROR_SUCCESS)
240 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
241 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
244 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
245 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
246 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
248 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
249 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
250 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
253 CloseHandle(hkey_shell);
258 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
259 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
262 DWORD dwMaxSubkeyLen, dwMaxValueLen;
263 DWORD dwMaxLen, dwSize;
264 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
269 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
273 /* Get highest length for keys, values */
274 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
275 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
276 if (ret) goto cleanup;
280 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
281 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
283 /* Name too big: alloc a buffer for it */
284 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
286 ret = ERROR_NOT_ENOUGH_MEMORY;
292 /* Recursively delete all the subkeys */
296 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
297 NULL, NULL, NULL)) break;
299 ret = myRegDeleteTreeA(hSubKey, lpszName);
300 if (ret) goto cleanup;
304 ret = RegDeleteKeyA(hKey, lpszSubKey);
309 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
310 NULL, NULL, NULL, NULL)) break;
312 ret = RegDeleteValueA(hKey, lpszName);
313 if (ret) goto cleanup;
317 /* Free buffer if allocated */
318 if (lpszName != szNameBuf)
319 HeapFree( GetProcessHeap(), 0, lpszName);
321 RegCloseKey(hSubKey);
325 static void delete_test_association(const char* extension)
327 char class[MAX_PATH];
329 sprintf(class, "shlexec%s", extension);
330 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
331 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
334 static void create_test_verb_dde(const char* extension, const char* verb,
335 int rawcmd, const char* cmdtail, const char *ddeexec,
336 const char *application, const char *topic,
339 HKEY hkey_shell, hkey_verb, hkey_cmd;
340 char shell[MAX_PATH];
344 sprintf(shell, "shlexec%s\\shell", extension);
345 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
346 KEY_CREATE_SUB_KEY, &hkey_shell);
347 assert(rc==ERROR_SUCCESS);
348 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
349 NULL, &hkey_verb, NULL);
350 assert(rc==ERROR_SUCCESS);
351 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
352 NULL, &hkey_cmd, NULL);
353 assert(rc==ERROR_SUCCESS);
357 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
361 cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
362 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
363 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
364 assert(rc==ERROR_SUCCESS);
365 HeapFree(GetProcessHeap(), 0, cmd);
370 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
372 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
373 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
374 assert(rc==ERROR_SUCCESS);
375 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
377 assert(rc==ERROR_SUCCESS);
380 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
381 NULL, &hkey_application, NULL);
382 assert(rc==ERROR_SUCCESS);
383 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
384 strlen(application)+1);
385 assert(rc==ERROR_SUCCESS);
386 CloseHandle(hkey_application);
390 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
391 NULL, &hkey_topic, NULL);
392 assert(rc==ERROR_SUCCESS);
393 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
395 assert(rc==ERROR_SUCCESS);
396 CloseHandle(hkey_topic);
400 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
401 NULL, &hkey_ifexec, NULL);
402 assert(rc==ERROR_SUCCESS);
403 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
405 assert(rc==ERROR_SUCCESS);
406 CloseHandle(hkey_ifexec);
408 CloseHandle(hkey_ddeexec);
411 CloseHandle(hkey_shell);
412 CloseHandle(hkey_verb);
413 CloseHandle(hkey_cmd);
416 static void create_test_verb(const char* extension, const char* verb,
417 int rawcmd, const char* cmdtail)
419 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
425 * Functions to check that the child process was started just right
426 * (borrowed from dlls/kernel32/tests/process.c)
430 static const char* encodeA(const char* str)
432 static char encoded[2*1024+1];
437 len = strlen(str) + 1;
438 if (len >= sizeof(encoded)/2)
440 fprintf(stderr, "string is too long!\n");
444 for (i = 0; i < len; i++)
445 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
450 static unsigned decode_char(char c)
452 if (c >= '0' && c <= '9') return c - '0';
453 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
454 assert(c >= 'A' && c <= 'F');
458 static char* decodeA(const char* str)
460 static char decoded[1024];
464 len = strlen(str) / 2;
465 if (!len--) return NULL;
466 if (len >= sizeof(decoded))
468 fprintf(stderr, "string is too long!\n");
472 for (i = 0; i < len; i++)
473 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
478 static void childPrintf(HANDLE h, const char* fmt, ...)
484 va_start(valist, fmt);
485 vsprintf(buffer, fmt, valist);
487 WriteFile(h, buffer, strlen(buffer), &w, NULL);
490 static DWORD ddeInst;
492 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
493 static BOOL post_quit_on_execute;
495 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
496 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
497 ULONG_PTR dwData1, ULONG_PTR dwData2)
501 if (winetest_debug > 2)
502 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
503 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
508 if (!DdeCmpStringHandles(hsz1, hszTopic))
510 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
511 assert(size < MAX_PATH);
512 return (HDDEDATA)TRUE;
514 return (HDDEDATA)FALSE;
517 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
518 assert(size < MAX_PATH);
519 DdeFreeDataHandle(hData);
520 if (post_quit_on_execute)
522 return (HDDEDATA)DDE_FACK;
530 * This is just to make sure the child won't run forever stuck in a GetMessage()
531 * loop when DDE fails for some reason.
533 static void CALLBACK childTimeout(HWND wnd, UINT msg, UINT_PTR timer, DWORD time)
535 trace("childTimeout called\n");
540 static void doChild(int argc, char** argv)
542 char *filename, longpath[MAX_PATH] = "";
553 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
554 if (hFile == INVALID_HANDLE_VALUE)
558 childPrintf(hFile, "[Arguments]\r\n");
559 if (winetest_debug > 2)
560 trace("argcA=%d\n", argc);
561 childPrintf(hFile, "argcA=%d\r\n", argc);
562 for (i = 0; i < argc; i++)
564 if (winetest_debug > 2)
565 trace("argvA%d=%s\n", i, argv[i]);
566 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
568 GetModuleFileNameA(GetModuleHandleA(NULL), longpath, MAX_PATH);
569 childPrintf(hFile, "longPath=%s\r\n", encodeA(longpath));
571 map = OpenFileMappingA(FILE_MAP_READ, FALSE, "winetest_shlexec_dde_map");
574 shared_block = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 4096);
576 if (shared_block[0] != '\0' || shared_block[1] != '\0')
578 post_quit_on_execute = TRUE;
580 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
581 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
582 assert(rc == DMLERR_NO_ERROR);
583 hszApplication = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
584 hszTopic = DdeCreateStringHandleA(ddeInst, shared_block + strlen(shared_block) + 1, CP_WINANSI);
585 assert(hszApplication && hszTopic);
586 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
588 timer = SetTimer(NULL, 0, 2500, childTimeout);
590 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
592 CloseHandle(dde_ready);
594 while (GetMessage(&msg, NULL, 0, 0))
595 DispatchMessage(&msg);
598 KillTimer(NULL, timer);
599 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
600 assert(DdeFreeStringHandle(ddeInst, hszTopic));
601 assert(DdeFreeStringHandle(ddeInst, hszApplication));
602 assert(DdeUninitialize(ddeInst));
606 dde_ready = OpenEvent(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
608 CloseHandle(dde_ready);
611 UnmapViewOfFile(shared_block);
613 childPrintf(hFile, "ddeExec=%s\r\n", encodeA(ddeExec));
618 init_event(filename);
623 static char* getChildString(const char* sect, const char* key)
628 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
629 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
630 assert(!(strlen(buf) & 1));
635 static void dump_child(void)
637 if (winetest_debug > 1)
643 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
644 trace("argcA=%d\n",c);
647 sprintf(key, "argvA%d", i);
648 str=getChildString("Arguments", key);
649 trace("%s=%s\n", key, str);
654 static int StrCmpPath(const char* s1, const char* s2)
656 if (!s1 && !s2) return 0;
667 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
669 while (*s1=='/' || *s1=='\\')
671 while (*s2=='/' || *s2=='\\')
674 else if (toupper(*s1)==toupper(*s2))
691 static void _okChildString(const char* file, int line, const char* key, const char* expected)
694 result=getChildString("Arguments", key);
697 ok_(file, line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
700 ok_(file, line)(lstrcmpiA(result, expected) == 0,
701 "%s expected '%s', got '%s'\n", key, expected, result);
704 static void _okChildPath(const char* file, int line, const char* key, const char* expected)
707 result=getChildString("Arguments", key);
710 ok_(file, line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
713 ok_(file, line)(StrCmpPath(result, expected) == 0,
714 "%s expected '%s', got '%s'\n", key, expected, result);
717 static void _okChildInt(const char* file, int line, const char* key, int expected)
720 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
721 ok_(file, line)(result == expected,
722 "%s expected %d, but got %d\n", key, expected, result);
725 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
726 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
727 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
731 * GetLongPathNameA equivalent that supports Win95 and WinNT
735 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
737 char tmplongpath[MAX_PATH];
739 DWORD sp = 0, lp = 0;
741 WIN32_FIND_DATAA wfd;
744 if (!shortpath || !shortpath[0])
747 if (shortpath[1] == ':')
749 tmplongpath[0] = shortpath[0];
750 tmplongpath[1] = ':';
754 while (shortpath[sp])
756 /* check for path delimiters and reproduce them */
757 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
759 if (!lp || tmplongpath[lp-1] != '\\')
761 /* strip double "\\" */
762 tmplongpath[lp++] = '\\';
764 tmplongpath[lp] = 0; /* terminate string */
770 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
772 tmplongpath[lp++] = *p++;
773 tmplongpath[lp++] = *p++;
775 for (; *p && *p != '/' && *p != '\\'; p++);
776 tmplen = p - (shortpath + sp);
777 lstrcpyn(tmplongpath + lp, shortpath + sp, tmplen + 1);
778 /* Check if the file exists and use the existing file name */
779 goit = FindFirstFileA(tmplongpath, &wfd);
780 if (goit == INVALID_HANDLE_VALUE)
783 strcpy(tmplongpath + lp, wfd.cFileName);
784 lp += strlen(tmplongpath + lp);
787 tmplen = strlen(shortpath) - 1;
788 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
789 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
790 tmplongpath[lp++] = shortpath[tmplen];
793 tmplen = strlen(tmplongpath) + 1;
794 if (tmplen <= longlen)
796 strcpy(longpath, tmplongpath);
797 tmplen--; /* length without 0 */
805 * PathFindFileNameA equivalent that supports WinNT
809 static LPSTR path_find_file_name(LPCSTR lpszPath)
811 LPCSTR lastSlash = lpszPath;
813 while (lpszPath && *lpszPath)
815 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
816 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
817 lastSlash = lpszPath + 1;
818 lpszPath = CharNext(lpszPath);
820 return (LPSTR)lastSlash;
829 static const char* testfiles[]=
831 "%s\\test file.shlexec",
832 "%s\\%%nasty%% $file.shlexec",
833 "%s\\test file.noassoc",
834 "%s\\test file.noassoc.shlexec",
835 "%s\\test file.shlexec.noassoc",
836 "%s\\test_shortcut_shlexec.lnk",
837 "%s\\test_shortcut_exe.lnk",
839 "%s\\test file.shlfoo",
841 "%s\\masked file.shlexec",
846 "%s\\simple.shlexec",
847 "%s\\drawback_file.noassoc",
848 "%s\\drawback_file.noassoc foo.shlexec",
849 "%s\\drawback_nonexist.noassoc foo.shlexec",
856 const char* basename;
861 static filename_tests_t filename_tests[]=
863 /* Test bad / nonexistent filenames */
864 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
865 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
868 {NULL, "%s\\test file.shlexec", 0x0, 33},
869 {NULL, "%s\\test file.shlexec.", 0x0, 33},
870 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
871 {NULL, "%s/test file.shlexec", 0x0, 33},
873 /* Test filenames with no association */
874 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
876 /* Test double extensions */
877 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
878 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
880 /* Test alternate verbs */
881 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
882 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
884 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
885 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
887 /* Test file masked due to space */
888 {NULL, "%s\\masked file.shlexec", 0x1, 33},
889 /* Test if quoting prevents the masking */
890 {NULL, "%s\\masked file.shlexec", 0x40, 33},
895 static filename_tests_t noquotes_tests[]=
897 /* Test unquoted '%1' thingies */
898 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
899 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
900 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
905 static void test_lpFile_parsed(void)
907 /* basename tmpdir */
908 const char* shorttmpdir;
909 const char *testfile;
910 char fileA[MAX_PATH];
913 GetTempPathA(sizeof(fileA), fileA);
914 shorttmpdir = tmpdir + strlen(fileA);
916 /* ensure tmpdir is in %TEMP%: GetTempPath() can succeed even if TEMP is undefined */
917 SetEnvironmentVariableA("TEMP", fileA);
919 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
920 testfile = "%s\\drawback_file.noassoc foo.shlexec";
921 sprintf(fileA, testfile, tmpdir);
922 rc=shell_execute(NULL, fileA, NULL, NULL);
925 "expected success (33), got %s (%lu), lpFile: %s\n",
926 rc > 32 ? "success" : "failure", rc, fileA
930 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
931 testfile = "\"%s\\drawback_file.noassoc foo.shlexec\"";
932 sprintf(fileA, testfile, tmpdir);
933 rc=shell_execute(NULL, fileA, NULL, NULL);
934 ok(rc>32 || broken(rc == 2) /* Win95/NT4 */,
935 "expected success (33), got %s (%lu), lpFile: %s\n",
936 rc > 32 ? "success" : "failure", rc, fileA
939 /* error should be 2, not 31 */
940 testfile = "\"%s\\drawback_file.noassoc\" foo.shlexec";
941 sprintf(fileA, testfile, tmpdir);
942 rc=shell_execute(NULL, fileA, NULL, NULL);
944 "expected failure (2), got %s (%lu), lpFile: %s\n",
945 rc > 32 ? "success" : "failure", rc, fileA
948 /* ""command"" not works on wine (and real win9x and w2k) */
949 testfile = "\"\"%s\\simple.shlexec\"\"";
950 sprintf(fileA, testfile, tmpdir);
951 rc=shell_execute(NULL, fileA, NULL, NULL);
953 ok(rc>32 || broken(rc == 2) /* Win9x/2000 */,
954 "expected success (33), got %s (%lu), lpFile: %s\n",
955 rc > 32 ? "success" : "failure", rc, fileA
959 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
960 testfile = "%s\\drawback_nonexist.noassoc foo.shlexec";
961 sprintf(fileA, testfile, tmpdir);
962 rc=shell_execute(NULL, fileA, NULL, NULL);
964 "expected success (33), got %s (%lu), lpFile: %s\n",
965 rc > 32 ? "success" : "failure", rc, fileA
968 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
969 testfile = "%%TEMP%%\\%s\\simple.shlexec";
970 sprintf(fileA, testfile, shorttmpdir);
971 rc=shell_execute(NULL, fileA, NULL, NULL);
974 "expected failure (2), got %s (%lu), lpFile: %s\n",
975 rc > 32 ? "success" : "failure", rc, fileA
980 testfile = "\"%%TEMP%%\\%s\\simple.shlexec\"";
981 sprintf(fileA, testfile, shorttmpdir);
982 rc=shell_execute(NULL, fileA, NULL, NULL);
985 "expected failure (2), got %s (%lu), lpFile: %s\n",
986 rc > 32 ? "success" : "failure", rc, fileA
990 /* test SEE_MASK_DOENVSUBST works */
991 testfile = "%%TEMP%%\\%s\\simple.shlexec";
992 sprintf(fileA, testfile, shorttmpdir);
993 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI, NULL, fileA, NULL, NULL);
995 "expected success (33), got %s (%lu), lpFile: %s\n",
996 rc > 32 ? "success" : "failure", rc, fileA
999 /* quoted lpFile not works only on real win95 and nt4 */
1000 testfile = "\"%%TEMP%%\\%s\\simple.shlexec\"";
1001 sprintf(fileA, testfile, shorttmpdir);
1002 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI, NULL, fileA, NULL, NULL);
1003 ok(rc>32 || broken(rc == 2) /* Win95/NT4 */,
1004 "expected success (33), got %s (%lu), lpFile: %s\n",
1005 rc > 32 ? "success" : "failure", rc, fileA
1010 static void test_argify(void)
1012 char fileA[MAX_PATH];
1015 sprintf(fileA, "%s\\test file.shlexec", tmpdir);
1018 rc=shell_execute("NoQuotesParam2", fileA, "a b", NULL);
1020 "expected success (33), got %s (%lu), lpFile: %s\n",
1021 rc > 32 ? "success" : "failure", rc, fileA
1025 okChildInt("argcA", 5);
1026 okChildString("argvA4", "a");
1030 /* '"a"""' -> 'a"' */
1031 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\"\"some string\"\"\"", NULL);
1033 "expected success (33), got %s (%lu), lpFile: %s\n",
1034 rc > 32 ? "success" : "failure", rc, fileA
1038 okChildInt("argcA", 5);
1040 okChildString("argvA4", "a:some string");
1045 /* backslash isn't escape char
1046 * '"a\""' -> '"a\""' */
1047 rc=shell_execute("NoQuotesParam2", fileA, "\"a:\\\"some string\\\"\"", NULL);
1049 "expected success (33), got %s (%lu), lpFile: %s\n",
1050 rc > 32 ? "success" : "failure", rc, fileA
1054 okChildInt("argcA", 5);
1056 okChildString("argvA4", "a:\\");
1061 /* \t isn't whitespace */
1062 rc=shell_execute("QuotedParam2", fileA, "a\tb c", NULL);
1064 "expected success (33), got %s (%lu), lpFile: %s\n",
1065 rc > 32 ? "success" : "failure", rc, fileA
1069 okChildInt("argcA", 5);
1071 okChildString("argvA4", "a\tb");
1076 rc=shell_execute("NoQuotesAllParams", fileA, "a b c d e f g h", NULL);
1078 "expected success (33), got %s (%lu), lpFile: %s\n",
1079 rc > 32 ? "success" : "failure", rc, fileA
1084 okChildInt("argcA", 12);
1085 okChildString("argvA4", "a");
1086 okChildString("argvA11", "h");
1090 /* %* can sometimes contain only whitespaces and no args */
1091 rc=shell_execute("QuotedAllParams", fileA, " ", NULL);
1093 "expected success (33), got %s (%lu), lpFile: %s\n",
1094 rc > 32 ? "success" : "failure", rc, fileA
1099 okChildInt("argcA", 5);
1100 okChildString("argvA4", " ");
1105 rc=shell_execute("NoQuotesParams345etc", fileA, "a b c d e f g h", NULL);
1107 "expected success (33), got %s (%lu), lpFile: %s\n",
1108 rc > 32 ? "success" : "failure", rc, fileA
1113 okChildInt("argcA", 11);
1114 okChildString("argvA4", "b");
1115 okChildString("argvA10", "h");
1119 /* %~3 is rest of command line starting with whitespaces after 2nd arg */
1120 rc=shell_execute("QuotedParams345etc", fileA, "a ", NULL);
1122 "expected success (33), got %s (%lu), lpFile: %s\n",
1123 rc > 32 ? "success" : "failure", rc, fileA
1127 okChildInt("argcA", 5);
1129 okChildString("argvA4", " ");
1135 static void test_filename(void)
1137 char filename[MAX_PATH];
1138 const filename_tests_t* test;
1142 test=filename_tests;
1143 while (test->basename)
1145 BOOL quotedfile = FALSE;
1147 if (skip_noassoc_tests && test->rc == SE_ERR_NOASSOC)
1149 win_skip("Skipping shellexecute of file with unassociated extension\n");
1154 sprintf(filename, test->basename, tmpdir);
1155 if (strchr(filename, '/'))
1165 if ((test->todo & 0x40)==0)
1167 rc=shell_execute(test->verb, filename, NULL, NULL);
1171 char quoted[MAX_PATH + 2];
1174 sprintf(quoted, "\"%s\"", filename);
1175 rc=shell_execute(test->verb, quoted, NULL, NULL);
1179 if ((test->todo & 0x1)==0)
1182 broken(quotedfile && rc == 2), /* NT4 */
1183 "%s failed: rc=%d err=%u\n", shell_call,
1184 rc, GetLastError());
1188 ok(rc==test->rc, "%s failed: rc=%d err=%u\n", shell_call,
1189 rc, GetLastError());
1194 if ((test->todo & 0x2)==0)
1196 okChildInt("argcA", 5);
1200 okChildInt("argcA", 5);
1202 verb=(test->verb ? test->verb : "Open");
1203 if ((test->todo & 0x4)==0)
1205 okChildString("argvA3", verb);
1209 okChildString("argvA3", verb);
1211 if ((test->todo & 0x8)==0)
1213 okChildPath("argvA4", filename);
1217 okChildPath("argvA4", filename);
1223 test=noquotes_tests;
1224 while (test->basename)
1226 sprintf(filename, test->basename, tmpdir);
1227 rc=shell_execute(test->verb, filename, NULL, NULL);
1230 if ((test->todo & 0x1)==0)
1232 ok(rc==test->rc, "%s failed: rc=%d err=%u\n", shell_call,
1233 rc, GetLastError());
1237 ok(rc==test->rc, "%s failed: rc=%d err=%u\n", shell_call,
1238 rc, GetLastError());
1246 verb=(test->verb ? test->verb : "Open");
1247 if ((test->todo & 0x4)==0)
1249 okChildString("argvA3", verb);
1253 okChildString("argvA3", verb);
1262 space=strchr(str, ' ');
1265 sprintf(attrib, "argvA%d", count);
1266 if ((test->todo & 0x8)==0)
1268 okChildPath(attrib, str);
1272 okChildPath(attrib, str);
1279 if ((test->todo & 0x2)==0)
1281 okChildInt("argcA", count);
1285 okChildInt("argcA", count);
1291 if (dllver.dwMajorVersion != 0)
1293 /* The more recent versions of shell32.dll accept quoted filenames
1294 * while older ones (e.g. 4.00) don't. Still we want to test this
1295 * because IE 6 depends on the new behavior.
1296 * One day we may need to check the exact version of the dll but for
1297 * now making sure DllGetVersion() is present is sufficient.
1299 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
1300 rc=shell_execute(NULL, filename, NULL, NULL);
1301 ok(rc > 32, "%s failed: rc=%d err=%u\n", shell_call, rc,
1303 okChildInt("argcA", 5);
1304 okChildString("argvA3", "Open");
1305 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1306 okChildPath("argvA4", filename);
1312 const char* urlprefix;
1313 const char* basename;
1318 #define URL_SUCCESS 0x1
1319 #define USE_COLON 0x2
1320 #define USE_BSLASH 0x4
1322 static fileurl_tests_t fileurl_tests[]=
1324 /* How many slashes does it take... */
1325 {"file:", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1326 {"file:/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1327 {"file://", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1328 {"file:///", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1329 {"File:///", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1330 {"file:////", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1331 {"file://///", "%s\\test file.shlexec", 0, 0x1},
1333 /* Test with Windows-style paths */
1334 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_COLON, 0x1},
1335 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_BSLASH, 0x1},
1337 /* Check handling of hostnames */
1338 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1339 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0x1},
1340 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS, 0x1},
1341 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0x1},
1342 {"file://::1/", "%s\\test file.shlexec", 0, 0x1},
1343 {"file://notahost/", "%s\\test file.shlexec", 0, 0x1},
1345 /* Environment variables are not expanded in URLs */
1346 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1347 {"file:///", "%s\\%%urlenvvar%% file.shlexec", 0, 0x1},
1352 static void test_fileurl(void)
1354 char filename[MAX_PATH], fileurl[MAX_PATH], longtmpdir[MAX_PATH];
1355 char command[MAX_PATH];
1356 const fileurl_tests_t* test;
1360 rc = (INT_PTR)ShellExecute(NULL, NULL, "file:///nosuchfile.shlexec", NULL, NULL, SW_SHOWNORMAL);
1363 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1367 get_long_path_name(tmpdir, longtmpdir, sizeof(longtmpdir)/sizeof(*longtmpdir));
1368 SetEnvironmentVariable("urlprefix", "file:///");
1369 SetEnvironmentVariable("urlenvvar", "test");
1372 while (test->basename)
1374 /* Build the file URL */
1375 sprintf(filename, test->basename, longtmpdir);
1376 strcpy(fileurl, test->urlprefix);
1377 strcat(fileurl, filename);
1378 s = fileurl + strlen(test->urlprefix);
1381 if (!(test->flags & USE_COLON) && *s == ':')
1383 else if (!(test->flags & USE_BSLASH) && *s == '\\')
1388 /* Test it first with FindExecutable() */
1389 rc = (INT_PTR)FindExecutableA(fileurl, NULL, command);
1390 ok(rc == SE_ERR_FNF, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl, rc);
1392 /* Then ShellExecute() */
1393 rc = shell_execute(NULL, fileurl, NULL, NULL);
1394 if (bad_shellexecute)
1396 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1399 if (test->flags & URL_SUCCESS)
1401 if ((test->todo & 0x1) == 0)
1402 ok(rc > 32, "%s failed: bad rc=%lu\n", shell_call, rc);
1404 ok(rc > 32, "%s failed: bad rc=%lu\n", shell_call, rc);
1408 if ((test->todo & 0x1) == 0)
1409 ok(rc == SE_ERR_FNF || rc == SE_ERR_PNF ||
1410 broken(rc == SE_ERR_ACCESSDENIED) /* win2000 */,
1411 "%s failed: bad rc=%lu\n", shell_call, rc);
1413 ok(rc == SE_ERR_FNF || rc == SE_ERR_PNF ||
1414 broken(rc == SE_ERR_ACCESSDENIED) /* win2000 */,
1415 "%s failed: bad rc=%lu\n", shell_call, rc);
1419 if ((test->todo & 0x2) == 0)
1420 okChildInt("argcA", 5);
1422 okChildInt("argcA", 5);
1424 if ((test->todo & 0x4) == 0)
1425 okChildString("argvA3", "Open");
1427 okChildString("argvA3", "Open");
1429 if ((test->todo & 0x8) == 0)
1430 okChildPath("argvA4", filename);
1432 okChildPath("argvA4", filename);
1437 SetEnvironmentVariable("urlprefix", NULL);
1438 SetEnvironmentVariable("urlenvvar", NULL);
1441 static void test_find_executable(void)
1443 char notepad_path[MAX_PATH];
1444 char filename[MAX_PATH];
1445 char command[MAX_PATH];
1446 const filename_tests_t* test;
1449 if (!create_test_association(".sfe"))
1451 skip("Unable to create association for '.sfe'\n");
1454 create_test_verb(".sfe", "Open", 1, "%1");
1456 /* Don't test FindExecutable(..., NULL), it always crashes */
1458 strcpy(command, "your word");
1459 if (0) /* Can crash on Vista! */
1461 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
1462 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1463 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1466 GetSystemDirectoryA( notepad_path, MAX_PATH );
1467 strcat( notepad_path, "\\notepad.exe" );
1469 /* Search for something that should be in the system-wide search path (no default directory) */
1470 strcpy(command, "your word");
1471 rc=(INT_PTR)FindExecutableA("notepad.exe", NULL, command);
1472 ok(rc > 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc);
1473 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
1475 /* Search for something that should be in the system-wide search path (with default directory) */
1476 strcpy(command, "your word");
1477 rc=(INT_PTR)FindExecutableA("notepad.exe", tmpdir, command);
1478 ok(rc > 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc);
1479 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
1481 strcpy(command, "your word");
1482 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
1483 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1484 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1486 sprintf(filename, "%s\\test file.sfe", tmpdir);
1487 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1488 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1489 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1491 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
1492 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1494 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
1495 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %ld\n", filename, rc);
1497 delete_test_association(".sfe");
1499 if (!create_test_association(".shl"))
1501 skip("Unable to create association for '.shl'\n");
1504 create_test_verb(".shl", "Open", 0, "Open");
1506 sprintf(filename, "%s\\test file.shl", tmpdir);
1507 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1508 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1510 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
1511 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1513 delete_test_association(".shl");
1517 /* On Windows XP and 2003 FindExecutable() is completely broken.
1518 * Probably what it does is convert the filename to 8.3 format,
1519 * which as a side effect converts the '.shlfoo' extension to '.shl',
1520 * and then tries to find an association for '.shl'. This means it
1521 * will normally fail on most extensions with more than 3 characters,
1522 * like '.mpeg', etc.
1523 * Also it means we cannot do any other test.
1525 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
1529 test=filename_tests;
1530 while (test->basename)
1532 sprintf(filename, test->basename, tmpdir);
1533 if (strchr(filename, '/'))
1544 /* Win98 does not '\0'-terminate command! */
1545 memset(command, '\0', sizeof(command));
1546 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1549 if ((test->todo & 0x10)==0)
1551 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1555 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1560 equal=strcmp(command, argv0) == 0 ||
1561 /* NT4 returns an extra 0x8 character! */
1562 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
1563 if ((test->todo & 0x20)==0)
1565 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1566 filename, command, argv0);
1570 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1571 filename, command, argv0);
1579 static filename_tests_t lnk_tests[]=
1581 /* Pass bad / nonexistent filenames as a parameter */
1582 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
1583 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
1585 /* Pass regular paths as a parameter */
1586 {NULL, "%s\\test file.shlexec", 0xa, 33},
1587 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1589 /* Pass filenames with no association as a parameter */
1590 {NULL, "%s\\test file.noassoc", 0xa, 33},
1595 static void test_lnks(void)
1597 char filename[MAX_PATH];
1598 char params[MAX_PATH];
1599 const filename_tests_t* test;
1602 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1603 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1604 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1606 okChildInt("argcA", 5);
1607 okChildString("argvA3", "Open");
1608 sprintf(params, "%s\\test file.shlexec", tmpdir);
1609 get_long_path_name(params, filename, sizeof(filename));
1610 okChildPath("argvA4", filename);
1612 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1613 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1614 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1616 okChildInt("argcA", 4);
1617 okChildString("argvA3", "Lnk");
1619 if (dllver.dwMajorVersion>=6)
1622 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1623 * Older versions don't or are quite buggy in this regard.
1625 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1633 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1634 ok(rc > 32, "%s failed: rc=%lu err=%u\n", shell_call, rc,
1636 okChildInt("argcA", 4);
1637 okChildString("argvA3", "Lnk");
1640 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1642 while (test->basename)
1645 sprintf(params+1, test->basename, tmpdir);
1646 strcat(params,"\"");
1647 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1651 if ((test->todo & 0x1)==0)
1653 ok(rc==test->rc, "%s failed: rc=%lu err=%u\n", shell_call,
1654 rc, GetLastError());
1658 ok(rc==test->rc, "%s failed: rc=%lu err=%u\n", shell_call,
1659 rc, GetLastError());
1663 if ((test->todo & 0x2)==0)
1665 okChildInt("argcA", 5);
1669 okChildInt("argcA", 5);
1671 if ((test->todo & 0x4)==0)
1673 okChildString("argvA3", "Lnk");
1677 okChildString("argvA3", "Lnk");
1679 sprintf(params, test->basename, tmpdir);
1680 if ((test->todo & 0x8)==0)
1682 okChildPath("argvA4", params);
1686 okChildPath("argvA4", params);
1694 static void test_exes(void)
1696 char filename[MAX_PATH];
1700 sprintf(params, "shlexec \"%s\" Exec", child_file);
1702 /* We need NOZONECHECKS on Win2003 to block a dialog */
1703 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1705 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
1706 okChildInt("argcA", 4);
1707 okChildString("argvA3", "Exec");
1709 if (! skip_noassoc_tests)
1711 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1712 if (CopyFile(argv0, filename, FALSE))
1714 rc=shell_execute(NULL, filename, params, NULL);
1716 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%lu\n", shell_call, rc);
1722 win_skip("Skipping shellexecute of file with unassociated extension\n");
1726 static void test_exes_long(void)
1728 char filename[MAX_PATH];
1730 char longparam[MAX_PATH];
1733 for (rc = 0; rc < MAX_PATH; rc++)
1734 longparam[rc]='a'+rc%26;
1735 longparam[MAX_PATH-1]=0;
1738 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1740 /* We need NOZONECHECKS on Win2003 to block a dialog */
1741 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1743 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
1744 okChildInt("argcA", 4);
1745 okChildString("argvA3", longparam);
1747 if (! skip_noassoc_tests)
1749 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1750 if (CopyFile(argv0, filename, FALSE))
1752 rc=shell_execute(NULL, filename, params, NULL);
1754 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%lu\n", shell_call, rc);
1760 win_skip("Skipping shellexecute of file with unassociated extension\n");
1766 const char* command;
1767 const char* ddeexec;
1768 const char* application;
1772 const char* expectedDdeExec;
1776 static dde_tests_t dde_tests[] =
1778 /* Test passing and not passing command-line
1779 * argument, no DDE */
1780 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0},
1781 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0},
1783 /* Test passing and not passing command-line
1784 * argument, with DDE */
1785 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1786 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0},
1788 /* Test unquoted %1 in command and ddeexec
1789 * (test filename has space) */
1790 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0},
1792 /* Test ifexec precedence over ddeexec */
1793 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0},
1795 /* Test default DDE topic */
1796 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0},
1798 /* Test default DDE application */
1799 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1801 {NULL, NULL, NULL, NULL, NULL, 0, 0x0}
1804 static DWORD WINAPI hooked_WaitForInputIdle(HANDLE process, DWORD timeout)
1806 return WaitForSingleObject(dde_ready_event, timeout);
1810 * WaitForInputIdle() will normally return immediately for console apps. That's
1811 * a problem for us because ShellExecute will assume that an app is ready to
1812 * receive DDE messages after it has called WaitForInputIdle() on that app.
1813 * To work around that we install our own version of WaitForInputIdle() that
1814 * will wait for the child to explicitly tell us that it is ready. We do that
1815 * by changing the entry for WaitForInputIdle() in the shell32 import address
1818 static void hook_WaitForInputIdle(DWORD (WINAPI *new_func)(HANDLE, DWORD))
1821 PIMAGE_NT_HEADERS nt_headers;
1822 DWORD import_directory_rva;
1823 PIMAGE_IMPORT_DESCRIPTOR import_descriptor;
1825 base = (char *) GetModuleHandleA("shell32.dll");
1826 nt_headers = (PIMAGE_NT_HEADERS)(base + ((PIMAGE_DOS_HEADER) base)->e_lfanew);
1827 import_directory_rva = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
1829 /* Search for the correct imported module by walking the import descriptors */
1830 import_descriptor = (PIMAGE_IMPORT_DESCRIPTOR)(base + import_directory_rva);
1831 while (U(*import_descriptor).OriginalFirstThunk != 0)
1833 char *import_module_name;
1835 import_module_name = base + import_descriptor->Name;
1836 if (lstrcmpiA(import_module_name, "user32.dll") == 0 ||
1837 lstrcmpiA(import_module_name, "user32") == 0)
1839 PIMAGE_THUNK_DATA int_entry;
1840 PIMAGE_THUNK_DATA iat_entry;
1842 /* The import name table and import address table are two parallel
1843 * arrays. We need the import name table to find the imported
1844 * routine and the import address table to patch the address, so
1845 * walk them side by side */
1846 int_entry = (PIMAGE_THUNK_DATA)(base + U(*import_descriptor).OriginalFirstThunk);
1847 iat_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->FirstThunk);
1848 while (int_entry->u1.Ordinal != 0)
1850 if (! IMAGE_SNAP_BY_ORDINAL(int_entry->u1.Ordinal))
1852 PIMAGE_IMPORT_BY_NAME import_by_name;
1853 import_by_name = (PIMAGE_IMPORT_BY_NAME)(base + int_entry->u1.AddressOfData);
1854 if (lstrcmpA((char *) import_by_name->Name, "WaitForInputIdle") == 0)
1856 /* Found the correct routine in the correct imported module. Patch it. */
1858 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), PAGE_READWRITE, &old_prot);
1859 iat_entry->u1.Function = (ULONG_PTR) new_func;
1860 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), old_prot, &old_prot);
1870 import_descriptor++;
1874 static void test_dde(void)
1876 char filename[MAX_PATH], defApplication[MAX_PATH];
1877 const dde_tests_t* test;
1883 hook_WaitForInputIdle(hooked_WaitForInputIdle);
1885 sprintf(filename, "%s\\test file.sde", tmpdir);
1887 /* Default service is application name minus path and extension */
1888 strcpy(defApplication, strrchr(argv0, '\\')+1);
1889 *strchr(defApplication, '.') = 0;
1891 map = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
1892 4096, "winetest_shlexec_dde_map");
1893 shared_block = MapViewOfFile(map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 4096);
1896 while (test->command)
1898 if (!create_test_association(".sde"))
1900 skip("Unable to create association for '.sde'\n");
1903 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1904 test->application, test->topic, test->ifexec);
1906 if (test->application != NULL || test->topic != NULL)
1908 strcpy(shared_block, test->application ? test->application : defApplication);
1909 strcpy(shared_block + strlen(shared_block) + 1, test->topic ? test->topic : SZDDESYS_TOPIC);
1913 shared_block[0] = '\0';
1914 shared_block[1] = '\0';
1918 dde_ready_event = CreateEventA(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
1919 rc = shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, filename, NULL, NULL);
1920 CloseHandle(dde_ready_event);
1921 if ((test->todo & 0x1)==0)
1923 ok(32 < rc, "%s failed: rc=%lu err=%u\n", shell_call,
1924 rc, GetLastError());
1928 ok(32 < rc, "%s failed: rc=%lu err=%u\n", shell_call,
1929 rc, GetLastError());
1933 if ((test->todo & 0x2)==0)
1935 okChildInt("argcA", test->expectedArgs + 3);
1939 okChildInt("argcA", test->expectedArgs + 3);
1941 if (test->expectedArgs == 1)
1943 if ((test->todo & 0x4) == 0)
1945 okChildPath("argvA3", filename);
1949 okChildPath("argvA3", filename);
1952 if ((test->todo & 0x8) == 0)
1954 sprintf(params, test->expectedDdeExec, filename);
1955 okChildPath("ddeExec", params);
1959 sprintf(params, test->expectedDdeExec, filename);
1960 okChildPath("ddeExec", params);
1964 delete_test_association(".sde");
1968 UnmapViewOfFile(shared_block);
1970 hook_WaitForInputIdle((void *) WaitForInputIdle);
1973 #define DDE_DEFAULT_APP_VARIANTS 2
1976 const char* command;
1977 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1979 int rc[DDE_DEFAULT_APP_VARIANTS];
1980 } dde_default_app_tests_t;
1982 static dde_default_app_tests_t dde_default_app_tests[] =
1984 /* Windows XP and 98 handle default DDE app names in different ways.
1985 * The application name we see in the first test determines the pattern
1986 * of application names and return codes we will look for. */
1988 /* Test unquoted existing filename with a space */
1989 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1990 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1992 /* Test quoted existing filename with a space */
1993 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1994 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1996 /* Test unquoted filename with a space that doesn't exist, but
1998 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1999 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
2001 /* Test quoted filename with a space that does not exist */
2002 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
2003 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
2005 /* Test filename supplied without the extension */
2006 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
2007 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
2009 /* Test an unquoted nonexistent filename */
2010 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
2011 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
2013 /* Test an application that will be found on the path */
2014 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
2015 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
2017 /* Test an application that will not be found on the path */
2018 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2019 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2021 {NULL, {NULL}, 0, {0}}
2027 DWORD threadIdParent;
2028 } dde_thread_info_t;
2030 static DWORD CALLBACK ddeThread(LPVOID arg)
2032 dde_thread_info_t *info = arg;
2033 assert(info && info->filename);
2034 PostThreadMessage(info->threadIdParent,
2036 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
2041 static void test_dde_default_app(void)
2043 char filename[MAX_PATH];
2045 dde_thread_info_t info = { filename, GetCurrentThreadId() };
2046 const dde_default_app_tests_t* test;
2053 post_quit_on_execute = FALSE;
2055 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
2056 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
2057 assert(rc == DMLERR_NO_ERROR);
2059 sprintf(filename, "%s\\test file.sde", tmpdir);
2061 /* It is strictly not necessary to register an application name here, but wine's
2062 * DdeNameService implementation complains if 0L is passed instead of
2063 * hszApplication with DNS_FILTEROFF */
2064 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2065 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2066 assert(hszApplication && hszTopic);
2067 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
2069 test = dde_default_app_tests;
2070 while (test->command)
2072 if (!create_test_association(".sde"))
2074 skip("Unable to create association for '.sde'\n");
2077 sprintf(params, test->command, tmpdir);
2078 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
2080 ddeApplication[0] = 0;
2082 /* No application will be run as we will respond to the first DDE event,
2083 * so don't wait for it */
2086 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
2087 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
2088 rc = msg.wParam > 32 ? 33 : msg.wParam;
2090 /* First test, find which set of test data we expect to see */
2091 if (test == dde_default_app_tests)
2094 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
2096 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
2102 if (i == DDE_DEFAULT_APP_VARIANTS)
2103 skip("Default DDE application test does not match any available results, using first expected data set.\n");
2106 if ((test->todo & 0x1)==0)
2108 ok(rc==test->rc[which], "%s failed: rc=%lu err=%u\n", shell_call,
2109 rc, GetLastError());
2113 ok(rc==test->rc[which], "%s failed: rc=%lu err=%u\n", shell_call,
2114 rc, GetLastError());
2118 if ((test->todo & 0x2)==0)
2120 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
2121 "Expected application '%s', got '%s'\n",
2122 test->expectedDdeApplication[which], ddeApplication);
2126 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
2127 "Expected application '%s', got '%s'\n",
2128 test->expectedDdeApplication[which], ddeApplication);
2132 delete_test_association(".sde");
2136 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
2137 assert(DdeFreeStringHandle(ddeInst, hszTopic));
2138 assert(DdeFreeStringHandle(ddeInst, hszApplication));
2139 assert(DdeUninitialize(ddeInst));
2142 static void init_test(void)
2145 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
2146 char filename[MAX_PATH];
2147 WCHAR lnkfile[MAX_PATH];
2149 const char* const * testfile;
2154 hdll=GetModuleHandleA("shell32.dll");
2155 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
2158 dllver.cbSize=sizeof(dllver);
2159 pDllGetVersion(&dllver);
2160 trace("major=%d minor=%d build=%d platform=%d\n",
2161 dllver.dwMajorVersion, dllver.dwMinorVersion,
2162 dllver.dwBuildNumber, dllver.dwPlatformID);
2166 memset(&dllver, 0, sizeof(dllver));
2169 r = CoInitialize(NULL);
2170 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
2174 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
2175 assert(rc!=0 && rc<sizeof(argv0));
2176 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
2178 strcat(argv0, ".so");
2179 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
2180 "unable to find argv0!\n");
2183 GetTempPathA(sizeof(filename), filename);
2184 GetTempFileNameA(filename, "wt", 0, tmpdir);
2185 DeleteFileA( tmpdir );
2186 rc = CreateDirectoryA( tmpdir, NULL );
2187 ok( rc, "failed to create %s err %u\n", tmpdir, GetLastError() );
2188 rc = GetTempFileNameA(tmpdir, "wt", 0, child_file);
2190 init_event(child_file);
2192 /* Set up the test files */
2198 sprintf(filename, *testfile, tmpdir);
2199 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2200 FILE_ATTRIBUTE_NORMAL, NULL);
2201 if (hfile==INVALID_HANDLE_VALUE)
2203 trace("unable to create '%s': err=%u\n", filename, GetLastError());
2210 /* Setup the test shortcuts */
2211 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
2212 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2213 desc.description=NULL;
2215 sprintf(filename, "%s\\test file.shlexec", tmpdir);
2218 desc.arguments="ignored";
2223 create_lnk(lnkfile, &desc, 0);
2225 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2226 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
2227 desc.description=NULL;
2231 sprintf(params, "shlexec \"%s\" Lnk", child_file);
2232 desc.arguments=params;
2237 create_lnk(lnkfile, &desc, 0);
2239 /* Create a basic association suitable for most tests */
2240 if (!create_test_association(".shlexec"))
2242 skip("Unable to create association for '.shlexec'\n");
2245 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2246 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2247 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2248 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2249 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2250 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2252 create_test_verb(".shlexec", "NoQuotesParam2", 0, "NoQuotesParam2 %2");
2253 create_test_verb(".shlexec", "QuotedParam2", 0, "QuotedParam2 \"%2\"");
2255 create_test_verb(".shlexec", "NoQuotesAllParams", 0, "NoQuotesAllParams %*");
2256 create_test_verb(".shlexec", "QuotedAllParams", 0, "QuotedAllParams \"%*\"");
2258 create_test_verb(".shlexec", "NoQuotesParams345etc", 0, "NoQuotesParams345etc %~3");
2259 create_test_verb(".shlexec", "QuotedParams345etc", 0, "QuotedParams345etc \"%~3\"");
2262 static void cleanup_test(void)
2264 char filename[MAX_PATH];
2265 const char* const * testfile;
2267 /* Delete the test files */
2271 sprintf(filename, *testfile, tmpdir);
2272 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2273 SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
2274 DeleteFile(filename);
2277 DeleteFile(child_file);
2278 RemoveDirectoryA(tmpdir);
2280 /* Delete the test association */
2281 delete_test_association(".shlexec");
2283 CloseHandle(hEvent);
2288 static void test_commandline(void)
2290 static const WCHAR one[] = {'o','n','e',0};
2291 static const WCHAR two[] = {'t','w','o',0};
2292 static const WCHAR three[] = {'t','h','r','e','e',0};
2293 static const WCHAR four[] = {'f','o','u','r',0};
2295 static const WCHAR fmt1[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
2296 static const WCHAR fmt2[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
2297 static const WCHAR fmt3[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
2298 static const WCHAR fmt4[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
2299 static const WCHAR fmt5[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
2300 static const WCHAR fmt6[] = {0};
2302 static const WCHAR chkfmt1[] = {'%','s','=','%','s',0};
2303 static const WCHAR chkfmt2[] = {'%','s',' ','%','s',0};
2304 static const WCHAR chkfmt3[] = {'\\','\"','%','s','\"',0};
2305 static const WCHAR chkfmt4[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
2307 LPWSTR *args = (LPWSTR*)0xdeadcafe, pbuf;
2312 wsprintfW(cmdline,fmt1,one,two,three,four);
2313 args=CommandLineToArgvW(cmdline,&numargs);
2314 if (args == NULL && numargs == -1)
2316 win_skip("CommandLineToArgvW not implemented, skipping\n");
2319 ok(numargs == 4, "expected 4 args, got %i\n",numargs);
2320 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
2321 ok(lstrcmpW(args[1],two)==0,"arg1 is not as expected\n");
2322 ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n");
2323 ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
2325 SetLastError(0xdeadbeef);
2326 args=CommandLineToArgvW(cmdline,NULL);
2327 lerror=GetLastError();
2328 ok(args == NULL && lerror == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n",args,lerror);
2329 SetLastError(0xdeadbeef);
2330 args=CommandLineToArgvW(NULL,NULL);
2331 lerror=GetLastError();
2332 ok(args == NULL && lerror == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n",args,lerror);
2334 wsprintfW(cmdline,fmt2,one,two,three,four);
2335 args=CommandLineToArgvW(cmdline,&numargs);
2336 ok(numargs == 5, "expected 5 args, got %i\n",numargs);
2337 ok(args[0][0]==0,"arg0 is not as expected\n");
2338 ok(lstrcmpW(args[1],one)==0,"arg1 is not as expected\n");
2339 ok(lstrcmpW(args[2],two)==0,"arg2 is not as expected\n");
2340 ok(lstrcmpW(args[3],three)==0,"arg3 is not as expected\n");
2341 ok(lstrcmpW(args[4],four)==0,"arg4 is not as expected\n");
2343 wsprintfW(cmdline,fmt3,one,two,three,four);
2344 args=CommandLineToArgvW(cmdline,&numargs);
2345 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
2346 wsprintfW(cmdline,chkfmt1,one,two);
2347 ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
2348 wsprintfW(cmdline,chkfmt1,three,four);
2349 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2351 wsprintfW(cmdline,fmt4,one,two,three,four);
2352 args=CommandLineToArgvW(cmdline,&numargs);
2353 ok(numargs == 3, "expected 3 args, got %i\n",numargs);
2354 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
2355 wsprintfW(cmdline,chkfmt2,two,three);
2356 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2357 ok(lstrcmpW(args[2],four)==0,"arg2 is not as expected\n");
2359 wsprintfW(cmdline,fmt5,one,two,three,four);
2360 args=CommandLineToArgvW(cmdline,&numargs);
2361 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
2362 wsprintfW(cmdline,chkfmt3,one);
2363 todo_wine ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
2364 wsprintfW(cmdline,chkfmt4,two,three,four);
2365 todo_wine ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
2367 wsprintfW(cmdline,fmt6);
2368 args=CommandLineToArgvW(cmdline,&numargs);
2369 ok(numargs == 1, "expected 1 args, got %i\n",numargs);
2371 buflen = max(lstrlenW(args[0])+1,256);
2372 pbuf = HeapAlloc(GetProcessHeap(), 0, buflen*sizeof(pbuf[0]));
2373 GetModuleFileNameW(NULL, pbuf, buflen);
2375 /* check args[0] is module file name */
2376 ok(lstrcmpW(args[0],pbuf)==0, "wrong path to the current executable\n");
2377 HeapFree(GetProcessHeap(), 0, pbuf);
2381 static void test_directory(void)
2383 char path[MAX_PATH], newdir[MAX_PATH];
2387 /* copy this executable to a new folder and cd to it */
2388 sprintf(newdir, "%s\\newfolder", tmpdir);
2389 rc = CreateDirectoryA( newdir, NULL );
2390 ok( rc, "failed to create %s err %u\n", newdir, GetLastError() );
2391 sprintf(path, "%s\\%s", newdir, path_find_file_name(argv0));
2392 CopyFileA(argv0, path, FALSE);
2393 SetCurrentDirectory(tmpdir);
2395 sprintf(params, "shlexec \"%s\" Exec", child_file);
2397 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2398 NULL, path_find_file_name(argv0), params, NULL);
2399 todo_wine ok(rc == SE_ERR_FNF, "%s returned %lu\n", shell_call, rc);
2401 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2402 NULL, path_find_file_name(argv0), params, newdir);
2403 ok(rc > 32, "%s returned %lu\n", shell_call, rc);
2404 okChildInt("argcA", 4);
2405 okChildString("argvA3", "Exec");
2406 todo_wine okChildPath("longPath", path);
2409 RemoveDirectoryA(newdir);
2415 myARGC = winetest_get_mainargs(&myARGV);
2418 doChild(myARGC, myARGV);
2425 test_lpFile_parsed();
2428 test_find_executable();
2433 test_dde_default_app();