add unittest for FontHost (just tables at the moment)
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 23 Feb 2012 14:51:10 +0000 (14:51 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 23 Feb 2012 14:51:10 +0000 (14:51 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@3233 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/ports.gyp
gyp/tests.gyp
tests/FontHostTest.cpp [new file with mode: 0644]

index c89a06d..148197d 100644 (file)
@@ -53,6 +53,9 @@
 #            '../src/ports/SkFontHost_gamma_none.cpp',
             '../src/ports/SkThread_pthread.cpp',
           ],
+          'sources!': [
+            '../src/ports/SkFontHost_tables.cpp',
+          ],
         }],
         [ 'skia_os == "ios"', {
           'include_dirs': [
index 63ff7c9..1a8f0cd 100644 (file)
@@ -34,6 +34,7 @@
         '../tests/EmptyPathTest.cpp',
         '../tests/FillPathTest.cpp',
         '../tests/FlateTest.cpp',
+        '../tests/FontHostTest.cpp',
         '../tests/GeometryTest.cpp',
         '../tests/GLInterfaceValidation.cpp',
         '../tests/GLProgramsTest.cpp',
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
new file mode 100644 (file)
index 0000000..5c94b3c
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkTypeface.h"
+#include "SkFontHost.h"
+
+//#define DUMP_TABLES
+
+#define kFontTableTag_head          SkSetFourByteTag('h', 'e', 'a', 'd')
+#define kFontTableTag_hhea          SkSetFourByteTag('h', 'h', 'e', 'a')
+#define kFontTableTag_os_slash_2    SkSetFourByteTag('O', 'S', '/', '2')
+#define kFontTableTag_maxp          SkSetFourByteTag('m', 'a', 'x', 'p')
+
+static const struct TagSize {
+    SkFontTableTag  fTag;
+    size_t          fSize;
+} gKnownTableSizes[] = {
+    {   kFontTableTag_head,         54 },
+    {   kFontTableTag_hhea,         36 },
+    {   kFontTableTag_os_slash_2,   96 },
+    {   kFontTableTag_maxp,         32 },
+};
+
+static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
+    SkFontID fontID = face->uniqueID();
+
+    int count = SkFontHost::CountTables(fontID);
+    REPORTER_ASSERT(reporter, count > 0);
+
+    SkAutoTMalloc<SkFontTableTag> storage(count);
+    SkFontTableTag* tags = storage.get();
+    SkFontHost::GetTableTags(fontID, tags);
+
+    for (int i = 0; i < count; ++i) {
+        size_t size = SkFontHost::GetTableSize(fontID, tags[i]);
+        REPORTER_ASSERT(reporter, size > 0);
+
+#ifdef DUMP_TABLES
+        char name[5];
+        name[0] = (tags[i] >> 24) & 0xFF;
+        name[1] = (tags[i] >> 16) & 0xFF;
+        name[2] = (tags[i] >>  8) & 0xFF;
+        name[3] = (tags[i] >>  0) & 0xFF;
+        name[4] = 0;
+        SkDebugf("%s %d\n", name, size);
+#endif
+
+        for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) {
+            if (gKnownTableSizes[j].fTag == tags[i]) {
+                REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size);
+            }
+        }
+    }
+}
+
+static void test_tables(skiatest::Reporter* reporter) {
+    static const char* const gNames[] = {
+        NULL,   // default font
+        "Arial", "Times", "Times New Roman", "Helvetica", "Courier",
+        "Courier New",
+    };
+
+    for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
+        SkTypeface* face = SkTypeface::CreateFromName(gNames[i],
+                                                      SkTypeface::kNormal);
+        if (face) {
+#ifdef DUMP_TABLES
+            SkDebugf("%s\n", gNames[i]);
+#endif
+            test_tables(reporter, face);
+            face->unref();
+        }
+    }
+}
+
+static void TestFontHost(skiatest::Reporter* reporter) {
+    test_tables(reporter);
+}
+
+// need tests for SkStrSearch
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost)