Fixed a typo in CryptExportKey.
[wine/hacks.git] / dlls / kernel / tests / process.c
blob7d962a9f9b0f85b3662211b02cab7129cd23aadf
1 /*
2 * Unit test suite for CreateProcess function.
4 * Copyright 2002 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <stdlib.h>
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wincon.h"
31 #include "winnls.h"
33 static char base[MAX_PATH];
34 static char selfname[MAX_PATH];
35 static char resfile[MAX_PATH];
37 static int myARGC;
38 static char** myARGV;
40 /* As some environment variables get very long on Unix, we only test for
41 * the first 127 bytes.
42 * Note that increasing this value past 256 may exceed the buffer size
43 * limitations of the *Profile functions (at least on Wine).
45 #define MAX_LISTED_ENV_VAR 128
47 /* ---------------- portable memory allocation thingie */
49 static char memory[1024*32];
50 static char* memory_index = memory;
52 static char* grab_memory(size_t len)
54 char* ret = memory_index;
55 /* align on dword */
56 len = (len + 3) & ~3;
57 memory_index += len;
58 assert(memory_index <= memory + sizeof(memory));
59 return ret;
62 static void release_memory(void)
64 memory_index = memory;
67 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
69 static const char* encodeA(const char* str)
71 char* ptr;
72 size_t len,i;
74 if (!str) return "";
75 len = strlen(str) + 1;
76 ptr = grab_memory(len * 2 + 1);
77 for (i = 0; i < len; i++)
78 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
79 ptr[2 * len] = '\0';
80 return ptr;
83 static const char* encodeW(const WCHAR* str)
85 char* ptr;
86 size_t len,i;
88 if (!str) return "";
89 len = lstrlenW(str) + 1;
90 ptr = grab_memory(len * 4 + 1);
91 assert(ptr);
92 for (i = 0; i < len; i++)
93 sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
94 ptr[4 * len] = '\0';
95 return ptr;
98 static unsigned decode_char(char c)
100 if (c >= '0' && c <= '9') return c - '0';
101 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
102 assert(c >= 'A' && c <= 'F');
103 return c - 'A' + 10;
106 static char* decodeA(const char* str)
108 char* ptr;
109 size_t len,i;
111 len = strlen(str) / 2;
112 if (!len--) return NULL;
113 ptr = grab_memory(len + 1);
114 for (i = 0; i < len; i++)
115 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
116 ptr[len] = '\0';
117 return ptr;
120 #if 0
121 /* This will be needed to decode Unicode strings saved by the child process
122 * when we test Unicode functions.
124 static WCHAR* decodeW(const char* str)
126 size_t len;
127 WCHAR* ptr;
128 int i;
130 len = strlen(str) / 4;
131 if (!len--) return NULL;
132 ptr = (WCHAR*)grab_memory(len * 2 + 1);
133 for (i = 0; i < len; i++)
134 ptr[i] = (decode_char(str[4 * i]) << 12) |
135 (decode_char(str[4 * i + 1]) << 8) |
136 (decode_char(str[4 * i + 2]) << 4) |
137 (decode_char(str[4 * i + 3]) << 0);
138 ptr[len] = '\0';
139 return ptr;
141 #endif
143 /******************************************************************
144 * init
146 * generates basic information like:
147 * base: absolute path to curr dir
148 * selfname: the way to reinvoke ourselves
150 static int init(void)
152 myARGC = winetest_get_mainargs( &myARGV );
153 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
154 strcpy(selfname, myARGV[0]);
155 return 1;
158 /******************************************************************
159 * get_file_name
161 * generates an absolute file_name for temporary file
164 static void get_file_name(char* buf)
166 char path[MAX_PATH];
168 buf[0] = '\0';
169 GetTempPathA(sizeof(path), path);
170 GetTempFileNameA(path, "wt", 0, buf);
173 /******************************************************************
174 * static void childPrintf
177 static void childPrintf(HANDLE h, const char* fmt, ...)
179 va_list valist;
180 char buffer[1024+4*MAX_LISTED_ENV_VAR];
181 DWORD w;
183 va_start(valist, fmt);
184 vsprintf(buffer, fmt, valist);
185 va_end(valist);
186 WriteFile(h, buffer, strlen(buffer), &w, NULL);
190 /******************************************************************
191 * doChild
193 * output most of the information in the child process
195 static void doChild(const char* file, const char* option)
197 STARTUPINFOA siA;
198 STARTUPINFOW siW;
199 int i;
200 char* ptrA;
201 WCHAR* ptrW;
202 char bufA[MAX_PATH];
203 WCHAR bufW[MAX_PATH];
204 HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
206 if (hFile == INVALID_HANDLE_VALUE) return;
208 /* output of startup info (Ansi) */
209 GetStartupInfoA(&siA);
210 childPrintf(hFile,
211 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
212 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
213 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
214 "dwFlags=%lu\nwShowWindow=%u\n"
215 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
216 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
217 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
218 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
219 siA.dwFlags, siA.wShowWindow,
220 (DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
222 /* since GetStartupInfoW is only implemented in win2k,
223 * zero out before calling so we can notice the difference
225 memset(&siW, 0, sizeof(siW));
226 GetStartupInfoW(&siW);
227 childPrintf(hFile,
228 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
229 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
230 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
231 "dwFlags=%lu\nwShowWindow=%u\n"
232 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
233 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
234 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
235 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
236 siW.dwFlags, siW.wShowWindow,
237 (DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
239 /* Arguments */
240 childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
241 for (i = 0; i < myARGC; i++)
243 childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
245 childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
247 #if 0
248 int argcW;
249 WCHAR** argvW;
251 /* this is part of shell32... and should be tested there */
252 argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
253 for (i = 0; i < argcW; i++)
255 childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
257 #endif
258 childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
260 /* output of environment (Ansi) */
261 ptrA = GetEnvironmentStringsA();
262 if (ptrA)
264 char env_var[MAX_LISTED_ENV_VAR];
266 childPrintf(hFile, "[EnvironmentA]\n");
267 i = 0;
268 while (*ptrA)
270 strncpy(env_var, ptrA, MAX_LISTED_ENV_VAR - 1);
271 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
272 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
273 i++;
274 ptrA += strlen(ptrA) + 1;
276 childPrintf(hFile, "len=%d\n\n", i);
279 /* output of environment (Unicode) */
280 ptrW = GetEnvironmentStringsW();
281 if (ptrW)
283 WCHAR env_var[MAX_LISTED_ENV_VAR];
285 childPrintf(hFile, "[EnvironmentW]\n");
286 i = 0;
287 while (*ptrW)
289 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
290 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
291 childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
292 i++;
293 ptrW += lstrlenW(ptrW) + 1;
295 childPrintf(hFile, "len=%d\n\n", i);
298 childPrintf(hFile, "[Misc]\n");
299 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
300 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
301 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
302 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
303 childPrintf(hFile, "\n");
305 if (option && strcmp(option, "console") == 0)
307 CONSOLE_SCREEN_BUFFER_INFO sbi;
308 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
309 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
310 DWORD modeIn, modeOut;
312 childPrintf(hFile, "[Console]\n");
313 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
315 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
316 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
317 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
318 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
319 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
320 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
322 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
323 GetConsoleCP(), GetConsoleOutputCP());
324 if (GetConsoleMode(hConIn, &modeIn))
325 childPrintf(hFile, "InputMode=%ld\n", modeIn);
326 if (GetConsoleMode(hConOut, &modeOut))
327 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
329 /* now that we have written all relevant information, let's change it */
330 ok(SetConsoleCP(1252), "Setting CP\n");
331 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
332 ok(SetConsoleMode(hConIn, modeIn ^ 1), "Setting mode (%ld)\n", GetLastError());
333 ok(SetConsoleMode(hConOut, modeOut ^ 1), "Setting mode (%ld)\n", GetLastError());
334 sbi.dwCursorPosition.X ^= 1;
335 sbi.dwCursorPosition.Y ^= 1;
336 ok(SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition), "Setting cursor position (%ld)\n", GetLastError());
338 if (option && strcmp(option, "stdhandle") == 0)
340 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
341 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
343 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
345 char buf[1024];
346 DWORD r, w;
348 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
349 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
350 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
354 if (option && strcmp(option, "exit_code") == 0)
356 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
357 CloseHandle(hFile);
358 ExitProcess(123);
361 CloseHandle(hFile);
364 static char* getChildString(const char* sect, const char* key)
366 char buf[1024+4*MAX_LISTED_ENV_VAR];
367 char* ret;
369 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
370 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
371 assert(!(strlen(buf) & 1));
372 ret = decodeA(buf);
373 return ret;
376 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
377 * others... (windows uses stricmp while Un*x uses strcasecmp...)
379 static int wtstrcasecmp(const char* p1, const char* p2)
381 char c1, c2;
383 c1 = c2 = '@';
384 while (c1 == c2 && c1)
386 c1 = *p1++; c2 = *p2++;
387 if (c1 != c2)
389 c1 = toupper(c1); c2 = toupper(c2);
392 return c1 - c2;
395 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
397 if (!s1 && !s2) return 0;
398 if (!s2) return -1;
399 if (!s1) return 1;
400 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
403 #define okChildString(sect, key, expect) \
404 do { \
405 char* result = getChildString((sect), (key)); \
406 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
407 } while (0)
409 #define okChildIString(sect, key, expect) \
410 do { \
411 char* result = getChildString(sect, key); \
412 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
413 } while (0)
415 /* using !expect insures that the test will fail if the sect/key isn't present
416 * in result file
418 #define okChildInt(sect, key, expect) \
419 do { \
420 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
421 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
422 } while (0)
424 static void test_Startup(void)
426 char buffer[MAX_PATH];
427 PROCESS_INFORMATION info;
428 STARTUPINFOA startup,si;
430 /* let's start simplistic */
431 memset(&startup, 0, sizeof(startup));
432 startup.cb = sizeof(startup);
433 startup.dwFlags = STARTF_USESHOWWINDOW;
434 startup.wShowWindow = SW_SHOWNORMAL;
436 get_file_name(resfile);
437 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
438 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
439 /* wait for child to terminate */
440 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
441 /* child process has changed result file, so let profile functions know about it */
442 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
444 GetStartupInfoA(&si);
445 okChildInt("StartupInfoA", "cb", startup.cb);
446 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
447 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
448 okChildInt("StartupInfoA", "dwX", startup.dwX);
449 okChildInt("StartupInfoA", "dwY", startup.dwY);
450 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
451 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
452 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
453 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
454 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
455 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
456 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
457 release_memory();
458 assert(DeleteFileA(resfile) != 0);
460 /* not so simplistic now */
461 memset(&startup, 0, sizeof(startup));
462 startup.cb = sizeof(startup);
463 startup.dwFlags = STARTF_USESHOWWINDOW;
464 startup.wShowWindow = SW_SHOWNORMAL;
465 startup.lpTitle = "I'm the title string";
466 startup.lpDesktop = "I'm the desktop string";
467 startup.dwXCountChars = 0x12121212;
468 startup.dwYCountChars = 0x23232323;
469 startup.dwX = 0x34343434;
470 startup.dwY = 0x45454545;
471 startup.dwXSize = 0x56565656;
472 startup.dwYSize = 0x67676767;
473 startup.dwFillAttribute = 0xA55A;
475 get_file_name(resfile);
476 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
477 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
478 /* wait for child to terminate */
479 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
480 /* child process has changed result file, so let profile functions know about it */
481 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
483 okChildInt("StartupInfoA", "cb", startup.cb);
484 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
485 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
486 okChildInt("StartupInfoA", "dwX", startup.dwX);
487 okChildInt("StartupInfoA", "dwY", startup.dwY);
488 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
489 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
490 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
491 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
492 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
493 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
494 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
495 release_memory();
496 assert(DeleteFileA(resfile) != 0);
498 /* not so simplistic now */
499 memset(&startup, 0, sizeof(startup));
500 startup.cb = sizeof(startup);
501 startup.dwFlags = STARTF_USESHOWWINDOW;
502 startup.wShowWindow = SW_SHOWNORMAL;
503 startup.lpTitle = "I'm the title string";
504 startup.lpDesktop = NULL;
505 startup.dwXCountChars = 0x12121212;
506 startup.dwYCountChars = 0x23232323;
507 startup.dwX = 0x34343434;
508 startup.dwY = 0x45454545;
509 startup.dwXSize = 0x56565656;
510 startup.dwYSize = 0x67676767;
511 startup.dwFillAttribute = 0xA55A;
513 get_file_name(resfile);
514 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
515 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
516 /* wait for child to terminate */
517 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
518 /* child process has changed result file, so let profile functions know about it */
519 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
521 okChildInt("StartupInfoA", "cb", startup.cb);
522 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
523 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
524 okChildInt("StartupInfoA", "dwX", startup.dwX);
525 okChildInt("StartupInfoA", "dwY", startup.dwY);
526 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
527 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
528 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
529 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
530 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
531 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
532 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
533 release_memory();
534 assert(DeleteFileA(resfile) != 0);
536 /* not so simplistic now */
537 memset(&startup, 0, sizeof(startup));
538 startup.cb = sizeof(startup);
539 startup.dwFlags = STARTF_USESHOWWINDOW;
540 startup.wShowWindow = SW_SHOWNORMAL;
541 startup.lpTitle = "I'm the title string";
542 startup.lpDesktop = "";
543 startup.dwXCountChars = 0x12121212;
544 startup.dwYCountChars = 0x23232323;
545 startup.dwX = 0x34343434;
546 startup.dwY = 0x45454545;
547 startup.dwXSize = 0x56565656;
548 startup.dwYSize = 0x67676767;
549 startup.dwFillAttribute = 0xA55A;
551 get_file_name(resfile);
552 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
553 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
554 /* wait for child to terminate */
555 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
556 /* child process has changed result file, so let profile functions know about it */
557 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
559 okChildInt("StartupInfoA", "cb", startup.cb);
560 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
561 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
562 okChildInt("StartupInfoA", "dwX", startup.dwX);
563 okChildInt("StartupInfoA", "dwY", startup.dwY);
564 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
565 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
566 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
567 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
568 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
569 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
570 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
571 release_memory();
572 assert(DeleteFileA(resfile) != 0);
574 /* not so simplistic now */
575 memset(&startup, 0, sizeof(startup));
576 startup.cb = sizeof(startup);
577 startup.dwFlags = STARTF_USESHOWWINDOW;
578 startup.wShowWindow = SW_SHOWNORMAL;
579 startup.lpTitle = NULL;
580 startup.lpDesktop = "I'm the desktop string";
581 startup.dwXCountChars = 0x12121212;
582 startup.dwYCountChars = 0x23232323;
583 startup.dwX = 0x34343434;
584 startup.dwY = 0x45454545;
585 startup.dwXSize = 0x56565656;
586 startup.dwYSize = 0x67676767;
587 startup.dwFillAttribute = 0xA55A;
589 get_file_name(resfile);
590 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
591 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
592 /* wait for child to terminate */
593 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
594 /* child process has changed result file, so let profile functions know about it */
595 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
597 okChildInt("StartupInfoA", "cb", startup.cb);
598 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
599 okChildString("StartupInfoA", "lpTitle", si.lpTitle);
600 okChildInt("StartupInfoA", "dwX", startup.dwX);
601 okChildInt("StartupInfoA", "dwY", startup.dwY);
602 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
603 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
604 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
605 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
606 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
607 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
608 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
609 release_memory();
610 assert(DeleteFileA(resfile) != 0);
612 /* not so simplistic now */
613 memset(&startup, 0, sizeof(startup));
614 startup.cb = sizeof(startup);
615 startup.dwFlags = STARTF_USESHOWWINDOW;
616 startup.wShowWindow = SW_SHOWNORMAL;
617 startup.lpTitle = "";
618 startup.lpDesktop = "I'm the desktop string";
619 startup.dwXCountChars = 0x12121212;
620 startup.dwYCountChars = 0x23232323;
621 startup.dwX = 0x34343434;
622 startup.dwY = 0x45454545;
623 startup.dwXSize = 0x56565656;
624 startup.dwYSize = 0x67676767;
625 startup.dwFillAttribute = 0xA55A;
627 get_file_name(resfile);
628 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
629 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
630 /* wait for child to terminate */
631 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
632 /* child process has changed result file, so let profile functions know about it */
633 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
635 okChildInt("StartupInfoA", "cb", startup.cb);
636 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
637 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
638 okChildInt("StartupInfoA", "dwX", startup.dwX);
639 okChildInt("StartupInfoA", "dwY", startup.dwY);
640 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
641 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
642 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
643 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
644 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
645 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
646 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
647 release_memory();
648 assert(DeleteFileA(resfile) != 0);
650 /* not so simplistic now */
651 memset(&startup, 0, sizeof(startup));
652 startup.cb = sizeof(startup);
653 startup.dwFlags = STARTF_USESHOWWINDOW;
654 startup.wShowWindow = SW_SHOWNORMAL;
655 startup.lpTitle = "";
656 startup.lpDesktop = "";
657 startup.dwXCountChars = 0x12121212;
658 startup.dwYCountChars = 0x23232323;
659 startup.dwX = 0x34343434;
660 startup.dwY = 0x45454545;
661 startup.dwXSize = 0x56565656;
662 startup.dwYSize = 0x67676767;
663 startup.dwFillAttribute = 0xA55A;
665 get_file_name(resfile);
666 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
667 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
668 /* wait for child to terminate */
669 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
670 /* child process has changed result file, so let profile functions know about it */
671 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
673 okChildInt("StartupInfoA", "cb", startup.cb);
674 todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
675 todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
676 okChildInt("StartupInfoA", "dwX", startup.dwX);
677 okChildInt("StartupInfoA", "dwY", startup.dwY);
678 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
679 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
680 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
681 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
682 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
683 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
684 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
685 release_memory();
686 assert(DeleteFileA(resfile) != 0);
688 /* TODO: test for A/W and W/A and W/W */
691 static void test_CommandLine(void)
693 char buffer[MAX_PATH];
694 PROCESS_INFORMATION info;
695 STARTUPINFOA startup;
697 memset(&startup, 0, sizeof(startup));
698 startup.cb = sizeof(startup);
699 startup.dwFlags = STARTF_USESHOWWINDOW;
700 startup.wShowWindow = SW_SHOWNORMAL;
702 /* the basics */
703 get_file_name(resfile);
704 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
705 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
706 /* wait for child to terminate */
707 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
708 /* child process has changed result file, so let profile functions know about it */
709 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
711 okChildInt("Arguments", "argcA", 4);
712 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
713 okChildString("Arguments", "argvA4", NULL);
714 okChildString("Arguments", "CommandLineA", buffer);
715 release_memory();
716 assert(DeleteFileA(resfile) != 0);
718 memset(&startup, 0, sizeof(startup));
719 startup.cb = sizeof(startup);
720 startup.dwFlags = STARTF_USESHOWWINDOW;
721 startup.wShowWindow = SW_SHOWNORMAL;
723 /* from Frangois */
724 get_file_name(resfile);
725 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
726 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
727 /* wait for child to terminate */
728 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
729 /* child process has changed result file, so let profile functions know about it */
730 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
732 okChildInt("Arguments", "argcA", 6);
733 okChildString("Arguments", "argvA3", "a\"b\\");
734 okChildString("Arguments", "argvA4", "c\"");
735 okChildString("Arguments", "argvA5", "d");
736 okChildString("Arguments", "argvA6", NULL);
737 okChildString("Arguments", "CommandLineA", buffer);
738 release_memory();
739 assert(DeleteFileA(resfile) != 0);
742 static void test_Directory(void)
744 char buffer[MAX_PATH];
745 PROCESS_INFORMATION info;
746 STARTUPINFOA startup;
747 char windir[MAX_PATH];
749 memset(&startup, 0, sizeof(startup));
750 startup.cb = sizeof(startup);
751 startup.dwFlags = STARTF_USESHOWWINDOW;
752 startup.wShowWindow = SW_SHOWNORMAL;
754 /* the basics */
755 get_file_name(resfile);
756 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
757 GetWindowsDirectoryA( windir, sizeof(windir) );
758 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
759 /* wait for child to terminate */
760 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
761 /* child process has changed result file, so let profile functions know about it */
762 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
764 okChildIString("Misc", "CurrDirA", windir);
765 release_memory();
766 assert(DeleteFileA(resfile) != 0);
769 static BOOL is_str_env_drive_dir(const char* str)
771 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
772 str[3] == '=' && str[4] == str[1];
775 /* compared expected child's environment (in gesA) from actual
776 * environment our child got
778 static void cmpEnvironment(const char* gesA)
780 int i, clen;
781 const char* ptrA;
782 char* res;
783 char key[32];
784 BOOL found;
786 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
788 /* now look each parent env in child */
789 if ((ptrA = gesA) != NULL)
791 while (*ptrA)
793 for (i = 0; i < clen; i++)
795 sprintf(key, "env%d", i);
796 res = getChildString("EnvironmentA", key);
797 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
798 break;
800 found = i < clen;
801 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
803 ptrA += strlen(ptrA) + 1;
804 release_memory();
807 /* and each child env in parent */
808 for (i = 0; i < clen; i++)
810 sprintf(key, "env%d", i);
811 res = getChildString("EnvironmentA", key);
812 if ((ptrA = gesA) != NULL)
814 while (*ptrA)
816 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
817 break;
818 ptrA += strlen(ptrA) + 1;
820 if (!*ptrA) ptrA = NULL;
823 if (!is_str_env_drive_dir(res))
825 found = ptrA != NULL;
826 ok(found, "Child-env string %s isn't in parent process\n", res);
828 /* else => should also test we get the right per drive default directory here... */
832 static void test_Environment(void)
834 char buffer[MAX_PATH];
835 PROCESS_INFORMATION info;
836 STARTUPINFOA startup;
837 char child_env[4096];
838 char* ptr;
839 char* env;
841 memset(&startup, 0, sizeof(startup));
842 startup.cb = sizeof(startup);
843 startup.dwFlags = STARTF_USESHOWWINDOW;
844 startup.wShowWindow = SW_SHOWNORMAL;
846 /* the basics */
847 get_file_name(resfile);
848 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
849 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
850 /* wait for child to terminate */
851 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
852 /* child process has changed result file, so let profile functions know about it */
853 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
855 cmpEnvironment(GetEnvironmentStringsA());
856 release_memory();
857 assert(DeleteFileA(resfile) != 0);
859 memset(&startup, 0, sizeof(startup));
860 startup.cb = sizeof(startup);
861 startup.dwFlags = STARTF_USESHOWWINDOW;
862 startup.wShowWindow = SW_SHOWNORMAL;
864 /* the basics */
865 get_file_name(resfile);
866 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
867 ptr = child_env;
868 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
869 ptr += strlen(ptr) + 1;
870 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
871 ptr += strlen(ptr) + 1;
872 strcpy(ptr, "FOO=BAR");
873 ptr += strlen(ptr) + 1;
874 strcpy(ptr, "BAR=FOOBAR");
875 ptr += strlen(ptr) + 1;
876 /* copy all existing variables except:
877 * - WINELOADER
878 * - PATH (already set above)
879 * - the directory definitions (=[A-Z]:=)
881 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
883 if (strncmp(env, "PATH=", 5) != 0 &&
884 strncmp(env, "WINELOADER=", 11) != 0 &&
885 !is_str_env_drive_dir(env))
887 strcpy(ptr, env);
888 ptr += strlen(ptr) + 1;
891 *ptr = '\0';
892 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
893 /* wait for child to terminate */
894 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
895 /* child process has changed result file, so let profile functions know about it */
896 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
898 cmpEnvironment(child_env);
900 release_memory();
901 assert(DeleteFileA(resfile) != 0);
904 static void test_SuspendFlag(void)
906 char buffer[MAX_PATH];
907 PROCESS_INFORMATION info;
908 STARTUPINFOA startup, us;
909 DWORD exit_status;
911 /* let's start simplistic */
912 memset(&startup, 0, sizeof(startup));
913 startup.cb = sizeof(startup);
914 startup.dwFlags = STARTF_USESHOWWINDOW;
915 startup.wShowWindow = SW_SHOWNORMAL;
917 get_file_name(resfile);
918 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
919 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
921 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
922 Sleep(8000);
923 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
924 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
926 /* wait for child to terminate */
927 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
928 /* child process has changed result file, so let profile functions know about it */
929 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
931 GetStartupInfoA(&us);
933 okChildInt("StartupInfoA", "cb", startup.cb);
934 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
935 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
936 okChildInt("StartupInfoA", "dwX", startup.dwX);
937 okChildInt("StartupInfoA", "dwY", startup.dwY);
938 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
939 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
940 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
941 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
942 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
943 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
944 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
945 release_memory();
946 assert(DeleteFileA(resfile) != 0);
949 static void test_DebuggingFlag(void)
951 char buffer[MAX_PATH];
952 PROCESS_INFORMATION info;
953 STARTUPINFOA startup, us;
954 DEBUG_EVENT de;
955 unsigned dbg = 0;
957 /* let's start simplistic */
958 memset(&startup, 0, sizeof(startup));
959 startup.cb = sizeof(startup);
960 startup.dwFlags = STARTF_USESHOWWINDOW;
961 startup.wShowWindow = SW_SHOWNORMAL;
963 get_file_name(resfile);
964 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
965 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
967 /* get all startup events up to the entry point break exception */
970 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
971 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
972 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
973 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
975 ok(dbg, "I have seen a debug event\n");
976 /* wait for child to terminate */
977 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
978 /* child process has changed result file, so let profile functions know about it */
979 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
981 GetStartupInfoA(&us);
983 okChildInt("StartupInfoA", "cb", startup.cb);
984 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
985 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
986 okChildInt("StartupInfoA", "dwX", startup.dwX);
987 okChildInt("StartupInfoA", "dwY", startup.dwY);
988 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
989 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
990 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
991 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
992 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
993 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
994 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
995 release_memory();
996 assert(DeleteFileA(resfile) != 0);
999 static void test_Console(void)
1001 char buffer[MAX_PATH];
1002 PROCESS_INFORMATION info;
1003 STARTUPINFOA startup, us;
1004 SECURITY_ATTRIBUTES sa;
1005 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1006 DWORD modeIn, modeOut, modeInC, modeOutC;
1007 DWORD cpIn, cpOut, cpInC, cpOutC;
1008 DWORD w;
1009 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1010 const char* msg = "This is a std-handle inheritance test.";
1011 unsigned msg_len;
1013 memset(&startup, 0, sizeof(startup));
1014 startup.cb = sizeof(startup);
1015 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1016 startup.wShowWindow = SW_SHOWNORMAL;
1018 sa.nLength = sizeof(sa);
1019 sa.lpSecurityDescriptor = NULL;
1020 sa.bInheritHandle = TRUE;
1022 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1023 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1025 /* first, we need to be sure we're attached to a console */
1026 if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE)
1028 /* we're not attached to a console, let's do it */
1029 AllocConsole();
1030 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1031 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1033 /* now verify everything's ok */
1034 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1035 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1036 startup.hStdError = startup.hStdOutput;
1038 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1039 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1040 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1041 cpIn = GetConsoleCP();
1042 cpOut = GetConsoleOutputCP();
1044 get_file_name(resfile);
1045 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1046 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1048 /* wait for child to terminate */
1049 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1050 /* child process has changed result file, so let profile functions know about it */
1051 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1053 /* now get the modification the child has made, and resets parents expected values */
1054 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1055 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1056 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1058 SetConsoleMode(startup.hStdInput, modeIn);
1059 SetConsoleMode(startup.hStdOutput, modeOut);
1061 cpInC = GetConsoleCP();
1062 cpOutC = GetConsoleOutputCP();
1063 SetConsoleCP(cpIn);
1064 SetConsoleOutputCP(cpOut);
1066 GetStartupInfoA(&us);
1068 okChildInt("StartupInfoA", "cb", startup.cb);
1069 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1070 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1071 okChildInt("StartupInfoA", "dwX", startup.dwX);
1072 okChildInt("StartupInfoA", "dwY", startup.dwY);
1073 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1074 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1075 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1076 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1077 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1078 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1079 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1081 /* check child correctly inherited the console */
1082 okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1083 okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1084 okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1085 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1086 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1087 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1088 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1089 okChildInt("Console", "Attributes", sbi.wAttributes);
1090 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1091 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1092 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1093 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1094 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1095 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1096 okChildInt("Console", "InputCP", cpIn);
1097 okChildInt("Console", "OutputCP", cpOut);
1098 okChildInt("Console", "InputMode", modeIn);
1099 okChildInt("Console", "OutputMode", modeOut);
1101 todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)\n", cpInC, cpIn);
1102 todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)\n", cpOutC, cpOut);
1103 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1104 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1105 ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position\n");
1106 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1108 release_memory();
1109 assert(DeleteFileA(resfile) != 0);
1111 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1112 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1113 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1114 "Duplicating as inheritable child-output pipe\n");
1115 CloseHandle(hChildOut);
1117 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1118 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1119 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1120 "Duplicating as inheritable child-input pipe\n");
1121 CloseHandle(hChildIn);
1123 memset(&startup, 0, sizeof(startup));
1124 startup.cb = sizeof(startup);
1125 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1126 startup.wShowWindow = SW_SHOWNORMAL;
1127 startup.hStdInput = hChildInInh;
1128 startup.hStdOutput = hChildOutInh;
1129 startup.hStdError = hChildOutInh;
1131 get_file_name(resfile);
1132 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1133 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1134 ok(CloseHandle(hChildInInh), "Closing handle\n");
1135 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1137 msg_len = strlen(msg) + 1;
1138 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1139 ok(w == msg_len, "Should have written %u bytes, actually wrote %lu\n", msg_len, w);
1140 memset(buffer, 0, sizeof(buffer));
1141 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1142 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1144 /* wait for child to terminate */
1145 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1146 /* child process has changed result file, so let profile functions know about it */
1147 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1149 okChildString("StdHandle", "msg", msg);
1151 release_memory();
1152 assert(DeleteFileA(resfile) != 0);
1155 static void test_ExitCode(void)
1157 char buffer[MAX_PATH];
1158 PROCESS_INFORMATION info;
1159 STARTUPINFOA startup;
1160 DWORD code;
1162 /* let's start simplistic */
1163 memset(&startup, 0, sizeof(startup));
1164 startup.cb = sizeof(startup);
1165 startup.dwFlags = STARTF_USESHOWWINDOW;
1166 startup.wShowWindow = SW_SHOWNORMAL;
1168 get_file_name(resfile);
1169 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1170 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1172 /* wait for child to terminate */
1173 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1174 /* child process has changed result file, so let profile functions know about it */
1175 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1177 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1178 okChildInt("ExitCode", "value", code);
1180 release_memory();
1181 assert(DeleteFileA(resfile) != 0);
1184 START_TEST(process)
1186 int b = init();
1187 ok(b, "Basic init of CreateProcess test\n");
1188 if (!b) return;
1190 if (myARGC >= 3)
1192 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1193 return;
1195 test_Startup();
1196 test_CommandLine();
1197 test_Directory();
1198 test_Environment();
1199 test_SuspendFlag();
1200 test_DebuggingFlag();
1201 test_Console();
1202 test_ExitCode();
1203 /* things that can be tested:
1204 * lookup: check the way program to be executed is searched
1205 * handles: check the handle inheritance stuff (+sec options)
1206 * console: check if console creation parameters work