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 void (WINAPI *pGetNativeSystemInfo)(LPSYSTEM_INFO);
59 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
60 static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
61 static BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
62 static BOOL (WINAPI *pQueryFullProcessImageNameA)(HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD lpdwSize);
63 static BOOL (WINAPI *pQueryFullProcessImageNameW)(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD lpdwSize);
65 /* ############################### */
66 static char base[MAX_PATH];
67 static char selfname[MAX_PATH];
69 static char resfile[MAX_PATH];
74 /* As some environment variables get very long on Unix, we only test for
75 * the first 127 bytes.
76 * Note that increasing this value past 256 may exceed the buffer size
77 * limitations of the *Profile functions (at least on Wine).
79 #define MAX_LISTED_ENV_VAR 128
81 /* ---------------- portable memory allocation thingie */
83 static char memory[1024*256];
84 static char* memory_index = memory;
86 static char* grab_memory(size_t len)
88 char* ret = memory_index;
92 assert(memory_index <= memory + sizeof(memory));
96 static void release_memory(void)
98 memory_index = memory;
101 /* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
103 static const char* encodeA(const char* str)
109 len = strlen(str) + 1;
110 ptr = grab_memory(len * 2 + 1);
111 for (i = 0; i < len; i++)
112 sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
117 static const char* encodeW(const WCHAR* str)
123 len = lstrlenW(str) + 1;
124 ptr = grab_memory(len * 4 + 1);
126 for (i = 0; i < len; i++)
127 sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
132 static unsigned decode_char(char c)
134 if (c >= '0' && c <= '9') return c - '0';
135 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
136 assert(c >= 'A' && c <= 'F');
140 static char* decodeA(const char* str)
145 len = strlen(str) / 2;
146 if (!len--) return NULL;
147 ptr = grab_memory(len + 1);
148 for (i = 0; i < len; i++)
149 ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
154 /* This will be needed to decode Unicode strings saved by the child process
155 * when we test Unicode functions.
157 static WCHAR* decodeW(const char* str)
163 len = strlen(str) / 4;
164 if (!len--) return NULL;
165 ptr = (WCHAR*)grab_memory(len * 2 + 1);
166 for (i = 0; i < len; i++)
167 ptr[i] = (decode_char(str[4 * i]) << 12) |
168 (decode_char(str[4 * i + 1]) << 8) |
169 (decode_char(str[4 * i + 2]) << 4) |
170 (decode_char(str[4 * i + 3]) << 0);
175 /******************************************************************
178 * generates basic information like:
179 * base: absolute path to curr dir
180 * selfname: the way to reinvoke ourselves
181 * exename: executable without the path
182 * function-pointers, which are not implemented in all windows versions
184 static int init(void)
188 myARGC = winetest_get_mainargs( &myARGV );
189 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
190 strcpy(selfname, myARGV[0]);
192 /* Strip the path of selfname */
193 if ((p = strrchr(selfname, '\\')) != NULL) exename = p + 1;
194 else exename = selfname;
196 if ((p = strrchr(exename, '/')) != NULL) exename = p + 1;
198 hkernel32 = GetModuleHandleA("kernel32");
199 pGetNativeSystemInfo = (void *) GetProcAddress(hkernel32, "GetNativeSystemInfo");
200 pIsWow64Process = (void *) GetProcAddress(hkernel32, "IsWow64Process");
201 pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
202 pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
203 pQueryFullProcessImageNameA = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameA");
204 pQueryFullProcessImageNameW = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameW");
208 /******************************************************************
211 * generates an absolute file_name for temporary file
214 static void get_file_name(char* buf)
219 GetTempPathA(sizeof(path), path);
220 GetTempFileNameA(path, "wt", 0, buf);
223 /******************************************************************
224 * static void childPrintf
227 static void childPrintf(HANDLE h, const char* fmt, ...)
230 char buffer[1024+4*MAX_LISTED_ENV_VAR];
233 va_start(valist, fmt);
234 vsprintf(buffer, fmt, valist);
236 WriteFile(h, buffer, strlen(buffer), &w, NULL);
240 /******************************************************************
243 * output most of the information in the child process
245 static void doChild(const char* file, const char* option)
253 WCHAR bufW[MAX_PATH];
254 HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
257 if (hFile == INVALID_HANDLE_VALUE) return;
259 /* output of startup info (Ansi) */
260 GetStartupInfoA(&siA);
262 "[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
263 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
264 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
265 "dwFlags=%lu\nwShowWindow=%u\n"
266 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
267 siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
268 siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
269 siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
270 siA.dwFlags, siA.wShowWindow,
271 (DWORD_PTR)siA.hStdInput, (DWORD_PTR)siA.hStdOutput, (DWORD_PTR)siA.hStdError);
273 /* since GetStartupInfoW is only implemented in win2k,
274 * zero out before calling so we can notice the difference
276 memset(&siW, 0, sizeof(siW));
277 GetStartupInfoW(&siW);
279 "[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
280 "dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
281 "dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
282 "dwFlags=%lu\nwShowWindow=%u\n"
283 "hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
284 siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
285 siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
286 siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
287 siW.dwFlags, siW.wShowWindow,
288 (DWORD_PTR)siW.hStdInput, (DWORD_PTR)siW.hStdOutput, (DWORD_PTR)siW.hStdError);
291 childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
292 for (i = 0; i < myARGC; i++)
294 childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
296 childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
302 /* this is part of shell32... and should be tested there */
303 argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
304 for (i = 0; i < argcW; i++)
306 childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
309 childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
311 /* output of environment (Ansi) */
312 ptrA = GetEnvironmentStringsA();
315 char env_var[MAX_LISTED_ENV_VAR];
317 childPrintf(hFile, "[EnvironmentA]\n");
321 lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
322 childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
324 ptrA += strlen(ptrA) + 1;
326 childPrintf(hFile, "len=%d\n\n", i);
329 /* output of environment (Unicode) */
330 ptrW = GetEnvironmentStringsW();
333 WCHAR env_var[MAX_LISTED_ENV_VAR];
335 childPrintf(hFile, "[EnvironmentW]\n");
339 lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
340 env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
341 childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
343 ptrW += lstrlenW(ptrW) + 1;
345 childPrintf(hFile, "len=%d\n\n", i);
348 childPrintf(hFile, "[Misc]\n");
349 if (GetCurrentDirectoryA(sizeof(bufA), bufA))
350 childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
351 if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
352 childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
353 childPrintf(hFile, "\n");
355 if (option && strcmp(option, "console") == 0)
357 CONSOLE_SCREEN_BUFFER_INFO sbi;
358 HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
359 HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
360 DWORD modeIn, modeOut;
362 childPrintf(hFile, "[Console]\n");
363 if (GetConsoleScreenBufferInfo(hConOut, &sbi))
365 childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
366 sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
367 childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
368 sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
369 childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
370 sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
372 childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
373 GetConsoleCP(), GetConsoleOutputCP());
374 if (GetConsoleMode(hConIn, &modeIn))
375 childPrintf(hFile, "InputMode=%ld\n", modeIn);
376 if (GetConsoleMode(hConOut, &modeOut))
377 childPrintf(hFile, "OutputMode=%ld\n", modeOut);
379 /* now that we have written all relevant information, let's change it */
380 SetLastError(0xdeadbeef);
381 ret = SetConsoleCP(1252);
382 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
384 win_skip("Setting the codepage is not implemented\n");
388 ok(ret, "Setting CP\n");
389 ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
392 ret = SetConsoleMode(hConIn, modeIn ^ 1);
393 ok( ret, "Setting mode (%d)\n", GetLastError());
394 ret = SetConsoleMode(hConOut, modeOut ^ 1);
395 ok( ret, "Setting mode (%d)\n", GetLastError());
396 sbi.dwCursorPosition.X ^= 1;
397 sbi.dwCursorPosition.Y ^= 1;
398 ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
399 ok( ret, "Setting cursor position (%d)\n", GetLastError());
401 if (option && strcmp(option, "stdhandle") == 0)
403 HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
404 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
406 if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
411 ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
412 childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
413 ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
417 if (option && strcmp(option, "exit_code") == 0)
419 childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
427 static char* getChildString(const char* sect, const char* key)
429 char buf[1024+4*MAX_LISTED_ENV_VAR];
432 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
433 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
434 assert(!(strlen(buf) & 1));
439 static WCHAR* getChildStringW(const char* sect, const char* key)
441 char buf[1024+4*MAX_LISTED_ENV_VAR];
444 GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
445 if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
446 assert(!(strlen(buf) & 1));
451 /* FIXME: this may be moved to the wtmain.c file, because it may be needed by
452 * others... (windows uses stricmp while Un*x uses strcasecmp...)
454 static int wtstrcasecmp(const char* p1, const char* p2)
459 while (c1 == c2 && c1)
461 c1 = *p1++; c2 = *p2++;
464 c1 = toupper(c1); c2 = toupper(c2);
470 static int strCmp(const char* s1, const char* s2, BOOL sensitive)
472 if (!s1 && !s2) return 0;
475 return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
478 static void ok_child_string( int line, const char *sect, const char *key,
479 const char *expect, int sensitive )
481 char* result = getChildString( sect, key );
482 ok_(__FILE__, line)( strCmp(result, expect, sensitive) == 0, "%s:%s expected '%s', got '%s'\n",
483 sect, key, expect ? expect : "(null)", result );
486 static void ok_child_stringWA( int line, const char *sect, const char *key,
487 const char *expect, int sensitive )
492 WCHAR* result = getChildStringW( sect, key );
494 len = MultiByteToWideChar( CP_ACP, 0, expect, -1, NULL, 0);
495 expectW = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
496 MultiByteToWideChar( CP_ACP, 0, expect, -1, expectW, len);
498 len = WideCharToMultiByte( CP_ACP, 0, result, -1, NULL, 0, NULL, NULL);
499 resultA = HeapAlloc(GetProcessHeap(),0,len*sizeof(CHAR));
500 WideCharToMultiByte( CP_ACP, 0, result, -1, resultA, len, NULL, NULL);
503 ok_(__FILE__, line)( lstrcmpW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
504 sect, key, expect ? expect : "(null)", resultA );
506 ok_(__FILE__, line)( lstrcmpiW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
507 sect, key, expect ? expect : "(null)", resultA );
508 HeapFree(GetProcessHeap(),0,expectW);
509 HeapFree(GetProcessHeap(),0,resultA);
512 #define okChildString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 1 )
513 #define okChildIString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 0 )
514 #define okChildStringWA(sect, key, expect) ok_child_stringWA(__LINE__, (sect), (key), (expect), 1 )
516 /* using !expect ensures that the test will fail if the sect/key isn't present
519 #define okChildInt(sect, key, expect) \
521 UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
522 ok(result == expect, "%s:%s expected %u, but got %u\n", (sect), (key), (UINT)(expect), result); \
525 static void test_Startup(void)
527 char buffer[MAX_PATH];
528 PROCESS_INFORMATION info;
529 STARTUPINFOA startup,si;
531 static CHAR title[] = "I'm the title string",
532 desktop[] = "winsta0\\default",
535 /* let's start simplistic */
536 memset(&startup, 0, sizeof(startup));
537 startup.cb = sizeof(startup);
538 startup.dwFlags = STARTF_USESHOWWINDOW;
539 startup.wShowWindow = SW_SHOWNORMAL;
541 get_file_name(resfile);
542 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
543 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
544 /* wait for child to terminate */
545 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
546 /* child process has changed result file, so let profile functions know about it */
547 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
549 GetStartupInfoA(&si);
550 okChildInt("StartupInfoA", "cb", startup.cb);
551 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
552 okChildInt("StartupInfoA", "dwX", startup.dwX);
553 okChildInt("StartupInfoA", "dwY", startup.dwY);
554 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
555 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
556 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
557 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
558 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
559 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
560 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
562 assert(DeleteFileA(resfile) != 0);
564 /* not so simplistic now */
565 memset(&startup, 0, sizeof(startup));
566 startup.cb = sizeof(startup);
567 startup.dwFlags = STARTF_USESHOWWINDOW;
568 startup.wShowWindow = SW_SHOWNORMAL;
569 startup.lpTitle = title;
570 startup.lpDesktop = desktop;
571 startup.dwXCountChars = 0x12121212;
572 startup.dwYCountChars = 0x23232323;
573 startup.dwX = 0x34343434;
574 startup.dwY = 0x45454545;
575 startup.dwXSize = 0x56565656;
576 startup.dwYSize = 0x67676767;
577 startup.dwFillAttribute = 0xA55A;
579 get_file_name(resfile);
580 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
581 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
582 /* wait for child to terminate */
583 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
584 /* child process has changed result file, so let profile functions know about it */
585 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
587 okChildInt("StartupInfoA", "cb", startup.cb);
588 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
589 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
590 okChildInt("StartupInfoA", "dwX", startup.dwX);
591 okChildInt("StartupInfoA", "dwY", startup.dwY);
592 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
593 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
594 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
595 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
596 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
597 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
598 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
600 assert(DeleteFileA(resfile) != 0);
602 /* not so simplistic now */
603 memset(&startup, 0, sizeof(startup));
604 startup.cb = sizeof(startup);
605 startup.dwFlags = STARTF_USESHOWWINDOW;
606 startup.wShowWindow = SW_SHOWNORMAL;
607 startup.lpTitle = title;
608 startup.lpDesktop = NULL;
609 startup.dwXCountChars = 0x12121212;
610 startup.dwYCountChars = 0x23232323;
611 startup.dwX = 0x34343434;
612 startup.dwY = 0x45454545;
613 startup.dwXSize = 0x56565656;
614 startup.dwYSize = 0x67676767;
615 startup.dwFillAttribute = 0xA55A;
617 get_file_name(resfile);
618 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
619 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
620 /* wait for child to terminate */
621 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
622 /* child process has changed result file, so let profile functions know about it */
623 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
625 okChildInt("StartupInfoA", "cb", startup.cb);
626 okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
627 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
628 okChildInt("StartupInfoA", "dwX", startup.dwX);
629 okChildInt("StartupInfoA", "dwY", startup.dwY);
630 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
631 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
632 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
633 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
634 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
635 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
636 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
638 assert(DeleteFileA(resfile) != 0);
640 /* not so simplistic now */
641 memset(&startup, 0, sizeof(startup));
642 startup.cb = sizeof(startup);
643 startup.dwFlags = STARTF_USESHOWWINDOW;
644 startup.wShowWindow = SW_SHOWNORMAL;
645 startup.lpTitle = title;
646 startup.lpDesktop = empty;
647 startup.dwXCountChars = 0x12121212;
648 startup.dwYCountChars = 0x23232323;
649 startup.dwX = 0x34343434;
650 startup.dwY = 0x45454545;
651 startup.dwXSize = 0x56565656;
652 startup.dwYSize = 0x67676767;
653 startup.dwFillAttribute = 0xA55A;
655 get_file_name(resfile);
656 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
657 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
658 /* wait for child to terminate */
659 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
660 /* child process has changed result file, so let profile functions know about it */
661 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
663 okChildInt("StartupInfoA", "cb", startup.cb);
664 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
665 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
666 okChildInt("StartupInfoA", "dwX", startup.dwX);
667 okChildInt("StartupInfoA", "dwY", startup.dwY);
668 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
669 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
670 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
671 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
672 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
673 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
674 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
676 assert(DeleteFileA(resfile) != 0);
678 /* not so simplistic now */
679 memset(&startup, 0, sizeof(startup));
680 startup.cb = sizeof(startup);
681 startup.dwFlags = STARTF_USESHOWWINDOW;
682 startup.wShowWindow = SW_SHOWNORMAL;
683 startup.lpTitle = NULL;
684 startup.lpDesktop = desktop;
685 startup.dwXCountChars = 0x12121212;
686 startup.dwYCountChars = 0x23232323;
687 startup.dwX = 0x34343434;
688 startup.dwY = 0x45454545;
689 startup.dwXSize = 0x56565656;
690 startup.dwYSize = 0x67676767;
691 startup.dwFillAttribute = 0xA55A;
693 get_file_name(resfile);
694 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
695 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
696 /* wait for child to terminate */
697 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
698 /* child process has changed result file, so let profile functions know about it */
699 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
701 okChildInt("StartupInfoA", "cb", startup.cb);
702 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
703 result = getChildString( "StartupInfoA", "lpTitle" );
704 ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
705 "expected '%s' or null, got '%s'\n", selfname, result );
706 okChildInt("StartupInfoA", "dwX", startup.dwX);
707 okChildInt("StartupInfoA", "dwY", startup.dwY);
708 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
709 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
710 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
711 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
712 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
713 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
714 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
716 assert(DeleteFileA(resfile) != 0);
718 /* not so simplistic now */
719 memset(&startup, 0, sizeof(startup));
720 startup.cb = sizeof(startup);
721 startup.dwFlags = STARTF_USESHOWWINDOW;
722 startup.wShowWindow = SW_SHOWNORMAL;
723 startup.lpTitle = empty;
724 startup.lpDesktop = desktop;
725 startup.dwXCountChars = 0x12121212;
726 startup.dwYCountChars = 0x23232323;
727 startup.dwX = 0x34343434;
728 startup.dwY = 0x45454545;
729 startup.dwXSize = 0x56565656;
730 startup.dwYSize = 0x67676767;
731 startup.dwFillAttribute = 0xA55A;
733 get_file_name(resfile);
734 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
735 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
736 /* wait for child to terminate */
737 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
738 /* child process has changed result file, so let profile functions know about it */
739 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
741 okChildInt("StartupInfoA", "cb", startup.cb);
742 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
743 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
744 okChildInt("StartupInfoA", "dwX", startup.dwX);
745 okChildInt("StartupInfoA", "dwY", startup.dwY);
746 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
747 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
748 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
749 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
750 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
751 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
752 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
754 assert(DeleteFileA(resfile) != 0);
756 /* not so simplistic now */
757 memset(&startup, 0, sizeof(startup));
758 startup.cb = sizeof(startup);
759 startup.dwFlags = STARTF_USESHOWWINDOW;
760 startup.wShowWindow = SW_SHOWNORMAL;
761 startup.lpTitle = empty;
762 startup.lpDesktop = empty;
763 startup.dwXCountChars = 0x12121212;
764 startup.dwYCountChars = 0x23232323;
765 startup.dwX = 0x34343434;
766 startup.dwY = 0x45454545;
767 startup.dwXSize = 0x56565656;
768 startup.dwYSize = 0x67676767;
769 startup.dwFillAttribute = 0xA55A;
771 get_file_name(resfile);
772 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
773 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
774 /* wait for child to terminate */
775 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
776 /* child process has changed result file, so let profile functions know about it */
777 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
779 okChildInt("StartupInfoA", "cb", startup.cb);
780 okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
781 okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
782 okChildInt("StartupInfoA", "dwX", startup.dwX);
783 okChildInt("StartupInfoA", "dwY", startup.dwY);
784 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
785 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
786 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
787 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
788 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
789 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
790 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
792 assert(DeleteFileA(resfile) != 0);
794 /* TODO: test for A/W and W/A and W/W */
797 static void test_CommandLine(void)
799 char buffer[MAX_PATH], fullpath[MAX_PATH], *lpFilePart, *p;
800 char buffer2[MAX_PATH];
801 PROCESS_INFORMATION info;
802 STARTUPINFOA startup;
805 memset(&startup, 0, sizeof(startup));
806 startup.cb = sizeof(startup);
807 startup.dwFlags = STARTF_USESHOWWINDOW;
808 startup.wShowWindow = SW_SHOWNORMAL;
811 get_file_name(resfile);
812 sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
813 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
814 /* wait for child to terminate */
815 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
816 /* child process has changed result file, so let profile functions know about it */
817 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
819 okChildInt("Arguments", "argcA", 4);
820 okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
821 okChildString("Arguments", "argvA4", NULL);
822 okChildString("Arguments", "CommandLineA", buffer);
824 assert(DeleteFileA(resfile) != 0);
826 memset(&startup, 0, sizeof(startup));
827 startup.cb = sizeof(startup);
828 startup.dwFlags = STARTF_USESHOWWINDOW;
829 startup.wShowWindow = SW_SHOWNORMAL;
832 get_file_name(resfile);
833 sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
834 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
835 /* wait for child to terminate */
836 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
837 /* child process has changed result file, so let profile functions know about it */
838 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
840 okChildInt("Arguments", "argcA", 6);
841 okChildString("Arguments", "argvA3", "a\"b\\");
842 okChildString("Arguments", "argvA4", "c\"");
843 okChildString("Arguments", "argvA5", "d");
844 okChildString("Arguments", "argvA6", NULL);
845 okChildString("Arguments", "CommandLineA", buffer);
847 assert(DeleteFileA(resfile) != 0);
849 /* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
850 get_file_name(resfile);
851 /* Use exename to avoid buffer containing things like 'C:' */
852 sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
853 SetLastError(0xdeadbeef);
854 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
855 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
856 /* wait for child to terminate */
857 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
858 /* child process has changed result file, so let profile functions know about it */
859 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
860 sprintf(buffer, "./%s", exename);
861 okChildString("Arguments", "argvA0", buffer);
863 assert(DeleteFileA(resfile) != 0);
865 get_file_name(resfile);
866 /* Use exename to avoid buffer containing things like 'C:' */
867 sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
868 SetLastError(0xdeadbeef);
869 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
870 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
871 /* wait for child to terminate */
872 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
873 /* child process has changed result file, so let profile functions know about it */
874 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
875 sprintf(buffer, ".\\%s", exename);
876 okChildString("Arguments", "argvA0", buffer);
878 assert(DeleteFileA(resfile) != 0);
880 get_file_name(resfile);
881 GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
882 assert ( lpFilePart != 0);
883 *(lpFilePart -1 ) = 0;
884 p = strrchr(fullpath, '\\');
885 /* Use exename to avoid buffer containing things like 'C:' */
886 if (p) sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, exename, resfile);
887 else sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
888 SetLastError(0xdeadbeef);
889 ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
890 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
891 /* wait for child to terminate */
892 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
893 /* child process has changed result file, so let profile functions know about it */
894 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
895 if (p) sprintf(buffer, "..%s/%s", p, exename);
896 else sprintf(buffer, "./%s", exename);
897 okChildString("Arguments", "argvA0", buffer);
899 assert(DeleteFileA(resfile) != 0);
902 get_file_name(resfile);
903 GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
904 assert ( lpFilePart != 0);
905 *(lpFilePart -1 ) = 0;
906 p = strrchr(fullpath, '\\');
907 /* Use exename to avoid buffer containing things like 'C:' */
908 if (p) sprintf(buffer, "..%s/%s", p, exename);
909 else sprintf(buffer, "./%s", exename);
910 sprintf(buffer2, "dummy tests/process.c %s \"a\\\"b\\\\\" c\\\" d", resfile);
911 SetLastError(0xdeadbeef);
912 ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
913 ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
914 /* wait for child to terminate */
915 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
916 /* child process has changed result file, so let profile functions know about it */
917 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
918 sprintf(buffer, "tests/process.c %s", resfile);
919 okChildString("Arguments", "argvA0", "dummy");
920 okChildString("Arguments", "CommandLineA", buffer2);
921 okChildStringWA("Arguments", "CommandLineW", buffer2);
923 assert(DeleteFileA(resfile) != 0);
925 if (0) /* Test crashes on NT-based Windows. */
927 /* Test NULL application name and command line parameters. */
928 SetLastError(0xdeadbeef);
929 ret = CreateProcessA(NULL, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
930 ok(!ret, "CreateProcessA unexpectedly succeeded\n");
931 ok(GetLastError() == ERROR_INVALID_PARAMETER,
932 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
937 /* Test empty application name parameter. */
938 SetLastError(0xdeadbeef);
939 ret = CreateProcessA(buffer, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
940 ok(!ret, "CreateProcessA unexpectedly succeeded\n");
941 ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
942 broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
943 broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
944 "Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
948 /* Test empty application name and command line parameters. */
949 SetLastError(0xdeadbeef);
950 ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
951 ok(!ret, "CreateProcessA unexpectedly succeeded\n");
952 ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
953 broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
954 broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
955 "Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
957 /* Test empty command line parameter. */
958 SetLastError(0xdeadbeef);
959 ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
960 ok(!ret, "CreateProcessA unexpectedly succeeded\n");
961 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
962 GetLastError() == ERROR_PATH_NOT_FOUND /* NT4 */ ||
963 GetLastError() == ERROR_BAD_PATHNAME /* Win98 */ ||
964 GetLastError() == ERROR_INVALID_PARAMETER /* Win7 */,
965 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
967 strcpy(buffer, "doesnotexist.exe");
968 strcpy(buffer2, "does not exist.exe");
970 /* Test nonexistent application name. */
971 SetLastError(0xdeadbeef);
972 ret = CreateProcessA(buffer, 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 SetLastError(0xdeadbeef);
977 ret = CreateProcessA(buffer2, NULL, 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 /* Test nonexistent command line parameter. */
982 SetLastError(0xdeadbeef);
983 ret = CreateProcessA(NULL, buffer, 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());
987 SetLastError(0xdeadbeef);
988 ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
989 ok(!ret, "CreateProcessA unexpectedly succeeded\n");
990 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
993 static void test_Directory(void)
995 char buffer[MAX_PATH];
996 PROCESS_INFORMATION info;
997 STARTUPINFOA startup;
998 char windir[MAX_PATH];
999 static CHAR cmdline[] = "winver.exe";
1001 memset(&startup, 0, sizeof(startup));
1002 startup.cb = sizeof(startup);
1003 startup.dwFlags = STARTF_USESHOWWINDOW;
1004 startup.wShowWindow = SW_SHOWNORMAL;
1007 get_file_name(resfile);
1008 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1009 GetWindowsDirectoryA( windir, sizeof(windir) );
1010 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
1011 /* wait for child to terminate */
1012 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1013 /* child process has changed result file, so let profile functions know about it */
1014 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1016 okChildIString("Misc", "CurrDirA", windir);
1018 assert(DeleteFileA(resfile) != 0);
1020 /* search PATH for the exe if directory is NULL */
1021 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
1022 ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
1024 /* if any directory is provided, don't search PATH, error on bad directory */
1025 SetLastError(0xdeadbeef);
1026 memset(&info, 0, sizeof(info));
1027 ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
1028 NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
1029 ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
1030 ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
1033 static BOOL is_str_env_drive_dir(const char* str)
1035 return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
1036 str[3] == '=' && str[4] == str[1];
1039 /* compared expected child's environment (in gesA) from actual
1040 * environment our child got
1042 static void cmpEnvironment(const char* gesA)
1050 clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
1052 /* now look each parent env in child */
1053 if ((ptrA = gesA) != NULL)
1057 for (i = 0; i < clen; i++)
1059 sprintf(key, "env%d", i);
1060 res = getChildString("EnvironmentA", key);
1061 if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
1065 ok(found, "Parent-env string %s isn't in child process\n", ptrA);
1067 ptrA += strlen(ptrA) + 1;
1071 /* and each child env in parent */
1072 for (i = 0; i < clen; i++)
1074 sprintf(key, "env%d", i);
1075 res = getChildString("EnvironmentA", key);
1076 if ((ptrA = gesA) != NULL)
1080 if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
1082 ptrA += strlen(ptrA) + 1;
1084 if (!*ptrA) ptrA = NULL;
1087 if (!is_str_env_drive_dir(res))
1089 found = ptrA != NULL;
1090 ok(found, "Child-env string %s isn't in parent process\n", res);
1092 /* else => should also test we get the right per drive default directory here... */
1096 static void test_Environment(void)
1098 char buffer[MAX_PATH];
1099 PROCESS_INFORMATION info;
1100 STARTUPINFOA startup;
1107 memset(&startup, 0, sizeof(startup));
1108 startup.cb = sizeof(startup);
1109 startup.dwFlags = STARTF_USESHOWWINDOW;
1110 startup.wShowWindow = SW_SHOWNORMAL;
1113 get_file_name(resfile);
1114 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1115 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
1116 /* wait for child to terminate */
1117 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1118 /* child process has changed result file, so let profile functions know about it */
1119 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1121 cmpEnvironment(GetEnvironmentStringsA());
1123 assert(DeleteFileA(resfile) != 0);
1125 memset(&startup, 0, sizeof(startup));
1126 startup.cb = sizeof(startup);
1127 startup.dwFlags = STARTF_USESHOWWINDOW;
1128 startup.wShowWindow = SW_SHOWNORMAL;
1131 get_file_name(resfile);
1132 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1135 ptr = GetEnvironmentStringsA();
1138 slen = strlen(ptr)+1;
1139 child_env_len += slen;
1142 /* Add space for additional environment variables */
1143 child_env_len += 256;
1144 child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
1147 sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
1148 ptr += strlen(ptr) + 1;
1149 strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
1150 ptr += strlen(ptr) + 1;
1151 strcpy(ptr, "FOO=BAR");
1152 ptr += strlen(ptr) + 1;
1153 strcpy(ptr, "BAR=FOOBAR");
1154 ptr += strlen(ptr) + 1;
1155 /* copy all existing variables except:
1157 * - PATH (already set above)
1158 * - the directory definitions (=[A-Z]:=)
1160 for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
1162 if (strncmp(env, "PATH=", 5) != 0 &&
1163 strncmp(env, "WINELOADER=", 11) != 0 &&
1164 !is_str_env_drive_dir(env))
1167 ptr += strlen(ptr) + 1;
1171 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
1172 /* wait for child to terminate */
1173 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1174 /* child process has changed result file, so let profile functions know about it */
1175 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1177 cmpEnvironment(child_env);
1179 HeapFree(GetProcessHeap(), 0, child_env);
1181 assert(DeleteFileA(resfile) != 0);
1184 static void test_SuspendFlag(void)
1186 char buffer[MAX_PATH];
1187 PROCESS_INFORMATION info;
1188 STARTUPINFOA startup, us;
1192 /* let's start simplistic */
1193 memset(&startup, 0, sizeof(startup));
1194 startup.cb = sizeof(startup);
1195 startup.dwFlags = STARTF_USESHOWWINDOW;
1196 startup.wShowWindow = SW_SHOWNORMAL;
1198 get_file_name(resfile);
1199 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1200 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
1202 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1204 ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
1205 ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
1207 /* wait for child to terminate */
1208 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1209 /* child process has changed result file, so let profile functions know about it */
1210 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1212 GetStartupInfoA(&us);
1214 okChildInt("StartupInfoA", "cb", startup.cb);
1215 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1216 result = getChildString( "StartupInfoA", "lpTitle" );
1217 ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
1218 "expected '%s' or null, got '%s'\n", selfname, result );
1219 okChildInt("StartupInfoA", "dwX", startup.dwX);
1220 okChildInt("StartupInfoA", "dwY", startup.dwY);
1221 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1222 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1223 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1224 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1225 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1226 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1227 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1229 assert(DeleteFileA(resfile) != 0);
1232 static void test_DebuggingFlag(void)
1234 char buffer[MAX_PATH];
1235 void *processbase = NULL;
1236 PROCESS_INFORMATION info;
1237 STARTUPINFOA startup, us;
1242 /* let's start simplistic */
1243 memset(&startup, 0, sizeof(startup));
1244 startup.cb = sizeof(startup);
1245 startup.dwFlags = STARTF_USESHOWWINDOW;
1246 startup.wShowWindow = SW_SHOWNORMAL;
1248 get_file_name(resfile);
1249 sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
1250 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1252 /* get all startup events up to the entry point break exception */
1255 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
1256 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
1259 ok(de.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT,
1260 "first event: %d\n", de.dwDebugEventCode);
1261 processbase = de.u.CreateProcessInfo.lpBaseOfImage;
1263 if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
1264 ok(de.dwDebugEventCode != LOAD_DLL_DEBUG_EVENT ||
1265 de.u.LoadDll.lpBaseOfDll != processbase, "got LOAD_DLL for main module\n");
1266 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
1268 ok(dbg, "I have seen a debug event\n");
1269 /* wait for child to terminate */
1270 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1271 /* child process has changed result file, so let profile functions know about it */
1272 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1274 GetStartupInfoA(&us);
1276 okChildInt("StartupInfoA", "cb", startup.cb);
1277 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1278 result = getChildString( "StartupInfoA", "lpTitle" );
1279 ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
1280 "expected '%s' or null, got '%s'\n", selfname, result );
1281 okChildInt("StartupInfoA", "dwX", startup.dwX);
1282 okChildInt("StartupInfoA", "dwY", startup.dwY);
1283 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1284 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1285 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1286 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1287 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1288 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1289 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1291 assert(DeleteFileA(resfile) != 0);
1294 static BOOL is_console(HANDLE h)
1296 return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
1299 static void test_Console(void)
1301 char buffer[MAX_PATH];
1302 PROCESS_INFORMATION info;
1303 STARTUPINFOA startup, us;
1304 SECURITY_ATTRIBUTES sa;
1305 CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
1306 DWORD modeIn, modeOut, modeInC, modeOutC;
1307 DWORD cpIn, cpOut, cpInC, cpOutC;
1309 HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
1310 const char* msg = "This is a std-handle inheritance test.";
1312 BOOL run_tests = TRUE;
1315 memset(&startup, 0, sizeof(startup));
1316 startup.cb = sizeof(startup);
1317 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1318 startup.wShowWindow = SW_SHOWNORMAL;
1320 sa.nLength = sizeof(sa);
1321 sa.lpSecurityDescriptor = NULL;
1322 sa.bInheritHandle = TRUE;
1324 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1325 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1327 /* first, we need to be sure we're attached to a console */
1328 if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
1330 /* we're not attached to a console, let's do it */
1332 startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1333 startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
1335 /* now verify everything's ok */
1336 ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
1337 ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
1338 startup.hStdError = startup.hStdOutput;
1340 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
1341 ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
1342 GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
1343 cpIn = GetConsoleCP();
1344 cpOut = GetConsoleOutputCP();
1346 get_file_name(resfile);
1347 sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
1348 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1350 /* wait for child to terminate */
1351 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1352 /* child process has changed result file, so let profile functions know about it */
1353 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1355 /* now get the modification the child has made, and resets parents expected values */
1356 ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
1357 ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
1358 GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
1360 SetConsoleMode(startup.hStdInput, modeIn);
1361 SetConsoleMode(startup.hStdOutput, modeOut);
1363 cpInC = GetConsoleCP();
1364 cpOutC = GetConsoleOutputCP();
1366 /* Try to set invalid CP */
1367 SetLastError(0xdeadbeef);
1368 ok(!SetConsoleCP(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());
1373 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1377 SetLastError(0xdeadbeef);
1378 ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
1379 ok(GetLastError()==ERROR_INVALID_PARAMETER ||
1380 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
1381 "GetLastError: expecting %u got %u\n",
1382 ERROR_INVALID_PARAMETER, GetLastError());
1385 SetConsoleOutputCP(cpOut);
1387 GetStartupInfoA(&us);
1389 okChildInt("StartupInfoA", "cb", startup.cb);
1390 okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
1391 result = getChildString( "StartupInfoA", "lpTitle" );
1392 ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
1393 "expected '%s' or null, got '%s'\n", selfname, result );
1394 okChildInt("StartupInfoA", "dwX", startup.dwX);
1395 okChildInt("StartupInfoA", "dwY", startup.dwY);
1396 okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
1397 okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
1398 okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
1399 okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
1400 okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
1401 okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
1402 okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
1404 /* check child correctly inherited the console */
1405 okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR)startup.hStdInput);
1406 okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR)startup.hStdOutput);
1407 okChildInt("StartupInfoA", "hStdError", (DWORD_PTR)startup.hStdError);
1408 okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
1409 okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
1410 okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
1411 okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
1412 okChildInt("Console", "Attributes", sbi.wAttributes);
1413 okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
1414 okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
1415 okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
1416 okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
1417 okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
1418 okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
1419 okChildInt("Console", "InputCP", cpIn);
1420 okChildInt("Console", "OutputCP", cpOut);
1421 okChildInt("Console", "InputMode", modeIn);
1422 okChildInt("Console", "OutputMode", modeOut);
1426 ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
1427 ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
1430 win_skip("Setting the codepage is not implemented\n");
1432 ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
1433 ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
1434 trace("cursor position(X): %d/%d\n",sbi.dwCursorPosition.X, sbiC.dwCursorPosition.X);
1435 ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
1438 assert(DeleteFileA(resfile) != 0);
1440 ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
1441 ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
1442 &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1443 "Duplicating as inheritable child-output pipe\n");
1444 CloseHandle(hChildOut);
1446 ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
1447 ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
1448 &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
1449 "Duplicating as inheritable child-input pipe\n");
1450 CloseHandle(hChildIn);
1452 memset(&startup, 0, sizeof(startup));
1453 startup.cb = sizeof(startup);
1454 startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
1455 startup.wShowWindow = SW_SHOWNORMAL;
1456 startup.hStdInput = hChildInInh;
1457 startup.hStdOutput = hChildOutInh;
1458 startup.hStdError = hChildOutInh;
1460 get_file_name(resfile);
1461 sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
1462 ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
1463 ok(CloseHandle(hChildInInh), "Closing handle\n");
1464 ok(CloseHandle(hChildOutInh), "Closing handle\n");
1466 msg_len = strlen(msg) + 1;
1467 ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
1468 ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
1469 memset(buffer, 0, sizeof(buffer));
1470 ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
1471 ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
1473 /* wait for child to terminate */
1474 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1475 /* child process has changed result file, so let profile functions know about it */
1476 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1478 okChildString("StdHandle", "msg", msg);
1481 assert(DeleteFileA(resfile) != 0);
1484 static void test_ExitCode(void)
1486 char buffer[MAX_PATH];
1487 PROCESS_INFORMATION info;
1488 STARTUPINFOA startup;
1491 /* let's start simplistic */
1492 memset(&startup, 0, sizeof(startup));
1493 startup.cb = sizeof(startup);
1494 startup.dwFlags = STARTF_USESHOWWINDOW;
1495 startup.wShowWindow = SW_SHOWNORMAL;
1497 get_file_name(resfile);
1498 sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
1499 ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
1501 /* wait for child to terminate */
1502 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
1503 /* child process has changed result file, so let profile functions know about it */
1504 WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
1506 ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
1507 okChildInt("ExitCode", "value", code);
1510 assert(DeleteFileA(resfile) != 0);
1513 static void test_OpenProcess(void)
1517 MEMORY_BASIC_INFORMATION info;
1518 SIZE_T dummy, read_bytes;
1520 /* not exported in all windows versions */
1521 if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) {
1522 win_skip("VirtualAllocEx not found\n");
1526 /* without PROCESS_VM_OPERATION */
1527 hproc = OpenProcess(PROCESS_ALL_ACCESS & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1528 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1530 SetLastError(0xdeadbeef);
1531 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1532 ok(!addr1, "VirtualAllocEx should fail\n");
1533 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1536 win_skip("VirtualAllocEx not implemented\n");
1539 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1541 read_bytes = 0xdeadbeef;
1542 SetLastError(0xdeadbeef);
1543 ok(ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes),
1544 "ReadProcessMemory error %d\n", GetLastError());
1545 ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
1549 hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
1550 ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
1552 addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
1553 ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
1555 /* without PROCESS_QUERY_INFORMATION */
1556 SetLastError(0xdeadbeef);
1557 ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
1558 "VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
1559 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1561 /* without PROCESS_VM_READ */
1562 read_bytes = 0xdeadbeef;
1563 SetLastError(0xdeadbeef);
1564 ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
1565 "ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
1566 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1567 ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
1571 hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
1573 memset(&info, 0xcc, sizeof(info));
1574 ok(VirtualQueryEx(hproc, addr1, &info, sizeof(info)) == sizeof(info),
1575 "VirtualQueryEx error %d\n", GetLastError());
1577 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
1578 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
1579 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
1580 ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
1581 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
1582 /* NT reports Protect == 0 for a not committed memory block */
1583 ok(info.Protect == 0 /* NT */ ||
1584 info.Protect == PAGE_NOACCESS, /* Win9x */
1585 "%x != PAGE_NOACCESS\n", info.Protect);
1586 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
1588 SetLastError(0xdeadbeef);
1589 ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
1590 "VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
1591 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
1595 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
1598 static void test_GetProcessVersion(void)
1600 static char cmdline[] = "winver.exe";
1601 PROCESS_INFORMATION pi;
1605 SetLastError(0xdeadbeef);
1606 ret = GetProcessVersion(0);
1607 ok(ret, "GetProcessVersion error %u\n", GetLastError());
1609 SetLastError(0xdeadbeef);
1610 ret = GetProcessVersion(GetCurrentProcessId());
1611 ok(ret, "GetProcessVersion error %u\n", GetLastError());
1613 memset(&si, 0, sizeof(si));
1615 si.dwFlags = STARTF_USESHOWWINDOW;
1616 si.wShowWindow = SW_HIDE;
1617 ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
1618 SetLastError(0xdeadbeef);
1619 ok(ret, "CreateProcess error %u\n", GetLastError());
1621 SetLastError(0xdeadbeef);
1622 ret = GetProcessVersion(pi.dwProcessId);
1623 ok(ret, "GetProcessVersion error %u\n", GetLastError());
1625 SetLastError(0xdeadbeef);
1626 ret = TerminateProcess(pi.hProcess, 0);
1627 ok(ret, "TerminateProcess error %u\n", GetLastError());
1629 CloseHandle(pi.hProcess);
1630 CloseHandle(pi.hThread);
1633 static void test_ProcessNameA(void)
1635 #define INIT_STR "Just some words"
1639 if (!pQueryFullProcessImageNameA)
1641 win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
1644 /* get the buffer length without \0 terminator */
1646 expect_eq_d(TRUE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &length));
1647 expect_eq_d(length, lstrlenA(buf));
1649 /* when the buffer is too small
1650 * - function fail with error ERROR_INSUFFICIENT_BUFFER
1651 * - the size variable is not modified
1652 * tested with the biggest too small size
1655 sprintf(buf,INIT_STR);
1656 expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &size));
1657 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1658 expect_eq_d(length, size);
1659 expect_eq_s(INIT_STR, buf);
1661 /* retest with smaller buffer size
1664 sprintf(buf,INIT_STR);
1665 expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &size));
1666 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1667 expect_eq_d(4, size);
1668 expect_eq_s(INIT_STR, buf);
1670 /* this is a difference between the ascii and the unicode version
1671 * the unicode version crashes when the size is big enough to hold the result
1672 * ascii version throughs an error
1675 expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, NULL, &size));
1676 expect_eq_d(1024, size);
1677 expect_eq_d(ERROR_INVALID_PARAMETER, GetLastError());
1680 static void test_ProcessName(void)
1683 WCHAR module_name[1024];
1684 WCHAR deviceW[] = {'\\','D', 'e','v','i','c','e',0};
1688 if (!pQueryFullProcessImageNameW)
1690 win_skip("QueryFullProcessImageNameW unavailable (added in Windows Vista)\n");
1694 ok(GetModuleFileNameW(NULL, module_name, 1024), "GetModuleFileNameW(NULL, ...) failed\n");
1696 /* GetCurrentProcess pseudo-handle */
1697 size = sizeof(buf) / sizeof(buf[0]);
1698 expect_eq_d(TRUE, pQueryFullProcessImageNameW(GetCurrentProcess(), 0, buf, &size));
1699 expect_eq_d(lstrlenW(buf), size);
1700 expect_eq_ws_i(buf, module_name);
1702 hSelf = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
1704 size = sizeof(buf) / sizeof(buf[0]);
1705 expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
1706 expect_eq_d(lstrlenW(buf), size);
1707 expect_eq_ws_i(buf, module_name);
1709 /* Buffer too small */
1710 size = lstrlenW(module_name)/2;
1711 lstrcpyW(buf, deviceW);
1712 SetLastError(0xdeadbeef);
1713 expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
1714 expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
1715 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1716 expect_eq_ws_i(deviceW, buf); /* buffer not changed */
1718 /* Too small - not space for NUL terminator */
1719 size = lstrlenW(module_name);
1720 SetLastError(0xdeadbeef);
1721 expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
1722 expect_eq_d(lstrlenW(module_name), size); /* size not changed(!) */
1723 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1727 expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, NULL, &size));
1728 expect_eq_d(0, size);
1729 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1732 size = sizeof(buf) / sizeof(buf[0]);
1733 expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, PROCESS_NAME_NATIVE, buf, &size));
1734 expect_eq_d(lstrlenW(buf), size);
1735 ok(buf[0] == '\\', "NT path should begin with '\\'\n");
1736 todo_wine ok(memcmp(buf, deviceW, sizeof(WCHAR)*lstrlenW(deviceW)) == 0, "NT path should begin with \\Device\n");
1738 /* Buffer too small */
1739 size = lstrlenW(module_name)/2;
1740 SetLastError(0xdeadbeef);
1741 lstrcpyW(buf, module_name);
1742 expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
1743 expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
1744 expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
1745 expect_eq_ws_i(module_name, buf); /* buffer not changed */
1750 static void test_Handles(void)
1752 HANDLE handle = GetCurrentProcess();
1757 ok( handle == (HANDLE)~(ULONG_PTR)0 ||
1758 handle == (HANDLE)(ULONG_PTR)0x7fffffff /* win9x */,
1759 "invalid current process handle %p\n", handle );
1760 ret = GetExitCodeProcess( handle, &code );
1761 ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
1763 /* truncated handle */
1764 SetLastError( 0xdeadbeef );
1765 handle = (HANDLE)((ULONG_PTR)handle & ~0u);
1766 ret = GetExitCodeProcess( handle, &code );
1767 ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
1768 ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
1769 /* sign-extended handle */
1770 SetLastError( 0xdeadbeef );
1771 handle = (HANDLE)((LONG_PTR)(int)(ULONG_PTR)handle);
1772 ret = GetExitCodeProcess( handle, &code );
1773 ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
1774 /* invalid high-word */
1775 SetLastError( 0xdeadbeef );
1776 handle = (HANDLE)(((ULONG_PTR)handle & ~0u) + ((ULONG_PTR)1 << 32));
1777 ret = GetExitCodeProcess( handle, &code );
1778 ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
1779 ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
1782 handle = GetStdHandle( STD_ERROR_HANDLE );
1783 ok( handle != 0, "handle %p\n", handle );
1784 DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), &h3,
1785 0, TRUE, DUPLICATE_SAME_ACCESS );
1786 SetStdHandle( STD_ERROR_HANDLE, h3 );
1787 CloseHandle( (HANDLE)STD_ERROR_HANDLE );
1788 h2 = GetStdHandle( STD_ERROR_HANDLE );
1790 broken( h2 == h3) || /* nt4, w2k */
1791 broken( h2 == INVALID_HANDLE_VALUE), /* win9x */
1792 "wrong handle %p/%p\n", h2, h3 );
1793 SetStdHandle( STD_ERROR_HANDLE, handle );
1796 static void test_SystemInfo(void)
1798 SYSTEM_INFO si, nsi;
1801 if (!pGetNativeSystemInfo)
1803 win_skip("GetNativeSystemInfo is not available\n");
1807 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1810 pGetNativeSystemInfo(&nsi);
1813 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
1815 ok(nsi.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64,
1816 "Expected PROCESSOR_ARCHITECTURE_AMD64, got %d\n",
1817 nsi.wProcessorArchitecture);
1818 ok(nsi.dwProcessorType == PROCESSOR_AMD_X8664,
1819 "Expected PROCESSOR_AMD_X8664, got %d\n",
1820 nsi.dwProcessorType);
1825 ok(si.wProcessorArchitecture == nsi.wProcessorArchitecture,
1826 "Expected no difference for wProcessorArchitecture, got %d and %d\n",
1827 si.wProcessorArchitecture, nsi.wProcessorArchitecture);
1828 ok(si.dwProcessorType == nsi.dwProcessorType,
1829 "Expected no difference for dwProcessorType, got %d and %d\n",
1830 si.dwProcessorType, nsi.dwProcessorType);
1837 ok(b, "Basic init of CreateProcess test\n");
1842 doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
1850 test_DebuggingFlag();
1854 test_GetProcessVersion();
1855 test_ProcessNameA();
1859 /* things that can be tested:
1860 * lookup: check the way program to be executed is searched
1861 * handles: check the handle inheritance stuff (+sec options)
1862 * console: check if console creation parameters work