From f64b823282807ebd9e2fa36252a1ab4996469367 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 19 May 2017 20:26:49 +0000 Subject: [PATCH] [GDI32_APITEST] Improve GetFontResourceInfoW tests. Patch by Katayama Hirofumi MZ. ROSTESTS-269 #resolve #comment Thanks! svn path=/trunk/; revision=74602 --- rostests/apitests/gdi32/ExampleFont.ttf | Bin 0 -> 1792 bytes .../apitests/gdi32/GetFontResourceInfoW.c | 91 +++++++++++++++--- rostests/apitests/gdi32/resource.rc | 1 + 3 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 rostests/apitests/gdi32/ExampleFont.ttf diff --git a/rostests/apitests/gdi32/ExampleFont.ttf b/rostests/apitests/gdi32/ExampleFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..72094599baad324c961bc37223c1fbf7ed6c3e89 GIT binary patch literal 1792 zcmd5+U27Cq7=F%~*^L@e*DazD>TF$N3?Xh-F_td2(PaGqKOh>5V0BzKJEJo@Wv6`QF>8Y+KYlWUPv+MMFkPf`kb?4>POUD&vMQ@&--=W z^PYDP1b}%s4g>r1`JG$8I}<(u;`b=~O`dlA+NivWTjY1h7kELz#sTc4zePUBw?{*4!spa)BDc!6Uu+-x=3DA7 z0rKB4sMZ>bv6}n;Kz%3FSvi0H<>~2t^K*}})VNOx{>+`c(ER?i6e)VP%8TT)AeEGZ zK3cLzc);_=vQYA&mCFZn`@)TP36}q*FDgG0u5o4quG-cKL;46Csgdvqo`CuJg8O;`}jjG0rsRjnA~RPoeo(|G_nG8MTECOvpR z{3+hYJJM_8W@HHwpWXl}yXi_0>Y@BTH2y!&hb%uPjtDKY#0?c4I=^Wl{I zT9tVW=h$&cbyvw$A~hzQsq->9^}VV}0>8h!6MTww5f+r6h_J*bxDjCkNj#0PiG^Zy zgkxAB+z7|fD$b}*FlRGIYC}P>(KEI_Bx_6MNilo5n?&luMplb@I0F zdi8C5FW&ST#0a05_xTQv9C+P*R0j{aQIU=Tlc-@AR~JVZtccC%=PskRA9}@nP_FGN zyGKTfo0agjg!^^kDvmuv%KdIN^z10-A%?B+l&;>+V&PQjy7f21@?of0sk%Yg%4B-F zGnot}1DGk#SMvh4aOaS-% */ #include +#include #include #include #include @@ -16,6 +17,7 @@ BOOL WINAPI GetFontResourceInfoW(LPCWSTR lpFileName, DWORD *pdwBufSize, void* lp typedef struct GFRI_ENTRY { LPCWSTR File; + BOOL Preinstalled; WCHAR FontInfo[64]; INT FontCount; WCHAR FaceNames[10][64]; @@ -24,9 +26,9 @@ typedef struct GFRI_ENTRY /* test entries */ static const GFRI_ENTRY TestEntries[] = { - { L"symbol.ttf", L"Symbol|", 1, { L"Symbol" } }, - { L"tahoma.ttf", L"Tahoma|", 1, { L"Tahoma" } }, - { L"tahomabd.ttf", L"Tahoma Bold|", 1, { L"Tahoma" } } + { L"symbol.ttf", TRUE, L"Symbol|", 1, { L"Symbol" } }, + { L"tahoma.ttf", TRUE, L"Tahoma|", 1, { L"Tahoma" } }, + { L"tahomabd.ttf", TRUE, L"Tahoma Bold|", 1, { L"Tahoma" } } }; /* Japanese */ @@ -34,7 +36,7 @@ static const GFRI_ENTRY AdditionalTestEntriesJapanese[] = { { /* MS Gothic & MS UI Gothic & MS PGothic */ - L"msgothic.ttc", + L"msgothic.ttc", TRUE, { 0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0020, 0x0026, 0x0020, 0x004D, 0x0053, 0x0020, 0x0055, 0x0049, 0x0020, @@ -51,6 +53,14 @@ static const GFRI_ENTRY AdditionalTestEntriesJapanese[] = { 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 }, { L'@', 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 } } + }, + { + L"ExampleFont.ttf", FALSE, + L"JapaneseDisplayName|", + 1, + { + L"JapaneseFamilyName" + } } }; @@ -59,7 +69,7 @@ static const GFRI_ENTRY AdditionalTestEntriesEnglish[] = { { /* MS Gothic & MS UI Gothic & MS PGothic */ - L"msgothic.ttc", + L"msgothic.ttc", TRUE, L"MS Gothic & MS UI Gothic & MS PGothic|", 6, { @@ -70,6 +80,14 @@ static const GFRI_ENTRY AdditionalTestEntriesEnglish[] = L"MS PGothic", L"@MS PGothic" } + }, + { + L"ExampleFont.ttf", FALSE, + L"EnglishDisplayName|", + 1, + { + L"EnglishFamilyName" + } } }; @@ -381,14 +399,56 @@ Test_GetFontResourceInfoW_case5(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry) static void DoEntry(const GFRI_ENTRY *Entry) { - WCHAR szPath[MAX_PATH]; + WCHAR szPath[MAX_PATH], szTempPath[MAX_PATH]; + BOOL Installed = FALSE; - GetSystemFontPath(szPath, Entry->File); - printf("GetSystemFontPath: %S\n", szPath); - if (GetFileAttributesW(szPath) == 0xFFFFFFFF) + if (Entry->Preinstalled) { - skip("Font file \"%S\" was not found\n", szPath); - return; + GetSystemFontPath(szPath, Entry->File); + printf("GetSystemFontPath: %S\n", szPath); + if (GetFileAttributesW(szPath) == INVALID_FILE_ATTRIBUTES) + { + skip("Font file \"%S\" was not found\n", szPath); + return; + } + } + else + { + /* load font data from resource */ + HANDLE hFile; + HMODULE hMod = GetModuleHandleW(NULL); + HRSRC hRsrc = FindResourceW(hMod, Entry->File, (LPCWSTR)RT_RCDATA); + HGLOBAL hGlobal = LoadResource(hMod, hRsrc); + DWORD Size = SizeofResource(hMod, hRsrc); + LPVOID pFont = LockResource(hGlobal); + + /* get temporary file name */ + GetTempPathW(_countof(szTempPath), szTempPath); + GetTempFileNameW(szTempPath, L"FNT", 0, szPath); + printf("GetTempFileNameW: %S\n", szPath); + + /* write to file */ + hFile = CreateFileW(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + WriteFile(hFile, pFont, Size, &Size, NULL); + CloseHandle(hFile); + + /* check existence */ + if (GetFileAttributesW(szPath) == INVALID_FILE_ATTRIBUTES) + { + skip("Font file \"%S\" was not stored\n", szPath); + return; + } + + /* install */ + Installed = !!AddFontResourceW(szPath); + if (!Installed) + { + skip("Font file \"%S\" was not installed\n", szPath); + RemoveFontResourceW(szPath); + DeleteFileW(szPath); + return; + } } Test_GetFontResourceInfoW_case0(szPath, Entry); @@ -397,6 +457,15 @@ DoEntry(const GFRI_ENTRY *Entry) Test_GetFontResourceInfoW_case3(szPath, Entry); Test_GetFontResourceInfoW_case4(szPath, Entry); Test_GetFontResourceInfoW_case5(szPath, Entry); + + if (!Entry->Preinstalled) + { + if (Installed) + { + RemoveFontResourceW(szPath); + DeleteFileW(szPath); + } + } } START_TEST(GetFontResourceInfoW) diff --git a/rostests/apitests/gdi32/resource.rc b/rostests/apitests/gdi32/resource.rc index 71ccce92193..3c758a78be2 100644 --- a/rostests/apitests/gdi32/resource.rc +++ b/rostests/apitests/gdi32/resource.rc @@ -4,3 +4,4 @@ ReactOSTestTahoma.ttf RCDATA ReactOSTestTahoma.ttf PanosePitchTest.ttf RCDATA PanosePitchTest.ttf TTCTestV.ttc RCDATA TTCTestV.ttc Shadows_Into_Light.ttf RCDATA Shadows_Into_Light.ttf +ExampleFont.ttf RCDATA ExampleFont.ttf -- 2.17.1