Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2884)

Unified Diff: Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp

Issue 1088093005: Unit tests for HarfBuzzShaper (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp
diff --git a/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp b/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d0b92cbeb998fa52d0589a478cd29433936f018d
--- /dev/null
+++ b/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp
@@ -0,0 +1,221 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "platform/fonts/shaping/HarfBuzzShaper.h"
+
+#include "platform/fonts/Font.h"
+#include "platform/fonts/FontCache.h"
+#include "platform/fonts/GlyphPage.h"
+#include "platform/text/TextRun.h"
+#include "wtf/Vector.h"
+#include <gtest/gtest.h>
+#include <unicode/uscript.h>
+
+namespace {
+
+using namespace blink;
+using namespace WTF;
+
+struct TestRun {
+ unsigned start;
+ unsigned end;
+ UScriptCode script;
+};
+
+// A port of hb_icu_script_to_script because harfbuzz on CrOS is built
+// without hb-icu. See http://crbug.com/356929
+static inline hb_script_t ICUScriptToHBScript(UScriptCode script)
+{
+ if (UNLIKELY(script == USCRIPT_INVALID_CODE))
+ return HB_SCRIPT_INVALID;
+
+ return hb_script_from_string(uscript_getShortName(script), -1);
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsLatin)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
Dominik Röttsches 2015/04/22 14:17:51 These setup lines seem to be identical in all test
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ TextRun latinCommon("ABC DEF.", 8);
+ HarfBuzzShaper shaper(font, latinCommon);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 8u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
+
+ delete font;
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsLeadingCommon)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ TextRun leadingCommon("... test", 8);
+ HarfBuzzShaper shaper(font, leadingCommon);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 8u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
+
+ delete font;
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsDevanagariCommon)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 };
+ TextRun devanagariCommonLatin(devanagariCommonString, 6);
+ HarfBuzzShaper shaper(font, devanagariCommonLatin);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 2u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
+
+ ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 3u);
+ ASSERT_EQ(numGlyphs, 3u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
+
+ delete font;
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsDevanagariCommonLatinCommon)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x62, 0x2E };
+ TextRun devanagariCommonLatin(devanagariCommonLatinString, 7);
+ HarfBuzzShaper shaper(font, devanagariCommonLatin);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 3u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
+
+ ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 3u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
+
+ ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 4u);
+ ASSERT_EQ(numGlyphs, 3u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
+
+ delete font;
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsArabicThaiHanLatin)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 };
+ TextRun mixed(mixedString, 6);
+ HarfBuzzShaper shaper(font, mixed);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 4u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 3u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
+
+ ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 3u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_THAI));
+
+ ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 4u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_HAN));
+
+ ASSERT_EQ(shaper.runInfoForTesting(3, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 5u);
+ ASSERT_EQ(numGlyphs, 1u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
+
+ delete font;
+}
+
+TEST(HarfBuzzShaper, ResolveCandidateRunsArabic)
+{
+ FontCachePurgePreventer fontCachePurgePreventer;
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font* font = new Font(fontDescription);
+ font->update(nullptr);
+
+ unsigned startIndex = 0;
+ unsigned numGlyphs = 0;
+ hb_script_t script = HB_SCRIPT_INVALID;
+
+ UChar arabicString[] = { 0x628, 0x64A, 0x629 };
+ TextRun arabic(arabicString, 3);
+ HarfBuzzShaper shaper(font, arabic);
+ shaper.shape();
+
+ ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
+ ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
+ ASSERT_EQ(startIndex, 0u);
+ ASSERT_EQ(numGlyphs, 3u);
+ ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
+
+ delete font;
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698