5e97f61171a5a28ca6880be3eeac79145d8c12c6
[reactos.git] / rostests / winetests / shell32 / shlexec.c
1 /*
2 * Unit test of the ShellExecute function.
3 *
4 * Copyright 2005 Francois Gouget for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 /* TODO:
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
27 * in the PATH
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
32 * we could check
33 */
34
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
39
40 #include <stdio.h>
41 #include <assert.h>
42
43 #include "wtypes.h"
44 #include "winbase.h"
45 #include "windef.h"
46 #include "shellapi.h"
47 #include "shlwapi.h"
48 #include "wine/test.h"
49
50 #include "shell32_test.h"
51
52
53 static char argv0[MAX_PATH];
54 static int myARGC;
55 static char** myARGV;
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
61
62 /***
63 *
64 * ShellExecute wrappers
65 *
66 ***/
67 static void dump_child(void);
68
69 static HANDLE hEvent;
70 static void init_event(const char* child_file)
71 {
72 char* event_name;
73 event_name=strrchr(child_file, '\\')+1;
74 hEvent=CreateEvent(NULL, FALSE, FALSE, event_name);
75 }
76
77 static void strcat_param(char* str, const char* param)
78 {
79 if (param!=NULL)
80 {
81 strcat(str, "\"");
82 strcat(str, param);
83 strcat(str, "\"");
84 }
85 else
86 {
87 strcat(str, "null");
88 }
89 }
90
91 static char shell_call[2048]="";
92 static int shell_execute(LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory)
93 {
94 INT_PTR rc;
95
96 strcpy(shell_call, "ShellExecute(");
97 strcat_param(shell_call, operation);
98 strcat(shell_call, ", ");
99 strcat_param(shell_call, file);
100 strcat(shell_call, ", ");
101 strcat_param(shell_call, parameters);
102 strcat(shell_call, ", ");
103 strcat_param(shell_call, directory);
104 strcat(shell_call, ")");
105 if (winetest_debug > 1)
106 trace("%s\n", shell_call);
107
108 DeleteFile(child_file);
109 SetLastError(0xcafebabe);
110
111 /* FIXME: We cannot use ShellExecuteEx() here because if there is no
112 * association it displays the 'Open With' dialog and I could not find
113 * a flag to prevent this.
114 */
115 rc=(INT_PTR)ShellExecute(NULL, operation, file, parameters, directory, SW_SHOWNORMAL);
116
117 if (rc > 32)
118 {
119 int wait_rc;
120 wait_rc=WaitForSingleObject(hEvent, 5000);
121 if (wait_rc == WAIT_TIMEOUT)
122 {
123 HWND wnd = FindWindowA("#32770", "Windows");
124 if (wnd != NULL)
125 {
126 SendMessage(wnd, WM_CLOSE, 0, 0);
127 win_skip("Skipping shellexecute of file with unassociated extension\n");
128 skip_noassoc_tests = TRUE;
129 rc = SE_ERR_NOASSOC;
130 }
131 }
132 ok(wait_rc==WAIT_OBJECT_0 || rc <= 32, "WaitForSingleObject returned %d\n", wait_rc);
133 }
134 /* The child process may have changed the result file, so let profile
135 * functions know about it
136 */
137 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
138 if (rc > 32)
139 dump_child();
140
141 return rc;
142 }
143
144 static int shell_execute_ex(DWORD mask, LPCSTR operation, LPCSTR file,
145 LPCSTR parameters, LPCSTR directory)
146 {
147 SHELLEXECUTEINFO sei;
148 BOOL success;
149 INT_PTR rc;
150
151 strcpy(shell_call, "ShellExecuteEx(");
152 strcat_param(shell_call, operation);
153 strcat(shell_call, ", ");
154 strcat_param(shell_call, file);
155 strcat(shell_call, ", ");
156 strcat_param(shell_call, parameters);
157 strcat(shell_call, ", ");
158 strcat_param(shell_call, directory);
159 strcat(shell_call, ")");
160 if (winetest_debug > 1)
161 trace("%s\n", shell_call);
162
163 sei.cbSize=sizeof(sei);
164 sei.fMask=SEE_MASK_NOCLOSEPROCESS | mask;
165 sei.hwnd=NULL;
166 sei.lpVerb=operation;
167 sei.lpFile=file;
168 sei.lpParameters=parameters;
169 sei.lpDirectory=directory;
170 sei.nShow=SW_SHOWNORMAL;
171 sei.hInstApp=NULL; /* Out */
172 sei.lpIDList=NULL;
173 sei.lpClass=NULL;
174 sei.hkeyClass=NULL;
175 sei.dwHotKey=0;
176 U(sei).hIcon=NULL;
177 sei.hProcess=NULL; /* Out */
178
179 DeleteFile(child_file);
180 SetLastError(0xcafebabe);
181 success=ShellExecuteEx(&sei);
182 rc=(INT_PTR)sei.hInstApp;
183 ok((success && rc > 32) || (!success && rc <= 32),
184 "%s rc=%d and hInstApp=%ld is not allowed\n", shell_call, success, rc);
185
186 if (rc > 32)
187 {
188 int wait_rc;
189 if (sei.hProcess!=NULL)
190 {
191 wait_rc=WaitForSingleObject(sei.hProcess, 5000);
192 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject(hProcess) returned %d\n", wait_rc);
193 }
194 wait_rc=WaitForSingleObject(hEvent, 5000);
195 ok(wait_rc==WAIT_OBJECT_0, "WaitForSingleObject returned %d\n", wait_rc);
196 }
197 /* The child process may have changed the result file, so let profile
198 * functions know about it
199 */
200 WritePrivateProfileStringA(NULL, NULL, NULL, child_file);
201 if (rc > 32)
202 dump_child();
203
204 return rc;
205 }
206
207
208
209 /***
210 *
211 * Functions to create / delete associations wrappers
212 *
213 ***/
214
215 static BOOL create_test_association(const char* extension)
216 {
217 HKEY hkey, hkey_shell;
218 char class[MAX_PATH];
219 LONG rc;
220
221 sprintf(class, "shlexec%s", extension);
222 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, extension, 0, NULL, 0, KEY_SET_VALUE,
223 NULL, &hkey, NULL);
224 if (rc != ERROR_SUCCESS)
225 return FALSE;
226
227 rc=RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE) class, strlen(class)+1);
228 ok(rc==ERROR_SUCCESS, "RegSetValueEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
229 CloseHandle(hkey);
230
231 rc=RegCreateKeyEx(HKEY_CLASSES_ROOT, class, 0, NULL, 0,
232 KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hkey, NULL);
233 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx '%s' failed, expected ERROR_SUCCESS, got %d\n", class, rc);
234
235 rc=RegCreateKeyEx(hkey, "shell", 0, NULL, 0,
236 KEY_CREATE_SUB_KEY, NULL, &hkey_shell, NULL);
237 ok(rc==ERROR_SUCCESS, "RegCreateKeyEx 'shell' failed, expected ERROR_SUCCESS, got %d\n", rc);
238
239 CloseHandle(hkey);
240 CloseHandle(hkey_shell);
241
242 return TRUE;
243 }
244
245 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
246 static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
247 {
248 LONG ret;
249 DWORD dwMaxSubkeyLen, dwMaxValueLen;
250 DWORD dwMaxLen, dwSize;
251 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
252 HKEY hSubKey = hKey;
253
254 if(lpszSubKey)
255 {
256 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
257 if (ret) return ret;
258 }
259
260 /* Get highest length for keys, values */
261 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
262 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
263 if (ret) goto cleanup;
264
265 dwMaxSubkeyLen++;
266 dwMaxValueLen++;
267 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
268 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
269 {
270 /* Name too big: alloc a buffer for it */
271 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
272 {
273 ret = ERROR_NOT_ENOUGH_MEMORY;
274 goto cleanup;
275 }
276 }
277
278
279 /* Recursively delete all the subkeys */
280 while (TRUE)
281 {
282 dwSize = dwMaxLen;
283 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
284 NULL, NULL, NULL)) break;
285
286 ret = myRegDeleteTreeA(hSubKey, lpszName);
287 if (ret) goto cleanup;
288 }
289
290 if (lpszSubKey)
291 ret = RegDeleteKeyA(hKey, lpszSubKey);
292 else
293 while (TRUE)
294 {
295 dwSize = dwMaxLen;
296 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
297 NULL, NULL, NULL, NULL)) break;
298
299 ret = RegDeleteValueA(hKey, lpszName);
300 if (ret) goto cleanup;
301 }
302
303 cleanup:
304 /* Free buffer if allocated */
305 if (lpszName != szNameBuf)
306 HeapFree( GetProcessHeap(), 0, lpszName);
307 if(lpszSubKey)
308 RegCloseKey(hSubKey);
309 return ret;
310 }
311
312 static void delete_test_association(const char* extension)
313 {
314 char class[MAX_PATH];
315
316 sprintf(class, "shlexec%s", extension);
317 myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
318 myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
319 }
320
321 static void create_test_verb_dde(const char* extension, const char* verb,
322 int rawcmd, const char* cmdtail, const char *ddeexec,
323 const char *application, const char *topic,
324 const char *ifexec)
325 {
326 HKEY hkey_shell, hkey_verb, hkey_cmd;
327 char shell[MAX_PATH];
328 char* cmd;
329 LONG rc;
330
331 sprintf(shell, "shlexec%s\\shell", extension);
332 rc=RegOpenKeyEx(HKEY_CLASSES_ROOT, shell, 0,
333 KEY_CREATE_SUB_KEY, &hkey_shell);
334 assert(rc==ERROR_SUCCESS);
335 rc=RegCreateKeyEx(hkey_shell, verb, 0, NULL, 0, KEY_CREATE_SUB_KEY,
336 NULL, &hkey_verb, NULL);
337 assert(rc==ERROR_SUCCESS);
338 rc=RegCreateKeyEx(hkey_verb, "command", 0, NULL, 0, KEY_SET_VALUE,
339 NULL, &hkey_cmd, NULL);
340 assert(rc==ERROR_SUCCESS);
341
342 if (rawcmd)
343 {
344 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
345 }
346 else
347 {
348 cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
349 sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
350 rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
351 assert(rc==ERROR_SUCCESS);
352 HeapFree(GetProcessHeap(), 0, cmd);
353 }
354
355 if (ddeexec)
356 {
357 HKEY hkey_ddeexec, hkey_application, hkey_topic, hkey_ifexec;
358
359 rc=RegCreateKeyEx(hkey_verb, "ddeexec", 0, NULL, 0, KEY_SET_VALUE |
360 KEY_CREATE_SUB_KEY, NULL, &hkey_ddeexec, NULL);
361 assert(rc==ERROR_SUCCESS);
362 rc=RegSetValueEx(hkey_ddeexec, NULL, 0, REG_SZ, (LPBYTE)ddeexec,
363 strlen(ddeexec)+1);
364 assert(rc==ERROR_SUCCESS);
365 if (application)
366 {
367 rc=RegCreateKeyEx(hkey_ddeexec, "application", 0, NULL, 0, KEY_SET_VALUE,
368 NULL, &hkey_application, NULL);
369 assert(rc==ERROR_SUCCESS);
370 rc=RegSetValueEx(hkey_application, NULL, 0, REG_SZ, (LPBYTE)application,
371 strlen(application)+1);
372 assert(rc==ERROR_SUCCESS);
373 CloseHandle(hkey_application);
374 }
375 if (topic)
376 {
377 rc=RegCreateKeyEx(hkey_ddeexec, "topic", 0, NULL, 0, KEY_SET_VALUE,
378 NULL, &hkey_topic, NULL);
379 assert(rc==ERROR_SUCCESS);
380 rc=RegSetValueEx(hkey_topic, NULL, 0, REG_SZ, (LPBYTE)topic,
381 strlen(topic)+1);
382 assert(rc==ERROR_SUCCESS);
383 CloseHandle(hkey_topic);
384 }
385 if (ifexec)
386 {
387 rc=RegCreateKeyEx(hkey_ddeexec, "ifexec", 0, NULL, 0, KEY_SET_VALUE,
388 NULL, &hkey_ifexec, NULL);
389 assert(rc==ERROR_SUCCESS);
390 rc=RegSetValueEx(hkey_ifexec, NULL, 0, REG_SZ, (LPBYTE)ifexec,
391 strlen(ifexec)+1);
392 assert(rc==ERROR_SUCCESS);
393 CloseHandle(hkey_ifexec);
394 }
395 CloseHandle(hkey_ddeexec);
396 }
397
398 CloseHandle(hkey_shell);
399 CloseHandle(hkey_verb);
400 CloseHandle(hkey_cmd);
401 }
402
403 static void create_test_verb(const char* extension, const char* verb,
404 int rawcmd, const char* cmdtail)
405 {
406 create_test_verb_dde(extension, verb, rawcmd, cmdtail, NULL, NULL,
407 NULL, NULL);
408 }
409
410 /***
411 *
412 * Functions to check that the child process was started just right
413 * (borrowed from dlls/kernel32/tests/process.c)
414 *
415 ***/
416
417 static const char* encodeA(const char* str)
418 {
419 static char encoded[2*1024+1];
420 char* ptr;
421 size_t len,i;
422
423 if (!str) return "";
424 len = strlen(str) + 1;
425 if (len >= sizeof(encoded)/2)
426 {
427 fprintf(stderr, "string is too long!\n");
428 assert(0);
429 }
430 ptr = encoded;
431 for (i = 0; i < len; i++)
432 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
433 ptr[2 * len] = '\0';
434 return ptr;
435 }
436
437 static unsigned decode_char(char c)
438 {
439 if (c >= '0' && c <= '9') return c - '0';
440 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
441 assert(c >= 'A' && c <= 'F');
442 return c - 'A' + 10;
443 }
444
445 static char* decodeA(const char* str)
446 {
447 static char decoded[1024];
448 char* ptr;
449 size_t len,i;
450
451 len = strlen(str) / 2;
452 if (!len--) return NULL;
453 if (len >= sizeof(decoded))
454 {
455 fprintf(stderr, "string is too long!\n");
456 assert(0);
457 }
458 ptr = decoded;
459 for (i = 0; i < len; i++)
460 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
461 ptr[len] = '\0';
462 return ptr;
463 }
464
465 static void childPrintf(HANDLE h, const char* fmt, ...)
466 {
467 va_list valist;
468 char buffer[1024];
469 DWORD w;
470
471 va_start(valist, fmt);
472 vsprintf(buffer, fmt, valist);
473 va_end(valist);
474 WriteFile(h, buffer, strlen(buffer), &w, NULL);
475 }
476
477 static DWORD ddeInst;
478 static HSZ hszTopic;
479 static char ddeExec[MAX_PATH], ddeApplication[MAX_PATH];
480 static BOOL post_quit_on_execute;
481
482 static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
483 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
484 ULONG_PTR dwData1, ULONG_PTR dwData2)
485 {
486 DWORD size = 0;
487
488 if (winetest_debug > 2)
489 trace("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
490 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
491
492 switch (uType)
493 {
494 case XTYP_CONNECT:
495 if (!DdeCmpStringHandles(hsz1, hszTopic))
496 {
497 size = DdeQueryString(ddeInst, hsz2, ddeApplication, MAX_PATH, CP_WINANSI);
498 assert(size < MAX_PATH);
499 return (HDDEDATA)TRUE;
500 }
501 return (HDDEDATA)FALSE;
502
503 case XTYP_EXECUTE:
504 size = DdeGetData(hData, (LPBYTE)ddeExec, MAX_PATH, 0L);
505 assert(size < MAX_PATH);
506 DdeFreeDataHandle(hData);
507 if (post_quit_on_execute)
508 PostQuitMessage(0);
509 return (HDDEDATA)DDE_FACK;
510
511 default:
512 return NULL;
513 }
514 }
515
516 /*
517 * This is just to make sure the child won't run forever stuck in a GetMessage()
518 * loop when DDE fails for some reason.
519 */
520 static void CALLBACK childTimeout(HWND wnd, UINT msg, UINT_PTR timer, DWORD time)
521 {
522 trace("childTimeout called\n");
523
524 PostQuitMessage(0);
525 }
526
527 static void doChild(int argc, char** argv)
528 {
529 char* filename;
530 HANDLE hFile, map;
531 int i;
532 int rc;
533 HSZ hszApplication;
534 UINT_PTR timer;
535 HANDLE dde_ready;
536 MSG msg;
537 char *shared_block;
538
539 filename=argv[2];
540 hFile=CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
541 if (hFile == INVALID_HANDLE_VALUE)
542 return;
543
544 /* Arguments */
545 childPrintf(hFile, "[Arguments]\r\n");
546 if (winetest_debug > 2)
547 trace("argcA=%d\n", argc);
548 childPrintf(hFile, "argcA=%d\r\n", argc);
549 for (i = 0; i < argc; i++)
550 {
551 if (winetest_debug > 2)
552 trace("argvA%d=%s\n", i, argv[i]);
553 childPrintf(hFile, "argvA%d=%s\r\n", i, encodeA(argv[i]));
554 }
555
556 map = OpenFileMappingA(FILE_MAP_READ, FALSE, "winetest_shlexec_dde_map");
557 if (map != NULL)
558 {
559 shared_block = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 4096);
560 CloseHandle(map);
561 if (shared_block[0] != '\0' || shared_block[1] != '\0')
562 {
563 post_quit_on_execute = TRUE;
564 ddeInst = 0;
565 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
566 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
567 assert(rc == DMLERR_NO_ERROR);
568 hszApplication = DdeCreateStringHandleA(ddeInst, shared_block, CP_WINANSI);
569 hszTopic = DdeCreateStringHandleA(ddeInst, shared_block + strlen(shared_block) + 1, CP_WINANSI);
570 assert(hszApplication && hszTopic);
571 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
572
573 timer = SetTimer(NULL, 0, 2500, childTimeout);
574
575 dde_ready = CreateEvent(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
576 SetEvent(dde_ready);
577 CloseHandle(dde_ready);
578
579 while (GetMessage(&msg, NULL, 0, 0))
580 DispatchMessage(&msg);
581
582 KillTimer(NULL, timer);
583 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
584 assert(DdeFreeStringHandle(ddeInst, hszTopic));
585 assert(DdeFreeStringHandle(ddeInst, hszApplication));
586 assert(DdeUninitialize(ddeInst));
587 }
588 else
589 {
590 dde_ready = CreateEvent(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
591 SetEvent(dde_ready);
592 CloseHandle(dde_ready);
593 }
594
595 UnmapViewOfFile(shared_block);
596
597 childPrintf(hFile, "ddeExec=%s\r\n", encodeA(ddeExec));
598 }
599
600 CloseHandle(hFile);
601
602 init_event(filename);
603 SetEvent(hEvent);
604 CloseHandle(hEvent);
605 }
606
607 static char* getChildString(const char* sect, const char* key)
608 {
609 char buf[1024];
610 char* ret;
611
612 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), child_file);
613 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
614 assert(!(strlen(buf) & 1));
615 ret = decodeA(buf);
616 return ret;
617 }
618
619 static void dump_child(void)
620 {
621 if (winetest_debug > 1)
622 {
623 char key[18];
624 char* str;
625 int i, c;
626
627 c=GetPrivateProfileIntA("Arguments", "argcA", -1, child_file);
628 trace("argcA=%d\n",c);
629 for (i=0;i<c;i++)
630 {
631 sprintf(key, "argvA%d", i);
632 str=getChildString("Arguments", key);
633 trace("%s=%s\n", key, str);
634 }
635 }
636 }
637
638 static int StrCmpPath(const char* s1, const char* s2)
639 {
640 if (!s1 && !s2) return 0;
641 if (!s2) return 1;
642 if (!s1) return -1;
643 while (*s1)
644 {
645 if (!*s2)
646 {
647 if (*s1=='.')
648 s1++;
649 return (*s1-*s2);
650 }
651 if ((*s1=='/' || *s1=='\\') && (*s2=='/' || *s2=='\\'))
652 {
653 while (*s1=='/' || *s1=='\\')
654 s1++;
655 while (*s2=='/' || *s2=='\\')
656 s2++;
657 }
658 else if (toupper(*s1)==toupper(*s2))
659 {
660 s1++;
661 s2++;
662 }
663 else
664 {
665 return (*s1-*s2);
666 }
667 }
668 if (*s2=='.')
669 s2++;
670 if (*s2)
671 return -1;
672 return 0;
673 }
674
675 static int _okChildString(const char* file, int line, const char* key, const char* expected)
676 {
677 char* result;
678 result=getChildString("Arguments", key);
679 return ok_(file, line)(lstrcmpiA(result, expected) == 0,
680 "%s expected '%s', got '%s'\n", key, expected, result);
681 }
682
683 static int _okChildPath(const char* file, int line, const char* key, const char* expected)
684 {
685 char* result;
686 result=getChildString("Arguments", key);
687 return ok_(file, line)(StrCmpPath(result, expected) == 0,
688 "%s expected '%s', got '%s'\n", key, expected, result);
689 }
690
691 static int _okChildInt(const char* file, int line, const char* key, int expected)
692 {
693 INT result;
694 result=GetPrivateProfileIntA("Arguments", key, expected, child_file);
695 return ok_(file, line)(result == expected,
696 "%s expected %d, but got %d\n", key, expected, result);
697 }
698
699 #define okChildString(key, expected) _okChildString(__FILE__, __LINE__, (key), (expected))
700 #define okChildPath(key, expected) _okChildPath(__FILE__, __LINE__, (key), (expected))
701 #define okChildInt(key, expected) _okChildInt(__FILE__, __LINE__, (key), (expected))
702
703 /***
704 *
705 * GetLongPathNameA equivalent that supports Win95 and WinNT
706 *
707 ***/
708
709 static DWORD get_long_path_name(const char* shortpath, char* longpath, DWORD longlen)
710 {
711 char tmplongpath[MAX_PATH];
712 const char* p;
713 DWORD sp = 0, lp = 0;
714 DWORD tmplen;
715 WIN32_FIND_DATAA wfd;
716 HANDLE goit;
717
718 if (!shortpath || !shortpath[0])
719 return 0;
720
721 if (shortpath[1] == ':')
722 {
723 tmplongpath[0] = shortpath[0];
724 tmplongpath[1] = ':';
725 lp = sp = 2;
726 }
727
728 while (shortpath[sp])
729 {
730 /* check for path delimiters and reproduce them */
731 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
732 {
733 if (!lp || tmplongpath[lp-1] != '\\')
734 {
735 /* strip double "\\" */
736 tmplongpath[lp++] = '\\';
737 }
738 tmplongpath[lp] = 0; /* terminate string */
739 sp++;
740 continue;
741 }
742
743 p = shortpath + sp;
744 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
745 {
746 tmplongpath[lp++] = *p++;
747 tmplongpath[lp++] = *p++;
748 }
749 for (; *p && *p != '/' && *p != '\\'; p++);
750 tmplen = p - (shortpath + sp);
751 lstrcpyn(tmplongpath + lp, shortpath + sp, tmplen + 1);
752 /* Check if the file exists and use the existing file name */
753 goit = FindFirstFileA(tmplongpath, &wfd);
754 if (goit == INVALID_HANDLE_VALUE)
755 return 0;
756 FindClose(goit);
757 strcpy(tmplongpath + lp, wfd.cFileName);
758 lp += strlen(tmplongpath + lp);
759 sp += tmplen;
760 }
761 tmplen = strlen(shortpath) - 1;
762 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
763 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
764 tmplongpath[lp++] = shortpath[tmplen];
765 tmplongpath[lp] = 0;
766
767 tmplen = strlen(tmplongpath) + 1;
768 if (tmplen <= longlen)
769 {
770 strcpy(longpath, tmplongpath);
771 tmplen--; /* length without 0 */
772 }
773
774 return tmplen;
775 }
776
777 /***
778 *
779 * Tests
780 *
781 ***/
782
783 static const char* testfiles[]=
784 {
785 "%s\\test file.shlexec",
786 "%s\\%%nasty%% $file.shlexec",
787 "%s\\test file.noassoc",
788 "%s\\test file.noassoc.shlexec",
789 "%s\\test file.shlexec.noassoc",
790 "%s\\test_shortcut_shlexec.lnk",
791 "%s\\test_shortcut_exe.lnk",
792 "%s\\test file.shl",
793 "%s\\test file.shlfoo",
794 "%s\\test file.sfe",
795 "%s\\masked file.shlexec",
796 "%s\\masked",
797 "%s\\test file.sde",
798 "%s\\test file.exe",
799 "%s\\test2.exe",
800 NULL
801 };
802
803 typedef struct
804 {
805 const char* verb;
806 const char* basename;
807 int todo;
808 int rc;
809 } filename_tests_t;
810
811 static filename_tests_t filename_tests[]=
812 {
813 /* Test bad / nonexistent filenames */
814 {NULL, "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
815 {NULL, "%s\\nonexistent.noassoc", 0x0, SE_ERR_FNF},
816
817 /* Standard tests */
818 {NULL, "%s\\test file.shlexec", 0x0, 33},
819 {NULL, "%s\\test file.shlexec.", 0x0, 33},
820 {NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
821 {NULL, "%s/test file.shlexec", 0x0, 33},
822
823 /* Test filenames with no association */
824 {NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
825
826 /* Test double extensions */
827 {NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
828 {NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
829
830 /* Test alternate verbs */
831 {"LowerL", "%s\\nonexistent.shlexec", 0x0, SE_ERR_FNF},
832 {"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
833
834 {"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
835 {"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
836
837 /* Test file masked due to space */
838 {NULL, "%s\\masked file.shlexec", 0x1, 33},
839 /* Test if quoting prevents the masking */
840 {NULL, "%s\\masked file.shlexec", 0x40, 33},
841
842 {NULL, NULL, 0}
843 };
844
845 static filename_tests_t noquotes_tests[]=
846 {
847 /* Test unquoted '%1' thingies */
848 {"NoQuotes", "%s\\test file.shlexec", 0xa, 33},
849 {"LowerL", "%s\\test file.shlexec", 0xa, 33},
850 {"UpperL", "%s\\test file.shlexec", 0xa, 33},
851
852 {NULL, NULL, 0}
853 };
854
855 static void test_filename(void)
856 {
857 char filename[MAX_PATH];
858 const filename_tests_t* test;
859 char* c;
860 int rc;
861
862 test=filename_tests;
863 while (test->basename)
864 {
865 BOOL quotedfile = FALSE;
866
867 if (skip_noassoc_tests && test->rc == SE_ERR_NOASSOC)
868 {
869 win_skip("Skipping shellexecute of file with unassociated extension\n");
870 test++;
871 continue;
872 }
873
874 sprintf(filename, test->basename, tmpdir);
875 if (strchr(filename, '/'))
876 {
877 c=filename;
878 while (*c)
879 {
880 if (*c=='\\')
881 *c='/';
882 c++;
883 }
884 }
885 if ((test->todo & 0x40)==0)
886 {
887 rc=shell_execute(test->verb, filename, NULL, NULL);
888 }
889 else
890 {
891 char quoted[MAX_PATH + 2];
892
893 quotedfile = TRUE;
894 sprintf(quoted, "\"%s\"", filename);
895 rc=shell_execute(test->verb, quoted, NULL, NULL);
896 }
897 if (rc > 32)
898 rc=33;
899 if ((test->todo & 0x1)==0)
900 {
901 ok(rc==test->rc ||
902 broken(quotedfile && rc == 2), /* NT4 */
903 "%s failed: rc=%d err=%d\n", shell_call,
904 rc, GetLastError());
905 }
906 else todo_wine
907 {
908 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
909 rc, GetLastError());
910 }
911 if (rc == 33)
912 {
913 const char* verb;
914 if ((test->todo & 0x2)==0)
915 {
916 okChildInt("argcA", 5);
917 }
918 else todo_wine
919 {
920 okChildInt("argcA", 5);
921 }
922 verb=(test->verb ? test->verb : "Open");
923 if ((test->todo & 0x4)==0)
924 {
925 okChildString("argvA3", verb);
926 }
927 else todo_wine
928 {
929 okChildString("argvA3", verb);
930 }
931 if ((test->todo & 0x8)==0)
932 {
933 okChildPath("argvA4", filename);
934 }
935 else todo_wine
936 {
937 okChildPath("argvA4", filename);
938 }
939 }
940 test++;
941 }
942
943 test=noquotes_tests;
944 while (test->basename)
945 {
946 sprintf(filename, test->basename, tmpdir);
947 rc=shell_execute(test->verb, filename, NULL, NULL);
948 if (rc > 32)
949 rc=33;
950 if ((test->todo & 0x1)==0)
951 {
952 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
953 rc, GetLastError());
954 }
955 else todo_wine
956 {
957 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
958 rc, GetLastError());
959 }
960 if (rc==0)
961 {
962 int count;
963 const char* verb;
964 char* str;
965
966 verb=(test->verb ? test->verb : "Open");
967 if ((test->todo & 0x4)==0)
968 {
969 okChildString("argvA3", verb);
970 }
971 else todo_wine
972 {
973 okChildString("argvA3", verb);
974 }
975
976 count=4;
977 str=filename;
978 while (1)
979 {
980 char attrib[18];
981 char* space;
982 space=strchr(str, ' ');
983 if (space)
984 *space='\0';
985 sprintf(attrib, "argvA%d", count);
986 if ((test->todo & 0x8)==0)
987 {
988 okChildPath(attrib, str);
989 }
990 else todo_wine
991 {
992 okChildPath(attrib, str);
993 }
994 count++;
995 if (!space)
996 break;
997 str=space+1;
998 }
999 if ((test->todo & 0x2)==0)
1000 {
1001 okChildInt("argcA", count);
1002 }
1003 else todo_wine
1004 {
1005 okChildInt("argcA", count);
1006 }
1007 }
1008 test++;
1009 }
1010
1011 if (dllver.dwMajorVersion != 0)
1012 {
1013 /* The more recent versions of shell32.dll accept quoted filenames
1014 * while older ones (e.g. 4.00) don't. Still we want to test this
1015 * because IE 6 depends on the new behavior.
1016 * One day we may need to check the exact version of the dll but for
1017 * now making sure DllGetVersion() is present is sufficient.
1018 */
1019 sprintf(filename, "\"%s\\test file.shlexec\"", tmpdir);
1020 rc=shell_execute(NULL, filename, NULL, NULL);
1021 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1022 GetLastError());
1023 okChildInt("argcA", 5);
1024 okChildString("argvA3", "Open");
1025 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1026 okChildPath("argvA4", filename);
1027 }
1028 }
1029
1030 static void test_find_executable(void)
1031 {
1032 char filename[MAX_PATH];
1033 char command[MAX_PATH];
1034 const filename_tests_t* test;
1035 INT_PTR rc;
1036
1037 if (!create_test_association(".sfe"))
1038 {
1039 skip("Unable to create association for '.sfe'\n");
1040 return;
1041 }
1042 create_test_verb(".sfe", "Open", 1, "%1");
1043
1044 /* Don't test FindExecutable(..., NULL), it always crashes */
1045
1046 strcpy(command, "your word");
1047 if (0) /* Can crash on Vista! */
1048 {
1049 rc=(INT_PTR)FindExecutableA(NULL, NULL, command);
1050 ok(rc == SE_ERR_FNF || rc > 32 /* nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1051 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1052 }
1053
1054 strcpy(command, "your word");
1055 rc=(INT_PTR)FindExecutableA(tmpdir, NULL, command);
1056 ok(rc == SE_ERR_NOASSOC /* >= win2000 */ || rc > 32 /* win98, nt4 */, "FindExecutable(NULL) returned %ld\n", rc);
1057 ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
1058
1059 sprintf(filename, "%s\\test file.sfe", tmpdir);
1060 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1061 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1062 /* Depending on the platform, command could be '%1' or 'test file.sfe' */
1063
1064 rc=(INT_PTR)FindExecutableA("test file.sfe", tmpdir, command);
1065 ok(rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1066
1067 rc=(INT_PTR)FindExecutableA("test file.sfe", NULL, command);
1068 ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %ld\n", filename, rc);
1069
1070 delete_test_association(".sfe");
1071
1072 if (!create_test_association(".shl"))
1073 {
1074 skip("Unable to create association for '.shl'\n");
1075 return;
1076 }
1077 create_test_verb(".shl", "Open", 0, "Open");
1078
1079 sprintf(filename, "%s\\test file.shl", tmpdir);
1080 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1081 ok(rc == SE_ERR_FNF /* NT4 */ || rc > 32, "FindExecutable(%s) returned %ld\n", filename, rc);
1082
1083 sprintf(filename, "%s\\test file.shlfoo", tmpdir);
1084 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1085
1086 delete_test_association(".shl");
1087
1088 if (rc > 32)
1089 {
1090 /* On Windows XP and 2003 FindExecutable() is completely broken.
1091 * Probably what it does is convert the filename to 8.3 format,
1092 * which as a side effect converts the '.shlfoo' extension to '.shl',
1093 * and then tries to find an association for '.shl'. This means it
1094 * will normally fail on most extensions with more than 3 characters,
1095 * like '.mpeg', etc.
1096 * Also it means we cannot do any other test.
1097 */
1098 trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
1099 return;
1100 }
1101
1102 test=filename_tests;
1103 while (test->basename)
1104 {
1105 sprintf(filename, test->basename, tmpdir);
1106 if (strchr(filename, '/'))
1107 {
1108 char* c;
1109 c=filename;
1110 while (*c)
1111 {
1112 if (*c=='\\')
1113 *c='/';
1114 c++;
1115 }
1116 }
1117 /* Win98 does not '\0'-terminate command! */
1118 memset(command, '\0', sizeof(command));
1119 rc=(INT_PTR)FindExecutableA(filename, NULL, command);
1120 if (rc > 32)
1121 rc=33;
1122 if ((test->todo & 0x10)==0)
1123 {
1124 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1125 }
1126 else todo_wine
1127 {
1128 ok(rc==test->rc, "FindExecutable(%s) failed: rc=%ld\n", filename, rc);
1129 }
1130 if (rc > 32)
1131 {
1132 int equal;
1133 equal=strcmp(command, argv0) == 0 ||
1134 /* NT4 returns an extra 0x8 character! */
1135 (strlen(command) == strlen(argv0)+1 && strncmp(command, argv0, strlen(argv0)) == 0);
1136 if ((test->todo & 0x20)==0)
1137 {
1138 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1139 filename, command, argv0);
1140 }
1141 else todo_wine
1142 {
1143 ok(equal, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
1144 filename, command, argv0);
1145 }
1146 }
1147 test++;
1148 }
1149 }
1150
1151
1152 static filename_tests_t lnk_tests[]=
1153 {
1154 /* Pass bad / nonexistent filenames as a parameter */
1155 {NULL, "%s\\nonexistent.shlexec", 0xa, 33},
1156 {NULL, "%s\\nonexistent.noassoc", 0xa, 33},
1157
1158 /* Pass regular paths as a parameter */
1159 {NULL, "%s\\test file.shlexec", 0xa, 33},
1160 {NULL, "%s/%%nasty%% $file.shlexec", 0xa, 33},
1161
1162 /* Pass filenames with no association as a parameter */
1163 {NULL, "%s\\test file.noassoc", 0xa, 33},
1164
1165 {NULL, NULL, 0}
1166 };
1167
1168 static void test_lnks(void)
1169 {
1170 char filename[MAX_PATH];
1171 char params[MAX_PATH];
1172 const filename_tests_t* test;
1173 int rc;
1174
1175 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1176 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1177 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1178 GetLastError());
1179 okChildInt("argcA", 5);
1180 okChildString("argvA3", "Open");
1181 sprintf(params, "%s\\test file.shlexec", tmpdir);
1182 get_long_path_name(params, filename, sizeof(filename));
1183 okChildPath("argvA4", filename);
1184
1185 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1186 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1187 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1188 GetLastError());
1189 okChildInt("argcA", 4);
1190 okChildString("argvA3", "Lnk");
1191
1192 if (dllver.dwMajorVersion>=6)
1193 {
1194 char* c;
1195 /* Recent versions of shell32.dll accept '/'s in shortcut paths.
1196 * Older versions don't or are quite buggy in this regard.
1197 */
1198 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1199 c=filename;
1200 while (*c)
1201 {
1202 if (*c=='\\')
1203 *c='/';
1204 c++;
1205 }
1206 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, NULL, NULL);
1207 ok(rc > 32, "%s failed: rc=%d err=%d\n", shell_call, rc,
1208 GetLastError());
1209 okChildInt("argcA", 4);
1210 okChildString("argvA3", "Lnk");
1211 }
1212
1213 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1214 test=lnk_tests;
1215 while (test->basename)
1216 {
1217 params[0]='\"';
1218 sprintf(params+1, test->basename, tmpdir);
1219 strcat(params,"\"");
1220 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, filename, params,
1221 NULL);
1222 if (rc > 32)
1223 rc=33;
1224 if ((test->todo & 0x1)==0)
1225 {
1226 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1227 rc, GetLastError());
1228 }
1229 else todo_wine
1230 {
1231 ok(rc==test->rc, "%s failed: rc=%d err=%d\n", shell_call,
1232 rc, GetLastError());
1233 }
1234 if (rc==0)
1235 {
1236 if ((test->todo & 0x2)==0)
1237 {
1238 okChildInt("argcA", 5);
1239 }
1240 else
1241 {
1242 okChildInt("argcA", 5);
1243 }
1244 if ((test->todo & 0x4)==0)
1245 {
1246 okChildString("argvA3", "Lnk");
1247 }
1248 else todo_wine
1249 {
1250 okChildString("argvA3", "Lnk");
1251 }
1252 sprintf(params, test->basename, tmpdir);
1253 if ((test->todo & 0x8)==0)
1254 {
1255 okChildPath("argvA4", params);
1256 }
1257 else
1258 {
1259 okChildPath("argvA4", params);
1260 }
1261 }
1262 test++;
1263 }
1264 }
1265
1266
1267 static void test_exes(void)
1268 {
1269 char filename[MAX_PATH];
1270 char params[1024];
1271 int rc;
1272
1273 sprintf(params, "shlexec \"%s\" Exec", child_file);
1274
1275 /* We need NOZONECHECKS on Win2003 to block a dialog */
1276 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1277 NULL);
1278 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1279 okChildInt("argcA", 4);
1280 okChildString("argvA3", "Exec");
1281
1282 if (! skip_noassoc_tests)
1283 {
1284 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1285 if (CopyFile(argv0, filename, FALSE))
1286 {
1287 rc=shell_execute(NULL, filename, params, NULL);
1288 todo_wine {
1289 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1290 }
1291 }
1292 }
1293 else
1294 {
1295 win_skip("Skipping shellexecute of file with unassociated extension\n");
1296 }
1297 }
1298
1299 static void test_exes_long(void)
1300 {
1301 char filename[MAX_PATH];
1302 char params[2024];
1303 char longparam[MAX_PATH];
1304 int rc;
1305
1306 for (rc = 0; rc < MAX_PATH; rc++)
1307 longparam[rc]='a'+rc%26;
1308 longparam[MAX_PATH-1]=0;
1309
1310
1311 sprintf(params, "shlexec \"%s\" %s", child_file,longparam);
1312
1313 /* We need NOZONECHECKS on Win2003 to block a dialog */
1314 rc=shell_execute_ex(SEE_MASK_NOZONECHECKS, NULL, argv0, params,
1315 NULL);
1316 ok(rc > 32, "%s returned %d\n", shell_call, rc);
1317 okChildInt("argcA", 4);
1318 okChildString("argvA3", longparam);
1319
1320 if (! skip_noassoc_tests)
1321 {
1322 sprintf(filename, "%s\\test file.noassoc", tmpdir);
1323 if (CopyFile(argv0, filename, FALSE))
1324 {
1325 rc=shell_execute(NULL, filename, params, NULL);
1326 todo_wine {
1327 ok(rc==SE_ERR_NOASSOC, "%s succeeded: rc=%d\n", shell_call, rc);
1328 }
1329 }
1330 }
1331 else
1332 {
1333 win_skip("Skipping shellexecute of file with unassociated extension\n");
1334 }
1335 }
1336
1337 typedef struct
1338 {
1339 const char* command;
1340 const char* ddeexec;
1341 const char* application;
1342 const char* topic;
1343 const char* ifexec;
1344 int expectedArgs;
1345 const char* expectedDdeExec;
1346 int todo;
1347 } dde_tests_t;
1348
1349 static dde_tests_t dde_tests[] =
1350 {
1351 /* Test passing and not passing command-line
1352 * argument, no DDE */
1353 {"", NULL, NULL, NULL, NULL, FALSE, "", 0x0},
1354 {"\"%1\"", NULL, NULL, NULL, NULL, TRUE, "", 0x0},
1355
1356 /* Test passing and not passing command-line
1357 * argument, with DDE */
1358 {"", "[open(\"%1\")]", "shlexec", "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1359 {"\"%1\"", "[open(\"%1\")]", "shlexec", "dde", NULL, TRUE, "[open(\"%s\")]", 0x0},
1360
1361 /* Test unquoted %1 in command and ddeexec
1362 * (test filename has space) */
1363 {"%1", "[open(%1)]", "shlexec", "dde", NULL, 2, "[open(%s)]", 0x0},
1364
1365 /* Test ifexec precedence over ddeexec */
1366 {"", "[open(\"%1\")]", "shlexec", "dde", "[ifexec(\"%1\")]", FALSE, "[ifexec(\"%s\")]", 0x0},
1367
1368 /* Test default DDE topic */
1369 {"", "[open(\"%1\")]", "shlexec", NULL, NULL, FALSE, "[open(\"%s\")]", 0x0},
1370
1371 /* Test default DDE application */
1372 {"", "[open(\"%1\")]", NULL, "dde", NULL, FALSE, "[open(\"%s\")]", 0x0},
1373
1374 {NULL, NULL, NULL, NULL, NULL, 0, 0x0}
1375 };
1376
1377 static DWORD WINAPI hooked_WaitForInputIdle(HANDLE process, DWORD timeout)
1378 {
1379 HANDLE dde_ready;
1380 DWORD wait_result;
1381
1382 dde_ready = CreateEventA(NULL, FALSE, FALSE, "winetest_shlexec_dde_ready");
1383 wait_result = WaitForSingleObject(dde_ready, timeout);
1384 CloseHandle(dde_ready);
1385
1386 return wait_result;
1387 }
1388
1389 /*
1390 * WaitForInputIdle() will normally return immediately for console apps. That's
1391 * a problem for us because ShellExecute will assume that an app is ready to
1392 * receive DDE messages after it has called WaitForInputIdle() on that app.
1393 * To work around that we install our own version of WaitForInputIdle() that
1394 * will wait for the child to explicitly tell us that it is ready. We do that
1395 * by changing the entry for WaitForInputIdle() in the shell32 import address
1396 * table.
1397 */
1398 static void hook_WaitForInputIdle(void *new_func)
1399 {
1400 char *base;
1401 PIMAGE_NT_HEADERS nt_headers;
1402 DWORD import_directory_rva;
1403 PIMAGE_IMPORT_DESCRIPTOR import_descriptor;
1404
1405 base = (char *) GetModuleHandleA("shell32.dll");
1406 nt_headers = (PIMAGE_NT_HEADERS)(base + ((PIMAGE_DOS_HEADER) base)->e_lfanew);
1407 import_directory_rva = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
1408
1409 /* Search for the correct imported module by walking the import descriptors */
1410 import_descriptor = (PIMAGE_IMPORT_DESCRIPTOR)(base + import_directory_rva);
1411 while (U(*import_descriptor).OriginalFirstThunk != 0)
1412 {
1413 char *import_module_name;
1414
1415 import_module_name = base + import_descriptor->Name;
1416 if (lstrcmpiA(import_module_name, "user32.dll") == 0 ||
1417 lstrcmpiA(import_module_name, "user32") == 0)
1418 {
1419 PIMAGE_THUNK_DATA int_entry;
1420 PIMAGE_THUNK_DATA iat_entry;
1421
1422 /* The import name table and import address table are two parallel
1423 * arrays. We need the import name table to find the imported
1424 * routine and the import address table to patch the address, so
1425 * walk them side by side */
1426 int_entry = (PIMAGE_THUNK_DATA)(base + U(*import_descriptor).OriginalFirstThunk);
1427 iat_entry = (PIMAGE_THUNK_DATA)(base + import_descriptor->FirstThunk);
1428 while (int_entry->u1.Ordinal != 0)
1429 {
1430 if (! IMAGE_SNAP_BY_ORDINAL(int_entry->u1.Ordinal))
1431 {
1432 PIMAGE_IMPORT_BY_NAME import_by_name;
1433 import_by_name = (PIMAGE_IMPORT_BY_NAME)(base + int_entry->u1.AddressOfData);
1434 if (lstrcmpA((char *) import_by_name->Name, "WaitForInputIdle") == 0)
1435 {
1436 /* Found the correct routine in the correct imported module. Patch it. */
1437 DWORD old_prot;
1438 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), PAGE_READWRITE, &old_prot);
1439 iat_entry->u1.Function = (ULONG_PTR) new_func;
1440 VirtualProtect(&iat_entry->u1.Function, sizeof(ULONG_PTR), old_prot, &old_prot);
1441 break;
1442 }
1443 }
1444 int_entry++;
1445 iat_entry++;
1446 }
1447 break;
1448 }
1449
1450 import_descriptor++;
1451 }
1452 }
1453
1454 static void test_dde(void)
1455 {
1456 char filename[MAX_PATH], defApplication[MAX_PATH];
1457 const dde_tests_t* test;
1458 char params[1024];
1459 int rc;
1460 HANDLE map;
1461 char *shared_block;
1462
1463 hook_WaitForInputIdle((void *) hooked_WaitForInputIdle);
1464
1465 sprintf(filename, "%s\\test file.sde", tmpdir);
1466
1467 /* Default service is application name minus path and extension */
1468 strcpy(defApplication, strrchr(argv0, '\\')+1);
1469 *strchr(defApplication, '.') = 0;
1470
1471 map = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
1472 4096, "winetest_shlexec_dde_map");
1473 shared_block = MapViewOfFile(map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 4096);
1474
1475 test = dde_tests;
1476 while (test->command)
1477 {
1478 if (!create_test_association(".sde"))
1479 {
1480 skip("Unable to create association for '.sfe'\n");
1481 return;
1482 }
1483 create_test_verb_dde(".sde", "Open", 0, test->command, test->ddeexec,
1484 test->application, test->topic, test->ifexec);
1485
1486 if (test->application != NULL || test->topic != NULL)
1487 {
1488 strcpy(shared_block, test->application ? test->application : defApplication);
1489 strcpy(shared_block + strlen(shared_block) + 1, test->topic ? test->topic : SZDDESYS_TOPIC);
1490 }
1491 else
1492 {
1493 shared_block[0] = '\0';
1494 shared_block[1] = '\0';
1495 }
1496 ddeExec[0] = 0;
1497
1498 rc = shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, filename, NULL, NULL);
1499 if ((test->todo & 0x1)==0)
1500 {
1501 ok(32 < rc, "%s failed: rc=%d err=%d\n", shell_call,
1502 rc, GetLastError());
1503 }
1504 else todo_wine
1505 {
1506 ok(32 < rc, "%s failed: rc=%d err=%d\n", shell_call,
1507 rc, GetLastError());
1508 }
1509 if (32 < rc)
1510 {
1511 if ((test->todo & 0x2)==0)
1512 {
1513 okChildInt("argcA", test->expectedArgs + 3);
1514 }
1515 else todo_wine
1516 {
1517 okChildInt("argcA", test->expectedArgs + 3);
1518 }
1519 if (test->expectedArgs == 1)
1520 {
1521 if ((test->todo & 0x4) == 0)
1522 {
1523 okChildPath("argvA3", filename);
1524 }
1525 else todo_wine
1526 {
1527 okChildPath("argvA3", filename);
1528 }
1529 }
1530 if ((test->todo & 0x8) == 0)
1531 {
1532 sprintf(params, test->expectedDdeExec, filename);
1533 okChildPath("ddeExec", params);
1534 }
1535 else todo_wine
1536 {
1537 sprintf(params, test->expectedDdeExec, filename);
1538 okChildPath("ddeExec", params);
1539 }
1540 }
1541
1542 delete_test_association(".sde");
1543 test++;
1544 }
1545
1546 UnmapViewOfFile(shared_block);
1547 CloseHandle(map);
1548 hook_WaitForInputIdle((void *) WaitForInputIdle);
1549 }
1550
1551 #define DDE_DEFAULT_APP_VARIANTS 2
1552 typedef struct
1553 {
1554 const char* command;
1555 const char* expectedDdeApplication[DDE_DEFAULT_APP_VARIANTS];
1556 int todo;
1557 int rc[DDE_DEFAULT_APP_VARIANTS];
1558 } dde_default_app_tests_t;
1559
1560 static dde_default_app_tests_t dde_default_app_tests[] =
1561 {
1562 /* Windows XP and 98 handle default DDE app names in different ways.
1563 * The application name we see in the first test determines the pattern
1564 * of application names and return codes we will look for. */
1565
1566 /* Test unquoted existing filename with a space */
1567 {"%s\\test file.exe", {"test file", "test"}, 0x0, {33, 33}},
1568 {"%s\\test file.exe param", {"test file", "test"}, 0x0, {33, 33}},
1569
1570 /* Test quoted existing filename with a space */
1571 {"\"%s\\test file.exe\"", {"test file", "test file"}, 0x0, {33, 33}},
1572 {"\"%s\\test file.exe\" param", {"test file", "test file"}, 0x0, {33, 33}},
1573
1574 /* Test unquoted filename with a space that doesn't exist, but
1575 * test2.exe does */
1576 {"%s\\test2 file.exe", {"test2", "test2"}, 0x0, {33, 33}},
1577 {"%s\\test2 file.exe param", {"test2", "test2"}, 0x0, {33, 33}},
1578
1579 /* Test quoted filename with a space that does not exist */
1580 {"\"%s\\test2 file.exe\"", {"", "test2 file"}, 0x0, {5, 33}},
1581 {"\"%s\\test2 file.exe\" param", {"", "test2 file"}, 0x0, {5, 33}},
1582
1583 /* Test filename supplied without the extension */
1584 {"%s\\test2", {"test2", "test2"}, 0x0, {33, 33}},
1585 {"%s\\test2 param", {"test2", "test2"}, 0x0, {33, 33}},
1586
1587 /* Test an unquoted nonexistent filename */
1588 {"%s\\notexist.exe", {"", "notexist"}, 0x0, {5, 33}},
1589 {"%s\\notexist.exe param", {"", "notexist"}, 0x0, {5, 33}},
1590
1591 /* Test an application that will be found on the path */
1592 {"cmd", {"cmd", "cmd"}, 0x0, {33, 33}},
1593 {"cmd param", {"cmd", "cmd"}, 0x0, {33, 33}},
1594
1595 /* Test an application that will not be found on the path */
1596 {"xyzwxyzwxyz", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1597 {"xyzwxyzwxyz param", {"", "xyzwxyzwxyz"}, 0x0, {5, 33}},
1598
1599 {NULL, {NULL}, 0, {0}}
1600 };
1601
1602 typedef struct
1603 {
1604 char *filename;
1605 DWORD threadIdParent;
1606 } dde_thread_info_t;
1607
1608 static DWORD CALLBACK ddeThread(LPVOID arg)
1609 {
1610 dde_thread_info_t *info = arg;
1611 assert(info && info->filename);
1612 PostThreadMessage(info->threadIdParent,
1613 WM_QUIT,
1614 shell_execute_ex(SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI, NULL, info->filename, NULL, NULL),
1615 0L);
1616 ExitThread(0);
1617 }
1618
1619 static void test_dde_default_app(void)
1620 {
1621 char filename[MAX_PATH];
1622 HSZ hszApplication;
1623 dde_thread_info_t info = { filename, GetCurrentThreadId() };
1624 const dde_default_app_tests_t* test;
1625 char params[1024];
1626 DWORD threadId;
1627 MSG msg;
1628 int rc, which = 0;
1629
1630 post_quit_on_execute = FALSE;
1631 ddeInst = 0;
1632 rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES |
1633 CBF_FAIL_POKES | CBF_FAIL_REQUESTS, 0L);
1634 assert(rc == DMLERR_NO_ERROR);
1635
1636 sprintf(filename, "%s\\test file.sde", tmpdir);
1637
1638 /* It is strictly not necessary to register an application name here, but wine's
1639 * DdeNameService implementation complains if 0L is passed instead of
1640 * hszApplication with DNS_FILTEROFF */
1641 hszApplication = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1642 hszTopic = DdeCreateStringHandleA(ddeInst, "shlexec", CP_WINANSI);
1643 assert(hszApplication && hszTopic);
1644 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_REGISTER | DNS_FILTEROFF));
1645
1646 test = dde_default_app_tests;
1647 while (test->command)
1648 {
1649 if (!create_test_association(".sde"))
1650 {
1651 skip("Unable to create association for '.sde'\n");
1652 return;
1653 }
1654 sprintf(params, test->command, tmpdir);
1655 create_test_verb_dde(".sde", "Open", 1, params, "[test]", NULL,
1656 "shlexec", NULL);
1657 ddeApplication[0] = 0;
1658
1659 /* No application will be run as we will respond to the first DDE event,
1660 * so don't wait for it */
1661 SetEvent(hEvent);
1662
1663 assert(CreateThread(NULL, 0, ddeThread, &info, 0, &threadId));
1664 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);
1665 rc = msg.wParam > 32 ? 33 : msg.wParam;
1666
1667 /* First test, find which set of test data we expect to see */
1668 if (test == dde_default_app_tests)
1669 {
1670 int i;
1671 for (i=0; i<DDE_DEFAULT_APP_VARIANTS; i++)
1672 {
1673 if (!strcmp(ddeApplication, test->expectedDdeApplication[i]))
1674 {
1675 which = i;
1676 break;
1677 }
1678 }
1679 if (i == DDE_DEFAULT_APP_VARIANTS)
1680 skip("Default DDE application test does not match any available results, using first expected data set.\n");
1681 }
1682
1683 if ((test->todo & 0x1)==0)
1684 {
1685 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1686 rc, GetLastError());
1687 }
1688 else todo_wine
1689 {
1690 ok(rc==test->rc[which], "%s failed: rc=%d err=%d\n", shell_call,
1691 rc, GetLastError());
1692 }
1693 if (rc == 33)
1694 {
1695 if ((test->todo & 0x2)==0)
1696 {
1697 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1698 "Expected application '%s', got '%s'\n",
1699 test->expectedDdeApplication[which], ddeApplication);
1700 }
1701 else todo_wine
1702 {
1703 ok(!strcmp(ddeApplication, test->expectedDdeApplication[which]),
1704 "Expected application '%s', got '%s'\n",
1705 test->expectedDdeApplication[which], ddeApplication);
1706 }
1707 }
1708
1709 delete_test_association(".sde");
1710 test++;
1711 }
1712
1713 assert(DdeNameService(ddeInst, hszApplication, 0L, DNS_UNREGISTER));
1714 assert(DdeFreeStringHandle(ddeInst, hszTopic));
1715 assert(DdeFreeStringHandle(ddeInst, hszApplication));
1716 assert(DdeUninitialize(ddeInst));
1717 }
1718
1719 static void init_test(void)
1720 {
1721 HMODULE hdll;
1722 HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO*);
1723 char filename[MAX_PATH];
1724 WCHAR lnkfile[MAX_PATH];
1725 char params[1024];
1726 const char* const * testfile;
1727 lnk_desc_t desc;
1728 DWORD rc;
1729 HRESULT r;
1730
1731 hdll=GetModuleHandleA("shell32.dll");
1732 pDllGetVersion=(void*)GetProcAddress(hdll, "DllGetVersion");
1733 if (pDllGetVersion)
1734 {
1735 dllver.cbSize=sizeof(dllver);
1736 pDllGetVersion(&dllver);
1737 trace("major=%d minor=%d build=%d platform=%d\n",
1738 dllver.dwMajorVersion, dllver.dwMinorVersion,
1739 dllver.dwBuildNumber, dllver.dwPlatformID);
1740 }
1741 else
1742 {
1743 memset(&dllver, 0, sizeof(dllver));
1744 }
1745
1746 r = CoInitialize(NULL);
1747 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
1748 if (FAILED(r))
1749 exit(1);
1750
1751 rc=GetModuleFileName(NULL, argv0, sizeof(argv0));
1752 assert(rc!=0 && rc<sizeof(argv0));
1753 if (GetFileAttributes(argv0)==INVALID_FILE_ATTRIBUTES)
1754 {
1755 strcat(argv0, ".so");
1756 ok(GetFileAttributes(argv0)!=INVALID_FILE_ATTRIBUTES,
1757 "unable to find argv0!\n");
1758 }
1759
1760 GetTempPathA(sizeof(filename), filename);
1761 GetTempFileNameA(filename, "wt", 0, tmpdir);
1762 DeleteFileA( tmpdir );
1763 rc = CreateDirectoryA( tmpdir, NULL );
1764 ok( rc, "failed to create %s err %u\n", tmpdir, GetLastError() );
1765 rc = GetTempFileNameA(tmpdir, "wt", 0, child_file);
1766 assert(rc != 0);
1767 init_event(child_file);
1768
1769 /* Set up the test files */
1770 testfile=testfiles;
1771 while (*testfile)
1772 {
1773 HANDLE hfile;
1774
1775 sprintf(filename, *testfile, tmpdir);
1776 hfile=CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1777 FILE_ATTRIBUTE_NORMAL, NULL);
1778 if (hfile==INVALID_HANDLE_VALUE)
1779 {
1780 trace("unable to create '%s': err=%d\n", filename, GetLastError());
1781 assert(0);
1782 }
1783 CloseHandle(hfile);
1784 testfile++;
1785 }
1786
1787 /* Setup the test shortcuts */
1788 sprintf(filename, "%s\\test_shortcut_shlexec.lnk", tmpdir);
1789 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1790 desc.description=NULL;
1791 desc.workdir=NULL;
1792 sprintf(filename, "%s\\test file.shlexec", tmpdir);
1793 desc.path=filename;
1794 desc.pidl=NULL;
1795 desc.arguments="ignored";
1796 desc.showcmd=0;
1797 desc.icon=NULL;
1798 desc.icon_id=0;
1799 desc.hotkey=0;
1800 create_lnk(lnkfile, &desc, 0);
1801
1802 sprintf(filename, "%s\\test_shortcut_exe.lnk", tmpdir);
1803 MultiByteToWideChar(CP_ACP, 0, filename, -1, lnkfile, sizeof(lnkfile)/sizeof(*lnkfile));
1804 desc.description=NULL;
1805 desc.workdir=NULL;
1806 desc.path=argv0;
1807 desc.pidl=NULL;
1808 sprintf(params, "shlexec \"%s\" Lnk", child_file);
1809 desc.arguments=params;
1810 desc.showcmd=0;
1811 desc.icon=NULL;
1812 desc.icon_id=0;
1813 desc.hotkey=0;
1814 create_lnk(lnkfile, &desc, 0);
1815
1816 /* Create a basic association suitable for most tests */
1817 if (!create_test_association(".shlexec"))
1818 {
1819 skip("Unable to create association for '.shlexec'\n");
1820 return;
1821 }
1822 create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
1823 create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
1824 create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
1825 create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
1826 create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
1827 create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
1828 }
1829
1830 static void cleanup_test(void)
1831 {
1832 char filename[MAX_PATH];
1833 const char* const * testfile;
1834
1835 /* Delete the test files */
1836 testfile=testfiles;
1837 while (*testfile)
1838 {
1839 sprintf(filename, *testfile, tmpdir);
1840 /* Make sure we can delete the files ('test file.noassoc' is read-only now) */
1841 SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
1842 DeleteFile(filename);
1843 testfile++;
1844 }
1845 DeleteFile(child_file);
1846 RemoveDirectoryA(tmpdir);
1847
1848 /* Delete the test association */
1849 delete_test_association(".shlexec");
1850
1851 CloseHandle(hEvent);
1852
1853 CoUninitialize();
1854 }
1855
1856 static void test_commandline(void)
1857 {
1858 static const WCHAR one[] = {'o','n','e',0};
1859 static const WCHAR two[] = {'t','w','o',0};
1860 static const WCHAR three[] = {'t','h','r','e','e',0};
1861 static const WCHAR four[] = {'f','o','u','r',0};
1862
1863 static const WCHAR fmt1[] = {'%','s',' ','%','s',' ','%','s',' ','%','s',0};
1864 static const WCHAR fmt2[] = {' ','%','s',' ','%','s',' ','%','s',' ','%','s',0};
1865 static const WCHAR fmt3[] = {'%','s','=','%','s',' ','%','s','=','\"','%','s','\"',0};
1866 static const WCHAR fmt4[] = {'\"','%','s','\"',' ','\"','%','s',' ','%','s','\"',' ','%','s',0};
1867 static const WCHAR fmt5[] = {'\\','\"','%','s','\"',' ','%','s','=','\"','%','s','\\','\"',' ','\"','%','s','\\','\"',0};
1868 static const WCHAR fmt6[] = {0};
1869
1870 static const WCHAR chkfmt1[] = {'%','s','=','%','s',0};
1871 static const WCHAR chkfmt2[] = {'%','s',' ','%','s',0};
1872 static const WCHAR chkfmt3[] = {'\\','\"','%','s','\"',0};
1873 static const WCHAR chkfmt4[] = {'%','s','=','%','s','\"',' ','%','s','\"',0};
1874 WCHAR cmdline[255];
1875 LPWSTR *args = (LPWSTR*)0xdeadcafe;
1876 INT numargs = -1;
1877
1878 wsprintfW(cmdline,fmt1,one,two,three,four);
1879 args=CommandLineToArgvW(cmdline,&numargs);
1880 if (args == NULL && numargs == -1)
1881 {
1882 win_skip("CommandLineToArgvW not implemented, skipping\n");
1883 return;
1884 }
1885 ok(numargs == 4, "expected 4 args, got %i\n",numargs);
1886 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1887 ok(lstrcmpW(args[1],two)==0,"arg1 is not as expected\n");
1888 ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n");
1889 ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
1890
1891 wsprintfW(cmdline,fmt2,one,two,three,four);
1892 args=CommandLineToArgvW(cmdline,&numargs);
1893 ok(numargs == 5, "expected 5 args, got %i\n",numargs);
1894 ok(args[0][0]==0,"arg0 is not as expected\n");
1895 ok(lstrcmpW(args[1],one)==0,"arg1 is not as expected\n");
1896 ok(lstrcmpW(args[2],two)==0,"arg2 is not as expected\n");
1897 ok(lstrcmpW(args[3],three)==0,"arg3 is not as expected\n");
1898 ok(lstrcmpW(args[4],four)==0,"arg4 is not as expected\n");
1899
1900 wsprintfW(cmdline,fmt3,one,two,three,four);
1901 args=CommandLineToArgvW(cmdline,&numargs);
1902 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1903 wsprintfW(cmdline,chkfmt1,one,two);
1904 ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1905 wsprintfW(cmdline,chkfmt1,three,four);
1906 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1907
1908 wsprintfW(cmdline,fmt4,one,two,three,four);
1909 args=CommandLineToArgvW(cmdline,&numargs);
1910 ok(numargs == 3, "expected 3 args, got %i\n",numargs);
1911 ok(lstrcmpW(args[0],one)==0,"arg0 is not as expected\n");
1912 wsprintfW(cmdline,chkfmt2,two,three);
1913 ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1914 ok(lstrcmpW(args[2],four)==0,"arg2 is not as expected\n");
1915
1916 wsprintfW(cmdline,fmt5,one,two,three,four);
1917 args=CommandLineToArgvW(cmdline,&numargs);
1918 ok(numargs == 2, "expected 2 args, got %i\n",numargs);
1919 wsprintfW(cmdline,chkfmt3,one);
1920 todo_wine ok(lstrcmpW(args[0],cmdline)==0,"arg0 is not as expected\n");
1921 wsprintfW(cmdline,chkfmt4,two,three,four);
1922 todo_wine ok(lstrcmpW(args[1],cmdline)==0,"arg1 is not as expected\n");
1923
1924 wsprintfW(cmdline,fmt6);
1925 args=CommandLineToArgvW(cmdline,&numargs);
1926 ok(numargs == 1, "expected 1 args, got %i\n",numargs);
1927 }
1928
1929 START_TEST(shlexec)
1930 {
1931
1932 myARGC = winetest_get_mainargs(&myARGV);
1933 if (myARGC >= 3)
1934 {
1935 doChild(myARGC, myARGV);
1936 exit(0);
1937 }
1938
1939 init_test();
1940
1941 test_filename();
1942 test_find_executable();
1943 test_lnks();
1944 test_exes();
1945 test_exes_long();
1946 test_dde();
1947 test_dde_default_app();
1948 test_commandline();
1949
1950 cleanup_test();
1951 }