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
;
63 * ShellExecute wrappers
66 static void dump_child(void);
69 static void init_event(const char* child_file
)
72 event_name
=strrchr(child_file
, '\\')+1;
73 hEvent
=CreateEvent(NULL
, FALSE
, FALSE
, event_name
);
76 static void strcat_param(char* str
, const char* param
)
90 static char shell_call
[2048]="";
91 static int shell_execute(LPCSTR operation
, LPCSTR file
, LPCSTR parameters
, LPCSTR directory
)
95 strcpy(shell_call
, "ShellExecute(");
96 strcat_param(shell_call
, operation
);
97 strcat(shell_call
, ", ");
98 strcat_param(shell_call
, file
);
99 strcat(shell_call
, ", ");
100 strcat_param(shell_call
, parameters
);
101 strcat(shell_call
, ", ");
102 strcat_param(shell_call
, directory
);
103 strcat(shell_call
, ")");
104 if (winetest_debug
> 1)
105 trace("%s\n", shell_call
);
107 DeleteFile(child_file
);
108 SetLastError(0xcafebabe);
110 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
111 * association it displays the 'Open With' dialog and I could not find
112 * a flag to prevent this.
114 rc
=(int)ShellExecute(NULL
, operation
, file
, parameters
, directory
,
120 wait_rc
=WaitForSingleObject(hEvent
, 5000);
121 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject returned %d\n", wait_rc
);
123 /* The child process may have changed the result file, so let profile
124 * functions know about it
126 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
133 static int shell_execute_ex(DWORD mask
, LPCSTR operation
, LPCSTR file
,
134 LPCSTR parameters
, LPCSTR directory
)
136 SHELLEXECUTEINFO sei
;
140 strcpy(shell_call
, "ShellExecuteEx(");
141 strcat_param(shell_call
, operation
);
142 strcat(shell_call
, ", ");
143 strcat_param(shell_call
, file
);
144 strcat(shell_call
, ", ");
145 strcat_param(shell_call
, parameters
);
146 strcat(shell_call
, ", ");
147 strcat_param(shell_call
, directory
);
148 strcat(shell_call
, ")");
149 if (winetest_debug
> 1)
150 trace("%s\n", shell_call
);
152 sei
.cbSize
=sizeof(sei
);
153 sei
.fMask
=SEE_MASK_NOCLOSEPROCESS
| mask
;
155 sei
.lpVerb
=operation
;
157 sei
.lpParameters
=parameters
;
158 sei
.lpDirectory
=directory
;
159 sei
.nShow
=SW_SHOWNORMAL
;
160 sei
.hInstApp
=NULL
; /* Out */
166 sei
.hProcess
=NULL
; /* Out */
168 DeleteFile(child_file
);
169 SetLastError(0xcafebabe);
170 success
=ShellExecuteEx(&sei
);
171 rc
=(int)sei
.hInstApp
;
172 ok((success
&& rc
> 32) || (!success
&& rc
<= 32),
173 "%s rc=%d and hInstApp=%d is not allowed\n", shell_call
, success
, rc
);
178 if (sei
.hProcess
!=NULL
)
180 wait_rc
=WaitForSingleObject(sei
.hProcess
, 5000);
181 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject(hProcess) returned %d\n", wait_rc
);
183 wait_rc
=WaitForSingleObject(hEvent
, 5000);
184 ok(wait_rc
==WAIT_OBJECT_0
, "WaitForSingleObject returned %d\n", wait_rc
);
186 /* The child process may have changed the result file, so let profile
187 * functions know about it
189 WritePrivateProfileStringA(NULL
, NULL
, NULL
, child_file
);
200 * Functions to create / delete associations wrappers
204 static BOOL
create_test_association(const char* extension
)
206 HKEY hkey
, hkey_shell
;
207 char class[MAX_PATH
];
210 sprintf(class, "shlexec%s", extension
);
211 rc
=RegCreateKeyEx(HKEY_CLASSES_ROOT
, extension
, 0, NULL
, 0, KEY_SET_VALUE
,
213 if (rc
!= ERROR_SUCCESS
)
216 rc
=RegSetValueEx(hkey
, NULL
, 0, REG_SZ
, (LPBYTE
) class, strlen(class)+1);
217 ok(rc
==ERROR_SUCCESS
, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
220 rc
=RegCreateKeyEx(HKEY_CLASSES_ROOT
, class, 0, NULL
, 0,
221 KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkey
, NULL
);
222 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc
);
224 rc
=RegCreateKeyEx(hkey
, "shell", 0, NULL
, 0,
225 KEY_CREATE_SUB_KEY
, NULL
, &hkey_shell
, NULL
);
226 ok(rc
==ERROR_SUCCESS
, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc
);
229 CloseHandle(hkey_shell
);
234 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
235 static LSTATUS
myRegDeleteTreeA(HKEY hKey
, LPCSTR lpszSubKey
)
238 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
239 DWORD dwMaxLen
, dwSize
;
240 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
245 ret
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
249 /* Get highest length for keys, values */
250 ret
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
251 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
252 if (ret
) goto cleanup
;
256 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
257 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(CHAR
))
259 /* Name too big: alloc a buffer for it */
260 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(CHAR
))))
262 ret
= ERROR_NOT_ENOUGH_MEMORY
;
268 /* Recursively delete all the subkeys */
272 if (RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
273 NULL
, NULL
, NULL
)) break;
275 ret
= myRegDeleteTreeA(hSubKey
, lpszName
);
276 if (ret
) goto cleanup
;
280 ret
= RegDeleteKeyA(hKey
, lpszSubKey
);
285 if (RegEnumValueA(hKey
, 0, lpszName
, &dwSize
,
286 NULL
, NULL
, NULL
, NULL
)) break;
288 ret
= RegDeleteValueA(hKey
, lpszName
);
289 if (ret
) goto cleanup
;
293 /* Free buffer if allocated */
294 if (lpszName
!= szNameBuf
)
295 HeapFree( GetProcessHeap(), 0, lpszName
);
297 RegCloseKey(hSubKey
);
301 static void delete_test_association(const char* extension
)
303 char class[MAX_PATH
];
305 sprintf(class, "shlexec%s", extension
);
306 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, class);
307 myRegDeleteTreeA(HKEY_CLASSES_ROOT
, extension
);
310 static void create_test_verb_dde(const char* extension
, const char* verb
,
311 int rawcmd
, const char* cmdtail
, const char *ddeexec
,
312 const char *application
, const char *topic
,
315 HKEY hkey_shell
, hkey_verb
, hkey_cmd
;
316 char shell
[MAX_PATH
];
320 sprintf(shell
, "shlexec%s\\shell", extension
);
321 rc
=RegOpenKeyEx(HKEY_CLASSES_ROOT
, shell
, 0,
322 KEY_CREATE_SUB_KEY
, &hkey_shell
);
323 assert(rc
==ERROR_SUCCESS
);
324 rc
=RegCreateKeyEx(hkey_shell
, verb
, 0, NULL
, 0, KEY_CREATE_SUB_KEY
,
325 NULL
, &hkey_verb
, NULL
);
326 assert(rc
==ERROR_SUCCESS
);
327 rc
=RegCreateKeyEx(hkey_verb
, "command", 0, NULL
, 0, KEY_SET_VALUE
,
328 NULL
, &hkey_cmd
, NULL
);
329 assert(rc
==ERROR_SUCCESS
);
333 rc
=RegSetValueEx(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmdtail
, strlen(cmdtail
)+1);
337 cmd
=malloc(strlen(argv0
)+10+strlen(child_file
)+2+strlen(cmdtail
)+1);
338 sprintf(cmd
,"%s shlexec \"%s\" %s", argv0
, child_file
, cmdtail
);
339 rc
=RegSetValueEx(hkey_cmd
, NULL
, 0, REG_SZ
, (LPBYTE
)cmd
, strlen(cmd
)+1);
340 assert(rc
==ERROR_SUCCESS
);
346 HKEY hkey_ddeexec
, hkey_application
, hkey_topic
, hkey_ifexec
;
348 rc
=RegCreateKeyEx(hkey_verb
, "ddeexec", 0, NULL
, 0, KEY_SET_VALUE
|
349 KEY_CREATE_SUB_KEY
, NULL
, &hkey_ddeexec
, NULL
);
350 assert(rc
==ERROR_SUCCESS
);
351 rc
=RegSetValueEx(hkey_ddeexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ddeexec
,
353 assert(rc
==ERROR_SUCCESS
);
356 rc
=RegCreateKeyEx(hkey_ddeexec
, "application", 0, NULL
, 0, KEY_SET_VALUE
,
357 NULL
, &hkey_application
, NULL
);
358 assert(rc
==ERROR_SUCCESS
);
359 rc
=RegSetValueEx(hkey_application
, NULL
, 0, REG_SZ
, (LPBYTE
)application
,
360 strlen(application
)+1);
361 assert(rc
==ERROR_SUCCESS
);
362 CloseHandle(hkey_application
);
366 rc
=RegCreateKeyEx(hkey_ddeexec
, "topic", 0, NULL
, 0, KEY_SET_VALUE
,
367 NULL
, &hkey_topic
, NULL
);
368 assert(rc
==ERROR_SUCCESS
);
369 rc
=RegSetValueEx(hkey_topic
, NULL
, 0, REG_SZ
, (LPBYTE
)topic
,
371 assert(rc
==ERROR_SUCCESS
);
372 CloseHandle(hkey_topic
);
376 rc
=RegCreateKeyEx(hkey_ddeexec
, "ifexec", 0, NULL
, 0, KEY_SET_VALUE
,
377 NULL
, &hkey_ifexec
, NULL
);
378 assert(rc
==ERROR_SUCCESS
);
379 rc
=RegSetValueEx(hkey_ifexec
, NULL
, 0, REG_SZ
, (LPBYTE
)ifexec
,
381 assert(rc
==ERROR_SUCCESS
);
382 CloseHandle(hkey_ifexec
);
384 CloseHandle(hkey_ddeexec
);
387 CloseHandle(hkey_shell
);
388 CloseHandle(hkey_verb
);
389 CloseHandle(hkey_cmd
);
392 static void create_test_verb(const char* extension
, const char* verb
,
393 int rawcmd
, const char* cmdtail
)
395 create_test_verb_dde(extension
, verb
, rawcmd
, cmdtail
, NULL
, NULL
,
401 * Functions to check that the child process was started just right
402 * (borrowed from dlls/kernel32/tests/process.c)
406 static const char* encodeA(const char* str
)
408 static char encoded
[2*1024+1];
413 len
= strlen(str
) + 1;
414 if (len
>= sizeof(encoded
)/2)
416 fprintf(stderr
, "string is too long!\n");
420 for (i
= 0; i
< len
; i
++)
421 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
426 static unsigned decode_char(char c
)
428 if (c
>= '0' && c
<= '9') return c
- '0';
429 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
430 assert(c
>= 'A' && c
<= 'F');
434 static char* decodeA(const char* str
)
436 static char decoded
[1024];
440 len
= strlen(str
) / 2;
441 if (!len
--) return NULL
;
442 if (len
>= sizeof(decoded
))
444 fprintf(stderr
, "string is too long!\n");
448 for (i
= 0; i
< len
; i
++)
449 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
454 static void childPrintf(HANDLE h
, const char* fmt
, ...)
460 va_start(valist
, fmt
);
461 vsprintf(buffer
, fmt
, valist
);
463 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
466 static void doChild(int argc
, char** argv
)
473 hFile
=CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
474 if (hFile
== INVALID_HANDLE_VALUE
)
478 childPrintf(hFile
, "[Arguments]\r\n");
479 if (winetest_debug
> 2)
480 trace("argcA=%d\n", argc
);
481 childPrintf(hFile
, "argcA=%d\r\n", argc
);
482 for (i
= 0; i
< argc
; i
++)
484 if (winetest_debug
> 2)
485 trace("argvA%d=%s\n", i
, argv
[i
]);
486 childPrintf(hFile
, "argvA%d=%s\r\n", i
, encodeA(argv
[i
]));
490 init_event(filename
);
495 static char* getChildString(const char* sect
, const char* key
)
500 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), child_file
);
501 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
502 assert(!(strlen(buf
) & 1));
507 static void dump_child(void)
509 if (winetest_debug
> 1)
515 c
=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file
);
516 trace("argcA=%d\n",c
);
519 sprintf(key
, "argvA%d", i
);
520 str
=getChildString("Arguments", key
);
521 trace("%s=%s\n", key
, str
);
526 static int StrCmpPath(const char* s1
, const char* s2
)
528 if (!s1
&& !s2
) return 0;
539 if ((*s1
=='/' || *s1
=='\\') && (*s2
=='/' || *s2
=='\\'))
541 while (*s1
=='/' || *s1
=='\\')
543 while (*s2
=='/' || *s2
=='\\')
546 else if (toupper(*s1
)==toupper(*s2
))
563 static int _okChildString(const char* file
, int line
, const char* key
, const char* expected
)
566 result
=getChildString("Arguments", key
);
567 return ok_(file
, line
)(lstrcmpiA(result
, expected
) == 0,
568 "%s expected '%s', got '%s'\n", key
, expected
, result
);
571 static int _okChildPath(const char* file
, int line
, const char* key
, const char* expected
)
574 result
=getChildString("Arguments", key
);
575 return ok_(file
, line
)(StrCmpPath(result
, expected
) == 0,
576 "%s expected '%s', got '%s'\n", key
, expected
, result
);
579 static int _okChildInt(const char* file
, int line
, const char* key
, int expected
)
582 result
=GetPrivateProfileIntA("Arguments", key
, expected
, child_file
);
583 return ok_(file
, line
)(result
== expected
,
584 "%s expected %d, but got %d\n", key
, expected
, result
);
587 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
588 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
589 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
599 static const char* testfiles
[]=
601 "%s\\test file.shlexec",
602 "%s\\%%nasty%% $file.shlexec",
603 "%s\\test file.noassoc",
604 "%s\\test file.noassoc.shlexec",
605 "%s\\test file.shlexec.noassoc",
606 "%s\\test_shortcut_shlexec.lnk",
607 "%s\\test_shortcut_exe.lnk",
609 "%s\\test file.shlfoo",
611 "%s\\masked file.shlexec",
622 const char* basename
;
627 static filename_tests_t filename_tests
[]=
629 /* Test bad / nonexistent filenames */
630 {NULL
, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
631 {NULL
, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF
},
634 {NULL
, "%s\\test file.shlexec", 0x0, 33},
635 {NULL
, "%s\\test file.shlexec.", 0x0, 33},
636 {NULL
, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
637 {NULL
, "%s/test file.shlexec", 0x0, 33},
639 /* Test filenames with no association */
640 {NULL
, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
642 /* Test double extensions */
643 {NULL
, "%s\\test file.noassoc.shlexec", 0x0, 33},
644 {NULL
, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC
},
646 /* Test alternate verbs */
647 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF
},
648 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC
},
650 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
651 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
653 /* Test file masked due to space */
654 {NULL
, "%s\\masked file.shlexec", 0x1, 33},
655 /* Test if quoting prevents the masking */
656 {NULL
, "%s\\masked file.shlexec", 0x40, 33},
661 static filename_tests_t noquotes_tests
[]=
663 /* Test unquoted '%1' thingies */
664 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
665 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
666 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
671 static void test_filename(void)
673 char filename
[MAX_PATH
];
674 const filename_tests_t
* test
;
679 while (test
->basename
)
681 sprintf(filename
, test
->basename
, tmpdir
);
682 if (strchr(filename
, '/'))
692 if ((test
->todo
& 0x40)==0)
694 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
698 char quoted
[MAX_PATH
+ 2];
699 sprintf(quoted
, "\"%s\"", filename
);
700 rc
=shell_execute(test
->verb
, quoted
, NULL
, NULL
);
704 if ((test
->todo
& 0x1)==0)
706 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
711 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
717 if ((test
->todo
& 0x2)==0)
719 okChildInt("argcA", 5);
723 okChildInt("argcA", 5);
725 verb
=(test
->verb
? test
->verb
: "Open");
726 if ((test
->todo
& 0x4)==0)
728 okChildString("argvA3", verb
);
732 okChildString("argvA3", verb
);
734 if ((test
->todo
& 0x8)==0)
736 okChildPath("argvA4", filename
);
740 okChildPath("argvA4", filename
);
747 while (test
->basename
)
749 sprintf(filename
, test
->basename
, tmpdir
);
750 rc
=shell_execute(test
->verb
, filename
, NULL
, NULL
);
753 if ((test
->todo
& 0x1)==0)
755 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
760 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
769 verb
=(test
->verb
? test
->verb
: "Open");
770 if ((test
->todo
& 0x4)==0)
772 okChildString("argvA3", verb
);
776 okChildString("argvA3", verb
);
785 space
=strchr(str
, ' ');
788 sprintf(attrib
, "argvA%d", count
);
789 if ((test
->todo
& 0x8)==0)
791 okChildPath(attrib
, str
);
795 okChildPath(attrib
, str
);
802 if ((test
->todo
& 0x2)==0)
804 okChildInt("argcA", count
);
808 okChildInt("argcA", count
);
814 if (dllver
.dwMajorVersion
!= 0)
816 /* The more recent versions of shell32.dll accept quoted filenames
817 * while older ones (e.g. 4.00) don't. Still we want to test this
818 * because IE 6 depends on the new behavior.
819 * One day we may need to check the exact version of the dll but for
820 * now making sure DllGetVersion() is present is sufficient.
822 sprintf(filename
, "\"%s\\test file.shlexec\"", tmpdir
);
823 rc
=shell_execute(NULL
, filename
, NULL
, NULL
);
824 ok(rc
> 32, "%s failed: rc=%d err=%d\n", shell_call
, rc
,
826 okChildInt("argcA", 5);
827 okChildString("argvA3", "Open");
828 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
829 okChildPath("argvA4", filename
);
833 static void test_find_executable(void)
835 char filename
[MAX_PATH
];
836 char command
[MAX_PATH
];
837 const filename_tests_t
* test
;
840 if (!create_test_association(".sfe"))
842 skip("Unable to create association for '.sfe'\n");
845 create_test_verb(".sfe", "Open", 1, "%1");
847 /* Don't test FindExecutable(..., NULL), it always crashes */
849 strcpy(command
, "your word");
850 if (0) /* Can crash on Vista! */
852 rc
=(int)FindExecutableA(NULL
, NULL
, command
);
853 ok(rc
== SE_ERR_FNF
|| rc
> 32 /* nt4 */, "FindExecutable(NULL) returned %d\n", rc
);
854 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
857 strcpy(command
, "your word");
858 rc
=(int)FindExecutableA(tmpdir
, NULL
, command
);
859 ok(rc
== SE_ERR_NOASSOC
/* >= win2000 */ || rc
> 32 /* win98, nt4 */, "FindExecutable(NULL) returned %d\n", rc
);
860 ok(strcmp(command
, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command
);
862 sprintf(filename
, "%s\\test file.sfe", tmpdir
);
863 rc
=(int)FindExecutableA(filename
, NULL
, command
);
864 ok(rc
> 32, "FindExecutable(%s) returned %d\n", filename
, rc
);
865 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
867 rc
=(int)FindExecutableA("test file.sfe", tmpdir
, command
);
868 ok(rc
> 32, "FindExecutable(%s) returned %d\n", filename
, rc
);
870 rc
=(int)FindExecutableA("test file.sfe", NULL
, command
);
871 ok(rc
== SE_ERR_FNF
, "FindExecutable(%s) returned %d\n", filename
, rc
);
873 delete_test_association(".sfe");
875 if (!create_test_association(".shl"))
877 skip("Unable to create association for '.shl'\n");
880 create_test_verb(".shl", "Open", 0, "Open");
882 sprintf(filename
, "%s\\test file.shl", tmpdir
);
883 rc
=(int)FindExecutableA(filename
, NULL
, command
);
884 ok(rc
== SE_ERR_FNF
/* NT4 */ || rc
> 32, "FindExecutable(%s) returned %d\n", filename
, rc
);
886 sprintf(filename
, "%s\\test file.shlfoo", tmpdir
);
887 rc
=(int)FindExecutableA(filename
, NULL
, command
);
889 delete_test_association(".shl");
893 /* On Windows XP and 2003 FindExecutable() is completely broken.
894 * Probably what it does is convert the filename to 8.3 format,
895 * which as a side effect converts the '.shlfoo' extension to '.shl',
896 * and then tries to find an association for '.shl'. This means it
897 * will normally fail on most extensions with more than 3 characters,
899 * Also it means we cannot do any other test.
901 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
906 while (test
->basename
)
908 sprintf(filename
, test
->basename
, tmpdir
);
909 if (strchr(filename
, '/'))
920 /* Win98 does not '\0'-terminate command! */
921 memset(command
, '\0', sizeof(command
));
922 rc
=(int)FindExecutableA(filename
, NULL
, command
);
925 if ((test
->todo
& 0x10)==0)
927 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%d\n", filename
, rc
);
931 ok(rc
==test
->rc
, "FindExecutable(%s) failed: rc=%d\n", filename
, rc
);
936 equal
=strcmp(command
, argv0
) == 0 ||
937 /* NT4 returns an extra 0x8 character! */
938 (strlen(command
) == strlen(argv0
)+1 && strncmp(command
, argv0
, strlen(argv0
)) == 0);
939 if ((test
->todo
& 0x20)==0)
941 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
942 filename
, command
, argv0
);
946 ok(equal
, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
947 filename
, command
, argv0
);
955 static filename_tests_t lnk_tests
[]=
957 /* Pass bad / nonexistent filenames as a parameter */
958 {NULL
, "%s\\nonexistent.shlexec", 0xa, 33},
959 {NULL
, "%s\\nonexistent.noassoc", 0xa, 33},
961 /* Pass regular paths as a parameter */
962 {NULL
, "%s\\test file.shlexec", 0xa, 33},
963 {NULL
, "%s/%%nasty%% $file.shlexec", 0xa, 33},
965 /* Pass filenames with no association as a parameter */
966 {NULL
, "%s\\test file.noassoc", 0xa, 33},
971 static void test_lnks(void)
973 char filename
[MAX_PATH
];
974 char params
[MAX_PATH
];
975 const filename_tests_t
* test
;
978 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
979 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
);
980 ok(rc
> 32, "%s failed: rc=%d err=%d\n", shell_call
, rc
,
982 okChildInt("argcA", 5);
983 okChildString("argvA3", "Open");
984 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
985 okChildPath("argvA4", filename
);
987 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
988 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
);
989 ok(rc
> 32, "%s failed: rc=%d err=%d\n", shell_call
, rc
,
991 okChildInt("argcA", 4);
992 okChildString("argvA3", "Lnk");
994 if (dllver
.dwMajorVersion
>=6)
997 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
998 * Older versions don't or are quite buggy in this regard.
1000 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1008 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, NULL
, NULL
);
1009 ok(rc
> 32, "%s failed: rc=%d err=%d\n", shell_call
, rc
,
1011 okChildInt("argcA", 4);
1012 okChildString("argvA3", "Lnk");
1015 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1017 while (test
->basename
)
1020 sprintf(params
+1, test
->basename
, tmpdir
);
1021 strcat(params
,"\"");
1022 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, filename
, params
,
1026 if ((test
->todo
& 0x1)==0)
1028 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
1029 rc
, GetLastError());
1033 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
1034 rc
, GetLastError());
1038 if ((test
->todo
& 0x2)==0)
1040 okChildInt("argcA", 5);
1044 okChildInt("argcA", 5);
1046 if ((test
->todo
& 0x4)==0)
1048 okChildString("argvA3", "Lnk");
1052 okChildString("argvA3", "Lnk");
1054 sprintf(params
, test
->basename
, tmpdir
);
1055 if ((test
->todo
& 0x8)==0)
1057 okChildPath("argvA4", params
);
1061 okChildPath("argvA4", params
);
1069 static void test_exes(void)
1071 char filename
[MAX_PATH
];
1075 sprintf(params
, "shlexec \"%s\" Exec", child_file
);
1077 /* We need NOZONECHECKS on Win2003 to block a dialog */
1078 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
1080 ok(rc
> 32, "%s returned %d\n", shell_call
, rc
);
1081 okChildInt("argcA", 4);
1082 okChildString("argvA3", "Exec");
1084 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
1085 if (CopyFile(argv0
, filename
, FALSE
))
1087 rc
=shell_execute(NULL
, filename
, params
, NULL
);
1089 ok(rc
==SE_ERR_NOASSOC
, "%s succeeded: rc=%d\n", shell_call
, rc
);
1094 static void test_exes_long(void)
1096 char filename
[MAX_PATH
];
1098 char longparam
[MAX_PATH
];
1101 for (rc
= 0; rc
< MAX_PATH
; rc
++)
1102 longparam
[rc
]='a'+rc
%26;
1103 longparam
[MAX_PATH
-1]=0;
1106 sprintf(params
, "shlexec \"%s\" %s", child_file
,longparam
);
1108 /* We need NOZONECHECKS on Win2003 to block a dialog */
1109 rc
=shell_execute_ex(SEE_MASK_NOZONECHECKS
, NULL
, argv0
, params
,
1111 ok(rc
> 32, "%s returned %d\n", shell_call
, rc
);
1112 okChildInt("argcA", 4);
1113 okChildString("argvA3", longparam
);
1115 sprintf(filename
, "%s\\test file.noassoc", tmpdir
);
1116 if (CopyFile(argv0
, filename
, FALSE
))
1118 rc
=shell_execute(NULL
, filename
, params
, NULL
);
1120 ok(rc
==SE_ERR_NOASSOC
, "%s succeeded: rc=%d\n", shell_call
, rc
);
1127 const char* command
;
1128 const char* ddeexec
;
1129 const char* application
;
1133 const char* expectedDdeExec
;
1138 static dde_tests_t dde_tests
[] =
1140 /* Test passing and not passing command-line
1141 * argument, no DDE */
1142 {"", NULL
, NULL
, NULL
, NULL
, FALSE
, "", 0x0, 33},
1143 {"\"%1\"", NULL
, NULL
, NULL
, NULL
, TRUE
, "", 0x0, 33},
1145 /* Test passing and not passing command-line
1146 * argument, with DDE */
1147 {"", "[open(\"%1\")]", "shlexec", "dde", NULL
, FALSE
, "[open(\"%s\")]", 0x0, 33},
1148 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL
, TRUE
, "[open(\"%s\")]", 0x0, 33},
1150 /* Test unquoted %1 in command and ddeexec
1151 * (test filename has space) */
1152 {"%1", "[open(%1)]", "shlexec", "dde", NULL
, 2, "[open(%s)]", 0x0, 33},
1154 /* Test ifexec precedence over ddeexec */
1155 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE
, "[ifexec(\"%s\")]", 0x0, 33},
1157 /* Test default DDE topic */
1158 {"", "[open(\"%1\")]", "shlexec", NULL
, NULL
, FALSE
, "[open(\"%s\")]", 0x0, 33},
1160 /* Test default DDE application */
1161 {"", "[open(\"%1\")]", NULL
, "dde", NULL
, FALSE
, "[open(\"%s\")]", 0x0, 33},
1163 {NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0x0, 0}
1166 static DWORD ddeInst
;
1167 static HSZ hszTopic
;
1168 static char ddeExec
[MAX_PATH
], ddeApplication
[MAX_PATH
];
1169 static BOOL denyNextConnection
;
1171 static HDDEDATA CALLBACK
ddeCb(UINT uType
, UINT uFmt
, HCONV hConv
,
1172 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
1173 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
1177 if (winetest_debug
> 2)
1178 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
1179 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
1184 if (!DdeCmpStringHandles(hsz1
, hszTopic
))
1186 if (denyNextConnection
)
1187 denyNextConnection
= FALSE
;
1190 size
= DdeQueryString(ddeInst
, hsz2
, ddeApplication
, MAX_PATH
, CP_WINANSI
);
1191 assert(size
< MAX_PATH
);
1192 return (HDDEDATA
)TRUE
;
1195 return (HDDEDATA
)FALSE
;
1198 size
= DdeGetData(hData
, (LPBYTE
)ddeExec
, MAX_PATH
, 0L);
1199 assert(size
< MAX_PATH
);
1200 DdeFreeDataHandle(hData
);
1201 return (HDDEDATA
)DDE_FACK
;
1211 DWORD threadIdParent
;
1212 } dde_thread_info_t
;
1214 static DWORD CALLBACK
ddeThread(LPVOID arg
)
1216 dde_thread_info_t
*info
= (dde_thread_info_t
*)arg
;
1217 assert(info
&& info
->filename
);
1218 PostThreadMessage(info
->threadIdParent
,
1220 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
, NULL
, info
->filename
, NULL
, NULL
),
1225 /* ShellExecute won't successfully send DDE commands to console applications after starting them,
1226 * so we run a DDE server in this application, deny the first connection request to make
1227 * ShellExecute start the application, and then process the next DDE connection in this application
1228 * to see the execute command that is sent. */
1229 static void test_dde(void)
1231 char filename
[MAX_PATH
], defApplication
[MAX_PATH
];
1233 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
1234 const dde_tests_t
* test
;
1241 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
1242 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0L);
1243 assert(rc
== DMLERR_NO_ERROR
);
1245 sprintf(filename
, "%s\\test file.sde", tmpdir
);
1247 /* Default service is application name minus path and extension */
1248 strcpy(defApplication
, strrchr(argv0
, '\\')+1);
1249 *strchr(defApplication
, '.') = 0;
1252 while (test
->command
)
1254 if (!create_test_association(".sde"))
1256 skip("Unable to create association for '.sfe'\n");
1259 create_test_verb_dde(".sde", "Open", 0, test
->command
, test
->ddeexec
,
1260 test
->application
, test
->topic
, test
->ifexec
);
1261 hszApplication
= DdeCreateStringHandleA(ddeInst
, test
->application
?
1262 test
->application
: defApplication
, CP_WINANSI
);
1263 hszTopic
= DdeCreateStringHandleA(ddeInst
, test
->topic
? test
->topic
: SZDDESYS_TOPIC
,
1265 assert(hszApplication
&& hszTopic
);
1266 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_REGISTER
));
1267 denyNextConnection
= TRUE
;
1270 assert(CreateThread(NULL
, 0, ddeThread
, (LPVOID
)&info
, 0, &threadId
));
1271 while (GetMessage(&msg
, NULL
, 0, 0)) DispatchMessage(&msg
);
1272 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
1273 if ((test
->todo
& 0x1)==0)
1275 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
1276 rc
, GetLastError());
1280 ok(rc
==test
->rc
, "%s failed: rc=%d err=%d\n", shell_call
,
1281 rc
, GetLastError());
1285 if ((test
->todo
& 0x2)==0)
1287 okChildInt("argcA", test
->expectedArgs
+ 3);
1291 okChildInt("argcA", test
->expectedArgs
+ 3);
1293 if (test
->expectedArgs
== 1)
1295 if ((test
->todo
& 0x4) == 0)
1297 okChildPath("argvA3", filename
);
1301 okChildPath("argvA3", filename
);
1304 if ((test
->todo
& 0x8) == 0)
1306 sprintf(params
, test
->expectedDdeExec
, filename
);
1307 ok(StrCmpPath(params
, ddeExec
) == 0,
1308 "ddeexec expected '%s', got '%s'\n", params
, ddeExec
);
1312 sprintf(params
, test
->expectedDdeExec
, filename
);
1313 ok(StrCmpPath(params
, ddeExec
) == 0,
1314 "ddeexec expected '%s', got '%s'\n", params
, ddeExec
);
1318 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_UNREGISTER
));
1319 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
1320 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
1321 delete_test_association(".sde");
1325 assert(DdeUninitialize(ddeInst
));
1328 #define DDE_DEFAULT_APP_VARIANTS 2
1331 const char* command
;
1332 const char* expectedDdeApplication
[DDE_DEFAULT_APP_VARIANTS
];
1334 int rc
[DDE_DEFAULT_APP_VARIANTS
];
1335 } dde_default_app_tests_t
;
1337 static dde_default_app_tests_t dde_default_app_tests
[] =
1339 /* Windows XP and 98 handle default DDE app names in different ways.
1340 * The application name we see in the first test determines the pattern
1341 * of application names and return codes we will look for. */
1343 /* Test unquoted existing filename with a space */
1344 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1345 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1347 /* Test quoted existing filename with a space */
1348 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1349 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1351 /* Test unquoted filename with a space that doesn't exist, but
1353 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1354 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1356 /* Test quoted filename with a space that does not exist */
1357 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1358 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1360 /* Test filename supplied without the extension */
1361 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1362 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1364 /* Test an unquoted nonexistent filename */
1365 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1366 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1368 /* Test an application that will be found on the path */
1369 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1370 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1372 /* Test an application that will not be found on the path */
1373 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1374 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1376 {NULL
, {NULL
}, 0, {0}}
1379 static void test_dde_default_app(void)
1381 char filename
[MAX_PATH
];
1383 dde_thread_info_t info
= { filename
, GetCurrentThreadId() };
1384 const dde_default_app_tests_t
* test
;
1391 rc
= DdeInitializeA(&ddeInst
, ddeCb
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
|
1392 CBF_FAIL_POKES
| CBF_FAIL_REQUESTS
, 0L);
1393 assert(rc
== DMLERR_NO_ERROR
);
1395 sprintf(filename
, "%s\\test file.sde", tmpdir
);
1397 /* It is strictly not necessary to register an application name here, but wine's
1398 * DdeNameService implementation complains if 0L is passed instead of
1399 * hszApplication with DNS_FILTEROFF */
1400 hszApplication
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
1401 hszTopic
= DdeCreateStringHandleA(ddeInst
, "shlexec", CP_WINANSI
);
1402 assert(hszApplication
&& hszTopic
);
1403 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_REGISTER
| DNS_FILTEROFF
));
1405 test
= dde_default_app_tests
;
1406 while (test
->command
)
1408 if (!create_test_association(".sde"))
1410 skip("Unable to create association for '.sde'\n");
1413 sprintf(params
, test
->command
, tmpdir
);
1414 create_test_verb_dde(".sde", "Open", 1, params
, "[test]", NULL
,
1416 denyNextConnection
= FALSE
;
1417 ddeApplication
[0] = 0;
1419 /* No application will be run as we will respond to the first DDE event,
1420 * so don't wait for it */
1423 assert(CreateThread(NULL
, 0, ddeThread
, (LPVOID
)&info
, 0, &threadId
));
1424 while (GetMessage(&msg
, NULL
, 0, 0)) DispatchMessage(&msg
);
1425 rc
= msg
.wParam
> 32 ? 33 : msg
.wParam
;
1427 /* First test, find which set of test data we expect to see */
1428 if (test
== dde_default_app_tests
)
1431 for (i
=0; i
<DDE_DEFAULT_APP_VARIANTS
; i
++)
1433 if (!strcmp(ddeApplication
, test
->expectedDdeApplication
[i
]))
1439 if (i
== DDE_DEFAULT_APP_VARIANTS
)
1440 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1443 if ((test
->todo
& 0x1)==0)
1445 ok(rc
==test
->rc
[which
], "%s failed: rc=%d err=%d\n", shell_call
,
1446 rc
, GetLastError());
1450 ok(rc
==test
->rc
[which
], "%s failed: rc=%d err=%d\n", shell_call
,
1451 rc
, GetLastError());
1455 if ((test
->todo
& 0x2)==0)
1457 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
1458 "Expected application '%s', got '%s'\n",
1459 test
->expectedDdeApplication
[which
], ddeApplication
);
1463 ok(!strcmp(ddeApplication
, test
->expectedDdeApplication
[which
]),
1464 "Expected application '%s', got '%s'\n",
1465 test
->expectedDdeApplication
[which
], ddeApplication
);
1469 delete_test_association(".sde");
1473 assert(DdeNameService(ddeInst
, hszApplication
, 0L, DNS_UNREGISTER
));
1474 assert(DdeFreeStringHandle(ddeInst
, hszTopic
));
1475 assert(DdeFreeStringHandle(ddeInst
, hszApplication
));
1476 assert(DdeUninitialize(ddeInst
));
1479 static void init_test(void)
1482 HRESULT (WINAPI
*pDllGetVersion
)(DLLVERSIONINFO
*);
1483 char filename
[MAX_PATH
];
1484 WCHAR lnkfile
[MAX_PATH
];
1486 const char* const * testfile
;
1491 hdll
=GetModuleHandleA("shell32.dll");
1492 pDllGetVersion
=(void*)GetProcAddress(hdll
, "DllGetVersion");
1495 dllver
.cbSize
=sizeof(dllver
);
1496 pDllGetVersion(&dllver
);
1497 trace("major=%d minor=%d build=%d platform=%d\n",
1498 dllver
.dwMajorVersion
, dllver
.dwMinorVersion
,
1499 dllver
.dwBuildNumber
, dllver
.dwPlatformID
);
1503 memset(&dllver
, 0, sizeof(dllver
));
1506 r
= CoInitialize(NULL
);
1507 ok(SUCCEEDED(r
), "CoInitialize failed (0x%08x)\n", r
);
1511 rc
=GetModuleFileName(NULL
, argv0
, sizeof(argv0
));
1512 assert(rc
!=0 && rc
<sizeof(argv0
));
1513 if (GetFileAttributes(argv0
)==INVALID_FILE_ATTRIBUTES
)
1515 strcat(argv0
, ".so");
1516 ok(GetFileAttributes(argv0
)!=INVALID_FILE_ATTRIBUTES
,
1517 "unable to find argv0!\n");
1520 GetTempPathA(sizeof(tmpdir
)/sizeof(*tmpdir
), tmpdir
);
1521 assert(GetTempFileNameA(tmpdir
, "wt", 0, child_file
)!=0);
1522 init_event(child_file
);
1524 /* Set up the test files */
1530 sprintf(filename
, *testfile
, tmpdir
);
1531 hfile
=CreateFile(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1532 FILE_ATTRIBUTE_NORMAL
, NULL
);
1533 if (hfile
==INVALID_HANDLE_VALUE
)
1535 trace("unable to create '%s': err=%d\n", filename
, GetLastError());
1542 /* Setup the test shortcuts */
1543 sprintf(filename
, "%s\\test_shortcut_shlexec.lnk", tmpdir
);
1544 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
1545 desc
.description
=NULL
;
1547 sprintf(filename
, "%s\\test file.shlexec", tmpdir
);
1550 desc
.arguments
="ignored";
1555 create_lnk(lnkfile
, &desc
, 0);
1557 sprintf(filename
, "%s\\test_shortcut_exe.lnk", tmpdir
);
1558 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, lnkfile
, sizeof(lnkfile
)/sizeof(*lnkfile
));
1559 desc
.description
=NULL
;
1563 sprintf(params
, "shlexec \"%s\" Lnk", child_file
);
1564 desc
.arguments
=params
;
1569 create_lnk(lnkfile
, &desc
, 0);
1571 /* Create a basic association suitable for most tests */
1572 if (!create_test_association(".shlexec"))
1574 skip("Unable to create association for '.shlexec'\n");
1577 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1578 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1579 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1580 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1581 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1582 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1585 static void cleanup_test(void)
1587 char filename
[MAX_PATH
];
1588 const char* const * testfile
;
1590 /* Delete the test files */
1594 sprintf(filename
, *testfile
, tmpdir
);
1595 DeleteFile(filename
);
1598 DeleteFile(child_file
);
1600 /* Delete the test association */
1601 delete_test_association(".shlexec");
1603 CloseHandle(hEvent
);
1608 static void test_commandline(void)
1610 static const WCHAR one
[] = {'o','n','e',0};
1611 static const WCHAR two
[] = {'t','w','o',0};
1612 static const WCHAR three
[] = {'t','h','r','e','e',0};
1613 static const WCHAR four
[] = {'f','o','u','r',0};
1615 static const WCHAR fmt1
[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
1616 static const WCHAR fmt2
[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
1617 static const WCHAR fmt3
[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
1618 static const WCHAR fmt4
[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
1619 static const WCHAR fmt5
[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
1621 static const WCHAR chkfmt1
[] = {'%','s','=','%','s',0};
1622 static const WCHAR chkfmt2
[] = {'%','s',' ','%','s',0};
1623 static const WCHAR chkfmt3
[] = {'\\','\"','%','s','\"',0};
1624 static const WCHAR chkfmt4
[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
1626 LPWSTR
*args
= (LPWSTR
*)0xdeadcafe;
1629 wsprintfW(cmdline
,fmt1
,one
,two
,three
,four
);
1630 args
=CommandLineToArgvW(cmdline
,&numargs
);
1631 if (args
== NULL
&& numargs
== -1)
1633 win_skip("CommandLineToArgvW not implemented, skipping\n");
1636 ok(numargs
== 4, "expected 4 args, got %i\n",numargs
);
1637 ok(lstrcmpW(args
[0],one
)==0,"arg0 is not as expected\n");
1638 ok(lstrcmpW(args
[1],two
)==0,"arg1 is not as expected\n");
1639 ok(lstrcmpW(args
[2],three
)==0,"arg2 is not as expected\n");
1640 ok(lstrcmpW(args
[3],four
)==0,"arg3 is not as expected\n");
1642 wsprintfW(cmdline
,fmt2
,one
,two
,three
,four
);
1643 args
=CommandLineToArgvW(cmdline
,&numargs
);
1644 ok(numargs
== 5, "expected 5 args, got %i\n",numargs
);
1645 ok(args
[0][0]==0,"arg0 is not as expected\n");
1646 ok(lstrcmpW(args
[1],one
)==0,"arg1 is not as expected\n");
1647 ok(lstrcmpW(args
[2],two
)==0,"arg2 is not as expected\n");
1648 ok(lstrcmpW(args
[3],three
)==0,"arg3 is not as expected\n");
1649 ok(lstrcmpW(args
[4],four
)==0,"arg4 is not as expected\n");
1651 wsprintfW(cmdline
,fmt3
,one
,two
,three
,four
);
1652 args
=CommandLineToArgvW(cmdline
,&numargs
);
1653 ok(numargs
== 2, "expected 2 args, got %i\n",numargs
);
1654 wsprintfW(cmdline
,chkfmt1
,one
,two
);
1655 ok(lstrcmpW(args
[0],cmdline
)==0,"arg0 is not as expected\n");
1656 wsprintfW(cmdline
,chkfmt1
,three
,four
);
1657 ok(lstrcmpW(args
[1],cmdline
)==0,"arg1 is not as expected\n");
1659 wsprintfW(cmdline
,fmt4
,one
,two
,three
,four
);
1660 args
=CommandLineToArgvW(cmdline
,&numargs
);
1661 ok(numargs
== 3, "expected 3 args, got %i\n",numargs
);
1662 ok(lstrcmpW(args
[0],one
)==0,"arg0 is not as expected\n");
1663 wsprintfW(cmdline
,chkfmt2
,two
,three
);
1664 ok(lstrcmpW(args
[1],cmdline
)==0,"arg1 is not as expected\n");
1665 ok(lstrcmpW(args
[2],four
)==0,"arg2 is not as expected\n");
1667 wsprintfW(cmdline
,fmt5
,one
,two
,three
,four
);
1668 args
=CommandLineToArgvW(cmdline
,&numargs
);
1669 ok(numargs
== 2, "expected 2 args, got %i\n",numargs
);
1670 wsprintfW(cmdline
,chkfmt3
,one
);
1671 todo_wine
ok(lstrcmpW(args
[0],cmdline
)==0,"arg0 is not as expected\n");
1672 wsprintfW(cmdline
,chkfmt4
,two
,three
,four
);
1673 todo_wine
ok(lstrcmpW(args
[1],cmdline
)==0,"arg1 is not as expected\n");
1679 myARGC
= winetest_get_mainargs(&myARGV
);
1682 doChild(myARGC
, myARGV
);
1689 test_find_executable();
1694 test_dde_default_app();