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/heap.h"
44 #include "wine/test.h"
46 #include "shell32_test.h"
49 static char argv0
[MAX_PATH
];
52 static char tmpdir
[MAX_PATH
];
53 static char child_file
[MAX_PATH
];
54 static DLLVERSIONINFO dllver
;
55 static BOOL skip_shlexec_tests
= FALSE
;
56 static BOOL skip_noassoc_tests
= FALSE
;
57 static HANDLE dde_ready_event
;
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
WINETEST_PRINTF_ATTR(2,3) childPrintf(HANDLE h
, const char* fmt
, ...)
121 __ms_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, %08lx, %08lx\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 %d\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 %d\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
);
198 * This is just to make sure the child won't run forever stuck in a
199 * GetMessage() loop when DDE fails for some reason.
201 static void CALLBACK
childTimeout(HWND wnd
, UINT msg
, UINT_PTR timer
, DWORD time
)
203 trace("childTimeout called\n");
208 static void doChild(int argc
, char** argv
)
210 char *filename
, buffer
[MAX_PATH
];
216 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
217 if (hFile
== INVALID_HANDLE_VALUE
)
221 childPrintf(hFile
, "[Child]\r\n");
222 if (winetest_debug
> 2)
224 trace("cmdlineA='%s'\n", GetCommandLineA());
225 trace("argcA=%d\n", argc
);
227 childPrintf(hFile
, "cmdlineA=%s\r\n", encodeA(GetCommandLineA()));
228 childPrintf(hFile
, "argcA=%d\r\n", argc
);
229 for (i
= 0; i
< argc
; i
++)
231 if (winetest_debug
> 2)
232 trace("argvA%d='%s'\n", i
, argv
[i
]);
233 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
235 GetModuleFileNameA(GetModuleHandleA(NULL
), buffer
, sizeof(buffer
));
236 childPrintf(hFile
, "longPath=%s\r\n", encodeA(buffer
));
238 /* Check environment variable inheritance */
241 GetEnvironmentVariableA("ShlexecVar", buffer
, sizeof(buffer
));
242 childPrintf(hFile
, "ShlexecVarLE=%d\r\n", GetLastError());
243 childPrintf(hFile
, "ShlexecVar=%s\r\n", encodeA(buffer
));
245 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
249 char *shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
251 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
258 post_quit_on_execute
= TRUE
;
260 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
261 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
262 ok(rc
== DMLERR_NO_ERROR
, "DdeInitializeA() returned %d\n", rc
);
263 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
264 ok(hszApplication
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
265 shared_block
+= strlen(shared_block
) + 1;
266 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
267 ok(hszTopic
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
268 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
269 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
271 timer
= SetTimer(NULL
, 0, CHILD_DDE_TIMEOUT
, childTimeout
);
273 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
275 CloseHandle(dde_ready
);
277 while (GetMessageA(&msg
, NULL
, 0, 0))
279 if (winetest_debug
> 2)
280 trace("msg %d lParam=%ld wParam=%lu\n", msg
.message
, msg
.lParam
, msg
.wParam
);
281 DispatchMessageA(&msg
);
285 KillTimer(NULL
, timer
);
286 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
287 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
288 ok(DdeFreeStringHandle(ddeInst
, hszTopic
), "DdeFreeStringHandle(topic)\n");
289 ok(DdeFreeStringHandle(ddeInst
, hszApplication
), "DdeFreeStringHandle(application)\n");
290 ok(DdeUninitialize(ddeInst
), "DdeUninitialize() failed\n");
294 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
296 CloseHandle(dde_ready
);
299 UnmapViewOfFile(shared_block
);
301 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
304 childPrintf(hFile
, "Failures=%d\r\n", winetest_get_failures());
307 init_event(filename
);
312 static void dump_child_(const char* file
, int line
)
314 if (winetest_debug
> 1)
320 str
=getChildString("Child", "cmdlineA");
321 trace_(file
, line
)("cmdlineA='%s'\n", str
);
322 c
=GetPrivateProfileIntA("Child", "argcA", -1, child_file
);
323 trace_(file
, line
)("argcA=%d\n",c
);
326 sprintf(key
, "argvA%d", i
);
327 str
=getChildString("Child", key
);
328 trace_(file
, line
)("%s='%s'\n", key
, str
);
331 c
=GetPrivateProfileIntA("Child", "ShlexecVarLE", -1, child_file
);
332 trace_(file
, line
)("ShlexecVarLE=%d\n", c
);
333 str
=getChildString("Child", "ShlexecVar");
334 trace_(file
, line
)("ShlexecVar='%s'\n", str
);
336 c
=GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
337 trace_(file
, line
)("Failures=%d\n", c
);
344 * Helpers to check the ShellExecute() / child process results.
348 static char shell_call
[2048];
349 static void WINAPIV
WINETEST_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
354 strcpy(buffer
, shell_call
);
356 __ms_va_start(valist
, msg
);
357 vsprintf(buffer
+strlen(buffer
), msg
, valist
);
359 winetest_ok(condition
, "%s", buffer
);
361 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
362 #define okShell okShell_(__FILE__, __LINE__)
364 static char assoc_desc
[2048];
365 static void reset_association_description(void)
370 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
373 result
=getChildString("Child", key
);
376 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
379 okShell_(file
, line
)(lstrcmpiA(result
, expected
) == 0 ||
380 broken(lstrcmpiA(result
, bad
) == 0),
381 "%s expected '%s', got '%s'\n", key
, expected
, result
);
383 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
384 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
386 static int StrCmpPath(const char* s1
, const char* s2
)
388 if (!s1
&& !s2
) return 0;
399 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
401 while (*s1
=='/' || *s1
=='\\')
403 while (*s2
=='/' || *s2
=='\\')
406 else if (toupper(*s1
)==toupper(*s2
))
423 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
426 int equal
, shortequal
;
427 result
=getChildString("Child", key
);
430 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
434 equal
= (StrCmpPath(result
, expected
) == 0);
437 char altpath
[MAX_PATH
];
438 DWORD rc
= GetLongPathNameA(expected
, altpath
, sizeof(altpath
));
439 if (0 < rc
&& rc
< sizeof(altpath
))
440 equal
= (StrCmpPath(result
, altpath
) == 0);
443 rc
= GetShortPathNameA(expected
, altpath
, sizeof(altpath
));
444 if (0 < rc
&& rc
< sizeof(altpath
))
445 shortequal
= (StrCmpPath(result
, altpath
) == 0);
448 okShell_(file
,line
)(equal
|| broken(shortequal
) /* XP SP1 */,
449 "%s expected '%s', got '%s'\n", key
, expected
, result
);
451 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
453 static void okChildInt_(const char* file
, int line
, const char* key
, int expected
)
456 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
457 okShell_(file
,line
)(result
== expected
,
458 "%s expected %d, but got %d\n", key
, expected
, result
);
460 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
462 static void okChildIntBroken_(const char* file
, int line
, const char* key
, int expected
)
465 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
466 okShell_(file
,line
)(result
== expected
|| broken(result
!= expected
),
467 "%s expected %d, but got %d\n", key
, expected
, result
);
469 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
474 * ShellExecute wrappers
478 static void strcat_param(char* str
, const char* name
, const char* param
)
482 if (str
[strlen(str
)-1] == '"')
491 static int _todo_wait
= 0;
492 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
494 static int bad_shellexecute
= 0;
496 static INT_PTR
shell_execute_(const char* file
, int line
, LPCSTR verb
, LPCSTR filename
, LPCSTR parameters
, LPCSTR directory
)
498 INT_PTR rc
, rcEmpty
= 0;
501 rcEmpty
= shell_execute_(file
, line
, "", filename
, parameters
, directory
);
503 strcpy(shell_call
, "ShellExecute(");
504 strcat_param(shell_call
, "verb", verb
);
505 strcat_param(shell_call
, "file", filename
);
506 strcat_param(shell_call
, "params", parameters
);
507 strcat_param(shell_call
, "dir", directory
);
508 strcat(shell_call
, ")");
509 strcat(shell_call
, assoc_desc
);
510 if (winetest_debug
> 1)
511 trace_(file
, line
)("Called %s\n", shell_call
);
513 DeleteFileA(child_file
);
514 SetLastError(0xcafebabe);
516 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
517 * association it displays the 'Open With' dialog and I could not find
518 * a flag to prevent this.
520 rc
=(INT_PTR
)ShellExecuteA(NULL
, verb
, filename
, parameters
, directory
, SW_HIDE
);
525 wait_rc
=WaitForSingleObject(hEvent
, 5000);
526 if (wait_rc
== WAIT_TIMEOUT
)
528 HWND wnd
= FindWindowA("#32770", "Windows");
530 wnd
= FindWindowA("Shell_Flyout", "");
533 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
534 win_skip("Skipping shellexecute of file with unassociated extension\n");
535 skip_noassoc_tests
= TRUE
;
539 todo_wine_if(_todo_wait
)
540 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
541 "WaitForSingleObject returned %d\n", wait_rc
);
543 /* The child process may have changed the result file, so let profile
544 * functions know about it
546 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
547 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
550 dump_child_(file
, line
);
551 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
553 winetest_add_failures(c
);
554 okChildInt_(file
, line
, "ShlexecVarLE", 0);
555 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
560 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
561 bad_shellexecute
= 1;
562 okShell_(file
, line
)(rc
== rcEmpty
||
563 broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
564 "Got different return value with empty string: %lu %lu\n", rc
, rcEmpty
);
569 #define shell_execute(verb, filename, parameters, directory) \
570 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
572 static INT_PTR
shell_execute_ex_(const char* file
, int line
,
573 DWORD mask
, LPCSTR verb
, LPCSTR filename
,
574 LPCSTR parameters
, LPCSTR directory
,
578 SHELLEXECUTEINFOA sei
;
582 /* Add some flags so we can wait for the child process */
583 mask
|= SEE_MASK_NOCLOSEPROCESS
| SEE_MASK_NO_CONSOLE
;
585 strcpy(shell_call
, "ShellExecuteEx(");
586 sprintf(smask
, "0x%x", mask
);
587 strcat_param(shell_call
, "mask", smask
);
588 strcat_param(shell_call
, "verb", verb
);
589 strcat_param(shell_call
, "file", filename
);
590 strcat_param(shell_call
, "params", parameters
);
591 strcat_param(shell_call
, "dir", directory
);
592 strcat_param(shell_call
, "class", class);
593 strcat(shell_call
, ")");
594 strcat(shell_call
, assoc_desc
);
595 if (winetest_debug
> 1)
596 trace_(file
, line
)("Called %s\n", shell_call
);
598 sei
.cbSize
=sizeof(sei
);
603 sei
.lpParameters
=parameters
;
604 sei
.lpDirectory
=directory
;
605 sei
.nShow
=SW_SHOWNORMAL
;
606 sei
.hInstApp
=NULL
; /* Out */
612 sei
.hProcess
=(HANDLE
)0xdeadbeef; /* Out */
614 DeleteFileA(child_file
);
615 SetLastError(0xcafebabe);
616 success
=ShellExecuteExA(&sei
);
617 rc
=(INT_PTR
)sei
.hInstApp
;
618 okShell_(file
, line
)((success
&& rc
> 32) || (!success
&& rc
<= 32),
619 "rc=%d and hInstApp=%ld is not allowed\n",
625 if (sei
.hProcess
!=NULL
)
627 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
628 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
629 "WaitForSingleObject(hProcess) returned %d\n",
631 wait_rc
= GetExitCodeProcess(sei
.hProcess
, &rc
);
632 okShell_(file
, line
)(wait_rc
, "GetExitCodeProcess() failed le=%u\n", GetLastError());
633 todo_wine_if(_todo_wait
)
634 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
635 CloseHandle(sei
.hProcess
);
637 wait_rc
=WaitForSingleObject(hEvent
, 5000);
638 todo_wine_if(_todo_wait
)
639 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
640 "WaitForSingleObject returned %d\n", wait_rc
);
643 okShell_(file
, line
)(sei
.hProcess
==NULL
,
644 "returned a process handle %p\n", sei
.hProcess
);
646 /* The child process may have changed the result file, so let profile
647 * functions know about it
649 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
650 if (rc
> 32 && GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
653 dump_child_(file
, line
);
654 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
656 winetest_add_failures(c
);
657 /* When NOZONECHECKS is specified the environment variables are not
658 * inherited if the process does not have elevated privileges.
660 if ((mask
& SEE_MASK_NOZONECHECKS
) && skip_shlexec_tests
)
662 okChildInt_(file
, line
, "ShlexecVarLE", 203);
663 okChildString_(file
, line
, "ShlexecVar", "", "");
667 okChildInt_(file
, line
, "ShlexecVarLE", 0);
668 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
674 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
675 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
680 * Functions to create / delete associations wrappers
684 static BOOL
create_test_class(const char* class, BOOL protocol
)
686 HKEY hkey
, hkey_shell
;
689 rc
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
690 KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
, NULL
,
692 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
693 "could not create class %s (rc=%d)\n", class, rc
);
694 if (rc
!= ERROR_SUCCESS
)
699 rc
= RegSetValueExA(hkey
, "URL Protocol", 0, REG_SZ
, (LPBYTE
)"", 1);
700 ok(rc
== ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
703 rc
= RegCreateKeyExA(hkey
, "shell", 0, NULL
, 0,
704 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
705 ok(rc
== ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
708 CloseHandle(hkey_shell
);
712 static BOOL
create_test_association(const char* extension
)
715 char class[MAX_PATH
];
718 sprintf(class, "shlexec%s", extension
);
719 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
721 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
722 "could not create association %s (rc=%d)\n", class, rc
);
723 if (rc
!= ERROR_SUCCESS
)
726 rc
=RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
727 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
730 return create_test_class(class, FALSE
);
733 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
734 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
737 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
738 DWORD dwMaxLen
, dwSize
;
739 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
744 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
748 /* Get highest length for keys, values */
749 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
750 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
751 if (ret
) goto cleanup
;
755 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
756 if (dwMaxLen
> ARRAY_SIZE(szNameBuf
))
758 /* Name too big: alloc a buffer for it */
759 if (!(lpszName
= heap_alloc(dwMaxLen
*sizeof(CHAR
))))
761 ret
= ERROR_NOT_ENOUGH_MEMORY
;
767 /* Recursively delete all the subkeys */
771 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
772 NULL
, NULL
, NULL
)) break;
774 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
775 if (ret
) goto cleanup
;
779 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
784 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
785 NULL
, NULL
, NULL
, NULL
)) break;
787 ret
= RegDeleteValueA(hKey
, lpszName
);
788 if (ret
) goto cleanup
;
792 /* Free buffer if allocated */
793 if (lpszName
!= szNameBuf
)
796 RegCloseKey(hSubKey
);
800 static void delete_test_class(const char* classname
)
802 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, classname
);
805 static void delete_test_association(const char* extension
)
807 char classname
[MAX_PATH
];
809 sprintf(classname
, "shlexec%s", extension
);
810 delete_test_class(classname
);
811 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
814 static void create_test_verb_dde(const char* classname
, const char* verb
,
815 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
816 const char *application
, const char *topic
,
819 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
820 char shell
[MAX_PATH
];
824 strcpy(assoc_desc
, " Assoc ");
825 strcat_param(assoc_desc
, "class", classname
);
826 strcat_param(assoc_desc
, "verb", verb
);
827 sprintf(shell
, "%d", rawcmd
);
828 strcat_param(assoc_desc
, "rawcmd", shell
);
829 strcat_param(assoc_desc
, "cmdtail", cmdtail
);
830 strcat_param(assoc_desc
, "ddeexec", ddeexec
);
831 strcat_param(assoc_desc
, "app", application
);
832 strcat_param(assoc_desc
, "topic", topic
);
833 strcat_param(assoc_desc
, "ifexec", ifexec
);
835 sprintf(shell
, "%s\\shell", classname
);
836 rc
=RegOpenKeyExA(HKEY_CLASSES_ROOT
, shell
, 0,
837 KEY_CREATE_SUB_KEY
, &hkey_shell
);
838 ok(rc
== ERROR_SUCCESS
, "%s key creation failed with %d\n", shell
, rc
);
840 rc
=RegCreateKeyExA(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
841 NULL
, &hkey_verb
, NULL
);
842 ok(rc
== ERROR_SUCCESS
, "%s verb key creation failed with %d\n", verb
, rc
);
844 rc
=RegCreateKeyExA(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
845 NULL
, &hkey_cmd
, NULL
);
846 ok(rc
== ERROR_SUCCESS
, "\'command\' key creation failed with %d\n", rc
);
850 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
854 cmd
= heap_alloc(strlen(argv0
) + 10 + strlen(child_file
) + 2 + strlen(cmdtail
) + 1);
855 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
856 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
857 ok(rc
== ERROR_SUCCESS
, "setting command failed with %d\n", rc
);
863 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
865 rc
=RegCreateKeyExA(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
866 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
867 ok(rc
== ERROR_SUCCESS
, "\'ddeexec\' key creation failed with %d\n", rc
);
868 rc
=RegSetValueExA(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
870 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
874 rc
=RegCreateKeyExA(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
875 NULL
, &hkey_application
, NULL
);
876 ok(rc
== ERROR_SUCCESS
, "\'application\' key creation failed with %d\n", rc
);
878 rc
=RegSetValueExA(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
879 strlen(application
)+1);
880 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
881 CloseHandle(hkey_application
);
885 rc
=RegCreateKeyExA(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
886 NULL
, &hkey_topic
, NULL
);
887 ok(rc
== ERROR_SUCCESS
, "\'topic\' key creation failed with %d\n", rc
);
888 rc
=RegSetValueExA(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
890 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
891 CloseHandle(hkey_topic
);
895 rc
=RegCreateKeyExA(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
896 NULL
, &hkey_ifexec
, NULL
);
897 ok(rc
== ERROR_SUCCESS
, "\'ifexec\' key creation failed with %d\n", rc
);
898 rc
=RegSetValueExA(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
900 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
901 CloseHandle(hkey_ifexec
);
903 CloseHandle(hkey_ddeexec
);
906 CloseHandle(hkey_shell
);
907 CloseHandle(hkey_verb
);
908 CloseHandle(hkey_cmd
);
911 /* Creates a class' non-DDE test verb.
912 * This function is meant to be used to create long term test verbs and thus
913 * does not trace them.
915 static void create_test_verb(const char* classname
, const char* verb
,
916 int rawcmd
, const char* cmdtail
)
918 create_test_verb_dde(classname
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
920 reset_association_description();
926 * GetLongPathNameA equivalent that supports Win95 and WinNT
930 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
932 char tmplongpath
[MAX_PATH
];
934 DWORD sp
= 0, lp
= 0;
936 WIN32_FIND_DATAA wfd
;
939 if (!shortpath
|| !shortpath
[0])
942 if (shortpath
[1] == ':')
944 tmplongpath
[0] = shortpath
[0];
945 tmplongpath
[1] = ':';
949 while (shortpath
[sp
])
951 /* check for path delimiters and reproduce them */
952 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
954 if (!lp
|| tmplongpath
[lp
-1] != '\\')
956 /* strip double "\\" */
957 tmplongpath
[lp
++] = '\\';
959 tmplongpath
[lp
] = 0; /* terminate string */
965 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
967 tmplongpath
[lp
++] = *p
++;
968 tmplongpath
[lp
++] = *p
++;
970 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
971 tmplen
= p
- (shortpath
+ sp
);
972 lstrcpynA(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
973 /* Check if the file exists and use the existing file name */
974 goit
= FindFirstFileA(tmplongpath
, &wfd
);
975 if (goit
== INVALID_HANDLE_VALUE
)
978 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
979 lp
+= strlen(tmplongpath
+ lp
);
982 tmplen
= strlen(shortpath
) - 1;
983 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
984 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
985 tmplongpath
[lp
++] = shortpath
[tmplen
];
988 tmplen
= strlen(tmplongpath
) + 1;
989 if (tmplen
<= longlen
)
991 strcpy(longpath
, tmplongpath
);
992 tmplen
--; /* length without 0 */
1005 static const char* testfiles
[]=
1007 "%s\\test file.shlexec",
1008 "%s\\%%nasty%% $file.shlexec",
1009 "%s\\test file.noassoc",
1010 "%s\\test file.noassoc.shlexec",
1011 "%s\\test file.shlexec.noassoc",
1012 "%s\\test_shortcut_shlexec.lnk",
1013 "%s\\test_shortcut_exe.lnk",
1014 "%s\\test file.shl",
1015 "%s\\test file.shlfoo",
1016 "%s\\test file.sha",
1017 "%s\\test file.sfe",
1018 "%s\\test file.shlproto",
1019 "%s\\masked file.shlexec",
1021 "%s\\test file.sde",
1022 "%s\\test file.exe",
1024 "%s\\simple.shlexec",
1025 "%s\\drawback_file.noassoc",
1026 "%s\\drawback_file.noassoc foo.shlexec",
1027 "%s\\drawback_nonexist.noassoc foo.shlexec",
1034 const char* basename
;
1039 static filename_tests_t filename_tests
[]=
1041 /* Test bad / nonexistent filenames */
1042 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1043 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
1045 /* Standard tests */
1046 {NULL
, "%s\\test file.shlexec", 0x0, 33},
1047 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
1048 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
1049 {NULL
, "%s/test file.shlexec", 0x0, 33},
1051 /* Test filenames with no association */
1052 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1054 /* Test double extensions */
1055 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
1056 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
1058 /* Test alternate verbs */
1059 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1060 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1062 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
1063 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1065 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC
},
1067 {"averb", "%s\\test file.sha", 0x10, 33},
1069 /* Test file masked due to space */
1070 {NULL
, "%s\\masked file.shlexec", 0x0, 33},
1071 /* Test if quoting prevents the masking */
1072 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
1073 /* Test with incorrect quote */
1074 {NULL
, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF
},
1076 /* Test extension / URI protocol collision */
1077 {NULL
, "%s\\test file.shlproto", 0x0, SE_ERR_NOASSOC
},
1082 static filename_tests_t noquotes_tests
[]=
1084 /* Test unquoted '%1' thingies */
1085 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1086 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1087 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1092 static void test_lpFile_parsed(void)
1094 char fileA
[MAX_PATH
];
1097 if (skip_shlexec_tests
)
1099 skip("No filename parsing tests due to lack of .shlexec association\n");
1103 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1104 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
1105 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1106 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1108 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1109 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
1110 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1111 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1112 "failed: rc=%lu\n", rc
);
1114 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1115 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
1116 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1117 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1119 /* ""command"" not works on wine (and real win9x and w2k) */
1120 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
1121 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1122 todo_wine
okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
1123 "failed: rc=%lu\n", rc
);
1125 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
1126 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
1127 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1128 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1130 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1131 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
1132 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1135 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
1136 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1138 /* test SEE_MASK_DOENVSUBST works */
1139 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1140 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
1141 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1143 /* quoted lpFile does not work on real win95 and nt4 */
1144 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1145 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
1146 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1147 "failed: rc=%lu\n", rc
);
1153 const char* args
[11];
1157 static const cmdline_tests_t cmdline_tests
[] =
1162 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1163 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
1165 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1166 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
1168 {"exe arg\"one\" \"second\"arg thirdarg ",
1169 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
1171 /* Don't lose unclosed quoted arguments */
1172 {"exe arg1 \"unclosed",
1173 {"exe", "arg1", "unclosed", NULL
}, 0},
1176 {"exe", "arg1", "", NULL
}, 0},
1178 /* cmd's metacharacters have no special meaning */
1179 {"exe \"one^\" \"arg\"&two three|four",
1180 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
1182 /* Environment variables are not interpreted either */
1184 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
1186 /* If not followed by a quote, backslashes go through as is */
1187 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1188 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1190 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1191 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1193 /* When followed by a quote their number is halved and the remainder
1196 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1197 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1199 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1200 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1202 /* One can put a quote in an unquoted string by tripling it, that is in
1203 * effect quoting it like so """ -> ". The general rule is as follows:
1204 * 3n quotes -> n quotes
1205 * 3n+1 quotes -> n quotes plus start of a quoted string
1206 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1207 * Nicely, when n is 0 we get the standard rules back.
1209 {"exe two\"\"quotes next",
1210 {"exe", "twoquotes", "next", NULL
}, 0},
1212 {"exe three\"\"\"quotes next",
1213 {"exe", "three\"quotes", "next", NULL
}, 0},
1215 {"exe four\"\"\"\" quotes\" next 4%3=1",
1216 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0},
1218 {"exe five\"\"\"\"\"quotes next",
1219 {"exe", "five\"quotes", "next", NULL
}, 0},
1221 {"exe six\"\"\"\"\"\"quotes next",
1222 {"exe", "six\"\"quotes", "next", NULL
}, 0},
1224 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1225 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0},
1227 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1228 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0},
1230 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1231 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1233 /* Inside a quoted string the opening quote is added to the set of
1234 * consecutive quotes to get the effective quotes count. This gives:
1235 * 1+3n quotes -> n quotes
1236 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1237 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1239 {"exe \"two\"\"quotes next",
1240 {"exe", "two\"quotes", "next", NULL
}, 0},
1242 {"exe \"two\"\" next",
1243 {"exe", "two\"", "next", NULL
}, 0},
1245 {"exe \"three\"\"\" quotes\" next 4%3=1",
1246 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0},
1248 {"exe \"four\"\"\"\"quotes next",
1249 {"exe", "four\"quotes", "next", NULL
}, 0},
1251 {"exe \"five\"\"\"\"\"quotes next",
1252 {"exe", "five\"\"quotes", "next", NULL
}, 0},
1254 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1255 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0},
1257 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1258 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0},
1260 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1261 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1263 /* Escaped consecutive quotes are fun */
1264 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1265 {"exe", "the crazy \\\"\\", "quotes", NULL
}, 0},
1267 /* The executable path has its own rules!!!
1268 * - Backslashes have no special meaning.
1269 * - If the first character is a quote, then the second quote ends the
1271 * - The previous rule holds even if the next character is not a space!
1272 * - If the first character is not a quote, then quotes have no special
1273 * meaning either and the executable path stops at the first space.
1274 * - The consecutive quotes rules don't apply either.
1275 * - Even if there is no space between the executable path and the first
1276 * argument, the latter is parsed using the regular rules.
1278 {"exe\"file\"path arg1",
1279 {"exe\"file\"path", "arg1", NULL
}, 0},
1281 {"exe\"file\"path\targ1",
1282 {"exe\"file\"path", "arg1", NULL
}, 0},
1284 {"exe\"path\\ arg1",
1285 {"exe\"path\\", "arg1", NULL
}, 0},
1287 {"\\\"exe \"arg one\"",
1288 {"\\\"exe", "arg one", NULL
}, 0},
1290 {"\"spaced exe\" \"next arg\"",
1291 {"spaced exe", "next arg", NULL
}, 0},
1293 {"\"spaced exe\"\t\"next arg\"",
1294 {"spaced exe", "next arg", NULL
}, 0},
1296 {"\"exe\"arg\" one\" argtwo",
1297 {"exe", "arg one", "argtwo", NULL
}, 0},
1299 {"\"spaced exe\\\"arg1 arg2",
1300 {"spaced exe\\", "arg1", "arg2", NULL
}, 0},
1303 {"two", " arg1 ", NULL
}, 0},
1305 {"\"three\"\"\" arg2",
1306 {"three", "", "arg2", NULL
}, 0},
1308 {"\"four\"\"\"\"arg1",
1309 {"four", "\"arg1", NULL
}, 0},
1311 /* If the first character is a space then the executable path is empty */
1312 {" \"arg\"one argtwo",
1313 {"", "argone", "argtwo", NULL
}, 0},
1318 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1320 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1326 /* trace("----- cmd='%s'\n", test->cmd); */
1327 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, ARRAY_SIZE(cmdW
));
1328 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1329 if (argsW
== NULL
&& cl2a_count
== -1)
1331 win_skip("CommandLineToArgvW not implemented, skipping\n");
1334 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1335 "expected NULL-terminated list of commandline arguments\n");
1338 while (test
->args
[count
])
1340 todo_wine_if(test
->todo
& 0x1)
1341 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1343 for (i
= 0; i
< cl2a_count
; i
++)
1347 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, ARRAY_SIZE(argW
));
1348 todo_wine_if(test
->todo
& (1 << (i
+4)))
1349 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1351 else todo_wine_if(test
->todo
& 0x1)
1352 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1359 static void test_commandline2argv(void)
1361 static const WCHAR exeW
[] = {'e','x','e',0};
1362 const cmdline_tests_t
* test
;
1363 WCHAR strW
[MAX_PATH
];
1368 test
= cmdline_tests
;
1371 if (!test_one_cmdline(test
))
1376 SetLastError(0xdeadbeef);
1377 args
= CommandLineToArgvW(exeW
, NULL
);
1378 le
= GetLastError();
1379 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1381 SetLastError(0xdeadbeef);
1382 args
= CommandLineToArgvW(NULL
, NULL
);
1383 le
= GetLastError();
1384 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1387 args
= CommandLineToArgvW(strW
, &numargs
);
1388 ok(numargs
== 1 || broken(numargs
> 1), "expected 1 args, got %d\n", numargs
);
1389 ok(!args
|| (!args
[numargs
] || broken(args
[numargs
] != NULL
) /* before Vista */),
1390 "expected NULL-terminated list of commandline arguments\n");
1393 GetModuleFileNameW(NULL
, strW
, ARRAY_SIZE(strW
));
1394 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
));
1396 if (args
) LocalFree(args
);
1399 /* The goal here is to analyze how ShellExecute() builds the command that
1400 * will be run. The tricky part is that there are three transformation
1401 * steps between the 'parameters' string we pass to ShellExecute() and the
1402 * argument list we observe in the child process:
1403 * - The parsing of 'parameters' string into individual arguments. The tests
1404 * show this is done differently from both CreateProcess() and
1405 * CommandLineToArgv()!
1406 * - The way the command 'formatting directives' such as %1, %2, etc are
1408 * - And the way the resulting command line is then parsed to yield the
1409 * argument list we check.
1420 static const argify_tests_t argify_tests
[] =
1422 /* Start with three simple parameters. Notice that one can reorder and
1423 * duplicate the parameters. Also notice how %* take the raw input
1424 * parameters string, including the trailing spaces, no matter what
1425 * arguments have already been used.
1427 {"Params232S", "p2 p3 p4 ", TRUE
,
1428 " p2 p3 \"p2\" \"p2 p3 p4 \""},
1430 /* Unquoted argument references like %2 don't automatically quote their
1431 * argument. Similarly, when they are quoted they don't escape the quotes
1432 * that their argument may contain.
1434 {"Params232S", "\"p two\" p3 p4 ", TRUE
,
1435 " p two p3 \"p two\" \"\"p two\" p3 p4 \""},
1437 /* Only single digits are supported so only %1 to %9. Shown here with %20
1438 * because %10 is a pain.
1440 {"Params20", "p", FALSE
,
1443 /* Only (double-)quotes have a special meaning. */
1444 {"Params23456", "'p2 p3` p4\\ $even", FALSE
,
1445 " \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\""},
1447 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", TRUE
,
1448 " \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\""},
1450 /* In unquoted strings, quotes are treated are a parameter separator just
1451 * like spaces! However they can be doubled to get a literal quote.
1453 * 2n quotes -> n quotes
1454 * 2n+1 quotes -> n quotes and a parameter separator
1456 {"Params23456789", "one\"quote \"p four\" one\"quote p7", TRUE
,
1457 " \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\""},
1459 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", TRUE
,
1460 " \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1462 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", TRUE
,
1463 " \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\""},
1465 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", TRUE
,
1466 " \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1468 /* Quoted strings cannot be continued by tacking on a non space character
1471 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", TRUE
,
1472 " \"p two\" \"p3\" \"p four\" \"p5\" \"p6\""},
1474 /* In quoted strings, the quotes are halved and an odd number closes the
1475 * string. Specifically:
1476 * 2n quotes -> n quotes
1477 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1479 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", TRUE
,
1480 " \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\""},
1482 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", TRUE
,
1483 " \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1485 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", TRUE
,
1486 " \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\""},
1488 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", TRUE
,
1489 " \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1491 /* The quoted string rules also apply to consecutive quotes at the start
1492 * of a parameter but don't count the opening quote!
1494 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", TRUE
,
1495 " \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\""},
1497 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", TRUE
,
1498 " \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\""},
1500 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", TRUE
,
1501 " \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\""},
1503 /* An unclosed quoted string gets lost! */
1504 {"Params23456", "p2 \"p3\" \"p4 is lost", TRUE
,
1505 " \"p2\" \"p3\" \"\" \"\" \"\"",
1506 " \"p2\" \"p3\" \"p3\" \"\" \"\""}, /* NT4/2k */
1508 /* Backslashes have no special meaning even when preceding quotes. All
1509 * they do is start an unquoted string.
1511 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", TRUE
,
1512 " \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\""},
1514 /* Environment variables are left untouched. */
1515 {"Params23456", "%TMPDIR% %t %c", FALSE
,
1516 " \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\""},
1518 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1519 * before the parameter!
1520 * (but not the previous parameter's closing quote fortunately)
1522 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", TRUE
,
1523 " ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 "},
1525 /* %~n works even if there is no nth parameter. */
1526 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", TRUE
,
1529 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", TRUE
,
1532 /* The %~n directives also transmit the tenth parameter and beyond. */
1533 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", TRUE
,
1534 " ~9=\" p9 p10 p11 and beyond!\""},
1536 /* Bad formatting directives lose their % sign, except those followed by
1537 * a tilde! Environment variables are not expanded but lose their % sign.
1539 {"ParamsBad", "p2 p3 p4 p5", TRUE
,
1540 " \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\""},
1545 static void test_argify(void)
1547 char fileA
[MAX_PATH
], params
[2*MAX_PATH
+12];
1549 const argify_tests_t
* test
;
1553 /* Test with a long parameter */
1554 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1555 fileA
[rc
] = 'a' + rc
% 26;
1556 fileA
[MAX_PATH
-1] = '\0';
1557 sprintf(params
, "shlexec \"%s\" %s", child_file
, fileA
);
1559 /* We need NOZONECHECKS on Win2003 to block a dialog */
1560 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
, NULL
, NULL
);
1561 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1562 okChildInt("argcA", 4);
1563 okChildPath("argvA3", fileA
);
1565 if (skip_shlexec_tests
)
1567 skip("No argify tests due to lack of .shlexec association\n");
1571 create_test_verb("shlexec.shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1572 create_test_verb("shlexec.shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1573 create_test_verb("shlexec.shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1574 create_test_verb("shlexec.shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1575 create_test_verb("shlexec.shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1576 create_test_verb("shlexec.shlexec", "Params20", 0, "Params20 \"%20\"");
1577 create_test_verb("shlexec.shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1579 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1581 test
= argify_tests
;
1582 while (test
->params
)
1584 bad
= test
->broken
? test
->broken
: test
->cmd
;
1586 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
, test
->verb
, fileA
, test
->params
, NULL
, NULL
);
1587 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1589 cmd
= getChildString("Child", "cmdlineA");
1590 /* Our commands are such that the verb immediately precedes the
1591 * part we are interested in.
1593 if (cmd
) cmd
= strstr(cmd
, test
->verb
);
1594 if (cmd
) cmd
+= strlen(test
->verb
);
1595 if (!cmd
) cmd
= "(null)";
1596 todo_wine_if(test
->todo
)
1597 okShell(!strcmp(cmd
, test
->cmd
) || broken(!strcmp(cmd
, bad
)),
1598 "expected '%s', got '%s'\n", cmd
, test
->cmd
);
1603 static void test_filename(void)
1605 char filename
[MAX_PATH
];
1606 const filename_tests_t
* test
;
1610 if (skip_shlexec_tests
)
1612 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1616 test
=filename_tests
;
1617 while (test
->basename
)
1619 BOOL quotedfile
= FALSE
;
1621 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1623 win_skip("Skipping shellexecute of file with unassociated extension\n");
1628 sprintf(filename
, test
->basename
, tmpdir
);
1629 if (strchr(filename
, '/'))
1639 if ((test
->todo
& 0x40)==0)
1641 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1645 char quoted
[MAX_PATH
+ 2];
1648 sprintf(quoted
, "\"%s\"", filename
);
1649 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1653 okShell(rc
==test
->rc
||
1654 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1655 "failed: rc=%ld err=%u\n", rc
, GetLastError());
1659 todo_wine_if(test
->todo
& 0x2)
1660 okChildInt("argcA", 5);
1661 verb
=(test
->verb
? test
->verb
: "Open");
1662 todo_wine_if(test
->todo
& 0x4)
1663 okChildString("argvA3", verb
);
1664 todo_wine_if(test
->todo
& 0x8)
1665 okChildPath("argvA4", filename
);
1670 test
=noquotes_tests
;
1671 while (test
->basename
)
1673 sprintf(filename
, test
->basename
, tmpdir
);
1674 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1677 todo_wine_if(test
->todo
& 0x1)
1678 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1685 verb
=(test
->verb
? test
->verb
: "Open");
1686 todo_wine_if(test
->todo
& 0x4)
1687 okChildString("argvA3", verb
);
1695 space
=strchr(str
, ' ');
1698 sprintf(attrib
, "argvA%d", count
);
1699 todo_wine_if(test
->todo
& 0x8)
1700 okChildPath(attrib
, str
);
1706 todo_wine_if(test
->todo
& 0x2)
1707 okChildInt("argcA", count
);
1712 if (dllver
.dwMajorVersion
!= 0)
1714 /* The more recent versions of shell32.dll accept quoted filenames
1715 * while older ones (e.g. 4.00) don't. Still we want to test this
1716 * because IE 6 depends on the new behavior.
1717 * One day we may need to check the exact version of the dll but for
1718 * now making sure DllGetVersion() is present is sufficient.
1720 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1721 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1722 okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1723 okChildInt("argcA", 5);
1724 okChildString("argvA3", "Open");
1725 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1726 okChildPath("argvA4", filename
);
1729 sprintf(filename
, "\"%s\\test file.sha\"", tmpdir
);
1730 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1731 todo_wine
okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1732 okChildInt("argcA", 5);
1733 todo_wine
okChildString("argvA3", "averb");
1734 sprintf(filename
, "%s\\test file.sha", tmpdir
);
1735 todo_wine
okChildPath("argvA4", filename
);
1740 const char* urlprefix
;
1741 const char* basename
;
1746 #define URL_SUCCESS 0x1
1747 #define USE_COLON 0x2
1748 #define USE_BSLASH 0x4
1750 static fileurl_tests_t fileurl_tests
[]=
1752 /* How many slashes does it take... */
1753 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1754 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1755 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1756 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1757 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1758 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1759 {"file://///", "%s\\test file.shlexec", 0, 0},
1761 /* Test with Windows-style paths */
1762 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0},
1763 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0},
1765 /* Check handling of hostnames */
1766 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1767 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1768 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1769 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1770 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1771 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1773 /* Environment variables are not expanded in URLs */
1774 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1775 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1777 /* Test shortcuts vs. URLs */
1778 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1c},
1780 /* Confuse things by mixing protocols */
1781 {"file://", "shlproto://foo/bar", USE_COLON
, 0},
1786 static void test_fileurls(void)
1788 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1789 char command
[MAX_PATH
];
1790 const fileurl_tests_t
* test
;
1794 if (skip_shlexec_tests
)
1796 skip("No file URL tests due to lack of .shlexec association\n");
1800 rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
, NULL
,
1801 "file:///nosuchfile.shlexec", NULL
, NULL
, NULL
);
1804 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1808 get_long_path_name(tmpdir
, longtmpdir
, ARRAY_SIZE(longtmpdir
));
1809 SetEnvironmentVariableA("urlprefix", "file:///");
1812 while (test
->basename
)
1814 /* Build the file URL */
1815 sprintf(filename
, test
->basename
, longtmpdir
);
1816 strcpy(fileurl
, test
->urlprefix
);
1817 strcat(fileurl
, filename
);
1818 s
= fileurl
+ strlen(test
->urlprefix
);
1821 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1823 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1828 /* Test it first with FindExecutable() */
1829 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1830 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1832 /* Then ShellExecute() */
1833 if ((test
->todo
& 0x10) == 0)
1834 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1836 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1837 if (bad_shellexecute
)
1839 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1842 if (test
->flags
& URL_SUCCESS
)
1844 todo_wine_if(test
->todo
& 0x1)
1845 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1849 todo_wine_if(test
->todo
& 0x1)
1850 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1851 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1852 "failed: bad rc=%lu\n", rc
);
1856 todo_wine_if(test
->todo
& 0x2)
1857 okChildInt("argcA", 5);
1858 todo_wine_if(test
->todo
& 0x4)
1859 okChildString("argvA3", "Open");
1860 todo_wine_if(test
->todo
& 0x8)
1861 okChildPath("argvA4", filename
);
1866 SetEnvironmentVariableA("urlprefix", NULL
);
1869 static void test_urls(void)
1874 if (!create_test_class("fakeproto", FALSE
))
1876 skip("Unable to create 'fakeproto' class for URL tests\n");
1879 create_test_verb("fakeproto", "open", 0, "URL %1");
1881 create_test_class("shlpaverb", TRUE
);
1882 create_test_verb("shlpaverb", "averb", 0, "PAVerb \"%1\"");
1884 /* Protocols must be properly declared */
1885 rc
= shell_execute(NULL
, "notaproto://foo", NULL
, NULL
);
1886 ok(rc
== SE_ERR_NOASSOC
|| broken(rc
== SE_ERR_ACCESSDENIED
),
1887 "%s returned %lu\n", shell_call
, rc
);
1889 rc
= shell_execute(NULL
, "fakeproto://foo/bar", NULL
, NULL
);
1890 todo_wine
ok(rc
== SE_ERR_NOASSOC
|| broken(rc
== SE_ERR_ACCESSDENIED
),
1891 "%s returned %lu\n", shell_call
, rc
);
1893 /* Here's a real live one */
1894 rc
= shell_execute(NULL
, "shlproto://foo/bar", NULL
, NULL
);
1895 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1896 okChildInt("argcA", 5);
1897 okChildString("argvA3", "URL");
1898 okChildString("argvA4", "shlproto://foo/bar");
1900 /* Check default verb detection */
1901 rc
= shell_execute(NULL
, "shlpaverb://foo/bar", NULL
, NULL
);
1902 todo_wine
ok(rc
> 32 || /* XP+IE7 - Win10 */
1903 broken(rc
== SE_ERR_NOASSOC
), /* XP+IE6 */
1904 "%s failed: rc=%lu\n", shell_call
, rc
);
1907 okChildInt("argcA", 5);
1908 todo_wine
okChildString("argvA3", "PAVerb");
1909 todo_wine
okChildString("argvA4", "shlpaverb://foo/bar");
1912 /* But alternative verbs are a recent feature! */
1913 rc
= shell_execute("averb", "shlproto://foo/bar", NULL
, NULL
);
1914 ok(rc
> 32 || /* Win8 - Win10 */
1915 broken(rc
== SE_ERR_ACCESSDENIED
), /* XP - Win7 */
1916 "%s failed: rc=%lu\n", shell_call
, rc
);
1919 okChildString("argvA3", "AVerb");
1920 okChildString("argvA4", "shlproto://foo/bar");
1923 /* A .lnk ending does not turn a URL into a shortcut */
1924 rc
= shell_execute(NULL
, "shlproto://foo/bar.lnk", NULL
, NULL
);
1925 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1926 okChildInt("argcA", 5);
1927 okChildString("argvA3", "URL");
1928 okChildString("argvA4", "shlproto://foo/bar.lnk");
1930 /* Neither does a .exe extension */
1931 rc
= shell_execute(NULL
, "shlproto://foo/bar.exe", NULL
, NULL
);
1932 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1933 okChildInt("argcA", 5);
1934 okChildString("argvA3", "URL");
1935 okChildString("argvA4", "shlproto://foo/bar.exe");
1937 /* But a class name overrides it */
1938 rc
= shell_execute(NULL
, "shlproto://foo/bar", "shlexec.shlexec", NULL
);
1939 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1940 okChildInt("argcA", 5);
1941 okChildString("argvA3", "URL");
1942 okChildString("argvA4", "shlproto://foo/bar");
1944 /* Environment variables are expanded in URLs (but not in file URLs!) */
1945 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1946 NULL
, "shlproto://%TMPDIR%/bar", NULL
, NULL
, NULL
);
1947 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1948 okChildInt("argcA", 5);
1949 sprintf(url
, "shlproto://%s/bar", tmpdir
);
1950 okChildString("argvA3", "URL");
1951 okChildStringBroken("argvA4", url
, "shlproto://%TMPDIR%/bar");
1953 /* But only after the path has been identified as a URL */
1954 SetEnvironmentVariableA("urlprefix", "shlproto:///");
1955 rc
= shell_execute(NULL
, "%urlprefix%foo", NULL
, NULL
);
1956 todo_wine
ok(rc
== SE_ERR_FNF
, "%s returned %lu\n", shell_call
, rc
);
1957 SetEnvironmentVariableA("urlprefix", NULL
);
1959 delete_test_class("fakeproto");
1960 delete_test_class("shlpaverb");
1963 static void test_find_executable(void)
1965 char notepad_path
[MAX_PATH
];
1966 char filename
[MAX_PATH
];
1967 char command
[MAX_PATH
];
1968 const filename_tests_t
* test
;
1971 if (!create_test_association(".sfe"))
1973 skip("Unable to create association for '.sfe'\n");
1976 create_test_verb("shlexec.sfe", "Open", 1, "%1");
1978 /* Don't test FindExecutable(..., NULL), it always crashes */
1980 strcpy(command
, "your word");
1981 if (0) /* Can crash on Vista! */
1983 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
1984 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1985 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1988 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
1989 strcat( notepad_path
, "\\notepad.exe" );
1991 /* Search for something that should be in the system-wide search path (no default directory) */
1992 strcpy(command
, "your word");
1993 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
1994 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1995 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1997 /* Search for something that should be in the system-wide search path (with default directory) */
1998 strcpy(command
, "your word");
1999 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
2000 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
2001 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
2003 strcpy(command
, "your word");
2004 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
2005 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
2006 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
2008 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
2009 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2010 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2011 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
2013 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
2014 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2016 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
2017 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2019 delete_test_association(".sfe");
2021 if (!create_test_association(".shl"))
2023 skip("Unable to create association for '.shl'\n");
2026 create_test_verb("shlexec.shl", "Open", 0, "Open");
2028 sprintf(filename
, "%s\\test file.shl", tmpdir
);
2029 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2030 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2032 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
2033 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2035 delete_test_association(".shl");
2039 /* On Windows XP and 2003 FindExecutable() is completely broken.
2040 * Probably what it does is convert the filename to 8.3 format,
2041 * which as a side effect converts the '.shlfoo' extension to '.shl',
2042 * and then tries to find an association for '.shl'. This means it
2043 * will normally fail on most extensions with more than 3 characters,
2044 * like '.mpeg', etc.
2045 * Also it means we cannot do any other test.
2047 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
2051 if (skip_shlexec_tests
)
2053 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2057 test
=filename_tests
;
2058 while (test
->basename
)
2060 sprintf(filename
, test
->basename
, tmpdir
);
2061 if (strchr(filename
, '/'))
2072 /* Win98 does not '\0'-terminate command! */
2073 memset(command
, '\0', sizeof(command
));
2074 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2077 todo_wine_if(test
->todo
& 0x10)
2078 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2082 equal
=strcmp(command
, argv0
) == 0 ||
2083 /* NT4 returns an extra 0x8 character! */
2084 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
2085 todo_wine_if(test
->todo
& 0x20)
2086 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2087 filename
, command
, argv0
);
2094 static filename_tests_t lnk_tests
[]=
2096 /* Pass bad / nonexistent filenames as a parameter */
2097 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
2098 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
2100 /* Pass regular paths as a parameter */
2101 {NULL
, "%s\\test file.shlexec", 0xa, 33},
2102 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2104 /* Pass filenames with no association as a parameter */
2105 {NULL
, "%s\\test file.noassoc", 0xa, 33},
2110 static void test_lnks(void)
2112 char filename
[MAX_PATH
];
2113 char params
[MAX_PATH
];
2114 const filename_tests_t
* test
;
2117 if (skip_shlexec_tests
)
2118 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2121 /* Should open through our association */
2122 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2123 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2124 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2125 okChildInt("argcA", 5);
2126 okChildString("argvA3", "Open");
2127 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2128 get_long_path_name(params
, filename
, sizeof(filename
));
2129 okChildPath("argvA4", filename
);
2131 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
2132 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2133 okChildInt("argcA", 5);
2134 okChildString("argvA3", "Open");
2135 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2136 get_long_path_name(params
, filename
, sizeof(filename
));
2137 okChildPath("argvA4", filename
);
2140 /* Should just run our executable */
2141 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2142 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2143 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2144 okChildInt("argcA", 4);
2145 okChildString("argvA3", "Lnk");
2147 if (!skip_shlexec_tests
)
2149 /* An explicit class overrides lnk's ContextMenuHandler */
2150 rc
=shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
2151 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2152 okChildInt("argcA", 5);
2153 okChildString("argvA3", "Open");
2154 okChildPath("argvA4", filename
);
2157 if (dllver
.dwMajorVersion
>=6)
2160 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2161 * Older versions don't or are quite buggy in this regard.
2163 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2171 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2172 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2173 okChildInt("argcA", 4);
2174 okChildString("argvA3", "Lnk");
2177 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2179 while (test
->basename
)
2182 sprintf(params
+1, test
->basename
, tmpdir
);
2183 strcat(params
,"\"");
2184 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2188 todo_wine_if(test
->todo
& 0x1)
2189 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2192 todo_wine_if(test
->todo
& 0x2)
2193 okChildInt("argcA", 5);
2194 todo_wine_if(test
->todo
& 0x4)
2195 okChildString("argvA3", "Lnk");
2196 sprintf(params
, test
->basename
, tmpdir
);
2197 okChildPath("argvA4", params
);
2204 static void test_exes(void)
2206 char filename
[MAX_PATH
];
2210 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2212 /* We need NOZONECHECKS on Win2003 to block a dialog */
2213 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
2215 okShell(rc
> 32, "returned %lu\n", rc
);
2216 okChildInt("argcA", 4);
2217 okChildString("argvA3", "Exec");
2219 if (! skip_noassoc_tests
)
2221 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
2222 if (CopyFileA(argv0
, filename
, FALSE
))
2224 rc
=shell_execute(NULL
, filename
, params
, NULL
);
2226 okShell(rc
==SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2232 win_skip("Skipping shellexecute of file with unassociated extension\n");
2235 /* test combining executable and parameters */
2236 sprintf(filename
, "%s shlexec \"%s\" Exec", argv0
, child_file
);
2237 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2238 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2240 sprintf(filename
, "\"%s\" shlexec \"%s\" Exec", argv0
, child_file
);
2241 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2242 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2244 /* A verb, even if invalid, overrides the normal handling of executables */
2245 todo_wait rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
,
2246 "notaverb", argv0
, NULL
, NULL
, NULL
);
2247 todo_wine
okShell(rc
== SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2249 if (!skip_shlexec_tests
)
2251 /* A class overrides the normal handling of executables too */
2252 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2253 rc
= shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
,
2254 NULL
, argv0
, NULL
, NULL
, ".shlexec");
2255 todo_wine
okShell(rc
> 32, "returned %lu\n", rc
);
2256 okChildInt("argcA", 5);
2257 todo_wine
okChildString("argvA3", "Open");
2258 todo_wine
okChildPath("argvA4", argv0
);
2264 const char* command
;
2265 const char* ddeexec
;
2266 const char* application
;
2270 const char* expectedDdeExec
;
2274 static dde_tests_t dde_tests
[] =
2276 /* Test passing and not passing command-line
2277 * argument, no DDE */
2278 {"", NULL
, NULL
, NULL
, NULL
, 0, ""},
2279 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, 1, ""},
2281 /* Test passing and not passing command-line
2282 * argument, with DDE */
2283 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 0, "[open(\"%s\")]"},
2284 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 1, "[open(\"%s\")]"},
2286 /* Test unquoted %1 in command and ddeexec
2287 * (test filename has space) */
2288 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", TRUE
/* before vista */},
2290 /* Test ifexec precedence over ddeexec */
2291 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2293 /* Test default DDE topic */
2294 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, 0, "[open(\"%s\")]"},
2296 /* Test default DDE application */
2297 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, 0, "[open(\"%s\")]"},
2302 static int waitforinputidle_count
;
2303 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
2305 waitforinputidle_count
++;
2306 if (winetest_debug
> 1)
2307 trace("WaitForInputIdle() waiting for dde event timeout=min(%u,5s)\n", timeout
);
2308 timeout
= timeout
< 5000 ? timeout
: 5000;
2309 return WaitForSingleObject(dde_ready_event
, timeout
);
2313 * WaitForInputIdle() will normally return immediately for console apps. That's
2314 * a problem for us because ShellExecute will assume that an app is ready to
2315 * receive DDE messages after it has called WaitForInputIdle() on that app.
2316 * To work around that we install our own version of WaitForInputIdle() that
2317 * will wait for the child to explicitly tell us that it is ready. We do that
2318 * by changing the entry for WaitForInputIdle() in the shell32 import address
2321 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2324 PIMAGE_NT_HEADERS nt_headers
;
2325 DWORD import_directory_rva
;
2326 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2329 base
= (char *) GetModuleHandleA("shell32.dll");
2330 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2331 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2333 /* Search for the correct imported module by walking the import descriptors */
2334 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2335 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2337 char *import_module_name
;
2339 import_module_name
= base
+ import_descriptor
->Name
;
2340 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2341 lstrcmpiA(import_module_name
, "user32") == 0)
2343 PIMAGE_THUNK_DATA int_entry
;
2344 PIMAGE_THUNK_DATA iat_entry
;
2346 /* The import name table and import address table are two parallel
2347 * arrays. We need the import name table to find the imported
2348 * routine and the import address table to patch the address, so
2349 * walk them side by side */
2350 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2351 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2352 while (int_entry
->u1
.Ordinal
!= 0)
2354 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2356 PIMAGE_IMPORT_BY_NAME import_by_name
;
2357 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2358 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2360 /* Found the correct routine in the correct imported module. Patch it. */
2362 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2363 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2364 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2365 if (winetest_debug
> 1)
2366 trace("Hooked %s.WaitForInputIdle\n", import_module_name
);
2377 import_descriptor
++;
2379 ok(hook_count
, "Could not hook WaitForInputIdle()\n");
2382 static void test_dde(void)
2384 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2385 const dde_tests_t
* test
;
2392 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2394 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2396 /* Default service is application name minus path and extension */
2397 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2398 *strchr(defApplication
, '.') = 0;
2400 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2401 4096, "winetest_shlexec_dde_map");
2402 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2404 ddeflags
= SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
2406 while (test
->command
)
2408 if (!create_test_association(".sde"))
2410 skip("Unable to create association for '.sde'\n");
2413 create_test_verb_dde("shlexec.sde", "Open", 0, test
->command
, test
->ddeexec
,
2414 test
->application
, test
->topic
, test
->ifexec
);
2416 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2418 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2419 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2423 shared_block
[0] = '\0';
2424 shared_block
[1] = '\0';
2428 waitforinputidle_count
= 0;
2429 dde_ready_event
= CreateEventA(NULL
, TRUE
, FALSE
, "winetest_shlexec_dde_ready");
2430 rc
= shell_execute_ex(ddeflags
, NULL
, filename
, NULL
, NULL
, NULL
);
2431 CloseHandle(dde_ready_event
);
2432 if (!(ddeflags
& SEE_MASK_WAITFORINPUTIDLE
) && rc
== SE_ERR_DDEFAIL
&&
2433 GetLastError() == ERROR_FILE_NOT_FOUND
&&
2434 strcmp(winetest_platform
, "windows") == 0)
2436 /* Windows 10 does not call WaitForInputIdle() for DDE which creates
2437 * a race condition as the DDE server may not have time to start up.
2438 * When that happens the test fails with the above results and we
2439 * compensate by forcing the WaitForInputIdle() call.
2441 trace("Adding SEE_MASK_WAITFORINPUTIDLE for Windows 10\n");
2442 ddeflags
|= SEE_MASK_WAITFORINPUTIDLE
;
2443 delete_test_association(".sde");
2444 Sleep(CHILD_DDE_TIMEOUT
);
2447 okShell(32 < rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2449 okShell(waitforinputidle_count
== 1 ||
2450 broken(waitforinputidle_count
== 0) /* Win10 race */,
2451 "WaitForInputIdle() was called %u times\n",
2452 waitforinputidle_count
);
2454 okShell(waitforinputidle_count
== 0, "WaitForInputIdle() was called %u times for a non-DDE case\n", waitforinputidle_count
);
2459 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
2461 okChildInt("argcA", test
->expectedArgs
+ 3);
2463 if (test
->expectedArgs
== 1) okChildPath("argvA3", filename
);
2465 sprintf(params
, test
->expectedDdeExec
, filename
);
2466 okChildPath("ddeExec", params
);
2468 reset_association_description();
2470 delete_test_association(".sde");
2474 UnmapViewOfFile(shared_block
);
2476 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2479 #define DDE_DEFAULT_APP_VARIANTS 3
2482 const char* command
;
2483 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2485 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2486 } dde_default_app_tests_t
;
2488 static dde_default_app_tests_t dde_default_app_tests
[] =
2490 /* There are three possible sets of results: Windows <= 2000, XP SP1 and
2491 * >= XP SP2. Use the first two tests to determine which results to expect.
2494 /* Test unquoted existing filename with a space */
2495 {"%s\\test file.exe", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2496 {"%s\\test2 file.exe", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2498 /* Test unquoted existing filename with a space */
2499 {"%s\\test file.exe param", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2501 /* Test quoted existing filename with a space */
2502 {"\"%s\\test file.exe\"", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2503 {"\"%s\\test file.exe\" param", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2505 /* Test unquoted filename with a space that doesn't exist, but
2507 {"%s\\test2 file.exe param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2509 /* Test quoted filename with a space that does not exist */
2510 {"\"%s\\test2 file.exe\"", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2511 {"\"%s\\test2 file.exe\" param", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2513 /* Test filename supplied without the extension */
2514 {"%s\\test2", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2515 {"%s\\test2 param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2517 /* Test an unquoted nonexistent filename */
2518 {"%s\\notexist.exe", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2519 {"%s\\notexist.exe param", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2521 /* Test an application that will be found on the path */
2522 {"cmd", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2523 {"cmd param", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2525 /* Test an application that will not be found on the path */
2526 {"xyzwxyzwxyz", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2527 {"xyzwxyzwxyz param", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2529 {NULL
, {NULL
}, 0, {0}}
2535 DWORD threadIdParent
;
2536 } dde_thread_info_t
;
2538 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2540 dde_thread_info_t
*info
= arg
;
2541 assert(info
&& info
->filename
);
2542 PostThreadMessageA(info
->threadIdParent
,
2544 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2549 static void test_dde_default_app(void)
2551 char filename
[MAX_PATH
];
2553 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2554 const dde_default_app_tests_t
* test
;
2563 post_quit_on_execute
= FALSE
;
2565 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2566 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
2567 ok(rc
== DMLERR_NO_ERROR
, "got %lx\n", rc
);
2569 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2571 /* It is strictly not necessary to register an application name here, but wine's
2572 * DdeNameService implementation complains if 0 is passed instead of
2573 * hszApplication with DNS_FILTEROFF */
2574 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2575 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2576 ok(hszApplication
&& hszTopic
, "got %p and %p\n", hszApplication
, hszTopic
);
2577 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
2578 ok(ret
!= 0, "got %p\n", ret
);
2580 test
= dde_default_app_tests
;
2581 while (test
->command
)
2585 if (!create_test_association(".sde"))
2587 skip("Unable to create association for '.sde'\n");
2590 sprintf(params
, test
->command
, tmpdir
);
2591 create_test_verb_dde("shlexec.sde", "Open", 1, params
, "[test]", NULL
,
2593 ddeApplication
[0] = 0;
2595 /* No application will be run as we will respond to the first DDE event,
2596 * so don't wait for it */
2599 thread
= CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
);
2600 ok(thread
!= NULL
, "got %p\n", thread
);
2601 while (GetMessageA(&msg
, NULL
, 0, 0)) DispatchMessageA(&msg
);
2602 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2604 /* The first two tests determine which set of results to expect.
2605 * First check the platform as only the first set of results is
2606 * acceptable for Wine.
2608 if (strcmp(winetest_platform
, "wine"))
2610 if (test
== dde_default_app_tests
)
2612 if (strcmp(ddeApplication
, test
->expectedDdeApplication
[0]))
2615 else if (test
== dde_default_app_tests
+ 1)
2617 if (which
== 0 && rc
== test
->rc
[1])
2619 trace("DDE result variant %d\n", which
);
2623 todo_wine_if(test
->todo
& 0x1)
2624 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2625 rc
, GetLastError());
2628 todo_wine_if(test
->todo
& 0x2)
2629 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2630 "Expected application '%s', got '%s'\n",
2631 test
->expectedDdeApplication
[which
], ddeApplication
);
2633 reset_association_description();
2635 delete_test_association(".sde");
2639 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
2640 ok(ret
!= 0, "got %p\n", ret
);
2641 b
= DdeFreeStringHandle(ddeInst
, hszTopic
);
2642 ok(b
, "got %d\n", b
);
2643 b
= DdeFreeStringHandle(ddeInst
, hszApplication
);
2644 ok(b
, "got %d\n", b
);
2645 b
= DdeUninitialize(ddeInst
);
2646 ok(b
, "got %d\n", b
);
2649 static void init_test(void)
2652 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2653 char filename
[MAX_PATH
];
2654 WCHAR lnkfile
[MAX_PATH
];
2656 const char* const * testfile
;
2661 hdll
=GetModuleHandleA("shell32.dll");
2662 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2665 dllver
.cbSize
=sizeof(dllver
);
2666 pDllGetVersion(&dllver
);
2667 trace("major=%d minor=%d build=%d platform=%d\n",
2668 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2669 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2673 memset(&dllver
, 0, sizeof(dllver
));
2676 r
= CoInitialize(NULL
);
2677 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2681 rc
=GetModuleFileNameA(NULL
, argv0
, sizeof(argv0
));
2682 ok(rc
!= 0 && rc
< sizeof(argv0
), "got %d\n", rc
);
2683 if (GetFileAttributesA(argv0
)==INVALID_FILE_ATTRIBUTES
)
2685 strcat(argv0
, ".so");
2686 ok(GetFileAttributesA(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2687 "unable to find argv0!\n");
2690 /* Older versions (win 2k) fail tests if there is a space in
2692 if (dllver
.dwMajorVersion
<= 5)
2693 strcpy(filename
, "c:\\");
2695 GetTempPathA(sizeof(filename
), filename
);
2696 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2697 GetLongPathNameA(tmpdir
, tmpdir
, sizeof(tmpdir
));
2698 DeleteFileA( tmpdir
);
2699 rc
= CreateDirectoryA( tmpdir
, NULL
);
2700 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2701 /* Set %TMPDIR% for the tests */
2702 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2704 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2705 ok(rc
!= 0, "got %d\n", rc
);
2706 init_event(child_file
);
2708 /* Set up the test files */
2714 sprintf(filename
, *testfile
, tmpdir
);
2715 hfile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2716 FILE_ATTRIBUTE_NORMAL
, NULL
);
2717 if (hfile
==INVALID_HANDLE_VALUE
)
2719 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2726 /* Setup the test shortcuts */
2727 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2728 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, ARRAY_SIZE(lnkfile
));
2729 desc
.description
=NULL
;
2731 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2734 desc
.arguments
="ignored";
2739 create_lnk(lnkfile
, &desc
, 0);
2741 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2742 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, ARRAY_SIZE(lnkfile
));
2743 desc
.description
=NULL
;
2747 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2748 desc
.arguments
=params
;
2753 create_lnk(lnkfile
, &desc
, 0);
2755 /* Create a basic association suitable for most tests */
2756 if (!create_test_association(".shlexec"))
2758 skip_shlexec_tests
= TRUE
;
2759 skip("Unable to create association for '.shlexec'\n");
2762 create_test_verb("shlexec.shlexec", "Open", 0, "Open \"%1\"");
2763 create_test_verb("shlexec.shlexec", "NoQuotes", 0, "NoQuotes %1");
2764 create_test_verb("shlexec.shlexec", "LowerL", 0, "LowerL %l");
2765 create_test_verb("shlexec.shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2766 create_test_verb("shlexec.shlexec", "UpperL", 0, "UpperL %L");
2767 create_test_verb("shlexec.shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2769 create_test_association(".sha");
2770 create_test_verb("shlexec.sha", "averb", 0, "AVerb \"%1\"");
2772 create_test_class("shlproto", TRUE
);
2773 create_test_verb("shlproto", "open", 0, "URL \"%1\"");
2774 create_test_verb("shlproto", "averb", 0, "AVerb \"%1\"");
2776 /* Set an environment variable to see if it is inherited */
2777 SetEnvironmentVariableA("ShlexecVar", "Present");
2780 static void cleanup_test(void)
2782 char filename
[MAX_PATH
];
2783 const char* const * testfile
;
2785 /* Delete the test files */
2789 sprintf(filename
, *testfile
, tmpdir
);
2790 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2791 SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
);
2792 DeleteFileA(filename
);
2795 DeleteFileA(child_file
);
2796 RemoveDirectoryA(tmpdir
);
2798 /* Delete the test association */
2799 delete_test_association(".shlexec");
2800 delete_test_association(".sha");
2801 delete_test_class("shlproto");
2803 CloseHandle(hEvent
);
2808 static void test_directory(void)
2810 char path
[MAX_PATH
], curdir
[MAX_PATH
];
2811 char params
[1024], dirpath
[1024];
2814 sprintf(path
, "%s\\test2.exe", tmpdir
);
2815 CopyFileA(argv0
, path
, FALSE
);
2817 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2819 /* Test with the current directory */
2820 GetCurrentDirectoryA(sizeof(curdir
), curdir
);
2821 SetCurrentDirectoryA(tmpdir
);
2822 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2823 NULL
, "test2.exe", params
, NULL
, NULL
);
2824 okShell(rc
> 32, "returned %lu\n", rc
);
2825 okChildInt("argcA", 4);
2826 okChildString("argvA3", "Exec");
2827 okChildPath("longPath", path
);
2828 SetCurrentDirectoryA(curdir
);
2830 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2831 NULL
, "test2.exe", params
, NULL
, NULL
);
2832 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2834 /* Explicitly specify the directory to use */
2835 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2836 NULL
, "test2.exe", params
, tmpdir
, NULL
);
2837 okShell(rc
> 32, "returned %lu\n", rc
);
2838 okChildInt("argcA", 4);
2839 okChildString("argvA3", "Exec");
2840 okChildPath("longPath", path
);
2842 /* Specify it through an environment variable */
2843 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2844 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2845 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2847 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
|SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2848 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2849 okShell(rc
> 32, "returned %lu\n", rc
);
2850 okChildInt("argcA", 4);
2851 okChildString("argvA3", "Exec");
2852 okChildPath("longPath", path
);
2854 /* Not a colon-separated directory list */
2855 sprintf(dirpath
, "%s:%s", curdir
, tmpdir
);
2856 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2857 NULL
, "test2.exe", params
, dirpath
, NULL
);
2858 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2864 myARGC
= winetest_get_mainargs(&myARGV
);
2867 doChild(myARGC
, myARGV
);
2868 /* Skip the tests/failures trace for child processes */
2869 ExitProcess(winetest_get_failures());
2874 test_commandline2argv();
2876 test_lpFile_parsed();
2880 test_find_executable();
2884 test_dde_default_app();