[5/5] gdi32: Add a buch of CreateScalableFontResource() tests. Take 4.

Dmitry Timoshkov dmitry at codeweavers.com
Wed Nov 24 12:11:34 CST 2010


---
 dlls/gdi32/tests/Makefile.in   |    2 +
 dlls/gdi32/tests/font.c        |  187 ++++++++++++++++++++++++++++++++++++++++
 dlls/gdi32/tests/resource.rc   |   24 +++++
 dlls/gdi32/tests/wine_test.ttf |  Bin 0 -> 1544 bytes
 4 files changed, 213 insertions(+), 0 deletions(-)
 create mode 100644 dlls/gdi32/tests/resource.rc
 create mode 100644 dlls/gdi32/tests/wine_test.ttf

diff --git a/dlls/gdi32/tests/Makefile.in b/dlls/gdi32/tests/Makefile.in
index 90f937e..89078d4 100644
--- a/dlls/gdi32/tests/Makefile.in
+++ b/dlls/gdi32/tests/Makefile.in
@@ -16,4 +16,6 @@ C_SRCS = \
 	path.c \
 	pen.c
 
+RC_SRCS = resource.rc
+
 @MAKE_TEST_RULES@
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index c87b062..55d869c 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -46,6 +46,8 @@ static BOOL  (WINAPI *pGdiRealizationInfo)(HDC hdc, DWORD *);
 static HFONT (WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDV *);
 static HANDLE (WINAPI *pAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *);
 static BOOL  (WINAPI *pRemoveFontMemResourceEx)(HANDLE);
+static INT   (WINAPI *pAddFontResourceExA)(LPCSTR, DWORD, PVOID);
+static BOOL  (WINAPI *pRemoveFontResourceExA)(LPCSTR, DWORD, PVOID);
 
 static HMODULE hgdi32 = 0;
 
@@ -63,6 +65,8 @@ static void init(void)
     pCreateFontIndirectExA = (void *)GetProcAddress(hgdi32, "CreateFontIndirectExA");
     pAddFontMemResourceEx = (void *)GetProcAddress(hgdi32, "AddFontMemResourceEx");
     pRemoveFontMemResourceEx = (void *)GetProcAddress(hgdi32, "RemoveFontMemResourceEx");
+    pAddFontResourceExA = (void *)GetProcAddress(hgdi32, "AddFontResourceExA");
+    pRemoveFontResourceExA = (void *)GetProcAddress(hgdi32, "RemoveFontResourceExA");
 }
 
 static INT CALLBACK is_truetype_font_installed_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
@@ -3307,6 +3311,184 @@ static void test_AddFontMemResource(void)
     free_font(font);
 }
 
