2003-05-13 06:46:54 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for console API
|
|
|
|
*
|
2004-09-08 03:25:05 +02:00
|
|
|
* Copyright (c) 2003,2004 Eric Pouech
|
2007-05-09 18:55:08 +02:00
|
|
|
* Copyright (c) 2007 Kirill K. Smirnov
|
2003-05-13 06:46:54 +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
|
2003-05-13 06:46:54 +02:00
|
|
|
*/
|
|
|
|
|
2020-11-10 16:31:34 +01:00
|
|
|
#include <ntstatus.h>
|
|
|
|
#define WIN32_NO_STATUS
|
2003-05-13 06:46:54 +02:00
|
|
|
#include <windows.h>
|
2020-06-25 22:26:30 +02:00
|
|
|
#include <winternl.h>
|
2020-11-20 15:40:19 +01:00
|
|
|
#include <winioctl.h>
|
2003-05-13 06:46:54 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-11-10 16:31:34 +01:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2020-08-20 23:49:09 +02:00
|
|
|
static void (WINAPI *pClosePseudoConsole)(HPCON);
|
|
|
|
static HRESULT (WINAPI *pCreatePseudoConsole)(COORD,HANDLE,HANDLE,DWORD,HPCON*);
|
2007-12-05 11:40:05 +01:00
|
|
|
static BOOL (WINAPI *pGetConsoleInputExeNameA)(DWORD, LPSTR);
|
2010-01-05 09:32:36 +01:00
|
|
|
static DWORD (WINAPI *pGetConsoleProcessList)(LPDWORD, DWORD);
|
2010-04-01 02:53:59 +02:00
|
|
|
static HANDLE (WINAPI *pOpenConsoleW)(LPCWSTR,DWORD,BOOL,DWORD);
|
2007-12-05 11:40:05 +01:00
|
|
|
static BOOL (WINAPI *pSetConsoleInputExeNameA)(LPCSTR);
|
2010-09-22 19:54:36 +02:00
|
|
|
static BOOL (WINAPI *pVerifyConsoleIoHandle)(HANDLE handle);
|
2007-12-02 22:12:19 +01:00
|
|
|
|
2020-07-01 16:27:22 +02:00
|
|
|
static BOOL skip_nt;
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* DEFAULT_ATTRIB is used for all initial filling of the console.
|
2003-09-25 22:29:40 +02:00
|
|
|
* all modifications are made with TEST_ATTRIB so that we could check
|
|
|
|
* what has to be modified or not
|
2003-05-13 06:46:54 +02:00
|
|
|
*/
|
|
|
|
#define TEST_ATTRIB (BACKGROUND_BLUE | FOREGROUND_GREEN)
|
|
|
|
#define DEFAULT_ATTRIB (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)
|
2003-09-25 22:29:40 +02:00
|
|
|
/* when filling the screen with non-blank chars, this macro defines
|
2003-05-13 06:46:54 +02:00
|
|
|
* what character should be at position 'c'
|
|
|
|
*/
|
|
|
|
#define CONTENT(c) ('A' + (((c).Y * 17 + (c).X) % 23))
|
|
|
|
|
|
|
|
#define okCURSOR(hCon, c) do { \
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO __sbi; \
|
|
|
|
BOOL expect = GetConsoleScreenBufferInfo((hCon), &__sbi) && \
|
|
|
|
__sbi.dwCursorPosition.X == (c).X && __sbi.dwCursorPosition.Y == (c).Y; \
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(expect, "Expected cursor at (%d,%d), got (%d,%d)\n", \
|
2003-05-13 06:46:54 +02:00
|
|
|
(c).X, (c).Y, __sbi.dwCursorPosition.X, __sbi.dwCursorPosition.Y); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define okCHAR(hCon, c, ch, attr) do { \
|
|
|
|
char __ch; WORD __attr; DWORD __len; BOOL expect; \
|
2013-10-21 10:01:37 +02:00
|
|
|
expect = ReadConsoleOutputCharacterA((hCon), &__ch, 1, (c), &__len) == 1 && __len == 1 && __ch == (ch); \
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(expect, "At (%d,%d): expecting char '%c'/%02x got '%c'/%02x\n", (c).X, (c).Y, (ch), (ch), __ch, __ch); \
|
2003-05-13 06:46:54 +02:00
|
|
|
expect = ReadConsoleOutputAttribute((hCon), &__attr, 1, (c), &__len) == 1 && __len == 1 && __attr == (attr); \
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(expect, "At (%d,%d): expecting attr %04x got %04x\n", (c).X, (c).Y, (attr), __attr); \
|
2003-05-13 06:46:54 +02:00
|
|
|
} while (0)
|
|
|
|
|
2007-12-05 11:40:05 +01:00
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
HMODULE hKernel32;
|
|
|
|
|
|
|
|
#define KERNEL32_GET_PROC(func) \
|
|
|
|
p##func = (void *)GetProcAddress(hKernel32, #func); \
|
|
|
|
if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
|
|
|
|
|
|
|
|
hKernel32 = GetModuleHandleA("kernel32.dll");
|
2020-08-20 23:49:09 +02:00
|
|
|
KERNEL32_GET_PROC(ClosePseudoConsole);
|
|
|
|
KERNEL32_GET_PROC(CreatePseudoConsole);
|
2007-12-05 11:40:05 +01:00
|
|
|
KERNEL32_GET_PROC(GetConsoleInputExeNameA);
|
2010-01-05 09:32:36 +01:00
|
|
|
KERNEL32_GET_PROC(GetConsoleProcessList);
|
2010-04-01 02:53:59 +02:00
|
|
|
KERNEL32_GET_PROC(OpenConsoleW);
|
2007-12-05 11:40:05 +01:00
|
|
|
KERNEL32_GET_PROC(SetConsoleInputExeNameA);
|
2010-09-22 19:54:36 +02:00
|
|
|
KERNEL32_GET_PROC(VerifyConsoleIoHandle);
|
2007-12-05 11:40:05 +01:00
|
|
|
|
|
|
|
#undef KERNEL32_GET_PROC
|
|
|
|
}
|
|
|
|
|
2020-11-12 19:56:30 +01:00
|
|
|
static HANDLE create_unbound_handle(BOOL output, BOOL test_status)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
UNICODE_STRING name;
|
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
attr.ObjectName = &name;
|
|
|
|
attr.Attributes = OBJ_INHERIT;
|
|
|
|
RtlInitUnicodeString( &name, output ? L"\\Device\\ConDrv\\Output" : L"\\Device\\ConDrv\\Input" );
|
|
|
|
status = NtCreateFile( &handle, FILE_READ_DATA | FILE_WRITE_DATA | SYNCHRONIZE | FILE_READ_ATTRIBUTES |
|
|
|
|
FILE_WRITE_ATTRIBUTES, &attr, &iosb, NULL, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_CREATE,
|
|
|
|
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
|
2022-03-02 09:03:21 +01:00
|
|
|
if (test_status) ok(!status, "NtCreateFile failed: %#lx\n", status);
|
2020-11-12 19:56:30 +01:00
|
|
|
return status ? NULL : handle;
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* FIXME: this could be optimized on a speed point of view */
|
|
|
|
static void resetContent(HANDLE hCon, COORD sbSize, BOOL content)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
WORD attr = DEFAULT_ATTRIB;
|
|
|
|
char ch;
|
|
|
|
DWORD len;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
for (c.X = 0; c.X < sbSize.X; c.X++)
|
|
|
|
{
|
|
|
|
for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
|
|
|
|
{
|
|
|
|
ch = (content) ? CONTENT(c) : ' ';
|
|
|
|
WriteConsoleOutputAttribute(hCon, &attr, 1, c, &len);
|
|
|
|
WriteConsoleOutputCharacterA(hCon, &ch, 1, c, &len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
/* dummy console ctrl handler to test reset of ctrl handler's list */
|
|
|
|
static BOOL WINAPI mydummych(DWORD event)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
static void testCursor(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
|
|
|
c.X = c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(0, c) == 0, "No handle\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %lu\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = sbSize.X - 1;
|
|
|
|
c.Y = sbSize.Y - 1;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in lower-right\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = sbSize.X;
|
|
|
|
c.Y = sbSize.Y - 1;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = sbSize.X - 1;
|
|
|
|
c.Y = sbSize.Y;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
|
|
|
|
c.X = -1;
|
|
|
|
c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
|
|
|
|
c.X = 0;
|
|
|
|
c.Y = -1;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
}
|
|
|
|
|
2008-06-24 12:21:57 +02:00
|
|
|
static void testCursorInfo(HANDLE hCon)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CONSOLE_CURSOR_INFO info;
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2008-06-24 12:21:57 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetConsoleCursorInfo(NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %lu\n",
|
2008-06-24 12:21:57 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
info.dwSize = -1;
|
|
|
|
ret = GetConsoleCursorInfo(NULL, &info);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(info.dwSize == -1, "Expected no change for dwSize\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %lu\n",
|
2008-06-24 12:21:57 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
|
|
|
/* Test the correct call first to distinguish between win9x and the rest */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetConsoleCursorInfo(hCon, &info);
|
|
|
|
ok(ret, "Expected success\n");
|
|
|
|
ok(info.dwSize == 25 ||
|
|
|
|
info.dwSize == 12 /* win9x */,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected 12 or 25, got %ld\n", info.dwSize);
|
2008-06-24 12:21:57 +02:00
|
|
|
ok(info.bVisible, "Expected the cursor to be visible\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "GetLastError: expecting %u got %lu\n",
|
2008-06-24 12:21:57 +02:00
|
|
|
0xdeadbeef, GetLastError());
|
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
info.dwSize = -1;
|
|
|
|
ret = GetConsoleCursorInfo(pipe1, &info);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(info.dwSize == -1, "Expected no change for dwSize\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: %lu\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2009-08-24 14:15:28 +02:00
|
|
|
/* Don't test NULL CONSOLE_CURSOR_INFO, it crashes on win9x and win7 */
|
2008-06-24 12:21:57 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 06:52:11 +01:00
|
|
|
static void testEmptyWrite(HANDLE hCon)
|
|
|
|
{
|
2011-01-03 04:18:36 +01:00
|
|
|
static const char emptybuf[16];
|
2009-01-19 06:52:11 +01:00
|
|
|
COORD c;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
c.X = c.Y = 0;
|
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
|
|
|
|
|
|
|
|
len = -1;
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, NULL, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
|
2009-01-19 06:52:11 +01:00
|
|
|
okCURSOR(hCon, c);
|
|
|
|
|
|
|
|
/* Passing a NULL lpBuffer with sufficiently large non-zero length succeeds
|
|
|
|
* on native Windows and result in memory-like contents being written to
|
|
|
|
* the console. Calling WriteConsoleW like this will crash on Wine. */
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
len = -1;
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(!WriteConsoleA(hCon, NULL, 16, &len, NULL) && len == -1, "WriteConsole\n");
|
2009-01-19 06:52:11 +01:00
|
|
|
okCURSOR(hCon, c);
|
|
|
|
|
|
|
|
/* Cursor advances for this call. */
|
|
|
|
len = -1;
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, NULL, 128, &len, NULL) != 0 && len == 128, "WriteConsole\n");
|
2009-01-19 06:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
len = -1;
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, emptybuf, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
|
2009-01-19 06:52:11 +01:00
|
|
|
okCURSOR(hCon, c);
|
|
|
|
|
|
|
|
/* WriteConsole does not halt on a null terminator and is happy to write
|
|
|
|
* memory contents beyond the actual size of the buffer. */
|
|
|
|
len = -1;
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, emptybuf, 16, &len, NULL) != 0 && len == 16, "WriteConsole\n");
|
2009-01-19 06:52:11 +01:00
|
|
|
c.X += 16;
|
|
|
|
okCURSOR(hCon, c);
|
|
|
|
}
|
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
static void simple_write_console(HANDLE console, const char *text)
|
2003-05-13 06:46:54 +02:00
|
|
|
{
|
2018-08-09 18:40:49 +02:00
|
|
|
DWORD len;
|
|
|
|
COORD c = {0, 0};
|
|
|
|
BOOL ret;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* single line write */
|
|
|
|
c.X = c.Y = 0;
|
2018-08-09 18:40:49 +02:00
|
|
|
ok(SetConsoleCursorPosition(console, c) != 0, "Cursor in upper-left\n");
|
|
|
|
|
|
|
|
ret = WriteConsoleA(console, text, strlen(text), &len, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleA failed: %lu\n", GetLastError());
|
|
|
|
ok(len == strlen(text), "unexpected len %lu\n", len);
|
2018-08-09 18:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteSimple(HANDLE hCon)
|
|
|
|
{
|
|
|
|
const char* mytest = "abcdefg";
|
|
|
|
int mylen = strlen(mytest);
|
|
|
|
COORD c = {0, 0};
|
2020-12-02 20:06:11 +01:00
|
|
|
DWORD len;
|
|
|
|
BOOL ret;
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
simple_write_console(hCon, mytest);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
for (c.X = 0; c.X < mylen; c.X++)
|
|
|
|
{
|
|
|
|
okCHAR(hCon, c, mytest[c.X], TEST_ATTRIB);
|
|
|
|
}
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2020-12-02 20:06:11 +01:00
|
|
|
|
|
|
|
ret = WriteFile(hCon, mytest, mylen, &len, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteFile failed: %lu\n", GetLastError());
|
|
|
|
ok(len == mylen, "unexpected len = %lu\n", len);
|
2020-12-02 20:06:11 +01:00
|
|
|
|
|
|
|
for (c.X = 0; c.X < 2 * mylen; c.X++)
|
|
|
|
{
|
|
|
|
okCHAR(hCon, c, mytest[c.X % mylen], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
|
|
|
|
okCURSOR(hCon, c);
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-05-13 06:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteNotWrappedNotProcessed(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD len, mode;
|
2005-01-28 15:02:52 +01:00
|
|
|
const char* mytest = "123";
|
|
|
|
const int mylen = strlen(mytest);
|
2004-05-03 22:07:24 +02:00
|
|
|
int ret;
|
2003-05-13 06:46:54 +02:00
|
|
|
int p;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
|
|
|
ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode & ~(ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT)),
|
2004-01-26 21:23:25 +01:00
|
|
|
"clearing wrap at EOL & processed output\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping disabled, buffer exceeds sb width */
|
|
|
|
c.X = sbSize.X - 3; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ret = WriteConsoleA(hCon, mytest, mylen, &len, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret != 0 && len == mylen, "Couldn't write, ret = %d, len = %ld\n", ret, len);
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
for (p = mylen - 3; p < mylen; p++)
|
|
|
|
{
|
|
|
|
c.X = sbSize.X - 3 + p % 3;
|
|
|
|
okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
|
|
|
|
c.X = 0; c.Y = 1;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
p = sbSize.X - 3 + mylen % 3;
|
|
|
|
c.X = p; c.Y = 0;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping disabled, strings end on end of line */
|
|
|
|
c.X = sbSize.X - mylen; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteNotWrappedProcessed(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD len, mode;
|
|
|
|
const char* mytest = "abcd\nf\tg";
|
2003-09-25 22:29:40 +02:00
|
|
|
const int mylen = strlen(mytest);
|
|
|
|
const int mylen2 = strchr(mytest, '\n') - mytest;
|
2003-05-13 06:46:54 +02:00
|
|
|
int p;
|
2009-10-14 13:34:06 +02:00
|
|
|
WORD attr;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2020-08-12 15:10:21 +02:00
|
|
|
ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, (mode | ENABLE_PROCESSED_OUTPUT) &
|
|
|
|
~(ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING)),
|
2004-01-26 21:23:25 +01:00
|
|
|
"clearing wrap at EOL & setting processed output\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping disabled, buffer exceeds sb width */
|
|
|
|
c.X = sbSize.X - 5; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-5\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
for (c.X = sbSize.X - 5; c.X < sbSize.X - 1; c.X++)
|
|
|
|
{
|
|
|
|
okCHAR(hCon, c, mytest[c.X - sbSize.X + 5], TEST_ATTRIB);
|
|
|
|
}
|
2009-10-14 13:34:06 +02:00
|
|
|
|
|
|
|
ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
|
|
|
|
/* Win9x and WinMe change the attribs for '\n' up to 'f' */
|
|
|
|
if (attr == TEST_ATTRIB)
|
|
|
|
{
|
|
|
|
win_skip("Win9x/WinMe don't respect ~ENABLE_WRAP_AT_EOL_OUTPUT\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = 0; c.Y++;
|
|
|
|
okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
|
|
|
|
for (c.X = 1; c.X < 8; c.X++)
|
|
|
|
okCHAR(hCon, c, ' ', TEST_ATTRIB);
|
|
|
|
okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
|
|
|
|
c.X++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping disabled, strings end on end of line */
|
|
|
|
c.X = sbSize.X - 4; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
for (c.X = sbSize.X - 4; c.X < sbSize.X; c.X++)
|
|
|
|
{
|
|
|
|
okCHAR(hCon, c, mytest[c.X - sbSize.X + 4], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
c.X = 0; c.Y++;
|
|
|
|
okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
|
|
|
|
for (c.X = 1; c.X < 8; c.X++)
|
|
|
|
okCHAR(hCon, c, ' ', TEST_ATTRIB);
|
|
|
|
okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
|
|
|
|
c.X++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping disabled, strings end after end of line */
|
|
|
|
c.X = sbSize.X - 3; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
for (p = mylen2 - 3; p < mylen2; p++)
|
|
|
|
{
|
|
|
|
c.X = sbSize.X - 3 + p % 3;
|
|
|
|
okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
c.X = 0; c.Y = 1;
|
|
|
|
okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
|
|
|
|
for (c.X = 1; c.X < 8; c.X++)
|
|
|
|
okCHAR(hCon, c, ' ', TEST_ATTRIB);
|
|
|
|
okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
|
|
|
|
c.X++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
okCURSOR(hCon, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteWrappedNotProcessed(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD len, mode;
|
|
|
|
const char* mytest = "abcd\nf\tg";
|
2003-09-25 22:29:40 +02:00
|
|
|
const int mylen = strlen(mytest);
|
2003-05-13 06:46:54 +02:00
|
|
|
int p;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
|
|
|
ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon,(mode | ENABLE_WRAP_AT_EOL_OUTPUT) & ~(ENABLE_PROCESSED_OUTPUT)),
|
2004-01-26 21:23:25 +01:00
|
|
|
"setting wrap at EOL & clearing processed output\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping enabled, buffer doesn't exceed sb width */
|
|
|
|
c.X = sbSize.X - 9; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
for (p = 0; p < mylen; p++)
|
|
|
|
{
|
|
|
|
c.X = sbSize.X - 9 + p;
|
|
|
|
okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
c.X = sbSize.X - 9 + mylen;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
|
|
|
c.X = 0; c.Y = 1;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping enabled, buffer does exceed sb width */
|
|
|
|
c.X = sbSize.X - 3; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 1;
|
|
|
|
c.X = mylen - 3;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteWrappedProcessed(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD len, mode;
|
|
|
|
const char* mytest = "abcd\nf\tg";
|
2003-09-25 22:29:40 +02:00
|
|
|
const int mylen = strlen(mytest);
|
2003-05-13 06:46:54 +02:00
|
|
|
int p;
|
2009-10-14 13:34:06 +02:00
|
|
|
WORD attr;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
|
|
|
ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode | (ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT)),
|
2004-01-26 21:23:25 +01:00
|
|
|
"setting wrap at EOL & processed output\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* write line, wrapping enabled, buffer doesn't exceed sb width */
|
|
|
|
c.X = sbSize.X - 9; c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
for (p = 0; p < 4; p++)
|
|
|
|
{
|
|
|
|
c.X = sbSize.X - 9 + p;
|
|
|
|
okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
c.X = sbSize.X - 9 + p;
|
2009-10-14 13:34:06 +02:00
|
|
|
ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
|
|
|
|
if (attr == TEST_ATTRIB)
|
|
|
|
win_skip("Win9x/WinMe changes attribs for '\\n' up to 'f'\n");
|
|
|
|
else
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-05-13 06:46:54 +02:00
|
|
|
c.X = 0; c.Y++;
|
|
|
|
okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
|
|
|
|
for (c.X = 1; c.X < 8; c.X++)
|
|
|
|
okCHAR(hCon, c, ' ', TEST_ATTRIB);
|
|
|
|
okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
|
|
|
|
c.X++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
|
|
|
okCURSOR(hCon, c);
|
|
|
|
|
|
|
|
/* write line, wrapping enabled, buffer does exceed sb width */
|
|
|
|
c.X = sbSize.X - 3; c.Y = 2;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
for (p = 0; p < 3; p++)
|
|
|
|
{
|
|
|
|
c.X = sbSize.X - 3 + p;
|
|
|
|
okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
|
|
|
|
}
|
|
|
|
c.X = 0; c.Y++;
|
|
|
|
okCHAR(hCon, c, mytest[3], TEST_ATTRIB);
|
|
|
|
c.X++;
|
2009-10-14 13:34:06 +02:00
|
|
|
ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
|
|
|
|
if (attr == TEST_ATTRIB)
|
|
|
|
win_skip("Win9x/WinMe changes attribs for '\\n' up to 'f'\n");
|
|
|
|
else
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
c.X = 0; c.Y++;
|
|
|
|
okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
|
|
|
|
for (c.X = 1; c.X < 8; c.X++)
|
|
|
|
okCHAR(hCon, c, ' ', TEST_ATTRIB);
|
|
|
|
okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
|
|
|
|
c.X++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
|
|
|
|
okCURSOR(hCon, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWrite(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
2013-10-01 17:02:00 +02:00
|
|
|
/* FIXME: should in fact ensure that the sb is at least 10 characters wide */
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleTextAttribute(hCon, TEST_ATTRIB), "Setting default text color\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
resetContent(hCon, sbSize, FALSE);
|
2009-01-19 06:52:11 +01:00
|
|
|
testEmptyWrite(hCon);
|
|
|
|
resetContent(hCon, sbSize, FALSE);
|
2009-01-19 06:51:14 +01:00
|
|
|
testWriteSimple(hCon);
|
2003-05-13 06:46:54 +02:00
|
|
|
resetContent(hCon, sbSize, FALSE);
|
|
|
|
testWriteNotWrappedNotProcessed(hCon, sbSize);
|
|
|
|
resetContent(hCon, sbSize, FALSE);
|
|
|
|
testWriteNotWrappedProcessed(hCon, sbSize);
|
|
|
|
resetContent(hCon, sbSize, FALSE);
|
|
|
|
testWriteWrappedNotProcessed(hCon, sbSize);
|
|
|
|
resetContent(hCon, sbSize, FALSE);
|
|
|
|
testWriteWrappedProcessed(hCon, sbSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testScroll(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
SMALL_RECT scroll, clip;
|
|
|
|
COORD dst, c, tc;
|
|
|
|
CHAR_INFO ci;
|
2008-05-02 12:05:02 +02:00
|
|
|
BOOL ret;
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
#define W 11
|
|
|
|
#define H 7
|
|
|
|
|
|
|
|
#define IN_SRECT(r,c) ((r).Left <= (c).X && (c).X <= (r).Right && (r).Top <= (c).Y && (c).Y <= (r).Bottom)
|
|
|
|
#define IN_SRECT2(r,d,c) ((d).X <= (c).X && (c).X <= (d).X + (r).Right - (r).Left && (d).Y <= (c).Y && (c).Y <= (d).Y + (r).Bottom - (r).Top)
|
|
|
|
|
2004-09-13 20:04:50 +02:00
|
|
|
/* no clipping, src & dst rect don't overlap */
|
|
|
|
resetContent(hCon, sbSize, TRUE);
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
scroll.Left = 0;
|
|
|
|
scroll.Right = W - 1;
|
|
|
|
scroll.Top = 0;
|
|
|
|
scroll.Bottom = H - 1;
|
|
|
|
dst.X = W + 3;
|
|
|
|
dst.Y = H + 3;
|
|
|
|
ci.Char.UnicodeChar = '#';
|
|
|
|
ci.Attributes = TEST_ATTRIB;
|
|
|
|
|
|
|
|
clip.Left = 0;
|
|
|
|
clip.Right = sbSize.X - 1;
|
|
|
|
clip.Top = 0;
|
|
|
|
clip.Bottom = sbSize.Y - 1;
|
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(ScrollConsoleScreenBufferA(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
|
|
|
|
{
|
|
|
|
for (c.X = 0; c.X < sbSize.X; c.X++)
|
|
|
|
{
|
|
|
|
if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
|
|
|
|
{
|
|
|
|
tc.X = c.X - dst.X;
|
|
|
|
tc.Y = c.Y - dst.Y;
|
|
|
|
okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
|
|
|
|
}
|
2003-09-25 22:29:40 +02:00
|
|
|
else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
|
2003-05-13 06:46:54 +02:00
|
|
|
okCHAR(hCon, c, '#', TEST_ATTRIB);
|
|
|
|
else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no clipping, src & dst rect do overlap */
|
|
|
|
resetContent(hCon, sbSize, TRUE);
|
|
|
|
|
|
|
|
scroll.Left = 0;
|
|
|
|
scroll.Right = W - 1;
|
|
|
|
scroll.Top = 0;
|
|
|
|
scroll.Bottom = H - 1;
|
|
|
|
dst.X = W /2;
|
|
|
|
dst.Y = H / 2;
|
|
|
|
ci.Char.UnicodeChar = '#';
|
|
|
|
ci.Attributes = TEST_ATTRIB;
|
|
|
|
|
|
|
|
clip.Left = 0;
|
|
|
|
clip.Right = sbSize.X - 1;
|
|
|
|
clip.Top = 0;
|
|
|
|
clip.Bottom = sbSize.Y - 1;
|
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
ok(ScrollConsoleScreenBufferA(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
|
|
|
|
{
|
|
|
|
for (c.X = 0; c.X < sbSize.X; c.X++)
|
|
|
|
{
|
|
|
|
if (dst.X <= c.X && c.X < dst.X + W && dst.Y <= c.Y && c.Y < dst.Y + H)
|
|
|
|
{
|
|
|
|
tc.X = c.X - dst.X;
|
|
|
|
tc.Y = c.Y - dst.Y;
|
|
|
|
okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
else if (c.X < W && c.Y < H) okCHAR(hCon, c, '#', TEST_ATTRIB);
|
|
|
|
else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clipping, src & dst rect don't overlap */
|
|
|
|
resetContent(hCon, sbSize, TRUE);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
scroll.Left = 0;
|
|
|
|
scroll.Right = W - 1;
|
|
|
|
scroll.Top = 0;
|
|
|
|
scroll.Bottom = H - 1;
|
|
|
|
dst.X = W + 3;
|
|
|
|
dst.Y = H + 3;
|
|
|
|
ci.Char.UnicodeChar = '#';
|
|
|
|
ci.Attributes = TEST_ATTRIB;
|
|
|
|
|
|
|
|
clip.Left = W / 2;
|
|
|
|
clip.Right = min(W + W / 2, sbSize.X - 1);
|
|
|
|
clip.Top = H / 2;
|
|
|
|
clip.Bottom = min(H + H / 2, sbSize.Y - 1);
|
|
|
|
|
2008-05-02 12:05:02 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-21 10:01:37 +02:00
|
|
|
ret = ScrollConsoleScreenBufferA(hCon, &scroll, &clip, dst, &ci);
|
2008-05-02 12:05:02 +02:00
|
|
|
if (ret)
|
2003-05-13 06:46:54 +02:00
|
|
|
{
|
2008-05-02 12:05:02 +02:00
|
|
|
for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
|
2003-05-13 06:46:54 +02:00
|
|
|
{
|
2008-05-02 12:05:02 +02:00
|
|
|
for (c.X = 0; c.X < sbSize.X; c.X++)
|
2003-05-13 06:46:54 +02:00
|
|
|
{
|
2008-05-02 12:05:02 +02:00
|
|
|
if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
|
|
|
|
{
|
|
|
|
tc.X = c.X - dst.X;
|
|
|
|
tc.Y = c.Y - dst.Y;
|
|
|
|
okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
|
|
|
|
okCHAR(hCon, c, '#', TEST_ATTRIB);
|
|
|
|
else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
|
2003-05-13 06:46:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-02 12:05:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Win9x will fail, Only accept ERROR_NOT_ENOUGH_MEMORY */
|
|
|
|
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected ERROR_NOT_ENOUGH_MEMORY, got %lu\n", GetLastError());
|
2008-05-02 12:05:02 +02:00
|
|
|
}
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
/* clipping, src & dst rect do overlap */
|
|
|
|
resetContent(hCon, sbSize, TRUE);
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
scroll.Left = 0;
|
|
|
|
scroll.Right = W - 1;
|
|
|
|
scroll.Top = 0;
|
|
|
|
scroll.Bottom = H - 1;
|
|
|
|
dst.X = W / 2 - 3;
|
|
|
|
dst.Y = H / 2 - 3;
|
|
|
|
ci.Char.UnicodeChar = '#';
|
|
|
|
ci.Attributes = TEST_ATTRIB;
|
|
|
|
|
|
|
|
clip.Left = W / 2;
|
|
|
|
clip.Right = min(W + W / 2, sbSize.X - 1);
|
|
|
|
clip.Top = H / 2;
|
|
|
|
clip.Bottom = min(H + H / 2, sbSize.Y - 1);
|
|
|
|
|
2020-07-23 17:32:23 +02:00
|
|
|
ret = ScrollConsoleScreenBufferA(hCon, &scroll, &clip, dst, &ci);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "ScrollConsoleScreenBufferA failed: %lu\n", GetLastError());
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
|
|
|
|
{
|
|
|
|
for (c.X = 0; c.X < sbSize.X; c.X++)
|
|
|
|
{
|
|
|
|
if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
|
|
|
|
{
|
|
|
|
tc.X = c.X - dst.X;
|
|
|
|
tc.Y = c.Y - dst.Y;
|
|
|
|
okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
|
|
|
|
}
|
2003-09-25 22:29:40 +02:00
|
|
|
else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
|
2003-05-13 06:46:54 +02:00
|
|
|
okCHAR(hCon, c, '#', TEST_ATTRIB);
|
|
|
|
else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 03:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mch_count;
|
|
|
|
/* we need the event as Wine console event generation isn't synchronous
|
|
|
|
* (ie GenerateConsoleCtrlEvent returns before all ctrl-handlers in all
|
|
|
|
* processes have been called).
|
|
|
|
*/
|
|
|
|
static HANDLE mch_event;
|
|
|
|
static BOOL WINAPI mch(DWORD event)
|
|
|
|
{
|
|
|
|
mch_count++;
|
|
|
|
SetEvent(mch_event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testCtrlHandler(void)
|
|
|
|
{
|
|
|
|
ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %lu\n", GetLastError());
|
2004-09-08 03:25:05 +02:00
|
|
|
ok(SetConsoleCtrlHandler(mch, TRUE), "Couldn't set handler\n");
|
2013-10-01 17:02:00 +02:00
|
|
|
/* wine requires the event for the test, as we cannot ensure, so far, that
|
|
|
|
* events are processed synchronously in GenerateConsoleCtrlEvent()
|
2004-09-08 03:25:05 +02:00
|
|
|
*/
|
|
|
|
mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
|
mch_count = 0;
|
|
|
|
ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
|
2007-01-06 19:32:56 +01:00
|
|
|
/* FIXME: it isn't synchronous on wine but it can still happen before we test */
|
|
|
|
if (0) ok(mch_count == 1, "Event isn't synchronous\n");
|
2004-09-08 03:25:05 +02:00
|
|
|
ok(WaitForSingleObject(mch_event, 3000) == WAIT_OBJECT_0, "event sending didn't work\n");
|
|
|
|
CloseHandle(mch_event);
|
2005-10-28 12:40:42 +02:00
|
|
|
|
|
|
|
/* Turning off ctrl-c handling doesn't work on win9x such way ... */
|
2004-09-08 03:25:05 +02:00
|
|
|
ok(SetConsoleCtrlHandler(NULL, TRUE), "Couldn't turn off ctrl-c handling\n");
|
|
|
|
mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
|
mch_count = 0;
|
2005-10-28 12:40:42 +02:00
|
|
|
if(!(GetVersion() & 0x80000000))
|
|
|
|
/* ... and next line leads to an unhandled exception on 9x. Avoid it on 9x. */
|
|
|
|
ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
|
2004-09-08 03:25:05 +02:00
|
|
|
ok(WaitForSingleObject(mch_event, 3000) == WAIT_TIMEOUT && mch_count == 0, "Event shouldn't have been sent\n");
|
|
|
|
CloseHandle(mch_event);
|
|
|
|
ok(SetConsoleCtrlHandler(mch, FALSE), "Couldn't remove handler\n");
|
|
|
|
ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %lu\n", GetLastError());
|
2004-09-08 03:25:05 +02:00
|
|
|
}
|
2003-05-13 06:46:54 +02:00
|
|
|
|
2007-05-09 18:55:08 +02:00
|
|
|
/*
|
|
|
|
* Test console screen buffer:
|
|
|
|
* 1) Try to set invalid handle.
|
|
|
|
* 2) Try to set non-console handles.
|
|
|
|
* 3) Use CONOUT$ file as active SB.
|
|
|
|
* 4) Test cursor.
|
|
|
|
* 5) Test output codepage to show it is not a property of SB.
|
|
|
|
* 6) Test switching to old SB if we close all handles to current SB - works
|
|
|
|
* in Windows, TODO in wine.
|
|
|
|
*
|
|
|
|
* What is not tested but should be:
|
|
|
|
* 1) ScreenBufferInfo
|
|
|
|
*/
|
|
|
|
static void testScreenBuffer(HANDLE hConOut)
|
|
|
|
{
|
|
|
|
HANDLE hConOutRW, hConOutRO, hConOutWT;
|
|
|
|
HANDLE hFileOutRW, hFileOutRO, hFileOutWT;
|
|
|
|
HANDLE hConOutNew;
|
|
|
|
char test_str1[] = "Test for SB1";
|
|
|
|
char test_str2[] = "Test for SB2";
|
|
|
|
char test_cp866[] = {0xe2, 0xa5, 0xe1, 0xe2, 0};
|
|
|
|
char test_cp1251[] = {0xf2, 0xe5, 0xf1, 0xf2, 0};
|
|
|
|
WCHAR test_unicode[] = {0x0442, 0x0435, 0x0441, 0x0442, 0};
|
|
|
|
WCHAR str_wbuf[20];
|
|
|
|
char str_buf[20];
|
2013-11-01 10:17:16 +01:00
|
|
|
DWORD len, error;
|
2007-05-09 18:55:08 +02:00
|
|
|
COORD c;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD oldcp;
|
|
|
|
|
2008-04-20 09:26:12 +02:00
|
|
|
if (!IsValidCodePage(866))
|
|
|
|
{
|
|
|
|
skip("Codepage 866 not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-09 18:55:08 +02:00
|
|
|
/* In the beginning set output codepage to 866 */
|
|
|
|
oldcp = GetConsoleOutputCP();
|
2008-05-02 13:28:10 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleOutputCP(866);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("SetConsoleOutputCP is not implemented\n");
|
2008-05-02 13:28:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(ret, "Cannot set output codepage to 866\n");
|
2007-05-09 18:55:08 +02:00
|
|
|
|
|
|
|
hConOutRW = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
|
|
|
ok(hConOutRW != INVALID_HANDLE_VALUE,
|
|
|
|
"Cannot create a new screen buffer for ReadWrite\n");
|
|
|
|
hConOutRO = CreateConsoleScreenBuffer(GENERIC_READ,
|
|
|
|
FILE_SHARE_READ, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
|
|
|
ok(hConOutRO != INVALID_HANDLE_VALUE,
|
|
|
|
"Cannot create a new screen buffer for ReadOnly\n");
|
|
|
|
hConOutWT = CreateConsoleScreenBuffer(GENERIC_WRITE,
|
|
|
|
FILE_SHARE_WRITE, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
|
|
|
ok(hConOutWT != INVALID_HANDLE_VALUE,
|
|
|
|
"Cannot create a new screen buffer for WriteOnly\n");
|
|
|
|
|
|
|
|
hFileOutRW = CreateFileA("NUL", GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(hFileOutRW != INVALID_HANDLE_VALUE, "Cannot open NUL for ReadWrite\n");
|
|
|
|
hFileOutRO = CreateFileA("NUL", GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(hFileOutRO != INVALID_HANDLE_VALUE, "Cannot open NUL for ReadOnly\n");
|
|
|
|
hFileOutWT = CreateFileA("NUL", GENERIC_WRITE, FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(hFileOutWT != INVALID_HANDLE_VALUE, "Cannot open NUL for WriteOnly\n");
|
|
|
|
|
|
|
|
/* Trying to set invalid handle */
|
|
|
|
SetLastError(0);
|
|
|
|
ok(!SetConsoleActiveScreenBuffer(INVALID_HANDLE_VALUE),
|
|
|
|
"Shouldn't succeed\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: expecting %u got %lu\n",
|
2007-05-09 18:55:08 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
|
|
|
/* Trying to set non-console handles */
|
|
|
|
SetLastError(0);
|
|
|
|
ok(!SetConsoleActiveScreenBuffer(hFileOutRW), "Shouldn't succeed\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: expecting %u got %lu\n",
|
2007-05-09 18:55:08 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0);
|
|
|
|
ok(!SetConsoleActiveScreenBuffer(hFileOutRO), "Shouldn't succeed\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: expecting %u got %lu\n",
|
2007-05-09 18:55:08 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0);
|
|
|
|
ok(!SetConsoleActiveScreenBuffer(hFileOutWT), "Shouldn't succeed\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: expecting %u got %lu\n",
|
2007-05-09 18:55:08 +02:00
|
|
|
ERROR_INVALID_HANDLE, GetLastError());
|
|
|
|
|
2012-03-06 14:51:57 +01:00
|
|
|
/* trying to write non-console handle */
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-01 10:17:16 +01:00
|
|
|
ret = WriteConsoleA(hFileOutRW, test_str1, lstrlenA(test_str1), &len, NULL);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "Shouldn't succeed\n");
|
|
|
|
ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: got %lu\n", error);
|
2012-03-06 14:51:57 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-01 10:17:16 +01:00
|
|
|
ret = WriteConsoleA(hFileOutRO, test_str1, lstrlenA(test_str1), &len, NULL);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "Shouldn't succeed\n");
|
|
|
|
ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: got %lu\n", error);
|
2012-03-06 14:51:57 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-01 10:17:16 +01:00
|
|
|
ret = WriteConsoleA(hFileOutWT, test_str1, lstrlenA(test_str1), &len, NULL);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "Shouldn't succeed\n");
|
2020-07-13 13:26:40 +02:00
|
|
|
ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetLastError: got %lu\n", error);
|
2012-03-06 14:51:57 +01:00
|
|
|
|
2007-05-09 18:55:08 +02:00
|
|
|
CloseHandle(hFileOutRW);
|
|
|
|
CloseHandle(hFileOutRO);
|
|
|
|
CloseHandle(hFileOutWT);
|
|
|
|
|
|
|
|
/* Trying to set SB handles with various access modes */
|
|
|
|
SetLastError(0);
|
|
|
|
ok(!SetConsoleActiveScreenBuffer(hConOutRO), "Shouldn't succeed\n");
|
2019-09-30 19:31:42 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_ACCESS_DENIED) /* win10 1809 */,
|
2022-03-02 09:03:21 +01:00
|
|
|
"unexpected last error %lu\n", GetLastError());
|
2007-05-09 18:55:08 +02:00
|
|
|
|
|
|
|
ok(SetConsoleActiveScreenBuffer(hConOutWT), "Couldn't set new WriteOnly SB\n");
|
|
|
|
|
|
|
|
ok(SetConsoleActiveScreenBuffer(hConOutRW), "Couldn't set new ReadWrite SB\n");
|
|
|
|
|
|
|
|
CloseHandle(hConOutWT);
|
|
|
|
CloseHandle(hConOutRO);
|
|
|
|
|
|
|
|
/* Now we have two ReadWrite SB, active must be hConOutRW */
|
|
|
|
/* Open current SB via CONOUT$ */
|
|
|
|
hConOutNew = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(hConOutNew != INVALID_HANDLE_VALUE, "CONOUT$ is not opened\n");
|
|
|
|
|
|
|
|
|
|
|
|
/* test cursor */
|
|
|
|
c.X = c.Y = 10;
|
|
|
|
SetConsoleCursorPosition(hConOut, c);
|
|
|
|
c.X = c.Y = 5;
|
|
|
|
SetConsoleCursorPosition(hConOutRW, c);
|
|
|
|
okCURSOR(hConOutNew, c);
|
|
|
|
c.X = c.Y = 10;
|
|
|
|
okCURSOR(hConOut, c);
|
|
|
|
|
|
|
|
|
|
|
|
c.X = c.Y = 0;
|
|
|
|
|
|
|
|
/* Write using hConOutNew... */
|
|
|
|
SetConsoleCursorPosition(hConOutNew, c);
|
|
|
|
ret = WriteConsoleA(hConOutNew, test_str2, lstrlenA(test_str2), &len, NULL);
|
|
|
|
ok (ret && len == lstrlenA(test_str2), "WriteConsoleA failed\n");
|
|
|
|
/* ... and read it back via hConOutRW */
|
|
|
|
ret = ReadConsoleOutputCharacterA(hConOutRW, str_buf, lstrlenA(test_str2), c, &len);
|
|
|
|
ok(ret && len == lstrlenA(test_str2), "ReadConsoleOutputCharacterA failed\n");
|
|
|
|
str_buf[lstrlenA(test_str2)] = 0;
|
|
|
|
ok(!lstrcmpA(str_buf, test_str2), "got '%s' expected '%s'\n", str_buf, test_str2);
|
|
|
|
|
|
|
|
|
|
|
|
/* Now test output codepage handling. Current is 866 as we set earlier. */
|
|
|
|
SetConsoleCursorPosition(hConOutRW, c);
|
|
|
|
ret = WriteConsoleA(hConOutRW, test_cp866, lstrlenA(test_cp866), &len, NULL);
|
|
|
|
ok(ret && len == lstrlenA(test_cp866), "WriteConsoleA failed\n");
|
|
|
|
ret = ReadConsoleOutputCharacterW(hConOutRW, str_wbuf, lstrlenA(test_cp866), c, &len);
|
|
|
|
ok(ret && len == lstrlenA(test_cp866), "ReadConsoleOutputCharacterW failed\n");
|
|
|
|
str_wbuf[lstrlenA(test_cp866)] = 0;
|
|
|
|
ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cp866 is OK, let's switch to cp1251.
|
|
|
|
* We expect that this codepage will be used in every SB - active and not.
|
|
|
|
*/
|
|
|
|
ok(SetConsoleOutputCP(1251), "Cannot set output cp to 1251\n");
|
|
|
|
SetConsoleCursorPosition(hConOutRW, c);
|
|
|
|
ret = WriteConsoleA(hConOutRW, test_cp1251, lstrlenA(test_cp1251), &len, NULL);
|
|
|
|
ok(ret && len == lstrlenA(test_cp1251), "WriteConsoleA failed\n");
|
|
|
|
ret = ReadConsoleOutputCharacterW(hConOutRW, str_wbuf, lstrlenA(test_cp1251), c, &len);
|
|
|
|
ok(ret && len == lstrlenA(test_cp1251), "ReadConsoleOutputCharacterW failed\n");
|
|
|
|
str_wbuf[lstrlenA(test_cp1251)] = 0;
|
|
|
|
ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
|
|
|
|
|
|
|
|
/* Check what has happened to hConOut. */
|
|
|
|
SetConsoleCursorPosition(hConOut, c);
|
|
|
|
ret = WriteConsoleA(hConOut, test_cp1251, lstrlenA(test_cp1251), &len, NULL);
|
|
|
|
ok(ret && len == lstrlenA(test_cp1251), "WriteConsoleA failed\n");
|
|
|
|
ret = ReadConsoleOutputCharacterW(hConOut, str_wbuf, lstrlenA(test_cp1251), c, &len);
|
|
|
|
ok(ret && len == lstrlenA(test_cp1251), "ReadConsoleOutputCharacterW failed\n");
|
|
|
|
str_wbuf[lstrlenA(test_cp1251)] = 0;
|
|
|
|
ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
|
|
|
|
|
|
|
|
/* Close all handles of current console SB */
|
|
|
|
CloseHandle(hConOutNew);
|
|
|
|
CloseHandle(hConOutRW);
|
|
|
|
|
|
|
|
/* Now active SB should be hConOut */
|
|
|
|
hConOutNew = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(hConOutNew != INVALID_HANDLE_VALUE, "CONOUT$ is not opened\n");
|
|
|
|
|
|
|
|
/* Write using hConOutNew... */
|
|
|
|
SetConsoleCursorPosition(hConOutNew, c);
|
|
|
|
ret = WriteConsoleA(hConOutNew, test_str1, lstrlenA(test_str1), &len, NULL);
|
|
|
|
ok (ret && len == lstrlenA(test_str1), "WriteConsoleA failed\n");
|
|
|
|
/* ... and read it back via hConOut */
|
|
|
|
ret = ReadConsoleOutputCharacterA(hConOut, str_buf, lstrlenA(test_str1), c, &len);
|
|
|
|
ok(ret && len == lstrlenA(test_str1), "ReadConsoleOutputCharacterA failed\n");
|
|
|
|
str_buf[lstrlenA(test_str1)] = 0;
|
|
|
|
todo_wine ok(!lstrcmpA(str_buf, test_str1), "got '%s' expected '%s'\n", str_buf, test_str1);
|
|
|
|
CloseHandle(hConOutNew);
|
|
|
|
|
|
|
|
/* This is not really needed under Windows */
|
|
|
|
SetConsoleActiveScreenBuffer(hConOut);
|
|
|
|
|
|
|
|
/* restore codepage */
|
|
|
|
SetConsoleOutputCP(oldcp);
|
|
|
|
}
|
|
|
|
|
2021-07-21 14:24:48 +02:00
|
|
|
static void test_new_screen_buffer_properties(HANDLE hConOut)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE hConOut2;
|
|
|
|
CONSOLE_FONT_INFOEX cfi, cfi2;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi, csbi2;
|
|
|
|
|
|
|
|
/* Font information */
|
|
|
|
cfi.cbSize = cfi2.cbSize = sizeof(CONSOLE_FONT_INFOEX);
|
|
|
|
|
|
|
|
ret = GetCurrentConsoleFontEx(hConOut, FALSE, &cfi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetCurrentConsoleFontEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
|
|
|
|
hConOut2 = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hConOut2 != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
|
|
|
|
ret = GetCurrentConsoleFontEx(hConOut2, FALSE, &cfi2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetCurrentConsoleFontEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
CloseHandle(hConOut2);
|
|
|
|
|
|
|
|
ok(cfi2.nFont == cfi.nFont, "Font index should match: "
|
2022-03-02 09:03:21 +01:00
|
|
|
"got %lu, expected %lu\n", cfi2.nFont, cfi.nFont);
|
2021-07-21 14:24:48 +02:00
|
|
|
ok(cfi2.dwFontSize.X == cfi.dwFontSize.X, "Font width should match: "
|
|
|
|
"got %d, expected %d\n", cfi2.dwFontSize.X, cfi.dwFontSize.X);
|
|
|
|
ok(cfi2.dwFontSize.Y == cfi.dwFontSize.Y, "Font height should match: "
|
|
|
|
"got %d, expected %d\n", cfi2.dwFontSize.Y, cfi.dwFontSize.Y);
|
|
|
|
ok(cfi2.FontFamily == cfi.FontFamily, "Font family should match: "
|
|
|
|
"got %u, expected %u\n", cfi2.FontFamily, cfi.FontFamily);
|
|
|
|
ok(cfi2.FontWeight == cfi.FontWeight, "Font weight should match: "
|
|
|
|
"got %u, expected %u\n", cfi2.FontWeight, cfi.FontWeight);
|
|
|
|
ok(!lstrcmpW(cfi2.FaceName, cfi.FaceName), "Font name should match: "
|
|
|
|
"got %s, expected %s\n", wine_dbgstr_w(cfi2.FaceName), wine_dbgstr_w(cfi.FaceName));
|
|
|
|
|
|
|
|
/* Display window size */
|
|
|
|
ret = GetConsoleScreenBufferInfo(hConOut, &csbi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
|
|
|
|
hConOut2 = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hConOut2 != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfo(hConOut2, &csbi2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:48 +02:00
|
|
|
CloseHandle(hConOut2);
|
|
|
|
|
|
|
|
ok(csbi2.srWindow.Left == csbi.srWindow.Left, "Left coordinate should match\n");
|
|
|
|
ok(csbi2.srWindow.Top == csbi.srWindow.Top, "Top coordinate should match\n");
|
|
|
|
ok(csbi2.srWindow.Right == csbi.srWindow.Right, "Right coordinate should match\n");
|
|
|
|
ok(csbi2.srWindow.Bottom == csbi.srWindow.Bottom, "Bottom coordinate should match\n");
|
|
|
|
}
|
|
|
|
|
2021-07-21 14:24:47 +02:00
|
|
|
static void test_new_screen_buffer_color_attributes(HANDLE hConOut)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFOEX csbi, csbi2;
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE hConOut2;
|
|
|
|
WORD orig_attr, orig_popup, attr;
|
|
|
|
|
|
|
|
csbi.cbSize = csbi2.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
|
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfoEx(hConOut, &csbi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
orig_attr = csbi.wAttributes;
|
|
|
|
orig_popup = csbi.wPopupAttributes;
|
|
|
|
|
|
|
|
hConOut2 = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hConOut2 != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfoEx(hConOut2, &csbi2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
CloseHandle(hConOut2);
|
|
|
|
|
2021-07-22 15:36:19 +02:00
|
|
|
ok(csbi2.wAttributes == orig_attr, "Character Attributes should have been copied: "
|
2021-07-21 14:24:47 +02:00
|
|
|
"got %#x, expected %#x\n", csbi2.wAttributes, orig_attr);
|
2021-07-26 15:02:34 +02:00
|
|
|
ok(csbi2.wPopupAttributes != orig_popup, "Popup Attributes should not match original value\n");
|
|
|
|
ok(csbi2.wPopupAttributes == orig_attr, "Popup Attributes should match Character Attributes\n");
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
/* Test different Character Attributes */
|
|
|
|
attr = FOREGROUND_BLUE|BACKGROUND_GREEN;
|
|
|
|
ret = SetConsoleTextAttribute(hConOut, attr);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleTextAttribute failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
hConOut2 = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hConOut2 != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
memset(&csbi2, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFOEX));
|
|
|
|
csbi2.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
|
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfoEx(hConOut2, &csbi2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
CloseHandle(hConOut2);
|
|
|
|
|
2021-07-22 15:36:19 +02:00
|
|
|
ok(csbi2.wAttributes == attr, "Character Attributes should have been copied: "
|
2021-07-21 14:24:47 +02:00
|
|
|
"got %#x, expected %#x\n", csbi2.wAttributes, attr);
|
2021-07-26 15:02:34 +02:00
|
|
|
ok(csbi2.wPopupAttributes != orig_popup, "Popup Attributes should not match original value\n");
|
|
|
|
ok(csbi2.wPopupAttributes == attr, "Popup Attributes should match Character Attributes\n");
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
ret = SetConsoleTextAttribute(hConOut, orig_attr);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleTextAttribute failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
/* Test inheritance of different Popup Attributes */
|
|
|
|
csbi.wPopupAttributes = attr;
|
|
|
|
ret = SetConsoleScreenBufferInfoEx(hConOut, &csbi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
hConOut2 = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hConOut2 != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
memset(&csbi2, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFOEX));
|
|
|
|
csbi2.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
|
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfoEx(hConOut2, &csbi2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
CloseHandle(hConOut2);
|
|
|
|
|
2021-07-22 15:36:19 +02:00
|
|
|
ok(csbi2.wAttributes == orig_attr, "Character Attributes should have been copied: "
|
2021-07-21 14:24:47 +02:00
|
|
|
"got %#x, expected %#x\n", csbi2.wAttributes, orig_attr);
|
2021-07-26 15:02:34 +02:00
|
|
|
ok(csbi2.wPopupAttributes != orig_popup, "Popup Attributes should not match original value\n");
|
|
|
|
ok(csbi2.wPopupAttributes == orig_attr, "Popup Attributes should match Character Attributes\n");
|
2021-07-21 14:24:47 +02:00
|
|
|
|
|
|
|
csbi.wPopupAttributes = orig_popup;
|
|
|
|
ret = SetConsoleScreenBufferInfoEx(hConOut, &csbi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleScreenBufferInfoEx failed: error %lu\n", GetLastError());
|
2021-07-21 14:24:47 +02:00
|
|
|
}
|
|
|
|
|
2016-08-16 20:35:27 +02:00
|
|
|
static void CALLBACK signaled_function(void *p, BOOLEAN timeout)
|
|
|
|
{
|
|
|
|
HANDLE event = p;
|
|
|
|
SetEvent(event);
|
|
|
|
ok(!timeout, "wait shouldn't have timed out\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWaitForConsoleInput(HANDLE input_handle)
|
|
|
|
{
|
|
|
|
HANDLE wait_handle;
|
|
|
|
HANDLE complete_event;
|
|
|
|
INPUT_RECORD record;
|
|
|
|
DWORD events_written;
|
|
|
|
DWORD wait_ret;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
complete_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
|
|
/* Test success case */
|
|
|
|
ret = RegisterWaitForSingleObject(&wait_handle, input_handle, signaled_function, complete_event, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(ret == TRUE, "Expected RegisterWaitForSingleObject to return TRUE, got %d\n", ret);
|
|
|
|
/* give worker thread a chance to start up */
|
|
|
|
Sleep(100);
|
|
|
|
record.EventType = KEY_EVENT;
|
|
|
|
record.Event.KeyEvent.bKeyDown = 1;
|
|
|
|
record.Event.KeyEvent.wRepeatCount = 1;
|
|
|
|
record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
|
|
|
|
record.Event.KeyEvent.wVirtualScanCode = VK_RETURN;
|
|
|
|
record.Event.KeyEvent.uChar.UnicodeChar = '\r';
|
|
|
|
record.Event.KeyEvent.dwControlKeyState = 0;
|
|
|
|
ret = WriteConsoleInputW(input_handle, &record, 1, &events_written);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
|
|
|
wait_ret = WaitForSingleObject(complete_event, INFINITE);
|
|
|
|
ok(wait_ret == WAIT_OBJECT_0, "Expected the handle to be signaled\n");
|
|
|
|
ret = UnregisterWait(wait_handle);
|
|
|
|
/* If the callback is still running, this fails with ERROR_IO_PENDING, but
|
|
|
|
that's ok and expected. */
|
|
|
|
ok(ret != 0 || GetLastError() == ERROR_IO_PENDING,
|
2022-03-02 09:03:21 +01:00
|
|
|
"UnregisterWait failed with error %ld\n", GetLastError());
|
2016-08-16 20:35:27 +02:00
|
|
|
|
|
|
|
/* Test timeout case */
|
|
|
|
FlushConsoleInputBuffer(input_handle);
|
|
|
|
ret = RegisterWaitForSingleObject(&wait_handle, input_handle, signaled_function, complete_event, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
wait_ret = WaitForSingleObject(complete_event, 100);
|
|
|
|
ok(wait_ret == WAIT_TIMEOUT, "Expected the wait to time out\n");
|
|
|
|
ret = UnregisterWait(wait_handle);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "UnregisterWait failed with error %ld\n", GetLastError());
|
2016-08-16 20:35:27 +02:00
|
|
|
|
|
|
|
/* Clean up */
|
2016-09-10 17:49:53 +02:00
|
|
|
CloseHandle(complete_event);
|
2016-08-16 20:35:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 16:31:34 +01:00
|
|
|
static void test_wait(HANDLE input, HANDLE orig_output)
|
|
|
|
{
|
2020-11-12 19:56:30 +01:00
|
|
|
HANDLE output, unbound_output, unbound_input;
|
2020-11-10 16:31:34 +01:00
|
|
|
LARGE_INTEGER zero;
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD res, count;
|
|
|
|
NTSTATUS status;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (skip_nt) return;
|
|
|
|
|
|
|
|
memset(&ir, 0, sizeof(ir));
|
|
|
|
ir.EventType = MOUSE_EVENT;
|
|
|
|
ir.Event.MouseEvent.dwEventFlags = MOUSE_MOVED;
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
|
|
|
|
output = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(output != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: %lu\n", GetLastError());
|
2020-11-10 16:31:34 +01:00
|
|
|
|
|
|
|
ret = SetConsoleActiveScreenBuffer(output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleActiveScreenBuffer failed: %lu\n", GetLastError());
|
2020-11-10 16:31:34 +01:00
|
|
|
FlushConsoleInputBuffer(input);
|
|
|
|
|
2020-11-12 19:56:30 +01:00
|
|
|
unbound_output = create_unbound_handle(TRUE, TRUE);
|
|
|
|
unbound_input = create_unbound_handle(FALSE, TRUE);
|
|
|
|
|
2020-11-10 16:31:34 +01:00
|
|
|
res = WaitForSingleObject(input, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
res = WaitForSingleObject(output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
res = WaitForSingleObject(orig_output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %lx\n", res);
|
2020-11-12 19:56:30 +01:00
|
|
|
res = WaitForSingleObject(unbound_output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %lx\n", res);
|
2020-11-12 19:56:30 +01:00
|
|
|
res = WaitForSingleObject(unbound_input, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
status = NtWaitForSingleObject(input, FALSE, &zero);
|
|
|
|
ok(status == STATUS_TIMEOUT || broken(status == STATUS_ACCESS_DENIED /* win2k8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"NtWaitForSingleObject returned %lx\n", status);
|
2020-11-10 16:31:34 +01:00
|
|
|
status = NtWaitForSingleObject(output, FALSE, &zero);
|
|
|
|
ok(status == STATUS_TIMEOUT || broken(status == STATUS_ACCESS_DENIED /* win2k8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"NtWaitForSingleObject returned %lx\n", status);
|
2020-11-10 16:31:34 +01:00
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input, &ir, 1, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleInputW failed: %lu\n", GetLastError());
|
2020-11-10 16:31:34 +01:00
|
|
|
|
|
|
|
res = WaitForSingleObject(input, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
res = WaitForSingleObject(output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
res = WaitForSingleObject(orig_output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res, "WaitForSingleObject returned %lx\n", res);
|
2020-11-12 19:56:30 +01:00
|
|
|
res = WaitForSingleObject(unbound_output, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res, "WaitForSingleObject returned %lx\n", res);
|
2020-11-12 19:56:30 +01:00
|
|
|
res = WaitForSingleObject(unbound_input, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res, "WaitForSingleObject returned %lx\n", res);
|
2020-11-10 16:31:34 +01:00
|
|
|
status = NtWaitForSingleObject(input, FALSE, &zero);
|
|
|
|
ok(!status || broken(status == STATUS_ACCESS_DENIED /* win2k8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"NtWaitForSingleObject returned %lx\n", status);
|
2020-11-10 16:31:34 +01:00
|
|
|
status = NtWaitForSingleObject(output, FALSE, &zero);
|
|
|
|
ok(!status || broken(status == STATUS_ACCESS_DENIED /* win2k8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"NtWaitForSingleObject returned %lx\n", status);
|
2020-11-10 16:31:34 +01:00
|
|
|
|
|
|
|
ret = SetConsoleActiveScreenBuffer(orig_output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleActiveScreenBuffer failed: %lu\n", GetLastError());
|
2020-11-10 16:31:34 +01:00
|
|
|
|
2020-11-12 19:56:30 +01:00
|
|
|
CloseHandle(unbound_input);
|
|
|
|
CloseHandle(unbound_output);
|
2020-11-10 16:31:34 +01:00
|
|
|
CloseHandle(output);
|
|
|
|
}
|
|
|
|
|
2007-12-02 22:12:19 +01:00
|
|
|
static void test_GetSetConsoleInputExeName(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD error;
|
|
|
|
char buffer[MAX_PATH], module[MAX_PATH], *p;
|
|
|
|
static char input_exe[MAX_PATH] = "winetest.exe";
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-05 11:40:05 +01:00
|
|
|
ret = pGetConsoleInputExeNameA(0, NULL);
|
2007-12-02 22:12:19 +01:00
|
|
|
error = GetLastError();
|
|
|
|
ok(ret, "GetConsoleInputExeNameA failed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == ERROR_BUFFER_OVERFLOW, "got %lu expected ERROR_BUFFER_OVERFLOW\n", error);
|
2007-12-02 22:12:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-05 11:40:05 +01:00
|
|
|
ret = pGetConsoleInputExeNameA(0, buffer);
|
2007-12-02 22:12:19 +01:00
|
|
|
error = GetLastError();
|
|
|
|
ok(ret, "GetConsoleInputExeNameA failed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == ERROR_BUFFER_OVERFLOW, "got %lu expected ERROR_BUFFER_OVERFLOW\n", error);
|
2007-12-02 22:12:19 +01:00
|
|
|
|
2013-10-21 10:01:37 +02:00
|
|
|
GetModuleFileNameA(GetModuleHandleA(NULL), module, sizeof(module));
|
2007-12-02 22:12:19 +01:00
|
|
|
p = strrchr(module, '\\') + 1;
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = pGetConsoleInputExeNameA(ARRAY_SIZE(buffer), buffer);
|
2007-12-02 22:12:19 +01:00
|
|
|
ok(ret, "GetConsoleInputExeNameA failed\n");
|
|
|
|
todo_wine ok(!lstrcmpA(buffer, p), "got %s expected %s\n", buffer, p);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-05 11:40:05 +01:00
|
|
|
ret = pSetConsoleInputExeNameA(NULL);
|
2007-12-02 22:12:19 +01:00
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "SetConsoleInputExeNameA failed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == ERROR_INVALID_PARAMETER, "got %lu expected ERROR_INVALID_PARAMETER\n", error);
|
2007-12-02 22:12:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-05 11:40:05 +01:00
|
|
|
ret = pSetConsoleInputExeNameA("");
|
2007-12-02 22:12:19 +01:00
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "SetConsoleInputExeNameA failed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == ERROR_INVALID_PARAMETER, "got %lu expected ERROR_INVALID_PARAMETER\n", error);
|
2007-12-02 22:12:19 +01:00
|
|
|
|
2007-12-05 11:40:05 +01:00
|
|
|
ret = pSetConsoleInputExeNameA(input_exe);
|
2007-12-02 22:12:19 +01:00
|
|
|
ok(ret, "SetConsoleInputExeNameA failed\n");
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = pGetConsoleInputExeNameA(ARRAY_SIZE(buffer), buffer);
|
2007-12-02 22:12:19 +01:00
|
|
|
ok(ret, "GetConsoleInputExeNameA failed\n");
|
|
|
|
ok(!lstrcmpA(buffer, input_exe), "got %s expected %s\n", buffer, input_exe);
|
|
|
|
}
|
|
|
|
|
2010-01-05 09:32:36 +01:00
|
|
|
static void test_GetConsoleProcessList(void)
|
|
|
|
{
|
|
|
|
DWORD ret, *list = NULL;
|
|
|
|
|
|
|
|
if (!pGetConsoleProcessList)
|
|
|
|
{
|
|
|
|
win_skip("GetConsoleProcessList is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleProcessList(NULL, 0);
|
|
|
|
ok(ret == 0, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %ld\n",
|
2010-01-05 09:32:36 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleProcessList(NULL, 1);
|
|
|
|
ok(ret == 0, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %ld\n",
|
2010-01-05 09:32:36 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
/* We should only have 1 process but only for these specific unit tests as
|
2022-02-12 12:56:02 +01:00
|
|
|
* we created our own console. An AttachConsole(ATTACH_PARENT_PROCESS)
|
|
|
|
* gives us two processes - see test_AttachConsole.
|
2010-01-05 09:32:36 +01:00
|
|
|
*/
|
|
|
|
list = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleProcessList(list, 0);
|
|
|
|
ok(ret == 0, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %ld\n",
|
2010-01-05 09:32:36 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleProcessList(list, 1);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret == 1, "Expected 1, got %ld\n", ret);
|
2010-01-05 09:32:36 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, list);
|
|
|
|
|
|
|
|
list = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(DWORD));
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleProcessList(list, ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret == 1, "Expected 1, got %ld\n", ret);
|
2010-01-05 09:32:36 +01:00
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
{
|
|
|
|
DWORD pid = GetCurrentProcessId();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(list[0] == pid, "Expected %ld, got %ld\n", pid, list[0]);
|
2010-01-05 09:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, list);
|
|
|
|
}
|
|
|
|
|
2011-05-10 22:02:26 +02:00
|
|
|
static void test_OpenCON(void)
|
|
|
|
{
|
|
|
|
static const WCHAR conW[] = {'C','O','N',0};
|
|
|
|
static const DWORD accesses[] = {CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
|
|
|
|
OPEN_ALWAYS, TRUNCATE_EXISTING};
|
|
|
|
unsigned i;
|
|
|
|
HANDLE h;
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(accesses); i++)
|
2011-05-10 22:02:26 +02:00
|
|
|
{
|
|
|
|
h = CreateFileW(conW, GENERIC_WRITE, 0, NULL, accesses[i], 0, NULL);
|
2013-12-21 20:36:35 +01:00
|
|
|
ok(h != INVALID_HANDLE_VALUE || broken(accesses[i] == TRUNCATE_EXISTING /* Win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected to open the CON device on write (%lx)\n", accesses[i]);
|
2011-05-10 22:02:26 +02:00
|
|
|
CloseHandle(h);
|
|
|
|
|
|
|
|
h = CreateFileW(conW, GENERIC_READ, 0, NULL, accesses[i], 0, NULL);
|
|
|
|
/* Windows versions differ here:
|
|
|
|
* MSDN states in CreateFile that TRUNCATE_EXISTING requires GENERIC_WRITE
|
2012-05-15 10:15:32 +02:00
|
|
|
* NT, XP, Vista comply, but Win7 doesn't and allows opening CON with TRUNCATE_EXISTING
|
2011-05-10 22:02:26 +02:00
|
|
|
* So don't test when disposition is TRUNCATE_EXISTING
|
|
|
|
*/
|
2013-12-21 20:36:35 +01:00
|
|
|
ok(h != INVALID_HANDLE_VALUE || broken(accesses[i] == TRUNCATE_EXISTING /* Win7+ */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected to open the CON device on read (%lx)\n", accesses[i]);
|
2011-05-10 22:02:26 +02:00
|
|
|
CloseHandle(h);
|
|
|
|
h = CreateFileW(conW, GENERIC_READ|GENERIC_WRITE, 0, NULL, accesses[i], 0, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(h == INVALID_HANDLE_VALUE, "Expected not to open the CON device on read-write (%lx)\n", accesses[i]);
|
2013-12-21 20:36:35 +01:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Unexpected error %lx\n", GetLastError());
|
2011-05-10 22:02:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-01 02:53:59 +02:00
|
|
|
static void test_OpenConsoleW(void)
|
|
|
|
{
|
|
|
|
static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
|
|
|
|
static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
|
|
|
|
static const WCHAR emptyW[] = {0};
|
|
|
|
static const WCHAR invalidW[] = {'I','N','V','A','L','I','D',0};
|
2013-11-01 10:17:16 +01:00
|
|
|
DWORD gle;
|
2010-04-01 02:53:59 +02:00
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
LPCWSTR name;
|
|
|
|
DWORD access;
|
|
|
|
BOOL inherit;
|
|
|
|
DWORD creation;
|
2013-11-01 10:17:16 +01:00
|
|
|
DWORD gle, gle2;
|
2010-04-01 02:53:59 +02:00
|
|
|
} invalid_table[] = {
|
2013-11-01 10:17:16 +01:00
|
|
|
{NULL, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
2013-12-21 20:33:47 +01:00
|
|
|
{NULL, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{NULL, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{NULL, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
2013-11-01 10:17:16 +01:00
|
|
|
{NULL, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{NULL, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{NULL, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{NULL, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
2013-12-21 20:33:47 +01:00
|
|
|
{emptyW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
2013-11-01 10:17:16 +01:00
|
|
|
{emptyW, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
|
|
|
|
{invalidW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
2013-12-21 20:33:47 +01:00
|
|
|
{invalidW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
|
|
|
{invalidW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
|
|
|
{invalidW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
2013-11-01 10:17:16 +01:00
|
|
|
{invalidW, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
|
|
|
{invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
|
|
|
{invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
|
|
|
{invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
|
2013-12-21 20:33:47 +01:00
|
|
|
{coninW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
|
|
|
{coninW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_ACCESS_DENIED},
|
|
|
|
{coninW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
|
|
|
{conoutW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
|
|
|
{conoutW, 0xceadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_ACCESS_DENIED},
|
|
|
|
{conoutW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
|
|
|
|
};
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
LPCWSTR name;
|
|
|
|
DWORD access;
|
|
|
|
BOOL inherit;
|
|
|
|
DWORD creation;
|
|
|
|
} valid_table[] = {
|
|
|
|
{coninW, 0, FALSE, 0 },
|
|
|
|
{coninW, 0, TRUE, 0 },
|
|
|
|
{coninW, GENERIC_EXECUTE, TRUE, 0 },
|
|
|
|
{coninW, GENERIC_ALL, TRUE, 0 },
|
|
|
|
{coninW, 0, FALSE, OPEN_ALWAYS },
|
|
|
|
{coninW, GENERIC_READ | GENERIC_WRITE, FALSE, 0 },
|
|
|
|
{coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW },
|
|
|
|
{coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS },
|
|
|
|
{coninW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS },
|
|
|
|
{coninW, GENERIC_READ | GENERIC_WRITE, FALSE, TRUNCATE_EXISTING},
|
|
|
|
{conoutW, 0, FALSE, 0 },
|
|
|
|
{conoutW, 0, FALSE, OPEN_ALWAYS },
|
|
|
|
{conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, 0 },
|
|
|
|
{conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, },
|
|
|
|
{conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS },
|
|
|
|
{conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS },
|
|
|
|
{conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, TRUNCATE_EXISTING},
|
2010-04-01 02:53:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int index;
|
|
|
|
HANDLE ret;
|
|
|
|
|
|
|
|
if (!pOpenConsoleW)
|
|
|
|
{
|
|
|
|
win_skip("OpenConsoleW is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (index = 0; index < ARRAY_SIZE(invalid_table); index++)
|
2010-04-01 02:53:59 +02:00
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pOpenConsoleW(invalid_table[index].name, invalid_table[index].access,
|
|
|
|
invalid_table[index].inherit, invalid_table[index].creation);
|
2013-11-01 10:17:16 +01:00
|
|
|
gle = GetLastError();
|
2010-04-01 02:53:59 +02:00
|
|
|
ok(ret == INVALID_HANDLE_VALUE,
|
|
|
|
"Expected OpenConsoleW to return INVALID_HANDLE_VALUE for index %d, got %p\n",
|
|
|
|
index, ret);
|
2013-11-01 10:17:16 +01:00
|
|
|
ok(gle == invalid_table[index].gle || (gle != 0 && gle == invalid_table[index].gle2),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected GetLastError() to return %lu/%lu for index %d, got %lu\n",
|
2013-11-01 10:17:16 +01:00
|
|
|
invalid_table[index].gle, invalid_table[index].gle2, index, gle);
|
2010-04-01 02:53:59 +02:00
|
|
|
}
|
2013-12-21 20:33:47 +01:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (index = 0; index < ARRAY_SIZE(valid_table); index++)
|
2013-12-21 20:33:47 +01:00
|
|
|
{
|
|
|
|
ret = pOpenConsoleW(valid_table[index].name, valid_table[index].access,
|
|
|
|
valid_table[index].inherit, valid_table[index].creation);
|
|
|
|
todo_wine
|
|
|
|
ok(ret != INVALID_HANDLE_VALUE || broken(ret == INVALID_HANDLE_VALUE /* until Win7 */),
|
|
|
|
"Expected OpenConsoleW to succeed for index %d, got %p\n", index, ret);
|
|
|
|
if (ret != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(ret);
|
|
|
|
}
|
2010-04-01 02:54:07 +02:00
|
|
|
|
|
|
|
ret = pOpenConsoleW(coninW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING);
|
2014-01-08 01:53:52 +01:00
|
|
|
ok(ret != INVALID_HANDLE_VALUE, "Expected OpenConsoleW to return a valid handle\n");
|
2010-04-01 02:54:07 +02:00
|
|
|
if (ret != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(ret);
|
|
|
|
|
|
|
|
ret = pOpenConsoleW(conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING);
|
2014-01-08 01:53:52 +01:00
|
|
|
ok(ret != INVALID_HANDLE_VALUE, "Expected OpenConsoleW to return a valid handle\n");
|
2010-04-01 02:54:07 +02:00
|
|
|
if (ret != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(ret);
|
2010-04-01 02:53:59 +02:00
|
|
|
}
|
|
|
|
|
2012-02-07 21:40:46 +01:00
|
|
|
static void test_CreateFileW(void)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
2020-06-25 22:26:30 +02:00
|
|
|
BOOL input;
|
2012-02-07 21:40:46 +01:00
|
|
|
DWORD access;
|
|
|
|
BOOL inherit;
|
|
|
|
DWORD creation;
|
|
|
|
DWORD gle;
|
|
|
|
BOOL is_broken;
|
|
|
|
} cf_table[] = {
|
2020-06-25 22:26:30 +02:00
|
|
|
{TRUE, 0, FALSE, OPEN_ALWAYS, 0, FALSE},
|
|
|
|
{TRUE, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
|
|
|
|
{TRUE, 0, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
|
|
|
|
{TRUE, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, 0, FALSE},
|
|
|
|
{TRUE, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS, 0, FALSE},
|
|
|
|
{TRUE, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, 0, FALSE},
|
|
|
|
{FALSE, 0, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
|
|
|
|
{FALSE, 0, FALSE, OPEN_ALWAYS, 0, FALSE},
|
|
|
|
{FALSE, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
|
|
|
|
{FALSE, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, 0, FALSE},
|
|
|
|
{FALSE, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS, 0, FALSE},
|
|
|
|
{FALSE, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, 0, FALSE},
|
2013-11-01 10:36:35 +01:00
|
|
|
/* TRUNCATE_EXISTING is forbidden starting with Windows 8 */
|
2012-02-07 21:40:46 +01:00
|
|
|
};
|
|
|
|
|
2020-06-25 22:26:30 +02:00
|
|
|
static const UINT nt_disposition[5] =
|
|
|
|
{
|
|
|
|
FILE_CREATE, /* CREATE_NEW */
|
|
|
|
FILE_OVERWRITE_IF, /* CREATE_ALWAYS */
|
|
|
|
FILE_OPEN, /* OPEN_EXISTING */
|
|
|
|
FILE_OPEN_IF, /* OPEN_ALWAYS */
|
|
|
|
FILE_OVERWRITE /* TRUNCATE_EXISTING */
|
|
|
|
};
|
|
|
|
|
2012-02-07 21:40:46 +01:00
|
|
|
int index;
|
|
|
|
HANDLE ret;
|
|
|
|
SECURITY_ATTRIBUTES sa;
|
2020-06-25 22:26:30 +02:00
|
|
|
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
|
|
|
|
UNICODE_STRING string;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2012-02-07 21:40:46 +01:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (index = 0; index < ARRAY_SIZE(cf_table); index++)
|
2012-02-07 21:40:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = cf_table[index].inherit;
|
|
|
|
|
2020-06-25 22:26:30 +02:00
|
|
|
ret = CreateFileW(cf_table[index].input ? L"CONIN$" : L"CONOUT$", cf_table[index].access,
|
2012-02-07 21:40:46 +01:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, &sa,
|
|
|
|
cf_table[index].creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (ret == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(cf_table[index].gle,
|
|
|
|
"Expected CreateFileW not to return INVALID_HANDLE_VALUE for index %d\n", index);
|
|
|
|
ok(GetLastError() == cf_table[index].gle,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected GetLastError() to return %lu for index %d, got %lu\n",
|
2012-02-07 21:40:46 +01:00
|
|
|
cf_table[index].gle, index, GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(!cf_table[index].gle || broken(cf_table[index].is_broken) /* Win7 */,
|
|
|
|
"Expected CreateFileW to succeed for index %d\n", index);
|
|
|
|
CloseHandle(ret);
|
|
|
|
}
|
2020-06-25 22:26:30 +02:00
|
|
|
|
|
|
|
if (skip_nt) continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = cf_table[index].inherit;
|
|
|
|
|
|
|
|
ret = CreateFileW(cf_table[index].input ? L"\\??\\CONIN$" : L"\\??\\CONOUT$", cf_table[index].access,
|
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, &sa,
|
|
|
|
cf_table[index].creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (cf_table[index].gle)
|
|
|
|
ok(ret == INVALID_HANDLE_VALUE && GetLastError() == cf_table[index].gle,
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileW to returned %p %lu for index %d\n", ret, GetLastError(), index);
|
2020-06-25 22:26:30 +02:00
|
|
|
else
|
|
|
|
ok(ret != INVALID_HANDLE_VALUE && (!cf_table[index].gle || broken(cf_table[index].is_broken) /* Win7 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileW to returned %p %lu for index %d\n", ret, GetLastError(), index);
|
2020-06-25 22:26:30 +02:00
|
|
|
if (ret != INVALID_HANDLE_VALUE) CloseHandle(ret);
|
|
|
|
|
|
|
|
if (cf_table[index].gle) continue;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&string, cf_table[index].input
|
|
|
|
? L"\\Device\\ConDrv\\CurrentIn" : L"\\Device\\ConDrv\\CurrentOut");
|
|
|
|
attr.ObjectName = &string;
|
|
|
|
status = NtCreateFile(&ret, cf_table[index].access | SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attr, &iosb, NULL,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, 0, nt_disposition[cf_table[index].creation - CREATE_NEW],
|
|
|
|
FILE_NON_DIRECTORY_FILE, NULL, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!status, "NtCreateFile failed %lx for %u\n", status, index);
|
2020-06-25 22:26:30 +02:00
|
|
|
CloseHandle(ret);
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&string, cf_table[index].input ? L"\\??\\CONIN$" : L"\\??\\CONOUT$");
|
|
|
|
attr.ObjectName = &string;
|
|
|
|
status = NtCreateFile(&ret, cf_table[index].access | SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attr, &iosb, NULL,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, 0, nt_disposition[cf_table[index].creation - CREATE_NEW],
|
|
|
|
FILE_NON_DIRECTORY_FILE, NULL, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!status, "NtCreateFile failed %lx for %u\n", status, index);
|
2020-06-25 22:26:30 +02:00
|
|
|
CloseHandle(ret);
|
2012-02-07 21:40:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:57:42 +02:00
|
|
|
static void test_VerifyConsoleIoHandle( HANDLE handle )
|
2010-09-22 19:54:36 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD error;
|
|
|
|
|
|
|
|
if (!pVerifyConsoleIoHandle)
|
|
|
|
{
|
|
|
|
win_skip("VerifyConsoleIoHandle is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invalid handle */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee0);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:36 +02:00
|
|
|
|
|
|
|
/* invalid handle + 1 */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee1);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:36 +02:00
|
|
|
|
|
|
|
/* invalid handle + 2 */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee2);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:36 +02:00
|
|
|
|
|
|
|
/* invalid handle + 3 */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee3);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:36 +02:00
|
|
|
|
|
|
|
/* valid handle */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pVerifyConsoleIoHandle(handle);
|
|
|
|
error = GetLastError();
|
2016-11-22 13:00:10 +01:00
|
|
|
ok(ret ||
|
|
|
|
broken(!ret), /* Windows 8 and 10 */
|
|
|
|
"expected VerifyConsoleIoHandle to succeed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-22 19:54:38 +02:00
|
|
|
static void test_GetSetStdHandle(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
DWORD error;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* get invalid std handle */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = GetStdHandle(42);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
|
2022-03-02 09:03:21 +01:00
|
|
|
"wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:38 +02:00
|
|
|
ok(handle == INVALID_HANDLE_VALUE, "expected INVALID_HANDLE_VALUE\n");
|
|
|
|
|
|
|
|
/* get valid */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
error = GetLastError();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:38 +02:00
|
|
|
|
|
|
|
/* set invalid std handle */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetStdHandle(42, handle);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret, "expected SetStdHandle to fail\n");
|
|
|
|
ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
|
2022-03-02 09:03:21 +01:00
|
|
|
"wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:38 +02:00
|
|
|
|
|
|
|
/* set valid (restore old value) */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetStdHandle(STD_INPUT_HANDLE, handle);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(ret, "expected SetStdHandle to succeed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(error == 0xdeadbeef, "wrong GetLastError() %ld\n", error);
|
2010-09-22 19:54:38 +02:00
|
|
|
}
|
2010-09-22 19:54:36 +02:00
|
|
|
|
2020-11-11 20:06:39 +01:00
|
|
|
static void test_DuplicateConsoleHandle(void)
|
|
|
|
{
|
|
|
|
HANDLE handle, event;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (skip_nt) return;
|
|
|
|
|
|
|
|
event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
/* duplicate an event handle with DuplicateConsoleHandle */
|
|
|
|
handle = DuplicateConsoleHandle(event, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(handle != NULL, "DuplicateConsoleHandle failed: %lu\n", GetLastError());
|
2020-11-11 20:06:39 +01:00
|
|
|
|
|
|
|
ret = SetEvent(handle);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetEvent failed: %lu\n", GetLastError());
|
2020-11-11 20:06:39 +01:00
|
|
|
|
|
|
|
ret = CloseConsoleHandle(handle);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "CloseConsoleHandle failed: %lu\n", GetLastError());
|
2020-11-11 20:06:39 +01:00
|
|
|
ret = CloseConsoleHandle(event);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "CloseConsoleHandle failed: %lu\n", GetLastError());
|
2020-11-11 20:06:39 +01:00
|
|
|
|
|
|
|
handle = DuplicateConsoleHandle((HANDLE)0xdeadbeef, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(handle == INVALID_HANDLE_VALUE, "DuplicateConsoleHandle failed: %lu\n", GetLastError());
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "last error = %lu\n", GetLastError());
|
2020-11-11 20:06:39 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:27:40 +01:00
|
|
|
static void test_GetNumberOfConsoleInputEvents(HANDLE input_handle)
|
|
|
|
{
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
LPDWORD nrofevents;
|
|
|
|
DWORD last_error;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
|
|
|
{NULL, NULL, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &count, ERROR_INVALID_HANDLE},
|
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:27:40 +01:00
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].nrofevents) count = 0xdeadbeef;
|
|
|
|
ret = GetNumberOfConsoleInputEvents(invalid_table[i].handle,
|
|
|
|
invalid_table[i].nrofevents);
|
|
|
|
ok(!ret, "[%d] Expected GetNumberOfConsoleInputEvents to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].nrofevents)
|
|
|
|
{
|
|
|
|
ok(count == 0xdeadbeef,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected output count to be unmodified, got %lu\n", i, count);
|
2011-01-04 04:27:40 +01:00
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:27:40 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test crashes on Windows 7. */
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, NULL);
|
|
|
|
ok(!ret, "Expected GetNumberOfConsoleInputEvents to return FALSE, got %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_ACCESS,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected last error to be ERROR_INVALID_ACCESS, got %lu\n",
|
2011-01-04 04:27:40 +01:00
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
|
|
|
ok(count != 0xdeadbeef, "Expected output count to initialized\n");
|
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:21 +01:00
|
|
|
static void test_WriteConsoleInputA(HANDLE input_handle)
|
|
|
|
{
|
2011-01-11 12:11:40 +01:00
|
|
|
INPUT_RECORD event;
|
|
|
|
INPUT_RECORD event_list[5];
|
2011-01-04 04:25:21 +01:00
|
|
|
MOUSE_EVENT_RECORD mouse_event = { {0, 0}, 0, 0, MOUSE_MOVED };
|
2011-01-11 12:11:40 +01:00
|
|
|
KEY_EVENT_RECORD key_event;
|
2014-01-04 18:35:14 +01:00
|
|
|
DWORD count, console_mode, gle;
|
2011-01-04 04:25:21 +01:00
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
const INPUT_RECORD *buffer;
|
|
|
|
DWORD count;
|
|
|
|
LPDWORD written;
|
2014-01-04 18:35:14 +01:00
|
|
|
DWORD gle, gle2;
|
2012-11-27 02:52:46 +01:00
|
|
|
int win_crash;
|
2011-01-04 04:25:21 +01:00
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2016-11-22 13:00:09 +01:00
|
|
|
{NULL, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, NULL, 0, &count,ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, NULL, 1, &count, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
|
|
|
|
{NULL, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, &event, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, &event, 1, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, &count, ERROR_INVALID_HANDLE, ERROR_INVALID_ACCESS},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 1, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{input_handle, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, NULL, 1, &count, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
|
|
|
|
{input_handle, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
2011-01-04 04:25:21 +01:00
|
|
|
};
|
|
|
|
|
2011-01-11 12:11:40 +01:00
|
|
|
/* Suppress external sources of input events for the duration of the test. */
|
|
|
|
ret = GetConsoleMode(input_handle, &console_mode);
|
|
|
|
ok(ret == TRUE, "Expected GetConsoleMode to return TRUE, got %d\n", ret);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
skip("GetConsoleMode failed with last error %lu\n", GetLastError());
|
2011-01-11 12:11:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SetConsoleMode(input_handle, console_mode & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
|
|
|
|
ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
skip("SetConsoleMode failed with last error %lu\n", GetLastError());
|
2011-01-11 12:11:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard any events queued before the tests. */
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
2011-01-04 04:25:21 +01:00
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:21 +01:00
|
|
|
{
|
2012-11-27 02:52:46 +01:00
|
|
|
if (invalid_table[i].win_crash)
|
2011-01-04 04:25:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].written) count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputA(invalid_table[i].handle,
|
|
|
|
invalid_table[i].buffer,
|
|
|
|
invalid_table[i].count,
|
|
|
|
invalid_table[i].written);
|
|
|
|
ok(!ret, "[%d] Expected WriteConsoleInputA to return FALSE, got %d\n", i, ret);
|
2014-01-04 18:35:14 +01:00
|
|
|
gle = GetLastError();
|
|
|
|
ok(gle == invalid_table[i].gle || (gle != 0 && gle == invalid_table[i].gle2),
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu or %lu, got %lu\n",
|
2014-01-04 18:35:14 +01:00
|
|
|
i, invalid_table[i].gle, invalid_table[i].gle2, gle);
|
2011-01-04 04:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputA(input_handle, NULL, 0, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:21 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 0, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:21 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:21 +01:00
|
|
|
|
2011-01-11 12:11:40 +01:00
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
/* Writing a single mouse event doesn't seem to affect the count if an adjacent mouse event is already queued. */
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
|
|
|
todo_wine
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(event_list); i++)
|
2011-01-11 12:11:40 +01:00
|
|
|
{
|
|
|
|
event_list[i].EventType = MOUSE_EVENT;
|
|
|
|
event_list[i].Event.MouseEvent = mouse_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writing consecutive chunks of mouse events appears to work. */
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = WriteConsoleInputA(input_handle, event_list, ARRAY_SIZE(event_list), &count);
|
2011-01-11 12:11:40 +01:00
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = WriteConsoleInputA(input_handle, event_list, ARRAY_SIZE(event_list), &count);
|
2011-01-11 12:11:40 +01:00
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == 2*ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be twice event list length, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
/* Again, writing a single mouse event with adjacent mouse events queued doesn't appear to affect the count. */
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
|
|
|
todo_wine
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == 2*ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be twice event list length, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
key_event.bKeyDown = FALSE;
|
|
|
|
key_event.wRepeatCount = 0;
|
|
|
|
key_event.wVirtualKeyCode = VK_SPACE;
|
|
|
|
key_event.wVirtualScanCode = VK_SPACE;
|
|
|
|
key_event.uChar.AsciiChar = ' ';
|
|
|
|
key_event.dwControlKeyState = 0;
|
|
|
|
|
|
|
|
event.EventType = KEY_EVENT;
|
|
|
|
event.Event.KeyEvent = key_event;
|
|
|
|
|
|
|
|
/* Key events don't exhibit the same behavior as mouse events. */
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 2, "Expected count to be 2, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
/* Try interleaving mouse and key events. */
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
event.EventType = KEY_EVENT;
|
|
|
|
event.Event.KeyEvent = key_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 2, "Expected count to be 2, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputA(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 3, "Expected count to be 3, got %lu\n", count);
|
2011-01-11 12:11:40 +01:00
|
|
|
|
|
|
|
/* Restore the old console mode. */
|
|
|
|
ret = SetConsoleMode(input_handle, console_mode);
|
|
|
|
ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
|
2011-01-04 04:25:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:16 +01:00
|
|
|
static void test_WriteConsoleInputW(HANDLE input_handle)
|
|
|
|
{
|
2011-01-11 12:11:37 +01:00
|
|
|
INPUT_RECORD event;
|
|
|
|
INPUT_RECORD event_list[5];
|
2011-01-04 04:25:16 +01:00
|
|
|
MOUSE_EVENT_RECORD mouse_event = { {0, 0}, 0, 0, MOUSE_MOVED };
|
2011-01-11 12:11:37 +01:00
|
|
|
KEY_EVENT_RECORD key_event;
|
2014-01-04 18:35:14 +01:00
|
|
|
DWORD count, console_mode, gle;
|
2011-01-04 04:25:16 +01:00
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
const INPUT_RECORD *buffer;
|
|
|
|
DWORD count;
|
|
|
|
LPDWORD written;
|
2014-01-04 18:35:14 +01:00
|
|
|
DWORD gle, gle2;
|
2012-11-27 02:52:46 +01:00
|
|
|
int win_crash;
|
2011-01-04 04:25:16 +01:00
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2016-11-22 13:00:09 +01:00
|
|
|
{NULL, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, NULL, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, NULL, 1, &count, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
|
|
|
|
{NULL, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, &event, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{NULL, &event, 1, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, &count, ERROR_INVALID_HANDLE, ERROR_INVALID_ACCESS},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 0, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &event, 1, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{input_handle, NULL, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, NULL, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, NULL, 1, &count, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
|
|
|
|
{input_handle, &event, 0, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
|
|
|
{input_handle, &event, 1, NULL, ERROR_INVALID_ACCESS, 0, 1},
|
2011-01-04 04:25:16 +01:00
|
|
|
};
|
|
|
|
|
2011-01-11 12:11:37 +01:00
|
|
|
/* Suppress external sources of input events for the duration of the test. */
|
|
|
|
ret = GetConsoleMode(input_handle, &console_mode);
|
|
|
|
ok(ret == TRUE, "Expected GetConsoleMode to return TRUE, got %d\n", ret);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
skip("GetConsoleMode failed with last error %lu\n", GetLastError());
|
2011-01-11 12:11:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SetConsoleMode(input_handle, console_mode & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
|
|
|
|
ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
skip("SetConsoleMode failed with last error %lu\n", GetLastError());
|
2011-01-11 12:11:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard any events queued before the tests. */
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
2011-01-04 04:25:16 +01:00
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:16 +01:00
|
|
|
{
|
2012-11-27 02:52:46 +01:00
|
|
|
if (invalid_table[i].win_crash)
|
2011-01-04 04:25:16 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].written) count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputW(invalid_table[i].handle,
|
|
|
|
invalid_table[i].buffer,
|
|
|
|
invalid_table[i].count,
|
|
|
|
invalid_table[i].written);
|
|
|
|
ok(!ret, "[%d] Expected WriteConsoleInputW to return FALSE, got %d\n", i, ret);
|
2014-01-04 18:35:14 +01:00
|
|
|
gle = GetLastError();
|
|
|
|
ok(gle == invalid_table[i].gle || (gle != 0 && gle == invalid_table[i].gle2),
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu or %lu, got %lu\n",
|
2014-01-04 18:35:14 +01:00
|
|
|
i, invalid_table[i].gle, invalid_table[i].gle2, gle);
|
2011-01-04 04:25:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputW(input_handle, NULL, 0, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:16 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 0, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:16 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:16 +01:00
|
|
|
|
2011-01-11 12:11:37 +01:00
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
/* Writing a single mouse event doesn't seem to affect the count if an adjacent mouse event is already queued. */
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
|
|
|
todo_wine
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(event_list); i++)
|
2011-01-11 12:11:37 +01:00
|
|
|
{
|
|
|
|
event_list[i].EventType = MOUSE_EVENT;
|
|
|
|
event_list[i].Event.MouseEvent = mouse_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writing consecutive chunks of mouse events appears to work. */
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = WriteConsoleInputW(input_handle, event_list, ARRAY_SIZE(event_list), &count);
|
2011-01-11 12:11:37 +01:00
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = WriteConsoleInputW(input_handle, event_list, ARRAY_SIZE(event_list), &count);
|
2011-01-11 12:11:37 +01:00
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be event list length, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == 2*ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be twice event list length, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
/* Again, writing a single mouse event with adjacent mouse events queued doesn't appear to affect the count. */
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
|
|
|
todo_wine
|
2018-06-27 20:56:45 +02:00
|
|
|
ok(count == 2*ARRAY_SIZE(event_list),
|
2022-03-02 09:03:21 +01:00
|
|
|
"Expected count to be twice event list length, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
key_event.bKeyDown = FALSE;
|
|
|
|
key_event.wRepeatCount = 0;
|
|
|
|
key_event.wVirtualKeyCode = VK_SPACE;
|
|
|
|
key_event.wVirtualScanCode = VK_SPACE;
|
|
|
|
key_event.uChar.UnicodeChar = ' ';
|
|
|
|
key_event.dwControlKeyState = 0;
|
|
|
|
|
|
|
|
event.EventType = KEY_EVENT;
|
|
|
|
event.Event.KeyEvent = key_event;
|
|
|
|
|
|
|
|
/* Key events don't exhibit the same behavior as mouse events. */
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 2, "Expected count to be 2, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input_handle);
|
|
|
|
ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
/* Try interleaving mouse and key events. */
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
event.EventType = KEY_EVENT;
|
|
|
|
event.Event.KeyEvent = key_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 2, "Expected count to be 2, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
event.EventType = MOUSE_EVENT;
|
|
|
|
event.Event.MouseEvent = mouse_event;
|
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input_handle, &event, 1, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input_handle, &count);
|
|
|
|
ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 3, "Expected count to be 3, got %lu\n", count);
|
2011-01-11 12:11:37 +01:00
|
|
|
|
|
|
|
/* Restore the old console mode. */
|
|
|
|
ret = SetConsoleMode(input_handle, console_mode);
|
|
|
|
ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
|
2011-01-04 04:25:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-15 18:19:30 +02:00
|
|
|
static void test_FlushConsoleInputBuffer(HANDLE input, HANDLE output)
|
|
|
|
{
|
|
|
|
INPUT_RECORD record;
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "FlushConsoleInputBuffer failed: %lu\n", GetLastError());
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetNumberOfConsoleInputEvents failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
record.EventType = KEY_EVENT;
|
|
|
|
record.Event.KeyEvent.bKeyDown = 1;
|
|
|
|
record.Event.KeyEvent.wRepeatCount = 1;
|
|
|
|
record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
|
|
|
|
record.Event.KeyEvent.wVirtualScanCode = VK_RETURN;
|
|
|
|
record.Event.KeyEvent.uChar.UnicodeChar = '\r';
|
|
|
|
record.Event.KeyEvent.dwControlKeyState = 0;
|
|
|
|
ret = WriteConsoleInputW(input, &record, 1, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleInputW failed: %lu\n", GetLastError());
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetNumberOfConsoleInputEvents failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 1, "Expected count to be 0, got %lu\n", count);
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(input);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "FlushConsoleInputBuffer failed: %lu\n", GetLastError());
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetNumberOfConsoleInputEvents failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = WriteConsoleInputW(input, &record, 1, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleInputW failed: %lu\n", GetLastError());
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetNumberOfConsoleInputEvents failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 1, "Expected count to be 0, got %lu\n", count);
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = FlushFileBuffers(input);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "FlushFileBuffers failed: %lu\n", GetLastError());
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = GetNumberOfConsoleInputEvents(input, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetNumberOfConsoleInputEvents failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2020-10-15 18:19:30 +02:00
|
|
|
|
|
|
|
ret = FlushConsoleInputBuffer(output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "FlushConsoleInputBuffer returned: %x(%lu)\n",
|
2020-10-15 18:19:30 +02:00
|
|
|
ret, GetLastError());
|
|
|
|
|
|
|
|
ret = FlushFileBuffers(output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "FlushFileBuffers returned: %x(%lu)\n",
|
2020-10-15 18:19:30 +02:00
|
|
|
ret, GetLastError());
|
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:29 +01:00
|
|
|
static void test_WriteConsoleOutputCharacterA(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
static const char output[] = {'a', 0};
|
|
|
|
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
LPCSTR str;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumCharsWritten;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, output, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, output, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, output, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, output, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:29 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:29 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].str,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumCharsWritten);
|
|
|
|
ok(!ret, "[%d] Expected WriteConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-04 04:25:29 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:29 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterA(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:29 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterA(output_handle, output, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:29 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterA(output_handle, output, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-23 17:32:23 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = WriteConsoleOutputCharacterA(output_handle, output, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:29 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:26 +01:00
|
|
|
static void test_WriteConsoleOutputCharacterW(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
static const WCHAR outputW[] = {'a',0};
|
|
|
|
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
LPCWSTR str;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumCharsWritten;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, outputW, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, outputW, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, outputW, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, outputW, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:26 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:26 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].str,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumCharsWritten);
|
|
|
|
ok(!ret, "[%d] Expected WriteConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-04 04:25:26 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:26 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterW(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:26 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterW(output_handle, outputW, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:26 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputCharacterW(output_handle, outputW, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-23 17:32:23 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = WriteConsoleOutputCharacterW(output_handle, outputW, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2020-07-23 17:32:23 +02:00
|
|
|
|
2011-01-04 04:25:26 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:34 +01:00
|
|
|
static void test_WriteConsoleOutputAttribute(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
WORD attr = FOREGROUND_BLUE;
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
2013-09-25 10:39:19 +02:00
|
|
|
const WORD *attr;
|
2011-01-04 04:25:34 +01:00
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumAttrsWritten;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:34 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:34 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumAttrsWritten) count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].attr,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumAttrsWritten);
|
|
|
|
ok(!ret, "[%d] Expected WriteConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].lpNumAttrsWritten)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-04 04:25:34 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:34 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputAttribute(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:34 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:34 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = WriteConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-23 17:32:23 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = WriteConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2020-07-23 17:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_region(SMALL_RECT *region, unsigned int left, unsigned int top, unsigned int right, unsigned int bottom)
|
|
|
|
{
|
|
|
|
region->Left = left;
|
|
|
|
region->Top = top;
|
|
|
|
region->Right = right;
|
|
|
|
region->Bottom = bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define check_region(a,b,c,d,e) check_region_(__LINE__,a,b,c,d,e)
|
2020-07-28 17:11:19 +02:00
|
|
|
static void check_region_(unsigned int line, const SMALL_RECT *region, unsigned int left, unsigned int top, int right, int bottom)
|
2020-07-23 17:32:23 +02:00
|
|
|
{
|
|
|
|
ok_(__FILE__,line)(region->Left == left, "Left = %u, expected %u\n", region->Left, left);
|
|
|
|
ok_(__FILE__,line)(region->Top == top, "Top = %u, expected %u\n", region->Top, top);
|
2020-07-28 17:11:19 +02:00
|
|
|
/* In multiple places returned region depends on Windows versions: some return right < left, others leave it untouched */
|
|
|
|
if (right >= 0)
|
|
|
|
ok_(__FILE__,line)(region->Right == right, "Right = %u, expected %u\n", region->Right, right);
|
|
|
|
else
|
|
|
|
ok_(__FILE__,line)(region->Right == -right || region->Right == region->Left - 1,
|
|
|
|
"Right = %u, expected %d\n", region->Right, right);
|
2020-08-20 23:46:26 +02:00
|
|
|
if (bottom > 0)
|
2020-07-28 17:11:19 +02:00
|
|
|
ok_(__FILE__,line)(region->Bottom == bottom, "Bottom = %u, expected %u\n", region->Bottom, bottom);
|
2020-08-20 23:46:26 +02:00
|
|
|
else if (bottom < 0)
|
2020-07-28 17:11:19 +02:00
|
|
|
ok_(__FILE__,line)(region->Bottom == -bottom || region->Bottom == region->Top - 1,
|
|
|
|
"Bottom = %u, expected %d\n", region->Bottom, bottom);
|
2020-07-23 17:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_WriteConsoleOutput(HANDLE console)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
|
|
CHAR_INFO char_info_buf[2048];
|
|
|
|
SMALL_RECT region;
|
|
|
|
COORD size, coord;
|
|
|
|
unsigned int i;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(char_info_buf); i++)
|
|
|
|
{
|
|
|
|
char_info_buf[i].Char.UnicodeChar = '0' + i % 10;
|
|
|
|
char_info_buf[i].Attributes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfo(console, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 200, 7, 15, 211);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 200, 7, 15, 211);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 200, 7, 211, 8);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 200, 7, 211, 8);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 9, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 9, 11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 11, 6);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 11, 6);
|
|
|
|
|
|
|
|
size.X = 2;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 3;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 11);
|
|
|
|
|
|
|
|
size.X = 6;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 13, 11);
|
|
|
|
|
|
|
|
size.X = 6;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW((HANDLE)0xdeadbeef, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "WriteConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
if (!skip_nt) check_region(®ion, 10, 7, 13, 11);
|
|
|
|
|
|
|
|
size.X = 16;
|
|
|
|
size.Y = 7;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 10);
|
|
|
|
|
|
|
|
size.X = 16;
|
|
|
|
size.Y = 7;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, info.dwSize.X - 2, 7, info.dwSize.X + 2, 7);
|
|
|
|
ret = WriteConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-23 17:32:23 +02:00
|
|
|
check_region(®ion, info.dwSize.X - 2, 7, info.dwSize.X - 1, 7);
|
2011-01-04 04:25:34 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:44 +01:00
|
|
|
static void test_FillConsoleOutputCharacterA(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
CHAR ch;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumCharsWritten;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2016-11-22 13:00:09 +01:00
|
|
|
{NULL, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, 'a', 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, 'a', 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:44 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:44 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].ch,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumCharsWritten);
|
|
|
|
ok(!ret, "[%d] Expected FillConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:44 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterA(output_handle, 'a', 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:44 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterA(output_handle, 'a', 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:44 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:39 +01:00
|
|
|
static void test_FillConsoleOutputCharacterW(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
WCHAR ch;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumCharsWritten;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2016-11-22 13:00:09 +01:00
|
|
|
{NULL, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, 'a', 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, 'a', 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, 'a', 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, 'a', 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:39 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:39 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].ch,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumCharsWritten);
|
|
|
|
ok(!ret, "[%d] Expected FillConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:39 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterW(output_handle, 'a', 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:39 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputCharacterW(output_handle, 'a', 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:39 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 04:25:47 +01:00
|
|
|
static void test_FillConsoleOutputAttribute(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
WORD attr;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD lpNumAttrsWritten;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2016-11-22 13:00:09 +01:00
|
|
|
{NULL, FOREGROUND_BLUE, 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, FOREGROUND_BLUE, 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, FOREGROUND_BLUE, 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, FOREGROUND_BLUE, 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 0, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 1, {0, 0}, &count, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, FOREGROUND_BLUE, 0, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, FOREGROUND_BLUE, 1, {0, 0}, NULL, ERROR_INVALID_ACCESS, 1},
|
2011-01-04 04:25:47 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-04 04:25:47 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].lpNumAttrsWritten) count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].attr,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].lpNumAttrsWritten);
|
|
|
|
ok(!ret, "[%d] Expected FillConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-04 04:25:47 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputAttribute(output_handle, FOREGROUND_BLUE, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-04 04:25:47 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputAttribute(output_handle, FOREGROUND_BLUE, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:47 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = FillConsoleOutputAttribute(output_handle, ~0, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2011-01-04 04:25:47 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 12:11:30 +01:00
|
|
|
static void test_ReadConsoleOutputCharacterA(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
CHAR read;
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
LPSTR lpstr;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD read_count;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{NULL, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 10, {0, 0}, &count, 10, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-11 12:11:30 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-11 12:11:30 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].read_count) count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].lpstr,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].read_count);
|
|
|
|
ok(!ret, "[%d] Expected ReadConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].read_count)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-11 12:11:30 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-11 12:11:30 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterA(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:30 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterA(output_handle, &read, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:30 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterA(output_handle, &read, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = ReadConsoleOutputCharacterA(output_handle, &read, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 12:11:16 +01:00
|
|
|
static void test_ReadConsoleOutputCharacterW(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
WCHAR read;
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
LPWSTR buffer;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD read_count;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{NULL, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 10, {0, 0}, &count, 10, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-11 12:11:16 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-11 12:11:16 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].read_count) count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].buffer,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].read_count);
|
|
|
|
ok(!ret, "[%d] Expected ReadConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].read_count)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-11 12:11:16 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-11 12:11:16 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterW(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:16 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterW(output_handle, &read, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:16 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputCharacterW(output_handle, &read, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = ReadConsoleOutputCharacterW(output_handle, &read, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:16 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 12:11:34 +01:00
|
|
|
static void test_ReadConsoleOutputAttribute(HANDLE output_handle)
|
|
|
|
{
|
|
|
|
WORD attr;
|
|
|
|
COORD origin = {0, 0};
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
HANDLE hConsoleOutput;
|
|
|
|
LPWORD lpAttribute;
|
|
|
|
DWORD length;
|
|
|
|
COORD coord;
|
|
|
|
LPDWORD read_count;
|
|
|
|
DWORD expected_count;
|
|
|
|
DWORD last_error;
|
|
|
|
int win7_crash;
|
|
|
|
} invalid_table[] =
|
|
|
|
{
|
2011-10-04 23:10:08 +02:00
|
|
|
{NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{NULL, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{NULL, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{NULL, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
|
|
|
|
{output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
|
|
|
{output_handle, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
|
2011-01-11 12:11:34 +01:00
|
|
|
};
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(invalid_table); i++)
|
2011-01-11 12:11:34 +01:00
|
|
|
{
|
|
|
|
if (invalid_table[i].win7_crash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
if (invalid_table[i].read_count) count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
|
|
|
|
invalid_table[i].lpAttribute,
|
|
|
|
invalid_table[i].length,
|
|
|
|
invalid_table[i].coord,
|
|
|
|
invalid_table[i].read_count);
|
|
|
|
ok(!ret, "[%d] Expected ReadConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
|
|
|
|
if (invalid_table[i].read_count)
|
|
|
|
{
|
|
|
|
ok(count == invalid_table[i].expected_count,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected count to be %lu, got %lu\n",
|
2011-01-11 12:11:34 +01:00
|
|
|
i, invalid_table[i].expected_count, count);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == invalid_table[i].last_error,
|
2022-03-02 09:03:21 +01:00
|
|
|
"[%d] Expected last error to be %lu, got %lu\n",
|
2011-01-11 12:11:34 +01:00
|
|
|
i, invalid_table[i].last_error, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputAttribute(output_handle, NULL, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:34 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 0, got %lu\n", count);
|
2011-01-11 12:11:34 +01:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = ReadConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 1, "Expected count to be 1, got %lu\n", count);
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
origin.X = 200;
|
|
|
|
ret = ReadConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
|
|
|
|
ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(count == 0, "Expected count to be 1, got %lu\n", count);
|
2020-07-28 17:11:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ReadConsoleOutput(HANDLE console)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
|
|
CHAR_INFO char_info_buf[2048];
|
|
|
|
SMALL_RECT region;
|
|
|
|
COORD size, coord;
|
|
|
|
DWORD count;
|
|
|
|
WCHAR ch;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (skip_nt) return;
|
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfo(console, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "ReadConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 200, 7, 15, 211);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret, "ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-08-20 23:46:26 +02:00
|
|
|
check_region(®ion, 200, 7, -15, 0);
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 200, 7, 211, 8);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
|
|
|
ok((!ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_FUNCTION)) || broken(ret /* win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleOutputW returned: %x %lu\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_INVALID_PARAMETER) check_region(®ion, 200, 7, -211, -8);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 9, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
|
|
|
ok((!ret && (GetLastError() == ERROR_INVALID_FUNCTION || GetLastError() == ERROR_NOT_ENOUGH_MEMORY)) || broken(ret /* win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, 9, -11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 11, 6);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
|
|
|
ok((!ret && (GetLastError() == ERROR_INVALID_FUNCTION || GetLastError() == ERROR_NOT_ENOUGH_MEMORY)) || broken(ret /* win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, -11, 6);
|
|
|
|
|
|
|
|
size.X = 2;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
|
|
|
ok((!ret && (GetLastError() == ERROR_INVALID_FUNCTION || GetLastError() == ERROR_NOT_ENOUGH_MEMORY)) || broken(ret /* win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, -15, -11);
|
|
|
|
|
|
|
|
size.X = 23;
|
|
|
|
size.Y = 3;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
|
|
|
ok((!ret && (GetLastError() == ERROR_INVALID_FUNCTION || GetLastError() == ERROR_NOT_ENOUGH_MEMORY)) || broken(ret /* win8 */),
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, -15, 6);
|
|
|
|
|
|
|
|
size.X = 6;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "ReadConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, 13, 11);
|
|
|
|
|
|
|
|
size.X = 6;
|
|
|
|
size.Y = 17;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW((HANDLE)0xdeadbeef, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "ReadConsoleOutputW returned: %x(%lu)\n", ret, GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
if (!skip_nt) check_region(®ion, 10, 7, 13, 11);
|
|
|
|
|
|
|
|
size.X = 16;
|
|
|
|
size.Y = 7;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, 10, 7, 15, 11);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "ReadConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 10, 7, 15, 10);
|
|
|
|
|
|
|
|
size.X = 16;
|
|
|
|
size.Y = 7;
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
set_region(®ion, info.dwSize.X - 2, 7, info.dwSize.X + 2, 7);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret || GetLastError() == ERROR_INVALID_PARAMETER, "ReadConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
if (ret) check_region(®ion, info.dwSize.X - 2, 7, info.dwSize.X - 1, 7);
|
|
|
|
|
|
|
|
coord.X = 2;
|
|
|
|
coord.Y = 3;
|
|
|
|
ret = WriteConsoleOutputCharacterW(console, L"xyz", 3, coord, &count);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "WriteConsoleOutputCharacterW failed: %lu\n", GetLastError());
|
|
|
|
ok(count == 3, "count = %lu\n", count);
|
2020-07-28 17:11:19 +02:00
|
|
|
|
|
|
|
memset(char_info_buf, 0xc0, sizeof(char_info_buf));
|
|
|
|
size.X = 16;
|
|
|
|
size.Y = 7;
|
|
|
|
coord.X = 5;
|
|
|
|
coord.Y = 6;
|
|
|
|
set_region(®ion, 2, 3, 5, 3);
|
|
|
|
ret = ReadConsoleOutputW(console, char_info_buf, size, coord, ®ion);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "ReadConsoleOutputW failed: %lu\n", GetLastError());
|
2020-07-28 17:11:19 +02:00
|
|
|
check_region(®ion, 2, 3, 5, 3);
|
|
|
|
ch = char_info_buf[coord.Y * size.X + coord.X].Char.UnicodeChar;
|
|
|
|
ok(ch == 'x', "unexpected char %c/%x\n", ch, ch);
|
|
|
|
ch = char_info_buf[coord.Y * size.X + coord.X + 1].Char.UnicodeChar;
|
|
|
|
ok(ch == 'y', "unexpected char %c/%x\n", ch, ch);
|
|
|
|
ch = char_info_buf[coord.Y * size.X + coord.X + 2].Char.UnicodeChar;
|
|
|
|
ok(ch == 'z', "unexpected char %c/%x\n", ch, ch);
|
2011-01-11 12:11:34 +01:00
|
|
|
}
|
|
|
|
|
2020-10-14 19:57:37 +02:00
|
|
|
static void test_ReadConsole(HANDLE input)
|
2014-04-14 08:28:32 +02:00
|
|
|
{
|
|
|
|
DWORD ret, bytes;
|
|
|
|
char buf[1024];
|
2020-10-14 19:57:51 +02:00
|
|
|
HANDLE output;
|
2014-04-14 08:28:32 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2020-10-14 19:57:37 +02:00
|
|
|
ret = GetFileSize(input, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret == INVALID_FILE_SIZE, "expected INVALID_FILE_SIZE, got %#lx\n", ret);
|
2016-11-22 13:00:08 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION, /* Win 8, 10 */
|
2022-03-02 09:03:21 +01:00
|
|
|
"expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
|
2014-04-14 08:28:32 +02:00
|
|
|
|
|
|
|
bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2020-10-14 19:57:37 +02:00
|
|
|
ret = ReadFile(input, buf, -128, &bytes, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret, "expected 0, got %lu\n", ret);
|
2016-11-22 13:00:08 +01:00
|
|
|
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY ||
|
|
|
|
GetLastError() == ERROR_NOACCESS, /* Win 8, 10 */
|
2022-03-02 09:03:21 +01:00
|
|
|
"expected ERROR_NOT_ENOUGH_MEMORY, got %ld\n", GetLastError());
|
|
|
|
ok(!bytes, "expected 0, got %lu\n", bytes);
|
2014-04-14 08:28:32 +02:00
|
|
|
|
|
|
|
bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2020-10-14 19:57:37 +02:00
|
|
|
ret = ReadConsoleA(input, buf, -128, &bytes, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret, "expected 0, got %lu\n", ret);
|
2016-11-22 13:00:08 +01:00
|
|
|
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY ||
|
|
|
|
GetLastError() == ERROR_NOACCESS, /* Win 8, 10 */
|
2022-03-02 09:03:21 +01:00
|
|
|
"expected ERROR_NOT_ENOUGH_MEMORY, got %ld\n", GetLastError());
|
|
|
|
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, got %#lx\n", bytes);
|
2014-04-14 08:28:32 +02:00
|
|
|
|
|
|
|
bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2020-10-14 19:57:37 +02:00
|
|
|
ret = ReadConsoleW(input, buf, -128, &bytes, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret, "expected 0, got %lu\n", ret);
|
2016-11-22 13:00:08 +01:00
|
|
|
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY ||
|
|
|
|
GetLastError() == ERROR_NOACCESS, /* Win 8, 10 */
|
2022-03-02 09:03:21 +01:00
|
|
|
"expected ERROR_NOT_ENOUGH_MEMORY, got %ld\n", GetLastError());
|
|
|
|
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, got %#lx\n", bytes);
|
2020-10-14 19:57:51 +02:00
|
|
|
|
|
|
|
output = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(output != INVALID_HANDLE_VALUE, "Could not open console\n");
|
|
|
|
|
|
|
|
ret = ReadConsoleW(output, buf, sizeof(buf) / sizeof(WCHAR), &bytes, NULL);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleW returned %lx(%lu)\n", ret, GetLastError());
|
2020-10-14 19:57:51 +02:00
|
|
|
|
|
|
|
ret = ReadConsoleA(output, buf, sizeof(buf), &bytes, NULL);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadConsoleA returned %lx(%lu)\n", ret, GetLastError());
|
2020-10-14 19:57:51 +02:00
|
|
|
|
|
|
|
ret = ReadFile(output, buf, sizeof(buf), &bytes, NULL);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadFile returned %lx(%lu)\n", ret, GetLastError());
|
2020-10-14 19:57:51 +02:00
|
|
|
|
|
|
|
CloseHandle(output);
|
2014-04-14 08:28:32 +02:00
|
|
|
}
|
|
|
|
|
2015-10-26 07:42:14 +01:00
|
|
|
static void test_GetCurrentConsoleFont(HANDLE std_output)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CONSOLE_FONT_INFO cfi;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
short int width, height;
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2015-10-26 07:42:14 +01:00
|
|
|
COORD c;
|
|
|
|
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(NULL, FALSE, &cfi);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2015-10-26 07:42:14 +01:00
|
|
|
ok(!cfi.dwFontSize.X, "got %d, expected 0\n", cfi.dwFontSize.X);
|
|
|
|
ok(!cfi.dwFontSize.Y, "got %d, expected 0\n", cfi.dwFontSize.Y);
|
|
|
|
|
2016-01-27 04:55:17 +01:00
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(NULL, TRUE, &cfi);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-01-27 04:55:17 +01:00
|
|
|
ok(!cfi.dwFontSize.X, "got %d, expected 0\n", cfi.dwFontSize.X);
|
|
|
|
ok(!cfi.dwFontSize.Y, "got %d, expected 0\n", cfi.dwFontSize.Y);
|
|
|
|
|
2015-10-26 07:42:14 +01:00
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(GetStdHandle(STD_INPUT_HANDLE), FALSE, &cfi);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2015-10-26 07:42:14 +01:00
|
|
|
ok(!cfi.dwFontSize.X, "got %d, expected 0\n", cfi.dwFontSize.X);
|
|
|
|
ok(!cfi.dwFontSize.Y, "got %d, expected 0\n", cfi.dwFontSize.Y);
|
|
|
|
|
2016-01-27 04:55:17 +01:00
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(GetStdHandle(STD_INPUT_HANDLE), TRUE, &cfi);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-01-27 04:55:17 +01:00
|
|
|
ok(!cfi.dwFontSize.X, "got %d, expected 0\n", cfi.dwFontSize.X);
|
|
|
|
ok(!cfi.dwFontSize.Y, "got %d, expected 0\n", cfi.dwFontSize.Y);
|
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(pipe1, TRUE, &cfi);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
ok(!cfi.dwFontSize.X, "got %d, expected 0\n", cfi.dwFontSize.X);
|
|
|
|
ok(!cfi.dwFontSize.Y, "got %d, expected 0\n", cfi.dwFontSize.Y);
|
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2015-10-26 07:42:14 +01:00
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(std_output, FALSE, &cfi);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2015-10-26 07:42:14 +01:00
|
|
|
GetConsoleScreenBufferInfo(std_output, &csbi);
|
|
|
|
width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
|
|
|
height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
|
|
|
c = GetConsoleFontSize(std_output, cfi.nFont);
|
|
|
|
ok(cfi.dwFontSize.X == width || cfi.dwFontSize.X == c.X /* Vista and higher */,
|
|
|
|
"got %d, expected %d\n", cfi.dwFontSize.X, width);
|
|
|
|
ok(cfi.dwFontSize.Y == height || cfi.dwFontSize.Y == c.Y /* Vista and higher */,
|
|
|
|
"got %d, expected %d\n", cfi.dwFontSize.Y, height);
|
2016-01-27 04:55:17 +01:00
|
|
|
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(std_output, TRUE, &cfi);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2016-01-27 04:55:17 +01:00
|
|
|
ok(cfi.dwFontSize.X == csbi.dwMaximumWindowSize.X,
|
|
|
|
"got %d, expected %d\n", cfi.dwFontSize.X, csbi.dwMaximumWindowSize.X);
|
|
|
|
ok(cfi.dwFontSize.Y == csbi.dwMaximumWindowSize.Y,
|
|
|
|
"got %d, expected %d\n", cfi.dwFontSize.Y, csbi.dwMaximumWindowSize.Y);
|
2015-10-26 07:42:14 +01:00
|
|
|
}
|
|
|
|
|
2019-11-20 11:45:30 +01:00
|
|
|
static void test_GetCurrentConsoleFontEx(HANDLE std_output)
|
|
|
|
{
|
|
|
|
HANDLE hmod;
|
|
|
|
BOOL (WINAPI *pGetCurrentConsoleFontEx)(HANDLE, BOOL, CONSOLE_FONT_INFOEX *);
|
|
|
|
CONSOLE_FONT_INFO cfi;
|
|
|
|
CONSOLE_FONT_INFOEX cfix;
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE std_input = GetStdHandle(STD_INPUT_HANDLE);
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2021-11-15 12:18:23 +01:00
|
|
|
COORD c;
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pGetCurrentConsoleFontEx = (void *)GetProcAddress(hmod, "GetCurrentConsoleFontEx");
|
|
|
|
if (!pGetCurrentConsoleFontEx)
|
|
|
|
{
|
|
|
|
win_skip("GetCurrentConsoleFontEx is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(NULL, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(NULL, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_input, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_input, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_output, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_output, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
cfix.cbSize = sizeof(CONSOLE_FONT_INFOEX);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(NULL, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(NULL, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_input, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_input, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(pipe1, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2019-11-20 11:45:30 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_output, FALSE, &cfix);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(std_output, FALSE, &cfi);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
ok(cfix.dwFontSize.X == cfi.dwFontSize.X, "expected values to match\n");
|
|
|
|
ok(cfix.dwFontSize.Y == cfi.dwFontSize.Y, "expected values to match\n");
|
|
|
|
|
2021-11-15 12:18:23 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(std_output, cfix.nFont);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(c.X && c.Y, "GetConsoleFontSize failed; err = %lu\n", GetLastError());
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2021-11-15 12:18:23 +01:00
|
|
|
|
2021-11-15 12:18:24 +01:00
|
|
|
ok(cfix.dwFontSize.X == c.X, "Font width doesn't match; got %u, expected %u\n",
|
2021-11-15 12:18:23 +01:00
|
|
|
cfix.dwFontSize.X, c.X);
|
2021-11-15 12:18:24 +01:00
|
|
|
ok(cfix.dwFontSize.Y == c.Y, "Font height doesn't match; got %u, expected %u\n",
|
2021-11-15 12:18:23 +01:00
|
|
|
cfix.dwFontSize.Y, c.Y);
|
|
|
|
|
2021-11-15 12:18:24 +01:00
|
|
|
ok(cfi.dwFontSize.X == c.X, "Font width doesn't match; got %u, expected %u\n",
|
2021-11-15 12:18:23 +01:00
|
|
|
cfi.dwFontSize.X, c.X);
|
2021-11-15 12:18:24 +01:00
|
|
|
ok(cfi.dwFontSize.Y == c.Y, "Font height doesn't match; got %u, expected %u\n",
|
2021-11-15 12:18:23 +01:00
|
|
|
cfi.dwFontSize.Y, c.Y);
|
|
|
|
|
2019-11-20 11:45:30 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetCurrentConsoleFontEx(std_output, TRUE, &cfix);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetCurrentConsoleFont(std_output, TRUE, &cfi);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2019-11-20 11:45:30 +01:00
|
|
|
|
|
|
|
ok(cfix.dwFontSize.X == cfi.dwFontSize.X, "expected values to match\n");
|
|
|
|
ok(cfix.dwFontSize.Y == cfi.dwFontSize.Y, "expected values to match\n");
|
|
|
|
}
|
|
|
|
|
2021-08-17 14:11:11 +02:00
|
|
|
static void test_SetCurrentConsoleFontEx(HANDLE std_output)
|
|
|
|
{
|
|
|
|
CONSOLE_FONT_INFOEX orig_cfix, cfix;
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE pipe1, pipe2;
|
|
|
|
HANDLE std_input = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
|
|
|
|
orig_cfix.cbSize = sizeof(CONSOLE_FONT_INFOEX);
|
|
|
|
|
|
|
|
ret = GetCurrentConsoleFontEx(std_output, FALSE, &orig_cfix);
|
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
|
|
|
|
|
|
|
cfix = orig_cfix;
|
|
|
|
cfix.cbSize = 0;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(NULL, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(NULL, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(pipe1, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(pipe1, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_input, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_input, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_output, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
cfix = orig_cfix;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(NULL, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(NULL, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(pipe1, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(pipe1, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_input, FALSE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_input, TRUE, &cfix);
|
|
|
|
ok(!ret, "got %d, expected 0\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
|
2022-02-09 20:43:54 +01:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_output, TRUE, &cfix);
|
2022-02-09 20:43:54 +01:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
|
|
|
|
/* Restore original console font parameters */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetCurrentConsoleFontEx(std_output, FALSE, &orig_cfix);
|
2022-02-09 20:43:54 +01:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2021-08-17 14:11:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:17:22 +01:00
|
|
|
static void test_GetConsoleFontSize(HANDLE std_output)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD index = 0;
|
|
|
|
CONSOLE_FONT_INFO cfi;
|
|
|
|
RECT r;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
LONG font_width, font_height;
|
|
|
|
HMODULE hmod;
|
|
|
|
DWORD (WINAPI *pGetNumberOfConsoleFonts)(void);
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2015-10-29 13:17:22 +01:00
|
|
|
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(NULL, index);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2015-10-29 13:17:22 +01:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(GetStdHandle(STD_INPUT_HANDLE), index);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2015-10-29 13:17:22 +01:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(pipe1, index);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2015-10-29 13:17:22 +01:00
|
|
|
GetCurrentConsoleFont(std_output, FALSE, &cfi);
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(std_output, cfi.nFont);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2015-10-29 13:17:22 +01:00
|
|
|
GetClientRect(GetConsoleWindow(), &r);
|
|
|
|
GetConsoleScreenBufferInfo(std_output, &csbi);
|
2021-08-09 15:27:45 +02:00
|
|
|
font_width = (r.right - r.left) / (csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
|
|
|
font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(c.X == font_width, "got %d, expected %ld\n", c.X, font_width);
|
|
|
|
ok(c.Y == font_height, "got %d, expected %ld\n", c.Y, font_height);
|
2015-10-29 13:17:22 +01:00
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pGetNumberOfConsoleFonts = (void *)GetProcAddress(hmod, "GetNumberOfConsoleFonts");
|
|
|
|
if (!pGetNumberOfConsoleFonts)
|
|
|
|
{
|
|
|
|
win_skip("GetNumberOfConsoleFonts is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index = pGetNumberOfConsoleFonts();
|
|
|
|
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetConsoleFontSize(std_output, index);
|
2019-09-30 19:31:42 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef) /* win10 1809 */,
|
2022-03-02 09:03:21 +01:00
|
|
|
"unexpected last error %lu\n", GetLastError());
|
2019-09-30 19:31:42 +02:00
|
|
|
if (GetLastError() == ERROR_INVALID_PARAMETER)
|
|
|
|
{
|
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
}
|
2015-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 08:59:35 +01:00
|
|
|
static void test_GetLargestConsoleWindowSize(HANDLE std_output)
|
|
|
|
{
|
|
|
|
COORD c, font;
|
|
|
|
RECT r;
|
|
|
|
LONG workarea_w, workarea_h, maxcon_w, maxcon_h;
|
2016-01-06 01:05:04 +01:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
2016-01-05 08:59:35 +01:00
|
|
|
CONSOLE_FONT_INFO cfi;
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2016-01-05 08:59:35 +01:00
|
|
|
DWORD index, i;
|
|
|
|
HMODULE hmod;
|
2016-01-06 01:05:04 +01:00
|
|
|
BOOL ret;
|
2016-01-05 08:59:35 +01:00
|
|
|
DWORD (WINAPI *pGetNumberOfConsoleFonts)(void);
|
|
|
|
BOOL (WINAPI *pSetConsoleFont)(HANDLE, DWORD);
|
|
|
|
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetLargestConsoleWindowSize(NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-01-05 08:59:35 +01:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetLargestConsoleWindowSize(GetStdHandle(STD_INPUT_HANDLE));
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-01-05 08:59:35 +01:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetLargestConsoleWindowSize(pipe1);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
ok(!c.X, "got %d, expected 0\n", c.X);
|
|
|
|
ok(!c.Y, "got %d, expected 0\n", c.Y);
|
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2016-01-05 08:59:35 +01:00
|
|
|
SystemParametersInfoW(SPI_GETWORKAREA, 0, &r, 0);
|
|
|
|
workarea_w = r.right - r.left;
|
|
|
|
workarea_h = r.bottom - r.top - GetSystemMetrics(SM_CYCAPTION);
|
|
|
|
|
|
|
|
GetCurrentConsoleFont(std_output, FALSE, &cfi);
|
|
|
|
index = cfi.nFont; /* save current font index */
|
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pGetNumberOfConsoleFonts = (void *)GetProcAddress(hmod, "GetNumberOfConsoleFonts");
|
|
|
|
if (!pGetNumberOfConsoleFonts)
|
|
|
|
{
|
|
|
|
win_skip("GetNumberOfConsoleFonts is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pSetConsoleFont = (void *)GetProcAddress(hmod, "SetConsoleFont");
|
|
|
|
if (!pSetConsoleFont)
|
|
|
|
{
|
|
|
|
win_skip("SetConsoleFont is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pGetNumberOfConsoleFonts(); i++)
|
|
|
|
{
|
|
|
|
pSetConsoleFont(std_output, i);
|
|
|
|
memset(&c, 10, sizeof(COORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
c = GetLargestConsoleWindowSize(std_output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2016-01-05 08:59:35 +01:00
|
|
|
GetCurrentConsoleFont(std_output, FALSE, &cfi);
|
|
|
|
font = GetConsoleFontSize(std_output, cfi.nFont);
|
|
|
|
maxcon_w = workarea_w / font.X;
|
|
|
|
maxcon_h = workarea_h / font.Y;
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(c.X == maxcon_w || c.X == maxcon_w - 1 /* Win10 */, "got %d, expected %ld\n", c.X, maxcon_w);
|
|
|
|
ok(c.Y == maxcon_h || c.Y == maxcon_h - 1 /* Win10 */, "got %d, expected %ld\n", c.Y, maxcon_h);
|
2016-01-06 01:05:04 +01:00
|
|
|
|
|
|
|
ret = GetConsoleScreenBufferInfo(std_output, &sbi);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed %lu\n", GetLastError());
|
2016-01-06 01:05:04 +01:00
|
|
|
ok(sbi.dwMaximumWindowSize.X == min(c.X, sbi.dwSize.X), "got %d, expected %d\n",
|
|
|
|
sbi.dwMaximumWindowSize.X, min(c.X, sbi.dwSize.X));
|
|
|
|
ok(sbi.dwMaximumWindowSize.Y == min(c.Y, sbi.dwSize.Y), "got %d, expected %d\n",
|
|
|
|
sbi.dwMaximumWindowSize.Y, min(c.Y, sbi.dwSize.Y));
|
2016-01-05 08:59:35 +01:00
|
|
|
}
|
|
|
|
pSetConsoleFont(std_output, index); /* restore original font size */
|
|
|
|
}
|
|
|
|
|
2016-04-26 14:06:51 +02:00
|
|
|
static void test_GetConsoleFontInfo(HANDLE std_output)
|
|
|
|
{
|
|
|
|
HANDLE hmod;
|
|
|
|
BOOL (WINAPI *pGetConsoleFontInfo)(HANDLE, BOOL, DWORD, CONSOLE_FONT_INFO *);
|
|
|
|
DWORD (WINAPI *pGetNumberOfConsoleFonts)(void);
|
|
|
|
DWORD num_fonts, index, i;
|
|
|
|
int memsize, win_width, win_height, tmp_w, tmp_h;
|
|
|
|
CONSOLE_FONT_INFO *cfi;
|
|
|
|
BOOL ret;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2016-05-03 02:06:50 +02:00
|
|
|
COORD orig_sb_size, tmp_sb_size, orig_font, tmp_font;
|
2016-04-26 14:06:51 +02:00
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pGetConsoleFontInfo = (void *)GetProcAddress(hmod, "GetConsoleFontInfo");
|
|
|
|
if (!pGetConsoleFontInfo)
|
|
|
|
{
|
|
|
|
win_skip("GetConsoleFontInfo is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pGetNumberOfConsoleFonts = (void *)GetProcAddress(hmod, "GetNumberOfConsoleFonts");
|
|
|
|
if (!pGetNumberOfConsoleFonts)
|
|
|
|
{
|
2019-11-06 16:46:09 +01:00
|
|
|
skip("GetNumberOfConsoleFonts is not available\n");
|
2016-04-26 14:06:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_fonts = pGetNumberOfConsoleFonts();
|
|
|
|
memsize = num_fonts * sizeof(CONSOLE_FONT_INFO);
|
|
|
|
cfi = HeapAlloc(GetProcessHeap(), 0, memsize);
|
|
|
|
memset(cfi, 0, memsize);
|
|
|
|
|
2016-05-03 02:06:50 +02:00
|
|
|
GetConsoleScreenBufferInfo(std_output, &csbi);
|
|
|
|
orig_sb_size = csbi.dwSize;
|
|
|
|
tmp_sb_size.X = csbi.dwSize.X + 3;
|
|
|
|
tmp_sb_size.Y = csbi.dwSize.Y + 5;
|
|
|
|
SetConsoleScreenBufferSize(std_output, tmp_sb_size);
|
|
|
|
|
2016-04-26 14:06:51 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(NULL, FALSE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2019-11-06 16:45:34 +01:00
|
|
|
if (GetLastError() == LOWORD(E_NOTIMPL) /* win10 1709+ */ ||
|
|
|
|
broken(GetLastError() == ERROR_GEN_FAILURE) /* win10 1607 */)
|
|
|
|
{
|
|
|
|
skip("GetConsoleFontInfo is not implemented\n");
|
|
|
|
SetConsoleScreenBufferSize(std_output, orig_sb_size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cfi);
|
|
|
|
return;
|
|
|
|
}
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-04-26 14:06:51 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(GetStdHandle(STD_INPUT_HANDLE), FALSE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-04-26 14:06:51 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(std_output, FALSE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2016-04-26 14:06:51 +02:00
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo(std_output, &csbi);
|
|
|
|
win_width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
|
|
|
win_height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
|
|
|
|
|
|
|
GetCurrentConsoleFont(std_output, FALSE, &cfi[0]);
|
|
|
|
index = cfi[0].nFont;
|
|
|
|
orig_font = GetConsoleFontSize(std_output, index);
|
|
|
|
|
2016-05-03 02:06:50 +02:00
|
|
|
memset(cfi, 0, memsize);
|
2016-04-26 14:06:51 +02:00
|
|
|
ret = pGetConsoleFontInfo(std_output, FALSE, num_fonts, cfi);
|
2019-11-06 16:46:09 +01:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
|
|
|
ok(cfi[index].dwFontSize.X == win_width, "got %d, expected %d\n",
|
|
|
|
cfi[index].dwFontSize.X, win_width);
|
|
|
|
ok(cfi[index].dwFontSize.Y == win_height, "got %d, expected %d\n",
|
|
|
|
cfi[index].dwFontSize.Y, win_height);
|
2016-04-26 14:06:51 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_fonts; i++)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(cfi[i].nFont == i, "element out of order, got nFont %ld, expected %ld\n", cfi[i].nFont, i);
|
2016-04-26 14:06:51 +02:00
|
|
|
tmp_font = GetConsoleFontSize(std_output, cfi[i].nFont);
|
|
|
|
tmp_w = (double)orig_font.X / tmp_font.X * win_width;
|
|
|
|
tmp_h = (double)orig_font.Y / tmp_font.Y * win_height;
|
2019-11-06 16:46:09 +01:00
|
|
|
ok(cfi[i].dwFontSize.X == tmp_w, "got %d, expected %d\n", cfi[i].dwFontSize.X, tmp_w);
|
|
|
|
ok(cfi[i].dwFontSize.Y == tmp_h, "got %d, expected %d\n", cfi[i].dwFontSize.Y, tmp_h);
|
2016-04-26 14:06:51 +02:00
|
|
|
}
|
2016-05-03 02:06:50 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(NULL, TRUE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-05-03 02:06:50 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(GetStdHandle(STD_INPUT_HANDLE), TRUE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-05-03 02:06:50 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleFontInfo(std_output, TRUE, 0, cfi);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2016-05-03 02:06:50 +02:00
|
|
|
|
|
|
|
memset(cfi, 0, memsize);
|
|
|
|
ret = pGetConsoleFontInfo(std_output, TRUE, num_fonts, cfi);
|
2019-11-06 16:46:09 +01:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
|
|
|
ok(cfi[index].dwFontSize.X == csbi.dwMaximumWindowSize.X, "got %d, expected %d\n",
|
|
|
|
cfi[index].dwFontSize.X, csbi.dwMaximumWindowSize.X);
|
|
|
|
ok(cfi[index].dwFontSize.Y == csbi.dwMaximumWindowSize.Y, "got %d, expected %d\n",
|
|
|
|
cfi[index].dwFontSize.Y, csbi.dwMaximumWindowSize.Y);
|
2016-05-03 02:06:50 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_fonts; i++)
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(cfi[i].nFont == i, "element out of order, got nFont %ld, expected %ld\n", cfi[i].nFont, i);
|
2016-05-03 02:06:50 +02:00
|
|
|
tmp_font = GetConsoleFontSize(std_output, cfi[i].nFont);
|
|
|
|
tmp_w = (double)orig_font.X / tmp_font.X * csbi.dwMaximumWindowSize.X;
|
|
|
|
tmp_h = (double)orig_font.Y / tmp_font.Y * csbi.dwMaximumWindowSize.Y;
|
2019-11-06 16:46:09 +01:00
|
|
|
ok(cfi[i].dwFontSize.X == tmp_w, "got %d, expected %d\n", cfi[i].dwFontSize.X, tmp_w);
|
|
|
|
ok(cfi[i].dwFontSize.Y == tmp_h, "got %d, expected %d\n", cfi[i].dwFontSize.Y, tmp_h);
|
2016-05-03 02:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cfi);
|
|
|
|
SetConsoleScreenBufferSize(std_output, orig_sb_size);
|
2016-04-26 14:06:51 +02:00
|
|
|
}
|
|
|
|
|
2016-05-03 02:07:01 +02:00
|
|
|
static void test_SetConsoleFont(HANDLE std_output)
|
|
|
|
{
|
|
|
|
HANDLE hmod;
|
|
|
|
BOOL (WINAPI *pSetConsoleFont)(HANDLE, DWORD);
|
|
|
|
BOOL ret;
|
|
|
|
DWORD (WINAPI *pGetNumberOfConsoleFonts)(void);
|
|
|
|
DWORD num_fonts;
|
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pSetConsoleFont = (void *)GetProcAddress(hmod, "SetConsoleFont");
|
|
|
|
if (!pSetConsoleFont)
|
|
|
|
{
|
|
|
|
win_skip("SetConsoleFont is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleFont(NULL, 0);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2019-11-14 00:29:46 +01:00
|
|
|
if (GetLastError() == LOWORD(E_NOTIMPL) /* win10 1709+ */ ||
|
|
|
|
broken(GetLastError() == ERROR_GEN_FAILURE) /* win10 1607 */)
|
|
|
|
{
|
|
|
|
skip("SetConsoleFont is not implemented\n");
|
|
|
|
return;
|
|
|
|
}
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-05-03 02:07:01 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleFont(GetStdHandle(STD_INPUT_HANDLE), 0);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-05-03 02:07:01 +02:00
|
|
|
|
|
|
|
pGetNumberOfConsoleFonts = (void *)GetProcAddress(hmod, "GetNumberOfConsoleFonts");
|
|
|
|
if (!pGetNumberOfConsoleFonts)
|
|
|
|
{
|
|
|
|
win_skip("GetNumberOfConsoleFonts is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_fonts = pGetNumberOfConsoleFonts();
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleFont(std_output, num_fonts);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2016-05-03 02:07:01 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 03:35:39 +02:00
|
|
|
static void test_GetConsoleScreenBufferInfoEx(HANDLE std_output)
|
|
|
|
{
|
|
|
|
HANDLE hmod;
|
|
|
|
BOOL (WINAPI *pGetConsoleScreenBufferInfoEx)(HANDLE, CONSOLE_SCREEN_BUFFER_INFOEX *);
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFOEX csbix;
|
2020-07-09 19:27:57 +02:00
|
|
|
HANDLE pipe1, pipe2;
|
2016-08-17 03:35:39 +02:00
|
|
|
BOOL ret;
|
|
|
|
HANDLE std_input = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pGetConsoleScreenBufferInfoEx = (void *)GetProcAddress(hmod, "GetConsoleScreenBufferInfoEx");
|
|
|
|
if (!pGetConsoleScreenBufferInfoEx)
|
|
|
|
{
|
|
|
|
win_skip("GetConsoleScreenBufferInfoEx is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(NULL, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(std_input, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(std_output, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
|
|
|
|
csbix.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(NULL, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(std_input, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
|
2020-07-09 19:27:57 +02:00
|
|
|
CreatePipe(&pipe1, &pipe2, NULL, 0);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(std_input, &csbix);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-07-09 19:27:57 +02:00
|
|
|
CloseHandle(pipe1);
|
|
|
|
CloseHandle(pipe2);
|
|
|
|
|
2016-08-17 03:35:39 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetConsoleScreenBufferInfoEx(std_output, &csbix);
|
2016-08-17 03:35:53 +02:00
|
|
|
ok(ret, "got %d, expected non-zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2016-08-17 03:35:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:30 +02:00
|
|
|
static void test_FreeConsole(void)
|
|
|
|
{
|
2020-11-27 18:13:59 +01:00
|
|
|
HANDLE handle, unbound_output = NULL, unbound_input = NULL;
|
2020-11-27 18:14:22 +01:00
|
|
|
DWORD size, mode, type;
|
2020-08-14 13:27:10 +02:00
|
|
|
WCHAR title[16];
|
2020-11-27 18:13:59 +01:00
|
|
|
char buf[32];
|
2020-08-14 13:27:20 +02:00
|
|
|
HWND hwnd;
|
2020-08-14 13:26:53 +02:00
|
|
|
UINT cp;
|
2020-06-25 22:26:30 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2020-08-13 16:00:27 +02:00
|
|
|
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
|
2021-12-17 14:13:46 +01:00
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "dummy ctrl handler shouldn't be set\n");
|
|
|
|
ret = SetConsoleCtrlHandler(mydummych, TRUE);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleCtrlHandler failed: %lu\n", GetLastError());
|
2020-11-27 18:13:59 +01:00
|
|
|
if (!skip_nt)
|
|
|
|
{
|
|
|
|
unbound_input = create_unbound_handle(FALSE, TRUE);
|
|
|
|
unbound_output = create_unbound_handle(TRUE, TRUE);
|
|
|
|
}
|
2020-08-13 16:00:27 +02:00
|
|
|
|
2020-06-25 22:26:30 +02:00
|
|
|
ret = FreeConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "FreeConsole failed: %lu\n", GetLastError());
|
2020-06-25 22:26:30 +02:00
|
|
|
|
2020-08-13 16:00:27 +02:00
|
|
|
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == NULL, "ConsoleHandle = %p\n",
|
|
|
|
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle);
|
|
|
|
|
2020-06-25 22:26:30 +02:00
|
|
|
handle = CreateFileA("CONOUT$", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(handle == INVALID_HANDLE_VALUE &&
|
|
|
|
(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_ACCESS_DENIED /* winxp */)),
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileA failed: %lu\n", GetLastError());
|
2020-06-25 22:26:30 +02:00
|
|
|
|
|
|
|
handle = CreateFileA("CONIN$", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(handle == INVALID_HANDLE_VALUE &&
|
|
|
|
(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_ACCESS_DENIED /* winxp */)),
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileA failed: %lu\n", GetLastError());
|
2020-06-25 22:26:30 +02:00
|
|
|
|
|
|
|
handle = CreateFileA("CON", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(handle == INVALID_HANDLE_VALUE &&
|
|
|
|
(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_ACCESS_DENIED /* winxp */)),
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileA failed: %lu\n", GetLastError());
|
2020-06-25 22:26:30 +02:00
|
|
|
|
|
|
|
handle = CreateFileA("CON", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(handle == INVALID_HANDLE_VALUE &&
|
|
|
|
(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_FILE_NOT_FOUND /* winxp */)),
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateFileA failed: %lu\n", GetLastError());
|
2020-07-01 16:27:22 +02:00
|
|
|
|
2020-07-21 14:57:06 +02:00
|
|
|
handle = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
|
|
|
ok(handle == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"CreateConsoleScreenBuffer returned: %p (%lu)\n", handle, GetLastError());
|
2020-07-21 14:57:06 +02:00
|
|
|
|
2020-08-14 13:26:53 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
cp = GetConsoleCP();
|
|
|
|
ok(!cp, "cp = %x\n", cp);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %lu\n", GetLastError());
|
2020-08-14 13:26:53 +02:00
|
|
|
|
2020-08-14 13:27:00 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
cp = GetConsoleOutputCP();
|
|
|
|
ok(!cp, "cp = %x\n", cp);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %lu\n", GetLastError());
|
2020-08-14 13:27:00 +02:00
|
|
|
|
2020-08-17 15:07:21 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleCP(GetOEMCP());
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "SetConsoleCP returned %x(%lu)\n", ret, GetLastError());
|
2020-08-17 15:07:21 +02:00
|
|
|
|
2020-08-17 15:07:30 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleOutputCP(GetOEMCP());
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "SetConsoleCP returned %x(%lu)\n", ret, GetLastError());
|
2020-08-17 15:07:30 +02:00
|
|
|
|
2020-09-08 19:35:31 +02:00
|
|
|
if (skip_nt) return;
|
|
|
|
|
2020-08-14 13:27:10 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset( title, 0xc0, sizeof(title) );
|
|
|
|
size = GetConsoleTitleW( title, ARRAY_SIZE(title) );
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!size, "GetConsoleTitleW returned %lu\n", size);
|
2020-08-14 13:27:10 +02:00
|
|
|
ok(title[0] == 0xc0c0, "title byffer changed\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %lu\n", GetLastError());
|
2020-08-14 13:27:10 +02:00
|
|
|
|
2020-08-17 15:07:39 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleTitleW( L"test" );
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "SetConsoleTitleW returned %x(%lu)\n", ret, GetLastError());
|
2020-08-17 15:07:39 +02:00
|
|
|
|
2020-08-14 13:27:20 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hwnd = GetConsoleWindow();
|
|
|
|
ok(!hwnd, "hwnd = %p\n", hwnd);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %lu\n", GetLastError());
|
2020-08-14 13:27:20 +02:00
|
|
|
|
2020-09-01 15:36:05 +02:00
|
|
|
ret = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "GenerateConsoleCtrlEvent returned %x(%lu)\n",
|
2020-09-01 15:36:05 +02:00
|
|
|
ret, GetLastError());
|
|
|
|
|
2020-09-01 15:35:33 +02:00
|
|
|
SetStdHandle( STD_INPUT_HANDLE, (HANDLE)0xdeadbeef );
|
|
|
|
handle = GetConsoleInputWaitHandle();
|
|
|
|
ok(handle == (HANDLE)0xdeadbeef, "GetConsoleInputWaitHandle returned %p\n", handle);
|
|
|
|
SetStdHandle( STD_INPUT_HANDLE, NULL );
|
|
|
|
handle = GetConsoleInputWaitHandle();
|
|
|
|
ok(!handle, "GetConsoleInputWaitHandle returned %p\n", handle);
|
2020-11-12 19:56:30 +01:00
|
|
|
|
2020-11-27 18:13:59 +01:00
|
|
|
ret = ReadFile(unbound_input, buf, sizeof(buf), &size, NULL);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadFile returned %x %lu\n", ret, GetLastError());
|
2020-11-27 18:13:59 +01:00
|
|
|
|
|
|
|
ret = FlushFileBuffers(unbound_input);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadFile returned %x %lu\n", ret, GetLastError());
|
2020-11-27 18:13:59 +01:00
|
|
|
|
2020-11-27 18:14:12 +01:00
|
|
|
ret = WriteFile(unbound_input, "test", 4, &size, NULL);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"ReadFile returned %x %lu\n", ret, GetLastError());
|
2020-11-27 18:14:12 +01:00
|
|
|
|
|
|
|
ret = GetConsoleMode(unbound_input, &mode);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetConsoleMode returned %x %lu\n", ret, GetLastError());
|
2020-11-12 19:56:30 +01:00
|
|
|
ret = GetConsoleMode(unbound_output, &mode);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetConsoleMode returned %x %lu\n", ret, GetLastError());
|
2020-11-12 19:56:30 +01:00
|
|
|
|
2020-11-27 18:14:22 +01:00
|
|
|
type = GetFileType(unbound_input);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(type == FILE_TYPE_CHAR, "GetFileType returned %lu\n", type);
|
2020-11-27 18:14:22 +01:00
|
|
|
type = GetFileType(unbound_output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(type == FILE_TYPE_CHAR, "GetFileType returned %lu\n", type);
|
2020-11-27 18:14:22 +01:00
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
todo_wine
|
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "FreeConsole() should have reset ctrl handlers' list\n");
|
|
|
|
|
2020-11-27 18:13:59 +01:00
|
|
|
CloseHandle(unbound_input);
|
2020-11-12 19:56:30 +01:00
|
|
|
CloseHandle(unbound_output);
|
2020-06-25 22:26:30 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 08:47:51 +01:00
|
|
|
static void test_SetConsoleScreenBufferInfoEx(HANDLE std_output)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE hmod;
|
|
|
|
HANDLE std_input = CreateFileA("CONIN$", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
BOOL (WINAPI *pSetConsoleScreenBufferInfoEx)(HANDLE, CONSOLE_SCREEN_BUFFER_INFOEX *);
|
|
|
|
BOOL (WINAPI *pGetConsoleScreenBufferInfoEx)(HANDLE, CONSOLE_SCREEN_BUFFER_INFOEX *);
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFOEX info;
|
|
|
|
|
|
|
|
hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
pSetConsoleScreenBufferInfoEx = (void *)GetProcAddress(hmod, "SetConsoleScreenBufferInfoEx");
|
|
|
|
pGetConsoleScreenBufferInfoEx = (void *)GetProcAddress(hmod, "GetConsoleScreenBufferInfoEx");
|
|
|
|
if (!pSetConsoleScreenBufferInfoEx || !pGetConsoleScreenBufferInfoEx)
|
|
|
|
{
|
|
|
|
win_skip("SetConsoleScreenBufferInfoEx is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFOEX));
|
|
|
|
info.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
|
|
|
|
pGetConsoleScreenBufferInfoEx(std_output, &info);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleScreenBufferInfoEx(NULL, &info);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "got %lu, expected 6\n", GetLastError());
|
2020-03-04 08:47:51 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleScreenBufferInfoEx(std_output, &info);
|
2020-03-04 08:47:52 +01:00
|
|
|
ok(ret, "got %d, expected one\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "got %lu, expected 0xdeadbeef\n", GetLastError());
|
2020-03-04 08:47:51 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleScreenBufferInfoEx(std_input, &info);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2020-03-04 08:47:52 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE || GetLastError() == ERROR_ACCESS_DENIED,
|
2022-03-02 09:03:21 +01:00
|
|
|
"got %lu, expected 5 or 6\n", GetLastError());
|
2020-03-04 08:47:51 +01:00
|
|
|
|
|
|
|
info.cbSize = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pSetConsoleScreenBufferInfoEx(std_output, &info);
|
|
|
|
ok(!ret, "got %d, expected zero\n", ret);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %lu, expected 87\n", GetLastError());
|
2020-03-04 08:47:51 +01:00
|
|
|
|
|
|
|
CloseHandle(std_input);
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:10:45 +02:00
|
|
|
static void test_console_title(void)
|
|
|
|
{
|
|
|
|
WCHAR buf[64];
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = SetConsoleTitleW(L"test");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleTitleW failed: %lu\n", GetLastError());
|
2020-08-12 15:10:45 +02:00
|
|
|
|
|
|
|
ret = GetConsoleTitleW(buf, ARRAY_SIZE(buf));
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleTitleW failed: %lu\n", GetLastError());
|
2020-08-12 15:10:45 +02:00
|
|
|
ok(!wcscmp(buf, L"test"), "title = %s\n", wine_dbgstr_w(buf));
|
|
|
|
|
|
|
|
if (!skip_nt)
|
|
|
|
{
|
|
|
|
ret = GetConsoleTitleW(buf, 2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleTitleW failed: %lu\n", GetLastError());
|
2020-08-12 15:10:45 +02:00
|
|
|
ok(!wcscmp(buf, L"t"), "title = %s\n", wine_dbgstr_w(buf));
|
|
|
|
|
|
|
|
ret = GetConsoleTitleW(buf, 4);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleTitleW failed: %lu\n", GetLastError());
|
2020-08-12 15:10:45 +02:00
|
|
|
ok(!wcscmp(buf, L"tes"), "title = %s\n", wine_dbgstr_w(buf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 15:39:44 +01:00
|
|
|
static void test_file_info(HANDLE input, HANDLE output)
|
|
|
|
{
|
|
|
|
FILE_STANDARD_INFORMATION std_info;
|
2020-11-20 15:40:19 +01:00
|
|
|
FILE_FS_DEVICE_INFORMATION fs_info;
|
2020-11-20 15:39:44 +01:00
|
|
|
LARGE_INTEGER size;
|
|
|
|
IO_STATUS_BLOCK io;
|
2020-11-20 15:40:19 +01:00
|
|
|
DWORD type;
|
2020-11-20 15:39:44 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (skip_nt) return;
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(input, &io, &std_info, sizeof(std_info), FileStandardInformation);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(status == STATUS_INVALID_DEVICE_REQUEST, "NtQueryInformationFile returned: %#lx\n", status);
|
2020-11-20 15:39:44 +01:00
|
|
|
|
|
|
|
status = NtQueryInformationFile(output, &io, &std_info, sizeof(std_info), FileStandardInformation);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(status == STATUS_INVALID_DEVICE_REQUEST, "NtQueryInformationFile returned: %#lx\n", status);
|
2020-11-20 15:39:44 +01:00
|
|
|
|
|
|
|
ret = GetFileSizeEx(input, &size);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_FUNCTION,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetFileSizeEx returned %x(%lu)\n", ret, GetLastError());
|
2020-11-20 15:39:44 +01:00
|
|
|
|
|
|
|
ret = GetFileSizeEx(output, &size);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_FUNCTION,
|
2022-03-02 09:03:21 +01:00
|
|
|
"GetFileSizeEx returned %x(%lu)\n", ret, GetLastError());
|
2020-11-20 15:40:19 +01:00
|
|
|
|
|
|
|
status = NtQueryVolumeInformationFile(input, &io, &fs_info, sizeof(fs_info), FileFsDeviceInformation);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!status, "NtQueryVolumeInformationFile failed: %#lx\n", status);
|
|
|
|
ok(fs_info.DeviceType == FILE_DEVICE_CONSOLE, "DeviceType = %lu\n", fs_info.DeviceType);
|
2020-11-20 15:40:19 +01:00
|
|
|
ok(fs_info.Characteristics == FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Characteristics = %lx\n", fs_info.Characteristics);
|
2020-11-20 15:40:19 +01:00
|
|
|
|
|
|
|
status = NtQueryVolumeInformationFile(output, &io, &fs_info, sizeof(fs_info), FileFsDeviceInformation);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!status, "NtQueryVolumeInformationFile failed: %#lx\n", status);
|
|
|
|
ok(fs_info.DeviceType == FILE_DEVICE_CONSOLE, "DeviceType = %lu\n", fs_info.DeviceType);
|
2020-11-20 15:40:19 +01:00
|
|
|
ok(fs_info.Characteristics == FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL,
|
2022-03-02 09:03:21 +01:00
|
|
|
"Characteristics = %lx\n", fs_info.Characteristics);
|
2020-11-20 15:40:19 +01:00
|
|
|
|
|
|
|
type = GetFileType(input);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(type == FILE_TYPE_CHAR, "GetFileType returned %lu\n", type);
|
2020-11-20 15:40:19 +01:00
|
|
|
type = GetFileType(output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(type == FILE_TYPE_CHAR, "GetFileType returned %lu\n", type);
|
2020-11-20 15:39:44 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
static void test_AttachConsole_child(DWORD console_pid)
|
|
|
|
{
|
|
|
|
HANDLE pipe_in, pipe_out;
|
|
|
|
COORD c = {0,0};
|
|
|
|
HANDLE console;
|
|
|
|
char buf[32];
|
|
|
|
DWORD len;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
res = CreatePipe(&pipe_in, &pipe_out, NULL, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CreatePipe failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
res = AttachConsole(console_pid);
|
|
|
|
ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
|
2022-03-02 09:03:21 +01:00
|
|
|
"AttachConsole returned: %x(%lu)\n", res, GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
2020-08-13 16:00:27 +02:00
|
|
|
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
|
2018-08-09 18:40:49 +02:00
|
|
|
res = FreeConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "FreeConsole failed: %lu\n", GetLastError());
|
2020-08-13 16:00:27 +02:00
|
|
|
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == NULL, "ConsoleHandle = %p\n",
|
|
|
|
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle);
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE, pipe_out);
|
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "dummy ctrl handler shouldn't be set\n");
|
|
|
|
res = SetConsoleCtrlHandler(mydummych, TRUE);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "SetConsoleCtrlHandler failed: %lu\n", GetLastError());
|
2021-12-17 14:13:46 +01:00
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
res = AttachConsole(console_pid);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "AttachConsole failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
ok(pipe_out != GetStdHandle(STD_ERROR_HANDLE), "std handle not set to console\n");
|
2020-08-13 16:00:27 +02:00
|
|
|
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
console = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(console != INVALID_HANDLE_VALUE, "Could not open console\n");
|
|
|
|
|
|
|
|
res = ReadConsoleOutputCharacterA(console, buf, 6, c, &len);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "ReadConsoleOutputCharacterA failed: %lu\n", GetLastError());
|
|
|
|
ok(len == 6, "len = %lu\n", len);
|
2018-08-09 18:40:49 +02:00
|
|
|
ok(!memcmp(buf, "Parent", 6), "Unexpected console output\n");
|
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
todo_wine
|
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "AttachConsole() should have reset ctrl handlers' list\n");
|
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
res = FreeConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "FreeConsole failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
SetStdHandle(STD_INPUT_HANDLE, pipe_in);
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, pipe_out);
|
|
|
|
|
|
|
|
res = AttachConsole(ATTACH_PARENT_PROCESS);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "AttachConsole failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
2022-02-12 12:56:02 +01:00
|
|
|
if (pGetConsoleProcessList)
|
|
|
|
{
|
|
|
|
DWORD list[2] = { 0xbabebabe };
|
|
|
|
DWORD pid = GetCurrentProcessId();
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
len = pGetConsoleProcessList(list, 1);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(len == 2, "Expected 2 processes, got %ld\n", len);
|
|
|
|
ok(list[0] == 0xbabebabe, "Unexpected value in list %lu\n", list[0]);
|
2022-02-12 12:56:02 +01:00
|
|
|
|
|
|
|
len = pGetConsoleProcessList(list, 2);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(len == 2, "Expected 2 processes, got %ld\n", len);
|
2022-02-12 12:56:02 +01:00
|
|
|
ok(list[0] == console_pid || list[1] == console_pid, "Parent PID not in list\n");
|
|
|
|
ok(list[0] == pid || list[1] == pid, "PID not in list\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Unexpected last error: %lu\n", GetLastError());
|
2022-02-12 12:56:02 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
ok(pipe_in != GetStdHandle(STD_INPUT_HANDLE), "std handle not set to console\n");
|
|
|
|
ok(pipe_out != GetStdHandle(STD_OUTPUT_HANDLE), "std handle not set to console\n");
|
|
|
|
|
|
|
|
console = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(console != INVALID_HANDLE_VALUE, "Could not open console\n");
|
|
|
|
|
|
|
|
res = ReadConsoleOutputCharacterA(console, buf, 6, c, &len);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "ReadConsoleOutputCharacterA failed: %lu\n", GetLastError());
|
|
|
|
ok(len == 6, "len = %lu\n", len);
|
2018-08-09 18:40:49 +02:00
|
|
|
ok(!memcmp(buf, "Parent", 6), "Unexpected console output\n");
|
|
|
|
|
|
|
|
simple_write_console(console, "Child");
|
|
|
|
CloseHandle(console);
|
|
|
|
|
|
|
|
res = FreeConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "FreeConsole failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
|
|
|
|
res = CloseHandle(pipe_in);
|
|
|
|
ok(res, "pipe_in is no longer valid\n");
|
|
|
|
res = CloseHandle(pipe_out);
|
|
|
|
ok(res, "pipe_out is no longer valid\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_AttachConsole(HANDLE console)
|
|
|
|
{
|
|
|
|
STARTUPINFOA si = { sizeof(si) };
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
char **argv, buf[MAX_PATH];
|
|
|
|
COORD c = {0,0};
|
|
|
|
DWORD len;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
simple_write_console(console, "Parent console");
|
|
|
|
|
|
|
|
winetest_get_mainargs(&argv);
|
2022-03-02 09:03:21 +01:00
|
|
|
sprintf(buf, "\"%s\" console attach_console %lx", argv[0], GetCurrentProcessId());
|
2018-08-09 18:40:49 +02:00
|
|
|
res = CreateProcessA(NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CreateProcess failed: %lu\n", GetLastError());
|
2018-08-09 18:40:49 +02:00
|
|
|
CloseHandle(info.hThread);
|
|
|
|
|
2020-03-16 23:52:21 +01:00
|
|
|
wait_child_process(info.hProcess);
|
2018-08-09 18:40:49 +02:00
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
|
|
|
|
res = ReadConsoleOutputCharacterA(console, buf, 5, c, &len);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "ReadConsoleOutputCharacterA failed: %lu\n", GetLastError());
|
|
|
|
ok(len == 5, "len = %lu\n", len);
|
2018-08-09 18:40:49 +02:00
|
|
|
ok(!memcmp(buf, "Child", 5), "Unexpected console output\n");
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:16:30 +02:00
|
|
|
static void test_AllocConsole_child(void)
|
|
|
|
{
|
|
|
|
HANDLE unbound_output;
|
|
|
|
HANDLE prev_output, prev_error;
|
|
|
|
STARTUPINFOW si;
|
|
|
|
DWORD mode;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
GetStartupInfoW(&si);
|
|
|
|
|
|
|
|
prev_output = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
res = DuplicateHandle(GetCurrentProcess(), prev_output, GetCurrentProcess(), &unbound_output,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "DuplicateHandle failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
res = GetConsoleMode(unbound_output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
prev_error = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
if (si.dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
|
|
|
res = GetConsoleMode(prev_error, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FreeConsole();
|
|
|
|
|
|
|
|
ok(GetStdHandle(STD_OUTPUT_HANDLE) == prev_output, "GetStdHandle(STD_OUTPUT_HANDLE) = %p\n", GetStdHandle(STD_OUTPUT_HANDLE));
|
|
|
|
ok(GetStdHandle(STD_ERROR_HANDLE) == prev_error, "GetStdHandle(STD_ERROR_HANDLE) = %p\n", GetStdHandle(STD_ERROR_HANDLE));
|
|
|
|
res = GetConsoleMode(unbound_output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "dummy ctrl handler shouldn't be set\n");
|
|
|
|
res = SetConsoleCtrlHandler(mydummych, TRUE);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "SetConsoleCtrlHandler failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
res = AllocConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "AllocConsole failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
if (si.dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
|
|
|
ok(GetStdHandle(STD_OUTPUT_HANDLE) == prev_output, "GetStdHandle(STD_OUTPUT_HANDLE) = %p\n", GetStdHandle(STD_OUTPUT_HANDLE));
|
|
|
|
ok(GetStdHandle(STD_ERROR_HANDLE) == prev_error, "GetStdHandle(STD_ERROR_HANDLE) = %p\n", GetStdHandle(STD_ERROR_HANDLE));
|
|
|
|
}
|
|
|
|
|
|
|
|
res = GetConsoleMode(unbound_output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
2021-12-17 14:13:46 +01:00
|
|
|
todo_wine
|
|
|
|
ok(!SetConsoleCtrlHandler(mydummych, FALSE), "AllocConsole() should have reset ctrl handlers' list\n");
|
|
|
|
|
2020-07-30 17:16:30 +02:00
|
|
|
FreeConsole();
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, NULL);
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE, NULL);
|
|
|
|
res = AllocConsole();
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "AllocConsole failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
ok(GetStdHandle(STD_OUTPUT_HANDLE) != NULL, "GetStdHandle(STD_OUTPUT_HANDLE) = %p\n", GetStdHandle(STD_OUTPUT_HANDLE));
|
|
|
|
ok(GetStdHandle(STD_ERROR_HANDLE) != NULL, "GetStdHandle(STD_ERROR_HANDLE) = %p\n", GetStdHandle(STD_ERROR_HANDLE));
|
|
|
|
|
|
|
|
res = GetConsoleMode(unbound_output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
res = GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
res = GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
res = CloseHandle(unbound_output);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CloseHandle failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_AllocConsole(void)
|
|
|
|
{
|
|
|
|
SECURITY_ATTRIBUTES inheritable_attr = { sizeof(inheritable_attr), NULL, TRUE };
|
|
|
|
STARTUPINFOA si = { sizeof(si) };
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
char **argv, buf[MAX_PATH];
|
|
|
|
HANDLE pipe_read, pipe_write;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
if (skip_nt) return;
|
|
|
|
|
|
|
|
winetest_get_mainargs(&argv);
|
2021-09-14 21:33:26 +02:00
|
|
|
sprintf(buf, "\"%s\" console alloc_console", argv[0]);
|
2020-07-30 17:16:30 +02:00
|
|
|
res = CreateProcessA(NULL, buf, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CreateProcess failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
CloseHandle(info.hThread);
|
|
|
|
wait_child_process(info.hProcess);
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
|
|
|
|
res = CreatePipe(&pipe_read, &pipe_write, &inheritable_attr, 0);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CreatePipe failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
si.hStdError = pipe_write;
|
|
|
|
res = CreateProcessA(NULL, buf, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(res, "CreateProcess failed: %lu\n", GetLastError());
|
2020-07-30 17:16:30 +02:00
|
|
|
CloseHandle(info.hThread);
|
|
|
|
wait_child_process(info.hProcess);
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
|
|
|
|
CloseHandle(pipe_read);
|
|
|
|
CloseHandle(pipe_write);
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:05:25 +02:00
|
|
|
static void test_pseudo_console_child(HANDLE input, HANDLE output)
|
2020-08-24 13:20:53 +02:00
|
|
|
{
|
2020-10-06 18:54:03 +02:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sb_info;
|
|
|
|
CONSOLE_CURSOR_INFO cursor_info;
|
2020-08-24 13:20:53 +02:00
|
|
|
DWORD mode;
|
2021-08-17 12:29:23 +02:00
|
|
|
HWND hwnd;
|
2020-08-24 13:20:53 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = GetConsoleMode(input, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-24 13:20:53 +02:00
|
|
|
ok(mode == (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT |
|
|
|
|
ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS | ENABLE_AUTO_POSITION),
|
2022-03-02 09:03:21 +01:00
|
|
|
"mode = %lx\n", mode);
|
2020-08-24 13:20:53 +02:00
|
|
|
|
|
|
|
ret = SetConsoleMode(input, mode & ~ENABLE_AUTO_POSITION);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-24 13:20:53 +02:00
|
|
|
|
|
|
|
ret = GetConsoleMode(input, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-24 13:20:53 +02:00
|
|
|
ok(mode == (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT |
|
2022-03-02 09:03:21 +01:00
|
|
|
ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS), "mode = %lx\n", mode);
|
2020-08-24 13:20:53 +02:00
|
|
|
|
|
|
|
ret = SetConsoleMode(input, mode | ENABLE_AUTO_POSITION);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-24 13:21:56 +02:00
|
|
|
|
2020-08-27 15:05:25 +02:00
|
|
|
ret = GetConsoleMode(output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleMode failed: %lu\n", GetLastError());
|
2020-09-11 14:31:32 +02:00
|
|
|
mode &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(mode == (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT), "mode = %lx\n", mode);
|
2020-08-27 15:05:25 +02:00
|
|
|
|
2020-08-27 15:05:36 +02:00
|
|
|
ret = SetConsoleMode(output, mode & ~ENABLE_WRAP_AT_EOL_OUTPUT);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-27 15:05:36 +02:00
|
|
|
|
|
|
|
ret = GetConsoleMode(output, &mode);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleMode failed: %lu\n", GetLastError());
|
|
|
|
ok(mode == ENABLE_PROCESSED_OUTPUT, "mode = %lx\n", mode);
|
2020-08-27 15:05:36 +02:00
|
|
|
|
|
|
|
ret = SetConsoleMode(output, mode | ENABLE_WRAP_AT_EOL_OUTPUT);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "SetConsoleMode failed: %lu\n", GetLastError());
|
2020-08-27 15:05:36 +02:00
|
|
|
|
2020-10-06 18:54:03 +02:00
|
|
|
ret = GetConsoleScreenBufferInfo(output, &sb_info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleScreenBufferInfo failed: %lu\n", GetLastError());
|
2020-10-06 18:54:03 +02:00
|
|
|
ok(sb_info.dwSize.X == 40, "dwSize.X = %u\n", sb_info.dwSize.X);
|
|
|
|
ok(sb_info.dwSize.Y == 30, "dwSize.Y = %u\n", sb_info.dwSize.Y);
|
|
|
|
ok(sb_info.dwCursorPosition.X == 0, "dwCursorPosition.X = %u\n", sb_info.dwCursorPosition.X);
|
|
|
|
ok(sb_info.dwCursorPosition.Y == 0, "dwCursorPosition.Y = %u\n", sb_info.dwCursorPosition.Y);
|
|
|
|
ok(sb_info.wAttributes == 7, "wAttributes = %x\n", sb_info.wAttributes);
|
|
|
|
ok(sb_info.srWindow.Left == 0, "srWindow.Left = %u\n", sb_info.srWindow.Left);
|
|
|
|
ok(sb_info.srWindow.Top == 0, "srWindow.Top = %u\n", sb_info.srWindow.Top);
|
|
|
|
ok(sb_info.srWindow.Right == 39, "srWindow.Right = %u\n", sb_info.srWindow.Right);
|
|
|
|
ok(sb_info.srWindow.Bottom == 29, "srWindow.Bottom = %u\n", sb_info.srWindow.Bottom);
|
|
|
|
ok(sb_info.dwMaximumWindowSize.X == 40, "dwMaximumWindowSize.X = %u\n", sb_info.dwMaximumWindowSize.X);
|
|
|
|
ok(sb_info.dwMaximumWindowSize.Y == 30, "dwMaximumWindowSize.Y = %u\n", sb_info.dwMaximumWindowSize.Y);
|
|
|
|
|
|
|
|
ret = GetConsoleCursorInfo(output, &cursor_info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "GetConsoleCursorInfo failed: %lu\n", GetLastError());
|
|
|
|
ok(cursor_info.dwSize == 25, "dwSize = %lu\n", cursor_info.dwSize);
|
2020-10-06 18:54:03 +02:00
|
|
|
ok(cursor_info.bVisible == TRUE, "bVisible = %x\n", cursor_info.bVisible);
|
|
|
|
|
2021-08-17 12:29:23 +02:00
|
|
|
hwnd = GetConsoleWindow();
|
|
|
|
ok(IsWindow(hwnd), "no console window\n");
|
|
|
|
|
2020-08-24 13:21:56 +02:00
|
|
|
test_console_title();
|
2020-08-25 14:52:58 +02:00
|
|
|
test_WriteConsoleInputW(input);
|
2020-08-24 13:20:53 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:49:09 +02:00
|
|
|
static DWORD WINAPI read_pipe_proc( void *handle )
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
DWORD size;
|
|
|
|
while (ReadFile(handle, buf, sizeof(buf), &size, NULL));
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(GetLastError() == ERROR_BROKEN_PIPE, "ReadFile returned %lu\n", GetLastError());
|
2020-08-20 23:49:09 +02:00
|
|
|
CloseHandle(handle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pseudo_console(void)
|
|
|
|
{
|
2020-08-20 23:49:22 +02:00
|
|
|
STARTUPINFOEXA startup = {{ sizeof(startup) }};
|
2020-08-20 23:49:09 +02:00
|
|
|
HANDLE console_pipe, console_pipe2, thread;
|
2020-08-20 23:49:22 +02:00
|
|
|
char **argv, cmdline[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2020-08-20 23:49:09 +02:00
|
|
|
HPCON pseudo_console;
|
2020-08-20 23:49:22 +02:00
|
|
|
SIZE_T attr_size;
|
2020-08-20 23:49:09 +02:00
|
|
|
COORD size;
|
2020-08-20 23:49:22 +02:00
|
|
|
BOOL ret;
|
2020-08-20 23:49:09 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if (!pCreatePseudoConsole)
|
|
|
|
{
|
|
|
|
win_skip("CreatePseudoConsole not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console_pipe = CreateNamedPipeW(L"\\\\.\\pipe\\pseudoconsoleconn", PIPE_ACCESS_DUPLEX,
|
|
|
|
PIPE_WAIT | PIPE_TYPE_BYTE, 1, 4096, 4096, NMPWAIT_USE_DEFAULT_WAIT, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(console_pipe != INVALID_HANDLE_VALUE, "CreateNamedPipeW failed: %lu\n", GetLastError());
|
2020-08-20 23:49:09 +02:00
|
|
|
|
|
|
|
console_pipe2 = CreateFileW(L"\\\\.\\pipe\\pseudoconsoleconn", GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(console_pipe2 != INVALID_HANDLE_VALUE, "CreateFile failed: %lu\n", GetLastError());
|
2020-08-20 23:49:09 +02:00
|
|
|
|
|
|
|
thread = CreateThread( NULL, 0, read_pipe_proc, console_pipe, 0, NULL );
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
size.X = 0;
|
|
|
|
size.Y = 30;
|
|
|
|
hres = pCreatePseudoConsole(size, console_pipe2, console_pipe2, 0, &pseudo_console);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hres == E_INVALIDARG, "CreatePseudoConsole failed: %08lx\n", hres);
|
2020-08-20 23:49:09 +02:00
|
|
|
|
|
|
|
size.X = 40;
|
|
|
|
size.Y = 0;
|
|
|
|
hres = pCreatePseudoConsole(size, console_pipe2, console_pipe2, 0, &pseudo_console);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hres == E_INVALIDARG, "CreatePseudoConsole failed: %08lx\n", hres);
|
2020-08-20 23:49:09 +02:00
|
|
|
|
|
|
|
size.X = 40;
|
|
|
|
size.Y = 30;
|
|
|
|
hres = pCreatePseudoConsole(size, console_pipe2, console_pipe2, 0, &pseudo_console);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(hres == S_OK, "CreatePseudoConsole failed: %08lx\n", hres);
|
2020-08-20 23:49:09 +02:00
|
|
|
CloseHandle(console_pipe2);
|
|
|
|
|
2020-08-20 23:49:22 +02:00
|
|
|
InitializeProcThreadAttributeList(NULL, 1, 0, &attr_size);
|
|
|
|
startup.lpAttributeList = HeapAlloc(GetProcessHeap(), 0, attr_size);
|
|
|
|
InitializeProcThreadAttributeList(startup.lpAttributeList, 1, 0, &attr_size);
|
|
|
|
UpdateProcThreadAttribute(startup.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, pseudo_console,
|
|
|
|
sizeof(pseudo_console), NULL, NULL);
|
|
|
|
|
|
|
|
winetest_get_mainargs(&argv);
|
|
|
|
sprintf(cmdline, "\"%s\" %s --pseudo-console", argv[0], argv[1]);
|
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, EXTENDED_STARTUPINFO_PRESENT, NULL, NULL, &startup.StartupInfo, &info);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(ret, "CreateProcessW failed: %lu\n", GetLastError());
|
2020-08-20 23:49:22 +02:00
|
|
|
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
HeapFree(GetProcessHeap(), 0, startup.lpAttributeList);
|
|
|
|
wait_child_process(info.hProcess);
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
|
2020-08-20 23:49:09 +02:00
|
|
|
pClosePseudoConsole(pseudo_console);
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:27:10 +01:00
|
|
|
/* copy an executable, but changing its subsystem */
|
|
|
|
static void copy_change_subsystem(const char* in, const char* out, DWORD subsyst)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE hFile, hMap;
|
|
|
|
void* mapping;
|
|
|
|
IMAGE_NT_HEADERS *nthdr;
|
|
|
|
|
|
|
|
ret = CopyFileA(in, out, FALSE);
|
|
|
|
ok(ret, "Failed to copy executable %s in %s (%lu)\n", in, out, GetLastError());
|
|
|
|
|
|
|
|
hFile = CreateFileA(out, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "Couldn't open file %s (%lu)\n", out, GetLastError());
|
|
|
|
hMap = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
|
|
|
|
ok(hMap != NULL, "Couldn't create map (%lu)\n", GetLastError());
|
|
|
|
mapping = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
|
|
|
ok(mapping != NULL, "Couldn't map (%lu)\n", GetLastError());
|
|
|
|
nthdr = RtlImageNtHeader(mapping);
|
|
|
|
ok(nthdr != NULL, "Cannot get NT headers out of %s\n", out);
|
|
|
|
if (nthdr) nthdr->OptionalHeader.Subsystem = subsyst;
|
|
|
|
ret = UnmapViewOfFile(mapping);
|
|
|
|
ok(ret, "Couldn't unmap (%lu)\n", GetLastError());
|
|
|
|
CloseHandle(hMap);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL check_whether_child_attached(const char* exec, DWORD flags)
|
|
|
|
{
|
|
|
|
STARTUPINFOA si = { sizeof(si) };
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
DWORD exit_code;
|
|
|
|
BOOL res;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
sprintf(buf, "\"%s\" console check_console", exec);
|
|
|
|
res = CreateProcessA(NULL, buf, NULL, NULL, FALSE, flags, NULL, NULL, &si, &info);
|
|
|
|
ok(res, "CreateProcess failed: %lu %s\n", GetLastError(), buf);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
ret = WaitForSingleObject(info.hProcess, 30000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "Could not wait for the child process: %ld le=%lu\n",
|
|
|
|
ret, GetLastError());
|
|
|
|
ret = GetExitCodeProcess(info.hProcess, &exit_code);
|
|
|
|
ok(ret && exit_code <= 255, "Couldn't get exit_code\n");
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
return exit_code != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CreateProcessCUI(void)
|
|
|
|
{
|
|
|
|
char guiexec[MAX_PATH];
|
|
|
|
char cuiexec[MAX_PATH];
|
|
|
|
char **argv;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
winetest_get_mainargs(&argv);
|
|
|
|
GetTempPathA(ARRAY_SIZE(guiexec), guiexec);
|
|
|
|
strcat(guiexec, "console_gui.exe");
|
|
|
|
copy_change_subsystem(argv[0], guiexec, IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|
|
|
GetTempPathA(ARRAY_SIZE(cuiexec), cuiexec);
|
|
|
|
strcat(cuiexec, "console_cui.exe");
|
|
|
|
copy_change_subsystem(argv[0], cuiexec, IMAGE_SUBSYSTEM_WINDOWS_CUI);
|
|
|
|
|
|
|
|
FreeConsole();
|
|
|
|
|
|
|
|
res = check_whether_child_attached(guiexec, DETACHED_PROCESS);
|
|
|
|
ok(!res, "Don't expecting child to be attached to a console\n");
|
|
|
|
res = check_whether_child_attached(guiexec, 0);
|
|
|
|
ok(!res, "Don't expecting child to be attached to a console\n");
|
|
|
|
res = check_whether_child_attached(cuiexec, DETACHED_PROCESS);
|
|
|
|
ok(!res, "Don't expecting child to be attached to a console\n");
|
|
|
|
res = check_whether_child_attached(cuiexec, 0);
|
2022-03-17 08:27:28 +01:00
|
|
|
ok(res, "Expecting child to be attached to a console\n");
|
2022-03-17 08:27:10 +01:00
|
|
|
|
|
|
|
DeleteFileA(guiexec);
|
|
|
|
DeleteFileA(cuiexec);
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
START_TEST(console)
|
|
|
|
{
|
2020-11-12 19:56:30 +01:00
|
|
|
HANDLE hConIn, hConOut, revert_output = NULL, unbound_output;
|
2020-08-12 15:10:37 +02:00
|
|
|
BOOL ret, test_current;
|
2003-05-13 06:46:54 +02:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
2020-08-20 23:49:22 +02:00
|
|
|
BOOL using_pseudo_console;
|
2011-01-10 12:11:50 +01:00
|
|
|
DWORD size;
|
2018-08-09 18:40:49 +02:00
|
|
|
char **argv;
|
|
|
|
int argc;
|
2003-05-13 06:46:54 +02:00
|
|
|
|
2007-12-05 11:40:05 +01:00
|
|
|
init_function_pointers();
|
|
|
|
|
2018-08-09 18:40:49 +02:00
|
|
|
argc = winetest_get_mainargs(&argv);
|
|
|
|
|
|
|
|
if (argc > 3 && !strcmp(argv[2], "attach_console"))
|
|
|
|
{
|
|
|
|
DWORD parent_pid;
|
2022-03-02 09:03:21 +01:00
|
|
|
sscanf(argv[3], "%lx", &parent_pid);
|
2018-08-09 18:40:49 +02:00
|
|
|
test_AttachConsole_child(parent_pid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:16:30 +02:00
|
|
|
if (argc == 3 && !strcmp(argv[2], "alloc_console"))
|
|
|
|
{
|
|
|
|
test_AllocConsole_child();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:27:10 +01:00
|
|
|
if (argc == 3 && !strcmp(argv[2], "check_console"))
|
|
|
|
{
|
|
|
|
ExitProcess(GetConsoleCP() != 0);
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:10:37 +02:00
|
|
|
test_current = argc >= 3 && !strcmp(argv[2], "--current");
|
2020-08-20 23:49:22 +02:00
|
|
|
using_pseudo_console = argc >= 3 && !strcmp(argv[2], "--pseudo-console");
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2020-08-20 23:49:22 +02:00
|
|
|
if (!test_current && !using_pseudo_console)
|
2020-08-12 15:10:37 +02:00
|
|
|
{
|
|
|
|
static const char font_name[] = "Lucida Console";
|
|
|
|
HKEY console_key;
|
|
|
|
char old_font[LF_FACESIZE];
|
|
|
|
BOOL delete = FALSE;
|
|
|
|
LONG err;
|
|
|
|
|
|
|
|
/* ReadConsoleOutputW doesn't retrieve characters from the output buffer
|
|
|
|
* correctly for characters that don't have a glyph in the console font. So,
|
|
|
|
* we first set the console font to Lucida Console (which has a wider
|
|
|
|
* selection of glyphs available than the default raster fonts). We want
|
|
|
|
* to be able to restore the original font afterwards, so don't change
|
|
|
|
* if we can't read the original font.
|
|
|
|
*/
|
|
|
|
err = RegOpenKeyExA(HKEY_CURRENT_USER, "Console", 0,
|
|
|
|
KEY_QUERY_VALUE | KEY_SET_VALUE, &console_key);
|
|
|
|
if (err == ERROR_SUCCESS)
|
2011-01-10 12:11:50 +01:00
|
|
|
{
|
2020-08-12 15:10:37 +02:00
|
|
|
size = sizeof(old_font);
|
|
|
|
err = RegQueryValueExA(console_key, "FaceName", NULL, NULL,
|
|
|
|
(LPBYTE) old_font, &size);
|
|
|
|
if (err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
delete = (err == ERROR_FILE_NOT_FOUND);
|
|
|
|
err = RegSetValueExA(console_key, "FaceName", 0, REG_SZ,
|
|
|
|
(const BYTE *) font_name, sizeof(font_name));
|
|
|
|
if (err != ERROR_SUCCESS)
|
2022-03-02 09:03:21 +01:00
|
|
|
trace("Unable to change default console font, error %ld\n", err);
|
2020-08-12 15:10:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
trace("Unable to query default console font, error %ld\n", err);
|
2020-08-12 15:10:37 +02:00
|
|
|
RegCloseKey(console_key);
|
|
|
|
console_key = NULL;
|
|
|
|
}
|
2011-01-10 12:11:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-02 09:03:21 +01:00
|
|
|
trace("Unable to open HKCU\\Console, error %ld\n", err);
|
2011-01-10 12:11:50 +01:00
|
|
|
console_key = NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:10:37 +02:00
|
|
|
/* Now detach and open a fresh console to play with */
|
|
|
|
FreeConsole();
|
|
|
|
ok(AllocConsole(), "Couldn't alloc console\n");
|
2011-01-10 12:11:50 +01:00
|
|
|
|
2020-08-12 15:10:37 +02:00
|
|
|
/* Restore default console font if needed */
|
|
|
|
if (console_key != NULL)
|
|
|
|
{
|
|
|
|
if (delete)
|
|
|
|
err = RegDeleteValueA(console_key, "FaceName");
|
|
|
|
else
|
|
|
|
err = RegSetValueExA(console_key, "FaceName", 0, REG_SZ,
|
|
|
|
(const BYTE *) old_font, strlen(old_font) + 1);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(err == ERROR_SUCCESS, "Unable to restore default console font, error %ld\n", err);
|
2020-08-12 15:10:37 +02:00
|
|
|
}
|
2011-01-10 12:11:50 +01:00
|
|
|
}
|
2020-08-12 15:10:37 +02:00
|
|
|
|
2020-11-12 19:56:30 +01:00
|
|
|
unbound_output = create_unbound_handle(TRUE, FALSE);
|
|
|
|
if (!unbound_output)
|
|
|
|
{
|
|
|
|
win_skip("Skipping NT path tests, not supported on this Windows version\n");
|
|
|
|
skip_nt = TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:54:12 +02:00
|
|
|
if (test_current)
|
|
|
|
{
|
|
|
|
HANDLE sb;
|
|
|
|
revert_output = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
sb = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
CONSOLE_TEXTMODE_BUFFER, NULL);
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(sb != INVALID_HANDLE_VALUE, "Could not allocate screen buffer: %lu\n", GetLastError());
|
2020-10-06 18:54:12 +02:00
|
|
|
SetConsoleActiveScreenBuffer(sb);
|
|
|
|
}
|
|
|
|
|
2003-06-21 04:07:10 +02:00
|
|
|
hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
|
|
|
|
/* now verify everything's ok */
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
|
|
|
|
ok(hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2020-08-20 23:49:22 +02:00
|
|
|
if (using_pseudo_console)
|
|
|
|
{
|
2020-08-27 15:05:25 +02:00
|
|
|
test_pseudo_console_child(hConIn, hConOut);
|
2020-08-20 23:49:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-04 13:55:07 +01:00
|
|
|
ret = GetConsoleScreenBufferInfo(hConOut, &sbi);
|
|
|
|
ok(ret, "Getting sb info\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
if (!ret) return;
|
|
|
|
|
2013-02-11 15:36:15 +01:00
|
|
|
/* Reduce the size of the buffer to the visible area plus 3 lines to speed
|
|
|
|
* up the tests.
|
|
|
|
*/
|
|
|
|
trace("Visible area: %dx%d - %dx%d Buffer size: %dx%d\n", sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom, sbi.dwSize.X, sbi.dwSize.Y);
|
|
|
|
sbi.dwSize.Y = size = (sbi.srWindow.Bottom + 1) + 3;
|
|
|
|
ret = SetConsoleScreenBufferSize(hConOut, sbi.dwSize);
|
|
|
|
ok(ret, "Setting sb info\n");
|
|
|
|
ret = GetConsoleScreenBufferInfo(hConOut, &sbi);
|
|
|
|
ok(ret, "Getting sb info\n");
|
2022-03-02 09:03:21 +01:00
|
|
|
ok(sbi.dwSize.Y == size, "Unexpected buffer size: %d instead of %ld\n", sbi.dwSize.Y, size);
|
2013-02-11 15:36:15 +01:00
|
|
|
if (!ret) return;
|
|
|
|
|
2020-10-14 19:57:37 +02:00
|
|
|
test_ReadConsole(hConIn);
|
2003-05-13 06:46:54 +02:00
|
|
|
/* Non interactive tests */
|
2003-06-21 04:07:10 +02:00
|
|
|
testCursor(hConOut, sbi.dwSize);
|
2008-06-24 12:21:57 +02:00
|
|
|
/* test parameters (FIXME: test functionality) */
|
|
|
|
testCursorInfo(hConOut);
|
2003-05-13 06:46:54 +02:00
|
|
|
/* will test wrapped (on/off) & processed (on/off) strings output */
|
2003-06-21 04:07:10 +02:00
|
|
|
testWrite(hConOut, sbi.dwSize);
|
2003-05-13 06:46:54 +02:00
|
|
|
/* will test line scrolling at the bottom of the screen */
|
|
|
|
/* testBottomScroll(); */
|
|
|
|
/* will test all the scrolling operations */
|
2004-09-08 03:25:05 +02:00
|
|
|
testScroll(hConOut, sbi.dwSize);
|
2007-05-09 18:55:08 +02:00
|
|
|
/* will test sb creation / modification / codepage handling */
|
2020-08-12 15:10:37 +02:00
|
|
|
if (!test_current) testScreenBuffer(hConOut);
|
2021-07-21 14:24:48 +02:00
|
|
|
test_new_screen_buffer_properties(hConOut);
|
2021-07-21 14:24:47 +02:00
|
|
|
test_new_screen_buffer_color_attributes(hConOut);
|
2016-08-16 20:35:27 +02:00
|
|
|
/* Test waiting for a console handle */
|
|
|
|
testWaitForConsoleInput(hConIn);
|
2020-11-10 16:31:34 +01:00
|
|
|
test_wait(hConIn, hConOut);
|
2016-01-05 08:59:34 +01:00
|
|
|
|
2020-08-12 15:10:37 +02:00
|
|
|
if (!test_current)
|
|
|
|
{
|
|
|
|
/* clear duplicated console font table */
|
|
|
|
CloseHandle(hConIn);
|
|
|
|
CloseHandle(hConOut);
|
|
|
|
FreeConsole();
|
|
|
|
ok(AllocConsole(), "Couldn't alloc console\n");
|
|
|
|
hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
|
|
|
|
ok(hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
|
|
|
|
}
|
2016-01-05 08:59:34 +01:00
|
|
|
|
2004-09-08 03:25:05 +02:00
|
|
|
testCtrlHandler();
|
|
|
|
/* still to be done: access rights & access on objects */
|
2007-12-02 22:12:19 +01:00
|
|
|
|
2007-12-05 14:22:05 +01:00
|
|
|
if (!pGetConsoleInputExeNameA || !pSetConsoleInputExeNameA)
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("GetConsoleInputExeNameA and/or SetConsoleInputExeNameA is not available\n");
|
2007-12-05 11:40:05 +01:00
|
|
|
else
|
|
|
|
test_GetSetConsoleInputExeName();
|
2010-01-05 09:32:36 +01:00
|
|
|
|
2020-10-06 18:54:12 +02:00
|
|
|
if (!test_current) test_GetConsoleProcessList();
|
2010-04-01 02:53:59 +02:00
|
|
|
test_OpenConsoleW();
|
2012-02-07 21:40:46 +01:00
|
|
|
test_CreateFileW();
|
2011-05-10 22:02:26 +02:00
|
|
|
test_OpenCON();
|
2010-09-29 11:57:42 +02:00
|
|
|
test_VerifyConsoleIoHandle(hConOut);
|
2010-09-22 19:54:38 +02:00
|
|
|
test_GetSetStdHandle();
|
2020-11-11 20:06:39 +01:00
|
|
|
test_DuplicateConsoleHandle();
|
2011-01-04 04:27:40 +01:00
|
|
|
test_GetNumberOfConsoleInputEvents(hConIn);
|
2011-01-04 04:25:21 +01:00
|
|
|
test_WriteConsoleInputA(hConIn);
|
2011-01-04 04:25:16 +01:00
|
|
|
test_WriteConsoleInputW(hConIn);
|
2020-10-15 18:19:30 +02:00
|
|
|
test_FlushConsoleInputBuffer(hConIn, hConOut);
|
2011-01-04 04:25:29 +01:00
|
|
|
test_WriteConsoleOutputCharacterA(hConOut);
|
2011-01-04 04:25:26 +01:00
|
|
|
test_WriteConsoleOutputCharacterW(hConOut);
|
2011-01-04 04:25:34 +01:00
|
|
|
test_WriteConsoleOutputAttribute(hConOut);
|
2020-07-23 17:32:23 +02:00
|
|
|
test_WriteConsoleOutput(hConOut);
|
2011-01-04 04:25:44 +01:00
|
|
|
test_FillConsoleOutputCharacterA(hConOut);
|
2011-01-04 04:25:39 +01:00
|
|
|
test_FillConsoleOutputCharacterW(hConOut);
|
2011-01-04 04:25:47 +01:00
|
|
|
test_FillConsoleOutputAttribute(hConOut);
|
2011-01-11 12:11:30 +01:00
|
|
|
test_ReadConsoleOutputCharacterA(hConOut);
|
2011-01-11 12:11:16 +01:00
|
|
|
test_ReadConsoleOutputCharacterW(hConOut);
|
2011-01-11 12:11:34 +01:00
|
|
|
test_ReadConsoleOutputAttribute(hConOut);
|
2020-07-28 17:11:19 +02:00
|
|
|
test_ReadConsoleOutput(hConOut);
|
2020-10-06 18:54:12 +02:00
|
|
|
if (!test_current)
|
|
|
|
{
|
|
|
|
test_GetCurrentConsoleFont(hConOut);
|
|
|
|
test_GetCurrentConsoleFontEx(hConOut);
|
2021-08-17 14:11:11 +02:00
|
|
|
test_SetCurrentConsoleFontEx(hConOut);
|
2020-10-06 18:54:12 +02:00
|
|
|
test_GetConsoleFontSize(hConOut);
|
|
|
|
test_GetLargestConsoleWindowSize(hConOut);
|
|
|
|
test_GetConsoleFontInfo(hConOut);
|
|
|
|
test_SetConsoleFont(hConOut);
|
|
|
|
}
|
2016-08-17 03:35:39 +02:00
|
|
|
test_GetConsoleScreenBufferInfoEx(hConOut);
|
2020-03-04 08:47:51 +01:00
|
|
|
test_SetConsoleScreenBufferInfoEx(hConOut);
|
2020-11-20 15:39:44 +01:00
|
|
|
test_file_info(hConIn, hConOut);
|
2020-08-12 15:10:45 +02:00
|
|
|
test_console_title();
|
2020-08-12 15:10:37 +02:00
|
|
|
if (!test_current)
|
|
|
|
{
|
2020-10-06 18:53:52 +02:00
|
|
|
test_pseudo_console();
|
2020-08-12 15:10:37 +02:00
|
|
|
test_AttachConsole(hConOut);
|
|
|
|
test_AllocConsole();
|
|
|
|
test_FreeConsole();
|
2022-03-17 08:27:10 +01:00
|
|
|
test_CreateProcessCUI();
|
2020-08-12 15:10:37 +02:00
|
|
|
}
|
2020-10-06 18:54:12 +02:00
|
|
|
else if (revert_output) SetConsoleActiveScreenBuffer(revert_output);
|
|
|
|
|
2020-11-12 19:56:30 +01:00
|
|
|
CloseHandle(unbound_output);
|
2003-05-13 06:46:54 +02:00
|
|
|
}
|