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 strncpy(env_var, ptrA, MAX_LISTED_ENV_VAR - 1);
272 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
273 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
275 ptrA += strlen(ptrA) + 1;
277 childPrintf(hFile, "len=%d\n\n", i);
280 /* output of environment (Unicode) */
281 ptrW = GetEnvironmentStringsW();
284 WCHAR env_var[MAX_LISTED_ENV_VAR];
286 childPrintf(hFile, "[EnvironmentW]\n");
290 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
291 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
292 childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
294 ptrW += lstrlenW(ptrW) + 1;
296 childPrintf(hFile, "len=%d\n\n", i);
299 childPrintf(hFile, "[Misc]\n");
300 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
301 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
302 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
303 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
304 childPrintf(hFile, "\n");
306 if (option && strcmp(option, "console") == 0)
308 CONSOLE_SCREEN_BUFFER_INFO sbi;
309 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
310 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
311 DWORD modeIn, modeOut;
313 childPrintf(hFile, "[Console]\n");
314 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
316 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
317 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
318 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
319 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
320 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
321 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
323 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
324 GetConsoleCP(), GetConsoleOutputCP());
325 if (GetConsoleMode(hConIn, &modeIn))
326 childPrintf(hFile, "InputMode=%ld\n", modeIn);
327 if (GetConsoleMode(hConOut, &modeOut))
328 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
330 /* now that we have written all relevant information, let's change it */
331 ok(SetConsoleCP(1252), "Setting CP\n");
332 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
333 ret = SetConsoleMode(hConIn, modeIn ^ 1);
334 ok( ret, "Setting mode (%ld)\n", GetLastError());
335 ret = SetConsoleMode(hConOut, modeOut ^ 1);
336 ok( ret, "Setting mode (%ld)\n", GetLastError());
337 sbi.dwCursorPosition.X ^= 1;
338 sbi.dwCursorPosition.Y ^= 1;
339 ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
340 ok( ret, "Setting cursor position (%ld)\n", GetLastError());
342 if (option && strcmp(option, "stdhandle") == 0)
344 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
345 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
347 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
352 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
353 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
354 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
358 if (option && strcmp(option, "exit_code") == 0)
360 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
368 static char* getChildString(const char* sect, const char* key)
370 char buf[1024+4*MAX_LISTED_ENV_VAR];
373 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
374 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
375 assert(!(strlen(buf) & 1));
380 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
381 * others... (windows uses stricmp while Un*x uses strcasecmp...)
383 static int wtstrcasecmp(const char* p1, const char* p2)
388 while (c1 == c2 && c1)
390 c1 = *p1++; c2 = *p2++;
393 c1 = toupper(c1); c2 = toupper(c2);
399 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
401 if (!s1 && !s2) return 0;
404 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
407 #define okChildString(sect, key, expect) \
409 char* result = getChildString((sect), (key)); \
410 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
413 #define okChildIString(sect, key, expect) \
415 char* result = getChildString(sect, key); \
416 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
419 /* using !expect insures that the test will fail if the sect/key isn't present
422 #define okChildInt(sect, key, expect) \
424 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
425 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
428 static void test_Startup(void)
430 char buffer[MAX_PATH];
431 PROCESS_INFORMATION info;
432 STARTUPINFOA startup,si;
434 /* let's start simplistic */
435 memset(&startup, 0, sizeof(startup));
436 startup.cb = sizeof(startup);
437 startup.dwFlags = STARTF_USESHOWWINDOW;
438 startup.wShowWindow = SW_SHOWNORMAL;
440 get_file_name(resfile);
441 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
442 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
443 /* wait for child to terminate */
444 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
445 /* child process has changed result file, so let profile functions know about it */
446 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
448 GetStartupInfoA(&si);
449 okChildInt("StartupInfoA", "cb", startup.cb);
450 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
451 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
452 okChildInt("StartupInfoA", "dwX", startup.dwX);
453 okChildInt("StartupInfoA", "dwY", startup.dwY);
454 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
455 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
456 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
457 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
458 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
459 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
460 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
462 assert(DeleteFileA(resfile) != 0);
464 /* not so simplistic now */
465 memset(&startup, 0, sizeof(startup));
466 startup.cb = sizeof(startup);
467 startup.dwFlags = STARTF_USESHOWWINDOW;
468 startup.wShowWindow = SW_SHOWNORMAL;
469 startup.lpTitle = "I'm the title string";
470 startup.lpDesktop = "I'm the desktop string";
471 startup.dwXCountChars = 0x12121212;
472 startup.dwYCountChars = 0x23232323;
473 startup.dwX = 0x34343434;
474 startup.dwY = 0x45454545;
475 startup.dwXSize = 0x56565656;
476 startup.dwYSize = 0x67676767;
477 startup.dwFillAttribute = 0xA55A;
479 get_file_name(resfile);
480 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
481 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
482 /* wait for child to terminate */
483 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
484 /* child process has changed result file, so let profile functions know about it */
485 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
487 okChildInt("StartupInfoA", "cb", startup.cb);
488 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
489 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
490 okChildInt("StartupInfoA", "dwX", startup.dwX);
491 okChildInt("StartupInfoA", "dwY", startup.dwY);
492 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
493 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
494 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
495 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
496 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
497 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
498 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
500 assert(DeleteFileA(resfile) != 0);
502 /* not so simplistic now */
503 memset(&startup, 0, sizeof(startup));
504 startup.cb = sizeof(startup);
505 startup.dwFlags = STARTF_USESHOWWINDOW;
506 startup.wShowWindow = SW_SHOWNORMAL;
507 startup.lpTitle = "I'm the title string";
508 startup.lpDesktop = NULL;
509 startup.dwXCountChars = 0x12121212;
510 startup.dwYCountChars = 0x23232323;
511 startup.dwX = 0x34343434;
512 startup.dwY = 0x45454545;
513 startup.dwXSize = 0x56565656;
514 startup.dwYSize = 0x67676767;
515 startup.dwFillAttribute = 0xA55A;
517 get_file_name(resfile);
518 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
519 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
520 /* wait for child to terminate */
521 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
522 /* child process has changed result file, so let profile functions know about it */
523 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
525 okChildInt("StartupInfoA", "cb", startup.cb);
526 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
527 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
528 okChildInt("StartupInfoA", "dwX", startup.dwX);
529 okChildInt("StartupInfoA", "dwY", startup.dwY);
530 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
531 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
532 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
533 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
534 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
535 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
536 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
538 assert(DeleteFileA(resfile) != 0);
540 /* not so simplistic now */
541 memset(&startup, 0, sizeof(startup));
542 startup.cb = sizeof(startup);
543 startup.dwFlags = STARTF_USESHOWWINDOW;
544 startup.wShowWindow = SW_SHOWNORMAL;
545 startup.lpTitle = "I'm the title string";
546 startup.lpDesktop = "";
547 startup.dwXCountChars = 0x12121212;
548 startup.dwYCountChars = 0x23232323;
549 startup.dwX = 0x34343434;
550 startup.dwY = 0x45454545;
551 startup.dwXSize = 0x56565656;
552 startup.dwYSize = 0x67676767;
553 startup.dwFillAttribute = 0xA55A;
555 get_file_name(resfile);
556 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
557 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
558 /* wait for child to terminate */
559 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
560 /* child process has changed result file, so let profile functions know about it */
561 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
563 okChildInt("StartupInfoA", "cb", startup.cb);
564 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
565 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
566 okChildInt("StartupInfoA", "dwX", startup.dwX);
567 okChildInt("StartupInfoA", "dwY", startup.dwY);
568 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
569 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
570 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
571 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
572 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
573 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
574 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
576 assert(DeleteFileA(resfile) != 0);
578 /* not so simplistic now */
579 memset(&startup, 0, sizeof(startup));
580 startup.cb = sizeof(startup);
581 startup.dwFlags = STARTF_USESHOWWINDOW;
582 startup.wShowWindow = SW_SHOWNORMAL;
583 startup.lpTitle = NULL;
584 startup.lpDesktop = "I'm the desktop string";
585 startup.dwXCountChars = 0x12121212;
586 startup.dwYCountChars = 0x23232323;
587 startup.dwX = 0x34343434;
588 startup.dwY = 0x45454545;
589 startup.dwXSize = 0x56565656;
590 startup.dwYSize = 0x67676767;
591 startup.dwFillAttribute = 0xA55A;
593 get_file_name(resfile);
594 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
595 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
596 /* wait for child to terminate */
597 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
598 /* child process has changed result file, so let profile functions know about it */
599 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
601 okChildInt("StartupInfoA", "cb", startup.cb);
602 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
603 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
604 okChildInt("StartupInfoA", "dwX", startup.dwX);
605 okChildInt("StartupInfoA", "dwY", startup.dwY);
606 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
607 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
608 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
609 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
610 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
611 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
612 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
614 assert(DeleteFileA(resfile) != 0);
616 /* not so simplistic now */
617 memset(&startup, 0, sizeof(startup));
618 startup.cb = sizeof(startup);
619 startup.dwFlags = STARTF_USESHOWWINDOW;
620 startup.wShowWindow = SW_SHOWNORMAL;
621 startup.lpTitle = "";
622 startup.lpDesktop = "I'm the desktop string";
623 startup.dwXCountChars = 0x12121212;
624 startup.dwYCountChars = 0x23232323;
625 startup.dwX = 0x34343434;
626 startup.dwY = 0x45454545;
627 startup.dwXSize = 0x56565656;
628 startup.dwYSize = 0x67676767;
629 startup.dwFillAttribute = 0xA55A;
631 get_file_name(resfile);
632 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
633 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
634 /* wait for child to terminate */
635 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
636 /* child process has changed result file, so let profile functions know about it */
637 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
639 okChildInt("StartupInfoA", "cb", startup.cb);
640 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
641 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
642 okChildInt("StartupInfoA", "dwX", startup.dwX);
643 okChildInt("StartupInfoA", "dwY", startup.dwY);
644 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
645 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
646 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
647 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
648 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
649 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
650 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
652 assert(DeleteFileA(resfile) != 0);
654 /* not so simplistic now */
655 memset(&startup, 0, sizeof(startup));
656 startup.cb = sizeof(startup);
657 startup.dwFlags = STARTF_USESHOWWINDOW;
658 startup.wShowWindow = SW_SHOWNORMAL;
659 startup.lpTitle = "";
660 startup.lpDesktop = "";
661 startup.dwXCountChars = 0x12121212;
662 startup.dwYCountChars = 0x23232323;
663 startup.dwX = 0x34343434;
664 startup.dwY = 0x45454545;
665 startup.dwXSize = 0x56565656;
666 startup.dwYSize = 0x67676767;
667 startup.dwFillAttribute = 0xA55A;
669 get_file_name(resfile);
670 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
671 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
672 /* wait for child to terminate */
673 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
674 /* child process has changed result file, so let profile functions know about it */
675 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
677 okChildInt("StartupInfoA", "cb", startup.cb);
678 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
679 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
680 okChildInt("StartupInfoA", "dwX", startup.dwX);
681 okChildInt("StartupInfoA", "dwY", startup.dwY);
682 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
683 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
684 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
685 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
686 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
687 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
688 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
690 assert(DeleteFileA(resfile) != 0);
692 /* TODO: test for A/W and W/A and W/W */
695 static void test_CommandLine(void)
697 char buffer[MAX_PATH];
698 PROCESS_INFORMATION info;
699 STARTUPINFOA startup;
701 memset(&startup, 0, sizeof(startup));
702 startup.cb = sizeof(startup);
703 startup.dwFlags = STARTF_USESHOWWINDOW;
704 startup.wShowWindow = SW_SHOWNORMAL;
707 get_file_name(resfile);
708 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
709 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
710 /* wait for child to terminate */
711 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
712 /* child process has changed result file, so let profile functions know about it */
713 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
715 okChildInt("Arguments", "argcA", 4);
716 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
717 okChildString("Arguments", "argvA4", NULL);
718 okChildString("Arguments", "CommandLineA", buffer);
720 assert(DeleteFileA(resfile) != 0);
722 memset(&startup, 0, sizeof(startup));
723 startup.cb = sizeof(startup);
724 startup.dwFlags = STARTF_USESHOWWINDOW;
725 startup.wShowWindow = SW_SHOWNORMAL;
728 get_file_name(resfile);
729 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
730 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
731 /* wait for child to terminate */
732 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
733 /* child process has changed result file, so let profile functions know about it */
734 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
736 okChildInt("Arguments", "argcA", 6);
737 okChildString("Arguments", "argvA3", "a\"b\\");
738 okChildString("Arguments", "argvA4", "c\"");
739 okChildString("Arguments", "argvA5", "d");
740 okChildString("Arguments", "argvA6", NULL);
741 okChildString("Arguments", "CommandLineA", buffer);
743 assert(DeleteFileA(resfile) != 0);
746 static void test_Directory(void)
748 char buffer[MAX_PATH];
749 PROCESS_INFORMATION info;
750 STARTUPINFOA startup;
751 char windir[MAX_PATH];
753 memset(&startup, 0, sizeof(startup));
754 startup.cb = sizeof(startup);
755 startup.dwFlags = STARTF_USESHOWWINDOW;
756 startup.wShowWindow = SW_SHOWNORMAL;
759 get_file_name(resfile);
760 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
761 GetWindowsDirectoryA( windir, sizeof(windir) );
762 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
763 /* wait for child to terminate */
764 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
765 /* child process has changed result file, so let profile functions know about it */
766 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
768 okChildIString("Misc", "CurrDirA", windir);
770 assert(DeleteFileA(resfile) != 0);
773 static BOOL is_str_env_drive_dir(const char* str)
775 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
776 str[3] == '=' && str[4] == str[1];
779 /* compared expected child's environment (in gesA) from actual
780 * environment our child got
782 static void cmpEnvironment(const char* gesA)
790 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
792 /* now look each parent env in child */
793 if ((ptrA = gesA) != NULL)
797 for (i = 0; i < clen; i++)
799 sprintf(key, "env%d", i);
800 res = getChildString("EnvironmentA", key);
801 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
805 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
807 ptrA += strlen(ptrA) + 1;
811 /* and each child env in parent */
812 for (i = 0; i < clen; i++)
814 sprintf(key, "env%d", i);
815 res = getChildString("EnvironmentA", key);
816 if ((ptrA = gesA) != NULL)
820 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
822 ptrA += strlen(ptrA) + 1;
824 if (!*ptrA) ptrA = NULL;
827 if (!is_str_env_drive_dir(res))
829 found = ptrA != NULL;
830 ok(found, "Child-env string %s isn't in parent process\n", res);
832 /* else => should also test we get the right per drive default directory here... */
836 static void test_Environment(void)
838 char buffer[MAX_PATH];
839 PROCESS_INFORMATION info;
840 STARTUPINFOA startup;
847 memset(&startup, 0, sizeof(startup));
848 startup.cb = sizeof(startup);
849 startup.dwFlags = STARTF_USESHOWWINDOW;
850 startup.wShowWindow = SW_SHOWNORMAL;
853 get_file_name(resfile);
854 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
855 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
856 /* wait for child to terminate */
857 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
858 /* child process has changed result file, so let profile functions know about it */
859 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
861 cmpEnvironment(GetEnvironmentStringsA());
863 assert(DeleteFileA(resfile) != 0);
865 memset(&startup, 0, sizeof(startup));
866 startup.cb = sizeof(startup);
867 startup.dwFlags = STARTF_USESHOWWINDOW;
868 startup.wShowWindow = SW_SHOWNORMAL;
871 get_file_name(resfile);
872 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
875 ptr = GetEnvironmentStringsA();
878 slen = strlen(ptr)+1;
879 child_env_len += slen;
882 /* Add space for additional environment variables */
883 child_env_len += 256;
884 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
887 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
888 ptr += strlen(ptr) + 1;
889 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
890 ptr += strlen(ptr) + 1;
891 strcpy(ptr, "FOO=BAR");
892 ptr += strlen(ptr) + 1;
893 strcpy(ptr, "BAR=FOOBAR");
894 ptr += strlen(ptr) + 1;
895 /* copy all existing variables except:
897 * - PATH (already set above)
898 * - the directory definitions (=[A-Z]:=)
900 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
902 if (strncmp(env, "PATH=", 5) != 0 &&
903 strncmp(env, "WINELOADER=", 11) != 0 &&
904 !is_str_env_drive_dir(env))
907 ptr += strlen(ptr) + 1;
911 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
912 /* wait for child to terminate */
913 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
914 /* child process has changed result file, so let profile functions know about it */
915 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
917 cmpEnvironment(child_env);
919 HeapFree(GetProcessHeap(), 0, child_env);
921 assert(DeleteFileA(resfile) != 0);
924 static void test_SuspendFlag(void)
926 char buffer[MAX_PATH];
927 PROCESS_INFORMATION info;
928 STARTUPINFOA startup, us;
931 /* let's start simplistic */
932 memset(&startup, 0, sizeof(startup));
933 startup.cb = sizeof(startup);
934 startup.dwFlags = STARTF_USESHOWWINDOW;
935 startup.wShowWindow = SW_SHOWNORMAL;
937 get_file_name(resfile);
938 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
939 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
941 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
943 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
944 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
946 /* wait for child to terminate */
947 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
948 /* child process has changed result file, so let profile functions know about it */
949 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
951 GetStartupInfoA(&us);
953 okChildInt("StartupInfoA", "cb", startup.cb);
954 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
955 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
956 okChildInt("StartupInfoA", "dwX", startup.dwX);
957 okChildInt("StartupInfoA", "dwY", startup.dwY);
958 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
959 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
960 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
961 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
962 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
963 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
964 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
966 assert(DeleteFileA(resfile) != 0);
969 static void test_DebuggingFlag(void)
971 char buffer[MAX_PATH];
972 PROCESS_INFORMATION info;
973 STARTUPINFOA startup, us;
977 /* let's start simplistic */
978 memset(&startup, 0, sizeof(startup));
979 startup.cb = sizeof(startup);
980 startup.dwFlags = STARTF_USESHOWWINDOW;
981 startup.wShowWindow = SW_SHOWNORMAL;
983 get_file_name(resfile);
984 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
985 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
987 /* get all startup events up to the entry point break exception */
990 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
991 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
992 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
993 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
995 ok(dbg, "I have seen a debug event\n");
996 /* wait for child to terminate */
997 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
998 /* child process has changed result file, so let profile functions know about it */
999 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1001 GetStartupInfoA(&us);
1003 okChildInt("StartupInfoA", "cb", startup.cb);
1004 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1005 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1006 okChildInt("StartupInfoA", "dwX", startup.dwX);
1007 okChildInt("StartupInfoA", "dwY", startup.dwY);
1008 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1009 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1010 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1011 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1012 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1013 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1014 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1016 assert(DeleteFileA(resfile) != 0);
1019 static void test_Console(void)
1021 char buffer[MAX_PATH];
1022 PROCESS_INFORMATION info;
1023 STARTUPINFOA startup, us;
1024 SECURITY_ATTRIBUTES sa;
1025 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1026 DWORD modeIn, modeOut, modeInC, modeOutC;
1027 DWORD cpIn, cpOut, cpInC, cpOutC;
1029 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1030 const char* msg = "This is a std-handle inheritance test.";
1033 memset(&startup, 0, sizeof(startup));
1034 startup.cb = sizeof(startup);
1035 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1036 startup.wShowWindow = SW_SHOWNORMAL;
1038 sa.nLength = sizeof(sa);
1039 sa.lpSecurityDescriptor = NULL;
1040 sa.bInheritHandle = TRUE;
1042 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1043 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1045 /* first, we need to be sure we're attached to a console */
1046 if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE)
1048 /* we're not attached to a console, let's do it */
1050 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1051 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1053 /* now verify everything's ok */
1054 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1055 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1056 startup.hStdError = startup.hStdOutput;
1058 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1059 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1060 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1061 cpIn = GetConsoleCP();
1062 cpOut = GetConsoleOutputCP();
1064 get_file_name(resfile);
1065 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1066 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1068 /* wait for child to terminate */
1069 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1070 /* child process has changed result file, so let profile functions know about it */
1071 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1073 /* now get the modification the child has made, and resets parents expected values */
1074 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1075 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1076 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1078 SetConsoleMode(startup.hStdInput, modeIn);
1079 SetConsoleMode(startup.hStdOutput, modeOut);
1081 cpInC = GetConsoleCP();
1082 cpOutC = GetConsoleOutputCP();
1084 SetConsoleOutputCP(cpOut);
1086 GetStartupInfoA(&us);
1088 okChildInt("StartupInfoA", "cb", startup.cb);
1089 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1090 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1091 okChildInt("StartupInfoA", "dwX", startup.dwX);
1092 okChildInt("StartupInfoA", "dwY", startup.dwY);
1093 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1094 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1095 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1096 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1097 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1098 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1099 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1101 /* check child correctly inherited the console */
1102 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1103 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1104 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1105 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1106 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1107 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1108 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1109 okChildInt("Console", "Attributes", sbi.wAttributes);
1110 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1111 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1112 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1113 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1114 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1115 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1116 okChildInt("Console", "InputCP", cpIn);
1117 okChildInt("Console", "OutputCP", cpOut);
1118 okChildInt("Console", "InputMode", modeIn);
1119 okChildInt("Console", "OutputMode", modeOut);
1121 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)\n", cpInC, cpIn);
1122 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)\n", cpOutC, cpOut);
1123 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1124 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1125 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1126 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1129 assert(DeleteFileA(resfile) != 0);
1131 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1132 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1133 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1134 "Duplicating as inheritable child-output pipe\n");
1135 CloseHandle(hChildOut);
1137 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1138 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1139 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1140 "Duplicating as inheritable child-input pipe\n");
1141 CloseHandle(hChildIn);
1143 memset(&startup, 0, sizeof(startup));
1144 startup.cb = sizeof(startup);
1145 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1146 startup.wShowWindow = SW_SHOWNORMAL;
1147 startup.hStdInput = hChildInInh;
1148 startup.hStdOutput = hChildOutInh;
1149 startup.hStdError = hChildOutInh;
1151 get_file_name(resfile);
1152 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1153 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1154 ok(CloseHandle(hChildInInh), "Closing handle\n");
1155 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1157 msg_len = strlen(msg) + 1;
1158 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1159 ok(w == msg_len, "Should have written %u bytes, actually wrote %lu\n", msg_len, w);
1160 memset(buffer, 0, sizeof(buffer));
1161 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1162 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1164 /* wait for child to terminate */
1165 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1166 /* child process has changed result file, so let profile functions know about it */
1167 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1169 okChildString("StdHandle", "msg", msg);
1172 assert(DeleteFileA(resfile) != 0);
1175 static void test_ExitCode(void)
1177 char buffer[MAX_PATH];
1178 PROCESS_INFORMATION info;
1179 STARTUPINFOA startup;
1182 /* let's start simplistic */
1183 memset(&startup, 0, sizeof(startup));
1184 startup.cb = sizeof(startup);
1185 startup.dwFlags = STARTF_USESHOWWINDOW;
1186 startup.wShowWindow = SW_SHOWNORMAL;
1188 get_file_name(resfile);
1189 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1190 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1192 /* wait for child to terminate */
1193 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1194 /* child process has changed result file, so let profile functions know about it */
1195 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1197 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1198 okChildInt("ExitCode", "value", code);
1201 assert(DeleteFileA(resfile) != 0);
1207 ok(b, "Basic init of CreateProcess test\n");
1212 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1220 test_DebuggingFlag();
1223 /* things that can be tested:
1224 * lookup: check the way program to be executed is searched
1225 * handles: check the handle inheritance stuff (+sec options)
1226 * console: check if console creation parameters work