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
22 * - test the default verb selection
23 * - test selection of an alternate class
24 * - try running executables in more ways
25 * - try passing arguments to executables
26 * - ShellExecute("foo.shlexec") with no path should work if foo.shlexec is
28 * - test associations that use %l, %L or "%1" instead of %1
29 * - ShellExecuteEx() also calls SetLastError() with meaningful values which
43 #include "wine/test.h"
45 #include "shell32_test.h"
48 static char argv0
[MAX_PATH
];
51 static char tmpdir
[MAX_PATH
];
52 static char child_file
[MAX_PATH
];
53 static DLLVERSIONINFO dllver
;
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
;
62 * Helpers to read from / write to the child process results file.
63 * (borrowed from dlls/kernel32/tests/process.c)
67 static const char* encodeA(const char* str
)
69 static char encoded
[2*1024+1];
74 len
= strlen(str
) + 1;
75 if (len
>= sizeof(encoded
)/2)
77 fprintf(stderr
, "string is too long!\n");
81 for (i
= 0; i
< len
; i
++)
82 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
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');
95 static char* decodeA(const char* str
)
97 static char decoded
[1024];
101 len
= strlen(str
) / 2;
102 if (!len
--) return NULL
;
103 if (len
>= sizeof(decoded
))
105 fprintf(stderr
, "string is too long!\n");
109 for (i
= 0; i
< len
; i
++)
110 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
115 static void WINAPIV
__WINE_PRINTF_ATTR(2,3) childPrintf(HANDLE h
, const char* fmt
, ...)
121 va_start(valist
, fmt
);
122 vsprintf(buffer
, fmt
, valist
);
124 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
127 static char* getChildString(const char* sect
, const char* key
)
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));
146 #define CHILD_DDE_TIMEOUT 2500
147 static DWORD ddeInst
;
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
)
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
);
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
;
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
)
182 return (HDDEDATA
)DDE_FACK
;
189 static HANDLE hEvent
;
190 static void init_event(const char* child_file
)
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");
210 static void doChild(int argc
, char** argv
)
212 char *filename
, buffer
[MAX_PATH
];
218 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
219 if (hFile
== INVALID_HANDLE_VALUE
)
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 */
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");
252 char *shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
254 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
261 post_quit_on_execute
= TRUE
;
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");
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
);
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");
297 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_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());
310 init_event(filename
);
315 static void dump_child_(const char* file
, int line
)
317 if (winetest_debug
> 1)
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
);
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
);
347 * Helpers to check the ShellExecute() / child process results.
351 static char shell_call
[2048];
352 static void WINAPIV
__WINE_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
357 strcpy(buffer
, shell_call
);
359 va_start(valist
, msg
);
360 vsprintf(buffer
+strlen(buffer
), msg
, 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)
373 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
376 result
=getChildString("Child", key
);
379 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
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;
402 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
404 while (*s1
=='/' || *s1
=='\\')
406 while (*s2
=='/' || *s2
=='\\')
409 else if (toupper(*s1
)==toupper(*s2
))
426 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
429 int equal
, shortequal
;
430 result
=getChildString("Child", key
);
433 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
437 equal
= (StrCmpPath(result
, expected
) == 0);
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);
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
)
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
)
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))
477 * ShellExecute wrappers
481 static void strcat_param(char* str
, const char* name
, const char* param
)
485 if (str
[strlen(str
)-1] == '"')
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;
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
);
528 wait_rc
=WaitForSingleObject(hEvent
, 5000);
529 if (wait_rc
== WAIT_TIMEOUT
)
531 HWND wnd
= FindWindowA("#32770", "Windows");
533 wnd
= FindWindowA("Shell_Flyout", "");
536 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
537 win_skip("Skipping shellexecute of file with unassociated extension\n");
538 skip_noassoc_tests
= TRUE
;
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
)
553 dump_child_(file
, line
);
554 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
556 winetest_add_failures(c
);
557 okChildInt_(file
, line
, "ShlexecVarLE", 0);
558 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
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
);
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
,
581 SHELLEXECUTEINFOA sei
;
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
);
606 sei
.lpParameters
=parameters
;
607 sei
.lpDirectory
=directory
;
608 sei
.nShow
=SW_SHOWNORMAL
;
609 sei
.hInstApp
=NULL
; /* Out */
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",
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",
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
);
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
)
656 dump_child_(file
, line
);
657 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
659 winetest_add_failures(c
);
660 c
= GetPrivateProfileIntA("Child", "Timeout", -1, child_file
);
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
);
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", "", "");
680 okChildInt_(file
, line
, "ShlexecVarLE", 0);
681 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
687 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
688 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
693 * Functions to create / delete associations wrappers
697 static BOOL
create_test_class(const char* class, BOOL protocol
)
699 HKEY hkey
, hkey_shell
;
702 rc
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
703 KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
, 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
)
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
);
721 CloseHandle(hkey_shell
);
725 static BOOL
create_test_association_key(const char* extension
, const char *class)
730 rc
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
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
)
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
);
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))
751 return create_test_class(class, FALSE
);
754 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
755 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
758 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
759 DWORD dwMaxLen
, dwSize
;
760 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
765 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
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
;
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
;
788 /* Recursively delete all the subkeys */
792 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
793 NULL
, NULL
, NULL
)) break;
795 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
796 if (ret
) goto cleanup
;
800 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
805 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
806 NULL
, NULL
, NULL
, NULL
)) break;
808 ret
= RegDeleteValueA(hKey
, lpszName
);
809 if (ret
) goto cleanup
;
813 /* Free buffer if allocated */
814 if (lpszName
!= szNameBuf
)
817 RegCloseKey(hSubKey
);
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
,
840 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
841 char shell
[MAX_PATH
];
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
);
871 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
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
);
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
,
891 ok(rc
== ERROR_SUCCESS
, "set value failed with %ld\n", rc
);
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
);
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
,
911 ok(rc
== ERROR_SUCCESS
, "set value failed with %ld\n", rc
);
912 CloseHandle(hkey_topic
);
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
,
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
,
941 reset_association_description();
947 * GetLongPathNameA equivalent that supports Win95 and WinNT
951 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
953 char tmplongpath
[MAX_PATH
];
955 DWORD sp
= 0, lp
= 0;
957 WIN32_FIND_DATAA wfd
;
960 if (!shortpath
|| !shortpath
[0])
963 if (shortpath
[1] == ':')
965 tmplongpath
[0] = shortpath
[0];
966 tmplongpath
[1] = ':';
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 */
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
)
999 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
1000 lp
+= strlen(tmplongpath
+ lp
);
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 */
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",
1042 "%s\\test file.sde",
1043 "%s\\test file.exe",
1045 "%s\\simple.shlexec",
1046 "%s\\drawback_file.noassoc",
1047 "%s\\drawback_file.noassoc foo.shlexec",
1048 "%s\\drawback_nonexist.noassoc foo.shlexec",
1055 const char* basename
;
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
},
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},
1113 static void test_lpFile_parsed(void)
1115 char fileA
[MAX_PATH
+ 38];
1118 if (skip_shlexec_tests
)
1120 skip("No filename parsing tests due to lack of .shlexec association\n");
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
);
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
);
1174 const char* args
[11];
1178 static const cmdline_tests_t cmdline_tests
[] =
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},
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 */
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
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
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},
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},
1339 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1341 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
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");
1355 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1356 "expected NULL-terminated list of commandline arguments\n");
1359 while (test
->args
[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
++)
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
));
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
];
1389 test
= cmdline_tests
;
1392 if (!test_one_cmdline(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
);
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");
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
1429 * - And the way the resulting command line is then parsed to yield the
1430 * argument list we check.
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
,
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.
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
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
,
1550 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", TRUE
,
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];
1570 const argify_tests_t
* test
;
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");
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
);
1625 static void test_filename(void)
1627 char filename
[MAX_PATH
+ 20];
1628 const filename_tests_t
* test
;
1632 if (skip_shlexec_tests
)
1634 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
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");
1650 sprintf(filename
, test
->basename
, tmpdir
);
1651 if (strchr(filename
, '/'))
1661 if ((test
->todo
& 0x40)==0)
1663 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1667 char quoted
[MAX_PATH
+ 22];
1670 sprintf(quoted
, "\"%s\"", filename
);
1671 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1675 okShell(rc
==test
->rc
||
1676 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1677 "failed: rc=%Id err=%lu\n", rc
, GetLastError());
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
);
1692 test
=noquotes_tests
;
1693 while (test
->basename
)
1695 sprintf(filename
, test
->basename
, tmpdir
);
1696 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1699 todo_wine_if(test
->todo
& 0x1)
1700 okShell(rc
==test
->rc
, "failed: rc=%Id err=%lu\n", rc
, GetLastError());
1707 verb
=(test
->verb
? test
->verb
: "Open");
1708 todo_wine_if(test
->todo
& 0x4)
1709 okChildString("argvA3", verb
);
1717 space
=strchr(str
, ' ');
1720 sprintf(attrib
, "argvA%d", count
);
1721 todo_wine_if(test
->todo
& 0x8)
1722 okChildPath(attrib
, str
);
1728 todo_wine_if(test
->todo
& 0x2)
1729 okChildInt("argcA", count
);
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
);
1762 const char* urlprefix
;
1763 const char* basename
;
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},
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
;
1816 if (skip_shlexec_tests
)
1818 skip("No file URL tests due to lack of .shlexec association\n");
1822 rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
, NULL
,
1823 "file:///nosuchfile.shlexec", NULL
, NULL
, NULL
);
1826 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1830 get_long_path_name(tmpdir
, longtmpdir
, ARRAY_SIZE(longtmpdir
));
1831 SetEnvironmentVariableA("urlprefix", "file:///");
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
);
1843 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1845 else if (!(test
->flags
& USE_BSLASH
) && *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
);
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");
1864 if (test
->flags
& URL_SUCCESS
)
1866 todo_wine_if(test
->todo
& 0x1)
1867 okShell(rc
> 32, "failed: bad rc=%Iu\n", rc
);
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
);
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
);
1888 SetEnvironmentVariableA("urlprefix", NULL
);
1891 static void test_urls(void)
1893 char url
[MAX_PATH
+ 15];
1896 if (!create_test_class("fakeproto", FALSE
))
1898 skip("Unable to create 'fakeproto' class for URL tests\n");
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
);
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
);
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
;
1993 if (!create_test_association(".sfe"))
1995 skip("Unable to create association for '.sfe'\n");
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");
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");
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");
2073 if (skip_shlexec_tests
)
2075 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2079 test
=filename_tests
;
2080 while (test
->basename
)
2082 sprintf(filename
, test
->basename
, tmpdir
);
2083 if (strchr(filename
, '/'))
2094 /* Win98 does not '\0'-terminate command! */
2095 memset(command
, '\0', sizeof(command
));
2096 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2099 todo_wine_if(test
->todo
& 0x10)
2100 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%Id\n", filename
, rc
);
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
);
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},
2132 static void test_lnks(void)
2134 char filename
[MAX_PATH
+ 26];
2135 char params
[MAX_PATH
+ 18];
2136 const filename_tests_t
* test
;
2139 if (skip_shlexec_tests
)
2140 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
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)
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
);
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
);
2201 while (test
->basename
)
2204 sprintf(params
+1, test
->basename
, tmpdir
);
2205 strcat(params
,"\"");
2206 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2210 todo_wine_if(test
->todo
& 0x1)
2211 okShell(rc
==test
->rc
, "failed: rc=%Iu err=%lu\n", rc
, GetLastError());
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
);
2226 static void test_exes(void)
2228 char filename
[2 * MAX_PATH
+ 17];
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
,
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
,
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
,
2251 okShell(rc
> 32, "returned %Iu\n", rc
);
2252 okChildInt("argcA", 4);
2253 okChildString("argvA3", "Exec");
2254 delete_test_association(".qqqq");
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
,
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");
2271 skip("Could not create associtation.\n");
2276 rc
= shell_execute_ex(SEE_MASK_NOZONECHECKS
| SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
, "runas", argv0
, params
,
2278 okShell(rc
> 32, "returned %Iu\n", rc
);
2279 okChildInt("argcA", 4);
2280 okChildString("argvA3", "Exec");
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
);
2294 okShell(rc
==SE_ERR_NOASSOC
, "returned %Iu\n", rc
);
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
);
2332 const char* command
;
2333 const char* ddeexec
;
2334 const char* application
;
2338 const char* expectedDdeExec
;
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\")]"},
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
2389 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2392 PIMAGE_NT_HEADERS nt_headers
;
2393 DWORD import_directory_rva
;
2394 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
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. */
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
);
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
;
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
;
2474 while (test
->command
)
2476 if (!create_test_association(".sde"))
2478 skip("Unable to create association for '.sde'\n");
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
);
2491 shared_block
[0] = '\0';
2492 shared_block
[1] = '\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
);
2515 okShell(32 < rc
, "failed: rc=%Iu err=%lu\n", rc
, GetLastError());
2517 okShell(waitforinputidle_count
== 1 ||
2518 broken(waitforinputidle_count
== 0) /* Win10 race */,
2519 "WaitForInputIdle() was called %u times\n",
2520 waitforinputidle_count
);
2522 okShell(waitforinputidle_count
== 0, "WaitForInputIdle() was called %u times for a non-DDE case\n", waitforinputidle_count
);
2527 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
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");
2542 UnmapViewOfFile(shared_block
);
2544 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2547 #define DDE_DEFAULT_APP_VARIANTS 3
2550 const char* command
;
2551 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
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
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}}
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
,
2612 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2617 static void test_dde_default_app(void)
2619 char filename
[MAX_PATH
+ 14];
2621 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2622 const dde_default_app_tests_t
* test
;
2631 post_quit_on_execute
= FALSE
;
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
)
2653 if (!create_test_association(".sde"))
2655 skip("Unable to create association for '.sde'\n");
2658 sprintf(params
, test
->command
, tmpdir
);
2659 create_test_verb_dde("shlexec.sde", "Open", 1, params
, "[test]", 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 */
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]))
2683 else if (test
== dde_default_app_tests
+ 1)
2685 if (which
== 0 && rc
== test
->rc
[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());
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");
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)
2720 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2721 char filename
[MAX_PATH
+ 26];
2722 WCHAR lnkfile
[MAX_PATH
];
2724 const char* const * testfile
;
2728 TOKEN_ELEVATION elevation
;
2732 hdll
=GetModuleHandleA("shell32.dll");
2733 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
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
);
2744 memset(&dllver
, 0, sizeof(dllver
));
2747 r
= CoInitialize(NULL
);
2748 ok(r
== S_OK
, "CoInitialize failed (0x%08lx)\n", r
);
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
2763 if (dllver
.dwMajorVersion
<= 5)
2764 strcpy(tmpdir
, "c:\\");
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 */
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());
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
;
2808 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2811 desc
.arguments
="ignored";
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
;
2824 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2825 desc
.arguments
=params
;
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");
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
;
2864 static void cleanup_test(void)
2866 char filename
[MAX_PATH
];
2867 const char* const * testfile
;
2869 /* Delete the test files */
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
);
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
);
2892 static void test_directory(void)
2894 char path
[MAX_PATH
+ 10], curdir
[MAX_PATH
];
2895 char params
[1024], dirpath
[1024];
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
);
2968 RemoveDirectoryA("tmp");
2969 SetCurrentDirectoryA(curdir
);
2975 myARGC
= winetest_get_mainargs(&myARGV
);
2978 doChild(myARGC
, myARGV
);
2979 /* Skip the tests/failures trace for child processes */
2980 ExitProcess(winetest_get_failures());
2985 test_commandline2argv();
2987 test_lpFile_parsed();
2991 test_find_executable();
2995 test_dde_default_app();