1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/tests/gtest/gfxFontSelectionTests.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * This file is #included directly by gfxFontSelectionTest.cpp, and as 1.12 + * such does not need any #include files or similar. (However, should 1.13 + * any extra ones be required, it should be ok to do so, as well as 1.14 + * defining new functions, etc. 1.15 + * 1.16 + * To add a new test, call AddTest with the following arguments: the 1.17 + * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII 1.18 + * or S_UTF8) indicating the string type, and then the text string 1.19 + * itself as a string literal. Unfortunately there is no good way to 1.20 + * embed UTF8 directly into C code, so hex literals will need to be 1.21 + * placed in the string. Because of the way \x is parsed things like 1.22 + * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03" 1.23 + * will work fine, though. 1.24 + * 1.25 + * The result of AddTest should be assigned to the variable t; after 1.26 + * AddTest, one or more calls to t->Expect() should be added to define 1.27 + * the expected result. Multiple Expect() calls in a row for the same 1.28 + * platform mean that the resulting glyph/font selection items needs 1.29 + * to have as many items as there are Expect() calls. (See below for 1.30 + * examples.) 1.31 + * 1.32 + * The arguments to Expect are: 1.33 + * 1.34 + * platform - a string identifying the platform. 1.35 + * Valid strings are "win32", "macosx", and "gtk2-pango". 1.36 + * font - a string (UTF8) giving the unique name of the font. 1.37 + * See below for how the unique name is constructed. 1.38 + * glyphs - a set of glyph IDs that are expected. 1.39 + * This array is constructed using a GLYPHS() macro. 1.40 + * 1.41 + * GLYPHS() is just a #define for LiteralArray, which is defined 1.42 + * in gfxFontSelectionTest.cpp -- if you need more array elements 1.43 + * than available, just extend LiteralArray with a new constructor 1.44 + * with the required number of unsigned longs. 1.45 + * 1.46 + * The unique font name is a platform-specific constructed string for 1.47 + * (mostly) identifying a font. On Mac, it's created by taking the 1.48 + * Postscript name of the font. On Windows, it's created by taking 1.49 + * the family name, and then appending attributes such as ":Bold", 1.50 + * ":Italic", etc. 1.51 + * 1.52 + * The easiest way to create a test is to add a call to AddTest, and 1.53 + * then run the test. The output will include a list like: 1.54 + * 1.55 + * ==== Test 1 1.56 + * expected: 1.57 + * Run[ 0]: 'Verdana' 73 82 82 1.58 + * Run[ 1]: 'MS UI Gothic' 19401 1.59 + * Run[ 2]: 'Verdana' 69 68 85 1.60 + * Test 1 failed 1.61 + * 1.62 + * This gives you the information needed for the calls to Expect() -- 1.63 + * the unique name, and the glyphs. Appropriate calls to expect for 1.64 + * the above would be: 1.65 + * 1.66 + * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); 1.67 + * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401)); 1.68 + * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); 1.69 + * 1.70 + */ 1.71 + 1.72 + 1.73 +void 1.74 +SetupTests(nsTArray<TestEntry>& testList) 1.75 +{ 1.76 + TestEntry *t; 1.77 + 1.78 + /* some common styles */ 1.79 + gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL, 1.80 + 400, 1.81 + 0, 1.82 + 16.0, 1.83 + NS_NewPermanentAtom(NS_LITERAL_STRING("en")), 1.84 + 0.0, 1.85 + false, false, 1.86 + NS_LITERAL_STRING("")); 1.87 + 1.88 + gfxFontStyle style_western_bold_16 (mozilla::gfx::FontStyle::NORMAL, 1.89 + 700, 1.90 + 0, 1.91 + 16.0, 1.92 + NS_NewPermanentAtom(NS_LITERAL_STRING("en")), 1.93 + 0.0, 1.94 + false, false, 1.95 + NS_LITERAL_STRING("")); 1.96 + 1.97 + /* Test 0 */ 1.98 + t = AddTest (testList, "sans-serif", 1.99 + style_western_normal_16, 1.100 + S_ASCII, 1.101 + "ABCD"); 1.102 + 1.103 + t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39)); 1.104 + t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39)); 1.105 + t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39)); 1.106 + 1.107 + /* Test 1 */ 1.108 + t = AddTest (testList, "verdana,sans-serif", 1.109 + style_western_normal_16, 1.110 + S_UTF8, 1.111 + "foo\xe2\x80\x91""bar"); 1.112 + 1.113 + t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); 1.114 + t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236)); 1.115 + t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); 1.116 + 1.117 + t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82)); 1.118 + t->Expect ("macosx", "Helvetica", GLYPHS(587)); 1.119 + t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85)); 1.120 + 1.121 + /* Test 2 */ 1.122 + t = AddTest (testList, "sans-serif", 1.123 + style_western_bold_16, 1.124 + S_ASCII, 1.125 + "ABCD"); 1.126 + 1.127 + t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39)); 1.128 + t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39)); 1.129 + t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39)); 1.130 + 1.131 + /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */ 1.132 + t = AddTest (testList, "sans-serif", 1.133 + style_western_normal_16, 1.134 + S_UTF8, 1.135 + " \xd8\xaa\xd9\x85 "); 1.136 + t->SetRTL(); 1.137 + t->Expect ("macosx", "Helvetica", GLYPHS(3)); 1.138 + t->Expect ("macosx", "ArialMT", GLYPHS(919, 993)); 1.139 + t->Expect ("macosx", "Helvetica", GLYPHS(3)); 1.140 + t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3)); 1.141 + 1.142 + /* Test 4: LTR Arabic with leading and trailing whitespace */ 1.143 + t = AddTest (testList, "sans-serif", 1.144 + style_western_normal_16, 1.145 + S_UTF8, 1.146 + " \xd9\x85\xd8\xaa "); 1.147 + t->Expect ("macosx", "Helvetica", GLYPHS(3)); 1.148 + t->Expect ("macosx", "ArialMT", GLYPHS(993, 919)); 1.149 + t->Expect ("macosx", "Helvetica", GLYPHS(3)); 1.150 + t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3)); 1.151 + 1.152 + /* Test 5: RTL ASCII with leading whitespace */ 1.153 + t = AddTest (testList, "sans-serif", 1.154 + style_western_normal_16, 1.155 + S_ASCII, 1.156 + " ab"); 1.157 + t->SetRTL(); 1.158 + t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69)); 1.159 + t->Expect ("win32", "Arial", GLYPHS(3, 68, 69)); 1.160 + t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69)); 1.161 + 1.162 + /* Test 6: RTL ASCII with trailing whitespace */ 1.163 + t = AddTest (testList, "sans-serif", 1.164 + style_western_normal_16, 1.165 + S_ASCII, 1.166 + "ab "); 1.167 + t->SetRTL(); 1.168 + t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3)); 1.169 + t->Expect ("win32", "Arial", GLYPHS(68, 69, 3)); 1.170 + t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3)); 1.171 + 1.172 + /* Test 7: Simple ASCII ligature */ 1.173 + /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */ 1.174 + t = AddTest (testList, "sans-serif", 1.175 + style_western_normal_16, 1.176 + S_ASCII, 1.177 + "fi"); 1.178 + t->Expect ("macosx", "Helvetica", GLYPHS(192)); 1.179 + t->Expect ("win32", "Arial", GLYPHS(73, 76)); 1.180 + 1.181 + /* Test 8: DEVANAGARI VOWEL I reordering */ 1.182 + /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */ 1.183 + t = AddTest (testList, "sans-serif", 1.184 + style_western_normal_16, 1.185 + S_UTF8, 1.186 + "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319 1.187 + t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60)); 1.188 + t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102)); 1.189 + 1.190 + // Disabled Test 9 & 10 because these appear to vary on mac 1.191 + 1.192 + /* Test 9: NWJ test */ 1.193 + //t = AddTest (testList, "Kartika", 1.194 + // style_western_normal_16, 1.195 + // S_UTF8, 1.196 + // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); 1.197 + //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); 1.198 + //t->Expect ("win32", "Kartika", GLYPHS(332)); 1.199 + 1.200 + /* Test 10: NWJ fallback test */ 1.201 + /* it isn't clear what we should actually do in this case. Ideally 1.202 + we would have the same results as the previous test, but because 1.203 + we use sans-serif (i.e. Arial) CSS says we should should really 1.204 + use Arial for U+200D. 1.205 + */ 1.206 + //t = AddTest (testList, "sans-serif", 1.207 + // style_western_normal_16, 1.208 + // S_UTF8, 1.209 + // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); 1.210 + // Disabled because these appear to vary 1.211 + //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); 1.212 + //t->Expect ("win32", "Kartika", GLYPHS(332)); 1.213 +}