[PATCH 2/2] kernel32/tests: Add a partial test for GetConsoleFontSize

Hugh McMaster hugh.mcmaster at outlook.com
Sun Jun 14 06:24:14 CDT 2015


MSDN says the font information should come from a font table,
but there is no known implementation, so we are calculating
the font size manually.

By knowing how to calculate the font size, we can add the functionality
to kernel32 and add a much-needed aspect of Wine's console support.

---
 dlls/kernel32/tests/console.c | 55 ++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index 254922c..020901c 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -1307,6 +1307,24 @@ static void test_GetSetStdHandle(void)
     ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
 }
 
+static void get_console_font_size(HANDLE hConOut, COORD *fontsize)
+{
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+    unsigned int columns, rows;
+    HWND hwnd;
+    RECT rcClient;
+
+    GetConsoleScreenBufferInfo(hConOut, &csbi);
+    columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
+    rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
+
+    hwnd = GetConsoleWindow();
+    GetClientRect(hwnd, &rcClient);
+
+    fontsize->X = rcClient.right / columns;
+    fontsize->Y = rcClient.bottom / rows;
+}
+
 static void test_GetLargestConsoleWindowSize(HANDLE hConOut)
 {
     CONSOLE_FONT_INFO cfi;
@@ -1320,22 +1338,7 @@ static void test_GetLargestConsoleWindowSize(HANDLE hConOut)
     /* GetCurrentConsoleFont and GetConsoleFontSize are unimplemented,
      * so allow the test suite to continue by calculating the font size. */
     if (!fontsize.X || !fontsize.Y)
-    {
-        CONSOLE_SCREEN_BUFFER_INFO csbi;
-        unsigned int columns, rows;
-        HWND hwnd;
-        RECT rcClient;
-
-        GetConsoleScreenBufferInfo(hConOut, &csbi);
-        columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
-        rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
-
-        hwnd = GetConsoleWindow();
-        GetClientRect(hwnd, &rcClient);
-
-        fontsize.X = rcClient.right / columns;
-        fontsize.Y = rcClient.bottom / rows;
-    }
+        get_console_font_size(hConOut, &fontsize);
 
     SystemParametersInfoW(SPI_GETWORKAREA, 0, &r, 0);
     caption = GetSystemMetrics(SM_CYCAPTION);
@@ -1351,6 +1354,25 @@ static void test_GetLargestConsoleWindowSize(HANDLE hConOut)
     ok(maxconwin_y == c.Y, "incorrect maximum height, got %d, expected %d\n", maxconwin_y, c.Y);
 }
 
+static void test_GetConsoleFontSize(HANDLE hConOut)
+{
+    CONSOLE_FONT_INFO cfi;
+    COORD fontsize, c;
+
+    /* FIXME: MSDN says the font information should come from a font table, but there is
+     * no known implementation. GetCurrentConsoleFont and GetConsoleFontSize are stubs.
+     */
+    get_console_font_size(hConOut, &fontsize);
+
+    GetCurrentConsoleFont(hConOut, FALSE, &cfi);
+    c = GetConsoleFontSize(hConOut, cfi.nFont);
+
+    todo_wine
+    ok(fontsize.X == c.X, "incorrect font width, got %d, expected %d\n", fontsize.X, c.X);
+    todo_wine
+    ok(fontsize.Y == c.Y, "incorrect font height, got %d, expected %d\n", fontsize.Y, c.Y);
+}
+
 static void test_GetNumberOfConsoleInputEvents(HANDLE input_handle)
 {
     DWORD count;
@@ -2753,6 +2775,7 @@ START_TEST(console)
     test_VerifyConsoleIoHandle(hConOut);
     test_GetSetStdHandle();
     test_GetLargestConsoleWindowSize(hConOut);
+    test_GetConsoleFontSize(hConOut);
     test_GetNumberOfConsoleInputEvents(hConIn);
     test_WriteConsoleInputA(hConIn);
     test_WriteConsoleInputW(hConIn);
-- 
1.9.1




More information about the wine-patches mailing list