ReactOS 0.4.15-dev-7942-gd23573b
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
13static int EnumProcCalls;
16
19
20static
21int
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
33static
34int
36 _In_ HDC hdc,
40{
42}
43
44static
45int
47 _In_ HDC hdc,
51{
52 LOGFONTA lf;
53
54 ZeroMemory(&lf, sizeof(lf));
56 lf.lfPitchAndFamily = 0;
58 return EnumFontFamiliesExA(hdc, &lf, EnumProc, lParam, 0);
59}
60
61static
62int
64 _In_ HDC hdc,
68{
69 LOGFONTW lf;
70
71 ZeroMemory(&lf, sizeof(lf));
73 lf.lfPitchAndFamily = 0;
75 return EnumFontFamiliesExW(hdc, &lf, EnumProc, lParam, 0);
76}
77
78static
79int
82 _In_ const LOGFONTA *elf,
83 _In_ const TEXTMETRICA *ntm,
84 _In_ DWORD FontType,
86{
88
91 "Context is %p, expected %p or %p\n",
93
94 LastFontA = *(ENUMLOGFONTA *)elf;
95 return lParam == (LPARAM)&ContextContinue ? 7 : 0;
96}
97
98static
99int
102 _In_ const LOGFONTW *elf,
103 _In_ const TEXTMETRICW *ntm,
104 _In_ DWORD FontType,
106{
108
111 "Context is %p, expected %p or %p\n",
113
114 LastFontW = *(ENUMLOGFONTW *)elf;
115 return lParam == (LPARAM)&ContextContinue ? 7 : 0;
116}
117
118static
119void
121 _In_ HDC hdc,
122 _In_ PCWSTR FontName,
123 _In_ BOOLEAN ExpectToFind)
124{
125 const struct
126 {
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 {
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);
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
static ENUMLOGFONTA LastFontA
int WRAP_ENUM_FONT_FAMILIES(_In_ HDC, _In_ PCWSTR, _In_ PVOID, _In_ LPARAM)
static int CALLBACK EnumProcW(_In_ const LOGFONTW *elf, _In_ const TEXTMETRICW *ntm, _In_ DWORD FontType, _In_ LPARAM lParam)
static int EnumProcCalls
static int WrapEnumFontFamiliesA(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
static int CALLBACK EnumProcA(_In_ const LOGFONTA *elf, _In_ const TEXTMETRICA *ntm, _In_ DWORD FontType, _In_ LPARAM lParam)
static ENUMLOGFONTW LastFontW
WRAP_ENUM_FONT_FAMILIES * PWRAP_ENUM_FONT_FAMILIES
static int WrapEnumFontFamiliesW(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
static BYTE ContextContinue
static int WrapEnumFontFamiliesExW(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
static int WrapEnumFontFamiliesExA(_In_ HDC hdc, _In_ PCWSTR Family, _In_ PVOID EnumProc, _In_ LPARAM lParam)
static void TestEnumFontFamilies(_In_ HDC hdc, _In_ PCWSTR FontName, _In_ BOOLEAN ExpectToFind)
static BYTE ContextStop
unsigned char BOOLEAN
static BOOL CALLBACK EnumProc(_In_ HWND hWnd, _In_ LPARAM lParam)
Definition: SetParent.c:53
struct NameRec_ * Name
Definition: cdprocs.h:460
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Description[]
Definition: oid.c:1266
#define CP_ACP
Definition: compat.h:109
#define SetLastError(x)
Definition: compat.h:752
#define CALLBACK
Definition: compat.h:35
#define WideCharToMultiByte
Definition: compat.h:111
unsigned long DWORD
Definition: ntddk_ex.h:95
#define error(str)
Definition: mkdosfs.c:1605
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
#define _In_
Definition: ms_sal.h:308
#define L(x)
Definition: ntvdm.h:50
static int Family
Definition: ping.c:62
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
BYTE lfPitchAndFamily
Definition: dimm.idl:54
BYTE lfCharSet
Definition: dimm.idl:50
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
BYTE lfCharSet
Definition: dimm.idl:67
BYTE lfPitchAndFamily
Definition: dimm.idl:71
const uint16_t * PCWSTR
Definition: typedefs.h:57
const char * PCSTR
Definition: typedefs.h:52
int ret
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LPARAM
Definition: windef.h:208
int WINAPI EnumFontFamiliesExW(_In_ HDC, _In_ PLOGFONTW, _In_ FONTENUMPROCW, _In_ LPARAM, _In_ DWORD)
int WINAPI EnumFontFamiliesExA(_In_ HDC, _In_ PLOGFONTA, _In_ FONTENUMPROCA, _In_ LPARAM, _In_ DWORD)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DEFAULT_CHARSET
Definition: wingdi.h:384
int WINAPI EnumFontFamiliesW(_In_ HDC, _In_opt_ LPCWSTR, _In_ FONTENUMPROCW, _In_ LPARAM)
int WINAPI EnumFontFamiliesA(_In_ HDC, _In_opt_ LPCSTR, _In_ FONTENUMPROCA, _In_ LPARAM)
BOOL WINAPI DeleteDC(_In_ HDC)
#define EnumFontFamilies
Definition: wingdi.h:4450
unsigned char BYTE
Definition: xxhash.c:193