2 * Unit test suite for CreateProcess function.
4 * Copyright 2002 Eric Pouech
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
26 #include "wine/test.h"
33 static char base
[MAX_PATH
];
34 static char selfname
[MAX_PATH
];
35 static char resfile
[MAX_PATH
];
40 /* As some environment variables get very long on Unix, we only test for
41 * the first 127 bytes.
42 * Note that increasing this value past 256 may exceed the buffer size
43 * limitations of the *Profile functions (at least on Wine).
45 #define MAX_LISTED_ENV_VAR 128
47 /* ---------------- portable memory allocation thingie */
49 static char memory
[1024*32];
50 static char* memory_index
= memory
;
52 static char* grab_memory(size_t len
)
54 char* ret
= memory_index
;
58 assert(memory_index
<= memory
+ sizeof(memory
));
62 static void release_memory(void)
64 memory_index
= memory
;
67 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
69 static const char* encodeA(const char* str
)
75 len
= strlen(str
) + 1;
76 ptr
= grab_memory(len
* 2 + 1);
77 for (i
= 0; i
< len
; i
++)
78 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
83 static const char* encodeW(const WCHAR
* str
)
89 len
= lstrlenW(str
) + 1;
90 ptr
= grab_memory(len
* 4 + 1);
92 for (i
= 0; i
< len
; i
++)
93 sprintf(&ptr
[i
* 4], "%04x", (unsigned int)(unsigned short)str
[i
]);
98 static unsigned decode_char(char c
)
100 if (c
>= '0' && c
<= '9') return c
- '0';
101 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
102 assert(c
>= 'A' && c
<= 'F');
106 static char* decodeA(const char* str
)
111 len
= strlen(str
) / 2;
112 if (!len
--) return NULL
;
113 ptr
= grab_memory(len
+ 1);
114 for (i
= 0; i
< len
; i
++)
115 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
121 /* This will be needed to decode Unicode strings saved by the child process
122 * when we test Unicode functions.
124 static WCHAR
* decodeW(const char* str
)
130 len
= strlen(str
) / 4;
131 if (!len
--) return NULL
;
132 ptr
= (WCHAR
*)grab_memory(len
* 2 + 1);
133 for (i
= 0; i
< len
; i
++)
134 ptr
[i
] = (decode_char(str
[4 * i
]) << 12) |
135 (decode_char(str
[4 * i
+ 1]) << 8) |
136 (decode_char(str
[4 * i
+ 2]) << 4) |
137 (decode_char(str
[4 * i
+ 3]) << 0);
143 /******************************************************************
146 * generates basic information like:
147 * base: absolute path to curr dir
148 * selfname: the way to reinvoke ourselves
150 static int init(void)
152 myARGC
= winetest_get_mainargs( &myARGV
);
153 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
154 strcpy(selfname
, myARGV
[0]);
158 /******************************************************************
161 * generates an absolute file_name for temporary file
164 static void get_file_name(char* buf
)
169 GetTempPathA(sizeof(path
), path
);
170 GetTempFileNameA(path
, "wt", 0, buf
);
173 /******************************************************************
174 * static void childPrintf
177 static void childPrintf(HANDLE h
, const char* fmt
, ...)
180 char buffer
[1024+4*MAX_LISTED_ENV_VAR
];
183 va_start(valist
, fmt
);
184 vsprintf(buffer
, fmt
, valist
);
186 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
190 /******************************************************************
193 * output most of the information in the child process
195 static void doChild(const char* file
, const char* option
)
203 WCHAR bufW
[MAX_PATH
];
204 HANDLE hFile
= CreateFileA(file
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
207 if (hFile
== INVALID_HANDLE_VALUE
) return;
209 /* output of startup info (Ansi) */
210 GetStartupInfoA(&siA
);
212 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
213 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
214 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
215 "dwFlags=%lu\nwShowWindow=%u\n"
216 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
217 siA
.cb
, encodeA(siA
.lpDesktop
), encodeA(siA
.lpTitle
),
218 siA
.dwX
, siA
.dwY
, siA
.dwXSize
, siA
.dwYSize
,
219 siA
.dwXCountChars
, siA
.dwYCountChars
, siA
.dwFillAttribute
,
220 siA
.dwFlags
, siA
.wShowWindow
,
221 (DWORD
)siA
.hStdInput
, (DWORD
)siA
.hStdOutput
, (DWORD
)siA
.hStdError
);
223 /* since GetStartupInfoW is only implemented in win2k,
224 * zero out before calling so we can notice the difference
226 memset(&siW
, 0, sizeof(siW
));
227 GetStartupInfoW(&siW
);
229 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
230 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
231 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
232 "dwFlags=%lu\nwShowWindow=%u\n"
233 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
234 siW
.cb
, encodeW(siW
.lpDesktop
), encodeW(siW
.lpTitle
),
235 siW
.dwX
, siW
.dwY
, siW
.dwXSize
, siW
.dwYSize
,
236 siW
.dwXCountChars
, siW
.dwYCountChars
, siW
.dwFillAttribute
,
237 siW
.dwFlags
, siW
.wShowWindow
,
238 (DWORD
)siW
.hStdInput
, (DWORD
)siW
.hStdOutput
, (DWORD
)siW
.hStdError
);
241 childPrintf(hFile
, "[Arguments]\nargcA=%d\n", myARGC
);
242 for (i
= 0; i
< myARGC
; i
++)
244 childPrintf(hFile
, "argvA%d=%s\n", i
, encodeA(myARGV
[i
]));
246 childPrintf(hFile
, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
252 /* this is part of shell32... and should be tested there */
253 argvW
= CommandLineToArgvW(GetCommandLineW(), &argcW
);
254 for (i
= 0; i
< argcW
; i
++)
256 childPrintf(hFile
, "argvW%d=%s\n", i
, encodeW(argvW
[i
]));
259 childPrintf(hFile
, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
261 /* output of environment (Ansi) */
262 ptrA
= GetEnvironmentStringsA();
265 char env_var
[MAX_LISTED_ENV_VAR
];
267 childPrintf(hFile
, "[EnvironmentA]\n");
271 lstrcpynA(env_var
, ptrA
, MAX_LISTED_ENV_VAR
);
272 childPrintf(hFile
, "env%d=%s\n", i
, encodeA(env_var
));
274 ptrA
+= strlen(ptrA
) + 1;
276 childPrintf(hFile
, "len=%d\n\n", i
);
279 /* output of environment (Unicode) */
280 ptrW
= GetEnvironmentStringsW();
283 WCHAR env_var
[MAX_LISTED_ENV_VAR
];
285 childPrintf(hFile
, "[EnvironmentW]\n");
289 lstrcpynW(env_var
, ptrW
, MAX_LISTED_ENV_VAR
- 1);
290 env_var
[MAX_LISTED_ENV_VAR
- 1] = '\0';
291 childPrintf(hFile
, "env%d=%s\n", i
, encodeW(env_var
));
293 ptrW
+= lstrlenW(ptrW
) + 1;
295 childPrintf(hFile
, "len=%d\n\n", i
);
298 childPrintf(hFile
, "[Misc]\n");
299 if (GetCurrentDirectoryA(sizeof(bufA
), bufA
))
300 childPrintf(hFile
, "CurrDirA=%s\n", encodeA(bufA
));
301 if (GetCurrentDirectoryW(sizeof(bufW
) / sizeof(bufW
[0]), bufW
))
302 childPrintf(hFile
, "CurrDirW=%s\n", encodeW(bufW
));
303 childPrintf(hFile
, "\n");
305 if (option
&& strcmp(option
, "console") == 0)
307 CONSOLE_SCREEN_BUFFER_INFO sbi
;
308 HANDLE hConIn
= GetStdHandle(STD_INPUT_HANDLE
);
309 HANDLE hConOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
310 DWORD modeIn
, modeOut
;
312 childPrintf(hFile
, "[Console]\n");
313 if (GetConsoleScreenBufferInfo(hConOut
, &sbi
))
315 childPrintf(hFile
, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
316 sbi
.dwSize
.X
, sbi
.dwSize
.Y
, sbi
.dwCursorPosition
.X
, sbi
.dwCursorPosition
.Y
, sbi
.wAttributes
);
317 childPrintf(hFile
, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
318 sbi
.srWindow
.Left
, sbi
.srWindow
.Top
, sbi
.srWindow
.Right
, sbi
.srWindow
.Bottom
);
319 childPrintf(hFile
, "maxWinWidth=%d\nmaxWinHeight=%d\n",
320 sbi
.dwMaximumWindowSize
.X
, sbi
.dwMaximumWindowSize
.Y
);
322 childPrintf(hFile
, "InputCP=%d\nOutputCP=%d\n",
323 GetConsoleCP(), GetConsoleOutputCP());
324 if (GetConsoleMode(hConIn
, &modeIn
))
325 childPrintf(hFile
, "InputMode=%ld\n", modeIn
);
326 if (GetConsoleMode(hConOut
, &modeOut
))
327 childPrintf(hFile
, "OutputMode=%ld\n", modeOut
);
329 /* now that we have written all relevant information, let's change it */
330 ok(SetConsoleCP(1252), "Setting CP\n");
331 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
332 ret
= SetConsoleMode(hConIn
, modeIn
^ 1);
333 ok( ret
, "Setting mode (%ld)\n", GetLastError());
334 ret
= SetConsoleMode(hConOut
, modeOut
^ 1);
335 ok( ret
, "Setting mode (%ld)\n", GetLastError());
336 sbi
.dwCursorPosition
.X
^= 1;
337 sbi
.dwCursorPosition
.Y
^= 1;
338 ret
= SetConsoleCursorPosition(hConOut
, sbi
.dwCursorPosition
);
339 ok( ret
, "Setting cursor position (%ld)\n", GetLastError());
341 if (option
&& strcmp(option
, "stdhandle") == 0)
343 HANDLE hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
344 HANDLE hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
346 if (hStdIn
!= INVALID_HANDLE_VALUE
|| hStdOut
!= INVALID_HANDLE_VALUE
)
351 ok(ReadFile(hStdIn
, buf
, sizeof(buf
), &r
, NULL
) && r
> 0, "Reading message from input pipe\n");
352 childPrintf(hFile
, "[StdHandle]\nmsg=%s\n\n", encodeA(buf
));
353 ok(WriteFile(hStdOut
, buf
, r
, &w
, NULL
) && w
== r
, "Writing message to output pipe\n");
357 if (option
&& strcmp(option
, "exit_code") == 0)
359 childPrintf(hFile
, "[ExitCode]\nvalue=%d\n\n", 123);
367 static char* getChildString(const char* sect
, const char* key
)
369 char buf
[1024+4*MAX_LISTED_ENV_VAR
];
372 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), resfile
);
373 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
374 assert(!(strlen(buf
) & 1));
379 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
380 * others... (windows uses stricmp while Un*x uses strcasecmp...)
382 static int wtstrcasecmp(const char* p1
, const char* p2
)
387 while (c1
== c2
&& c1
)
389 c1
= *p1
++; c2
= *p2
++;
392 c1
= toupper(c1
); c2
= toupper(c2
);
398 static int strCmp(const char* s1
, const char* s2
, BOOL sensitive
)
400 if (!s1
&& !s2
) return 0;
403 return (sensitive
) ? strcmp(s1
, s2
) : wtstrcasecmp(s1
, s2
);
406 #define okChildString(sect, key, expect) \
408 char* result = getChildString((sect), (key)); \
409 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
412 #define okChildIString(sect, key, expect) \
414 char* result = getChildString(sect, key); \
415 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
418 /* using !expect ensures that the test will fail if the sect/key isn't present
421 #define okChildInt(sect, key, expect) \
423 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
424 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
427 static void test_Startup(void)
429 char buffer
[MAX_PATH
];
430 PROCESS_INFORMATION info
;
431 STARTUPINFOA startup
,si
;
432 static CHAR title
[] = "I'm the title string",
433 desktop
[] = "I'm the desktop string",
436 /* let's start simplistic */
437 memset(&startup
, 0, sizeof(startup
));
438 startup
.cb
= sizeof(startup
);
439 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
440 startup
.wShowWindow
= SW_SHOWNORMAL
;
442 get_file_name(resfile
);
443 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
444 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
445 /* wait for child to terminate */
446 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
447 /* child process has changed result file, so let profile functions know about it */
448 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
450 GetStartupInfoA(&si
);
451 okChildInt("StartupInfoA", "cb", startup
.cb
);
452 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
453 okChildString("StartupInfoA", "lpTitle", si
.lpTitle
);
454 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
455 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
456 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
457 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
458 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
459 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
460 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
461 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
462 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
464 assert(DeleteFileA(resfile
) != 0);
466 /* not so simplistic now */
467 memset(&startup
, 0, sizeof(startup
));
468 startup
.cb
= sizeof(startup
);
469 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
470 startup
.wShowWindow
= SW_SHOWNORMAL
;
471 startup
.lpTitle
= title
;
472 startup
.lpDesktop
= desktop
;
473 startup
.dwXCountChars
= 0x12121212;
474 startup
.dwYCountChars
= 0x23232323;
475 startup
.dwX
= 0x34343434;
476 startup
.dwY
= 0x45454545;
477 startup
.dwXSize
= 0x56565656;
478 startup
.dwYSize
= 0x67676767;
479 startup
.dwFillAttribute
= 0xA55A;
481 get_file_name(resfile
);
482 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
483 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
484 /* wait for child to terminate */
485 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
486 /* child process has changed result file, so let profile functions know about it */
487 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
489 okChildInt("StartupInfoA", "cb", startup
.cb
);
490 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
491 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
492 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
493 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
494 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
495 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
496 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
497 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
498 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
499 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
500 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
502 assert(DeleteFileA(resfile
) != 0);
504 /* not so simplistic now */
505 memset(&startup
, 0, sizeof(startup
));
506 startup
.cb
= sizeof(startup
);
507 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
508 startup
.wShowWindow
= SW_SHOWNORMAL
;
509 startup
.lpTitle
= title
;
510 startup
.lpDesktop
= NULL
;
511 startup
.dwXCountChars
= 0x12121212;
512 startup
.dwYCountChars
= 0x23232323;
513 startup
.dwX
= 0x34343434;
514 startup
.dwY
= 0x45454545;
515 startup
.dwXSize
= 0x56565656;
516 startup
.dwYSize
= 0x67676767;
517 startup
.dwFillAttribute
= 0xA55A;
519 get_file_name(resfile
);
520 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
521 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
522 /* wait for child to terminate */
523 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
524 /* child process has changed result file, so let profile functions know about it */
525 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
527 okChildInt("StartupInfoA", "cb", startup
.cb
);
528 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
529 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
530 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
531 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
532 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
533 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
534 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
535 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
536 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
537 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
538 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
540 assert(DeleteFileA(resfile
) != 0);
542 /* not so simplistic now */
543 memset(&startup
, 0, sizeof(startup
));
544 startup
.cb
= sizeof(startup
);
545 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
546 startup
.wShowWindow
= SW_SHOWNORMAL
;
547 startup
.lpTitle
= title
;
548 startup
.lpDesktop
= empty
;
549 startup
.dwXCountChars
= 0x12121212;
550 startup
.dwYCountChars
= 0x23232323;
551 startup
.dwX
= 0x34343434;
552 startup
.dwY
= 0x45454545;
553 startup
.dwXSize
= 0x56565656;
554 startup
.dwYSize
= 0x67676767;
555 startup
.dwFillAttribute
= 0xA55A;
557 get_file_name(resfile
);
558 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
559 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
560 /* wait for child to terminate */
561 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
562 /* child process has changed result file, so let profile functions know about it */
563 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
565 okChildInt("StartupInfoA", "cb", startup
.cb
);
566 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
567 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
568 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
569 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
570 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
571 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
572 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
573 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
574 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
575 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
576 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
578 assert(DeleteFileA(resfile
) != 0);
580 /* not so simplistic now */
581 memset(&startup
, 0, sizeof(startup
));
582 startup
.cb
= sizeof(startup
);
583 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
584 startup
.wShowWindow
= SW_SHOWNORMAL
;
585 startup
.lpTitle
= NULL
;
586 startup
.lpDesktop
= desktop
;
587 startup
.dwXCountChars
= 0x12121212;
588 startup
.dwYCountChars
= 0x23232323;
589 startup
.dwX
= 0x34343434;
590 startup
.dwY
= 0x45454545;
591 startup
.dwXSize
= 0x56565656;
592 startup
.dwYSize
= 0x67676767;
593 startup
.dwFillAttribute
= 0xA55A;
595 get_file_name(resfile
);
596 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
597 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
598 /* wait for child to terminate */
599 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
600 /* child process has changed result file, so let profile functions know about it */
601 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
603 okChildInt("StartupInfoA", "cb", startup
.cb
);
604 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
605 okChildString("StartupInfoA", "lpTitle", si
.lpTitle
);
606 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
607 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
608 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
609 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
610 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
611 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
612 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
613 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
614 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
616 assert(DeleteFileA(resfile
) != 0);
618 /* not so simplistic now */
619 memset(&startup
, 0, sizeof(startup
));
620 startup
.cb
= sizeof(startup
);
621 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
622 startup
.wShowWindow
= SW_SHOWNORMAL
;
623 startup
.lpTitle
= empty
;
624 startup
.lpDesktop
= desktop
;
625 startup
.dwXCountChars
= 0x12121212;
626 startup
.dwYCountChars
= 0x23232323;
627 startup
.dwX
= 0x34343434;
628 startup
.dwY
= 0x45454545;
629 startup
.dwXSize
= 0x56565656;
630 startup
.dwYSize
= 0x67676767;
631 startup
.dwFillAttribute
= 0xA55A;
633 get_file_name(resfile
);
634 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
635 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
636 /* wait for child to terminate */
637 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
638 /* child process has changed result file, so let profile functions know about it */
639 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
641 okChildInt("StartupInfoA", "cb", startup
.cb
);
642 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
643 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
644 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
645 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
646 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
647 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
648 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
649 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
650 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
651 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
652 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
654 assert(DeleteFileA(resfile
) != 0);
656 /* not so simplistic now */
657 memset(&startup
, 0, sizeof(startup
));
658 startup
.cb
= sizeof(startup
);
659 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
660 startup
.wShowWindow
= SW_SHOWNORMAL
;
661 startup
.lpTitle
= empty
;
662 startup
.lpDesktop
= empty
;
663 startup
.dwXCountChars
= 0x12121212;
664 startup
.dwYCountChars
= 0x23232323;
665 startup
.dwX
= 0x34343434;
666 startup
.dwY
= 0x45454545;
667 startup
.dwXSize
= 0x56565656;
668 startup
.dwYSize
= 0x67676767;
669 startup
.dwFillAttribute
= 0xA55A;
671 get_file_name(resfile
);
672 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
673 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
674 /* wait for child to terminate */
675 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
676 /* child process has changed result file, so let profile functions know about it */
677 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
679 okChildInt("StartupInfoA", "cb", startup
.cb
);
680 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
681 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
682 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
683 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
684 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
685 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
686 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
687 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
688 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
689 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
690 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
692 assert(DeleteFileA(resfile
) != 0);
694 /* TODO: test for A/W and W/A and W/W */
697 static void test_CommandLine(void)
699 char buffer
[MAX_PATH
], fullpath
[MAX_PATH
], *lpFilePart
, *p
;
700 PROCESS_INFORMATION info
;
701 STARTUPINFOA startup
;
704 memset(&startup
, 0, sizeof(startup
));
705 startup
.cb
= sizeof(startup
);
706 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
707 startup
.wShowWindow
= SW_SHOWNORMAL
;
710 get_file_name(resfile
);
711 sprintf(buffer
, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname
, resfile
);
712 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
713 /* wait for child to terminate */
714 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
715 /* child process has changed result file, so let profile functions know about it */
716 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
718 okChildInt("Arguments", "argcA", 4);
719 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
720 okChildString("Arguments", "argvA4", NULL
);
721 okChildString("Arguments", "CommandLineA", buffer
);
723 assert(DeleteFileA(resfile
) != 0);
725 memset(&startup
, 0, sizeof(startup
));
726 startup
.cb
= sizeof(startup
);
727 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
728 startup
.wShowWindow
= SW_SHOWNORMAL
;
731 get_file_name(resfile
);
732 sprintf(buffer
, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
733 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
734 /* wait for child to terminate */
735 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
736 /* child process has changed result file, so let profile functions know about it */
737 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
739 okChildInt("Arguments", "argcA", 6);
740 okChildString("Arguments", "argvA3", "a\"b\\");
741 okChildString("Arguments", "argvA4", "c\"");
742 okChildString("Arguments", "argvA5", "d");
743 okChildString("Arguments", "argvA6", NULL
);
744 okChildString("Arguments", "CommandLineA", buffer
);
746 assert(DeleteFileA(resfile
) != 0);
748 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
749 get_file_name(resfile
);
750 sprintf(buffer
, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
751 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
752 /* wait for child to terminate */
753 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
754 /* child process has changed result file, so let profile functions know about it */
755 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
756 sprintf(buffer
, "./%s", selfname
);
757 okChildString("Arguments", "argvA0", buffer
);
759 assert(DeleteFileA(resfile
) != 0);
761 get_file_name(resfile
);
762 sprintf(buffer
, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
763 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
764 /* wait for child to terminate */
765 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
766 /* child process has changed result file, so let profile functions know about it */
767 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
768 sprintf(buffer
, ".\\%s", selfname
);
769 okChildString("Arguments", "argvA0", buffer
);
771 assert(DeleteFileA(resfile
) != 0);
773 get_file_name(resfile
);
774 len
= GetFullPathNameA(selfname
, MAX_PATH
, fullpath
, &lpFilePart
);
775 assert ( lpFilePart
!= 0);
776 *(lpFilePart
-1 ) = 0;
777 p
= strrchr(fullpath
, '\\');
779 sprintf(buffer
, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p
, selfname
, resfile
);
780 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
781 /* wait for child to terminate */
782 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
783 /* child process has changed result file, so let profile functions know about it */
784 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
785 sprintf(buffer
, "..%s/%s", p
, selfname
);
786 okChildString("Arguments", "argvA0", buffer
);
788 assert(DeleteFileA(resfile
) != 0);
792 static void test_Directory(void)
794 char buffer
[MAX_PATH
];
795 PROCESS_INFORMATION info
;
796 STARTUPINFOA startup
;
797 char windir
[MAX_PATH
];
798 static CHAR cmdline
[] = "winver.exe";
800 memset(&startup
, 0, sizeof(startup
));
801 startup
.cb
= sizeof(startup
);
802 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
803 startup
.wShowWindow
= SW_SHOWNORMAL
;
806 get_file_name(resfile
);
807 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
808 GetWindowsDirectoryA( windir
, sizeof(windir
) );
809 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, windir
, &startup
, &info
), "CreateProcess\n");
810 /* wait for child to terminate */
811 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
812 /* child process has changed result file, so let profile functions know about it */
813 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
815 okChildIString("Misc", "CurrDirA", windir
);
817 assert(DeleteFileA(resfile
) != 0);
819 /* search PATH for the exe if directory is NULL */
820 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
821 ok(TerminateProcess(info
.hProcess
, 0), "Child process termination\n");
823 /* if any directory is provided, don't search PATH, error on bad directory */
824 SetLastError(0xdeadbeef);
825 memset(&info
, 0, sizeof(info
));
826 ok(!CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L,
827 NULL
, "non\\existent\\directory", &startup
, &info
), "CreateProcess\n");
828 ok(GetLastError() == ERROR_DIRECTORY
, "Expected ERROR_DIRECTORY, got %ld\n", GetLastError());
829 ok(!TerminateProcess(info
.hProcess
, 0), "Child process should not exist\n");
832 static BOOL
is_str_env_drive_dir(const char* str
)
834 return str
[0] == '=' && str
[1] >= 'A' && str
[1] <= 'Z' && str
[2] == ':' &&
835 str
[3] == '=' && str
[4] == str
[1];
838 /* compared expected child's environment (in gesA) from actual
839 * environment our child got
841 static void cmpEnvironment(const char* gesA
)
849 clen
= GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile
);
851 /* now look each parent env in child */
852 if ((ptrA
= gesA
) != NULL
)
856 for (i
= 0; i
< clen
; i
++)
858 sprintf(key
, "env%d", i
);
859 res
= getChildString("EnvironmentA", key
);
860 if (strncmp(ptrA
, res
, MAX_LISTED_ENV_VAR
- 1) == 0)
864 ok(found
, "Parent-env string %s isn't in child process\n", ptrA
);
866 ptrA
+= strlen(ptrA
) + 1;
870 /* and each child env in parent */
871 for (i
= 0; i
< clen
; i
++)
873 sprintf(key
, "env%d", i
);
874 res
= getChildString("EnvironmentA", key
);
875 if ((ptrA
= gesA
) != NULL
)
879 if (strncmp(res
, ptrA
, MAX_LISTED_ENV_VAR
- 1) == 0)
881 ptrA
+= strlen(ptrA
) + 1;
883 if (!*ptrA
) ptrA
= NULL
;
886 if (!is_str_env_drive_dir(res
))
888 found
= ptrA
!= NULL
;
889 ok(found
, "Child-env string %s isn't in parent process\n", res
);
891 /* else => should also test we get the right per drive default directory here... */
895 static void test_Environment(void)
897 char buffer
[MAX_PATH
];
898 PROCESS_INFORMATION info
;
899 STARTUPINFOA startup
;
906 memset(&startup
, 0, sizeof(startup
));
907 startup
.cb
= sizeof(startup
);
908 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
909 startup
.wShowWindow
= SW_SHOWNORMAL
;
912 get_file_name(resfile
);
913 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
914 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
915 /* wait for child to terminate */
916 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
917 /* child process has changed result file, so let profile functions know about it */
918 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
920 cmpEnvironment(GetEnvironmentStringsA());
922 assert(DeleteFileA(resfile
) != 0);
924 memset(&startup
, 0, sizeof(startup
));
925 startup
.cb
= sizeof(startup
);
926 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
927 startup
.wShowWindow
= SW_SHOWNORMAL
;
930 get_file_name(resfile
);
931 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
934 ptr
= GetEnvironmentStringsA();
937 slen
= strlen(ptr
)+1;
938 child_env_len
+= slen
;
941 /* Add space for additional environment variables */
942 child_env_len
+= 256;
943 child_env
= HeapAlloc(GetProcessHeap(), 0, child_env_len
);
946 sprintf(ptr
, "=%c:=%s", 'C', "C:\\FOO\\BAR");
947 ptr
+= strlen(ptr
) + 1;
948 strcpy(ptr
, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
949 ptr
+= strlen(ptr
) + 1;
950 strcpy(ptr
, "FOO=BAR");
951 ptr
+= strlen(ptr
) + 1;
952 strcpy(ptr
, "BAR=FOOBAR");
953 ptr
+= strlen(ptr
) + 1;
954 /* copy all existing variables except:
956 * - PATH (already set above)
957 * - the directory definitions (=[A-Z]:=)
959 for (env
= GetEnvironmentStringsA(); *env
; env
+= strlen(env
) + 1)
961 if (strncmp(env
, "PATH=", 5) != 0 &&
962 strncmp(env
, "WINELOADER=", 11) != 0 &&
963 !is_str_env_drive_dir(env
))
966 ptr
+= strlen(ptr
) + 1;
970 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, child_env
, NULL
, &startup
, &info
), "CreateProcess\n");
971 /* wait for child to terminate */
972 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
973 /* child process has changed result file, so let profile functions know about it */
974 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
976 cmpEnvironment(child_env
);
978 HeapFree(GetProcessHeap(), 0, child_env
);
980 assert(DeleteFileA(resfile
) != 0);
983 static void test_SuspendFlag(void)
985 char buffer
[MAX_PATH
];
986 PROCESS_INFORMATION info
;
987 STARTUPINFOA startup
, us
;
990 /* let's start simplistic */
991 memset(&startup
, 0, sizeof(startup
));
992 startup
.cb
= sizeof(startup
);
993 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
994 startup
.wShowWindow
= SW_SHOWNORMAL
;
996 get_file_name(resfile
);
997 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
998 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1000 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1002 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1003 ok(ResumeThread(info
.hThread
) == 1, "Resuming thread\n");
1005 /* wait for child to terminate */
1006 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1007 /* child process has changed result file, so let profile functions know about it */
1008 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1010 GetStartupInfoA(&us
);
1012 okChildInt("StartupInfoA", "cb", startup
.cb
);
1013 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1014 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1015 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1016 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1017 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1018 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1019 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1020 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1021 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1022 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1023 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1025 assert(DeleteFileA(resfile
) != 0);
1028 static void test_DebuggingFlag(void)
1030 char buffer
[MAX_PATH
];
1031 PROCESS_INFORMATION info
;
1032 STARTUPINFOA startup
, us
;
1036 /* let's start simplistic */
1037 memset(&startup
, 0, sizeof(startup
));
1038 startup
.cb
= sizeof(startup
);
1039 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1040 startup
.wShowWindow
= SW_SHOWNORMAL
;
1042 get_file_name(resfile
);
1043 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1044 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1046 /* get all startup events up to the entry point break exception */
1049 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
1050 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
1051 if (de
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
) dbg
++;
1052 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
1054 ok(dbg
, "I have seen a debug event\n");
1055 /* wait for child to terminate */
1056 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1057 /* child process has changed result file, so let profile functions know about it */
1058 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1060 GetStartupInfoA(&us
);
1062 okChildInt("StartupInfoA", "cb", startup
.cb
);
1063 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1064 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1065 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1066 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1067 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1068 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1069 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1070 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1071 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1072 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1073 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1075 assert(DeleteFileA(resfile
) != 0);
1078 static BOOL
is_console(HANDLE h
)
1080 return h
!= INVALID_HANDLE_VALUE
&& ((ULONG_PTR
)h
& 3) == 3;
1083 static void test_Console(void)
1085 char buffer
[MAX_PATH
];
1086 PROCESS_INFORMATION info
;
1087 STARTUPINFOA startup
, us
;
1088 SECURITY_ATTRIBUTES sa
;
1089 CONSOLE_SCREEN_BUFFER_INFO sbi
, sbiC
;
1090 DWORD modeIn
, modeOut
, modeInC
, modeOutC
;
1091 DWORD cpIn
, cpOut
, cpInC
, cpOutC
;
1093 HANDLE hChildIn
, hChildInInh
, hChildOut
, hChildOutInh
, hParentIn
, hParentOut
;
1094 const char* msg
= "This is a std-handle inheritance test.";
1097 memset(&startup
, 0, sizeof(startup
));
1098 startup
.cb
= sizeof(startup
);
1099 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1100 startup
.wShowWindow
= SW_SHOWNORMAL
;
1102 sa
.nLength
= sizeof(sa
);
1103 sa
.lpSecurityDescriptor
= NULL
;
1104 sa
.bInheritHandle
= TRUE
;
1106 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1107 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1109 /* first, we need to be sure we're attached to a console */
1110 if (!is_console(startup
.hStdInput
) || !is_console(startup
.hStdOutput
))
1112 /* we're not attached to a console, let's do it */
1114 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1115 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1117 /* now verify everything's ok */
1118 ok(startup
.hStdInput
!= INVALID_HANDLE_VALUE
, "Opening ConIn\n");
1119 ok(startup
.hStdOutput
!= INVALID_HANDLE_VALUE
, "Opening ConOut\n");
1120 startup
.hStdError
= startup
.hStdOutput
;
1122 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbi
), "Getting sb info\n");
1123 ok(GetConsoleMode(startup
.hStdInput
, &modeIn
) &&
1124 GetConsoleMode(startup
.hStdOutput
, &modeOut
), "Getting console modes\n");
1125 cpIn
= GetConsoleCP();
1126 cpOut
= GetConsoleOutputCP();
1128 get_file_name(resfile
);
1129 sprintf(buffer
, "%s tests/process.c %s console", selfname
, resfile
);
1130 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1132 /* wait for child to terminate */
1133 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1134 /* child process has changed result file, so let profile functions know about it */
1135 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1137 /* now get the modification the child has made, and resets parents expected values */
1138 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbiC
), "Getting sb info\n");
1139 ok(GetConsoleMode(startup
.hStdInput
, &modeInC
) &&
1140 GetConsoleMode(startup
.hStdOutput
, &modeOutC
), "Getting console modes\n");
1142 SetConsoleMode(startup
.hStdInput
, modeIn
);
1143 SetConsoleMode(startup
.hStdOutput
, modeOut
);
1145 cpInC
= GetConsoleCP();
1146 cpOutC
= GetConsoleOutputCP();
1148 SetConsoleOutputCP(cpOut
);
1150 GetStartupInfoA(&us
);
1152 okChildInt("StartupInfoA", "cb", startup
.cb
);
1153 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1154 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1155 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1156 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1157 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1158 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1159 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1160 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1161 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1162 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1163 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1165 /* check child correctly inherited the console */
1166 okChildInt("StartupInfoA", "hStdInput", (DWORD
)startup
.hStdInput
);
1167 okChildInt("StartupInfoA", "hStdOutput", (DWORD
)startup
.hStdOutput
);
1168 okChildInt("StartupInfoA", "hStdError", (DWORD
)startup
.hStdError
);
1169 okChildInt("Console", "SizeX", (DWORD
)sbi
.dwSize
.X
);
1170 okChildInt("Console", "SizeY", (DWORD
)sbi
.dwSize
.Y
);
1171 okChildInt("Console", "CursorX", (DWORD
)sbi
.dwCursorPosition
.X
);
1172 okChildInt("Console", "CursorY", (DWORD
)sbi
.dwCursorPosition
.Y
);
1173 okChildInt("Console", "Attributes", sbi
.wAttributes
);
1174 okChildInt("Console", "winLeft", (DWORD
)sbi
.srWindow
.Left
);
1175 okChildInt("Console", "winTop", (DWORD
)sbi
.srWindow
.Top
);
1176 okChildInt("Console", "winRight", (DWORD
)sbi
.srWindow
.Right
);
1177 okChildInt("Console", "winBottom", (DWORD
)sbi
.srWindow
.Bottom
);
1178 okChildInt("Console", "maxWinWidth", (DWORD
)sbi
.dwMaximumWindowSize
.X
);
1179 okChildInt("Console", "maxWinHeight", (DWORD
)sbi
.dwMaximumWindowSize
.Y
);
1180 okChildInt("Console", "InputCP", cpIn
);
1181 okChildInt("Console", "OutputCP", cpOut
);
1182 okChildInt("Console", "InputMode", modeIn
);
1183 okChildInt("Console", "OutputMode", modeOut
);
1185 todo_wine
ok(cpInC
== 1252, "Wrong console CP (expected 1252 got %ld/%ld)\n", cpInC
, cpIn
);
1186 todo_wine
ok(cpOutC
== 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)\n", cpOutC
, cpOut
);
1187 ok(modeInC
== (modeIn
^ 1), "Wrong console mode\n");
1188 ok(modeOutC
== (modeOut
^ 1), "Wrong console-SB mode\n");
1189 ok(sbiC
.dwCursorPosition
.X
== (sbi
.dwCursorPosition
.X
^ 1), "Wrong cursor position\n");
1190 ok(sbiC
.dwCursorPosition
.Y
== (sbi
.dwCursorPosition
.Y
^ 1), "Wrong cursor position\n");
1193 assert(DeleteFileA(resfile
) != 0);
1195 ok(CreatePipe(&hParentIn
, &hChildOut
, NULL
, 0), "Creating parent-input pipe\n");
1196 ok(DuplicateHandle(GetCurrentProcess(), hChildOut
, GetCurrentProcess(),
1197 &hChildOutInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1198 "Duplicating as inheritable child-output pipe\n");
1199 CloseHandle(hChildOut
);
1201 ok(CreatePipe(&hChildIn
, &hParentOut
, NULL
, 0), "Creating parent-output pipe\n");
1202 ok(DuplicateHandle(GetCurrentProcess(), hChildIn
, GetCurrentProcess(),
1203 &hChildInInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1204 "Duplicating as inheritable child-input pipe\n");
1205 CloseHandle(hChildIn
);
1207 memset(&startup
, 0, sizeof(startup
));
1208 startup
.cb
= sizeof(startup
);
1209 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1210 startup
.wShowWindow
= SW_SHOWNORMAL
;
1211 startup
.hStdInput
= hChildInInh
;
1212 startup
.hStdOutput
= hChildOutInh
;
1213 startup
.hStdError
= hChildOutInh
;
1215 get_file_name(resfile
);
1216 sprintf(buffer
, "%s tests/process.c %s stdhandle", selfname
, resfile
);
1217 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1218 ok(CloseHandle(hChildInInh
), "Closing handle\n");
1219 ok(CloseHandle(hChildOutInh
), "Closing handle\n");
1221 msg_len
= strlen(msg
) + 1;
1222 ok(WriteFile(hParentOut
, msg
, msg_len
, &w
, NULL
), "Writing to child\n");
1223 ok(w
== msg_len
, "Should have written %u bytes, actually wrote %lu\n", msg_len
, w
);
1224 memset(buffer
, 0, sizeof(buffer
));
1225 ok(ReadFile(hParentIn
, buffer
, sizeof(buffer
), &w
, NULL
), "Reading from child\n");
1226 ok(strcmp(buffer
, msg
) == 0, "Should have received '%s'\n", msg
);
1228 /* wait for child to terminate */
1229 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1230 /* child process has changed result file, so let profile functions know about it */
1231 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1233 okChildString("StdHandle", "msg", msg
);
1236 assert(DeleteFileA(resfile
) != 0);
1239 static void test_ExitCode(void)
1241 char buffer
[MAX_PATH
];
1242 PROCESS_INFORMATION info
;
1243 STARTUPINFOA startup
;
1246 /* let's start simplistic */
1247 memset(&startup
, 0, sizeof(startup
));
1248 startup
.cb
= sizeof(startup
);
1249 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1250 startup
.wShowWindow
= SW_SHOWNORMAL
;
1252 get_file_name(resfile
);
1253 sprintf(buffer
, "%s tests/process.c %s exit_code", selfname
, resfile
);
1254 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1256 /* wait for child to terminate */
1257 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1258 /* child process has changed result file, so let profile functions know about it */
1259 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1261 ok(GetExitCodeProcess(info
.hProcess
, &code
), "Getting exit code\n");
1262 okChildInt("ExitCode", "value", code
);
1265 assert(DeleteFileA(resfile
) != 0);
1271 ok(b
, "Basic init of CreateProcess test\n");
1276 doChild(myARGV
[2], (myARGC
== 3) ? NULL
: myARGV
[3]);
1284 test_DebuggingFlag();
1287 /* things that can be tested:
1288 * lookup: check the way program to be executed is searched
1289 * handles: check the handle inheritance stuff (+sec options)
1290 * console: check if console creation parameters work