+static BOOL write_ttf_file(char *tmp_name)
+{
+    char tmp_path[MAX_PATH];
+    HRSRC rsrc;
+    void *rsrc_data;
+    DWORD rsrc_size;
+    HANDLE hfile;
+    BOOL ret;
+
+    SetLastError(0xdeadbeef);
+    rsrc = FindResource(GetModuleHandle(0), "wine_test.ttf", RT_RCDATA);
+    ok(rsrc != 0, "FindResource error %d\n", GetLastError());
+    if (!rsrc) return FALSE;
+    SetLastError(0xdeadbeef);
+    rsrc_data = LockResource(LoadResource(GetModuleHandle(0), rsrc));
+    ok(rsrc_data != 0, "LockResource error %d\n", GetLastError());
+    if (!rsrc_data) return FALSE;
+    SetLastError(0xdeadbeef);
+    rsrc_size = SizeofResource(GetModuleHandle(0), rsrc);
+    ok(rsrc_size != 0, "SizeofResource error %d\n", GetLastError());
+    if (!rsrc_size) return FALSE;
+
+    SetLastError(0xdeadbeef);
+    ret = GetTempPath(MAX_PATH, tmp_path);
+    ok(ret, "GetTempPath() error %d\n", GetLastError());
+    SetLastError(0xdeadbeef);
+    ret = GetTempFileName(tmp_path, "ttf", 0, tmp_name);
+    ok(ret, "GetTempFileName() error %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    hfile = CreateFile(tmp_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+    ok(hfile != INVALID_HANDLE_VALUE, "CreateFile() error %d\n", GetLastError());
+    if (hfile == INVALID_HANDLE_VALUE) return FALSE;
+
+    SetLastError(0xdeadbeef);
+    ret = WriteFile(hfile, rsrc_data, rsrc_size, &rsrc_size, NULL);
+    ok(ret, "WriteFile() error %d\n", GetLastError());
+
+    CloseHandle(hfile);
+    return ret;
+}
+
+static void test_CreateScalableFontResource(void)
+{
+    char ttf_name[MAX_PATH];
+    char tmp_path[MAX_PATH];
+    char fot_name[MAX_PATH];
+    char *file_part;
+    DWORD ret;
+
+    if (!pAddFontResourceExA || !pRemoveFontResourceExA)
+    {
+        win_skip("AddFontResourceExA is not available on this platform\n");
+        return;
+    }
+
+    if (!write_ttf_file(ttf_name))
+    {
+        skip("Failed to create ttf file for testing\n");
+        return;
+    }
+
+    trace("created %s\n", ttf_name);
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    ret = GetTempPath(MAX_PATH, tmp_path);
+    ok(ret, "GetTempPath() error %d\n", GetLastError());
+    ret = GetTempFileName(tmp_path, "fot", 0, fot_name);
+    ok(ret, "GetTempFileName() error %d\n", GetLastError());
+
+    ret = GetFileAttributes(fot_name);
+    ok(ret != INVALID_FILE_ATTRIBUTES, "file %s does not exist\n", fot_name);
+
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, ttf_name, NULL);
+    ok(!ret, "CreateScalableFontResource() should fail\n");
+    ok(GetLastError() == ERROR_FILE_EXISTS, "not expected error %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, ttf_name, "");
+    ok(!ret, "CreateScalableFontResource() should fail\n");
+    ok(GetLastError() == ERROR_FILE_EXISTS, "not expected error %d\n", GetLastError());
+
+    file_part = strrchr(ttf_name, '\\');
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, file_part, tmp_path);
+    ok(!ret, "CreateScalableFontResource() should fail\n");
+    ok(GetLastError() == ERROR_FILE_EXISTS, "not expected error %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, "random file name", tmp_path);
+    ok(!ret, "CreateScalableFontResource() should fail\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, NULL, ttf_name);
+    ok(!ret, "CreateScalableFontResource() should fail\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
+
+    ret = DeleteFile(fot_name);
+    ok(ret, "DeleteFile() error %d\n", GetLastError());
+
+    ret = pRemoveFontResourceExA(fot_name, 0, 0);
+    ok(!ret, "RemoveFontResourceEx() should fail\n");
+
+    /* test public font resource */
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(0, fot_name, ttf_name, NULL);
+    ok(ret, "CreateScalableFontResource() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    SetLastError(0xdeadbeef);
+    ret = pAddFontResourceExA(fot_name, 0, 0);
+    ok(ret, "AddFontResourceEx() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(ret, "font wine_test should be enumerated\n");
+
+    ret = pRemoveFontResourceExA(fot_name, FR_PRIVATE, 0);
+    ok(!ret, "RemoveFontResourceEx() with not matching flags should fail\n");
+
+    SetLastError(0xdeadbeef);
+    ret = pRemoveFontResourceExA(fot_name, 0, 0);
+todo_wine
+    ok(ret, "RemoveFontResourceEx() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+todo_wine
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    /* FIXME: since RemoveFontResource is a stub correct testing is impossible */
+    if (ret)
+    {
+        /* remove once RemoveFontResource is implemented */
+        DeleteFile(fot_name);
+        DeleteFile(ttf_name);
+        return;
+    }
+
+    ret = pRemoveFontResourceExA(fot_name, 0, 0);
+    ok(!ret, "RemoveFontResourceEx() should fail\n");
+
+    DeleteFile(fot_name);
+
+    /* test hidden font resource */
+    SetLastError(0xdeadbeef);
+    ret = CreateScalableFontResource(1, fot_name, ttf_name, NULL);
+    ok(ret, "CreateScalableFontResource() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    SetLastError(0xdeadbeef);
+    ret = pAddFontResourceExA(fot_name, 0, 0);
+    ok(ret, "AddFontResourceEx() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    /* XP allows removing a private font added with 0 flags */
+    SetLastError(0xdeadbeef);
+    ret = pRemoveFontResourceExA(fot_name, FR_PRIVATE, 0);
+    ok(ret, "RemoveFontResourceEx() error %d\n", GetLastError());
+
+    ret = is_truetype_font_installed("wine_test");
+    ok(!ret, "font wine_test should not be enumerated\n");
+
+    ret = pRemoveFontResourceExA(fot_name, 0, 0);
+    ok(!ret, "RemoveFontResourceEx() should fail\n");
+
+    DeleteFile(fot_name);
+    DeleteFile(ttf_name);
+}
+
 START_TEST(font)
 {
     init();
@@ -3356,4 +3538,9 @@ START_TEST(font)
     test_CreateFontIndirect();
     test_CreateFontIndirectEx();
     test_oemcharset();
+
+    /* CreateScalableFontResource should be last test until RemoveFontResource
+     * is properly implemented.
+     */
+    test_CreateScalableFontResource();
 }
diff --git a/dlls/gdi32/tests/resource.rc b/dlls/gdi32/tests/resource.rc
new file mode 100644
index 0000000..f172b80
--- /dev/null
+++ b/dlls/gdi32/tests/resource.rc
@@ -0,0 +1,24 @@
+/*
+ * Resources for gdi32 test suite.
+ *
+ * Copyright 2010 Dmitry Timoshkov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "windef.h"
+
+/* @makedep: wine_test.ttf */
+wine_test.ttf RCDATA wine_test.ttf
diff --git a/dlls/gdi32/tests/wine_test.ttf b/dlls/gdi32/tests/wine_test.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..12dfe88dae541c3585231aac6786602817e31e58
GIT binary patch
literal 1544
zcmds1%S%*I82_F77+;~O(MseFnW^}=GfDKAh2*4e#6`ZMg%0y at E;$couI21ngbUk;
zL0~(fAaWMr9}wiCDB4sI8LbtfHx=6N+&MD_F4}i4=YGHM_dU*czjMxo08o$X&@nqS
zG(LLi-LJcVxlOiZIDBCU4QQqQlzQvf#lGOp at 6GQ4k)%EwO+~V3(4SL(&3Qh0)wK{d
z8v(tAc4ID*&+hFpGt9 at -tLNqmi4%8TuF>92eL5MB#6CY-{X{I+JC!6+ogZVoXrtbi
zOu38ZErh9WQa?POiAFHZ2f9VQHWgXSVgzSsAE9ogBdK_CYq_2F8-UiF&E(y^I<QuA
zh4wDUZ{^(l+IMcIA at mh>)g-9@=z39+TuqCa6V$7rNtS~#9<#Bw1gtG-F)vfeR(cyA
zV^m^fr0}=_^m;DZ+LHJJlbKGMw`puGN&OWPS`*iVk9|@@)>#=-PCAYO_~G{@b`#j}
zD)DNnxL6R{w(Jx0+^euMpPVhK+7LCFxdjF+N`sHo{oEt(z4t+RLiqL<5b|5fognmv
zjN7kQk^i0W&N8~yBfC&O9XhJeyDrcdDpncT39kFhx1pl05n^4Jv?=Lgl~4Q*71_d_
z;K at dR<8gnZKdf21ZDM6NX- at pSA2yzOU8~1~a_ at 1BXIl1GZb1#ME6f9e6 at _)~;Twew
z)QDPzO&k`d6!ww7EO*?fVWuI at 5*BE}yuum|VOe1vr?INAL7#65o3O+Yg?(re!x%&c
zSrm|igE`(Vm#3)%QFKxUVI#oF{{T|7yYwnh8z)XNE>Hg}lvjblOtz47=8~?}5$&{s
zcEGm6DaXwftZ^rm$tSO5=yZ*7X~Z$ZOmRlLq<9}@+<2aFlw6D+3(Sqtc+6R#oKhhc
z&T`>{2}*oFdRS<H?{dkI7tK0rRq_+}_XGkxvb29yGRaDEtk2=MrMax_^`Y03vKyF;
z=kiV_ZP|99*S2jk2P^yg)5<rFS2MxAJ2(tdf?iS*@eXTh=jH$WC^=~<{fDGyX?XI<
Q?!zsqZhmZ=D#>=|57Fe#DF6Tf

literal 0
HcmV?d00001

-- 
1.7.3.2




More information about the wine-patches mailing list