shdocvw: Pass correct buffer size to UrlApplySchemeW.
[wine/hacks.git] / dlls / gdiplus / tests / font.c
blob80f11bc0032a7c30fd9cc634f1e38f46df04e16a
1 /*
2 * Unit test suite for fonts
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <math.h>
23 #include "windows.h"
24 #include "gdiplus.h"
25 #include "wine/test.h"
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
30 static const WCHAR arial[] = {'A','r','i','a','l','\0'};
31 static const WCHAR nonexistent[] = {'T','h','i','s','F','o','n','t','s','h','o','u','l','d','N','o','t','E','x','i','s','t','\0'};
32 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
33 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
34 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
35 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
37 static void test_createfont(void)
39 GpFontFamily* fontfamily = NULL, *fontfamily2;
40 GpFont* font = NULL;
41 GpStatus stat;
42 Unit unit;
43 UINT i;
44 REAL size;
45 WCHAR familyname[LF_FACESIZE];
47 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
48 expect (FontFamilyNotFound, stat);
49 stat = GdipDeleteFont(font);
50 expect (InvalidParameter, stat);
51 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
52 if(stat == FontFamilyNotFound)
54 skip("Arial not installed\n");
55 return;
57 expect (Ok, stat);
58 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
59 expect (Ok, stat);
60 stat = GdipGetFontUnit (font, &unit);
61 expect (Ok, stat);
62 expect (UnitPoint, unit);
64 stat = GdipGetFamily(font, &fontfamily2);
65 expect(Ok, stat);
66 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
67 expect(Ok, stat);
68 ok (lstrcmpiW(arial, familyname) == 0, "Expected arial, got %s\n",
69 wine_dbgstr_w(familyname));
70 stat = GdipDeleteFontFamily(fontfamily2);
71 expect(Ok, stat);
73 /* Test to see if returned size is based on unit (its not) */
74 GdipGetFontSize(font, &size);
75 ok (size == 12, "Expected 12, got %f\n", size);
76 GdipDeleteFont(font);
78 /* Make sure everything is converted correctly for all Units */
79 for (i = UnitWorld; i <=UnitMillimeter; i++)
81 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
82 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
83 GdipGetFontSize (font, &size);
84 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
85 GdipGetFontUnit (font, &unit);
86 expect (i, unit);
87 GdipDeleteFont(font);
90 GdipDeleteFontFamily(fontfamily);
93 static void test_logfont(void)
95 LOGFONTA lfa, lfa2;
96 GpFont *font;
97 GpStatus stat;
98 GpGraphics *graphics;
99 HDC hdc = GetDC(0);
100 INT style;
102 GdipCreateFromHDC(hdc, &graphics);
103 memset(&lfa, 0, sizeof(LOGFONTA));
104 memset(&lfa2, 0xff, sizeof(LOGFONTA));
106 /* empty FaceName */
107 lfa.lfFaceName[0] = 0;
108 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
109 expect(NotTrueTypeFont, stat);
111 lstrcpyA(lfa.lfFaceName, "Arial");
113 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
114 if (stat == FileNotFound)
116 skip("Arial not installed.\n");
117 return;
119 expect(Ok, stat);
120 stat = GdipGetLogFontA(font, graphics, &lfa2);
121 expect(Ok, stat);
123 ok(lfa2.lfHeight < 0, "Expected negative height\n");
124 expect(0, lfa2.lfWidth);
125 expect(0, lfa2.lfEscapement);
126 expect(0, lfa2.lfOrientation);
127 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
128 expect(0, lfa2.lfItalic);
129 expect(0, lfa2.lfUnderline);
130 expect(0, lfa2.lfStrikeOut);
131 expect(GetTextCharset(hdc), lfa2.lfCharSet);
132 expect(0, lfa2.lfOutPrecision);
133 expect(0, lfa2.lfClipPrecision);
134 expect(0, lfa2.lfQuality);
135 expect(0, lfa2.lfPitchAndFamily);
137 GdipDeleteFont(font);
139 memset(&lfa, 0, sizeof(LOGFONTA));
140 lfa.lfHeight = 25;
141 lfa.lfWidth = 25;
142 lfa.lfEscapement = lfa.lfOrientation = 50;
143 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
145 memset(&lfa2, 0xff, sizeof(LOGFONTA));
146 lstrcpyA(lfa.lfFaceName, "Arial");
148 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
149 expect(Ok, stat);
150 stat = GdipGetLogFontA(font, graphics, &lfa2);
151 expect(Ok, stat);
153 ok(lfa2.lfHeight < 0, "Expected negative height\n");
154 expect(0, lfa2.lfWidth);
155 expect(0, lfa2.lfEscapement);
156 expect(0, lfa2.lfOrientation);
157 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
158 expect(TRUE, lfa2.lfItalic);
159 expect(TRUE, lfa2.lfUnderline);
160 expect(TRUE, lfa2.lfStrikeOut);
161 expect(GetTextCharset(hdc), lfa2.lfCharSet);
162 expect(0, lfa2.lfOutPrecision);
163 expect(0, lfa2.lfClipPrecision);
164 expect(0, lfa2.lfQuality);
165 expect(0, lfa2.lfPitchAndFamily);
167 stat = GdipGetFontStyle(font, &style);
168 expect(Ok, stat);
169 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
170 "Expected , got %d\n", style);
172 GdipDeleteFont(font);
174 GdipDeleteGraphics(graphics);
175 ReleaseDC(0, hdc);
178 static void test_fontfamily (void)
180 GpFontFamily *family, *clonedFontFamily;
181 WCHAR itsName[LF_FACESIZE];
182 GpStatus stat;
184 /* FontFamily cannot be NULL */
185 stat = GdipCreateFontFamilyFromName (arial , NULL, NULL);
186 expect (InvalidParameter, stat);
188 /* FontFamily must be able to actually find the family.
189 * If it can't, any subsequent calls should fail.
191 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
192 expect (FontFamilyNotFound, stat);
194 /* Bitmap fonts are not found */
195 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
196 expect (FontFamilyNotFound, stat);
197 if(stat == Ok) GdipDeleteFontFamily(family);
199 stat = GdipCreateFontFamilyFromName (arial, NULL, &family);
200 if(stat == FontFamilyNotFound)
202 skip("Arial not installed\n");
203 return;
205 expect (Ok, stat);
207 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
208 expect (Ok, stat);
209 expect (0, lstrcmpiW(itsName, arial));
211 if (0)
213 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
214 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
215 expect (Ok, stat);
218 /* Make sure we don't read old data */
219 ZeroMemory (itsName, sizeof(itsName));
220 stat = GdipCloneFontFamily(family, &clonedFontFamily);
221 expect (Ok, stat);
222 GdipDeleteFontFamily(family);
223 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
224 expect(Ok, stat);
225 expect(0, lstrcmpiW(itsName, arial));
227 GdipDeleteFontFamily(clonedFontFamily);
230 static void test_fontfamily_properties (void)
232 GpFontFamily* FontFamily = NULL;
233 GpStatus stat;
234 UINT16 result = 0;
236 stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily);
237 if(stat == FontFamilyNotFound)
238 skip("Arial not installed\n");
239 else
241 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
242 expect(Ok, stat);
243 ok (result == 2355, "Expected 2355, got %d\n", result);
244 result = 0;
245 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
246 expect(Ok, stat);
247 ok(result == 2048, "Expected 2048, got %d\n", result);
248 result = 0;
249 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
250 expect(Ok, stat);
251 ok(result == 1854, "Expected 1854, got %d\n", result);
252 result = 0;
253 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
254 ok(result == 434, "Expected 434, got %d\n", result);
255 GdipDeleteFontFamily(FontFamily);
258 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
259 if(stat == FontFamilyNotFound)
260 skip("Times New Roman not installed\n");
261 else
263 result = 0;
264 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
265 expect(Ok, stat);
266 ok(result == 2355, "Expected 2355, got %d\n", result);
267 result = 0;
268 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
269 expect(Ok, stat);
270 ok(result == 2048, "Expected 2048, got %d\n", result);
271 result = 0;
272 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
273 expect(Ok, stat);
274 ok(result == 1825, "Expected 1825, got %d\n", result);
275 result = 0;
276 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
277 ok(result == 443, "Expected 443 got %d\n", result);
278 GdipDeleteFontFamily(FontFamily);
282 static void test_getgenerics (void)
284 GpStatus stat;
285 GpFontFamily* family;
286 WCHAR familyName[LF_FACESIZE];
287 ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR));
289 stat = GdipGetGenericFontFamilySansSerif (&family);
290 if (stat == FontFamilyNotFound)
292 skip("Microsoft Sans Serif not installed\n");
293 goto serif;
295 expect (Ok, stat);
296 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
297 expect (Ok, stat);
298 todo_wine ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0),
299 "Expected Microsoft Sans Serif, got %s\n",
300 wine_dbgstr_w(familyName));
301 stat = GdipDeleteFontFamily (family);
302 expect (Ok, stat);
304 serif:
305 stat = GdipGetGenericFontFamilySerif (&family);
306 if (stat == FontFamilyNotFound)
308 skip("Times New Roman not installed\n");
309 goto monospace;
311 expect (Ok, stat);
312 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
313 expect (Ok, stat);
314 ok (lstrcmpiW(familyName, TimesNewRoman) == 0,
315 "Expected Times New Roman, got %s\n", wine_dbgstr_w(familyName));
316 stat = GdipDeleteFontFamily (family);
317 expect (Ok, stat);
319 monospace:
320 stat = GdipGetGenericFontFamilyMonospace (&family);
321 if (stat == FontFamilyNotFound)
323 skip("Courier New not installed\n");
324 return;
326 expect (Ok, stat);
327 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
328 expect (Ok, stat);
329 ok (lstrcmpiW(familyName, CourierNew) == 0,
330 "Expected Courier New, got %s\n", wine_dbgstr_w(familyName));
331 stat = GdipDeleteFontFamily (family);
332 expect (Ok, stat);
335 static void test_installedfonts (void)
337 GpStatus stat;
338 GpFontCollection* collection=NULL;
340 stat = GdipNewInstalledFontCollection(NULL);
341 expect (InvalidParameter, stat);
343 stat = GdipNewInstalledFontCollection(&collection);
344 expect (Ok, stat);
345 ok (collection != NULL, "got NULL font collection\n");
348 static void test_heightgivendpi(void)
350 GpStatus stat;
351 GpFont* font = NULL;
352 GpFontFamily* fontfamily = NULL;
353 REAL height;
355 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
356 if(stat == FontFamilyNotFound)
358 skip("Arial not installed\n");
359 return;
361 expect(Ok, stat);
363 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
364 expect(Ok, stat);
366 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
367 expect(InvalidParameter, stat);
369 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
370 expect(InvalidParameter, stat);
372 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
373 expect(Ok, stat);
374 expectf((REAL)34.497070, height);
375 GdipDeleteFont(font);
377 height = 12345;
378 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
379 expect(Ok, stat);
380 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
381 expect(Ok, stat);
382 expectf((REAL)34.497070, height);
383 GdipDeleteFont(font);
385 height = 12345;
386 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
387 expect(Ok, stat);
388 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
389 expect(Ok, stat);
390 expectf((REAL)45.996094, height);
391 GdipDeleteFont(font);
393 height = 12345;
394 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
395 expect(Ok, stat);
396 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
397 expect(Ok, stat);
398 expectf((REAL)3311.718750, height);
399 GdipDeleteFont(font);
401 height = 12345;
402 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
403 expect(Ok, stat);
404 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
405 expect(Ok, stat);
406 expectf((REAL)11.039062, height);
407 GdipDeleteFont(font);
409 height = 12345;
410 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
411 expect(Ok, stat);
412 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
413 expect(Ok, stat);
414 expectf((REAL)130.382614, height);
415 GdipDeleteFont(font);
417 GdipDeleteFontFamily(fontfamily);
420 START_TEST(font)
422 struct GdiplusStartupInput gdiplusStartupInput;
423 ULONG_PTR gdiplusToken;
425 gdiplusStartupInput.GdiplusVersion = 1;
426 gdiplusStartupInput.DebugEventCallback = NULL;
427 gdiplusStartupInput.SuppressBackgroundThread = 0;
428 gdiplusStartupInput.SuppressExternalCodecs = 0;
430 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
432 test_createfont();
433 test_logfont();
434 test_fontfamily();
435 test_fontfamily_properties();
436 test_getgenerics();
437 test_installedfonts();
438 test_heightgivendpi();
440 GdiplusShutdown(gdiplusToken);