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], fullpath[MAX_PATH], *lpFilePart, *p;
697 PROCESS_INFORMATION info;
698 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);
745 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
746 get_file_name(resfile);
747 sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
748 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
749 /* wait for child to terminate */
750 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
751 /* child process has changed result file, so let profile functions know about it */
752 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
753 sprintf(buffer, "./%s", selfname);
754 okChildString("Arguments", "argvA0", buffer);
756 assert(DeleteFileA(resfile) != 0);
758 get_file_name(resfile);
759 sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
760 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
761 /* wait for child to terminate */
762 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
763 /* child process has changed result file, so let profile functions know about it */
764 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
765 sprintf(buffer, ".\\%s", selfname);
766 okChildString("Arguments", "argvA0", buffer);
768 assert(DeleteFileA(resfile) != 0);
770 get_file_name(resfile);
771 len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
772 assert ( lpFilePart != 0);
773 *(lpFilePart -1 ) = 0;
774 p = strrchr(fullpath, '\\');
776 sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, selfname, resfile);
777 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
778 /* wait for child to terminate */
779 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
780 /* child process has changed result file, so let profile functions know about it */
781 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
782 sprintf(buffer, "..%s/%s", p, selfname);
783 okChildString("Arguments", "argvA0", buffer);
785 assert(DeleteFileA(resfile) != 0);
789 static void test_Directory(void)
791 char buffer[MAX_PATH];
792 PROCESS_INFORMATION info;
793 STARTUPINFOA startup;
794 char windir[MAX_PATH];
796 memset(&startup, 0, sizeof(startup));
797 startup.cb = sizeof(startup);
798 startup.dwFlags = STARTF_USESHOWWINDOW;
799 startup.wShowWindow = SW_SHOWNORMAL;
802 get_file_name(resfile);
803 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
804 GetWindowsDirectoryA( windir, sizeof(windir) );
805 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
806 /* wait for child to terminate */
807 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
808 /* child process has changed result file, so let profile functions know about it */
809 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
811 okChildIString("Misc", "CurrDirA", windir);
813 assert(DeleteFileA(resfile) != 0);
816 static BOOL is_str_env_drive_dir(const char* str)
818 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
819 str[3] == '=' && str[4] == str[1];
822 /* compared expected child's environment (in gesA) from actual
823 * environment our child got
825 static void cmpEnvironment(const char* gesA)
833 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
835 /* now look each parent env in child */
836 if ((ptrA = gesA) != NULL)
840 for (i = 0; i < clen; i++)
842 sprintf(key, "env%d", i);
843 res = getChildString("EnvironmentA", key);
844 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
848 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
850 ptrA += strlen(ptrA) + 1;
854 /* and each child env in parent */
855 for (i = 0; i < clen; i++)
857 sprintf(key, "env%d", i);
858 res = getChildString("EnvironmentA", key);
859 if ((ptrA = gesA) != NULL)
863 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
865 ptrA += strlen(ptrA) + 1;
867 if (!*ptrA) ptrA = NULL;
870 if (!is_str_env_drive_dir(res))
872 found = ptrA != NULL;
873 ok(found, "Child-env string %s isn't in parent process\n", res);
875 /* else => should also test we get the right per drive default directory here... */
879 static void test_Environment(void)
881 char buffer[MAX_PATH];
882 PROCESS_INFORMATION info;
883 STARTUPINFOA startup;
890 memset(&startup, 0, sizeof(startup));
891 startup.cb = sizeof(startup);
892 startup.dwFlags = STARTF_USESHOWWINDOW;
893 startup.wShowWindow = SW_SHOWNORMAL;
896 get_file_name(resfile);
897 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
898 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
899 /* wait for child to terminate */
900 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
901 /* child process has changed result file, so let profile functions know about it */
902 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
904 cmpEnvironment(GetEnvironmentStringsA());
906 assert(DeleteFileA(resfile) != 0);
908 memset(&startup, 0, sizeof(startup));
909 startup.cb = sizeof(startup);
910 startup.dwFlags = STARTF_USESHOWWINDOW;
911 startup.wShowWindow = SW_SHOWNORMAL;
914 get_file_name(resfile);
915 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
918 ptr = GetEnvironmentStringsA();
921 slen = strlen(ptr)+1;
922 child_env_len += slen;
925 /* Add space for additional environment variables */
926 child_env_len += 256;
927 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
930 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
931 ptr += strlen(ptr) + 1;
932 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
933 ptr += strlen(ptr) + 1;
934 strcpy(ptr, "FOO=BAR");
935 ptr += strlen(ptr) + 1;
936 strcpy(ptr, "BAR=FOOBAR");
937 ptr += strlen(ptr) + 1;
938 /* copy all existing variables except:
940 * - PATH (already set above)
941 * - the directory definitions (=[A-Z]:=)
943 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
945 if (strncmp(env, "PATH=", 5) != 0 &&
946 strncmp(env, "WINELOADER=", 11) != 0 &&
947 !is_str_env_drive_dir(env))
950 ptr += strlen(ptr) + 1;
954 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
955 /* wait for child to terminate */
956 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
957 /* child process has changed result file, so let profile functions know about it */
958 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
960 cmpEnvironment(child_env);
962 HeapFree(GetProcessHeap(), 0, child_env);
964 assert(DeleteFileA(resfile) != 0);
967 static void test_SuspendFlag(void)
969 char buffer[MAX_PATH];
970 PROCESS_INFORMATION info;
971 STARTUPINFOA startup, us;
974 /* let's start simplistic */
975 memset(&startup, 0, sizeof(startup));
976 startup.cb = sizeof(startup);
977 startup.dwFlags = STARTF_USESHOWWINDOW;
978 startup.wShowWindow = SW_SHOWNORMAL;
980 get_file_name(resfile);
981 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
982 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
984 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
986 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
987 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
989 /* wait for child to terminate */
990 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
991 /* child process has changed result file, so let profile functions know about it */
992 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
994 GetStartupInfoA(&us);
996 okChildInt("StartupInfoA", "cb", startup.cb);
997 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
998 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
999 okChildInt("StartupInfoA", "dwX", startup.dwX);
1000 okChildInt("StartupInfoA", "dwY", startup.dwY);
1001 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1002 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1003 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1004 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1005 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1006 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1007 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1009 assert(DeleteFileA(resfile) != 0);
1012 static void test_DebuggingFlag(void)
1014 char buffer[MAX_PATH];
1015 PROCESS_INFORMATION info;
1016 STARTUPINFOA startup, us;
1020 /* let's start simplistic */
1021 memset(&startup, 0, sizeof(startup));
1022 startup.cb = sizeof(startup);
1023 startup.dwFlags = STARTF_USESHOWWINDOW;
1024 startup.wShowWindow = SW_SHOWNORMAL;
1026 get_file_name(resfile);
1027 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1028 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1030 /* get all startup events up to the entry point break exception */
1033 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
1034 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
1035 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
1036 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
1038 ok(dbg, "I have seen a debug event\n");
1039 /* wait for child to terminate */
1040 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1041 /* child process has changed result file, so let profile functions know about it */
1042 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1044 GetStartupInfoA(&us);
1046 okChildInt("StartupInfoA", "cb", startup.cb);
1047 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1048 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1049 okChildInt("StartupInfoA", "dwX", startup.dwX);
1050 okChildInt("StartupInfoA", "dwY", startup.dwY);
1051 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1052 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1053 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1054 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1055 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1056 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1057 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1059 assert(DeleteFileA(resfile) != 0);
1062 static BOOL is_console(HANDLE h)
1064 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1067 static void test_Console(void)
1069 char buffer[MAX_PATH];
1070 PROCESS_INFORMATION info;
1071 STARTUPINFOA startup, us;
1072 SECURITY_ATTRIBUTES sa;
1073 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1074 DWORD modeIn, modeOut, modeInC, modeOutC;
1075 DWORD cpIn, cpOut, cpInC, cpOutC;
1077 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1078 const char* msg = "This is a std-handle inheritance test.";
1081 memset(&startup, 0, sizeof(startup));
1082 startup.cb = sizeof(startup);
1083 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1084 startup.wShowWindow = SW_SHOWNORMAL;
1086 sa.nLength = sizeof(sa);
1087 sa.lpSecurityDescriptor = NULL;
1088 sa.bInheritHandle = TRUE;
1090 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1091 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1093 /* first, we need to be sure we're attached to a console */
1094 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1096 /* we're not attached to a console, let's do it */
1098 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1099 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1101 /* now verify everything's ok */
1102 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1103 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1104 startup.hStdError = startup.hStdOutput;
1106 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1107 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1108 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1109 cpIn = GetConsoleCP();
1110 cpOut = GetConsoleOutputCP();
1112 get_file_name(resfile);
1113 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1114 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1116 /* wait for child to terminate */
1117 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1118 /* child process has changed result file, so let profile functions know about it */
1119 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1121 /* now get the modification the child has made, and resets parents expected values */
1122 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1123 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1124 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1126 SetConsoleMode(startup.hStdInput, modeIn);
1127 SetConsoleMode(startup.hStdOutput, modeOut);
1129 cpInC = GetConsoleCP();
1130 cpOutC = GetConsoleOutputCP();
1132 SetConsoleOutputCP(cpOut);
1134 GetStartupInfoA(&us);
1136 okChildInt("StartupInfoA", "cb", startup.cb);
1137 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1138 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1139 okChildInt("StartupInfoA", "dwX", startup.dwX);
1140 okChildInt("StartupInfoA", "dwY", startup.dwY);
1141 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1142 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1143 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1144 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1145 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1146 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1147 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1149 /* check child correctly inherited the console */
1150 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1151 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1152 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1153 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1154 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1155 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1156 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1157 okChildInt("Console", "Attributes", sbi.wAttributes);
1158 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1159 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1160 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1161 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1162 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1163 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1164 okChildInt("Console", "InputCP", cpIn);
1165 okChildInt("Console", "OutputCP", cpOut);
1166 okChildInt("Console", "InputMode", modeIn);
1167 okChildInt("Console", "OutputMode", modeOut);
1169 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)\n", cpInC, cpIn);
1170 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)\n", cpOutC, cpOut);
1171 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1172 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1173 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1174 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1177 assert(DeleteFileA(resfile) != 0);
1179 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1180 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1181 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1182 "Duplicating as inheritable child-output pipe\n");
1183 CloseHandle(hChildOut);
1185 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1186 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1187 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1188 "Duplicating as inheritable child-input pipe\n");
1189 CloseHandle(hChildIn);
1191 memset(&startup, 0, sizeof(startup));
1192 startup.cb = sizeof(startup);
1193 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1194 startup.wShowWindow = SW_SHOWNORMAL;
1195 startup.hStdInput = hChildInInh;
1196 startup.hStdOutput = hChildOutInh;
1197 startup.hStdError = hChildOutInh;
1199 get_file_name(resfile);
1200 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1201 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1202 ok(CloseHandle(hChildInInh), "Closing handle\n");
1203 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1205 msg_len = strlen(msg) + 1;
1206 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1207 ok(w == msg_len, "Should have written %u bytes, actually wrote %lu\n", msg_len, w);
1208 memset(buffer, 0, sizeof(buffer));
1209 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1210 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1212 /* wait for child to terminate */
1213 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1214 /* child process has changed result file, so let profile functions know about it */
1215 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1217 okChildString("StdHandle", "msg", msg);
1220 assert(DeleteFileA(resfile) != 0);
1223 static void test_ExitCode(void)
1225 char buffer[MAX_PATH];
1226 PROCESS_INFORMATION info;
1227 STARTUPINFOA startup;
1230 /* let's start simplistic */
1231 memset(&startup, 0, sizeof(startup));
1232 startup.cb = sizeof(startup);
1233 startup.dwFlags = STARTF_USESHOWWINDOW;
1234 startup.wShowWindow = SW_SHOWNORMAL;
1236 get_file_name(resfile);
1237 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1238 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1240 /* wait for child to terminate */
1241 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1242 /* child process has changed result file, so let profile functions know about it */
1243 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1245 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1246 okChildInt("ExitCode", "value", code);
1249 assert(DeleteFileA(resfile) != 0);
1255 ok(b, "Basic init of CreateProcess test\n");
1260 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1268 test_DebuggingFlag();
1271 /* things that can be tested:
1272 * lookup: check the way program to be executed is searched
1273 * handles: check the handle inheritance stuff (+sec options)
1274 * console: check if console creation parameters work