ReactOS 0.4.16-dev-199-g898cc56
AddFontMemResourceEx.c File Reference
#include "precomp.h"
Include dependency graph for AddFontMemResourceEx.c:

Go to the source code of this file.

Classes

struct  _fnt_res
 
struct  _fnt_test
 

Macros

#define ok_int2(expression)
 
#define ok_hex2(expression)
 

Typedefs

typedef struct _fnt_res fnt_res
 
typedef struct _fnt_test fnt_test
 

Functions

static void test_font_caps (HDC hdc, int test_index)
 
static BOOL is_font_available (HDC hdc, const char *fontName)
 
 START_TEST (AddFontMemResourceEx)
 

Variables

static fnt_test test_data []
 

Macro Definition Documentation

◆ ok_hex2

#define ok_hex2 (   expression)
Value:
do { \
int _value = (expression); \
ok(_value == (res->expression), "Wrong value for '%s', expected: 0x%x, got: 0x%x for %s/%s\n", \
#expression, (int)(res->expression), _value, test_name, res->FontName); \
} while (0)
GLuint res
Definition: glext.h:9613
static const char * test_name
Definition: run.c:177

Definition at line 212 of file AddFontMemResourceEx.c.

◆ ok_int2

#define ok_int2 (   expression)
Value:
do { \
int _value = (expression); \
ok(_value == (res->expression), "Wrong value for '%s', expected: %d, got: %d for %s/%s\n", \
#expression, (int)(res->expression), _value, test_name, res->FontName); \
} while (0)

Definition at line 205 of file AddFontMemResourceEx.c.

Typedef Documentation

◆ fnt_res

◆ fnt_test

Function Documentation

◆ is_font_available()

static BOOL is_font_available ( HDC  hdc,
const char fontName 
)
static

Definition at line 281 of file AddFontMemResourceEx.c.

282{
283 char name[64];
284 BOOL ret;
285
289
290
291 SetLastError(0xdeadbeef);
292
293 ret = GetTextFaceA(hdc, sizeof(name), name);
294 ok(ret, "GetTextFaceA error %lu for %s\n", GetLastError(), fontName);
295 SelectObject(hdc, old);
297
298 if (ret)
299 {
300 return !_strcmpi(name, fontName);
301 }
302 return FALSE;
303}
#define ok(value,...)
Definition: atltest.h:57
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLenum const GLvoid * fontName
Definition: glext.h:11715
HDC hdc
Definition: main.c:9
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: mk_font.cpp:20
_Check_return_ _CRTIMP int __cdecl _strcmpi(_In_z_ const char *_Str1, _In_z_ const char *_Str2)
Definition: name.c:39
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define DEFAULT_PITCH
Definition: wingdi.h:443
#define FW_DONTCARE
Definition: wingdi.h:368
#define DEFAULT_QUALITY
Definition: wingdi.h:436
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
int WINAPI GetTextFaceA(_In_ HDC hdc, _In_ int c, _Out_writes_to_opt_(c, return) LPSTR lpName)
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:415
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:426
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( AddFontMemResourceEx  )

Definition at line 307 of file AddFontMemResourceEx.c.

308{
309 HMODULE mod;
310 HRSRC hRsrc;
311
312 HGLOBAL hTemplate;
313 DWORD dwSize, dwNumFonts;
314 LPVOID pFont;
315
317 fnt_test* data;
318 int n;
319
321 BOOL is_font_available_broken = is_font_available(hdc, "Nonexisting font name here");
322
323 ok(!is_font_available_broken, "Validating font is broken! (CORE-13053)!\n");
324
325 for (n = 0; n < _countof(test_data); ++n)
326 {
327 data = test_data + n;
328
330 hRsrc = FindResourceA(mod, data->ResourceName, MAKEINTRESOURCE(RT_RCDATA));
331
332 hTemplate = LoadResource(mod, hRsrc);
333 dwSize = SizeofResource(mod, hRsrc);
334 pFont = LockResource(hTemplate);
335
336 dwNumFonts = 0;
337 hFont = AddFontMemResourceEx(pFont, dwSize, NULL, &dwNumFonts);
338 ok(dwNumFonts == data->NumFaces, "dwNumFonts was %lu, expected %d for %s\n", dwNumFonts, data->NumFaces, data->ResourceName);
339 ok(hFont != NULL, "Expected valid handle for %s\n", data->ResourceName);
340
341 if (hFont)
342 {
345 if (!is_font_available_broken)
346 {
347 ok (!is_font_available(hdc, data->ResourceName), "Expected font to be unregistered again for %s\n", data->ResourceName);
348 }
349 else
350 {
351 skip("Font unregister test for %s\n", data->ResourceName);
352 }
353 }
354
355 UnlockResource(hTemplate);
356 FreeResource(hTemplate);
357 }
358
359 DeleteDC(hdc);
360}
static void test_font_caps(HDC hdc, int test_index)
static BOOL is_font_available(HDC hdc, const char *fontName)
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
#define skip(...)
Definition: atltest.h:64
HFONT hFont
Definition: main.c:53
#define NULL
Definition: types.h:112
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static HDC
Definition: imagelist.c:88
#define RT_RCDATA
Definition: pedump.c:372
#define _countof(array)
Definition: sndvol32.h:70
BOOL WINAPI RemoveFontMemResourceEx(HANDLE fh)
Definition: font.c:2475
#define GetModuleHandle
Definition: winbase.h:3851
#define UnlockResource(handle)
Definition: winbase.h:3396
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DeleteDC(_In_ HDC)
HANDLE WINAPI AddFontMemResourceEx(_In_reads_bytes_(cjSize) PVOID pvFileView, _In_ DWORD cjSize, _Reserved_ PVOID pvResrved, _In_ DWORD *pNumFonts)
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ test_font_caps()

static void test_font_caps ( HDC  hdc,
int  test_index 
)
static

Definition at line 220 of file AddFontMemResourceEx.c.

221{
222 HGDIOBJ old;
223 TEXTMETRICA tm = { 0 };
224 char name[64];
225 BOOL ret;
226 HFONT font;
227 int n;
228 const char* test_name = test_data[test_index].ResourceName;
229
230 for (n = 0; test_data[test_index].res[n].FontName; ++n)
231 {
232 fnt_res* res = test_data[test_index].res + n;
235
236 if (font)
237 {
238 old = SelectObject(hdc, font);
239
240 memset(&tm, 0xaa, sizeof(tm));
242 ok(ret, "GetTextMetricsA() for %s/%s\n", test_name, res->FontName);
243
244 SetLastError(0xdeadbeef);
245 ret = GetTextFaceA(hdc, sizeof(name), name);
246 ok(ret, "GetTextFaceA error %lu for %s/%s\n", GetLastError(), test_name, res->FontName);
247 if (ret)
248 {
249 ok(!strcmp(name, res->FontName), "FontName was %s, expected %s for %s/%s", name, res->FontName, test_name, res->FontName);
250 }
251
252 ok_int2(tm.tmHeight);
253 ok_int2(tm.tmAscent);
254 ok_int2(tm.tmDescent);
255 ok_int2(tm.tmInternalLeading);
256 ok_int2(tm.tmExternalLeading);
257 ok_int2(tm.tmAveCharWidth);
258 ok_int2(tm.tmMaxCharWidth);
259 ok_int2(tm.tmWeight);
260 ok_int2(tm.tmOverhang);
261 ok_int2(tm.tmDigitizedAspectX);
262 ok_int2(tm.tmDigitizedAspectY);
263 ok_int2(tm.tmFirstChar);
264 ok_int2(tm.tmLastChar);
265 ok_int2(tm.tmDefaultChar);
266 ok_int2(tm.tmBreakChar);
267 ok_int2(tm.tmItalic);
268 ok_int2(tm.tmUnderlined);
269 ok_int2(tm.tmStruckOut);
270 ok_hex2(tm.tmPitchAndFamily);
271 ok_int2(tm.tmCharSet);
272
273 SelectObject(hdc, old);
275 }
276 }
277}
#define ok_int2(expression)
#define ok_hex2(expression)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define memset(x, y, z)
Definition: compat.h:39
Definition: time.h:68
BOOL WINAPI GetTextMetricsA(_In_ HDC, _Out_ LPTEXTMETRICA)
Definition: text.c:200

Referenced by START_TEST().

Variable Documentation

◆ test_data

fnt_test test_data[]
static

Definition at line 29 of file AddFontMemResourceEx.c.