ReactOS  0.4.15-dev-341-g17c5fb8
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)
static const char * test_name
Definition: run.c:177
GLuint res
Definition: glext.h:9613

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)
static const char * test_name
Definition: run.c:177
GLuint res
Definition: glext.h:9613

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 
288  HGDIOBJ old = SelectObject(hdc, font);
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 DEFAULT_QUALITY
Definition: wingdi.h:435
Definition: mk_font.cpp:20
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define DEFAULT_CHARSET
Definition: wingdi.h:383
GLenum const GLvoid * fontName
Definition: glext.h:11715
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
#define DEFAULT_PITCH
Definition: wingdi.h:442
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
#define SetLastError(x)
Definition: compat.h:418
int ret
HDC hdc
Definition: main.c:9
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)
#define FW_DONTCARE
Definition: wingdi.h:367
#define ok(value,...)
Definition: atltest.h:57
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: name.c:38
int WINAPI GetTextFaceA(_In_ HDC hdc, _In_ int c, _Out_writes_to_opt_(c, return) LPSTR lpName)
_Check_return_ _CRTIMP int __cdecl _strcmpi(_In_z_ const char *_Str1, _In_z_ const char *_Str2)

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 
316  HANDLE hFont;
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  {
343  test_font_caps(hdc, n);
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 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
static HDC
Definition: imagelist.c:92
GLdouble n
Definition: glext.h:7729
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HANDLE WINAPI AddFontMemResourceEx(_In_reads_bytes_(cjSize) PVOID pvFileView, _In_ DWORD cjSize, _Reserved_ PVOID pvResrved, _In_ DWORD *pNumFonts)
HFONT hFont
Definition: main.c:53
#define UnlockResource(h)
Definition: winbase.h:3212
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
static void test_font_caps(HDC hdc, int test_index)
#define _countof(array)
Definition: sndvol32.h:68
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define RT_RCDATA
Definition: pedump.c:372
HDC hdc
Definition: main.c:9
BOOL WINAPI RemoveFontMemResourceEx(HANDLE fh)
Definition: font.c:2475
#define GetModuleHandle
Definition: winbase.h:3667
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define skip(...)
Definition: atltest.h:64
static BOOL is_font_available(HDC hdc, const char *fontName)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
static int mod
Definition: i386-dis.c:1273

◆ 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));
241  ret = GetTextMetricsA(hdc, &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 DEFAULT_QUALITY
Definition: wingdi.h:435
Definition: mk_font.cpp:20
GLdouble n
Definition: glext.h:7729
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define DEFAULT_CHARSET
Definition: wingdi.h:383
#define ok_int2(expression)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
BOOL WINAPI GetTextMetricsA(_In_ HDC, _Out_ LPTEXTMETRICA)
Definition: text.c:200
#define DEFAULT_PITCH
Definition: wingdi.h:442
#define ok_hex2(expression)
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
#define SetLastError(x)
Definition: compat.h:418
int ret
HDC hdc
Definition: main.c:9
Definition: time.h:76
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)
static const char * test_name
Definition: run.c:177
#define FW_DONTCARE
Definition: wingdi.h:367
#define ok(value,...)
Definition: atltest.h:57
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: name.c:38
int WINAPI GetTextFaceA(_In_ HDC hdc, _In_ int c, _Out_writes_to_opt_(c, return) LPSTR lpName)
GLuint res
Definition: glext.h:9613
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

Variable Documentation

◆ test_data

fnt_test test_data[]
static

Definition at line 29 of file AddFontMemResourceEx.c.