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