SHGetFileInfo should tolerate null pointers.
[wine] / dlls / kernel / tests / process.c
1 /*
2  * Unit test suite for CreateProcess function.
3  *
4  * Copyright 2002 Eric Pouech
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wincon.h"
29 #include "winnls.h"
30
31 static char     base[MAX_PATH];
32 static char     selfname[MAX_PATH];
33 static char     resfile[MAX_PATH];
34
35 static int      myARGC;
36 static char**   myARGV;
37
38 /* as some environment variables get very long on Unix, we only test for
39  * the first 127 bytes
40  */
41 #define MAX_LISTED_ENV_VAR      128
42
43 /* ---------------- portable memory allocation thingie */
44
45 static char     memory[1024*32];
46 static char*    memory_index = memory;
47
48 static char*    grab_memory(size_t len)
49 {
50     char*       ret = memory_index;
51     /* align on dword */
52     len = (len + 3) & ~3;
53     memory_index += len;
54     assert(memory_index <= memory + sizeof(memory));
55     return ret;
56 }
57
58 static void     release_memory(void)
59 {
60     memory_index = memory;
61 }
62
63 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
64
65 static char*    encodeA(const char* str)
66 {
67     char*       ptr;
68     size_t      len,i;
69
70     if (!str) return "";
71     len = strlen(str) + 1;
72     ptr = grab_memory(len * 2 + 1);
73     for (i = 0; i < len; i++)
74         sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
75     ptr[2 * len] = '\0';
76     return ptr;
77 }
78
79 static char*    encodeW(const WCHAR* str)
80 {
81     char*       ptr;
82     size_t      len,i;
83
84     if (!str) return "";
85     len = lstrlenW(str) + 1;
86     ptr = grab_memory(len * 4 + 1);
87     assert(ptr);
88     for (i = 0; i < len; i++)
89         sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
90     ptr[4 * len] = '\0';
91     return ptr;
92 }
93
94 static unsigned decode_char(char c)
95 {
96     if (c >= '0' && c <= '9') return c - '0';
97     if (c >= 'a' && c <= 'f') return c - 'a' + 10;
98     assert(c >= 'A' && c <= 'F');
99     return c - 'A' + 10;
100 }
101
102 static char*    decodeA(const char* str)
103 {
104     char*       ptr;
105     size_t      len,i;
106
107     len = strlen(str) / 2;
108     if (!len--) return NULL;
109     ptr = grab_memory(len + 1);
110     for (i = 0; i < len; i++)
111         ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
112     ptr[len] = '\0';
113     return ptr;
114 }
115
116 #if 0
117 /* This will be needed to decode Unicode strings saved by the child process
118  * when we test Unicode functions.
119  */
120 static WCHAR*   decodeW(const char* str)
121 {
122     size_t      len;
123     WCHAR*      ptr;
124     int         i;
125
126     len = strlen(str) / 4;
127     if (!len--) return NULL;
128     ptr = (WCHAR*)grab_memory(len * 2 + 1);
129     for (i = 0; i < len; i++)
130         ptr[i] = (decode_char(str[4 * i]) << 12) |
131             (decode_char(str[4 * i + 1]) << 8) |
132             (decode_char(str[4 * i + 2]) << 4) |
133             (decode_char(str[4 * i + 3]) << 0);
134     ptr[len] = '\0';
135     return ptr;
136 }
137 #endif
138
139 /******************************************************************
140  *              init
141  *
142  * generates basic information like:
143  *      base:           absolute path to curr dir
144  *      selfname:       the way to reinvoke ourselves
145  */
146 static int     init(void)
147 {
148     myARGC = winetest_get_mainargs( &myARGV );
149     if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
150     strcpy(selfname, myARGV[0]);
151     return 1;
152 }
153
154 /******************************************************************
155  *              get_file_name
156  *
157  * generates an absolute file_name for temporary file
158  *
159  */
160 static void     get_file_name(char* buf)
161 {
162     char        path[MAX_PATH];
163
164     buf[0] = '\0';
165     GetTempPathA(sizeof(path), path);
166     GetTempFileNameA(path, "wt", 0, buf);
167 }
168
169 /******************************************************************
170  *              static void     childPrintf
171  *
172  */
173 static void     childPrintf(HANDLE h, const char* fmt, ...)
174 {
175     va_list     valist;
176     char        buffer[2048];
177     DWORD       w;
178
179     va_start(valist, fmt);
180     vsprintf(buffer, fmt, valist);
181     va_end(valist);
182     WriteFile(h, buffer, strlen(buffer), &w, NULL);
183 }
184
185
186 /******************************************************************
187  *              doChild
188  *
189  * output most of the information in the child process
190  */
191 static void     doChild(const char* file, const char* option)
192 {
193     STARTUPINFOA        siA;
194     STARTUPINFOW        siW;
195     int                 i;
196     char*               ptrA;
197     WCHAR*              ptrW;
198     char                bufA[MAX_PATH];
199     WCHAR               bufW[MAX_PATH];
200     HANDLE              hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
201
202     if (hFile == INVALID_HANDLE_VALUE) return;
203
204     /* output of startup info (Ansi) */
205     GetStartupInfoA(&siA);
206     childPrintf(hFile,
207                 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
208                 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
209                 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
210                 "dwFlags=%lu\nwShowWindow=%u\n"
211                 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
212                 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
213                 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
214                 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
215                 siA.dwFlags, siA.wShowWindow,
216                 (DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
217
218     /* since GetStartupInfoW is only implemented in win2k,
219      * zero out before calling so we can notice the difference
220      */
221     memset(&siW, 0, sizeof(siW));
222     GetStartupInfoW(&siW);
223     childPrintf(hFile,
224                 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
225                 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
226                 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
227                 "dwFlags=%lu\nwShowWindow=%u\n"
228                 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
229                 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
230                 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
231                 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
232                 siW.dwFlags, siW.wShowWindow,
233                 (DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
234
235     /* Arguments */
236     childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
237     for (i = 0; i < myARGC; i++)
238     {
239         childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
240     }
241     childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
242
243 #if 0
244     int                 argcW;
245     WCHAR**             argvW;
246
247     /* this is part of shell32... and should be tested there */
248     argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
249     for (i = 0; i < argcW; i++)
250     {
251         childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
252     }
253 #endif
254     childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
255
256     /* output of environment (Ansi) */
257     ptrA = GetEnvironmentStringsA();
258     if (ptrA)
259     {
260         char    env_var[MAX_LISTED_ENV_VAR];
261
262         childPrintf(hFile, "[EnvironmentA]\n");
263         i = 0;
264         while (*ptrA)
265         {
266             strncpy(env_var, ptrA, MAX_LISTED_ENV_VAR - 1);
267             env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
268             childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
269             i++;
270             ptrA += strlen(ptrA) + 1;
271         }
272         childPrintf(hFile, "len=%d\n\n", i);
273     }
274
275     /* output of environment (Unicode) */
276     ptrW = GetEnvironmentStringsW();
277     if (ptrW)
278     {
279         WCHAR   env_var[MAX_LISTED_ENV_VAR];
280
281         childPrintf(hFile, "[EnvironmentW]\n");
282         i = 0;
283         while (*ptrW)
284         {
285             lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
286             env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
287             childPrintf(hFile, "env%d=%s\n", i, encodeW(ptrW));
288             i++;
289             ptrW += lstrlenW(ptrW) + 1;
290         }
291         childPrintf(hFile, "len=%d\n\n", i);
292     }
293
294     childPrintf(hFile, "[Misc]\n");
295     if (GetCurrentDirectoryA(sizeof(bufA), bufA))
296         childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
297     if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
298         childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
299     childPrintf(hFile, "\n");
300
301     if (option && strcmp(option, "console") == 0)
302     {
303         CONSOLE_SCREEN_BUFFER_INFO      sbi;
304         HANDLE hConIn  = GetStdHandle(STD_INPUT_HANDLE);
305         HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
306         DWORD modeIn, modeOut;
307
308         childPrintf(hFile, "[Console]\n");
309         if (GetConsoleScreenBufferInfo(hConOut, &sbi))
310         {
311             childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
312                         sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
313             childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
314                         sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
315             childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
316                         sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
317         }
318         childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
319                     GetConsoleCP(), GetConsoleOutputCP());
320         if (GetConsoleMode(hConIn, &modeIn))
321             childPrintf(hFile, "InputMode=%ld\n", modeIn);
322         if (GetConsoleMode(hConOut, &modeOut))
323             childPrintf(hFile, "OutputMode=%ld\n", modeOut);
324
325         /* now that we have written all relevant information, let's change it */
326         ok(SetConsoleCP(1252), "Setting CP");
327         ok(SetConsoleOutputCP(1252), "Setting SB CP");
328         ok(SetConsoleMode(hConIn, modeIn ^ 1), "Setting mode (%ld)", GetLastError());
329         ok(SetConsoleMode(hConOut, modeOut ^ 1), "Setting mode (%ld)", GetLastError());
330         sbi.dwCursorPosition.X ^= 1;
331         sbi.dwCursorPosition.Y ^= 1;
332         ok(SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition), "Setting cursor position (%ld)", GetLastError());
333     }
334     if (option && strcmp(option, "stdhandle") == 0)
335     {
336         HANDLE hStdIn  = GetStdHandle(STD_INPUT_HANDLE);
337         HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
338
339         if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
340         {
341             char buf[1024];
342             DWORD r, w;
343
344             ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe");
345             childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
346             ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writting message to output pipe");
347         }
348     }
349
350     CloseHandle(hFile);
351 }
352
353 static char* getChildString(const char* sect, const char* key)
354 {
355     char        buf[1024];
356     char*       ret;
357
358     GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
359     if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
360     assert(!(strlen(buf) & 1));
361     ret = decodeA(buf);
362     return ret;
363 }
364
365 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
366  * others... (windows uses stricmp while Un*x uses strcasecmp...)
367  */
368 static int wtstrcasecmp(const char* p1, const char* p2)
369 {
370     char c1, c2;
371
372     c1 = c2 = '@';
373     while (c1 == c2 && c1)
374     {
375         c1 = *p1++; c2 = *p2++;
376         if (c1 != c2)
377         {
378             c1 = toupper(c1); c2 = toupper(c2);
379         }
380     }
381     return c1 - c2;
382 }
383
384 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
385 {
386     if (!s1 && !s2) return 0;
387     if (!s2) return -1;
388     if (!s1) return 1;
389     return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
390 }
391
392 #define okChildString(sect, key, expect) \
393     do { \
394         char* result = getChildString((sect), (key)); \
395         ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'", (sect), (key), (expect)?(expect):"(null)", result); \
396     } while (0)
397
398 #define okChildIString(sect, key, expect) \
399     do { \
400         char* result = getChildString(sect, key); \
401         ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'", sect, key, expect, result); \
402     } while (0)
403
404 /* using !expect insures that the test will fail if the sect/key isn't present
405  * in result file
406  */
407 #define okChildInt(sect, key, expect) \
408     do { \
409         UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
410         ok(result == expect, "%s:%s expected %d, but got %d", (sect), (key), (int)(expect), result); \
411    } while (0)
412
413 static void test_Startup(void)
414 {
415     char                buffer[MAX_PATH];
416     PROCESS_INFORMATION info;
417     STARTUPINFOA        startup,si;
418
419     /* let's start simplistic */
420     memset(&startup, 0, sizeof(startup));
421     startup.cb = sizeof(startup);
422     startup.dwFlags = STARTF_USESHOWWINDOW;
423     startup.wShowWindow = SW_SHOWNORMAL;
424
425     get_file_name(resfile);
426     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
427     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
428     /* wait for child to terminate */
429     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
430     /* child process has changed result file, so let profile functions know about it */
431     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
432
433     GetStartupInfoA(&si);
434     okChildInt("StartupInfoA", "cb", startup.cb);
435     okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
436     okChildString("StartupInfoA", "lpTitle", si.lpTitle);
437     okChildInt("StartupInfoA", "dwX", startup.dwX);
438     okChildInt("StartupInfoA", "dwY", startup.dwY);
439     okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
440     okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
441     okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
442     okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
443     okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
444     okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
445     okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
446     release_memory();
447     assert(DeleteFileA(resfile) != 0);
448
449     /* not so simplistic now */
450     memset(&startup, 0, sizeof(startup));
451     startup.cb = sizeof(startup);
452     startup.dwFlags = STARTF_USESHOWWINDOW;
453     startup.wShowWindow = SW_SHOWNORMAL;
454     startup.lpTitle = "I'm the title string";
455     startup.lpDesktop = "I'm the desktop string";
456     startup.dwXCountChars = 0x12121212;
457     startup.dwYCountChars = 0x23232323;
458     startup.dwX = 0x34343434;
459     startup.dwY = 0x45454545;
460     startup.dwXSize = 0x56565656;
461     startup.dwYSize = 0x67676767;
462     startup.dwFillAttribute = 0xA55A;
463
464     get_file_name(resfile);
465     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
466     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
467     /* wait for child to terminate */
468     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
469     /* child process has changed result file, so let profile functions know about it */
470     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
471
472     okChildInt("StartupInfoA", "cb", startup.cb);
473     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
474     okChildString("StartupInfoA", "lpTitle", startup.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);
484     release_memory();
485     assert(DeleteFileA(resfile) != 0);
486
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 = "I'm the title string";
493     startup.lpDesktop = NULL;
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;
501
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");
505     /* wait for child to terminate */
506     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
507     /* child process has changed result file, so let profile functions know about it */
508     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
509
510     okChildInt("StartupInfoA", "cb", startup.cb);
511     okChildString("StartupInfoA", "lpDesktop", si.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);
522     release_memory();
523     assert(DeleteFileA(resfile) != 0);
524
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 = "I'm the title string";
531     startup.lpDesktop = "";
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;
539
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");
543     /* wait for child to terminate */
544     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
545     /* child process has changed result file, so let profile functions know about it */
546     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
547
548     okChildInt("StartupInfoA", "cb", startup.cb);
549     todo_wine okChildString("StartupInfoA", "lpDesktop", startup.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);
560     release_memory();
561     assert(DeleteFileA(resfile) != 0);
562
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 = NULL;
569     startup.lpDesktop = "I'm the desktop string";
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;
577
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");
581     /* wait for child to terminate */
582     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
583     /* child process has changed result file, so let profile functions know about it */
584     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
585
586     okChildInt("StartupInfoA", "cb", startup.cb);
587     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
588     okChildString("StartupInfoA", "lpTitle", si.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);
598     release_memory();
599     assert(DeleteFileA(resfile) != 0);
600
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 = "";
607     startup.lpDesktop = "I'm the desktop string";
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;
615
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");
619     /* wait for child to terminate */
620     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
621     /* child process has changed result file, so let profile functions know about it */
622     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
623
624     okChildInt("StartupInfoA", "cb", startup.cb);
625     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
626     todo_wine okChildString("StartupInfoA", "lpTitle", startup.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);
636     release_memory();
637     assert(DeleteFileA(resfile) != 0);
638
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 = "";
645     startup.lpDesktop = "";
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;
653
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");
657     /* wait for child to terminate */
658     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
659     /* child process has changed result file, so let profile functions know about it */
660     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
661
662     okChildInt("StartupInfoA", "cb", startup.cb);
663     todo_wine 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);
674     release_memory();
675     assert(DeleteFileA(resfile) != 0);
676
677     /* TODO: test for A/W and W/A and W/W */
678 }
679
680 static void test_CommandLine(void)
681 {
682     char                buffer[MAX_PATH];
683     PROCESS_INFORMATION info;
684     STARTUPINFOA        startup;
685
686     memset(&startup, 0, sizeof(startup));
687     startup.cb = sizeof(startup);
688     startup.dwFlags = STARTF_USESHOWWINDOW;
689     startup.wShowWindow = SW_SHOWNORMAL;
690
691     /* the basics */
692     get_file_name(resfile);
693     sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
694     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
695     /* wait for child to terminate */
696     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
697     /* child process has changed result file, so let profile functions know about it */
698     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
699
700     okChildInt("Arguments", "argcA", 4);
701     okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
702     okChildString("Arguments", "argvA4", NULL);
703     okChildString("Arguments", "CommandLineA", buffer);
704     release_memory();
705     assert(DeleteFileA(resfile) != 0);
706
707     memset(&startup, 0, sizeof(startup));
708     startup.cb = sizeof(startup);
709     startup.dwFlags = STARTF_USESHOWWINDOW;
710     startup.wShowWindow = SW_SHOWNORMAL;
711
712     /* from Frangois */
713     get_file_name(resfile);
714     sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
715     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
716     /* wait for child to terminate */
717     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
718     /* child process has changed result file, so let profile functions know about it */
719     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
720
721     okChildInt("Arguments", "argcA", 6);
722     okChildString("Arguments", "argvA3", "a\"b\\");
723     okChildString("Arguments", "argvA4", "c\"");
724     okChildString("Arguments", "argvA5", "d");
725     okChildString("Arguments", "argvA6", NULL);
726     okChildString("Arguments", "CommandLineA", buffer);
727     release_memory();
728     assert(DeleteFileA(resfile) != 0);
729 }
730
731 static void test_Directory(void)
732 {
733     char                buffer[MAX_PATH];
734     PROCESS_INFORMATION info;
735     STARTUPINFOA        startup;
736     char windir[MAX_PATH];
737
738     memset(&startup, 0, sizeof(startup));
739     startup.cb = sizeof(startup);
740     startup.dwFlags = STARTF_USESHOWWINDOW;
741     startup.wShowWindow = SW_SHOWNORMAL;
742
743     /* the basics */
744     get_file_name(resfile);
745     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
746     GetWindowsDirectoryA( windir, sizeof(windir) );
747     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess");
748     /* wait for child to terminate */
749     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
750     /* child process has changed result file, so let profile functions know about it */
751     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
752
753     okChildIString("Misc", "CurrDirA", windir);
754     release_memory();
755     assert(DeleteFileA(resfile) != 0);
756 }
757
758 static BOOL is_str_env_drive_dir(const char* str)
759 {
760     return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
761         str[3] == '=' && str[4] == str[1];
762 }
763
764 /* compared expected child's environment (in gesA) from actual
765  * environment our child got
766  */
767 static void cmpEnvironment(const char* gesA)
768 {
769     int                 i, clen;
770     const char*         ptrA;
771     char*               res;
772     char                key[32];
773     BOOL                found;
774
775     clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
776     
777     /* now look each parent env in child */
778     if ((ptrA = gesA) != NULL)
779     {
780         while (*ptrA)
781         {
782             for (i = 0; i < clen; i++)
783             {
784                 sprintf(key, "env%d", i);
785                 res = getChildString("EnvironmentA", key);
786                 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
787                     break;
788             }
789             found = i < clen;
790             ok(found, "Parent-env string %s isn't in child process", ptrA);
791             
792             ptrA += strlen(ptrA) + 1;
793             release_memory();
794         }
795     }
796     /* and each child env in parent */
797     for (i = 0; i < clen; i++)
798     {
799         sprintf(key, "env%d", i);
800         res = getChildString("EnvironmentA", key);
801         if ((ptrA = gesA) != NULL)
802         {
803             while (*ptrA)
804             {
805                 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
806                     break;
807                 ptrA += strlen(ptrA) + 1;
808             }
809             if (!*ptrA) ptrA = NULL;
810         }
811
812         if (!is_str_env_drive_dir(res))
813         {
814             found = ptrA != NULL;
815             ok(found, "Child-env string %s isn't in parent process", res);
816         }
817         /* else => should also test we get the right per drive default directory here... */
818     }
819 }
820
821 static void test_Environment(void)
822 {
823     char                buffer[MAX_PATH];
824     PROCESS_INFORMATION info;
825     STARTUPINFOA        startup;
826     char                child_env[4096];
827     char*               ptr;
828     char*               env;
829
830     memset(&startup, 0, sizeof(startup));
831     startup.cb = sizeof(startup);
832     startup.dwFlags = STARTF_USESHOWWINDOW;
833     startup.wShowWindow = SW_SHOWNORMAL;
834
835     /* the basics */
836     get_file_name(resfile);
837     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
838     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess");
839     /* wait for child to terminate */
840     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
841     /* child process has changed result file, so let profile functions know about it */
842     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
843     
844     cmpEnvironment(GetEnvironmentStringsA());
845     release_memory();
846     assert(DeleteFileA(resfile) != 0);
847
848     memset(&startup, 0, sizeof(startup));
849     startup.cb = sizeof(startup);
850     startup.dwFlags = STARTF_USESHOWWINDOW;
851     startup.wShowWindow = SW_SHOWNORMAL;
852
853     /* the basics */
854     get_file_name(resfile);
855     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
856     ptr = child_env;
857     sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
858     ptr += strlen(ptr) + 1;
859     strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
860     ptr += strlen(ptr) + 1;
861     strcpy(ptr, "FOO=BAR");
862     ptr += strlen(ptr) + 1;
863     strcpy(ptr, "BAR=FOOBAR");
864     ptr += strlen(ptr) + 1;
865     /* copy all existing variables except:
866      * - WINELOADER
867      * - PATH (already set above)
868      * - the directory definitions (=[A-Z]:=)
869      */
870     for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
871     {
872         if (strncmp(env, "PATH=", 5) != 0 &&
873             strncmp(env, "WINELOADER=", 11) != 0 &&
874             !is_str_env_drive_dir(env))
875         {
876             strcpy(ptr, env);
877             ptr += strlen(ptr) + 1;
878         }
879     }
880     *ptr = '\0';
881     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess");
882     /* wait for child to terminate */
883     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
884     /* child process has changed result file, so let profile functions know about it */
885     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
886     
887     cmpEnvironment(child_env);
888
889     release_memory();
890     assert(DeleteFileA(resfile) != 0);
891 }
892
893 static  void    test_SuspendFlag(void)
894 {
895     char                buffer[MAX_PATH];
896     PROCESS_INFORMATION info;
897     STARTUPINFOA        startup;
898     DWORD               exit_status;
899
900     /* let's start simplistic */
901     memset(&startup, 0, sizeof(startup));
902     startup.cb = sizeof(startup);
903     startup.dwFlags = STARTF_USESHOWWINDOW;
904     startup.wShowWindow = SW_SHOWNORMAL;
905
906     get_file_name(resfile);
907     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
908     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess");
909
910     ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running");
911     Sleep(8000);
912     ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running");
913     ok(ResumeThread(info.hThread) == 1, "Resuming thread");
914
915     /* wait for child to terminate */
916     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
917     /* child process has changed result file, so let profile functions know about it */
918     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
919
920     okChildInt("StartupInfoA", "cb", startup.cb);
921     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
922     okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
923     okChildInt("StartupInfoA", "dwX", startup.dwX);
924     okChildInt("StartupInfoA", "dwY", startup.dwY);
925     okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
926     okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
927     okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
928     okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
929     okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
930     okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
931     okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
932     release_memory();
933     assert(DeleteFileA(resfile) != 0);
934 }
935
936 static  void    test_DebuggingFlag(void)
937 {
938     char                buffer[MAX_PATH];
939     PROCESS_INFORMATION info;
940     STARTUPINFOA        startup;
941     DEBUG_EVENT         de;
942     unsigned            dbg = 0;
943
944     /* let's start simplistic */
945     memset(&startup, 0, sizeof(startup));
946     startup.cb = sizeof(startup);
947     startup.dwFlags = STARTF_USESHOWWINDOW;
948     startup.wShowWindow = SW_SHOWNORMAL;
949
950     get_file_name(resfile);
951     sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
952     ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess");
953
954     /* get all startup events up to the entry point break exception */
955     do 
956     {
957         ok(WaitForDebugEvent(&de, INFINITE), "reading debug event");
958         ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
959         if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
960     } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
961
962     ok(dbg, "I have seen a debug event");
963     /* wait for child to terminate */
964     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
965     /* child process has changed result file, so let profile functions know about it */
966     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
967
968     okChildInt("StartupInfoA", "cb", startup.cb);
969     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
970     okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
971     okChildInt("StartupInfoA", "dwX", startup.dwX);
972     okChildInt("StartupInfoA", "dwY", startup.dwY);
973     okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
974     okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
975     okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
976     okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
977     okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
978     okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
979     okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
980     release_memory();
981     assert(DeleteFileA(resfile) != 0);
982 }
983
984 static void test_Console(void)
985 {
986     char                buffer[MAX_PATH];
987     PROCESS_INFORMATION info;
988     STARTUPINFOA        startup;
989     SECURITY_ATTRIBUTES sa;
990     CONSOLE_SCREEN_BUFFER_INFO  sbi, sbiC;
991     DWORD               modeIn, modeOut, modeInC, modeOutC;
992     DWORD               cpIn, cpOut, cpInC, cpOutC;
993     DWORD               w;
994     HANDLE              hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
995     const char*         msg = "This is a std-handle inheritance test.";
996     unsigned            msg_len;
997
998     memset(&startup, 0, sizeof(startup));
999     startup.cb = sizeof(startup);
1000     startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1001     startup.wShowWindow = SW_SHOWNORMAL;
1002
1003     sa.nLength = sizeof(sa);
1004     sa.lpSecurityDescriptor = NULL;
1005     sa.bInheritHandle = TRUE;
1006
1007     startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1008     startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1009
1010     /* first, we need to be sure we're attached to a console */
1011     if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE)
1012     {
1013         /* we're not attached to a console, let's do it */
1014         AllocConsole();
1015         startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1016         startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1017     }
1018     /* now verify everything's ok */
1019     ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn");
1020     ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut");
1021     startup.hStdError = startup.hStdOutput;
1022
1023     ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info");
1024     ok(GetConsoleMode(startup.hStdInput, &modeIn) && 
1025        GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes");
1026     cpIn = GetConsoleCP();
1027     cpOut = GetConsoleOutputCP();
1028
1029     get_file_name(resfile);
1030     sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1031     ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess");
1032
1033     /* wait for child to terminate */
1034     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
1035     /* child process has changed result file, so let profile functions know about it */
1036     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1037
1038     /* now get the modification the child has made, and resets parents expected values */
1039     ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info");
1040     ok(GetConsoleMode(startup.hStdInput, &modeInC) && 
1041        GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes");
1042
1043     SetConsoleMode(startup.hStdInput, modeIn);
1044     SetConsoleMode(startup.hStdOutput, modeOut);
1045
1046     cpInC = GetConsoleCP();
1047     cpOutC = GetConsoleOutputCP();
1048     SetConsoleCP(cpIn);
1049     SetConsoleOutputCP(cpOut);
1050
1051     okChildInt("StartupInfoA", "cb", startup.cb);
1052     okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
1053     okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
1054     okChildInt("StartupInfoA", "dwX", startup.dwX);
1055     okChildInt("StartupInfoA", "dwY", startup.dwY);
1056     okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1057     okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1058     okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1059     okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1060     okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1061     okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1062     okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1063
1064     /* check child correctly inherited the console */
1065     okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
1066     okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
1067     okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
1068     okChildInt("Console", "SizeX", sbi.dwSize.X);
1069     okChildInt("Console", "SizeY", sbi.dwSize.Y);
1070     okChildInt("Console", "CursorX", sbi.dwCursorPosition.X);
1071     okChildInt("Console", "CursorY", sbi.dwCursorPosition.Y);
1072     okChildInt("Console", "Attributes", sbi.wAttributes);
1073     okChildInt("Console", "winLeft", sbi.srWindow.Left);
1074     okChildInt("Console", "winTop", sbi.srWindow.Top);
1075     okChildInt("Console", "winRight", sbi.srWindow.Right);
1076     okChildInt("Console", "winBottom", sbi.srWindow.Bottom);
1077     okChildInt("Console", "maxWinWidth", sbi.dwMaximumWindowSize.X);
1078     okChildInt("Console", "maxWinHeight", sbi.dwMaximumWindowSize.Y);
1079     okChildInt("Console", "InputCP", cpIn);
1080     okChildInt("Console", "OutputCP", cpOut);
1081     okChildInt("Console", "InputMode", modeIn);
1082     okChildInt("Console", "OutputMode", modeOut);
1083
1084     todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)", cpInC, cpIn);
1085     todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)", cpOutC, cpOut);
1086     ok(modeInC == (modeIn ^ 1), "Wrong console mode");
1087     ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode");
1088     ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position");
1089     ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position");
1090
1091     release_memory();
1092     assert(DeleteFileA(resfile) != 0);
1093
1094     ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe");
1095     ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(), 
1096                        &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1097        "Duplicating as inheritable child-output pipe");
1098     CloseHandle(hChildOut);
1099  
1100     ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe");
1101     ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(), 
1102                        &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1103        "Duplicating as inheritable child-input pipe");
1104     CloseHandle(hChildIn); 
1105     
1106     memset(&startup, 0, sizeof(startup));
1107     startup.cb = sizeof(startup);
1108     startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1109     startup.wShowWindow = SW_SHOWNORMAL;
1110     startup.hStdInput = hChildInInh;
1111     startup.hStdOutput = hChildOutInh;
1112     startup.hStdError = hChildOutInh;
1113
1114     get_file_name(resfile);
1115     sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1116     ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess");
1117     ok(CloseHandle(hChildInInh), "Closing handle");
1118     ok(CloseHandle(hChildOutInh), "Closing handle");
1119
1120     msg_len = strlen(msg) + 1;
1121     ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writting to child");
1122     ok(w == msg_len, "Should have written %u bytes, actually wrote %lu", msg_len, w);
1123     memset(buffer, 0, sizeof(buffer));
1124     ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child");
1125     ok(strcmp(buffer, msg) == 0, "Should have received '%s'", msg);
1126
1127     /* wait for child to terminate */
1128     ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination");
1129     /* child process has changed result file, so let profile functions know about it */
1130     WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1131
1132     okChildString("StdHandle", "msg", msg);
1133
1134     release_memory();
1135     assert(DeleteFileA(resfile) != 0);
1136 }
1137
1138 START_TEST(process)
1139 {
1140     int b = init();
1141     ok(b, "Basic init of CreateProcess test");
1142     if (!b) return;
1143
1144     if (myARGC >= 3)
1145     {
1146         doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1147         return;
1148     }
1149     test_Startup();
1150     test_CommandLine();
1151     test_Directory();
1152     test_Environment();
1153     test_SuspendFlag();
1154     test_DebuggingFlag();
1155     test_Console();
1156     /* things that can be tested:
1157      *  lookup:         check the way program to be executed is searched
1158      *  handles:        check the handle inheritance stuff (+sec options)
1159      *  console:        check if console creation parameters work
1160      */
1161 }