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
, longpath
[MAX_PATH
] = "";
223 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
224 if (hFile
== INVALID_HANDLE_VALUE
)
228 childPrintf(hFile
, "[Arguments]\r\n");
229 if (winetest_debug
> 2)
231 trace("cmdlineA='%s'\n", GetCommandLineA());
232 trace("argcA=%d\n", argc
);
234 childPrintf(hFile
, "cmdlineA=%s\r\n", encodeA(GetCommandLineA()));
235 childPrintf(hFile
, "argcA=%d\r\n", argc
);
236 for (i
= 0; i
< argc
; i
++)
238 if (winetest_debug
> 2)
239 trace("argvA%d='%s'\n", i
, argv
[i
]);
240 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
242 GetModuleFileNameA(GetModuleHandleA(NULL
), longpath
, MAX_PATH
);
243 childPrintf(hFile
, "longPath=%s\r\n", encodeA(longpath
));
245 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
248 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
250 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
252 post_quit_on_execute
= TRUE
;
254 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
255 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
256 ok(rc
== DMLERR_NO_ERROR
, "got %d\n", rc
);
257 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
258 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
+ strlen(shared_block
) + 1, CP_WINANSI
);
259 assert(hszApplication
&& hszTopic
);
260 assert(DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
));
262 timer
= SetTimer(NULL
, 0, 2500, childTimeout
);
264 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
266 CloseHandle(dde_ready
);
268 while (GetMessageA(&msg
, NULL
, 0, 0))
269 DispatchMessageA(&msg
);
272 KillTimer(NULL
, timer
);
273 assert(DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
));
274 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
275 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
276 assert(DdeUninitialize(ddeInst
));
280 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
282 CloseHandle(dde_ready
);
285 UnmapViewOfFile(shared_block
);
287 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
292 init_event(filename
);
297 static void dump_child_(const char* file
, int line
)
299 if (winetest_debug
> 1)
305 str
=getChildString("Arguments", "cmdlineA");
306 trace_(file
, line
)("cmdlineA='%s'\n", str
);
307 c
=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file
);
308 trace_(file
, line
)("argcA=%d\n",c
);
311 sprintf(key
, "argvA%d", i
);
312 str
=getChildString("Arguments", key
);
313 trace_(file
, line
)("%s='%s'\n", key
, str
);
321 * Helpers to check the ShellExecute() / child process results.
325 static char shell_call
[2048];
326 static char assoc_desc
[2048];
327 static int shell_call_traced
;
328 static void WINETEST_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
332 /* Note: if winetest_debug > 1 the ShellExecute() command has already been
335 if (!condition
&& winetest_debug
<= 1 && !shell_call_traced
)
337 printf("Called %s\n", shell_call
);
339 printf("%s\n", assoc_desc
);
343 va_start(valist
, msg
);
344 winetest_vok(condition
, msg
, valist
);
347 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
348 #define okShell okShell_(__FILE__, __LINE__)
350 void reset_association_description(void)
355 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
358 result
=getChildString("Arguments", key
);
361 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
364 okShell_(file
, line
)(lstrcmpiA(result
, expected
) == 0 ||
365 broken(lstrcmpiA(result
, bad
) == 0),
366 "%s expected '%s', got '%s'\n", key
, expected
, result
);
368 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
369 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
371 static int StrCmpPath(const char* s1
, const char* s2
)
373 if (!s1
&& !s2
) return 0;
384 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
386 while (*s1
=='/' || *s1
=='\\')
388 while (*s2
=='/' || *s2
=='\\')
391 else if (toupper(*s1
)==toupper(*s2
))
408 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
411 result
=getChildString("Arguments", key
);
414 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
417 okShell_(file
,line
)(StrCmpPath(result
, expected
) == 0,
418 "%s expected '%s', got '%s'\n", key
, expected
, result
);
420 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
422 static void okChildInt_(const char* file
, int line
, const char* key
, int expected
)
425 result
=GetPrivateProfileIntA("Arguments", key
, expected
, child_file
);
426 okShell_(file
,line
)(result
== expected
,
427 "%s expected %d, but got %d\n", key
, expected
, result
);
429 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
431 static void okChildIntBroken_(const char* file
, int line
, const char* key
, int expected
)
434 result
=GetPrivateProfileIntA("Arguments", key
, expected
, child_file
);
435 okShell_(file
,line
)(result
== expected
|| broken(result
!= expected
),
436 "%s expected %d, but got %d\n", key
, expected
, result
);
438 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
443 * ShellExecute wrappers
447 static void strcat_param(char* str
, const char* name
, const char* param
)
451 if (str
[strlen(str
)-1] == '"')
460 static int _todo_wait
= 0;
461 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
463 static int bad_shellexecute
= 0;
465 static INT_PTR
shell_execute_(const char* file
, int line
, LPCSTR verb
, LPCSTR filename
, LPCSTR parameters
, LPCSTR directory
)
467 INT_PTR rc
, rcEmpty
= 0;
470 rcEmpty
= shell_execute_(file
, line
, "", filename
, parameters
, directory
);
473 strcpy(shell_call
, "ShellExecute(");
474 strcat_param(shell_call
, "verb", verb
);
475 strcat_param(shell_call
, "file", filename
);
476 strcat_param(shell_call
, "params", parameters
);
477 strcat_param(shell_call
, "dir", directory
);
478 strcat(shell_call
, ")");
479 if (winetest_debug
> 1)
481 trace_(file
, line
)("Called %s\n", shell_call
);
483 trace_(file
, line
)("%s\n", assoc_desc
);
487 DeleteFileA(child_file
);
488 SetLastError(0xcafebabe);
490 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
491 * association it displays the 'Open With' dialog and I could not find
492 * a flag to prevent this.
494 rc
=(INT_PTR
)ShellExecuteA(NULL
, verb
, filename
, parameters
, directory
, SW_HIDE
);
499 wait_rc
=WaitForSingleObject(hEvent
, 5000);
500 if (wait_rc
== WAIT_TIMEOUT
)
502 HWND wnd
= FindWindowA("#32770", "Windows");
504 wnd
= FindWindowA("Shell_Flyout", "");
507 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
508 win_skip("Skipping shellexecute of file with unassociated extension\n");
509 skip_noassoc_tests
= TRUE
;
514 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
515 "WaitForSingleObject returned %d\n", wait_rc
);
517 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
518 "WaitForSingleObject returned %d\n", wait_rc
);
520 /* The child process may have changed the result file, so let profile
521 * functions know about it
523 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
525 dump_child_(file
, line
);
529 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
530 bad_shellexecute
= 1;
531 okShell_(file
, line
)(rc
== rcEmpty
||
532 broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
533 "Got different return value with empty string: %lu %lu\n", rc
, rcEmpty
);
538 #define shell_execute(verb, filename, parameters, directory) \
539 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
541 static INT_PTR
shell_execute_ex_(const char* file
, int line
,
542 DWORD mask
, LPCSTR verb
, LPCSTR filename
,
543 LPCSTR parameters
, LPCSTR directory
,
547 SHELLEXECUTEINFOA sei
;
551 /* Add some flags so we can wait for the child process */
552 mask
|= SEE_MASK_NOCLOSEPROCESS
| SEE_MASK_NO_CONSOLE
;
555 strcpy(shell_call
, "ShellExecuteEx(");
556 sprintf(smask
, "0x%x", mask
);
557 strcat_param(shell_call
, "mask", smask
);
558 strcat_param(shell_call
, "verb", verb
);
559 strcat_param(shell_call
, "file", filename
);
560 strcat_param(shell_call
, "params", parameters
);
561 strcat_param(shell_call
, "dir", directory
);
562 strcat_param(shell_call
, "class", class);
563 strcat(shell_call
, ")");
564 if (winetest_debug
> 1)
566 trace_(file
, line
)("Called %s\n", shell_call
);
568 trace_(file
, line
)("%s\n", assoc_desc
);
572 sei
.cbSize
=sizeof(sei
);
577 sei
.lpParameters
=parameters
;
578 sei
.lpDirectory
=directory
;
579 sei
.nShow
=SW_SHOWNORMAL
;
580 sei
.hInstApp
=NULL
; /* Out */
586 sei
.hProcess
=(HANDLE
)0xdeadbeef; /* Out */
588 DeleteFileA(child_file
);
589 SetLastError(0xcafebabe);
590 success
=ShellExecuteExA(&sei
);
591 rc
=(INT_PTR
)sei
.hInstApp
;
592 okShell_(file
, line
)((success
&& rc
> 32) || (!success
&& rc
<= 32),
593 "rc=%d and hInstApp=%ld is not allowed\n",
599 if (sei
.hProcess
!=NULL
)
601 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
602 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
603 "WaitForSingleObject(hProcess) returned %d\n",
605 wait_rc
= GetExitCodeProcess(sei
.hProcess
, &rc
);
606 okShell_(file
, line
)(wait_rc
, "GetExitCodeProcess() failed le=%u\n", GetLastError());
608 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
610 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
611 CloseHandle(sei
.hProcess
);
613 wait_rc
=WaitForSingleObject(hEvent
, 5000);
615 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
616 "WaitForSingleObject returned %d\n", wait_rc
);
618 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
619 "WaitForSingleObject returned %d\n", wait_rc
);
622 okShell_(file
, line
)(sei
.hProcess
==NULL
,
623 "returned a process handle %p\n", sei
.hProcess
);
625 /* The child process may have changed the result file, so let profile
626 * functions know about it
628 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
630 dump_child_(file
, line
);
634 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
635 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
640 * Functions to create / delete associations wrappers
644 static BOOL
create_test_association(const char* extension
)
646 HKEY hkey
, hkey_shell
;
647 char class[MAX_PATH
];
650 sprintf(class, "shlexec%s", extension
);
651 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
653 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
654 "could not create association %s (rc=%d)\n", class, rc
);
655 if (rc
!= ERROR_SUCCESS
)
658 rc
=RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
659 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
662 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
663 KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkey
, NULL
);
664 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
666 rc
=RegCreateKeyExA(hkey
, "shell", 0, NULL
, 0,
667 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
668 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
671 CloseHandle(hkey_shell
);
676 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
677 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
680 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
681 DWORD dwMaxLen
, dwSize
;
682 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
687 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
691 /* Get highest length for keys, values */
692 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
693 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
694 if (ret
) goto cleanup
;
698 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
699 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
701 /* Name too big: alloc a buffer for it */
702 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
704 ret
= ERROR_NOT_ENOUGH_MEMORY
;
710 /* Recursively delete all the subkeys */
714 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
715 NULL
, NULL
, NULL
)) break;
717 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
718 if (ret
) goto cleanup
;
722 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
727 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
728 NULL
, NULL
, NULL
, NULL
)) break;
730 ret
= RegDeleteValueA(hKey
, lpszName
);
731 if (ret
) goto cleanup
;
735 /* Free buffer if allocated */
736 if (lpszName
!= szNameBuf
)
737 HeapFree( GetProcessHeap(), 0, lpszName
);
739 RegCloseKey(hSubKey
);
743 static void delete_test_association(const char* extension
)
745 char class[MAX_PATH
];
747 sprintf(class, "shlexec%s", extension
);
748 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, class);
749 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
752 static void create_test_verb_dde(const char* extension
, const char* verb
,
753 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
754 const char *application
, const char *topic
,
757 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
758 char shell
[MAX_PATH
];
762 strcpy(assoc_desc
, "Assoc ");
763 strcat_param(assoc_desc
, "ext", extension
);
764 strcat_param(assoc_desc
, "verb", verb
);
765 sprintf(shell
, "%d", rawcmd
);
766 strcat_param(assoc_desc
, "rawcmd", shell
);
767 strcat_param(assoc_desc
, "cmdtail", cmdtail
);
768 strcat_param(assoc_desc
, "ddeexec", ddeexec
);
769 strcat_param(assoc_desc
, "app", application
);
770 strcat_param(assoc_desc
, "topic", topic
);
771 strcat_param(assoc_desc
, "ifexec", ifexec
);
773 sprintf(shell
, "shlexec%s\\shell", extension
);
774 rc
=RegOpenKeyExA(HKEY_CLASSES_ROOT
, shell
, 0,
775 KEY_CREATE_SUB_KEY
, &hkey_shell
);
776 ok(rc
== ERROR_SUCCESS
, "%s key creation failed with %d\n", shell
, rc
);
778 rc
=RegCreateKeyExA(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
779 NULL
, &hkey_verb
, NULL
);
780 ok(rc
== ERROR_SUCCESS
, "%s verb key creation failed with %d\n", verb
, rc
);
782 rc
=RegCreateKeyExA(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
783 NULL
, &hkey_cmd
, NULL
);
784 ok(rc
== ERROR_SUCCESS
, "\'command\' key creation failed with %d\n", rc
);
788 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
792 cmd
=HeapAlloc(GetProcessHeap(), 0, strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
793 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
794 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
795 ok(rc
== ERROR_SUCCESS
, "setting command failed with %d\n", rc
);
796 HeapFree(GetProcessHeap(), 0, cmd
);
801 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
803 rc
=RegCreateKeyExA(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
804 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
805 ok(rc
== ERROR_SUCCESS
, "\'ddeexec\' key creation failed with %d\n", rc
);
806 rc
=RegSetValueExA(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
808 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
812 rc
=RegCreateKeyExA(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
813 NULL
, &hkey_application
, NULL
);
814 ok(rc
== ERROR_SUCCESS
, "\'application\' key creation failed with %d\n", rc
);
816 rc
=RegSetValueExA(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
817 strlen(application
)+1);
818 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
819 CloseHandle(hkey_application
);
823 rc
=RegCreateKeyExA(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
824 NULL
, &hkey_topic
, NULL
);
825 ok(rc
== ERROR_SUCCESS
, "\'topic\' key creation failed with %d\n", rc
);
826 rc
=RegSetValueExA(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
828 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
829 CloseHandle(hkey_topic
);
833 rc
=RegCreateKeyExA(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
834 NULL
, &hkey_ifexec
, NULL
);
835 ok(rc
== ERROR_SUCCESS
, "\'ifexec\' key creation failed with %d\n", rc
);
836 rc
=RegSetValueExA(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
838 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
839 CloseHandle(hkey_ifexec
);
841 CloseHandle(hkey_ddeexec
);
844 CloseHandle(hkey_shell
);
845 CloseHandle(hkey_verb
);
846 CloseHandle(hkey_cmd
);
849 /* Creates a class' non-DDE test verb.
850 * This function is meant to be used to create long term test verbs and thus
851 * does not trace them.
853 static void create_test_verb(const char* extension
, const char* verb
,
854 int rawcmd
, const char* cmdtail
)
856 create_test_verb_dde(extension
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
858 reset_association_description();
864 * GetLongPathNameA equivalent that supports Win95 and WinNT
868 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
870 char tmplongpath
[MAX_PATH
];
872 DWORD sp
= 0, lp
= 0;
874 WIN32_FIND_DATAA wfd
;
877 if (!shortpath
|| !shortpath
[0])
880 if (shortpath
[1] == ':')
882 tmplongpath
[0] = shortpath
[0];
883 tmplongpath
[1] = ':';
887 while (shortpath
[sp
])
889 /* check for path delimiters and reproduce them */
890 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
892 if (!lp
|| tmplongpath
[lp
-1] != '\\')
894 /* strip double "\\" */
895 tmplongpath
[lp
++] = '\\';
897 tmplongpath
[lp
] = 0; /* terminate string */
903 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
905 tmplongpath
[lp
++] = *p
++;
906 tmplongpath
[lp
++] = *p
++;
908 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
909 tmplen
= p
- (shortpath
+ sp
);
910 lstrcpynA(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
911 /* Check if the file exists and use the existing file name */
912 goit
= FindFirstFileA(tmplongpath
, &wfd
);
913 if (goit
== INVALID_HANDLE_VALUE
)
916 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
917 lp
+= strlen(tmplongpath
+ lp
);
920 tmplen
= strlen(shortpath
) - 1;
921 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
922 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
923 tmplongpath
[lp
++] = shortpath
[tmplen
];
926 tmplen
= strlen(tmplongpath
) + 1;
927 if (tmplen
<= longlen
)
929 strcpy(longpath
, tmplongpath
);
930 tmplen
--; /* length without 0 */
943 static const char* testfiles
[]=
945 "%s\\test file.shlexec",
946 "%s\\%%nasty%% $file.shlexec",
947 "%s\\test file.noassoc",
948 "%s\\test file.noassoc.shlexec",
949 "%s\\test file.shlexec.noassoc",
950 "%s\\test_shortcut_shlexec.lnk",
951 "%s\\test_shortcut_exe.lnk",
953 "%s\\test file.shlfoo",
955 "%s\\masked file.shlexec",
960 "%s\\simple.shlexec",
961 "%s\\drawback_file.noassoc",
962 "%s\\drawback_file.noassoc foo.shlexec",
963 "%s\\drawback_nonexist.noassoc foo.shlexec",
970 const char* basename
;
975 static filename_tests_t filename_tests
[]=
977 /* Test bad / nonexistent filenames */
978 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
979 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
982 {NULL
, "%s\\test file.shlexec", 0x0, 33},
983 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
984 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
985 {NULL
, "%s/test file.shlexec", 0x0, 33},
987 /* Test filenames with no association */
988 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
990 /* Test double extensions */
991 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
992 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
994 /* Test alternate verbs */
995 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
996 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
998 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
999 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1001 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC
},
1003 /* Test file masked due to space */
1004 {NULL
, "%s\\masked file.shlexec", 0x0, 33},
1005 /* Test if quoting prevents the masking */
1006 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
1007 /* Test with incorrect quote */
1008 {NULL
, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF
},
1013 static filename_tests_t noquotes_tests
[]=
1015 /* Test unquoted '%1' thingies */
1016 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1017 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1018 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1023 static void test_lpFile_parsed(void)
1025 char fileA
[MAX_PATH
];
1028 if (skip_shlexec_tests
)
1030 skip("No filename parsing tests due to lack of .shlexec association\n");
1034 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1035 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
1036 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1037 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1039 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1040 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
1041 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1042 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1043 "failed: rc=%lu\n", rc
);
1045 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1046 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
1047 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1048 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1050 /* ""command"" not works on wine (and real win9x and w2k) */
1051 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
1052 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1053 todo_wine
okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
1054 "failed: rc=%lu\n", rc
);
1056 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
1057 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
1058 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1059 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1061 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1062 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
1063 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1066 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
1067 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1069 /* test SEE_MASK_DOENVSUBST works */
1070 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1071 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
1072 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1074 /* quoted lpFile does not work on real win95 and nt4 */
1075 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1076 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
1077 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1078 "failed: rc=%lu\n", rc
);
1084 const char* args
[11];
1088 static const cmdline_tests_t cmdline_tests
[] =
1093 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1094 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
1096 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1097 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
1099 {"exe arg\"one\" \"second\"arg thirdarg ",
1100 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
1102 /* Don't lose unclosed quoted arguments */
1103 {"exe arg1 \"unclosed",
1104 {"exe", "arg1", "unclosed", NULL
}, 0},
1107 {"exe", "arg1", "", NULL
}, 0},
1109 /* cmd's metacharacters have no special meaning */
1110 {"exe \"one^\" \"arg\"&two three|four",
1111 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
1113 /* Environment variables are not interpreted either */
1115 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
1117 /* If not followed by a quote, backslashes go through as is */
1118 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1119 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1121 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1122 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1124 /* When followed by a quote their number is halved and the remainder
1127 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1128 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1130 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1131 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1133 /* One can put a quote in an unquoted string by tripling it, that is in
1134 * effect quoting it like so """ -> ". The general rule is as follows:
1135 * 3n quotes -> n quotes
1136 * 3n+1 quotes -> n quotes plus start of a quoted string
1137 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1138 * Nicely, when n is 0 we get the standard rules back.
1140 {"exe two\"\"quotes next",
1141 {"exe", "twoquotes", "next", NULL
}, 0},
1143 {"exe three\"\"\"quotes next",
1144 {"exe", "three\"quotes", "next", NULL
}, 0},
1146 {"exe four\"\"\"\" quotes\" next 4%3=1",
1147 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0},
1149 {"exe five\"\"\"\"\"quotes next",
1150 {"exe", "five\"quotes", "next", NULL
}, 0},
1152 {"exe six\"\"\"\"\"\"quotes next",
1153 {"exe", "six\"\"quotes", "next", NULL
}, 0},
1155 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1156 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0},
1158 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1159 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0},
1161 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1162 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1164 /* Inside a quoted string the opening quote is added to the set of
1165 * consecutive quotes to get the effective quotes count. This gives:
1166 * 1+3n quotes -> n quotes
1167 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1168 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1170 {"exe \"two\"\"quotes next",
1171 {"exe", "two\"quotes", "next", NULL
}, 0},
1173 {"exe \"two\"\" next",
1174 {"exe", "two\"", "next", NULL
}, 0},
1176 {"exe \"three\"\"\" quotes\" next 4%3=1",
1177 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0},
1179 {"exe \"four\"\"\"\"quotes next",
1180 {"exe", "four\"quotes", "next", NULL
}, 0},
1182 {"exe \"five\"\"\"\"\"quotes next",
1183 {"exe", "five\"\"quotes", "next", NULL
}, 0},
1185 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1186 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0},
1188 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1189 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0},
1191 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1192 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1194 /* Escaped consecutive quotes are fun */
1195 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1196 {"exe", "the crazy \\\"\\", "quotes", NULL
}, 0},
1198 /* The executable path has its own rules!!!
1199 * - Backslashes have no special meaning.
1200 * - If the first character is a quote, then the second quote ends the
1202 * - The previous rule holds even if the next character is not a space!
1203 * - If the first character is not a quote, then quotes have no special
1204 * meaning either and the executable path stops at the first space.
1205 * - The consecutive quotes rules don't apply either.
1206 * - Even if there is no space between the executable path and the first
1207 * argument, the latter is parsed using the regular rules.
1209 {"exe\"file\"path arg1",
1210 {"exe\"file\"path", "arg1", NULL
}, 0},
1212 {"exe\"file\"path\targ1",
1213 {"exe\"file\"path", "arg1", NULL
}, 0},
1215 {"exe\"path\\ arg1",
1216 {"exe\"path\\", "arg1", NULL
}, 0},
1218 {"\\\"exe \"arg one\"",
1219 {"\\\"exe", "arg one", NULL
}, 0},
1221 {"\"spaced exe\" \"next arg\"",
1222 {"spaced exe", "next arg", NULL
}, 0},
1224 {"\"spaced exe\"\t\"next arg\"",
1225 {"spaced exe", "next arg", NULL
}, 0},
1227 {"\"exe\"arg\" one\" argtwo",
1228 {"exe", "arg one", "argtwo", NULL
}, 0},
1230 {"\"spaced exe\\\"arg1 arg2",
1231 {"spaced exe\\", "arg1", "arg2", NULL
}, 0},
1234 {"two", " arg1 ", NULL
}, 0},
1236 {"\"three\"\"\" arg2",
1237 {"three", "", "arg2", NULL
}, 0},
1239 {"\"four\"\"\"\"arg1",
1240 {"four", "\"arg1", NULL
}, 0},
1242 /* If the first character is a space then the executable path is empty */
1243 {" \"arg\"one argtwo",
1244 {"", "argone", "argtwo", NULL
}, 0},
1249 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1251 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1257 /* trace("----- cmd='%s'\n", test->cmd); */
1258 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, sizeof(cmdW
)/sizeof(*cmdW
));
1259 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1260 if (argsW
== NULL
&& cl2a_count
== -1)
1262 win_skip("CommandLineToArgvW not implemented, skipping\n");
1265 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1266 "expected NULL-terminated list of commandline arguments\n");
1269 while (test
->args
[count
])
1271 if ((test
->todo
& 0x1) == 0)
1272 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1274 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1276 for (i
= 0; i
< cl2a_count
; i
++)
1280 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, sizeof(argW
)/sizeof(*argW
));
1281 if ((test
->todo
& (1 << (i
+4))) == 0)
1282 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1284 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1286 else if ((test
->todo
& 0x1) == 0)
1287 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1289 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1296 static void test_commandline2argv(void)
1298 static const WCHAR exeW
[] = {'e','x','e',0};
1299 const cmdline_tests_t
* test
;
1300 WCHAR strW
[MAX_PATH
];
1305 test
= cmdline_tests
;
1308 if (!test_one_cmdline(test
))
1313 SetLastError(0xdeadbeef);
1314 args
= CommandLineToArgvW(exeW
, NULL
);
1315 le
= GetLastError();
1316 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1318 SetLastError(0xdeadbeef);
1319 args
= CommandLineToArgvW(NULL
, NULL
);
1320 le
= GetLastError();
1321 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1324 args
= CommandLineToArgvW(strW
, &numargs
);
1325 ok(numargs
== 1 || broken(numargs
> 1), "expected 1 args, got %d\n", numargs
);
1326 ok(!args
|| (!args
[numargs
] || broken(args
[numargs
] != NULL
) /* before Vista */),
1327 "expected NULL-terminated list of commandline arguments\n");
1330 GetModuleFileNameW(NULL
, strW
, sizeof(strW
)/sizeof(*strW
));
1331 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
));
1333 if (args
) LocalFree(args
);
1336 /* The goal here is to analyze how ShellExecute() builds the command that
1337 * will be run. The tricky part is that there are three transformation
1338 * steps between the 'parameters' string we pass to ShellExecute() and the
1339 * argument list we observe in the child process:
1340 * - The parsing of 'parameters' string into individual arguments. The tests
1341 * show this is done differently from both CreateProcess() and
1342 * CommandLineToArgv()!
1343 * - The way the command 'formatting directives' such as %1, %2, etc are
1345 * - And the way the resulting command line is then parsed to yield the
1346 * argument list we check.
1353 cmdline_tests_t cmd
;
1354 cmdline_tests_t broken
;
1357 static const argify_tests_t argify_tests
[] =
1359 /* Start with three simple parameters. Notice that one can reorder and
1360 * duplicate the parameters. Also notice how %* take the raw input
1361 * parameters string, including the trailing spaces, no matter what
1362 * arguments have already been used.
1364 {"Params232S", "p2 p3 p4 ", 0xc2,
1365 {" p2 p3 \"p2\" \"p2 p3 p4 \"",
1366 {"", "p2", "p3", "p2", "p2 p3 p4 ", NULL
}, 0}},
1368 /* Unquoted argument references like %2 don't automatically quote their
1369 * argument. Similarly, when they are quoted they don't escape the quotes
1370 * that their argument may contain.
1372 {"Params232S", "\"p two\" p3 p4 ", 0x3f3,
1373 {" p two p3 \"p two\" \"\"p two\" p3 p4 \"",
1374 {"", "p", "two", "p3", "p two", "p", "two p3 p4 ", NULL
}, 0}},
1376 /* Only single digits are supported so only %1 to %9. Shown here with %20
1377 * because %10 is a pain.
1379 {"Params20", "p", 0,
1381 {"", "p0", NULL
}, 0}},
1383 /* Only (double-)quotes have a special meaning. */
1384 {"Params23456", "'p2 p3` p4\\ $even", 0x40,
1385 {" \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\"",
1386 {"", "'p2", "p3`", "p4\" $even \"", NULL
}, 0}},
1388 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", 0x1c2,
1389 {" \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\"",
1390 {"", "p=2", "p-3", "p4\tp4\rp4\np4", "", "", NULL
}, 0}},
1392 /* In unquoted strings, quotes are treated are a parameter separator just
1393 * like spaces! However they can be doubled to get a literal quote.
1395 * 2n quotes -> n quotes
1396 * 2n+1 quotes -> n quotes and a parameter separator
1398 {"Params23456789", "one\"quote \"p four\" one\"quote p7", 0xff3,
1399 {" \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\"",
1400 {"", "one", "quote", "p four", "one", "quote", "p7", "", "", NULL
}, 0}},
1402 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", 0xf2,
1403 {" \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1404 {"", "twoquotes p", "three twoquotes", "p5", "", "", "", "", NULL
}, 0}},
1406 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", 0xff3,
1407 {" \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\"",
1408 {"", "three\"", "quotes", "p four", "three\"", "quotes", "p6", "", "", NULL
}, 0}},
1410 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", 0xf3,
1411 {" \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1412 {"", "four\"quotes p", "three fourquotes p5 \"", "", "", "", NULL
}, 0}},
1414 /* Quoted strings cannot be continued by tacking on a non space character
1417 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", 0x1f3,
1418 {" \"p two\" \"p3\" \"p four\" \"p5\" \"p6\"",
1419 {"", "p two", "p3", "p four", "p5", "p6", NULL
}, 0}},
1421 /* In quoted strings, the quotes are halved and an odd number closes the
1422 * string. Specifically:
1423 * 2n quotes -> n quotes
1424 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1426 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", 0xff3,
1427 {" \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\"",
1428 {"", "one q", "uote", "p four", "one q", "uote", "p7", "", "", NULL
}, 0}},
1430 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", 0x1ff3,
1431 {" \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1432 {"", "two ", "quotes p", "three two", " quotes", "p5", "", "", "", "", NULL
}, 0}},
1434 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", 0xff3,
1435 {" \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\"",
1436 {"", "three q\"", "uotes", "p four", "three q\"", "uotes", "p7", "", "", NULL
}, 0}},
1438 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", 0xff3,
1439 {" \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1440 {"", "four \"", "quotes p", "three four", "", "quotes p5 \"", "", "", "", NULL
}, 0}},
1442 /* The quoted string rules also apply to consecutive quotes at the start
1443 * of a parameter but don't count the opening quote!
1445 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", 0xbf3,
1446 {" \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\"",
1447 {"", "", "twoquotes", "p four", "", "twoquotes", "p7", "", "", NULL
}, 0}},
1449 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", 0x6f3,
1450 {" \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1451 {"", "three", "quotes p", "three \"three", "quotes p5 \"", "", "", "", NULL
}, 0}},
1453 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", 0xbf3,
1454 {" \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\"",
1455 {"", "\"", "fourquotes", "p four", "\"", "fourquotes", "p7", "", "", NULL
}, 0}},
1457 /* An unclosed quoted string gets lost! */
1458 {"Params23456", "p2 \"p3\" \"p4 is lost", 0x1c3,
1459 {" \"p2\" \"p3\" \"\" \"\" \"\"",
1460 {"", "p2", "p3", "", "", "", NULL
}, 0},
1461 {" \"p2\" \"p3\" \"p3\" \"\" \"\"",
1462 {"", "p2", "p3", "p3", "", "", NULL
}, 0}},
1464 /* Backslashes have no special meaning even when preceding quotes. All
1465 * they do is start an unquoted string.
1467 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", 0x73,
1468 {" \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\"",
1469 {"", "\" p\\three pfour\"", "pfive", "", NULL
}, 0}},
1471 /* Environment variables are left untouched. */
1472 {"Params23456", "%TMPDIR% %t %c", 0,
1473 {" \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\"",
1474 {"", "%TMPDIR%", "%t", "%c", "", "", NULL
}, 0}},
1476 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1477 * before the parameter!
1478 * (but not the previous parameter's closing quote fortunately)
1480 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", 0x3f3,
1481 {" ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 ",
1482 {"", "~2=p2 p3 p4 p5 p6 ", "~3= p3 p4 p5 p6 ", "~4= p4 p5 p6 ", "~5=", "p5", "p6", NULL
}, 0}},
1484 /* %~n works even if there is no nth parameter. */
1485 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", 0x12,
1487 {"", "~9= ", NULL
}, 0}},
1489 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", 0x12,
1491 {"", "~9=", NULL
}, 0}},
1493 /* The %~n directives also transmit the tenth parameter and beyond. */
1494 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", 0x12,
1495 {" ~9=\" p9 p10 p11 and beyond!\"",
1496 {"", "~9= p9 p10 p11 and beyond!", NULL
}, 0}},
1498 /* Bad formatting directives lose their % sign, except those followed by
1499 * a tilde! Environment variables are not expanded but lose their % sign.
1501 {"ParamsBad", "p2 p3 p4 p5", 0x12,
1502 {" \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\"",
1503 {"", "% - %~ %~0 %~1 %~a %~* a b c TMPDIR", NULL
}, 0}},
1505 {NULL
, NULL
, 0, {NULL
, {NULL
}, 0}}
1508 static void test_argify(void)
1510 BOOL has_cl2a
= TRUE
;
1511 char fileA
[MAX_PATH
], params
[2*MAX_PATH
+12];
1513 const argify_tests_t
* test
;
1514 const cmdline_tests_t
*bad
;
1518 if (skip_shlexec_tests
)
1520 skip("No argify tests due to lack of .shlexec association\n");
1524 create_test_verb(".shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1525 create_test_verb(".shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1526 create_test_verb(".shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1527 create_test_verb(".shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1528 create_test_verb(".shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1529 create_test_verb(".shlexec", "Params20", 0, "Params20 \"%20\"");
1530 create_test_verb(".shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1532 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1534 test
= argify_tests
;
1535 while (test
->params
)
1537 bad
= test
->broken
.cmd
? &test
->broken
: &test
->cmd
;
1539 /* trace("***** verb='%s' params='%s'\n", test->verb, test->params); */
1540 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
, test
->verb
, fileA
, test
->params
, NULL
, NULL
);
1541 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1544 while (test
->cmd
.args
[count
])
1546 if ((test
->todo
& 0x1) == 0)
1547 /* +4 for the shlexec arguments, -1 because of the added ""
1548 * argument for the CommandLineToArgvW() tests.
1550 okChildInt("argcA", 4 + count
- 1);
1552 okChildInt("argcA", 4 + count
- 1);
1554 cmd
= getChildString("Arguments", "cmdlineA");
1555 /* Our commands are such that the verb immediately precedes the
1556 * part we are interested in.
1558 if (cmd
) cmd
= strstr(cmd
, test
->verb
);
1559 if (cmd
) cmd
+= strlen(test
->verb
);
1560 if (!cmd
) cmd
= "(null)";
1561 if ((test
->todo
& 0x2) == 0)
1562 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1563 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
1565 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1566 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
1568 for (i
= 0; i
< count
- 1; i
++)
1571 sprintf(argname
, "argvA%d", 4 + i
);
1572 if ((test
->todo
& (1 << (i
+4))) == 0)
1573 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1575 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1579 has_cl2a
= test_one_cmdline(&(test
->cmd
));
1583 /* Test with a long parameter */
1584 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1585 fileA
[rc
] = 'a' + rc
% 26;
1586 fileA
[MAX_PATH
-1] = '\0';
1587 sprintf(params
, "shlexec \"%s\" %s", child_file
, fileA
);
1589 /* We need NOZONECHECKS on Win2003 to block a dialog */
1590 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
, NULL
, NULL
);
1591 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1592 okChildInt("argcA", 4);
1593 okChildPath("argvA3", fileA
);
1596 static void test_filename(void)
1598 char filename
[MAX_PATH
];
1599 const filename_tests_t
* test
;
1603 if (skip_shlexec_tests
)
1605 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1609 test
=filename_tests
;
1610 while (test
->basename
)
1612 BOOL quotedfile
= FALSE
;
1614 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1616 win_skip("Skipping shellexecute of file with unassociated extension\n");
1621 sprintf(filename
, test
->basename
, tmpdir
);
1622 if (strchr(filename
, '/'))
1632 if ((test
->todo
& 0x40)==0)
1634 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1638 char quoted
[MAX_PATH
+ 2];
1641 sprintf(quoted
, "\"%s\"", filename
);
1642 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1646 okShell(rc
==test
->rc
||
1647 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1648 "failed: rc=%ld err=%u\n", rc
, GetLastError());
1652 if ((test
->todo
& 0x2)==0)
1654 okChildInt("argcA", 5);
1658 okChildInt("argcA", 5);
1660 verb
=(test
->verb
? test
->verb
: "Open");
1661 if ((test
->todo
& 0x4)==0)
1663 okChildString("argvA3", verb
);
1667 okChildString("argvA3", verb
);
1669 if ((test
->todo
& 0x8)==0)
1671 okChildPath("argvA4", filename
);
1675 okChildPath("argvA4", filename
);
1681 test
=noquotes_tests
;
1682 while (test
->basename
)
1684 sprintf(filename
, test
->basename
, tmpdir
);
1685 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1688 if ((test
->todo
& 0x1)==0)
1690 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1694 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1702 verb
=(test
->verb
? test
->verb
: "Open");
1703 if ((test
->todo
& 0x4)==0)
1705 okChildString("argvA3", verb
);
1709 okChildString("argvA3", verb
);
1718 space
=strchr(str
, ' ');
1721 sprintf(attrib
, "argvA%d", count
);
1722 if ((test
->todo
& 0x8)==0)
1724 okChildPath(attrib
, str
);
1728 okChildPath(attrib
, str
);
1735 if ((test
->todo
& 0x2)==0)
1737 okChildInt("argcA", count
);
1741 okChildInt("argcA", count
);
1747 if (dllver
.dwMajorVersion
!= 0)
1749 /* The more recent versions of shell32.dll accept quoted filenames
1750 * while older ones (e.g. 4.00) don't. Still we want to test this
1751 * because IE 6 depends on the new behavior.
1752 * One day we may need to check the exact version of the dll but for
1753 * now making sure DllGetVersion() is present is sufficient.
1755 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1756 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1757 okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1758 okChildInt("argcA", 5);
1759 okChildString("argvA3", "Open");
1760 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1761 okChildPath("argvA4", filename
);
1767 const char* urlprefix
;
1768 const char* basename
;
1773 #define URL_SUCCESS 0x1
1774 #define USE_COLON 0x2
1775 #define USE_BSLASH 0x4
1777 static fileurl_tests_t fileurl_tests
[]=
1779 /* How many slashes does it take... */
1780 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1781 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1782 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1783 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1784 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1785 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1786 {"file://///", "%s\\test file.shlexec", 0, 0},
1788 /* Test with Windows-style paths */
1789 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0},
1790 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0},
1792 /* Check handling of hostnames */
1793 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1794 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1795 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1796 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1797 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1798 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1800 /* Environment variables are not expanded in URLs */
1801 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1802 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1804 /* Test shortcuts vs. URLs */
1805 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1d},
1810 static void test_fileurls(void)
1812 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1813 char command
[MAX_PATH
];
1814 const fileurl_tests_t
* test
;
1818 if (skip_shlexec_tests
)
1820 skip("No file URL tests due to lack of .shlexec association\n");
1824 rc
= (INT_PTR
)ShellExecuteA(NULL
, NULL
, "file:///nosuchfile.shlexec", NULL
, NULL
, SW_SHOWNORMAL
);
1827 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1831 get_long_path_name(tmpdir
, longtmpdir
, sizeof(longtmpdir
)/sizeof(*longtmpdir
));
1832 SetEnvironmentVariableA("urlprefix", "file:///");
1835 while (test
->basename
)
1837 /* Build the file URL */
1838 sprintf(filename
, test
->basename
, longtmpdir
);
1839 strcpy(fileurl
, test
->urlprefix
);
1840 strcat(fileurl
, filename
);
1841 s
= fileurl
+ strlen(test
->urlprefix
);
1844 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1846 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1851 /* Test it first with FindExecutable() */
1852 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1853 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1855 /* Then ShellExecute() */
1856 if ((test
->todo
& 0x10) == 0)
1857 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1859 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1860 if (bad_shellexecute
)
1862 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1865 if (test
->flags
& URL_SUCCESS
)
1867 if ((test
->todo
& 0x1) == 0)
1868 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1870 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1874 if ((test
->todo
& 0x1) == 0)
1875 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1876 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1877 "failed: bad rc=%lu\n", rc
);
1879 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1880 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1881 "failed: bad rc=%lu\n", rc
);
1885 if ((test
->todo
& 0x2) == 0)
1886 okChildInt("argcA", 5);
1888 okChildInt("argcA", 5);
1890 if ((test
->todo
& 0x4) == 0)
1891 okChildString("argvA3", "Open");
1893 okChildString("argvA3", "Open");
1895 if ((test
->todo
& 0x8) == 0)
1896 okChildPath("argvA4", filename
);
1898 okChildPath("argvA4", filename
);
1903 SetEnvironmentVariableA("urlprefix", NULL
);
1906 static void test_find_executable(void)
1908 char notepad_path
[MAX_PATH
];
1909 char filename
[MAX_PATH
];
1910 char command
[MAX_PATH
];
1911 const filename_tests_t
* test
;
1914 if (!create_test_association(".sfe"))
1916 skip("Unable to create association for '.sfe'\n");
1919 create_test_verb(".sfe", "Open", 1, "%1");
1921 /* Don't test FindExecutable(..., NULL), it always crashes */
1923 strcpy(command
, "your word");
1924 if (0) /* Can crash on Vista! */
1926 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
1927 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1928 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1931 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
1932 strcat( notepad_path
, "\\notepad.exe" );
1934 /* Search for something that should be in the system-wide search path (no default directory) */
1935 strcpy(command
, "your word");
1936 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
1937 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1938 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1940 /* Search for something that should be in the system-wide search path (with default directory) */
1941 strcpy(command
, "your word");
1942 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
1943 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1944 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1946 strcpy(command
, "your word");
1947 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
1948 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1949 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1951 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
1952 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1953 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1954 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1956 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
1957 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1959 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
1960 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1962 delete_test_association(".sfe");
1964 if (!create_test_association(".shl"))
1966 skip("Unable to create association for '.shl'\n");
1969 create_test_verb(".shl", "Open", 0, "Open");
1971 sprintf(filename
, "%s\\test file.shl", tmpdir
);
1972 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1973 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1975 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
1976 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1978 delete_test_association(".shl");
1982 /* On Windows XP and 2003 FindExecutable() is completely broken.
1983 * Probably what it does is convert the filename to 8.3 format,
1984 * which as a side effect converts the '.shlfoo' extension to '.shl',
1985 * and then tries to find an association for '.shl'. This means it
1986 * will normally fail on most extensions with more than 3 characters,
1987 * like '.mpeg', etc.
1988 * Also it means we cannot do any other test.
1990 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
1994 if (skip_shlexec_tests
)
1996 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2000 test
=filename_tests
;
2001 while (test
->basename
)
2003 sprintf(filename
, test
->basename
, tmpdir
);
2004 if (strchr(filename
, '/'))
2015 /* Win98 does not '\0'-terminate command! */
2016 memset(command
, '\0', sizeof(command
));
2017 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2020 if ((test
->todo
& 0x10)==0)
2022 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2026 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2031 equal
=strcmp(command
, argv0
) == 0 ||
2032 /* NT4 returns an extra 0x8 character! */
2033 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
2034 if ((test
->todo
& 0x20)==0)
2036 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2037 filename
, command
, argv0
);
2041 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2042 filename
, command
, argv0
);
2050 static filename_tests_t lnk_tests
[]=
2052 /* Pass bad / nonexistent filenames as a parameter */
2053 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
2054 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
2056 /* Pass regular paths as a parameter */
2057 {NULL
, "%s\\test file.shlexec", 0xa, 33},
2058 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2060 /* Pass filenames with no association as a parameter */
2061 {NULL
, "%s\\test file.noassoc", 0xa, 33},
2066 static void test_lnks(void)
2068 char filename
[MAX_PATH
];
2069 char params
[MAX_PATH
];
2070 const filename_tests_t
* test
;
2073 if (skip_shlexec_tests
)
2074 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2077 /* Should open through our association */
2078 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2079 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2080 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2081 okChildInt("argcA", 5);
2082 okChildString("argvA3", "Open");
2083 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2084 get_long_path_name(params
, filename
, sizeof(filename
));
2085 okChildPath("argvA4", filename
);
2087 todo_wait rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
2088 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2089 okChildInt("argcA", 5);
2090 todo_wine
okChildString("argvA3", "Open");
2091 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2092 get_long_path_name(params
, filename
, sizeof(filename
));
2093 todo_wine
okChildPath("argvA4", filename
);
2096 /* Should just run our executable */
2097 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2098 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2099 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2100 okChildInt("argcA", 4);
2101 okChildString("argvA3", "Lnk");
2103 /* An explicit class overrides lnk's ContextMenuHandler */
2104 rc
=shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
2105 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2106 okChildInt("argcA", 5);
2107 okChildString("argvA3", "Open");
2108 okChildPath("argvA4", filename
);
2110 if (dllver
.dwMajorVersion
>=6)
2113 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2114 * Older versions don't or are quite buggy in this regard.
2116 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2124 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2125 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2126 okChildInt("argcA", 4);
2127 okChildString("argvA3", "Lnk");
2130 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2132 while (test
->basename
)
2135 sprintf(params
+1, test
->basename
, tmpdir
);
2136 strcat(params
,"\"");
2137 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2141 if ((test
->todo
& 0x1)==0)
2143 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2147 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2151 if ((test
->todo
& 0x2)==0)
2153 okChildInt("argcA", 5);
2157 okChildInt("argcA", 5);
2159 if ((test
->todo
& 0x4)==0)
2161 okChildString("argvA3", "Lnk");
2165 okChildString("argvA3", "Lnk");
2167 sprintf(params
, test
->basename
, tmpdir
);
2168 if ((test
->todo
& 0x8)==0)
2170 okChildPath("argvA4", params
);
2174 okChildPath("argvA4", params
);
2182 static void test_exes(void)
2184 char filename
[MAX_PATH
];
2188 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2190 /* We need NOZONECHECKS on Win2003 to block a dialog */
2191 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
2193 okShell(rc
> 32, "returned %lu\n", rc
);
2194 okChildInt("argcA", 4);
2195 okChildString("argvA3", "Exec");
2197 if (! skip_noassoc_tests
)
2199 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
2200 if (CopyFileA(argv0
, filename
, FALSE
))
2202 rc
=shell_execute(NULL
, filename
, params
, NULL
);
2204 okShell(rc
==SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2210 win_skip("Skipping shellexecute of file with unassociated extension\n");
2213 /* test combining executable and parameters */
2214 sprintf(filename
, "%s shlexec \"%s\" Exec", argv0
, child_file
);
2215 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2216 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2218 sprintf(filename
, "\"%s\" shlexec \"%s\" Exec", argv0
, child_file
);
2219 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2220 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2222 /* A verb, even if invalid, overrides the normal handling of executables */
2223 todo_wait rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
,
2224 "notaverb", argv0
, NULL
, NULL
, NULL
);
2225 todo_wine
okShell(rc
== SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2227 /* A class overrides the normal handling of executables too */
2228 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2229 rc
= shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
,
2230 NULL
, argv0
, NULL
, NULL
, ".shlexec");
2231 todo_wine
okShell(rc
> 32, "returned %lu\n", rc
);
2232 okChildInt("argcA", 5);
2233 todo_wine
okChildString("argvA3", "Open");
2234 todo_wine
okChildPath("argvA4", argv0
);
2239 const char* command
;
2240 const char* ddeexec
;
2241 const char* application
;
2245 const char* expectedDdeExec
;
2249 static dde_tests_t dde_tests
[] =
2251 /* Test passing and not passing command-line
2252 * argument, no DDE */
2253 {"", NULL
, NULL
, NULL
, NULL
, 0, ""},
2254 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, 1, ""},
2256 /* Test passing and not passing command-line
2257 * argument, with DDE */
2258 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 0, "[open(\"%s\")]"},
2259 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 1, "[open(\"%s\")]"},
2261 /* Test unquoted %1 in command and ddeexec
2262 * (test filename has space) */
2263 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", TRUE
/* before vista */},
2265 /* Test ifexec precedence over ddeexec */
2266 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2268 /* Test default DDE topic */
2269 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, 0, "[open(\"%s\")]"},
2271 /* Test default DDE application */
2272 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, 0, "[open(\"%s\")]"},
2277 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
2279 if (winetest_debug
> 1)
2280 trace("WaitForInputIdle() waiting for dde event\n");
2281 return WaitForSingleObject(dde_ready_event
, timeout
);
2285 * WaitForInputIdle() will normally return immediately for console apps. That's
2286 * a problem for us because ShellExecute will assume that an app is ready to
2287 * receive DDE messages after it has called WaitForInputIdle() on that app.
2288 * To work around that we install our own version of WaitForInputIdle() that
2289 * will wait for the child to explicitly tell us that it is ready. We do that
2290 * by changing the entry for WaitForInputIdle() in the shell32 import address
2293 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2296 PIMAGE_NT_HEADERS nt_headers
;
2297 DWORD import_directory_rva
;
2298 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2301 base
= (char *) GetModuleHandleA("shell32.dll");
2302 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2303 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2305 /* Search for the correct imported module by walking the import descriptors */
2306 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2307 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2309 char *import_module_name
;
2311 import_module_name
= base
+ import_descriptor
->Name
;
2312 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2313 lstrcmpiA(import_module_name
, "user32") == 0)
2315 PIMAGE_THUNK_DATA int_entry
;
2316 PIMAGE_THUNK_DATA iat_entry
;
2318 /* The import name table and import address table are two parallel
2319 * arrays. We need the import name table to find the imported
2320 * routine and the import address table to patch the address, so
2321 * walk them side by side */
2322 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2323 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2324 while (int_entry
->u1
.Ordinal
!= 0)
2326 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2328 PIMAGE_IMPORT_BY_NAME import_by_name
;
2329 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2330 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2332 /* Found the correct routine in the correct imported module. Patch it. */
2334 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2335 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2336 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2337 if (winetest_debug
> 1)
2338 trace("Hooked %s.WaitForInputIdle\n", import_module_name
);
2349 import_descriptor
++;
2351 ok(hook_count
, "Could not hook WaitForInputIdle()\n");
2354 static void test_dde(void)
2356 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2357 const dde_tests_t
* test
;
2363 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2365 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2367 /* Default service is application name minus path and extension */
2368 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2369 *strchr(defApplication
, '.') = 0;
2371 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2372 4096, "winetest_shlexec_dde_map");
2373 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2376 while (test
->command
)
2378 if (!create_test_association(".sde"))
2380 skip("Unable to create association for '.sde'\n");
2383 create_test_verb_dde(".sde", "Open", 0, test
->command
, test
->ddeexec
,
2384 test
->application
, test
->topic
, test
->ifexec
);
2386 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2388 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2389 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2393 shared_block
[0] = '\0';
2394 shared_block
[1] = '\0';
2398 dde_ready_event
= CreateEventA(NULL
, FALSE
, FALSE
, "winetest_shlexec_dde_ready");
2399 rc
= shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, filename
, NULL
, NULL
, NULL
);
2400 CloseHandle(dde_ready_event
);
2401 okShell(32 < rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2406 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
2408 okChildInt("argcA", test
->expectedArgs
+ 3);
2410 if (test
->expectedArgs
== 1) okChildPath("argvA3", filename
);
2412 sprintf(params
, test
->expectedDdeExec
, filename
);
2413 okChildPath("ddeExec", params
);
2415 reset_association_description();
2417 delete_test_association(".sde");
2421 UnmapViewOfFile(shared_block
);
2423 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2426 #define DDE_DEFAULT_APP_VARIANTS 2
2429 const char* command
;
2430 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2432 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2433 } dde_default_app_tests_t
;
2435 static dde_default_app_tests_t dde_default_app_tests
[] =
2437 /* Windows XP and 98 handle default DDE app names in different ways.
2438 * The application name we see in the first test determines the pattern
2439 * of application names and return codes we will look for. */
2441 /* Test unquoted existing filename with a space */
2442 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
2443 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
2445 /* Test quoted existing filename with a space */
2446 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
2447 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
2449 /* Test unquoted filename with a space that doesn't exist, but
2451 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
2452 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
2454 /* Test quoted filename with a space that does not exist */
2455 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
2456 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
2458 /* Test filename supplied without the extension */
2459 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
2460 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
2462 /* Test an unquoted nonexistent filename */
2463 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
2464 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
2466 /* Test an application that will be found on the path */
2467 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
2468 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
2470 /* Test an application that will not be found on the path */
2471 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2472 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2474 {NULL
, {NULL
}, 0, {0}}
2480 DWORD threadIdParent
;
2481 } dde_thread_info_t
;
2483 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2485 dde_thread_info_t
*info
= arg
;
2486 assert(info
&& info
->filename
);
2487 PostThreadMessageA(info
->threadIdParent
,
2489 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2494 static void test_dde_default_app(void)
2496 char filename
[MAX_PATH
];
2498 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2499 const dde_default_app_tests_t
* test
;
2508 post_quit_on_execute
= FALSE
;
2510 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2511 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
2512 ok(rc
== DMLERR_NO_ERROR
, "got %lx\n", rc
);
2514 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2516 /* It is strictly not necessary to register an application name here, but wine's
2517 * DdeNameService implementation complains if 0 is passed instead of
2518 * hszApplication with DNS_FILTEROFF */
2519 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2520 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2521 ok(hszApplication
&& hszTopic
, "got %p and %p\n", hszApplication
, hszTopic
);
2522 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
2523 ok(ret
!= 0, "got %p\n", ret
);
2525 test
= dde_default_app_tests
;
2526 while (test
->command
)
2530 if (!create_test_association(".sde"))
2532 skip("Unable to create association for '.sde'\n");
2535 sprintf(params
, test
->command
, tmpdir
);
2536 create_test_verb_dde(".sde", "Open", 1, params
, "[test]", NULL
,
2538 ddeApplication
[0] = 0;
2540 /* No application will be run as we will respond to the first DDE event,
2541 * so don't wait for it */
2544 thread
= CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
);
2545 ok(thread
!= NULL
, "got %p\n", thread
);
2546 while (GetMessageA(&msg
, NULL
, 0, 0)) DispatchMessageA(&msg
);
2547 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2549 /* First test, find which set of test data we expect to see */
2550 if (test
== dde_default_app_tests
)
2553 for (i
=0; i
<DDE_DEFAULT_APP_VARIANTS
; i
++)
2555 if (!strcmp(ddeApplication
, test
->expectedDdeApplication
[i
]))
2561 if (i
== DDE_DEFAULT_APP_VARIANTS
)
2562 skip("Default DDE application test does not match any available results, using first expected data set.\n");
2565 if ((test
->todo
& 0x1)==0)
2567 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2568 rc
, GetLastError());
2572 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2573 rc
, GetLastError());
2577 if ((test
->todo
& 0x2)==0)
2579 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2580 "Expected application '%s', got '%s'\n",
2581 test
->expectedDdeApplication
[which
], ddeApplication
);
2585 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2586 "Expected application '%s', got '%s'\n",
2587 test
->expectedDdeApplication
[which
], ddeApplication
);
2590 reset_association_description();
2592 delete_test_association(".sde");
2596 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
2597 ok(ret
!= 0, "got %p\n", ret
);
2598 b
= DdeFreeStringHandle(ddeInst
, hszTopic
);
2599 ok(b
, "got %d\n", b
);
2600 b
= DdeFreeStringHandle(ddeInst
, hszApplication
);
2601 ok(b
, "got %d\n", b
);
2602 b
= DdeUninitialize(ddeInst
);
2603 ok(b
, "got %d\n", b
);
2606 static void init_test(void)
2609 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2610 char filename
[MAX_PATH
];
2611 WCHAR lnkfile
[MAX_PATH
];
2613 const char* const * testfile
;
2618 hdll
=GetModuleHandleA("shell32.dll");
2619 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2622 dllver
.cbSize
=sizeof(dllver
);
2623 pDllGetVersion(&dllver
);
2624 trace("major=%d minor=%d build=%d platform=%d\n",
2625 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2626 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2630 memset(&dllver
, 0, sizeof(dllver
));
2633 r
= CoInitialize(NULL
);
2634 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2638 rc
=GetModuleFileNameA(NULL
, argv0
, sizeof(argv0
));
2639 ok(rc
!= 0 && rc
< sizeof(argv0
), "got %d\n", rc
);
2640 if (GetFileAttributesA(argv0
)==INVALID_FILE_ATTRIBUTES
)
2642 strcat(argv0
, ".so");
2643 ok(GetFileAttributesA(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2644 "unable to find argv0!\n");
2647 /* Older versions (win 2k) fail tests if there is a space in
2649 if (dllver
.dwMajorVersion
<= 5)
2650 strcpy(filename
, "c:\\");
2652 GetTempPathA(sizeof(filename
), filename
);
2653 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2654 GetLongPathNameA(tmpdir
, tmpdir
, sizeof(tmpdir
));
2655 DeleteFileA( tmpdir
);
2656 rc
= CreateDirectoryA( tmpdir
, NULL
);
2657 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2658 /* Set %TMPDIR% for the tests */
2659 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2661 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2662 ok(rc
!= 0, "got %d\n", rc
);
2663 init_event(child_file
);
2665 /* Set up the test files */
2671 sprintf(filename
, *testfile
, tmpdir
);
2672 hfile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2673 FILE_ATTRIBUTE_NORMAL
, NULL
);
2674 if (hfile
==INVALID_HANDLE_VALUE
)
2676 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2683 /* Setup the test shortcuts */
2684 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2685 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2686 desc
.description
=NULL
;
2688 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2691 desc
.arguments
="ignored";
2696 create_lnk(lnkfile
, &desc
, 0);
2698 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2699 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2700 desc
.description
=NULL
;
2704 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2705 desc
.arguments
=params
;
2710 create_lnk(lnkfile
, &desc
, 0);
2712 /* Create a basic association suitable for most tests */
2713 if (!create_test_association(".shlexec"))
2715 skip_shlexec_tests
= TRUE
;
2716 skip("Unable to create association for '.shlexec'\n");
2719 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2720 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2721 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2722 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2723 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2724 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2727 static void cleanup_test(void)
2729 char filename
[MAX_PATH
];
2730 const char* const * testfile
;
2732 /* Delete the test files */
2736 sprintf(filename
, *testfile
, tmpdir
);
2737 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2738 SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
);
2739 DeleteFileA(filename
);
2742 DeleteFileA(child_file
);
2743 RemoveDirectoryA(tmpdir
);
2745 /* Delete the test association */
2746 delete_test_association(".shlexec");
2748 CloseHandle(hEvent
);
2753 static void test_directory(void)
2755 char path
[MAX_PATH
], curdir
[MAX_PATH
];
2756 char params
[1024], dirpath
[1024];
2759 sprintf(path
, "%s\\test2.exe", tmpdir
);
2760 CopyFileA(argv0
, path
, FALSE
);
2762 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2764 /* Test with the current directory */
2765 GetCurrentDirectoryA(sizeof(curdir
), curdir
);
2766 SetCurrentDirectoryA(tmpdir
);
2767 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2768 NULL
, "test2.exe", params
, NULL
, NULL
);
2769 okShell(rc
> 32, "returned %lu\n", rc
);
2770 okChildInt("argcA", 4);
2771 okChildString("argvA3", "Exec");
2772 todo_wine
okChildPath("longPath", path
);
2773 SetCurrentDirectoryA(curdir
);
2775 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2776 NULL
, "test2.exe", params
, NULL
, NULL
);
2777 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2779 /* Explicitly specify the directory to use */
2780 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2781 NULL
, "test2.exe", params
, tmpdir
, NULL
);
2782 okShell(rc
> 32, "returned %lu\n", rc
);
2783 okChildInt("argcA", 4);
2784 okChildString("argvA3", "Exec");
2785 todo_wine
okChildPath("longPath", path
);
2787 /* Specify it through an environment variable */
2788 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2789 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2790 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2792 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
|SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2793 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2794 okShell(rc
> 32, "returned %lu\n", rc
);
2795 okChildInt("argcA", 4);
2796 okChildString("argvA3", "Exec");
2797 todo_wine
okChildPath("longPath", path
);
2799 /* Not a colon-separated directory list */
2800 sprintf(dirpath
, "%s:%s", curdir
, tmpdir
);
2801 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2802 NULL
, "test2.exe", params
, dirpath
, NULL
);
2803 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2809 myARGC
= winetest_get_mainargs(&myARGV
);
2812 doChild(myARGC
, myARGV
);
2818 test_commandline2argv();
2820 test_lpFile_parsed();
2823 test_find_executable();
2827 test_dde_default_app();