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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/test.h"
31 static char base[MAX_PATH];
32 static char selfname[MAX_PATH];
33 static char resfile[MAX_PATH];
38 /* as some environment variables get very long on Unix, we only test for
41 #define MAX_LISTED_ENV_VAR 128
43 /* ---------------- portable memory allocation thingie */
45 static char memory[1024*32];
46 static char* memory_index = memory;
48 static char* grab_memory(size_t len)
50 char* ret = memory_index;
54 assert(memory_index <= memory + sizeof(memory));
58 static void release_memory(void)
60 memory_index = memory;
63 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
65 static char* encodeA(const char* str)
71 len = strlen(str) + 1;
72 ptr = grab_memory(len * 2 + 1);
73 for (i = 0; i < len; i++)
74 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
79 static char* encodeW(const WCHAR* str)
85 len = lstrlenW(str) + 1;
86 ptr = grab_memory(len * 4 + 1);
88 for (i = 0; i < len; i++)
89 sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
94 static unsigned decode_char(char c)
96 if (c >= '0' && c <= '9') return c - '0';
97 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
98 assert(c >= 'A' && c <= 'F');
102 static char* decodeA(const char* str)
107 len = strlen(str) / 2;
108 if (!len--) return NULL;
109 ptr = grab_memory(len + 1);
110 for (i = 0; i < len; i++)
111 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
117 /* This will be needed to decode Unicode strings saved by the child process
118 * when we test Unicode functions.
120 static WCHAR* decodeW(const char* str)
126 len = strlen(str) / 4;
127 if (!len--) return NULL;
128 ptr = (WCHAR*)grab_memory(len * 2 + 1);
129 for (i = 0; i < len; i++)
130 ptr[i] = (decode_char(str[4 * i]) << 12) |
131 (decode_char(str[4 * i + 1]) << 8) |
132 (decode_char(str[4 * i + 2]) << 4) |
133 (decode_char(str[4 * i + 3]) << 0);
139 /******************************************************************
142 * generates basic information like:
143 * base: absolute path to curr dir
144 * selfname: the way to reinvoke ourselves
146 static int init(void)
148 myARGC = winetest_get_mainargs( &myARGV );
149 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
150 strcpy(selfname, myARGV[0]);
154 /******************************************************************
157 * generates an absolute file_name for temporary file
160 static void get_file_name(char* buf)
165 GetTempPathA(sizeof(path), path);
166 GetTempFileNameA(path, "wt", 0, buf);
169 /******************************************************************
170 * static void childPrintf
173 static void childPrintf(HANDLE h, const char* fmt, ...)
179 va_start(valist, fmt);
180 vsprintf(buffer, fmt, valist);
182 WriteFile(h, buffer, strlen(buffer), &w, NULL);
186 /******************************************************************
189 * output most of the information in the child process
191 static void doChild(const char* file, const char* option)
199 WCHAR bufW[MAX_PATH];
200 HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
202 if (hFile == INVALID_HANDLE_VALUE) return;
204 /* output of startup info (Ansi) */
205 GetStartupInfoA(&siA);
207 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
208 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
209 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
210 "dwFlags=%lu\nwShowWindow=%u\n"
211 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
212 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
213 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
214 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
215 siA.dwFlags, siA.wShowWindow,
216 (DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
218 /* since GetStartupInfoW is only implemented in win2k,
219 * zero out before calling so we can notice the difference
221 memset(&siW, 0, sizeof(siW));
222 GetStartupInfoW(&siW);
224 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
225 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
226 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
227 "dwFlags=%lu\nwShowWindow=%u\n"
228 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
229 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
230 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
231 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
232 siW.dwFlags, siW.wShowWindow,
233 (DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
236 childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
237 for (i = 0; i < myARGC; i++)
239 childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
241 childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
247 /* this is part of shell32... and should be tested there */
248 argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
249 for (i = 0; i < argcW; i++)
251 childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
254 childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
256 /* output of environment (Ansi) */
257 ptrA = GetEnvironmentStringsA();
260 char env_var[MAX_LISTED_ENV_VAR];
262 childPrintf(hFile, "[EnvironmentA]\n");
266 strncpy(env_var, ptrA, MAX_LISTED_ENV_VAR - 1);
267 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
268 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
270 ptrA += strlen(ptrA) + 1;
272 childPrintf(hFile, "len=%d\n\n", i);
275 /* output of environment (Unicode) */
276 ptrW = GetEnvironmentStringsW();
279 WCHAR env_var[MAX_LISTED_ENV_VAR];
281 childPrintf(hFile, "[EnvironmentW]\n");
285 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
286 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
287 childPrintf(hFile, "env%d=%s\n", i, encodeW(ptrW));
289 ptrW += lstrlenW(ptrW) + 1;
291 childPrintf(hFile, "len=%d\n\n", i);
294 childPrintf(hFile, "[Misc]\n");
295 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
296 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
297 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
298 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
299 childPrintf(hFile, "\n");
301 if (option && strcmp(option, "console") == 0)
303 CONSOLE_SCREEN_BUFFER_INFO sbi;
304 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
305 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
306 DWORD modeIn, modeOut;
308 childPrintf(hFile, "[Console]\n");
309 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
311 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
312 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
313 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
314 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
315 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
316 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
318 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
319 GetConsoleCP(), GetConsoleOutputCP());
320 if (GetConsoleMode(hConIn, &modeIn))
321 childPrintf(hFile, "InputMode=%ld\n", modeIn);
322 if (GetConsoleMode(hConOut, &modeOut))
323 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
325 /* now that we have written all relevant information, let's change it */
326 ok(SetConsoleCP(1252), "Setting CP");
327 ok(SetConsoleOutputCP(1252), "Setting SB CP");
328 ok(SetConsoleMode(hConIn, modeIn ^ 1), "Setting mode (%ld)", GetLastError());
329 ok(SetConsoleMode(hConOut, modeOut ^ 1), "Setting mode (%ld)", GetLastError());
330 sbi.dwCursorPosition.X ^= 1;
331 sbi.dwCursorPosition.Y ^= 1;
332 ok(SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition), "Setting cursor position (%ld)", GetLastError());
334 if (option && strcmp(option, "stdhandle") == 0)
336 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
337 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
339 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
344 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe");
345 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
346 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writting message to output pipe");
350 if (option && strcmp(option, "exit_code") == 0)
352 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
360 static char* getChildString(const char* sect, const char* key)
365 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
366 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
367 assert(!(strlen(buf) & 1));
372 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
373 * others... (windows uses stricmp while Un*x uses strcasecmp...)
375 static int wtstrcasecmp(const char* p1, const char* p2)
380 while (c1 == c2 && c1)
382 c1 = *p1++; c2 = *p2++;
385 c1 = toupper(c1); c2 = toupper(c2);
391 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
393 if (!s1 && !s2) return 0;
396 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
399 #define okChildString(sect, key, expect) \
401 char* result = getChildString((sect), (key)); \
402 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'", (sect), (key), (expect)?(expect):"(null)", result); \
405 #define okChildIString(sect, key, expect) \
407 char* result = getChildString(sect, key); \
408 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'", sect, key, expect, result); \
411 /* using !expect insures that the test will fail if the sect/key isn't present
414 #define okChildInt(sect, key, expect) \
416 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
417 ok(result == expect, "%s:%s expected %d, but got %d", (sect), (key), (int)(expect), result); \
420 static void test_Startup(void)
422 char buffer[MAX_PATH];
423 PROCESS_INFORMATION info;
424 STARTUPINFOA startup,si;
426 /* let's start simplistic */
427 memset(&startup, 0, sizeof(startup));
428 startup.cb = sizeof(startup);
429 startup.dwFlags = STARTF_USESHOWWINDOW;
430 startup.wShowWindow = SW_SHOWNORMAL;
432 get_file_name(resfile);
433 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
434 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
435 /* wait for child to terminate */
436 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
437 /* child process has changed result file, so let profile functions know about it */
438 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
440 GetStartupInfoA(&si);
441 okChildInt("StartupInfoA", "cb", startup.cb);
442 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
443 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
444 okChildInt("StartupInfoA", "dwX", startup.dwX);
445 okChildInt("StartupInfoA", "dwY", startup.dwY);
446 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
447 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
448 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
449 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
450 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
451 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
452 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
454 assert(DeleteFileA(resfile) != 0);
456 /* not so simplistic now */
457 memset(&startup, 0, sizeof(startup));
458 startup.cb = sizeof(startup);
459 startup.dwFlags = STARTF_USESHOWWINDOW;
460 startup.wShowWindow = SW_SHOWNORMAL;
461 startup.lpTitle = "I'm the title string";
462 startup.lpDesktop = "I'm the desktop string";
463 startup.dwXCountChars = 0x12121212;
464 startup.dwYCountChars = 0x23232323;
465 startup.dwX = 0x34343434;
466 startup.dwY = 0x45454545;
467 startup.dwXSize = 0x56565656;
468 startup.dwYSize = 0x67676767;
469 startup.dwFillAttribute = 0xA55A;
471 get_file_name(resfile);
472 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
473 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
474 /* wait for child to terminate */
475 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
476 /* child process has changed result file, so let profile functions know about it */
477 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
479 okChildInt("StartupInfoA", "cb", startup.cb);
480 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
481 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
482 okChildInt("StartupInfoA", "dwX", startup.dwX);
483 okChildInt("StartupInfoA", "dwY", startup.dwY);
484 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
485 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
486 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
487 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
488 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
489 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
490 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
492 assert(DeleteFileA(resfile) != 0);
494 /* not so simplistic now */
495 memset(&startup, 0, sizeof(startup));
496 startup.cb = sizeof(startup);
497 startup.dwFlags = STARTF_USESHOWWINDOW;
498 startup.wShowWindow = SW_SHOWNORMAL;
499 startup.lpTitle = "I'm the title string";
500 startup.lpDesktop = NULL;
501 startup.dwXCountChars = 0x12121212;
502 startup.dwYCountChars = 0x23232323;
503 startup.dwX = 0x34343434;
504 startup.dwY = 0x45454545;
505 startup.dwXSize = 0x56565656;
506 startup.dwYSize = 0x67676767;
507 startup.dwFillAttribute = 0xA55A;
509 get_file_name(resfile);
510 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
511 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
512 /* wait for child to terminate */
513 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
514 /* child process has changed result file, so let profile functions know about it */
515 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
517 okChildInt("StartupInfoA", "cb", startup.cb);
518 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
519 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
520 okChildInt("StartupInfoA", "dwX", startup.dwX);
521 okChildInt("StartupInfoA", "dwY", startup.dwY);
522 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
523 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
524 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
525 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
526 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
527 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
528 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
530 assert(DeleteFileA(resfile) != 0);
532 /* not so simplistic now */
533 memset(&startup, 0, sizeof(startup));
534 startup.cb = sizeof(startup);
535 startup.dwFlags = STARTF_USESHOWWINDOW;
536 startup.wShowWindow = SW_SHOWNORMAL;
537 startup.lpTitle = "I'm the title string";
538 startup.lpDesktop = "";
539 startup.dwXCountChars = 0x12121212;
540 startup.dwYCountChars = 0x23232323;
541 startup.dwX = 0x34343434;
542 startup.dwY = 0x45454545;
543 startup.dwXSize = 0x56565656;
544 startup.dwYSize = 0x67676767;
545 startup.dwFillAttribute = 0xA55A;
547 get_file_name(resfile);
548 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
549 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
550 /* wait for child to terminate */
551 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
552 /* child process has changed result file, so let profile functions know about it */
553 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
555 okChildInt("StartupInfoA", "cb", startup.cb);
556 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
557 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
558 okChildInt("StartupInfoA", "dwX", startup.dwX);
559 okChildInt("StartupInfoA", "dwY", startup.dwY);
560 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
561 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
562 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
563 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
564 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
565 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
566 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
568 assert(DeleteFileA(resfile) != 0);
570 /* not so simplistic now */
571 memset(&startup, 0, sizeof(startup));
572 startup.cb = sizeof(startup);
573 startup.dwFlags = STARTF_USESHOWWINDOW;
574 startup.wShowWindow = SW_SHOWNORMAL;
575 startup.lpTitle = NULL;
576 startup.lpDesktop = "I'm the desktop string";
577 startup.dwXCountChars = 0x12121212;
578 startup.dwYCountChars = 0x23232323;
579 startup.dwX = 0x34343434;
580 startup.dwY = 0x45454545;
581 startup.dwXSize = 0x56565656;
582 startup.dwYSize = 0x67676767;
583 startup.dwFillAttribute = 0xA55A;
585 get_file_name(resfile);
586 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
587 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
588 /* wait for child to terminate */
589 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
590 /* child process has changed result file, so let profile functions know about it */
591 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
593 okChildInt("StartupInfoA", "cb", startup.cb);
594 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
595 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
596 okChildInt("StartupInfoA", "dwX", startup.dwX);
597 okChildInt("StartupInfoA", "dwY", startup.dwY);
598 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
599 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
600 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
601 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
602 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
603 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
604 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
606 assert(DeleteFileA(resfile) != 0);
608 /* not so simplistic now */
609 memset(&startup, 0, sizeof(startup));
610 startup.cb = sizeof(startup);
611 startup.dwFlags = STARTF_USESHOWWINDOW;
612 startup.wShowWindow = SW_SHOWNORMAL;
613 startup.lpTitle = "";
614 startup.lpDesktop = "I'm the desktop string";
615 startup.dwXCountChars = 0x12121212;
616 startup.dwYCountChars = 0x23232323;
617 startup.dwX = 0x34343434;
618 startup.dwY = 0x45454545;
619 startup.dwXSize = 0x56565656;
620 startup.dwYSize = 0x67676767;
621 startup.dwFillAttribute = 0xA55A;
623 get_file_name(resfile);
624 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
625 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
626 /* wait for child to terminate */
627 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
628 /* child process has changed result file, so let profile functions know about it */
629 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
631 okChildInt("StartupInfoA", "cb", startup.cb);
632 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
633 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
634 okChildInt("StartupInfoA", "dwX", startup.dwX);
635 okChildInt("StartupInfoA", "dwY", startup.dwY);
636 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
637 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
638 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
639 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
640 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
641 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
642 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
644 assert(DeleteFileA(resfile) != 0);
646 /* not so simplistic now */
647 memset(&startup, 0, sizeof(startup));
648 startup.cb = sizeof(startup);
649 startup.dwFlags = STARTF_USESHOWWINDOW;
650 startup.wShowWindow = SW_SHOWNORMAL;
651 startup.lpTitle = "";
652 startup.lpDesktop = "";
653 startup.dwXCountChars = 0x12121212;
654 startup.dwYCountChars = 0x23232323;
655 startup.dwX = 0x34343434;
656 startup.dwY = 0x45454545;
657 startup.dwXSize = 0x56565656;
658 startup.dwYSize = 0x67676767;
659 startup.dwFillAttribute = 0xA55A;
661 get_file_name(resfile);
662 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
663 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
664 /* wait for child to terminate */
665 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
666 /* child process has changed result file, so let profile functions know about it */
667 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
669 okChildInt("StartupInfoA", "cb", startup.cb);
670 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
671 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
672 okChildInt("StartupInfoA", "dwX", startup.dwX);
673 okChildInt("StartupInfoA", "dwY", startup.dwY);
674 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
675 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
676 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
677 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
678 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
679 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
680 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
682 assert(DeleteFileA(resfile) != 0);
684 /* TODO: test for A/W and W/A and W/W */
687 static void test_CommandLine(void)
689 char buffer[MAX_PATH];
690 PROCESS_INFORMATION info;
691 STARTUPINFOA startup;
693 memset(&startup, 0, sizeof(startup));
694 startup.cb = sizeof(startup);
695 startup.dwFlags = STARTF_USESHOWWINDOW;
696 startup.wShowWindow = SW_SHOWNORMAL;
699 get_file_name(resfile);
700 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
701 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
702 /* wait for child to terminate */
703 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
704 /* child process has changed result file, so let profile functions know about it */
705 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
707 okChildInt("Arguments", "argcA", 4);
708 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
709 okChildString("Arguments", "argvA4", NULL);
710 okChildString("Arguments", "CommandLineA", buffer);
712 assert(DeleteFileA(resfile) != 0);
714 memset(&startup, 0, sizeof(startup));
715 startup.cb = sizeof(startup);
716 startup.dwFlags = STARTF_USESHOWWINDOW;
717 startup.wShowWindow = SW_SHOWNORMAL;
720 get_file_name(resfile);
721 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
722 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
723 /* wait for child to terminate */
724 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
725 /* child process has changed result file, so let profile functions know about it */
726 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
728 okChildInt("Arguments", "argcA", 6);
729 okChildString("Arguments", "argvA3", "a\"b\\");
730 okChildString("Arguments", "argvA4", "c\"");
731 okChildString("Arguments", "argvA5", "d");
732 okChildString("Arguments", "argvA6", NULL);
733 okChildString("Arguments", "CommandLineA", buffer);
735 assert(DeleteFileA(resfile) != 0);
738 static void test_Directory(void)
740 char buffer[MAX_PATH];
741 PROCESS_INFORMATION info;
742 STARTUPINFOA startup;
743 char windir[MAX_PATH];
745 memset(&startup, 0, sizeof(startup));
746 startup.cb = sizeof(startup);
747 startup.dwFlags = STARTF_USESHOWWINDOW;
748 startup.wShowWindow = SW_SHOWNORMAL;
751 get_file_name(resfile);
752 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
753 GetWindowsDirectoryA( windir, sizeof(windir) );
754 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess");
755 /* wait for child to terminate */
756 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
757 /* child process has changed result file, so let profile functions know about it */
758 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
760 okChildIString("Misc", "CurrDirA", windir);
762 assert(DeleteFileA(resfile) != 0);
765 static BOOL is_str_env_drive_dir(const char* str)
767 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
768 str[3] == '=' && str[4] == str[1];
771 /* compared expected child's environment (in gesA) from actual
772 * environment our child got
774 static void cmpEnvironment(const char* gesA)
782 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
784 /* now look each parent env in child */
785 if ((ptrA = gesA) != NULL)
789 for (i = 0; i < clen; i++)
791 sprintf(key, "env%d", i);
792 res = getChildString("EnvironmentA", key);
793 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
797 ok(found, "Parent-env string %s isn't in child process", ptrA);
799 ptrA += strlen(ptrA) + 1;
803 /* and each child env in parent */
804 for (i = 0; i < clen; i++)
806 sprintf(key, "env%d", i);
807 res = getChildString("EnvironmentA", key);
808 if ((ptrA = gesA) != NULL)
812 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
814 ptrA += strlen(ptrA) + 1;
816 if (!*ptrA) ptrA = NULL;
819 if (!is_str_env_drive_dir(res))
821 found = ptrA != NULL;
822 ok(found, "Child-env string %s isn't in parent process", res);
824 /* else => should also test we get the right per drive default directory here... */
828 static void test_Environment(void)
830 char buffer[MAX_PATH];
831 PROCESS_INFORMATION info;
832 STARTUPINFOA startup;
833 char child_env[4096];
837 memset(&startup, 0, sizeof(startup));
838 startup.cb = sizeof(startup);
839 startup.dwFlags = STARTF_USESHOWWINDOW;
840 startup.wShowWindow = SW_SHOWNORMAL;
843 get_file_name(resfile);
844 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
845 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
846 /* wait for child to terminate */
847 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
848 /* child process has changed result file, so let profile functions know about it */
849 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
851 cmpEnvironment(GetEnvironmentStringsA());
853 assert(DeleteFileA(resfile) != 0);
855 memset(&startup, 0, sizeof(startup));
856 startup.cb = sizeof(startup);
857 startup.dwFlags = STARTF_USESHOWWINDOW;
858 startup.wShowWindow = SW_SHOWNORMAL;
861 get_file_name(resfile);
862 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
864 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
865 ptr += strlen(ptr) + 1;
866 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
867 ptr += strlen(ptr) + 1;
868 strcpy(ptr, "FOO=BAR");
869 ptr += strlen(ptr) + 1;
870 strcpy(ptr, "BAR=FOOBAR");
871 ptr += strlen(ptr) + 1;
872 /* copy all existing variables except:
874 * - PATH (already set above)
875 * - the directory definitions (=[A-Z]:=)
877 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
879 if (strncmp(env, "PATH=", 5) != 0 &&
880 strncmp(env, "WINELOADER=", 11) != 0 &&
881 !is_str_env_drive_dir(env))
884 ptr += strlen(ptr) + 1;
888 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess");
889 /* wait for child to terminate */
890 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
891 /* child process has changed result file, so let profile functions know about it */
892 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
894 cmpEnvironment(child_env);
897 assert(DeleteFileA(resfile) != 0);
900 static void test_SuspendFlag(void)
902 char buffer[MAX_PATH];
903 PROCESS_INFORMATION info;
904 STARTUPINFOA startup;
907 /* let's start simplistic */
908 memset(&startup, 0, sizeof(startup));
909 startup.cb = sizeof(startup);
910 startup.dwFlags = STARTF_USESHOWWINDOW;
911 startup.wShowWindow = SW_SHOWNORMAL;
913 get_file_name(resfile);
914 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
915 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess");
917 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running");
919 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running");
920 ok(ResumeThread(info.hThread) == 1, "Resuming thread");
922 /* wait for child to terminate */
923 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
924 /* child process has changed result file, so let profile functions know about it */
925 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
927 okChildInt("StartupInfoA", "cb", startup.cb);
928 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
929 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
930 okChildInt("StartupInfoA", "dwX", startup.dwX);
931 okChildInt("StartupInfoA", "dwY", startup.dwY);
932 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
933 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
934 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
935 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
936 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
937 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
938 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
940 assert(DeleteFileA(resfile) != 0);
943 static void test_DebuggingFlag(void)
945 char buffer[MAX_PATH];
946 PROCESS_INFORMATION info;
947 STARTUPINFOA startup;
951 /* let's start simplistic */
952 memset(&startup, 0, sizeof(startup));
953 startup.cb = sizeof(startup);
954 startup.dwFlags = STARTF_USESHOWWINDOW;
955 startup.wShowWindow = SW_SHOWNORMAL;
957 get_file_name(resfile);
958 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
959 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess");
961 /* get all startup events up to the entry point break exception */
964 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event");
965 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
966 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
967 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
969 ok(dbg, "I have seen a debug event");
970 /* wait for child to terminate */
971 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
972 /* child process has changed result file, so let profile functions know about it */
973 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
975 okChildInt("StartupInfoA", "cb", startup.cb);
976 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
977 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
978 okChildInt("StartupInfoA", "dwX", startup.dwX);
979 okChildInt("StartupInfoA", "dwY", startup.dwY);
980 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
981 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
982 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
983 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
984 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
985 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
986 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
988 assert(DeleteFileA(resfile) != 0);
991 static void test_Console(void)
993 char buffer[MAX_PATH];
994 PROCESS_INFORMATION info;
995 STARTUPINFOA startup;
996 SECURITY_ATTRIBUTES sa;
997 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
998 DWORD modeIn, modeOut, modeInC, modeOutC;
999 DWORD cpIn, cpOut, cpInC, cpOutC;
1001 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1002 const char* msg = "This is a std-handle inheritance test.";
1005 memset(&startup, 0, sizeof(startup));
1006 startup.cb = sizeof(startup);
1007 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1008 startup.wShowWindow = SW_SHOWNORMAL;
1010 sa.nLength = sizeof(sa);
1011 sa.lpSecurityDescriptor = NULL;
1012 sa.bInheritHandle = TRUE;
1014 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1015 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1017 /* first, we need to be sure we're attached to a console */
1018 if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE)
1020 /* we're not attached to a console, let's do it */
1022 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1023 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1025 /* now verify everything's ok */
1026 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn");
1027 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut");
1028 startup.hStdError = startup.hStdOutput;
1030 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info");
1031 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1032 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes");
1033 cpIn = GetConsoleCP();
1034 cpOut = GetConsoleOutputCP();
1036 get_file_name(resfile);
1037 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1038 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess");
1040 /* wait for child to terminate */
1041 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
1042 /* child process has changed result file, so let profile functions know about it */
1043 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1045 /* now get the modification the child has made, and resets parents expected values */
1046 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info");
1047 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1048 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes");
1050 SetConsoleMode(startup.hStdInput, modeIn);
1051 SetConsoleMode(startup.hStdOutput, modeOut);
1053 cpInC = GetConsoleCP();
1054 cpOutC = GetConsoleOutputCP();
1056 SetConsoleOutputCP(cpOut);
1058 okChildInt("StartupInfoA", "cb", startup.cb);
1059 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
1060 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1061 okChildInt("StartupInfoA", "dwX", startup.dwX);
1062 okChildInt("StartupInfoA", "dwY", startup.dwY);
1063 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1064 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1065 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1066 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1067 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1068 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1069 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1071 /* check child correctly inherited the console */
1072 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1073 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1074 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1075 okChildInt("Console", "SizeX", sbi.dwSize.X);
1076 okChildInt("Console", "SizeY", sbi.dwSize.Y);
1077 okChildInt("Console", "CursorX", sbi.dwCursorPosition.X);
1078 okChildInt("Console", "CursorY", sbi.dwCursorPosition.Y);
1079 okChildInt("Console", "Attributes", sbi.wAttributes);
1080 okChildInt("Console", "winLeft", sbi.srWindow.Left);
1081 okChildInt("Console", "winTop", sbi.srWindow.Top);
1082 okChildInt("Console", "winRight", sbi.srWindow.Right);
1083 okChildInt("Console", "winBottom", sbi.srWindow.Bottom);
1084 okChildInt("Console", "maxWinWidth", sbi.dwMaximumWindowSize.X);
1085 okChildInt("Console", "maxWinHeight", sbi.dwMaximumWindowSize.Y);
1086 okChildInt("Console", "InputCP", cpIn);
1087 okChildInt("Console", "OutputCP", cpOut);
1088 okChildInt("Console", "InputMode", modeIn);
1089 okChildInt("Console", "OutputMode", modeOut);
1091 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)", cpInC, cpIn);
1092 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)", cpOutC, cpOut);
1093 ok(modeInC == (modeIn ^ 1), "Wrong console mode");
1094 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode");
1095 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position");
1096 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position");
1099 assert(DeleteFileA(resfile) != 0);
1101 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe");
1102 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1103 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1104 "Duplicating as inheritable child-output pipe");
1105 CloseHandle(hChildOut);
1107 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe");
1108 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1109 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1110 "Duplicating as inheritable child-input pipe");
1111 CloseHandle(hChildIn);
1113 memset(&startup, 0, sizeof(startup));
1114 startup.cb = sizeof(startup);
1115 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1116 startup.wShowWindow = SW_SHOWNORMAL;
1117 startup.hStdInput = hChildInInh;
1118 startup.hStdOutput = hChildOutInh;
1119 startup.hStdError = hChildOutInh;
1121 get_file_name(resfile);
1122 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1123 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess");
1124 ok(CloseHandle(hChildInInh), "Closing handle");
1125 ok(CloseHandle(hChildOutInh), "Closing handle");
1127 msg_len = strlen(msg) + 1;
1128 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writting to child");
1129 ok(w == msg_len, "Should have written %u bytes, actually wrote %lu", msg_len, w);
1130 memset(buffer, 0, sizeof(buffer));
1131 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child");
1132 ok(strcmp(buffer, msg) == 0, "Should have received '%s'", msg);
1134 /* wait for child to terminate */
1135 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
1136 /* child process has changed result file, so let profile functions know about it */
1137 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1139 okChildString("StdHandle", "msg", msg);
1142 assert(DeleteFileA(resfile) != 0);
1145 static void test_ExitCode(void)
1147 char buffer[MAX_PATH];
1148 PROCESS_INFORMATION info;
1149 STARTUPINFOA startup;
1152 /* let's start simplistic */
1153 memset(&startup, 0, sizeof(startup));
1154 startup.cb = sizeof(startup);
1155 startup.dwFlags = STARTF_USESHOWWINDOW;
1156 startup.wShowWindow = SW_SHOWNORMAL;
1158 get_file_name(resfile);
1159 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1160 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess");
1162 /* wait for child to terminate */
1163 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
1164 /* child process has changed result file, so let profile functions know about it */
1165 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1167 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code");
1168 okChildInt("ExitCode", "value", code);
1171 assert(DeleteFileA(resfile) != 0);
1177 ok(b, "Basic init of CreateProcess test");
1182 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1190 test_DebuggingFlag();
1193 /* things that can be tested:
1194 * lookup: check the way program to be executed is searched
1195 * handles: check the handle inheritance stuff (+sec options)
1196 * console: check if console creation parameters work