2 * Unit test suite for CreateProcess function.
4 * Copyright 2002 Eric Pouech
5 * Copyright 2006 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
34 static char base
[MAX_PATH
];
35 static char selfname
[MAX_PATH
];
36 static char resfile
[MAX_PATH
];
41 /* As some environment variables get very long on Unix, we only test for
42 * the first 127 bytes.
43 * Note that increasing this value past 256 may exceed the buffer size
44 * limitations of the *Profile functions (at least on Wine).
46 #define MAX_LISTED_ENV_VAR 128
48 /* ---------------- portable memory allocation thingie */
50 static char memory
[1024*256];
51 static char* memory_index
= memory
;
53 static char* grab_memory(size_t len
)
55 char* ret
= memory_index
;
59 assert(memory_index
<= memory
+ sizeof(memory
));
63 static void release_memory(void)
65 memory_index
= memory
;
68 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
70 static const char* encodeA(const char* str
)
76 len
= strlen(str
) + 1;
77 ptr
= grab_memory(len
* 2 + 1);
78 for (i
= 0; i
< len
; i
++)
79 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
84 static const char* encodeW(const WCHAR
* str
)
90 len
= lstrlenW(str
) + 1;
91 ptr
= grab_memory(len
* 4 + 1);
93 for (i
= 0; i
< len
; i
++)
94 sprintf(&ptr
[i
* 4], "%04x", (unsigned int)(unsigned short)str
[i
]);
99 static unsigned decode_char(char c
)
101 if (c
>= '0' && c
<= '9') return c
- '0';
102 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
103 assert(c
>= 'A' && c
<= 'F');
107 static char* decodeA(const char* str
)
112 len
= strlen(str
) / 2;
113 if (!len
--) return NULL
;
114 ptr
= grab_memory(len
+ 1);
115 for (i
= 0; i
< len
; i
++)
116 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
122 /* This will be needed to decode Unicode strings saved by the child process
123 * when we test Unicode functions.
125 static WCHAR
* decodeW(const char* str
)
131 len
= strlen(str
) / 4;
132 if (!len
--) return NULL
;
133 ptr
= (WCHAR
*)grab_memory(len
* 2 + 1);
134 for (i
= 0; i
< len
; i
++)
135 ptr
[i
] = (decode_char(str
[4 * i
]) << 12) |
136 (decode_char(str
[4 * i
+ 1]) << 8) |
137 (decode_char(str
[4 * i
+ 2]) << 4) |
138 (decode_char(str
[4 * i
+ 3]) << 0);
144 /******************************************************************
147 * generates basic information like:
148 * base: absolute path to curr dir
149 * selfname: the way to reinvoke ourselves
151 static int init(void)
153 myARGC
= winetest_get_mainargs( &myARGV
);
154 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
155 strcpy(selfname
, myARGV
[0]);
159 /******************************************************************
162 * generates an absolute file_name for temporary file
165 static void get_file_name(char* buf
)
170 GetTempPathA(sizeof(path
), path
);
171 GetTempFileNameA(path
, "wt", 0, buf
);
174 /******************************************************************
175 * static void childPrintf
178 static void childPrintf(HANDLE h
, const char* fmt
, ...)
181 char buffer
[1024+4*MAX_LISTED_ENV_VAR
];
184 va_start(valist
, fmt
);
185 vsprintf(buffer
, fmt
, valist
);
187 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
191 /******************************************************************
194 * output most of the information in the child process
196 static void doChild(const char* file
, const char* option
)
204 WCHAR bufW
[MAX_PATH
];
205 HANDLE hFile
= CreateFileA(file
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
208 if (hFile
== INVALID_HANDLE_VALUE
) return;
210 /* output of startup info (Ansi) */
211 GetStartupInfoA(&siA
);
213 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
214 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
215 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
216 "dwFlags=%lu\nwShowWindow=%u\n"
217 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
218 siA
.cb
, encodeA(siA
.lpDesktop
), encodeA(siA
.lpTitle
),
219 siA
.dwX
, siA
.dwY
, siA
.dwXSize
, siA
.dwYSize
,
220 siA
.dwXCountChars
, siA
.dwYCountChars
, siA
.dwFillAttribute
,
221 siA
.dwFlags
, siA
.wShowWindow
,
222 (DWORD
)siA
.hStdInput
, (DWORD
)siA
.hStdOutput
, (DWORD
)siA
.hStdError
);
224 /* since GetStartupInfoW is only implemented in win2k,
225 * zero out before calling so we can notice the difference
227 memset(&siW
, 0, sizeof(siW
));
228 GetStartupInfoW(&siW
);
230 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
231 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
232 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
233 "dwFlags=%lu\nwShowWindow=%u\n"
234 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
235 siW
.cb
, encodeW(siW
.lpDesktop
), encodeW(siW
.lpTitle
),
236 siW
.dwX
, siW
.dwY
, siW
.dwXSize
, siW
.dwYSize
,
237 siW
.dwXCountChars
, siW
.dwYCountChars
, siW
.dwFillAttribute
,
238 siW
.dwFlags
, siW
.wShowWindow
,
239 (DWORD
)siW
.hStdInput
, (DWORD
)siW
.hStdOutput
, (DWORD
)siW
.hStdError
);
242 childPrintf(hFile
, "[Arguments]\nargcA=%d\n", myARGC
);
243 for (i
= 0; i
< myARGC
; i
++)
245 childPrintf(hFile
, "argvA%d=%s\n", i
, encodeA(myARGV
[i
]));
247 childPrintf(hFile
, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
253 /* this is part of shell32... and should be tested there */
254 argvW
= CommandLineToArgvW(GetCommandLineW(), &argcW
);
255 for (i
= 0; i
< argcW
; i
++)
257 childPrintf(hFile
, "argvW%d=%s\n", i
, encodeW(argvW
[i
]));
260 childPrintf(hFile
, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
262 /* output of environment (Ansi) */
263 ptrA
= GetEnvironmentStringsA();
266 char env_var
[MAX_LISTED_ENV_VAR
];
268 childPrintf(hFile
, "[EnvironmentA]\n");
272 lstrcpynA(env_var
, ptrA
, MAX_LISTED_ENV_VAR
);
273 childPrintf(hFile
, "env%d=%s\n", i
, encodeA(env_var
));
275 ptrA
+= strlen(ptrA
) + 1;
277 childPrintf(hFile
, "len=%d\n\n", i
);
280 /* output of environment (Unicode) */
281 ptrW
= GetEnvironmentStringsW();
284 WCHAR env_var
[MAX_LISTED_ENV_VAR
];
286 childPrintf(hFile
, "[EnvironmentW]\n");
290 lstrcpynW(env_var
, ptrW
, MAX_LISTED_ENV_VAR
- 1);
291 env_var
[MAX_LISTED_ENV_VAR
- 1] = '\0';
292 childPrintf(hFile
, "env%d=%s\n", i
, encodeW(env_var
));
294 ptrW
+= lstrlenW(ptrW
) + 1;
296 childPrintf(hFile
, "len=%d\n\n", i
);
299 childPrintf(hFile
, "[Misc]\n");
300 if (GetCurrentDirectoryA(sizeof(bufA
), bufA
))
301 childPrintf(hFile
, "CurrDirA=%s\n", encodeA(bufA
));
302 if (GetCurrentDirectoryW(sizeof(bufW
) / sizeof(bufW
[0]), bufW
))
303 childPrintf(hFile
, "CurrDirW=%s\n", encodeW(bufW
));
304 childPrintf(hFile
, "\n");
306 if (option
&& strcmp(option
, "console") == 0)
308 CONSOLE_SCREEN_BUFFER_INFO sbi
;
309 HANDLE hConIn
= GetStdHandle(STD_INPUT_HANDLE
);
310 HANDLE hConOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
311 DWORD modeIn
, modeOut
;
313 childPrintf(hFile
, "[Console]\n");
314 if (GetConsoleScreenBufferInfo(hConOut
, &sbi
))
316 childPrintf(hFile
, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
317 sbi
.dwSize
.X
, sbi
.dwSize
.Y
, sbi
.dwCursorPosition
.X
, sbi
.dwCursorPosition
.Y
, sbi
.wAttributes
);
318 childPrintf(hFile
, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
319 sbi
.srWindow
.Left
, sbi
.srWindow
.Top
, sbi
.srWindow
.Right
, sbi
.srWindow
.Bottom
);
320 childPrintf(hFile
, "maxWinWidth=%d\nmaxWinHeight=%d\n",
321 sbi
.dwMaximumWindowSize
.X
, sbi
.dwMaximumWindowSize
.Y
);
323 childPrintf(hFile
, "InputCP=%d\nOutputCP=%d\n",
324 GetConsoleCP(), GetConsoleOutputCP());
325 if (GetConsoleMode(hConIn
, &modeIn
))
326 childPrintf(hFile
, "InputMode=%ld\n", modeIn
);
327 if (GetConsoleMode(hConOut
, &modeOut
))
328 childPrintf(hFile
, "OutputMode=%ld\n", modeOut
);
330 /* now that we have written all relevant information, let's change it */
331 ok(SetConsoleCP(1252), "Setting CP\n");
332 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
333 ret
= SetConsoleMode(hConIn
, modeIn
^ 1);
334 ok( ret
, "Setting mode (%d)\n", GetLastError());
335 ret
= SetConsoleMode(hConOut
, modeOut
^ 1);
336 ok( ret
, "Setting mode (%d)\n", GetLastError());
337 sbi
.dwCursorPosition
.X
^= 1;
338 sbi
.dwCursorPosition
.Y
^= 1;
339 ret
= SetConsoleCursorPosition(hConOut
, sbi
.dwCursorPosition
);
340 ok( ret
, "Setting cursor position (%d)\n", GetLastError());
342 if (option
&& strcmp(option
, "stdhandle") == 0)
344 HANDLE hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
345 HANDLE hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
347 if (hStdIn
!= INVALID_HANDLE_VALUE
|| hStdOut
!= INVALID_HANDLE_VALUE
)
352 ok(ReadFile(hStdIn
, buf
, sizeof(buf
), &r
, NULL
) && r
> 0, "Reading message from input pipe\n");
353 childPrintf(hFile
, "[StdHandle]\nmsg=%s\n\n", encodeA(buf
));
354 ok(WriteFile(hStdOut
, buf
, r
, &w
, NULL
) && w
== r
, "Writing message to output pipe\n");
358 if (option
&& strcmp(option
, "exit_code") == 0)
360 childPrintf(hFile
, "[ExitCode]\nvalue=%d\n\n", 123);
368 static char* getChildString(const char* sect
, const char* key
)
370 char buf
[1024+4*MAX_LISTED_ENV_VAR
];
373 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), resfile
);
374 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
375 assert(!(strlen(buf
) & 1));
380 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
381 * others... (windows uses stricmp while Un*x uses strcasecmp...)
383 static int wtstrcasecmp(const char* p1
, const char* p2
)
388 while (c1
== c2
&& c1
)
390 c1
= *p1
++; c2
= *p2
++;
393 c1
= toupper(c1
); c2
= toupper(c2
);
399 static int strCmp(const char* s1
, const char* s2
, BOOL sensitive
)
401 if (!s1
&& !s2
) return 0;
404 return (sensitive
) ? strcmp(s1
, s2
) : wtstrcasecmp(s1
, s2
);
407 #define okChildString(sect, key, expect) \
409 char* result = getChildString((sect), (key)); \
410 ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'\n", (sect), (key), (expect)?(expect):"(null)", result); \
413 #define okChildIString(sect, key, expect) \
415 char* result = getChildString(sect, key); \
416 ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'\n", sect, key, expect, result); \
419 /* using !expect ensures that the test will fail if the sect/key isn't present
422 #define okChildInt(sect, key, expect) \
424 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
425 ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
428 static void test_Startup(void)
430 char buffer
[MAX_PATH
];
431 PROCESS_INFORMATION info
;
432 STARTUPINFOA startup
,si
;
433 static CHAR title
[] = "I'm the title string",
434 desktop
[] = "I'm the desktop string",
437 /* let's start simplistic */
438 memset(&startup
, 0, sizeof(startup
));
439 startup
.cb
= sizeof(startup
);
440 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
441 startup
.wShowWindow
= SW_SHOWNORMAL
;
443 get_file_name(resfile
);
444 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
445 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
446 /* wait for child to terminate */
447 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
448 /* child process has changed result file, so let profile functions know about it */
449 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
451 GetStartupInfoA(&si
);
452 okChildInt("StartupInfoA", "cb", startup
.cb
);
453 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
454 okChildString("StartupInfoA", "lpTitle", si
.lpTitle
);
455 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
456 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
457 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
458 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
459 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
460 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
461 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
462 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
463 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
465 assert(DeleteFileA(resfile
) != 0);
467 /* not so simplistic now */
468 memset(&startup
, 0, sizeof(startup
));
469 startup
.cb
= sizeof(startup
);
470 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
471 startup
.wShowWindow
= SW_SHOWNORMAL
;
472 startup
.lpTitle
= title
;
473 startup
.lpDesktop
= desktop
;
474 startup
.dwXCountChars
= 0x12121212;
475 startup
.dwYCountChars
= 0x23232323;
476 startup
.dwX
= 0x34343434;
477 startup
.dwY
= 0x45454545;
478 startup
.dwXSize
= 0x56565656;
479 startup
.dwYSize
= 0x67676767;
480 startup
.dwFillAttribute
= 0xA55A;
482 get_file_name(resfile
);
483 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
484 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
485 /* wait for child to terminate */
486 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
487 /* child process has changed result file, so let profile functions know about it */
488 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
490 okChildInt("StartupInfoA", "cb", startup
.cb
);
491 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
492 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
493 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
494 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
495 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
496 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
497 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
498 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
499 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
500 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
501 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
503 assert(DeleteFileA(resfile
) != 0);
505 /* not so simplistic now */
506 memset(&startup
, 0, sizeof(startup
));
507 startup
.cb
= sizeof(startup
);
508 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
509 startup
.wShowWindow
= SW_SHOWNORMAL
;
510 startup
.lpTitle
= title
;
511 startup
.lpDesktop
= NULL
;
512 startup
.dwXCountChars
= 0x12121212;
513 startup
.dwYCountChars
= 0x23232323;
514 startup
.dwX
= 0x34343434;
515 startup
.dwY
= 0x45454545;
516 startup
.dwXSize
= 0x56565656;
517 startup
.dwYSize
= 0x67676767;
518 startup
.dwFillAttribute
= 0xA55A;
520 get_file_name(resfile
);
521 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
522 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
523 /* wait for child to terminate */
524 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
525 /* child process has changed result file, so let profile functions know about it */
526 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
528 okChildInt("StartupInfoA", "cb", startup
.cb
);
529 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
530 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
531 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
532 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
533 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
534 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
535 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
536 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
537 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
538 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
539 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
541 assert(DeleteFileA(resfile
) != 0);
543 /* not so simplistic now */
544 memset(&startup
, 0, sizeof(startup
));
545 startup
.cb
= sizeof(startup
);
546 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
547 startup
.wShowWindow
= SW_SHOWNORMAL
;
548 startup
.lpTitle
= title
;
549 startup
.lpDesktop
= empty
;
550 startup
.dwXCountChars
= 0x12121212;
551 startup
.dwYCountChars
= 0x23232323;
552 startup
.dwX
= 0x34343434;
553 startup
.dwY
= 0x45454545;
554 startup
.dwXSize
= 0x56565656;
555 startup
.dwYSize
= 0x67676767;
556 startup
.dwFillAttribute
= 0xA55A;
558 get_file_name(resfile
);
559 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
560 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
561 /* wait for child to terminate */
562 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
563 /* child process has changed result file, so let profile functions know about it */
564 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
566 okChildInt("StartupInfoA", "cb", startup
.cb
);
567 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
568 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
569 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
570 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
571 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
572 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
573 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
574 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
575 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
576 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
577 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
579 assert(DeleteFileA(resfile
) != 0);
581 /* not so simplistic now */
582 memset(&startup
, 0, sizeof(startup
));
583 startup
.cb
= sizeof(startup
);
584 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
585 startup
.wShowWindow
= SW_SHOWNORMAL
;
586 startup
.lpTitle
= NULL
;
587 startup
.lpDesktop
= desktop
;
588 startup
.dwXCountChars
= 0x12121212;
589 startup
.dwYCountChars
= 0x23232323;
590 startup
.dwX
= 0x34343434;
591 startup
.dwY
= 0x45454545;
592 startup
.dwXSize
= 0x56565656;
593 startup
.dwYSize
= 0x67676767;
594 startup
.dwFillAttribute
= 0xA55A;
596 get_file_name(resfile
);
597 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
598 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
599 /* wait for child to terminate */
600 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
601 /* child process has changed result file, so let profile functions know about it */
602 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
604 okChildInt("StartupInfoA", "cb", startup
.cb
);
605 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
606 okChildString("StartupInfoA", "lpTitle", si
.lpTitle
);
607 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
608 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
609 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
610 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
611 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
612 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
613 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
614 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
615 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
617 assert(DeleteFileA(resfile
) != 0);
619 /* not so simplistic now */
620 memset(&startup
, 0, sizeof(startup
));
621 startup
.cb
= sizeof(startup
);
622 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
623 startup
.wShowWindow
= SW_SHOWNORMAL
;
624 startup
.lpTitle
= empty
;
625 startup
.lpDesktop
= desktop
;
626 startup
.dwXCountChars
= 0x12121212;
627 startup
.dwYCountChars
= 0x23232323;
628 startup
.dwX
= 0x34343434;
629 startup
.dwY
= 0x45454545;
630 startup
.dwXSize
= 0x56565656;
631 startup
.dwYSize
= 0x67676767;
632 startup
.dwFillAttribute
= 0xA55A;
634 get_file_name(resfile
);
635 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
636 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
637 /* wait for child to terminate */
638 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
639 /* child process has changed result file, so let profile functions know about it */
640 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
642 okChildInt("StartupInfoA", "cb", startup
.cb
);
643 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
644 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
645 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
646 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
647 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
648 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
649 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
650 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
651 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
652 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
653 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
655 assert(DeleteFileA(resfile
) != 0);
657 /* not so simplistic now */
658 memset(&startup
, 0, sizeof(startup
));
659 startup
.cb
= sizeof(startup
);
660 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
661 startup
.wShowWindow
= SW_SHOWNORMAL
;
662 startup
.lpTitle
= empty
;
663 startup
.lpDesktop
= empty
;
664 startup
.dwXCountChars
= 0x12121212;
665 startup
.dwYCountChars
= 0x23232323;
666 startup
.dwX
= 0x34343434;
667 startup
.dwY
= 0x45454545;
668 startup
.dwXSize
= 0x56565656;
669 startup
.dwYSize
= 0x67676767;
670 startup
.dwFillAttribute
= 0xA55A;
672 get_file_name(resfile
);
673 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
674 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
675 /* wait for child to terminate */
676 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
677 /* child process has changed result file, so let profile functions know about it */
678 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
680 okChildInt("StartupInfoA", "cb", startup
.cb
);
681 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
682 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
683 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
684 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
685 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
686 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
687 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
688 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
689 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
690 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
691 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
693 assert(DeleteFileA(resfile
) != 0);
695 /* TODO: test for A/W and W/A and W/W */
698 static void test_CommandLine(void)
700 char buffer
[MAX_PATH
], fullpath
[MAX_PATH
], *lpFilePart
, *p
;
701 PROCESS_INFORMATION info
;
702 STARTUPINFOA startup
;
705 memset(&startup
, 0, sizeof(startup
));
706 startup
.cb
= sizeof(startup
);
707 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
708 startup
.wShowWindow
= SW_SHOWNORMAL
;
711 get_file_name(resfile
);
712 sprintf(buffer
, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname
, resfile
);
713 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
714 /* wait for child to terminate */
715 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
716 /* child process has changed result file, so let profile functions know about it */
717 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
719 okChildInt("Arguments", "argcA", 4);
720 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
721 okChildString("Arguments", "argvA4", NULL
);
722 okChildString("Arguments", "CommandLineA", buffer
);
724 assert(DeleteFileA(resfile
) != 0);
726 memset(&startup
, 0, sizeof(startup
));
727 startup
.cb
= sizeof(startup
);
728 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
729 startup
.wShowWindow
= SW_SHOWNORMAL
;
732 get_file_name(resfile
);
733 sprintf(buffer
, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
734 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
735 /* wait for child to terminate */
736 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
737 /* child process has changed result file, so let profile functions know about it */
738 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
740 okChildInt("Arguments", "argcA", 6);
741 okChildString("Arguments", "argvA3", "a\"b\\");
742 okChildString("Arguments", "argvA4", "c\"");
743 okChildString("Arguments", "argvA5", "d");
744 okChildString("Arguments", "argvA6", NULL
);
745 okChildString("Arguments", "CommandLineA", buffer
);
747 assert(DeleteFileA(resfile
) != 0);
749 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
750 get_file_name(resfile
);
751 sprintf(buffer
, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
752 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
753 /* wait for child to terminate */
754 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
755 /* child process has changed result file, so let profile functions know about it */
756 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
757 sprintf(buffer
, "./%s", selfname
);
758 okChildString("Arguments", "argvA0", buffer
);
760 assert(DeleteFileA(resfile
) != 0);
762 get_file_name(resfile
);
763 sprintf(buffer
, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
764 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
765 /* wait for child to terminate */
766 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
767 /* child process has changed result file, so let profile functions know about it */
768 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
769 sprintf(buffer
, ".\\%s", selfname
);
770 okChildString("Arguments", "argvA0", buffer
);
772 assert(DeleteFileA(resfile
) != 0);
774 get_file_name(resfile
);
775 len
= GetFullPathNameA(selfname
, MAX_PATH
, fullpath
, &lpFilePart
);
776 assert ( lpFilePart
!= 0);
777 *(lpFilePart
-1 ) = 0;
778 p
= strrchr(fullpath
, '\\');
780 sprintf(buffer
, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p
, selfname
, resfile
);
781 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
782 /* wait for child to terminate */
783 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
784 /* child process has changed result file, so let profile functions know about it */
785 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
786 sprintf(buffer
, "..%s/%s", p
, selfname
);
787 okChildString("Arguments", "argvA0", buffer
);
789 assert(DeleteFileA(resfile
) != 0);
793 static void test_Directory(void)
795 char buffer
[MAX_PATH
];
796 PROCESS_INFORMATION info
;
797 STARTUPINFOA startup
;
798 char windir
[MAX_PATH
];
799 static CHAR cmdline
[] = "winver.exe";
801 memset(&startup
, 0, sizeof(startup
));
802 startup
.cb
= sizeof(startup
);
803 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
804 startup
.wShowWindow
= SW_SHOWNORMAL
;
807 get_file_name(resfile
);
808 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
809 GetWindowsDirectoryA( windir
, sizeof(windir
) );
810 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, windir
, &startup
, &info
), "CreateProcess\n");
811 /* wait for child to terminate */
812 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
813 /* child process has changed result file, so let profile functions know about it */
814 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
816 okChildIString("Misc", "CurrDirA", windir
);
818 assert(DeleteFileA(resfile
) != 0);
820 /* search PATH for the exe if directory is NULL */
821 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
822 ok(TerminateProcess(info
.hProcess
, 0), "Child process termination\n");
824 /* if any directory is provided, don't search PATH, error on bad directory */
825 SetLastError(0xdeadbeef);
826 memset(&info
, 0, sizeof(info
));
827 ok(!CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L,
828 NULL
, "non\\existent\\directory", &startup
, &info
), "CreateProcess\n");
829 ok(GetLastError() == ERROR_DIRECTORY
, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
830 ok(!TerminateProcess(info
.hProcess
, 0), "Child process should not exist\n");
833 static BOOL
is_str_env_drive_dir(const char* str
)
835 return str
[0] == '=' && str
[1] >= 'A' && str
[1] <= 'Z' && str
[2] == ':' &&
836 str
[3] == '=' && str
[4] == str
[1];
839 /* compared expected child's environment (in gesA) from actual
840 * environment our child got
842 static void cmpEnvironment(const char* gesA
)
850 clen
= GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile
);
852 /* now look each parent env in child */
853 if ((ptrA
= gesA
) != NULL
)
857 for (i
= 0; i
< clen
; i
++)
859 sprintf(key
, "env%d", i
);
860 res
= getChildString("EnvironmentA", key
);
861 if (strncmp(ptrA
, res
, MAX_LISTED_ENV_VAR
- 1) == 0)
865 ok(found
, "Parent-env string %s isn't in child process\n", ptrA
);
867 ptrA
+= strlen(ptrA
) + 1;
871 /* and each child env in parent */
872 for (i
= 0; i
< clen
; i
++)
874 sprintf(key
, "env%d", i
);
875 res
= getChildString("EnvironmentA", key
);
876 if ((ptrA
= gesA
) != NULL
)
880 if (strncmp(res
, ptrA
, MAX_LISTED_ENV_VAR
- 1) == 0)
882 ptrA
+= strlen(ptrA
) + 1;
884 if (!*ptrA
) ptrA
= NULL
;
887 if (!is_str_env_drive_dir(res
))
889 found
= ptrA
!= NULL
;
890 ok(found
, "Child-env string %s isn't in parent process\n", res
);
892 /* else => should also test we get the right per drive default directory here... */
896 static void test_Environment(void)
898 char buffer
[MAX_PATH
];
899 PROCESS_INFORMATION info
;
900 STARTUPINFOA startup
;
907 memset(&startup
, 0, sizeof(startup
));
908 startup
.cb
= sizeof(startup
);
909 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
910 startup
.wShowWindow
= SW_SHOWNORMAL
;
913 get_file_name(resfile
);
914 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
915 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
916 /* wait for child to terminate */
917 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
918 /* child process has changed result file, so let profile functions know about it */
919 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
921 cmpEnvironment(GetEnvironmentStringsA());
923 assert(DeleteFileA(resfile
) != 0);
925 memset(&startup
, 0, sizeof(startup
));
926 startup
.cb
= sizeof(startup
);
927 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
928 startup
.wShowWindow
= SW_SHOWNORMAL
;
931 get_file_name(resfile
);
932 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
935 ptr
= GetEnvironmentStringsA();
938 slen
= strlen(ptr
)+1;
939 child_env_len
+= slen
;
942 /* Add space for additional environment variables */
943 child_env_len
+= 256;
944 child_env
= HeapAlloc(GetProcessHeap(), 0, child_env_len
);
947 sprintf(ptr
, "=%c:=%s", 'C', "C:\\FOO\\BAR");
948 ptr
+= strlen(ptr
) + 1;
949 strcpy(ptr
, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
950 ptr
+= strlen(ptr
) + 1;
951 strcpy(ptr
, "FOO=BAR");
952 ptr
+= strlen(ptr
) + 1;
953 strcpy(ptr
, "BAR=FOOBAR");
954 ptr
+= strlen(ptr
) + 1;
955 /* copy all existing variables except:
957 * - PATH (already set above)
958 * - the directory definitions (=[A-Z]:=)
960 for (env
= GetEnvironmentStringsA(); *env
; env
+= strlen(env
) + 1)
962 if (strncmp(env
, "PATH=", 5) != 0 &&
963 strncmp(env
, "WINELOADER=", 11) != 0 &&
964 !is_str_env_drive_dir(env
))
967 ptr
+= strlen(ptr
) + 1;
971 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, child_env
, NULL
, &startup
, &info
), "CreateProcess\n");
972 /* wait for child to terminate */
973 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
974 /* child process has changed result file, so let profile functions know about it */
975 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
977 cmpEnvironment(child_env
);
979 HeapFree(GetProcessHeap(), 0, child_env
);
981 assert(DeleteFileA(resfile
) != 0);
984 static void test_SuspendFlag(void)
986 char buffer
[MAX_PATH
];
987 PROCESS_INFORMATION info
;
988 STARTUPINFOA startup
, us
;
991 /* let's start simplistic */
992 memset(&startup
, 0, sizeof(startup
));
993 startup
.cb
= sizeof(startup
);
994 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
995 startup
.wShowWindow
= SW_SHOWNORMAL
;
997 get_file_name(resfile
);
998 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
999 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1001 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1003 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1004 ok(ResumeThread(info
.hThread
) == 1, "Resuming thread\n");
1006 /* wait for child to terminate */
1007 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1008 /* child process has changed result file, so let profile functions know about it */
1009 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1011 GetStartupInfoA(&us
);
1013 okChildInt("StartupInfoA", "cb", startup
.cb
);
1014 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1015 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1016 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1017 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1018 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1019 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1020 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1021 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1022 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1023 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1024 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1026 assert(DeleteFileA(resfile
) != 0);
1029 static void test_DebuggingFlag(void)
1031 char buffer
[MAX_PATH
];
1032 PROCESS_INFORMATION info
;
1033 STARTUPINFOA startup
, us
;
1037 /* let's start simplistic */
1038 memset(&startup
, 0, sizeof(startup
));
1039 startup
.cb
= sizeof(startup
);
1040 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1041 startup
.wShowWindow
= SW_SHOWNORMAL
;
1043 get_file_name(resfile
);
1044 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1045 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1047 /* get all startup events up to the entry point break exception */
1050 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
1051 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
1052 if (de
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
) dbg
++;
1053 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
1055 ok(dbg
, "I have seen a debug event\n");
1056 /* wait for child to terminate */
1057 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1058 /* child process has changed result file, so let profile functions know about it */
1059 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1061 GetStartupInfoA(&us
);
1063 okChildInt("StartupInfoA", "cb", startup
.cb
);
1064 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1065 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1066 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1067 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1068 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1069 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1070 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1071 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1072 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1073 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1074 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1076 assert(DeleteFileA(resfile
) != 0);
1079 static BOOL
is_console(HANDLE h
)
1081 return h
!= INVALID_HANDLE_VALUE
&& ((ULONG_PTR
)h
& 3) == 3;
1084 static void test_Console(void)
1086 char buffer
[MAX_PATH
];
1087 PROCESS_INFORMATION info
;
1088 STARTUPINFOA startup
, us
;
1089 SECURITY_ATTRIBUTES sa
;
1090 CONSOLE_SCREEN_BUFFER_INFO sbi
, sbiC
;
1091 DWORD modeIn
, modeOut
, modeInC
, modeOutC
;
1092 DWORD cpIn
, cpOut
, cpInC
, cpOutC
;
1094 HANDLE hChildIn
, hChildInInh
, hChildOut
, hChildOutInh
, hParentIn
, hParentOut
;
1095 const char* msg
= "This is a std-handle inheritance test.";
1098 memset(&startup
, 0, sizeof(startup
));
1099 startup
.cb
= sizeof(startup
);
1100 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1101 startup
.wShowWindow
= SW_SHOWNORMAL
;
1103 sa
.nLength
= sizeof(sa
);
1104 sa
.lpSecurityDescriptor
= NULL
;
1105 sa
.bInheritHandle
= TRUE
;
1107 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1108 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1110 /* first, we need to be sure we're attached to a console */
1111 if (!is_console(startup
.hStdInput
) || !is_console(startup
.hStdOutput
))
1113 /* we're not attached to a console, let's do it */
1115 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1116 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1118 /* now verify everything's ok */
1119 ok(startup
.hStdInput
!= INVALID_HANDLE_VALUE
, "Opening ConIn\n");
1120 ok(startup
.hStdOutput
!= INVALID_HANDLE_VALUE
, "Opening ConOut\n");
1121 startup
.hStdError
= startup
.hStdOutput
;
1123 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbi
), "Getting sb info\n");
1124 ok(GetConsoleMode(startup
.hStdInput
, &modeIn
) &&
1125 GetConsoleMode(startup
.hStdOutput
, &modeOut
), "Getting console modes\n");
1126 cpIn
= GetConsoleCP();
1127 cpOut
= GetConsoleOutputCP();
1129 get_file_name(resfile
);
1130 sprintf(buffer
, "%s tests/process.c %s console", selfname
, resfile
);
1131 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1133 /* wait for child to terminate */
1134 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1135 /* child process has changed result file, so let profile functions know about it */
1136 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1138 /* now get the modification the child has made, and resets parents expected values */
1139 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbiC
), "Getting sb info\n");
1140 ok(GetConsoleMode(startup
.hStdInput
, &modeInC
) &&
1141 GetConsoleMode(startup
.hStdOutput
, &modeOutC
), "Getting console modes\n");
1143 SetConsoleMode(startup
.hStdInput
, modeIn
);
1144 SetConsoleMode(startup
.hStdOutput
, modeOut
);
1146 cpInC
= GetConsoleCP();
1147 cpOutC
= GetConsoleOutputCP();
1149 SetConsoleOutputCP(cpOut
);
1151 GetStartupInfoA(&us
);
1153 okChildInt("StartupInfoA", "cb", startup
.cb
);
1154 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1155 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
1156 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1157 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1158 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1159 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1160 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1161 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1162 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1163 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1164 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1166 /* check child correctly inherited the console */
1167 okChildInt("StartupInfoA", "hStdInput", (DWORD
)startup
.hStdInput
);
1168 okChildInt("StartupInfoA", "hStdOutput", (DWORD
)startup
.hStdOutput
);
1169 okChildInt("StartupInfoA", "hStdError", (DWORD
)startup
.hStdError
);
1170 okChildInt("Console", "SizeX", (DWORD
)sbi
.dwSize
.X
);
1171 okChildInt("Console", "SizeY", (DWORD
)sbi
.dwSize
.Y
);
1172 okChildInt("Console", "CursorX", (DWORD
)sbi
.dwCursorPosition
.X
);
1173 okChildInt("Console", "CursorY", (DWORD
)sbi
.dwCursorPosition
.Y
);
1174 okChildInt("Console", "Attributes", sbi
.wAttributes
);
1175 okChildInt("Console", "winLeft", (DWORD
)sbi
.srWindow
.Left
);
1176 okChildInt("Console", "winTop", (DWORD
)sbi
.srWindow
.Top
);
1177 okChildInt("Console", "winRight", (DWORD
)sbi
.srWindow
.Right
);
1178 okChildInt("Console", "winBottom", (DWORD
)sbi
.srWindow
.Bottom
);
1179 okChildInt("Console", "maxWinWidth", (DWORD
)sbi
.dwMaximumWindowSize
.X
);
1180 okChildInt("Console", "maxWinHeight", (DWORD
)sbi
.dwMaximumWindowSize
.Y
);
1181 okChildInt("Console", "InputCP", cpIn
);
1182 okChildInt("Console", "OutputCP", cpOut
);
1183 okChildInt("Console", "InputMode", modeIn
);
1184 okChildInt("Console", "OutputMode", modeOut
);
1186 todo_wine
ok(cpInC
== 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC
, cpIn
);
1187 todo_wine
ok(cpOutC
== 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC
, cpOut
);
1188 ok(modeInC
== (modeIn
^ 1), "Wrong console mode\n");
1189 ok(modeOutC
== (modeOut
^ 1), "Wrong console-SB mode\n");
1190 ok(sbiC
.dwCursorPosition
.X
== (sbi
.dwCursorPosition
.X
^ 1), "Wrong cursor position\n");
1191 ok(sbiC
.dwCursorPosition
.Y
== (sbi
.dwCursorPosition
.Y
^ 1), "Wrong cursor position\n");
1194 assert(DeleteFileA(resfile
) != 0);
1196 ok(CreatePipe(&hParentIn
, &hChildOut
, NULL
, 0), "Creating parent-input pipe\n");
1197 ok(DuplicateHandle(GetCurrentProcess(), hChildOut
, GetCurrentProcess(),
1198 &hChildOutInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1199 "Duplicating as inheritable child-output pipe\n");
1200 CloseHandle(hChildOut
);
1202 ok(CreatePipe(&hChildIn
, &hParentOut
, NULL
, 0), "Creating parent-output pipe\n");
1203 ok(DuplicateHandle(GetCurrentProcess(), hChildIn
, GetCurrentProcess(),
1204 &hChildInInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1205 "Duplicating as inheritable child-input pipe\n");
1206 CloseHandle(hChildIn
);
1208 memset(&startup
, 0, sizeof(startup
));
1209 startup
.cb
= sizeof(startup
);
1210 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1211 startup
.wShowWindow
= SW_SHOWNORMAL
;
1212 startup
.hStdInput
= hChildInInh
;
1213 startup
.hStdOutput
= hChildOutInh
;
1214 startup
.hStdError
= hChildOutInh
;
1216 get_file_name(resfile
);
1217 sprintf(buffer
, "%s tests/process.c %s stdhandle", selfname
, resfile
);
1218 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1219 ok(CloseHandle(hChildInInh
), "Closing handle\n");
1220 ok(CloseHandle(hChildOutInh
), "Closing handle\n");
1222 msg_len
= strlen(msg
) + 1;
1223 ok(WriteFile(hParentOut
, msg
, msg_len
, &w
, NULL
), "Writing to child\n");
1224 ok(w
== msg_len
, "Should have written %u bytes, actually wrote %u\n", msg_len
, w
);
1225 memset(buffer
, 0, sizeof(buffer
));
1226 ok(ReadFile(hParentIn
, buffer
, sizeof(buffer
), &w
, NULL
), "Reading from child\n");
1227 ok(strcmp(buffer
, msg
) == 0, "Should have received '%s'\n", msg
);
1229 /* wait for child to terminate */
1230 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1231 /* child process has changed result file, so let profile functions know about it */
1232 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1234 okChildString("StdHandle", "msg", msg
);
1237 assert(DeleteFileA(resfile
) != 0);
1240 static void test_ExitCode(void)
1242 char buffer
[MAX_PATH
];
1243 PROCESS_INFORMATION info
;
1244 STARTUPINFOA startup
;
1247 /* let's start simplistic */
1248 memset(&startup
, 0, sizeof(startup
));
1249 startup
.cb
= sizeof(startup
);
1250 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1251 startup
.wShowWindow
= SW_SHOWNORMAL
;
1253 get_file_name(resfile
);
1254 sprintf(buffer
, "%s tests/process.c %s exit_code", selfname
, resfile
);
1255 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1257 /* wait for child to terminate */
1258 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1259 /* child process has changed result file, so let profile functions know about it */
1260 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1262 ok(GetExitCodeProcess(info
.hProcess
, &code
), "Getting exit code\n");
1263 okChildInt("ExitCode", "value", code
);
1266 assert(DeleteFileA(resfile
) != 0);
1269 static void test_OpenProcess(void)
1273 MEMORY_BASIC_INFORMATION info
;
1274 SIZE_T dummy
, read_bytes
;
1276 /* without PROCESS_VM_OPERATION */
1277 hproc
= OpenProcess(PROCESS_ALL_ACCESS
& ~PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1278 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1280 SetLastError(0xdeadbeef);
1281 addr1
= VirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1283 ok(!addr1
, "VirtualAllocEx should fail\n");
1284 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1287 read_bytes
= 0xdeadbeef;
1288 SetLastError(0xdeadbeef);
1289 ok(ReadProcessMemory(hproc
, test_OpenProcess
, &dummy
, sizeof(dummy
), &read_bytes
),
1290 "ReadProcessMemory error %d\n", GetLastError());
1291 ok(read_bytes
== sizeof(dummy
), "wrong read bytes %ld\n", read_bytes
);
1295 hproc
= OpenProcess(PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1296 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1298 addr1
= VirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1300 ok(addr1
!= NULL
, "VirtualAllocEx error %d\n", GetLastError());
1302 if (addr1
== NULL
) /* FIXME: remove once Wine is fixed */
1303 addr1
= VirtualAllocEx(GetCurrentProcess(), 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1305 /* without PROCESS_QUERY_INFORMATION */
1306 SetLastError(0xdeadbeef);
1307 ok(!VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)),
1308 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1309 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1311 /* without PROCESS_VM_READ */
1312 read_bytes
= 0xdeadbeef;
1313 SetLastError(0xdeadbeef);
1314 ok(!ReadProcessMemory(hproc
, addr1
, &dummy
, sizeof(dummy
), &read_bytes
),
1315 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1316 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1317 ok(read_bytes
== 0, "wrong read bytes %ld\n", read_bytes
);
1321 hproc
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
1323 memset(&info
, 0xaa, sizeof(info
));
1324 ok(VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)) == sizeof(info
),
1325 "VirtualQueryEx error %d\n", GetLastError());
1327 ok(info
.BaseAddress
== addr1
, "%p != %p\n", info
.BaseAddress
, addr1
);
1328 ok(info
.AllocationBase
== addr1
, "%p != %p\n", info
.AllocationBase
, addr1
);
1329 ok(info
.AllocationProtect
== PAGE_NOACCESS
, "%x != PAGE_NOACCESS\n", info
.AllocationProtect
);
1330 ok(info
.RegionSize
== 0x10000, "%lx != 0x10000\n", info
.RegionSize
);
1331 ok(info
.State
== MEM_RESERVE
, "%x != MEM_RESERVE\n", info
.State
);
1332 /* NT reports Protect == 0 for a not committed memory block */
1333 ok(info
.Protect
== 0 /* NT */ ||
1334 info
.Protect
== PAGE_NOACCESS
, /* Win9x */
1335 "%x != PAGE_NOACCESS\n", info
.Protect
);
1336 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
1338 SetLastError(0xdeadbeef);
1340 ok(!VirtualFreeEx(hproc
, addr1
, 0, MEM_RELEASE
),
1341 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1342 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1348 ok(VirtualFree(addr1
, 0, MEM_RELEASE
), "VirtualFree failed\n");
1355 ok(b
, "Basic init of CreateProcess test\n");
1360 doChild(myARGV
[2], (myARGC
== 3) ? NULL
: myARGV
[3]);
1368 test_DebuggingFlag();
1372 /* things that can be tested:
1373 * lookup: check the way program to be executed is searched
1374 * handles: check the handle inheritance stuff (+sec options)
1375 * console: check if console creation parameters work