[GDI32_APITEST] Add test for AddFontMemResourceEx. Uses PanosePitchTest.ttf from...
authorMark Jansen <mark.jansen@reactos.org>
Sat, 8 Apr 2017 22:25:54 +0000 (22:25 +0000)
committerMark Jansen <mark.jansen@reactos.org>
Sat, 8 Apr 2017 22:25:54 +0000 (22:25 +0000)
svn path=/trunk/; revision=74287

rostests/apitests/gdi32/AddFontMemResourceEx.c [new file with mode: 0644]
rostests/apitests/gdi32/CMakeLists.txt
rostests/apitests/gdi32/PanosePitchTest.ttf [new file with mode: 0644]
rostests/apitests/gdi32/resource.rc
rostests/apitests/gdi32/testlist.c

diff --git a/rostests/apitests/gdi32/AddFontMemResourceEx.c b/rostests/apitests/gdi32/AddFontMemResourceEx.c
new file mode 100644 (file)
index 0000000..b249998
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * PURPOSE:         Test for AddFontMemResourceEx
+ * PROGRAMMERS:     Mark Jansen
+ *
+ * PanosePitchTest by Katayama Hirofumi MZ, licensed under CC BY
+ */
+
+
+#include <apitest.h>
+#include <wingdi.h>
+#include <winuser.h>
+
+
+static void test_font_caps(HDC hdc)
+{
+    HGDIOBJ old;
+    TEXTMETRICA tm = { 0 };
+    char name[64];
+    BOOL ret;
+    HFONT font = CreateFont(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
+                            OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, TEXT("PanosePitchTest"));
+
+    if (font)
+    {
+        old = SelectObject(hdc, font);
+
+        memset(&tm, 0xaa, sizeof(tm));
+        ret = GetTextMetricsA(hdc, &tm);
+        ok_int(ret, TRUE);
+
+        SetLastError(0xdeadbeef);
+        ret = GetTextFaceA(hdc, sizeof(name), name);
+        ok(ret, "GetTextFaceA error %lu\n", GetLastError());
+        if (ret)
+        {
+            ok_str(name, "PanosePitchTest");
+        }
+
+        ok_int(tm.tmHeight, 11);
+        ok_int(tm.tmAscent, 11);
+        ok_int(tm.tmDescent, 0);
+        ok_int(tm.tmInternalLeading, -5);
+        ok_int(tm.tmExternalLeading, 1);
+        ok_int(tm.tmAveCharWidth, 8);
+        ok_int(tm.tmMaxCharWidth, 11);
+        ok_int(tm.tmWeight, FW_NORMAL);
+        ok_int(tm.tmOverhang, 0);
+        ok_int(tm.tmDigitizedAspectX, 96);
+        ok_int(tm.tmDigitizedAspectY, 96);
+        ok_int(tm.tmFirstChar, 63);
+        ok_int(tm.tmLastChar, 65);
+        ok_int(tm.tmDefaultChar, 165);
+        ok_int(tm.tmBreakChar, 65);
+        ok_int(tm.tmItalic, 0);
+        ok_int(tm.tmUnderlined, 0);
+        ok_int(tm.tmStruckOut, 0);
+        ok_hex(tm.tmPitchAndFamily, TMPF_TRUETYPE | TMPF_VECTOR);
+        ok_int(tm.tmCharSet, SHIFTJIS_CHARSET);
+
+        SelectObject(hdc, old);
+        DeleteObject(font);
+    }
+
+    font = CreateFont(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
+                      OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, TEXT("@PanosePitchTest"));
+
+    if (font)
+    {
+        old = SelectObject(hdc, font);
+
+        memset(&tm, 0xaa, sizeof(tm));
+        ret = GetTextMetricsA(hdc, &tm);
+        ok_int(ret, TRUE);
+
+        SetLastError(0xdeadbeef);
+        ret = GetTextFaceA(hdc, sizeof(name), name);
+        ok(ret, "GetTextFaceA error %lu\n", GetLastError());
+        if (ret)
+        {
+            ok_str(name, "@PanosePitchTest");
+        }
+
+        ok_int(tm.tmHeight, 11);
+        ok_int(tm.tmAscent, 11);
+        ok_int(tm.tmDescent, 0);
+        ok_int(tm.tmInternalLeading, -5);
+        ok_int(tm.tmExternalLeading, 1);
+        ok_int(tm.tmAveCharWidth, 8);
+        ok_int(tm.tmMaxCharWidth, 11);
+        ok_int(tm.tmWeight, FW_NORMAL);
+        ok_int(tm.tmOverhang, 0);
+        ok_int(tm.tmDigitizedAspectX, 96);
+        ok_int(tm.tmDigitizedAspectY, 96);
+        ok_int(tm.tmFirstChar, 63);
+        ok_int(tm.tmLastChar, 65);
+        ok_int(tm.tmDefaultChar, 165);
+        ok_int(tm.tmBreakChar, 65);
+        ok_int(tm.tmItalic, 0);
+        ok_int(tm.tmUnderlined, 0);
+        ok_int(tm.tmStruckOut, 0);
+        ok_hex(tm.tmPitchAndFamily, TMPF_TRUETYPE | TMPF_VECTOR);
+        ok_int(tm.tmCharSet, SHIFTJIS_CHARSET);
+
+        SelectObject(hdc, old);
+        DeleteObject(font);
+    }
+}
+
+/* Not working as of 2017-04-08 on ReactOS */
+static BOOL is_font_available(HDC hdc, const char* fontName)
+{
+    char name[64];
+    BOOL ret;
+
+    HFONT font = CreateFontA(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
+                            OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, fontName);
+    HGDIOBJ old = SelectObject(hdc, font);
+
+
+    SetLastError(0xdeadbeef);
+
+    ret = GetTextFaceA(hdc, sizeof(name), name);
+    ok(ret, "GetTextFaceA error %lu\n", GetLastError());
+    SelectObject(hdc, old);
+    DeleteObject(font);
+
+    if (ret)
+    {
+        return !_strcmpi(name, fontName);
+    }
+    return FALSE;
+}
+
+
+
+START_TEST(AddFontMemResourceEx)
+{
+    HMODULE mod;
+    HRSRC hRsrc;
+
+    HGLOBAL hTemplate;
+    DWORD dwSize, dwNumFonts;
+    LPVOID pFont;
+
+    HANDLE hFont;
+
+    HDC hdc = CreateCompatibleDC(NULL);
+    BOOL is_font_available_broken = is_font_available(hdc, "Nonexisting font name here");
+
+    ok(!is_font_available_broken, "Validating font is broken! (CORE-13053) !\n");
+
+    if (is_font_available_broken || !is_font_available(hdc, "PanosePitchTest"))
+    {
+        mod = GetModuleHandle(NULL);
+        hRsrc = FindResource(mod, TEXT("PanosePitchTest.ttf"), MAKEINTRESOURCE(RT_RCDATA));
+
+        hTemplate = LoadResource(mod, hRsrc);
+        dwSize = SizeofResource(mod, hRsrc);
+        pFont = LockResource(hTemplate);
+
+        dwNumFonts = 0;
+        hFont = AddFontMemResourceEx(pFont, dwSize, NULL, &dwNumFonts);
+        ok_int(dwNumFonts, 2);
+        ok(hFont != NULL, "Expected valid handle\n");
+
+        if (hFont)
+        {
+            test_font_caps(hdc);
+            RemoveFontMemResourceEx(hFont);
+            if (!is_font_available_broken)
+            {
+                ok (!is_font_available(hdc, "PanosePitchTest"), "Expected font to be unregistered again\n");
+            }
+            else
+            {
+                skip("Font unregister test\n");
+            }
+        }
+
+        UnlockResource(hTemplate);
+        FreeResource(hTemplate);
+    }
+    else
+    {
+        skip("Font PanosePitchTest already available\n");
+    }
+    DeleteDC(hdc);
+}
+
index 7c593eb..e1edb91 100644 (file)
@@ -2,6 +2,7 @@
 include_directories(${REACTOS_SOURCE_DIR}/win32ss)
 
 list(APPEND SOURCE
+    AddFontMemResourceEx.c
     AddFontResource.c
     AddFontResourceEx.c
     BeginPath.c
diff --git a/rostests/apitests/gdi32/PanosePitchTest.ttf b/rostests/apitests/gdi32/PanosePitchTest.ttf
new file mode 100644 (file)
index 0000000..cfdd9c6
Binary files /dev/null and b/rostests/apitests/gdi32/PanosePitchTest.ttf differ
index 5b3c2db..fbf571f 100644 (file)
@@ -1,3 +1,4 @@
 #include "windef.h"
 
 ReactOSTestTahoma.ttf RCDATA ReactOSTestTahoma.ttf
+PanosePitchTest.ttf RCDATA PanosePitchTest.ttf
index 48204c0..db6ded9 100644 (file)
@@ -3,6 +3,7 @@
 #define STANDALONE
 #include <apitest.h>
 
+extern void func_AddFontMemResourceEx(void);
 extern void func_AddFontResource(void);
 extern void func_AddFontResourceEx(void);
 extern void func_BeginPath(void);
@@ -75,6 +76,7 @@ extern void func_SetWorldTransform(void);
 
 const struct test winetest_testlist[] =
 {
+    { "AddFontMemResourceEx", func_AddFontMemResourceEx },
     { "AddFontResource", func_AddFontResource },
     { "AddFontResourceEx", func_AddFontResourceEx },
     { "BeginPath", func_BeginPath },