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 #define CHILD_DDE_TIMEOUT 2500
150 static DWORD ddeInst
;
152 static char ddeExec
[MAX_PATH
], ddeApplication
[MAX_PATH
];
153 static BOOL post_quit_on_execute
;
155 /* Handle DDE for doChild() and test_dde_default_app() */
156 static HDDEDATA CALLBACK
ddeCb(UINT uType
, UINT uFmt
, HCONV hConv
,
157 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
158 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
162 if (winetest_debug
> 2)
163 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
164 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
169 if (!DdeCmpStringHandles(hsz1
, hszTopic
))
171 size
= DdeQueryStringA(ddeInst
, hsz2
, ddeApplication
, MAX_PATH
, CP_WINANSI
);
172 ok(size
< MAX_PATH
, "got size %d\n", size
);
173 assert(size
< MAX_PATH
);
174 return (HDDEDATA
)TRUE
;
176 return (HDDEDATA
)FALSE
;
179 size
= DdeGetData(hData
, (LPBYTE
)ddeExec
, MAX_PATH
, 0);
180 ok(size
< MAX_PATH
, "got size %d\n", size
);
181 assert(size
< MAX_PATH
);
182 DdeFreeDataHandle(hData
);
183 if (post_quit_on_execute
)
185 return (HDDEDATA
)DDE_FACK
;
192 static HANDLE hEvent
;
193 static void init_event(const char* child_file
)
196 event_name
=strrchr(child_file
, '\\')+1;
197 hEvent
=CreateEventA(NULL
, FALSE
, FALSE
, event_name
);
201 * This is just to make sure the child won't run forever stuck in a
202 * GetMessage() loop when DDE fails for some reason.
204 static void CALLBACK
childTimeout(HWND wnd
, UINT msg
, UINT_PTR timer
, DWORD time
)
206 trace("childTimeout called\n");
211 static void doChild(int argc
, char** argv
)
213 char *filename
, buffer
[MAX_PATH
];
219 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
220 if (hFile
== INVALID_HANDLE_VALUE
)
224 childPrintf(hFile
, "[Child]\r\n");
225 if (winetest_debug
> 2)
227 trace("cmdlineA='%s'\n", GetCommandLineA());
228 trace("argcA=%d\n", argc
);
230 childPrintf(hFile
, "cmdlineA=%s\r\n", encodeA(GetCommandLineA()));
231 childPrintf(hFile
, "argcA=%d\r\n", argc
);
232 for (i
= 0; i
< argc
; i
++)
234 if (winetest_debug
> 2)
235 trace("argvA%d='%s'\n", i
, argv
[i
]);
236 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
238 GetModuleFileNameA(GetModuleHandleA(NULL
), buffer
, sizeof(buffer
));
239 childPrintf(hFile
, "longPath=%s\r\n", encodeA(buffer
));
241 /* Check environment variable inheritance */
244 GetEnvironmentVariableA("ShlexecVar", buffer
, sizeof(buffer
));
245 childPrintf(hFile
, "ShlexecVarLE=%d\r\n", GetLastError());
246 childPrintf(hFile
, "ShlexecVar=%s\r\n", encodeA(buffer
));
248 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
252 char *shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
254 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
261 post_quit_on_execute
= TRUE
;
263 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
264 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
265 ok(rc
== DMLERR_NO_ERROR
, "DdeInitializeA() returned %d\n", rc
);
266 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
267 ok(hszApplication
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
268 shared_block
+= strlen(shared_block
) + 1;
269 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
270 ok(hszTopic
!= NULL
, "DdeCreateStringHandleA(%s) = NULL\n", shared_block
);
271 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
272 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
274 timer
= SetTimer(NULL
, 0, CHILD_DDE_TIMEOUT
, childTimeout
);
276 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
278 CloseHandle(dde_ready
);
280 while (GetMessageA(&msg
, NULL
, 0, 0))
282 if (winetest_debug
> 2)
283 trace("msg %d lParam=%ld wParam=%lu\n", msg
.message
, msg
.lParam
, msg
.wParam
);
284 DispatchMessageA(&msg
);
288 KillTimer(NULL
, timer
);
289 hdde
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
290 ok(hdde
!= NULL
, "DdeNameService() failed le=%u\n", GetLastError());
291 ok(DdeFreeStringHandle(ddeInst
, hszTopic
), "DdeFreeStringHandle(topic)\n");
292 ok(DdeFreeStringHandle(ddeInst
, hszApplication
), "DdeFreeStringHandle(application)\n");
293 ok(DdeUninitialize(ddeInst
), "DdeUninitialize() failed\n");
297 dde_ready
= OpenEventA(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
299 CloseHandle(dde_ready
);
302 UnmapViewOfFile(shared_block
);
304 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
307 childPrintf(hFile
, "Failures=%d\r\n", winetest_get_failures());
310 init_event(filename
);
315 static void dump_child_(const char* file
, int line
)
317 if (winetest_debug
> 1)
323 str
=getChildString("Child", "cmdlineA");
324 trace_(file
, line
)("cmdlineA='%s'\n", str
);
325 c
=GetPrivateProfileIntA("Child", "argcA", -1, child_file
);
326 trace_(file
, line
)("argcA=%d\n",c
);
329 sprintf(key
, "argvA%d", i
);
330 str
=getChildString("Child", key
);
331 trace_(file
, line
)("%s='%s'\n", key
, str
);
334 c
=GetPrivateProfileIntA("Child", "ShlexecVarLE", -1, child_file
);
335 trace_(file
, line
)("ShlexecVarLE=%d\n", c
);
336 str
=getChildString("Child", "ShlexecVar");
337 trace_(file
, line
)("ShlexecVar='%s'\n", str
);
339 c
=GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
340 trace_(file
, line
)("Failures=%d\n", c
);
347 * Helpers to check the ShellExecute() / child process results.
351 static char shell_call
[2048];
352 static void WINETEST_PRINTF_ATTR(2,3) _okShell(int condition
, const char *msg
, ...)
357 strcpy(buffer
, shell_call
);
359 va_start(valist
, msg
);
360 vsprintf(buffer
+strlen(buffer
), msg
, valist
);
362 winetest_ok(condition
, "%s", buffer
);
364 #define okShell_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : _okShell
365 #define okShell okShell_(__FILE__, __LINE__)
367 static char assoc_desc
[2048];
368 static void reset_association_description(void)
373 static void okChildString_(const char* file
, int line
, const char* key
, const char* expected
, const char* bad
)
376 result
=getChildString("Child", key
);
379 okShell_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
382 okShell_(file
, line
)(lstrcmpiA(result
, expected
) == 0 ||
383 broken(lstrcmpiA(result
, bad
) == 0),
384 "%s expected '%s', got '%s'\n", key
, expected
, result
);
386 #define okChildString(key, expected) okChildString_(__FILE__, __LINE__, (key), (expected), (expected))
387 #define okChildStringBroken(key, expected, broken) okChildString_(__FILE__, __LINE__, (key), (expected), (broken))
389 static int StrCmpPath(const char* s1
, const char* s2
)
391 if (!s1
&& !s2
) return 0;
402 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
404 while (*s1
=='/' || *s1
=='\\')
406 while (*s2
=='/' || *s2
=='\\')
409 else if (toupper(*s1
)==toupper(*s2
))
426 static void okChildPath_(const char* file
, int line
, const char* key
, const char* expected
)
429 int equal
, shortequal
;
430 result
=getChildString("Child", key
);
433 okShell_(file
,line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
437 equal
= (StrCmpPath(result
, expected
) == 0);
440 char altpath
[MAX_PATH
];
441 DWORD rc
= GetLongPathNameA(expected
, altpath
, sizeof(altpath
));
442 if (0 < rc
&& rc
< sizeof(altpath
))
443 equal
= (StrCmpPath(result
, altpath
) == 0);
446 rc
= GetShortPathNameA(expected
, altpath
, sizeof(altpath
));
447 if (0 < rc
&& rc
< sizeof(altpath
))
448 shortequal
= (StrCmpPath(result
, altpath
) == 0);
451 okShell_(file
,line
)(equal
|| broken(shortequal
) /* XP SP1 */,
452 "%s expected '%s', got '%s'\n", key
, expected
, result
);
454 #define okChildPath(key, expected) okChildPath_(__FILE__, __LINE__, (key), (expected))
456 static void okChildInt_(const char* file
, int line
, const char* key
, int expected
)
459 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
460 okShell_(file
,line
)(result
== expected
,
461 "%s expected %d, but got %d\n", key
, expected
, result
);
463 #define okChildInt(key, expected) okChildInt_(__FILE__, __LINE__, (key), (expected))
465 static void okChildIntBroken_(const char* file
, int line
, const char* key
, int expected
)
468 result
=GetPrivateProfileIntA("Child", key
, expected
, child_file
);
469 okShell_(file
,line
)(result
== expected
|| broken(result
!= expected
),
470 "%s expected %d, but got %d\n", key
, expected
, result
);
472 #define okChildIntBroken(key, expected) okChildIntBroken_(__FILE__, __LINE__, (key), (expected))
477 * ShellExecute wrappers
481 static void strcat_param(char* str
, const char* name
, const char* param
)
485 if (str
[strlen(str
)-1] == '"')
494 static int _todo_wait
= 0;
495 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
497 static int bad_shellexecute
= 0;
499 static INT_PTR
shell_execute_(const char* file
, int line
, LPCSTR verb
, LPCSTR filename
, LPCSTR parameters
, LPCSTR directory
)
501 INT_PTR rc
, rcEmpty
= 0;
504 rcEmpty
= shell_execute_(file
, line
, "", filename
, parameters
, directory
);
506 strcpy(shell_call
, "ShellExecute(");
507 strcat_param(shell_call
, "verb", verb
);
508 strcat_param(shell_call
, "file", filename
);
509 strcat_param(shell_call
, "params", parameters
);
510 strcat_param(shell_call
, "dir", directory
);
511 strcat(shell_call
, ")");
512 strcat(shell_call
, assoc_desc
);
513 if (winetest_debug
> 1)
514 trace_(file
, line
)("Called %s\n", shell_call
);
516 DeleteFileA(child_file
);
517 SetLastError(0xcafebabe);
519 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
520 * association it displays the 'Open With' dialog and I could not find
521 * a flag to prevent this.
523 rc
=(INT_PTR
)ShellExecuteA(NULL
, verb
, filename
, parameters
, directory
, SW_HIDE
);
528 wait_rc
=WaitForSingleObject(hEvent
, 5000);
529 if (wait_rc
== WAIT_TIMEOUT
)
531 HWND wnd
= FindWindowA("#32770", "Windows");
533 wnd
= FindWindowA("Shell_Flyout", "");
536 SendMessageA(wnd
, WM_CLOSE
, 0, 0);
537 win_skip("Skipping shellexecute of file with unassociated extension\n");
538 skip_noassoc_tests
= TRUE
;
542 todo_wine_if(_todo_wait
)
543 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32,
544 "WaitForSingleObject returned %d\n", wait_rc
);
546 /* The child process may have changed the result file, so let profile
547 * functions know about it
549 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
550 if (GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
553 dump_child_(file
, line
);
554 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
556 winetest_add_failures(c
);
557 okChildInt_(file
, line
, "ShlexecVarLE", 0);
558 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
563 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
564 bad_shellexecute
= 1;
565 okShell_(file
, line
)(rc
== rcEmpty
||
566 broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
567 "Got different return value with empty string: %lu %lu\n", rc
, rcEmpty
);
572 #define shell_execute(verb, filename, parameters, directory) \
573 shell_execute_(__FILE__, __LINE__, verb, filename, parameters, directory)
575 static INT_PTR
shell_execute_ex_(const char* file
, int line
,
576 DWORD mask
, LPCSTR verb
, LPCSTR filename
,
577 LPCSTR parameters
, LPCSTR directory
,
581 SHELLEXECUTEINFOA sei
;
585 /* Add some flags so we can wait for the child process */
586 mask
|= SEE_MASK_NOCLOSEPROCESS
| SEE_MASK_NO_CONSOLE
;
588 strcpy(shell_call
, "ShellExecuteEx(");
589 sprintf(smask
, "0x%x", mask
);
590 strcat_param(shell_call
, "mask", smask
);
591 strcat_param(shell_call
, "verb", verb
);
592 strcat_param(shell_call
, "file", filename
);
593 strcat_param(shell_call
, "params", parameters
);
594 strcat_param(shell_call
, "dir", directory
);
595 strcat_param(shell_call
, "class", class);
596 strcat(shell_call
, ")");
597 strcat(shell_call
, assoc_desc
);
598 if (winetest_debug
> 1)
599 trace_(file
, line
)("Called %s\n", shell_call
);
601 sei
.cbSize
=sizeof(sei
);
606 sei
.lpParameters
=parameters
;
607 sei
.lpDirectory
=directory
;
608 sei
.nShow
=SW_SHOWNORMAL
;
609 sei
.hInstApp
=NULL
; /* Out */
615 sei
.hProcess
=(HANDLE
)0xdeadbeef; /* Out */
617 DeleteFileA(child_file
);
618 SetLastError(0xcafebabe);
619 success
=ShellExecuteExA(&sei
);
620 rc
=(INT_PTR
)sei
.hInstApp
;
621 okShell_(file
, line
)((success
&& rc
> 32) || (!success
&& rc
<= 32),
622 "rc=%d and hInstApp=%ld is not allowed\n",
628 if (sei
.hProcess
!=NULL
)
630 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
631 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
632 "WaitForSingleObject(hProcess) returned %d\n",
634 wait_rc
= GetExitCodeProcess(sei
.hProcess
, &rc
);
635 okShell_(file
, line
)(wait_rc
, "GetExitCodeProcess() failed le=%u\n", GetLastError());
636 todo_wine_if(_todo_wait
)
637 okShell_(file
, line
)(rc
== 0, "child returned %u\n", rc
);
638 CloseHandle(sei
.hProcess
);
640 wait_rc
=WaitForSingleObject(hEvent
, 5000);
641 todo_wine_if(_todo_wait
)
642 okShell_(file
, line
)(wait_rc
==WAIT_OBJECT_0
,
643 "WaitForSingleObject returned %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 (rc
> 32 && GetFileAttributesA(child_file
) != INVALID_FILE_ATTRIBUTES
)
656 dump_child_(file
, line
);
657 c
= GetPrivateProfileIntA("Child", "Failures", -1, child_file
);
659 winetest_add_failures(c
);
660 /* When NOZONECHECKS is specified the environment variables are not
661 * inherited if the process does not have elevated privileges.
663 if ((mask
& SEE_MASK_NOZONECHECKS
) && skip_shlexec_tests
)
665 okChildInt_(file
, line
, "ShlexecVarLE", 203);
666 okChildString_(file
, line
, "ShlexecVar", "", "");
670 okChildInt_(file
, line
, "ShlexecVarLE", 0);
671 okChildString_(file
, line
, "ShlexecVar", "Present", "Present");
677 #define shell_execute_ex(mask, verb, filename, parameters, directory, class) \
678 shell_execute_ex_(__FILE__, __LINE__, mask, verb, filename, parameters, directory, class)
683 * Functions to create / delete associations wrappers
687 static BOOL
create_test_class(const char* class, BOOL protocol
)
689 HKEY hkey
, hkey_shell
;
692 rc
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
693 KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
, NULL
,
695 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
696 "could not create class %s (rc=%d)\n", class, rc
);
697 if (rc
!= ERROR_SUCCESS
)
702 rc
= RegSetValueExA(hkey
, "URL Protocol", 0, REG_SZ
, (LPBYTE
)"", 1);
703 ok(rc
== ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
706 rc
= RegCreateKeyExA(hkey
, "shell", 0, NULL
, 0,
707 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
708 ok(rc
== ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
711 CloseHandle(hkey_shell
);
715 static BOOL
create_test_association(const char* extension
)
718 char class[MAX_PATH
];
721 sprintf(class, "shlexec%s", extension
);
722 rc
=RegCreateKeyExA(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
724 ok(rc
== ERROR_SUCCESS
|| rc
== ERROR_ACCESS_DENIED
,
725 "could not create association %s (rc=%d)\n", class, rc
);
726 if (rc
!= ERROR_SUCCESS
)
729 rc
=RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
730 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
733 return create_test_class(class, FALSE
);
736 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
737 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
740 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
741 DWORD dwMaxLen
, dwSize
;
742 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
747 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
751 /* Get highest length for keys, values */
752 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
753 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
754 if (ret
) goto cleanup
;
758 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
759 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
761 /* Name too big: alloc a buffer for it */
762 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
764 ret
= ERROR_NOT_ENOUGH_MEMORY
;
770 /* Recursively delete all the subkeys */
774 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
775 NULL
, NULL
, NULL
)) break;
777 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
778 if (ret
) goto cleanup
;
782 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
787 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
788 NULL
, NULL
, NULL
, NULL
)) break;
790 ret
= RegDeleteValueA(hKey
, lpszName
);
791 if (ret
) goto cleanup
;
795 /* Free buffer if allocated */
796 if (lpszName
!= szNameBuf
)
797 HeapFree( GetProcessHeap(), 0, lpszName
);
799 RegCloseKey(hSubKey
);
803 static void delete_test_class(const char* classname
)
805 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, classname
);
808 static void delete_test_association(const char* extension
)
810 char classname
[MAX_PATH
];
812 sprintf(classname
, "shlexec%s", extension
);
813 delete_test_class(classname
);
814 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
817 static void create_test_verb_dde(const char* classname
, const char* verb
,
818 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
819 const char *application
, const char *topic
,
822 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
823 char shell
[MAX_PATH
];
827 strcpy(assoc_desc
, " Assoc ");
828 strcat_param(assoc_desc
, "class", classname
);
829 strcat_param(assoc_desc
, "verb", verb
);
830 sprintf(shell
, "%d", rawcmd
);
831 strcat_param(assoc_desc
, "rawcmd", shell
);
832 strcat_param(assoc_desc
, "cmdtail", cmdtail
);
833 strcat_param(assoc_desc
, "ddeexec", ddeexec
);
834 strcat_param(assoc_desc
, "app", application
);
835 strcat_param(assoc_desc
, "topic", topic
);
836 strcat_param(assoc_desc
, "ifexec", ifexec
);
838 sprintf(shell
, "%s\\shell", classname
);
839 rc
=RegOpenKeyExA(HKEY_CLASSES_ROOT
, shell
, 0,
840 KEY_CREATE_SUB_KEY
, &hkey_shell
);
841 ok(rc
== ERROR_SUCCESS
, "%s key creation failed with %d\n", shell
, rc
);
843 rc
=RegCreateKeyExA(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
844 NULL
, &hkey_verb
, NULL
);
845 ok(rc
== ERROR_SUCCESS
, "%s verb key creation failed with %d\n", verb
, rc
);
847 rc
=RegCreateKeyExA(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
848 NULL
, &hkey_cmd
, NULL
);
849 ok(rc
== ERROR_SUCCESS
, "\'command\' key creation failed with %d\n", rc
);
853 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
857 cmd
=HeapAlloc(GetProcessHeap(), 0, strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
858 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
859 rc
=RegSetValueExA(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
860 ok(rc
== ERROR_SUCCESS
, "setting command failed with %d\n", rc
);
861 HeapFree(GetProcessHeap(), 0, cmd
);
866 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
868 rc
=RegCreateKeyExA(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
869 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
870 ok(rc
== ERROR_SUCCESS
, "\'ddeexec\' key creation failed with %d\n", rc
);
871 rc
=RegSetValueExA(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
873 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
877 rc
=RegCreateKeyExA(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
878 NULL
, &hkey_application
, NULL
);
879 ok(rc
== ERROR_SUCCESS
, "\'application\' key creation failed with %d\n", rc
);
881 rc
=RegSetValueExA(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
882 strlen(application
)+1);
883 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
884 CloseHandle(hkey_application
);
888 rc
=RegCreateKeyExA(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
889 NULL
, &hkey_topic
, NULL
);
890 ok(rc
== ERROR_SUCCESS
, "\'topic\' key creation failed with %d\n", rc
);
891 rc
=RegSetValueExA(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
893 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
894 CloseHandle(hkey_topic
);
898 rc
=RegCreateKeyExA(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
899 NULL
, &hkey_ifexec
, NULL
);
900 ok(rc
== ERROR_SUCCESS
, "\'ifexec\' key creation failed with %d\n", rc
);
901 rc
=RegSetValueExA(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
903 ok(rc
== ERROR_SUCCESS
, "set value failed with %d\n", rc
);
904 CloseHandle(hkey_ifexec
);
906 CloseHandle(hkey_ddeexec
);
909 CloseHandle(hkey_shell
);
910 CloseHandle(hkey_verb
);
911 CloseHandle(hkey_cmd
);
914 /* Creates a class' non-DDE test verb.
915 * This function is meant to be used to create long term test verbs and thus
916 * does not trace them.
918 static void create_test_verb(const char* classname
, const char* verb
,
919 int rawcmd
, const char* cmdtail
)
921 create_test_verb_dde(classname
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
923 reset_association_description();
929 * GetLongPathNameA equivalent that supports Win95 and WinNT
933 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
935 char tmplongpath
[MAX_PATH
];
937 DWORD sp
= 0, lp
= 0;
939 WIN32_FIND_DATAA wfd
;
942 if (!shortpath
|| !shortpath
[0])
945 if (shortpath
[1] == ':')
947 tmplongpath
[0] = shortpath
[0];
948 tmplongpath
[1] = ':';
952 while (shortpath
[sp
])
954 /* check for path delimiters and reproduce them */
955 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
957 if (!lp
|| tmplongpath
[lp
-1] != '\\')
959 /* strip double "\\" */
960 tmplongpath
[lp
++] = '\\';
962 tmplongpath
[lp
] = 0; /* terminate string */
968 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
970 tmplongpath
[lp
++] = *p
++;
971 tmplongpath
[lp
++] = *p
++;
973 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
974 tmplen
= p
- (shortpath
+ sp
);
975 lstrcpynA(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
976 /* Check if the file exists and use the existing file name */
977 goit
= FindFirstFileA(tmplongpath
, &wfd
);
978 if (goit
== INVALID_HANDLE_VALUE
)
981 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
982 lp
+= strlen(tmplongpath
+ lp
);
985 tmplen
= strlen(shortpath
) - 1;
986 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
987 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
988 tmplongpath
[lp
++] = shortpath
[tmplen
];
991 tmplen
= strlen(tmplongpath
) + 1;
992 if (tmplen
<= longlen
)
994 strcpy(longpath
, tmplongpath
);
995 tmplen
--; /* length without 0 */
1008 static const char* testfiles
[]=
1010 "%s\\test file.shlexec",
1011 "%s\\%%nasty%% $file.shlexec",
1012 "%s\\test file.noassoc",
1013 "%s\\test file.noassoc.shlexec",
1014 "%s\\test file.shlexec.noassoc",
1015 "%s\\test_shortcut_shlexec.lnk",
1016 "%s\\test_shortcut_exe.lnk",
1017 "%s\\test file.shl",
1018 "%s\\test file.shlfoo",
1019 "%s\\test file.sha",
1020 "%s\\test file.sfe",
1021 "%s\\test file.shlproto",
1022 "%s\\masked file.shlexec",
1024 "%s\\test file.sde",
1025 "%s\\test file.exe",
1027 "%s\\simple.shlexec",
1028 "%s\\drawback_file.noassoc",
1029 "%s\\drawback_file.noassoc foo.shlexec",
1030 "%s\\drawback_nonexist.noassoc foo.shlexec",
1037 const char* basename
;
1042 static filename_tests_t filename_tests
[]=
1044 /* Test bad / nonexistent filenames */
1045 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1046 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
1048 /* Standard tests */
1049 {NULL
, "%s\\test file.shlexec", 0x0, 33},
1050 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
1051 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
1052 {NULL
, "%s/test file.shlexec", 0x0, 33},
1054 /* Test filenames with no association */
1055 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1057 /* Test double extensions */
1058 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
1059 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
1061 /* Test alternate verbs */
1062 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
1063 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
1065 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
1066 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
1068 {"notaverb", "%s\\test file.shlexec", 0x10, SE_ERR_NOASSOC
},
1070 {"averb", "%s\\test file.sha", 0x10, 33},
1072 /* Test file masked due to space */
1073 {NULL
, "%s\\masked file.shlexec", 0x0, 33},
1074 /* Test if quoting prevents the masking */
1075 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
1076 /* Test with incorrect quote */
1077 {NULL
, "\"%s\\masked file.shlexec", 0x0, SE_ERR_FNF
},
1079 /* Test extension / URI protocol collision */
1080 {NULL
, "%s\\test file.shlproto", 0x0, SE_ERR_NOASSOC
},
1085 static filename_tests_t noquotes_tests
[]=
1087 /* Test unquoted '%1' thingies */
1088 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
1089 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
1090 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
1095 static void test_lpFile_parsed(void)
1097 char fileA
[MAX_PATH
];
1100 if (skip_shlexec_tests
)
1102 skip("No filename parsing tests due to lack of .shlexec association\n");
1106 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1107 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
1108 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1109 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1111 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
1112 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
1113 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1114 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1115 "failed: rc=%lu\n", rc
);
1117 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
1118 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
1119 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1120 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1122 /* ""command"" not works on wine (and real win9x and w2k) */
1123 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
1124 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1125 todo_wine
okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
1126 "failed: rc=%lu\n", rc
);
1128 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
1129 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
1130 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
1131 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1133 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
1134 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
1135 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1138 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
1139 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
1141 /* test SEE_MASK_DOENVSUBST works */
1142 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1143 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
1144 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1146 /* quoted lpFile does not work on real win95 and nt4 */
1147 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1148 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
1149 okShell(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
1150 "failed: rc=%lu\n", rc
);
1156 const char* args
[11];
1160 static const cmdline_tests_t cmdline_tests
[] =
1165 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
1166 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
1168 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
1169 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
1171 {"exe arg\"one\" \"second\"arg thirdarg ",
1172 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
1174 /* Don't lose unclosed quoted arguments */
1175 {"exe arg1 \"unclosed",
1176 {"exe", "arg1", "unclosed", NULL
}, 0},
1179 {"exe", "arg1", "", NULL
}, 0},
1181 /* cmd's metacharacters have no special meaning */
1182 {"exe \"one^\" \"arg\"&two three|four",
1183 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
1185 /* Environment variables are not interpreted either */
1187 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
1189 /* If not followed by a quote, backslashes go through as is */
1190 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
1191 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1193 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
1194 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1196 /* When followed by a quote their number is halved and the remainder
1199 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1200 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1202 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1203 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1205 /* One can put a quote in an unquoted string by tripling it, that is in
1206 * effect quoting it like so """ -> ". The general rule is as follows:
1207 * 3n quotes -> n quotes
1208 * 3n+1 quotes -> n quotes plus start of a quoted string
1209 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1210 * Nicely, when n is 0 we get the standard rules back.
1212 {"exe two\"\"quotes next",
1213 {"exe", "twoquotes", "next", NULL
}, 0},
1215 {"exe three\"\"\"quotes next",
1216 {"exe", "three\"quotes", "next", NULL
}, 0},
1218 {"exe four\"\"\"\" quotes\" next 4%3=1",
1219 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0},
1221 {"exe five\"\"\"\"\"quotes next",
1222 {"exe", "five\"quotes", "next", NULL
}, 0},
1224 {"exe six\"\"\"\"\"\"quotes next",
1225 {"exe", "six\"\"quotes", "next", NULL
}, 0},
1227 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1228 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0},
1230 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1231 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0},
1233 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1234 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1236 /* Inside a quoted string the opening quote is added to the set of
1237 * consecutive quotes to get the effective quotes count. This gives:
1238 * 1+3n quotes -> n quotes
1239 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1240 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1242 {"exe \"two\"\"quotes next",
1243 {"exe", "two\"quotes", "next", NULL
}, 0},
1245 {"exe \"two\"\" next",
1246 {"exe", "two\"", "next", NULL
}, 0},
1248 {"exe \"three\"\"\" quotes\" next 4%3=1",
1249 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0},
1251 {"exe \"four\"\"\"\"quotes next",
1252 {"exe", "four\"quotes", "next", NULL
}, 0},
1254 {"exe \"five\"\"\"\"\"quotes next",
1255 {"exe", "five\"\"quotes", "next", NULL
}, 0},
1257 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1258 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0},
1260 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1261 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0},
1263 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1264 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0},
1266 /* Escaped consecutive quotes are fun */
1267 {"exe \"the crazy \\\\\"\"\"\\\\\" quotes",
1268 {"exe", "the crazy \\\"\\", "quotes", NULL
}, 0},
1270 /* The executable path has its own rules!!!
1271 * - Backslashes have no special meaning.
1272 * - If the first character is a quote, then the second quote ends the
1274 * - The previous rule holds even if the next character is not a space!
1275 * - If the first character is not a quote, then quotes have no special
1276 * meaning either and the executable path stops at the first space.
1277 * - The consecutive quotes rules don't apply either.
1278 * - Even if there is no space between the executable path and the first
1279 * argument, the latter is parsed using the regular rules.
1281 {"exe\"file\"path arg1",
1282 {"exe\"file\"path", "arg1", NULL
}, 0},
1284 {"exe\"file\"path\targ1",
1285 {"exe\"file\"path", "arg1", NULL
}, 0},
1287 {"exe\"path\\ arg1",
1288 {"exe\"path\\", "arg1", NULL
}, 0},
1290 {"\\\"exe \"arg one\"",
1291 {"\\\"exe", "arg one", NULL
}, 0},
1293 {"\"spaced exe\" \"next arg\"",
1294 {"spaced exe", "next arg", NULL
}, 0},
1296 {"\"spaced exe\"\t\"next arg\"",
1297 {"spaced exe", "next arg", NULL
}, 0},
1299 {"\"exe\"arg\" one\" argtwo",
1300 {"exe", "arg one", "argtwo", NULL
}, 0},
1302 {"\"spaced exe\\\"arg1 arg2",
1303 {"spaced exe\\", "arg1", "arg2", NULL
}, 0},
1306 {"two", " arg1 ", NULL
}, 0},
1308 {"\"three\"\"\" arg2",
1309 {"three", "", "arg2", NULL
}, 0},
1311 {"\"four\"\"\"\"arg1",
1312 {"four", "\"arg1", NULL
}, 0},
1314 /* If the first character is a space then the executable path is empty */
1315 {" \"arg\"one argtwo",
1316 {"", "argone", "argtwo", NULL
}, 0},
1321 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1323 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1329 /* trace("----- cmd='%s'\n", test->cmd); */
1330 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, sizeof(cmdW
)/sizeof(*cmdW
));
1331 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1332 if (argsW
== NULL
&& cl2a_count
== -1)
1334 win_skip("CommandLineToArgvW not implemented, skipping\n");
1337 ok(!argsW
[cl2a_count
] || broken(argsW
[cl2a_count
] != NULL
) /* before Vista */,
1338 "expected NULL-terminated list of commandline arguments\n");
1341 while (test
->args
[count
])
1343 todo_wine_if(test
->todo
& 0x1)
1344 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1346 for (i
= 0; i
< cl2a_count
; i
++)
1350 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, sizeof(argW
)/sizeof(*argW
));
1351 todo_wine_if(test
->todo
& (1 << (i
+4)))
1352 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1354 else todo_wine_if(test
->todo
& 0x1)
1355 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1362 static void test_commandline2argv(void)
1364 static const WCHAR exeW
[] = {'e','x','e',0};
1365 const cmdline_tests_t
* test
;
1366 WCHAR strW
[MAX_PATH
];
1371 test
= cmdline_tests
;
1374 if (!test_one_cmdline(test
))
1379 SetLastError(0xdeadbeef);
1380 args
= CommandLineToArgvW(exeW
, NULL
);
1381 le
= GetLastError();
1382 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1384 SetLastError(0xdeadbeef);
1385 args
= CommandLineToArgvW(NULL
, NULL
);
1386 le
= GetLastError();
1387 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1390 args
= CommandLineToArgvW(strW
, &numargs
);
1391 ok(numargs
== 1 || broken(numargs
> 1), "expected 1 args, got %d\n", numargs
);
1392 ok(!args
|| (!args
[numargs
] || broken(args
[numargs
] != NULL
) /* before Vista */),
1393 "expected NULL-terminated list of commandline arguments\n");
1396 GetModuleFileNameW(NULL
, strW
, sizeof(strW
)/sizeof(*strW
));
1397 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
));
1399 if (args
) LocalFree(args
);
1402 /* The goal here is to analyze how ShellExecute() builds the command that
1403 * will be run. The tricky part is that there are three transformation
1404 * steps between the 'parameters' string we pass to ShellExecute() and the
1405 * argument list we observe in the child process:
1406 * - The parsing of 'parameters' string into individual arguments. The tests
1407 * show this is done differently from both CreateProcess() and
1408 * CommandLineToArgv()!
1409 * - The way the command 'formatting directives' such as %1, %2, etc are
1411 * - And the way the resulting command line is then parsed to yield the
1412 * argument list we check.
1419 cmdline_tests_t cmd
;
1420 cmdline_tests_t broken
;
1423 static const argify_tests_t argify_tests
[] =
1425 /* Start with three simple parameters. Notice that one can reorder and
1426 * duplicate the parameters. Also notice how %* take the raw input
1427 * parameters string, including the trailing spaces, no matter what
1428 * arguments have already been used.
1430 {"Params232S", "p2 p3 p4 ", 0xc2,
1431 {" p2 p3 \"p2\" \"p2 p3 p4 \"",
1432 {"", "p2", "p3", "p2", "p2 p3 p4 ", NULL
}, 0}},
1434 /* Unquoted argument references like %2 don't automatically quote their
1435 * argument. Similarly, when they are quoted they don't escape the quotes
1436 * that their argument may contain.
1438 {"Params232S", "\"p two\" p3 p4 ", 0x3f3,
1439 {" p two p3 \"p two\" \"\"p two\" p3 p4 \"",
1440 {"", "p", "two", "p3", "p two", "p", "two p3 p4 ", NULL
}, 0}},
1442 /* Only single digits are supported so only %1 to %9. Shown here with %20
1443 * because %10 is a pain.
1445 {"Params20", "p", 0,
1447 {"", "p0", NULL
}, 0}},
1449 /* Only (double-)quotes have a special meaning. */
1450 {"Params23456", "'p2 p3` p4\\ $even", 0x40,
1451 {" \"'p2\" \"p3`\" \"p4\\\" \"$even\" \"\"",
1452 {"", "'p2", "p3`", "p4\" $even \"", NULL
}, 0}},
1454 {"Params23456", "p=2 p-3 p4\tp4\rp4\np4", 0x1c2,
1455 {" \"p=2\" \"p-3\" \"p4\tp4\rp4\np4\" \"\" \"\"",
1456 {"", "p=2", "p-3", "p4\tp4\rp4\np4", "", "", NULL
}, 0}},
1458 /* In unquoted strings, quotes are treated are a parameter separator just
1459 * like spaces! However they can be doubled to get a literal quote.
1461 * 2n quotes -> n quotes
1462 * 2n+1 quotes -> n quotes and a parameter separator
1464 {"Params23456789", "one\"quote \"p four\" one\"quote p7", 0xff3,
1465 {" \"one\" \"quote\" \"p four\" \"one\" \"quote\" \"p7\" \"\" \"\"",
1466 {"", "one", "quote", "p four", "one", "quote", "p7", "", "", NULL
}, 0}},
1468 {"Params23456789", "two\"\"quotes \"p three\" two\"\"quotes p5", 0xf2,
1469 {" \"two\"quotes\" \"p three\" \"two\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1470 {"", "twoquotes p", "three twoquotes", "p5", "", "", "", "", NULL
}, 0}},
1472 {"Params23456789", "three\"\"\"quotes \"p four\" three\"\"\"quotes p6", 0xff3,
1473 {" \"three\"\" \"quotes\" \"p four\" \"three\"\" \"quotes\" \"p6\" \"\" \"\"",
1474 {"", "three\"", "quotes", "p four", "three\"", "quotes", "p6", "", "", NULL
}, 0}},
1476 {"Params23456789", "four\"\"\"\"quotes \"p three\" four\"\"\"\"quotes p5", 0xf3,
1477 {" \"four\"\"quotes\" \"p three\" \"four\"\"quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1478 {"", "four\"quotes p", "three fourquotes p5 \"", "", "", "", NULL
}, 0}},
1480 /* Quoted strings cannot be continued by tacking on a non space character
1483 {"Params23456", "\"p two\"p3 \"p four\"p5 p6", 0x1f3,
1484 {" \"p two\" \"p3\" \"p four\" \"p5\" \"p6\"",
1485 {"", "p two", "p3", "p four", "p5", "p6", NULL
}, 0}},
1487 /* In quoted strings, the quotes are halved and an odd number closes the
1488 * string. Specifically:
1489 * 2n quotes -> n quotes
1490 * 2n+1 quotes -> n quotes and closes the string and hence the parameter
1492 {"Params23456789", "\"one q\"uote \"p four\" \"one q\"uote p7", 0xff3,
1493 {" \"one q\" \"uote\" \"p four\" \"one q\" \"uote\" \"p7\" \"\" \"\"",
1494 {"", "one q", "uote", "p four", "one q", "uote", "p7", "", "", NULL
}, 0}},
1496 {"Params23456789", "\"two \"\" quotes\" \"p three\" \"two \"\" quotes\" p5", 0x1ff3,
1497 {" \"two \" quotes\" \"p three\" \"two \" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1498 {"", "two ", "quotes p", "three two", " quotes", "p5", "", "", "", "", NULL
}, 0}},
1500 {"Params23456789", "\"three q\"\"\"uotes \"p four\" \"three q\"\"\"uotes p7", 0xff3,
1501 {" \"three q\"\" \"uotes\" \"p four\" \"three q\"\" \"uotes\" \"p7\" \"\" \"\"",
1502 {"", "three q\"", "uotes", "p four", "three q\"", "uotes", "p7", "", "", NULL
}, 0}},
1504 {"Params23456789", "\"four \"\"\"\" quotes\" \"p three\" \"four \"\"\"\" quotes\" p5", 0xff3,
1505 {" \"four \"\" quotes\" \"p three\" \"four \"\" quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1506 {"", "four \"", "quotes p", "three four", "", "quotes p5 \"", "", "", "", NULL
}, 0}},
1508 /* The quoted string rules also apply to consecutive quotes at the start
1509 * of a parameter but don't count the opening quote!
1511 {"Params23456789", "\"\"twoquotes \"p four\" \"\"twoquotes p7", 0xbf3,
1512 {" \"\" \"twoquotes\" \"p four\" \"\" \"twoquotes\" \"p7\" \"\" \"\"",
1513 {"", "", "twoquotes", "p four", "", "twoquotes", "p7", "", "", NULL
}, 0}},
1515 {"Params23456789", "\"\"\"three quotes\" \"p three\" \"\"\"three quotes\" p5", 0x6f3,
1516 {" \"\"three quotes\" \"p three\" \"\"three quotes\" \"p5\" \"\" \"\" \"\" \"\"",
1517 {"", "three", "quotes p", "three \"three", "quotes p5 \"", "", "", "", NULL
}, 0}},
1519 {"Params23456789", "\"\"\"\"fourquotes \"p four\" \"\"\"\"fourquotes p7", 0xbf3,
1520 {" \"\"\" \"fourquotes\" \"p four\" \"\"\" \"fourquotes\" \"p7\" \"\" \"\"",
1521 {"", "\"", "fourquotes", "p four", "\"", "fourquotes", "p7", "", "", NULL
}, 0}},
1523 /* An unclosed quoted string gets lost! */
1524 {"Params23456", "p2 \"p3\" \"p4 is lost", 0x1c3,
1525 {" \"p2\" \"p3\" \"\" \"\" \"\"",
1526 {"", "p2", "p3", "", "", "", NULL
}, 0},
1527 {" \"p2\" \"p3\" \"p3\" \"\" \"\"",
1528 {"", "p2", "p3", "p3", "", "", NULL
}, 0}},
1530 /* Backslashes have no special meaning even when preceding quotes. All
1531 * they do is start an unquoted string.
1533 {"Params23456", "\\\"p\\three \"pfour\\\" pfive", 0x73,
1534 {" \"\\\" \"p\\three\" \"pfour\\\" \"pfive\" \"\"",
1535 {"", "\" p\\three pfour\"", "pfive", "", NULL
}, 0}},
1537 /* Environment variables are left untouched. */
1538 {"Params23456", "%TMPDIR% %t %c", 0,
1539 {" \"%TMPDIR%\" \"%t\" \"%c\" \"\" \"\"",
1540 {"", "%TMPDIR%", "%t", "%c", "", "", NULL
}, 0}},
1542 /* %~2 is equivalent to %*. However %~3 and higher include the spaces
1543 * before the parameter!
1544 * (but not the previous parameter's closing quote fortunately)
1546 {"Params2345Etc", "p2 p3 \"p4\" p5 p6 ", 0x3f3,
1547 {" ~2=\"p2 p3 \"p4\" p5 p6 \" ~3=\" p3 \"p4\" p5 p6 \" ~4=\" \"p4\" p5 p6 \" ~5= p5 p6 ",
1548 {"", "~2=p2 p3 p4 p5 p6 ", "~3= p3 p4 p5 p6 ", "~4= p4 p5 p6 ", "~5=", "p5", "p6", NULL
}, 0}},
1550 /* %~n works even if there is no nth parameter. */
1551 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 ", 0x12,
1553 {"", "~9= ", NULL
}, 0}},
1555 {"Params9Etc", "p2 p3 p4 p5 p6 p7 ", 0x12,
1557 {"", "~9=", NULL
}, 0}},
1559 /* The %~n directives also transmit the tenth parameter and beyond. */
1560 {"Params9Etc", "p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 and beyond!", 0x12,
1561 {" ~9=\" p9 p10 p11 and beyond!\"",
1562 {"", "~9= p9 p10 p11 and beyond!", NULL
}, 0}},
1564 /* Bad formatting directives lose their % sign, except those followed by
1565 * a tilde! Environment variables are not expanded but lose their % sign.
1567 {"ParamsBad", "p2 p3 p4 p5", 0x12,
1568 {" \"% - %~ %~0 %~1 %~a %~* a b c TMPDIR\"",
1569 {"", "% - %~ %~0 %~1 %~a %~* a b c TMPDIR", NULL
}, 0}},
1571 {NULL
, NULL
, 0, {NULL
, {NULL
}, 0}}
1574 static void test_argify(void)
1576 BOOL has_cl2a
= TRUE
;
1577 char fileA
[MAX_PATH
], params
[2*MAX_PATH
+12];
1579 const argify_tests_t
* test
;
1580 const cmdline_tests_t
*bad
;
1584 /* Test with a long parameter */
1585 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1586 fileA
[rc
] = 'a' + rc
% 26;
1587 fileA
[MAX_PATH
-1] = '\0';
1588 sprintf(params
, "shlexec \"%s\" %s", child_file
, fileA
);
1590 /* We need NOZONECHECKS on Win2003 to block a dialog */
1591 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
, NULL
, NULL
);
1592 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1593 okChildInt("argcA", 4);
1594 okChildPath("argvA3", fileA
);
1596 if (skip_shlexec_tests
)
1598 skip("No argify tests due to lack of .shlexec association\n");
1602 create_test_verb("shlexec.shlexec", "Params232S", 0, "Params232S %2 %3 \"%2\" \"%*\"");
1603 create_test_verb("shlexec.shlexec", "Params23456", 0, "Params23456 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\"");
1604 create_test_verb("shlexec.shlexec", "Params23456789", 0, "Params23456789 \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\"");
1605 create_test_verb("shlexec.shlexec", "Params2345Etc", 0, "Params2345Etc ~2=\"%~2\" ~3=\"%~3\" ~4=\"%~4\" ~5=%~5");
1606 create_test_verb("shlexec.shlexec", "Params9Etc", 0, "Params9Etc ~9=\"%~9\"");
1607 create_test_verb("shlexec.shlexec", "Params20", 0, "Params20 \"%20\"");
1608 create_test_verb("shlexec.shlexec", "ParamsBad", 0, "ParamsBad \"%% %- %~ %~0 %~1 %~a %~* %a %b %c %TMPDIR%\"");
1610 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1612 test
= argify_tests
;
1613 while (test
->params
)
1615 bad
= test
->broken
.cmd
? &test
->broken
: &test
->cmd
;
1617 /* trace("***** verb='%s' params='%s'\n", test->verb, test->params); */
1618 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
, test
->verb
, fileA
, test
->params
, NULL
, NULL
);
1619 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
1622 while (test
->cmd
.args
[count
])
1624 /* +4 for the shlexec arguments, -1 because of the added ""
1625 * argument for the CommandLineToArgvW() tests.
1627 todo_wine_if(test
->todo
& 0x1)
1628 okChildInt("argcA", 4 + count
- 1);
1630 cmd
= getChildString("Child", "cmdlineA");
1631 /* Our commands are such that the verb immediately precedes the
1632 * part we are interested in.
1634 if (cmd
) cmd
= strstr(cmd
, test
->verb
);
1635 if (cmd
) cmd
+= strlen(test
->verb
);
1636 if (!cmd
) cmd
= "(null)";
1637 todo_wine_if(test
->todo
& 0x2)
1638 okShell(!strcmp(cmd
, test
->cmd
.cmd
) || broken(!strcmp(cmd
, bad
->cmd
)),
1639 "the cmdline is '%s' instead of '%s'\n", cmd
, test
->cmd
.cmd
);
1641 for (i
= 0; i
< count
- 1; i
++)
1644 sprintf(argname
, "argvA%d", 4 + i
);
1645 todo_wine_if(test
->todo
& (1 << (i
+4)))
1646 okChildStringBroken(argname
, test
->cmd
.args
[i
+1], bad
->args
[i
+1]);
1650 has_cl2a
= test_one_cmdline(&(test
->cmd
));
1655 static void test_filename(void)
1657 char filename
[MAX_PATH
];
1658 const filename_tests_t
* test
;
1662 if (skip_shlexec_tests
)
1664 skip("No ShellExecute/filename tests due to lack of .shlexec association\n");
1668 test
=filename_tests
;
1669 while (test
->basename
)
1671 BOOL quotedfile
= FALSE
;
1673 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1675 win_skip("Skipping shellexecute of file with unassociated extension\n");
1680 sprintf(filename
, test
->basename
, tmpdir
);
1681 if (strchr(filename
, '/'))
1691 if ((test
->todo
& 0x40)==0)
1693 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1697 char quoted
[MAX_PATH
+ 2];
1700 sprintf(quoted
, "\"%s\"", filename
);
1701 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1705 okShell(rc
==test
->rc
||
1706 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1707 "failed: rc=%ld err=%u\n", rc
, GetLastError());
1711 todo_wine_if(test
->todo
& 0x2)
1712 okChildInt("argcA", 5);
1713 verb
=(test
->verb
? test
->verb
: "Open");
1714 todo_wine_if(test
->todo
& 0x4)
1715 okChildString("argvA3", verb
);
1716 todo_wine_if(test
->todo
& 0x8)
1717 okChildPath("argvA4", filename
);
1722 test
=noquotes_tests
;
1723 while (test
->basename
)
1725 sprintf(filename
, test
->basename
, tmpdir
);
1726 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1729 todo_wine_if(test
->todo
& 0x1)
1730 okShell(rc
==test
->rc
, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1737 verb
=(test
->verb
? test
->verb
: "Open");
1738 todo_wine_if(test
->todo
& 0x4)
1739 okChildString("argvA3", verb
);
1747 space
=strchr(str
, ' ');
1750 sprintf(attrib
, "argvA%d", count
);
1751 todo_wine_if(test
->todo
& 0x8)
1752 okChildPath(attrib
, str
);
1758 todo_wine_if(test
->todo
& 0x2)
1759 okChildInt("argcA", count
);
1764 if (dllver
.dwMajorVersion
!= 0)
1766 /* The more recent versions of shell32.dll accept quoted filenames
1767 * while older ones (e.g. 4.00) don't. Still we want to test this
1768 * because IE 6 depends on the new behavior.
1769 * One day we may need to check the exact version of the dll but for
1770 * now making sure DllGetVersion() is present is sufficient.
1772 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1773 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1774 okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1775 okChildInt("argcA", 5);
1776 okChildString("argvA3", "Open");
1777 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1778 okChildPath("argvA4", filename
);
1781 sprintf(filename
, "\"%s\\test file.sha\"", tmpdir
);
1782 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1783 todo_wine
okShell(rc
> 32, "failed: rc=%ld err=%u\n", rc
, GetLastError());
1784 okChildInt("argcA", 5);
1785 todo_wine
okChildString("argvA3", "averb");
1786 sprintf(filename
, "%s\\test file.sha", tmpdir
);
1787 todo_wine
okChildPath("argvA4", filename
);
1792 const char* urlprefix
;
1793 const char* basename
;
1798 #define URL_SUCCESS 0x1
1799 #define USE_COLON 0x2
1800 #define USE_BSLASH 0x4
1802 static fileurl_tests_t fileurl_tests
[]=
1804 /* How many slashes does it take... */
1805 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1806 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1807 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1808 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1809 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1810 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1811 {"file://///", "%s\\test file.shlexec", 0, 0},
1813 /* Test with Windows-style paths */
1814 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0},
1815 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0},
1817 /* Check handling of hostnames */
1818 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1819 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0},
1820 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0},
1821 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0},
1822 {"file://::1/", "%s\\test file.shlexec", 0, 0},
1823 {"file://notahost/", "%s\\test file.shlexec", 0, 0},
1825 /* Environment variables are not expanded in URLs */
1826 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1827 {"file:///", "%%TMPDIR%%\\test file.shlexec", 0, 0},
1829 /* Test shortcuts vs. URLs */
1830 {"file://///", "%s\\test_shortcut_shlexec.lnk", 0, 0x1d},
1832 /* Confuse things by mixing protocols */
1833 {"file://", "shlproto://foo/bar", USE_COLON
, 0},
1838 static void test_fileurls(void)
1840 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1841 char command
[MAX_PATH
];
1842 const fileurl_tests_t
* test
;
1846 if (skip_shlexec_tests
)
1848 skip("No file URL tests due to lack of .shlexec association\n");
1852 rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
, NULL
,
1853 "file:///nosuchfile.shlexec", NULL
, NULL
, NULL
);
1856 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1860 get_long_path_name(tmpdir
, longtmpdir
, sizeof(longtmpdir
)/sizeof(*longtmpdir
));
1861 SetEnvironmentVariableA("urlprefix", "file:///");
1864 while (test
->basename
)
1866 /* Build the file URL */
1867 sprintf(filename
, test
->basename
, longtmpdir
);
1868 strcpy(fileurl
, test
->urlprefix
);
1869 strcat(fileurl
, filename
);
1870 s
= fileurl
+ strlen(test
->urlprefix
);
1873 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1875 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1880 /* Test it first with FindExecutable() */
1881 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1882 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1884 /* Then ShellExecute() */
1885 if ((test
->todo
& 0x10) == 0)
1886 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1888 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1889 if (bad_shellexecute
)
1891 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1894 if (test
->flags
& URL_SUCCESS
)
1896 todo_wine_if(test
->todo
& 0x1)
1897 okShell(rc
> 32, "failed: bad rc=%lu\n", rc
);
1901 todo_wine_if(test
->todo
& 0x1)
1902 okShell(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1903 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1904 "failed: bad rc=%lu\n", rc
);
1908 todo_wine_if(test
->todo
& 0x2)
1909 okChildInt("argcA", 5);
1910 todo_wine_if(test
->todo
& 0x4)
1911 okChildString("argvA3", "Open");
1912 todo_wine_if(test
->todo
& 0x8)
1913 okChildPath("argvA4", filename
);
1918 SetEnvironmentVariableA("urlprefix", NULL
);
1921 static void test_urls(void)
1926 if (!create_test_class("fakeproto", FALSE
))
1928 skip("Unable to create 'fakeproto' class for URL tests\n");
1931 create_test_verb("fakeproto", "open", 0, "URL %1");
1933 create_test_class("shlpaverb", TRUE
);
1934 create_test_verb("shlpaverb", "averb", 0, "PAVerb \"%1\"");
1936 /* Protocols must be properly declared */
1937 rc
= shell_execute(NULL
, "notaproto://foo", NULL
, NULL
);
1938 ok(rc
== SE_ERR_NOASSOC
|| broken(rc
== SE_ERR_ACCESSDENIED
),
1939 "%s returned %lu\n", shell_call
, rc
);
1941 rc
= shell_execute(NULL
, "fakeproto://foo/bar", NULL
, NULL
);
1942 todo_wine
ok(rc
== SE_ERR_NOASSOC
|| broken(rc
== SE_ERR_ACCESSDENIED
),
1943 "%s returned %lu\n", shell_call
, rc
);
1945 /* Here's a real live one */
1946 rc
= shell_execute(NULL
, "shlproto://foo/bar", NULL
, NULL
);
1947 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1948 okChildInt("argcA", 5);
1949 okChildString("argvA3", "URL");
1950 okChildString("argvA4", "shlproto://foo/bar");
1952 /* Check default verb detection */
1953 rc
= shell_execute(NULL
, "shlpaverb://foo/bar", NULL
, NULL
);
1954 todo_wine
ok(rc
> 32 || /* XP+IE7 - Win10 */
1955 broken(rc
== SE_ERR_NOASSOC
), /* XP+IE6 */
1956 "%s failed: rc=%lu\n", shell_call
, rc
);
1959 okChildInt("argcA", 5);
1960 todo_wine
okChildString("argvA3", "PAVerb");
1961 todo_wine
okChildString("argvA4", "shlpaverb://foo/bar");
1964 /* But alternative verbs are a recent feature! */
1965 rc
= shell_execute("averb", "shlproto://foo/bar", NULL
, NULL
);
1966 ok(rc
> 32 || /* Win8 - Win10 */
1967 broken(rc
== SE_ERR_ACCESSDENIED
), /* XP - Win7 */
1968 "%s failed: rc=%lu\n", shell_call
, rc
);
1971 okChildString("argvA3", "AVerb");
1972 okChildString("argvA4", "shlproto://foo/bar");
1975 /* A .lnk ending does not turn a URL into a shortcut */
1976 todo_wait rc
= shell_execute(NULL
, "shlproto://foo/bar.lnk", NULL
, NULL
);
1977 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1978 okChildInt("argcA", 5);
1979 todo_wine
okChildString("argvA3", "URL");
1980 todo_wine
okChildString("argvA4", "shlproto://foo/bar.lnk");
1982 /* Neither does a .exe extension */
1983 rc
= shell_execute(NULL
, "shlproto://foo/bar.exe", NULL
, NULL
);
1984 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1985 okChildInt("argcA", 5);
1986 okChildString("argvA3", "URL");
1987 okChildString("argvA4", "shlproto://foo/bar.exe");
1989 /* But a class name overrides it */
1990 rc
= shell_execute(NULL
, "shlproto://foo/bar", "shlexec.shlexec", NULL
);
1991 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1992 okChildInt("argcA", 5);
1993 okChildString("argvA3", "URL");
1994 okChildString("argvA4", "shlproto://foo/bar");
1996 /* Environment variables are expanded in URLs (but not in file URLs!) */
1997 rc
= shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
1998 NULL
, "shlproto://%TMPDIR%/bar", NULL
, NULL
, NULL
);
1999 okShell(rc
> 32, "failed: rc=%lu\n", rc
);
2000 okChildInt("argcA", 5);
2001 sprintf(url
, "shlproto://%s/bar", tmpdir
);
2002 okChildString("argvA3", "URL");
2003 okChildStringBroken("argvA4", url
, "shlproto://%TMPDIR%/bar");
2005 /* But only after the path has been identified as a URL */
2006 SetEnvironmentVariableA("urlprefix", "shlproto:///");
2007 rc
= shell_execute(NULL
, "%urlprefix%foo", NULL
, NULL
);
2008 todo_wine
ok(rc
== SE_ERR_FNF
, "%s returned %lu\n", shell_call
, rc
);
2009 SetEnvironmentVariableA("urlprefix", NULL
);
2011 delete_test_class("fakeproto");
2012 delete_test_class("shlpaverb");
2015 static void test_find_executable(void)
2017 char notepad_path
[MAX_PATH
];
2018 char filename
[MAX_PATH
];
2019 char command
[MAX_PATH
];
2020 const filename_tests_t
* test
;
2023 if (!create_test_association(".sfe"))
2025 skip("Unable to create association for '.sfe'\n");
2028 create_test_verb("shlexec.sfe", "Open", 1, "%1");
2030 /* Don't test FindExecutable(..., NULL), it always crashes */
2032 strcpy(command
, "your word");
2033 if (0) /* Can crash on Vista! */
2035 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
2036 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
2037 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
2040 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
2041 strcat( notepad_path
, "\\notepad.exe" );
2043 /* Search for something that should be in the system-wide search path (no default directory) */
2044 strcpy(command
, "your word");
2045 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
2046 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
2047 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
2049 /* Search for something that should be in the system-wide search path (with default directory) */
2050 strcpy(command
, "your word");
2051 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
2052 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
2053 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
2055 strcpy(command
, "your word");
2056 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
2057 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
2058 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
2060 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
2061 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2062 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2063 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
2065 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
2066 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2068 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
2069 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2071 delete_test_association(".sfe");
2073 if (!create_test_association(".shl"))
2075 skip("Unable to create association for '.shl'\n");
2078 create_test_verb("shlexec.shl", "Open", 0, "Open");
2080 sprintf(filename
, "%s\\test file.shl", tmpdir
);
2081 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2082 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
2084 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
2085 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2087 delete_test_association(".shl");
2091 /* On Windows XP and 2003 FindExecutable() is completely broken.
2092 * Probably what it does is convert the filename to 8.3 format,
2093 * which as a side effect converts the '.shlfoo' extension to '.shl',
2094 * and then tries to find an association for '.shl'. This means it
2095 * will normally fail on most extensions with more than 3 characters,
2096 * like '.mpeg', etc.
2097 * Also it means we cannot do any other test.
2099 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
2103 if (skip_shlexec_tests
)
2105 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2109 test
=filename_tests
;
2110 while (test
->basename
)
2112 sprintf(filename
, test
->basename
, tmpdir
);
2113 if (strchr(filename
, '/'))
2124 /* Win98 does not '\0'-terminate command! */
2125 memset(command
, '\0', sizeof(command
));
2126 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
2129 todo_wine_if(test
->todo
& 0x10)
2130 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
2134 equal
=strcmp(command
, argv0
) == 0 ||
2135 /* NT4 returns an extra 0x8 character! */
2136 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
2137 todo_wine_if(test
->todo
& 0x20)
2138 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
2139 filename
, command
, argv0
);
2146 static filename_tests_t lnk_tests
[]=
2148 /* Pass bad / nonexistent filenames as a parameter */
2149 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
2150 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
2152 /* Pass regular paths as a parameter */
2153 {NULL
, "%s\\test file.shlexec", 0xa, 33},
2154 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
2156 /* Pass filenames with no association as a parameter */
2157 {NULL
, "%s\\test file.noassoc", 0xa, 33},
2162 static void test_lnks(void)
2164 char filename
[MAX_PATH
];
2165 char params
[MAX_PATH
];
2166 const filename_tests_t
* test
;
2169 if (skip_shlexec_tests
)
2170 skip("No FindExecutable/filename tests due to lack of .shlexec association\n");
2173 /* Should open through our association */
2174 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2175 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2176 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2177 okChildInt("argcA", 5);
2178 okChildString("argvA3", "Open");
2179 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2180 get_long_path_name(params
, filename
, sizeof(filename
));
2181 okChildPath("argvA4", filename
);
2183 todo_wait rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
2184 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2185 okChildInt("argcA", 5);
2186 todo_wine
okChildString("argvA3", "Open");
2187 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
2188 get_long_path_name(params
, filename
, sizeof(filename
));
2189 todo_wine
okChildPath("argvA4", filename
);
2192 /* Should just run our executable */
2193 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2194 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2195 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2196 okChildInt("argcA", 4);
2197 okChildString("argvA3", "Lnk");
2199 if (!skip_shlexec_tests
)
2201 /* An explicit class overrides lnk's ContextMenuHandler */
2202 rc
=shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
2203 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2204 okChildInt("argcA", 5);
2205 okChildString("argvA3", "Open");
2206 okChildPath("argvA4", filename
);
2209 if (dllver
.dwMajorVersion
>=6)
2212 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
2213 * Older versions don't or are quite buggy in this regard.
2215 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2223 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
2224 okShell(rc
> 32, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2225 okChildInt("argcA", 4);
2226 okChildString("argvA3", "Lnk");
2229 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2231 while (test
->basename
)
2234 sprintf(params
+1, test
->basename
, tmpdir
);
2235 strcat(params
,"\"");
2236 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
2240 todo_wine_if(test
->todo
& 0x1)
2241 okShell(rc
==test
->rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2244 todo_wine_if(test
->todo
& 0x2)
2245 okChildInt("argcA", 5);
2246 todo_wine_if(test
->todo
& 0x4)
2247 okChildString("argvA3", "Lnk");
2248 sprintf(params
, test
->basename
, tmpdir
);
2249 okChildPath("argvA4", params
);
2256 static void test_exes(void)
2258 char filename
[MAX_PATH
];
2262 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2264 /* We need NOZONECHECKS on Win2003 to block a dialog */
2265 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
2267 okShell(rc
> 32, "returned %lu\n", rc
);
2268 okChildInt("argcA", 4);
2269 okChildString("argvA3", "Exec");
2271 if (! skip_noassoc_tests
)
2273 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
2274 if (CopyFileA(argv0
, filename
, FALSE
))
2276 rc
=shell_execute(NULL
, filename
, params
, NULL
);
2278 okShell(rc
==SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2284 win_skip("Skipping shellexecute of file with unassociated extension\n");
2287 /* test combining executable and parameters */
2288 sprintf(filename
, "%s shlexec \"%s\" Exec", argv0
, child_file
);
2289 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2290 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2292 sprintf(filename
, "\"%s\" shlexec \"%s\" Exec", argv0
, child_file
);
2293 rc
= shell_execute(NULL
, filename
, NULL
, NULL
);
2294 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2296 /* A verb, even if invalid, overrides the normal handling of executables */
2297 todo_wait rc
= shell_execute_ex(SEE_MASK_FLAG_NO_UI
,
2298 "notaverb", argv0
, NULL
, NULL
, NULL
);
2299 todo_wine
okShell(rc
== SE_ERR_NOASSOC
, "returned %lu\n", rc
);
2301 if (!skip_shlexec_tests
)
2303 /* A class overrides the normal handling of executables too */
2304 /* FIXME SEE_MASK_FLAG_NO_UI is only needed due to Wine's bug */
2305 rc
= shell_execute_ex(SEE_MASK_CLASSNAME
| SEE_MASK_FLAG_NO_UI
,
2306 NULL
, argv0
, NULL
, NULL
, ".shlexec");
2307 todo_wine
okShell(rc
> 32, "returned %lu\n", rc
);
2308 okChildInt("argcA", 5);
2309 todo_wine
okChildString("argvA3", "Open");
2310 todo_wine
okChildPath("argvA4", argv0
);
2316 const char* command
;
2317 const char* ddeexec
;
2318 const char* application
;
2322 const char* expectedDdeExec
;
2326 static dde_tests_t dde_tests
[] =
2328 /* Test passing and not passing command-line
2329 * argument, no DDE */
2330 {"", NULL
, NULL
, NULL
, NULL
, 0, ""},
2331 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, 1, ""},
2333 /* Test passing and not passing command-line
2334 * argument, with DDE */
2335 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 0, "[open(\"%s\")]"},
2336 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, 1, "[open(\"%s\")]"},
2338 /* Test unquoted %1 in command and ddeexec
2339 * (test filename has space) */
2340 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", TRUE
/* before vista */},
2342 /* Test ifexec precedence over ddeexec */
2343 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", 0, "[ifexec(\"%s\")]"},
2345 /* Test default DDE topic */
2346 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, 0, "[open(\"%s\")]"},
2348 /* Test default DDE application */
2349 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, 0, "[open(\"%s\")]"},
2354 static int waitforinputidle_count
;
2355 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
2357 waitforinputidle_count
++;
2358 if (winetest_debug
> 1)
2359 trace("WaitForInputIdle() waiting for dde event timeout=min(%u,5s)\n", timeout
);
2360 timeout
= timeout
< 5000 ? timeout
: 5000;
2361 return WaitForSingleObject(dde_ready_event
, timeout
);
2365 * WaitForInputIdle() will normally return immediately for console apps. That's
2366 * a problem for us because ShellExecute will assume that an app is ready to
2367 * receive DDE messages after it has called WaitForInputIdle() on that app.
2368 * To work around that we install our own version of WaitForInputIdle() that
2369 * will wait for the child to explicitly tell us that it is ready. We do that
2370 * by changing the entry for WaitForInputIdle() in the shell32 import address
2373 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
2376 PIMAGE_NT_HEADERS nt_headers
;
2377 DWORD import_directory_rva
;
2378 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2381 base
= (char *) GetModuleHandleA("shell32.dll");
2382 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2383 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2385 /* Search for the correct imported module by walking the import descriptors */
2386 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2387 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2389 char *import_module_name
;
2391 import_module_name
= base
+ import_descriptor
->Name
;
2392 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2393 lstrcmpiA(import_module_name
, "user32") == 0)
2395 PIMAGE_THUNK_DATA int_entry
;
2396 PIMAGE_THUNK_DATA iat_entry
;
2398 /* The import name table and import address table are two parallel
2399 * arrays. We need the import name table to find the imported
2400 * routine and the import address table to patch the address, so
2401 * walk them side by side */
2402 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2403 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2404 while (int_entry
->u1
.Ordinal
!= 0)
2406 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2408 PIMAGE_IMPORT_BY_NAME import_by_name
;
2409 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2410 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2412 /* Found the correct routine in the correct imported module. Patch it. */
2414 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2415 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2416 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2417 if (winetest_debug
> 1)
2418 trace("Hooked %s.WaitForInputIdle\n", import_module_name
);
2429 import_descriptor
++;
2431 ok(hook_count
, "Could not hook WaitForInputIdle()\n");
2434 static void test_dde(void)
2436 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2437 const dde_tests_t
* test
;
2444 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2446 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2448 /* Default service is application name minus path and extension */
2449 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2450 *strchr(defApplication
, '.') = 0;
2452 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2453 4096, "winetest_shlexec_dde_map");
2454 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2456 ddeflags
= SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
2458 while (test
->command
)
2460 if (!create_test_association(".sde"))
2462 skip("Unable to create association for '.sde'\n");
2465 create_test_verb_dde("shlexec.sde", "Open", 0, test
->command
, test
->ddeexec
,
2466 test
->application
, test
->topic
, test
->ifexec
);
2468 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2470 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2471 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2475 shared_block
[0] = '\0';
2476 shared_block
[1] = '\0';
2480 waitforinputidle_count
= 0;
2481 dde_ready_event
= CreateEventA(NULL
, TRUE
, FALSE
, "winetest_shlexec_dde_ready");
2482 rc
= shell_execute_ex(ddeflags
, NULL
, filename
, NULL
, NULL
, NULL
);
2483 CloseHandle(dde_ready_event
);
2484 if (!(ddeflags
& SEE_MASK_WAITFORINPUTIDLE
) && rc
== SE_ERR_DDEFAIL
&&
2485 GetLastError() == ERROR_FILE_NOT_FOUND
&&
2486 strcmp(winetest_platform
, "windows") == 0)
2488 /* Windows 10 does not call WaitForInputIdle() for DDE which creates
2489 * a race condition as the DDE server may not have time to start up.
2490 * When that happens the test fails with the above results and we
2491 * compensate by forcing the WaitForInputIdle() call.
2493 trace("Adding SEE_MASK_WAITFORINPUTIDLE for Windows 10\n");
2494 ddeflags
|= SEE_MASK_WAITFORINPUTIDLE
;
2495 delete_test_association(".sde");
2496 Sleep(CHILD_DDE_TIMEOUT
);
2499 okShell(32 < rc
, "failed: rc=%lu err=%u\n", rc
, GetLastError());
2501 okShell(waitforinputidle_count
== 1 ||
2502 broken(waitforinputidle_count
== 0) /* Win10 race */,
2503 "WaitForInputIdle() was called %u times\n",
2504 waitforinputidle_count
);
2506 okShell(waitforinputidle_count
== 0, "WaitForInputIdle() was called %u times for a non-DDE case\n", waitforinputidle_count
);
2511 okChildIntBroken("argcA", test
->expectedArgs
+ 3);
2513 okChildInt("argcA", test
->expectedArgs
+ 3);
2515 if (test
->expectedArgs
== 1) okChildPath("argvA3", filename
);
2517 sprintf(params
, test
->expectedDdeExec
, filename
);
2518 okChildPath("ddeExec", params
);
2520 reset_association_description();
2522 delete_test_association(".sde");
2526 UnmapViewOfFile(shared_block
);
2528 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2531 #define DDE_DEFAULT_APP_VARIANTS 3
2534 const char* command
;
2535 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2537 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2538 } dde_default_app_tests_t
;
2540 static dde_default_app_tests_t dde_default_app_tests
[] =
2542 /* There are three possible sets of results: Windows <= 2000, XP SP1 and
2543 * >= XP SP2. Use the first two tests to determine which results to expect.
2546 /* Test unquoted existing filename with a space */
2547 {"%s\\test file.exe", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2548 {"%s\\test2 file.exe", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2550 /* Test unquoted existing filename with a space */
2551 {"%s\\test file.exe param", {"test file", "test file", "test"}, 0x0, {33, 33, 33}},
2553 /* Test quoted existing filename with a space */
2554 {"\"%s\\test file.exe\"", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2555 {"\"%s\\test file.exe\" param", {"test file", "test file", "test file"}, 0x0, {33, 33, 33}},
2557 /* Test unquoted filename with a space that doesn't exist, but
2559 {"%s\\test2 file.exe param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2561 /* Test quoted filename with a space that does not exist */
2562 {"\"%s\\test2 file.exe\"", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2563 {"\"%s\\test2 file.exe\" param", {"", "", "test2 file"}, 0x0, {5, 2, 33}},
2565 /* Test filename supplied without the extension */
2566 {"%s\\test2", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2567 {"%s\\test2 param", {"test2", "", "test2"}, 0x0, {33, 5, 33}},
2569 /* Test an unquoted nonexistent filename */
2570 {"%s\\notexist.exe", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2571 {"%s\\notexist.exe param", {"", "", "notexist"}, 0x0, {5, 2, 33}},
2573 /* Test an application that will be found on the path */
2574 {"cmd", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2575 {"cmd param", {"cmd", "cmd", "cmd"}, 0x0, {33, 33, 33}},
2577 /* Test an application that will not be found on the path */
2578 {"xyzwxyzwxyz", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2579 {"xyzwxyzwxyz param", {"", "", "xyzwxyzwxyz"}, 0x0, {5, 2, 33}},
2581 {NULL
, {NULL
}, 0, {0}}
2587 DWORD threadIdParent
;
2588 } dde_thread_info_t
;
2590 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2592 dde_thread_info_t
*info
= arg
;
2593 assert(info
&& info
->filename
);
2594 PostThreadMessageA(info
->threadIdParent
,
2596 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2601 static void test_dde_default_app(void)
2603 char filename
[MAX_PATH
];
2605 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2606 const dde_default_app_tests_t
* test
;
2615 post_quit_on_execute
= FALSE
;
2617 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2618 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0);
2619 ok(rc
== DMLERR_NO_ERROR
, "got %lx\n", rc
);
2621 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2623 /* It is strictly not necessary to register an application name here, but wine's
2624 * DdeNameService implementation complains if 0 is passed instead of
2625 * hszApplication with DNS_FILTEROFF */
2626 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2627 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2628 ok(hszApplication
&& hszTopic
, "got %p and %p\n", hszApplication
, hszTopic
);
2629 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_REGISTER
| DNS_FILTEROFF
);
2630 ok(ret
!= 0, "got %p\n", ret
);
2632 test
= dde_default_app_tests
;
2633 while (test
->command
)
2637 if (!create_test_association(".sde"))
2639 skip("Unable to create association for '.sde'\n");
2642 sprintf(params
, test
->command
, tmpdir
);
2643 create_test_verb_dde("shlexec.sde", "Open", 1, params
, "[test]", NULL
,
2645 ddeApplication
[0] = 0;
2647 /* No application will be run as we will respond to the first DDE event,
2648 * so don't wait for it */
2651 thread
= CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
);
2652 ok(thread
!= NULL
, "got %p\n", thread
);
2653 while (GetMessageA(&msg
, NULL
, 0, 0)) DispatchMessageA(&msg
);
2654 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2656 /* The first two tests determine which set of results to expect.
2657 * First check the platform as only the first set of results is
2658 * acceptable for Wine.
2660 if (strcmp(winetest_platform
, "wine"))
2662 if (test
== dde_default_app_tests
)
2664 if (strcmp(ddeApplication
, test
->expectedDdeApplication
[0]))
2667 else if (test
== dde_default_app_tests
+ 1)
2669 if (which
== 0 && rc
== test
->rc
[1])
2671 trace("DDE result variant %d\n", which
);
2675 todo_wine_if(test
->todo
& 0x1)
2676 okShell(rc
==test
->rc
[which
], "failed: rc=%lu err=%u\n",
2677 rc
, GetLastError());
2680 todo_wine_if(test
->todo
& 0x2)
2681 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2682 "Expected application '%s', got '%s'\n",
2683 test
->expectedDdeApplication
[which
], ddeApplication
);
2685 reset_association_description();
2687 delete_test_association(".sde");
2691 ret
= DdeNameService(ddeInst
, hszApplication
, 0, DNS_UNREGISTER
);
2692 ok(ret
!= 0, "got %p\n", ret
);
2693 b
= DdeFreeStringHandle(ddeInst
, hszTopic
);
2694 ok(b
, "got %d\n", b
);
2695 b
= DdeFreeStringHandle(ddeInst
, hszApplication
);
2696 ok(b
, "got %d\n", b
);
2697 b
= DdeUninitialize(ddeInst
);
2698 ok(b
, "got %d\n", b
);
2701 static void init_test(void)
2704 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2705 char filename
[MAX_PATH
];
2706 WCHAR lnkfile
[MAX_PATH
];
2708 const char* const * testfile
;
2713 hdll
=GetModuleHandleA("shell32.dll");
2714 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2717 dllver
.cbSize
=sizeof(dllver
);
2718 pDllGetVersion(&dllver
);
2719 trace("major=%d minor=%d build=%d platform=%d\n",
2720 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2721 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2725 memset(&dllver
, 0, sizeof(dllver
));
2728 r
= CoInitialize(NULL
);
2729 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2733 rc
=GetModuleFileNameA(NULL
, argv0
, sizeof(argv0
));
2734 ok(rc
!= 0 && rc
< sizeof(argv0
), "got %d\n", rc
);
2735 if (GetFileAttributesA(argv0
)==INVALID_FILE_ATTRIBUTES
)
2737 strcat(argv0
, ".so");
2738 ok(GetFileAttributesA(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2739 "unable to find argv0!\n");
2742 /* Older versions (win 2k) fail tests if there is a space in
2744 if (dllver
.dwMajorVersion
<= 5)
2745 strcpy(filename
, "c:\\");
2747 GetTempPathA(sizeof(filename
), filename
);
2748 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2749 GetLongPathNameA(tmpdir
, tmpdir
, sizeof(tmpdir
));
2750 DeleteFileA( tmpdir
);
2751 rc
= CreateDirectoryA( tmpdir
, NULL
);
2752 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2753 /* Set %TMPDIR% for the tests */
2754 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2756 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2757 ok(rc
!= 0, "got %d\n", rc
);
2758 init_event(child_file
);
2760 /* Set up the test files */
2766 sprintf(filename
, *testfile
, tmpdir
);
2767 hfile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2768 FILE_ATTRIBUTE_NORMAL
, NULL
);
2769 if (hfile
==INVALID_HANDLE_VALUE
)
2771 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2778 /* Setup the test shortcuts */
2779 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2780 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2781 desc
.description
=NULL
;
2783 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2786 desc
.arguments
="ignored";
2791 create_lnk(lnkfile
, &desc
, 0);
2793 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2794 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2795 desc
.description
=NULL
;
2799 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2800 desc
.arguments
=params
;
2805 create_lnk(lnkfile
, &desc
, 0);
2807 /* Create a basic association suitable for most tests */
2808 if (!create_test_association(".shlexec"))
2810 skip_shlexec_tests
= TRUE
;
2811 skip("Unable to create association for '.shlexec'\n");
2814 create_test_verb("shlexec.shlexec", "Open", 0, "Open \"%1\"");
2815 create_test_verb("shlexec.shlexec", "NoQuotes", 0, "NoQuotes %1");
2816 create_test_verb("shlexec.shlexec", "LowerL", 0, "LowerL %l");
2817 create_test_verb("shlexec.shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2818 create_test_verb("shlexec.shlexec", "UpperL", 0, "UpperL %L");
2819 create_test_verb("shlexec.shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2821 create_test_association(".sha");
2822 create_test_verb("shlexec.sha", "averb", 0, "AVerb \"%1\"");
2824 create_test_class("shlproto", TRUE
);
2825 create_test_verb("shlproto", "open", 0, "URL \"%1\"");
2826 create_test_verb("shlproto", "averb", 0, "AVerb \"%1\"");
2828 /* Set an environment variable to see if it is inherited */
2829 SetEnvironmentVariableA("ShlexecVar", "Present");
2832 static void cleanup_test(void)
2834 char filename
[MAX_PATH
];
2835 const char* const * testfile
;
2837 /* Delete the test files */
2841 sprintf(filename
, *testfile
, tmpdir
);
2842 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2843 SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
);
2844 DeleteFileA(filename
);
2847 DeleteFileA(child_file
);
2848 RemoveDirectoryA(tmpdir
);
2850 /* Delete the test association */
2851 delete_test_association(".shlexec");
2852 delete_test_association(".sha");
2853 delete_test_class("shlproto");
2855 CloseHandle(hEvent
);
2860 static void test_directory(void)
2862 char path
[MAX_PATH
], curdir
[MAX_PATH
];
2863 char params
[1024], dirpath
[1024];
2866 sprintf(path
, "%s\\test2.exe", tmpdir
);
2867 CopyFileA(argv0
, path
, FALSE
);
2869 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2871 /* Test with the current directory */
2872 GetCurrentDirectoryA(sizeof(curdir
), curdir
);
2873 SetCurrentDirectoryA(tmpdir
);
2874 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2875 NULL
, "test2.exe", params
, NULL
, NULL
);
2876 okShell(rc
> 32, "returned %lu\n", rc
);
2877 okChildInt("argcA", 4);
2878 okChildString("argvA3", "Exec");
2879 todo_wine
okChildPath("longPath", path
);
2880 SetCurrentDirectoryA(curdir
);
2882 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2883 NULL
, "test2.exe", params
, NULL
, NULL
);
2884 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2886 /* Explicitly specify the directory to use */
2887 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2888 NULL
, "test2.exe", params
, tmpdir
, NULL
);
2889 okShell(rc
> 32, "returned %lu\n", rc
);
2890 okChildInt("argcA", 4);
2891 okChildString("argvA3", "Exec");
2892 todo_wine
okChildPath("longPath", path
);
2894 /* Specify it through an environment variable */
2895 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2896 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2897 todo_wine
okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2899 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
|SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2900 NULL
, "test2.exe", params
, "%TMPDIR%", NULL
);
2901 okShell(rc
> 32, "returned %lu\n", rc
);
2902 okChildInt("argcA", 4);
2903 okChildString("argvA3", "Exec");
2904 todo_wine
okChildPath("longPath", path
);
2906 /* Not a colon-separated directory list */
2907 sprintf(dirpath
, "%s:%s", curdir
, tmpdir
);
2908 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2909 NULL
, "test2.exe", params
, dirpath
, NULL
);
2910 okShell(rc
== SE_ERR_FNF
, "returned %lu\n", rc
);
2916 myARGC
= winetest_get_mainargs(&myARGV
);
2919 doChild(myARGC
, myARGV
);
2920 /* Skip the tests/failures trace for child processes */
2921 ExitProcess(winetest_get_failures());
2926 test_commandline2argv();
2928 test_lpFile_parsed();
2932 test_find_executable();
2936 test_dde_default_app();