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
23 #include "wine/test.h"
25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
27 static const WCHAR arial
[] = {'A','r','i','a','l','\0'};
28 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'};
29 static const WCHAR MSSansSerif
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
30 static const WCHAR MicrosoftSansSerif
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
31 static const WCHAR TimesNewRoman
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
32 static const WCHAR CourierNew
[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
34 static const char *debugstr_w(LPCWSTR str
)
36 static char buf
[1024];
37 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
42 static void test_createfont(void)
44 GpFontFamily
* fontfamily
= NULL
;
51 stat
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &fontfamily
);
52 expect (FontFamilyNotFound
, stat
);
53 stat
= GdipDeleteFont(font
);
54 expect (InvalidParameter
, stat
);
55 stat
= GdipCreateFontFamilyFromName(arial
, NULL
, &fontfamily
);
56 if(stat
== FontFamilyNotFound
)
58 skip("Arial not installed\n");
62 stat
= GdipCreateFont(fontfamily
, 12, FontStyleRegular
, UnitPoint
, &font
);
64 stat
= GdipGetFontUnit (font
, &unit
);
66 expect (UnitPoint
, unit
);
68 /* Test to see if returned size is based on unit (its not) */
69 GdipGetFontSize(font
, &size
);
70 ok (size
== 12, "Expected 12, got %f\n", size
);
73 /* Make sure everything is converted correctly for all Units */
74 for (i
= UnitWorld
; i
<=UnitMillimeter
; i
++)
76 if (i
== UnitDisplay
) continue; /* Crashes WindowsXP, wtf? */
77 GdipCreateFont(fontfamily
, 24, FontStyleRegular
, i
, &font
);
78 GdipGetFontSize (font
, &size
);
79 ok (size
== 24, "Expected 24, got %f (with unit: %d)\n", size
, i
);
80 GdipGetFontUnit (font
, &unit
);
85 GdipDeleteFontFamily(fontfamily
);
88 static void test_logfont(void)
96 GdipCreateFromHDC(hdc
, &graphics
);
97 memset(&lfw
, 0, sizeof(LOGFONTW
));
98 memset(&lfw2
, 0xff, sizeof(LOGFONTW
));
101 lfw
.lfFaceName
[0] = 0;
102 stat
= GdipCreateFontFromLogfontW(hdc
, &lfw
, &font
);
105 expect(NotTrueTypeFont
, stat
);
108 memcpy(&lfw
.lfFaceName
, arial
, 6 * sizeof(WCHAR
));
110 stat
= GdipCreateFontFromLogfontW(hdc
, &lfw
, &font
);
111 if (stat
== FileNotFound
)
113 skip("Arial not installed.\n");
117 stat
= GdipGetLogFontW(font
, graphics
, &lfw2
);
120 ok(lfw2
.lfHeight
< 0, "Expected negative height\n");
121 expect(0, lfw2
.lfWidth
);
122 expect(0, lfw2
.lfEscapement
);
123 expect(0, lfw2
.lfOrientation
);
124 ok((lfw2
.lfWeight
>= 100) && (lfw2
.lfWeight
<= 900), "Expected weight to be set\n");
125 expect(0, lfw2
.lfItalic
);
126 expect(0, lfw2
.lfUnderline
);
127 expect(0, lfw2
.lfStrikeOut
);
128 expect(0, lfw2
.lfCharSet
);
129 expect(0, lfw2
.lfOutPrecision
);
130 expect(0, lfw2
.lfClipPrecision
);
131 expect(0, lfw2
.lfQuality
);
132 expect(0, lfw2
.lfPitchAndFamily
);
134 GdipDeleteFont(font
);
136 memset(&lfw
, 0, sizeof(LOGFONTW
));
139 lfw
.lfEscapement
= lfw
.lfOrientation
= 50;
140 lfw
.lfItalic
= lfw
.lfUnderline
= lfw
.lfStrikeOut
= TRUE
;
142 memset(&lfw2
, 0xff, sizeof(LOGFONTW
));
143 memcpy(&lfw
.lfFaceName
, arial
, 6 * sizeof(WCHAR
));
145 stat
= GdipCreateFontFromLogfontW(hdc
, &lfw
, &font
);
147 stat
= GdipGetLogFontW(font
, graphics
, &lfw2
);
150 ok(lfw2
.lfHeight
< 0, "Expected negative height\n");
151 expect(0, lfw2
.lfWidth
);
152 expect(0, lfw2
.lfEscapement
);
153 expect(0, lfw2
.lfOrientation
);
154 ok((lfw2
.lfWeight
>= 100) && (lfw2
.lfWeight
<= 900), "Expected weight to be set\n");
155 expect(TRUE
, lfw2
.lfItalic
);
156 expect(TRUE
, lfw2
.lfUnderline
);
157 expect(TRUE
, lfw2
.lfStrikeOut
);
158 expect(0, lfw2
.lfCharSet
);
159 expect(0, lfw2
.lfOutPrecision
);
160 expect(0, lfw2
.lfClipPrecision
);
161 expect(0, lfw2
.lfQuality
);
162 expect(0, lfw2
.lfPitchAndFamily
);
164 GdipDeleteFont(font
);
166 GdipDeleteGraphics(graphics
);
170 static void test_fontfamily (void)
172 GpFontFamily
*family
, *clonedFontFamily
;
173 WCHAR itsName
[LF_FACESIZE
];
176 /* FontFamily cannot be NULL */
177 stat
= GdipCreateFontFamilyFromName (arial
, NULL
, NULL
);
178 expect (InvalidParameter
, stat
);
180 /* FontFamily must be able to actually find the family.
181 * If it can't, any subsequent calls should fail.
183 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
184 expect (FontFamilyNotFound
, stat
);
186 /* Bitmap fonts are not found */
189 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
190 expect (FontFamilyNotFound
, stat
);
193 stat
= GdipCreateFontFamilyFromName (arial
, NULL
, &family
);
194 if(stat
== FontFamilyNotFound
)
196 skip("Arial not installed\n");
201 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
203 expect (0, lstrcmpiW(itsName
, arial
));
207 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
208 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
212 /* Make sure we don't read old data */
213 ZeroMemory (itsName
, sizeof(itsName
));
214 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
216 GdipDeleteFontFamily(family
);
217 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
219 expect(0, lstrcmpiW(itsName
, arial
));
221 GdipDeleteFontFamily(clonedFontFamily
);
224 static void test_fontfamily_properties (void)
226 GpFontFamily
* FontFamily
= NULL
;
230 stat
= GdipCreateFontFamilyFromName(arial
, NULL
, &FontFamily
);
231 if(stat
== FontFamilyNotFound
)
232 skip("Arial not installed\n");
237 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
239 ok (result
== 2355, "Expected 2355, got %d\n", result
);
242 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
244 ok(result
== 2048, "Expected 2048, got %d\n", result
);
246 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
248 ok(result
== 1854, "Expected 1854, got %d\n", result
);
250 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
251 ok(result
== 434, "Expected 434, got %d\n", result
);
252 GdipDeleteFontFamily(FontFamily
);
255 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
256 if(stat
== FontFamilyNotFound
)
257 skip("Times New Roman not installed\n");
263 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
265 ok(result
== 2355, "Expected 2355, got %d\n", result
);
268 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
270 ok(result
== 2048, "Expected 2048, got %d\n", result
);
272 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
274 ok(result
== 1825, "Expected 1825, got %d\n", result
);
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)
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");
296 stat
= GdipGetFamilyName (family
, familyName
, LANG_NEUTRAL
);
298 ok ((lstrcmpiW(familyName
, MicrosoftSansSerif
) == 0) ||
299 (lstrcmpiW(familyName
,MSSansSerif
) == 0),
300 "Expected Microsoft Sans Serif or MS Sans Serif, got %s\n",
301 debugstr_w(familyName
));
302 stat
= GdipDeleteFontFamily (family
);
306 stat
= GdipGetGenericFontFamilySerif (&family
);
307 if (stat
== FontFamilyNotFound
)
309 skip("Times New Roman not installed\n");
313 stat
= GdipGetFamilyName (family
, familyName
, LANG_NEUTRAL
);
315 ok (lstrcmpiW(familyName
, TimesNewRoman
) == 0,
316 "Expected Times New Roman, got %s\n", debugstr_w(familyName
));
317 stat
= GdipDeleteFontFamily (family
);
321 stat
= GdipGetGenericFontFamilyMonospace (&family
);
322 if (stat
== FontFamilyNotFound
)
324 skip("Courier New not installed\n");
328 stat
= GdipGetFamilyName (family
, familyName
, LANG_NEUTRAL
);
330 ok (lstrcmpiW(familyName
, CourierNew
) == 0,
331 "Expected Courier New, got %s\n", debugstr_w(familyName
));
332 stat
= GdipDeleteFontFamily (family
);
338 struct GdiplusStartupInput gdiplusStartupInput
;
339 ULONG_PTR gdiplusToken
;
341 gdiplusStartupInput
.GdiplusVersion
= 1;
342 gdiplusStartupInput
.DebugEventCallback
= NULL
;
343 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
344 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
346 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
351 test_fontfamily_properties();
354 GdiplusShutdown(gdiplusToken
);