[PATCH v7] kernel32/tests: Add tests for SetCurrentConsoleFontEx

Hugh McMaster hugh.mcmaster at outlook.com
Sun Dec 12 02:41:19 CST 2021


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
Changes in this version:
 - Dynamically calculate expected font height
 - Sleep for a short time to ensure window has been redrawn

 dlls/kernel32/tests/console.c | 95 +++++++++++++++++++++++++++++++++--
 1 file changed, 92 insertions(+), 3 deletions(-)

diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index 8b5abfa2da9..7fa6db70b3c 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -3554,12 +3554,16 @@ static void test_GetCurrentConsoleFontEx(HANDLE std_output)
 
 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 std_input = GetStdHandle(STD_INPUT_HANDLE);
+    HWND hwnd = GetConsoleWindow();
+    RECT r;
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+    unsigned int font_height;
 
-    orig_cfix.cbSize = sizeof(CONSOLE_FONT_INFOEX);
+    orig_cfix.cbSize = tmp.cbSize = sizeof(CONSOLE_FONT_INFOEX);
 
     ret = GetCurrentConsoleFontEx(std_output, FALSE, &orig_cfix);
     ok(ret, "got %d, expected non-zero\n", ret);
@@ -3651,16 +3655,101 @@ 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());
 
+    /* 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");
+
+    /* Test font height 20 */
+    cfix.dwFontSize.Y = 20;
     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());
 
+    Sleep(100);
+    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, 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());
+
+    Sleep(100);
+    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, FALSE, &cfix);
     todo_wine ok(ret, "got %d, expected non-zero\n", ret);
     todo_wine ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
 
+    Sleep(100);
+    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());
+
+    Sleep(100);
+    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());
+
+    Sleep(100);
+    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);
-- 
2.34.1




More information about the wine-devel mailing list