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
28 #define WIN32_NO_STATUS
36 #include "wine/test.h"
38 #define expect_eq_d(expected, actual) \
40 int value = (actual); \
41 ok((expected) == value, "Expected " #actual " to be %d (" #expected ") is %d\n", \
44 #define expect_eq_s(expected, actual) \
46 LPCSTR value = (actual); \
47 ok(lstrcmpA((expected), value) == 0, "Expected " #actual " to be L\"%s\" (" #expected ") is L\"%s\"\n", \
50 #define expect_eq_ws_i(expected, actual) \
52 LPCWSTR value = (actual); \
53 ok(lstrcmpiW((expected), value) == 0, "Expected " #actual " to be L\"%s\" (" #expected ") is L\"%s\"\n", \
54 wine_dbgstr_w(expected), wine_dbgstr_w(value)); \
57 static HINSTANCE hkernel32
;
58 static LPVOID (WINAPI
*pVirtualAllocEx
)(HANDLE
, LPVOID
, SIZE_T
, DWORD
, DWORD
);
59 static BOOL (WINAPI
*pVirtualFreeEx
)(HANDLE
, LPVOID
, SIZE_T
, DWORD
);
60 static BOOL (WINAPI
*pQueryFullProcessImageNameA
)(HANDLE hProcess
, DWORD dwFlags
, LPSTR lpExeName
, PDWORD lpdwSize
);
61 static BOOL (WINAPI
*pQueryFullProcessImageNameW
)(HANDLE hProcess
, DWORD dwFlags
, LPWSTR lpExeName
, PDWORD lpdwSize
);
63 /* ############################### */
64 static char base
[MAX_PATH
];
65 static char selfname
[MAX_PATH
];
67 static char resfile
[MAX_PATH
];
72 /* As some environment variables get very long on Unix, we only test for
73 * the first 127 bytes.
74 * Note that increasing this value past 256 may exceed the buffer size
75 * limitations of the *Profile functions (at least on Wine).
77 #define MAX_LISTED_ENV_VAR 128
79 /* ---------------- portable memory allocation thingie */
81 static char memory
[1024*256];
82 static char* memory_index
= memory
;
84 static char* grab_memory(size_t len
)
86 char* ret
= memory_index
;
90 assert(memory_index
<= memory
+ sizeof(memory
));
94 static void release_memory(void)
96 memory_index
= memory
;
99 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
101 static const char* encodeA(const char* str
)
107 len
= strlen(str
) + 1;
108 ptr
= grab_memory(len
* 2 + 1);
109 for (i
= 0; i
< len
; i
++)
110 sprintf(&ptr
[i
* 2], "%02x", (unsigned char)str
[i
]);
115 static const char* encodeW(const WCHAR
* str
)
121 len
= lstrlenW(str
) + 1;
122 ptr
= grab_memory(len
* 4 + 1);
124 for (i
= 0; i
< len
; i
++)
125 sprintf(&ptr
[i
* 4], "%04x", (unsigned int)(unsigned short)str
[i
]);
130 static unsigned decode_char(char c
)
132 if (c
>= '0' && c
<= '9') return c
- '0';
133 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
134 assert(c
>= 'A' && c
<= 'F');
138 static char* decodeA(const char* str
)
143 len
= strlen(str
) / 2;
144 if (!len
--) return NULL
;
145 ptr
= grab_memory(len
+ 1);
146 for (i
= 0; i
< len
; i
++)
147 ptr
[i
] = (decode_char(str
[2 * i
]) << 4) | decode_char(str
[2 * i
+ 1]);
152 /* This will be needed to decode Unicode strings saved by the child process
153 * when we test Unicode functions.
155 static WCHAR
* decodeW(const char* str
)
161 len
= strlen(str
) / 4;
162 if (!len
--) return NULL
;
163 ptr
= (WCHAR
*)grab_memory(len
* 2 + 1);
164 for (i
= 0; i
< len
; i
++)
165 ptr
[i
] = (decode_char(str
[4 * i
]) << 12) |
166 (decode_char(str
[4 * i
+ 1]) << 8) |
167 (decode_char(str
[4 * i
+ 2]) << 4) |
168 (decode_char(str
[4 * i
+ 3]) << 0);
173 /******************************************************************
176 * generates basic information like:
177 * base: absolute path to curr dir
178 * selfname: the way to reinvoke ourselves
179 * exename: executable without the path
180 * function-pointers, which are not implemented in all windows versions
182 static int init(void)
186 myARGC
= winetest_get_mainargs( &myARGV
);
187 if (!GetCurrentDirectoryA(sizeof(base
), base
)) return 0;
188 strcpy(selfname
, myARGV
[0]);
190 /* Strip the path of selfname */
191 if ((p
= strrchr(selfname
, '\\')) != NULL
) exename
= p
+ 1;
192 else exename
= selfname
;
194 if ((p
= strrchr(exename
, '/')) != NULL
) exename
= p
+ 1;
196 hkernel32
= GetModuleHandleA("kernel32");
197 pVirtualAllocEx
= (void *) GetProcAddress(hkernel32
, "VirtualAllocEx");
198 pVirtualFreeEx
= (void *) GetProcAddress(hkernel32
, "VirtualFreeEx");
199 pQueryFullProcessImageNameA
= (void *) GetProcAddress(hkernel32
, "QueryFullProcessImageNameA");
200 pQueryFullProcessImageNameW
= (void *) GetProcAddress(hkernel32
, "QueryFullProcessImageNameW");
204 /******************************************************************
207 * generates an absolute file_name for temporary file
210 static void get_file_name(char* buf
)
215 GetTempPathA(sizeof(path
), path
);
216 GetTempFileNameA(path
, "wt", 0, buf
);
219 /******************************************************************
220 * static void childPrintf
223 static void childPrintf(HANDLE h
, const char* fmt
, ...)
226 char buffer
[1024+4*MAX_LISTED_ENV_VAR
];
229 va_start(valist
, fmt
);
230 vsprintf(buffer
, fmt
, valist
);
232 WriteFile(h
, buffer
, strlen(buffer
), &w
, NULL
);
236 /******************************************************************
239 * output most of the information in the child process
241 static void doChild(const char* file
, const char* option
)
249 WCHAR bufW
[MAX_PATH
];
250 HANDLE hFile
= CreateFileA(file
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
253 if (hFile
== INVALID_HANDLE_VALUE
) return;
255 /* output of startup info (Ansi) */
256 GetStartupInfoA(&siA
);
258 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
259 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
260 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
261 "dwFlags=%lu\nwShowWindow=%u\n"
262 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
263 siA
.cb
, encodeA(siA
.lpDesktop
), encodeA(siA
.lpTitle
),
264 siA
.dwX
, siA
.dwY
, siA
.dwXSize
, siA
.dwYSize
,
265 siA
.dwXCountChars
, siA
.dwYCountChars
, siA
.dwFillAttribute
,
266 siA
.dwFlags
, siA
.wShowWindow
,
267 (DWORD_PTR
)siA
.hStdInput
, (DWORD_PTR
)siA
.hStdOutput
, (DWORD_PTR
)siA
.hStdError
);
269 /* since GetStartupInfoW is only implemented in win2k,
270 * zero out before calling so we can notice the difference
272 memset(&siW
, 0, sizeof(siW
));
273 GetStartupInfoW(&siW
);
275 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
276 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
277 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
278 "dwFlags=%lu\nwShowWindow=%u\n"
279 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
280 siW
.cb
, encodeW(siW
.lpDesktop
), encodeW(siW
.lpTitle
),
281 siW
.dwX
, siW
.dwY
, siW
.dwXSize
, siW
.dwYSize
,
282 siW
.dwXCountChars
, siW
.dwYCountChars
, siW
.dwFillAttribute
,
283 siW
.dwFlags
, siW
.wShowWindow
,
284 (DWORD_PTR
)siW
.hStdInput
, (DWORD_PTR
)siW
.hStdOutput
, (DWORD_PTR
)siW
.hStdError
);
287 childPrintf(hFile
, "[Arguments]\nargcA=%d\n", myARGC
);
288 for (i
= 0; i
< myARGC
; i
++)
290 childPrintf(hFile
, "argvA%d=%s\n", i
, encodeA(myARGV
[i
]));
292 childPrintf(hFile
, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
298 /* this is part of shell32... and should be tested there */
299 argvW
= CommandLineToArgvW(GetCommandLineW(), &argcW
);
300 for (i
= 0; i
< argcW
; i
++)
302 childPrintf(hFile
, "argvW%d=%s\n", i
, encodeW(argvW
[i
]));
305 childPrintf(hFile
, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
307 /* output of environment (Ansi) */
308 ptrA
= GetEnvironmentStringsA();
311 char env_var
[MAX_LISTED_ENV_VAR
];
313 childPrintf(hFile
, "[EnvironmentA]\n");
317 lstrcpynA(env_var
, ptrA
, MAX_LISTED_ENV_VAR
);
318 childPrintf(hFile
, "env%d=%s\n", i
, encodeA(env_var
));
320 ptrA
+= strlen(ptrA
) + 1;
322 childPrintf(hFile
, "len=%d\n\n", i
);
325 /* output of environment (Unicode) */
326 ptrW
= GetEnvironmentStringsW();
329 WCHAR env_var
[MAX_LISTED_ENV_VAR
];
331 childPrintf(hFile
, "[EnvironmentW]\n");
335 lstrcpynW(env_var
, ptrW
, MAX_LISTED_ENV_VAR
- 1);
336 env_var
[MAX_LISTED_ENV_VAR
- 1] = '\0';
337 childPrintf(hFile
, "env%d=%s\n", i
, encodeW(env_var
));
339 ptrW
+= lstrlenW(ptrW
) + 1;
341 childPrintf(hFile
, "len=%d\n\n", i
);
344 childPrintf(hFile
, "[Misc]\n");
345 if (GetCurrentDirectoryA(sizeof(bufA
), bufA
))
346 childPrintf(hFile
, "CurrDirA=%s\n", encodeA(bufA
));
347 if (GetCurrentDirectoryW(sizeof(bufW
) / sizeof(bufW
[0]), bufW
))
348 childPrintf(hFile
, "CurrDirW=%s\n", encodeW(bufW
));
349 childPrintf(hFile
, "\n");
351 if (option
&& strcmp(option
, "console") == 0)
353 CONSOLE_SCREEN_BUFFER_INFO sbi
;
354 HANDLE hConIn
= GetStdHandle(STD_INPUT_HANDLE
);
355 HANDLE hConOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
356 DWORD modeIn
, modeOut
;
358 childPrintf(hFile
, "[Console]\n");
359 if (GetConsoleScreenBufferInfo(hConOut
, &sbi
))
361 childPrintf(hFile
, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
362 sbi
.dwSize
.X
, sbi
.dwSize
.Y
, sbi
.dwCursorPosition
.X
, sbi
.dwCursorPosition
.Y
, sbi
.wAttributes
);
363 childPrintf(hFile
, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
364 sbi
.srWindow
.Left
, sbi
.srWindow
.Top
, sbi
.srWindow
.Right
, sbi
.srWindow
.Bottom
);
365 childPrintf(hFile
, "maxWinWidth=%d\nmaxWinHeight=%d\n",
366 sbi
.dwMaximumWindowSize
.X
, sbi
.dwMaximumWindowSize
.Y
);
368 childPrintf(hFile
, "InputCP=%d\nOutputCP=%d\n",
369 GetConsoleCP(), GetConsoleOutputCP());
370 if (GetConsoleMode(hConIn
, &modeIn
))
371 childPrintf(hFile
, "InputMode=%ld\n", modeIn
);
372 if (GetConsoleMode(hConOut
, &modeOut
))
373 childPrintf(hFile
, "OutputMode=%ld\n", modeOut
);
375 /* now that we have written all relevant information, let's change it */
376 SetLastError(0xdeadbeef);
377 ret
= SetConsoleCP(1252);
378 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
380 win_skip("Setting the codepage is not implemented\n");
384 ok(ret
, "Setting CP\n");
385 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
388 ret
= SetConsoleMode(hConIn
, modeIn
^ 1);
389 ok( ret
, "Setting mode (%d)\n", GetLastError());
390 ret
= SetConsoleMode(hConOut
, modeOut
^ 1);
391 ok( ret
, "Setting mode (%d)\n", GetLastError());
392 sbi
.dwCursorPosition
.X
^= 1;
393 sbi
.dwCursorPosition
.Y
^= 1;
394 ret
= SetConsoleCursorPosition(hConOut
, sbi
.dwCursorPosition
);
395 ok( ret
, "Setting cursor position (%d)\n", GetLastError());
397 if (option
&& strcmp(option
, "stdhandle") == 0)
399 HANDLE hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
400 HANDLE hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
402 if (hStdIn
!= INVALID_HANDLE_VALUE
|| hStdOut
!= INVALID_HANDLE_VALUE
)
407 ok(ReadFile(hStdIn
, buf
, sizeof(buf
), &r
, NULL
) && r
> 0, "Reading message from input pipe\n");
408 childPrintf(hFile
, "[StdHandle]\nmsg=%s\n\n", encodeA(buf
));
409 ok(WriteFile(hStdOut
, buf
, r
, &w
, NULL
) && w
== r
, "Writing message to output pipe\n");
413 if (option
&& strcmp(option
, "exit_code") == 0)
415 childPrintf(hFile
, "[ExitCode]\nvalue=%d\n\n", 123);
423 static char* getChildString(const char* sect
, const char* key
)
425 char buf
[1024+4*MAX_LISTED_ENV_VAR
];
428 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), resfile
);
429 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
430 assert(!(strlen(buf
) & 1));
435 static WCHAR
* getChildStringW(const char* sect
, const char* key
)
437 char buf
[1024+4*MAX_LISTED_ENV_VAR
];
440 GetPrivateProfileStringA(sect
, key
, "-", buf
, sizeof(buf
), resfile
);
441 if (buf
[0] == '\0' || (buf
[0] == '-' && buf
[1] == '\0')) return NULL
;
442 assert(!(strlen(buf
) & 1));
447 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
448 * others... (windows uses stricmp while Un*x uses strcasecmp...)
450 static int wtstrcasecmp(const char* p1
, const char* p2
)
455 while (c1
== c2
&& c1
)
457 c1
= *p1
++; c2
= *p2
++;
460 c1
= toupper(c1
); c2
= toupper(c2
);
466 static int strCmp(const char* s1
, const char* s2
, BOOL sensitive
)
468 if (!s1
&& !s2
) return 0;
471 return (sensitive
) ? strcmp(s1
, s2
) : wtstrcasecmp(s1
, s2
);
474 static void ok_child_string( int line
, const char *sect
, const char *key
,
475 const char *expect
, int sensitive
)
477 char* result
= getChildString( sect
, key
);
478 ok_(__FILE__
, line
)( strCmp(result
, expect
, sensitive
) == 0, "%s:%s expected '%s', got '%s'\n",
479 sect
, key
, expect
? expect
: "(null)", result
);
482 static void ok_child_stringWA( int line
, const char *sect
, const char *key
,
483 const char *expect
, int sensitive
)
488 WCHAR
* result
= getChildStringW( sect
, key
);
490 len
= MultiByteToWideChar( CP_ACP
, 0, expect
, -1, NULL
, 0);
491 expectW
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
492 MultiByteToWideChar( CP_ACP
, 0, expect
, -1, expectW
, len
);
494 len
= WideCharToMultiByte( CP_ACP
, 0, result
, -1, NULL
, 0, NULL
, NULL
);
495 resultA
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(CHAR
));
496 WideCharToMultiByte( CP_ACP
, 0, result
, -1, resultA
, len
, NULL
, NULL
);
499 ok_(__FILE__
, line
)( lstrcmpW(result
, expectW
) == 0, "%s:%s expected '%s', got '%s'\n",
500 sect
, key
, expect
? expect
: "(null)", resultA
);
502 ok_(__FILE__
, line
)( lstrcmpiW(result
, expectW
) == 0, "%s:%s expected '%s', got '%s'\n",
503 sect
, key
, expect
? expect
: "(null)", resultA
);
504 HeapFree(GetProcessHeap(),0,expectW
);
505 HeapFree(GetProcessHeap(),0,resultA
);
508 #define okChildString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 1 )
509 #define okChildIString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 0 )
510 #define okChildStringWA(sect, key, expect) ok_child_stringWA(__LINE__, (sect), (key), (expect), 1 )
512 /* using !expect ensures that the test will fail if the sect/key isn't present
515 #define okChildInt(sect, key, expect) \
517 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
518 ok(result == expect, "%s:%s expected %u, but got %u\n", (sect), (key), (UINT)(expect), result); \
521 static void test_Startup(void)
523 char buffer
[MAX_PATH
];
524 PROCESS_INFORMATION info
;
525 STARTUPINFOA startup
,si
;
526 static CHAR title
[] = "I'm the title string",
527 desktop
[] = "winsta0\\default",
530 /* let's start simplistic */
531 memset(&startup
, 0, sizeof(startup
));
532 startup
.cb
= sizeof(startup
);
533 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
534 startup
.wShowWindow
= SW_SHOWNORMAL
;
536 get_file_name(resfile
);
537 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
538 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
539 /* wait for child to terminate */
540 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
541 /* child process has changed result file, so let profile functions know about it */
542 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
544 GetStartupInfoA(&si
);
545 okChildInt("StartupInfoA", "cb", startup
.cb
);
546 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
547 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
548 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
549 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
550 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
551 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
552 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
553 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
554 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
555 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
557 assert(DeleteFileA(resfile
) != 0);
559 /* not so simplistic now */
560 memset(&startup
, 0, sizeof(startup
));
561 startup
.cb
= sizeof(startup
);
562 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
563 startup
.wShowWindow
= SW_SHOWNORMAL
;
564 startup
.lpTitle
= title
;
565 startup
.lpDesktop
= desktop
;
566 startup
.dwXCountChars
= 0x12121212;
567 startup
.dwYCountChars
= 0x23232323;
568 startup
.dwX
= 0x34343434;
569 startup
.dwY
= 0x45454545;
570 startup
.dwXSize
= 0x56565656;
571 startup
.dwYSize
= 0x67676767;
572 startup
.dwFillAttribute
= 0xA55A;
574 get_file_name(resfile
);
575 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
576 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
577 /* wait for child to terminate */
578 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
579 /* child process has changed result file, so let profile functions know about it */
580 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
582 okChildInt("StartupInfoA", "cb", startup
.cb
);
583 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
584 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
585 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
586 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
587 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
588 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
589 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
590 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
591 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
592 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
593 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
595 assert(DeleteFileA(resfile
) != 0);
597 /* not so simplistic now */
598 memset(&startup
, 0, sizeof(startup
));
599 startup
.cb
= sizeof(startup
);
600 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
601 startup
.wShowWindow
= SW_SHOWNORMAL
;
602 startup
.lpTitle
= title
;
603 startup
.lpDesktop
= NULL
;
604 startup
.dwXCountChars
= 0x12121212;
605 startup
.dwYCountChars
= 0x23232323;
606 startup
.dwX
= 0x34343434;
607 startup
.dwY
= 0x45454545;
608 startup
.dwXSize
= 0x56565656;
609 startup
.dwYSize
= 0x67676767;
610 startup
.dwFillAttribute
= 0xA55A;
612 get_file_name(resfile
);
613 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
614 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
615 /* wait for child to terminate */
616 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
617 /* child process has changed result file, so let profile functions know about it */
618 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
620 okChildInt("StartupInfoA", "cb", startup
.cb
);
621 okChildString("StartupInfoA", "lpDesktop", si
.lpDesktop
);
622 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
623 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
624 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
625 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
626 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
627 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
628 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
629 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
630 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
631 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
633 assert(DeleteFileA(resfile
) != 0);
635 /* not so simplistic now */
636 memset(&startup
, 0, sizeof(startup
));
637 startup
.cb
= sizeof(startup
);
638 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
639 startup
.wShowWindow
= SW_SHOWNORMAL
;
640 startup
.lpTitle
= title
;
641 startup
.lpDesktop
= empty
;
642 startup
.dwXCountChars
= 0x12121212;
643 startup
.dwYCountChars
= 0x23232323;
644 startup
.dwX
= 0x34343434;
645 startup
.dwY
= 0x45454545;
646 startup
.dwXSize
= 0x56565656;
647 startup
.dwYSize
= 0x67676767;
648 startup
.dwFillAttribute
= 0xA55A;
650 get_file_name(resfile
);
651 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
652 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
653 /* wait for child to terminate */
654 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
655 /* child process has changed result file, so let profile functions know about it */
656 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
658 okChildInt("StartupInfoA", "cb", startup
.cb
);
659 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
660 okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
661 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
662 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
663 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
664 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
665 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
666 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
667 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
668 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
669 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
671 assert(DeleteFileA(resfile
) != 0);
673 /* not so simplistic now */
674 memset(&startup
, 0, sizeof(startup
));
675 startup
.cb
= sizeof(startup
);
676 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
677 startup
.wShowWindow
= SW_SHOWNORMAL
;
678 startup
.lpTitle
= NULL
;
679 startup
.lpDesktop
= desktop
;
680 startup
.dwXCountChars
= 0x12121212;
681 startup
.dwYCountChars
= 0x23232323;
682 startup
.dwX
= 0x34343434;
683 startup
.dwY
= 0x45454545;
684 startup
.dwXSize
= 0x56565656;
685 startup
.dwYSize
= 0x67676767;
686 startup
.dwFillAttribute
= 0xA55A;
688 get_file_name(resfile
);
689 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
690 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
691 /* wait for child to terminate */
692 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
693 /* child process has changed result file, so let profile functions know about it */
694 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
696 okChildInt("StartupInfoA", "cb", startup
.cb
);
697 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
698 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
699 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
700 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
701 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
702 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
703 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
704 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
705 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
706 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
707 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
708 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
710 assert(DeleteFileA(resfile
) != 0);
712 /* not so simplistic now */
713 memset(&startup
, 0, sizeof(startup
));
714 startup
.cb
= sizeof(startup
);
715 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
716 startup
.wShowWindow
= SW_SHOWNORMAL
;
717 startup
.lpTitle
= empty
;
718 startup
.lpDesktop
= desktop
;
719 startup
.dwXCountChars
= 0x12121212;
720 startup
.dwYCountChars
= 0x23232323;
721 startup
.dwX
= 0x34343434;
722 startup
.dwY
= 0x45454545;
723 startup
.dwXSize
= 0x56565656;
724 startup
.dwYSize
= 0x67676767;
725 startup
.dwFillAttribute
= 0xA55A;
727 get_file_name(resfile
);
728 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
729 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
730 /* wait for child to terminate */
731 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
732 /* child process has changed result file, so let profile functions know about it */
733 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
735 okChildInt("StartupInfoA", "cb", startup
.cb
);
736 okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
737 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
738 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
739 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
740 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
741 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
742 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
743 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
744 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
745 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
746 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
748 assert(DeleteFileA(resfile
) != 0);
750 /* not so simplistic now */
751 memset(&startup
, 0, sizeof(startup
));
752 startup
.cb
= sizeof(startup
);
753 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
754 startup
.wShowWindow
= SW_SHOWNORMAL
;
755 startup
.lpTitle
= empty
;
756 startup
.lpDesktop
= empty
;
757 startup
.dwXCountChars
= 0x12121212;
758 startup
.dwYCountChars
= 0x23232323;
759 startup
.dwX
= 0x34343434;
760 startup
.dwY
= 0x45454545;
761 startup
.dwXSize
= 0x56565656;
762 startup
.dwYSize
= 0x67676767;
763 startup
.dwFillAttribute
= 0xA55A;
765 get_file_name(resfile
);
766 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
767 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
768 /* wait for child to terminate */
769 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
770 /* child process has changed result file, so let profile functions know about it */
771 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
773 okChildInt("StartupInfoA", "cb", startup
.cb
);
774 todo_wine
okChildString("StartupInfoA", "lpDesktop", startup
.lpDesktop
);
775 todo_wine
okChildString("StartupInfoA", "lpTitle", startup
.lpTitle
);
776 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
777 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
778 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
779 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
780 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
781 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
782 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
783 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
784 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
786 assert(DeleteFileA(resfile
) != 0);
788 /* TODO: test for A/W and W/A and W/W */
791 static void test_CommandLine(void)
793 char buffer
[MAX_PATH
], fullpath
[MAX_PATH
], *lpFilePart
, *p
;
794 char buffer2
[MAX_PATH
];
795 PROCESS_INFORMATION info
;
796 STARTUPINFOA startup
;
800 memset(&startup
, 0, sizeof(startup
));
801 startup
.cb
= sizeof(startup
);
802 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
803 startup
.wShowWindow
= SW_SHOWNORMAL
;
806 get_file_name(resfile
);
807 sprintf(buffer
, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname
, resfile
);
808 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
809 /* wait for child to terminate */
810 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
811 /* child process has changed result file, so let profile functions know about it */
812 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
814 okChildInt("Arguments", "argcA", 4);
815 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
816 okChildString("Arguments", "argvA4", NULL
);
817 okChildString("Arguments", "CommandLineA", buffer
);
819 assert(DeleteFileA(resfile
) != 0);
821 memset(&startup
, 0, sizeof(startup
));
822 startup
.cb
= sizeof(startup
);
823 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
824 startup
.wShowWindow
= SW_SHOWNORMAL
;
827 get_file_name(resfile
);
828 sprintf(buffer
, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname
, resfile
);
829 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
830 /* wait for child to terminate */
831 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
832 /* child process has changed result file, so let profile functions know about it */
833 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
835 okChildInt("Arguments", "argcA", 6);
836 okChildString("Arguments", "argvA3", "a\"b\\");
837 okChildString("Arguments", "argvA4", "c\"");
838 okChildString("Arguments", "argvA5", "d");
839 okChildString("Arguments", "argvA6", NULL
);
840 okChildString("Arguments", "CommandLineA", buffer
);
842 assert(DeleteFileA(resfile
) != 0);
844 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
845 get_file_name(resfile
);
846 /* Use exename to avoid buffer containing things like 'C:' */
847 sprintf(buffer
, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename
, resfile
);
848 SetLastError(0xdeadbeef);
849 ret
= CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
850 ok(ret
, "CreateProcess (%s) failed : %d\n", buffer
, GetLastError());
851 /* wait for child to terminate */
852 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
853 /* child process has changed result file, so let profile functions know about it */
854 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
855 sprintf(buffer
, "./%s", exename
);
856 okChildString("Arguments", "argvA0", buffer
);
858 assert(DeleteFileA(resfile
) != 0);
860 get_file_name(resfile
);
861 /* Use exename to avoid buffer containing things like 'C:' */
862 sprintf(buffer
, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename
, resfile
);
863 SetLastError(0xdeadbeef);
864 ret
= CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
865 ok(ret
, "CreateProcess (%s) failed : %d\n", buffer
, GetLastError());
866 /* wait for child to terminate */
867 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
868 /* child process has changed result file, so let profile functions know about it */
869 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
870 sprintf(buffer
, ".\\%s", exename
);
871 okChildString("Arguments", "argvA0", buffer
);
873 assert(DeleteFileA(resfile
) != 0);
875 get_file_name(resfile
);
876 len
= GetFullPathNameA(selfname
, MAX_PATH
, fullpath
, &lpFilePart
);
877 assert ( lpFilePart
!= 0);
878 *(lpFilePart
-1 ) = 0;
879 p
= strrchr(fullpath
, '\\');
880 /* Use exename to avoid buffer containing things like 'C:' */
881 if (p
) sprintf(buffer
, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p
, exename
, resfile
);
882 else sprintf(buffer
, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename
, resfile
);
883 SetLastError(0xdeadbeef);
884 ret
= CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
885 ok(ret
, "CreateProcess (%s) failed : %d\n", buffer
, GetLastError());
886 /* wait for child to terminate */
887 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
888 /* child process has changed result file, so let profile functions know about it */
889 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
890 if (p
) sprintf(buffer
, "..%s/%s", p
, exename
);
891 else sprintf(buffer
, "./%s", exename
);
892 okChildString("Arguments", "argvA0", buffer
);
894 assert(DeleteFileA(resfile
) != 0);
897 get_file_name(resfile
);
898 len
= GetFullPathNameA(selfname
, MAX_PATH
, fullpath
, &lpFilePart
);
899 assert ( lpFilePart
!= 0);
900 *(lpFilePart
-1 ) = 0;
901 p
= strrchr(fullpath
, '\\');
902 /* Use exename to avoid buffer containing things like 'C:' */
903 if (p
) sprintf(buffer
, "..%s/%s", p
, exename
);
904 else sprintf(buffer
, "./%s", exename
);
905 sprintf(buffer2
, "dummy tests/process.c %s \"a\\\"b\\\\\" c\\\" d", resfile
);
906 SetLastError(0xdeadbeef);
907 ret
= CreateProcessA(buffer
, buffer2
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
908 ok(ret
, "CreateProcess (%s) failed : %d\n", buffer
, GetLastError());
909 /* wait for child to terminate */
910 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
911 /* child process has changed result file, so let profile functions know about it */
912 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
913 sprintf(buffer
, "tests/process.c %s", resfile
);
914 okChildString("Arguments", "argvA0", "dummy");
915 okChildString("Arguments", "CommandLineA", buffer2
);
916 okChildStringWA("Arguments", "CommandLineW", buffer2
);
918 assert(DeleteFileA(resfile
) != 0);
920 if (0) /* Test crashes on NT-based Windows. */
922 /* Test NULL application name and command line parameters. */
923 SetLastError(0xdeadbeef);
924 ret
= CreateProcessA(NULL
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
925 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
926 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
927 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
932 /* Test empty application name parameter. */
933 SetLastError(0xdeadbeef);
934 ret
= CreateProcessA(buffer
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
935 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
936 ok(GetLastError() == ERROR_PATH_NOT_FOUND
||
937 broken(GetLastError() == ERROR_FILE_NOT_FOUND
) /* Win9x/WinME */ ||
938 broken(GetLastError() == ERROR_ACCESS_DENIED
) /* Win98 */,
939 "Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
943 /* Test empty application name and command line parameters. */
944 SetLastError(0xdeadbeef);
945 ret
= CreateProcessA(buffer
, buffer2
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
946 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
947 ok(GetLastError() == ERROR_PATH_NOT_FOUND
||
948 broken(GetLastError() == ERROR_FILE_NOT_FOUND
) /* Win9x/WinME */ ||
949 broken(GetLastError() == ERROR_ACCESS_DENIED
) /* Win98 */,
950 "Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
952 /* Test empty command line parameter. */
953 SetLastError(0xdeadbeef);
954 ret
= CreateProcessA(NULL
, buffer2
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
955 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
956 ok(GetLastError() == ERROR_FILE_NOT_FOUND
||
957 GetLastError() == ERROR_PATH_NOT_FOUND
/* NT4 */ ||
958 GetLastError() == ERROR_BAD_PATHNAME
/* Win98 */,
959 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
961 strcpy(buffer
, "doesnotexist.exe");
962 strcpy(buffer2
, "does not exist.exe");
964 /* Test nonexistent application name. */
965 SetLastError(0xdeadbeef);
966 ret
= CreateProcessA(buffer
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
967 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
968 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
970 SetLastError(0xdeadbeef);
971 ret
= CreateProcessA(buffer2
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
972 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
973 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
975 /* Test nonexistent command line parameter. */
976 SetLastError(0xdeadbeef);
977 ret
= CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
978 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
979 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
981 SetLastError(0xdeadbeef);
982 ret
= CreateProcessA(NULL
, buffer2
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
983 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
984 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
987 static void test_Directory(void)
989 char buffer
[MAX_PATH
];
990 PROCESS_INFORMATION info
;
991 STARTUPINFOA startup
;
992 char windir
[MAX_PATH
];
993 static CHAR cmdline
[] = "winver.exe";
995 memset(&startup
, 0, sizeof(startup
));
996 startup
.cb
= sizeof(startup
);
997 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
998 startup
.wShowWindow
= SW_SHOWNORMAL
;
1001 get_file_name(resfile
);
1002 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1003 GetWindowsDirectoryA( windir
, sizeof(windir
) );
1004 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, windir
, &startup
, &info
), "CreateProcess\n");
1005 /* wait for child to terminate */
1006 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1007 /* child process has changed result file, so let profile functions know about it */
1008 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1010 okChildIString("Misc", "CurrDirA", windir
);
1012 assert(DeleteFileA(resfile
) != 0);
1014 /* search PATH for the exe if directory is NULL */
1015 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1016 ok(TerminateProcess(info
.hProcess
, 0), "Child process termination\n");
1018 /* if any directory is provided, don't search PATH, error on bad directory */
1019 SetLastError(0xdeadbeef);
1020 memset(&info
, 0, sizeof(info
));
1021 ok(!CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L,
1022 NULL
, "non\\existent\\directory", &startup
, &info
), "CreateProcess\n");
1023 ok(GetLastError() == ERROR_DIRECTORY
, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
1024 ok(!TerminateProcess(info
.hProcess
, 0), "Child process should not exist\n");
1027 static BOOL
is_str_env_drive_dir(const char* str
)
1029 return str
[0] == '=' && str
[1] >= 'A' && str
[1] <= 'Z' && str
[2] == ':' &&
1030 str
[3] == '=' && str
[4] == str
[1];
1033 /* compared expected child's environment (in gesA) from actual
1034 * environment our child got
1036 static void cmpEnvironment(const char* gesA
)
1044 clen
= GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile
);
1046 /* now look each parent env in child */
1047 if ((ptrA
= gesA
) != NULL
)
1051 for (i
= 0; i
< clen
; i
++)
1053 sprintf(key
, "env%d", i
);
1054 res
= getChildString("EnvironmentA", key
);
1055 if (strncmp(ptrA
, res
, MAX_LISTED_ENV_VAR
- 1) == 0)
1059 ok(found
, "Parent-env string %s isn't in child process\n", ptrA
);
1061 ptrA
+= strlen(ptrA
) + 1;
1065 /* and each child env in parent */
1066 for (i
= 0; i
< clen
; i
++)
1068 sprintf(key
, "env%d", i
);
1069 res
= getChildString("EnvironmentA", key
);
1070 if ((ptrA
= gesA
) != NULL
)
1074 if (strncmp(res
, ptrA
, MAX_LISTED_ENV_VAR
- 1) == 0)
1076 ptrA
+= strlen(ptrA
) + 1;
1078 if (!*ptrA
) ptrA
= NULL
;
1081 if (!is_str_env_drive_dir(res
))
1083 found
= ptrA
!= NULL
;
1084 ok(found
, "Child-env string %s isn't in parent process\n", res
);
1086 /* else => should also test we get the right per drive default directory here... */
1090 static void test_Environment(void)
1092 char buffer
[MAX_PATH
];
1093 PROCESS_INFORMATION info
;
1094 STARTUPINFOA startup
;
1101 memset(&startup
, 0, sizeof(startup
));
1102 startup
.cb
= sizeof(startup
);
1103 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1104 startup
.wShowWindow
= SW_SHOWNORMAL
;
1107 get_file_name(resfile
);
1108 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1109 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1110 /* wait for child to terminate */
1111 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1112 /* child process has changed result file, so let profile functions know about it */
1113 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1115 cmpEnvironment(GetEnvironmentStringsA());
1117 assert(DeleteFileA(resfile
) != 0);
1119 memset(&startup
, 0, sizeof(startup
));
1120 startup
.cb
= sizeof(startup
);
1121 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1122 startup
.wShowWindow
= SW_SHOWNORMAL
;
1125 get_file_name(resfile
);
1126 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1129 ptr
= GetEnvironmentStringsA();
1132 slen
= strlen(ptr
)+1;
1133 child_env_len
+= slen
;
1136 /* Add space for additional environment variables */
1137 child_env_len
+= 256;
1138 child_env
= HeapAlloc(GetProcessHeap(), 0, child_env_len
);
1141 sprintf(ptr
, "=%c:=%s", 'C', "C:\\FOO\\BAR");
1142 ptr
+= strlen(ptr
) + 1;
1143 strcpy(ptr
, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
1144 ptr
+= strlen(ptr
) + 1;
1145 strcpy(ptr
, "FOO=BAR");
1146 ptr
+= strlen(ptr
) + 1;
1147 strcpy(ptr
, "BAR=FOOBAR");
1148 ptr
+= strlen(ptr
) + 1;
1149 /* copy all existing variables except:
1151 * - PATH (already set above)
1152 * - the directory definitions (=[A-Z]:=)
1154 for (env
= GetEnvironmentStringsA(); *env
; env
+= strlen(env
) + 1)
1156 if (strncmp(env
, "PATH=", 5) != 0 &&
1157 strncmp(env
, "WINELOADER=", 11) != 0 &&
1158 !is_str_env_drive_dir(env
))
1161 ptr
+= strlen(ptr
) + 1;
1165 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, child_env
, NULL
, &startup
, &info
), "CreateProcess\n");
1166 /* wait for child to terminate */
1167 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1168 /* child process has changed result file, so let profile functions know about it */
1169 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1171 cmpEnvironment(child_env
);
1173 HeapFree(GetProcessHeap(), 0, child_env
);
1175 assert(DeleteFileA(resfile
) != 0);
1178 static void test_SuspendFlag(void)
1180 char buffer
[MAX_PATH
];
1181 PROCESS_INFORMATION info
;
1182 STARTUPINFOA startup
, us
;
1185 /* let's start simplistic */
1186 memset(&startup
, 0, sizeof(startup
));
1187 startup
.cb
= sizeof(startup
);
1188 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1189 startup
.wShowWindow
= SW_SHOWNORMAL
;
1191 get_file_name(resfile
);
1192 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1193 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1195 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1197 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1198 ok(ResumeThread(info
.hThread
) == 1, "Resuming thread\n");
1200 /* wait for child to terminate */
1201 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1202 /* child process has changed result file, so let profile functions know about it */
1203 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1205 GetStartupInfoA(&us
);
1207 okChildInt("StartupInfoA", "cb", startup
.cb
);
1208 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1209 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1210 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1211 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1212 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1213 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1214 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1215 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1216 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1217 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1218 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1219 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1221 assert(DeleteFileA(resfile
) != 0);
1224 static void test_DebuggingFlag(void)
1226 char buffer
[MAX_PATH
];
1227 void *processbase
= NULL
;
1228 PROCESS_INFORMATION info
;
1229 STARTUPINFOA startup
, us
;
1233 /* let's start simplistic */
1234 memset(&startup
, 0, sizeof(startup
));
1235 startup
.cb
= sizeof(startup
);
1236 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1237 startup
.wShowWindow
= SW_SHOWNORMAL
;
1239 get_file_name(resfile
);
1240 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1241 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1243 /* get all startup events up to the entry point break exception */
1246 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
1247 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
1250 ok(de
.dwDebugEventCode
== CREATE_PROCESS_DEBUG_EVENT
,
1251 "first event: %d\n", de
.dwDebugEventCode
);
1252 processbase
= de
.u
.CreateProcessInfo
.lpBaseOfImage
;
1254 if (de
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
) dbg
++;
1255 ok(de
.dwDebugEventCode
!= LOAD_DLL_DEBUG_EVENT
||
1256 de
.u
.LoadDll
.lpBaseOfDll
!= processbase
, "got LOAD_DLL for main module\n");
1257 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
1259 ok(dbg
, "I have seen a debug event\n");
1260 /* wait for child to terminate */
1261 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1262 /* child process has changed result file, so let profile functions know about it */
1263 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1265 GetStartupInfoA(&us
);
1267 okChildInt("StartupInfoA", "cb", startup
.cb
);
1268 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1269 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1270 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1271 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1272 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1273 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1274 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1275 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1276 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1277 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1278 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1279 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1281 assert(DeleteFileA(resfile
) != 0);
1284 static BOOL
is_console(HANDLE h
)
1286 return h
!= INVALID_HANDLE_VALUE
&& ((ULONG_PTR
)h
& 3) == 3;
1289 static void test_Console(void)
1291 char buffer
[MAX_PATH
];
1292 PROCESS_INFORMATION info
;
1293 STARTUPINFOA startup
, us
;
1294 SECURITY_ATTRIBUTES sa
;
1295 CONSOLE_SCREEN_BUFFER_INFO sbi
, sbiC
;
1296 DWORD modeIn
, modeOut
, modeInC
, modeOutC
;
1297 DWORD cpIn
, cpOut
, cpInC
, cpOutC
;
1299 HANDLE hChildIn
, hChildInInh
, hChildOut
, hChildOutInh
, hParentIn
, hParentOut
;
1300 const char* msg
= "This is a std-handle inheritance test.";
1302 BOOL run_tests
= TRUE
;
1304 memset(&startup
, 0, sizeof(startup
));
1305 startup
.cb
= sizeof(startup
);
1306 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1307 startup
.wShowWindow
= SW_SHOWNORMAL
;
1309 sa
.nLength
= sizeof(sa
);
1310 sa
.lpSecurityDescriptor
= NULL
;
1311 sa
.bInheritHandle
= TRUE
;
1313 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1314 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1316 /* first, we need to be sure we're attached to a console */
1317 if (!is_console(startup
.hStdInput
) || !is_console(startup
.hStdOutput
))
1319 /* we're not attached to a console, let's do it */
1321 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1322 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1324 /* now verify everything's ok */
1325 ok(startup
.hStdInput
!= INVALID_HANDLE_VALUE
, "Opening ConIn\n");
1326 ok(startup
.hStdOutput
!= INVALID_HANDLE_VALUE
, "Opening ConOut\n");
1327 startup
.hStdError
= startup
.hStdOutput
;
1329 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbi
), "Getting sb info\n");
1330 ok(GetConsoleMode(startup
.hStdInput
, &modeIn
) &&
1331 GetConsoleMode(startup
.hStdOutput
, &modeOut
), "Getting console modes\n");
1332 cpIn
= GetConsoleCP();
1333 cpOut
= GetConsoleOutputCP();
1335 get_file_name(resfile
);
1336 sprintf(buffer
, "%s tests/process.c %s console", selfname
, resfile
);
1337 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1339 /* wait for child to terminate */
1340 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1341 /* child process has changed result file, so let profile functions know about it */
1342 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1344 /* now get the modification the child has made, and resets parents expected values */
1345 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbiC
), "Getting sb info\n");
1346 ok(GetConsoleMode(startup
.hStdInput
, &modeInC
) &&
1347 GetConsoleMode(startup
.hStdOutput
, &modeOutC
), "Getting console modes\n");
1349 SetConsoleMode(startup
.hStdInput
, modeIn
);
1350 SetConsoleMode(startup
.hStdOutput
, modeOut
);
1352 cpInC
= GetConsoleCP();
1353 cpOutC
= GetConsoleOutputCP();
1355 /* Try to set invalid CP */
1356 SetLastError(0xdeadbeef);
1357 ok(!SetConsoleCP(0), "Shouldn't succeed\n");
1358 ok(GetLastError()==ERROR_INVALID_PARAMETER
||
1359 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
), /* win9x */
1360 "GetLastError: expecting %u got %u\n",
1361 ERROR_INVALID_PARAMETER
, GetLastError());
1362 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1366 SetLastError(0xdeadbeef);
1367 ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
1368 ok(GetLastError()==ERROR_INVALID_PARAMETER
||
1369 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
), /* win9x */
1370 "GetLastError: expecting %u got %u\n",
1371 ERROR_INVALID_PARAMETER
, GetLastError());
1374 SetConsoleOutputCP(cpOut
);
1376 GetStartupInfoA(&us
);
1378 okChildInt("StartupInfoA", "cb", startup
.cb
);
1379 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1380 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1381 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1382 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1383 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1384 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1385 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1386 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1387 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1388 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1389 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1390 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1392 /* check child correctly inherited the console */
1393 okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR
)startup
.hStdInput
);
1394 okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR
)startup
.hStdOutput
);
1395 okChildInt("StartupInfoA", "hStdError", (DWORD_PTR
)startup
.hStdError
);
1396 okChildInt("Console", "SizeX", (DWORD
)sbi
.dwSize
.X
);
1397 okChildInt("Console", "SizeY", (DWORD
)sbi
.dwSize
.Y
);
1398 okChildInt("Console", "CursorX", (DWORD
)sbi
.dwCursorPosition
.X
);
1399 okChildInt("Console", "CursorY", (DWORD
)sbi
.dwCursorPosition
.Y
);
1400 okChildInt("Console", "Attributes", sbi
.wAttributes
);
1401 okChildInt("Console", "winLeft", (DWORD
)sbi
.srWindow
.Left
);
1402 okChildInt("Console", "winTop", (DWORD
)sbi
.srWindow
.Top
);
1403 okChildInt("Console", "winRight", (DWORD
)sbi
.srWindow
.Right
);
1404 okChildInt("Console", "winBottom", (DWORD
)sbi
.srWindow
.Bottom
);
1405 okChildInt("Console", "maxWinWidth", (DWORD
)sbi
.dwMaximumWindowSize
.X
);
1406 okChildInt("Console", "maxWinHeight", (DWORD
)sbi
.dwMaximumWindowSize
.Y
);
1407 okChildInt("Console", "InputCP", cpIn
);
1408 okChildInt("Console", "OutputCP", cpOut
);
1409 okChildInt("Console", "InputMode", modeIn
);
1410 okChildInt("Console", "OutputMode", modeOut
);
1414 ok(cpInC
== 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC
, cpIn
);
1415 ok(cpOutC
== 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC
, cpOut
);
1418 win_skip("Setting the codepage is not implemented\n");
1420 ok(modeInC
== (modeIn
^ 1), "Wrong console mode\n");
1421 ok(modeOutC
== (modeOut
^ 1), "Wrong console-SB mode\n");
1422 trace("cursor position(X): %d/%d\n",sbi
.dwCursorPosition
.X
, sbiC
.dwCursorPosition
.X
);
1423 ok(sbiC
.dwCursorPosition
.Y
== (sbi
.dwCursorPosition
.Y
^ 1), "Wrong cursor position\n");
1426 assert(DeleteFileA(resfile
) != 0);
1428 ok(CreatePipe(&hParentIn
, &hChildOut
, NULL
, 0), "Creating parent-input pipe\n");
1429 ok(DuplicateHandle(GetCurrentProcess(), hChildOut
, GetCurrentProcess(),
1430 &hChildOutInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1431 "Duplicating as inheritable child-output pipe\n");
1432 CloseHandle(hChildOut
);
1434 ok(CreatePipe(&hChildIn
, &hParentOut
, NULL
, 0), "Creating parent-output pipe\n");
1435 ok(DuplicateHandle(GetCurrentProcess(), hChildIn
, GetCurrentProcess(),
1436 &hChildInInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1437 "Duplicating as inheritable child-input pipe\n");
1438 CloseHandle(hChildIn
);
1440 memset(&startup
, 0, sizeof(startup
));
1441 startup
.cb
= sizeof(startup
);
1442 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1443 startup
.wShowWindow
= SW_SHOWNORMAL
;
1444 startup
.hStdInput
= hChildInInh
;
1445 startup
.hStdOutput
= hChildOutInh
;
1446 startup
.hStdError
= hChildOutInh
;
1448 get_file_name(resfile
);
1449 sprintf(buffer
, "%s tests/process.c %s stdhandle", selfname
, resfile
);
1450 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1451 ok(CloseHandle(hChildInInh
), "Closing handle\n");
1452 ok(CloseHandle(hChildOutInh
), "Closing handle\n");
1454 msg_len
= strlen(msg
) + 1;
1455 ok(WriteFile(hParentOut
, msg
, msg_len
, &w
, NULL
), "Writing to child\n");
1456 ok(w
== msg_len
, "Should have written %u bytes, actually wrote %u\n", msg_len
, w
);
1457 memset(buffer
, 0, sizeof(buffer
));
1458 ok(ReadFile(hParentIn
, buffer
, sizeof(buffer
), &w
, NULL
), "Reading from child\n");
1459 ok(strcmp(buffer
, msg
) == 0, "Should have received '%s'\n", msg
);
1461 /* wait for child to terminate */
1462 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1463 /* child process has changed result file, so let profile functions know about it */
1464 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1466 okChildString("StdHandle", "msg", msg
);
1469 assert(DeleteFileA(resfile
) != 0);
1472 static void test_ExitCode(void)
1474 char buffer
[MAX_PATH
];
1475 PROCESS_INFORMATION info
;
1476 STARTUPINFOA startup
;
1479 /* let's start simplistic */
1480 memset(&startup
, 0, sizeof(startup
));
1481 startup
.cb
= sizeof(startup
);
1482 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1483 startup
.wShowWindow
= SW_SHOWNORMAL
;
1485 get_file_name(resfile
);
1486 sprintf(buffer
, "%s tests/process.c %s exit_code", selfname
, resfile
);
1487 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1489 /* wait for child to terminate */
1490 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1491 /* child process has changed result file, so let profile functions know about it */
1492 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1494 ok(GetExitCodeProcess(info
.hProcess
, &code
), "Getting exit code\n");
1495 okChildInt("ExitCode", "value", code
);
1498 assert(DeleteFileA(resfile
) != 0);
1501 static void test_OpenProcess(void)
1505 MEMORY_BASIC_INFORMATION info
;
1506 SIZE_T dummy
, read_bytes
;
1508 /* not exported in all windows versions */
1509 if ((!pVirtualAllocEx
) || (!pVirtualFreeEx
)) {
1510 win_skip("VirtualAllocEx not found\n");
1514 /* without PROCESS_VM_OPERATION */
1515 hproc
= OpenProcess(PROCESS_ALL_ACCESS
& ~PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1516 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1518 SetLastError(0xdeadbeef);
1519 addr1
= pVirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1520 ok(!addr1
, "VirtualAllocEx should fail\n");
1521 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1524 win_skip("VirtualAllocEx not implemented\n");
1527 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1529 read_bytes
= 0xdeadbeef;
1530 SetLastError(0xdeadbeef);
1531 ok(ReadProcessMemory(hproc
, test_OpenProcess
, &dummy
, sizeof(dummy
), &read_bytes
),
1532 "ReadProcessMemory error %d\n", GetLastError());
1533 ok(read_bytes
== sizeof(dummy
), "wrong read bytes %ld\n", read_bytes
);
1537 hproc
= OpenProcess(PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1538 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1540 addr1
= pVirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1541 ok(addr1
!= NULL
, "VirtualAllocEx error %d\n", GetLastError());
1543 /* without PROCESS_QUERY_INFORMATION */
1544 SetLastError(0xdeadbeef);
1545 ok(!VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)),
1546 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1547 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1549 /* without PROCESS_VM_READ */
1550 read_bytes
= 0xdeadbeef;
1551 SetLastError(0xdeadbeef);
1552 ok(!ReadProcessMemory(hproc
, addr1
, &dummy
, sizeof(dummy
), &read_bytes
),
1553 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1554 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1555 ok(read_bytes
== 0, "wrong read bytes %ld\n", read_bytes
);
1559 hproc
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
1561 memset(&info
, 0xcc, sizeof(info
));
1562 ok(VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)) == sizeof(info
),
1563 "VirtualQueryEx error %d\n", GetLastError());
1565 ok(info
.BaseAddress
== addr1
, "%p != %p\n", info
.BaseAddress
, addr1
);
1566 ok(info
.AllocationBase
== addr1
, "%p != %p\n", info
.AllocationBase
, addr1
);
1567 ok(info
.AllocationProtect
== PAGE_NOACCESS
, "%x != PAGE_NOACCESS\n", info
.AllocationProtect
);
1568 ok(info
.RegionSize
== 0x10000, "%lx != 0x10000\n", info
.RegionSize
);
1569 ok(info
.State
== MEM_RESERVE
, "%x != MEM_RESERVE\n", info
.State
);
1570 /* NT reports Protect == 0 for a not committed memory block */
1571 ok(info
.Protect
== 0 /* NT */ ||
1572 info
.Protect
== PAGE_NOACCESS
, /* Win9x */
1573 "%x != PAGE_NOACCESS\n", info
.Protect
);
1574 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
1576 SetLastError(0xdeadbeef);
1577 ok(!pVirtualFreeEx(hproc
, addr1
, 0, MEM_RELEASE
),
1578 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1579 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1583 ok(VirtualFree(addr1
, 0, MEM_RELEASE
), "VirtualFree failed\n");
1586 static void test_GetProcessVersion(void)
1588 static char cmdline
[] = "winver.exe";
1589 PROCESS_INFORMATION pi
;
1593 SetLastError(0xdeadbeef);
1594 ret
= GetProcessVersion(0);
1595 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1597 SetLastError(0xdeadbeef);
1598 ret
= GetProcessVersion(GetCurrentProcessId());
1599 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1601 memset(&si
, 0, sizeof(si
));
1603 si
.dwFlags
= STARTF_USESHOWWINDOW
;
1604 si
.wShowWindow
= SW_HIDE
;
1605 ret
= CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
1606 SetLastError(0xdeadbeef);
1607 ok(ret
, "CreateProcess error %u\n", GetLastError());
1609 SetLastError(0xdeadbeef);
1610 ret
= GetProcessVersion(pi
.dwProcessId
);
1611 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1613 SetLastError(0xdeadbeef);
1614 ret
= TerminateProcess(pi
.hProcess
, 0);
1615 ok(ret
, "TerminateProcess error %u\n", GetLastError());
1617 CloseHandle(pi
.hProcess
);
1618 CloseHandle(pi
.hThread
);
1621 static void test_ProcessNameA(void)
1623 #define INIT_STR "Just some words"
1627 if (!pQueryFullProcessImageNameA
)
1629 win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
1632 /* get the buffer length without \0 terminator */
1634 expect_eq_d(TRUE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &length
));
1635 expect_eq_d(length
, lstrlenA(buf
));
1637 /* when the buffer is too small
1638 * - function fail with error ERROR_INSUFFICIENT_BUFFER
1639 * - the size variable is not modified
1640 * tested with the biggest too small size
1643 sprintf(buf
,INIT_STR
);
1644 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &size
));
1645 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1646 expect_eq_d(length
, size
);
1647 expect_eq_s(INIT_STR
, buf
);
1649 /* retest with smaller buffer size
1652 sprintf(buf
,INIT_STR
);
1653 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &size
));
1654 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1655 expect_eq_d(4, size
);
1656 expect_eq_s(INIT_STR
, buf
);
1658 /* this is a difference between the ascii and the unicode version
1659 * the unicode version crashes when the size is big enough to hold the result
1660 * ascii version throughs an error
1663 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, NULL
, &size
));
1664 expect_eq_d(1024, size
);
1665 expect_eq_d(ERROR_INVALID_PARAMETER
, GetLastError());
1668 static void test_ProcessName(void)
1671 WCHAR module_name
[1024];
1672 WCHAR deviceW
[] = {'\\','D', 'e','v','i','c','e',0};
1676 if (!pQueryFullProcessImageNameW
)
1678 win_skip("QueryFullProcessImageNameW unavailable (added in Windows Vista)\n");
1682 ok(GetModuleFileNameW(NULL
, module_name
, 1024), "GetModuleFileNameW(NULL, ...) failed\n");
1684 /* GetCurrentProcess pseudo-handle */
1685 size
= sizeof(buf
) / sizeof(buf
[0]);
1686 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(GetCurrentProcess(), 0, buf
, &size
));
1687 expect_eq_d(lstrlenW(buf
), size
);
1688 expect_eq_ws_i(buf
, module_name
);
1690 hSelf
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
1692 size
= sizeof(buf
) / sizeof(buf
[0]);
1693 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1694 expect_eq_d(lstrlenW(buf
), size
);
1695 expect_eq_ws_i(buf
, module_name
);
1697 /* Buffer too small */
1698 size
= lstrlenW(module_name
)/2;
1699 lstrcpyW(buf
, deviceW
);
1700 SetLastError(0xdeadbeef);
1701 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1702 expect_eq_d(lstrlenW(module_name
)/2, size
); /* size not changed(!) */
1703 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1704 expect_eq_ws_i(deviceW
, buf
); /* buffer not changed */
1706 /* Too small - not space for NUL terminator */
1707 size
= lstrlenW(module_name
);
1708 SetLastError(0xdeadbeef);
1709 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1710 expect_eq_d(lstrlenW(module_name
), size
); /* size not changed(!) */
1711 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1715 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, NULL
, &size
));
1716 expect_eq_d(0, size
);
1717 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1720 size
= sizeof(buf
) / sizeof(buf
[0]);
1721 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(hSelf
, PROCESS_NAME_NATIVE
, buf
, &size
));
1722 expect_eq_d(lstrlenW(buf
), size
);
1723 ok(buf
[0] == '\\', "NT path should begin with '\\'\n");
1724 todo_wine
ok(memcmp(buf
, deviceW
, sizeof(WCHAR
)*lstrlenW(deviceW
)) == 0, "NT path should begin with \\Device\n");
1726 /* Buffer too small */
1727 size
= lstrlenW(module_name
)/2;
1728 SetLastError(0xdeadbeef);
1729 lstrcpyW(buf
, module_name
);
1730 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1731 expect_eq_d(lstrlenW(module_name
)/2, size
); /* size not changed(!) */
1732 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1733 expect_eq_ws_i(module_name
, buf
); /* buffer not changed */
1738 static void test_Handles(void)
1740 HANDLE handle
= GetCurrentProcess();
1744 ok( handle
== (HANDLE
)~(ULONG_PTR
)0 ||
1745 handle
== (HANDLE
)(ULONG_PTR
)0x7fffffff /* win9x */,
1746 "invalid current process handle %p\n", handle
);
1747 ret
= GetExitCodeProcess( handle
, &code
);
1748 ok( ret
, "GetExitCodeProcess failed err %u\n", GetLastError() );
1750 /* truncated handle */
1751 SetLastError( 0xdeadbeef );
1752 handle
= (HANDLE
)((ULONG_PTR
)handle
& ~0u);
1753 ret
= GetExitCodeProcess( handle
, &code
);
1754 ok( !ret
, "GetExitCodeProcess succeeded for %p\n", handle
);
1755 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
1756 /* sign-extended handle */
1757 SetLastError( 0xdeadbeef );
1758 handle
= (HANDLE
)((LONG_PTR
)(int)(ULONG_PTR
)handle
);
1759 ret
= GetExitCodeProcess( handle
, &code
);
1760 ok( ret
, "GetExitCodeProcess failed err %u\n", GetLastError() );
1761 /* invalid high-word */
1762 SetLastError( 0xdeadbeef );
1763 handle
= (HANDLE
)(((ULONG_PTR
)handle
& ~0u) + ((ULONG_PTR
)1 << 32));
1764 ret
= GetExitCodeProcess( handle
, &code
);
1765 ok( !ret
, "GetExitCodeProcess succeeded for %p\n", handle
);
1766 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
1773 ok(b
, "Basic init of CreateProcess test\n");
1778 doChild(myARGV
[2], (myARGC
== 3) ? NULL
: myARGV
[3]);
1786 test_DebuggingFlag();
1790 test_GetProcessVersion();
1791 test_ProcessNameA();
1794 /* things that can be tested:
1795 * lookup: check the way program to be executed is searched
1796 * handles: check the handle inheritance stuff (+sec options)
1797 * console: check if console creation parameters work