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;
714 memset(&startup, 0, sizeof(startup));
715 startup.cb = sizeof(startup);
716 startup.dwFlags = STARTF_USESHOWWINDOW;
717 startup.wShowWindow = SW_SHOWNORMAL;
720 get_file_name(resfile);
721 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
722 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
723 /* wait for child to terminate */
724 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
725 /* child process has changed result file, so let profile functions know about it */
726 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
728 okChildInt("Arguments", "argcA", 4);
729 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
730 okChildString("Arguments", "argvA4", NULL);
731 okChildString("Arguments", "CommandLineA", buffer);
733 assert(DeleteFileA(resfile) != 0);
735 memset(&startup, 0, sizeof(startup));
736 startup.cb = sizeof(startup);
737 startup.dwFlags = STARTF_USESHOWWINDOW;
738 startup.wShowWindow = SW_SHOWNORMAL;
741 get_file_name(resfile);
742 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
743 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
744 /* wait for child to terminate */
745 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
746 /* child process has changed result file, so let profile functions know about it */
747 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
749 okChildInt("Arguments", "argcA", 6);
750 okChildString("Arguments", "argvA3", "a\"b\\");
751 okChildString("Arguments", "argvA4", "c\"");
752 okChildString("Arguments", "argvA5", "d");
753 okChildString("Arguments", "argvA6", NULL);
754 okChildString("Arguments", "CommandLineA", buffer);
756 assert(DeleteFileA(resfile) != 0);
758 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
759 get_file_name(resfile);
760 sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
761 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
762 /* wait for child to terminate */
763 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
764 /* child process has changed result file, so let profile functions know about it */
765 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
766 sprintf(buffer, "./%s", selfname);
767 okChildString("Arguments", "argvA0", buffer);
769 assert(DeleteFileA(resfile) != 0);
771 get_file_name(resfile);
772 sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
773 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
774 /* wait for child to terminate */
775 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
776 /* child process has changed result file, so let profile functions know about it */
777 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
778 sprintf(buffer, ".\\%s", selfname);
779 okChildString("Arguments", "argvA0", buffer);
781 assert(DeleteFileA(resfile) != 0);
783 get_file_name(resfile);
784 len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
785 assert ( lpFilePart != 0);
786 *(lpFilePart -1 ) = 0;
787 p = strrchr(fullpath, '\\');
789 sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, selfname, resfile);
790 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
791 /* wait for child to terminate */
792 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
793 /* child process has changed result file, so let profile functions know about it */
794 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
795 sprintf(buffer, "..%s/%s", p, selfname);
796 okChildString("Arguments", "argvA0", buffer);
798 assert(DeleteFileA(resfile) != 0);
802 static void test_Directory(void)
804 char buffer[MAX_PATH];
805 PROCESS_INFORMATION info;
806 STARTUPINFOA startup;
807 char windir[MAX_PATH];
808 static CHAR cmdline[] = "winver.exe";
810 memset(&startup, 0, sizeof(startup));
811 startup.cb = sizeof(startup);
812 startup.dwFlags = STARTF_USESHOWWINDOW;
813 startup.wShowWindow = SW_SHOWNORMAL;
816 get_file_name(resfile);
817 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
818 GetWindowsDirectoryA( windir, sizeof(windir) );
819 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
820 /* wait for child to terminate */
821 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
822 /* child process has changed result file, so let profile functions know about it */
823 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
825 okChildIString("Misc", "CurrDirA", windir);
827 assert(DeleteFileA(resfile) != 0);
829 /* search PATH for the exe if directory is NULL */
830 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
831 ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
833 /* if any directory is provided, don't search PATH, error on bad directory */
834 SetLastError(0xdeadbeef);
835 memset(&info, 0, sizeof(info));
836 ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
837 NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
838 ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
839 ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
842 static BOOL is_str_env_drive_dir(const char* str)
844 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
845 str[3] == '=' && str[4] == str[1];
848 /* compared expected child's environment (in gesA) from actual
849 * environment our child got
851 static void cmpEnvironment(const char* gesA)
859 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
861 /* now look each parent env in child */
862 if ((ptrA = gesA) != NULL)
866 for (i = 0; i < clen; i++)
868 sprintf(key, "env%d", i);
869 res = getChildString("EnvironmentA", key);
870 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
874 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
876 ptrA += strlen(ptrA) + 1;
880 /* and each child env in parent */
881 for (i = 0; i < clen; i++)
883 sprintf(key, "env%d", i);
884 res = getChildString("EnvironmentA", key);
885 if ((ptrA = gesA) != NULL)
889 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
891 ptrA += strlen(ptrA) + 1;
893 if (!*ptrA) ptrA = NULL;
896 if (!is_str_env_drive_dir(res))
898 found = ptrA != NULL;
899 ok(found, "Child-env string %s isn't in parent process\n", res);
901 /* else => should also test we get the right per drive default directory here... */
905 static void test_Environment(void)
907 char buffer[MAX_PATH];
908 PROCESS_INFORMATION info;
909 STARTUPINFOA startup;
916 memset(&startup, 0, sizeof(startup));
917 startup.cb = sizeof(startup);
918 startup.dwFlags = STARTF_USESHOWWINDOW;
919 startup.wShowWindow = SW_SHOWNORMAL;
922 get_file_name(resfile);
923 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
924 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
925 /* wait for child to terminate */
926 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
927 /* child process has changed result file, so let profile functions know about it */
928 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
930 cmpEnvironment(GetEnvironmentStringsA());
932 assert(DeleteFileA(resfile) != 0);
934 memset(&startup, 0, sizeof(startup));
935 startup.cb = sizeof(startup);
936 startup.dwFlags = STARTF_USESHOWWINDOW;
937 startup.wShowWindow = SW_SHOWNORMAL;
940 get_file_name(resfile);
941 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
944 ptr = GetEnvironmentStringsA();
947 slen = strlen(ptr)+1;
948 child_env_len += slen;
951 /* Add space for additional environment variables */
952 child_env_len += 256;
953 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
956 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
957 ptr += strlen(ptr) + 1;
958 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
959 ptr += strlen(ptr) + 1;
960 strcpy(ptr, "FOO=BAR");
961 ptr += strlen(ptr) + 1;
962 strcpy(ptr, "BAR=FOOBAR");
963 ptr += strlen(ptr) + 1;
964 /* copy all existing variables except:
966 * - PATH (already set above)
967 * - the directory definitions (=[A-Z]:=)
969 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
971 if (strncmp(env, "PATH=", 5) != 0 &&
972 strncmp(env, "WINELOADER=", 11) != 0 &&
973 !is_str_env_drive_dir(env))
976 ptr += strlen(ptr) + 1;
980 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
981 /* wait for child to terminate */
982 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
983 /* child process has changed result file, so let profile functions know about it */
984 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
986 cmpEnvironment(child_env);
988 HeapFree(GetProcessHeap(), 0, child_env);
990 assert(DeleteFileA(resfile) != 0);
993 static void test_SuspendFlag(void)
995 char buffer[MAX_PATH];
996 PROCESS_INFORMATION info;
997 STARTUPINFOA startup, us;
1000 /* let's start simplistic */
1001 memset(&startup, 0, sizeof(startup));
1002 startup.cb = sizeof(startup);
1003 startup.dwFlags = STARTF_USESHOWWINDOW;
1004 startup.wShowWindow = SW_SHOWNORMAL;
1006 get_file_name(resfile);
1007 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1008 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
1010 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1012 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1013 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
1015 /* wait for child to terminate */
1016 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1017 /* child process has changed result file, so let profile functions know about it */
1018 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1020 GetStartupInfoA(&us);
1022 okChildInt("StartupInfoA", "cb", startup.cb);
1023 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1024 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1025 okChildInt("StartupInfoA", "dwX", startup.dwX);
1026 okChildInt("StartupInfoA", "dwY", startup.dwY);
1027 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1028 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1029 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1030 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1031 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1032 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1033 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1035 assert(DeleteFileA(resfile) != 0);
1038 static void test_DebuggingFlag(void)
1040 char buffer[MAX_PATH];
1041 PROCESS_INFORMATION info;
1042 STARTUPINFOA startup, us;
1046 /* let's start simplistic */
1047 memset(&startup, 0, sizeof(startup));
1048 startup.cb = sizeof(startup);
1049 startup.dwFlags = STARTF_USESHOWWINDOW;
1050 startup.wShowWindow = SW_SHOWNORMAL;
1052 get_file_name(resfile);
1053 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1054 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1056 /* get all startup events up to the entry point break exception */
1059 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
1060 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
1061 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
1062 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
1064 ok(dbg, "I have seen a debug event\n");
1065 /* wait for child to terminate */
1066 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1067 /* child process has changed result file, so let profile functions know about it */
1068 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1070 GetStartupInfoA(&us);
1072 okChildInt("StartupInfoA", "cb", startup.cb);
1073 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1074 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1075 okChildInt("StartupInfoA", "dwX", startup.dwX);
1076 okChildInt("StartupInfoA", "dwY", startup.dwY);
1077 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1078 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1079 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1080 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1081 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1082 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1083 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1085 assert(DeleteFileA(resfile) != 0);
1088 static BOOL is_console(HANDLE h)
1090 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1093 static void test_Console(void)
1095 char buffer[MAX_PATH];
1096 PROCESS_INFORMATION info;
1097 STARTUPINFOA startup, us;
1098 SECURITY_ATTRIBUTES sa;
1099 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1100 DWORD modeIn, modeOut, modeInC, modeOutC;
1101 DWORD cpIn, cpOut, cpInC, cpOutC;
1103 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1104 const char* msg = "This is a std-handle inheritance test.";
1107 memset(&startup, 0, sizeof(startup));
1108 startup.cb = sizeof(startup);
1109 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1110 startup.wShowWindow = SW_SHOWNORMAL;
1112 sa.nLength = sizeof(sa);
1113 sa.lpSecurityDescriptor = NULL;
1114 sa.bInheritHandle = TRUE;
1116 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1117 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1119 /* first, we need to be sure we're attached to a console */
1120 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1122 /* we're not attached to a console, let's do it */
1124 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1125 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1127 /* now verify everything's ok */
1128 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1129 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1130 startup.hStdError = startup.hStdOutput;
1132 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1133 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1134 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1135 cpIn = GetConsoleCP();
1136 cpOut = GetConsoleOutputCP();
1138 get_file_name(resfile);
1139 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1140 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1142 /* wait for child to terminate */
1143 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1144 /* child process has changed result file, so let profile functions know about it */
1145 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1147 /* now get the modification the child has made, and resets parents expected values */
1148 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1149 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1150 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1152 SetConsoleMode(startup.hStdInput, modeIn);
1153 SetConsoleMode(startup.hStdOutput, modeOut);
1155 cpInC = GetConsoleCP();
1156 cpOutC = GetConsoleOutputCP();
1158 SetConsoleOutputCP(cpOut);
1160 GetStartupInfoA(&us);
1162 okChildInt("StartupInfoA", "cb", startup.cb);
1163 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1164 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1165 okChildInt("StartupInfoA", "dwX", startup.dwX);
1166 okChildInt("StartupInfoA", "dwY", startup.dwY);
1167 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1168 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1169 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1170 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1171 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1172 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1173 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1175 /* check child correctly inherited the console */
1176 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1177 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1178 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1179 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1180 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1181 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1182 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1183 okChildInt("Console", "Attributes", sbi.wAttributes);
1184 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1185 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1186 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1187 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1188 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1189 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1190 okChildInt("Console", "InputCP", cpIn);
1191 okChildInt("Console", "OutputCP", cpOut);
1192 okChildInt("Console", "InputMode", modeIn);
1193 okChildInt("Console", "OutputMode", modeOut);
1195 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
1196 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
1197 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1198 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1199 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1200 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1203 assert(DeleteFileA(resfile) != 0);
1205 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1206 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1207 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1208 "Duplicating as inheritable child-output pipe\n");
1209 CloseHandle(hChildOut);
1211 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1212 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1213 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1214 "Duplicating as inheritable child-input pipe\n");
1215 CloseHandle(hChildIn);
1217 memset(&startup, 0, sizeof(startup));
1218 startup.cb = sizeof(startup);
1219 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1220 startup.wShowWindow = SW_SHOWNORMAL;
1221 startup.hStdInput = hChildInInh;
1222 startup.hStdOutput = hChildOutInh;
1223 startup.hStdError = hChildOutInh;
1225 get_file_name(resfile);
1226 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1227 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1228 ok(CloseHandle(hChildInInh), "Closing handle\n");
1229 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1231 msg_len = strlen(msg) + 1;
1232 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1233 ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
1234 memset(buffer, 0, sizeof(buffer));
1235 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1236 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1238 /* wait for child to terminate */
1239 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1240 /* child process has changed result file, so let profile functions know about it */
1241 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1243 okChildString("StdHandle", "msg", msg);
1246 assert(DeleteFileA(resfile) != 0);
1249 static void test_ExitCode(void)
1251 char buffer[MAX_PATH];
1252 PROCESS_INFORMATION info;
1253 STARTUPINFOA startup;
1256 /* let's start simplistic */
1257 memset(&startup, 0, sizeof(startup));
1258 startup.cb = sizeof(startup);
1259 startup.dwFlags = STARTF_USESHOWWINDOW;
1260 startup.wShowWindow = SW_SHOWNORMAL;
1262 get_file_name(resfile);
1263 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1264 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1266 /* wait for child to terminate */
1267 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1268 /* child process has changed result file, so let profile functions know about it */
1269 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1271 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1272 okChildInt("ExitCode", "value", code);
1275 assert(DeleteFileA(resfile) != 0);
1278 static void test_OpenProcess(void)
1282 MEMORY_BASIC_INFORMATION info;
1283 SIZE_T dummy, read_bytes;
1285 /* Not implemented in all windows versions */
1286 if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) return;
1288 /* without PROCESS_VM_OPERATION */
1289 hproc = OpenProcess(PROCESS_ALL_ACCESS & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1290 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1292 SetLastError(0xdeadbeef);
1293 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1295 ok(!addr1, "VirtualAllocEx should fail\n");
1296 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1299 read_bytes = 0xdeadbeef;
1300 SetLastError(0xdeadbeef);
1301 ok(ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes),
1302 "ReadProcessMemory error %d\n", GetLastError());
1303 ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
1307 hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1308 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1310 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1312 ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
1314 if (addr1 == NULL) /* FIXME: remove once Wine is fixed */
1315 addr1 = pVirtualAllocEx(GetCurrentProcess(), 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1317 /* without PROCESS_QUERY_INFORMATION */
1318 SetLastError(0xdeadbeef);
1319 ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
1320 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1321 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1323 /* without PROCESS_VM_READ */
1324 read_bytes = 0xdeadbeef;
1325 SetLastError(0xdeadbeef);
1326 ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
1327 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1328 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1329 ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
1333 hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
1335 memset(&info, 0xaa, sizeof(info));
1336 ok(VirtualQueryEx(hproc, addr1, &info, sizeof(info)) == sizeof(info),
1337 "VirtualQueryEx error %d\n", GetLastError());
1339 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
1340 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
1341 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
1342 ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
1343 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
1344 /* NT reports Protect == 0 for a not committed memory block */
1345 ok(info.Protect == 0 /* NT */ ||
1346 info.Protect == PAGE_NOACCESS, /* Win9x */
1347 "%x != PAGE_NOACCESS\n", info.Protect);
1348 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
1350 SetLastError(0xdeadbeef);
1352 ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
1353 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1354 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1360 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
1367 ok(b, "Basic init of CreateProcess test\n");
1372 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1380 test_DebuggingFlag();
1384 /* things that can be tested:
1385 * lookup: check the way program to be executed is searched
1386 * handles: check the handle inheritance stuff (+sec options)
1387 * console: check if console creation parameters work