2 * Unit test of the ShellExecute function.
4 * Copyright 2005 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 * - we may want to test ShellExecuteEx() instead of ShellExecute()
30 * and then we could also check its return value
31 * - ShellExecuteEx() also calls SetLastError() with meaningful values which
35 /* Needed to get SEE_MASK_NOZONECHECKS with the PSDK */
36 #define NTDDI_WINXPSP1 0x05010100
37 #define NTDDI_VERSION NTDDI_WINXPSP1
38 #define _WIN32_WINNT 0x0501
48 #include "wine/test.h"
50 #include "shell32_test.h"
53 static char argv0
[MAX_PATH
];
56 static char tmpdir
[MAX_PATH
];
57 static char child_file
[MAX_PATH
];
58 static DLLVERSIONINFO dllver
;
59 static BOOL skip_noassoc_tests
= FALSE
;
60 static HANDLE dde_ready_event
;
65 * ShellExecute wrappers
68 static void dump_child(void);
71 static void init_event(const char* child_file
)
74 event_name
=strrchr(child_file
, '\\')+1;
75 hEvent
=CreateEvent(NULL
, FALSE
, FALSE
, event_name
);
78 static void strcat_param(char* str
, const char* name
, const char* param
)
82 if (str
[strlen(str
)-1] == '"')
91 static int _todo_wait
= 0;
92 #define todo_wait for (_todo_wait = 1; _todo_wait; _todo_wait = 0)
94 static char shell_call
[2048]="";
95 static int bad_shellexecute
= 0;
96 static INT_PTR
shell_execute(LPCSTR operation
, LPCSTR file
, LPCSTR parameters
, LPCSTR directory
)
98 INT_PTR rc
, rcEmpty
= 0;
101 rcEmpty
= shell_execute("", file
, parameters
, directory
);
103 strcpy(shell_call
, "ShellExecute(");
104 strcat_param(shell_call
, "verb", operation
);
105 strcat_param(shell_call
, "file", file
);
106 strcat_param(shell_call
, "params", parameters
);
107 strcat_param(shell_call
, "dir", directory
);
108 strcat(shell_call
, ")");
109 if (winetest_debug
> 1)
110 trace("%s\n", shell_call
);
112 DeleteFile(child_file
);
113 SetLastError(0xcafebabe);
115 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
116 * association it displays the 'Open With' dialog and I could not find
117 * a flag to prevent this.
119 rc
=(INT_PTR
)ShellExecute(NULL
, operation
, file
, parameters
, directory
, SW_SHOWNORMAL
);
124 wait_rc
=WaitForSingleObject(hEvent
, 5000);
125 if (wait_rc
== WAIT_TIMEOUT
)
127 HWND wnd
= FindWindowA("#32770", "Windows");
130 SendMessage(wnd
, WM_CLOSE
, 0, 0);
131 win_skip("Skipping shellexecute of file with unassociated extension\n");
132 skip_noassoc_tests
= TRUE
;
137 ok(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32, "%s WaitForSingleObject returned %d\n", shell_call
, wait_rc
);
139 ok(wait_rc
==WAIT_OBJECT_0
|| rc
<= 32, "%s WaitForSingleObject returned %d\n", shell_call
, wait_rc
);
141 /* The child process may have changed the result file, so let profile
142 * functions know about it
144 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
150 if (rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */
151 bad_shellexecute
= 1;
152 ok(rc
== rcEmpty
|| broken(rc
!= rcEmpty
&& rcEmpty
== SE_ERR_NOASSOC
) /* NT4 */,
153 "%s Got different return value with empty string: %lu %lu\n", shell_call
, rc
, rcEmpty
);
159 static INT_PTR
shell_execute_ex(DWORD mask
, LPCSTR operation
, LPCSTR file
,
160 LPCSTR parameters
, LPCSTR directory
,
163 SHELLEXECUTEINFO sei
;
167 strcpy(shell_call
, "ShellExecuteEx(");
171 sprintf(smask
, "0x%x", mask
);
172 strcat_param(shell_call
, "mask", smask
);
174 strcat_param(shell_call
, "verb", operation
);
175 strcat_param(shell_call
, "file", file
);
176 strcat_param(shell_call
, "params", parameters
);
177 strcat_param(shell_call
, "dir", directory
);
178 strcat_param(shell_call
, "class", class);
179 strcat(shell_call
, ")");
180 if (winetest_debug
> 1)
181 trace("%s\n", shell_call
);
183 sei
.cbSize
=sizeof(sei
);
184 sei
.fMask
=SEE_MASK_NOCLOSEPROCESS
| mask
;
186 sei
.lpVerb
=operation
;
188 sei
.lpParameters
=parameters
;
189 sei
.lpDirectory
=directory
;
190 sei
.nShow
=SW_SHOWNORMAL
;
191 sei
.hInstApp
=NULL
; /* Out */
197 sei
.hProcess
=NULL
; /* Out */
199 DeleteFile(child_file
);
200 SetLastError(0xcafebabe);
201 success
=ShellExecuteEx(&sei
);
202 rc
=(INT_PTR
)sei
.hInstApp
;
203 ok((success
&& rc
> 32) || (!success
&& rc
<= 32),
204 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call
, success
, rc
);
209 if (sei
.hProcess
!=NULL
)
211 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
212 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject(hProcess) returned %d\n", wait_rc
);
214 wait_rc
=WaitForSingleObject(hEvent
, 5000);
216 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject returned %d\n", wait_rc
);
218 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject returned %d\n", wait_rc
);
220 /* The child process may have changed the result file, so let profile
221 * functions know about it
223 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
234 * Functions to create / delete associations wrappers
238 static BOOL
create_test_association(const char* extension
)
240 HKEY hkey
, hkey_shell
;
241 char class[MAX_PATH
];
244 sprintf(class, "shlexec%s", extension
);
245 rc
=RegCreateKeyEx(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
247 if (rc
!= ERROR_SUCCESS
)
250 rc
=RegSetValueEx(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
251 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
254 rc
=RegCreateKeyEx(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
255 KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkey
, NULL
);
256 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
258 rc
=RegCreateKeyEx(hkey
, "shell", 0, NULL
, 0,
259 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
260 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
263 CloseHandle(hkey_shell
);
268 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
269 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
272 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
273 DWORD dwMaxLen
, dwSize
;
274 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
279 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
283 /* Get highest length for keys, values */
284 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
285 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
286 if (ret
) goto cleanup
;
290 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
291 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
293 /* Name too big: alloc a buffer for it */
294 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
296 ret
= ERROR_NOT_ENOUGH_MEMORY
;
302 /* Recursively delete all the subkeys */
306 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
307 NULL
, NULL
, NULL
)) break;
309 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
310 if (ret
) goto cleanup
;
314 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
319 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
320 NULL
, NULL
, NULL
, NULL
)) break;
322 ret
= RegDeleteValueA(hKey
, lpszName
);
323 if (ret
) goto cleanup
;
327 /* Free buffer if allocated */
328 if (lpszName
!= szNameBuf
)
329 HeapFree( GetProcessHeap(), 0, lpszName
);
331 RegCloseKey(hSubKey
);
335 static void delete_test_association(const char* extension
)
337 char class[MAX_PATH
];
339 sprintf(class, "shlexec%s", extension
);
340 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, class);
341 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
344 static void create_test_verb_dde(const char* extension
, const char* verb
,
345 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
346 const char *application
, const char *topic
,
349 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
350 char shell
[MAX_PATH
];
354 sprintf(shell
, "shlexec%s\\shell", extension
);
355 rc
=RegOpenKeyEx(HKEY_CLASSES_ROOT
, shell
, 0,
356 KEY_CREATE_SUB_KEY
, &hkey_shell
);
357 assert(rc
==ERROR_SUCCESS
);
358 rc
=RegCreateKeyEx(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
359 NULL
, &hkey_verb
, NULL
);
360 assert(rc
==ERROR_SUCCESS
);
361 rc
=RegCreateKeyEx(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
362 NULL
, &hkey_cmd
, NULL
);
363 assert(rc
==ERROR_SUCCESS
);
367 rc
=RegSetValueEx(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
371 cmd
=HeapAlloc(GetProcessHeap(), 0, strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
372 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
373 rc
=RegSetValueEx(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
374 assert(rc
==ERROR_SUCCESS
);
375 HeapFree(GetProcessHeap(), 0, cmd
);
380 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
382 rc
=RegCreateKeyEx(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
383 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
384 assert(rc
==ERROR_SUCCESS
);
385 rc
=RegSetValueEx(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
387 assert(rc
==ERROR_SUCCESS
);
390 rc
=RegCreateKeyEx(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
391 NULL
, &hkey_application
, NULL
);
392 assert(rc
==ERROR_SUCCESS
);
393 rc
=RegSetValueEx(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
394 strlen(application
)+1);
395 assert(rc
==ERROR_SUCCESS
);
396 CloseHandle(hkey_application
);
400 rc
=RegCreateKeyEx(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
401 NULL
, &hkey_topic
, NULL
);
402 assert(rc
==ERROR_SUCCESS
);
403 rc
=RegSetValueEx(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
405 assert(rc
==ERROR_SUCCESS
);
406 CloseHandle(hkey_topic
);
410 rc
=RegCreateKeyEx(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
411 NULL
, &hkey_ifexec
, NULL
);
412 assert(rc
==ERROR_SUCCESS
);
413 rc
=RegSetValueEx(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
415 assert(rc
==ERROR_SUCCESS
);
416 CloseHandle(hkey_ifexec
);
418 CloseHandle(hkey_ddeexec
);
421 CloseHandle(hkey_shell
);
422 CloseHandle(hkey_verb
);
423 CloseHandle(hkey_cmd
);
426 static void create_test_verb(const char* extension
, const char* verb
,
427 int rawcmd
, const char* cmdtail
)
429 create_test_verb_dde(extension
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
435 * Functions to check that the child process was started just right
436 * (borrowed from dlls/kernel32/tests/process.c)
440 static const char* encodeA(const char* str
)
442 static char encoded
[2*1024+1];
447 len
= strlen(str
) + 1;
448 if (len
>= sizeof(encoded
)/2)
450 fprintf(stderr
, "string is too long!\n");
454 for (i
= 0; i
< len
; i
++)
455 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
460 static unsigned decode_char(char c
)
462 if (c
>= '0' && c
<= '9') return c
- '0';
463 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
464 assert(c
>= 'A' && c
<= 'F');
468 static char* decodeA(const char* str
)
470 static char decoded
[1024];
474 len
= strlen(str
) / 2;
475 if (!len
--) return NULL
;
476 if (len
>= sizeof(decoded
))
478 fprintf(stderr
, "string is too long!\n");
482 for (i
= 0; i
< len
; i
++)
483 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
488 static void childPrintf(HANDLE h
, const char* fmt
, ...)
494 va_start(valist
, fmt
);
495 vsprintf(buffer
, fmt
, valist
);
497 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
500 static DWORD ddeInst
;
502 static char ddeExec
[MAX_PATH
], ddeApplication
[MAX_PATH
];
503 static BOOL post_quit_on_execute
;
505 static HDDEDATA CALLBACK
ddeCb(UINT uType
, UINT uFmt
, HCONV hConv
,
506 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
507 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
511 if (winetest_debug
> 2)
512 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
513 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
518 if (!DdeCmpStringHandles(hsz1
, hszTopic
))
520 size
= DdeQueryString(ddeInst
, hsz2
, ddeApplication
, MAX_PATH
, CP_WINANSI
);
521 assert(size
< MAX_PATH
);
522 return (HDDEDATA
)TRUE
;
524 return (HDDEDATA
)FALSE
;
527 size
= DdeGetData(hData
, (LPBYTE
)ddeExec
, MAX_PATH
, 0L);
528 assert(size
< MAX_PATH
);
529 DdeFreeDataHandle(hData
);
530 if (post_quit_on_execute
)
532 return (HDDEDATA
)DDE_FACK
;
540 * This is just to make sure the child won't run forever stuck in a GetMessage()
541 * loop when DDE fails for some reason.
543 static void CALLBACK
childTimeout(HWND wnd
, UINT msg
, UINT_PTR timer
, DWORD time
)
545 trace("childTimeout called\n");
550 static void doChild(int argc
, char** argv
)
552 char *filename
, longpath
[MAX_PATH
] = "";
563 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
564 if (hFile
== INVALID_HANDLE_VALUE
)
568 childPrintf(hFile
, "[Arguments]\r\n");
569 if (winetest_debug
> 2)
570 trace("argcA=%d\n", argc
);
571 childPrintf(hFile
, "argcA=%d\r\n", argc
);
572 for (i
= 0; i
< argc
; i
++)
574 if (winetest_debug
> 2)
575 trace("argvA%d=%s\n", i
, argv
[i
]);
576 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
578 GetModuleFileNameA(GetModuleHandleA(NULL
), longpath
, MAX_PATH
);
579 childPrintf(hFile
, "longPath=%s\r\n", encodeA(longpath
));
581 map
= OpenFileMappingA(FILE_MAP_READ
, FALSE
, "winetest_shlexec_dde_map");
584 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 4096);
586 if (shared_block
[0] != '\0' || shared_block
[1] != '\0')
588 post_quit_on_execute
= TRUE
;
590 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
591 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0L);
592 assert(rc
== DMLERR_NO_ERROR
);
593 hszApplication
= DdeCreateStringHandleA(ddeInst
, shared_block
, CP_WINANSI
);
594 hszTopic
= DdeCreateStringHandleA(ddeInst
, shared_block
+ strlen(shared_block
) + 1, CP_WINANSI
);
595 assert(hszApplication
&& hszTopic
);
596 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_REGISTER
| DNS_FILTEROFF
));
598 timer
= SetTimer(NULL
, 0, 2500, childTimeout
);
600 dde_ready
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
602 CloseHandle(dde_ready
);
604 while (GetMessage(&msg
, NULL
, 0, 0))
605 DispatchMessage(&msg
);
608 KillTimer(NULL
, timer
);
609 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_UNREGISTER
));
610 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
611 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
612 assert(DdeUninitialize(ddeInst
));
616 dde_ready
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, "winetest_shlexec_dde_ready");
618 CloseHandle(dde_ready
);
621 UnmapViewOfFile(shared_block
);
623 childPrintf(hFile
, "ddeExec=%s\r\n", encodeA(ddeExec
));
628 init_event(filename
);
633 static char* getChildString(const char* sect
, const char* key
)
638 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), child_file
);
639 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
640 assert(!(strlen(buf
) & 1));
645 static void dump_child(void)
647 if (winetest_debug
> 1)
653 c
=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file
);
654 trace("argcA=%d\n",c
);
657 sprintf(key
, "argvA%d", i
);
658 str
=getChildString("Arguments", key
);
659 trace("%s=%s\n", key
, str
);
664 static int StrCmpPath(const char* s1
, const char* s2
)
666 if (!s1
&& !s2
) return 0;
677 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
679 while (*s1
=='/' || *s1
=='\\')
681 while (*s2
=='/' || *s2
=='\\')
684 else if (toupper(*s1
)==toupper(*s2
))
701 static void _okChildString(const char* file
, int line
, const char* key
, const char* expected
)
704 result
=getChildString("Arguments", key
);
707 ok_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
710 ok_(file
, line
)(lstrcmpiA(result
, expected
) == 0,
711 "%s expected '%s', got '%s'\n", key
, expected
, result
);
714 static void _okChildPath(const char* file
, int line
, const char* key
, const char* expected
)
717 result
=getChildString("Arguments", key
);
720 ok_(file
, line
)(FALSE
, "%s expected '%s', but key not found or empty\n", key
, expected
);
723 ok_(file
, line
)(StrCmpPath(result
, expected
) == 0,
724 "%s expected '%s', got '%s'\n", key
, expected
, result
);
727 static void _okChildInt(const char* file
, int line
, const char* key
, int expected
)
730 result
=GetPrivateProfileIntA("Arguments", key
, expected
, child_file
);
731 ok_(file
, line
)(result
== expected
,
732 "%s expected %d, but got %d\n", key
, expected
, result
);
735 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
736 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
737 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
741 * GetLongPathNameA equivalent that supports Win95 and WinNT
745 static DWORD
get_long_path_name(const char* shortpath
, char* longpath
, DWORD longlen
)
747 char tmplongpath
[MAX_PATH
];
749 DWORD sp
= 0, lp
= 0;
751 WIN32_FIND_DATAA wfd
;
754 if (!shortpath
|| !shortpath
[0])
757 if (shortpath
[1] == ':')
759 tmplongpath
[0] = shortpath
[0];
760 tmplongpath
[1] = ':';
764 while (shortpath
[sp
])
766 /* check for path delimiters and reproduce them */
767 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
769 if (!lp
|| tmplongpath
[lp
-1] != '\\')
771 /* strip double "\\" */
772 tmplongpath
[lp
++] = '\\';
774 tmplongpath
[lp
] = 0; /* terminate string */
780 if (sp
== 0 && p
[0] == '.' && (p
[1] == '/' || p
[1] == '\\'))
782 tmplongpath
[lp
++] = *p
++;
783 tmplongpath
[lp
++] = *p
++;
785 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
786 tmplen
= p
- (shortpath
+ sp
);
787 lstrcpyn(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
788 /* Check if the file exists and use the existing file name */
789 goit
= FindFirstFileA(tmplongpath
, &wfd
);
790 if (goit
== INVALID_HANDLE_VALUE
)
793 strcpy(tmplongpath
+ lp
, wfd
.cFileName
);
794 lp
+= strlen(tmplongpath
+ lp
);
797 tmplen
= strlen(shortpath
) - 1;
798 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
799 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
800 tmplongpath
[lp
++] = shortpath
[tmplen
];
803 tmplen
= strlen(tmplongpath
) + 1;
804 if (tmplen
<= longlen
)
806 strcpy(longpath
, tmplongpath
);
807 tmplen
--; /* length without 0 */
815 * PathFindFileNameA equivalent that supports WinNT
819 static LPSTR
path_find_file_name(LPCSTR lpszPath
)
821 LPCSTR lastSlash
= lpszPath
;
823 while (lpszPath
&& *lpszPath
)
825 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
826 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
827 lastSlash
= lpszPath
+ 1;
828 lpszPath
= CharNext(lpszPath
);
830 return (LPSTR
)lastSlash
;
839 static const char* testfiles
[]=
841 "%s\\test file.shlexec",
842 "%s\\%%nasty%% $file.shlexec",
843 "%s\\test file.noassoc",
844 "%s\\test file.noassoc.shlexec",
845 "%s\\test file.shlexec.noassoc",
846 "%s\\test_shortcut_shlexec.lnk",
847 "%s\\test_shortcut_exe.lnk",
849 "%s\\test file.shlfoo",
851 "%s\\masked file.shlexec",
856 "%s\\simple.shlexec",
857 "%s\\drawback_file.noassoc",
858 "%s\\drawback_file.noassoc foo.shlexec",
859 "%s\\drawback_nonexist.noassoc foo.shlexec",
866 const char* basename
;
871 static filename_tests_t filename_tests
[]=
873 /* Test bad / nonexistent filenames */
874 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
875 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
878 {NULL
, "%s\\test file.shlexec", 0x0, 33},
879 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
880 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
881 {NULL
, "%s/test file.shlexec", 0x0, 33},
883 /* Test filenames with no association */
884 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
886 /* Test double extensions */
887 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
888 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
890 /* Test alternate verbs */
891 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
892 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
894 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
895 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
897 /* Test file masked due to space */
898 {NULL
, "%s\\masked file.shlexec", 0x1, 33},
899 /* Test if quoting prevents the masking */
900 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
905 static filename_tests_t noquotes_tests
[]=
907 /* Test unquoted '%1' thingies */
908 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
909 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
910 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
915 static void test_lpFile_parsed(void)
917 char fileA
[MAX_PATH
];
920 /* existing "drawback_file.noassoc" prevents finding "drawback_file.noassoc foo.shlexec" on wine */
921 sprintf(fileA
, "%s\\drawback_file.noassoc foo.shlexec", tmpdir
);
922 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
923 todo_wine
ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
925 /* if quoted, existing "drawback_file.noassoc" not prevents finding "drawback_file.noassoc foo.shlexec" on wine */
926 sprintf(fileA
, "\"%s\\drawback_file.noassoc foo.shlexec\"", tmpdir
);
927 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
928 ok(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
929 "%s failed: rc=%lu\n", shell_call
, rc
);
931 /* error should be SE_ERR_FNF, not SE_ERR_NOASSOC */
932 sprintf(fileA
, "\"%s\\drawback_file.noassoc\" foo.shlexec", tmpdir
);
933 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
934 ok(rc
== SE_ERR_FNF
, "%s succeeded: rc=%lu\n", shell_call
, rc
);
936 /* ""command"" not works on wine (and real win9x and w2k) */
937 sprintf(fileA
, "\"\"%s\\simple.shlexec\"\"", tmpdir
);
938 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
939 todo_wine
ok(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win9x/2000 */,
940 "%s failed: rc=%lu\n", shell_call
, rc
);
942 /* nonexisting "drawback_nonexist.noassoc" not prevents finding "drawback_nonexist.noassoc foo.shlexec" on wine */
943 sprintf(fileA
, "%s\\drawback_nonexist.noassoc foo.shlexec", tmpdir
);
944 rc
=shell_execute(NULL
, fileA
, NULL
, NULL
);
945 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
947 /* is SEE_MASK_DOENVSUBST default flag? Should only be when XP emulates 9x (XP bug or real 95 or ME behavior ?) */
948 rc
=shell_execute(NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
);
949 todo_wine
ok(rc
== SE_ERR_FNF
, "%s succeeded: rc=%lu\n", shell_call
, rc
);
952 rc
=shell_execute(NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
);
953 todo_wine
ok(rc
== SE_ERR_FNF
, "%s succeeded: rc=%lu\n", shell_call
, rc
);
955 /* test SEE_MASK_DOENVSUBST works */
956 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
957 NULL
, "%TMPDIR%\\simple.shlexec", NULL
, NULL
, NULL
);
958 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
960 /* quoted lpFile does not work on real win95 and nt4 */
961 rc
=shell_execute_ex(SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
,
962 NULL
, "\"%TMPDIR%\\simple.shlexec\"", NULL
, NULL
, NULL
);
963 ok(rc
> 32 || broken(rc
== SE_ERR_FNF
) /* Win95/NT4 */,
964 "%s failed: rc=%lu\n", shell_call
, rc
);
970 const char* args
[11];
974 static const cmdline_tests_t cmdline_tests
[] =
976 {"exe arg1 arg2 \"arg three\" 'four five` six\\ $even)",
977 {"exe", "arg1", "arg2", "arg three", "'four", "five`", "six\\", "$even)", NULL
}, 0},
979 {"exe arg=1 arg-2 three\tfour\rfour\nfour ",
980 {"exe", "arg=1", "arg-2", "three", "four\rfour\nfour", NULL
}, 0},
982 {"exe arg\"one\" \"second\"arg thirdarg ",
983 {"exe", "argone", "secondarg", "thirdarg", NULL
}, 0},
985 /* cmd's metacharacters have no special meaning */
986 {"exe \"one^\" \"arg\"&two three|four",
987 {"exe", "one^", "arg&two", "three|four", NULL
}, 0},
989 /* Environment variables are not interpreted either */
991 {"exe", "%TMPDIR%", "%2", NULL
}, 0},
993 /* If not followed by a quote, backslashes go through as is */
994 {"exe o\\ne t\\\\wo t\\\\\\ree f\\\\\\\\our ",
995 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
997 {"exe \"o\\ne\" \"t\\\\wo\" \"t\\\\\\ree\" \"f\\\\\\\\our\" ",
998 {"exe", "o\\ne", "t\\\\wo", "t\\\\\\ree", "f\\\\\\\\our", NULL
}, 0},
1000 /* When followed by a quote their number is halved and the remainder
1003 {"exe \\\"one \\\\\"two\" \\\\\\\"three \\\\\\\\\"four\" end",
1004 {"exe", "\"one", "\\two", "\\\"three", "\\\\four", "end", NULL
}, 0},
1006 {"exe \"one\\\" still\" \"two\\\\\" \"three\\\\\\\" still\" \"four\\\\\\\\\" end",
1007 {"exe", "one\" still", "two\\", "three\\\" still", "four\\\\", "end", NULL
}, 0},
1009 /* One can put a quote in an unquoted string by tripling it, that is in
1010 * effect quoting it like so """ -> ". The general rule is as follows:
1011 * 3n quotes -> n quotes
1012 * 3n+1 quotes -> n quotes plus start of a quoted string
1013 * 3n+2 quotes -> n quotes (plus an empty string from the remaining pair)
1014 * Nicely, when n is 0 we get the standard rules back.
1016 {"exe two\"\"quotes next",
1017 {"exe", "twoquotes", "next", NULL
}, 0},
1019 {"exe three\"\"\"quotes next",
1020 {"exe", "three\"quotes", "next", NULL
}, 0x21},
1022 {"exe four\"\"\"\" quotes\" next 4%3=1",
1023 {"exe", "four\" quotes", "next", "4%3=1", NULL
}, 0x61},
1025 {"exe five\"\"\"\"\"quotes next",
1026 {"exe", "five\"quotes", "next", NULL
}, 0x21},
1028 {"exe six\"\"\"\"\"\"quotes next",
1029 {"exe", "six\"\"quotes", "next", NULL
}, 0x20},
1031 {"exe seven\"\"\"\"\"\"\" quotes\" next 7%3=1",
1032 {"exe", "seven\"\" quotes", "next", "7%3=1", NULL
}, 0x20},
1034 {"exe twelve\"\"\"\"\"\"\"\"\"\"\"\"quotes next",
1035 {"exe", "twelve\"\"\"\"quotes", "next", NULL
}, 0x20},
1037 {"exe thirteen\"\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1038 {"exe", "thirteen\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0x20},
1040 /* Inside a quoted string the opening quote is added to the set of
1041 * consecutive quotes to get the effective quotes count. This gives:
1042 * 1+3n quotes -> n quotes
1043 * 1+3n+1 quotes -> n quotes plus closes the quoted string
1044 * 1+3n+2 quotes -> n+1 quotes plus closes the quoted string
1046 {"exe \"two\"\"quotes next",
1047 {"exe", "two\"quotes", "next", NULL
}, 0x21},
1049 {"exe \"two\"\" next",
1050 {"exe", "two\"", "next", NULL
}, 0x21},
1052 {"exe \"three\"\"\" quotes\" next 4%3=1",
1053 {"exe", "three\" quotes", "next", "4%3=1", NULL
}, 0x61},
1055 {"exe \"four\"\"\"\"quotes next",
1056 {"exe", "four\"quotes", "next", NULL
}, 0x21},
1058 {"exe \"five\"\"\"\"\"quotes next",
1059 {"exe", "five\"\"quotes", "next", NULL
}, 0x20},
1061 {"exe \"six\"\"\"\"\"\" quotes\" next 7%3=1",
1062 {"exe", "six\"\" quotes", "next", "7%3=1", NULL
}, 0x20},
1064 {"exe \"eleven\"\"\"\"\"\"\"\"\"\"\"quotes next",
1065 {"exe", "eleven\"\"\"\"quotes", "next", NULL
}, 0x20},
1067 {"exe \"twelve\"\"\"\"\"\"\"\"\"\"\"\" quotes\" next 13%3=1",
1068 {"exe", "twelve\"\"\"\" quotes", "next", "13%3=1", NULL
}, 0x20},
1070 /* The executable path has its own rules!!!
1071 * - Backslashes have no special meaning.
1072 * - If the first character is a quote, then the second quote ends the
1074 * - The previous rule holds even if the next character is not a space!
1075 * - If the first character is not a quote, then quotes have no special
1076 * meaning either and the executable path stops at the first space.
1077 * - The consecutive quotes rules don't apply either.
1078 * - Even if there is no space between the executable path and the first
1079 * argument, the latter is parsed using the regular rules.
1081 {"exe\"file\"path arg1",
1082 {"exe\"file\"path", "arg1", NULL
}, 0x30},
1084 {"exe\"path\\ arg1",
1085 {"exe\"path\\", "arg1", NULL
}, 0x31},
1087 {"\\\"exe \"arg one\"",
1088 {"\\\"exe", "arg one", NULL
}, 0x10},
1090 {"\"spaced exe\" \"next arg\"",
1091 {"spaced exe", "next arg", NULL
}, 0},
1093 {"\"exe\"arg\" one\" argtwo",
1094 {"exe", "arg one", "argtwo", NULL
}, 0x31},
1096 {"\"spaced exe\\\"arg1 arg2",
1097 {"spaced exe\\", "arg1", "arg2", NULL
}, 0x11},
1100 {"two", " arg1 ", NULL
}, 0x21},
1102 {"\"three\"\"\" arg2",
1103 {"three", "", "arg2", NULL
}, 0x61},
1105 {"\"four\"\"\"\"arg1",
1106 {"four", "\"arg1", NULL
}, 0x21},
1108 /* If the first character is a space then the executable path is empty */
1109 {" \"arg\"one argtwo",
1110 {"", "argone", "argtwo", NULL
}, 0},
1115 static BOOL
test_one_cmdline(const cmdline_tests_t
* test
)
1117 WCHAR cmdW
[MAX_PATH
], argW
[MAX_PATH
];
1123 /* trace("----- cmd='%s'\n", test->cmd); */
1124 MultiByteToWideChar(CP_ACP
, 0, test
->cmd
, -1, cmdW
, sizeof(cmdW
)/sizeof(*cmdW
));
1125 argsW
= cl2a
= CommandLineToArgvW(cmdW
, &cl2a_count
);
1126 if (argsW
== NULL
&& cl2a_count
== -1)
1128 win_skip("CommandLineToArgvW not implemented, skipping\n");
1133 while (test
->args
[count
])
1135 if ((test
->todo
& 0x1) == 0)
1136 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1138 ok(cl2a_count
== count
, "%s: expected %d arguments, but got %d\n", test
->cmd
, count
, cl2a_count
);
1140 for (i
= 0; i
< cl2a_count
- 1; i
++)
1144 MultiByteToWideChar(CP_ACP
, 0, test
->args
[i
], -1, argW
, sizeof(argW
)/sizeof(*argW
));
1145 if ((test
->todo
& (1 << (i
+4))) == 0)
1146 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1148 ok(!lstrcmpW(*argsW
, argW
), "%s: arg[%d] expected %s but got %s\n", test
->cmd
, i
, wine_dbgstr_w(argW
), wine_dbgstr_w(*argsW
));
1150 else if ((test
->todo
& 0x1) == 0)
1151 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1153 ok(0, "%s: got extra arg[%d]=%s\n", test
->cmd
, i
, wine_dbgstr_w(*argsW
));
1160 static void test_commandline2argv(void)
1162 static const WCHAR exeW
[] = {'e','x','e',0};
1163 const cmdline_tests_t
* test
;
1164 WCHAR strW
[MAX_PATH
];
1169 test
= cmdline_tests
;
1172 if (!test_one_cmdline(test
))
1177 SetLastError(0xdeadbeef);
1178 args
= CommandLineToArgvW(exeW
, NULL
);
1179 le
= GetLastError();
1180 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1182 SetLastError(0xdeadbeef);
1183 args
= CommandLineToArgvW(NULL
, NULL
);
1184 le
= GetLastError();
1185 ok(args
== NULL
&& le
== ERROR_INVALID_PARAMETER
, "expected NULL with ERROR_INVALID_PARAMETER got %p with %u\n", args
, le
);
1188 args
= CommandLineToArgvW(strW
, &numargs
);
1189 ok(numargs
== 1, "expected 1 args, got %d\n", numargs
);
1192 GetModuleFileNameW(NULL
, strW
, sizeof(strW
)/sizeof(*strW
));
1193 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
));
1195 if (args
) LocalFree(args
);
1198 static void test_argify(void)
1200 char fileA
[MAX_PATH
];
1203 sprintf(fileA
, "%s\\test file.shlexec", tmpdir
);
1206 rc
=shell_execute("NoQuotesParam2", fileA
, "a b", NULL
);
1207 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1210 okChildInt("argcA", 5);
1211 okChildString("argvA4", "a");
1215 /* '"a"""' -> 'a"' */
1216 rc
=shell_execute("NoQuotesParam2", fileA
, "\"a:\"\"some string\"\"\"", NULL
);
1217 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1220 okChildInt("argcA", 5);
1222 okChildString("argvA4", "a:some string");
1227 /* backslash isn't escape char
1228 * '"a\""' -> '"a\""' */
1229 rc
=shell_execute("NoQuotesParam2", fileA
, "\"a:\\\"some string\\\"\"", NULL
);
1230 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1233 okChildInt("argcA", 5);
1235 okChildString("argvA4", "a:\\");
1240 /* \t isn't whitespace */
1241 rc
=shell_execute("QuotedParam2", fileA
, "a\tb c", NULL
);
1242 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1245 okChildInt("argcA", 5);
1247 okChildString("argvA4", "a\tb");
1252 rc
=shell_execute("NoQuotesAllParams", fileA
, "a b c d e f g h", NULL
);
1253 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1257 okChildInt("argcA", 12);
1258 okChildString("argvA4", "a");
1259 okChildString("argvA11", "h");
1263 /* %* can sometimes contain only whitespaces and no args */
1264 rc
=shell_execute("QuotedAllParams", fileA
, " ", NULL
);
1265 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1269 okChildInt("argcA", 5);
1270 okChildString("argvA4", " ");
1275 rc
=shell_execute("NoQuotesParams345etc", fileA
, "a b c d e f g h", NULL
);
1276 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1280 okChildInt("argcA", 11);
1281 okChildString("argvA4", "b");
1282 okChildString("argvA10", "h");
1286 /* %~3 is rest of command line starting with whitespaces after 2nd arg */
1287 rc
=shell_execute("QuotedParams345etc", fileA
, "a ", NULL
);
1288 ok(rc
> 32, "%s failed: rc=%lu\n", shell_call
, rc
);
1291 okChildInt("argcA", 5);
1293 okChildString("argvA4", " ");
1299 static void test_filename(void)
1301 char filename
[MAX_PATH
];
1302 const filename_tests_t
* test
;
1306 test
=filename_tests
;
1307 while (test
->basename
)
1309 BOOL quotedfile
= FALSE
;
1311 if (skip_noassoc_tests
&& test
->rc
== SE_ERR_NOASSOC
)
1313 win_skip("Skipping shellexecute of file with unassociated extension\n");
1318 sprintf(filename
, test
->basename
, tmpdir
);
1319 if (strchr(filename
, '/'))
1329 if ((test
->todo
& 0x40)==0)
1331 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1335 char quoted
[MAX_PATH
+ 2];
1338 sprintf(quoted
, "\"%s\"", filename
);
1339 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
1343 if ((test
->todo
& 0x1)==0)
1346 broken(quotedfile
&& rc
== SE_ERR_FNF
), /* NT4 */
1347 "%s failed: rc=%ld err=%u\n", shell_call
,
1348 rc
, GetLastError());
1352 ok(rc
==test
->rc
, "%s failed: rc=%ld err=%u\n", shell_call
,
1353 rc
, GetLastError());
1358 if ((test
->todo
& 0x2)==0)
1360 okChildInt("argcA", 5);
1364 okChildInt("argcA", 5);
1366 verb
=(test
->verb
? test
->verb
: "Open");
1367 if ((test
->todo
& 0x4)==0)
1369 okChildString("argvA3", verb
);
1373 okChildString("argvA3", verb
);
1375 if ((test
->todo
& 0x8)==0)
1377 okChildPath("argvA4", filename
);
1381 okChildPath("argvA4", filename
);
1387 test
=noquotes_tests
;
1388 while (test
->basename
)
1390 sprintf(filename
, test
->basename
, tmpdir
);
1391 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
1394 if ((test
->todo
& 0x1)==0)
1396 ok(rc
==test
->rc
, "%s failed: rc=%ld err=%u\n", shell_call
,
1397 rc
, GetLastError());
1401 ok(rc
==test
->rc
, "%s failed: rc=%ld err=%u\n", shell_call
,
1402 rc
, GetLastError());
1410 verb
=(test
->verb
? test
->verb
: "Open");
1411 if ((test
->todo
& 0x4)==0)
1413 okChildString("argvA3", verb
);
1417 okChildString("argvA3", verb
);
1426 space
=strchr(str
, ' ');
1429 sprintf(attrib
, "argvA%d", count
);
1430 if ((test
->todo
& 0x8)==0)
1432 okChildPath(attrib
, str
);
1436 okChildPath(attrib
, str
);
1443 if ((test
->todo
& 0x2)==0)
1445 okChildInt("argcA", count
);
1449 okChildInt("argcA", count
);
1455 if (dllver
.dwMajorVersion
!= 0)
1457 /* The more recent versions of shell32.dll accept quoted filenames
1458 * while older ones (e.g. 4.00) don't. Still we want to test this
1459 * because IE 6 depends on the new behavior.
1460 * One day we may need to check the exact version of the dll but for
1461 * now making sure DllGetVersion() is present is sufficient.
1463 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
1464 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
1465 ok(rc
> 32, "%s failed: rc=%ld err=%u\n", shell_call
, rc
,
1467 okChildInt("argcA", 5);
1468 okChildString("argvA3", "Open");
1469 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1470 okChildPath("argvA4", filename
);
1476 const char* urlprefix
;
1477 const char* basename
;
1482 #define URL_SUCCESS 0x1
1483 #define USE_COLON 0x2
1484 #define USE_BSLASH 0x4
1486 static fileurl_tests_t fileurl_tests
[]=
1488 /* How many slashes does it take... */
1489 {"file:", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1490 {"file:/", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1491 {"file://", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1492 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1493 {"File:///", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1494 {"file:////", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1495 {"file://///", "%s\\test file.shlexec", 0, 0x1},
1497 /* Test with Windows-style paths */
1498 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_COLON
, 0x1},
1499 {"file:///", "%s\\test file.shlexec", URL_SUCCESS
| USE_BSLASH
, 0x1},
1501 /* Check handling of hostnames */
1502 {"file://localhost/", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1503 {"file://localhost:80/", "%s\\test file.shlexec", 0, 0x1},
1504 {"file://LocalHost/", "%s\\test file.shlexec", URL_SUCCESS
, 0x1},
1505 {"file://127.0.0.1/", "%s\\test file.shlexec", 0, 0x1},
1506 {"file://::1/", "%s\\test file.shlexec", 0, 0x1},
1507 {"file://notahost/", "%s\\test file.shlexec", 0, 0x1},
1509 /* Environment variables are not expanded in URLs */
1510 {"%urlprefix%", "%s\\test file.shlexec", 0, 0x1},
1511 {"file:///", "%s\\%%urlenvvar%% file.shlexec", 0, 0x1},
1516 static void test_fileurl(void)
1518 char filename
[MAX_PATH
], fileurl
[MAX_PATH
], longtmpdir
[MAX_PATH
];
1519 char command
[MAX_PATH
];
1520 const fileurl_tests_t
* test
;
1524 rc
= (INT_PTR
)ShellExecute(NULL
, NULL
, "file:///nosuchfile.shlexec", NULL
, NULL
, SW_SHOWNORMAL
);
1527 win_skip("shell32 is too old (likely < 4.72). Skipping the file URL tests\n");
1531 get_long_path_name(tmpdir
, longtmpdir
, sizeof(longtmpdir
)/sizeof(*longtmpdir
));
1532 SetEnvironmentVariable("urlprefix", "file:///");
1533 SetEnvironmentVariable("urlenvvar", "test");
1536 while (test
->basename
)
1538 /* Build the file URL */
1539 sprintf(filename
, test
->basename
, longtmpdir
);
1540 strcpy(fileurl
, test
->urlprefix
);
1541 strcat(fileurl
, filename
);
1542 s
= fileurl
+ strlen(test
->urlprefix
);
1545 if (!(test
->flags
& USE_COLON
) && *s
== ':')
1547 else if (!(test
->flags
& USE_BSLASH
) && *s
== '\\')
1552 /* Test it first with FindExecutable() */
1553 rc
= (INT_PTR
)FindExecutableA(fileurl
, NULL
, command
);
1554 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) failed: bad rc=%lu\n", fileurl
, rc
);
1556 /* Then ShellExecute() */
1557 rc
= shell_execute(NULL
, fileurl
, NULL
, NULL
);
1558 if (bad_shellexecute
)
1560 win_skip("shell32 is too old (likely 4.72). Skipping the file URL tests\n");
1563 if (test
->flags
& URL_SUCCESS
)
1565 if ((test
->todo
& 0x1) == 0)
1566 ok(rc
> 32, "%s failed: bad rc=%lu\n", shell_call
, rc
);
1568 ok(rc
> 32, "%s failed: bad rc=%lu\n", shell_call
, rc
);
1572 if ((test
->todo
& 0x1) == 0)
1573 ok(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1574 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1575 "%s failed: bad rc=%lu\n", shell_call
, rc
);
1577 ok(rc
== SE_ERR_FNF
|| rc
== SE_ERR_PNF
||
1578 broken(rc
== SE_ERR_ACCESSDENIED
) /* win2000 */,
1579 "%s failed: bad rc=%lu\n", shell_call
, rc
);
1583 if ((test
->todo
& 0x2) == 0)
1584 okChildInt("argcA", 5);
1586 okChildInt("argcA", 5);
1588 if ((test
->todo
& 0x4) == 0)
1589 okChildString("argvA3", "Open");
1591 okChildString("argvA3", "Open");
1593 if ((test
->todo
& 0x8) == 0)
1594 okChildPath("argvA4", filename
);
1596 okChildPath("argvA4", filename
);
1601 SetEnvironmentVariable("urlprefix", NULL
);
1602 SetEnvironmentVariable("urlenvvar", NULL
);
1605 static void test_find_executable(void)
1607 char notepad_path
[MAX_PATH
];
1608 char filename
[MAX_PATH
];
1609 char command
[MAX_PATH
];
1610 const filename_tests_t
* test
;
1613 if (!create_test_association(".sfe"))
1615 skip("Unable to create association for '.sfe'\n");
1618 create_test_verb(".sfe", "Open", 1, "%1");
1620 /* Don't test FindExecutable(..., NULL), it always crashes */
1622 strcpy(command
, "your word");
1623 if (0) /* Can crash on Vista! */
1625 rc
=(INT_PTR
)FindExecutableA(NULL
, NULL
, command
);
1626 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1627 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1630 GetSystemDirectoryA( notepad_path
, MAX_PATH
);
1631 strcat( notepad_path
, "\\notepad.exe" );
1633 /* Search for something that should be in the system-wide search path (no default directory) */
1634 strcpy(command
, "your word");
1635 rc
=(INT_PTR
)FindExecutableA("notepad.exe", NULL
, command
);
1636 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1637 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1639 /* Search for something that should be in the system-wide search path (with default directory) */
1640 strcpy(command
, "your word");
1641 rc
=(INT_PTR
)FindExecutableA("notepad.exe", tmpdir
, command
);
1642 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", "notepad.exe", rc
);
1643 ok(strcasecmp(command
, notepad_path
) == 0, "FindExecutable(%s) returned command=[%s]\n", "notepad.exe", command
);
1645 strcpy(command
, "your word");
1646 rc
=(INT_PTR
)FindExecutableA(tmpdir
, NULL
, command
);
1647 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc
);
1648 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
1650 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
1651 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1652 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1653 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1655 rc
=(INT_PTR
)FindExecutableA("test file.sfe", tmpdir
, command
);
1656 ok(rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1658 rc
=(INT_PTR
)FindExecutableA("test file.sfe", NULL
, command
);
1659 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1661 delete_test_association(".sfe");
1663 if (!create_test_association(".shl"))
1665 skip("Unable to create association for '.shl'\n");
1668 create_test_verb(".shl", "Open", 0, "Open");
1670 sprintf(filename
, "%s\\test file.shl", tmpdir
);
1671 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1672 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %ld\n", filename
, rc
);
1674 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
1675 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1677 delete_test_association(".shl");
1681 /* On Windows XP and 2003 FindExecutable() is completely broken.
1682 * Probably what it does is convert the filename to 8.3 format,
1683 * which as a side effect converts the '.shlfoo' extension to '.shl',
1684 * and then tries to find an association for '.shl'. This means it
1685 * will normally fail on most extensions with more than 3 characters,
1686 * like '.mpeg', etc.
1687 * Also it means we cannot do any other test.
1689 win_skip("FindExecutable() is broken -> not running 4+ character extension tests\n");
1693 test
=filename_tests
;
1694 while (test
->basename
)
1696 sprintf(filename
, test
->basename
, tmpdir
);
1697 if (strchr(filename
, '/'))
1708 /* Win98 does not '\0'-terminate command! */
1709 memset(command
, '\0', sizeof(command
));
1710 rc
=(INT_PTR
)FindExecutableA(filename
, NULL
, command
);
1713 if ((test
->todo
& 0x10)==0)
1715 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
1719 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%ld\n", filename
, rc
);
1724 equal
=strcmp(command
, argv0
) == 0 ||
1725 /* NT4 returns an extra 0x8 character! */
1726 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
1727 if ((test
->todo
& 0x20)==0)
1729 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1730 filename
, command
, argv0
);
1734 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1735 filename
, command
, argv0
);
1743 static filename_tests_t lnk_tests
[]=
1745 /* Pass bad / nonexistent filenames as a parameter */
1746 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
1747 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
1749 /* Pass regular paths as a parameter */
1750 {NULL
, "%s\\test file.shlexec", 0xa, 33},
1751 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1753 /* Pass filenames with no association as a parameter */
1754 {NULL
, "%s\\test file.noassoc", 0xa, 33},
1759 static void test_lnks(void)
1761 char filename
[MAX_PATH
];
1762 char params
[MAX_PATH
];
1763 const filename_tests_t
* test
;
1766 /* Should open through our association */
1767 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
1768 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
1769 ok(rc
> 32, "%s failed: rc=%lu err=%u\n", shell_call
, rc
, GetLastError());
1770 okChildInt("argcA", 5);
1771 okChildString("argvA3", "Open");
1772 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
1773 get_long_path_name(params
, filename
, sizeof(filename
));
1774 okChildPath("argvA4", filename
);
1776 todo_wait rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_DOENVSUBST
, NULL
, "%TMPDIR%\\test_shortcut_shlexec.lnk", NULL
, NULL
, NULL
);
1777 ok(rc
> 32, "%s failed: rc=%lu err=%u\n", shell_call
, rc
, GetLastError());
1778 okChildInt("argcA", 5);
1779 todo_wine
okChildString("argvA3", "Open");
1780 sprintf(params
, "%s\\test file.shlexec", tmpdir
);
1781 get_long_path_name(params
, filename
, sizeof(filename
));
1782 todo_wine
okChildPath("argvA4", filename
);
1784 /* Should just run our executable */
1785 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1786 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
1787 ok(rc
> 32, "%s failed: rc=%lu err=%u\n", shell_call
, rc
, GetLastError());
1788 okChildInt("argcA", 4);
1789 okChildString("argvA3", "Lnk");
1791 /* Lnk's ContextMenuHandler has priority over an explicit class */
1792 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, "shlexec.shlexec");
1793 ok(rc
> 32, "%s failed: rc=%lu err=%u\n", shell_call
, rc
, GetLastError());
1794 okChildInt("argcA", 4);
1795 okChildString("argvA3", "Lnk");
1797 if (dllver
.dwMajorVersion
>=6)
1800 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1801 * Older versions don't or are quite buggy in this regard.
1803 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1811 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
, NULL
);
1812 ok(rc
> 32, "%s failed: rc=%lu err=%u\n", shell_call
, rc
,
1814 okChildInt("argcA", 4);
1815 okChildString("argvA3", "Lnk");
1818 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1820 while (test
->basename
)
1823 sprintf(params
+1, test
->basename
, tmpdir
);
1824 strcat(params
,"\"");
1825 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
1829 if ((test
->todo
& 0x1)==0)
1831 ok(rc
==test
->rc
, "%s failed: rc=%lu err=%u\n", shell_call
,
1832 rc
, GetLastError());
1836 ok(rc
==test
->rc
, "%s failed: rc=%lu err=%u\n", shell_call
,
1837 rc
, GetLastError());
1841 if ((test
->todo
& 0x2)==0)
1843 okChildInt("argcA", 5);
1847 okChildInt("argcA", 5);
1849 if ((test
->todo
& 0x4)==0)
1851 okChildString("argvA3", "Lnk");
1855 okChildString("argvA3", "Lnk");
1857 sprintf(params
, test
->basename
, tmpdir
);
1858 if ((test
->todo
& 0x8)==0)
1860 okChildPath("argvA4", params
);
1864 okChildPath("argvA4", params
);
1872 static void test_exes(void)
1874 char filename
[MAX_PATH
];
1878 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
1880 /* We need NOZONECHECKS on Win2003 to block a dialog */
1881 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
1883 ok(rc
> 32, "%s returned %lu\n", shell_call
, rc
);
1884 okChildInt("argcA", 4);
1885 okChildString("argvA3", "Exec");
1887 if (! skip_noassoc_tests
)
1889 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
1890 if (CopyFile(argv0
, filename
, FALSE
))
1892 rc
=shell_execute(NULL
, filename
, params
, NULL
);
1894 ok(rc
==SE_ERR_NOASSOC
, "%s succeeded: rc=%lu\n", shell_call
, rc
);
1900 win_skip("Skipping shellexecute of file with unassociated extension\n");
1904 static void test_exes_long(void)
1906 char filename
[MAX_PATH
];
1908 char longparam
[MAX_PATH
];
1911 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1912 longparam
[rc
]='a'+rc
%26;
1913 longparam
[MAX_PATH
-1]=0;
1916 sprintf(params
, "shlexec \"%s\" %s", child_file
,longparam
);
1918 /* We need NOZONECHECKS on Win2003 to block a dialog */
1919 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
1921 ok(rc
> 32, "%s returned %lu\n", shell_call
, rc
);
1922 okChildInt("argcA", 4);
1923 okChildString("argvA3", longparam
);
1925 if (! skip_noassoc_tests
)
1927 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
1928 if (CopyFile(argv0
, filename
, FALSE
))
1930 rc
=shell_execute(NULL
, filename
, params
, NULL
);
1932 ok(rc
==SE_ERR_NOASSOC
, "%s succeeded: rc=%lu\n", shell_call
, rc
);
1938 win_skip("Skipping shellexecute of file with unassociated extension\n");
1944 const char* command
;
1945 const char* ddeexec
;
1946 const char* application
;
1950 const char* expectedDdeExec
;
1954 static dde_tests_t dde_tests
[] =
1956 /* Test passing and not passing command-line
1957 * argument, no DDE */
1958 {"", NULL
, NULL
, NULL
, NULL
, FALSE
, "", 0x0},
1959 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, TRUE
, "", 0x0},
1961 /* Test passing and not passing command-line
1962 * argument, with DDE */
1963 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, FALSE
, "[open(\"%s\")]", 0x0},
1964 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, TRUE
, "[open(\"%s\")]", 0x0},
1966 /* Test unquoted %1 in command and ddeexec
1967 * (test filename has space) */
1968 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", 0x0},
1970 /* Test ifexec precedence over ddeexec */
1971 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE
, "[ifexec(\"%s\")]", 0x0},
1973 /* Test default DDE topic */
1974 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, FALSE
, "[open(\"%s\")]", 0x0},
1976 /* Test default DDE application */
1977 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, FALSE
, "[open(\"%s\")]", 0x0},
1979 {NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0x0}
1982 static DWORD WINAPI
hooked_WaitForInputIdle(HANDLE process
, DWORD timeout
)
1984 return WaitForSingleObject(dde_ready_event
, timeout
);
1988 * WaitForInputIdle() will normally return immediately for console apps. That's
1989 * a problem for us because ShellExecute will assume that an app is ready to
1990 * receive DDE messages after it has called WaitForInputIdle() on that app.
1991 * To work around that we install our own version of WaitForInputIdle() that
1992 * will wait for the child to explicitly tell us that it is ready. We do that
1993 * by changing the entry for WaitForInputIdle() in the shell32 import address
1996 static void hook_WaitForInputIdle(DWORD (WINAPI
*new_func
)(HANDLE
, DWORD
))
1999 PIMAGE_NT_HEADERS nt_headers
;
2000 DWORD import_directory_rva
;
2001 PIMAGE_IMPORT_DESCRIPTOR import_descriptor
;
2003 base
= (char *) GetModuleHandleA("shell32.dll");
2004 nt_headers
= (PIMAGE_NT_HEADERS
)(base
+ ((PIMAGE_DOS_HEADER
) base
)->e_lfanew
);
2005 import_directory_rva
= nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
].VirtualAddress
;
2007 /* Search for the correct imported module by walking the import descriptors */
2008 import_descriptor
= (PIMAGE_IMPORT_DESCRIPTOR
)(base
+ import_directory_rva
);
2009 while (U(*import_descriptor
).OriginalFirstThunk
!= 0)
2011 char *import_module_name
;
2013 import_module_name
= base
+ import_descriptor
->Name
;
2014 if (lstrcmpiA(import_module_name
, "user32.dll") == 0 ||
2015 lstrcmpiA(import_module_name
, "user32") == 0)
2017 PIMAGE_THUNK_DATA int_entry
;
2018 PIMAGE_THUNK_DATA iat_entry
;
2020 /* The import name table and import address table are two parallel
2021 * arrays. We need the import name table to find the imported
2022 * routine and the import address table to patch the address, so
2023 * walk them side by side */
2024 int_entry
= (PIMAGE_THUNK_DATA
)(base
+ U(*import_descriptor
).OriginalFirstThunk
);
2025 iat_entry
= (PIMAGE_THUNK_DATA
)(base
+ import_descriptor
->FirstThunk
);
2026 while (int_entry
->u1
.Ordinal
!= 0)
2028 if (! IMAGE_SNAP_BY_ORDINAL(int_entry
->u1
.Ordinal
))
2030 PIMAGE_IMPORT_BY_NAME import_by_name
;
2031 import_by_name
= (PIMAGE_IMPORT_BY_NAME
)(base
+ int_entry
->u1
.AddressOfData
);
2032 if (lstrcmpA((char *) import_by_name
->Name
, "WaitForInputIdle") == 0)
2034 /* Found the correct routine in the correct imported module. Patch it. */
2036 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), PAGE_READWRITE
, &old_prot
);
2037 iat_entry
->u1
.Function
= (ULONG_PTR
) new_func
;
2038 VirtualProtect(&iat_entry
->u1
.Function
, sizeof(ULONG_PTR
), old_prot
, &old_prot
);
2048 import_descriptor
++;
2052 static void test_dde(void)
2054 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
2055 const dde_tests_t
* test
;
2061 hook_WaitForInputIdle(hooked_WaitForInputIdle
);
2063 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2065 /* Default service is application name minus path and extension */
2066 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
2067 *strchr(defApplication
, '.') = 0;
2069 map
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
2070 4096, "winetest_shlexec_dde_map");
2071 shared_block
= MapViewOfFile(map
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 4096);
2074 while (test
->command
)
2076 if (!create_test_association(".sde"))
2078 skip("Unable to create association for '.sde'\n");
2081 create_test_verb_dde(".sde", "Open", 0, test
->command
, test
->ddeexec
,
2082 test
->application
, test
->topic
, test
->ifexec
);
2084 if (test
->application
!= NULL
|| test
->topic
!= NULL
)
2086 strcpy(shared_block
, test
->application
? test
->application
: defApplication
);
2087 strcpy(shared_block
+ strlen(shared_block
) + 1, test
->topic
? test
->topic
: SZDDESYS_TOPIC
);
2091 shared_block
[0] = '\0';
2092 shared_block
[1] = '\0';
2096 dde_ready_event
= CreateEventA(NULL
, FALSE
, FALSE
, "winetest_shlexec_dde_ready");
2097 rc
= shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, filename
, NULL
, NULL
, NULL
);
2098 CloseHandle(dde_ready_event
);
2099 if ((test
->todo
& 0x1)==0)
2101 ok(32 < rc
, "%s failed: rc=%lu err=%u\n", shell_call
,
2102 rc
, GetLastError());
2106 ok(32 < rc
, "%s failed: rc=%lu err=%u\n", shell_call
,
2107 rc
, GetLastError());
2111 if ((test
->todo
& 0x2)==0)
2113 okChildInt("argcA", test
->expectedArgs
+ 3);
2117 okChildInt("argcA", test
->expectedArgs
+ 3);
2119 if (test
->expectedArgs
== 1)
2121 if ((test
->todo
& 0x4) == 0)
2123 okChildPath("argvA3", filename
);
2127 okChildPath("argvA3", filename
);
2130 if ((test
->todo
& 0x8) == 0)
2132 sprintf(params
, test
->expectedDdeExec
, filename
);
2133 okChildPath("ddeExec", params
);
2137 sprintf(params
, test
->expectedDdeExec
, filename
);
2138 okChildPath("ddeExec", params
);
2142 delete_test_association(".sde");
2146 UnmapViewOfFile(shared_block
);
2148 hook_WaitForInputIdle((void *) WaitForInputIdle
);
2151 #define DDE_DEFAULT_APP_VARIANTS 2
2154 const char* command
;
2155 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
2157 int rc
[DDE_DEFAULT_APP_VARIANTS
];
2158 } dde_default_app_tests_t
;
2160 static dde_default_app_tests_t dde_default_app_tests
[] =
2162 /* Windows XP and 98 handle default DDE app names in different ways.
2163 * The application name we see in the first test determines the pattern
2164 * of application names and return codes we will look for. */
2166 /* Test unquoted existing filename with a space */
2167 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
2168 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
2170 /* Test quoted existing filename with a space */
2171 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
2172 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
2174 /* Test unquoted filename with a space that doesn't exist, but
2176 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
2177 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
2179 /* Test quoted filename with a space that does not exist */
2180 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
2181 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
2183 /* Test filename supplied without the extension */
2184 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
2185 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
2187 /* Test an unquoted nonexistent filename */
2188 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
2189 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
2191 /* Test an application that will be found on the path */
2192 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
2193 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
2195 /* Test an application that will not be found on the path */
2196 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2197 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
2199 {NULL
, {NULL
}, 0, {0}}
2205 DWORD threadIdParent
;
2206 } dde_thread_info_t
;
2208 static DWORD CALLBACK
ddeThread(LPVOID arg
)
2210 dde_thread_info_t
*info
= arg
;
2211 assert(info
&& info
->filename
);
2212 PostThreadMessage(info
->threadIdParent
,
2214 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
, NULL
),
2219 static void test_dde_default_app(void)
2221 char filename
[MAX_PATH
];
2223 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
2224 const dde_default_app_tests_t
* test
;
2231 post_quit_on_execute
= FALSE
;
2233 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
2234 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0L);
2235 assert(rc
== DMLERR_NO_ERROR
);
2237 sprintf(filename
, "%s\\test file.sde", tmpdir
);
2239 /* It is strictly not necessary to register an application name here, but wine's
2240 * DdeNameService implementation complains if 0L is passed instead of
2241 * hszApplication with DNS_FILTEROFF */
2242 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2243 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
2244 assert(hszApplication
&& hszTopic
);
2245 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_REGISTER
| DNS_FILTEROFF
));
2247 test
= dde_default_app_tests
;
2248 while (test
->command
)
2250 if (!create_test_association(".sde"))
2252 skip("Unable to create association for '.sde'\n");
2255 sprintf(params
, test
->command
, tmpdir
);
2256 create_test_verb_dde(".sde", "Open", 1, params
, "[test]", NULL
,
2258 ddeApplication
[0] = 0;
2260 /* No application will be run as we will respond to the first DDE event,
2261 * so don't wait for it */
2264 assert(CreateThread(NULL
, 0, ddeThread
, &info
, 0, &threadId
));
2265 while (GetMessage(&msg
, NULL
, 0, 0)) DispatchMessage(&msg
);
2266 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
2268 /* First test, find which set of test data we expect to see */
2269 if (test
== dde_default_app_tests
)
2272 for (i
=0; i
<DDE_DEFAULT_APP_VARIANTS
; i
++)
2274 if (!strcmp(ddeApplication
, test
->expectedDdeApplication
[i
]))
2280 if (i
== DDE_DEFAULT_APP_VARIANTS
)
2281 skip("Default DDE application test does not match any available results, using first expected data set.\n");
2284 if ((test
->todo
& 0x1)==0)
2286 ok(rc
==test
->rc
[which
], "%s failed: rc=%lu err=%u\n", shell_call
,
2287 rc
, GetLastError());
2291 ok(rc
==test
->rc
[which
], "%s failed: rc=%lu err=%u\n", shell_call
,
2292 rc
, GetLastError());
2296 if ((test
->todo
& 0x2)==0)
2298 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2299 "Expected application '%s', got '%s'\n",
2300 test
->expectedDdeApplication
[which
], ddeApplication
);
2304 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
2305 "Expected application '%s', got '%s'\n",
2306 test
->expectedDdeApplication
[which
], ddeApplication
);
2310 delete_test_association(".sde");
2314 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_UNREGISTER
));
2315 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
2316 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
2317 assert(DdeUninitialize(ddeInst
));
2320 static void init_test(void)
2323 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
2324 char filename
[MAX_PATH
];
2325 WCHAR lnkfile
[MAX_PATH
];
2327 const char* const * testfile
;
2332 hdll
=GetModuleHandleA("shell32.dll");
2333 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
2336 dllver
.cbSize
=sizeof(dllver
);
2337 pDllGetVersion(&dllver
);
2338 trace("major=%d minor=%d build=%d platform=%d\n",
2339 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
2340 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
2344 memset(&dllver
, 0, sizeof(dllver
));
2347 r
= CoInitialize(NULL
);
2348 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
2352 rc
=GetModuleFileName(NULL
, argv0
, sizeof(argv0
));
2353 assert(rc
!=0 && rc
<sizeof(argv0
));
2354 if (GetFileAttributes(argv0
)==INVALID_FILE_ATTRIBUTES
)
2356 strcat(argv0
, ".so");
2357 ok(GetFileAttributes(argv0
)!=INVALID_FILE_ATTRIBUTES
,
2358 "unable to find argv0!\n");
2361 GetTempPathA(sizeof(filename
), filename
);
2362 GetTempFileNameA(filename
, "wt", 0, tmpdir
);
2363 DeleteFileA( tmpdir
);
2364 rc
= CreateDirectoryA( tmpdir
, NULL
);
2365 ok( rc
, "failed to create %s err %u\n", tmpdir
, GetLastError() );
2366 /* Set %TMPDIR% for the tests */
2367 SetEnvironmentVariableA("TMPDIR", tmpdir
);
2369 rc
= GetTempFileNameA(tmpdir
, "wt", 0, child_file
);
2371 init_event(child_file
);
2373 /* Set up the test files */
2379 sprintf(filename
, *testfile
, tmpdir
);
2380 hfile
=CreateFile(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2381 FILE_ATTRIBUTE_NORMAL
, NULL
);
2382 if (hfile
==INVALID_HANDLE_VALUE
)
2384 trace("unable to create '%s': err=%u\n", filename
, GetLastError());
2391 /* Setup the test shortcuts */
2392 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
2393 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2394 desc
.description
=NULL
;
2396 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
2399 desc
.arguments
="ignored";
2404 create_lnk(lnkfile
, &desc
, 0);
2406 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
2407 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
2408 desc
.description
=NULL
;
2412 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
2413 desc
.arguments
=params
;
2418 create_lnk(lnkfile
, &desc
, 0);
2420 /* Create a basic association suitable for most tests */
2421 if (!create_test_association(".shlexec"))
2423 skip("Unable to create association for '.shlexec'\n");
2426 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
2427 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
2428 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
2429 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
2430 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
2431 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
2433 create_test_verb(".shlexec", "NoQuotesParam2", 0, "NoQuotesParam2 %2");
2434 create_test_verb(".shlexec", "QuotedParam2", 0, "QuotedParam2 \"%2\"");
2436 create_test_verb(".shlexec", "NoQuotesAllParams", 0, "NoQuotesAllParams %*");
2437 create_test_verb(".shlexec", "QuotedAllParams", 0, "QuotedAllParams \"%*\"");
2439 create_test_verb(".shlexec", "NoQuotesParams345etc", 0, "NoQuotesParams345etc %~3");
2440 create_test_verb(".shlexec", "QuotedParams345etc", 0, "QuotedParams345etc \"%~3\"");
2443 static void cleanup_test(void)
2445 char filename
[MAX_PATH
];
2446 const char* const * testfile
;
2448 /* Delete the test files */
2452 sprintf(filename
, *testfile
, tmpdir
);
2453 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
2454 SetFileAttributes(filename
, FILE_ATTRIBUTE_NORMAL
);
2455 DeleteFile(filename
);
2458 DeleteFile(child_file
);
2459 RemoveDirectoryA(tmpdir
);
2461 /* Delete the test association */
2462 delete_test_association(".shlexec");
2464 CloseHandle(hEvent
);
2469 static void test_directory(void)
2471 char path
[MAX_PATH
], newdir
[MAX_PATH
];
2475 /* copy this executable to a new folder and cd to it */
2476 sprintf(newdir
, "%s\\newfolder", tmpdir
);
2477 rc
= CreateDirectoryA( newdir
, NULL
);
2478 ok( rc
, "failed to create %s err %u\n", newdir
, GetLastError() );
2479 sprintf(path
, "%s\\%s", newdir
, path_find_file_name(argv0
));
2480 CopyFileA(argv0
, path
, FALSE
);
2481 SetCurrentDirectory(tmpdir
);
2483 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
2485 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2486 NULL
, path_find_file_name(argv0
), params
, NULL
, NULL
);
2487 todo_wine
ok(rc
== SE_ERR_FNF
, "%s returned %lu\n", shell_call
, rc
);
2489 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
|SEE_MASK_FLAG_NO_UI
,
2490 NULL
, path_find_file_name(argv0
), params
, newdir
, NULL
);
2491 ok(rc
> 32, "%s returned %lu\n", shell_call
, rc
);
2492 okChildInt("argcA", 4);
2493 okChildString("argvA3", "Exec");
2494 todo_wine
okChildPath("longPath", path
);
2497 RemoveDirectoryA(newdir
);
2503 myARGC
= winetest_get_mainargs(&myARGV
);
2506 doChild(myARGC
, myARGV
);
2512 test_commandline2argv();
2514 test_lpFile_parsed();
2517 test_find_executable();
2522 test_dde_default_app();