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
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;
433 /* let's start simplistic */
434 memset(&startup, 0, sizeof(startup));
435 startup.cb = sizeof(startup);
436 startup.dwFlags = STARTF_USESHOWWINDOW;
437 startup.wShowWindow = SW_SHOWNORMAL;
439 get_file_name(resfile);
440 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
441 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
442 /* wait for child to terminate */
443 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
444 /* child process has changed result file, so let profile functions know about it */
445 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
447 GetStartupInfoA(&si);
448 okChildInt("StartupInfoA", "cb", startup.cb);
449 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
450 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
451 okChildInt("StartupInfoA", "dwX", startup.dwX);
452 okChildInt("StartupInfoA", "dwY", startup.dwY);
453 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
454 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
455 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
456 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
457 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
458 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
459 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
461 assert(DeleteFileA(resfile) != 0);
463 /* not so simplistic now */
464 memset(&startup, 0, sizeof(startup));
465 startup.cb = sizeof(startup);
466 startup.dwFlags = STARTF_USESHOWWINDOW;
467 startup.wShowWindow = SW_SHOWNORMAL;
468 startup.lpTitle = "I'm the title string";
469 startup.lpDesktop = "I'm the desktop string";
470 startup.dwXCountChars = 0x12121212;
471 startup.dwYCountChars = 0x23232323;
472 startup.dwX = 0x34343434;
473 startup.dwY = 0x45454545;
474 startup.dwXSize = 0x56565656;
475 startup.dwYSize = 0x67676767;
476 startup.dwFillAttribute = 0xA55A;
478 get_file_name(resfile);
479 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
480 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
481 /* wait for child to terminate */
482 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
483 /* child process has changed result file, so let profile functions know about it */
484 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
486 okChildInt("StartupInfoA", "cb", startup.cb);
487 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
488 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
489 okChildInt("StartupInfoA", "dwX", startup.dwX);
490 okChildInt("StartupInfoA", "dwY", startup.dwY);
491 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
492 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
493 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
494 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
495 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
496 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
497 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
499 assert(DeleteFileA(resfile) != 0);
501 /* not so simplistic now */
502 memset(&startup, 0, sizeof(startup));
503 startup.cb = sizeof(startup);
504 startup.dwFlags = STARTF_USESHOWWINDOW;
505 startup.wShowWindow = SW_SHOWNORMAL;
506 startup.lpTitle = "I'm the title string";
507 startup.lpDesktop = NULL;
508 startup.dwXCountChars = 0x12121212;
509 startup.dwYCountChars = 0x23232323;
510 startup.dwX = 0x34343434;
511 startup.dwY = 0x45454545;
512 startup.dwXSize = 0x56565656;
513 startup.dwYSize = 0x67676767;
514 startup.dwFillAttribute = 0xA55A;
516 get_file_name(resfile);
517 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
518 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
519 /* wait for child to terminate */
520 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
521 /* child process has changed result file, so let profile functions know about it */
522 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
524 okChildInt("StartupInfoA", "cb", startup.cb);
525 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
526 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
527 okChildInt("StartupInfoA", "dwX", startup.dwX);
528 okChildInt("StartupInfoA", "dwY", startup.dwY);
529 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
530 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
531 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
532 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
533 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
534 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
535 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
537 assert(DeleteFileA(resfile) != 0);
539 /* not so simplistic now */
540 memset(&startup, 0, sizeof(startup));
541 startup.cb = sizeof(startup);
542 startup.dwFlags = STARTF_USESHOWWINDOW;
543 startup.wShowWindow = SW_SHOWNORMAL;
544 startup.lpTitle = "I'm the title string";
545 startup.lpDesktop = "";
546 startup.dwXCountChars = 0x12121212;
547 startup.dwYCountChars = 0x23232323;
548 startup.dwX = 0x34343434;
549 startup.dwY = 0x45454545;
550 startup.dwXSize = 0x56565656;
551 startup.dwYSize = 0x67676767;
552 startup.dwFillAttribute = 0xA55A;
554 get_file_name(resfile);
555 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
556 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
557 /* wait for child to terminate */
558 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
559 /* child process has changed result file, so let profile functions know about it */
560 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
562 okChildInt("StartupInfoA", "cb", startup.cb);
563 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
564 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
565 okChildInt("StartupInfoA", "dwX", startup.dwX);
566 okChildInt("StartupInfoA", "dwY", startup.dwY);
567 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
568 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
569 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
570 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
571 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
572 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
573 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
575 assert(DeleteFileA(resfile) != 0);
577 /* not so simplistic now */
578 memset(&startup, 0, sizeof(startup));
579 startup.cb = sizeof(startup);
580 startup.dwFlags = STARTF_USESHOWWINDOW;
581 startup.wShowWindow = SW_SHOWNORMAL;
582 startup.lpTitle = NULL;
583 startup.lpDesktop = "I'm the desktop string";
584 startup.dwXCountChars = 0x12121212;
585 startup.dwYCountChars = 0x23232323;
586 startup.dwX = 0x34343434;
587 startup.dwY = 0x45454545;
588 startup.dwXSize = 0x56565656;
589 startup.dwYSize = 0x67676767;
590 startup.dwFillAttribute = 0xA55A;
592 get_file_name(resfile);
593 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
594 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
595 /* wait for child to terminate */
596 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
597 /* child process has changed result file, so let profile functions know about it */
598 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
600 okChildInt("StartupInfoA", "cb", startup.cb);
601 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
602 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
603 okChildInt("StartupInfoA", "dwX", startup.dwX);
604 okChildInt("StartupInfoA", "dwY", startup.dwY);
605 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
606 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
607 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
608 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
609 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
610 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
611 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
613 assert(DeleteFileA(resfile) != 0);
615 /* not so simplistic now */
616 memset(&startup, 0, sizeof(startup));
617 startup.cb = sizeof(startup);
618 startup.dwFlags = STARTF_USESHOWWINDOW;
619 startup.wShowWindow = SW_SHOWNORMAL;
620 startup.lpTitle = "";
621 startup.lpDesktop = "I'm the desktop string";
622 startup.dwXCountChars = 0x12121212;
623 startup.dwYCountChars = 0x23232323;
624 startup.dwX = 0x34343434;
625 startup.dwY = 0x45454545;
626 startup.dwXSize = 0x56565656;
627 startup.dwYSize = 0x67676767;
628 startup.dwFillAttribute = 0xA55A;
630 get_file_name(resfile);
631 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
632 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
633 /* wait for child to terminate */
634 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
635 /* child process has changed result file, so let profile functions know about it */
636 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
638 okChildInt("StartupInfoA", "cb", startup.cb);
639 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
640 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
641 okChildInt("StartupInfoA", "dwX", startup.dwX);
642 okChildInt("StartupInfoA", "dwY", startup.dwY);
643 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
644 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
645 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
646 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
647 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
648 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
649 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
651 assert(DeleteFileA(resfile) != 0);
653 /* not so simplistic now */
654 memset(&startup, 0, sizeof(startup));
655 startup.cb = sizeof(startup);
656 startup.dwFlags = STARTF_USESHOWWINDOW;
657 startup.wShowWindow = SW_SHOWNORMAL;
658 startup.lpTitle = "";
659 startup.lpDesktop = "";
660 startup.dwXCountChars = 0x12121212;
661 startup.dwYCountChars = 0x23232323;
662 startup.dwX = 0x34343434;
663 startup.dwY = 0x45454545;
664 startup.dwXSize = 0x56565656;
665 startup.dwYSize = 0x67676767;
666 startup.dwFillAttribute = 0xA55A;
668 get_file_name(resfile);
669 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
670 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
671 /* wait for child to terminate */
672 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
673 /* child process has changed result file, so let profile functions know about it */
674 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
676 okChildInt("StartupInfoA", "cb", startup.cb);
677 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
678 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
679 okChildInt("StartupInfoA", "dwX", startup.dwX);
680 okChildInt("StartupInfoA", "dwY", startup.dwY);
681 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
682 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
683 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
684 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
685 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
686 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
687 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
689 assert(DeleteFileA(resfile) != 0);
691 /* TODO: test for A/W and W/A and W/W */
694 static void test_CommandLine(void)
696 char buffer[MAX_PATH];
697 PROCESS_INFORMATION info;
698 STARTUPINFOA startup;
700 memset(&startup, 0, sizeof(startup));
701 startup.cb = sizeof(startup);
702 startup.dwFlags = STARTF_USESHOWWINDOW;
703 startup.wShowWindow = SW_SHOWNORMAL;
706 get_file_name(resfile);
707 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
708 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
709 /* wait for child to terminate */
710 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
711 /* child process has changed result file, so let profile functions know about it */
712 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
714 okChildInt("Arguments", "argcA", 4);
715 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
716 okChildString("Arguments", "argvA4", NULL);
717 okChildString("Arguments", "CommandLineA", buffer);
719 assert(DeleteFileA(resfile) != 0);
721 memset(&startup, 0, sizeof(startup));
722 startup.cb = sizeof(startup);
723 startup.dwFlags = STARTF_USESHOWWINDOW;
724 startup.wShowWindow = SW_SHOWNORMAL;
727 get_file_name(resfile);
728 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
729 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
730 /* wait for child to terminate */
731 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
732 /* child process has changed result file, so let profile functions know about it */
733 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
735 okChildInt("Arguments", "argcA", 6);
736 okChildString("Arguments", "argvA3", "a\"b\\");
737 okChildString("Arguments", "argvA4", "c\"");
738 okChildString("Arguments", "argvA5", "d");
739 okChildString("Arguments", "argvA6", NULL);
740 okChildString("Arguments", "CommandLineA", buffer);
742 assert(DeleteFileA(resfile) != 0);
745 static void test_Directory(void)
747 char buffer[MAX_PATH];
748 PROCESS_INFORMATION info;
749 STARTUPINFOA startup;
750 char windir[MAX_PATH];
752 memset(&startup, 0, sizeof(startup));
753 startup.cb = sizeof(startup);
754 startup.dwFlags = STARTF_USESHOWWINDOW;
755 startup.wShowWindow = SW_SHOWNORMAL;
758 get_file_name(resfile);
759 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
760 GetWindowsDirectoryA( windir, sizeof(windir) );
761 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
762 /* wait for child to terminate */
763 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
764 /* child process has changed result file, so let profile functions know about it */
765 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
767 okChildIString("Misc", "CurrDirA", windir);
769 assert(DeleteFileA(resfile) != 0);
772 static BOOL is_str_env_drive_dir(const char* str)
774 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
775 str[3] == '=' && str[4] == str[1];
778 /* compared expected child's environment (in gesA) from actual
779 * environment our child got
781 static void cmpEnvironment(const char* gesA)
789 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
791 /* now look each parent env in child */
792 if ((ptrA = gesA) != NULL)
796 for (i = 0; i < clen; i++)
798 sprintf(key, "env%d", i);
799 res = getChildString("EnvironmentA", key);
800 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
804 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
806 ptrA += strlen(ptrA) + 1;
810 /* and each child env in parent */
811 for (i = 0; i < clen; i++)
813 sprintf(key, "env%d", i);
814 res = getChildString("EnvironmentA", key);
815 if ((ptrA = gesA) != NULL)
819 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
821 ptrA += strlen(ptrA) + 1;
823 if (!*ptrA) ptrA = NULL;
826 if (!is_str_env_drive_dir(res))
828 found = ptrA != NULL;
829 ok(found, "Child-env string %s isn't in parent process\n", res);
831 /* else => should also test we get the right per drive default directory here... */
835 static void test_Environment(void)
837 char buffer[MAX_PATH];
838 PROCESS_INFORMATION info;
839 STARTUPINFOA startup;
846 memset(&startup, 0, sizeof(startup));
847 startup.cb = sizeof(startup);
848 startup.dwFlags = STARTF_USESHOWWINDOW;
849 startup.wShowWindow = SW_SHOWNORMAL;
852 get_file_name(resfile);
853 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
854 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
855 /* wait for child to terminate */
856 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
857 /* child process has changed result file, so let profile functions know about it */
858 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
860 cmpEnvironment(GetEnvironmentStringsA());
862 assert(DeleteFileA(resfile) != 0);
864 memset(&startup, 0, sizeof(startup));
865 startup.cb = sizeof(startup);
866 startup.dwFlags = STARTF_USESHOWWINDOW;
867 startup.wShowWindow = SW_SHOWNORMAL;
870 get_file_name(resfile);
871 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
874 ptr = GetEnvironmentStringsA();
877 slen = strlen(ptr)+1;
878 child_env_len += slen;
881 /* Add space for additional environment variables */
882 child_env_len += 256;
883 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
886 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
887 ptr += strlen(ptr) + 1;
888 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
889 ptr += strlen(ptr) + 1;
890 strcpy(ptr, "FOO=BAR");
891 ptr += strlen(ptr) + 1;
892 strcpy(ptr, "BAR=FOOBAR");
893 ptr += strlen(ptr) + 1;
894 /* copy all existing variables except:
896 * - PATH (already set above)
897 * - the directory definitions (=[A-Z]:=)
899 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
901 if (strncmp(env, "PATH=", 5) != 0 &&
902 strncmp(env, "WINELOADER=", 11) != 0 &&
903 !is_str_env_drive_dir(env))
906 ptr += strlen(ptr) + 1;
910 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
911 /* wait for child to terminate */
912 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
913 /* child process has changed result file, so let profile functions know about it */
914 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
916 cmpEnvironment(child_env);
918 HeapFree(GetProcessHeap(), 0, child_env);
920 assert(DeleteFileA(resfile) != 0);
923 static void test_SuspendFlag(void)
925 char buffer[MAX_PATH];
926 PROCESS_INFORMATION info;
927 STARTUPINFOA startup, us;
930 /* let's start simplistic */
931 memset(&startup, 0, sizeof(startup));
932 startup.cb = sizeof(startup);
933 startup.dwFlags = STARTF_USESHOWWINDOW;
934 startup.wShowWindow = SW_SHOWNORMAL;
936 get_file_name(resfile);
937 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
938 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
940 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
942 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
943 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
945 /* wait for child to terminate */
946 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
947 /* child process has changed result file, so let profile functions know about it */
948 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
950 GetStartupInfoA(&us);
952 okChildInt("StartupInfoA", "cb", startup.cb);
953 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
954 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
955 okChildInt("StartupInfoA", "dwX", startup.dwX);
956 okChildInt("StartupInfoA", "dwY", startup.dwY);
957 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
958 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
959 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
960 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
961 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
962 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
963 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
965 assert(DeleteFileA(resfile) != 0);
968 static void test_DebuggingFlag(void)
970 char buffer[MAX_PATH];
971 PROCESS_INFORMATION info;
972 STARTUPINFOA startup, us;
976 /* let's start simplistic */
977 memset(&startup, 0, sizeof(startup));
978 startup.cb = sizeof(startup);
979 startup.dwFlags = STARTF_USESHOWWINDOW;
980 startup.wShowWindow = SW_SHOWNORMAL;
982 get_file_name(resfile);
983 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
984 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
986 /* get all startup events up to the entry point break exception */
989 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
990 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
991 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
992 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
994 ok(dbg, "I have seen a debug event\n");
995 /* wait for child to terminate */
996 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
997 /* child process has changed result file, so let profile functions know about it */
998 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1000 GetStartupInfoA(&us);
1002 okChildInt("StartupInfoA", "cb", startup.cb);
1003 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1004 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1005 okChildInt("StartupInfoA", "dwX", startup.dwX);
1006 okChildInt("StartupInfoA", "dwY", startup.dwY);
1007 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1008 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1009 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1010 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1011 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1012 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1013 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1015 assert(DeleteFileA(resfile) != 0);
1018 static BOOL is_console(HANDLE h)
1020 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1023 static void test_Console(void)
1025 char buffer[MAX_PATH];
1026 PROCESS_INFORMATION info;
1027 STARTUPINFOA startup, us;
1028 SECURITY_ATTRIBUTES sa;
1029 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1030 DWORD modeIn, modeOut, modeInC, modeOutC;
1031 DWORD cpIn, cpOut, cpInC, cpOutC;
1033 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1034 const char* msg = "This is a std-handle inheritance test.";
1037 memset(&startup, 0, sizeof(startup));
1038 startup.cb = sizeof(startup);
1039 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1040 startup.wShowWindow = SW_SHOWNORMAL;
1042 sa.nLength = sizeof(sa);
1043 sa.lpSecurityDescriptor = NULL;
1044 sa.bInheritHandle = TRUE;
1046 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1047 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1049 /* first, we need to be sure we're attached to a console */
1050 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1052 /* we're not attached to a console, let's do it */
1054 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1055 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1057 /* now verify everything's ok */
1058 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1059 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1060 startup.hStdError = startup.hStdOutput;
1062 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1063 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1064 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1065 cpIn = GetConsoleCP();
1066 cpOut = GetConsoleOutputCP();
1068 get_file_name(resfile);
1069 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1070 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1072 /* wait for child to terminate */
1073 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1074 /* child process has changed result file, so let profile functions know about it */
1075 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1077 /* now get the modification the child has made, and resets parents expected values */
1078 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1079 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1080 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1082 SetConsoleMode(startup.hStdInput, modeIn);
1083 SetConsoleMode(startup.hStdOutput, modeOut);
1085 cpInC = GetConsoleCP();
1086 cpOutC = GetConsoleOutputCP();
1088 SetConsoleOutputCP(cpOut);
1090 GetStartupInfoA(&us);
1092 okChildInt("StartupInfoA", "cb", startup.cb);
1093 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1094 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1095 okChildInt("StartupInfoA", "dwX", startup.dwX);
1096 okChildInt("StartupInfoA", "dwY", startup.dwY);
1097 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1098 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1099 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1100 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1101 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1102 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1103 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1105 /* check child correctly inherited the console */
1106 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1107 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1108 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1109 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1110 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1111 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1112 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1113 okChildInt("Console", "Attributes", sbi.wAttributes);
1114 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1115 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1116 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1117 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1118 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1119 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1120 okChildInt("Console", "InputCP", cpIn);
1121 okChildInt("Console", "OutputCP", cpOut);
1122 okChildInt("Console", "InputMode", modeIn);
1123 okChildInt("Console", "OutputMode", modeOut);
1125 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)\n", cpInC, cpIn);
1126 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)\n", cpOutC, cpOut);
1127 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1128 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1129 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1130 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1133 assert(DeleteFileA(resfile) != 0);
1135 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1136 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1137 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1138 "Duplicating as inheritable child-output pipe\n");
1139 CloseHandle(hChildOut);
1141 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1142 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1143 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1144 "Duplicating as inheritable child-input pipe\n");
1145 CloseHandle(hChildIn);
1147 memset(&startup, 0, sizeof(startup));
1148 startup.cb = sizeof(startup);
1149 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1150 startup.wShowWindow = SW_SHOWNORMAL;
1151 startup.hStdInput = hChildInInh;
1152 startup.hStdOutput = hChildOutInh;
1153 startup.hStdError = hChildOutInh;
1155 get_file_name(resfile);
1156 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1157 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1158 ok(CloseHandle(hChildInInh), "Closing handle\n");
1159 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1161 msg_len = strlen(msg) + 1;
1162 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1163 ok(w == msg_len, "Should have written %u bytes, actually wrote %lu\n", msg_len, w);
1164 memset(buffer, 0, sizeof(buffer));
1165 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1166 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1168 /* wait for child to terminate */
1169 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1170 /* child process has changed result file, so let profile functions know about it */
1171 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1173 okChildString("StdHandle", "msg", msg);
1176 assert(DeleteFileA(resfile) != 0);
1179 static void test_ExitCode(void)
1181 char buffer[MAX_PATH];
1182 PROCESS_INFORMATION info;
1183 STARTUPINFOA startup;
1186 /* let's start simplistic */
1187 memset(&startup, 0, sizeof(startup));
1188 startup.cb = sizeof(startup);
1189 startup.dwFlags = STARTF_USESHOWWINDOW;
1190 startup.wShowWindow = SW_SHOWNORMAL;
1192 get_file_name(resfile);
1193 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1194 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1196 /* wait for child to terminate */
1197 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1198 /* child process has changed result file, so let profile functions know about it */
1199 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1201 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1202 okChildInt("ExitCode", "value", code);
1205 assert(DeleteFileA(resfile) != 0);
1211 ok(b, "Basic init of CreateProcess test\n");
1216 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1224 test_DebuggingFlag();
1227 /* things that can be tested:
1228 * lookup: check the way program to be executed is searched
1229 * handles: check the handle inheritance stuff (+sec options)
1230 * console: check if console creation parameters work