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 BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
38 /* ############################### */
39 static char base[MAX_PATH];
40 static char selfname[MAX_PATH];
42 static char resfile[MAX_PATH];
47 /* As some environment variables get very long on Unix, we only test for
48 * the first 127 bytes.
49 * Note that increasing this value past 256 may exceed the buffer size
50 * limitations of the *Profile functions (at least on Wine).
52 #define MAX_LISTED_ENV_VAR 128
54 /* ---------------- portable memory allocation thingie */
56 static char memory[1024*256];
57 static char* memory_index = memory;
59 static char* grab_memory(size_t len)
61 char* ret = memory_index;
65 assert(memory_index <= memory + sizeof(memory));
69 static void release_memory(void)
71 memory_index = memory;
74 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
76 static const char* encodeA(const char* str)
82 len = strlen(str) + 1;
83 ptr = grab_memory(len * 2 + 1);
84 for (i = 0; i < len; i++)
85 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
90 static const char* encodeW(const WCHAR* str)
96 len = lstrlenW(str) + 1;
97 ptr = grab_memory(len * 4 + 1);
99 for (i = 0; i < len; i++)
100 sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
105 static unsigned decode_char(char c)
107 if (c >= '0' && c <= '9') return c - '0';
108 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
109 assert(c >= 'A' && c <= 'F');
113 static char* decodeA(const char* str)
118 len = strlen(str) / 2;
119 if (!len--) return NULL;
120 ptr = grab_memory(len + 1);
121 for (i = 0; i < len; i++)
122 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
128 /* This will be needed to decode Unicode strings saved by the child process
129 * when we test Unicode functions.
131 static WCHAR* decodeW(const char* str)
137 len = strlen(str) / 4;
138 if (!len--) return NULL;
139 ptr = (WCHAR*)grab_memory(len * 2 + 1);
140 for (i = 0; i < len; i++)
141 ptr[i] = (decode_char(str[4 * i]) << 12) |
142 (decode_char(str[4 * i + 1]) << 8) |
143 (decode_char(str[4 * i + 2]) << 4) |
144 (decode_char(str[4 * i + 3]) << 0);
150 /******************************************************************
153 * generates basic information like:
154 * base: absolute path to curr dir
155 * selfname: the way to reinvoke ourselves
156 * exename: executable without the path
157 * function-pointers, which are not implemented in all windows versions
159 static int init(void)
163 myARGC = winetest_get_mainargs( &myARGV );
164 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
165 strcpy(selfname, myARGV[0]);
167 /* Strip the path of selfname */
168 if ((p = strrchr(selfname, '\\')) != NULL) exename = p + 1;
169 else exename = selfname;
171 if ((p = strrchr(exename, '/')) != NULL) exename = p + 1;
173 hkernel32 = GetModuleHandleA("kernel32");
174 pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
175 pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
179 /******************************************************************
182 * generates an absolute file_name for temporary file
185 static void get_file_name(char* buf)
190 GetTempPathA(sizeof(path), path);
191 GetTempFileNameA(path, "wt", 0, buf);
194 /******************************************************************
195 * static void childPrintf
198 static void childPrintf(HANDLE h, const char* fmt, ...)
201 char buffer[1024+4*MAX_LISTED_ENV_VAR];
204 va_start(valist, fmt);
205 vsprintf(buffer, fmt, valist);
207 WriteFile(h, buffer, strlen(buffer), &w, NULL);
211 /******************************************************************
214 * output most of the information in the child process
216 static void doChild(const char* file, const char* option)
224 WCHAR bufW[MAX_PATH];
225 HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
228 if (hFile == INVALID_HANDLE_VALUE) return;
230 /* output of startup info (Ansi) */
231 GetStartupInfoA(&siA);
233 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
234 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
235 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
236 "dwFlags=%lu\nwShowWindow=%u\n"
237 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
238 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
239 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
240 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
241 siA.dwFlags, siA.wShowWindow,
242 (DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
244 /* since GetStartupInfoW is only implemented in win2k,
245 * zero out before calling so we can notice the difference
247 memset(&siW, 0, sizeof(siW));
248 GetStartupInfoW(&siW);
250 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
251 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
252 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
253 "dwFlags=%lu\nwShowWindow=%u\n"
254 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
255 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
256 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
257 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
258 siW.dwFlags, siW.wShowWindow,
259 (DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
262 childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
263 for (i = 0; i < myARGC; i++)
265 childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
267 childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
273 /* this is part of shell32... and should be tested there */
274 argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
275 for (i = 0; i < argcW; i++)
277 childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
280 childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
282 /* output of environment (Ansi) */
283 ptrA = GetEnvironmentStringsA();
286 char env_var[MAX_LISTED_ENV_VAR];
288 childPrintf(hFile, "[EnvironmentA]\n");
292 lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
293 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
295 ptrA += strlen(ptrA) + 1;
297 childPrintf(hFile, "len=%d\n\n", i);
300 /* output of environment (Unicode) */
301 ptrW = GetEnvironmentStringsW();
304 WCHAR env_var[MAX_LISTED_ENV_VAR];
306 childPrintf(hFile, "[EnvironmentW]\n");
310 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
311 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
312 childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
314 ptrW += lstrlenW(ptrW) + 1;
316 childPrintf(hFile, "len=%d\n\n", i);
319 childPrintf(hFile, "[Misc]\n");
320 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
321 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
322 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
323 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
324 childPrintf(hFile, "\n");
326 if (option && strcmp(option, "console") == 0)
328 CONSOLE_SCREEN_BUFFER_INFO sbi;
329 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
330 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
331 DWORD modeIn, modeOut;
333 childPrintf(hFile, "[Console]\n");
334 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
336 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
337 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
338 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
339 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
340 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
341 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
343 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
344 GetConsoleCP(), GetConsoleOutputCP());
345 if (GetConsoleMode(hConIn, &modeIn))
346 childPrintf(hFile, "InputMode=%ld\n", modeIn);
347 if (GetConsoleMode(hConOut, &modeOut))
348 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
350 /* now that we have written all relevant information, let's change it */
351 ok(SetConsoleCP(1252), "Setting CP\n");
352 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
353 ret = SetConsoleMode(hConIn, modeIn ^ 1);
354 ok( ret, "Setting mode (%d)\n", GetLastError());
355 ret = SetConsoleMode(hConOut, modeOut ^ 1);
356 ok( ret, "Setting mode (%d)\n", GetLastError());
357 sbi.dwCursorPosition.X ^= 1;
358 sbi.dwCursorPosition.Y ^= 1;
359 ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
360 ok( ret, "Setting cursor position (%d)\n", GetLastError());
362 if (option && strcmp(option, "stdhandle") == 0)
364 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
365 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
367 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
372 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
373 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
374 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
378 if (option && strcmp(option, "exit_code") == 0)
380 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
388 static char* getChildString(const char* sect, const char* key)
390 char buf[1024+4*MAX_LISTED_ENV_VAR];
393 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
394 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
395 assert(!(strlen(buf) & 1));
400 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
401 * others... (windows uses stricmp while Un*x uses strcasecmp...)
403 static int wtstrcasecmp(const char* p1, const char* p2)
408 while (c1 == c2 && c1)
410 c1 = *p1++; c2 = *p2++;
413 c1 = toupper(c1); c2 = toupper(c2);
419 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
421 if (!s1 && !s2) return 0;
424 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
427 #define okChildString(sect, key, expect) \
429 char* result = getChildString((sect), (key)); \
430 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
433 #define okChildIString(sect, key, expect) \
435 char* result = getChildString(sect, key); \
436 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
439 /* using !expect ensures that the test will fail if the sect/key isn't present
442 #define okChildInt(sect, key, expect) \
444 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
445 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
448 static void test_Startup(void)
450 char buffer[MAX_PATH];
451 PROCESS_INFORMATION info;
452 STARTUPINFOA startup,si;
453 static CHAR title[] = "I'm the title string",
454 desktop[] = "I'm the desktop string",
457 /* let's start simplistic */
458 memset(&startup, 0, sizeof(startup));
459 startup.cb = sizeof(startup);
460 startup.dwFlags = STARTF_USESHOWWINDOW;
461 startup.wShowWindow = SW_SHOWNORMAL;
463 get_file_name(resfile);
464 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
465 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
466 /* wait for child to terminate */
467 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
468 /* child process has changed result file, so let profile functions know about it */
469 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
471 GetStartupInfoA(&si);
472 okChildInt("StartupInfoA", "cb", startup.cb);
473 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
474 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
475 okChildInt("StartupInfoA", "dwX", startup.dwX);
476 okChildInt("StartupInfoA", "dwY", startup.dwY);
477 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
478 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
479 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
480 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
481 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
482 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
483 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
485 assert(DeleteFileA(resfile) != 0);
487 /* not so simplistic now */
488 memset(&startup, 0, sizeof(startup));
489 startup.cb = sizeof(startup);
490 startup.dwFlags = STARTF_USESHOWWINDOW;
491 startup.wShowWindow = SW_SHOWNORMAL;
492 startup.lpTitle = title;
493 startup.lpDesktop = desktop;
494 startup.dwXCountChars = 0x12121212;
495 startup.dwYCountChars = 0x23232323;
496 startup.dwX = 0x34343434;
497 startup.dwY = 0x45454545;
498 startup.dwXSize = 0x56565656;
499 startup.dwYSize = 0x67676767;
500 startup.dwFillAttribute = 0xA55A;
502 get_file_name(resfile);
503 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
504 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
505 /* wait for child to terminate */
506 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
507 /* child process has changed result file, so let profile functions know about it */
508 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
510 okChildInt("StartupInfoA", "cb", startup.cb);
511 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
512 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
513 okChildInt("StartupInfoA", "dwX", startup.dwX);
514 okChildInt("StartupInfoA", "dwY", startup.dwY);
515 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
516 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
517 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
518 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
519 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
520 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
521 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
523 assert(DeleteFileA(resfile) != 0);
525 /* not so simplistic now */
526 memset(&startup, 0, sizeof(startup));
527 startup.cb = sizeof(startup);
528 startup.dwFlags = STARTF_USESHOWWINDOW;
529 startup.wShowWindow = SW_SHOWNORMAL;
530 startup.lpTitle = title;
531 startup.lpDesktop = NULL;
532 startup.dwXCountChars = 0x12121212;
533 startup.dwYCountChars = 0x23232323;
534 startup.dwX = 0x34343434;
535 startup.dwY = 0x45454545;
536 startup.dwXSize = 0x56565656;
537 startup.dwYSize = 0x67676767;
538 startup.dwFillAttribute = 0xA55A;
540 get_file_name(resfile);
541 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
542 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
543 /* wait for child to terminate */
544 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
545 /* child process has changed result file, so let profile functions know about it */
546 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
548 okChildInt("StartupInfoA", "cb", startup.cb);
549 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
550 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
551 okChildInt("StartupInfoA", "dwX", startup.dwX);
552 okChildInt("StartupInfoA", "dwY", startup.dwY);
553 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
554 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
555 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
556 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
557 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
558 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
559 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
561 assert(DeleteFileA(resfile) != 0);
563 /* not so simplistic now */
564 memset(&startup, 0, sizeof(startup));
565 startup.cb = sizeof(startup);
566 startup.dwFlags = STARTF_USESHOWWINDOW;
567 startup.wShowWindow = SW_SHOWNORMAL;
568 startup.lpTitle = title;
569 startup.lpDesktop = empty;
570 startup.dwXCountChars = 0x12121212;
571 startup.dwYCountChars = 0x23232323;
572 startup.dwX = 0x34343434;
573 startup.dwY = 0x45454545;
574 startup.dwXSize = 0x56565656;
575 startup.dwYSize = 0x67676767;
576 startup.dwFillAttribute = 0xA55A;
578 get_file_name(resfile);
579 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
580 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
581 /* wait for child to terminate */
582 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
583 /* child process has changed result file, so let profile functions know about it */
584 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
586 okChildInt("StartupInfoA", "cb", startup.cb);
587 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
588 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
589 okChildInt("StartupInfoA", "dwX", startup.dwX);
590 okChildInt("StartupInfoA", "dwY", startup.dwY);
591 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
592 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
593 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
594 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
595 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
596 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
597 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
599 assert(DeleteFileA(resfile) != 0);
601 /* not so simplistic now */
602 memset(&startup, 0, sizeof(startup));
603 startup.cb = sizeof(startup);
604 startup.dwFlags = STARTF_USESHOWWINDOW;
605 startup.wShowWindow = SW_SHOWNORMAL;
606 startup.lpTitle = NULL;
607 startup.lpDesktop = desktop;
608 startup.dwXCountChars = 0x12121212;
609 startup.dwYCountChars = 0x23232323;
610 startup.dwX = 0x34343434;
611 startup.dwY = 0x45454545;
612 startup.dwXSize = 0x56565656;
613 startup.dwYSize = 0x67676767;
614 startup.dwFillAttribute = 0xA55A;
616 get_file_name(resfile);
617 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
618 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
619 /* wait for child to terminate */
620 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
621 /* child process has changed result file, so let profile functions know about it */
622 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
624 okChildInt("StartupInfoA", "cb", startup.cb);
625 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
626 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
627 okChildInt("StartupInfoA", "dwX", startup.dwX);
628 okChildInt("StartupInfoA", "dwY", startup.dwY);
629 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
630 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
631 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
632 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
633 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
634 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
635 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
637 assert(DeleteFileA(resfile) != 0);
639 /* not so simplistic now */
640 memset(&startup, 0, sizeof(startup));
641 startup.cb = sizeof(startup);
642 startup.dwFlags = STARTF_USESHOWWINDOW;
643 startup.wShowWindow = SW_SHOWNORMAL;
644 startup.lpTitle = empty;
645 startup.lpDesktop = desktop;
646 startup.dwXCountChars = 0x12121212;
647 startup.dwYCountChars = 0x23232323;
648 startup.dwX = 0x34343434;
649 startup.dwY = 0x45454545;
650 startup.dwXSize = 0x56565656;
651 startup.dwYSize = 0x67676767;
652 startup.dwFillAttribute = 0xA55A;
654 get_file_name(resfile);
655 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
656 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
657 /* wait for child to terminate */
658 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
659 /* child process has changed result file, so let profile functions know about it */
660 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
662 okChildInt("StartupInfoA", "cb", startup.cb);
663 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
664 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
665 okChildInt("StartupInfoA", "dwX", startup.dwX);
666 okChildInt("StartupInfoA", "dwY", startup.dwY);
667 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
668 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
669 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
670 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
671 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
672 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
673 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
675 assert(DeleteFileA(resfile) != 0);
677 /* not so simplistic now */
678 memset(&startup, 0, sizeof(startup));
679 startup.cb = sizeof(startup);
680 startup.dwFlags = STARTF_USESHOWWINDOW;
681 startup.wShowWindow = SW_SHOWNORMAL;
682 startup.lpTitle = empty;
683 startup.lpDesktop = empty;
684 startup.dwXCountChars = 0x12121212;
685 startup.dwYCountChars = 0x23232323;
686 startup.dwX = 0x34343434;
687 startup.dwY = 0x45454545;
688 startup.dwXSize = 0x56565656;
689 startup.dwYSize = 0x67676767;
690 startup.dwFillAttribute = 0xA55A;
692 get_file_name(resfile);
693 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
694 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
695 /* wait for child to terminate */
696 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
697 /* child process has changed result file, so let profile functions know about it */
698 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
700 okChildInt("StartupInfoA", "cb", startup.cb);
701 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
702 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
703 okChildInt("StartupInfoA", "dwX", startup.dwX);
704 okChildInt("StartupInfoA", "dwY", startup.dwY);
705 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
706 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
707 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
708 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
709 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
710 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
711 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
713 assert(DeleteFileA(resfile) != 0);
715 /* TODO: test for A/W and W/A and W/W */
718 static void test_CommandLine(void)
720 char buffer[MAX_PATH], fullpath[MAX_PATH], *lpFilePart, *p;
721 PROCESS_INFORMATION info;
722 STARTUPINFOA startup;
726 memset(&startup, 0, sizeof(startup));
727 startup.cb = sizeof(startup);
728 startup.dwFlags = STARTF_USESHOWWINDOW;
729 startup.wShowWindow = SW_SHOWNORMAL;
732 get_file_name(resfile);
733 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
734 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
735 /* wait for child to terminate */
736 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
737 /* child process has changed result file, so let profile functions know about it */
738 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
740 okChildInt("Arguments", "argcA", 4);
741 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
742 okChildString("Arguments", "argvA4", NULL);
743 okChildString("Arguments", "CommandLineA", buffer);
745 assert(DeleteFileA(resfile) != 0);
747 memset(&startup, 0, sizeof(startup));
748 startup.cb = sizeof(startup);
749 startup.dwFlags = STARTF_USESHOWWINDOW;
750 startup.wShowWindow = SW_SHOWNORMAL;
753 get_file_name(resfile);
754 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
755 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
756 /* wait for child to terminate */
757 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
758 /* child process has changed result file, so let profile functions know about it */
759 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
761 okChildInt("Arguments", "argcA", 6);
762 okChildString("Arguments", "argvA3", "a\"b\\");
763 okChildString("Arguments", "argvA4", "c\"");
764 okChildString("Arguments", "argvA5", "d");
765 okChildString("Arguments", "argvA6", NULL);
766 okChildString("Arguments", "CommandLineA", buffer);
768 assert(DeleteFileA(resfile) != 0);
770 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
771 get_file_name(resfile);
772 /* Use exename to avoid buffer containing things like 'C:' */
773 sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
774 SetLastError(0xdeadbeef);
775 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
776 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
777 /* wait for child to terminate */
778 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
779 /* child process has changed result file, so let profile functions know about it */
780 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
781 sprintf(buffer, "./%s", exename);
782 okChildString("Arguments", "argvA0", buffer);
784 assert(DeleteFileA(resfile) != 0);
786 get_file_name(resfile);
787 /* Use exename to avoid buffer containing things like 'C:' */
788 sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
789 SetLastError(0xdeadbeef);
790 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
791 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
792 /* wait for child to terminate */
793 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
794 /* child process has changed result file, so let profile functions know about it */
795 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
796 sprintf(buffer, ".\\%s", exename);
797 okChildString("Arguments", "argvA0", buffer);
799 assert(DeleteFileA(resfile) != 0);
801 get_file_name(resfile);
802 len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
803 assert ( lpFilePart != 0);
804 *(lpFilePart -1 ) = 0;
805 p = strrchr(fullpath, '\\');
807 /* Use exename to avoid buffer containing things like 'C:' */
808 sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, exename, resfile);
809 SetLastError(0xdeadbeef);
810 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
811 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
812 /* wait for child to terminate */
813 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
814 /* child process has changed result file, so let profile functions know about it */
815 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
816 sprintf(buffer, "..%s/%s", p, exename);
817 okChildString("Arguments", "argvA0", buffer);
819 assert(DeleteFileA(resfile) != 0);
823 static void test_Directory(void)
825 char buffer[MAX_PATH];
826 PROCESS_INFORMATION info;
827 STARTUPINFOA startup;
828 char windir[MAX_PATH];
829 static CHAR cmdline[] = "winver.exe";
831 memset(&startup, 0, sizeof(startup));
832 startup.cb = sizeof(startup);
833 startup.dwFlags = STARTF_USESHOWWINDOW;
834 startup.wShowWindow = SW_SHOWNORMAL;
837 get_file_name(resfile);
838 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
839 GetWindowsDirectoryA( windir, sizeof(windir) );
840 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
841 /* wait for child to terminate */
842 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
843 /* child process has changed result file, so let profile functions know about it */
844 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
846 okChildIString("Misc", "CurrDirA", windir);
848 assert(DeleteFileA(resfile) != 0);
850 /* search PATH for the exe if directory is NULL */
851 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
852 ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
854 /* if any directory is provided, don't search PATH, error on bad directory */
855 SetLastError(0xdeadbeef);
856 memset(&info, 0, sizeof(info));
857 ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
858 NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
859 ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
860 ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
863 static BOOL is_str_env_drive_dir(const char* str)
865 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
866 str[3] == '=' && str[4] == str[1];
869 /* compared expected child's environment (in gesA) from actual
870 * environment our child got
872 static void cmpEnvironment(const char* gesA)
880 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
882 /* now look each parent env in child */
883 if ((ptrA = gesA) != NULL)
887 for (i = 0; i < clen; i++)
889 sprintf(key, "env%d", i);
890 res = getChildString("EnvironmentA", key);
891 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
895 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
897 ptrA += strlen(ptrA) + 1;
901 /* and each child env in parent */
902 for (i = 0; i < clen; i++)
904 sprintf(key, "env%d", i);
905 res = getChildString("EnvironmentA", key);
906 if ((ptrA = gesA) != NULL)
910 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
912 ptrA += strlen(ptrA) + 1;
914 if (!*ptrA) ptrA = NULL;
917 if (!is_str_env_drive_dir(res))
919 found = ptrA != NULL;
920 ok(found, "Child-env string %s isn't in parent process\n", res);
922 /* else => should also test we get the right per drive default directory here... */
926 static void test_Environment(void)
928 char buffer[MAX_PATH];
929 PROCESS_INFORMATION info;
930 STARTUPINFOA startup;
937 memset(&startup, 0, sizeof(startup));
938 startup.cb = sizeof(startup);
939 startup.dwFlags = STARTF_USESHOWWINDOW;
940 startup.wShowWindow = SW_SHOWNORMAL;
943 get_file_name(resfile);
944 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
945 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
946 /* wait for child to terminate */
947 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
948 /* child process has changed result file, so let profile functions know about it */
949 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
951 cmpEnvironment(GetEnvironmentStringsA());
953 assert(DeleteFileA(resfile) != 0);
955 memset(&startup, 0, sizeof(startup));
956 startup.cb = sizeof(startup);
957 startup.dwFlags = STARTF_USESHOWWINDOW;
958 startup.wShowWindow = SW_SHOWNORMAL;
961 get_file_name(resfile);
962 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
965 ptr = GetEnvironmentStringsA();
968 slen = strlen(ptr)+1;
969 child_env_len += slen;
972 /* Add space for additional environment variables */
973 child_env_len += 256;
974 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
977 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
978 ptr += strlen(ptr) + 1;
979 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
980 ptr += strlen(ptr) + 1;
981 strcpy(ptr, "FOO=BAR");
982 ptr += strlen(ptr) + 1;
983 strcpy(ptr, "BAR=FOOBAR");
984 ptr += strlen(ptr) + 1;
985 /* copy all existing variables except:
987 * - PATH (already set above)
988 * - the directory definitions (=[A-Z]:=)
990 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
992 if (strncmp(env, "PATH=", 5) != 0 &&
993 strncmp(env, "WINELOADER=", 11) != 0 &&
994 !is_str_env_drive_dir(env))
997 ptr += strlen(ptr) + 1;
1001 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
1002 /* wait for child to terminate */
1003 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1004 /* child process has changed result file, so let profile functions know about it */
1005 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1007 cmpEnvironment(child_env);
1009 HeapFree(GetProcessHeap(), 0, child_env);
1011 assert(DeleteFileA(resfile) != 0);
1014 static void test_SuspendFlag(void)
1016 char buffer[MAX_PATH];
1017 PROCESS_INFORMATION info;
1018 STARTUPINFOA startup, us;
1021 /* let's start simplistic */
1022 memset(&startup, 0, sizeof(startup));
1023 startup.cb = sizeof(startup);
1024 startup.dwFlags = STARTF_USESHOWWINDOW;
1025 startup.wShowWindow = SW_SHOWNORMAL;
1027 get_file_name(resfile);
1028 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1029 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
1031 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1033 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1034 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
1036 /* wait for child to terminate */
1037 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1038 /* child process has changed result file, so let profile functions know about it */
1039 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1041 GetStartupInfoA(&us);
1043 okChildInt("StartupInfoA", "cb", startup.cb);
1044 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1045 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1046 okChildInt("StartupInfoA", "dwX", startup.dwX);
1047 okChildInt("StartupInfoA", "dwY", startup.dwY);
1048 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1049 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1050 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1051 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1052 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1053 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1054 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1056 assert(DeleteFileA(resfile) != 0);
1059 static void test_DebuggingFlag(void)
1061 char buffer[MAX_PATH];
1062 PROCESS_INFORMATION info;
1063 STARTUPINFOA startup, us;
1067 /* let's start simplistic */
1068 memset(&startup, 0, sizeof(startup));
1069 startup.cb = sizeof(startup);
1070 startup.dwFlags = STARTF_USESHOWWINDOW;
1071 startup.wShowWindow = SW_SHOWNORMAL;
1073 get_file_name(resfile);
1074 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1075 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1077 /* get all startup events up to the entry point break exception */
1080 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
1081 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
1082 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
1083 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
1085 ok(dbg, "I have seen a debug event\n");
1086 /* wait for child to terminate */
1087 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1088 /* child process has changed result file, so let profile functions know about it */
1089 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1091 GetStartupInfoA(&us);
1093 okChildInt("StartupInfoA", "cb", startup.cb);
1094 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1095 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1096 okChildInt("StartupInfoA", "dwX", startup.dwX);
1097 okChildInt("StartupInfoA", "dwY", startup.dwY);
1098 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1099 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1100 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1101 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1102 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1103 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1104 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1106 assert(DeleteFileA(resfile) != 0);
1109 static BOOL is_console(HANDLE h)
1111 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1114 static void test_Console(void)
1116 char buffer[MAX_PATH];
1117 PROCESS_INFORMATION info;
1118 STARTUPINFOA startup, us;
1119 SECURITY_ATTRIBUTES sa;
1120 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1121 DWORD modeIn, modeOut, modeInC, modeOutC;
1122 DWORD cpIn, cpOut, cpInC, cpOutC;
1124 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1125 const char* msg = "This is a std-handle inheritance test.";
1128 memset(&startup, 0, sizeof(startup));
1129 startup.cb = sizeof(startup);
1130 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1131 startup.wShowWindow = SW_SHOWNORMAL;
1133 sa.nLength = sizeof(sa);
1134 sa.lpSecurityDescriptor = NULL;
1135 sa.bInheritHandle = TRUE;
1137 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1138 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1140 /* first, we need to be sure we're attached to a console */
1141 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1143 /* we're not attached to a console, let's do it */
1145 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1146 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1148 /* now verify everything's ok */
1149 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1150 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1151 startup.hStdError = startup.hStdOutput;
1153 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1154 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1155 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1156 cpIn = GetConsoleCP();
1157 cpOut = GetConsoleOutputCP();
1159 get_file_name(resfile);
1160 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1161 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1163 /* wait for child to terminate */
1164 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1165 /* child process has changed result file, so let profile functions know about it */
1166 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1168 /* now get the modification the child has made, and resets parents expected values */
1169 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1170 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1171 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1173 SetConsoleMode(startup.hStdInput, modeIn);
1174 SetConsoleMode(startup.hStdOutput, modeOut);
1176 cpInC = GetConsoleCP();
1177 cpOutC = GetConsoleOutputCP();
1179 /* Try to set invalid CP */
1180 SetLastError(0xdeadbeef);
1181 ok(!SetConsoleCP(0), "Shouldn't succeed\n");
1182 ok(GetLastError()==ERROR_INVALID_PARAMETER,
1183 "GetLastError: expecting %u got %u\n",
1184 ERROR_INVALID_PARAMETER, GetLastError());
1186 SetLastError(0xdeadbeef);
1187 ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
1188 ok(GetLastError()==ERROR_INVALID_PARAMETER,
1189 "GetLastError: expecting %u got %u\n",
1190 ERROR_INVALID_PARAMETER, GetLastError());
1193 SetConsoleOutputCP(cpOut);
1195 GetStartupInfoA(&us);
1197 okChildInt("StartupInfoA", "cb", startup.cb);
1198 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1199 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1200 okChildInt("StartupInfoA", "dwX", startup.dwX);
1201 okChildInt("StartupInfoA", "dwY", startup.dwY);
1202 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1203 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1204 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1205 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1206 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1207 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1208 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1210 /* check child correctly inherited the console */
1211 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1212 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1213 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1214 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1215 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1216 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1217 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1218 okChildInt("Console", "Attributes", sbi.wAttributes);
1219 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1220 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1221 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1222 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1223 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1224 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1225 okChildInt("Console", "InputCP", cpIn);
1226 okChildInt("Console", "OutputCP", cpOut);
1227 okChildInt("Console", "InputMode", modeIn);
1228 okChildInt("Console", "OutputMode", modeOut);
1230 ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
1231 ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
1232 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1233 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1234 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1235 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1238 assert(DeleteFileA(resfile) != 0);
1240 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1241 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1242 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1243 "Duplicating as inheritable child-output pipe\n");
1244 CloseHandle(hChildOut);
1246 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1247 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1248 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1249 "Duplicating as inheritable child-input pipe\n");
1250 CloseHandle(hChildIn);
1252 memset(&startup, 0, sizeof(startup));
1253 startup.cb = sizeof(startup);
1254 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1255 startup.wShowWindow = SW_SHOWNORMAL;
1256 startup.hStdInput = hChildInInh;
1257 startup.hStdOutput = hChildOutInh;
1258 startup.hStdError = hChildOutInh;
1260 get_file_name(resfile);
1261 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1262 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1263 ok(CloseHandle(hChildInInh), "Closing handle\n");
1264 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1266 msg_len = strlen(msg) + 1;
1267 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1268 ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
1269 memset(buffer, 0, sizeof(buffer));
1270 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1271 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
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 okChildString("StdHandle", "msg", msg);
1281 assert(DeleteFileA(resfile) != 0);
1284 static void test_ExitCode(void)
1286 char buffer[MAX_PATH];
1287 PROCESS_INFORMATION info;
1288 STARTUPINFOA startup;
1291 /* let's start simplistic */
1292 memset(&startup, 0, sizeof(startup));
1293 startup.cb = sizeof(startup);
1294 startup.dwFlags = STARTF_USESHOWWINDOW;
1295 startup.wShowWindow = SW_SHOWNORMAL;
1297 get_file_name(resfile);
1298 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1299 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1301 /* wait for child to terminate */
1302 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1303 /* child process has changed result file, so let profile functions know about it */
1304 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1306 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1307 okChildInt("ExitCode", "value", code);
1310 assert(DeleteFileA(resfile) != 0);
1313 static void test_OpenProcess(void)
1317 MEMORY_BASIC_INFORMATION info;
1318 SIZE_T dummy, read_bytes;
1320 /* not exported in all windows versions */
1321 if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) {
1322 skip("VirtualAllocEx not found\n");
1326 /* without PROCESS_VM_OPERATION */
1327 hproc = OpenProcess(PROCESS_ALL_ACCESS & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1328 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1330 SetLastError(0xdeadbeef);
1331 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1332 ok(!addr1, "VirtualAllocEx should fail\n");
1333 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1336 skip("VirtualAllocEx not implemented\n");
1339 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1341 read_bytes = 0xdeadbeef;
1342 SetLastError(0xdeadbeef);
1343 ok(ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes),
1344 "ReadProcessMemory error %d\n", GetLastError());
1345 ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
1349 hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1350 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1352 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1353 ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
1355 /* without PROCESS_QUERY_INFORMATION */
1356 SetLastError(0xdeadbeef);
1357 ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
1358 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1359 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1361 /* without PROCESS_VM_READ */
1362 read_bytes = 0xdeadbeef;
1363 SetLastError(0xdeadbeef);
1364 ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
1365 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1366 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1367 ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
1371 hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
1373 memset(&info, 0xaa, sizeof(info));
1374 ok(VirtualQueryEx(hproc, addr1, &info, sizeof(info)) == sizeof(info),
1375 "VirtualQueryEx error %d\n", GetLastError());
1377 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
1378 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
1379 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
1380 ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
1381 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
1382 /* NT reports Protect == 0 for a not committed memory block */
1383 ok(info.Protect == 0 /* NT */ ||
1384 info.Protect == PAGE_NOACCESS, /* Win9x */
1385 "%x != PAGE_NOACCESS\n", info.Protect);
1386 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
1388 SetLastError(0xdeadbeef);
1389 ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
1390 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1391 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1395 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
1401 ok(b, "Basic init of CreateProcess test\n");
1406 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1414 test_DebuggingFlag();
1418 /* things that can be tested:
1419 * lookup: check the way program to be executed is searched
1420 * handles: check the handle inheritance stuff (+sec options)
1421 * console: check if console creation parameters work