[GDI32_APITEST] Add tests for GetFontResourceInfoW. Patch by Katayama Hirofumi MZ...
[reactos.git] / rostests / apitests / gdi32 / GetFontResourceInfoW.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetFontResourceInfoW
5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7 #include <apitest.h>
8 #include <wingdi.h>
9 #include <winnls.h>
10 #include <stdio.h>
11
12 /* GetFontResourceInfoW is undocumented */
13 BOOL WINAPI GetFontResourceInfoW(LPCWSTR lpFileName, DWORD *pdwBufSize, void* lpBuffer, DWORD dwType);
14
15 /* structure of test entry */
16 typedef struct GFRI_ENTRY
17 {
18 LPCWSTR File;
19 WCHAR FontInfo[64];
20 INT FontCount;
21 WCHAR FaceNames[10][64];
22 } GFRI_ENTRY;
23
24 /* test entries */
25 static const GFRI_ENTRY TestEntries[] =
26 {
27 { L"symbol.ttf", L"Symbol|", 1, { L"Symbol" } },
28 { L"tahoma.ttf", L"Tahoma|", 1, { L"Tahoma" } },
29 { L"tahomabd.ttf", L"Tahoma Bold|", 1, { L"Tahoma" } }
30 };
31
32 /* Japanese */
33 static const GFRI_ENTRY AdditionalTestEntriesJapanese[] =
34 {
35 {
36 /* MS Gothic & MS UI Gothic & MS PGothic */
37 L"msgothic.ttc",
38 {
39 0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0020,
40 0x0026, 0x0020, 0x004D, 0x0053, 0x0020, 0x0055, 0x0049, 0x0020,
41 0x0047, 0x006F, 0x0074, 0x0068, 0x0069, 0x0063, 0x0020, 0x0026,
42 0x0020, 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3,
43 0x30AF, L'|', 0
44 },
45 6,
46 {
47 { 0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 },
48 { L'@', 0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 },
49 L"MS UI Gothic",
50 L"@MS UI Gothic",
51 { 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 },
52 { L'@', 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0 }
53 }
54 }
55 };
56
57 /* English */
58 static const GFRI_ENTRY AdditionalTestEntriesEnglish[] =
59 {
60 {
61 /* MS Gothic & MS UI Gothic & MS PGothic */
62 L"msgothic.ttc",
63 L"MS Gothic & MS UI Gothic & MS PGothic|",
64 6,
65 {
66 L"MS Gothic",
67 L"@MS Gothic",
68 L"MS UI Gothic",
69 L"@MS UI Gothic",
70 L"MS PGothic",
71 L"@MS PGothic"
72 }
73 }
74 };
75
76 static void
77 GetSystemFontDirectory(LPWSTR pszDir)
78 {
79 GetWindowsDirectoryW(pszDir, MAX_PATH);
80 lstrcatW(pszDir, L"\\Fonts");
81 }
82
83 static void
84 GetSystemFontPath(LPWSTR pszPath, LPCWSTR pszFile)
85 {
86 GetSystemFontDirectory(pszPath);
87 lstrcatW(pszPath, L"\\");
88 lstrcatW(pszPath, pszFile);
89 }
90
91 static INT
92 GetMultiSzLength(const WCHAR *pszz)
93 {
94 INT Len, TotalLen = 0;
95 for (;;)
96 {
97 Len = lstrlenW(pszz);
98 TotalLen += Len + 1;
99 pszz += Len + 1;
100 if (*pszz == 0)
101 break;
102 }
103 ++TotalLen;
104 return TotalLen;
105 }
106
107 static void
108 ReplaceChars(WCHAR *pch, INT Len, WCHAR From, WCHAR To)
109 {
110 while (Len > 0)
111 {
112 if (*pch == From)
113 {
114 *pch = To;
115 }
116 //printf("0x%04X, ", *pch);
117 ++pch;
118 --Len;
119 }
120 }
121
122 static void
123 SzFromMultiSz(WCHAR *pszz)
124 {
125 INT Length = GetMultiSzLength(pszz);
126 //printf("Length: %d\n", Length);
127 if (Length > 0)
128 {
129 ReplaceChars(pszz, Length - 1, L'\0', L'|');
130 pszz[Length - 1] = 0;
131 }
132 else
133 {
134 pszz[0] = 0;
135 }
136 //printf("pszz: %S\n", pszz);
137 }
138
139 static void
140 Test_GetFontResourceInfoW_case0(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
141 {
142 BOOL Ret;
143 DWORD Size, Case = 0;
144 DWORD Data;
145
146 /* data NULL, size zero */
147 Size = 0;
148 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
149 ok_int(Ret, 1);
150 ok_int(Size, 4);
151
152 /* data NULL, size non-zero */
153 Size = 1024;
154 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
155 ok_int(Ret, 0);
156 ok_int(Size, 1024);
157
158 /* size zero */
159 Data = 0xDEADFACE;
160 Size = 0;
161 Ret = GetFontResourceInfoW(pszFilePath, &Size, &Data, Case);
162 ok_int(Ret, 1);
163 ok_int(Data, 0xDEADFACE);
164 ok_int(Size, 4);
165
166 /* size non-zero */
167 Data = 0xDEADFACE;
168 Size = sizeof(Data);
169 Ret = GetFontResourceInfoW(pszFilePath, &Size, &Data, Case);
170 ok_int(Ret, 1);
171 ok_int(Data, Entry->FontCount);
172 ok_int(Size, 4);
173 }
174
175 static void
176 Test_GetFontResourceInfoW_case1(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
177 {
178 BOOL Ret;
179 DWORD Size, Case = 1;
180 static WCHAR Data[1024 / sizeof(WCHAR)];
181
182 /* data NULL, size zero */
183 Size = 0;
184 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
185 ok_int(Ret, 1);
186 /* FIXME: What's the result of Size? */
187 ok(Size != 0, "Size expected non-zero but zero\n");
188
189 /* data NULL, size non-zero */
190 Size = 1024;
191 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
192 ok_int(Ret, 0);
193 ok_int(Size, 1024);
194
195 /* size zero */
196 Size = 0;
197 CopyMemory(Data, L"ABC\0", sizeof(L"ABC\0"));
198 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
199 ok_int(Ret, 1);
200 /* FIXME: What's the result of Size? */
201 ok(Size != 0, "Size expected non-zero but zero\n");
202 ok(lstrcmpiW(Data, L"ABC") == 0, "data mismatched: \"%S\"\n", Data);
203
204 /* size non-zero */
205 Size = 1024;
206 CopyMemory(Data, L"ABC\0", sizeof(L"ABC\0"));
207 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
208 ok_int(Ret, 1);
209 /* FIXME: What's the result of Size? */
210 ok(Size != 0, "Size expected non-zero but zero\n");
211
212 SzFromMultiSz(Data);
213 ok(lstrcmpiW(Data, Entry->FontInfo) == 0, "data mismatched: \"%S\" and \"%S\"\n",
214 Data, Entry->FontInfo);
215 #if 0
216 if (lstrcmpiW(Data, Entry->FontInfo) != 0)
217 {
218 int i, len = lstrlenW(Data) + 1;
219 for (i = 0; i < len; ++i)
220 {
221 printf("0x%04X <=> 0x%04X\n", Data[i], Entry->FontInfo[i]);
222 }
223 }
224 #endif
225 }
226
227 static void
228 Test_GetFontResourceInfoW_case2(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
229 {
230 BOOL Ret;
231 DWORD i, Size, Case = 2;
232 static LOGFONTW Data[100];
233
234 /* data NULL, size zero */
235 Size = 0;
236 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
237 ok_int(Ret, 1);
238 ok_int(Size, Entry->FontCount * sizeof(LOGFONTW));
239
240 /* data NULL, size non-zero */
241 Size = 1024;
242 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
243 ok_int(Ret, 0);
244 ok_int(Size, 1024);
245
246 /* size zero */
247 Size = 0;
248 ZeroMemory(Data, sizeof(Data));
249 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
250 ok_int(Ret, 1);
251 ok_int(Size, Entry->FontCount * sizeof(LOGFONTW));
252
253 /* size non-zero */
254 Size = sizeof(Data);
255 ZeroMemory(Data, sizeof(Data));
256 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
257 ok_int(Ret, 1);
258 ok_int(Size, Entry->FontCount * sizeof(LOGFONTW));
259 for (i = 0; i < Entry->FontCount; ++i)
260 {
261 ok(lstrcmpiW(Data[i].lfFaceName, Entry->FaceNames[i]) == 0,
262 "face name #%d mismatched: \"%S\" and \"%S\"\n", (int)i, Data[i].lfFaceName, Entry->FaceNames[i]);
263 #if 0
264 if (lstrcmpiW(Data[i].lfFaceName, Entry->FaceNames[i]) != 0)
265 {
266 int k, len = lstrlenW(Data[i].lfFaceName);
267 for (k = 0; k < len; ++k)
268 {
269 printf("0x%04X <=> 0x%04X\n", Entry->FaceNames[i][k], Data[i].lfFaceName[k]);
270 }
271 }
272 #endif
273 }
274 }
275
276 static void
277 Test_GetFontResourceInfoW_case3(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
278 {
279 BOOL Ret;
280 DWORD Size, Case = 3;
281 DWORD Data[2];
282
283 /* data NULL, size zero */
284 Size = 0;
285 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
286 ok_int(Ret, 1);
287 ok_int(Size, 4);
288
289 /* data NULL, size non-zero */
290 Size = sizeof(Data);
291 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
292 ok_int(Ret, 0);
293 ok_int(Size, 8);
294
295 /* size zero */
296 Size = 0;
297 Data[0] = 0xDEADFACE;
298 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
299 ok_int(Ret, 1);
300 ok_int(Size, 4);
301 ok_int(Data[0], 0xDEADFACE);
302
303 /* size non-zero */
304 Size = sizeof(Data);
305 Data[0] = 0xDEADFACE;
306 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
307 ok_int(Ret, 1);
308 ok_int(Size, 4);
309 ok_int(Data[0], 1);
310 }
311
312 static void
313 Test_GetFontResourceInfoW_case4(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
314 {
315 BOOL Ret;
316 DWORD Size, Case = 4;
317 WCHAR Data[MAX_PATH];
318
319 /* data NULL, size zero */
320 Size = 0;
321 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
322 ok_int(Ret, 1);
323 ok_int(Size, (lstrlenW(pszFilePath) + 1) * sizeof(WCHAR));
324
325 /* data NULL, size non-zero */
326 Size = MAX_PATH;
327 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
328 ok_int(Ret, 0);
329 ok_int(Size, MAX_PATH);
330
331 /* size zero */
332 Size = 0;
333 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
334 ok_int(Ret, 1);
335 ok_int(Size, (lstrlenW(pszFilePath) + 1) * sizeof(WCHAR));
336
337 /* size non-zero */
338 Size = MAX_PATH;
339 Ret = GetFontResourceInfoW(pszFilePath, &Size, Data, Case);
340 ok_int(Ret, 1);
341 ok_int(Size, (lstrlenW(pszFilePath) + 1) * sizeof(WCHAR));
342 ok(lstrcmpiW(pszFilePath, Data) == 0, "data mismatched: \"%S\"\n", Data);
343 }
344
345 static void
346 Test_GetFontResourceInfoW_case5(LPCWSTR pszFilePath, const GFRI_ENTRY *Entry)
347 {
348 BOOL Ret;
349 DWORD Size, Case = 5;
350 DWORD Data;
351
352 /* data NULL, size zero */
353 Size = 0;
354 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
355 ok_int(Ret, 1);
356 ok_int(Size, 4);
357
358 /* data NULL, size non-zero */
359 Size = sizeof(Data);
360 Ret = GetFontResourceInfoW(pszFilePath, &Size, NULL, Case);
361 ok_int(Ret, 0);
362 ok_int(Size, 4);
363
364 /* size zero */
365 Size = 0;
366 Data = 0xDEADFACE;
367 Ret = GetFontResourceInfoW(pszFilePath, &Size, &Data, Case);
368 ok_int(Ret, 1);
369 ok_int(Size, 4);
370 ok_int(Data, 0xDEADFACE);
371
372 /* size non-zero */
373 Size = sizeof(Data);
374 Data = 0xDEADFACE;
375 Ret = GetFontResourceInfoW(pszFilePath, &Size, &Data, Case);
376 ok_int(Ret, 1);
377 ok_int(Size, 4);
378 ok_int(Data, 0);
379 }
380
381 static void
382 DoEntry(const GFRI_ENTRY *Entry)
383 {
384 WCHAR szPath[MAX_PATH];
385
386 GetSystemFontPath(szPath, Entry->File);
387 printf("GetSystemFontPath: %S\n", szPath);
388 if (GetFileAttributesW(szPath) == 0xFFFFFFFF)
389 {
390 skip("Font file \"%S\" was not found\n", szPath);
391 return;
392 }
393
394 Test_GetFontResourceInfoW_case0(szPath, Entry);
395 Test_GetFontResourceInfoW_case1(szPath, Entry);
396 Test_GetFontResourceInfoW_case2(szPath, Entry);
397 Test_GetFontResourceInfoW_case3(szPath, Entry);
398 Test_GetFontResourceInfoW_case4(szPath, Entry);
399 Test_GetFontResourceInfoW_case5(szPath, Entry);
400 }
401
402 START_TEST(GetFontResourceInfoW)
403 {
404 INT i;
405 const GFRI_ENTRY *Entry;
406
407 printf("sizeof(LOGFONTW) == %u\n", (int)sizeof(LOGFONTW));
408
409 for (i = 0; i < _countof(TestEntries); ++i)
410 {
411 Entry = &TestEntries[i];
412 DoEntry(Entry);
413 }
414
415 if (PRIMARYLANGID(GetSystemDefaultLangID()) == LANG_JAPANESE)
416 {
417 /* Japanese */
418 for (i = 0; i < _countof(AdditionalTestEntriesJapanese); ++i)
419 {
420 Entry = &AdditionalTestEntriesJapanese[i];
421 DoEntry(Entry);
422 }
423 }
424 else
425 {
426 /* non-Japanese */
427 for (i = 0; i < _countof(AdditionalTestEntriesEnglish); ++i)
428 {
429 Entry = &AdditionalTestEntriesEnglish[i];
430 DoEntry(Entry);
431 }
432 }
433 }