[NTFS]
[reactos.git] / rostests / apitests / gdi32 / EnumFontFamilies.c
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 <apitest.h>
9
10 #include <wingdi.h>
11 #include <winddi.h>
12 #include <strsafe.h>
13
14 static BYTE ContextContinue;
15 static BYTE ContextStop;
16
17 static int EnumProcCalls;
18 static ENUMLOGFONTA LastFontA;
19 static ENUMLOGFONTW LastFontW;
20
21 static
22 int
23 CALLBACK
24 EnumProcA(
25 _In_ const LOGFONTA *elf,
26 _In_ const TEXTMETRICA *ntm,
27 _In_ DWORD FontType,
28 _In_ LPARAM lParam)
29 {
30 EnumProcCalls++;
31
32 ok(lParam == (LPARAM)&ContextContinue ||
33 lParam == (LPARAM)&ContextStop,
34 "Context is %p, expected %p or %p\n",
35 (PVOID)lParam, &ContextContinue, &ContextStop);
36
37 LastFontA = *(ENUMLOGFONTA *)elf;
38 return lParam == (LPARAM)&ContextContinue ? 7 : 0;
39 }
40
41 static
42 int
43 CALLBACK
44 EnumProcW(
45 _In_ const LOGFONTW *elf,
46 _In_ const TEXTMETRICW *ntm,
47 _In_ DWORD FontType,
48 _In_ LPARAM lParam)
49 {
50 EnumProcCalls++;
51
52 ok(lParam == (LPARAM)&ContextContinue ||
53 lParam == (LPARAM)&ContextStop,
54 "Context is %p, expected %p or %p\n",
55 (PVOID)lParam, &ContextContinue, &ContextStop);
56
57 LastFontW = *(ENUMLOGFONTW *)elf;
58 return lParam == (LPARAM)&ContextContinue ? 7 : 0;
59 }
60
61 static
62 void
63 TestEnumFontFamiliesA(
64 _In_ HDC hdc,
65 _In_ PCSTR FontName)
66 {
67 int ret;
68 DWORD error;
69
70 EnumProcCalls = 0;
71 SetLastError(0xdeadbeef);
72 ret = EnumFontFamiliesA(hdc,
73 FontName,
74 EnumProcA,
75 (LPARAM)&ContextContinue);
76 error = GetLastError();
77 ok(ret == 1, "ret is %d, expected 1\n", ret);
78 ok(error == 0xdeadbeef, "error is %lu\n", error);
79 ok(EnumProcCalls == 0, "EnumProcCalls is %d\n", EnumProcCalls);
80 }
81
82 static
83 void
84 TestEnumFontFamiliesW(
85 _In_ HDC hdc,
86 _In_ PCWSTR FontName)
87 {
88 int ret;
89 DWORD error;
90
91 EnumProcCalls = 0;
92 SetLastError(0xdeadbeef);
93 ret = EnumFontFamiliesW(hdc,
94 FontName,
95 EnumProcW,
96 (LPARAM)&ContextContinue);
97 error = GetLastError();
98 ok(ret == 1, "ret is %d, expected 1\n", ret);
99 ok(error == 0xdeadbeef, "error is %lu\n", error);
100 ok(EnumProcCalls == 0, "EnumProcCalls is %d\n", EnumProcCalls);
101 }
102
103 static
104 void
105 TestEnumFontFamiliesExA(
106 _In_ HDC hdc,
107 _In_ PCSTR FontName)
108 {
109 int ret;
110 DWORD error;
111 LOGFONTA lf;
112
113 EnumProcCalls = 0;
114 ZeroMemory(&lf, sizeof(lf));
115 lf.lfCharSet = DEFAULT_CHARSET;
116 lf.lfPitchAndFamily = 0;
117 StringCbCopyA(lf.lfFaceName, sizeof(lf.lfFaceName), FontName);
118 SetLastError(0xdeadbeef);
119 ret = EnumFontFamiliesExA(hdc,
120 &lf,
121 EnumProcA,
122 (LPARAM)&ContextContinue,
123 0);
124 error = GetLastError();
125 ok(ret == 1, "ret is %d, expected 1\n", ret);
126 ok(error == 0xdeadbeef, "error is %lu\n", error);
127 ok(EnumProcCalls == 0, "EnumProcCalls is %d\n", EnumProcCalls);
128 }
129
130 static
131 void
132 TestEnumFontFamiliesExW(
133 _In_ HDC hdc,
134 _In_ PCWSTR FontName)
135 {
136 int ret;
137 DWORD error;
138 LOGFONTW lf;
139
140 EnumProcCalls = 0;
141 ZeroMemory(&lf, sizeof(lf));
142 lf.lfCharSet = DEFAULT_CHARSET;
143 lf.lfPitchAndFamily = 0;
144 StringCbCopyW(lf.lfFaceName, sizeof(lf.lfFaceName), FontName);
145 SetLastError(0xdeadbeef);
146 ret = EnumFontFamiliesExW(hdc,
147 &lf,
148 EnumProcW,
149 (LPARAM)&ContextContinue,
150 0);
151 error = GetLastError();
152 ok(ret == 1, "ret is %d, expected 1\n", ret);
153 ok(error == 0xdeadbeef, "error is %lu\n", error);
154 ok(EnumProcCalls == 0, "EnumProcCalls is %d\n", EnumProcCalls);
155 }
156
157 START_TEST(EnumFontFamilies)
158 {
159 HDC hdc;
160
161 hdc = CreateCompatibleDC(NULL);
162 if (!hdc)
163 {
164 skip("No DC\n");
165 return;
166 }
167
168 TestEnumFontFamiliesA(hdc, "ThisFontDoesNotExist");
169 TestEnumFontFamiliesW(hdc, L"ThisFontDoesNotExist");
170 TestEnumFontFamiliesExA(hdc, "ThisFontDoesNotExist");
171 TestEnumFontFamiliesExW(hdc, L"ThisFontDoesNotExist");
172
173 DeleteDC(hdc);
174 }
175