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

Side by Side 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: w/test fixture 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 unified diff | Download patch
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/fonts/shaping/HarfBuzzShaper.h"
7
8 #include "platform/fonts/Font.h"
9 #include "platform/fonts/FontCache.h"
10 #include "platform/fonts/GlyphPage.h"
11 #include "platform/text/TextRun.h"
12 #include "wtf/Vector.h"
13 #include <gtest/gtest.h>
14 #include <unicode/uscript.h>
15
16 namespace {
17
18 using namespace blink;
19 using namespace WTF;
20
21 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built
22 // without hb-icu. See http://crbug.com/356929
23 static inline hb_script_t ICUScriptToHBScript(UScriptCode script)
24 {
25 if (UNLIKELY(script == USCRIPT_INVALID_CODE))
26 return HB_SCRIPT_INVALID;
27
28 return hb_script_from_string(uscript_getShortName(script), -1);
29 }
30
31 class HarfBuzzShaperTest : public ::testing::Test {
32 protected:
33 virtual void SetUp()
34 {
35 fontDescription.setComputedSize(12.0);
36 font = new Font(fontDescription);
37 font->update(nullptr);
38 }
39
40 virtual void TearDown()
41 {
42 delete font;
43 }
44
45 FontCachePurgePreventer fontCachePurgePreventer;
46 FontDescription fontDescription;
47 Font* font;
48 unsigned startIndex = 0;
49 unsigned numGlyphs = 0;
50 hb_script_t script = HB_SCRIPT_INVALID;
51 };
52
53
54 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin)
55 {
56 TextRun latinCommon("ABC DEF.", 8);
57 HarfBuzzShaper shaper(font, latinCommon);
58 shaper.shape();
59
60 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
61 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
62 ASSERT_EQ(startIndex, 0u);
63 ASSERT_EQ(numGlyphs, 8u);
64 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
65 }
66
67 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon)
68 {
69 TextRun leadingCommon("... test", 8);
70 HarfBuzzShaper shaper(font, leadingCommon);
71 shaper.shape();
72
73 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
74 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
75 ASSERT_EQ(startIndex, 0u);
76 ASSERT_EQ(numGlyphs, 8u);
77 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
78 }
79
80 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon)
81 {
82 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 };
83 TextRun devanagariCommonLatin(devanagariCommonString, 6);
84 HarfBuzzShaper shaper(font, devanagariCommonLatin);
85 shaper.shape();
86
87 ASSERT_EQ(shaper.numberOfRunsForTesting(), 2u);
88 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
89 ASSERT_EQ(startIndex, 0u);
90 ASSERT_EQ(numGlyphs, 1u);
91 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
92
93 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
94 ASSERT_EQ(startIndex, 3u);
95 ASSERT_EQ(numGlyphs, 3u);
96 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
97 }
98
99 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon)
100 {
101 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E };
102 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7);
103 HarfBuzzShaper shaper(font, devanagariCommonLatin);
104 shaper.shape();
105
106 ASSERT_EQ(shaper.numberOfRunsForTesting(), 3u);
107 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
108 ASSERT_EQ(startIndex, 0u);
109 ASSERT_EQ(numGlyphs, 1u);
110 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
111
112 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
113 ASSERT_EQ(startIndex, 3u);
114 ASSERT_EQ(numGlyphs, 1u);
115 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
116
117 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
118 ASSERT_EQ(startIndex, 4u);
119 ASSERT_EQ(numGlyphs, 3u);
120 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
121 }
122
123 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin)
124 {
125 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 };
126 TextRun mixed(mixedString, 6);
127 HarfBuzzShaper shaper(font, mixed);
128 shaper.shape();
129
130 ASSERT_EQ(shaper.numberOfRunsForTesting(), 4u);
131 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
132 ASSERT_EQ(startIndex, 0u);
133 ASSERT_EQ(numGlyphs, 3u);
134 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
135
136 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
137 ASSERT_EQ(startIndex, 3u);
138 ASSERT_EQ(numGlyphs, 1u);
139 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_THAI));
140
141 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
142 ASSERT_EQ(startIndex, 4u);
143 ASSERT_EQ(numGlyphs, 1u);
144 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_HAN));
145
146 ASSERT_EQ(shaper.runInfoForTesting(3, startIndex, numGlyphs, script), true);
147 ASSERT_EQ(startIndex, 5u);
148 ASSERT_EQ(numGlyphs, 1u);
149 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
150 }
151
152 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic)
153 {
154 UChar arabicString[] = { 0x628, 0x64A, 0x629 };
155 TextRun arabic(arabicString, 3);
156 HarfBuzzShaper shaper(font, arabic);
157 shaper.shape();
158
159 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
160 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
161 ASSERT_EQ(startIndex, 0u);
162 ASSERT_EQ(numGlyphs, 3u);
163 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
164 }
165
166 }
OLDNEW
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698