kernel32/tests: Add an option to test current console.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-08-12 15:10:37 +02:00 committed by Alexandre Julliard
parent 3d4be8e150
commit 5a6341d8c7
1 changed files with 71 additions and 65 deletions

View File

@ -3872,14 +3872,9 @@ static void test_AllocConsole(void)
START_TEST(console)
{
static const char font_name[] = "Lucida Console";
HANDLE hConIn, hConOut;
BOOL ret;
BOOL ret, test_current;
CONSOLE_SCREEN_BUFFER_INFO sbi;
LONG err;
HKEY console_key;
char old_font[LF_FACESIZE];
BOOL delete = FALSE;
DWORD size;
char **argv;
int argc;
@ -3902,62 +3897,67 @@ START_TEST(console)
return;
}
/* be sure we have a clean console (and that's our own)
* 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
*/
test_current = argc >= 3 && !strcmp(argv[2], "--current");
/* 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)
if (!test_current)
{
size = sizeof(old_font);
err = RegQueryValueExA(console_key, "FaceName", NULL, NULL,
(LPBYTE) old_font, &size);
if (err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND)
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)
{
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)
trace("Unable to change default console font, error %d\n", err);
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)
trace("Unable to change default console font, error %d\n", err);
}
else
{
trace("Unable to query default console font, error %d\n", err);
RegCloseKey(console_key);
console_key = NULL;
}
}
else
{
trace("Unable to query default console font, error %d\n", err);
RegCloseKey(console_key);
trace("Unable to open HKCU\\Console, error %d\n", err);
console_key = NULL;
}
}
else
{
trace("Unable to open HKCU\\Console, error %d\n", err);
console_key = NULL;
/* Now detach and open a fresh console to play with */
FreeConsole();
ok(AllocConsole(), "Couldn't alloc console\n");
/* 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);
ok(err == ERROR_SUCCESS, "Unable to restore default console font, error %d\n", err);
}
}
/* Now detach and open a fresh console to play with */
FreeConsole();
ok(AllocConsole(), "Couldn't alloc console\n");
/* 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);
ok(err == ERROR_SUCCESS, "Unable to restore default console font, error %d\n", err);
}
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);
@ -3993,19 +3993,22 @@ START_TEST(console)
/* will test all the scrolling operations */
testScroll(hConOut, sbi.dwSize);
/* will test sb creation / modification / codepage handling */
testScreenBuffer(hConOut);
if (!test_current) testScreenBuffer(hConOut);
/* Test waiting for a console handle */
testWaitForConsoleInput(hConIn);
/* 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");
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");
}
testCtrlHandler();
/* still to be done: access rights & access on objects */
@ -4043,7 +4046,10 @@ START_TEST(console)
test_SetConsoleFont(hConOut);
test_GetConsoleScreenBufferInfoEx(hConOut);
test_SetConsoleScreenBufferInfoEx(hConOut);
test_AttachConsole(hConOut);
test_AllocConsole();
test_FreeConsole();
if (!test_current)
{
test_AttachConsole(hConOut);
test_AllocConsole();
test_FreeConsole();
}
}