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
33 /* Needed to get SEE_MASK_NOZONECHECKS with the PSDK */
34 #define NTDDI_WINXPSP1 0x05010100
35 #define NTDDI_VERSION NTDDI_WINXPSP1
36 #define _WIN32_WINNT 0x0501
47 #include "wine/test.h"
49 #include "shell32_test.h"
52 static char argv0
[MAX_PATH
];
55 static char tmpdir
[MAX_PATH
];
56 static char child_file
[MAX_PATH
];
57 static DLLVERSIONINFO dllver
;
58 static BOOL skip_shlexec_tests
= FALSE
;
59 static BOOL skip_noassoc_tests
= FALSE
;
60 static HANDLE dde_ready_event
;
65 * Helpers to read from / write to the child process results file.
66 * (borrowed from dlls/kernel32/tests/process.c)
70 static const char* encodeA(const char* str
)
72 static char encoded
[2*1024+1];
77 len
= strlen(str
) + 1;
78 if (len
>= sizeof(encoded
)/2)
80 fprintf(stderr
, "string is too long!\n");
84 for (i
= 0; i
< len
; i
++)
85 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
90 static unsigned decode_char(char c
)
92 if (c
>= '0' && c
<= '9') return c
- '0';
93 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
94 assert(c
>= 'A' && c
<= 'F');
98 static char* decodeA(const char* str
)
100 static char decoded
[1024];
104 len
= strlen(str
) / 2;
105 if (!len
--) return NULL
;
106 if (len
>= sizeof(decoded
))
108 fprintf(stderr
, "string is too long!\n");
112 for (i
= 0; i
< len
; i
++)
113 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
118 static void WINETEST_PRINTF_ATTR(2,3) childPrintf(HANDLE h
, const char* fmt
, ...)
124 va_start(valist
, fmt
);
125 vsprintf(buffer
, fmt
, valist
);
127 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
130 static char* getChildString(const char* sect
, const char* key
)
135 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), child_file
);
136 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
137 assert(!(strlen(buf
) & 1));
149 static DWORD ddeInst
;
151 static char ddeExec
[MAX_PATH
], ddeApplication
[MAX_PATH
];
152 static BOOL post_quit_on_execute
;
154 /* Handle DDE for doChild() and test_dde_default_app() */
155 static HDDEDATA CALLBACK
ddeCb(UINT uType
, UINT uFmt
, HCONV hConv
,
156 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
157 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
161 if (winetest_debug
> 2)
162 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
163 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
168 if (!DdeCmpStringHandles(hsz1
, hszTopic
))
170 size
= DdeQueryStringA(ddeInst
, hsz2
, ddeApplication
, MAX_PATH
, CP_WINANSI
);
171 ok(size
< MAX_PATH
, "got size %d\n", size
);
172 assert(size
< MAX_PATH
);
173 return (HDDEDATA
)TRUE
;
175 return (HDDEDATA
)FALSE
;
178 size
= DdeGetData(hData
, (LPBYTE
)ddeExec
, MAX_PATH
, 0);
179 ok(size
< MAX_PATH
, "got size %d\n", size
);
180 assert(size
< MAX_PATH
);
181 DdeFreeDataHandle(hData
);
182 if (post_quit_on_execute
)
184 return (HDDEDATA
)DDE_FACK
;
191 static HANDLE hEvent
;
192 static void init_event(const char* child_file
)
195 event_name
=strrchr(child_file
, '\\')+1;
196 hEvent
=CreateEventA(NULL
, FALSE
, FALSE
, event_name
);
200 * This is just to make sure the child won't run forever stuck in a
201 * GetMessage() loop when DDE fails for some reason.
203 static void CALLBACK
childTimeout(HWND wnd
, UINT msg
, UINT_PTR timer
, DWORD time
)
205 trace("childTimeout called\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
)
223 childPrintf(hFile
, "[Child]\r\n");
224 if (winetest_debug
> 2)
226 trace("cmdlineA='%s'\n", GetCommandLineA());
227 trace("argcA=%d\n", argc
);
229 childPrintf(hFile
, "cmdlineA=%s\r\n", encodeA(GetCommandLineA()));
230 childPrintf(hFile
, "argcA=%d\r\n", argc
);
231 for (i
= 0; i
< argc
; i
++)
233 if (winetest_debug
> 2)
234 trace("argvA%d='%s'\n", i
, argv
[i
]);
235 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
237 GetModuleFileNameA(GetModuleHandleA(NULL
), buffer
, sizeof(buffer
));
238 childPrintf(hFile
, "longPath=%s\r\n", encodeA(buffer
));
240 /* Check environment variable inheritance */
243 GetEnvironmentVariableA("ShlexecVar", buffer
, sizeof(buffer
));
244 childPrintf(hFile
, "ShlexecVarLE=%d\r\n", GetLastError());
245 childPrintf(hFile
, "ShlexecVar=%s\r\n", encodeA(buffer
));
247 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
251 char *shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
253 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
260 post_quit_on_execute
= TRUE
;
262 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
263 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
264 ok(rc
== DMLERR_NO_ERROR
, "DdeInitializeA() returned %d\n", rc
);
265 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
266 ok(hszApplication
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
267 shared_block
+= strlen(shared_block
) + 1;
268 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
269 ok(hszTopic
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
270 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
271 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
273 timer
= SetTimer(NULL
, 0, 2500, childTimeout
);
275 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
277 CloseHandle(dde_ready
);
279 while (GetMessageA(&msg
, NULL
, 0, 0))
281 if (winetest_debug
> 2)
282 trace("msg %d lParam=%ld wParam=%lu\n", msg
.message
, msg
.lParam
, msg
.wParam
);
283 DispatchMessageA(&msg
);
287 KillTimer(NULL
, timer
);
288 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
289 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
290 ok(DdeFreeStringHandle(ddeInst
, hszTopic
), "DdeFreeStringHandle(topic)\n");
291 ok(DdeFreeStringHandle(ddeInst
, hszApplication
), "DdeFreeStringHandle(application)\n");
292 ok(DdeUninitialize(ddeInst
), "DdeUninitialize() failed\n");
296 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
298 CloseHandle(dde_ready
);
301 UnmapViewOfFile(shared_block
);
303 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
306 childPrintf(hFile
, "Failures=%d\r\n", winetest_get_failures());
309 init_event(filename
);
314 static void dump_child_(const char* file
, int line
)
316 if (winetest_debug
> 1)
322 str
=getChildString("Child", "cmdlineA");
323 trace_(file
, line
)("cmdlineA='%s'\n", str
);
324 c
=GetPrivateProfileIntA("Child", "argcA", -1, child_file
);
325 trace_(file
, line
)("argcA=%d\n",c
);
328 sprintf(key
, "argvA%d", i
);
329 str
=getChildString("Child", key
);
330 trace_(file
, line
)("%s='%s'\n", key
, str
);
333 c
=GetPrivateProfileIntA("Child", "ShlexecVarLE", -1, child_file
);
334 trace_(file
, line
)("ShlexecVarLE=%d\n", c
);
335 str
=getChildString("Child", "ShlexecVar");
336 trace_(file
, line
)("ShlexecVar='%s'\n", str
);
338 c
=GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
339 trace_(file
, line
)("Failures=%d\n", c
);
346 * Helpers to check the ShellExecute() / child process results.
350 static char shell_call
[2048];
351 static void WINETEST_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
356 strcpy(buffer
, shell_call
);
358 va_start(valist
, msg
);
359 vsprintf(buffer
+strlen(buffer
), msg
, valist
);
361 winetest_ok(condition
, "%s", buffer
);
363 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
364 #define okShell okShell_(__FILE__, __LINE__)
366 static char assoc_desc
[2048];
367 void reset_association_description(void)
372 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
375 result
=getChildString("Child", key
);
378 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
381 okShell_(file
, line
)(lstrcmpiA(result
, expected
) == 0 ||
382 broken(lstrcmpiA(result
, bad
) == 0),
383 "%s expected '%s', got '%s'\n", key
, expected
, result
);
385 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
386 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
388 static int StrCmpPath(const char* s1
, const char* s2
)
390 if (!s1
&& !s2
) return 0;
401 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
403 while (*s1
=='/' || *s1
=='\\')
405 while (*s2
=='/' || *s2
=='\\')
408 else if (toupper(*s1
)==toupper(*s2
))
425 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
428 result
=getChildString("Child", key
);
431 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
434 okShell_(file
,line
)(StrCmpPath(result
, expected
) == 0,
435 "%s expected '%s', got '%s'\n", key
, expected
, result
);
437 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
439 static void okChildInt_(const char* file
, int line
, const char* key
, int expected
)
442 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
443 okShell_(file
,line
)(result
== expected
,
444 "%s expected %d, but got %d\n", key
, expected
, result
);
446 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
448 static void okChildIntBroken_(const char* file
, int line
, const char* key
, int expected
)
451 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
452 okShell_(file
,line
)(result
== expected
|| broken(result
!= expected
),
453 "%s expected %d, but got %d\n", key
, expected
, result
);
455 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
460 * ShellExecute wrappers
464 static void strcat_param(char* str
, const char* name
, const char* param
)
468 if (str
[strlen(str
)-1] == '"')
477 static int _todo_wait
= 0;
478 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
480 static int bad_shellexecute
= 0;
482 static INT_PTR
shell_execute_(const char* file
, int line
, LPCSTR verb
, LPCSTR filename
, LPCSTR parameters
, LPCSTR directory
)
484 INT_PTR rc
, rcEmpty
= 0;
487 rcEmpty
= shell_execute_(file
, line
, "", filename
, parameters
, directory
);
489 strcpy(shell_call
, "ShellExecute(");
490 strcat_param(shell_call
, "verb", verb
);
491 strcat_param(shell_call
, "file", filename
);
492 strcat_param(shell_call
, "params", parameters
);
493 strcat_param(shell_call
, "dir", directory
);
494 strcat(shell_call
, ")");
495 strcat(shell_call
, assoc_desc
);
496 if (winetest_debug
> 1)
497 trace_(file
, line
)("Called %s\n", shell_call
);
499 DeleteFileA(child_file
);
500 SetLastError(0xcafebabe);
502 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
503 * association it displays the 'Open With' dialog and I could not find
504 * a flag to prevent this.
506 rc
=(INT_PTR
)ShellExecuteA(NULL
, verb
, filename
, parameters
, directory
, SW_HIDE
);
511 wait_rc
=WaitForSingleObject(hEvent
, 5000);
512 if (wait_rc
== WAIT_TIMEOUT
)
514 HWND wnd
= FindWindowA("#32770", "Windows");
516 wnd
= FindWindowA("Shell_Flyout", "");
519 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
520 win_skip("Skipping shellexecute of file with unassociated extension\n");
521 skip_noassoc_tests
= TRUE
;
526 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
527 "WaitForSingleObject returned %d\n", wait_rc
);
529 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
530 "WaitForSingleObject returned %d\n", wait_rc
);
532 /* The child process may have changed the result file, so let profile
533 * functions know about it
535 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
536 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
539 dump_child_(file
, line
);
540 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
542 winetest_add_failures(c
);
543 okChildInt_(file
, line
, "ShlexecVarLE", 0);
544 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
549 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
550 bad_shellexecute
= 1;
551 okShell_(file
, line
)(rc
== rcEmpty
||
552 broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
553 "Got different return value with empty string: %lu %lu\n", rc
, rcEmpty
);
558 #define shell_execute(verb, filename, parameters, directory) \
559 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
561 static INT_PTR
shell_execute_ex_(const char* file
, int line
,
562 DWORD mask
, LPCSTR verb
, LPCSTR filename
,
563 LPCSTR parameters
, LPCSTR directory
,
567 SHELLEXECUTEINFOA sei
;
571 /* Add some flags so we can wait for the child process */
572 mask
|= SEE_MASK_NOCLOSEPROCESS
| SEE_MASK_NO_CONSOLE
;
574 strcpy(shell_call
, "ShellExecuteEx(");
575 sprintf(smask
, "0x%x", mask
);
576 strcat_param(shell_call
, "mask", smask
);
577 strcat_param(shell_call
, "verb", verb
);
578 strcat_param(shell_call
, "file", filename
);
579 strcat_param(shell_call
, "params", parameters
);
580 strcat_param(shell_call
, "dir", directory
);
581 strcat_param(shell_call
, "class", class);
582 strcat(shell_call
, ")");
583 strcat(shell_call
, assoc_desc
);
584 if (winetest_debug
> 1)
585 trace_(file
, line
)("Called %s\n", shell_call
);
587 sei
.cbSize
=sizeof(sei
);
592 sei
.lpParameters
=parameters
;
593 sei
.lpDirectory
=directory
;
594 sei
.nShow
=SW_SHOWNORMAL
;
595 sei
.hInstApp
=NULL
; /* Out */
601 sei
.hProcess
=(HANDLE
)0xdeadbeef; /* Out */
603 DeleteFileA(child_file
);
604 SetLastError(0xcafebabe);
605 success
=ShellExecuteExA(&sei
);
606 rc
=(INT_PTR
)sei
.hInstApp
;
607 okShell_(file
, line
)((success
&& rc
> 32) || (!success
&& rc
<= 32),
608 "rc=%d and hInstApp=%ld is not allowed\n",
614 if (sei
.hProcess
!=NULL
)
616 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
617 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
618 "WaitForSingleObject(hProcess) returned %d\n",
620 wait_rc
= GetExitCodeProcess(sei
.hProcess
, &rc
);
621 okShell_(file
, line
)(wait_rc
, "GetExitCodeProcess() failed le=%u\n", GetLastError());
623 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
625 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
626 CloseHandle(sei
.hProcess
);
628 wait_rc
=WaitForSingleObject(hEvent
, 5000);
630 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
631 "WaitForSingleObject returned %d\n", wait_rc
);
633 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
634 "WaitForSingleObject returned %d\n", wait_rc
);
637 okShell_(file
, line
)(sei
.hProcess
==NULL
,
638 "returned a process handle %p\n", sei
.hProcess
);
640 /* The child process may have changed the result file, so let profile
641 * functions know about it
643 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
644 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
647 dump_child_(file
, line
);
648 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
650 winetest_add_failures(c
);
651 okChildInt_(file
, line
, "ShlexecVarLE", 0);
652 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
657 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
658 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
663 * Functions to create / delete associations wrappers
667 static BOOL
create_test_association(const char* extension
)
669 HKEY hkey
, hkey_shell
;
670 char class[MAX_PATH
];
673 sprintf(class, "shlexec%s", extension
);
674 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
676 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
677 "could not create association %s (rc=%d)\n", class, rc
);
678 if (rc
!= ERROR_SUCCESS
)
681 rc
=RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
682 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
685 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
686 KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkey
, NULL
);
687 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
689 rc
=RegCreateKeyExA(hkey
, "shell", 0, NULL
, 0,
690 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
691 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
694 CloseHandle(hkey_shell
);
699 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
700 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
703 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
704 DWORD dwMaxLen
, dwSize
;
705 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
710 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
714 /* Get highest length for keys, values */
715 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
716 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
717 if (ret
) goto cleanup
;
721 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
722 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
724 /* Name too big: alloc a buffer for it */
725 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
727 ret
= ERROR_NOT_ENOUGH_MEMORY
;
733 /* Recursively delete all the subkeys */
737 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
738 NULL
, NULL
, NULL
)) break;
740 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
741 if (ret
) goto cleanup
;
745 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
750 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
751 NULL
, NULL
, NULL
, NULL
)) break;
753 ret
= RegDeleteValueA(hKey
, lpszName
);
754 if (ret
) goto cleanup
;
758 /* Free buffer if allocated */
759 if (lpszName
!= szNameBuf
)
760 HeapFree( GetProcessHeap(), 0, lpszName
);
762 RegCloseKey(hSubKey
);
766 static void delete_test_association(const char* extension
)
768 char class[MAX_PATH
];
770 sprintf(class, "shlexec%s", extension
);
771 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, class);
772 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
775 static void create_test_verb_dde(const char* extension
, const char* verb
,
776 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
777 const char *application
, const char *topic
,
780 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
781 char shell
[MAX_PATH
];
785 strcpy(assoc_desc
, " Assoc ");
786 strcat_param(assoc_desc
, "ext", extension
);
787 strcat_param(assoc_desc
, "verb", verb
);
788 sprintf(shell
, "%d", rawcmd
);
789 strcat_param(assoc_desc
, "rawcmd", shell
);
790 strcat_param(assoc_desc
, "cmdtail", cmdtail
);
791 strcat_param(assoc_desc
, "ddeexec", ddeexec
);
792 strcat_param(assoc_desc
, "app", application
);
793 strcat_param(assoc_desc
, "topic", topic
);
794 strcat_param(assoc_desc
, "ifexec", ifexec
);
796 sprintf(shell
, "shlexec%s\\shell", extension
);
797 rc
=RegOpenKeyExA(HKEY_CLASSES_ROOT
, shell
, 0,
798 KEY_CREATE_SUB_KEY
, &hkey_shell
);
799 ok(rc
== ERROR_SUCCESS
, "%s key creation failed with %d\n", shell
, rc
);
801 rc
=RegCreateKeyExA(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
802 NULL
, &hkey_verb
, NULL
);
803 ok(rc
== ERROR_SUCCESS
, "%s verb key creation failed with %d\n", verb
, rc
);
805 rc
=RegCreateKeyExA(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
806 NULL
, &hkey_cmd
, NULL
);
807 ok(rc
== ERROR_SUCCESS
, "\'command\' key creation failed with %d\n", rc
);
811 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
815 cmd
=HeapAlloc(GetProcessHeap(), 0, strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
816 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
817 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
818 ok(rc
== ERROR_SUCCESS
, "setting command failed with %d\n", rc
);
819 HeapFree(GetProcessHeap(), 0, cmd
);
824 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
826 rc
=RegCreateKeyExA(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
827 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
828 ok(rc
== ERROR_SUCCESS
, "\'ddeexec\' key creation failed with %d\n", rc
);
829 rc
=RegSetValueExA(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
831 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
835 rc
=RegCreateKeyExA(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
836 NULL
, &hkey_application
, NULL
);
837 ok(rc
== ERROR_SUCCESS
, "\'application\' key creation failed with %d\n", rc
);
839 rc
=RegSetValueExA(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
840 strlen(application
)+1);
841 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
842 CloseHandle(hkey_application
);
846 rc
=RegCreateKeyExA(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
847 NULL
, &hkey_topic
, NULL
);
848 ok(rc
== ERROR_SUCCESS
, "\'topic\' key creation failed with %d\n", rc
);
849 rc
=RegSetValueExA(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
851 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
852 CloseHandle(hkey_topic
);
856 rc
=RegCreateKeyExA(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
857 NULL
, &hkey_ifexec
, NULL
);
858 ok(rc
== ERROR_SUCCESS
, "\'ifexec\' key creation failed with %d\n", rc
);
859 rc
=RegSetValueExA(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
861 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
862 CloseHandle(hkey_ifexec
);
864 CloseHandle(hkey_ddeexec
);
867 CloseHandle(hkey_shell
);
868 CloseHandle(hkey_verb
);
869 CloseHandle(hkey_cmd
);
872 /* Creates a class' non-DDE test verb.
873 * This function is meant to be used to create long term test verbs and thus
874 * does not trace them.
876 static void create_test_verb(const char* extension
, const char* verb
,
877 int rawcmd
, const char* cmdtail
)
879 create_test_verb_dde(extension
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
881 reset_association_description();
887 * GetLongPathNameA equivalent that supports Win95 and WinNT
891 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
893 char tmplongpath
[MAX_PATH
];
895 DWORD sp
= 0, lp
= 0;
897 WIN32_FIND_DATAA wfd
;
900 if (!shortpath
|| !shortpath
[0])
903 if (shortpath
[1] == ':')
905 tmplongpath
[0] = shortpath
[0];
906 tmplongpath
[1] = ':';
910 while (shortpath
[sp
])
912 /* check for path delimiters and reproduce them */
913 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
915 if (!lp
|| tmplongpath
[lp
-1] != '\\')
917 /* strip double "\\" */
918 tmplongpath
[lp
++] = '\\';
920 tmplongpath
[lp
] = 0; /* terminate string */
926 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
928 tmplongpath
[lp
++] = *p
++;
929 tmplongpath
[lp
++] = *p
++;
931 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
932 tmplen
= p
- (shortpath
+ sp
);
933 lstrcpynA(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
934 /* Check if the file exists and use the existing file name */
935 goit
= FindFirstFileA(tmplongpath
, &wfd
);
936 if (goit
== INVALID_HANDLE_VALUE
)
939 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
940 lp
+= strlen(tmplongpath
+ lp
);
943 tmplen
= strlen(shortpath
) - 1;
944 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
945 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
946 tmplongpath
[lp
++] = shortpath
[tmplen
];
949 tmplen
= strlen(tmplongpath
) + 1;
950 if (tmplen
<= longlen
)
952 strcpy(longpath
, tmplongpath
);
953 tmplen
--; /* length without 0 */
966 static const char* testfiles
[]=
968 "%s\\test file.shlexec",
969 "%s\\%%nasty%% $file.shlexec",
970 "%s\\test file.noassoc",
971 "%s\\test file.noassoc.shlexec",
972 "%s\\test file.shlexec.noassoc",
973 "%s\\test_shortcut_shlexec.lnk",
974 "%s\\test_shortcut_exe.lnk",
976 "%s\\test file.shlfoo",
978 "%s\\masked file.shlexec",
983 "%s\\simple.shlexec",
984 "%s\\drawback_file.noassoc",
985 "%s\\drawback_file.noassoc foo.shlexec",
986 "%s\\drawback_nonexist.noassoc foo.shlexec",
993 const char* basename
;
998 static filename_tests_t filename_tests
[]=
1000 /* Test bad / nonexistent filenames */
1001 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1002 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
1004 /* Standard tests */
1005 {NULL
, "%s\\test file.shlexec", 0x0, 33},
1006 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
1007 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
1008 {NULL
, "%s/test file.shlexec", 0x0, 33},
1010 /* Test filenames with no association */
1011 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1013 /* Test double extensions */
1014 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
1015 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
1017 /* Test alternate verbs */
1018 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1019 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1021 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
1022 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1024 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC
},
1026 /* Test file masked due to space */
1027 {NULL
, "%s\\masked file.shlexec", 0x0, 33},
1028 /* Test if quoting prevents the masking */
1029 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
1030 /* Test with incorrect quote */
1031 {NULL
, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF
},
1036 static filename_tests_t noquotes_tests
[]=
1038 /* Test unquoted '%1' thingies */
1039 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1040 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1041 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1046 static void test_lpFile_parsed(void)
1048 char fileA
[MAX_PATH
];
1051 if (skip_shlexec_tests
)
1053 skip("No filename parsing tests due to lack of .shlexec association\n");
1057 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1058 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
1059 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1060 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1062 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1063 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
1064 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1065 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1066 "failed: rc=%lu\n", rc
);
1068 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1069 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
1070 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1071 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1073 /* ""command"" not works on wine (and real win9x and w2k) */
1074 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
1075 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1076 todo_wine
okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
1077 "failed: rc=%lu\n", rc
);
1079 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
1080 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
1081 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1082 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1084 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1085 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
1086 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1089 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
1090 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1092 /* test SEE_MASK_DOENVSUBST works */
1093 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1094 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
1095 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1097 /* quoted lpFile does not work on real win95 and nt4 */
1098 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1099 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
1100 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1101 "failed: rc=%lu\n", rc
);
1107 const char* args
[11];
1111 static const cmdline_tests_t cmdline_tests
[] =
1116 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1117 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
1119 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1120 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
1122 {"exe arg\"one\" \"second\"arg thirdarg ",
1123 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
1125 /* Don't lose unclosed quoted arguments */
1126 {"exe arg1 \"unclosed",
1127 {"exe", "arg1", "unclosed", NULL
}, 0},
1130 {"exe", "arg1", "", NULL
}, 0},
1132 /* cmd's metacharacters have no special meaning */
1133 {"exe \"one^\" \"arg\"&two three|four",
1134 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
1136 /* Environment variables are not interpreted either */
1138 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
1140 /* If not followed by a quote, backslashes go through as is */
1141 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1142 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1144 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1145 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1147 /* When followed by a quote their number is halved and the remainder
1150 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1151 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1153 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1154 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1156 /* One can put a quote in an unquoted string by tripling it, that is in
1157 * effect quoting it like so """ -> ". The general rule is as follows:
1158 * 3n quotes -> n quotes
1159 * 3n+1 quotes -> n quotes plus start of a quoted string
1160 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1161 * Nicely, when n is 0 we get the standard rules back.
1163 {"exe two\"\"quotes next",
1164 {"exe", "twoquotes", "next", NULL
}, 0},
1166 {"exe three\"\"\"quotes next",
1167 {"exe", "three\"quotes", "next", NULL
}, 0},
1169 {"exe four\"\"\"\" quotes\" next 4%3=1",
1170 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0},
1172 {"exe five\"\"\"\"\"quotes next",
1173 {"exe", "five\"quotes", "next", NULL
}, 0},
1175 {"exe six\"\"\"\"\"\"quotes next",
1176 {"exe", "six\"\"quotes", "next", NULL
}, 0},
1178 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1179 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0},
1181 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1182 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0},
1184 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1185 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1187 /* Inside a quoted string the opening quote is added to the set of
1188 * consecutive quotes to get the effective quotes count. This gives:
1189 * 1+3n quotes -> n quotes
1190 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1191 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1193 {"exe \"two\"\"quotes next",
1194 {"exe", "two\"quotes", "next", NULL
}, 0},
1196 {"exe \"two\"\" next",
1197 {"exe", "two\"", "next", NULL
}, 0},
1199 {"exe \"three\"\"\" quotes\" next 4%3=1",
1200 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0},
1202 {"exe \"four\"\"\"\"quotes next",
1203 {"exe", "four\"quotes", "next", NULL
}, 0},
1205 {"exe \"five\"\"\"\"\"quotes next",
1206 {"exe", "five\"\"quotes", "next", NULL
}, 0},
1208 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1209 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0},
1211 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1212 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0},
1214 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1215 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1217 /* Escaped consecutive quotes are fun */
1218 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1219 {"exe", "the crazy \\\"\\", "quotes", NULL
}, 0},
1221 /* The executable path has its own rules!!!
1222 * - Backslashes have no special meaning.
1223 * - If the first character is a quote, then the second quote ends the
1225 * - The previous rule holds even if the next character is not a space!
1226 * - If the first character is not a quote, then quotes have no special
1227 * meaning either and the executable path stops at the first space.
1228 * - The consecutive quotes rules don't apply either.
1229 * - Even if there is no space between the executable path and the first
1230 * argument, the latter is parsed using the regular rules.
1232 {"exe\"file\"path arg1",
1233 {"exe\"file\"path", "arg1", NULL
}, 0},
1235 {"exe\"file\"path\targ1",
1236 {"exe\"file\"path", "arg1", NULL
}, 0},
1238 {"exe\"path\\ arg1",
1239 {"exe\"path\\", "arg1", NULL
}, 0},
1241 {"\\\"exe \"arg one\"",
1242 {"\\\"exe", "arg one", NULL
}, 0},
1244 {"\"spaced exe\" \"next arg\"",
1245 {"spaced exe", "next arg", NULL
}, 0},
1247 {"\"spaced exe\"\t\"next arg\"",
1248 {"spaced exe", "next arg", NULL
}, 0},
1250 {"\"exe\"arg\" one\" argtwo",
1251 {"exe", "arg one", "argtwo", NULL
}, 0},
1253 {"\"spaced exe\\\"arg1 arg2",
1254 {"spaced exe\\", "arg1", "arg2", NULL
}, 0},
1257 {"two", " arg1 ", NULL
}, 0},
1259 {"\"three\"\"\" arg2",
1260 {"three", "", "arg2", NULL
}, 0},
1262 {"\"four\"\"\"\"arg1",
1263 {"four", "\"arg1", NULL
}, 0},
1265 /* If the first character is a space then the executable path is empty */
1266 {" \"arg\"one argtwo",
1267 {"", "argone", "argtwo", NULL
}, 0},
1272 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1274 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1280 /* trace("----- cmd='%s'\n", test->cmd); */
1281 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, sizeof(cmdW
)/sizeof(*cmdW
));
1282 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1283 if (argsW
== NULL
&& cl2a_count
== -1)
1285 win_skip("CommandLineToArgvW not implemented, skipping\n");
1288 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1289 "expected NULL-terminated list of commandline arguments\n");
1292 while (test
->args
[count
])
1294 if ((test
->todo
& 0x1) == 0)
1295 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1297 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1299 for (i
= 0; i
< cl2a_count
; i
++)
1303 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, sizeof(argW
)/sizeof(*argW
));
1304 if ((test
->todo
& (1 << (i
+4))) == 0)
1305 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1307 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1309 else if ((test
->todo
& 0x1) == 0)
1310 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1312 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1319 static void test_commandline2argv(void)
1321 static const WCHAR exeW
[] = {'e','x','e',0};
1322 const cmdline_tests_t
* test
;
1323 WCHAR strW
[MAX_PATH
];
1328 test
= cmdline_tests
;
1331 if (!test_one_cmdline(test
))
1336 SetLastError(0xdeadbeef);
1337 args
= CommandLineToArgvW(exeW
, NULL
);
1338 le
= GetLastError();
1339 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1341 SetLastError(0xdeadbeef);
1342 args
= CommandLineToArgvW(NULL
, NULL
);
1343 le
= GetLastError();
1344 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1347 args
= CommandLineToArgvW(strW
, &numargs
);
1348 ok(numargs
== 1 || broken(numargs
> 1), "expected 1 args, got %d\n", numargs
);
1349 ok(!args
|| (!args
[numargs
] || broken(args
[numargs
] != NULL
) /* before Vista */),
1350 "expected NULL-terminated list of commandline arguments\n");
1353 GetModuleFileNameW(NULL
, strW
, sizeof(strW
)/sizeof(*strW
));
1354 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
));
1356 if (args
) LocalFree(args
);
1359 /* The goal here is to analyze how ShellExecute() builds the command that
1360 * will be run. The tricky part is that there are three transformation
1361 * steps between the 'parameters' string we pass to ShellExecute() and the
1362 * argument list we observe in the child process:
1363 * - The parsing of 'parameters' string into individual arguments. The tests
1364 * show this is done differently from both CreateProcess() and
1365 * CommandLineToArgv()!
1366 * - The way the command 'formatting directives' such as %1, %2, etc are
1368 * - And the way the resulting command line is then parsed to yield the
1369 * argument list we check.
1376 cmdline_tests_t cmd
;
1377 cmdline_tests_t broken
;
1380 static const argify_tests_t argify_tests
[] =
1382 /* Start with three simple parameters. Notice that one can reorder and
1383 * duplicate the parameters. Also notice how %* take the raw input
1384 * parameters string, including the trailing spaces, no matter what
1385 * arguments have already been used.
1387 {"Params232S", "p2 p3 p4 ", 0xc2,
1388 {" p2 p3 \"p2\" \"p2 p3 p4 \"",
1389 {"", "p2", "p3", "p2", "p2 p3 p4 ", NULL
}, 0}},
1391 /* Unquoted argument references like %2 don't automatically quote their
1392 * argument. Similarly, when they are quoted they don't escape the quotes
1393 * that their argument may contain.
1395 {"Params232S", "\"p two\" p3 p4 ", 0x3f3,
1396 {" p two p3 \"p two\" \"\"p two\" p3 p4 \"",
1397 {"", "p", "two", "p3", "p two", "p", "two p3 p4 ", NULL
}, 0}},
1399 /* Only single digits are supported so only %1 to %9. Shown here with %20
1400 * because %10 is a pain.
1402 {"Params20", "p", 0,
1404 {"", "p0", NULL
}, 0}},
1406 /* Only (double-)quotes have a special meaning. */
1407 {"Params23456", "'p2 p3` p4\\ $even", 0x40,
1408 {" \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\"",
1409 {"", "'p2", "p3`", "p4\" $even \"", NULL
}, 0}},
1411 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", 0x1c2,
1412 {" \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\"",
1413 {"", "p=2", "p-3", "p4\tp4\rp4\np4", "", "", NULL
}, 0}},
1415 /* In unquoted strings, quotes are treated are a parameter separator just
1416 * like spaces! However they can be doubled to get a literal quote.
1418 * 2n quotes -> n quotes
1419 * 2n+1 quotes -> n quotes and a parameter separator
1421 {"Params23456789", "one\"quote \"p four\" one\"quote p7", 0xff3,
1422 {" \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\"",
1423 {"", "one", "quote", "p four", "one", "quote", "p7", "", "", NULL
}, 0}},
1425 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", 0xf2,
1426 {" \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1427 {"", "twoquotes p", "three twoquotes", "p5", "", "", "", "", NULL
}, 0}},
1429 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", 0xff3,
1430 {" \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\"",
1431 {"", "three\"", "quotes", "p four", "three\"", "quotes", "p6", "", "", NULL
}, 0}},
1433 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", 0xf3,
1434 {" \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1435 {"", "four\"quotes p", "three fourquotes p5 \"", "", "", "", NULL
}, 0}},
1437 /* Quoted strings cannot be continued by tacking on a non space character
1440 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", 0x1f3,
1441 {" \"p two\" \"p3\" \"p four\" \"p5\" \"p6\"",
1442 {"", "p two", "p3", "p four", "p5", "p6", NULL
}, 0}},
1444 /* In quoted strings, the quotes are halved and an odd number closes the
1445 * string. Specifically:
1446 * 2n quotes -> n quotes
1447 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1449 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", 0xff3,
1450 {" \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\"",
1451 {"", "one q", "uote", "p four", "one q", "uote", "p7", "", "", NULL
}, 0}},
1453 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", 0x1ff3,
1454 {" \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1455 {"", "two ", "quotes p", "three two", " quotes", "p5", "", "", "", "", NULL
}, 0}},
1457 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", 0xff3,
1458 {" \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\"",
1459 {"", "three q\"", "uotes", "p four", "three q\"", "uotes", "p7", "", "", NULL
}, 0}},
1461 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", 0xff3,
1462 {" \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1463 {"", "four \"", "quotes p", "three four", "", "quotes p5 \"", "", "", "", NULL
}, 0}},
1465 /* The quoted string rules also apply to consecutive quotes at the start
1466 * of a parameter but don't count the opening quote!
1468 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", 0xbf3,
1469 {" \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\"",
1470 {"", "", "twoquotes", "p four", "", "twoquotes", "p7", "", "", NULL
}, 0}},
1472 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", 0x6f3,
1473 {" \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1474 {"", "three", "quotes p", "three \"three", "quotes p5 \"", "", "", "", NULL
}, 0}},
1476 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", 0xbf3,
1477 {" \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\"",
1478 {"", "\"", "fourquotes", "p four", "\"", "fourquotes", "p7", "", "", NULL
}, 0}},
1480 /* An unclosed quoted string gets lost! */
1481 {"Params23456", "p2 \"p3\" \"p4 is lost", 0x1c3,
1482 {" \"p2\" \"p3\" \"\" \"\" \"\"",
1483 {"", "p2", "p3", "", "", "", NULL
}, 0},
1484 {" \"p2\" \"p3\" \"p3\" \"\" \"\"",
1485 {"", "p2", "p3", "p3", "", "", NULL
}, 0}},
1487 /* Backslashes have no special meaning even when preceding quotes. All
1488 * they do is start an unquoted string.
1490 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", 0x73,
1491 {" \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\"",
1492 {"", "\" p\\three pfour\"", "pfive", "", NULL
}, 0}},
1494 /* Environment variables are left untouched. */
1495 {"Params23456", "%TMPDIR% %t %c", 0,
1496 {" \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\"",
1497 {"", "%TMPDIR%", "%t", "%c", "", "", NULL
}, 0}},
1499 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1500 * before the parameter!
1501 * (but not the previous parameter's closing quote fortunately)
1503 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", 0x3f3,
1504 {" ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 ",
1505 {"", "~2=p2 p3 p4 p5 p6 ", "~3= p3 p4 p5 p6 ", "~4= p4 p5 p6 ", "~5=", "p5", "p6", NULL
}, 0}},
1507 /* %~n works even if there is no nth parameter. */
1508 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", 0x12,
1510 {"", "~9= ", NULL
}, 0}},
1512 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", 0x12,
1514 {"", "~9=", NULL
}, 0}},
1516 /* The %~n directives also transmit the tenth parameter and beyond. */
1517 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", 0x12,
1518 {" ~9=\" p9 p10 p11 and beyond!\"",
1519 {"", "~9= p9 p10 p11 and beyond!", NULL
}, 0}},
1521 /* Bad formatting directives lose their % sign, except those followed by
1522 * a tilde! Environment variables are not expanded but lose their % sign.
1524 {"ParamsBad", "p2 p3 p4 p5", 0x12,
1525 {" \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\"",
1526 {"", "% - %~ %~0 %~1 %~a %~* a b c TMPDIR", NULL
}, 0}},
1528 {NULL
, NULL
, 0, {NULL
, {NULL
}, 0}}
1531 static void test_argify(void)
1533 BOOL has_cl2a
= TRUE
;
1534 char fileA
[MAX_PATH
], params
[2*MAX_PATH
+12];
1536 const argify_tests_t
* test
;
1537 const cmdline_tests_t
*bad
;
1541 /* Test with a long parameter */
1542 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1543 fileA
[rc
] = 'a' + rc
% 26;
1544 fileA
[MAX_PATH
-1] = '\0';
1545 sprintf(params
, "shlexec \"%s\" %s", child_file
, fileA
);
1547 /* We need NOZONECHECKS on Win2003 to block a dialog */
1548 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
, NULL
, NULL
);
1549 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1550 okChildInt("argcA", 4);
1551 okChildPath("argvA3", fileA
);
1553 if (skip_shlexec_tests
)
1555 skip("No argify tests due to lack of .shlexec association\n");
1559 create_test_verb(".shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1560 create_test_verb(".shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1561 create_test_verb(".shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1562 create_test_verb(".shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1563 create_test_verb(".shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1564 create_test_verb(".shlexec", "Params20", 0, "Params20 \"%20\"");
1565 create_test_verb(".shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1567 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1569 test
= argify_tests
;
1570 while (test
->params
)
1572 bad
= test
->broken
.cmd
? &test
->broken
: &test
->cmd
;
1574 /* trace("***** verb='%s' params='%s'\n", test->verb, test->params); */
1575 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
, test
->verb
, fileA
, test
->params
, NULL
, NULL
);
1576 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1579 while (test
->cmd
.args
[count
])
1581 if ((test
->todo
& 0x1) == 0)
1582 /* +4 for the shlexec arguments, -1 because of the added ""
1583 * argument for the CommandLineToArgvW() tests.
1585 okChildInt("argcA", 4 + count
- 1);
1587 okChildInt("argcA", 4 + count
- 1);
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 if ((test
->todo
& 0x2) == 0)
1597 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1598 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
1600 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1601 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
1603 for (i
= 0; i
< count
- 1; i
++)
1606 sprintf(argname
, "argvA%d", 4 + i
);
1607 if ((test
->todo
& (1 << (i
+4))) == 0)
1608 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1610 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1614 has_cl2a
= test_one_cmdline(&(test
->cmd
));
1619 static void test_filename(void)
1621 char filename
[MAX_PATH
];
1622 const filename_tests_t
* test
;
1626 if (skip_shlexec_tests
)
1628 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1632 test
=filename_tests
;
1633 while (test
->basename
)
1635 BOOL quotedfile
= FALSE
;
1637 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1639 win_skip("Skipping shellexecute of file with unassociated extension\n");
1644 sprintf(filename
, test
->basename
, tmpdir
);
1645 if (strchr(filename
, '/'))
1655 if ((test
->todo
& 0x40)==0)
1657 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1661 char quoted
[MAX_PATH
+ 2];
1664 sprintf(quoted
, "\"%s\"", filename
);
1665 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1669 okShell(rc
==test
->rc
||
1670 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1671 "failed: rc=%ld err=%u\n", rc
, GetLastError());
1675 if ((test
->todo
& 0x2)==0)
1677 okChildInt("argcA", 5);
1681 okChildInt("argcA", 5);
1683 verb
=(test
->verb
? test
->verb
: "Open");
1684 if ((test
->todo
& 0x4)==0)
1686 okChildString("argvA3", verb
);
1690 okChildString("argvA3", verb
);
1692 if ((test
->todo
& 0x8)==0)
1694 okChildPath("argvA4", filename
);
1698 okChildPath("argvA4", filename
);
1704 test
=noquotes_tests
;
1705 while (test
->basename
)
1707 sprintf(filename
, test
->basename
, tmpdir
);
1708 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1711 if ((test
->todo
& 0x1)==0)
1713 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1717 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1725 verb
=(test
->verb
? test
->verb
: "Open");
1726 if ((test
->todo
& 0x4)==0)
1728 okChildString("argvA3", verb
);
1732 okChildString("argvA3", verb
);
1741 space
=strchr(str
, ' ');
1744 sprintf(attrib
, "argvA%d", count
);
1745 if ((test
->todo
& 0x8)==0)
1747 okChildPath(attrib
, str
);
1751 okChildPath(attrib
, str
);
1758 if ((test
->todo
& 0x2)==0)
1760 okChildInt("argcA", count
);
1764 okChildInt("argcA", count
);
1770 if (dllver
.dwMajorVersion
!= 0)
1772 /* The more recent versions of shell32.dll accept quoted filenames
1773 * while older ones (e.g. 4.00) don't. Still we want to test this
1774 * because IE 6 depends on the new behavior.
1775 * One day we may need to check the exact version of the dll but for
1776 * now making sure DllGetVersion() is present is sufficient.
1778 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1779 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1780 okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1781 okChildInt("argcA", 5);
1782 okChildString("argvA3", "Open");
1783 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1784 okChildPath("argvA4", filename
);
1790 const char* urlprefix
;
1791 const char* basename
;
1796 #define URL_SUCCESS 0x1
1797 #define USE_COLON 0x2
1798 #define USE_BSLASH 0x4
1800 static fileurl_tests_t fileurl_tests
[]=
1802 /* How many slashes does it take... */
1803 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1804 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1805 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1806 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1807 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1808 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1809 {"file://///", "%s\\test file.shlexec", 0, 0},
1811 /* Test with Windows-style paths */
1812 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0},
1813 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0},
1815 /* Check handling of hostnames */
1816 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1817 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1818 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1819 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1820 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1821 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1823 /* Environment variables are not expanded in URLs */
1824 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1825 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1827 /* Test shortcuts vs. URLs */
1828 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1d},
1833 static void test_fileurls(void)
1835 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1836 char command
[MAX_PATH
];
1837 const fileurl_tests_t
* test
;
1841 if (skip_shlexec_tests
)
1843 skip("No file URL tests due to lack of .shlexec association\n");
1847 rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
, NULL
,
1848 "file:///nosuchfile.shlexec", NULL
, NULL
, NULL
);
1851 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1855 get_long_path_name(tmpdir
, longtmpdir
, sizeof(longtmpdir
)/sizeof(*longtmpdir
));
1856 SetEnvironmentVariableA("urlprefix", "file:///");
1859 while (test
->basename
)
1861 /* Build the file URL */
1862 sprintf(filename
, test
->basename
, longtmpdir
);
1863 strcpy(fileurl
, test
->urlprefix
);
1864 strcat(fileurl
, filename
);
1865 s
= fileurl
+ strlen(test
->urlprefix
);
1868 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1870 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1875 /* Test it first with FindExecutable() */
1876 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1877 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1879 /* Then ShellExecute() */
1880 if ((test
->todo
& 0x10) == 0)
1881 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1883 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1884 if (bad_shellexecute
)
1886 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1889 if (test
->flags
& URL_SUCCESS
)
1891 if ((test
->todo
& 0x1) == 0)
1892 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1894 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1898 if ((test
->todo
& 0x1) == 0)
1899 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1900 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1901 "failed: bad rc=%lu\n", rc
);
1903 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1904 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1905 "failed: bad rc=%lu\n", rc
);
1909 if ((test
->todo
& 0x2) == 0)
1910 okChildInt("argcA", 5);
1912 okChildInt("argcA", 5);
1914 if ((test
->todo
& 0x4) == 0)
1915 okChildString("argvA3", "Open");
1917 okChildString("argvA3", "Open");
1919 if ((test
->todo
& 0x8) == 0)
1920 okChildPath("argvA4", filename
);
1922 okChildPath("argvA4", filename
);
1927 SetEnvironmentVariableA("urlprefix", NULL
);
1930 static void test_find_executable(void)
1932 char notepad_path
[MAX_PATH
];
1933 char filename
[MAX_PATH
];
1934 char command
[MAX_PATH
];
1935 const filename_tests_t
* test
;
1938 if (!create_test_association(".sfe"))
1940 skip("Unable to create association for '.sfe'\n");
1943 create_test_verb(".sfe", "Open", 1, "%1");
1945 /* Don't test FindExecutable(..., NULL), it always crashes */
1947 strcpy(command
, "your word");
1948 if (0) /* Can crash on Vista! */
1950 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
1951 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1952 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1955 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
1956 strcat( notepad_path
, "\\notepad.exe" );
1958 /* Search for something that should be in the system-wide search path (no default directory) */
1959 strcpy(command
, "your word");
1960 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
1961 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1962 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1964 /* Search for something that should be in the system-wide search path (with default directory) */
1965 strcpy(command
, "your word");
1966 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
1967 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1968 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1970 strcpy(command
, "your word");
1971 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
1972 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1973 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1975 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
1976 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1977 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1978 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1980 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
1981 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1983 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
1984 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1986 delete_test_association(".sfe");
1988 if (!create_test_association(".shl"))
1990 skip("Unable to create association for '.shl'\n");
1993 create_test_verb(".shl", "Open", 0, "Open");
1995 sprintf(filename
, "%s\\test file.shl", tmpdir
);
1996 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1997 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1999 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
2000 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2002 delete_test_association(".shl");
2006 /* On Windows XP and 2003 FindExecutable() is completely broken.
2007 * Probably what it does is convert the filename to 8.3 format,
2008 * which as a side effect converts the '.shlfoo' extension to '.shl',
2009 * and then tries to find an association for '.shl'. This means it
2010 * will normally fail on most extensions with more than 3 characters,
2011 * like '.mpeg', etc.
2012 * Also it means we cannot do any other test.
2014 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
2018 if (skip_shlexec_tests
)
2020 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2024 test
=filename_tests
;
2025 while (test
->basename
)
2027 sprintf(filename
, test
->basename
, tmpdir
);
2028 if (strchr(filename
, '/'))
2039 /* Win98 does not '\0'-terminate command! */
2040 memset(command
, '\0', sizeof(command
));
2041 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2044 if ((test
->todo
& 0x10)==0)
2046 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2050 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2055 equal
=strcmp(command
, argv0
) == 0 ||
2056 /* NT4 returns an extra 0x8 character! */
2057 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
2058 if ((test
->todo
& 0x20)==0)
2060 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2061 filename
, command
, argv0
);
2065 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2066 filename
, command
, argv0
);
2074 static filename_tests_t lnk_tests
[]=
2076 /* Pass bad / nonexistent filenames as a parameter */
2077 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
2078 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
2080 /* Pass regular paths as a parameter */
2081 {NULL
, "%s\\test file.shlexec", 0xa, 33},
2082 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2084 /* Pass filenames with no association as a parameter */
2085 {NULL
, "%s\\test file.noassoc", 0xa, 33},
2090 static void test_lnks(void)
2092 char filename
[MAX_PATH
];
2093 char params
[MAX_PATH
];
2094 const filename_tests_t
* test
;
2097 if (skip_shlexec_tests
)
2098 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2101 /* Should open through our association */
2102 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2103 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2104 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2105 okChildInt("argcA", 5);
2106 okChildString("argvA3", "Open");
2107 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2108 get_long_path_name(params
, filename
, sizeof(filename
));
2109 okChildPath("argvA4", filename
);
2111 todo_wait rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
2112 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2113 okChildInt("argcA", 5);
2114 todo_wine
okChildString("argvA3", "Open");
2115 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2116 get_long_path_name(params
, filename
, sizeof(filename
));
2117 todo_wine
okChildPath("argvA4", filename
);
2120 /* Should just run our executable */
2121 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2122 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2123 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2124 okChildInt("argcA", 4);
2125 okChildString("argvA3", "Lnk");
2127 if (!skip_shlexec_tests
)
2129 /* An explicit class overrides lnk's ContextMenuHandler */
2130 rc
=shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
2131 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2132 okChildInt("argcA", 5);
2133 okChildString("argvA3", "Open");
2134 okChildPath("argvA4", filename
);
2137 if (dllver
.dwMajorVersion
>=6)
2140 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2141 * Older versions don't or are quite buggy in this regard.
2143 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2151 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2152 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2153 okChildInt("argcA", 4);
2154 okChildString("argvA3", "Lnk");
2157 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2159 while (test
->basename
)
2162 sprintf(params
+1, test
->basename
, tmpdir
);
2163 strcat(params
,"\"");
2164 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2168 if ((test
->todo
& 0x1)==0)
2170 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2174 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2178 if ((test
->todo
& 0x2)==0)
2180 okChildInt("argcA", 5);
2184 okChildInt("argcA", 5);
2186 if ((test
->todo
& 0x4)==0)
2188 okChildString("argvA3", "Lnk");
2192 okChildString("argvA3", "Lnk");
2194 sprintf(params
, test
->basename
, tmpdir
);
2195 okChildPath("argvA4", params
);
2202 static void test_exes(void)
2204 char filename
[MAX_PATH
];
2208 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2210 /* We need NOZONECHECKS on Win2003 to block a dialog */
2211 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
2213 okShell(rc
> 32, "returned %lu\n", rc
);
2214 okChildInt("argcA", 4);
2215 okChildString("argvA3", "Exec");
2217 if (! skip_noassoc_tests
)
2219 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
2220 if (CopyFileA(argv0
, filename
, FALSE
))
2222 rc
=shell_execute(NULL
, filename
, params
, NULL
);
2224 okShell(rc
==SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2230 win_skip("Skipping shellexecute of file with unassociated extension\n");
2233 /* test combining executable and parameters */
2234 sprintf(filename
, "%s shlexec \"%s\" Exec", argv0
, child_file
);
2235 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2236 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2238 sprintf(filename
, "\"%s\" shlexec \"%s\" Exec", argv0
, child_file
);
2239 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2240 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2242 /* A verb, even if invalid, overrides the normal handling of executables */
2243 todo_wait rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
,
2244 "notaverb", argv0
, NULL
, NULL
, NULL
);
2245 todo_wine
okShell(rc
== SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2247 if (!skip_shlexec_tests
)
2249 /* A class overrides the normal handling of executables too */
2250 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2251 rc
= shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
,
2252 NULL
, argv0
, NULL
, NULL
, ".shlexec");
2253 todo_wine
okShell(rc
> 32, "returned %lu\n", rc
);
2254 okChildInt("argcA", 5);
2255 todo_wine
okChildString("argvA3", "Open");
2256 todo_wine
okChildPath("argvA4", argv0
);
2262 const char* command
;
2263 const char* ddeexec
;
2264 const char* application
;
2268 const char* expectedDdeExec
;
2272 static dde_tests_t dde_tests
[] =
2274 /* Test passing and not passing command-line
2275 * argument, no DDE */
2276 {"", NULL
, NULL
, NULL
, NULL
, 0, ""},
2277 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, 1, ""},
2279 /* Test passing and not passing command-line
2280 * argument, with DDE */
2281 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 0, "[open(\"%s\")]"},
2282 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 1, "[open(\"%s\")]"},
2284 /* Test unquoted %1 in command and ddeexec
2285 * (test filename has space) */
2286 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", TRUE
/* before vista */},
2288 /* Test ifexec precedence over ddeexec */
2289 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2291 /* Test default DDE topic */
2292 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, 0, "[open(\"%s\")]"},
2294 /* Test default DDE application */
2295 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, 0, "[open(\"%s\")]"},
2300 static int waitforinputidle_count
;
2301 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
2303 waitforinputidle_count
++;
2304 if (winetest_debug
> 1)
2305 trace("WaitForInputIdle() waiting for dde event timeout=min(%u,5s)\n", timeout
);
2306 timeout
= timeout
< 5000 ? timeout
: 5000;
2307 return WaitForSingleObject(dde_ready_event
, timeout
);
2311 * WaitForInputIdle() will normally return immediately for console apps. That's
2312 * a problem for us because ShellExecute will assume that an app is ready to
2313 * receive DDE messages after it has called WaitForInputIdle() on that app.
2314 * To work around that we install our own version of WaitForInputIdle() that
2315 * will wait for the child to explicitly tell us that it is ready. We do that
2316 * by changing the entry for WaitForInputIdle() in the shell32 import address
2319 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2322 PIMAGE_NT_HEADERS nt_headers
;
2323 DWORD import_directory_rva
;
2324 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2327 base
= (char *) GetModuleHandleA("shell32.dll");
2328 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2329 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2331 /* Search for the correct imported module by walking the import descriptors */
2332 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2333 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2335 char *import_module_name
;
2337 import_module_name
= base
+ import_descriptor
->Name
;
2338 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2339 lstrcmpiA(import_module_name
, "user32") == 0)
2341 PIMAGE_THUNK_DATA int_entry
;
2342 PIMAGE_THUNK_DATA iat_entry
;
2344 /* The import name table and import address table are two parallel
2345 * arrays. We need the import name table to find the imported
2346 * routine and the import address table to patch the address, so
2347 * walk them side by side */
2348 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2349 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2350 while (int_entry
->u1
.Ordinal
!= 0)
2352 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2354 PIMAGE_IMPORT_BY_NAME import_by_name
;
2355 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2356 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2358 /* Found the correct routine in the correct imported module. Patch it. */
2360 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2361 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2362 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2363 if (winetest_debug
> 1)
2364 trace("Hooked %s.WaitForInputIdle\n", import_module_name
);
2375 import_descriptor
++;
2377 ok(hook_count
, "Could not hook WaitForInputIdle()\n");
2380 static void test_dde(void)
2382 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2383 const dde_tests_t
* test
;
2390 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2392 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2394 /* Default service is application name minus path and extension */
2395 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2396 *strchr(defApplication
, '.') = 0;
2398 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2399 4096, "winetest_shlexec_dde_map");
2400 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2402 ddeflags
= SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
2404 while (test
->command
)
2406 if (!create_test_association(".sde"))
2408 skip("Unable to create association for '.sde'\n");
2411 create_test_verb_dde(".sde", "Open", 0, test
->command
, test
->ddeexec
,
2412 test
->application
, test
->topic
, test
->ifexec
);
2414 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2416 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2417 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2421 shared_block
[0] = '\0';
2422 shared_block
[1] = '\0';
2426 waitforinputidle_count
= 0;
2427 dde_ready_event
= CreateEventA(NULL
, TRUE
, FALSE
, "winetest_shlexec_dde_ready");
2428 rc
= shell_execute_ex(ddeflags
, NULL
, filename
, NULL
, NULL
, NULL
);
2429 CloseHandle(dde_ready_event
);
2430 if (!(ddeflags
& SEE_MASK_WAITFORINPUTIDLE
) && rc
== SE_ERR_DDEFAIL
&&
2431 GetLastError() == ERROR_FILE_NOT_FOUND
&&
2432 strcmp(winetest_platform
, "windows") == 0)
2434 /* Windows 10 does not call WaitForInputIdle() for DDE, which
2435 * breaks the tests. So force the call by adding
2436 * SEE_MASK_WAITFORINPUTIDLE.
2438 trace("Adding SEE_MASK_WAITFORINPUTIDLE for Windows 10\n");
2439 ddeflags
|= SEE_MASK_WAITFORINPUTIDLE
;
2440 delete_test_association(".sde");
2443 okShell(32 < rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2445 ok(waitforinputidle_count
== 1, "WaitForInputIdle() was called %u times\n", waitforinputidle_count
);
2447 ok(waitforinputidle_count
== 0, "WaitForInputIdle() was called %u times for a non-DDE case\n", waitforinputidle_count
);
2452 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
2454 okChildInt("argcA", test
->expectedArgs
+ 3);
2456 if (test
->expectedArgs
== 1) okChildPath("argvA3", filename
);
2458 sprintf(params
, test
->expectedDdeExec
, filename
);
2459 okChildPath("ddeExec", params
);
2461 reset_association_description();
2463 delete_test_association(".sde");
2467 UnmapViewOfFile(shared_block
);
2469 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2472 #define DDE_DEFAULT_APP_VARIANTS 3
2475 const char* command
;
2476 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2478 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2479 } dde_default_app_tests_t
;
2481 static dde_default_app_tests_t dde_default_app_tests
[] =
2483 /* There are three possible sets of results: Windows <= 2000, XP SP1 and
2484 * >= XP SP2. Use the first two tests to determine which results to expect.
2487 /* Test unquoted existing filename with a space */
2488 {"%s\\test file.exe", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2489 {"%s\\test2 file.exe", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2491 /* Test unquoted existing filename with a space */
2492 {"%s\\test file.exe param", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2494 /* Test quoted existing filename with a space */
2495 {"\"%s\\test file.exe\"", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2496 {"\"%s\\test file.exe\" param", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2498 /* Test unquoted filename with a space that doesn't exist, but
2500 {"%s\\test2 file.exe param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2502 /* Test quoted filename with a space that does not exist */
2503 {"\"%s\\test2 file.exe\"", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2504 {"\"%s\\test2 file.exe\" param", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2506 /* Test filename supplied without the extension */
2507 {"%s\\test2", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2508 {"%s\\test2 param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2510 /* Test an unquoted nonexistent filename */
2511 {"%s\\notexist.exe", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2512 {"%s\\notexist.exe param", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2514 /* Test an application that will be found on the path */
2515 {"cmd", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2516 {"cmd param", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2518 /* Test an application that will not be found on the path */
2519 {"xyzwxyzwxyz", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2520 {"xyzwxyzwxyz param", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2522 {NULL
, {NULL
}, 0, {0}}
2528 DWORD threadIdParent
;
2529 } dde_thread_info_t
;
2531 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2533 dde_thread_info_t
*info
= arg
;
2534 assert(info
&& info
->filename
);
2535 PostThreadMessageA(info
->threadIdParent
,
2537 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2542 static void test_dde_default_app(void)
2544 char filename
[MAX_PATH
];
2546 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2547 const dde_default_app_tests_t
* test
;
2556 post_quit_on_execute
= FALSE
;
2558 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2559 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
2560 ok(rc
== DMLERR_NO_ERROR
, "got %lx\n", rc
);
2562 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2564 /* It is strictly not necessary to register an application name here, but wine's
2565 * DdeNameService implementation complains if 0 is passed instead of
2566 * hszApplication with DNS_FILTEROFF */
2567 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2568 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2569 ok(hszApplication
&& hszTopic
, "got %p and %p\n", hszApplication
, hszTopic
);
2570 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
2571 ok(ret
!= 0, "got %p\n", ret
);
2573 test
= dde_default_app_tests
;
2574 while (test
->command
)
2578 if (!create_test_association(".sde"))
2580 skip("Unable to create association for '.sde'\n");
2583 sprintf(params
, test
->command
, tmpdir
);
2584 create_test_verb_dde(".sde", "Open", 1, params
, "[test]", NULL
,
2586 ddeApplication
[0] = 0;
2588 /* No application will be run as we will respond to the first DDE event,
2589 * so don't wait for it */
2592 thread
= CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
);
2593 ok(thread
!= NULL
, "got %p\n", thread
);
2594 while (GetMessageA(&msg
, NULL
, 0, 0)) DispatchMessageA(&msg
);
2595 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2597 /* The first two tests determine which set of results to expect.
2598 * First check the platform as only the first set of results is
2599 * acceptable for Wine.
2601 if (strcmp(winetest_platform
, "wine"))
2603 if (test
== dde_default_app_tests
)
2605 if (strcmp(ddeApplication
, test
->expectedDdeApplication
[0]))
2608 else if (test
== dde_default_app_tests
+ 1)
2610 if (which
== 0 && rc
== test
->rc
[1])
2612 trace("DDE result variant %d\n", which
);
2616 if ((test
->todo
& 0x1)==0)
2618 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2619 rc
, GetLastError());
2623 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2624 rc
, GetLastError());
2628 if ((test
->todo
& 0x2)==0)
2630 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2631 "Expected application '%s', got '%s'\n",
2632 test
->expectedDdeApplication
[which
], ddeApplication
);
2636 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2637 "Expected application '%s', got '%s'\n",
2638 test
->expectedDdeApplication
[which
], ddeApplication
);
2641 reset_association_description();
2643 delete_test_association(".sde");
2647 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
2648 ok(ret
!= 0, "got %p\n", ret
);
2649 b
= DdeFreeStringHandle(ddeInst
, hszTopic
);
2650 ok(b
, "got %d\n", b
);
2651 b
= DdeFreeStringHandle(ddeInst
, hszApplication
);
2652 ok(b
, "got %d\n", b
);
2653 b
= DdeUninitialize(ddeInst
);
2654 ok(b
, "got %d\n", b
);
2657 static void init_test(void)
2660 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2661 char filename
[MAX_PATH
];
2662 WCHAR lnkfile
[MAX_PATH
];
2664 const char* const * testfile
;
2669 hdll
=GetModuleHandleA("shell32.dll");
2670 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2673 dllver
.cbSize
=sizeof(dllver
);
2674 pDllGetVersion(&dllver
);
2675 trace("major=%d minor=%d build=%d platform=%d\n",
2676 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2677 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2681 memset(&dllver
, 0, sizeof(dllver
));
2684 r
= CoInitialize(NULL
);
2685 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2689 rc
=GetModuleFileNameA(NULL
, argv0
, sizeof(argv0
));
2690 ok(rc
!= 0 && rc
< sizeof(argv0
), "got %d\n", rc
);
2691 if (GetFileAttributesA(argv0
)==INVALID_FILE_ATTRIBUTES
)
2693 strcat(argv0
, ".so");
2694 ok(GetFileAttributesA(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2695 "unable to find argv0!\n");
2698 /* Older versions (win 2k) fail tests if there is a space in
2700 if (dllver
.dwMajorVersion
<= 5)
2701 strcpy(filename
, "c:\\");
2703 GetTempPathA(sizeof(filename
), filename
);
2704 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2705 GetLongPathNameA(tmpdir
, tmpdir
, sizeof(tmpdir
));
2706 DeleteFileA( tmpdir
);
2707 rc
= CreateDirectoryA( tmpdir
, NULL
);
2708 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2709 /* Set %TMPDIR% for the tests */
2710 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2712 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2713 ok(rc
!= 0, "got %d\n", rc
);
2714 init_event(child_file
);
2716 /* Set up the test files */
2722 sprintf(filename
, *testfile
, tmpdir
);
2723 hfile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2724 FILE_ATTRIBUTE_NORMAL
, NULL
);
2725 if (hfile
==INVALID_HANDLE_VALUE
)
2727 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2734 /* Setup the test shortcuts */
2735 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2736 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2737 desc
.description
=NULL
;
2739 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2742 desc
.arguments
="ignored";
2747 create_lnk(lnkfile
, &desc
, 0);
2749 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2750 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2751 desc
.description
=NULL
;
2755 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2756 desc
.arguments
=params
;
2761 create_lnk(lnkfile
, &desc
, 0);
2763 /* Create a basic association suitable for most tests */
2764 if (!create_test_association(".shlexec"))
2766 skip_shlexec_tests
= TRUE
;
2767 skip("Unable to create association for '.shlexec'\n");
2770 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2771 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2772 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2773 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2774 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2775 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2777 /* Set an environment variable to see if it is inherited */
2778 SetEnvironmentVariableA("ShlexecVar", "Present");
2781 static void cleanup_test(void)
2783 char filename
[MAX_PATH
];
2784 const char* const * testfile
;
2786 /* Delete the test files */
2790 sprintf(filename
, *testfile
, tmpdir
);
2791 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2792 SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
);
2793 DeleteFileA(filename
);
2796 DeleteFileA(child_file
);
2797 RemoveDirectoryA(tmpdir
);
2799 /* Delete the test association */
2800 delete_test_association(".shlexec");
2802 CloseHandle(hEvent
);
2807 static void test_directory(void)
2809 char path
[MAX_PATH
], curdir
[MAX_PATH
];
2810 char params
[1024], dirpath
[1024];
2813 sprintf(path
, "%s\\test2.exe", tmpdir
);
2814 CopyFileA(argv0
, path
, FALSE
);
2816 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2818 /* Test with the current directory */
2819 GetCurrentDirectoryA(sizeof(curdir
), curdir
);
2820 SetCurrentDirectoryA(tmpdir
);
2821 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2822 NULL
, "test2.exe", params
, NULL
, NULL
);
2823 okShell(rc
> 32, "returned %lu\n", rc
);
2824 okChildInt("argcA", 4);
2825 okChildString("argvA3", "Exec");
2826 todo_wine
okChildPath("longPath", path
);
2827 SetCurrentDirectoryA(curdir
);
2829 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2830 NULL
, "test2.exe", params
, NULL
, NULL
);
2831 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2833 /* Explicitly specify the directory to use */
2834 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2835 NULL
, "test2.exe", params
, tmpdir
, NULL
);
2836 okShell(rc
> 32, "returned %lu\n", rc
);
2837 okChildInt("argcA", 4);
2838 okChildString("argvA3", "Exec");
2839 todo_wine
okChildPath("longPath", path
);
2841 /* Specify it through an environment variable */
2842 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2843 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2844 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2846 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
|SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2847 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2848 okShell(rc
> 32, "returned %lu\n", rc
);
2849 okChildInt("argcA", 4);
2850 okChildString("argvA3", "Exec");
2851 todo_wine
okChildPath("longPath", path
);
2853 /* Not a colon-separated directory list */
2854 sprintf(dirpath
, "%s:%s", curdir
, tmpdir
);
2855 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2856 NULL
, "test2.exe", params
, dirpath
, NULL
);
2857 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2863 myARGC
= winetest_get_mainargs(&myARGV
);
2866 doChild(myARGC
, myARGV
);
2867 /* Skip the tests/failures trace for child processes */
2868 ExitProcess(winetest_get_failures());
2873 test_commandline2argv();
2875 test_lpFile_parsed();
2878 test_find_executable();
2882 test_dde_default_app();