Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / gfx / tests / gfxFontSelectionTests.h
blob52c8e4061a762570086e6ed8a0d5c30b1a3ed019
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Corporation code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Vladimir Vukicevic <vladimir@pobox.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * This file is #included directly by gfxFontSelectionTest.cpp, and as
41 * such does not need any #include files or similar. (However, should
42 * any extra ones be required, it should be ok to do so, as well as
43 * defining new functions, etc.
45 * To add a new test, call AddTest with the following arguments: the
46 * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII
47 * or S_UTF8) indicating the string type, and then the text string
48 * itself as a string literal. Unfortunately there is no good way to
49 * embed UTF8 directly into C code, so hex literals will need to be
50 * placed in the string. Because of the way \x is parsed things like
51 * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03"
52 * will work fine, though.
54 * The result of AddTest should be assigned to the variable t; after
55 * AddTest, one or more calls to t->Expect() should be added to define
56 * the expected result. Multiple Expect() calls in a row for the same
57 * platform mean that the resulting glyph/font selection items needs
58 * to have as many items as there are Expect() calls. (See below for
59 * examples.)
61 * The arguments to Expect are:
63 * platform - a string identifying the platform.
64 * Valid strings are "win32", "macosx", and "gtk2-pango".
65 * font - a string (UTF8) giving the unique name of the font.
66 * See below for how the unique name is constructed.
67 * glyphs - a set of glyph IDs that are expected.
68 * This array is constructed using a GLYPHS() macro.
70 * GLYPHS() is just a #define for LiteralArray, which is defined
71 * in gfxFontSelectionTest.cpp -- if you need more array elements
72 * than available, just extend LiteralArray with a new constructor
73 * with the required number of unsigned longs.
75 * The unique font name is a platform-specific constructed string for
76 * (mostly) identifying a font. On Mac, it's created by taking the
77 * Postscript name of the font. On Windows, it's created by taking
78 * the family name, and then appending attributes such as ":Bold",
79 * ":Italic", etc.
81 * The easiest way to create a test is to add a call to AddTest, and
82 * then run the test. The output will include a list like:
84 * ==== Test 1
85 * expected:
86 * Run[ 0]: 'Verdana' 73 82 82
87 * Run[ 1]: 'MS UI Gothic' 19401
88 * Run[ 2]: 'Verdana' 69 68 85
89 * Test 1 failed
91 * This gives you the information needed for the calls to Expect() --
92 * the unique name, and the glyphs. Appropriate calls to expect for
93 * the above would be:
95 * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
96 * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401));
97 * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
102 void
103 SetupTests()
105 TestEntry *t;
107 /* some common styles */
108 gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
109 NS_FONT_STRETCH_NORMAL,
110 400,
111 16.0,
112 NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
113 0.0,
114 PR_FALSE, PR_FALSE, PR_FALSE,
115 NS_LITERAL_STRING(""),
116 NS_LITERAL_STRING(""));
118 gfxFontStyle style_western_bold_16 (FONT_STYLE_NORMAL,
119 NS_FONT_STRETCH_NORMAL,
120 700,
121 16.0,
122 NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
123 0.0,
124 PR_FALSE, PR_FALSE, PR_FALSE,
125 NS_LITERAL_STRING(""),
126 NS_LITERAL_STRING(""));
128 /* Test 0 */
129 t = AddTest ("sans-serif",
130 style_western_normal_16,
131 S_ASCII,
132 "ABCD");
134 t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39));
135 t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39));
136 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39));
138 /* Test 1 */
139 t = AddTest ("verdana,sans-serif",
140 style_western_normal_16,
141 S_UTF8,
142 "foo\xe2\x80\x91""bar");
144 t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
145 t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236));
146 t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
148 t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82));
149 t->Expect ("macosx", "Helvetica", GLYPHS(587));
150 t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85));
152 /* Test 2 */
153 t = AddTest ("sans-serif",
154 style_western_bold_16,
155 S_ASCII,
156 "ABCD");
158 t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39));
159 t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39));
160 t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39));
162 /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */
163 t = AddTest ("sans-serif",
164 style_western_normal_16,
165 S_UTF8,
166 " \xd8\xaa\xd9\x85 ");
167 t->SetRTL();
168 t->Expect ("macosx", "Helvetica", GLYPHS(3));
169 t->Expect ("macosx", "AlBayan", GLYPHS(47));
170 t->Expect ("macosx", "Helvetica", GLYPHS(3));
171 t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3));
173 /* Test 4: LTR Arabic with leading and trailing whitespace */
174 t = AddTest ("sans-serif",
175 style_western_normal_16,
176 S_UTF8,
177 " \xd9\x85\xd8\xaa ");
178 t->Expect ("macosx", "Helvetica", GLYPHS(3));
179 t->Expect ("macosx", "AlBayan", GLYPHS(2, 47));
180 t->Expect ("macosx", "Helvetica", GLYPHS(3));
181 t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3));
183 /* Test 5: RTL ASCII with leading whitespace */
184 t = AddTest ("sans-serif",
185 style_western_normal_16,
186 S_ASCII,
187 " ab");
188 t->SetRTL();
189 t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69));
190 t->Expect ("win32", "Arial", GLYPHS(3, 68, 69));
191 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69));
193 /* Test 6: RTL ASCII with trailing whitespace */
194 t = AddTest ("sans-serif",
195 style_western_normal_16,
196 S_ASCII,
197 "ab ");
198 t->SetRTL();
199 t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3));
200 t->Expect ("win32", "Arial", GLYPHS(68, 69, 3));
201 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3));
203 /* Test 7: Simple ASCII ligature */
204 /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */
205 t = AddTest ("sans-serif",
206 style_western_normal_16,
207 S_ASCII,
208 "fi");
209 t->Expect ("macosx", "Helvetica", GLYPHS(192));
210 t->Expect ("win32", "Arial", GLYPHS(73, 76));
212 /* Test 8: DEVANAGARI VOWEL I reordering */
213 /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */
214 t = AddTest ("sans-serif",
215 style_western_normal_16,
216 S_UTF8,
217 "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319
218 t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60));
219 t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102));
221 /* Test 9: NWJ test */
222 t = AddTest ("Kartika",
223 style_western_normal_16,
224 S_UTF8,
225 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
226 t->Expect ("win32", "Kartika", GLYPHS(332));
228 /* Test 10: NWJ fallback test */
229 /* it isn't clear what we should actually do in this case. Ideally
230 we would have the same results as the previous test, but because
231 we use sans-serif (i.e. Arial) CSS says we should should really
232 use Arial for U+200D.
234 t = AddTest ("sans-serif",
235 style_western_normal_16,
236 S_UTF8,
237 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
238 t->Expect ("win32", "Kartika", GLYPHS(332));