server: Send WM_WINE_SETCURSOR with the thread input cursor handle.
[wine.git] / dlls / shell32 / tests / shlexec.c
blob90e96b91586fd4d6349273cf0b178e2d6d81ef23
1 /*
2 * Unit test of the ShellExecute function.
4 * Copyright 2005, 2016 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
21 /* TODO:
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
27 * in the PATH
28 * - test associations that use %l, %L or "%1" instead of %1
29 * - ShellExecuteEx() also calls SetLastError() with meaningful values which
30 * we could check
33 #include <stdio.h>
34 #include <assert.h>
36 #include "wtypes.h"
37 #include "winbase.h"
38 #include "windef.h"
39 #include "shellapi.h"
40 #include "shlwapi.h"
41 #include "ddeml.h"
43 #include "wine/test.h"
45 #include "shell32_test.h"
48 static char argv0[MAX_PATH];
49 static int myARGC;
50 static char** myARGV;
51 static char tmpdir[MAX_PATH];
52 static char child_file[MAX_PATH];
53 static DLLVERSIONINFO dllver;
54 static BOOL skip_shlexec_tests = FALSE;
55 static BOOL skip_noassoc_tests = FALSE;
56 static HANDLE dde_ready_event;
57 static BOOL is_elevated;
60 /***
62 * Helpers to read from / write to the child process results file.
63 * (borrowed from dlls/kernel32/tests/process.c)
65 ***/
67 static const char* encodeA(const char* str)
69 static char encoded[2*1024+1];
70 char* ptr;
71 size_t len,i;
73 if (!str) return "";
74 len = strlen(str) + 1;
75 if (len >= sizeof(encoded)/2)
77 fprintf(stderr, "string is too long!\n");
78 assert(0);
80 ptr = encoded;
81 for (i = 0; i < len; i++)
82 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
83 ptr[2 * len] = '\0';
84 return ptr;
87 static unsigned decode_char(char c)
89 if (c >= '0' && c <= '9') return c - '0';
90 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
91 assert(c >= 'A' && c <= 'F');
92 return c - 'A' + 10;
95 static char* decodeA(const char* str)
97 static char decoded[1024];
98 char* ptr;
99 size_t len,i;
101 len = strlen(str) / 2;
102 if (!len--) return NULL;
103 if (len >= sizeof(decoded))
105 fprintf(stderr, "string is too long!\n");
106 assert(0);
108 ptr = decoded;
109 for (i = 0; i < len; i++)
110 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
111 ptr[len] = '\0';
112 return ptr;
115 static void WINAPIV __WINE_PRINTF_ATTR(2,3) childPrintf(HANDLE h, const char* fmt, ...)
117 va_list valist;
118 char buffer[1024];
119 DWORD w;
121 va_start(valist, fmt);
122 vsprintf(buffer, fmt, valist);
123 va_end(valist);
124 WriteFile(h, buffer, strlen(buffer), &w, NULL);
127 static char* getChildString(const char* sect, const char* key)
129 char buf[1024];
130 char* ret;
132 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
133 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
134 assert(!(strlen(buf) & 1));
135 ret = decodeA(buf);
136 return ret;
140 /***
142 * Child code
144 ***/
146 #define CHILD_DDE_TIMEOUT 2500
147 static DWORD ddeInst;
148 static HSZ hszTopic;
149 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
150 static BOOL post_quit_on_execute;
152 /* Handle DDE for doChild() and test_dde_default_app() */
153 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
154 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
155 ULONG_PTR dwData1, ULONG_PTR dwData2)
157 DWORD size = 0;
159 if (winetest_debug > 2)
160 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08Ix, %08Ix\n",
161 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
163 switch (uType)
165 case XTYP_CONNECT:
166 if (!DdeCmpStringHandles(hsz1, hszTopic))
168 size = DdeQueryStringA(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
169 ok(size < MAX_PATH, "got size %ld\n", size);
170 assert(size < MAX_PATH);
171 return (HDDEDATA)TRUE;
173 return (HDDEDATA)FALSE;
175 case XTYP_EXECUTE:
176 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0);
177 ok(size < MAX_PATH, "got size %ld\n", size);
178 assert(size < MAX_PATH);
179 DdeFreeDataHandle(hData);
180 if (post_quit_on_execute)
181 PostQuitMessage(0);
182 return (HDDEDATA)DDE_FACK;
184 default:
185 return NULL;
189 static HANDLE hEvent;
190 static void init_event(const char* child_file)
192 char* event_name;
193 event_name=strrchr(child_file, '\\')+1;
194 hEvent=CreateEventA(NULL, FALSE, FALSE, event_name);
197 static HANDLE hChildFile;
199 * This is just to make sure the child won't run forever stuck in a
200 * GetMessage() loop when DDE fails for some reason.
202 static void CALLBACK childTimeout(HWND wnd, UINT msg, UINT_PTR timer, DWORD time)
204 trace("childTimeout called\n");
205 childPrintf(hChildFile, "Timeout=1\r\n");
207 PostQuitMessage(0);
210 static void doChild(int argc, char** argv)
212 char *filename, buffer[MAX_PATH];
213 HANDLE hFile, map;
214 int i;
215 UINT_PTR timer;
217 filename=argv[2];
218 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
219 if (hFile == INVALID_HANDLE_VALUE)
220 return;
222 hChildFile = hFile;
223 /* Arguments */
224 childPrintf(hFile, "[Child]\r\n");
225 if (winetest_debug > 2)
227 trace("cmdlineA='%s'\n", GetCommandLineA());
228 trace("argcA=%d\n", argc);
230 childPrintf(hFile, "cmdlineA=%s\r\n", encodeA(GetCommandLineA()));
231 childPrintf(hFile, "argcA=%d\r\n", argc);
232 for (i = 0; i < argc; i++)
234 if (winetest_debug > 2)
235 trace("argvA%d='%s'\n", i, argv[i]);
236 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
238 GetModuleFileNameA(GetModuleHandleA(NULL), buffer, sizeof(buffer));
239 childPrintf(hFile, "longPath=%s\r\n", encodeA(buffer));
241 /* Check environment variable inheritance */
242 *buffer = '\0';
243 SetLastError(0);
244 GetEnvironmentVariableA("ShlexecVar", buffer, sizeof(buffer));
245 childPrintf(hFile, "ShlexecVarLE=%ld\r\n", GetLastError());
246 childPrintf(hFile, "ShlexecVar=%s\r\n", encodeA(buffer));
248 map = OpenFileMappingA(FILE_MAP_READ, FALSE, "winetest_shlexec_dde_map");
249 if (map != NULL)
251 HANDLE dde_ready;
252 char *shared_block = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 4096);
253 CloseHandle(map);
254 if (shared_block[0] != '\0' || shared_block[1] != '\0')
256 HDDEDATA hdde;
257 HSZ hszApplication;
258 MSG msg;
259 UINT rc;
261 post_quit_on_execute = TRUE;
262 ddeInst = 0;
263 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
264 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0);
265 ok(rc == DMLERR_NO_ERROR, "DdeInitializeA() returned %d\n", rc);
266 hszApplication = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
267 ok(hszApplication != NULL, "DdeCreateStringHandleA(%s) = NULL\n", shared_block);
268 shared_block += strlen(shared_block) + 1;
269 hszTopic = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
270 ok(hszTopic != NULL, "DdeCreateStringHandleA(%s) = NULL\n", shared_block);
271 hdde = DdeNameService(ddeInst, hszApplication, 0, DNS_REGISTER | DNS_FILTEROFF);
272 ok(hdde != NULL, "DdeNameService() failed le=%lu\n", GetLastError());
274 timer = SetTimer(NULL, 0, CHILD_DDE_TIMEOUT, childTimeout);
276 dde_ready = OpenEventA(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
277 SetEvent(dde_ready);
278 CloseHandle(dde_ready);
280 while (GetMessageA(&msg, NULL, 0, 0))
282 if (winetest_debug > 2)
283 trace("msg %d lParam=%Id wParam=%Iu\n", msg.message, msg.lParam, msg.wParam);
284 DispatchMessageA(&msg);
287 Sleep(500);
288 KillTimer(NULL, timer);
289 hdde = DdeNameService(ddeInst, hszApplication, 0, DNS_UNREGISTER);
290 ok(hdde != NULL, "DdeNameService() failed le=%lu\n", GetLastError());
291 ok(DdeFreeStringHandle(ddeInst, hszTopic), "DdeFreeStringHandle(topic)\n");
292 ok(DdeFreeStringHandle(ddeInst, hszApplication), "DdeFreeStringHandle(application)\n");
293 ok(DdeUninitialize(ddeInst), "DdeUninitialize() failed\n");
295 else
297 dde_ready = OpenEventA(EVENT_MODIFY_STATE, FALSE, "winetest_shlexec_dde_ready");
298 SetEvent(dde_ready);
299 CloseHandle(dde_ready);
302 UnmapViewOfFile(shared_block);
304 childPrintf(hFile, "ddeExec=%s\r\n", encodeA(ddeExec));
307 childPrintf(hFile, "Failures=%ld\r\n", winetest_get_failures());
308 CloseHandle(hFile);
310 init_event(filename);
311 SetEvent(hEvent);
312 CloseHandle(hEvent);
315 static void dump_child_(const char* file, int line)
317 if (winetest_debug > 1)
319 char key[18];
320 char* str;
321 int i, c;
323 str=getChildString("Child", "cmdlineA");
324 trace_(file, line)("cmdlineA='%s'\n", str);
325 c=GetPrivateProfileIntA("Child", "argcA", -1, child_file);
326 trace_(file, line)("argcA=%d\n",c);
327 for (i=0;i<c;i++)
329 sprintf(key, "argvA%d", i);
330 str=getChildString("Child", key);
331 trace_(file, line)("%s='%s'\n", key, str);
334 c=GetPrivateProfileIntA("Child", "ShlexecVarLE", -1, child_file);
335 trace_(file, line)("ShlexecVarLE=%d\n", c);
336 str=getChildString("Child", "ShlexecVar");
337 trace_(file, line)("ShlexecVar='%s'\n", str);
339 c=GetPrivateProfileIntA("Child", "Failures", -1, child_file);
340 trace_(file, line)("Failures=%d\n", c);
345 /***
347 * Helpers to check the ShellExecute() / child process results.
349 ***/
351 static char shell_call[2048];
352 static void WINAPIV __WINE_PRINTF_ATTR(2,3) _okShell(int condition, const char *msg, ...)
354 va_list valist;
355 char buffer[2048];
357 strcpy(buffer, shell_call);
358 strcat(buffer, " ");
359 va_start(valist, msg);
360 vsprintf(buffer+strlen(buffer), msg, valist);
361 va_end(valist);
362 winetest_ok(condition, "%s", buffer);
364 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
365 #define okShell okShell_(__FILE__, __LINE__)
367 static char assoc_desc[2048];
368 static void reset_association_description(void)
370 *assoc_desc = '\0';
373 static void okChildString_(const char* file, int line, const char* key, const char* expected, const char* bad)
375 char* result;
376 result=getChildString("Child", key);
377 if (!result)
379 okShell_(file, line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
380 return;
382 okShell_(file, line)(lstrcmpiA(result, expected) == 0 ||
383 broken(lstrcmpiA(result, bad) == 0),
384 "%s expected '%s', got '%s'\n", key, expected, result);
386 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
387 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
389 static int StrCmpPath(const char* s1, const char* s2)
391 if (!s1 && !s2) return 0;
392 if (!s2) return 1;
393 if (!s1) return -1;
394 while (*s1)
396 if (!*s2)
398 if (*s1=='.')
399 s1++;
400 return (*s1-*s2);
402 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
404 while (*s1=='/' || *s1=='\\')
405 s1++;
406 while (*s2=='/' || *s2=='\\')
407 s2++;
409 else if (toupper(*s1)==toupper(*s2))
411 s1++;
412 s2++;
414 else
416 return (*s1-*s2);
419 if (*s2=='.')
420 s2++;
421 if (*s2)
422 return -1;
423 return 0;
426 static void okChildPath_(const char* file, int line, const char* key, const char* expected)
428 char* result;
429 int equal, shortequal;
430 result=getChildString("Child", key);
431 if (!result)
433 okShell_(file,line)(FALSE, "%s expected '%s', but key not found or empty\n", key, expected);
434 return;
436 shortequal = FALSE;
437 equal = (StrCmpPath(result, expected) == 0);
438 if (!equal)
440 char altpath[MAX_PATH];
441 DWORD rc = GetLongPathNameA(expected, altpath, sizeof(altpath));
442 if (0 < rc && rc < sizeof(altpath))
443 equal = (StrCmpPath(result, altpath) == 0);
444 if (!equal)
446 rc = GetShortPathNameA(expected, altpath, sizeof(altpath));
447 if (0 < rc && rc < sizeof(altpath))
448 shortequal = (StrCmpPath(result, altpath) == 0);
451 okShell_(file,line)(equal || broken(shortequal) /* XP SP1 */,
452 "%s expected '%s', got '%s'\n", key, expected, result);
454 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
456 static void okChildInt_(const char* file, int line, const char* key, int expected)
458 INT result;
459 result=GetPrivateProfileIntA("Child", key, expected, child_file);
460 okShell_(file,line)(result == expected,
461 "%s expected %d, but got %d\n", key, expected, result);
463 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
465 static void okChildIntBroken_(const char* file, int line, const char* key, int expected)
467 INT result;
468 result=GetPrivateProfileIntA("Child", key, expected, child_file);
469 okShell_(file,line)(result == expected || broken(result != expected),
470 "%s expected %d, but got %d\n", key, expected, result);
472 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
475 /***
477 * ShellExecute wrappers
479 ***/
481 static void strcat_param(char* str, const char* name, const char* param)
483 if (param)
485 if (str[strlen(str)-1] == '"')
486 strcat(str, ", ");
487 strcat(str, name);
488 strcat(str, "=\"");
489 strcat(str, param);
490 strcat(str, "\"");
494 static int _todo_wait = 0;
495 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
497 static int bad_shellexecute = 0;
499 static INT_PTR shell_execute_(const char* file, int line, LPCSTR verb, LPCSTR filename, LPCSTR parameters, LPCSTR directory)
501 INT_PTR rc, rcEmpty = 0;
503 if(!verb)
504 rcEmpty = shell_execute_(file, line, "", filename, parameters, directory);
506 strcpy(shell_call, "ShellExecute(");
507 strcat_param(shell_call, "verb", verb);
508 strcat_param(shell_call, "file", filename);
509 strcat_param(shell_call, "params", parameters);
510 strcat_param(shell_call, "dir", directory);
511 strcat(shell_call, ")");
512 strcat(shell_call, assoc_desc);
513 if (winetest_debug > 1)
514 trace_(file, line)("Called %s\n", shell_call);
516 DeleteFileA(child_file);
517 SetLastError(0xcafebabe);
519 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
520 * association it displays the 'Open With' dialog and I could not find
521 * a flag to prevent this.
523 rc=(INT_PTR)ShellExecuteA(NULL, verb, filename, parameters, directory, SW_HIDE);
525 if (rc > 32)
527 int wait_rc;
528 wait_rc=WaitForSingleObject(hEvent, 5000);
529 if (wait_rc == WAIT_TIMEOUT)
531 HWND wnd = FindWindowA("#32770", "Windows");
532 if (!wnd)
533 wnd = FindWindowA("Shell_Flyout", "");
534 if (wnd != NULL)
536 SendMessageA(wnd, WM_CLOSE, 0, 0);
537 win_skip("Skipping shellexecute of file with unassociated extension\n");
538 skip_noassoc_tests = TRUE;
539 rc = SE_ERR_NOASSOC;
542 todo_wine_if(_todo_wait)
543 okShell_(file, line)(wait_rc==WAIT_OBJECT_0 || rc <= 32,
544 "WaitForSingleObject returned %d\n", wait_rc);
546 /* The child process may have changed the result file, so let profile
547 * functions know about it
549 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
550 if (GetFileAttributesA(child_file) != INVALID_FILE_ATTRIBUTES)
552 int c;
553 dump_child_(file, line);
554 c = GetPrivateProfileIntA("Child", "Failures", -1, child_file);
555 if (c > 0)
556 winetest_add_failures(c);
557 okChildInt_(file, line, "ShlexecVarLE", 0);
558 okChildString_(file, line, "ShlexecVar", "Present", "Present");
561 if(!verb)
563 if (rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */
564 bad_shellexecute = 1;
565 okShell_(file, line)(rc == rcEmpty ||
566 broken(rc != rcEmpty && rcEmpty == SE_ERR_NOASSOC) /* NT4 */,
567 "Got different return value with empty string: %Iu %Iu\n", rc, rcEmpty);
570 return rc;
572 #define shell_execute(verb, filename, parameters, directory) \
573 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
575 static INT_PTR shell_execute_ex_(const char* file, int line,
576 DWORD mask, LPCSTR verb, LPCSTR filename,
577 LPCSTR parameters, LPCSTR directory,
578 LPCSTR class)
580 char smask[11];
581 SHELLEXECUTEINFOA sei;
582 BOOL success;
583 INT_PTR rc;
585 /* Add some flags so we can wait for the child process */
586 mask |= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE;
588 strcpy(shell_call, "ShellExecuteEx(");
589 sprintf(smask, "0x%lx", mask);
590 strcat_param(shell_call, "mask", smask);
591 strcat_param(shell_call, "verb", verb);
592 strcat_param(shell_call, "file", filename);
593 strcat_param(shell_call, "params", parameters);
594 strcat_param(shell_call, "dir", directory);
595 strcat_param(shell_call, "class", class);
596 strcat(shell_call, ")");
597 strcat(shell_call, assoc_desc);
598 if (winetest_debug > 1)
599 trace_(file, line)("Called %s\n", shell_call);
601 sei.cbSize=sizeof(sei);
602 sei.fMask=mask;
603 sei.hwnd=NULL;
604 sei.lpVerb=verb;
605 sei.lpFile=filename;
606 sei.lpParameters=parameters;
607 sei.lpDirectory=directory;
608 sei.nShow=SW_SHOWNORMAL;
609 sei.hInstApp=NULL; /* Out */
610 sei.lpIDList=NULL;
611 sei.lpClass=class;
612 sei.hkeyClass=NULL;
613 sei.dwHotKey=0;
614 sei.hIcon=NULL;
615 sei.hProcess=(HANDLE)0xdeadbeef; /* Out */
617 DeleteFileA(child_file);
618 SetLastError(0xcafebabe);
619 success=ShellExecuteExA(&sei);
620 rc=(INT_PTR)sei.hInstApp;
621 okShell_(file, line)((success && rc > 32) || (!success && rc <= 32),
622 "rc=%d and hInstApp=%Id is not allowed\n",
623 success, rc);
625 if (rc > 32)
627 DWORD wait_rc, rc;
628 if (sei.hProcess!=NULL)
630 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
631 okShell_(file, line)(wait_rc==WAIT_OBJECT_0,
632 "WaitForSingleObject(hProcess) returned %ld\n",
633 wait_rc);
634 wait_rc = GetExitCodeProcess(sei.hProcess, &rc);
635 okShell_(file, line)(wait_rc, "GetExitCodeProcess() failed le=%lu\n", GetLastError());
636 todo_wine_if(_todo_wait)
637 okShell_(file, line)(rc == 0, "child returned %lu\n", rc);
638 CloseHandle(sei.hProcess);
640 wait_rc=WaitForSingleObject(hEvent, 5000);
641 todo_wine_if(_todo_wait)
642 okShell_(file, line)(wait_rc==WAIT_OBJECT_0,
643 "WaitForSingleObject returned %ld\n", wait_rc);
645 else
646 okShell_(file, line)(sei.hProcess==NULL,
647 "returned a process handle %p\n", sei.hProcess);
649 /* The child process may have changed the result file, so let profile
650 * functions know about it
652 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
653 if (rc > 32 && GetFileAttributesA(child_file) != INVALID_FILE_ATTRIBUTES)
655 int c;
656 dump_child_(file, line);
657 c = GetPrivateProfileIntA("Child", "Failures", -1, child_file);
658 if (c > 0)
659 winetest_add_failures(c);
660 c = GetPrivateProfileIntA("Child", "Timeout", -1, child_file);
661 if (c > 0)
663 /* Inform caller of the timeout... these two following bits
664 * are directly returned by some Windows10 versions.
665 * Return the same bits when we detect a timeout in child.
667 SetLastError(ERROR_FILE_NOT_FOUND);
668 rc = SE_ERR_DDEFAIL;
670 /* When NOZONECHECKS is specified the environment variables are not
671 * inherited if the process does not have elevated privileges.
673 else if ((mask & SEE_MASK_NOZONECHECKS) && skip_shlexec_tests)
675 okChildInt_(file, line, "ShlexecVarLE", 203);
676 okChildString_(file, line, "ShlexecVar", "", "");
678 else
680 okChildInt_(file, line, "ShlexecVarLE", 0);
681 okChildString_(file, line, "ShlexecVar", "Present", "Present");
685 return rc;
687 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
688 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
691 /***
693 * Functions to create / delete associations wrappers
695 ***/
697 static BOOL create_test_class(const char* class, BOOL protocol)
699 HKEY hkey, hkey_shell;
700 LONG rc;
702 rc = RegCreateKeyExA(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
703 KEY_CREATE_SUB_KEY | KEY_SET_VALUE, NULL,
704 &hkey, NULL);
705 ok(rc == ERROR_SUCCESS || rc == ERROR_ACCESS_DENIED,
706 "could not create class %s (rc=%ld)\n", class, rc);
707 if (rc != ERROR_SUCCESS)
708 return FALSE;
710 if (protocol)
712 rc = RegSetValueExA(hkey, "URL Protocol", 0, REG_SZ, (LPBYTE)"", 1);
713 ok(rc == ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %ld\n", class, rc);
716 rc = RegCreateKeyExA(hkey, "shell", 0, NULL, 0,
717 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
718 ok(rc == ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %ld\n", rc);
720 CloseHandle(hkey);
721 CloseHandle(hkey_shell);
722 return TRUE;
725 static BOOL create_test_association_key(const char* extension, const char *class)
727 HKEY hkey;
728 LONG rc;
730 rc = RegCreateKeyExA(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
731 NULL, &hkey, NULL);
732 ok(rc == ERROR_SUCCESS || rc == ERROR_ACCESS_DENIED,
733 "could not create association %s (rc=%ld)\n", class, rc);
734 if (rc != ERROR_SUCCESS)
735 return FALSE;
737 rc = RegSetValueExA(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
738 ok(rc == ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %ld\n", class, rc);
739 CloseHandle(hkey);
740 return TRUE;
743 static BOOL create_test_association(const char* extension)
745 char class[MAX_PATH];
747 sprintf(class, "shlexec%s", extension);
748 if (!create_test_association_key(extension, class))
749 return FALSE;
751 return create_test_class(class, FALSE);
754 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
755 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
757 LONG ret;
758 DWORD dwMaxSubkeyLen, dwMaxValueLen;
759 DWORD dwMaxLen, dwSize;
760 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
761 HKEY hSubKey = hKey;
763 if(lpszSubKey)
765 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
766 if (ret) return ret;
769 /* Get highest length for keys, values */
770 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
771 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
772 if (ret) goto cleanup;
774 dwMaxSubkeyLen++;
775 dwMaxValueLen++;
776 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
777 if (dwMaxLen > ARRAY_SIZE(szNameBuf))
779 /* Name too big: alloc a buffer for it */
780 if (!(lpszName = malloc(dwMaxLen*sizeof(CHAR))))
782 ret = ERROR_NOT_ENOUGH_MEMORY;
783 goto cleanup;
788 /* Recursively delete all the subkeys */
789 while (TRUE)
791 dwSize = dwMaxLen;
792 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
793 NULL, NULL, NULL)) break;
795 ret = myRegDeleteTreeA(hSubKey, lpszName);
796 if (ret) goto cleanup;
799 if (lpszSubKey)
800 ret = RegDeleteKeyA(hKey, lpszSubKey);
801 else
802 while (TRUE)
804 dwSize = dwMaxLen;
805 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
806 NULL, NULL, NULL, NULL)) break;
808 ret = RegDeleteValueA(hKey, lpszName);
809 if (ret) goto cleanup;
812 cleanup:
813 /* Free buffer if allocated */
814 if (lpszName != szNameBuf)
815 free(lpszName);
816 if(lpszSubKey)
817 RegCloseKey(hSubKey);
818 return ret;
821 static void delete_test_class(const char* classname)
823 myRegDeleteTreeA(HKEY_CLASSES_ROOT, classname);
826 static void delete_test_association(const char* extension)
828 char classname[MAX_PATH];
830 sprintf(classname, "shlexec%s", extension);
831 delete_test_class(classname);
832 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
835 static void create_test_verb_dde(const char* classname, const char* verb,
836 int rawcmd, const char* cmdtail, const char *ddeexec,
837 const char *application, const char *topic,
838 const char *ifexec)
840 HKEY hkey_shell, hkey_verb, hkey_cmd;
841 char shell[MAX_PATH];
842 char* cmd;
843 LONG rc;
845 strcpy(assoc_desc, " Assoc ");
846 strcat_param(assoc_desc, "class", classname);
847 strcat_param(assoc_desc, "verb", verb);
848 sprintf(shell, "%d", rawcmd);
849 strcat_param(assoc_desc, "rawcmd", shell);
850 strcat_param(assoc_desc, "cmdtail", cmdtail);
851 strcat_param(assoc_desc, "ddeexec", ddeexec);
852 strcat_param(assoc_desc, "app", application);
853 strcat_param(assoc_desc, "topic", topic);
854 strcat_param(assoc_desc, "ifexec", ifexec);
856 sprintf(shell, "%s\\shell", classname);
857 rc=RegOpenKeyExA(HKEY_CLASSES_ROOT, shell, 0,
858 KEY_CREATE_SUB_KEY, &hkey_shell);
859 ok(rc == ERROR_SUCCESS, "%s key creation failed with %ld\n", shell, rc);
861 rc=RegCreateKeyExA(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
862 NULL, &hkey_verb, NULL);
863 ok(rc == ERROR_SUCCESS, "%s verb key creation failed with %ld\n", verb, rc);
865 rc=RegCreateKeyExA(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
866 NULL, &hkey_cmd, NULL);
867 ok(rc == ERROR_SUCCESS, "\'command\' key creation failed with %ld\n", rc);
869 if (rawcmd)
871 rc=RegSetValueExA(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
873 else
875 cmd = malloc(strlen(argv0) + 10 + strlen(child_file) + 2 + strlen(cmdtail) + 1);
876 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
877 rc=RegSetValueExA(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
878 ok(rc == ERROR_SUCCESS, "setting command failed with %ld\n", rc);
879 free(cmd);
882 if (ddeexec)
884 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
886 rc=RegCreateKeyExA(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
887 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
888 ok(rc == ERROR_SUCCESS, "\'ddeexec\' key creation failed with %ld\n", rc);
889 rc=RegSetValueExA(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
890 strlen(ddeexec)+1);
891 ok(rc == ERROR_SUCCESS, "set value failed with %ld\n", rc);
893 if (application)
895 rc=RegCreateKeyExA(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
896 NULL, &hkey_application, NULL);
897 ok(rc == ERROR_SUCCESS, "\'application\' key creation failed with %ld\n", rc);
899 rc=RegSetValueExA(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
900 strlen(application)+1);
901 ok(rc == ERROR_SUCCESS, "set value failed with %ld\n", rc);
902 CloseHandle(hkey_application);
904 if (topic)
906 rc=RegCreateKeyExA(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
907 NULL, &hkey_topic, NULL);
908 ok(rc == ERROR_SUCCESS, "\'topic\' key creation failed with %ld\n", rc);
909 rc=RegSetValueExA(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
910 strlen(topic)+1);
911 ok(rc == ERROR_SUCCESS, "set value failed with %ld\n", rc);
912 CloseHandle(hkey_topic);
914 if (ifexec)
916 rc=RegCreateKeyExA(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
917 NULL, &hkey_ifexec, NULL);
918 ok(rc == ERROR_SUCCESS, "\'ifexec\' key creation failed with %ld\n", rc);
919 rc=RegSetValueExA(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
920 strlen(ifexec)+1);
921 ok(rc == ERROR_SUCCESS, "set value failed with %ld\n", rc);
922 CloseHandle(hkey_ifexec);
924 CloseHandle(hkey_ddeexec);
927 CloseHandle(hkey_shell);
928 CloseHandle(hkey_verb);
929 CloseHandle(hkey_cmd);
932 /* Creates a class' non-DDE test verb.
933 * This function is meant to be used to create long term test verbs and thus
934 * does not trace them.
936 static void create_test_verb(const char* classname, const char* verb,
937 int rawcmd, const char* cmdtail)
939 create_test_verb_dde(classname, verb, rawcmd, cmdtail, NULL, NULL,
940 NULL, NULL);
941 reset_association_description();
945 /***
947 * GetLongPathNameA equivalent that supports Win95 and WinNT
949 ***/
951 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
953 char tmplongpath[MAX_PATH];
954 const char* p;
955 DWORD sp = 0, lp = 0;
956 DWORD tmplen;
957 WIN32_FIND_DATAA wfd;
958 HANDLE goit;
960 if (!shortpath || !shortpath[0])
961 return 0;
963 if (shortpath[1] == ':')
965 tmplongpath[0] = shortpath[0];
966 tmplongpath[1] = ':';
967 lp = sp = 2;
970 while (shortpath[sp])
972 /* check for path delimiters and reproduce them */
973 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
975 if (!lp || tmplongpath[lp-1] != '\\')
977 /* strip double "\\" */
978 tmplongpath[lp++] = '\\';
980 tmplongpath[lp] = 0; /* terminate string */
981 sp++;
982 continue;
985 p = shortpath + sp;
986 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
988 tmplongpath[lp++] = *p++;
989 tmplongpath[lp++] = *p++;
991 for (; *p && *p != '/' && *p != '\\'; p++);
992 tmplen = p - (shortpath + sp);
993 lstrcpynA(tmplongpath + lp, shortpath + sp, tmplen + 1);
994 /* Check if the file exists and use the existing file name */
995 goit = FindFirstFileA(tmplongpath, &wfd);
996 if (goit == INVALID_HANDLE_VALUE)
997 return 0;
998 FindClose(goit);
999 strcpy(tmplongpath + lp, wfd.cFileName);
1000 lp += strlen(tmplongpath + lp);
1001 sp += tmplen;
1003 tmplen = strlen(shortpath) - 1;
1004 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
1005 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
1006 tmplongpath[lp++] = shortpath[tmplen];
1007 tmplongpath[lp] = 0;
1009 tmplen = strlen(tmplongpath) + 1;
1010 if (tmplen <= longlen)
1012 strcpy(longpath, tmplongpath);
1013 tmplen--; /* length without 0 */
1016 return tmplen;
1020 /***
1022 * Tests
1024 ***/
1026 static const char* testfiles[]=
1028 "%s\\test file.shlexec",
1029 "%s\\%%nasty%% $file.shlexec",
1030 "%s\\test file.noassoc",
1031 "%s\\test file.noassoc.shlexec",
1032 "%s\\test file.shlexec.noassoc",
1033 "%s\\test_shortcut_shlexec.lnk",
1034 "%s\\test_shortcut_exe.lnk",
1035 "%s\\test file.shl",
1036 "%s\\test file.shlfoo",
1037 "%s\\test file.sha",
1038 "%s\\test file.sfe",
1039 "%s\\test file.shlproto",
1040 "%s\\masked file.shlexec",
1041 "%s\\masked",
1042 "%s\\test file.sde",
1043 "%s\\test file.exe",
1044 "%s\\test2.exe",
1045 "%s\\simple.shlexec",
1046 "%s\\drawback_file.noassoc",
1047 "%s\\drawback_file.noassoc foo.shlexec",
1048 "%s\\drawback_nonexist.noassoc foo.shlexec",
1049 NULL
1052 typedef struct
1054 const char* verb;
1055 const char* basename;
1056 int todo;
1057 INT_PTR rc;
1058 } filename_tests_t;
1060 static filename_tests_t filename_tests[]=
1062 /* Test bad / nonexistent filenames */
1063 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
1064 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
1066 /* Standard tests */
1067 {NULL, "%s\\test file.shlexec", 0x0, 33},
1068 {NULL, "%s\\test file.shlexec.", 0x0, 33},
1069 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
1070 {NULL, "%s/test file.shlexec", 0x0, 33},
1072 /* Test filenames with no association */
1073 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
1075 /* Test double extensions */
1076 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
1077 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
1079 /* Test alternate verbs */
1080 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
1081 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
1083 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
1084 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1086 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC},
1088 {"averb", "%s\\test file.sha", 0x10, 33},
1090 /* Test file masked due to space */
1091 {NULL, "%s\\masked file.shlexec", 0x0, 33},
1092 /* Test if quoting prevents the masking */
1093 {NULL, "%s\\masked file.shlexec", 0x40, 33},
1094 /* Test with incorrect quote */
1095 {NULL, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF},
1097 /* Test extension / URI protocol collision */
1098 {NULL, "%s\\test file.shlproto", 0x0, SE_ERR_NOASSOC},
1100 {NULL, NULL, 0}
1103 static filename_tests_t noquotes_tests[]=
1105 /* Test unquoted '%1' thingies */
1106 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1107 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1108 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1110 {NULL, NULL, 0}
1113 static void test_lpFile_parsed(void)
1115 char fileA[MAX_PATH + 38];
1116 INT_PTR rc;
1118 if (skip_shlexec_tests)
1120 skip("No filename parsing tests due to lack of .shlexec association\n");
1121 return;
1124 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on Wine */
1125 sprintf(fileA, "%s\\drawback_file.noassoc foo.shlexec", tmpdir);
1126 rc=shell_execute(NULL, fileA, NULL, NULL);
1127 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1129 /* if quoted, existing "drawback_file.noassoc" does not prevent finding "drawback_file.noassoc foo.shlexec" on Wine */
1130 sprintf(fileA, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir);
1131 rc=shell_execute(NULL, fileA, NULL, NULL);
1132 okShell(rc > 32 || broken(rc == SE_ERR_FNF) /* Win95/NT4 */,
1133 "failed: rc=%Iu\n", rc);
1135 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1136 sprintf(fileA, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir);
1137 rc=shell_execute(NULL, fileA, NULL, NULL);
1138 okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
1140 /* ""command"" not works on wine (and real win9x and w2k) */
1141 sprintf(fileA, "\"\"%s\\simple.shlexec\"\"", tmpdir);
1142 rc=shell_execute(NULL, fileA, NULL, NULL);
1143 todo_wine okShell(rc > 32 || broken(rc == SE_ERR_FNF) /* Win9x/2000 */,
1144 "failed: rc=%Iu\n", rc);
1146 /* nonexistent "drawback_nonexist.noassoc" does not prevent finding "drawback_nonexist.noassoc foo.shlexec" on Wine */
1147 sprintf(fileA, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir);
1148 rc=shell_execute(NULL, fileA, NULL, NULL);
1149 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1151 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1152 rc=shell_execute(NULL, "%TMPDIR%\\simple.shlexec", NULL, NULL);
1153 todo_wine okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
1155 /* quoted */
1156 rc=shell_execute(NULL, "\"%TMPDIR%\\simple.shlexec\"", NULL, NULL);
1157 todo_wine okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
1159 /* test SEE_MASK_DOENVSUBST works */
1160 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI,
1161 NULL, "%TMPDIR%\\simple.shlexec", NULL, NULL, NULL);
1162 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1164 /* quoted lpFile does not work on real win95 and nt4 */
1165 rc=shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI,
1166 NULL, "\"%TMPDIR%\\simple.shlexec\"", NULL, NULL, NULL);
1167 okShell(rc > 32 || broken(rc == SE_ERR_FNF) /* Win95/NT4 */,
1168 "failed: rc=%Iu\n", rc);
1171 typedef struct
1173 const char* cmd;
1174 const char* args[11];
1175 int todo;
1176 } cmdline_tests_t;
1178 static const cmdline_tests_t cmdline_tests[] =
1180 {"exe",
1181 {"exe", NULL}, 0},
1183 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1184 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL}, 0},
1186 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1187 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL}, 0},
1189 {"exe arg\"one\" \"second\"arg thirdarg ",
1190 {"exe", "argone", "secondarg", "thirdarg", NULL}, 0},
1192 /* Don't lose unclosed quoted arguments */
1193 {"exe arg1 \"unclosed",
1194 {"exe", "arg1", "unclosed", NULL}, 0},
1196 {"exe arg1 \"",
1197 {"exe", "arg1", "", NULL}, 0},
1199 /* cmd's metacharacters have no special meaning */
1200 {"exe \"one^\" \"arg\"&two three|four",
1201 {"exe", "one^", "arg&two", "three|four", NULL}, 0},
1203 /* Environment variables are not interpreted either */
1204 {"exe %TMPDIR% %2",
1205 {"exe", "%TMPDIR%", "%2", NULL}, 0},
1207 /* If not followed by a quote, backslashes go through as is */
1208 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1209 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL}, 0},
1211 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1212 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL}, 0},
1214 /* When followed by a quote their number is halved and the remainder
1215 * escapes the quote
1217 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1218 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL}, 0},
1220 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1221 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL}, 0},
1223 /* One can put a quote in an unquoted string by tripling it, that is in
1224 * effect quoting it like so """ -> ". The general rule is as follows:
1225 * 3n quotes -> n quotes
1226 * 3n+1 quotes -> n quotes plus start of a quoted string
1227 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1228 * Nicely, when n is 0 we get the standard rules back.
1230 {"exe two\"\"quotes next",
1231 {"exe", "twoquotes", "next", NULL}, 0},
1233 {"exe three\"\"\"quotes next",
1234 {"exe", "three\"quotes", "next", NULL}, 0},
1236 {"exe four\"\"\"\" quotes\" next 4%3=1",
1237 {"exe", "four\" quotes", "next", "4%3=1", NULL}, 0},
1239 {"exe five\"\"\"\"\"quotes next",
1240 {"exe", "five\"quotes", "next", NULL}, 0},
1242 {"exe six\"\"\"\"\"\"quotes next",
1243 {"exe", "six\"\"quotes", "next", NULL}, 0},
1245 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1246 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL}, 0},
1248 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1249 {"exe", "twelve\"\"\"\"quotes", "next", NULL}, 0},
1251 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1252 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL}, 0},
1254 /* Inside a quoted string the opening quote is added to the set of
1255 * consecutive quotes to get the effective quotes count. This gives:
1256 * 1+3n quotes -> n quotes
1257 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1258 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1260 {"exe \"two\"\"quotes next",
1261 {"exe", "two\"quotes", "next", NULL}, 0},
1263 {"exe \"two\"\" next",
1264 {"exe", "two\"", "next", NULL}, 0},
1266 {"exe \"three\"\"\" quotes\" next 4%3=1",
1267 {"exe", "three\" quotes", "next", "4%3=1", NULL}, 0},
1269 {"exe \"four\"\"\"\"quotes next",
1270 {"exe", "four\"quotes", "next", NULL}, 0},
1272 {"exe \"five\"\"\"\"\"quotes next",
1273 {"exe", "five\"\"quotes", "next", NULL}, 0},
1275 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1276 {"exe", "six\"\" quotes", "next", "7%3=1", NULL}, 0},
1278 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1279 {"exe", "eleven\"\"\"\"quotes", "next", NULL}, 0},
1281 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1282 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL}, 0},
1284 /* Escaped consecutive quotes are fun */
1285 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1286 {"exe", "the crazy \\\"\\", "quotes", NULL}, 0},
1288 /* The executable path has its own rules!!!
1289 * - Backslashes have no special meaning.
1290 * - If the first character is a quote, then the second quote ends the
1291 * executable path.
1292 * - The previous rule holds even if the next character is not a space!
1293 * - If the first character is not a quote, then quotes have no special
1294 * meaning either and the executable path stops at the first space.
1295 * - The consecutive quotes rules don't apply either.
1296 * - Even if there is no space between the executable path and the first
1297 * argument, the latter is parsed using the regular rules.
1299 {"exe\"file\"path arg1",
1300 {"exe\"file\"path", "arg1", NULL}, 0},
1302 {"exe\"file\"path\targ1",
1303 {"exe\"file\"path", "arg1", NULL}, 0},
1305 {"exe\"path\\ arg1",
1306 {"exe\"path\\", "arg1", NULL}, 0},
1308 {"\\\"exe \"arg one\"",
1309 {"\\\"exe", "arg one", NULL}, 0},
1311 {"\"spaced exe\" \"next arg\"",
1312 {"spaced exe", "next arg", NULL}, 0},
1314 {"\"spaced exe\"\t\"next arg\"",
1315 {"spaced exe", "next arg", NULL}, 0},
1317 {"\"exe\"arg\" one\" argtwo",
1318 {"exe", "arg one", "argtwo", NULL}, 0},
1320 {"\"spaced exe\\\"arg1 arg2",
1321 {"spaced exe\\", "arg1", "arg2", NULL}, 0},
1323 {"\"two\"\" arg1 ",
1324 {"two", " arg1 ", NULL}, 0},
1326 {"\"three\"\"\" arg2",
1327 {"three", "", "arg2", NULL}, 0},
1329 {"\"four\"\"\"\"arg1",
1330 {"four", "\"arg1", NULL}, 0},
1332 /* If the first character is a space then the executable path is empty */
1333 {" \"arg\"one argtwo",
1334 {"", "argone", "argtwo", NULL}, 0},
1336 {NULL, {NULL}, 0}
1339 static BOOL test_one_cmdline(const cmdline_tests_t* test)
1341 WCHAR cmdW[MAX_PATH], argW[MAX_PATH];
1342 LPWSTR *cl2a;
1343 int cl2a_count;
1344 LPWSTR *argsW;
1345 int i, count;
1347 /* trace("----- cmd='%s'\n", test->cmd); */
1348 MultiByteToWideChar(CP_ACP, 0, test->cmd, -1, cmdW, ARRAY_SIZE(cmdW));
1349 argsW = cl2a = CommandLineToArgvW(cmdW, &cl2a_count);
1350 if (argsW == NULL && cl2a_count == -1)
1352 win_skip("CommandLineToArgvW not implemented, skipping\n");
1353 return FALSE;
1355 ok(!argsW[cl2a_count] || broken(argsW[cl2a_count] != NULL) /* before Vista */,
1356 "expected NULL-terminated list of commandline arguments\n");
1358 count = 0;
1359 while (test->args[count])
1360 count++;
1361 todo_wine_if(test->todo & 0x1)
1362 ok(cl2a_count == count, "%s: expected %d arguments, but got %d\n", test->cmd, count, cl2a_count);
1364 for (i = 0; i < cl2a_count; i++)
1366 if (i < count)
1368 MultiByteToWideChar(CP_ACP, 0, test->args[i], -1, argW, ARRAY_SIZE(argW));
1369 todo_wine_if(test->todo & (1 << (i+4)))
1370 ok(!lstrcmpW(*argsW, argW), "%s: arg[%d] expected %s but got %s\n", test->cmd, i, wine_dbgstr_w(argW), wine_dbgstr_w(*argsW));
1372 else todo_wine_if(test->todo & 0x1)
1373 ok(0, "%s: got extra arg[%d]=%s\n", test->cmd, i, wine_dbgstr_w(*argsW));
1374 argsW++;
1376 LocalFree(cl2a);
1377 return TRUE;
1380 static void test_commandline2argv(void)
1382 static const WCHAR exeW[] = {'e','x','e',0};
1383 const cmdline_tests_t* test;
1384 WCHAR strW[MAX_PATH];
1385 LPWSTR *args;
1386 int numargs;
1387 DWORD le;
1389 test = cmdline_tests;
1390 while (test->cmd)
1392 if (!test_one_cmdline(test))
1393 return;
1394 test++;
1397 SetLastError(0xdeadbeef);
1398 args = CommandLineToArgvW(exeW, NULL);
1399 le = GetLastError();
1400 ok(args == NULL && le == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %lu\n", args, le);
1402 SetLastError(0xdeadbeef);
1403 args = CommandLineToArgvW(NULL, NULL);
1404 le = GetLastError();
1405 ok(args == NULL && le == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %lu\n", args, le);
1407 *strW = 0;
1408 args = CommandLineToArgvW(strW, &numargs);
1409 ok(numargs == 1 || broken(numargs > 1), "expected 1 args, got %d\n", numargs);
1410 ok(!args || (!args[numargs] || broken(args[numargs] != NULL) /* before Vista */),
1411 "expected NULL-terminated list of commandline arguments\n");
1412 if (numargs == 1)
1414 GetModuleFileNameW(NULL, strW, ARRAY_SIZE(strW));
1415 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));
1417 if (args) LocalFree(args);
1420 /* The goal here is to analyze how ShellExecute() builds the command that
1421 * will be run. The tricky part is that there are three transformation
1422 * steps between the 'parameters' string we pass to ShellExecute() and the
1423 * argument list we observe in the child process:
1424 * - The parsing of 'parameters' string into individual arguments. The tests
1425 * show this is done differently from both CreateProcess() and
1426 * CommandLineToArgv()!
1427 * - The way the command 'formatting directives' such as %1, %2, etc are
1428 * handled.
1429 * - And the way the resulting command line is then parsed to yield the
1430 * argument list we check.
1432 typedef struct
1434 const char* verb;
1435 const char* params;
1436 int todo;
1437 const char *cmd;
1438 const char *broken;
1439 } argify_tests_t;
1441 static const argify_tests_t argify_tests[] =
1443 {"ParamsS", "p2 p3 \"p4 ", FALSE, " p2 p3 \"p4 "},
1445 /* Notice that one can reorder and duplicate the parameters.
1446 * Also notice how %* take the raw input parameters string, including
1447 * the trailing spaces, no matter what arguments have already been used. */
1448 {"Params232S", "p2 p3 p4 ", TRUE,
1449 " p2 p3 \"p2\" \"p2 p3 p4 \""},
1451 /* Unquoted argument references like %2 don't automatically quote their
1452 * argument. Similarly, when they are quoted they don't escape the quotes
1453 * that their argument may contain.
1455 {"Params232S", "\"p two\" p3 p4 ", TRUE,
1456 " p two p3 \"p two\" \"\"p two\" p3 p4 \""},
1458 /* Only single digits are supported so only %1 to %9. Shown here with %20
1459 * because %10 is a pain.
1461 {"Params20", "p", FALSE,
1462 " \"p0\""},
1464 /* Only (double-)quotes have a special meaning. */
1465 {"Params23456", "'p2 p3` p4\\ $even", FALSE,
1466 " \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\""},
1468 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", TRUE,
1469 " \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\""},
1471 /* In unquoted strings, quotes are treated are a parameter separator just
1472 * like spaces! However they can be doubled to get a literal quote.
1473 * Specifically:
1474 * 2n quotes -> n quotes
1475 * 2n+1 quotes -> n quotes and a parameter separator
1477 {"Params23456789", "one\"quote \"p four\" one\"quote p7", TRUE,
1478 " \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\""},
1480 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", TRUE,
1481 " \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1483 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", TRUE,
1484 " \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\""},
1486 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", TRUE,
1487 " \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1489 /* Quoted strings cannot be continued by tacking on a non space character
1490 * either.
1492 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", TRUE,
1493 " \"p two\" \"p3\" \"p four\" \"p5\" \"p6\""},
1495 /* In quoted strings, the quotes are halved and an odd number closes the
1496 * string. Specifically:
1497 * 2n quotes -> n quotes
1498 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1500 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", TRUE,
1501 " \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\""},
1503 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", TRUE,
1504 " \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1506 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", TRUE,
1507 " \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\""},
1509 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", TRUE,
1510 " \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1512 /* The quoted string rules also apply to consecutive quotes at the start
1513 * of a parameter but don't count the opening quote!
1515 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", TRUE,
1516 " \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\""},
1518 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", TRUE,
1519 " \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1521 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", TRUE,
1522 " \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\""},
1524 /* An unclosed quoted string gets lost! */
1525 {"Params23456", "p2 \"p3\" \"p4 is lost", TRUE,
1526 " \"p2\" \"p3\" \"\" \"\" \"\"",
1527 " \"p2\" \"p3\" \"p3\" \"\" \"\""}, /* NT4/2k */
1529 /* Backslashes have no special meaning even when preceding quotes. All
1530 * they do is start an unquoted string.
1532 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", TRUE,
1533 " \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\""},
1535 /* Environment variables are left untouched. */
1536 {"Params23456", "%TMPDIR% %t %c", FALSE,
1537 " \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\""},
1539 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1540 * before the parameter!
1541 * (but not the previous parameter's closing quote fortunately)
1543 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", TRUE,
1544 " ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 "},
1546 /* %~n works even if there is no nth parameter. */
1547 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", TRUE,
1548 " ~9=\" \""},
1550 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", TRUE,
1551 " ~9=\"\""},
1553 /* The %~n directives also transmit the tenth parameter and beyond. */
1554 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", TRUE,
1555 " ~9=\" p9 p10 p11 and beyond!\""},
1557 /* Bad formatting directives lose their % sign, except those followed by
1558 * a tilde! Environment variables are not expanded but lose their % sign.
1560 {"ParamsBad", "p2 p3 p4 p5", TRUE,
1561 " \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\""},
1566 static void test_argify(void)
1568 char fileA[MAX_PATH + 18], params[2 * MAX_PATH + 28];
1569 INT_PTR rc;
1570 const argify_tests_t* test;
1571 const char *bad;
1572 const char* cmd;
1574 /* Test with a long parameter */
1575 for (rc = 0; rc < MAX_PATH; rc++)
1576 fileA[rc] = 'a' + rc % 26;
1577 fileA[MAX_PATH-1] = '\0';
1578 sprintf(params, "shlexec \"%s\" %s", child_file, fileA);
1580 /* We need NOZONECHECKS on Win2003 to block a dialog */
1581 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params, NULL, NULL);
1582 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1583 okChildInt("argcA", 4);
1584 okChildPath("argvA3", fileA);
1586 if (skip_shlexec_tests)
1588 skip("No argify tests due to lack of .shlexec association\n");
1589 return;
1592 create_test_verb("shlexec.shlexec", "ParamsS", 0, "ParamsS %*");
1593 create_test_verb("shlexec.shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1594 create_test_verb("shlexec.shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1595 create_test_verb("shlexec.shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1596 create_test_verb("shlexec.shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1597 create_test_verb("shlexec.shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1598 create_test_verb("shlexec.shlexec", "Params20", 0, "Params20 \"%20\"");
1599 create_test_verb("shlexec.shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1601 sprintf(fileA, "%s\\test file.shlexec", tmpdir);
1603 test = argify_tests;
1604 while (test->params)
1606 bad = test->broken ? test->broken : test->cmd;
1608 rc = shell_execute_ex(SEE_MASK_DOENVSUBST, test->verb, fileA, test->params, NULL, NULL);
1609 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1611 cmd = getChildString("Child", "cmdlineA");
1612 /* Our commands are such that the verb immediately precedes the
1613 * part we are interested in.
1615 if (cmd) cmd = strstr(cmd, test->verb);
1616 if (cmd) cmd += strlen(test->verb);
1617 if (!cmd) cmd = "(null)";
1618 todo_wine_if(test->todo)
1619 okShell(!strcmp(cmd, test->cmd) || broken(!strcmp(cmd, bad)),
1620 "expected '%s', got '%s'\n", test->cmd, cmd);
1621 test++;
1625 static void test_filename(void)
1627 char filename[MAX_PATH + 20];
1628 const filename_tests_t* test;
1629 char* c;
1630 INT_PTR rc;
1632 if (skip_shlexec_tests)
1634 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1635 return;
1638 test=filename_tests;
1639 while (test->basename)
1641 BOOL quotedfile = FALSE;
1643 if (skip_noassoc_tests && test->rc == SE_ERR_NOASSOC)
1645 win_skip("Skipping shellexecute of file with unassociated extension\n");
1646 test++;
1647 continue;
1650 sprintf(filename, test->basename, tmpdir);
1651 if (strchr(filename, '/'))
1653 c=filename;
1654 while (*c)
1656 if (*c=='\\')
1657 *c='/';
1658 c++;
1661 if ((test->todo & 0x40)==0)
1663 rc=shell_execute(test->verb, filename, NULL, NULL);
1665 else
1667 char quoted[MAX_PATH + 22];
1669 quotedfile = TRUE;
1670 sprintf(quoted, "\"%s\"", filename);
1671 rc=shell_execute(test->verb, quoted, NULL, NULL);
1673 if (rc > 32)
1674 rc=33;
1675 okShell(rc==test->rc ||
1676 broken(quotedfile && rc == SE_ERR_FNF), /* NT4 */
1677 "failed: rc=%Id err=%lu\n", rc, GetLastError());
1678 if (rc == 33)
1680 const char* verb;
1681 todo_wine_if(test->todo & 0x2)
1682 okChildInt("argcA", 5);
1683 verb=(test->verb ? test->verb : "Open");
1684 todo_wine_if(test->todo & 0x4)
1685 okChildString("argvA3", verb);
1686 todo_wine_if(test->todo & 0x8)
1687 okChildPath("argvA4", filename);
1689 test++;
1692 test=noquotes_tests;
1693 while (test->basename)
1695 sprintf(filename, test->basename, tmpdir);
1696 rc=shell_execute(test->verb, filename, NULL, NULL);
1697 if (rc > 32)
1698 rc=33;
1699 todo_wine_if(test->todo & 0x1)
1700 okShell(rc==test->rc, "failed: rc=%Id err=%lu\n", rc, GetLastError());
1701 if (rc==0)
1703 int count;
1704 const char* verb;
1705 char* str;
1707 verb=(test->verb ? test->verb : "Open");
1708 todo_wine_if(test->todo & 0x4)
1709 okChildString("argvA3", verb);
1711 count=4;
1712 str=filename;
1713 while (1)
1715 char attrib[18];
1716 char* space;
1717 space=strchr(str, ' ');
1718 if (space)
1719 *space='\0';
1720 sprintf(attrib, "argvA%d", count);
1721 todo_wine_if(test->todo & 0x8)
1722 okChildPath(attrib, str);
1723 count++;
1724 if (!space)
1725 break;
1726 str=space+1;
1728 todo_wine_if(test->todo & 0x2)
1729 okChildInt("argcA", count);
1731 test++;
1734 if (dllver.dwMajorVersion != 0)
1736 /* The more recent versions of shell32.dll accept quoted filenames
1737 * while older ones (e.g. 4.00) don't. Still we want to test this
1738 * because IE 6 depends on the new behavior.
1739 * One day we may need to check the exact version of the dll but for
1740 * now making sure DllGetVersion() is present is sufficient.
1742 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
1743 rc=shell_execute(NULL, filename, NULL, NULL);
1744 okShell(rc > 32, "failed: rc=%Id err=%lu\n", rc, GetLastError());
1745 okChildInt("argcA", 5);
1746 okChildString("argvA3", "Open");
1747 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1748 okChildPath("argvA4", filename);
1751 sprintf(filename, "\"%s\\test file.sha\"", tmpdir);
1752 rc=shell_execute(NULL, filename, NULL, NULL);
1753 todo_wine okShell(rc > 32, "failed: rc=%Id err=%lu\n", rc, GetLastError());
1754 okChildInt("argcA", 5);
1755 todo_wine okChildString("argvA3", "averb");
1756 sprintf(filename, "%s\\test file.sha", tmpdir);
1757 todo_wine okChildPath("argvA4", filename);
1760 typedef struct
1762 const char* urlprefix;
1763 const char* basename;
1764 int flags;
1765 int todo;
1766 } fileurl_tests_t;
1768 #define URL_SUCCESS 0x1
1769 #define USE_COLON 0x2
1770 #define USE_BSLASH 0x4
1772 static fileurl_tests_t fileurl_tests[]=
1774 /* How many slashes does it take... */
1775 {"file:", "%s\\test file.shlexec", URL_SUCCESS, 0},
1776 {"file:/", "%s\\test file.shlexec", URL_SUCCESS, 0},
1777 {"file://", "%s\\test file.shlexec", URL_SUCCESS, 0},
1778 {"file:///", "%s\\test file.shlexec", URL_SUCCESS, 0},
1779 {"File:///", "%s\\test file.shlexec", URL_SUCCESS, 0},
1780 {"file:////", "%s\\test file.shlexec", URL_SUCCESS, 0},
1781 {"file://///", "%s\\test file.shlexec", 0, 0},
1783 /* Test with Windows-style paths */
1784 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_COLON, 0},
1785 {"file:///", "%s\\test file.shlexec", URL_SUCCESS | USE_BSLASH, 0},
1787 /* Check handling of hostnames */
1788 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS, 0},
1789 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1790 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS, 0},
1791 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1792 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1793 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1795 /* Environment variables are not expanded in URLs */
1796 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1797 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1799 /* Test shortcuts vs. URLs */
1800 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1c},
1802 /* Confuse things by mixing protocols */
1803 {"file://", "shlproto://foo/bar", USE_COLON, 0},
1805 {NULL, NULL, 0, 0}
1808 static void test_fileurls(void)
1810 char filename[MAX_PATH], fileurl[MAX_PATH], longtmpdir[MAX_PATH];
1811 char command[MAX_PATH];
1812 const fileurl_tests_t* test;
1813 char *s;
1814 INT_PTR rc;
1816 if (skip_shlexec_tests)
1818 skip("No file URL tests due to lack of .shlexec association\n");
1819 return;
1822 rc = shell_execute_ex(SEE_MASK_FLAG_NO_UI, NULL,
1823 "file:///nosuchfile.shlexec", NULL, NULL, NULL);
1824 if (rc > 32)
1826 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1827 return;
1830 get_long_path_name(tmpdir, longtmpdir, ARRAY_SIZE(longtmpdir));
1831 SetEnvironmentVariableA("urlprefix", "file:///");
1833 test=fileurl_tests;
1834 while (test->basename)
1836 /* Build the file URL */
1837 sprintf(filename, test->basename, longtmpdir);
1838 strcpy(fileurl, test->urlprefix);
1839 strcat(fileurl, filename);
1840 s = fileurl + strlen(test->urlprefix);
1841 while (*s)
1843 if (!(test->flags & USE_COLON) && *s == ':')
1844 *s = '|';
1845 else if (!(test->flags & USE_BSLASH) && *s == '\\')
1846 *s = '/';
1847 s++;
1850 /* Test it first with FindExecutable() */
1851 rc = (INT_PTR)FindExecutableA(fileurl, NULL, command);
1852 ok(rc == SE_ERR_FNF, "FindExecutable(%s) failed: bad rc=%Iu\n", fileurl, rc);
1854 /* Then ShellExecute() */
1855 if ((test->todo & 0x10) == 0)
1856 rc = shell_execute(NULL, fileurl, NULL, NULL);
1857 else todo_wait
1858 rc = shell_execute(NULL, fileurl, NULL, NULL);
1859 if (bad_shellexecute)
1861 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1862 break;
1864 if (test->flags & URL_SUCCESS)
1866 todo_wine_if(test->todo & 0x1)
1867 okShell(rc > 32, "failed: bad rc=%Iu\n", rc);
1869 else
1871 todo_wine_if(test->todo & 0x1)
1872 okShell(rc == SE_ERR_FNF || rc == SE_ERR_PNF ||
1873 broken(rc == SE_ERR_ACCESSDENIED) /* win2000 */,
1874 "failed: bad rc=%Iu\n", rc);
1876 if (rc == 33)
1878 todo_wine_if(test->todo & 0x2)
1879 okChildInt("argcA", 5);
1880 todo_wine_if(test->todo & 0x4)
1881 okChildString("argvA3", "Open");
1882 todo_wine_if(test->todo & 0x8)
1883 okChildPath("argvA4", filename);
1885 test++;
1888 SetEnvironmentVariableA("urlprefix", NULL);
1891 static void test_urls(void)
1893 char url[MAX_PATH + 15];
1894 INT_PTR rc;
1896 if (!create_test_class("fakeproto", FALSE))
1898 skip("Unable to create 'fakeproto' class for URL tests\n");
1899 return;
1901 create_test_verb("fakeproto", "open", 0, "URL %1");
1903 create_test_class("shlpaverb", TRUE);
1904 create_test_verb("shlpaverb", "averb", 0, "PAVerb \"%1\"");
1906 /* Protocols must be properly declared */
1907 rc = shell_execute(NULL, "notaproto://foo", NULL, NULL);
1908 ok(rc == SE_ERR_NOASSOC || broken(rc == SE_ERR_ACCESSDENIED),
1909 "%s returned %Iu\n", shell_call, rc);
1911 rc = shell_execute(NULL, "fakeproto://foo/bar", NULL, NULL);
1912 todo_wine ok(rc == SE_ERR_NOASSOC || broken(rc == SE_ERR_ACCESSDENIED),
1913 "%s returned %Iu\n", shell_call, rc);
1915 /* Here's a real live one */
1916 rc = shell_execute(NULL, "shlproto://foo/bar", NULL, NULL);
1917 ok(rc > 32, "%s failed: rc=%Iu\n", shell_call, rc);
1918 okChildInt("argcA", 5);
1919 okChildString("argvA3", "URL");
1920 okChildString("argvA4", "shlproto://foo/bar");
1922 /* Check default verb detection */
1923 rc = shell_execute(NULL, "shlpaverb://foo/bar", NULL, NULL);
1924 todo_wine ok(rc > 32 || /* XP+IE7 - Win10 */
1925 broken(rc == SE_ERR_NOASSOC), /* XP+IE6 */
1926 "%s failed: rc=%Iu\n", shell_call, rc);
1927 if (rc > 32)
1929 okChildInt("argcA", 5);
1930 todo_wine okChildString("argvA3", "PAVerb");
1931 todo_wine okChildString("argvA4", "shlpaverb://foo/bar");
1934 /* But alternative verbs are a recent feature! */
1935 rc = shell_execute("averb", "shlproto://foo/bar", NULL, NULL);
1936 ok(rc > 32 || /* Win8 - Win10 */
1937 broken(rc == SE_ERR_ACCESSDENIED), /* XP - Win7 */
1938 "%s failed: rc=%Iu\n", shell_call, rc);
1939 if (rc > 32)
1941 okChildString("argvA3", "AVerb");
1942 okChildString("argvA4", "shlproto://foo/bar");
1945 /* A .lnk ending does not turn a URL into a shortcut */
1946 rc = shell_execute(NULL, "shlproto://foo/bar.lnk", NULL, NULL);
1947 ok(rc > 32, "%s failed: rc=%Iu\n", shell_call, rc);
1948 okChildInt("argcA", 5);
1949 okChildString("argvA3", "URL");
1950 okChildString("argvA4", "shlproto://foo/bar.lnk");
1952 /* Neither does a .exe extension */
1953 rc = shell_execute(NULL, "shlproto://foo/bar.exe", NULL, NULL);
1954 ok(rc > 32, "%s failed: rc=%Iu\n", shell_call, rc);
1955 okChildInt("argcA", 5);
1956 okChildString("argvA3", "URL");
1957 okChildString("argvA4", "shlproto://foo/bar.exe");
1959 /* But a class name overrides it */
1960 rc = shell_execute(NULL, "shlproto://foo/bar", "shlexec.shlexec", NULL);
1961 ok(rc > 32, "%s failed: rc=%Iu\n", shell_call, rc);
1962 okChildInt("argcA", 5);
1963 okChildString("argvA3", "URL");
1964 okChildString("argvA4", "shlproto://foo/bar");
1966 /* Environment variables are expanded in URLs (but not in file URLs!) */
1967 rc = shell_execute_ex(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI,
1968 NULL, "shlproto://%TMPDIR%/bar", NULL, NULL, NULL);
1969 okShell(rc > 32, "failed: rc=%Iu\n", rc);
1970 okChildInt("argcA", 5);
1971 sprintf(url, "shlproto://%s/bar", tmpdir);
1972 okChildString("argvA3", "URL");
1973 okChildStringBroken("argvA4", url, "shlproto://%TMPDIR%/bar");
1975 /* But only after the path has been identified as a URL */
1976 SetEnvironmentVariableA("urlprefix", "shlproto:///");
1977 rc = shell_execute(NULL, "%urlprefix%foo", NULL, NULL);
1978 todo_wine ok(rc == SE_ERR_FNF, "%s returned %Iu\n", shell_call, rc);
1979 SetEnvironmentVariableA("urlprefix", NULL);
1981 delete_test_class("fakeproto");
1982 delete_test_class("shlpaverb");
1985 static void test_find_executable(void)
1987 char notepad_path[MAX_PATH];
1988 char filename[MAX_PATH + 17];
1989 char command[MAX_PATH];
1990 const filename_tests_t* test;
1991 INT_PTR rc;
1993 if (!create_test_association(".sfe"))
1995 skip("Unable to create association for '.sfe'\n");
1996 return;
1998 create_test_verb("shlexec.sfe", "Open", 1, "%1");
2000 /* Don't test FindExecutable(..., NULL), it always crashes */
2002 strcpy(command, "your word");
2003 if (0) /* Can crash on Vista! */
2005 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
2006 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %Id\n", rc);
2007 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
2010 GetSystemDirectoryA( notepad_path, MAX_PATH );
2011 strcat( notepad_path, "\\notepad.exe" );
2013 /* Search for something that should be in the system-wide search path (no default directory) */
2014 strcpy(command, "your word");
2015 rc=(INT_PTR)FindExecutableA("notepad.exe", NULL, command);
2016 ok(rc > 32, "FindExecutable(%s) returned %Id\n", "notepad.exe", rc);
2017 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
2019 /* Search for something that should be in the system-wide search path (with default directory) */
2020 strcpy(command, "your word");
2021 rc=(INT_PTR)FindExecutableA("notepad.exe", tmpdir, command);
2022 ok(rc > 32, "FindExecutable(%s) returned %Id\n", "notepad.exe", rc);
2023 ok(strcasecmp(command, notepad_path) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command);
2025 strcpy(command, "your word");
2026 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
2027 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %Id\n", rc);
2028 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
2030 sprintf(filename, "%s\\test file.sfe", tmpdir);
2031 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
2032 ok(rc > 32, "FindExecutable(%s) returned %Id\n", filename, rc);
2033 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
2035 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
2036 ok(rc > 32, "FindExecutable(%s) returned %Id\n", filename, rc);
2038 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
2039 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %Id\n", filename, rc);
2041 delete_test_association(".sfe");
2043 if (!create_test_association(".shl"))
2045 skip("Unable to create association for '.shl'\n");
2046 return;
2048 create_test_verb("shlexec.shl", "Open", 0, "Open");
2050 sprintf(filename, "%s\\test file.shl", tmpdir);
2051 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
2052 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %Id\n", filename, rc);
2054 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
2055 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
2057 delete_test_association(".shl");
2059 if (rc > 32)
2061 /* On Windows XP and 2003 FindExecutable() is completely broken.
2062 * Probably what it does is convert the filename to 8.3 format,
2063 * which as a side effect converts the '.shlfoo' extension to '.shl',
2064 * and then tries to find an association for '.shl'. This means it
2065 * will normally fail on most extensions with more than 3 characters,
2066 * like '.mpeg', etc.
2067 * Also it means we cannot do any other test.
2069 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
2070 return;
2073 if (skip_shlexec_tests)
2075 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2076 return;
2079 test=filename_tests;
2080 while (test->basename)
2082 sprintf(filename, test->basename, tmpdir);
2083 if (strchr(filename, '/'))
2085 char* c;
2086 c=filename;
2087 while (*c)
2089 if (*c=='\\')
2090 *c='/';
2091 c++;
2094 /* Win98 does not '\0'-terminate command! */
2095 memset(command, '\0', sizeof(command));
2096 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
2097 if (rc > 32)
2098 rc=33;
2099 todo_wine_if(test->todo & 0x10)
2100 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%Id\n", filename, rc);
2101 if (rc > 32)
2103 BOOL equal;
2104 equal=strcmp(command, argv0) == 0 ||
2105 /* NT4 returns an extra 0x8 character! */
2106 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
2107 todo_wine_if(test->todo & 0x20)
2108 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2109 filename, command, argv0);
2111 test++;
2116 static filename_tests_t lnk_tests[]=
2118 /* Pass bad / nonexistent filenames as a parameter */
2119 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
2120 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
2122 /* Pass regular paths as a parameter */
2123 {NULL, "%s\\test file.shlexec", 0xa, 33},
2124 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2126 /* Pass filenames with no association as a parameter */
2127 {NULL, "%s\\test file.noassoc", 0xa, 33},
2129 {NULL, NULL, 0}
2132 static void test_lnks(void)
2134 char filename[MAX_PATH + 26];
2135 char params[MAX_PATH + 18];
2136 const filename_tests_t* test;
2137 INT_PTR rc;
2139 if (skip_shlexec_tests)
2140 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2141 else
2143 /* Should open through our association */
2144 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
2145 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL, NULL);
2146 okShell(rc > 32, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2147 okChildInt("argcA", 5);
2148 okChildString("argvA3", "Open");
2149 sprintf(params, "%s\\test file.shlexec", tmpdir);
2150 get_long_path_name(params, filename, sizeof(filename));
2151 okChildPath("argvA4", filename);
2153 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_DOENVSUBST, NULL, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL, NULL, NULL);
2154 okShell(rc > 32, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2155 okChildInt("argcA", 5);
2156 okChildString("argvA3", "Open");
2157 sprintf(params, "%s\\test file.shlexec", tmpdir);
2158 get_long_path_name(params, filename, sizeof(filename));
2159 okChildPath("argvA4", filename);
2162 /* Should just run our executable */
2163 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2164 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL, NULL);
2165 okShell(rc > 32, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2166 okChildInt("argcA", 4);
2167 okChildString("argvA3", "Lnk");
2169 if (!skip_shlexec_tests)
2171 /* An explicit class overrides lnk's ContextMenuHandler */
2172 rc=shell_execute_ex(SEE_MASK_CLASSNAME | SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL, "shlexec.shlexec");
2173 okShell(rc > 32, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2174 okChildInt("argcA", 5);
2175 okChildString("argvA3", "Open");
2176 okChildPath("argvA4", filename);
2179 if (dllver.dwMajorVersion>=6)
2181 char* c;
2182 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2183 * Older versions don't or are quite buggy in this regard.
2185 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2186 c=filename;
2187 while (*c)
2189 if (*c=='\\')
2190 *c='/';
2191 c++;
2193 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL, NULL);
2194 okShell(rc > 32, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2195 okChildInt("argcA", 4);
2196 okChildString("argvA3", "Lnk");
2199 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2200 test=lnk_tests;
2201 while (test->basename)
2203 params[0]='\"';
2204 sprintf(params+1, test->basename, tmpdir);
2205 strcat(params,"\"");
2206 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
2207 NULL, NULL);
2208 if (rc > 32)
2209 rc=33;
2210 todo_wine_if(test->todo & 0x1)
2211 okShell(rc==test->rc, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2212 if (rc==0)
2214 todo_wine_if(test->todo & 0x2)
2215 okChildInt("argcA", 5);
2216 todo_wine_if(test->todo & 0x4)
2217 okChildString("argvA3", "Lnk");
2218 sprintf(params, test->basename, tmpdir);
2219 okChildPath("argvA4", params);
2221 test++;
2226 static void test_exes(void)
2228 char filename[2 * MAX_PATH + 17];
2229 char params[1024];
2230 INT_PTR rc;
2232 sprintf(params, "shlexec \"%s\" Exec", child_file);
2234 /* We need NOZONECHECKS on Win2003 to block a dialog */
2235 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
2236 NULL, NULL);
2237 okShell(rc > 32, "returned %Iu\n", rc);
2238 okChildInt("argcA", 4);
2239 okChildString("argvA3", "Exec");
2241 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS | SEE_MASK_CLASSNAME | SEE_MASK_FLAG_NO_UI, NULL, argv0, params,
2242 NULL, ".exe");
2243 okShell(rc > 32, "returned %Iu\n", rc);
2244 okChildInt("argcA", 4);
2245 okChildString("argvA3", "Exec");
2247 if (create_test_association_key(".qqqq", "exefile"))
2249 rc = shell_execute_ex(SEE_MASK_NOZONECHECKS | SEE_MASK_CLASSNAME | SEE_MASK_FLAG_NO_UI, NULL, argv0, params,
2250 NULL, ".qqqq");
2251 okShell(rc > 32, "returned %Iu\n", rc);
2252 okChildInt("argcA", 4);
2253 okChildString("argvA3", "Exec");
2254 delete_test_association(".qqqq");
2256 else
2258 skip("Could not create associtation.\n");
2261 if (create_test_association_key("qqqq", "exefile"))
2263 rc = shell_execute_ex(SEE_MASK_NOZONECHECKS | SEE_MASK_CLASSNAME | SEE_MASK_FLAG_NO_UI, NULL, argv0, params,
2264 NULL, "qqqq");
2265 okShell(rc < 32, "returned %Iu\n", rc);
2266 todo_wine okShell(rc == SE_ERR_NOASSOC, "returned %Iu\n", rc);
2267 delete_test_association("qqqq");
2269 else
2271 skip("Could not create associtation.\n");
2274 if (is_elevated)
2276 rc = shell_execute_ex(SEE_MASK_NOZONECHECKS | SEE_MASK_CLASSNAME | SEE_MASK_FLAG_NO_UI, "runas", argv0, params,
2277 NULL, ".exe");
2278 okShell(rc > 32, "returned %Iu\n", rc);
2279 okChildInt("argcA", 4);
2280 okChildString("argvA3", "Exec");
2282 else
2284 skip("No admin privileges, skipping runas test.\n");
2287 if (! skip_noassoc_tests)
2289 sprintf(filename, "%s\\test file.noassoc", tmpdir);
2290 if (CopyFileA(argv0, filename, FALSE))
2292 rc=shell_execute(NULL, filename, params, NULL);
2293 todo_wine {
2294 okShell(rc==SE_ERR_NOASSOC, "returned %Iu\n", rc);
2298 else
2300 win_skip("Skipping shellexecute of file with unassociated extension\n");
2303 /* test combining executable and parameters */
2304 sprintf(filename, "%s shlexec \"%s\" Exec", argv0, child_file);
2305 rc = shell_execute(NULL, filename, NULL, NULL);
2306 okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
2308 sprintf(filename, "\"%s\" shlexec \"%s\" Exec", argv0, child_file);
2309 rc = shell_execute(NULL, filename, NULL, NULL);
2310 okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
2312 /* A verb, even if invalid, overrides the normal handling of executables */
2313 todo_wait rc = shell_execute_ex(SEE_MASK_FLAG_NO_UI,
2314 "notaverb", argv0, NULL, NULL, NULL);
2315 todo_wine okShell(rc == SE_ERR_NOASSOC, "returned %Iu\n", rc);
2317 if (!skip_shlexec_tests)
2319 /* A class overrides the normal handling of executables too */
2320 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2321 rc = shell_execute_ex(SEE_MASK_CLASSNAME | SEE_MASK_FLAG_NO_UI,
2322 NULL, argv0, NULL, NULL, ".shlexec");
2323 okShell(rc > 32, "returned %Iu\n", rc);
2324 okChildInt("argcA", 5);
2325 okChildString("argvA3", "Open");
2326 okChildPath("argvA4", argv0);
2330 typedef struct
2332 const char* command;
2333 const char* ddeexec;
2334 const char* application;
2335 const char* topic;
2336 const char* ifexec;
2337 int expectedArgs;
2338 const char* expectedDdeExec;
2339 BOOL broken;
2340 } dde_tests_t;
2342 static dde_tests_t dde_tests[] =
2344 /* Test passing and not passing command-line
2345 * argument, no DDE */
2346 {"", NULL, NULL, NULL, NULL, 0, ""},
2347 {"\"%1\"", NULL, NULL, NULL, NULL, 1, ""},
2349 /* Test passing and not passing command-line
2350 * argument, with DDE */
2351 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, 0, "[open(\"%s\")]"},
2352 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, 1, "[open(\"%s\")]"},
2354 /* Test unquoted %1 in command and ddeexec
2355 * (test filename has space) */
2356 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", TRUE /* before vista */},
2358 /* Test ifexec precedence over ddeexec */
2359 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2361 /* Test default DDE topic */
2362 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, 0, "[open(\"%s\")]"},
2364 /* Test default DDE application */
2365 {"", "[open(\"%1\")]", NULL, "dde", NULL, 0, "[open(\"%s\")]"},
2367 {NULL}
2370 static int waitforinputidle_count;
2371 static DWORD WINAPI hooked_WaitForInputIdle(HANDLE process, DWORD timeout)
2373 waitforinputidle_count++;
2374 if (winetest_debug > 1)
2375 trace("WaitForInputIdle() waiting for dde event timeout=min(%lu,5s)\n", timeout);
2376 timeout = timeout < 5000 ? timeout : 5000;
2377 return WaitForSingleObject(dde_ready_event, timeout);
2381 * WaitForInputIdle() will normally return immediately for console apps. That's
2382 * a problem for us because ShellExecute will assume that an app is ready to
2383 * receive DDE messages after it has called WaitForInputIdle() on that app.
2384 * To work around that we install our own version of WaitForInputIdle() that
2385 * will wait for the child to explicitly tell us that it is ready. We do that
2386 * by changing the entry for WaitForInputIdle() in the shell32 import address
2387 * table.
2389 static void hook_WaitForInputIdle(DWORD (WINAPI *new_func)(HANDLE, DWORD))
2391 char *base;
2392 PIMAGE_NT_HEADERS nt_headers;
2393 DWORD import_directory_rva;
2394 PIMAGE_IMPORT_DESCRIPTOR import_descriptor;
2395 int hook_count = 0;
2397 base = (char *) GetModuleHandleA("shell32.dll");
2398 nt_headers = (PIMAGE_NT_HEADERS)(base + ((PIMAGE_DOS_HEADER) base)->e_lfanew);
2399 import_directory_rva = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
2401 /* Search for the correct imported module by walking the import descriptors */
2402 import_descriptor = (PIMAGE_IMPORT_DESCRIPTOR)(base + import_directory_rva);
2403 while (import_descriptor->OriginalFirstThunk != 0)
2405 char *import_module_name;
2407 import_module_name = base + import_descriptor->Name;
2408 if (lstrcmpiA(import_module_name, "user32.dll") == 0 ||
2409 lstrcmpiA(import_module_name, "user32") == 0)
2411 PIMAGE_THUNK_DATA int_entry;
2412 PIMAGE_THUNK_DATA iat_entry;
2414 /* The import name table and import address table are two parallel
2415 * arrays. We need the import name table to find the imported
2416 * routine and the import address table to patch the address, so
2417 * walk them side by side */
2418 int_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->OriginalFirstThunk);
2419 iat_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->FirstThunk);
2420 while (int_entry->u1.Ordinal != 0)
2422 if (! IMAGE_SNAP_BY_ORDINAL(int_entry->u1.Ordinal))
2424 PIMAGE_IMPORT_BY_NAME import_by_name;
2425 import_by_name = (PIMAGE_IMPORT_BY_NAME)(base + int_entry->u1.AddressOfData);
2426 if (lstrcmpA((char *) import_by_name->Name, "WaitForInputIdle") == 0)
2428 /* Found the correct routine in the correct imported module. Patch it. */
2429 DWORD old_prot;
2430 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), PAGE_READWRITE, &old_prot);
2431 iat_entry->u1.Function = (ULONG_PTR) new_func;
2432 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), old_prot, &old_prot);
2433 if (winetest_debug > 1)
2434 trace("Hooked %s.WaitForInputIdle\n", import_module_name);
2435 hook_count++;
2436 break;
2439 int_entry++;
2440 iat_entry++;
2442 break;
2445 import_descriptor++;
2447 ok(hook_count, "Could not hook WaitForInputIdle()\n");
2450 static void test_dde(void)
2452 char filename[MAX_PATH + 14], defApplication[MAX_PATH];
2453 const dde_tests_t* test;
2454 char params[1024];
2455 INT_PTR rc;
2456 HANDLE map;
2457 char *shared_block;
2458 DWORD ddeflags;
2460 hook_WaitForInputIdle(hooked_WaitForInputIdle);
2462 sprintf(filename, "%s\\test file.sde", tmpdir);
2464 /* Default service is application name minus path and extension */
2465 strcpy(defApplication, strrchr(argv0, '\\')+1);
2466 *strchr(defApplication, '.') = 0;
2468 map = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
2469 4096, "winetest_shlexec_dde_map");
2470 shared_block = MapViewOfFile(map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 4096);
2472 ddeflags = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
2473 test = dde_tests;
2474 while (test->command)
2476 if (!create_test_association(".sde"))
2478 skip("Unable to create association for '.sde'\n");
2479 return;
2481 create_test_verb_dde("shlexec.sde", "Open", 0, test->command, test->ddeexec,
2482 test->application, test->topic, test->ifexec);
2484 if (test->application != NULL || test->topic != NULL)
2486 strcpy(shared_block, test->application ? test->application : defApplication);
2487 strcpy(shared_block + strlen(shared_block) + 1, test->topic ? test->topic : SZDDESYS_TOPIC);
2489 else
2491 shared_block[0] = '\0';
2492 shared_block[1] = '\0';
2494 ddeExec[0] = 0;
2496 waitforinputidle_count = 0;
2497 dde_ready_event = CreateEventA(NULL, TRUE, FALSE, "winetest_shlexec_dde_ready");
2498 rc = shell_execute_ex(ddeflags, NULL, filename, NULL, NULL, NULL);
2499 CloseHandle(dde_ready_event);
2500 if (!(ddeflags & SEE_MASK_WAITFORINPUTIDLE) && rc == SE_ERR_DDEFAIL &&
2501 GetLastError() == ERROR_FILE_NOT_FOUND &&
2502 strcmp(winetest_platform, "windows") == 0)
2504 /* Windows 10 does not call WaitForInputIdle() for DDE which creates
2505 * a race condition as the DDE server may not have time to start up.
2506 * When that happens the test fails with the above results and we
2507 * compensate by forcing the WaitForInputIdle() call.
2509 trace("Adding SEE_MASK_WAITFORINPUTIDLE for Windows 10\n");
2510 ddeflags |= SEE_MASK_WAITFORINPUTIDLE;
2511 delete_test_association(".sde");
2512 Sleep(CHILD_DDE_TIMEOUT);
2513 continue;
2515 okShell(32 < rc, "failed: rc=%Iu err=%lu\n", rc, GetLastError());
2516 if (test->ddeexec)
2517 okShell(waitforinputidle_count == 1 ||
2518 broken(waitforinputidle_count == 0) /* Win10 race */,
2519 "WaitForInputIdle() was called %u times\n",
2520 waitforinputidle_count);
2521 else
2522 okShell(waitforinputidle_count == 0, "WaitForInputIdle() was called %u times for a non-DDE case\n", waitforinputidle_count);
2524 if (32 < rc)
2526 if (test->broken)
2527 okChildIntBroken("argcA", test->expectedArgs + 3);
2528 else
2529 okChildInt("argcA", test->expectedArgs + 3);
2531 if (test->expectedArgs == 1) okChildPath("argvA3", filename);
2533 sprintf(params, test->expectedDdeExec, filename);
2534 okChildPath("ddeExec", params);
2536 reset_association_description();
2538 delete_test_association(".sde");
2539 test++;
2542 UnmapViewOfFile(shared_block);
2543 CloseHandle(map);
2544 hook_WaitForInputIdle((void *) WaitForInputIdle);
2547 #define DDE_DEFAULT_APP_VARIANTS 3
2548 typedef struct
2550 const char* command;
2551 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
2552 int todo;
2553 int rc[DDE_DEFAULT_APP_VARIANTS];
2554 } dde_default_app_tests_t;
2556 static dde_default_app_tests_t dde_default_app_tests[] =
2558 /* There are three possible sets of results: Windows <= 2000, XP SP1 and
2559 * >= XP SP2. Use the first two tests to determine which results to expect.
2562 /* Test unquoted existing filename with a space */
2563 {"%s\\test file.exe", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2564 {"%s\\test2 file.exe", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2566 /* Test unquoted existing filename with a space */
2567 {"%s\\test file.exe param", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2569 /* Test quoted existing filename with a space */
2570 {"\"%s\\test file.exe\"", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2571 {"\"%s\\test file.exe\" param", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2573 /* Test unquoted filename with a space that doesn't exist, but
2574 * test2.exe does */
2575 {"%s\\test2 file.exe param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2577 /* Test quoted filename with a space that does not exist */
2578 {"\"%s\\test2 file.exe\"", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2579 {"\"%s\\test2 file.exe\" param", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2581 /* Test filename supplied without the extension */
2582 {"%s\\test2", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2583 {"%s\\test2 param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2585 /* Test an unquoted nonexistent filename */
2586 {"%s\\notexist.exe", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2587 {"%s\\notexist.exe param", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2589 /* Test an application that will be found on the path */
2590 {"cmd", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2591 {"cmd param", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2593 /* Test an application that will not be found on the path */
2594 {"xyzwxyzwxyz", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2595 {"xyzwxyzwxyz param", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2597 {NULL, {NULL}, 0, {0}}
2600 typedef struct
2602 char *filename;
2603 DWORD threadIdParent;
2604 } dde_thread_info_t;
2606 static DWORD CALLBACK ddeThread(LPVOID arg)
2608 dde_thread_info_t *info = arg;
2609 assert(info && info->filename);
2610 PostThreadMessageA(info->threadIdParent,
2611 WM_QUIT,
2612 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL, NULL),
2614 ExitThread(0);
2617 static void test_dde_default_app(void)
2619 char filename[MAX_PATH + 14];
2620 HSZ hszApplication;
2621 dde_thread_info_t info = { filename, GetCurrentThreadId() };
2622 const dde_default_app_tests_t* test;
2623 char params[1024];
2624 DWORD threadId;
2625 MSG msg;
2626 INT_PTR rc;
2627 int which = 0;
2628 HDDEDATA ret;
2629 BOOL b;
2631 post_quit_on_execute = FALSE;
2632 ddeInst = 0;
2633 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
2634 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0);
2635 ok(rc == DMLERR_NO_ERROR, "got %Ix\n", rc);
2637 sprintf(filename, "%s\\test file.sde", tmpdir);
2639 /* It is strictly not necessary to register an application name here, but wine's
2640 * DdeNameService implementation complains if 0 is passed instead of
2641 * hszApplication with DNS_FILTEROFF */
2642 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2643 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
2644 ok(hszApplication && hszTopic, "got %p and %p\n", hszApplication, hszTopic);
2645 ret = DdeNameService(ddeInst, hszApplication, 0, DNS_REGISTER | DNS_FILTEROFF);
2646 ok(ret != 0, "got %p\n", ret);
2648 test = dde_default_app_tests;
2649 while (test->command)
2651 HANDLE thread;
2653 if (!create_test_association(".sde"))
2655 skip("Unable to create association for '.sde'\n");
2656 return;
2658 sprintf(params, test->command, tmpdir);
2659 create_test_verb_dde("shlexec.sde", "Open", 1, params, "[test]", NULL,
2660 "shlexec", NULL);
2661 ddeApplication[0] = 0;
2663 /* No application will be run as we will respond to the first DDE event,
2664 * so don't wait for it */
2665 SetEvent(hEvent);
2667 thread = CreateThread(NULL, 0, ddeThread, &info, 0, &threadId);
2668 ok(thread != NULL, "got %p\n", thread);
2669 while (GetMessageA(&msg, NULL, 0, 0)) DispatchMessageA(&msg);
2670 rc = msg.wParam > 32 ? 33 : msg.wParam;
2672 /* The first two tests determine which set of results to expect.
2673 * First check the platform as only the first set of results is
2674 * acceptable for Wine.
2676 if (strcmp(winetest_platform, "wine"))
2678 if (test == dde_default_app_tests)
2680 if (strcmp(ddeApplication, test->expectedDdeApplication[0]))
2681 which = 2;
2683 else if (test == dde_default_app_tests + 1)
2685 if (which == 0 && rc == test->rc[1])
2686 which = 1;
2687 trace("DDE result variant %d\n", which);
2691 todo_wine_if(test->todo & 0x1)
2692 okShell(rc==test->rc[which], "failed: rc=%Iu err=%lu\n",
2693 rc, GetLastError());
2694 if (rc == 33)
2696 todo_wine_if(test->todo & 0x2)
2697 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
2698 "Expected application '%s', got '%s'\n",
2699 test->expectedDdeApplication[which], ddeApplication);
2701 reset_association_description();
2703 delete_test_association(".sde");
2704 test++;
2707 ret = DdeNameService(ddeInst, hszApplication, 0, DNS_UNREGISTER);
2708 ok(ret != 0, "got %p\n", ret);
2709 b = DdeFreeStringHandle(ddeInst, hszTopic);
2710 ok(b, "got %d\n", b);
2711 b = DdeFreeStringHandle(ddeInst, hszApplication);
2712 ok(b, "got %d\n", b);
2713 b = DdeUninitialize(ddeInst);
2714 ok(b, "got %d\n", b);
2717 static void init_test(void)
2719 HMODULE hdll;
2720 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
2721 char filename[MAX_PATH + 26];
2722 WCHAR lnkfile[MAX_PATH];
2723 char params[1024];
2724 const char* const * testfile;
2725 lnk_desc_t desc;
2726 DWORD rc;
2727 HRESULT r;
2728 TOKEN_ELEVATION elevation;
2729 HANDLE token;
2730 BOOL ret;
2732 hdll=GetModuleHandleA("shell32.dll");
2733 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
2734 if (pDllGetVersion)
2736 dllver.cbSize=sizeof(dllver);
2737 pDllGetVersion(&dllver);
2738 trace("major=%ld minor=%ld build=%ld platform=%ld\n",
2739 dllver.dwMajorVersion, dllver.dwMinorVersion,
2740 dllver.dwBuildNumber, dllver.dwPlatformID);
2742 else
2744 memset(&dllver, 0, sizeof(dllver));
2747 r = CoInitialize(NULL);
2748 ok(r == S_OK, "CoInitialize failed (0x%08lx)\n", r);
2749 if (FAILED(r))
2750 exit(1);
2752 rc=GetModuleFileNameA(NULL, argv0, sizeof(argv0));
2753 ok(rc != 0 && rc < sizeof(argv0), "got %ld\n", rc);
2754 if (GetFileAttributesA(argv0)==INVALID_FILE_ATTRIBUTES)
2756 strcat(argv0, ".so");
2757 ok(GetFileAttributesA(argv0)!=INVALID_FILE_ATTRIBUTES,
2758 "unable to find argv0!\n");
2761 /* Older versions (win 2k) fail tests if there is a space in
2762 the path. */
2763 if (dllver.dwMajorVersion <= 5)
2764 strcpy(tmpdir, "c:\\");
2765 else
2766 GetTempPathA(sizeof(tmpdir), tmpdir);
2767 GetLongPathNameA(tmpdir, tmpdir, sizeof(tmpdir));
2769 /* In case of a failure it is necessary to show the path that was passed to
2770 * ShellExecute(). That means the paths must not be randomized so as not to
2771 * prevent the TestBot from detecting new failures.
2773 strcat(tmpdir, "wtShlexecDir");
2774 DeleteFileA( tmpdir );
2775 rc = CreateDirectoryA( tmpdir, NULL );
2776 ok( rc || GetLastError() == ERROR_ALREADY_EXISTS,
2777 "failed to create %s err %lu\n", tmpdir, GetLastError() );
2778 /* Set %TMPDIR% for the tests */
2779 SetEnvironmentVariableA("TMPDIR", tmpdir);
2781 strcpy(child_file, tmpdir);
2782 strcat(child_file, "\\wtShlexecFile");
2783 init_event(child_file);
2785 /* Set up the test files */
2786 testfile=testfiles;
2787 while (*testfile)
2789 HANDLE hfile;
2791 sprintf(filename, *testfile, tmpdir);
2792 hfile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2793 FILE_ATTRIBUTE_NORMAL, NULL);
2794 if (hfile==INVALID_HANDLE_VALUE)
2796 trace("unable to create '%s': err=%lu\n", filename, GetLastError());
2797 assert(0);
2799 CloseHandle(hfile);
2800 testfile++;
2803 /* Setup the test shortcuts */
2804 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
2805 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, ARRAY_SIZE(lnkfile));
2806 desc.description=NULL;
2807 desc.workdir=NULL;
2808 sprintf(filename, "%s\\test file.shlexec", tmpdir);
2809 desc.path=filename;
2810 desc.pidl=NULL;
2811 desc.arguments="ignored";
2812 desc.showcmd=0;
2813 desc.icon=NULL;
2814 desc.icon_id=0;
2815 desc.hotkey=0;
2816 create_lnk(lnkfile, &desc);
2818 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
2819 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, ARRAY_SIZE(lnkfile));
2820 desc.description=NULL;
2821 desc.workdir=NULL;
2822 desc.path=argv0;
2823 desc.pidl=NULL;
2824 sprintf(params, "shlexec \"%s\" Lnk", child_file);
2825 desc.arguments=params;
2826 desc.showcmd=0;
2827 desc.icon=NULL;
2828 desc.icon_id=0;
2829 desc.hotkey=0;
2830 create_lnk(lnkfile, &desc);
2832 /* Create a basic association suitable for most tests */
2833 if (!create_test_association(".shlexec"))
2835 skip_shlexec_tests = TRUE;
2836 skip("Unable to create association for '.shlexec'\n");
2837 return;
2839 create_test_verb("shlexec.shlexec", "Open", 0, "Open \"%1\"");
2840 create_test_verb("shlexec.shlexec", "NoQuotes", 0, "NoQuotes %1");
2841 create_test_verb("shlexec.shlexec", "LowerL", 0, "LowerL %l");
2842 create_test_verb("shlexec.shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2843 create_test_verb("shlexec.shlexec", "UpperL", 0, "UpperL %L");
2844 create_test_verb("shlexec.shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2846 create_test_association(".sha");
2847 create_test_verb("shlexec.sha", "averb", 0, "AVerb \"%1\"");
2849 create_test_class("shlproto", TRUE);
2850 create_test_verb("shlproto", "open", 0, "URL \"%1\"");
2851 create_test_verb("shlproto", "averb", 0, "AVerb \"%1\"");
2853 /* Set an environment variable to see if it is inherited */
2854 SetEnvironmentVariableA("ShlexecVar", "Present");
2856 ret = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
2857 ok(ret, "OpenProcessToken failed.\n");
2858 ret = GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &rc);
2859 ok(ret, "GetTokenInformation failed.\n");
2860 is_elevated = elevation.TokenIsElevated;
2861 CloseHandle(token);
2864 static void cleanup_test(void)
2866 char filename[MAX_PATH];
2867 const char* const * testfile;
2869 /* Delete the test files */
2870 testfile=testfiles;
2871 while (*testfile)
2873 sprintf(filename, *testfile, tmpdir);
2874 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2875 SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL);
2876 DeleteFileA(filename);
2877 testfile++;
2879 DeleteFileA(child_file);
2880 RemoveDirectoryA(tmpdir);
2882 /* Delete the test association */
2883 delete_test_association(".shlexec");
2884 delete_test_association(".sha");
2885 delete_test_class("shlproto");
2887 CloseHandle(hEvent);
2889 CoUninitialize();
2892 static void test_directory(void)
2894 char path[MAX_PATH + 10], curdir[MAX_PATH];
2895 char params[1024], dirpath[1024];
2896 INT_PTR rc;
2897 BOOL ret;
2899 sprintf(path, "%s\\test2.exe", tmpdir);
2900 CopyFileA(argv0, path, FALSE);
2902 sprintf(params, "shlexec \"%s\" Exec", child_file);
2904 /* Test with the current directory */
2905 GetCurrentDirectoryA(sizeof(curdir), curdir);
2906 SetCurrentDirectoryA(tmpdir);
2907 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2908 NULL, "test2.exe", params, NULL, NULL);
2909 okShell(rc > 32, "returned %Iu\n", rc);
2910 okChildInt("argcA", 4);
2911 todo_wine okChildString("argvA0", path);
2912 okChildString("argvA3", "Exec");
2913 okChildPath("longPath", path);
2914 SetCurrentDirectoryA(curdir);
2916 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2917 NULL, "test2.exe", params, NULL, NULL);
2918 okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
2920 /* Explicitly specify the directory to use */
2921 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2922 NULL, "test2.exe", params, tmpdir, NULL);
2923 okShell(rc > 32, "returned %Iu\n", rc);
2924 okChildInt("argcA", 4);
2925 okChildString("argvA0", path);
2926 okChildString("argvA3", "Exec");
2927 okChildPath("longPath", path);
2929 /* Specify it through an environment variable */
2930 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2931 NULL, "test2.exe", params, "%TMPDIR%", NULL);
2932 todo_wine okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
2934 rc=shell_execute_ex(SEE_MASK_DOENVSUBST|SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2935 NULL, "test2.exe", params, "%TMPDIR%", NULL);
2936 okShell(rc > 32, "returned %Iu\n", rc);
2937 okChildInt("argcA", 4);
2938 okChildString("argvA0", path);
2939 okChildString("argvA3", "Exec");
2940 okChildPath("longPath", path);
2942 /* Not a colon-separated directory list */
2943 sprintf(dirpath, "%s:%s", curdir, tmpdir);
2944 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2945 NULL, "test2.exe", params, dirpath, NULL);
2946 okShell(rc == SE_ERR_FNF, "returned %Iu\n", rc);
2948 /* Same-named executable in different directory */
2949 snprintf(path, ARRAY_SIZE(path), "%s%s", tmpdir, strrchr(argv0, '\\'));
2950 CopyFileA(argv0, path, FALSE);
2951 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2952 NULL, strrchr(argv0, '\\') + 1, params, tmpdir, NULL);
2953 okShell(rc > 32, "returned %Iu\n", rc);
2954 okChildInt("argcA", 4);
2955 okChildString("argvA0", path);
2956 okChildString("argvA3", "Exec");
2957 okChildPath("longPath", path);
2959 SetCurrentDirectoryA(tmpdir);
2960 ret = CreateDirectoryA( "tmp", NULL );
2961 ok(ret || GetLastError() == ERROR_ALREADY_EXISTS, "Failed to create 'tmp' err %lu\n", GetLastError());
2962 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS|SEE_MASK_FLAG_NO_UI,
2963 NULL, path, params, "tmp", NULL);
2964 okShell(rc > 32, "returned %Iu\n", rc);
2966 DeleteFileA(path);
2968 RemoveDirectoryA("tmp");
2969 SetCurrentDirectoryA(curdir);
2972 START_TEST(shlexec)
2975 myARGC = winetest_get_mainargs(&myARGV);
2976 if (myARGC >= 3)
2978 doChild(myARGC, myARGV);
2979 /* Skip the tests/failures trace for child processes */
2980 ExitProcess(winetest_get_failures());
2983 init_test();
2985 test_commandline2argv();
2986 test_argify();
2987 test_lpFile_parsed();
2988 test_filename();
2989 test_fileurls();
2990 test_urls();
2991 test_find_executable();
2992 test_lnks();
2993 test_exes();
2994 test_dde();
2995 test_dde_default_app();
2996 test_directory();
2998 cleanup_test();