gecko/gfx/tests/gfxFontSelectionTest.cpp
Zack Weinberg 00dd731d9b Bug 571989 part 4: Reorganize all the tests directories below gfx/. r=joedrew
--HG--
rename : gfx/thebes/crashtests/122875-1.html => gfx/tests/crashtests/122875-1.html
rename : gfx/thebes/crashtests/156882-1.html => gfx/tests/crashtests/156882-1.html
rename : gfx/thebes/crashtests/157320-1.html => gfx/tests/crashtests/157320-1.html
rename : gfx/thebes/crashtests/199379-1.html => gfx/tests/crashtests/199379-1.html
rename : gfx/thebes/crashtests/206561-1.html => gfx/tests/crashtests/206561-1.html
rename : gfx/thebes/crashtests/248518-1.html => gfx/tests/crashtests/248518-1.html
rename : gfx/thebes/crashtests/306649-1.xml => gfx/tests/crashtests/306649-1.xml
rename : gfx/src/thebes/crashtests/306902-1.xml => gfx/tests/crashtests/306902-1.xml
rename : gfx/thebes/crashtests/333861-1.html => gfx/tests/crashtests/333861-1.html
rename : gfx/thebes/crashtests/334735-1.html => gfx/tests/crashtests/334735-1.html
rename : gfx/thebes/crashtests/345576-1.html => gfx/tests/crashtests/345576-1.html
rename : gfx/thebes/crashtests/345629-1.html => gfx/tests/crashtests/345629-1.html
rename : gfx/thebes/crashtests/348462-1.html => gfx/tests/crashtests/348462-1.html
rename : gfx/thebes/crashtests/348462-2.html => gfx/tests/crashtests/348462-2.html
rename : gfx/thebes/crashtests/369688-1.html => gfx/tests/crashtests/369688-1.html
rename : gfx/thebes/crashtests/369947-1.html => gfx/tests/crashtests/369947-1.html
rename : gfx/thebes/crashtests/372094-1.xhtml => gfx/tests/crashtests/372094-1.xhtml
rename : gfx/thebes/crashtests/376627-1.html => gfx/tests/crashtests/376627-1.html
rename : gfx/thebes/crashtests/377231-1.html => gfx/tests/crashtests/377231-1.html
rename : gfx/thebes/crashtests/377232-1.xhtml => gfx/tests/crashtests/377232-1.xhtml
rename : gfx/thebes/crashtests/377461-1.xhtml => gfx/tests/crashtests/377461-1.xhtml
rename : gfx/thebes/crashtests/383473-1.html => gfx/tests/crashtests/383473-1.html
rename : gfx/src/thebes/crashtests/383872-1.svg => gfx/tests/crashtests/383872-1.svg
rename : gfx/thebes/crashtests/385228-1.svg => gfx/tests/crashtests/385228-1.svg
rename : gfx/thebes/crashtests/385228-2.svg => gfx/tests/crashtests/385228-2.svg
rename : gfx/thebes/crashtests/385289-1.xhtml => gfx/tests/crashtests/385289-1.xhtml
rename : gfx/thebes/crashtests/385417-1.html => gfx/tests/crashtests/385417-1.html
rename : gfx/thebes/crashtests/385417-2.html => gfx/tests/crashtests/385417-2.html
rename : gfx/thebes/crashtests/385423-1.html => gfx/tests/crashtests/385423-1.html
rename : gfx/thebes/crashtests/385423-2.html => gfx/tests/crashtests/385423-2.html
rename : gfx/thebes/crashtests/385719-1.html => gfx/tests/crashtests/385719-1.html
rename : gfx/thebes/crashtests/389326-1-inner.xhtml => gfx/tests/crashtests/389326-1-inner.xhtml
rename : gfx/thebes/crashtests/389326-1.html => gfx/tests/crashtests/389326-1.html
rename : gfx/thebes/crashtests/393746-1.xhtml => gfx/tests/crashtests/393746-1.xhtml
rename : gfx/thebes/crashtests/393749-1.html => gfx/tests/crashtests/393749-1.html
rename : gfx/thebes/crashtests/393822-1.html => gfx/tests/crashtests/393822-1.html
rename : gfx/thebes/crashtests/394246-1.html => gfx/tests/crashtests/394246-1.html
rename : gfx/thebes/crashtests/394246-2.html => gfx/tests/crashtests/394246-2.html
rename : gfx/thebes/crashtests/394384-1.html => gfx/tests/crashtests/394384-1.html
rename : gfx/thebes/crashtests/395335-1.xhtml => gfx/tests/crashtests/395335-1.xhtml
rename : gfx/thebes/crashtests/395458-1.html => gfx/tests/crashtests/395458-1.html
rename : gfx/thebes/crashtests/396321-1.svg => gfx/tests/crashtests/396321-1.svg
rename : gfx/thebes/crashtests/398042-1.xhtml => gfx/tests/crashtests/398042-1.xhtml
rename : gfx/thebes/crashtests/398042-2.xhtml => gfx/tests/crashtests/398042-2.xhtml
rename : gfx/thebes/crashtests/402307-1.html => gfx/tests/crashtests/402307-1.html
rename : gfx/thebes/crashtests/403464-1.html => gfx/tests/crashtests/403464-1.html
rename : gfx/thebes/crashtests/404112-1.html => gfx/tests/crashtests/404112-1.html
rename : gfx/thebes/crashtests/404112-2.html => gfx/tests/crashtests/404112-2.html
rename : gfx/thebes/crashtests/405268-1.xhtml => gfx/tests/crashtests/405268-1.xhtml
rename : gfx/thebes/crashtests/407761-1.html => gfx/tests/crashtests/407761-1.html
rename : gfx/thebes/crashtests/407842.html => gfx/tests/crashtests/407842.html
rename : gfx/thebes/crashtests/408754-1.html => gfx/tests/crashtests/408754-1.html
rename : gfx/thebes/crashtests/410728-1.xml => gfx/tests/crashtests/410728-1.xml
rename : gfx/thebes/crashtests/416637-1.html => gfx/tests/crashtests/416637-1.html
rename : gfx/thebes/crashtests/419095-1.html => gfx/tests/crashtests/419095-1.html
rename : gfx/thebes/crashtests/419255-1.html => gfx/tests/crashtests/419255-1.html
rename : gfx/thebes/crashtests/420945-1.html => gfx/tests/crashtests/420945-1.html
rename : gfx/thebes/crashtests/420962-1.html => gfx/tests/crashtests/420962-1.html
rename : gfx/thebes/crashtests/421393-1.html => gfx/tests/crashtests/421393-1.html
rename : gfx/thebes/crashtests/421813-1.html => gfx/tests/crashtests/421813-1.html
rename : gfx/src/thebes/crashtests/423110-1.xhtml => gfx/tests/crashtests/423110-1.xhtml
rename : gfx/thebes/crashtests/423270-1.html => gfx/tests/crashtests/423270-1.html
rename : gfx/thebes/crashtests/429899-1.html => gfx/tests/crashtests/429899-1.html
rename : gfx/thebes/crashtests/441360.html => gfx/tests/crashtests/441360.html
rename : gfx/thebes/crashtests/441360_data.gif => gfx/tests/crashtests/441360_data.gif
rename : gfx/src/thebes/crashtests/445711.html => gfx/tests/crashtests/445711.html
rename : gfx/thebes/crashtests/463307-1.html => gfx/tests/crashtests/463307-1.html
rename : gfx/thebes/crashtests/467703-1.xhtml => gfx/tests/crashtests/467703-1.xhtml
rename : gfx/thebes/crashtests/467873-1.html => gfx/tests/crashtests/467873-1.html
rename : gfx/thebes/crashtests/470418-1.html => gfx/tests/crashtests/470418-1.html
rename : gfx/thebes/crashtests/474410-1.html => gfx/tests/crashtests/474410-1.html
rename : gfx/thebes/crashtests/483120-1.xhtml => gfx/tests/crashtests/483120-1.xhtml
rename : gfx/thebes/crashtests/483120-2.xhtml => gfx/tests/crashtests/483120-2.xhtml
rename : gfx/thebes/crashtests/487549-1.html => gfx/tests/crashtests/487549-1.html
rename : gfx/thebes/crashtests/487549-bad_kern_table.ttf => gfx/tests/crashtests/487549-bad_kern_table.ttf
rename : gfx/thebes/crashtests/487724-1.html => gfx/tests/crashtests/487724-1.html
rename : gfx/thebes/crashtests/490777-1.html => gfx/tests/crashtests/490777-1.html
rename : gfx/thebes/crashtests/532726-1.html => gfx/tests/crashtests/532726-1.html
rename : gfx/thebes/crashtests/538065-1.html => gfx/tests/crashtests/538065-1.html
rename : gfx/thebes/crashtests/546870-1.html => gfx/tests/crashtests/546870-1.html
rename : gfx/thebes/crashtests/balinese-letter-spacing.html => gfx/tests/crashtests/balinese-letter-spacing.html
rename : gfx/thebes/crashtests/crashtests.list => gfx/tests/crashtests/crashtests.list
rename : gfx/thebes/test/gfxColorManagementTest.cmtest => gfx/tests/gfxColorManagementTest.cmtest
rename : gfx/thebes/test/gfxColorManagementTest.cpp => gfx/tests/gfxColorManagementTest.cpp
rename : gfx/thebes/test/gfxFontSelectionTest.cpp => gfx/tests/gfxFontSelectionTest.cpp
rename : gfx/thebes/test/gfxFontSelectionTests.h => gfx/tests/gfxFontSelectionTests.h
rename : gfx/thebes/test/gfxSurfaceRefCountTest.cpp => gfx/tests/gfxSurfaceRefCountTest.cpp
rename : gfx/thebes/test/gfxTestCocoaHelper.h => gfx/tests/gfxTestCocoaHelper.h
rename : gfx/thebes/test/gfxTestCocoaHelper.mm => gfx/tests/gfxTestCocoaHelper.mm
rename : gfx/thebes/test/gfxTextRunPerfTest.cpp => gfx/tests/gfxTextRunPerfTest.cpp
rename : gfx/thebes/test/gfxWordCacheTest.cpp => gfx/tests/gfxWordCacheTest.cpp
rename : gfx/thebes/mochitest/test_bug509244.html => gfx/tests/mochitest/test_bug509244.html
rename : gfx/thebes/mochitest/test_bug513439.html => gfx/tests/mochitest/test_bug513439.html
rename : gfx/thebes/test/per-word-runs.h => gfx/tests/per-word-runs.h
rename : gfx/thebes/test/process-textruns.pl => gfx/tests/process-textruns.pl
rename : gfx/thebes/test/testprofiles/DELL2407WFP-2B283C91.icc => gfx/tests/testprofiles/DELL2407WFP-2B283C91.icc
rename : gfx/thebes/test/testprofiles/G22LWk-2489A79.icc => gfx/tests/testprofiles/G22LWk-2489A79.icc
rename : gfx/thebes/test/testprofiles/MBP20080419-1.icc => gfx/tests/testprofiles/MBP20080419-1.icc
rename : gfx/thebes/test/testprofiles/PhLCD17a.icm => gfx/tests/testprofiles/PhLCD17a.icm
rename : gfx/thebes/test/testprofiles/identity.icc => gfx/tests/testprofiles/identity.icc
rename : gfx/thebes/test/testprofiles/murphy.icc => gfx/tests/testprofiles/murphy.icc
rename : gfx/thebes/test/testprofiles/sRGB_IEC61966-2-1_noBPC.icc => gfx/tests/testprofiles/sRGB_IEC61966-2-1_noBPC.icc
rename : gfx/thebes/test/testprofiles/sRGB_IEC61966-2-1_withBPC.icc => gfx/tests/testprofiles/sRGB_IEC61966-2-1_withBPC.icc
rename : gfx/thebes/test/testprofiles/sRGB_v4_ICC_preference.icc => gfx/tests/testprofiles/sRGB_v4_ICC_preference.icc
2010-07-13 14:54:18 -07:00

