michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * michael@0: * This file is #included directly by gfxFontSelectionTest.cpp, and as michael@0: * such does not need any #include files or similar. (However, should michael@0: * any extra ones be required, it should be ok to do so, as well as michael@0: * defining new functions, etc. michael@0: * michael@0: * To add a new test, call AddTest with the following arguments: the michael@0: * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII michael@0: * or S_UTF8) indicating the string type, and then the text string michael@0: * itself as a string literal. Unfortunately there is no good way to michael@0: * embed UTF8 directly into C code, so hex literals will need to be michael@0: * placed in the string. Because of the way \x is parsed things like michael@0: * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03" michael@0: * will work fine, though. michael@0: * michael@0: * The result of AddTest should be assigned to the variable t; after michael@0: * AddTest, one or more calls to t->Expect() should be added to define michael@0: * the expected result. Multiple Expect() calls in a row for the same michael@0: * platform mean that the resulting glyph/font selection items needs michael@0: * to have as many items as there are Expect() calls. (See below for michael@0: * examples.) michael@0: * michael@0: * The arguments to Expect are: michael@0: * michael@0: * platform - a string identifying the platform. michael@0: * Valid strings are "win32", "macosx", and "gtk2-pango". michael@0: * font - a string (UTF8) giving the unique name of the font. michael@0: * See below for how the unique name is constructed. michael@0: * glyphs - a set of glyph IDs that are expected. michael@0: * This array is constructed using a GLYPHS() macro. michael@0: * michael@0: * GLYPHS() is just a #define for LiteralArray, which is defined michael@0: * in gfxFontSelectionTest.cpp -- if you need more array elements michael@0: * than available, just extend LiteralArray with a new constructor michael@0: * with the required number of unsigned longs. michael@0: * michael@0: * The unique font name is a platform-specific constructed string for michael@0: * (mostly) identifying a font. On Mac, it's created by taking the michael@0: * Postscript name of the font. On Windows, it's created by taking michael@0: * the family name, and then appending attributes such as ":Bold", michael@0: * ":Italic", etc. michael@0: * michael@0: * The easiest way to create a test is to add a call to AddTest, and michael@0: * then run the test. The output will include a list like: michael@0: * michael@0: * ==== Test 1 michael@0: * expected: michael@0: * Run[ 0]: 'Verdana' 73 82 82 michael@0: * Run[ 1]: 'MS UI Gothic' 19401 michael@0: * Run[ 2]: 'Verdana' 69 68 85 michael@0: * Test 1 failed michael@0: * michael@0: * This gives you the information needed for the calls to Expect() -- michael@0: * the unique name, and the glyphs. Appropriate calls to expect for michael@0: * the above would be: michael@0: * michael@0: * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); michael@0: * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401)); michael@0: * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); michael@0: * michael@0: */ michael@0: michael@0: michael@0: void michael@0: SetupTests(nsTArray& testList) michael@0: { michael@0: TestEntry *t; michael@0: michael@0: /* some common styles */ michael@0: gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL, michael@0: 400, michael@0: 0, michael@0: 16.0, michael@0: NS_NewPermanentAtom(NS_LITERAL_STRING("en")), michael@0: 0.0, michael@0: false, false, michael@0: NS_LITERAL_STRING("")); michael@0: michael@0: gfxFontStyle style_western_bold_16 (mozilla::gfx::FontStyle::NORMAL, michael@0: 700, michael@0: 0, michael@0: 16.0, michael@0: NS_NewPermanentAtom(NS_LITERAL_STRING("en")), michael@0: 0.0, michael@0: false, false, michael@0: NS_LITERAL_STRING("")); michael@0: michael@0: /* Test 0 */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_ASCII, michael@0: "ABCD"); michael@0: michael@0: t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39)); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39)); michael@0: t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39)); michael@0: michael@0: /* Test 1 */ michael@0: t = AddTest (testList, "verdana,sans-serif", michael@0: style_western_normal_16, michael@0: S_UTF8, michael@0: "foo\xe2\x80\x91""bar"); michael@0: michael@0: t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82)); michael@0: t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236)); michael@0: t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85)); michael@0: michael@0: t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82)); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(587)); michael@0: t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85)); michael@0: michael@0: /* Test 2 */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_bold_16, michael@0: S_ASCII, michael@0: "ABCD"); michael@0: michael@0: t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39)); michael@0: t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39)); michael@0: t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39)); michael@0: michael@0: /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_UTF8, michael@0: " \xd8\xaa\xd9\x85 "); michael@0: t->SetRTL(); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(3)); michael@0: t->Expect ("macosx", "ArialMT", GLYPHS(919, 993)); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(3)); michael@0: t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3)); michael@0: michael@0: /* Test 4: LTR Arabic with leading and trailing whitespace */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_UTF8, michael@0: " \xd9\x85\xd8\xaa "); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(3)); michael@0: t->Expect ("macosx", "ArialMT", GLYPHS(993, 919)); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(3)); michael@0: t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3)); michael@0: michael@0: /* Test 5: RTL ASCII with leading whitespace */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_ASCII, michael@0: " ab"); michael@0: t->SetRTL(); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69)); michael@0: t->Expect ("win32", "Arial", GLYPHS(3, 68, 69)); michael@0: t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69)); michael@0: michael@0: /* Test 6: RTL ASCII with trailing whitespace */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_ASCII, michael@0: "ab "); michael@0: t->SetRTL(); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3)); michael@0: t->Expect ("win32", "Arial", GLYPHS(68, 69, 3)); michael@0: t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3)); michael@0: michael@0: /* Test 7: Simple ASCII ligature */ michael@0: /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_ASCII, michael@0: "fi"); michael@0: t->Expect ("macosx", "Helvetica", GLYPHS(192)); michael@0: t->Expect ("win32", "Arial", GLYPHS(73, 76)); michael@0: michael@0: /* Test 8: DEVANAGARI VOWEL I reordering */ michael@0: /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */ michael@0: t = AddTest (testList, "sans-serif", michael@0: style_western_normal_16, michael@0: S_UTF8, michael@0: "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319 michael@0: t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60)); michael@0: t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102)); michael@0: michael@0: // Disabled Test 9 & 10 because these appear to vary on mac michael@0: michael@0: /* Test 9: NWJ test */ michael@0: //t = AddTest (testList, "Kartika", michael@0: // style_western_normal_16, michael@0: // S_UTF8, michael@0: // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); michael@0: //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); michael@0: //t->Expect ("win32", "Kartika", GLYPHS(332)); michael@0: michael@0: /* Test 10: NWJ fallback test */ michael@0: /* it isn't clear what we should actually do in this case. Ideally michael@0: we would have the same results as the previous test, but because michael@0: we use sans-serif (i.e. Arial) CSS says we should should really michael@0: use Arial for U+200D. michael@0: */ michael@0: //t = AddTest (testList, "sans-serif", michael@0: // style_western_normal_16, michael@0: // S_UTF8, michael@0: // "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d"); michael@0: // Disabled because these appear to vary michael@0: //t->Expect ("macosx", "MalayalamMN", GLYPHS(360)); michael@0: //t->Expect ("win32", "Kartika", GLYPHS(332)); michael@0: }