2 * Unit test suite for process functions
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 GetLastError() == ERROR_INVALID_PARAMETER
/* Win7 */,
960 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
962 strcpy(buffer
, "doesnotexist.exe");
963 strcpy(buffer2
, "does not exist.exe");
965 /* Test nonexistent application name. */
966 SetLastError(0xdeadbeef);
967 ret
= CreateProcessA(buffer
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
968 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
969 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
971 SetLastError(0xdeadbeef);
972 ret
= CreateProcessA(buffer2
, NULL
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
973 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
974 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
976 /* Test nonexistent command line parameter. */
977 SetLastError(0xdeadbeef);
978 ret
= CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
979 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
980 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
982 SetLastError(0xdeadbeef);
983 ret
= CreateProcessA(NULL
, buffer2
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
);
984 ok(!ret
, "CreateProcessA unexpectedly succeeded\n");
985 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
988 static void test_Directory(void)
990 char buffer
[MAX_PATH
];
991 PROCESS_INFORMATION info
;
992 STARTUPINFOA startup
;
993 char windir
[MAX_PATH
];
994 static CHAR cmdline
[] = "winver.exe";
996 memset(&startup
, 0, sizeof(startup
));
997 startup
.cb
= sizeof(startup
);
998 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
999 startup
.wShowWindow
= SW_SHOWNORMAL
;
1002 get_file_name(resfile
);
1003 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1004 GetWindowsDirectoryA( windir
, sizeof(windir
) );
1005 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, windir
, &startup
, &info
), "CreateProcess\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 okChildIString("Misc", "CurrDirA", windir
);
1013 assert(DeleteFileA(resfile
) != 0);
1015 /* search PATH for the exe if directory is NULL */
1016 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1017 ok(TerminateProcess(info
.hProcess
, 0), "Child process termination\n");
1019 /* if any directory is provided, don't search PATH, error on bad directory */
1020 SetLastError(0xdeadbeef);
1021 memset(&info
, 0, sizeof(info
));
1022 ok(!CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L,
1023 NULL
, "non\\existent\\directory", &startup
, &info
), "CreateProcess\n");
1024 ok(GetLastError() == ERROR_DIRECTORY
, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
1025 ok(!TerminateProcess(info
.hProcess
, 0), "Child process should not exist\n");
1028 static BOOL
is_str_env_drive_dir(const char* str
)
1030 return str
[0] == '=' && str
[1] >= 'A' && str
[1] <= 'Z' && str
[2] == ':' &&
1031 str
[3] == '=' && str
[4] == str
[1];
1034 /* compared expected child's environment (in gesA) from actual
1035 * environment our child got
1037 static void cmpEnvironment(const char* gesA
)
1045 clen
= GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile
);
1047 /* now look each parent env in child */
1048 if ((ptrA
= gesA
) != NULL
)
1052 for (i
= 0; i
< clen
; i
++)
1054 sprintf(key
, "env%d", i
);
1055 res
= getChildString("EnvironmentA", key
);
1056 if (strncmp(ptrA
, res
, MAX_LISTED_ENV_VAR
- 1) == 0)
1060 ok(found
, "Parent-env string %s isn't in child process\n", ptrA
);
1062 ptrA
+= strlen(ptrA
) + 1;
1066 /* and each child env in parent */
1067 for (i
= 0; i
< clen
; i
++)
1069 sprintf(key
, "env%d", i
);
1070 res
= getChildString("EnvironmentA", key
);
1071 if ((ptrA
= gesA
) != NULL
)
1075 if (strncmp(res
, ptrA
, MAX_LISTED_ENV_VAR
- 1) == 0)
1077 ptrA
+= strlen(ptrA
) + 1;
1079 if (!*ptrA
) ptrA
= NULL
;
1082 if (!is_str_env_drive_dir(res
))
1084 found
= ptrA
!= NULL
;
1085 ok(found
, "Child-env string %s isn't in parent process\n", res
);
1087 /* else => should also test we get the right per drive default directory here... */
1091 static void test_Environment(void)
1093 char buffer
[MAX_PATH
];
1094 PROCESS_INFORMATION info
;
1095 STARTUPINFOA startup
;
1102 memset(&startup
, 0, sizeof(startup
));
1103 startup
.cb
= sizeof(startup
);
1104 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1105 startup
.wShowWindow
= SW_SHOWNORMAL
;
1108 get_file_name(resfile
);
1109 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1110 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1111 /* wait for child to terminate */
1112 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1113 /* child process has changed result file, so let profile functions know about it */
1114 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1116 cmpEnvironment(GetEnvironmentStringsA());
1118 assert(DeleteFileA(resfile
) != 0);
1120 memset(&startup
, 0, sizeof(startup
));
1121 startup
.cb
= sizeof(startup
);
1122 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1123 startup
.wShowWindow
= SW_SHOWNORMAL
;
1126 get_file_name(resfile
);
1127 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1130 ptr
= GetEnvironmentStringsA();
1133 slen
= strlen(ptr
)+1;
1134 child_env_len
+= slen
;
1137 /* Add space for additional environment variables */
1138 child_env_len
+= 256;
1139 child_env
= HeapAlloc(GetProcessHeap(), 0, child_env_len
);
1142 sprintf(ptr
, "=%c:=%s", 'C', "C:\\FOO\\BAR");
1143 ptr
+= strlen(ptr
) + 1;
1144 strcpy(ptr
, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
1145 ptr
+= strlen(ptr
) + 1;
1146 strcpy(ptr
, "FOO=BAR");
1147 ptr
+= strlen(ptr
) + 1;
1148 strcpy(ptr
, "BAR=FOOBAR");
1149 ptr
+= strlen(ptr
) + 1;
1150 /* copy all existing variables except:
1152 * - PATH (already set above)
1153 * - the directory definitions (=[A-Z]:=)
1155 for (env
= GetEnvironmentStringsA(); *env
; env
+= strlen(env
) + 1)
1157 if (strncmp(env
, "PATH=", 5) != 0 &&
1158 strncmp(env
, "WINELOADER=", 11) != 0 &&
1159 !is_str_env_drive_dir(env
))
1162 ptr
+= strlen(ptr
) + 1;
1166 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0L, child_env
, NULL
, &startup
, &info
), "CreateProcess\n");
1167 /* wait for child to terminate */
1168 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1169 /* child process has changed result file, so let profile functions know about it */
1170 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1172 cmpEnvironment(child_env
);
1174 HeapFree(GetProcessHeap(), 0, child_env
);
1176 assert(DeleteFileA(resfile
) != 0);
1179 static void test_SuspendFlag(void)
1181 char buffer
[MAX_PATH
];
1182 PROCESS_INFORMATION info
;
1183 STARTUPINFOA startup
, us
;
1186 /* let's start simplistic */
1187 memset(&startup
, 0, sizeof(startup
));
1188 startup
.cb
= sizeof(startup
);
1189 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1190 startup
.wShowWindow
= SW_SHOWNORMAL
;
1192 get_file_name(resfile
);
1193 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1194 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1196 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1198 ok(GetExitCodeThread(info
.hThread
, &exit_status
) && exit_status
== STILL_ACTIVE
, "thread still running\n");
1199 ok(ResumeThread(info
.hThread
) == 1, "Resuming thread\n");
1201 /* wait for child to terminate */
1202 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1203 /* child process has changed result file, so let profile functions know about it */
1204 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1206 GetStartupInfoA(&us
);
1208 okChildInt("StartupInfoA", "cb", startup
.cb
);
1209 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1210 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1211 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1212 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1213 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1214 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1215 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1216 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1217 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1218 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1219 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1220 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1222 assert(DeleteFileA(resfile
) != 0);
1225 static void test_DebuggingFlag(void)
1227 char buffer
[MAX_PATH
];
1228 void *processbase
= NULL
;
1229 PROCESS_INFORMATION info
;
1230 STARTUPINFOA startup
, us
;
1234 /* let's start simplistic */
1235 memset(&startup
, 0, sizeof(startup
));
1236 startup
.cb
= sizeof(startup
);
1237 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1238 startup
.wShowWindow
= SW_SHOWNORMAL
;
1240 get_file_name(resfile
);
1241 sprintf(buffer
, "%s tests/process.c %s", selfname
, resfile
);
1242 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1244 /* get all startup events up to the entry point break exception */
1247 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
1248 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
1251 ok(de
.dwDebugEventCode
== CREATE_PROCESS_DEBUG_EVENT
,
1252 "first event: %d\n", de
.dwDebugEventCode
);
1253 processbase
= de
.u
.CreateProcessInfo
.lpBaseOfImage
;
1255 if (de
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
) dbg
++;
1256 ok(de
.dwDebugEventCode
!= LOAD_DLL_DEBUG_EVENT
||
1257 de
.u
.LoadDll
.lpBaseOfDll
!= processbase
, "got LOAD_DLL for main module\n");
1258 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
1260 ok(dbg
, "I have seen a debug event\n");
1261 /* wait for child to terminate */
1262 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1263 /* child process has changed result file, so let profile functions know about it */
1264 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1266 GetStartupInfoA(&us
);
1268 okChildInt("StartupInfoA", "cb", startup
.cb
);
1269 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1270 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1271 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1272 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1273 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1274 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1275 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1276 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1277 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1278 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1279 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1280 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1282 assert(DeleteFileA(resfile
) != 0);
1285 static BOOL
is_console(HANDLE h
)
1287 return h
!= INVALID_HANDLE_VALUE
&& ((ULONG_PTR
)h
& 3) == 3;
1290 static void test_Console(void)
1292 char buffer
[MAX_PATH
];
1293 PROCESS_INFORMATION info
;
1294 STARTUPINFOA startup
, us
;
1295 SECURITY_ATTRIBUTES sa
;
1296 CONSOLE_SCREEN_BUFFER_INFO sbi
, sbiC
;
1297 DWORD modeIn
, modeOut
, modeInC
, modeOutC
;
1298 DWORD cpIn
, cpOut
, cpInC
, cpOutC
;
1300 HANDLE hChildIn
, hChildInInh
, hChildOut
, hChildOutInh
, hParentIn
, hParentOut
;
1301 const char* msg
= "This is a std-handle inheritance test.";
1303 BOOL run_tests
= TRUE
;
1305 memset(&startup
, 0, sizeof(startup
));
1306 startup
.cb
= sizeof(startup
);
1307 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1308 startup
.wShowWindow
= SW_SHOWNORMAL
;
1310 sa
.nLength
= sizeof(sa
);
1311 sa
.lpSecurityDescriptor
= NULL
;
1312 sa
.bInheritHandle
= TRUE
;
1314 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1315 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1317 /* first, we need to be sure we're attached to a console */
1318 if (!is_console(startup
.hStdInput
) || !is_console(startup
.hStdOutput
))
1320 /* we're not attached to a console, let's do it */
1322 startup
.hStdInput
= CreateFileA("CONIN$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1323 startup
.hStdOutput
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, &sa
, OPEN_EXISTING
, 0, 0);
1325 /* now verify everything's ok */
1326 ok(startup
.hStdInput
!= INVALID_HANDLE_VALUE
, "Opening ConIn\n");
1327 ok(startup
.hStdOutput
!= INVALID_HANDLE_VALUE
, "Opening ConOut\n");
1328 startup
.hStdError
= startup
.hStdOutput
;
1330 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbi
), "Getting sb info\n");
1331 ok(GetConsoleMode(startup
.hStdInput
, &modeIn
) &&
1332 GetConsoleMode(startup
.hStdOutput
, &modeOut
), "Getting console modes\n");
1333 cpIn
= GetConsoleCP();
1334 cpOut
= GetConsoleOutputCP();
1336 get_file_name(resfile
);
1337 sprintf(buffer
, "%s tests/process.c %s console", selfname
, resfile
);
1338 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1340 /* wait for child to terminate */
1341 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1342 /* child process has changed result file, so let profile functions know about it */
1343 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1345 /* now get the modification the child has made, and resets parents expected values */
1346 ok(GetConsoleScreenBufferInfo(startup
.hStdOutput
, &sbiC
), "Getting sb info\n");
1347 ok(GetConsoleMode(startup
.hStdInput
, &modeInC
) &&
1348 GetConsoleMode(startup
.hStdOutput
, &modeOutC
), "Getting console modes\n");
1350 SetConsoleMode(startup
.hStdInput
, modeIn
);
1351 SetConsoleMode(startup
.hStdOutput
, modeOut
);
1353 cpInC
= GetConsoleCP();
1354 cpOutC
= GetConsoleOutputCP();
1356 /* Try to set invalid CP */
1357 SetLastError(0xdeadbeef);
1358 ok(!SetConsoleCP(0), "Shouldn't succeed\n");
1359 ok(GetLastError()==ERROR_INVALID_PARAMETER
||
1360 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
), /* win9x */
1361 "GetLastError: expecting %u got %u\n",
1362 ERROR_INVALID_PARAMETER
, GetLastError());
1363 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1367 SetLastError(0xdeadbeef);
1368 ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
1369 ok(GetLastError()==ERROR_INVALID_PARAMETER
||
1370 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
), /* win9x */
1371 "GetLastError: expecting %u got %u\n",
1372 ERROR_INVALID_PARAMETER
, GetLastError());
1375 SetConsoleOutputCP(cpOut
);
1377 GetStartupInfoA(&us
);
1379 okChildInt("StartupInfoA", "cb", startup
.cb
);
1380 okChildString("StartupInfoA", "lpDesktop", us
.lpDesktop
);
1381 ok (startup
.lpTitle
== NULL
|| !strcmp(startup
.lpTitle
, selfname
),
1382 "StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname
, startup
.lpTitle
);
1383 okChildInt("StartupInfoA", "dwX", startup
.dwX
);
1384 okChildInt("StartupInfoA", "dwY", startup
.dwY
);
1385 okChildInt("StartupInfoA", "dwXSize", startup
.dwXSize
);
1386 okChildInt("StartupInfoA", "dwYSize", startup
.dwYSize
);
1387 okChildInt("StartupInfoA", "dwXCountChars", startup
.dwXCountChars
);
1388 okChildInt("StartupInfoA", "dwYCountChars", startup
.dwYCountChars
);
1389 okChildInt("StartupInfoA", "dwFillAttribute", startup
.dwFillAttribute
);
1390 okChildInt("StartupInfoA", "dwFlags", startup
.dwFlags
);
1391 okChildInt("StartupInfoA", "wShowWindow", startup
.wShowWindow
);
1393 /* check child correctly inherited the console */
1394 okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR
)startup
.hStdInput
);
1395 okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR
)startup
.hStdOutput
);
1396 okChildInt("StartupInfoA", "hStdError", (DWORD_PTR
)startup
.hStdError
);
1397 okChildInt("Console", "SizeX", (DWORD
)sbi
.dwSize
.X
);
1398 okChildInt("Console", "SizeY", (DWORD
)sbi
.dwSize
.Y
);
1399 okChildInt("Console", "CursorX", (DWORD
)sbi
.dwCursorPosition
.X
);
1400 okChildInt("Console", "CursorY", (DWORD
)sbi
.dwCursorPosition
.Y
);
1401 okChildInt("Console", "Attributes", sbi
.wAttributes
);
1402 okChildInt("Console", "winLeft", (DWORD
)sbi
.srWindow
.Left
);
1403 okChildInt("Console", "winTop", (DWORD
)sbi
.srWindow
.Top
);
1404 okChildInt("Console", "winRight", (DWORD
)sbi
.srWindow
.Right
);
1405 okChildInt("Console", "winBottom", (DWORD
)sbi
.srWindow
.Bottom
);
1406 okChildInt("Console", "maxWinWidth", (DWORD
)sbi
.dwMaximumWindowSize
.X
);
1407 okChildInt("Console", "maxWinHeight", (DWORD
)sbi
.dwMaximumWindowSize
.Y
);
1408 okChildInt("Console", "InputCP", cpIn
);
1409 okChildInt("Console", "OutputCP", cpOut
);
1410 okChildInt("Console", "InputMode", modeIn
);
1411 okChildInt("Console", "OutputMode", modeOut
);
1415 ok(cpInC
== 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC
, cpIn
);
1416 ok(cpOutC
== 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC
, cpOut
);
1419 win_skip("Setting the codepage is not implemented\n");
1421 ok(modeInC
== (modeIn
^ 1), "Wrong console mode\n");
1422 ok(modeOutC
== (modeOut
^ 1), "Wrong console-SB mode\n");
1423 trace("cursor position(X): %d/%d\n",sbi
.dwCursorPosition
.X
, sbiC
.dwCursorPosition
.X
);
1424 ok(sbiC
.dwCursorPosition
.Y
== (sbi
.dwCursorPosition
.Y
^ 1), "Wrong cursor position\n");
1427 assert(DeleteFileA(resfile
) != 0);
1429 ok(CreatePipe(&hParentIn
, &hChildOut
, NULL
, 0), "Creating parent-input pipe\n");
1430 ok(DuplicateHandle(GetCurrentProcess(), hChildOut
, GetCurrentProcess(),
1431 &hChildOutInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1432 "Duplicating as inheritable child-output pipe\n");
1433 CloseHandle(hChildOut
);
1435 ok(CreatePipe(&hChildIn
, &hParentOut
, NULL
, 0), "Creating parent-output pipe\n");
1436 ok(DuplicateHandle(GetCurrentProcess(), hChildIn
, GetCurrentProcess(),
1437 &hChildInInh
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
1438 "Duplicating as inheritable child-input pipe\n");
1439 CloseHandle(hChildIn
);
1441 memset(&startup
, 0, sizeof(startup
));
1442 startup
.cb
= sizeof(startup
);
1443 startup
.dwFlags
= STARTF_USESHOWWINDOW
|STARTF_USESTDHANDLES
;
1444 startup
.wShowWindow
= SW_SHOWNORMAL
;
1445 startup
.hStdInput
= hChildInInh
;
1446 startup
.hStdOutput
= hChildOutInh
;
1447 startup
.hStdError
= hChildOutInh
;
1449 get_file_name(resfile
);
1450 sprintf(buffer
, "%s tests/process.c %s stdhandle", selfname
, resfile
);
1451 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1452 ok(CloseHandle(hChildInInh
), "Closing handle\n");
1453 ok(CloseHandle(hChildOutInh
), "Closing handle\n");
1455 msg_len
= strlen(msg
) + 1;
1456 ok(WriteFile(hParentOut
, msg
, msg_len
, &w
, NULL
), "Writing to child\n");
1457 ok(w
== msg_len
, "Should have written %u bytes, actually wrote %u\n", msg_len
, w
);
1458 memset(buffer
, 0, sizeof(buffer
));
1459 ok(ReadFile(hParentIn
, buffer
, sizeof(buffer
), &w
, NULL
), "Reading from child\n");
1460 ok(strcmp(buffer
, msg
) == 0, "Should have received '%s'\n", msg
);
1462 /* wait for child to terminate */
1463 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1464 /* child process has changed result file, so let profile functions know about it */
1465 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1467 okChildString("StdHandle", "msg", msg
);
1470 assert(DeleteFileA(resfile
) != 0);
1473 static void test_ExitCode(void)
1475 char buffer
[MAX_PATH
];
1476 PROCESS_INFORMATION info
;
1477 STARTUPINFOA startup
;
1480 /* let's start simplistic */
1481 memset(&startup
, 0, sizeof(startup
));
1482 startup
.cb
= sizeof(startup
);
1483 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
1484 startup
.wShowWindow
= SW_SHOWNORMAL
;
1486 get_file_name(resfile
);
1487 sprintf(buffer
, "%s tests/process.c %s exit_code", selfname
, resfile
);
1488 ok(CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1490 /* wait for child to terminate */
1491 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
1492 /* child process has changed result file, so let profile functions know about it */
1493 WritePrivateProfileStringA(NULL
, NULL
, NULL
, resfile
);
1495 ok(GetExitCodeProcess(info
.hProcess
, &code
), "Getting exit code\n");
1496 okChildInt("ExitCode", "value", code
);
1499 assert(DeleteFileA(resfile
) != 0);
1502 static void test_OpenProcess(void)
1506 MEMORY_BASIC_INFORMATION info
;
1507 SIZE_T dummy
, read_bytes
;
1509 /* not exported in all windows versions */
1510 if ((!pVirtualAllocEx
) || (!pVirtualFreeEx
)) {
1511 win_skip("VirtualAllocEx not found\n");
1515 /* without PROCESS_VM_OPERATION */
1516 hproc
= OpenProcess(PROCESS_ALL_ACCESS
& ~PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1517 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1519 SetLastError(0xdeadbeef);
1520 addr1
= pVirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1521 ok(!addr1
, "VirtualAllocEx should fail\n");
1522 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1525 win_skip("VirtualAllocEx not implemented\n");
1528 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1530 read_bytes
= 0xdeadbeef;
1531 SetLastError(0xdeadbeef);
1532 ok(ReadProcessMemory(hproc
, test_OpenProcess
, &dummy
, sizeof(dummy
), &read_bytes
),
1533 "ReadProcessMemory error %d\n", GetLastError());
1534 ok(read_bytes
== sizeof(dummy
), "wrong read bytes %ld\n", read_bytes
);
1538 hproc
= OpenProcess(PROCESS_VM_OPERATION
, FALSE
, GetCurrentProcessId());
1539 ok(hproc
!= NULL
, "OpenProcess error %d\n", GetLastError());
1541 addr1
= pVirtualAllocEx(hproc
, 0, 0xFFFC, MEM_RESERVE
, PAGE_NOACCESS
);
1542 ok(addr1
!= NULL
, "VirtualAllocEx error %d\n", GetLastError());
1544 /* without PROCESS_QUERY_INFORMATION */
1545 SetLastError(0xdeadbeef);
1546 ok(!VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)),
1547 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1548 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1550 /* without PROCESS_VM_READ */
1551 read_bytes
= 0xdeadbeef;
1552 SetLastError(0xdeadbeef);
1553 ok(!ReadProcessMemory(hproc
, addr1
, &dummy
, sizeof(dummy
), &read_bytes
),
1554 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1555 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1556 ok(read_bytes
== 0, "wrong read bytes %ld\n", read_bytes
);
1560 hproc
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
1562 memset(&info
, 0xcc, sizeof(info
));
1563 ok(VirtualQueryEx(hproc
, addr1
, &info
, sizeof(info
)) == sizeof(info
),
1564 "VirtualQueryEx error %d\n", GetLastError());
1566 ok(info
.BaseAddress
== addr1
, "%p != %p\n", info
.BaseAddress
, addr1
);
1567 ok(info
.AllocationBase
== addr1
, "%p != %p\n", info
.AllocationBase
, addr1
);
1568 ok(info
.AllocationProtect
== PAGE_NOACCESS
, "%x != PAGE_NOACCESS\n", info
.AllocationProtect
);
1569 ok(info
.RegionSize
== 0x10000, "%lx != 0x10000\n", info
.RegionSize
);
1570 ok(info
.State
== MEM_RESERVE
, "%x != MEM_RESERVE\n", info
.State
);
1571 /* NT reports Protect == 0 for a not committed memory block */
1572 ok(info
.Protect
== 0 /* NT */ ||
1573 info
.Protect
== PAGE_NOACCESS
, /* Win9x */
1574 "%x != PAGE_NOACCESS\n", info
.Protect
);
1575 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
1577 SetLastError(0xdeadbeef);
1578 ok(!pVirtualFreeEx(hproc
, addr1
, 0, MEM_RELEASE
),
1579 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1580 ok(GetLastError() == ERROR_ACCESS_DENIED
, "wrong error %d\n", GetLastError());
1584 ok(VirtualFree(addr1
, 0, MEM_RELEASE
), "VirtualFree failed\n");
1587 static void test_GetProcessVersion(void)
1589 static char cmdline
[] = "winver.exe";
1590 PROCESS_INFORMATION pi
;
1594 SetLastError(0xdeadbeef);
1595 ret
= GetProcessVersion(0);
1596 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1598 SetLastError(0xdeadbeef);
1599 ret
= GetProcessVersion(GetCurrentProcessId());
1600 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1602 memset(&si
, 0, sizeof(si
));
1604 si
.dwFlags
= STARTF_USESHOWWINDOW
;
1605 si
.wShowWindow
= SW_HIDE
;
1606 ret
= CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
1607 SetLastError(0xdeadbeef);
1608 ok(ret
, "CreateProcess error %u\n", GetLastError());
1610 SetLastError(0xdeadbeef);
1611 ret
= GetProcessVersion(pi
.dwProcessId
);
1612 ok(ret
, "GetProcessVersion error %u\n", GetLastError());
1614 SetLastError(0xdeadbeef);
1615 ret
= TerminateProcess(pi
.hProcess
, 0);
1616 ok(ret
, "TerminateProcess error %u\n", GetLastError());
1618 CloseHandle(pi
.hProcess
);
1619 CloseHandle(pi
.hThread
);
1622 static void test_ProcessNameA(void)
1624 #define INIT_STR "Just some words"
1628 if (!pQueryFullProcessImageNameA
)
1630 win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
1633 /* get the buffer length without \0 terminator */
1635 expect_eq_d(TRUE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &length
));
1636 expect_eq_d(length
, lstrlenA(buf
));
1638 /* when the buffer is too small
1639 * - function fail with error ERROR_INSUFFICIENT_BUFFER
1640 * - the size variable is not modified
1641 * tested with the biggest too small size
1644 sprintf(buf
,INIT_STR
);
1645 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &size
));
1646 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1647 expect_eq_d(length
, size
);
1648 expect_eq_s(INIT_STR
, buf
);
1650 /* retest with smaller buffer size
1653 sprintf(buf
,INIT_STR
);
1654 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf
, &size
));
1655 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1656 expect_eq_d(4, size
);
1657 expect_eq_s(INIT_STR
, buf
);
1659 /* this is a difference between the ascii and the unicode version
1660 * the unicode version crashes when the size is big enough to hold the result
1661 * ascii version throughs an error
1664 expect_eq_d(FALSE
, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, NULL
, &size
));
1665 expect_eq_d(1024, size
);
1666 expect_eq_d(ERROR_INVALID_PARAMETER
, GetLastError());
1669 static void test_ProcessName(void)
1672 WCHAR module_name
[1024];
1673 WCHAR deviceW
[] = {'\\','D', 'e','v','i','c','e',0};
1677 if (!pQueryFullProcessImageNameW
)
1679 win_skip("QueryFullProcessImageNameW unavailable (added in Windows Vista)\n");
1683 ok(GetModuleFileNameW(NULL
, module_name
, 1024), "GetModuleFileNameW(NULL, ...) failed\n");
1685 /* GetCurrentProcess pseudo-handle */
1686 size
= sizeof(buf
) / sizeof(buf
[0]);
1687 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(GetCurrentProcess(), 0, buf
, &size
));
1688 expect_eq_d(lstrlenW(buf
), size
);
1689 expect_eq_ws_i(buf
, module_name
);
1691 hSelf
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
1693 size
= sizeof(buf
) / sizeof(buf
[0]);
1694 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1695 expect_eq_d(lstrlenW(buf
), size
);
1696 expect_eq_ws_i(buf
, module_name
);
1698 /* Buffer too small */
1699 size
= lstrlenW(module_name
)/2;
1700 lstrcpyW(buf
, deviceW
);
1701 SetLastError(0xdeadbeef);
1702 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1703 expect_eq_d(lstrlenW(module_name
)/2, size
); /* size not changed(!) */
1704 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1705 expect_eq_ws_i(deviceW
, buf
); /* buffer not changed */
1707 /* Too small - not space for NUL terminator */
1708 size
= lstrlenW(module_name
);
1709 SetLastError(0xdeadbeef);
1710 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1711 expect_eq_d(lstrlenW(module_name
), size
); /* size not changed(!) */
1712 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1716 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, NULL
, &size
));
1717 expect_eq_d(0, size
);
1718 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1721 size
= sizeof(buf
) / sizeof(buf
[0]);
1722 expect_eq_d(TRUE
, pQueryFullProcessImageNameW(hSelf
, PROCESS_NAME_NATIVE
, buf
, &size
));
1723 expect_eq_d(lstrlenW(buf
), size
);
1724 ok(buf
[0] == '\\', "NT path should begin with '\\'\n");
1725 todo_wine
ok(memcmp(buf
, deviceW
, sizeof(WCHAR
)*lstrlenW(deviceW
)) == 0, "NT path should begin with \\Device\n");
1727 /* Buffer too small */
1728 size
= lstrlenW(module_name
)/2;
1729 SetLastError(0xdeadbeef);
1730 lstrcpyW(buf
, module_name
);
1731 expect_eq_d(FALSE
, pQueryFullProcessImageNameW(hSelf
, 0, buf
, &size
));
1732 expect_eq_d(lstrlenW(module_name
)/2, size
); /* size not changed(!) */
1733 expect_eq_d(ERROR_INSUFFICIENT_BUFFER
, GetLastError());
1734 expect_eq_ws_i(module_name
, buf
); /* buffer not changed */
1739 static void test_Handles(void)
1741 HANDLE handle
= GetCurrentProcess();
1745 ok( handle
== (HANDLE
)~(ULONG_PTR
)0 ||
1746 handle
== (HANDLE
)(ULONG_PTR
)0x7fffffff /* win9x */,
1747 "invalid current process handle %p\n", handle
);
1748 ret
= GetExitCodeProcess( handle
, &code
);
1749 ok( ret
, "GetExitCodeProcess failed err %u\n", GetLastError() );
1751 /* truncated handle */
1752 SetLastError( 0xdeadbeef );
1753 handle
= (HANDLE
)((ULONG_PTR
)handle
& ~0u);
1754 ret
= GetExitCodeProcess( handle
, &code
);
1755 ok( !ret
, "GetExitCodeProcess succeeded for %p\n", handle
);
1756 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
1757 /* sign-extended handle */
1758 SetLastError( 0xdeadbeef );
1759 handle
= (HANDLE
)((LONG_PTR
)(int)(ULONG_PTR
)handle
);
1760 ret
= GetExitCodeProcess( handle
, &code
);
1761 ok( ret
, "GetExitCodeProcess failed err %u\n", GetLastError() );
1762 /* invalid high-word */
1763 SetLastError( 0xdeadbeef );
1764 handle
= (HANDLE
)(((ULONG_PTR
)handle
& ~0u) + ((ULONG_PTR
)1 << 32));
1765 ret
= GetExitCodeProcess( handle
, &code
);
1766 ok( !ret
, "GetExitCodeProcess succeeded for %p\n", handle
);
1767 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
1774 ok(b
, "Basic init of CreateProcess test\n");
1779 doChild(myARGV
[2], (myARGC
== 3) ? NULL
: myARGV
[3]);
1787 test_DebuggingFlag();
1791 test_GetProcessVersion();
1792 test_ProcessNameA();
1795 /* things that can be tested:
1796 * lookup: check the way program to be executed is searched
1797 * handles: check the handle inheritance stuff (+sec options)
1798 * console: check if console creation parameters work