|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * |
|
8 * This file is #included directly by gfxFontSelectionTest.cpp, and as |
|
9 * such does not need any #include files or similar. (However, should |
|
10 * any extra ones be required, it should be ok to do so, as well as |
|
11 * defining new functions, etc. |
|
12 * |
|
13 * To add a new test, call AddTest with the following arguments: the |
|
14 * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII |
|
15 * or S_UTF8) indicating the string type, and then the text string |
|
16 * itself as a string literal. Unfortunately there is no good way to |
|
17 * embed UTF8 directly into C code, so hex literals will need to be |
|
18 * placed in the string. Because of the way \x is parsed things like |
|
19 * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03" |
|
20 * will work fine, though. |
|
21 * |
|
22 * The result of AddTest should be assigned to the variable t; after |
|
23 * AddTest, one or more calls to t->Expect() should be added to define |
|
24 * the expected result. Multiple Expect() calls in a row for the same |
|
25 * platform mean that the resulting glyph/font selection items needs |
|
26 * to have as many items as there are Expect() calls. (See below for |
|
27 * examples.) |
|
28 * |
|
29 * The arguments to Expect are: |
|
30 * |
|
31 * platform - a string identifying the platform. |
|
32 * Valid strings are "win32", "macosx", and "gtk2-pango". |
|
33 * font - a string (UTF8) giving the unique name of the font. |
|
34 * See below for how the unique name is constructed. |
|
35 * glyphs - a set of glyph IDs that are expected. |
|
36 * This array is constructed using a GLYPHS() macro. |
|
37 * |
|
38 * GLYPHS() is just a #define for LiteralArray, which is defined |
|
39 * in gfxFontSelectionTest.cpp -- if you need more array elements |
|
40 * than available, just extend LiteralArray with a new constructor |
|
41 * with the required number of unsigned longs. |
|
42 * |
|
43 * The unique font name is a platform-specific constructed string for |
|
44 * (mostly) identifying a font. On Mac, it's created by taking the |
|
45 * Postscript name of the font. On Windows, it's created by taking |
|
46 * the family name, and then appending attributes such as ":Bold", |
|
47 * ":Italic", etc. |
|
48 * |
|
49 * The easiest way to create a test is to add a call to AddTest, and |
|
50 * then run the test. The output will include a list like: |
|
51 * |
|
52 * ==== Test 1 |
|
53 * expected: |
|
54 * Run[ 0]: 'Verdana' 73 82 82 |
|
55 * Run[ 1]: 'MS UI Gothic' 19401 |
|
56 * Run[ 2]: 'Verdana' 69 68 85 |
|
57 * Test 1 failed |
|
58 * |
|
59 * This gives you the information needed for the calls to Expect() -- |
|
60 * the unique name, and the glyphs. Appropriate calls to expect for |
|
61 * the above would be: |
|
62 * |
|
63 * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); |
|
64 * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401)); |
|
65 * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); |
|
66 * |
|
67 */ |
|
68 |
|
69 |
|
70 void |
|
71 SetupTests(nsTArray<TestEntry>& testList) |
|
72 { |
|
73 TestEntry *t; |
|
74 |
|
75 /* some common styles */ |
|
76 gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL, |
|
77 400, |
|
78 0, |
|
79 16.0, |
|
80 NS_NewPermanentAtom(NS_LITERAL_STRING("en")), |
|
81 0.0, |
|
82 false, false, |
|
83 NS_LITERAL_STRING("")); |
|
84 |
|
85 gfxFontStyle style_western_bold_16 (mozilla::gfx::FontStyle::NORMAL, |
|
86 700, |
|
87 0, |
|
88 16.0, |
|
89 NS_NewPermanentAtom(NS_LITERAL_STRING("en")), |
|
90 0.0, |
|
91 false, false, |
|
92 NS_LITERAL_STRING("")); |
|
93 |
|
94 /* Test 0 */ |
|
95 t = AddTest (testList, "sans-serif", |
|
96 style_western_normal_16, |
|
97 S_ASCII, |
|
98 "ABCD"); |
|
99 |
|
100 t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39)); |
|
101 t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39)); |
|
102 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39)); |
|
103 |
|
104 /* Test 1 */ |
|
105 t = AddTest (testList, "verdana,sans-serif", |
|
106 style_western_normal_16, |
|
107 S_UTF8, |
|
108 "foo\xe2\x80\x91""bar"); |
|
109 |
|
110 t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); |
|
111 t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236)); |
|
112 t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); |
|
113 |
|
114 t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82)); |
|
115 t->Expect ("macosx", "Helvetica", GLYPHS(587)); |
|
116 t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85)); |
|
117 |
|
118 /* Test 2 */ |
|
119 t = AddTest (testList, "sans-serif", |
|
120 style_western_bold_16, |
|
121 S_ASCII, |
|
122 "ABCD"); |
|
123 |
|
124 t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39)); |
|
125 t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39)); |
|
126 t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39)); |
|
127 |
|
128 /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */ |
|
129 t = AddTest (testList, "sans-serif", |
|
130 style_western_normal_16, |
|
131 S_UTF8, |
|
132 " \xd8\xaa\xd9\x85 "); |
|
133 t->SetRTL(); |
|
134 t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
|
135 t->Expect ("macosx", "ArialMT", GLYPHS(919, 993)); |
|
136 t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
|
137 t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3)); |
|
138 |
|
139 /* Test 4: LTR Arabic with leading and trailing whitespace */ |
|
140 t = AddTest (testList, "sans-serif", |
|
141 style_western_normal_16, |
|
142 S_UTF8, |
|
143 " \xd9\x85\xd8\xaa "); |
|
144 t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
|
145 t->Expect ("macosx", "ArialMT", GLYPHS(993, 919)); |
|
146 t->Expect ("macosx", "Helvetica", GLYPHS(3)); |
|
147 t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3)); |
|
148 |
|
149 /* Test 5: RTL ASCII with leading whitespace */ |
|
150 t = AddTest (testList, "sans-serif", |
|
151 style_western_normal_16, |
|
152 S_ASCII, |
|
153 " ab"); |
|
154 t->SetRTL(); |
|
155 t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69)); |
|
156 t->Expect ("win32", "Arial", GLYPHS(3, 68, 69)); |
|
157 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69)); |
|
158 |
|
159 /* Test 6: RTL ASCII with trailing whitespace */ |
|
160 t = AddTest (testList, "sans-serif", |
|
161 style_western_normal_16, |
|
162 S_ASCII, |
|
163 "ab "); |
|
164 t->SetRTL(); |
|
165 t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3)); |
|
166 t->Expect ("win32", "Arial", GLYPHS(68, 69, 3)); |
|
167 t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3)); |
|
168 |
|
169 /* Test 7: Simple ASCII ligature */ |
|
170 /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */ |
|
171 t = AddTest (testList, "sans-serif", |
|
172 style_western_normal_16, |
|
173 S_ASCII, |
|
174 "fi"); |
|
175 t->Expect ("macosx", "Helvetica", GLYPHS(192)); |
|
176 t->Expect ("win32", "Arial", GLYPHS(73, 76)); |
|
177 |
|
178 /* Test 8: DEVANAGARI VOWEL I reordering */ |
|
179 /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */ |
|
180 t = AddTest (testList, "sans-serif", |
|
181 style_western_normal_16, |
|
182 S_UTF8, |
|
183 "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319 |
|
184 t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60)); |
|
185 t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102)); |
|
186 |
|
187 // Disabled Test 9 & 10 because these appear to vary on mac |
|
188 |
|
189 /* Test 9: NWJ test */ |
|
190 //t = AddTest (testList, "Kartika", |
|
191 // style_western_normal_16, |
|
192 // S_UTF8, |
|
193 // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); |
|
194 //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); |
|
195 //t->Expect ("win32", "Kartika", GLYPHS(332)); |
|
196 |
|
197 /* Test 10: NWJ fallback test */ |
|
198 /* it isn't clear what we should actually do in this case. Ideally |
|
199 we would have the same results as the previous test, but because |
|
200 we use sans-serif (i.e. Arial) CSS says we should should really |
|
201 use Arial for U+200D. |
|
202 */ |
|
203 //t = AddTest (testList, "sans-serif", |
|
204 // style_western_normal_16, |
|
205 // S_UTF8, |
|
206 // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); |
|
207 // Disabled because these appear to vary |
|
208 //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); |
|
209 //t->Expect ("win32", "Kartika", GLYPHS(332)); |
|
210 } |