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
|
|
|
|
2008-10-15 16:44:54 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
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"
|
2008-10-15 16:44:54 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2009-03-29 23:36:33 +02:00
|
|
|
#define expect_eq_d(expected, actual) \
|
|
|
|
do { \
|
|
|
|
int value = (actual); \
|
|
|
|
ok((expected) == value, "Expected " #actual " to be %d (" #expected ") is %d\n", \
|
|
|
|
(expected), value); \
|
|
|
|
} while (0)
|
|
|
|
#define expect_eq_ws_i(expected, actual) \
|
|
|
|
do { \
|
|
|
|
LPCWSTR value = (actual); \
|
|
|
|
ok(lstrcmpiW((expected), value) == 0, "Expected " #actual " to be L\"%s\" (" #expected ") is L\"%s\"\n", \
|
|
|
|
wine_dbgstr_w(expected), wine_dbgstr_w(value)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* A simpler version of wine_dbgstr_w. Note that the returned buffer will be
|
|
|
|
* invalid after 16 calls to this funciton. */
|
|
|
|
static const char *wine_dbgstr_w(LPCWSTR wstr)
|
|
|
|
{
|
|
|
|
static char *buffers[16];
|
|
|
|
static int curr_buffer = 0;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
curr_buffer = (curr_buffer + 1) % 16;
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffers[curr_buffer]);
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
|
buffers[curr_buffer] = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, wstr, -1, buffers[curr_buffer], size, NULL, NULL);
|
|
|
|
return buffers[curr_buffer];
|
|
|
|
}
|
|
|
|
|
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);
|
2009-03-29 23:36:33 +02:00
|
|
|
static BOOL (WINAPI *pQueryFullProcessImageNameW)(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD lpdwSize);
|
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
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* 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");
|
2009-03-29 23:36:33 +02:00
|
|
|
pQueryFullProcessImageNameW = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameW");
|
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,
|
2009-01-08 13:17:53 +01:00
|
|
|
(DWORD_PTR)siA.hStdInput, (DWORD_PTR)siA.hStdOutput, (DWORD_PTR)siA.hStdError);
|
2002-04-22 00:07:03 +02:00
|
|
|
|
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,
|
2009-01-08 13:17:53 +01:00
|
|
|
(DWORD_PTR)siW.hStdInput, (DWORD_PTR)siW.hStdOutput, (DWORD_PTR)siW.hStdError);
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2008-10-15 16:30:28 +02:00
|
|
|
static WCHAR* getChildStringW(const char* sect, const char* key)
|
|
|
|
{
|
|
|
|
char buf[1024+4*MAX_LISTED_ENV_VAR];
|
|
|
|
WCHAR* ret;
|
|
|
|
|
|
|
|
GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
|
|
|
|
if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
|
|
|
|
assert(!(strlen(buf) & 1));
|
|
|
|
ret = decodeW(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* 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
|
|
|
|
2008-10-15 16:30:28 +02:00
|
|
|
static void ok_child_stringWA( int line, const char *sect, const char *key,
|
|
|
|
const char *expect, int sensitive )
|
|
|
|
{
|
|
|
|
WCHAR* expectW;
|
|
|
|
CHAR* resultA;
|
|
|
|
DWORD len;
|
|
|
|
WCHAR* result = getChildStringW( sect, key );
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, expect, -1, NULL, 0);
|
|
|
|
expectW = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, expect, -1, expectW, len);
|
|
|
|
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, result, -1, NULL, 0, NULL, NULL);
|
|
|
|
resultA = HeapAlloc(GetProcessHeap(),0,len*sizeof(CHAR));
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, result, -1, resultA, len, NULL, NULL);
|
|
|
|
|
|
|
|
if (sensitive)
|
|
|
|
ok_(__FILE__, line)( lstrcmpW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", resultA );
|
|
|
|
else
|
|
|
|
ok_(__FILE__, line)( lstrcmpiW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", resultA );
|
|
|
|
HeapFree(GetProcessHeap(),0,expectW);
|
|
|
|
HeapFree(GetProcessHeap(),0,resultA);
|
|
|
|
}
|
|
|
|
|
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 )
|
2008-10-15 16:30:28 +02:00
|
|
|
#define okChildStringWA(sect, key, expect) ok_child_stringWA(__LINE__, (sect), (key), (expect), 1 )
|
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); \
|
2009-01-08 13:17:53 +01:00
|
|
|
ok(result == expect, "%s:%s expected %u, but got %u\n", (sect), (key), (UINT)(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",
|
2008-11-17 23:37:00 +01:00
|
|
|
desktop[] = "winsta0\\default",
|
2006-06-02 20:01:23 +02:00
|
|
|
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;
|
2008-10-15 16:30:21 +02:00
|
|
|
char buffer2[MAX_PATH];
|
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, '\\');
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2008-11-17 23:37:00 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s tests/process.c %s \"a\\\"b\\\\\" c\\\" d", p, exename, resfile);
|
|
|
|
else 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);
|
2008-11-17 23:37:00 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s", p, exename);
|
|
|
|
else sprintf(buffer, "./%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2008-10-15 16:30:21 +02:00
|
|
|
|
|
|
|
/* Using AppName */
|
|
|
|
get_file_name(resfile);
|
|
|
|
len = GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
|
|
|
|
assert ( lpFilePart != 0);
|
|
|
|
*(lpFilePart -1 ) = 0;
|
|
|
|
p = strrchr(fullpath, '\\');
|
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2008-11-17 23:37:00 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s", p, exename);
|
|
|
|
else sprintf(buffer, "./%s", exename);
|
2008-10-15 16:30:21 +02:00
|
|
|
sprintf(buffer2, "dummy tests/process.c %s \"a\\\"b\\\\\" c\\\" d", resfile);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
|
|
|
/* 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);
|
|
|
|
sprintf(buffer, "tests/process.c %s", resfile);
|
|
|
|
okChildString("Arguments", "argvA0", "dummy");
|
|
|
|
okChildString("Arguments", "CommandLineA", buffer2);
|
2008-10-15 16:30:28 +02:00
|
|
|
okChildStringWA("Arguments", "CommandLineW", buffer2);
|
2008-10-15 16:30:21 +02:00
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2009-05-18 12:07:04 +02:00
|
|
|
|
|
|
|
if (0) /* Test crashes on NT-based Windows. */
|
|
|
|
{
|
|
|
|
/* Test NULL application name and command line parameters. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
2009-05-18 12:07:10 +02:00
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
/* Test empty application name parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
|
2009-05-18 19:22:28 +02:00
|
|
|
broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
|
2009-05-18 12:07:10 +02:00
|
|
|
broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
|
|
|
|
"Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
buffer2[0] = '\0';
|
|
|
|
|
|
|
|
/* Test empty application name and command line parameters. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
|
2009-05-18 19:22:28 +02:00
|
|
|
broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
|
2009-05-18 12:07:10 +02:00
|
|
|
broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
|
|
|
|
"Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
|
2009-05-18 12:07:18 +02:00
|
|
|
|
|
|
|
/* Test empty command line parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND /* NT4 */ ||
|
|
|
|
GetLastError() == ERROR_BAD_PATHNAME /* Win98 */,
|
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
strcpy(buffer, "doesnotexist.exe");
|
|
|
|
strcpy(buffer2, "does not exist.exe");
|
|
|
|
|
|
|
|
/* Test nonexistent application name. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer2, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Test nonexistent command line parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
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 */
|
2009-01-08 13:17:53 +01:00
|
|
|
okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR)startup.hStdInput);
|
|
|
|
okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR)startup.hStdOutput);
|
|
|
|
okChildInt("StartupInfoA", "hStdError", (DWORD_PTR)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)) {
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("VirtualAllocEx not found\n");
|
2007-01-20 12:38:14 +01:00
|
|
|
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);
|
2009-02-24 00:03:07 +01:00
|
|
|
win_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");
|
|
|
|
}
|
|
|
|
|
2008-10-15 16:44:54 +02:00
|
|
|
static void test_GetProcessVersion(void)
|
|
|
|
{
|
|
|
|
static char cmdline[] = "winver.exe";
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(0);
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(GetCurrentProcessId());
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(ret, "CreateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(pi.dwProcessId);
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
2009-03-29 23:36:33 +02:00
|
|
|
static void test_ProcessName(void)
|
|
|
|
{
|
|
|
|
HANDLE hSelf;
|
|
|
|
WCHAR module_name[1024];
|
|
|
|
WCHAR deviceW[] = {'\\','D', 'e','v','i','c','e',0};
|
|
|
|
WCHAR buf[1024];
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!pQueryFullProcessImageNameW)
|
|
|
|
{
|
|
|
|
win_skip("QueryFullProcessImageNameW unavailable (added in Windows Vista)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(GetModuleFileNameW(NULL, module_name, 1024), "GetModuleFileNameW(NULL, ...) failed\n");
|
|
|
|
|
|
|
|
/* GetCurrentProcess pseudo-handle */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(GetCurrentProcess(), 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
expect_eq_ws_i(buf, module_name);
|
|
|
|
|
|
|
|
hSelf = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
/* Real handle */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
expect_eq_ws_i(buf, module_name);
|
|
|
|
|
|
|
|
/* Buffer too small */
|
|
|
|
size = lstrlenW(module_name)/2;
|
|
|
|
lstrcpyW(buf, deviceW);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_ws_i(deviceW, buf); /* buffer not changed */
|
|
|
|
|
|
|
|
/* Too small - not space for NUL terminator */
|
|
|
|
size = lstrlenW(module_name);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name), size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
|
|
|
|
/* NULL buffer */
|
|
|
|
size = 0;
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, NULL, &size));
|
|
|
|
expect_eq_d(0, size);
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
|
|
|
|
/* native path */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, PROCESS_NAME_NATIVE, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
ok(buf[0] == '\\', "NT path should begin with '\\'\n");
|
|
|
|
todo_wine ok(memcmp(buf, deviceW, sizeof(WCHAR)*lstrlenW(deviceW)) == 0, "NT path should begin with \\Device\n");
|
|
|
|
|
|
|
|
/* Buffer too small */
|
|
|
|
size = lstrlenW(module_name)/2;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
lstrcpyW(buf, module_name);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_ws_i(module_name, buf); /* buffer not changed */
|
|
|
|
|
|
|
|
CloseHandle(hSelf);
|
|
|
|
}
|
|
|
|
|
2008-12-08 13:39:31 +01:00
|
|
|
static void test_Handles(void)
|
|
|
|
{
|
|
|
|
HANDLE handle = GetCurrentProcess();
|
|
|
|
BOOL ret;
|
|
|
|
DWORD code;
|
|
|
|
|
2008-12-08 21:19:39 +01:00
|
|
|
ok( handle == (HANDLE)~(ULONG_PTR)0 ||
|
|
|
|
handle == (HANDLE)(ULONG_PTR)0x7fffffff /* win9x */,
|
|
|
|
"invalid current process handle %p\n", handle );
|
2008-12-08 13:39:31 +01:00
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
|
|
|
|
#ifdef _WIN64
|
|
|
|
/* truncated handle */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)((ULONG_PTR)handle & ~0u);
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
|
|
|
|
/* sign-extended handle */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)((LONG_PTR)(int)(ULONG_PTR)handle);
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
|
|
|
|
/* invalid high-word */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)(((ULONG_PTR)handle & ~0u) + ((ULONG_PTR)1 << 32));
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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();
|
2008-10-15 16:44:54 +02:00
|
|
|
test_GetProcessVersion();
|
2009-03-29 23:36:33 +02:00
|
|
|
test_ProcessName();
|
2008-12-08 13:39:31 +01:00
|
|
|
test_Handles();
|
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
|
|
|
|
*/
|
|
|
|
}
|