2 * Unit test suite for CreateProcess function.
4 * Copyright 2002 Eric Pouech
5 * Copyright 2006 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
34 static HINSTANCE hkernel32;
35 static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
36 static LPVOID (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
38 static char base[MAX_PATH];
39 static char selfname[MAX_PATH];
40 static char resfile[MAX_PATH];
45 /* As some environment variables get very long on Unix, we only test for
46 * the first 127 bytes.
47 * Note that increasing this value past 256 may exceed the buffer size
48 * limitations of the *Profile functions (at least on Wine).
50 #define MAX_LISTED_ENV_VAR 128
52 /* ---------------- portable memory allocation thingie */
54 static char memory[1024*256];
55 static char* memory_index = memory;
57 static char* grab_memory(size_t len)
59 char* ret = memory_index;
63 assert(memory_index <= memory + sizeof(memory));
67 static void release_memory(void)
69 memory_index = memory;
72 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
74 static const char* encodeA(const char* str)
80 len = strlen(str) + 1;
81 ptr = grab_memory(len * 2 + 1);
82 for (i = 0; i < len; i++)
83 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
88 static const char* encodeW(const WCHAR* str)
94 len = lstrlenW(str) + 1;
95 ptr = grab_memory(len * 4 + 1);
97 for (i = 0; i < len; i++)
98 sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
103 static unsigned decode_char(char c)
105 if (c >= '0' && c <= '9') return c - '0';
106 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
107 assert(c >= 'A' && c <= 'F');
111 static char* decodeA(const char* str)
116 len = strlen(str) / 2;
117 if (!len--) return NULL;
118 ptr = grab_memory(len + 1);
119 for (i = 0; i < len; i++)
120 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
126 /* This will be needed to decode Unicode strings saved by the child process
127 * when we test Unicode functions.
129 static WCHAR* decodeW(const char* str)
135 len = strlen(str) / 4;
136 if (!len--) return NULL;
137 ptr = (WCHAR*)grab_memory(len * 2 + 1);
138 for (i = 0; i < len; i++)
139 ptr[i] = (decode_char(str[4 * i]) << 12) |
140 (decode_char(str[4 * i + 1]) << 8) |
141 (decode_char(str[4 * i + 2]) << 4) |
142 (decode_char(str[4 * i + 3]) << 0);
148 /******************************************************************
151 * generates basic information like:
152 * base: absolute path to curr dir
153 * selfname: the way to reinvoke ourselves
154 * function-pointers, which are not implemented in all windows versions
156 static int init(void)
158 myARGC = winetest_get_mainargs( &myARGV );
159 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
160 strcpy(selfname, myARGV[0]);
162 hkernel32 = GetModuleHandleA("kernel32");
163 pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
164 pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
168 /******************************************************************
171 * generates an absolute file_name for temporary file
174 static void get_file_name(char* buf)
179 GetTempPathA(sizeof(path), path);
180 GetTempFileNameA(path, "wt", 0, buf);
183 /******************************************************************
184 * static void childPrintf
187 static void childPrintf(HANDLE h, const char* fmt, ...)
190 char buffer[1024+4*MAX_LISTED_ENV_VAR];
193 va_start(valist, fmt);
194 vsprintf(buffer, fmt, valist);
196 WriteFile(h, buffer, strlen(buffer), &w, NULL);
200 /******************************************************************
203 * output most of the information in the child process
205 static void doChild(const char* file, const char* option)
213 WCHAR bufW[MAX_PATH];
214 HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
217 if (hFile == INVALID_HANDLE_VALUE) return;
219 /* output of startup info (Ansi) */
220 GetStartupInfoA(&siA);
222 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
223 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
224 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
225 "dwFlags=%lu\nwShowWindow=%u\n"
226 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
227 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
228 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
229 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
230 siA.dwFlags, siA.wShowWindow,
231 (DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
233 /* since GetStartupInfoW is only implemented in win2k,
234 * zero out before calling so we can notice the difference
236 memset(&siW, 0, sizeof(siW));
237 GetStartupInfoW(&siW);
239 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
240 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
241 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
242 "dwFlags=%lu\nwShowWindow=%u\n"
243 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
244 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
245 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
246 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
247 siW.dwFlags, siW.wShowWindow,
248 (DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
251 childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
252 for (i = 0; i < myARGC; i++)
254 childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
256 childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
262 /* this is part of shell32... and should be tested there */
263 argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
264 for (i = 0; i < argcW; i++)
266 childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
269 childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
271 /* output of environment (Ansi) */
272 ptrA = GetEnvironmentStringsA();
275 char env_var[MAX_LISTED_ENV_VAR];
277 childPrintf(hFile, "[EnvironmentA]\n");
281 lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
282 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
284 ptrA += strlen(ptrA) + 1;
286 childPrintf(hFile, "len=%d\n\n", i);
289 /* output of environment (Unicode) */
290 ptrW = GetEnvironmentStringsW();
293 WCHAR env_var[MAX_LISTED_ENV_VAR];
295 childPrintf(hFile, "[EnvironmentW]\n");
299 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
300 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
301 childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
303 ptrW += lstrlenW(ptrW) + 1;
305 childPrintf(hFile, "len=%d\n\n", i);
308 childPrintf(hFile, "[Misc]\n");
309 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
310 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
311 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
312 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
313 childPrintf(hFile, "\n");
315 if (option && strcmp(option, "console") == 0)
317 CONSOLE_SCREEN_BUFFER_INFO sbi;
318 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
319 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
320 DWORD modeIn, modeOut;
322 childPrintf(hFile, "[Console]\n");
323 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
325 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
326 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
327 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
328 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
329 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
330 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
332 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
333 GetConsoleCP(), GetConsoleOutputCP());
334 if (GetConsoleMode(hConIn, &modeIn))
335 childPrintf(hFile, "InputMode=%ld\n", modeIn);
336 if (GetConsoleMode(hConOut, &modeOut))
337 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
339 /* now that we have written all relevant information, let's change it */
340 ok(SetConsoleCP(1252), "Setting CP\n");
341 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
342 ret = SetConsoleMode(hConIn, modeIn ^ 1);
343 ok( ret, "Setting mode (%d)\n", GetLastError());
344 ret = SetConsoleMode(hConOut, modeOut ^ 1);
345 ok( ret, "Setting mode (%d)\n", GetLastError());
346 sbi.dwCursorPosition.X ^= 1;
347 sbi.dwCursorPosition.Y ^= 1;
348 ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
349 ok( ret, "Setting cursor position (%d)\n", GetLastError());
351 if (option && strcmp(option, "stdhandle") == 0)
353 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
354 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
356 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
361 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
362 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
363 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
367 if (option && strcmp(option, "exit_code") == 0)
369 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
377 static char* getChildString(const char* sect, const char* key)
379 char buf[1024+4*MAX_LISTED_ENV_VAR];
382 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
383 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
384 assert(!(strlen(buf) & 1));
389 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
390 * others... (windows uses stricmp while Un*x uses strcasecmp...)
392 static int wtstrcasecmp(const char* p1, const char* p2)
397 while (c1 == c2 && c1)
399 c1 = *p1++; c2 = *p2++;
402 c1 = toupper(c1); c2 = toupper(c2);
408 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
410 if (!s1 && !s2) return 0;
413 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
416 #define okChildString(sect, key, expect) \
418 char* result = getChildString((sect), (key)); \
419 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
422 #define okChildIString(sect, key, expect) \
424 char* result = getChildString(sect, key); \
425 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
428 /* using !expect ensures that the test will fail if the sect/key isn't present
431 #define okChildInt(sect, key, expect) \
433 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
434 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
437 static void test_Startup(void)
439 char buffer[MAX_PATH];
440 PROCESS_INFORMATION info;
441 STARTUPINFOA startup,si;
442 static CHAR title[] = "I'm the title string",
443 desktop[] = "I'm the desktop string",
446 /* let's start simplistic */
447 memset(&startup, 0, sizeof(startup));
448 startup.cb = sizeof(startup);
449 startup.dwFlags = STARTF_USESHOWWINDOW;
450 startup.wShowWindow = SW_SHOWNORMAL;
452 get_file_name(resfile);
453 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
454 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
455 /* wait for child to terminate */
456 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
457 /* child process has changed result file, so let profile functions know about it */
458 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
460 GetStartupInfoA(&si);
461 okChildInt("StartupInfoA", "cb", startup.cb);
462 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
463 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
464 okChildInt("StartupInfoA", "dwX", startup.dwX);
465 okChildInt("StartupInfoA", "dwY", startup.dwY);
466 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
467 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
468 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
469 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
470 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
471 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
472 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
474 assert(DeleteFileA(resfile) != 0);
476 /* not so simplistic now */
477 memset(&startup, 0, sizeof(startup));
478 startup.cb = sizeof(startup);
479 startup.dwFlags = STARTF_USESHOWWINDOW;
480 startup.wShowWindow = SW_SHOWNORMAL;
481 startup.lpTitle = title;
482 startup.lpDesktop = desktop;
483 startup.dwXCountChars = 0x12121212;
484 startup.dwYCountChars = 0x23232323;
485 startup.dwX = 0x34343434;
486 startup.dwY = 0x45454545;
487 startup.dwXSize = 0x56565656;
488 startup.dwYSize = 0x67676767;
489 startup.dwFillAttribute = 0xA55A;
491 get_file_name(resfile);
492 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
493 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
494 /* wait for child to terminate */
495 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
496 /* child process has changed result file, so let profile functions know about it */
497 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
499 okChildInt("StartupInfoA", "cb", startup.cb);
500 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
501 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
502 okChildInt("StartupInfoA", "dwX", startup.dwX);
503 okChildInt("StartupInfoA", "dwY", startup.dwY);
504 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
505 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
506 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
507 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
508 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
509 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
510 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
512 assert(DeleteFileA(resfile) != 0);
514 /* not so simplistic now */
515 memset(&startup, 0, sizeof(startup));
516 startup.cb = sizeof(startup);
517 startup.dwFlags = STARTF_USESHOWWINDOW;
518 startup.wShowWindow = SW_SHOWNORMAL;
519 startup.lpTitle = title;
520 startup.lpDesktop = NULL;
521 startup.dwXCountChars = 0x12121212;
522 startup.dwYCountChars = 0x23232323;
523 startup.dwX = 0x34343434;
524 startup.dwY = 0x45454545;
525 startup.dwXSize = 0x56565656;
526 startup.dwYSize = 0x67676767;
527 startup.dwFillAttribute = 0xA55A;
529 get_file_name(resfile);
530 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
531 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
532 /* wait for child to terminate */
533 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
534 /* child process has changed result file, so let profile functions know about it */
535 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
537 okChildInt("StartupInfoA", "cb", startup.cb);
538 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
539 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
540 okChildInt("StartupInfoA", "dwX", startup.dwX);
541 okChildInt("StartupInfoA", "dwY", startup.dwY);
542 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
543 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
544 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
545 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
546 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
547 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
548 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
550 assert(DeleteFileA(resfile) != 0);
552 /* not so simplistic now */
553 memset(&startup, 0, sizeof(startup));
554 startup.cb = sizeof(startup);
555 startup.dwFlags = STARTF_USESHOWWINDOW;
556 startup.wShowWindow = SW_SHOWNORMAL;
557 startup.lpTitle = title;
558 startup.lpDesktop = empty;
559 startup.dwXCountChars = 0x12121212;
560 startup.dwYCountChars = 0x23232323;
561 startup.dwX = 0x34343434;
562 startup.dwY = 0x45454545;
563 startup.dwXSize = 0x56565656;
564 startup.dwYSize = 0x67676767;
565 startup.dwFillAttribute = 0xA55A;
567 get_file_name(resfile);
568 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
569 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
570 /* wait for child to terminate */
571 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
572 /* child process has changed result file, so let profile functions know about it */
573 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
575 okChildInt("StartupInfoA", "cb", startup.cb);
576 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
577 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
578 okChildInt("StartupInfoA", "dwX", startup.dwX);
579 okChildInt("StartupInfoA", "dwY", startup.dwY);
580 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
581 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
582 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
583 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
584 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
585 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
586 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
588 assert(DeleteFileA(resfile) != 0);
590 /* not so simplistic now */
591 memset(&startup, 0, sizeof(startup));
592 startup.cb = sizeof(startup);
593 startup.dwFlags = STARTF_USESHOWWINDOW;
594 startup.wShowWindow = SW_SHOWNORMAL;
595 startup.lpTitle = NULL;
596 startup.lpDesktop = desktop;
597 startup.dwXCountChars = 0x12121212;
598 startup.dwYCountChars = 0x23232323;
599 startup.dwX = 0x34343434;
600 startup.dwY = 0x45454545;
601 startup.dwXSize = 0x56565656;
602 startup.dwYSize = 0x67676767;
603 startup.dwFillAttribute = 0xA55A;
605 get_file_name(resfile);
606 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
607 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
608 /* wait for child to terminate */
609 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
610 /* child process has changed result file, so let profile functions know about it */
611 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
613 okChildInt("StartupInfoA", "cb", startup.cb);
614 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
615 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
616 okChildInt("StartupInfoA", "dwX", startup.dwX);
617 okChildInt("StartupInfoA", "dwY", startup.dwY);
618 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
619 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
620 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
621 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
622 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
623 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
624 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
626 assert(DeleteFileA(resfile) != 0);
628 /* not so simplistic now */
629 memset(&startup, 0, sizeof(startup));
630 startup.cb = sizeof(startup);
631 startup.dwFlags = STARTF_USESHOWWINDOW;
632 startup.wShowWindow = SW_SHOWNORMAL;
633 startup.lpTitle = empty;
634 startup.lpDesktop = desktop;
635 startup.dwXCountChars = 0x12121212;
636 startup.dwYCountChars = 0x23232323;
637 startup.dwX = 0x34343434;
638 startup.dwY = 0x45454545;
639 startup.dwXSize = 0x56565656;
640 startup.dwYSize = 0x67676767;
641 startup.dwFillAttribute = 0xA55A;
643 get_file_name(resfile);
644 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
645 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
646 /* wait for child to terminate */
647 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
648 /* child process has changed result file, so let profile functions know about it */
649 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
651 okChildInt("StartupInfoA", "cb", startup.cb);
652 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
653 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
654 okChildInt("StartupInfoA", "dwX", startup.dwX);
655 okChildInt("StartupInfoA", "dwY", startup.dwY);
656 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
657 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
658 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
659 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
660 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
661 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
662 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
664 assert(DeleteFileA(resfile) != 0);
666 /* not so simplistic now */
667 memset(&startup, 0, sizeof(startup));
668 startup.cb = sizeof(startup);
669 startup.dwFlags = STARTF_USESHOWWINDOW;
670 startup.wShowWindow = SW_SHOWNORMAL;
671 startup.lpTitle = empty;
672 startup.lpDesktop = empty;
673 startup.dwXCountChars = 0x12121212;
674 startup.dwYCountChars = 0x23232323;
675 startup.dwX = 0x34343434;
676 startup.dwY = 0x45454545;
677 startup.dwXSize = 0x56565656;
678 startup.dwYSize = 0x67676767;
679 startup.dwFillAttribute = 0xA55A;
681 get_file_name(resfile);
682 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
683 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
684 /* wait for child to terminate */
685 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
686 /* child process has changed result file, so let profile functions know about it */
687 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
689 okChildInt("StartupInfoA", "cb", startup.cb);
690 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
691 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
692 okChildInt("StartupInfoA", "dwX", startup.dwX);
693 okChildInt("StartupInfoA", "dwY", startup.dwY);
694 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
695 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
696 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
697 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
698 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
699 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
700 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
702 assert(DeleteFileA(resfile) != 0);
704 /* TODO: test for A/W and W/A and W/W */
707 static void test_CommandLine(void)
709 char buffer[MAX_PATH], fullpath[MAX_PATH], *lpFilePart, *p;
710 PROCESS_INFORMATION info;
711 STARTUPINFOA startup;
715 memset(&startup, 0, sizeof(startup));
716 startup.cb = sizeof(startup);
717 startup.dwFlags = STARTF_USESHOWWINDOW;
718 startup.wShowWindow = SW_SHOWNORMAL;
721 get_file_name(resfile);
722 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
723 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
724 /* wait for child to terminate */
725 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
726 /* child process has changed result file, so let profile functions know about it */
727 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
729 okChildInt("Arguments", "argcA", 4);
730 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
731 okChildString("Arguments", "argvA4", NULL);
732 okChildString("Arguments", "CommandLineA", buffer);
734 assert(DeleteFileA(resfile) != 0);
736 memset(&startup, 0, sizeof(startup));
737 startup.cb = sizeof(startup);
738 startup.dwFlags = STARTF_USESHOWWINDOW;
739 startup.wShowWindow = SW_SHOWNORMAL;
742 get_file_name(resfile);
743 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
744 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
745 /* wait for child to terminate */
746 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
747 /* child process has changed result file, so let profile functions know about it */
748 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
750 okChildInt("Arguments", "argcA", 6);
751 okChildString("Arguments", "argvA3", "a\"b\\");
752 okChildString("Arguments", "argvA4", "c\"");
753 okChildString("Arguments", "argvA5", "d");
754 okChildString("Arguments", "argvA6", NULL);
755 okChildString("Arguments", "CommandLineA", buffer);
757 assert(DeleteFileA(resfile) != 0);
759 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
760 get_file_name(resfile);
761 sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
762 SetLastError(0xdeadbeef);
763 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
764 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
765 /* wait for child to terminate */
766 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
767 /* child process has changed result file, so let profile functions know about it */
768 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
769 sprintf(buffer, "./%s", selfname);
770 okChildString("Arguments", "argvA0", buffer);
772 assert(DeleteFileA(resfile) != 0);
774 get_file_name(resfile);
775 sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
776 SetLastError(0xdeadbeef);
777 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
778 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
779 /* wait for child to terminate */
780 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
781 /* child process has changed result file, so let profile functions know about it */
782 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
783 sprintf(buffer, ".\\%s", selfname);
784 okChildString("Arguments", "argvA0", buffer);
786 assert(DeleteFileA(resfile) != 0);
788 get_file_name(resfile);
789 len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
790 assert ( lpFilePart != 0);
791 *(lpFilePart -1 ) = 0;
792 p = strrchr(fullpath, '\\');
794 sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, selfname, resfile);
795 SetLastError(0xdeadbeef);
796 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
797 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
798 /* wait for child to terminate */
799 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
800 /* child process has changed result file, so let profile functions know about it */
801 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
802 sprintf(buffer, "..%s/%s", p, selfname);
803 okChildString("Arguments", "argvA0", buffer);
805 assert(DeleteFileA(resfile) != 0);
809 static void test_Directory(void)
811 char buffer[MAX_PATH];
812 PROCESS_INFORMATION info;
813 STARTUPINFOA startup;
814 char windir[MAX_PATH];
815 static CHAR cmdline[] = "winver.exe";
817 memset(&startup, 0, sizeof(startup));
818 startup.cb = sizeof(startup);
819 startup.dwFlags = STARTF_USESHOWWINDOW;
820 startup.wShowWindow = SW_SHOWNORMAL;
823 get_file_name(resfile);
824 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
825 GetWindowsDirectoryA( windir, sizeof(windir) );
826 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
827 /* wait for child to terminate */
828 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
829 /* child process has changed result file, so let profile functions know about it */
830 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
832 okChildIString("Misc", "CurrDirA", windir);
834 assert(DeleteFileA(resfile) != 0);
836 /* search PATH for the exe if directory is NULL */
837 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
838 ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
840 /* if any directory is provided, don't search PATH, error on bad directory */
841 SetLastError(0xdeadbeef);
842 memset(&info, 0, sizeof(info));
843 ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
844 NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
845 ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
846 ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
849 static BOOL is_str_env_drive_dir(const char* str)
851 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
852 str[3] == '=' && str[4] == str[1];
855 /* compared expected child's environment (in gesA) from actual
856 * environment our child got
858 static void cmpEnvironment(const char* gesA)
866 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
868 /* now look each parent env in child */
869 if ((ptrA = gesA) != NULL)
873 for (i = 0; i < clen; i++)
875 sprintf(key, "env%d", i);
876 res = getChildString("EnvironmentA", key);
877 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
881 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
883 ptrA += strlen(ptrA) + 1;
887 /* and each child env in parent */
888 for (i = 0; i < clen; i++)
890 sprintf(key, "env%d", i);
891 res = getChildString("EnvironmentA", key);
892 if ((ptrA = gesA) != NULL)
896 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
898 ptrA += strlen(ptrA) + 1;
900 if (!*ptrA) ptrA = NULL;
903 if (!is_str_env_drive_dir(res))
905 found = ptrA != NULL;
906 ok(found, "Child-env string %s isn't in parent process\n", res);
908 /* else => should also test we get the right per drive default directory here... */
912 static void test_Environment(void)
914 char buffer[MAX_PATH];
915 PROCESS_INFORMATION info;
916 STARTUPINFOA startup;
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);
931 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
932 /* wait for child to terminate */
933 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
934 /* child process has changed result file, so let profile functions know about it */
935 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
937 cmpEnvironment(GetEnvironmentStringsA());
939 assert(DeleteFileA(resfile) != 0);
941 memset(&startup, 0, sizeof(startup));
942 startup.cb = sizeof(startup);
943 startup.dwFlags = STARTF_USESHOWWINDOW;
944 startup.wShowWindow = SW_SHOWNORMAL;
947 get_file_name(resfile);
948 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
951 ptr = GetEnvironmentStringsA();
954 slen = strlen(ptr)+1;
955 child_env_len += slen;
958 /* Add space for additional environment variables */
959 child_env_len += 256;
960 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
963 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
964 ptr += strlen(ptr) + 1;
965 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
966 ptr += strlen(ptr) + 1;
967 strcpy(ptr, "FOO=BAR");
968 ptr += strlen(ptr) + 1;
969 strcpy(ptr, "BAR=FOOBAR");
970 ptr += strlen(ptr) + 1;
971 /* copy all existing variables except:
973 * - PATH (already set above)
974 * - the directory definitions (=[A-Z]:=)
976 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
978 if (strncmp(env, "PATH=", 5) != 0 &&
979 strncmp(env, "WINELOADER=", 11) != 0 &&
980 !is_str_env_drive_dir(env))
983 ptr += strlen(ptr) + 1;
987 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
988 /* wait for child to terminate */
989 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
990 /* child process has changed result file, so let profile functions know about it */
991 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
993 cmpEnvironment(child_env);
995 HeapFree(GetProcessHeap(), 0, child_env);
997 assert(DeleteFileA(resfile) != 0);
1000 static void test_SuspendFlag(void)
1002 char buffer[MAX_PATH];
1003 PROCESS_INFORMATION info;
1004 STARTUPINFOA startup, us;
1007 /* let's start simplistic */
1008 memset(&startup, 0, sizeof(startup));
1009 startup.cb = sizeof(startup);
1010 startup.dwFlags = STARTF_USESHOWWINDOW;
1011 startup.wShowWindow = SW_SHOWNORMAL;
1013 get_file_name(resfile);
1014 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1015 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
1017 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1019 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1020 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
1022 /* wait for child to terminate */
1023 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1024 /* child process has changed result file, so let profile functions know about it */
1025 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1027 GetStartupInfoA(&us);
1029 okChildInt("StartupInfoA", "cb", startup.cb);
1030 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1031 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1032 okChildInt("StartupInfoA", "dwX", startup.dwX);
1033 okChildInt("StartupInfoA", "dwY", startup.dwY);
1034 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1035 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1036 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1037 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1038 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1039 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1040 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1042 assert(DeleteFileA(resfile) != 0);
1045 static void test_DebuggingFlag(void)
1047 char buffer[MAX_PATH];
1048 PROCESS_INFORMATION info;
1049 STARTUPINFOA startup, us;
1053 /* let's start simplistic */
1054 memset(&startup, 0, sizeof(startup));
1055 startup.cb = sizeof(startup);
1056 startup.dwFlags = STARTF_USESHOWWINDOW;
1057 startup.wShowWindow = SW_SHOWNORMAL;
1059 get_file_name(resfile);
1060 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1061 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1063 /* get all startup events up to the entry point break exception */
1066 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
1067 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
1068 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
1069 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
1071 ok(dbg, "I have seen a debug event\n");
1072 /* wait for child to terminate */
1073 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1074 /* child process has changed result file, so let profile functions know about it */
1075 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1077 GetStartupInfoA(&us);
1079 okChildInt("StartupInfoA", "cb", startup.cb);
1080 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1081 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1082 okChildInt("StartupInfoA", "dwX", startup.dwX);
1083 okChildInt("StartupInfoA", "dwY", startup.dwY);
1084 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1085 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1086 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1087 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1088 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1089 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1090 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1092 assert(DeleteFileA(resfile) != 0);
1095 static BOOL is_console(HANDLE h)
1097 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1100 static void test_Console(void)
1102 char buffer[MAX_PATH];
1103 PROCESS_INFORMATION info;
1104 STARTUPINFOA startup, us;
1105 SECURITY_ATTRIBUTES sa;
1106 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1107 DWORD modeIn, modeOut, modeInC, modeOutC;
1108 DWORD cpIn, cpOut, cpInC, cpOutC;
1110 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1111 const char* msg = "This is a std-handle inheritance test.";
1114 memset(&startup, 0, sizeof(startup));
1115 startup.cb = sizeof(startup);
1116 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1117 startup.wShowWindow = SW_SHOWNORMAL;
1119 sa.nLength = sizeof(sa);
1120 sa.lpSecurityDescriptor = NULL;
1121 sa.bInheritHandle = TRUE;
1123 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1124 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1126 /* first, we need to be sure we're attached to a console */
1127 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1129 /* we're not attached to a console, let's do it */
1131 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1132 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1134 /* now verify everything's ok */
1135 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1136 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1137 startup.hStdError = startup.hStdOutput;
1139 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1140 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1141 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1142 cpIn = GetConsoleCP();
1143 cpOut = GetConsoleOutputCP();
1145 get_file_name(resfile);
1146 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1147 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1149 /* wait for child to terminate */
1150 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1151 /* child process has changed result file, so let profile functions know about it */
1152 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1154 /* now get the modification the child has made, and resets parents expected values */
1155 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1156 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1157 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1159 SetConsoleMode(startup.hStdInput, modeIn);
1160 SetConsoleMode(startup.hStdOutput, modeOut);
1162 cpInC = GetConsoleCP();
1163 cpOutC = GetConsoleOutputCP();
1165 SetConsoleOutputCP(cpOut);
1167 GetStartupInfoA(&us);
1169 okChildInt("StartupInfoA", "cb", startup.cb);
1170 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1171 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1172 okChildInt("StartupInfoA", "dwX", startup.dwX);
1173 okChildInt("StartupInfoA", "dwY", startup.dwY);
1174 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1175 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1176 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1177 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1178 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1179 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1180 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1182 /* check child correctly inherited the console */
1183 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1184 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1185 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1186 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1187 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1188 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1189 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1190 okChildInt("Console", "Attributes", sbi.wAttributes);
1191 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1192 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1193 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1194 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1195 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1196 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1197 okChildInt("Console", "InputCP", cpIn);
1198 okChildInt("Console", "OutputCP", cpOut);
1199 okChildInt("Console", "InputMode", modeIn);
1200 okChildInt("Console", "OutputMode", modeOut);
1202 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
1203 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
1204 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1205 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1206 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1207 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1210 assert(DeleteFileA(resfile) != 0);
1212 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1213 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1214 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1215 "Duplicating as inheritable child-output pipe\n");
1216 CloseHandle(hChildOut);
1218 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1219 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1220 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1221 "Duplicating as inheritable child-input pipe\n");
1222 CloseHandle(hChildIn);
1224 memset(&startup, 0, sizeof(startup));
1225 startup.cb = sizeof(startup);
1226 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1227 startup.wShowWindow = SW_SHOWNORMAL;
1228 startup.hStdInput = hChildInInh;
1229 startup.hStdOutput = hChildOutInh;
1230 startup.hStdError = hChildOutInh;
1232 get_file_name(resfile);
1233 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1234 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1235 ok(CloseHandle(hChildInInh), "Closing handle\n");
1236 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1238 msg_len = strlen(msg) + 1;
1239 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1240 ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
1241 memset(buffer, 0, sizeof(buffer));
1242 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1243 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1245 /* wait for child to terminate */
1246 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1247 /* child process has changed result file, so let profile functions know about it */
1248 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1250 okChildString("StdHandle", "msg", msg);
1253 assert(DeleteFileA(resfile) != 0);
1256 static void test_ExitCode(void)
1258 char buffer[MAX_PATH];
1259 PROCESS_INFORMATION info;
1260 STARTUPINFOA startup;
1263 /* let's start simplistic */
1264 memset(&startup, 0, sizeof(startup));
1265 startup.cb = sizeof(startup);
1266 startup.dwFlags = STARTF_USESHOWWINDOW;
1267 startup.wShowWindow = SW_SHOWNORMAL;
1269 get_file_name(resfile);
1270 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1271 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1273 /* wait for child to terminate */
1274 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1275 /* child process has changed result file, so let profile functions know about it */
1276 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1278 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1279 okChildInt("ExitCode", "value", code);
1282 assert(DeleteFileA(resfile) != 0);
1285 static void test_OpenProcess(void)
1289 MEMORY_BASIC_INFORMATION info;
1290 SIZE_T dummy, read_bytes;
1292 /* Not implemented in all windows versions */
1293 if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) return;
1295 /* without PROCESS_VM_OPERATION */
1296 hproc = OpenProcess(PROCESS_ALL_ACCESS & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1297 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1299 SetLastError(0xdeadbeef);
1300 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1302 ok(!addr1, "VirtualAllocEx should fail\n");
1303 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1306 read_bytes = 0xdeadbeef;
1307 SetLastError(0xdeadbeef);
1308 ok(ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes),
1309 "ReadProcessMemory error %d\n", GetLastError());
1310 ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
1314 hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1315 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1317 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1319 ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
1321 if (addr1 == NULL) /* FIXME: remove once Wine is fixed */
1322 addr1 = pVirtualAllocEx(GetCurrentProcess(), 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1324 /* without PROCESS_QUERY_INFORMATION */
1325 SetLastError(0xdeadbeef);
1326 ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
1327 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1328 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1330 /* without PROCESS_VM_READ */
1331 read_bytes = 0xdeadbeef;
1332 SetLastError(0xdeadbeef);
1333 ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
1334 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1335 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1336 ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
1340 hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
1342 memset(&info, 0xaa, sizeof(info));
1343 ok(VirtualQueryEx(hproc, addr1, &info, sizeof(info)) == sizeof(info),
1344 "VirtualQueryEx error %d\n", GetLastError());
1346 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
1347 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
1348 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
1349 ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
1350 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
1351 /* NT reports Protect == 0 for a not committed memory block */
1352 ok(info.Protect == 0 /* NT */ ||
1353 info.Protect == PAGE_NOACCESS, /* Win9x */
1354 "%x != PAGE_NOACCESS\n", info.Protect);
1355 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
1357 SetLastError(0xdeadbeef);
1359 ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
1360 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1361 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1367 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
1374 ok(b, "Basic init of CreateProcess test\n");
1379 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1387 test_DebuggingFlag();
1391 /* things that can be tested:
1392 * lookup: check the way program to be executed is searched
1393 * handles: check the handle inheritance stuff (+sec options)
1394 * console: check if console creation parameters work