ReactOS  0.4.14-dev-1256-g2125fec
EnumFontFamilies.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Test for EnumFontFamilies[Ex]
5  * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
12 
13 static int EnumProcCalls;
16 
19 
20 static
21 int
23  _In_ HDC hdc,
27 {
28  char FamilyA[100];
29  WideCharToMultiByte(CP_ACP, 0, Family, -1, FamilyA, sizeof(FamilyA), NULL, NULL);
30  return EnumFontFamiliesA(hdc, FamilyA, EnumProc, lParam);
31 }
32 
33 static
34 int
36  _In_ HDC hdc,
40 {
42 }
43 
44 static
45 int
47  _In_ HDC hdc,
51 {
52  LOGFONTA lf;
53 
54  ZeroMemory(&lf, sizeof(lf));
56  lf.lfPitchAndFamily = 0;
57  WideCharToMultiByte(CP_ACP, 0, Family, -1, lf.lfFaceName, sizeof(lf.lfFaceName), NULL, NULL);
58  return EnumFontFamiliesExA(hdc, &lf, EnumProc, lParam, 0);
59 }
60 
61 static
62 int
64  _In_ HDC hdc,
68 {
69  LOGFONTW lf;
70 
71  ZeroMemory(&lf, sizeof(lf));
73  lf.lfPitchAndFamily = 0;
74  StringCbCopyW(lf.lfFaceName, sizeof(lf.lfFaceName), Family);
75  return EnumFontFamiliesExW(hdc, &lf, EnumProc, lParam, 0);
76 }
77 
78 static
79 int
82  _In_ const LOGFONTA *elf,
83  _In_ const TEXTMETRICA *ntm,
84  _In_ DWORD FontType,
86 {
87  EnumProcCalls++;
88 
91  "Context is %p, expected %p or %p\n",
93 
94  LastFontA = *(ENUMLOGFONTA *)elf;
95  return lParam == (LPARAM)&ContextContinue ? 7 : 0;
96 }
97 
98 static
99 int
100 CALLBACK
102  _In_ const LOGFONTW *elf,
103  _In_ const TEXTMETRICW *ntm,
104  _In_ DWORD FontType,
106 {
107  EnumProcCalls++;
108 
111  "Context is %p, expected %p or %p\n",
113 
114  LastFontW = *(ENUMLOGFONTW *)elf;
115  return lParam == (LPARAM)&ContextContinue ? 7 : 0;
116 }
117 
118 static
119 void
121  _In_ HDC hdc,
122  _In_ PCWSTR FontName,
123  _In_ BOOLEAN ExpectToFind)
124 {
125  const struct
126  {
127  PWRAP_ENUM_FONT_FAMILIES Wrapper;
128  PCSTR Name;
129  BOOLEAN Wide;
130  } *fun, functions[] =
131  {
132  { WrapEnumFontFamiliesA, "EnumFontFamiliesA", FALSE },
133  { WrapEnumFontFamiliesW, "EnumFontFamiliesW", TRUE },
134  { WrapEnumFontFamiliesExA, "EnumFontFamiliesExA", FALSE },
135  { WrapEnumFontFamiliesExW, "EnumFontFamiliesExW", TRUE },
136  };
137  const struct
138  {
139  PVOID Context;
141  } *ctx, contexts[] =
142  {
143  { &ContextContinue, "Continue" },
144  { &ContextStop, "Stop" },
145  };
146  int ret;
147  DWORD error;
148  unsigned iFunction;
149  unsigned iContext;
150 
151  for (iContext = 0; iContext < _countof(contexts); iContext++)
152  {
153  ctx = &contexts[iContext];
154  for (iFunction = 0; iFunction < _countof(functions); iFunction++)
155  {
156  fun = &functions[iFunction];
157  EnumProcCalls = 0;
158  SetLastError(0xdeadbeef);
159  ret = fun->Wrapper(hdc,
160  FontName,
161  fun->Wide ? (PVOID)EnumProcW : (PVOID)EnumProcA,
162  (LPARAM)ctx->Context);
163  error = GetLastError();
164  ok(error == 0xdeadbeef, "[%s, %s, '%ls'] error is %lu\n", fun->Name, ctx->Description, FontName, error);
165  if (ExpectToFind)
166  {
167  if (ctx->Context == &ContextContinue)
168  {
169  ok(ret == 7, "[%s, %s, '%ls'] ret is %d, expected 7\n", fun->Name, ctx->Description, FontName, ret);
170  ok(EnumProcCalls >= 1, "[%s, %s, '%ls'] EnumProcCalls is %d\n", fun->Name, ctx->Description, FontName, EnumProcCalls);
171  }
172  else
173  {
174  ok(ret == 0, "[%s, %s, '%ls'] ret is %d, expected 0\n", fun->Name, ctx->Description, FontName, ret);
175  ok(EnumProcCalls == 1, "[%s, %s, '%ls'] EnumProcCalls is %d\n", fun->Name, ctx->Description, FontName, EnumProcCalls);
176  }
177  }
178  else
179  {
180  ok(ret == 1, "[%s, %s, '%ls'] ret is %d, expected 1\n", fun->Name, ctx->Description, FontName, ret);
181  ok(EnumProcCalls == 0, "[%s, %s, '%ls'] EnumProcCalls is %d\n", fun->Name, ctx->Description, FontName, EnumProcCalls);
182  }
183  }
184  }
185 }
186 
188 {
189  HDC hdc;
190 
192  if (!hdc)
193  {
194  skip("No DC\n");
195  return;
196  }
197 
198  TestEnumFontFamilies(hdc, L"ThisFontDoesNotExist", FALSE);
199  /* Basic fonts that should be installed */
200  TestEnumFontFamilies(hdc, L"MS Sans Serif", TRUE);
201  TestEnumFontFamilies(hdc, L"Tahoma", TRUE);
202  TestEnumFontFamilies(hdc, L"System", TRUE);
203  /* Show case insensitivity */
204  TestEnumFontFamilies(hdc, L"tahOmA", TRUE);
205  /* Special fonts that we have a hack for in win32k ;) */
206  TestEnumFontFamilies(hdc, L"Marlett", TRUE);
207  TestEnumFontFamilies(hdc, L"Symbol", TRUE);
209 
210  DeleteDC(hdc);
211 }
212 
const uint16_t * PCWSTR
Definition: typedefs.h:56
static int CALLBACK EnumProcA(_In_ const LOGFONTA *elf, _In_ const TEXTMETRICA *ntm, _In_ DWORD FontType, _In_ LPARAM lParam)
#define TRUE
Definition: types.h:120
BYTE lfPitchAndFamily
Definition: dimm.idl:71
#define WideCharToMultiByte
Definition: compat.h:101
#define error(str)
Definition: mkdosfs.c:1605
int WINAPI EnumFontFamiliesExW(_In_ HDC, _In_ PLOGFONTW, _In_ FONTENUMPROCW, _In_ LPARAM, _In_ DWORD)
#define CP_ACP
Definition: compat.h:99
BYTE lfCharSet
Definition: dimm.idl:67
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1648
BYTE lfCharSet
Definition: dimm.idl:50
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
static BYTE ContextStop
static const WCHAR Description[]
Definition: oid.c:1266
static int CALLBACK EnumProcW(_In_ const LOGFONTW *elf, _In_ const TEXTMETRICW *ntm, _In_ DWORD FontType, _In_ LPARAM lParam)
#define DEFAULT_CHARSET
Definition: wingdi.h:383
static int Family
Definition: ping.c:62
static int WrapEnumFontFamiliesExW(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
int WINAPI EnumFontFamiliesA(_In_ HDC, _In_opt_ LPCSTR, _In_ FONTENUMPROCA, _In_ LPARAM)
static ENUMLOGFONTA LastFontA
struct NameRec_ * Name
Definition: cdprocs.h:464
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
BYTE lfPitchAndFamily
Definition: dimm.idl:54
WRAP_ENUM_FONT_FAMILIES * PWRAP_ENUM_FONT_FAMILIES
static int WrapEnumFontFamiliesA(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
#define _countof(array)
Definition: sndvol32.h:68
static int WrapEnumFontFamiliesW(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
int ret
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
#define EnumFontFamilies
Definition: wingdi.h:4449
unsigned char BYTE
Definition: mem.h:68
#define _In_
Definition: no_sal2.h:204
static int EnumProcCalls
BOOL WINAPI DeleteDC(_In_ HDC)
static void TestEnumFontFamilies(_In_ HDC hdc, _In_ PCWSTR FontName, _In_ BOOLEAN ExpectToFind)
#define ok(value,...)
Definition: atltest.h:57
static ENUMLOGFONTW LastFontW
int WINAPI EnumFontFamiliesW(_In_ HDC, _In_opt_ LPCWSTR, _In_ FONTENUMPROCW, _In_ LPARAM)
#define skip(...)
Definition: atltest.h:64
static int WrapEnumFontFamiliesExA(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
struct tagContext Context
Definition: acpixf.h:1034
static BOOL CALLBACK EnumProc(_In_ HWND hWnd, _In_ LPARAM lParam)
Definition: SetParent.c:53
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
const char * PCSTR
Definition: typedefs.h:52
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
int WINAPI EnumFontFamiliesExA(_In_ HDC, _In_ PLOGFONTA, _In_ FONTENUMPROCA, _In_ LPARAM, _In_ DWORD)
static BYTE ContextContinue
LPARAM lParam
Definition: combotst.c:139
int WRAP_ENUM_FONT_FAMILIES(_In_ HDC, _In_ PCWSTR, _In_ PVOID, _In_ LPARAM)
START_TEST(EnumFontFamilies)