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
];
223 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
224 if (hFile
== INVALID_HANDLE_VALUE
)
228 childPrintf(hFile
, "[Child]\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
), buffer
, sizeof(buffer
));
243 childPrintf(hFile
, "longPath=%s\r\n", encodeA(buffer
));
245 /* Check environment variable inheritance */
248 GetEnvironmentVariableA("ShlexecVar", buffer
, sizeof(buffer
));
249 childPrintf(hFile
, "ShlexecVarLE=%d\r\n", GetLastError());
250 childPrintf(hFile
, "ShlexecVar=%s\r\n", encodeA(buffer
));
252 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
255 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
257 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
259 post_quit_on_execute
= TRUE
;
261 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
262 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
263 ok(rc
== DMLERR_NO_ERROR
, "got %d\n", rc
);
264 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
265 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
+ strlen(shared_block
) + 1, CP_WINANSI
);
266 assert(hszApplication
&& hszTopic
);
267 assert(DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
));
269 timer
= SetTimer(NULL
, 0, 2500, childTimeout
);
271 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
273 CloseHandle(dde_ready
);
275 while (GetMessageA(&msg
, NULL
, 0, 0))
276 DispatchMessageA(&msg
);
279 KillTimer(NULL
, timer
);
280 assert(DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
));
281 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
282 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
283 assert(DdeUninitialize(ddeInst
));
287 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
289 CloseHandle(dde_ready
);
292 UnmapViewOfFile(shared_block
);
294 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
297 childPrintf(hFile
, "Failures=%d\r\n", winetest_get_failures());
300 init_event(filename
);
305 static void dump_child_(const char* file
, int line
)
307 if (winetest_debug
> 1)
313 str
=getChildString("Child", "cmdlineA");
314 trace_(file
, line
)("cmdlineA='%s'\n", str
);
315 c
=GetPrivateProfileIntA("Child", "argcA", -1, child_file
);
316 trace_(file
, line
)("argcA=%d\n",c
);
319 sprintf(key
, "argvA%d", i
);
320 str
=getChildString("Child", key
);
321 trace_(file
, line
)("%s='%s'\n", key
, str
);
324 c
=GetPrivateProfileIntA("Child", "ShlexecVarLE", -1, child_file
);
325 trace_(file
, line
)("ShlexecVarLE=%d\n", c
);
326 str
=getChildString("Child", "ShlexecVar");
327 trace_(file
, line
)("ShlexecVar='%s'\n", str
);
329 c
=GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
330 trace_(file
, line
)("Failures=%d\n", c
);
337 * Helpers to check the ShellExecute() / child process results.
341 static char shell_call
[2048];
342 static char assoc_desc
[2048];
343 static int shell_call_traced
;
344 static void WINETEST_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
348 /* Note: if winetest_debug > 1 the ShellExecute() command has already been
351 if (!condition
&& winetest_debug
<= 1 && !shell_call_traced
)
353 printf("Called %s\n", shell_call
);
355 printf("%s\n", assoc_desc
);
359 va_start(valist
, msg
);
360 winetest_vok(condition
, msg
, valist
);
363 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
364 #define okShell okShell_(__FILE__, __LINE__)
366 void reset_association_description(void)
371 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
374 result
=getChildString("Child", key
);
377 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
380 okShell_(file
, line
)(lstrcmpiA(result
, expected
) == 0 ||
381 broken(lstrcmpiA(result
, bad
) == 0),
382 "%s expected '%s', got '%s'\n", key
, expected
, result
);
384 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
385 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
387 static int StrCmpPath(const char* s1
, const char* s2
)
389 if (!s1
&& !s2
) return 0;
400 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
402 while (*s1
=='/' || *s1
=='\\')
404 while (*s2
=='/' || *s2
=='\\')
407 else if (toupper(*s1
)==toupper(*s2
))
424 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
427 result
=getChildString("Child", key
);
430 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
433 okShell_(file
,line
)(StrCmpPath(result
, expected
) == 0,
434 "%s expected '%s', got '%s'\n", key
, expected
, result
);
436 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
438 static void okChildInt_(const char* file
, int line
, const char* key
, int expected
)
441 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
442 okShell_(file
,line
)(result
== expected
,
443 "%s expected %d, but got %d\n", key
, expected
, result
);
445 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
447 static void okChildIntBroken_(const char* file
, int line
, const char* key
, int expected
)
450 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
451 okShell_(file
,line
)(result
== expected
|| broken(result
!= expected
),
452 "%s expected %d, but got %d\n", key
, expected
, result
);
454 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
459 * ShellExecute wrappers
463 static void strcat_param(char* str
, const char* name
, const char* param
)
467 if (str
[strlen(str
)-1] == '"')
476 static int _todo_wait
= 0;
477 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
479 static int bad_shellexecute
= 0;
481 static INT_PTR
shell_execute_(const char* file
, int line
, LPCSTR verb
, LPCSTR filename
, LPCSTR parameters
, LPCSTR directory
)
483 INT_PTR rc
, rcEmpty
= 0;
486 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 if (winetest_debug
> 1)
497 trace_(file
, line
)("Called %s\n", shell_call
);
499 trace_(file
, line
)("%s\n", assoc_desc
);
503 DeleteFileA(child_file
);
504 SetLastError(0xcafebabe);
506 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
507 * association it displays the 'Open With' dialog and I could not find
508 * a flag to prevent this.
510 rc
=(INT_PTR
)ShellExecuteA(NULL
, verb
, filename
, parameters
, directory
, SW_HIDE
);
515 wait_rc
=WaitForSingleObject(hEvent
, 5000);
516 if (wait_rc
== WAIT_TIMEOUT
)
518 HWND wnd
= FindWindowA("#32770", "Windows");
520 wnd
= FindWindowA("Shell_Flyout", "");
523 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
524 win_skip("Skipping shellexecute of file with unassociated extension\n");
525 skip_noassoc_tests
= TRUE
;
530 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
531 "WaitForSingleObject returned %d\n", wait_rc
);
533 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
534 "WaitForSingleObject returned %d\n", wait_rc
);
536 /* The child process may have changed the result file, so let profile
537 * functions know about it
539 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
540 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
543 dump_child_(file
, line
);
544 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
546 winetest_add_failures(c
);
547 okChildInt_(file
, line
, "ShlexecVarLE", 0);
548 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
553 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
554 bad_shellexecute
= 1;
555 okShell_(file
, line
)(rc
== rcEmpty
||
556 broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
557 "Got different return value with empty string: %lu %lu\n", rc
, rcEmpty
);
562 #define shell_execute(verb, filename, parameters, directory) \
563 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
565 static INT_PTR
shell_execute_ex_(const char* file
, int line
,
566 DWORD mask
, LPCSTR verb
, LPCSTR filename
,
567 LPCSTR parameters
, LPCSTR directory
,
571 SHELLEXECUTEINFOA sei
;
575 /* Add some flags so we can wait for the child process */
576 mask
|= SEE_MASK_NOCLOSEPROCESS
| SEE_MASK_NO_CONSOLE
;
579 strcpy(shell_call
, "ShellExecuteEx(");
580 sprintf(smask
, "0x%x", mask
);
581 strcat_param(shell_call
, "mask", smask
);
582 strcat_param(shell_call
, "verb", verb
);
583 strcat_param(shell_call
, "file", filename
);
584 strcat_param(shell_call
, "params", parameters
);
585 strcat_param(shell_call
, "dir", directory
);
586 strcat_param(shell_call
, "class", class);
587 strcat(shell_call
, ")");
588 if (winetest_debug
> 1)
590 trace_(file
, line
)("Called %s\n", shell_call
);
592 trace_(file
, line
)("%s\n", assoc_desc
);
596 sei
.cbSize
=sizeof(sei
);
601 sei
.lpParameters
=parameters
;
602 sei
.lpDirectory
=directory
;
603 sei
.nShow
=SW_SHOWNORMAL
;
604 sei
.hInstApp
=NULL
; /* Out */
610 sei
.hProcess
=(HANDLE
)0xdeadbeef; /* Out */
612 DeleteFileA(child_file
);
613 SetLastError(0xcafebabe);
614 success
=ShellExecuteExA(&sei
);
615 rc
=(INT_PTR
)sei
.hInstApp
;
616 okShell_(file
, line
)((success
&& rc
> 32) || (!success
&& rc
<= 32),
617 "rc=%d and hInstApp=%ld is not allowed\n",
623 if (sei
.hProcess
!=NULL
)
625 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
626 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
627 "WaitForSingleObject(hProcess) returned %d\n",
629 wait_rc
= GetExitCodeProcess(sei
.hProcess
, &rc
);
630 okShell_(file
, line
)(wait_rc
, "GetExitCodeProcess() failed le=%u\n", GetLastError());
632 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
634 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
635 CloseHandle(sei
.hProcess
);
637 wait_rc
=WaitForSingleObject(hEvent
, 5000);
639 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
640 "WaitForSingleObject returned %d\n", wait_rc
);
642 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
643 "WaitForSingleObject returned %d\n", wait_rc
);
646 okShell_(file
, line
)(sei
.hProcess
==NULL
,
647 "returned a process handle %p\n", sei
.hProcess
);
649 /* The child process may have changed the result file, so let profile
650 * functions know about it
652 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
653 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
656 dump_child_(file
, line
);
657 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
659 winetest_add_failures(c
);
660 okChildInt_(file
, line
, "ShlexecVarLE", 0);
661 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
666 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
667 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
672 * Functions to create / delete associations wrappers
676 static BOOL
create_test_association(const char* extension
)
678 HKEY hkey
, hkey_shell
;
679 char class[MAX_PATH
];
682 sprintf(class, "shlexec%s", extension
);
683 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
685 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
686 "could not create association %s (rc=%d)\n", class, rc
);
687 if (rc
!= ERROR_SUCCESS
)
690 rc
=RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
691 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
694 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
695 KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkey
, NULL
);
696 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
698 rc
=RegCreateKeyExA(hkey
, "shell", 0, NULL
, 0,
699 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
700 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
703 CloseHandle(hkey_shell
);
708 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
709 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
712 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
713 DWORD dwMaxLen
, dwSize
;
714 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
719 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
723 /* Get highest length for keys, values */
724 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
725 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
726 if (ret
) goto cleanup
;
730 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
731 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
733 /* Name too big: alloc a buffer for it */
734 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
736 ret
= ERROR_NOT_ENOUGH_MEMORY
;
742 /* Recursively delete all the subkeys */
746 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
747 NULL
, NULL
, NULL
)) break;
749 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
750 if (ret
) goto cleanup
;
754 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
759 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
760 NULL
, NULL
, NULL
, NULL
)) break;
762 ret
= RegDeleteValueA(hKey
, lpszName
);
763 if (ret
) goto cleanup
;
767 /* Free buffer if allocated */
768 if (lpszName
!= szNameBuf
)
769 HeapFree( GetProcessHeap(), 0, lpszName
);
771 RegCloseKey(hSubKey
);
775 static void delete_test_association(const char* extension
)
777 char class[MAX_PATH
];
779 sprintf(class, "shlexec%s", extension
);
780 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, class);
781 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
784 static void create_test_verb_dde(const char* extension
, const char* verb
,
785 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
786 const char *application
, const char *topic
,
789 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
790 char shell
[MAX_PATH
];
794 strcpy(assoc_desc
, "Assoc ");
795 strcat_param(assoc_desc
, "ext", extension
);
796 strcat_param(assoc_desc
, "verb", verb
);
797 sprintf(shell
, "%d", rawcmd
);
798 strcat_param(assoc_desc
, "rawcmd", shell
);
799 strcat_param(assoc_desc
, "cmdtail", cmdtail
);
800 strcat_param(assoc_desc
, "ddeexec", ddeexec
);
801 strcat_param(assoc_desc
, "app", application
);
802 strcat_param(assoc_desc
, "topic", topic
);
803 strcat_param(assoc_desc
, "ifexec", ifexec
);
805 sprintf(shell
, "shlexec%s\\shell", extension
);
806 rc
=RegOpenKeyExA(HKEY_CLASSES_ROOT
, shell
, 0,
807 KEY_CREATE_SUB_KEY
, &hkey_shell
);
808 ok(rc
== ERROR_SUCCESS
, "%s key creation failed with %d\n", shell
, rc
);
810 rc
=RegCreateKeyExA(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
811 NULL
, &hkey_verb
, NULL
);
812 ok(rc
== ERROR_SUCCESS
, "%s verb key creation failed with %d\n", verb
, rc
);
814 rc
=RegCreateKeyExA(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
815 NULL
, &hkey_cmd
, NULL
);
816 ok(rc
== ERROR_SUCCESS
, "\'command\' key creation failed with %d\n", rc
);
820 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
824 cmd
=HeapAlloc(GetProcessHeap(), 0, strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
825 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
826 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
827 ok(rc
== ERROR_SUCCESS
, "setting command failed with %d\n", rc
);
828 HeapFree(GetProcessHeap(), 0, cmd
);
833 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
835 rc
=RegCreateKeyExA(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
836 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
837 ok(rc
== ERROR_SUCCESS
, "\'ddeexec\' key creation failed with %d\n", rc
);
838 rc
=RegSetValueExA(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
840 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
844 rc
=RegCreateKeyExA(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
845 NULL
, &hkey_application
, NULL
);
846 ok(rc
== ERROR_SUCCESS
, "\'application\' key creation failed with %d\n", rc
);
848 rc
=RegSetValueExA(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
849 strlen(application
)+1);
850 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
851 CloseHandle(hkey_application
);
855 rc
=RegCreateKeyExA(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
856 NULL
, &hkey_topic
, NULL
);
857 ok(rc
== ERROR_SUCCESS
, "\'topic\' key creation failed with %d\n", rc
);
858 rc
=RegSetValueExA(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
860 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
861 CloseHandle(hkey_topic
);
865 rc
=RegCreateKeyExA(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
866 NULL
, &hkey_ifexec
, NULL
);
867 ok(rc
== ERROR_SUCCESS
, "\'ifexec\' key creation failed with %d\n", rc
);
868 rc
=RegSetValueExA(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
870 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
871 CloseHandle(hkey_ifexec
);
873 CloseHandle(hkey_ddeexec
);
876 CloseHandle(hkey_shell
);
877 CloseHandle(hkey_verb
);
878 CloseHandle(hkey_cmd
);
881 /* Creates a class' non-DDE test verb.
882 * This function is meant to be used to create long term test verbs and thus
883 * does not trace them.
885 static void create_test_verb(const char* extension
, const char* verb
,
886 int rawcmd
, const char* cmdtail
)
888 create_test_verb_dde(extension
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
890 reset_association_description();
896 * GetLongPathNameA equivalent that supports Win95 and WinNT
900 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
902 char tmplongpath
[MAX_PATH
];
904 DWORD sp
= 0, lp
= 0;
906 WIN32_FIND_DATAA wfd
;
909 if (!shortpath
|| !shortpath
[0])
912 if (shortpath
[1] == ':')
914 tmplongpath
[0] = shortpath
[0];
915 tmplongpath
[1] = ':';
919 while (shortpath
[sp
])
921 /* check for path delimiters and reproduce them */
922 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
924 if (!lp
|| tmplongpath
[lp
-1] != '\\')
926 /* strip double "\\" */
927 tmplongpath
[lp
++] = '\\';
929 tmplongpath
[lp
] = 0; /* terminate string */
935 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
937 tmplongpath
[lp
++] = *p
++;
938 tmplongpath
[lp
++] = *p
++;
940 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
941 tmplen
= p
- (shortpath
+ sp
);
942 lstrcpynA(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
943 /* Check if the file exists and use the existing file name */
944 goit
= FindFirstFileA(tmplongpath
, &wfd
);
945 if (goit
== INVALID_HANDLE_VALUE
)
948 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
949 lp
+= strlen(tmplongpath
+ lp
);
952 tmplen
= strlen(shortpath
) - 1;
953 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
954 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
955 tmplongpath
[lp
++] = shortpath
[tmplen
];
958 tmplen
= strlen(tmplongpath
) + 1;
959 if (tmplen
<= longlen
)
961 strcpy(longpath
, tmplongpath
);
962 tmplen
--; /* length without 0 */
975 static const char* testfiles
[]=
977 "%s\\test file.shlexec",
978 "%s\\%%nasty%% $file.shlexec",
979 "%s\\test file.noassoc",
980 "%s\\test file.noassoc.shlexec",
981 "%s\\test file.shlexec.noassoc",
982 "%s\\test_shortcut_shlexec.lnk",
983 "%s\\test_shortcut_exe.lnk",
985 "%s\\test file.shlfoo",
987 "%s\\masked file.shlexec",
992 "%s\\simple.shlexec",
993 "%s\\drawback_file.noassoc",
994 "%s\\drawback_file.noassoc foo.shlexec",
995 "%s\\drawback_nonexist.noassoc foo.shlexec",
1002 const char* basename
;
1007 static filename_tests_t filename_tests
[]=
1009 /* Test bad / nonexistent filenames */
1010 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1011 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
1013 /* Standard tests */
1014 {NULL
, "%s\\test file.shlexec", 0x0, 33},
1015 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
1016 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
1017 {NULL
, "%s/test file.shlexec", 0x0, 33},
1019 /* Test filenames with no association */
1020 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1022 /* Test double extensions */
1023 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
1024 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
1026 /* Test alternate verbs */
1027 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1028 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1030 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
1031 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1033 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC
},
1035 /* Test file masked due to space */
1036 {NULL
, "%s\\masked file.shlexec", 0x0, 33},
1037 /* Test if quoting prevents the masking */
1038 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
1039 /* Test with incorrect quote */
1040 {NULL
, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF
},
1045 static filename_tests_t noquotes_tests
[]=
1047 /* Test unquoted '%1' thingies */
1048 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1049 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1050 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1055 static void test_lpFile_parsed(void)
1057 char fileA
[MAX_PATH
];
1060 if (skip_shlexec_tests
)
1062 skip("No filename parsing tests due to lack of .shlexec association\n");
1066 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1067 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
1068 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1069 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1071 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1072 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
1073 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1074 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1075 "failed: rc=%lu\n", rc
);
1077 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1078 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
1079 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1080 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1082 /* ""command"" not works on wine (and real win9x and w2k) */
1083 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
1084 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1085 todo_wine
okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
1086 "failed: rc=%lu\n", rc
);
1088 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
1089 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
1090 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1091 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1093 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1094 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
1095 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1098 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
1099 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1101 /* test SEE_MASK_DOENVSUBST works */
1102 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1103 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
1104 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1106 /* quoted lpFile does not work on real win95 and nt4 */
1107 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1108 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
1109 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1110 "failed: rc=%lu\n", rc
);
1116 const char* args
[11];
1120 static const cmdline_tests_t cmdline_tests
[] =
1125 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1126 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
1128 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1129 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
1131 {"exe arg\"one\" \"second\"arg thirdarg ",
1132 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
1134 /* Don't lose unclosed quoted arguments */
1135 {"exe arg1 \"unclosed",
1136 {"exe", "arg1", "unclosed", NULL
}, 0},
1139 {"exe", "arg1", "", NULL
}, 0},
1141 /* cmd's metacharacters have no special meaning */
1142 {"exe \"one^\" \"arg\"&two three|four",
1143 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
1145 /* Environment variables are not interpreted either */
1147 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
1149 /* If not followed by a quote, backslashes go through as is */
1150 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1151 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1153 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1154 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1156 /* When followed by a quote their number is halved and the remainder
1159 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1160 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1162 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1163 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1165 /* One can put a quote in an unquoted string by tripling it, that is in
1166 * effect quoting it like so """ -> ". The general rule is as follows:
1167 * 3n quotes -> n quotes
1168 * 3n+1 quotes -> n quotes plus start of a quoted string
1169 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1170 * Nicely, when n is 0 we get the standard rules back.
1172 {"exe two\"\"quotes next",
1173 {"exe", "twoquotes", "next", NULL
}, 0},
1175 {"exe three\"\"\"quotes next",
1176 {"exe", "three\"quotes", "next", NULL
}, 0},
1178 {"exe four\"\"\"\" quotes\" next 4%3=1",
1179 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0},
1181 {"exe five\"\"\"\"\"quotes next",
1182 {"exe", "five\"quotes", "next", NULL
}, 0},
1184 {"exe six\"\"\"\"\"\"quotes next",
1185 {"exe", "six\"\"quotes", "next", NULL
}, 0},
1187 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1188 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0},
1190 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1191 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0},
1193 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1194 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1196 /* Inside a quoted string the opening quote is added to the set of
1197 * consecutive quotes to get the effective quotes count. This gives:
1198 * 1+3n quotes -> n quotes
1199 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1200 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1202 {"exe \"two\"\"quotes next",
1203 {"exe", "two\"quotes", "next", NULL
}, 0},
1205 {"exe \"two\"\" next",
1206 {"exe", "two\"", "next", NULL
}, 0},
1208 {"exe \"three\"\"\" quotes\" next 4%3=1",
1209 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0},
1211 {"exe \"four\"\"\"\"quotes next",
1212 {"exe", "four\"quotes", "next", NULL
}, 0},
1214 {"exe \"five\"\"\"\"\"quotes next",
1215 {"exe", "five\"\"quotes", "next", NULL
}, 0},
1217 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1218 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0},
1220 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1221 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0},
1223 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1224 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1226 /* Escaped consecutive quotes are fun */
1227 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1228 {"exe", "the crazy \\\"\\", "quotes", NULL
}, 0},
1230 /* The executable path has its own rules!!!
1231 * - Backslashes have no special meaning.
1232 * - If the first character is a quote, then the second quote ends the
1234 * - The previous rule holds even if the next character is not a space!
1235 * - If the first character is not a quote, then quotes have no special
1236 * meaning either and the executable path stops at the first space.
1237 * - The consecutive quotes rules don't apply either.
1238 * - Even if there is no space between the executable path and the first
1239 * argument, the latter is parsed using the regular rules.
1241 {"exe\"file\"path arg1",
1242 {"exe\"file\"path", "arg1", NULL
}, 0},
1244 {"exe\"file\"path\targ1",
1245 {"exe\"file\"path", "arg1", NULL
}, 0},
1247 {"exe\"path\\ arg1",
1248 {"exe\"path\\", "arg1", NULL
}, 0},
1250 {"\\\"exe \"arg one\"",
1251 {"\\\"exe", "arg one", NULL
}, 0},
1253 {"\"spaced exe\" \"next arg\"",
1254 {"spaced exe", "next arg", NULL
}, 0},
1256 {"\"spaced exe\"\t\"next arg\"",
1257 {"spaced exe", "next arg", NULL
}, 0},
1259 {"\"exe\"arg\" one\" argtwo",
1260 {"exe", "arg one", "argtwo", NULL
}, 0},
1262 {"\"spaced exe\\\"arg1 arg2",
1263 {"spaced exe\\", "arg1", "arg2", NULL
}, 0},
1266 {"two", " arg1 ", NULL
}, 0},
1268 {"\"three\"\"\" arg2",
1269 {"three", "", "arg2", NULL
}, 0},
1271 {"\"four\"\"\"\"arg1",
1272 {"four", "\"arg1", NULL
}, 0},
1274 /* If the first character is a space then the executable path is empty */
1275 {" \"arg\"one argtwo",
1276 {"", "argone", "argtwo", NULL
}, 0},
1281 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1283 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1289 /* trace("----- cmd='%s'\n", test->cmd); */
1290 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, sizeof(cmdW
)/sizeof(*cmdW
));
1291 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1292 if (argsW
== NULL
&& cl2a_count
== -1)
1294 win_skip("CommandLineToArgvW not implemented, skipping\n");
1297 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1298 "expected NULL-terminated list of commandline arguments\n");
1301 while (test
->args
[count
])
1303 if ((test
->todo
& 0x1) == 0)
1304 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1306 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1308 for (i
= 0; i
< cl2a_count
; i
++)
1312 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, sizeof(argW
)/sizeof(*argW
));
1313 if ((test
->todo
& (1 << (i
+4))) == 0)
1314 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1316 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1318 else if ((test
->todo
& 0x1) == 0)
1319 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1321 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1328 static void test_commandline2argv(void)
1330 static const WCHAR exeW
[] = {'e','x','e',0};
1331 const cmdline_tests_t
* test
;
1332 WCHAR strW
[MAX_PATH
];
1337 test
= cmdline_tests
;
1340 if (!test_one_cmdline(test
))
1345 SetLastError(0xdeadbeef);
1346 args
= CommandLineToArgvW(exeW
, NULL
);
1347 le
= GetLastError();
1348 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1350 SetLastError(0xdeadbeef);
1351 args
= CommandLineToArgvW(NULL
, NULL
);
1352 le
= GetLastError();
1353 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1356 args
= CommandLineToArgvW(strW
, &numargs
);
1357 ok(numargs
== 1 || broken(numargs
> 1), "expected 1 args, got %d\n", numargs
);
1358 ok(!args
|| (!args
[numargs
] || broken(args
[numargs
] != NULL
) /* before Vista */),
1359 "expected NULL-terminated list of commandline arguments\n");
1362 GetModuleFileNameW(NULL
, strW
, sizeof(strW
)/sizeof(*strW
));
1363 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
));
1365 if (args
) LocalFree(args
);
1368 /* The goal here is to analyze how ShellExecute() builds the command that
1369 * will be run. The tricky part is that there are three transformation
1370 * steps between the 'parameters' string we pass to ShellExecute() and the
1371 * argument list we observe in the child process:
1372 * - The parsing of 'parameters' string into individual arguments. The tests
1373 * show this is done differently from both CreateProcess() and
1374 * CommandLineToArgv()!
1375 * - The way the command 'formatting directives' such as %1, %2, etc are
1377 * - And the way the resulting command line is then parsed to yield the
1378 * argument list we check.
1385 cmdline_tests_t cmd
;
1386 cmdline_tests_t broken
;
1389 static const argify_tests_t argify_tests
[] =
1391 /* Start with three simple parameters. Notice that one can reorder and
1392 * duplicate the parameters. Also notice how %* take the raw input
1393 * parameters string, including the trailing spaces, no matter what
1394 * arguments have already been used.
1396 {"Params232S", "p2 p3 p4 ", 0xc2,
1397 {" p2 p3 \"p2\" \"p2 p3 p4 \"",
1398 {"", "p2", "p3", "p2", "p2 p3 p4 ", NULL
}, 0}},
1400 /* Unquoted argument references like %2 don't automatically quote their
1401 * argument. Similarly, when they are quoted they don't escape the quotes
1402 * that their argument may contain.
1404 {"Params232S", "\"p two\" p3 p4 ", 0x3f3,
1405 {" p two p3 \"p two\" \"\"p two\" p3 p4 \"",
1406 {"", "p", "two", "p3", "p two", "p", "two p3 p4 ", NULL
}, 0}},
1408 /* Only single digits are supported so only %1 to %9. Shown here with %20
1409 * because %10 is a pain.
1411 {"Params20", "p", 0,
1413 {"", "p0", NULL
}, 0}},
1415 /* Only (double-)quotes have a special meaning. */
1416 {"Params23456", "'p2 p3` p4\\ $even", 0x40,
1417 {" \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\"",
1418 {"", "'p2", "p3`", "p4\" $even \"", NULL
}, 0}},
1420 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", 0x1c2,
1421 {" \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\"",
1422 {"", "p=2", "p-3", "p4\tp4\rp4\np4", "", "", NULL
}, 0}},
1424 /* In unquoted strings, quotes are treated are a parameter separator just
1425 * like spaces! However they can be doubled to get a literal quote.
1427 * 2n quotes -> n quotes
1428 * 2n+1 quotes -> n quotes and a parameter separator
1430 {"Params23456789", "one\"quote \"p four\" one\"quote p7", 0xff3,
1431 {" \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\"",
1432 {"", "one", "quote", "p four", "one", "quote", "p7", "", "", NULL
}, 0}},
1434 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", 0xf2,
1435 {" \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1436 {"", "twoquotes p", "three twoquotes", "p5", "", "", "", "", NULL
}, 0}},
1438 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", 0xff3,
1439 {" \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\"",
1440 {"", "three\"", "quotes", "p four", "three\"", "quotes", "p6", "", "", NULL
}, 0}},
1442 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", 0xf3,
1443 {" \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1444 {"", "four\"quotes p", "three fourquotes p5 \"", "", "", "", NULL
}, 0}},
1446 /* Quoted strings cannot be continued by tacking on a non space character
1449 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", 0x1f3,
1450 {" \"p two\" \"p3\" \"p four\" \"p5\" \"p6\"",
1451 {"", "p two", "p3", "p four", "p5", "p6", NULL
}, 0}},
1453 /* In quoted strings, the quotes are halved and an odd number closes the
1454 * string. Specifically:
1455 * 2n quotes -> n quotes
1456 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1458 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", 0xff3,
1459 {" \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\"",
1460 {"", "one q", "uote", "p four", "one q", "uote", "p7", "", "", NULL
}, 0}},
1462 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", 0x1ff3,
1463 {" \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1464 {"", "two ", "quotes p", "three two", " quotes", "p5", "", "", "", "", NULL
}, 0}},
1466 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", 0xff3,
1467 {" \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\"",
1468 {"", "three q\"", "uotes", "p four", "three q\"", "uotes", "p7", "", "", NULL
}, 0}},
1470 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", 0xff3,
1471 {" \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1472 {"", "four \"", "quotes p", "three four", "", "quotes p5 \"", "", "", "", NULL
}, 0}},
1474 /* The quoted string rules also apply to consecutive quotes at the start
1475 * of a parameter but don't count the opening quote!
1477 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", 0xbf3,
1478 {" \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\"",
1479 {"", "", "twoquotes", "p four", "", "twoquotes", "p7", "", "", NULL
}, 0}},
1481 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", 0x6f3,
1482 {" \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1483 {"", "three", "quotes p", "three \"three", "quotes p5 \"", "", "", "", NULL
}, 0}},
1485 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", 0xbf3,
1486 {" \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\"",
1487 {"", "\"", "fourquotes", "p four", "\"", "fourquotes", "p7", "", "", NULL
}, 0}},
1489 /* An unclosed quoted string gets lost! */
1490 {"Params23456", "p2 \"p3\" \"p4 is lost", 0x1c3,
1491 {" \"p2\" \"p3\" \"\" \"\" \"\"",
1492 {"", "p2", "p3", "", "", "", NULL
}, 0},
1493 {" \"p2\" \"p3\" \"p3\" \"\" \"\"",
1494 {"", "p2", "p3", "p3", "", "", NULL
}, 0}},
1496 /* Backslashes have no special meaning even when preceding quotes. All
1497 * they do is start an unquoted string.
1499 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", 0x73,
1500 {" \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\"",
1501 {"", "\" p\\three pfour\"", "pfive", "", NULL
}, 0}},
1503 /* Environment variables are left untouched. */
1504 {"Params23456", "%TMPDIR% %t %c", 0,
1505 {" \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\"",
1506 {"", "%TMPDIR%", "%t", "%c", "", "", NULL
}, 0}},
1508 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1509 * before the parameter!
1510 * (but not the previous parameter's closing quote fortunately)
1512 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", 0x3f3,
1513 {" ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 ",
1514 {"", "~2=p2 p3 p4 p5 p6 ", "~3= p3 p4 p5 p6 ", "~4= p4 p5 p6 ", "~5=", "p5", "p6", NULL
}, 0}},
1516 /* %~n works even if there is no nth parameter. */
1517 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", 0x12,
1519 {"", "~9= ", NULL
}, 0}},
1521 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", 0x12,
1523 {"", "~9=", NULL
}, 0}},
1525 /* The %~n directives also transmit the tenth parameter and beyond. */
1526 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", 0x12,
1527 {" ~9=\" p9 p10 p11 and beyond!\"",
1528 {"", "~9= p9 p10 p11 and beyond!", NULL
}, 0}},
1530 /* Bad formatting directives lose their % sign, except those followed by
1531 * a tilde! Environment variables are not expanded but lose their % sign.
1533 {"ParamsBad", "p2 p3 p4 p5", 0x12,
1534 {" \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\"",
1535 {"", "% - %~ %~0 %~1 %~a %~* a b c TMPDIR", NULL
}, 0}},
1537 {NULL
, NULL
, 0, {NULL
, {NULL
}, 0}}
1540 static void test_argify(void)
1542 BOOL has_cl2a
= TRUE
;
1543 char fileA
[MAX_PATH
], params
[2*MAX_PATH
+12];
1545 const argify_tests_t
* test
;
1546 const cmdline_tests_t
*bad
;
1550 if (skip_shlexec_tests
)
1552 skip("No argify tests due to lack of .shlexec association\n");
1556 create_test_verb(".shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1557 create_test_verb(".shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1558 create_test_verb(".shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1559 create_test_verb(".shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1560 create_test_verb(".shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1561 create_test_verb(".shlexec", "Params20", 0, "Params20 \"%20\"");
1562 create_test_verb(".shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1564 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1566 test
= argify_tests
;
1567 while (test
->params
)
1569 bad
= test
->broken
.cmd
? &test
->broken
: &test
->cmd
;
1571 /* trace("***** verb='%s' params='%s'\n", test->verb, test->params); */
1572 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
, test
->verb
, fileA
, test
->params
, NULL
, NULL
);
1573 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1576 while (test
->cmd
.args
[count
])
1578 if ((test
->todo
& 0x1) == 0)
1579 /* +4 for the shlexec arguments, -1 because of the added ""
1580 * argument for the CommandLineToArgvW() tests.
1582 okChildInt("argcA", 4 + count
- 1);
1584 okChildInt("argcA", 4 + count
- 1);
1586 cmd
= getChildString("Child", "cmdlineA");
1587 /* Our commands are such that the verb immediately precedes the
1588 * part we are interested in.
1590 if (cmd
) cmd
= strstr(cmd
, test
->verb
);
1591 if (cmd
) cmd
+= strlen(test
->verb
);
1592 if (!cmd
) cmd
= "(null)";
1593 if ((test
->todo
& 0x2) == 0)
1594 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1595 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
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 for (i
= 0; i
< count
- 1; i
++)
1603 sprintf(argname
, "argvA%d", 4 + i
);
1604 if ((test
->todo
& (1 << (i
+4))) == 0)
1605 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1607 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1611 has_cl2a
= test_one_cmdline(&(test
->cmd
));
1615 /* Test with a long parameter */
1616 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1617 fileA
[rc
] = 'a' + rc
% 26;
1618 fileA
[MAX_PATH
-1] = '\0';
1619 sprintf(params
, "shlexec \"%s\" %s", child_file
, fileA
);
1621 /* We need NOZONECHECKS on Win2003 to block a dialog */
1622 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
, NULL
, NULL
);
1623 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1624 okChildInt("argcA", 4);
1625 okChildPath("argvA3", fileA
);
1628 static void test_filename(void)
1630 char filename
[MAX_PATH
];
1631 const filename_tests_t
* test
;
1635 if (skip_shlexec_tests
)
1637 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1641 test
=filename_tests
;
1642 while (test
->basename
)
1644 BOOL quotedfile
= FALSE
;
1646 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1648 win_skip("Skipping shellexecute of file with unassociated extension\n");
1653 sprintf(filename
, test
->basename
, tmpdir
);
1654 if (strchr(filename
, '/'))
1664 if ((test
->todo
& 0x40)==0)
1666 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1670 char quoted
[MAX_PATH
+ 2];
1673 sprintf(quoted
, "\"%s\"", filename
);
1674 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1678 okShell(rc
==test
->rc
||
1679 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1680 "failed: rc=%ld err=%u\n", rc
, GetLastError());
1684 if ((test
->todo
& 0x2)==0)
1686 okChildInt("argcA", 5);
1690 okChildInt("argcA", 5);
1692 verb
=(test
->verb
? test
->verb
: "Open");
1693 if ((test
->todo
& 0x4)==0)
1695 okChildString("argvA3", verb
);
1699 okChildString("argvA3", verb
);
1701 if ((test
->todo
& 0x8)==0)
1703 okChildPath("argvA4", filename
);
1707 okChildPath("argvA4", filename
);
1713 test
=noquotes_tests
;
1714 while (test
->basename
)
1716 sprintf(filename
, test
->basename
, tmpdir
);
1717 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1720 if ((test
->todo
& 0x1)==0)
1722 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1726 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1734 verb
=(test
->verb
? test
->verb
: "Open");
1735 if ((test
->todo
& 0x4)==0)
1737 okChildString("argvA3", verb
);
1741 okChildString("argvA3", verb
);
1750 space
=strchr(str
, ' ');
1753 sprintf(attrib
, "argvA%d", count
);
1754 if ((test
->todo
& 0x8)==0)
1756 okChildPath(attrib
, str
);
1760 okChildPath(attrib
, str
);
1767 if ((test
->todo
& 0x2)==0)
1769 okChildInt("argcA", count
);
1773 okChildInt("argcA", count
);
1779 if (dllver
.dwMajorVersion
!= 0)
1781 /* The more recent versions of shell32.dll accept quoted filenames
1782 * while older ones (e.g. 4.00) don't. Still we want to test this
1783 * because IE 6 depends on the new behavior.
1784 * One day we may need to check the exact version of the dll but for
1785 * now making sure DllGetVersion() is present is sufficient.
1787 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1788 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1789 okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1790 okChildInt("argcA", 5);
1791 okChildString("argvA3", "Open");
1792 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1793 okChildPath("argvA4", filename
);
1799 const char* urlprefix
;
1800 const char* basename
;
1805 #define URL_SUCCESS 0x1
1806 #define USE_COLON 0x2
1807 #define USE_BSLASH 0x4
1809 static fileurl_tests_t fileurl_tests
[]=
1811 /* How many slashes does it take... */
1812 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1813 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1814 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1815 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1816 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1817 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1818 {"file://///", "%s\\test file.shlexec", 0, 0},
1820 /* Test with Windows-style paths */
1821 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0},
1822 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0},
1824 /* Check handling of hostnames */
1825 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1826 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1827 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1828 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1829 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1830 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1832 /* Environment variables are not expanded in URLs */
1833 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1834 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1836 /* Test shortcuts vs. URLs */
1837 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1d},
1842 static void test_fileurls(void)
1844 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1845 char command
[MAX_PATH
];
1846 const fileurl_tests_t
* test
;
1850 if (skip_shlexec_tests
)
1852 skip("No file URL tests due to lack of .shlexec association\n");
1856 rc
= (INT_PTR
)ShellExecuteA(NULL
, NULL
, "file:///nosuchfile.shlexec", NULL
, NULL
, SW_SHOWNORMAL
);
1859 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1863 get_long_path_name(tmpdir
, longtmpdir
, sizeof(longtmpdir
)/sizeof(*longtmpdir
));
1864 SetEnvironmentVariableA("urlprefix", "file:///");
1867 while (test
->basename
)
1869 /* Build the file URL */
1870 sprintf(filename
, test
->basename
, longtmpdir
);
1871 strcpy(fileurl
, test
->urlprefix
);
1872 strcat(fileurl
, filename
);
1873 s
= fileurl
+ strlen(test
->urlprefix
);
1876 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1878 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1883 /* Test it first with FindExecutable() */
1884 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1885 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1887 /* Then ShellExecute() */
1888 if ((test
->todo
& 0x10) == 0)
1889 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1891 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1892 if (bad_shellexecute
)
1894 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1897 if (test
->flags
& URL_SUCCESS
)
1899 if ((test
->todo
& 0x1) == 0)
1900 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1902 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1906 if ((test
->todo
& 0x1) == 0)
1907 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1908 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1909 "failed: bad rc=%lu\n", rc
);
1911 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1912 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1913 "failed: bad rc=%lu\n", rc
);
1917 if ((test
->todo
& 0x2) == 0)
1918 okChildInt("argcA", 5);
1920 okChildInt("argcA", 5);
1922 if ((test
->todo
& 0x4) == 0)
1923 okChildString("argvA3", "Open");
1925 okChildString("argvA3", "Open");
1927 if ((test
->todo
& 0x8) == 0)
1928 okChildPath("argvA4", filename
);
1930 okChildPath("argvA4", filename
);
1935 SetEnvironmentVariableA("urlprefix", NULL
);
1938 static void test_find_executable(void)
1940 char notepad_path
[MAX_PATH
];
1941 char filename
[MAX_PATH
];
1942 char command
[MAX_PATH
];
1943 const filename_tests_t
* test
;
1946 if (!create_test_association(".sfe"))
1948 skip("Unable to create association for '.sfe'\n");
1951 create_test_verb(".sfe", "Open", 1, "%1");
1953 /* Don't test FindExecutable(..., NULL), it always crashes */
1955 strcpy(command
, "your word");
1956 if (0) /* Can crash on Vista! */
1958 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
1959 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1960 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1963 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
1964 strcat( notepad_path
, "\\notepad.exe" );
1966 /* Search for something that should be in the system-wide search path (no default directory) */
1967 strcpy(command
, "your word");
1968 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
1969 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1970 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1972 /* Search for something that should be in the system-wide search path (with default directory) */
1973 strcpy(command
, "your word");
1974 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
1975 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1976 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1978 strcpy(command
, "your word");
1979 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
1980 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1981 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1983 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
1984 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1985 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1986 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1988 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
1989 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1991 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
1992 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1994 delete_test_association(".sfe");
1996 if (!create_test_association(".shl"))
1998 skip("Unable to create association for '.shl'\n");
2001 create_test_verb(".shl", "Open", 0, "Open");
2003 sprintf(filename
, "%s\\test file.shl", tmpdir
);
2004 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2005 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2007 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
2008 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2010 delete_test_association(".shl");
2014 /* On Windows XP and 2003 FindExecutable() is completely broken.
2015 * Probably what it does is convert the filename to 8.3 format,
2016 * which as a side effect converts the '.shlfoo' extension to '.shl',
2017 * and then tries to find an association for '.shl'. This means it
2018 * will normally fail on most extensions with more than 3 characters,
2019 * like '.mpeg', etc.
2020 * Also it means we cannot do any other test.
2022 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
2026 if (skip_shlexec_tests
)
2028 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2032 test
=filename_tests
;
2033 while (test
->basename
)
2035 sprintf(filename
, test
->basename
, tmpdir
);
2036 if (strchr(filename
, '/'))
2047 /* Win98 does not '\0'-terminate command! */
2048 memset(command
, '\0', sizeof(command
));
2049 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2052 if ((test
->todo
& 0x10)==0)
2054 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2058 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2063 equal
=strcmp(command
, argv0
) == 0 ||
2064 /* NT4 returns an extra 0x8 character! */
2065 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
2066 if ((test
->todo
& 0x20)==0)
2068 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2069 filename
, command
, argv0
);
2073 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2074 filename
, command
, argv0
);
2082 static filename_tests_t lnk_tests
[]=
2084 /* Pass bad / nonexistent filenames as a parameter */
2085 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
2086 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
2088 /* Pass regular paths as a parameter */
2089 {NULL
, "%s\\test file.shlexec", 0xa, 33},
2090 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2092 /* Pass filenames with no association as a parameter */
2093 {NULL
, "%s\\test file.noassoc", 0xa, 33},
2098 static void test_lnks(void)
2100 char filename
[MAX_PATH
];
2101 char params
[MAX_PATH
];
2102 const filename_tests_t
* test
;
2105 if (skip_shlexec_tests
)
2106 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2109 /* Should open through our association */
2110 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2111 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2112 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2113 okChildInt("argcA", 5);
2114 okChildString("argvA3", "Open");
2115 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2116 get_long_path_name(params
, filename
, sizeof(filename
));
2117 okChildPath("argvA4", filename
);
2119 todo_wait rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
2120 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2121 okChildInt("argcA", 5);
2122 todo_wine
okChildString("argvA3", "Open");
2123 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2124 get_long_path_name(params
, filename
, sizeof(filename
));
2125 todo_wine
okChildPath("argvA4", filename
);
2128 /* Should just run our executable */
2129 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2130 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2131 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2132 okChildInt("argcA", 4);
2133 okChildString("argvA3", "Lnk");
2135 /* An explicit class overrides lnk's ContextMenuHandler */
2136 rc
=shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
2137 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2138 okChildInt("argcA", 5);
2139 okChildString("argvA3", "Open");
2140 okChildPath("argvA4", filename
);
2142 if (dllver
.dwMajorVersion
>=6)
2145 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2146 * Older versions don't or are quite buggy in this regard.
2148 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2156 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2157 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2158 okChildInt("argcA", 4);
2159 okChildString("argvA3", "Lnk");
2162 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2164 while (test
->basename
)
2167 sprintf(params
+1, test
->basename
, tmpdir
);
2168 strcat(params
,"\"");
2169 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2173 if ((test
->todo
& 0x1)==0)
2175 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2179 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2183 if ((test
->todo
& 0x2)==0)
2185 okChildInt("argcA", 5);
2189 okChildInt("argcA", 5);
2191 if ((test
->todo
& 0x4)==0)
2193 okChildString("argvA3", "Lnk");
2197 okChildString("argvA3", "Lnk");
2199 sprintf(params
, test
->basename
, tmpdir
);
2200 if ((test
->todo
& 0x8)==0)
2202 okChildPath("argvA4", params
);
2206 okChildPath("argvA4", params
);
2214 static void test_exes(void)
2216 char filename
[MAX_PATH
];
2220 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2222 /* We need NOZONECHECKS on Win2003 to block a dialog */
2223 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
2225 okShell(rc
> 32, "returned %lu\n", rc
);
2226 okChildInt("argcA", 4);
2227 okChildString("argvA3", "Exec");
2229 if (! skip_noassoc_tests
)
2231 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
2232 if (CopyFileA(argv0
, filename
, FALSE
))
2234 rc
=shell_execute(NULL
, filename
, params
, NULL
);
2236 okShell(rc
==SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2242 win_skip("Skipping shellexecute of file with unassociated extension\n");
2245 /* test combining executable and parameters */
2246 sprintf(filename
, "%s shlexec \"%s\" Exec", argv0
, child_file
);
2247 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2248 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2250 sprintf(filename
, "\"%s\" shlexec \"%s\" Exec", argv0
, child_file
);
2251 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2252 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2254 /* A verb, even if invalid, overrides the normal handling of executables */
2255 todo_wait rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
,
2256 "notaverb", argv0
, NULL
, NULL
, NULL
);
2257 todo_wine
okShell(rc
== SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2259 /* A class overrides the normal handling of executables too */
2260 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2261 rc
= shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
,
2262 NULL
, argv0
, NULL
, NULL
, ".shlexec");
2263 todo_wine
okShell(rc
> 32, "returned %lu\n", rc
);
2264 okChildInt("argcA", 5);
2265 todo_wine
okChildString("argvA3", "Open");
2266 todo_wine
okChildPath("argvA4", argv0
);
2271 const char* command
;
2272 const char* ddeexec
;
2273 const char* application
;
2277 const char* expectedDdeExec
;
2281 static dde_tests_t dde_tests
[] =
2283 /* Test passing and not passing command-line
2284 * argument, no DDE */
2285 {"", NULL
, NULL
, NULL
, NULL
, 0, ""},
2286 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, 1, ""},
2288 /* Test passing and not passing command-line
2289 * argument, with DDE */
2290 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 0, "[open(\"%s\")]"},
2291 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 1, "[open(\"%s\")]"},
2293 /* Test unquoted %1 in command and ddeexec
2294 * (test filename has space) */
2295 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", TRUE
/* before vista */},
2297 /* Test ifexec precedence over ddeexec */
2298 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2300 /* Test default DDE topic */
2301 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, 0, "[open(\"%s\")]"},
2303 /* Test default DDE application */
2304 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, 0, "[open(\"%s\")]"},
2309 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
2311 if (winetest_debug
> 1)
2312 trace("WaitForInputIdle() waiting for dde event\n");
2313 return WaitForSingleObject(dde_ready_event
, timeout
);
2317 * WaitForInputIdle() will normally return immediately for console apps. That's
2318 * a problem for us because ShellExecute will assume that an app is ready to
2319 * receive DDE messages after it has called WaitForInputIdle() on that app.
2320 * To work around that we install our own version of WaitForInputIdle() that
2321 * will wait for the child to explicitly tell us that it is ready. We do that
2322 * by changing the entry for WaitForInputIdle() in the shell32 import address
2325 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2328 PIMAGE_NT_HEADERS nt_headers
;
2329 DWORD import_directory_rva
;
2330 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2333 base
= (char *) GetModuleHandleA("shell32.dll");
2334 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2335 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2337 /* Search for the correct imported module by walking the import descriptors */
2338 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2339 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2341 char *import_module_name
;
2343 import_module_name
= base
+ import_descriptor
->Name
;
2344 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2345 lstrcmpiA(import_module_name
, "user32") == 0)
2347 PIMAGE_THUNK_DATA int_entry
;
2348 PIMAGE_THUNK_DATA iat_entry
;
2350 /* The import name table and import address table are two parallel
2351 * arrays. We need the import name table to find the imported
2352 * routine and the import address table to patch the address, so
2353 * walk them side by side */
2354 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2355 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2356 while (int_entry
->u1
.Ordinal
!= 0)
2358 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2360 PIMAGE_IMPORT_BY_NAME import_by_name
;
2361 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2362 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2364 /* Found the correct routine in the correct imported module. Patch it. */
2366 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2367 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2368 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2369 if (winetest_debug
> 1)
2370 trace("Hooked %s.WaitForInputIdle\n", import_module_name
);
2381 import_descriptor
++;
2383 ok(hook_count
, "Could not hook WaitForInputIdle()\n");
2386 static void test_dde(void)
2388 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2389 const dde_tests_t
* test
;
2395 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2397 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2399 /* Default service is application name minus path and extension */
2400 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2401 *strchr(defApplication
, '.') = 0;
2403 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2404 4096, "winetest_shlexec_dde_map");
2405 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2408 while (test
->command
)
2410 if (!create_test_association(".sde"))
2412 skip("Unable to create association for '.sde'\n");
2415 create_test_verb_dde(".sde", "Open", 0, test
->command
, test
->ddeexec
,
2416 test
->application
, test
->topic
, test
->ifexec
);
2418 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2420 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2421 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2425 shared_block
[0] = '\0';
2426 shared_block
[1] = '\0';
2430 dde_ready_event
= CreateEventA(NULL
, FALSE
, FALSE
, "winetest_shlexec_dde_ready");
2431 rc
= shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, filename
, NULL
, NULL
, NULL
);
2432 CloseHandle(dde_ready_event
);
2433 okShell(32 < rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2438 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
2440 okChildInt("argcA", test
->expectedArgs
+ 3);
2442 if (test
->expectedArgs
== 1) okChildPath("argvA3", filename
);
2444 sprintf(params
, test
->expectedDdeExec
, filename
);
2445 okChildPath("ddeExec", params
);
2447 reset_association_description();
2449 delete_test_association(".sde");
2453 UnmapViewOfFile(shared_block
);
2455 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2458 #define DDE_DEFAULT_APP_VARIANTS 2
2461 const char* command
;
2462 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2464 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2465 } dde_default_app_tests_t
;
2467 static dde_default_app_tests_t dde_default_app_tests
[] =
2469 /* Windows XP and 98 handle default DDE app names in different ways.
2470 * The application name we see in the first test determines the pattern
2471 * of application names and return codes we will look for. */
2473 /* Test unquoted existing filename with a space */
2474 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
2475 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
2477 /* Test quoted existing filename with a space */
2478 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
2479 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
2481 /* Test unquoted filename with a space that doesn't exist, but
2483 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
2484 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
2486 /* Test quoted filename with a space that does not exist */
2487 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
2488 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
2490 /* Test filename supplied without the extension */
2491 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
2492 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
2494 /* Test an unquoted nonexistent filename */
2495 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
2496 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
2498 /* Test an application that will be found on the path */
2499 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
2500 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
2502 /* Test an application that will not be found on the path */
2503 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2504 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2506 {NULL
, {NULL
}, 0, {0}}
2512 DWORD threadIdParent
;
2513 } dde_thread_info_t
;
2515 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2517 dde_thread_info_t
*info
= arg
;
2518 assert(info
&& info
->filename
);
2519 PostThreadMessageA(info
->threadIdParent
,
2521 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2526 static void test_dde_default_app(void)
2528 char filename
[MAX_PATH
];
2530 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2531 const dde_default_app_tests_t
* test
;
2540 post_quit_on_execute
= FALSE
;
2542 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2543 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
2544 ok(rc
== DMLERR_NO_ERROR
, "got %lx\n", rc
);
2546 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2548 /* It is strictly not necessary to register an application name here, but wine's
2549 * DdeNameService implementation complains if 0 is passed instead of
2550 * hszApplication with DNS_FILTEROFF */
2551 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2552 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2553 ok(hszApplication
&& hszTopic
, "got %p and %p\n", hszApplication
, hszTopic
);
2554 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
2555 ok(ret
!= 0, "got %p\n", ret
);
2557 test
= dde_default_app_tests
;
2558 while (test
->command
)
2562 if (!create_test_association(".sde"))
2564 skip("Unable to create association for '.sde'\n");
2567 sprintf(params
, test
->command
, tmpdir
);
2568 create_test_verb_dde(".sde", "Open", 1, params
, "[test]", NULL
,
2570 ddeApplication
[0] = 0;
2572 /* No application will be run as we will respond to the first DDE event,
2573 * so don't wait for it */
2576 thread
= CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
);
2577 ok(thread
!= NULL
, "got %p\n", thread
);
2578 while (GetMessageA(&msg
, NULL
, 0, 0)) DispatchMessageA(&msg
);
2579 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2581 /* First test, find which set of test data we expect to see */
2582 if (test
== dde_default_app_tests
)
2585 for (i
=0; i
<DDE_DEFAULT_APP_VARIANTS
; i
++)
2587 if (!strcmp(ddeApplication
, test
->expectedDdeApplication
[i
]))
2593 if (i
== DDE_DEFAULT_APP_VARIANTS
)
2594 skip("Default DDE application test does not match any available results, using first expected data set.\n");
2597 if ((test
->todo
& 0x1)==0)
2599 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2600 rc
, GetLastError());
2604 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2605 rc
, GetLastError());
2609 if ((test
->todo
& 0x2)==0)
2611 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2612 "Expected application '%s', got '%s'\n",
2613 test
->expectedDdeApplication
[which
], ddeApplication
);
2617 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2618 "Expected application '%s', got '%s'\n",
2619 test
->expectedDdeApplication
[which
], ddeApplication
);
2622 reset_association_description();
2624 delete_test_association(".sde");
2628 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
2629 ok(ret
!= 0, "got %p\n", ret
);
2630 b
= DdeFreeStringHandle(ddeInst
, hszTopic
);
2631 ok(b
, "got %d\n", b
);
2632 b
= DdeFreeStringHandle(ddeInst
, hszApplication
);
2633 ok(b
, "got %d\n", b
);
2634 b
= DdeUninitialize(ddeInst
);
2635 ok(b
, "got %d\n", b
);
2638 static void init_test(void)
2641 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2642 char filename
[MAX_PATH
];
2643 WCHAR lnkfile
[MAX_PATH
];
2645 const char* const * testfile
;
2650 hdll
=GetModuleHandleA("shell32.dll");
2651 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2654 dllver
.cbSize
=sizeof(dllver
);
2655 pDllGetVersion(&dllver
);
2656 trace("major=%d minor=%d build=%d platform=%d\n",
2657 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2658 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2662 memset(&dllver
, 0, sizeof(dllver
));
2665 r
= CoInitialize(NULL
);
2666 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2670 rc
=GetModuleFileNameA(NULL
, argv0
, sizeof(argv0
));
2671 ok(rc
!= 0 && rc
< sizeof(argv0
), "got %d\n", rc
);
2672 if (GetFileAttributesA(argv0
)==INVALID_FILE_ATTRIBUTES
)
2674 strcat(argv0
, ".so");
2675 ok(GetFileAttributesA(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2676 "unable to find argv0!\n");
2679 /* Older versions (win 2k) fail tests if there is a space in
2681 if (dllver
.dwMajorVersion
<= 5)
2682 strcpy(filename
, "c:\\");
2684 GetTempPathA(sizeof(filename
), filename
);
2685 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2686 GetLongPathNameA(tmpdir
, tmpdir
, sizeof(tmpdir
));
2687 DeleteFileA( tmpdir
);
2688 rc
= CreateDirectoryA( tmpdir
, NULL
);
2689 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2690 /* Set %TMPDIR% for the tests */
2691 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2693 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2694 ok(rc
!= 0, "got %d\n", rc
);
2695 init_event(child_file
);
2697 /* Set up the test files */
2703 sprintf(filename
, *testfile
, tmpdir
);
2704 hfile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2705 FILE_ATTRIBUTE_NORMAL
, NULL
);
2706 if (hfile
==INVALID_HANDLE_VALUE
)
2708 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2715 /* Setup the test shortcuts */
2716 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2717 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2718 desc
.description
=NULL
;
2720 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2723 desc
.arguments
="ignored";
2728 create_lnk(lnkfile
, &desc
, 0);
2730 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2731 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2732 desc
.description
=NULL
;
2736 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2737 desc
.arguments
=params
;
2742 create_lnk(lnkfile
, &desc
, 0);
2744 /* Create a basic association suitable for most tests */
2745 if (!create_test_association(".shlexec"))
2747 skip_shlexec_tests
= TRUE
;
2748 skip("Unable to create association for '.shlexec'\n");
2751 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2752 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2753 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2754 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2755 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2756 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2758 /* Set an environment variable to see if it is inherited */
2759 SetEnvironmentVariableA("ShlexecVar", "Present");
2762 static void cleanup_test(void)
2764 char filename
[MAX_PATH
];
2765 const char* const * testfile
;
2767 /* Delete the test files */
2771 sprintf(filename
, *testfile
, tmpdir
);
2772 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2773 SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
);
2774 DeleteFileA(filename
);
2777 DeleteFileA(child_file
);
2778 RemoveDirectoryA(tmpdir
);
2780 /* Delete the test association */
2781 delete_test_association(".shlexec");
2783 CloseHandle(hEvent
);
2788 static void test_directory(void)
2790 char path
[MAX_PATH
], curdir
[MAX_PATH
];
2791 char params
[1024], dirpath
[1024];
2794 sprintf(path
, "%s\\test2.exe", tmpdir
);
2795 CopyFileA(argv0
, path
, FALSE
);
2797 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2799 /* Test with the current directory */
2800 GetCurrentDirectoryA(sizeof(curdir
), curdir
);
2801 SetCurrentDirectoryA(tmpdir
);
2802 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2803 NULL
, "test2.exe", params
, NULL
, NULL
);
2804 okShell(rc
> 32, "returned %lu\n", rc
);
2805 okChildInt("argcA", 4);
2806 okChildString("argvA3", "Exec");
2807 todo_wine
okChildPath("longPath", path
);
2808 SetCurrentDirectoryA(curdir
);
2810 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2811 NULL
, "test2.exe", params
, NULL
, NULL
);
2812 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2814 /* Explicitly specify the directory to use */
2815 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2816 NULL
, "test2.exe", params
, tmpdir
, NULL
);
2817 okShell(rc
> 32, "returned %lu\n", rc
);
2818 okChildInt("argcA", 4);
2819 okChildString("argvA3", "Exec");
2820 todo_wine
okChildPath("longPath", path
);
2822 /* Specify it through an environment variable */
2823 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2824 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2825 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2827 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
|SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2828 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2829 okShell(rc
> 32, "returned %lu\n", rc
);
2830 okChildInt("argcA", 4);
2831 okChildString("argvA3", "Exec");
2832 todo_wine
okChildPath("longPath", path
);
2834 /* Not a colon-separated directory list */
2835 sprintf(dirpath
, "%s:%s", curdir
, tmpdir
);
2836 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2837 NULL
, "test2.exe", params
, dirpath
, NULL
);
2838 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2844 myARGC
= winetest_get_mainargs(&myARGV
);
2847 doChild(myARGC
, myARGV
);
2848 /* Skip the tests/failures trace for child processes */
2849 ExitProcess(winetest_get_failures());
2854 test_commandline2argv();
2856 test_lpFile_parsed();
2859 test_find_executable();
2863 test_dde_default_app();