2008-06-18 19:10:39 +00:00
|
|
|
/*
|
2008-06-19 08:36:17 +00:00
|
|
|
* PROJECT: ReactOS API Test GUI
|
2008-06-18 19:10:39 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE:
|
|
|
|
* PURPOSE: main dialog implementation
|
|
|
|
* COPYRIGHT: Copyright 2008 Ged Murphy <gedmurphy@reactos.org>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
2008-10-20 14:49:59 +00:00
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
#define BUFSIZE 4096
|
2008-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
|
2008-10-20 14:49:59 +00:00
|
|
|
WCHAR szPipeName[] = L"\\\\.\\pipe\\winetest_pipe";
|
|
|
|
|
2008-06-21 19:19:22 +00:00
|
|
|
typedef int (_cdecl *RUNTEST)(char **);
|
2008-06-18 19:10:39 +00:00
|
|
|
|
2008-11-18 18:57:27 +00:00
|
|
|
DWORD WINAPI
|
|
|
|
PipeReadThread(LPVOID lpParam)
|
|
|
|
{
|
|
|
|
PMAIN_WND_INFO pInfo;
|
|
|
|
HWND hList, hEdit;
|
|
|
|
DWORD dwRead;
|
|
|
|
CHAR chBuf[BUFSIZE];
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LVITEMA item;
|
|
|
|
INT count;
|
|
|
|
|
|
|
|
pInfo = (PMAIN_WND_INFO)lpParam;
|
|
|
|
|
|
|
|
hList = GetDlgItem(pInfo->hMainWnd, IDC_LIST);
|
|
|
|
hEdit = GetDlgItem(pInfo->hMainWnd, IDC_OUTPUT);
|
|
|
|
|
|
|
|
ZeroMemory(&item, sizeof(LVITEMA));
|
|
|
|
item.mask = LVIF_TEXT;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
dwRead = 0;
|
|
|
|
bSuccess = ReadFile(pInfo->hStdOutRd,
|
|
|
|
chBuf,
|
|
|
|
BUFSIZE,
|
|
|
|
&dwRead,
|
|
|
|
NULL);
|
|
|
|
if(!bSuccess || dwRead == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
chBuf[dwRead] = 0;
|
|
|
|
|
|
|
|
count = GetWindowTextLengthA(hEdit);
|
|
|
|
SendMessageA(hEdit, EM_SETSEL, (WPARAM)count, (LPARAM)count);
|
|
|
|
SendMessageA(hEdit, EM_REPLACESEL, 0, (LPARAM)chBuf);
|
|
|
|
|
|
|
|
//item.iItem = ListView_GetItemCount(hList);
|
|
|
|
//item.pszText = chBuf;
|
|
|
|
//SendMessage(hEdit, LVM_INSERTITEMA, 0, (LPARAM)&item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-20 14:49:59 +00:00
|
|
|
|
2008-11-18 18:57:27 +00:00
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
CreateClientProcess(PMAIN_WND_INFO pInfo)
|
2008-10-20 14:49:59 +00:00
|
|
|
{
|
2008-11-18 18:57:27 +00:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
|
|
|
STARTUPINFO si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the security attributes
|
|
|
|
//
|
|
|
|
sa.nLength= sizeof(SECURITY_ATTRIBUTES);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a pipe for the child process's STDOUT
|
|
|
|
//
|
|
|
|
if (!CreatePipe(&pInfo->hStdOutRd,
|
|
|
|
&pInfo->hStdOutWr,
|
|
|
|
&sa,
|
|
|
|
0))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Ensure the read handle to the pipe for STDOUT is not inherited
|
|
|
|
//
|
|
|
|
if (!SetHandleInformation(pInfo->hStdOutRd,
|
|
|
|
HANDLE_FLAG_INHERIT,
|
|
|
|
0))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(STARTUPINFO));
|
|
|
|
si.cb = sizeof(STARTUPINFO);
|
|
|
|
si.hStdError = pInfo->hStdOutWr;
|
|
|
|
si.hStdOutput = pInfo->hStdOutWr;
|
|
|
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
si.dwFlags |= STARTF_USESTDHANDLES;
|
|
|
|
|
|
|
|
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
|
|
|
|
|
|
|
|
bSuccess = CreateProcessW(pInfo->lpCmdLine,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
0,//CREATE_SUSPENDED,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi);
|
|
|
|
if (bSuccess)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Create thread to handle pipe input from child processes
|
|
|
|
//
|
|
|
|
pInfo->hPipeThread = CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
PipeReadThread,
|
|
|
|
pInfo,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
2008-10-20 14:49:59 +00:00
|
|
|
|
2008-11-18 18:57:27 +00:00
|
|
|
return bSuccess;
|
2008-10-20 14:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-18 19:10:39 +00:00
|
|
|
static BOOL
|
|
|
|
OnInitMainDialog(HWND hDlg,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
PMAIN_WND_INFO pInfo;
|
|
|
|
|
|
|
|
pInfo = (PMAIN_WND_INFO)lParam;
|
|
|
|
|
|
|
|
/* Initialize the main window context */
|
|
|
|
pInfo->hMainWnd = hDlg;
|
|
|
|
|
|
|
|
SetWindowLongPtr(hDlg,
|
|
|
|
GWLP_USERDATA,
|
|
|
|
(LONG_PTR)pInfo);
|
|
|
|
|
|
|
|
pInfo->hSmIcon = LoadImageW(hInstance,
|
2008-06-21 19:19:22 +00:00
|
|
|
MAKEINTRESOURCEW(IDI_ICON),
|
|
|
|
IMAGE_ICON,
|
|
|
|
16,
|
|
|
|
16,
|
|
|
|
0);
|
2008-06-18 19:10:39 +00:00
|
|
|
if (pInfo->hSmIcon)
|
|
|
|
{
|
|
|
|
SendMessageW(hDlg,
|
|
|
|
WM_SETICON,
|
|
|
|
ICON_SMALL,
|
|
|
|
(LPARAM)pInfo->hSmIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->hBgIcon = LoadImageW(hInstance,
|
2008-06-21 19:19:22 +00:00
|
|
|
MAKEINTRESOURCEW(IDI_ICON),
|
|
|
|
IMAGE_ICON,
|
|
|
|
32,
|
|
|
|
32,
|
|
|
|
0);
|
2008-06-18 19:10:39 +00:00
|
|
|
if (pInfo->hBgIcon)
|
|
|
|
{
|
|
|
|
SendMessageW(hDlg,
|
|
|
|
WM_SETICON,
|
|
|
|
ICON_BIG,
|
|
|
|
(LPARAM)pInfo->hBgIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-21 19:19:22 +00:00
|
|
|
static VOID
|
|
|
|
RunSelectedTest(PMAIN_WND_INFO pInfo)
|
|
|
|
{
|
|
|
|
HWND hRunCmd;
|
|
|
|
WCHAR szTextCmd[MAX_RUN_CMD];
|
2008-10-20 14:49:59 +00:00
|
|
|
INT sel;
|
2008-06-21 19:19:22 +00:00
|
|
|
|
|
|
|
hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
|
|
|
|
|
|
|
|
sel = SendMessageW(hRunCmd,
|
|
|
|
CB_GETCURSEL,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
if (sel != CB_ERR)
|
|
|
|
{
|
|
|
|
if (SendMessageW(hRunCmd,
|
|
|
|
CB_GETLBTEXT,
|
|
|
|
sel,
|
2008-10-20 14:49:59 +00:00
|
|
|
(LPARAM)szTextCmd) != CB_ERR)
|
2008-06-21 19:19:22 +00:00
|
|
|
{
|
2008-11-18 18:57:27 +00:00
|
|
|
pInfo->lpCmdLine = (LPWSTR)SendMessage(hRunCmd,
|
|
|
|
CB_GETITEMDATA,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
if (pInfo->lpCmdLine)
|
2008-06-21 19:19:22 +00:00
|
|
|
{
|
2008-11-18 18:57:27 +00:00
|
|
|
//
|
|
|
|
// Create a new thread to create the client process
|
2013-04-13 21:33:03 +00:00
|
|
|
// and receive any ouput via stdout
|
2008-11-18 18:57:27 +00:00
|
|
|
//
|
|
|
|
CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
CreateClientProcess,
|
|
|
|
pInfo,
|
|
|
|
0,
|
|
|
|
NULL);
|
2008-06-21 19:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
AddTestToCombo(PMAIN_WND_INFO pInfo)
|
|
|
|
{
|
|
|
|
HWND hRunCmd;
|
2008-10-20 14:49:59 +00:00
|
|
|
LPWSTR lpExePath;
|
2008-06-21 19:19:22 +00:00
|
|
|
INT len;
|
|
|
|
|
|
|
|
hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
|
|
|
|
if (hRunCmd)
|
|
|
|
{
|
|
|
|
SendMessageW(hRunCmd,
|
|
|
|
CB_INSERTSTRING,
|
|
|
|
0,
|
2008-11-18 18:57:27 +00:00
|
|
|
(LPARAM)pInfo->SelectedTest.szName);
|
2008-06-21 19:19:22 +00:00
|
|
|
|
2008-11-18 18:57:27 +00:00
|
|
|
len = (wcslen(pInfo->SelectedTest.szRunCmd) + 1) * sizeof(WCHAR);
|
2008-10-20 14:49:59 +00:00
|
|
|
lpExePath = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (lpExePath)
|
2008-06-21 19:19:22 +00:00
|
|
|
{
|
2008-10-20 14:49:59 +00:00
|
|
|
wcsncpy(lpExePath,
|
2008-11-18 18:57:27 +00:00
|
|
|
pInfo->SelectedTest.szRunCmd,
|
2008-06-21 19:19:22 +00:00
|
|
|
len / sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageW(hRunCmd,
|
|
|
|
CB_SETITEMDATA,
|
|
|
|
0,
|
2008-10-20 14:49:59 +00:00
|
|
|
(LPARAM)lpExePath);
|
2008-06-21 19:19:22 +00:00
|
|
|
SendMessageW(hRunCmd,
|
|
|
|
CB_SETCURSEL,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
FreeTestCmdStrings(PMAIN_WND_INFO pInfo)
|
|
|
|
{
|
|
|
|
HWND hRunCmd;
|
2008-10-20 14:49:59 +00:00
|
|
|
LPWSTR lpExePath;
|
2008-06-21 19:19:22 +00:00
|
|
|
INT cnt, i;
|
|
|
|
|
|
|
|
hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
|
|
|
|
|
|
|
|
cnt = SendMessageW(hRunCmd,
|
|
|
|
CB_GETCOUNT,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
if (cnt != CB_ERR)
|
|
|
|
{
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
{
|
2008-10-20 14:49:59 +00:00
|
|
|
lpExePath = (LPWSTR)SendMessage(hRunCmd,
|
|
|
|
CB_GETITEMDATA,
|
|
|
|
i,
|
|
|
|
0);
|
|
|
|
if (lpExePath)
|
2008-06-21 19:19:22 +00:00
|
|
|
{
|
2008-10-20 14:49:59 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpExePath);
|
2008-06-21 19:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
static BOOL CALLBACK
|
|
|
|
MainDlgProc(HWND hDlg,
|
|
|
|
UINT Message,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
PMAIN_WND_INFO pInfo;
|
|
|
|
|
|
|
|
/* Get the window context */
|
|
|
|
pInfo = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
|
|
|
|
GWLP_USERDATA);
|
|
|
|
if (pInfo == NULL && Message != WM_INITDIALOG)
|
|
|
|
{
|
|
|
|
goto HandleDefaultMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(Message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return OnInitMainDialog(hDlg, lParam);
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_BROWSE:
|
2008-06-21 19:19:22 +00:00
|
|
|
{
|
|
|
|
INT_PTR ret;
|
|
|
|
|
|
|
|
ret = DialogBoxParamW(hInstance,
|
|
|
|
MAKEINTRESOURCEW(IDD_TESTBROWSER),
|
|
|
|
hDlg,
|
|
|
|
(DLGPROC)BrowseDlgProc,
|
|
|
|
(LPARAM)pInfo);
|
|
|
|
if (ret == IDOK)
|
|
|
|
{
|
|
|
|
AddTestToCombo(pInfo);
|
|
|
|
}
|
2008-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
break;
|
2008-06-21 19:19:22 +00:00
|
|
|
}
|
2008-10-20 14:49:59 +00:00
|
|
|
case IDC_OPTIONS:
|
|
|
|
DialogBoxParamW(hInstance,
|
|
|
|
MAKEINTRESOURCEW(IDD_OPTIONS),
|
|
|
|
hDlg,
|
|
|
|
(DLGPROC)OptionsDlgProc,
|
|
|
|
(LPARAM)pInfo);
|
|
|
|
break;
|
2008-06-21 19:19:22 +00:00
|
|
|
|
|
|
|
case IDC_RUN:
|
|
|
|
RunSelectedTest(pInfo);
|
|
|
|
break;
|
2008-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
case IDOK:
|
|
|
|
EndDialog(hDlg, 0);
|
2008-06-21 19:19:22 +00:00
|
|
|
break;
|
2008-06-18 19:10:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
2008-06-21 19:19:22 +00:00
|
|
|
EndDialog(hDlg, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
if (pInfo->hSmIcon)
|
2008-06-18 19:10:39 +00:00
|
|
|
DestroyIcon(pInfo->hSmIcon);
|
|
|
|
if (pInfo->hBgIcon)
|
|
|
|
DestroyIcon(pInfo->hBgIcon);
|
2008-06-21 19:19:22 +00:00
|
|
|
|
|
|
|
FreeTestCmdStrings(pInfo);
|
|
|
|
|
2008-06-18 19:10:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
HandleDefaultMessage:
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT WINAPI
|
|
|
|
wWinMain(HINSTANCE hInst,
|
|
|
|
HINSTANCE hPrev,
|
|
|
|
LPWSTR Cmd,
|
|
|
|
int iCmd)
|
|
|
|
{
|
|
|
|
INITCOMMONCONTROLSEX iccx;
|
|
|
|
PMAIN_WND_INFO pInfo;
|
2008-10-20 14:49:59 +00:00
|
|
|
INT Ret = -1;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(hPrev);
|
|
|
|
UNREFERENCED_PARAMETER(Cmd);
|
|
|
|
UNREFERENCED_PARAMETER(iCmd);
|
2008-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
hInstance = hInst;
|
|
|
|
|
|
|
|
ZeroMemory(&iccx, sizeof(INITCOMMONCONTROLSEX));
|
|
|
|
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
iccx.dwICC = ICC_TAB_CLASSES;
|
|
|
|
InitCommonControlsEx(&iccx);
|
|
|
|
|
2008-10-20 14:49:59 +00:00
|
|
|
pInfo = HeapAlloc(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(MAIN_WND_INFO));
|
2008-06-18 19:10:39 +00:00
|
|
|
if (pInfo)
|
|
|
|
{
|
|
|
|
Ret = (DialogBoxParamW(hInstance,
|
|
|
|
MAKEINTRESOURCEW(IDD_WINETESTGUI),
|
|
|
|
NULL,
|
|
|
|
(DLGPROC)MainDlgProc,
|
|
|
|
(LPARAM)pInfo) == IDOK);
|
|
|
|
|
2008-10-20 14:49:59 +00:00
|
|
|
HeapFree(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
pInfo);
|
2008-06-18 19:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|