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
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* 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; \
|
|
|
|
expect = ReadConsoleOutputCharacter((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)
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %u\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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\n",
|
2003-05-13 06:46:54 +02:00
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWriteSimple(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
DWORD len;
|
|
|
|
const char* mytest = "abcdefg";
|
2003-09-25 22:29:40 +02:00
|
|
|
const int mylen = strlen(mytest);
|
|
|
|
|
2003-05-13 06:46:54 +02:00
|
|
|
/* single line write */
|
|
|
|
c.X = c.Y = 0;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
c.Y = 0;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-05-03 22:07:24 +02:00
|
|
|
ret = WriteConsole(hCon, mytest, mylen, &len, NULL);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret != 0 && len == mylen, "Couldn't write, ret = %d, len = %d\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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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;
|
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 & 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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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;
|
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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_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);
|
|
|
|
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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(WriteConsole(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++;
|
|
|
|
okCHAR(hCon, c, ' ', DEFAULT_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);
|
|
|
|
okCURSOR(hCon, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testWrite(HANDLE hCon, COORD sbSize)
|
|
|
|
{
|
|
|
|
/* FIXME: should in fact insure that the sb is at least 10 character 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);
|
|
|
|
testWriteSimple(hCon, sbSize);
|
|
|
|
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;
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ScrollConsoleScreenBuffer(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;
|
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ScrollConsoleScreenBuffer(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);
|
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ScrollConsoleScreenBuffer(hCon, &scroll, &clip, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ScrollConsoleScreenBuffer(hCon, &scroll, &clip, 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);
|
|
|
|
}
|
|
|
|
}
|
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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %u\n", GetLastError());
|
2004-09-08 03:25:05 +02:00
|
|
|
ok(SetConsoleCtrlHandler(mch, TRUE), "Couldn't set handler\n");
|
|
|
|
/* wine requires the event for the test, as we cannot insure, so far, that event
|
|
|
|
* are processed synchronously in GenerateConsoleCtrlEvent()
|
|
|
|
*/
|
|
|
|
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");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %u\n", GetLastError());
|
2004-09-08 03:25:05 +02:00
|
|
|
}
|
2003-05-13 06:46:54 +02:00
|
|
|
|
|
|
|
START_TEST(console)
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
HANDLE hConIn, hConOut;
|
2003-05-13 06:46:54 +02:00
|
|
|
BOOL ret;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
|
|
|
|
2003-09-25 22:29:40 +02:00
|
|
|
/* be sure we have a clean console (and that's our own)
|
2003-05-13 06:46:54 +02:00
|
|
|
* FIXME: this will make the test fail (currently) if we don't run
|
|
|
|
* under X11
|
|
|
|
* Another solution would be to rerun the test under wineconsole with
|
|
|
|
* the curses backend
|
|
|
|
*/
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2004-10-09 01:35:47 +02:00
|
|
|
/* first, we detach and open a fresh console to play with */
|
|
|
|
FreeConsole();
|
2005-12-22 13:55:03 +01:00
|
|
|
ok(AllocConsole(), "Couldn't alloc console\n");
|
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
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret = GetConsoleScreenBufferInfo(hConOut, &sbi), "Getting sb info\n");
|
2003-05-13 06:46:54 +02:00
|
|
|
if (!ret) return;
|
|
|
|
|
|
|
|
/* Non interactive tests */
|
2003-06-21 04:07:10 +02:00
|
|
|
testCursor(hConOut, sbi.dwSize);
|
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);
|
2003-05-13 06:46:54 +02:00
|
|
|
/* will test sb creation / modification... */
|
|
|
|
/* testScreenBuffer() */
|
2004-09-08 03:25:05 +02:00
|
|
|
testCtrlHandler();
|
|
|
|
/* still to be done: access rights & access on objects */
|
2003-05-13 06:46:54 +02:00
|
|
|
}
|