[PATCH] kernel32/tests: Add tests for SetCurrentConsoleFontEx
Hugh McMaster
hugh.mcmaster at outlook.com
Thu Jan 20 06:33:03 CST 2022
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
dlls/kernel32/tests/console.c | 162 ++++++++++++++++++++++++++++++++--
1 file changed, 156 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index e4d9d43f4c4..12924719f16 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -3558,12 +3558,46 @@ static void test_GetCurrentConsoleFontEx(HANDLE std_output)
ok(cfix.dwFontSize.Y == cfi.dwFontSize.Y, "expected values to match\n");
}
+static HANDLE console_event;
+
+static void CALLBACK console_event_hook_proc(HWINEVENTHOOK hook, DWORD event, HWND hwnd,
+ LONG object_id, LONG child_id,
+ DWORD thread_id, DWORD event_time)
+{
+ SetEvent(console_event);
+}
+
+static DWORD WINAPI console_event_thread_proc(void *param)
+{
+ MSG msg;
+ HANDLE hthread_event = *(HANDLE *)param;
+ HWINEVENTHOOK hook;
+
+ hook = SetWinEventHook(EVENT_CONSOLE_LAYOUT, EVENT_CONSOLE_LAYOUT, NULL,
+ console_event_hook_proc, 0, 0, WINEVENT_OUTOFCONTEXT);
+ ok(hook != 0, "SetWinEventHook failed\n");
+
+ SetEvent(hthread_event);
+
+ while (GetMessageA(&msg, 0, 0, 0) > 0)
+ DispatchMessageA(&msg);
+
+ ok(UnhookWinEvent(hook), "UnhookWinEvent failed\n");
+
+ return 0;
+}
+
static void test_SetCurrentConsoleFontEx(HANDLE std_output)
{
- CONSOLE_FONT_INFOEX orig_cfix, cfix;
+ CONSOLE_FONT_INFOEX orig_cfix, cfix, tmp;
BOOL ret;
- HANDLE pipe1, pipe2;
+ HANDLE pipe1, pipe2, hthread, hthread_event;
HANDLE std_input = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD hthread_id, res;
+ HWND hwnd = GetConsoleWindow();
+ RECT r;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ unsigned int font_height;
orig_cfix.cbSize = sizeof(CONSOLE_FONT_INFOEX);
@@ -3652,26 +3686,142 @@ static void test_SetCurrentConsoleFontEx(HANDLE std_output)
ok(!ret, "got %d, expected 0\n", ret);
todo_wine ok(GetLastError() == ERROR_INVALID_HANDLE, "got %u, expected 6\n", GetLastError());
+ /* Font parameter tests */
+ console_event = CreateEventA(NULL, FALSE, FALSE, "console_event");
+ ok(console_event != NULL, "CreateEvent failed: %u\n", GetLastError());
+
+ hthread_event = CreateEventA(NULL, FALSE, FALSE, "hthread_event");
+ ok(hthread_event != NULL, "CreateEvent failed: %u\n", GetLastError());
+
+ hthread = CreateThread(NULL, 0, console_event_thread_proc, &hthread_event, 0, &hthread_id);
+ ok(hthread != NULL, "CreateThread failed: %u\n", GetLastError());
+
+ res = WaitForSingleObject(hthread_event, INFINITE);
+ ok(res == WAIT_OBJECT_0, "got %u, expected WAIT_OBJECT_0\n", res);
+
+ /* Try setting console font information for the current window size */
+ cfix.cbSize = sizeof(cfix);
+ cfix.nFont = 0;
+ cfix.dwFontSize.X = 0;
+ cfix.FontFamily = TMPF_VECTOR | TMPF_TRUETYPE | FF_MODERN;
+ cfix.FontWeight = FW_NORMAL;
+ lstrcpyW(cfix.FaceName, L"Lucida Console");
+
+ tmp.cbSize = sizeof(tmp);
+
+ /* Test font height 20 */
+ cfix.dwFontSize.Y = 20;
SetLastError(0xdeadbeef);
- ret = SetCurrentConsoleFontEx(std_input, TRUE, &cfix);
- ok(!ret, "got %d, expected 0\n", ret);
- todo_wine ok(GetLastError() == ERROR_INVALID_HANDLE, "got %u, expected 6\n", GetLastError());
+ ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
+ todo_wine ok(ret, "got %d, expected non-zero\n", ret);
+ todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(1) got %u, expected WAIT_OBJECT_0\n", res);
+
+ ret = GetCurrentConsoleFontEx(std_output, FALSE, &tmp);
+ ok(ret, "GetCurrentConsoleFontEx failed: %u\n", GetLastError());
+ GetClientRect(hwnd, &r);
+ GetConsoleScreenBufferInfo(std_output, &csbi);
+ font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
+ ok(tmp.dwFontSize.Y == font_height, "got %u, expected %u\n", tmp.dwFontSize.Y, font_height);
+ todo_wine ok(tmp.FontFamily == cfix.FontFamily, "got %u, expected %u\n", tmp.FontFamily, cfix.FontFamily);
+ ok(tmp.FontWeight == cfix.FontWeight, "got %u, expected %u\n", tmp.FontWeight, cfix.FontWeight);
+ /* Test font height 12 */
+ cfix.dwFontSize.Y = 12;
SetLastError(0xdeadbeef);
ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
todo_wine ok(ret, "got %d, expected non-zero\n", ret);
todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(2) got %u, expected WAIT_OBJECT_0\n", res);
+
+ ret = GetCurrentConsoleFontEx(std_output, FALSE, &tmp);
+ ok(ret, "GetCurrentConsoleFontEx failed: %u\n", GetLastError());
+ GetClientRect(hwnd, &r);
+ GetConsoleScreenBufferInfo(std_output, &csbi);
+ font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
+ ok(tmp.dwFontSize.Y == font_height, "got %u, expected %u\n", tmp.dwFontSize.Y, font_height);
+ todo_wine ok(tmp.FontFamily == cfix.FontFamily, "got %u, expected %u\n", tmp.FontFamily, cfix.FontFamily);
+ ok(tmp.FontWeight == cfix.FontWeight, "got %u, expected %u\n", tmp.FontWeight, cfix.FontWeight);
+
+ /* Test font height 16 */
+ cfix.dwFontSize.Y = 16;
SetLastError(0xdeadbeef);
- ret = SetCurrentConsoleFontEx(std_output, TRUE, &cfix);
+ ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
+ todo_wine ok(ret, "got %d, expected non-zero\n", ret);
+ todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(3) got %u, expected WAIT_OBJECT_0\n", res);
+
+ ret = GetCurrentConsoleFontEx(std_output, FALSE, &tmp);
+ ok(ret, "GetCurrentConsoleFontEx failed: %u\n", GetLastError());
+ GetClientRect(hwnd, &r);
+ GetConsoleScreenBufferInfo(std_output, &csbi);
+ font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
+ ok(tmp.dwFontSize.Y == font_height, "got %u, expected %u\n", tmp.dwFontSize.Y, font_height);
+ todo_wine ok(tmp.FontFamily == cfix.FontFamily, "got %u, expected %u\n", tmp.FontFamily, cfix.FontFamily);
+ ok(tmp.FontWeight == cfix.FontWeight, "got %u, expected %u\n", tmp.FontWeight, cfix.FontWeight);
+
+ /* Test invalid font height */
+ cfix.dwFontSize.Y = 0;
+ SetLastError(0xdeadbeef);
+ ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
todo_wine ok(ret, "got %d, expected non-zero\n", ret);
todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(4) got %u, expected WAIT_OBJECT_0\n", res);
+
+ ret = GetCurrentConsoleFontEx(std_output, FALSE, &tmp);
+ ok(ret, "GetCurrentConsoleFontEx failed: %u\n", GetLastError());
+ GetClientRect(hwnd, &r);
+ GetConsoleScreenBufferInfo(std_output, &csbi);
+ font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
+ ok(tmp.dwFontSize.Y == font_height, "got %u, expected %u\n", tmp.dwFontSize.Y, font_height);
+ todo_wine ok(font_height == 12, "got %u, expected 12\n", font_height);
+ todo_wine ok(tmp.FontFamily == cfix.FontFamily, "got %u, expected %u\n", tmp.FontFamily, cfix.FontFamily);
+ ok(tmp.FontWeight == cfix.FontWeight, "got %u, expected %u\n", tmp.FontWeight, cfix.FontWeight);
+
+ /* Test invalid font weight */
+ cfix.dwFontSize.Y = 16;
+ cfix.FontWeight = 0;
+ SetLastError(0xdeadbeef);
+ ret = SetCurrentConsoleFontEx(std_output, FALSE, &cfix);
+ todo_wine ok(ret, "got %d, expected non-zero\n", ret);
+ todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(5) got %u, expected WAIT_OBJECT_0\n", res);
+
+ ret = GetCurrentConsoleFontEx(std_output, FALSE, &tmp);
+ ok(ret, "GetCurrentConsoleFontEx failed: %u\n", GetLastError());
+ GetClientRect(hwnd, &r);
+ GetConsoleScreenBufferInfo(std_output, &csbi);
+ font_height = (r.bottom - r.top) / (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
+ ok(tmp.dwFontSize.Y == font_height, "got %u, expected %u\n", tmp.dwFontSize.Y, font_height);
+ todo_wine ok(tmp.FontFamily == cfix.FontFamily, "got %u, expected %u\n", tmp.FontFamily, cfix.FontFamily);
+ ok(tmp.FontWeight == FW_NORMAL, "got %u, expected %u\n", tmp.FontWeight, FW_NORMAL);
+
/* Restore original console font parameters */
SetLastError(0xdeadbeef);
ret = SetCurrentConsoleFontEx(std_output, FALSE, &orig_cfix);
todo_wine ok(ret, "got %d, expected non-zero\n", ret);
todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
+
+ res = WaitForSingleObject(console_event, 1000);
+ todo_wine ok(res == WAIT_OBJECT_0, "(5) got %u, expected WAIT_OBJECT_0\n", res);
+
+ /* Clean up */
+ PostThreadMessageA(hthread_id, WM_QUIT, 0, 0);
+ res = WaitForSingleObject(hthread, INFINITE);
+ ok(res == WAIT_OBJECT_0, "got %u, expected WAIT_OBJECT_0\n", res);
+ CloseHandle(hthread);
+ CloseHandle(hthread_event);
+ CloseHandle(console_event);
}
static void test_GetConsoleFontSize(HANDLE std_output)
--
2.34.1
More information about the wine-devel
mailing list