405 lines
11 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Corporation code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsString.h"
#include "nsDependentString.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "gfxContext.h"
#include "gfxFont.h"
#include "gfxPlatform.h"
#include "gfxTextRunWordCache.h"
#include "gfxFontTest.h"
#if defined(XP_MACOSX)
#include "gfxTestCocoaHelper.h"
#endif
#ifdef MOZ_WIDGET_GTK2
#include "gtk/gtk.h"
#endif
enum {
S_UTF8 = 0,
S_ASCII = 1
};
class FrameTextRunCache;
static gfxTextRunWordCache *gTextRunCache;
struct LiteralArray {
LiteralArray (unsigned long l1) {
data.AppendElement(l1);
}
LiteralArray (unsigned long l1, unsigned long l2) {
data.AppendElement(l1);
data.AppendElement(l2);
}
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3) {
data.AppendElement(l1);
data.AppendElement(l2);
data.AppendElement(l3);
}
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3, unsigned long l4) {
data.AppendElement(l1);
data.AppendElement(l2);
data.AppendElement(l3);
data.AppendElement(l4);
}
LiteralArray (unsigned long l1, unsigned long l2, unsigned long l3, unsigned long l4, unsigned long l5) {
data.AppendElement(l1);
data.AppendElement(l2);
data.AppendElement(l3);
data.AppendElement(l4);
data.AppendElement(l5);
}
LiteralArray (const LiteralArray& other) {
data = other.data;
}
nsTArray<unsigned long> data;
};
#define GLYPHS LiteralArray
struct TestEntry {
TestEntry (const char *aUTF8FamilyString,
const gfxFontStyle& aFontStyle,
const char *aString)
: utf8FamilyString(aUTF8FamilyString),
fontStyle(aFontStyle),
stringType(S_ASCII),
string(aString),
isRTL(PR_FALSE)
{
}
TestEntry (const char *aUTF8FamilyString,
const gfxFontStyle& aFontStyle,
int stringType,
const char *aString)
: utf8FamilyString(aUTF8FamilyString),
fontStyle(aFontStyle),
stringType(stringType),
string(aString),
isRTL(PR_FALSE)
{
}
struct ExpectItem {
ExpectItem(const nsCString& aFontName,
const LiteralArray& aGlyphs)
: fontName(aFontName), glyphs(aGlyphs)
{ }
PRBool Compare(const nsCString& aFontName,
cairo_glyph_t *aGlyphs,
int num_glyphs)
{
// bit that allowed for empty fontname to match all is commented
// out
if (/*!fontName.IsEmpty() &&*/ !fontName.Equals(aFontName))
return PR_FALSE;
if (num_glyphs != int(glyphs.data.Length()))
return PR_FALSE;
for (int j = 0; j < num_glyphs; j++) {
if (glyphs.data[j] != aGlyphs[j].index)
return PR_FALSE;
}
return PR_TRUE;
}
nsCString fontName;
LiteralArray glyphs;
};
void SetRTL()
{
isRTL = PR_TRUE;
}
// empty/NULL fontName means ignore font name
void Expect (const char *platform,
const char *fontName,
const LiteralArray& glyphs)
{
if (fontName)
Expect (platform, nsDependentCString(fontName), glyphs);
else
Expect (platform, nsCString(), glyphs);
}
void Expect (const char *platform,
const nsCString& fontName,
const LiteralArray& glyphs)
{
#if defined(XP_WIN)
if (strcmp(platform, "win32"))
return;
#elif defined(XP_MACOSX)
if (strcmp(platform, "macosx"))
return;
#elif defined(XP_UNIX)
if (strcmp(platform, "gtk2-pango"))
return;
#else
return;
#endif
expectItems.AppendElement(ExpectItem(fontName, glyphs));
}
PRBool Check (gfxFontTestStore *store) {
if (expectItems.Length() == 0 ||
store->items.Length() != expectItems.Length())
{
return PR_FALSE;
}
for (PRUint32 i = 0; i < expectItems.Length(); i++) {
if (!expectItems[i].Compare(store->items[i].platformFont,
store->items[i].glyphs,
store->items[i].num_glyphs))
return PR_FALSE;
}
return PR_TRUE;
}
const char *utf8FamilyString;
gfxFontStyle fontStyle;
int stringType;
const char *string;
PRPackedBool isRTL;
nsTArray<ExpectItem> expectItems;
};
nsTArray<TestEntry> testList;
already_AddRefed<gfxContext>
MakeContext ()
{
const int size = 200;
nsRefPtr<gfxASurface> surface;
surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(size, size), gfxASurface::ImageFormatRGB24);
gfxContext *ctx = new gfxContext(surface);
NS_IF_ADDREF(ctx);
return ctx;
}
TestEntry*
AddTest (const char *utf8FamilyString,
const gfxFontStyle& fontStyle,
int stringType,
const char *string)
{
TestEntry te (utf8FamilyString,
fontStyle,
stringType,
string);
testList.AppendElement(te);
return &(testList[testList.Length()-1]);
}
void SetupTests();
void
DumpStore (gfxFontTestStore *store) {
if (store->items.Length() == 0) {
printf ("(empty)\n");
}
for (PRUint32 i = 0;
i < store->items.Length();
i++)
{
printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(store->items[i].platformFont).get());
for (int j = 0; j < store->items[i].num_glyphs; j++)
printf ("%d ", int(store->items[i].glyphs[j].index));
printf ("\n");
}
}
void
DumpTestExpect (TestEntry *test) {
for (PRUint32 i = 0; i < test->expectItems.Length(); i++) {
printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(test->expectItems[i].fontName).get());
for (PRUint32 j = 0; j < test->expectItems[i].glyphs.data.Length(); j++)
printf ("%d ", int(test->expectItems[i].glyphs.data[j]));
printf ("\n");
}
}
PRBool
RunTest (TestEntry *test, gfxContext *ctx) {
nsRefPtr<gfxFontGroup> fontGroup;
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle, nsnull);
nsAutoPtr<gfxTextRun> textRun;
gfxTextRunFactory::Parameters params = {
ctx, nsnull, nsnull, nsnull, 0, 60
};
PRUint32 flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
if (test->isRTL) {
flags |= gfxTextRunFactory::TEXT_IS_RTL;
}
PRUint32 length;
if (test->stringType == S_ASCII) {
flags |= gfxTextRunFactory::TEXT_IS_ASCII | gfxTextRunFactory::TEXT_IS_8BIT;
length = strlen(test->string);
textRun = gfxTextRunWordCache::MakeTextRun(reinterpret_cast<const PRUint8*>(test->string), length, fontGroup, &params, flags);
} else {
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->string));
length = str.Length();
textRun = gfxTextRunWordCache::MakeTextRun(str.get(), length, fontGroup, &params, flags);
}
gfxFontTestStore::NewStore();
textRun->Draw(ctx, gfxPoint(0,0), 0, length, nsnull, nsnull, nsnull);
gfxFontTestStore *s = gfxFontTestStore::CurrentStore();
gTextRunCache->RemoveTextRun(textRun);
if (!test->Check(s)) {
DumpStore(s);
printf (" expected:\n");
DumpTestExpect(test);
return PR_FALSE;
}
return PR_TRUE;
}
int
main (int argc, char **argv) {
int passed = 0;
int failed = 0;
#ifdef MOZ_WIDGET_GTK2
gtk_init(&argc, &argv);
#endif
#ifdef XP_MACOSX
CocoaPoolInit();
#endif
// Initialize XPCOM
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
if (NS_FAILED(rv))
return -1;
rv = gfxPlatform::Init();
if (NS_FAILED(rv))
return -1;
gTextRunCache = new gfxTextRunWordCache();
// let's get all the xpcom goop out of the system
fflush (stderr);
fflush (stdout);
// don't need to query, we might need to set up some prefs later
if (0) {
nsresult rv;
nsCOMPtr<nsIPrefService> prefsvc = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefsvc) {
printf ("Pref svc get failed!\n");
}
nsCOMPtr<nsIPrefBranch> branch;
rv = prefsvc->GetBranch(nsnull, getter_AddRefs(branch));
if (NS_FAILED(rv))
printf ("Failed 0x%08x\n", rv);
nsXPIDLCString str;
rv = branch->GetCharPref("font.name.sans-serif.x-western", getter_Copies(str));
if (NS_FAILED(rv))
printf ("Failed[2] 0x%08x\n", rv);
printf ("sans-serif.x-western: %s\n", nsPromiseFlatCString(str).get());
}
// set up the tests
SetupTests();
nsRefPtr<gfxContext> context = MakeContext();
for (uint test = 0;
test < testList.Length();
test++)
{
printf ("==== Test %d\n", test);
PRBool result = RunTest (&testList[test], context);
if (result) {
printf ("Test %d succeeded\n", test);
passed++;
} else {
printf ("Test %d failed\n", test);
failed++;
}
}
printf ("PASSED: %d FAILED: %d\n", passed, failed);
fflush (stderr);
fflush (stdout);
}
// The tests themselves
#include "gfxFontSelectionTests.h"