2002-04-22 00:07:03 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for CreateProcess function.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Eric Pouech
|
2006-11-08 16:45:33 +01:00
|
|
|
* Copyright 2006 Dmitry Timoshkov
|
2002-04-22 00:07:03 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-04-22 00:07:03 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-05-23 04:40:07 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-04-22 00:07:03 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2003-06-18 05:24:20 +02:00
|
|
|
#include "wincon.h"
|
|
|
|
#include "winnls.h"
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2006-11-19 16:05:47 +01:00
|
|
|
static HINSTANCE hkernel32;
|
|
|
|
static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
|
2007-01-20 12:38:14 +01:00
|
|
|
static BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2007-01-20 12:38:14 +01:00
|
|
|
/* ############################### */
|
2002-04-22 00:07:03 +02:00
|
|
|
static char base[MAX_PATH];
|
|
|
|
static char selfname[MAX_PATH];
|
2006-12-20 18:28:11 +01:00
|
|
|
static char* exename;
|
2002-04-22 00:07:03 +02:00
|
|
|
static char resfile[MAX_PATH];
|
|
|
|
|
|
|
|
static int myARGC;
|
|
|
|
static char** myARGV;
|
|
|
|
|
2003-11-18 20:38:51 +01:00
|
|
|
/* As some environment variables get very long on Unix, we only test for
|
|
|
|
* the first 127 bytes.
|
|
|
|
* Note that increasing this value past 256 may exceed the buffer size
|
|
|
|
* limitations of the *Profile functions (at least on Wine).
|
2003-01-13 19:28:43 +01:00
|
|
|
*/
|
|
|
|
#define MAX_LISTED_ENV_VAR 128
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* ---------------- portable memory allocation thingie */
|
|
|
|
|
2006-11-15 11:31:41 +01:00
|
|
|
static char memory[1024*256];
|
2002-04-22 00:07:03 +02:00
|
|
|
static char* memory_index = memory;
|
|
|
|
|
|
|
|
static char* grab_memory(size_t len)
|
|
|
|
{
|
|
|
|
char* ret = memory_index;
|
|
|
|
/* align on dword */
|
|
|
|
len = (len + 3) & ~3;
|
|
|
|
memory_index += len;
|
|
|
|
assert(memory_index <= memory + sizeof(memory));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_memory(void)
|
|
|
|
{
|
|
|
|
memory_index = memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
|
|
|
|
|
2003-11-09 01:30:36 +01:00
|
|
|
static const char* encodeA(const char* str)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (!str) return "";
|
|
|
|
len = strlen(str) + 1;
|
|
|
|
ptr = grab_memory(len * 2 + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
|
|
|
|
ptr[2 * len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2003-11-09 01:30:36 +01:00
|
|
|
static const char* encodeW(const WCHAR* str)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (!str) return "";
|
|
|
|
len = lstrlenW(str) + 1;
|
|
|
|
ptr = grab_memory(len * 4 + 1);
|
|
|
|
assert(ptr);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
|
|
|
|
ptr[4 * len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned decode_char(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9') return c - '0';
|
|
|
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
|
|
assert(c >= 'A' && c <= 'F');
|
|
|
|
return c - 'A' + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* decodeA(const char* str)
|
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
len = strlen(str) / 2;
|
|
|
|
if (!len--) return NULL;
|
|
|
|
ptr = grab_memory(len + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
|
|
|
|
ptr[len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2002-12-18 21:51:33 +01:00
|
|
|
#if 0
|
|
|
|
/* This will be needed to decode Unicode strings saved by the child process
|
|
|
|
* when we test Unicode functions.
|
|
|
|
*/
|
2002-04-22 00:07:03 +02:00
|
|
|
static WCHAR* decodeW(const char* str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
WCHAR* ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
len = strlen(str) / 4;
|
|
|
|
if (!len--) return NULL;
|
|
|
|
ptr = (WCHAR*)grab_memory(len * 2 + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
2002-06-01 01:06:46 +02:00
|
|
|
ptr[i] = (decode_char(str[4 * i]) << 12) |
|
2002-04-22 00:07:03 +02:00
|
|
|
(decode_char(str[4 * i + 1]) << 8) |
|
|
|
|
(decode_char(str[4 * i + 2]) << 4) |
|
|
|
|
(decode_char(str[4 * i + 3]) << 0);
|
|
|
|
ptr[len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
2002-12-18 21:51:33 +01:00
|
|
|
#endif
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* init
|
|
|
|
*
|
|
|
|
* generates basic information like:
|
|
|
|
* base: absolute path to curr dir
|
|
|
|
* selfname: the way to reinvoke ourselves
|
2006-12-20 18:28:11 +01:00
|
|
|
* exename: executable without the path
|
2006-11-19 16:05:47 +01:00
|
|
|
* function-pointers, which are not implemented in all windows versions
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
|
|
|
static int init(void)
|
|
|
|
{
|
2006-12-20 18:28:11 +01:00
|
|
|
char *p;
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
myARGC = winetest_get_mainargs( &myARGV );
|
|
|
|
if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
|
2002-05-12 05:16:39 +02:00
|
|
|
strcpy(selfname, myARGV[0]);
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Strip the path of selfname */
|
|
|
|
if ((p = strrchr(selfname, '\\')) != NULL) exename = p + 1;
|
|
|
|
else exename = selfname;
|
|
|
|
|
|
|
|
if ((p = strrchr(exename, '/')) != NULL) exename = p + 1;
|
|
|
|
|
2006-11-19 16:05:47 +01:00
|
|
|
hkernel32 = GetModuleHandleA("kernel32");
|
|
|
|
pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
|
|
|
|
pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
|
2002-04-22 00:07:03 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* get_file_name
|
|
|
|
*
|
|
|
|
* generates an absolute file_name for temporary file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void get_file_name(char* buf)
|
|
|
|
{
|
|
|
|
char path[MAX_PATH];
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
GetTempPathA(sizeof(path), path);
|
|
|
|
GetTempFileNameA(path, "wt", 0, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* static void childPrintf
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void childPrintf(HANDLE h, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list valist;
|
2003-11-18 20:38:51 +01:00
|
|
|
char buffer[1024+4*MAX_LISTED_ENV_VAR];
|
2002-04-22 00:07:03 +02:00
|
|
|
DWORD w;
|
|
|
|
|
|
|
|
va_start(valist, fmt);
|
|
|
|
vsprintf(buffer, fmt, valist);
|
|
|
|
va_end(valist);
|
|
|
|
WriteFile(h, buffer, strlen(buffer), &w, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* doChild
|
|
|
|
*
|
|
|
|
* output most of the information in the child process
|
|
|
|
*/
|
2003-06-18 05:24:20 +02:00
|
|
|
static void doChild(const char* file, const char* option)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
STARTUPINFOA siA;
|
|
|
|
STARTUPINFOW siW;
|
|
|
|
int i;
|
|
|
|
char* ptrA;
|
|
|
|
WCHAR* ptrW;
|
|
|
|
char bufA[MAX_PATH];
|
|
|
|
WCHAR bufW[MAX_PATH];
|
|
|
|
HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
/* output of startup info (Ansi) */
|
|
|
|
GetStartupInfoA(&siA);
|
2002-06-01 01:06:46 +02:00
|
|
|
childPrintf(hFile,
|
2002-04-22 00:07:03 +02:00
|
|
|
"[StartupInfoA]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
|
|
|
|
"dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
|
|
|
|
"dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
|
|
|
|
"dwFlags=%lu\nwShowWindow=%u\n"
|
|
|
|
"hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
|
|
|
|
siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
|
2002-06-01 01:06:46 +02:00
|
|
|
siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
|
|
|
|
siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
|
|
|
|
siA.dwFlags, siA.wShowWindow,
|
2002-04-22 00:07:03 +02:00
|
|
|
(DWORD)siA.hStdInput, (DWORD)siA.hStdOutput, (DWORD)siA.hStdError);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* since GetStartupInfoW is only implemented in win2k,
|
2002-04-22 00:07:03 +02:00
|
|
|
* zero out before calling so we can notice the difference
|
|
|
|
*/
|
|
|
|
memset(&siW, 0, sizeof(siW));
|
|
|
|
GetStartupInfoW(&siW);
|
2002-06-01 01:06:46 +02:00
|
|
|
childPrintf(hFile,
|
2002-04-22 00:07:03 +02:00
|
|
|
"[StartupInfoW]\ncb=%08ld\nlpDesktop=%s\nlpTitle=%s\n"
|
|
|
|
"dwX=%lu\ndwY=%lu\ndwXSize=%lu\ndwYSize=%lu\n"
|
|
|
|
"dwXCountChars=%lu\ndwYCountChars=%lu\ndwFillAttribute=%lu\n"
|
|
|
|
"dwFlags=%lu\nwShowWindow=%u\n"
|
|
|
|
"hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
|
|
|
|
siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
|
2002-06-01 01:06:46 +02:00
|
|
|
siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
|
|
|
|
siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
|
|
|
|
siW.dwFlags, siW.wShowWindow,
|
2002-04-22 00:07:03 +02:00
|
|
|
(DWORD)siW.hStdInput, (DWORD)siW.hStdOutput, (DWORD)siW.hStdError);
|
|
|
|
|
|
|
|
/* Arguments */
|
|
|
|
childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
|
|
|
|
for (i = 0; i < myARGC; i++)
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
|
|
|
|
}
|
|
|
|
childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int argcW;
|
|
|
|
WCHAR** argvW;
|
|
|
|
|
|
|
|
/* this is part of shell32... and should be tested there */
|
|
|
|
argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
|
|
|
|
for (i = 0; i < argcW; i++)
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "argvW%d=%s\n", i, encodeW(argvW[i]));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
|
|
|
|
|
|
|
|
/* output of environment (Ansi) */
|
|
|
|
ptrA = GetEnvironmentStringsA();
|
|
|
|
if (ptrA)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
char env_var[MAX_LISTED_ENV_VAR];
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
childPrintf(hFile, "[EnvironmentA]\n");
|
|
|
|
i = 0;
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
|
|
|
|
i++;
|
2002-04-22 00:07:03 +02:00
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
}
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "len=%d\n\n", i);
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output of environment (Unicode) */
|
|
|
|
ptrW = GetEnvironmentStringsW();
|
|
|
|
if (ptrW)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
WCHAR env_var[MAX_LISTED_ENV_VAR];
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
childPrintf(hFile, "[EnvironmentW]\n");
|
|
|
|
i = 0;
|
|
|
|
while (*ptrW)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
|
|
|
|
env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
|
2003-11-09 01:30:36 +01:00
|
|
|
childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
|
2003-01-13 19:28:43 +01:00
|
|
|
i++;
|
2002-04-22 00:07:03 +02:00
|
|
|
ptrW += lstrlenW(ptrW) + 1;
|
|
|
|
}
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "len=%d\n\n", i);
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
childPrintf(hFile, "[Misc]\n");
|
|
|
|
if (GetCurrentDirectoryA(sizeof(bufA), bufA))
|
|
|
|
childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
|
|
|
|
if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
|
|
|
|
childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
|
|
|
|
childPrintf(hFile, "\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
if (option && strcmp(option, "console") == 0)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
|
|
|
HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
DWORD modeIn, modeOut;
|
|
|
|
|
|
|
|
childPrintf(hFile, "[Console]\n");
|
|
|
|
if (GetConsoleScreenBufferInfo(hConOut, &sbi))
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
|
|
|
|
sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
|
|
|
|
childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
|
|
|
|
sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
|
|
|
|
childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
|
|
|
|
sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
|
|
|
|
}
|
|
|
|
childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
|
|
|
|
GetConsoleCP(), GetConsoleOutputCP());
|
|
|
|
if (GetConsoleMode(hConIn, &modeIn))
|
|
|
|
childPrintf(hFile, "InputMode=%ld\n", modeIn);
|
|
|
|
if (GetConsoleMode(hConOut, &modeOut))
|
|
|
|
childPrintf(hFile, "OutputMode=%ld\n", modeOut);
|
|
|
|
|
|
|
|
/* now that we have written all relevant information, let's change it */
|
2008-09-20 12:49:41 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleCP(1252);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("Setting the codepage is not implemented");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(ret, "Setting CP\n");
|
|
|
|
ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
|
|
|
|
}
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleMode(hConIn, modeIn ^ 1);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting mode (%d)\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleMode(hConOut, modeOut ^ 1);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting mode (%d)\n", GetLastError());
|
2003-06-18 05:24:20 +02:00
|
|
|
sbi.dwCursorPosition.X ^= 1;
|
|
|
|
sbi.dwCursorPosition.Y ^= 1;
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting cursor position (%d)\n", GetLastError());
|
2003-06-18 05:24:20 +02:00
|
|
|
}
|
|
|
|
if (option && strcmp(option, "stdhandle") == 0)
|
|
|
|
{
|
|
|
|
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
DWORD r, w;
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:05:40 +02:00
|
|
|
if (option && strcmp(option, "exit_code") == 0)
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
ExitProcess(123);
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* getChildString(const char* sect, const char* key)
|
|
|
|
{
|
2003-11-18 20:38:51 +01:00
|
|
|
char buf[1024+4*MAX_LISTED_ENV_VAR];
|
2002-04-22 00:07:03 +02:00
|
|
|
char* ret;
|
|
|
|
|
|
|
|
GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
|
|
|
|
if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
|
|
|
|
assert(!(strlen(buf) & 1));
|
|
|
|
ret = decodeA(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: this may be moved to the wtmain.c file, because it may be needed by
|
|
|
|
* others... (windows uses stricmp while Un*x uses strcasecmp...)
|
|
|
|
*/
|
|
|
|
static int wtstrcasecmp(const char* p1, const char* p2)
|
|
|
|
{
|
|
|
|
char c1, c2;
|
|
|
|
|
|
|
|
c1 = c2 = '@';
|
|
|
|
while (c1 == c2 && c1)
|
|
|
|
{
|
|
|
|
c1 = *p1++; c2 = *p2++;
|
|
|
|
if (c1 != c2)
|
|
|
|
{
|
|
|
|
c1 = toupper(c1); c2 = toupper(c2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strCmp(const char* s1, const char* s2, BOOL sensitive)
|
|
|
|
{
|
|
|
|
if (!s1 && !s2) return 0;
|
|
|
|
if (!s2) return -1;
|
|
|
|
if (!s1) return 1;
|
|
|
|
return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:15:40 +02:00
|
|
|
static void ok_child_string( int line, const char *sect, const char *key,
|
|
|
|
const char *expect, int sensitive )
|
|
|
|
{
|
|
|
|
char* result = getChildString( sect, key );
|
|
|
|
ok_(__FILE__, line)( strCmp(result, expect, sensitive) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", result );
|
|
|
|
}
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2007-10-17 14:15:40 +02:00
|
|
|
#define okChildString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 1 )
|
|
|
|
#define okChildIString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 0 )
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2005-08-17 11:56:24 +02:00
|
|
|
/* using !expect ensures that the test will fail if the sect/key isn't present
|
2002-06-01 01:06:46 +02:00
|
|
|
* in result file
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
|
|
|
#define okChildInt(sect, key, expect) \
|
|
|
|
do { \
|
2002-12-18 03:22:51 +01:00
|
|
|
UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(result == expect, "%s:%s expected %d, but got %d\n", (sect), (key), (int)(expect), result); \
|
2002-04-22 00:07:03 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void test_Startup(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2002-12-18 21:51:33 +01:00
|
|
|
STARTUPINFOA startup,si;
|
2006-06-02 20:01:23 +02:00
|
|
|
static CHAR title[] = "I'm the title string",
|
|
|
|
desktop[] = "I'm the desktop string",
|
|
|
|
empty[] = "";
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2002-12-18 21:51:33 +01:00
|
|
|
GetStartupInfoA(&si);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2002-12-18 21:51:33 +01:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.lpDesktop = NULL;
|
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2002-12-18 21:51:33 +01:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
|
|
|
startup.lpDesktop = empty;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
startup.lpTitle = NULL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
2008-05-08 00:44:48 +02:00
|
|
|
ok (startup.lpTitle == NULL || !strcmp(startup.lpTitle, selfname),
|
|
|
|
"StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname, startup.lpTitle);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = empty;
|
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = empty;
|
|
|
|
startup.lpDesktop = empty;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
todo_wine okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* TODO: test for A/W and W/A and W/W */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CommandLine(void)
|
|
|
|
{
|
2005-10-27 12:25:49 +02:00
|
|
|
char buffer[MAX_PATH], fullpath[MAX_PATH], *lpFilePart, *p;
|
2002-04-22 00:07:03 +02:00
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
2005-10-27 12:25:49 +02:00
|
|
|
DWORD len;
|
2006-12-14 14:29:45 +01:00
|
|
|
BOOL ret;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("Arguments", "argcA", 4);
|
|
|
|
okChildString("Arguments", "argvA3", "C:\\Program Files\\my nice app.exe");
|
|
|
|
okChildString("Arguments", "argvA4", NULL);
|
|
|
|
okChildString("Arguments", "CommandLineA", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* from Frangois */
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("Arguments", "argcA", 6);
|
|
|
|
okChildString("Arguments", "argvA3", "a\"b\\");
|
|
|
|
okChildString("Arguments", "argvA4", "c\"");
|
|
|
|
okChildString("Arguments", "argvA5", "d");
|
|
|
|
okChildString("Arguments", "argvA6", NULL);
|
|
|
|
okChildString("Arguments", "CommandLineA", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2005-10-27 12:25:49 +02:00
|
|
|
|
|
|
|
/* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
|
|
|
|
get_file_name(resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
|
|
|
sprintf(buffer, "./%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
sprintf(buffer, "./%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
|
|
|
sprintf(buffer, ".\\%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
sprintf(buffer, ".\\%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
|
|
|
|
assert ( lpFilePart != 0);
|
|
|
|
*(lpFilePart -1 ) = 0;
|
|
|
|
p = strrchr(fullpath, '\\');
|
|
|
|
assert (p);
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
|
|
|
sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
sprintf(buffer, "..%s/%s", p, exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_Directory(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
char windir[MAX_PATH];
|
2006-08-01 21:16:41 +02:00
|
|
|
static CHAR cmdline[] = "winver.exe";
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
|
|
|
GetWindowsDirectoryA( windir, sizeof(windir) );
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildIString("Misc", "CurrDirA", windir);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2006-03-27 05:53:09 +02:00
|
|
|
|
|
|
|
/* search PATH for the exe if directory is NULL */
|
2006-08-01 21:16:41 +02:00
|
|
|
ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2006-03-27 05:53:09 +02:00
|
|
|
ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
|
|
|
|
|
|
|
|
/* if any directory is provided, don't search PATH, error on bad directory */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset(&info, 0, sizeof(info));
|
2006-08-01 21:16:41 +02:00
|
|
|
ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
|
2006-03-27 05:53:09 +02:00
|
|
|
NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
|
2006-03-27 05:53:09 +02:00
|
|
|
ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
static BOOL is_str_env_drive_dir(const char* str)
|
|
|
|
{
|
|
|
|
return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
|
|
|
|
str[3] == '=' && str[4] == str[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compared expected child's environment (in gesA) from actual
|
|
|
|
* environment our child got
|
|
|
|
*/
|
|
|
|
static void cmpEnvironment(const char* gesA)
|
|
|
|
{
|
|
|
|
int i, clen;
|
|
|
|
const char* ptrA;
|
|
|
|
char* res;
|
|
|
|
char key[32];
|
|
|
|
BOOL found;
|
|
|
|
|
|
|
|
clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
|
|
|
|
|
|
|
|
/* now look each parent env in child */
|
|
|
|
if ((ptrA = gesA) != NULL)
|
|
|
|
{
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
|
|
|
for (i = 0; i < clen; i++)
|
|
|
|
{
|
|
|
|
sprintf(key, "env%d", i);
|
|
|
|
res = getChildString("EnvironmentA", key);
|
|
|
|
if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
found = i < clen;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(found, "Parent-env string %s isn't in child process\n", ptrA);
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
release_memory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* and each child env in parent */
|
|
|
|
for (i = 0; i < clen; i++)
|
|
|
|
{
|
|
|
|
sprintf(key, "env%d", i);
|
|
|
|
res = getChildString("EnvironmentA", key);
|
|
|
|
if ((ptrA = gesA) != NULL)
|
|
|
|
{
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
|
|
|
if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
|
|
|
|
break;
|
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
}
|
|
|
|
if (!*ptrA) ptrA = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_str_env_drive_dir(res))
|
|
|
|
{
|
|
|
|
found = ptrA != NULL;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(found, "Child-env string %s isn't in parent process\n", res);
|
2003-01-13 19:28:43 +01:00
|
|
|
}
|
|
|
|
/* else => should also test we get the right per drive default directory here... */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_Environment(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
2004-11-22 19:28:56 +01:00
|
|
|
char* child_env;
|
|
|
|
int child_env_len;
|
2003-01-13 19:28:43 +01:00
|
|
|
char* ptr;
|
|
|
|
char* env;
|
2004-11-22 19:28:56 +01:00
|
|
|
int slen;
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
cmpEnvironment(GetEnvironmentStringsA());
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-11-22 19:28:56 +01:00
|
|
|
|
|
|
|
child_env_len = 0;
|
|
|
|
ptr = GetEnvironmentStringsA();
|
|
|
|
while(*ptr)
|
|
|
|
{
|
|
|
|
slen = strlen(ptr)+1;
|
|
|
|
child_env_len += slen;
|
|
|
|
ptr += slen;
|
|
|
|
}
|
|
|
|
/* Add space for additional environment variables */
|
|
|
|
child_env_len += 256;
|
|
|
|
child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
ptr = child_env;
|
|
|
|
sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "FOO=BAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "BAR=FOOBAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
/* copy all existing variables except:
|
|
|
|
* - WINELOADER
|
|
|
|
* - PATH (already set above)
|
|
|
|
* - the directory definitions (=[A-Z]:=)
|
|
|
|
*/
|
|
|
|
for (env = GetEnvironmentStringsA(); *env; env += strlen(env) + 1)
|
|
|
|
{
|
|
|
|
if (strncmp(env, "PATH=", 5) != 0 &&
|
|
|
|
strncmp(env, "WINELOADER=", 11) != 0 &&
|
|
|
|
!is_str_env_drive_dir(env))
|
|
|
|
{
|
|
|
|
strcpy(ptr, env);
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ptr = '\0';
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
cmpEnvironment(child_env);
|
|
|
|
|
2004-11-22 19:28:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, child_env);
|
2003-01-13 19:28:43 +01:00
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SuspendFlag(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-01-13 19:28:43 +01:00
|
|
|
DWORD exit_status;
|
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
Sleep(8000);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
|
|
|
|
ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2008-05-08 00:44:48 +02:00
|
|
|
ok (startup.lpTitle == NULL || !strcmp(startup.lpTitle, selfname),
|
|
|
|
"StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname, startup.lpTitle);
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_DebuggingFlag(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-01-13 19:28:43 +01:00
|
|
|
DEBUG_EVENT de;
|
|
|
|
unsigned dbg = 0;
|
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* get all startup events up to the entry point break exception */
|
|
|
|
do
|
|
|
|
{
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
|
|
|
|
if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
|
|
|
|
} while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(dbg, "I have seen a debug event\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2008-05-08 00:44:48 +02:00
|
|
|
ok (startup.lpTitle == NULL || !strcmp(startup.lpTitle, selfname),
|
|
|
|
"StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname, startup.lpTitle);
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
static BOOL is_console(HANDLE h)
|
|
|
|
{
|
|
|
|
return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
static void test_Console(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-06-18 05:24:20 +02:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
|
|
|
|
DWORD modeIn, modeOut, modeInC, modeOutC;
|
|
|
|
DWORD cpIn, cpOut, cpInC, cpOutC;
|
|
|
|
DWORD w;
|
|
|
|
HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
|
|
|
|
const char* msg = "This is a std-handle inheritance test.";
|
|
|
|
unsigned msg_len;
|
2008-09-20 12:49:41 +02:00
|
|
|
BOOL run_tests = TRUE;
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
|
|
|
|
/* first, we need to be sure we're attached to a console */
|
2005-06-27 11:54:09 +02:00
|
|
|
if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
|
2003-06-18 05:24:20 +02:00
|
|
|
{
|
|
|
|
/* we're not attached to a console, let's do it */
|
|
|
|
AllocConsole();
|
|
|
|
startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
}
|
|
|
|
/* now verify everything's ok */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
|
|
|
|
ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
startup.hStdError = startup.hStdOutput;
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
|
2004-02-06 06:24:34 +01:00
|
|
|
GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
cpIn = GetConsoleCP();
|
|
|
|
cpOut = GetConsoleOutputCP();
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s console", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
/* now get the modification the child has made, and resets parents expected values */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
|
2004-02-06 06:24:34 +01:00
|
|
|
GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
SetConsoleMode(startup.hStdInput, modeIn);
|
|
|
|
SetConsoleMode(startup.hStdOutput, modeOut);
|
|
|
|
|
|
|
|
cpInC = GetConsoleCP();
|
|
|
|
cpOutC = GetConsoleOutputCP();
|
2007-05-10 19:24:11 +02:00
|
|
|
|
|
|
|
/* Try to set invalid CP */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!SetConsoleCP(0), "Shouldn't succeed\n");
|
2008-08-29 04:14:47 +02:00
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER ||
|
2008-09-20 12:49:41 +02:00
|
|
|
broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
|
2007-05-10 19:24:11 +02:00
|
|
|
"GetLastError: expecting %u got %u\n",
|
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
2008-09-20 12:49:41 +02:00
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
run_tests = FALSE;
|
|
|
|
|
2007-05-10 19:24:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
|
2008-08-29 04:14:47 +02:00
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER ||
|
2008-09-20 12:49:41 +02:00
|
|
|
broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
|
2007-05-10 19:24:11 +02:00
|
|
|
"GetLastError: expecting %u got %u\n",
|
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
SetConsoleCP(cpIn);
|
|
|
|
SetConsoleOutputCP(cpOut);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2008-05-08 00:44:48 +02:00
|
|
|
ok (startup.lpTitle == NULL || !strcmp(startup.lpTitle, selfname),
|
|
|
|
"StartupInfoA:lpTitle expected '%s' or null, got '%s'\n", selfname, startup.lpTitle);
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
|
|
|
|
/* check child correctly inherited the console */
|
|
|
|
okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput);
|
|
|
|
okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput);
|
|
|
|
okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError);
|
2004-08-10 01:42:19 +02:00
|
|
|
okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
|
|
|
|
okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
|
|
|
|
okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
|
|
|
|
okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("Console", "Attributes", sbi.wAttributes);
|
2004-08-10 01:42:19 +02:00
|
|
|
okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
|
|
|
|
okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
|
|
|
|
okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
|
|
|
|
okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
|
|
|
|
okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
|
|
|
|
okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("Console", "InputCP", cpIn);
|
|
|
|
okChildInt("Console", "OutputCP", cpOut);
|
|
|
|
okChildInt("Console", "InputMode", modeIn);
|
|
|
|
okChildInt("Console", "OutputMode", modeOut);
|
|
|
|
|
2008-09-20 12:49:41 +02:00
|
|
|
if (run_tests)
|
|
|
|
{
|
|
|
|
ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
|
|
|
|
ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
|
|
|
|
}
|
|
|
|
else
|
2008-10-07 14:07:50 +02:00
|
|
|
win_skip("Setting the codepage is not implemented\n");
|
2008-09-20 12:49:41 +02:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
|
|
|
|
ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
|
2008-05-08 00:44:48 +02:00
|
|
|
trace("cursor position(X): %d/%d\n",sbi.dwCursorPosition.X, sbiC.dwCursorPosition.X);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
|
|
|
|
&hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
|
2004-02-06 06:24:34 +01:00
|
|
|
"Duplicating as inheritable child-output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
CloseHandle(hChildOut);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
|
|
|
|
&hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
|
2004-02-06 06:24:34 +01:00
|
|
|
"Duplicating as inheritable child-input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
CloseHandle(hChildIn);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
startup.hStdInput = hChildInInh;
|
|
|
|
startup.hStdOutput = hChildOutInh;
|
|
|
|
startup.hStdError = hChildOutInh;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
|
|
|
|
ok(CloseHandle(hChildInInh), "Closing handle\n");
|
|
|
|
ok(CloseHandle(hChildOutInh), "Closing handle\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
msg_len = strlen(msg) + 1;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
|
2003-06-18 05:24:20 +02:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
|
|
|
|
ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildString("StdHandle", "msg", msg);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:05:40 +02:00
|
|
|
static void test_ExitCode(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
DWORD code;
|
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
okChildInt("ExitCode", "value", code);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2006-11-08 16:45:33 +01:00
|
|
|
static void test_OpenProcess(void)
|
|
|
|
{
|
|
|
|
HANDLE hproc;
|
|
|
|
void *addr1;
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
|
|
|
SIZE_T dummy, read_bytes;
|
|
|
|
|
2007-01-20 12:38:14 +01:00
|
|
|
/* not exported in all windows versions */
|
|
|
|
if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) {
|
|
|
|
skip("VirtualAllocEx not found\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2006-11-08 16:45:33 +01:00
|
|
|
/* without PROCESS_VM_OPERATION */
|
|
|
|
hproc = OpenProcess(PROCESS_ALL_ACCESS & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
|
|
|
|
ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-11-19 16:05:47 +01:00
|
|
|
addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(!addr1, "VirtualAllocEx should fail\n");
|
2007-01-06 11:44:36 +01:00
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{ /* Win9x */
|
|
|
|
CloseHandle(hproc);
|
2007-01-20 12:38:14 +01:00
|
|
|
skip("VirtualAllocEx not implemented\n");
|
2007-01-06 11:44:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
read_bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes),
|
|
|
|
"ReadProcessMemory error %d\n", GetLastError());
|
|
|
|
ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
|
|
|
hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
|
|
|
|
ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
2006-11-19 16:05:47 +01:00
|
|
|
addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* without PROCESS_QUERY_INFORMATION */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
|
|
|
|
"VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* without PROCESS_VM_READ */
|
|
|
|
read_bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
|
|
|
|
"ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
|
|
|
hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
|
2008-03-05 12:04:43 +01:00
|
|
|
memset(&info, 0xcc, sizeof(info));
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(VirtualQueryEx(hproc, addr1, &info, sizeof(info)) == sizeof(info),
|
|
|
|
"VirtualQueryEx error %d\n", GetLastError());
|
|
|
|
|
|
|
|
ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
|
|
|
|
ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
|
|
|
|
ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
|
|
|
|
ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
|
|
|
|
ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
|
|
|
|
/* NT reports Protect == 0 for a not committed memory block */
|
|
|
|
ok(info.Protect == 0 /* NT */ ||
|
|
|
|
info.Protect == PAGE_NOACCESS, /* Win9x */
|
|
|
|
"%x != PAGE_NOACCESS\n", info.Protect);
|
|
|
|
ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-11-19 16:05:47 +01:00
|
|
|
ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
|
2006-11-08 16:45:33 +01:00
|
|
|
"VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
|
|
|
ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
START_TEST(process)
|
|
|
|
{
|
|
|
|
int b = init();
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(b, "Basic init of CreateProcess test\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
if (!b) return;
|
|
|
|
|
|
|
|
if (myARGC >= 3)
|
|
|
|
{
|
2003-06-18 05:24:20 +02:00
|
|
|
doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
|
2002-04-22 00:07:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
test_Startup();
|
|
|
|
test_CommandLine();
|
|
|
|
test_Directory();
|
2003-01-13 19:28:43 +01:00
|
|
|
test_Environment();
|
|
|
|
test_SuspendFlag();
|
|
|
|
test_DebuggingFlag();
|
2003-06-18 05:24:20 +02:00
|
|
|
test_Console();
|
2003-06-26 04:05:40 +02:00
|
|
|
test_ExitCode();
|
2006-11-08 16:45:33 +01:00
|
|
|
test_OpenProcess();
|
2002-04-22 00:07:03 +02:00
|
|
|
/* things that can be tested:
|
|
|
|
* lookup: check the way program to be executed is searched
|
|
|
|
* handles: check the handle inheritance stuff (+sec options)
|
|
|
|
* console: check if console creation parameters work
|
|
|
|
*/
|
|
|
|
}
|