diff options
author | Seigo Nonaka <nona@google.com> | 2018-02-20 11:39:45 -0800 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2018-02-20 11:41:08 -0800 |
commit | 54e248ac7fa00d430092a8e993c83fccd4f72df5 (patch) | |
tree | 87d5efa550828725afa85db9f6e901835ff5239b | |
parent | 055beb393788376b6a96f7456054ef10a867cfff (diff) | |
download | minikin-54e248ac7fa00d430092a8e993c83fccd4f72df5.tar.gz |
Remove kTestFontDir and remove /system/fonts dependency from unit tests
Bug: N/A
Test: minikin_tests
Test: minikin_stress_tests
Change-Id: I01c8b885ce196f2f628d347c187691805a4d9c71
-rw-r--r-- | tests/perftests/FontCollection.cpp | 8 | ||||
-rw-r--r-- | tests/stresstest/FontFamilyTest.cpp | 6 | ||||
-rw-r--r-- | tests/stresstest/MultithreadTest.cpp | 2 | ||||
-rw-r--r-- | tests/unittest/Android.bp | 9 | ||||
-rw-r--r-- | tests/unittest/FontCollectionItemizeTest.cpp | 329 | ||||
-rw-r--r-- | tests/unittest/FontCollectionTest.cpp | 14 | ||||
-rw-r--r-- | tests/unittest/FontFamilyTest.cpp | 24 | ||||
-rw-r--r-- | tests/unittest/LayoutTest.cpp | 4 | ||||
-rw-r--r-- | tests/unittest/MeasuredTextTest.cpp | 4 | ||||
-rw-r--r-- | tests/util/FontTestUtils.cpp | 11 | ||||
-rw-r--r-- | tests/util/FontTestUtils.h | 13 | ||||
-rw-r--r-- | tests/util/FreeTypeMinikinFontForTest.cpp | 2 | ||||
-rw-r--r-- | tests/util/PathUtils.cpp | 18 | ||||
-rw-r--r-- | tests/util/PathUtils.h | 10 |
14 files changed, 238 insertions, 216 deletions
diff --git a/tests/perftests/FontCollection.cpp b/tests/perftests/FontCollection.cpp index 7d7af6d..819f125 100644 --- a/tests/perftests/FontCollection.cpp +++ b/tests/perftests/FontCollection.cpp @@ -42,8 +42,8 @@ static void BM_FontCollection_construct(benchmark::State& state) { BENCHMARK(BM_FontCollection_construct); static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { - std::shared_ptr<FontCollection> collection( - getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); + auto collection = + std::make_shared<FontCollection>(getFontFamilies(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); uint32_t baseCp = state.range(0); uint32_t vsCp = state.range(1); @@ -79,8 +79,8 @@ struct ItemizeTestCases { }; static void BM_FontCollection_itemize(benchmark::State& state) { - std::shared_ptr<FontCollection> collection( - getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); + auto collection = + std::make_shared<FontCollection>(getFontFamilies(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); size_t testIndex = state.range(0); state.SetLabel("Itemize: " + ITEMIZE_TEST_CASES[testIndex].labelText); diff --git a/tests/stresstest/FontFamilyTest.cpp b/tests/stresstest/FontFamilyTest.cpp index 77371cb..7554314 100644 --- a/tests/stresstest/FontFamilyTest.cpp +++ b/tests/stresstest/FontFamilyTest.cpp @@ -22,6 +22,7 @@ #include "minikin/FontCollection.h" #include "FontTestUtils.h" +#include "FreeTypeMinikinFontForTest.h" #include "MinikinInternal.h" namespace minikin { @@ -34,7 +35,10 @@ TEST_P(FontFamilyHarfBuzzCompatibilityTest, CoverageTest) { const std::string& fontPath = GetParam().first; int ttcIndex = GetParam().second; - std::shared_ptr<FontFamily> family = buildFontFamily(fontPath); + auto font = std::make_shared<FreeTypeMinikinFontForTest>(fontPath); + std::vector<Font> fonts; + fonts.push_back(Font::Builder(font).build()); + std::shared_ptr<FontFamily> family = std::make_shared<FontFamily>(std::move(fonts)); hb_font_t* hbFont = family->getFont(0)->baseFont().get(); diff --git a/tests/stresstest/MultithreadTest.cpp b/tests/stresstest/MultithreadTest.cpp index aa179e8..a1a2f12 100644 --- a/tests/stresstest/MultithreadTest.cpp +++ b/tests/stresstest/MultithreadTest.cpp @@ -67,7 +67,7 @@ static void thread_main(int tid) { std::mt19937 mt(tid); for (int i = 0; i < COLLECTION_COUNT_PER_THREAD; ++i) { - MinikinPaint paint(buildFontCollection(getTestFontPath("Ascii.ttf"))); + MinikinPaint paint(buildFontCollection("Ascii.ttf")); paint.size = 10.0f; // Make 1em = 10px for (int j = 0; j < LAYOUT_COUNT_PER_COLLECTION; ++j) { diff --git a/tests/unittest/Android.bp b/tests/unittest/Android.bp index 9ded52e..7475b94 100644 --- a/tests/unittest/Android.bp +++ b/tests/unittest/Android.bp @@ -67,13 +67,4 @@ cc_test { "-Wall", "-Wextra", ], - - multilib: { - lib32: { - cppflags: ["-DkTestFontDir=\"/data/nativetest/minikin_tests/data/\""], - }, - lib64: { - cppflags: ["-DkTestFontDir=\"/data/nativetest64/minikin_tests/data/\""], - }, - }, } diff --git a/tests/unittest/FontCollectionItemizeTest.cpp b/tests/unittest/FontCollectionItemizeTest.cpp index d1ff460..e8a3a3e 100644 --- a/tests/unittest/FontCollectionItemizeTest.cpp +++ b/tests/unittest/FontCollectionItemizeTest.cpp @@ -32,26 +32,26 @@ namespace minikin { -const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; -const char kCherokeeFont[] = kTestFontDir "Cherokee.ttf"; -const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; -const char kJAFont[] = kTestFontDir "Ja.ttf"; -const char kKOFont[] = kTestFontDir "Ko.ttf"; -const char kLatinBoldFont[] = kTestFontDir "Bold.ttf"; -const char kLatinBoldItalicFont[] = kTestFontDir "BoldItalic.ttf"; -const char kLatinFont[] = kTestFontDir "Regular.ttf"; -const char kLatinItalicFont[] = kTestFontDir "Italic.ttf"; -const char kZH_HansFont[] = kTestFontDir "ZhHans.ttf"; -const char kZH_HantFont[] = kTestFontDir "ZhHant.ttf"; - -const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; -const char kNoGlyphFont[] = kTestFontDir "NoGlyphFont.ttf"; -const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; -const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; -const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; - -const char kHasCmapFormat14Font[] = kTestFontDir "NoCmapFormat14.ttf"; -const char kNoCmapFormat14Font[] = kTestFontDir "VariationSelectorTest-Regular.ttf"; +const char kItemizeFontXml[] = "itemize.xml"; +const char kCherokeeFont[] = "Cherokee.ttf"; +const char kEmojiFont[] = "Emoji.ttf"; +const char kJAFont[] = "Ja.ttf"; +const char kKOFont[] = "Ko.ttf"; +const char kLatinBoldFont[] = "Bold.ttf"; +const char kLatinBoldItalicFont[] = "BoldItalic.ttf"; +const char kLatinFont[] = "Regular.ttf"; +const char kLatinItalicFont[] = "Italic.ttf"; +const char kZH_HansFont[] = "ZhHans.ttf"; +const char kZH_HantFont[] = "ZhHant.ttf"; + +const char kEmojiXmlFile[] = "emoji.xml"; +const char kNoGlyphFont[] = "NoGlyphFont.ttf"; +const char kColorEmojiFont[] = "ColorEmojiFont.ttf"; +const char kTextEmojiFont[] = "TextEmojiFont.ttf"; +const char kMixedEmojiFont[] = "ColorTextMixedEmojiFont.ttf"; + +const char kHasCmapFormat14Font[] = "NoCmapFormat14.ttf"; +const char kNoCmapFormat14Font[] = "VariationSelectorTest-Regular.ttf"; // Utility functions for calling itemize function. void itemize(const std::shared_ptr<FontCollection>& collection, const char* str, FontStyle style, @@ -88,9 +88,10 @@ void itemize(const std::shared_ptr<FontCollection>& collection, const char* str, } // Utility function to obtain font path associated with run. -const std::string& getFontPath(const FontCollection::Run& run) { +std::string getFontName(const FontCollection::Run& run) { EXPECT_NE(nullptr, run.fakedFont.font); - return ((FreeTypeMinikinFontForTest*)run.fakedFont.font->typeface().get())->fontPath(); + return getBasename( + ((FreeTypeMinikinFontForTest*)run.fakedFont.font->typeface().get())->fontPath()); } // Utility function to obtain LocaleList from string. @@ -99,7 +100,7 @@ const LocaleList& registerAndGetLocaleList(const std::string& locale_string) { } TEST(FontCollectionItemizeTest, itemize_latin) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; const FontStyle kRegularStyle = FontStyle(); @@ -111,7 +112,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -119,7 +120,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinItalicFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinItalicFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -127,7 +128,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinBoldFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinBoldFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -135,7 +136,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinBoldItalicFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinBoldItalicFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -145,7 +146,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -153,7 +154,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -163,7 +164,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } @@ -171,74 +172,74 @@ TEST(FontCollectionItemizeTest, itemize_latin) { TEST(FontCollectionItemizeTest, itemize_newline) { // The regular font does not support \n in its cmap table, but the Arabic font does. // It should not matter, and \n should be ignored. - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; itemize(collection, "'a' U+000A", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+000A", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_combining) { // The regular font and the Cherokee font both support U+0301 (COMBINING ACUTE ACCENT). Since // it's a combining mark, it should come from whatever font the base character comes from. - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; itemize(collection, "'a' U+0301", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); // CHEROKEE LETTER A, COMBINING ACUTE ACCENT itemize(collection, "U+13A0 U+0301", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kCherokeeFont, getFontPath(runs[0])); + EXPECT_EQ(kCherokeeFont, getFontName(runs[0])); // CHEROKEE LETTER A, COMBINING ACUTE ACCENT, COMBINING ACUTE ACCENT itemize(collection, "U+13A0 U+0301 U+0301", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kCherokeeFont, getFontPath(runs[0])); + EXPECT_EQ(kCherokeeFont, getFontName(runs[0])); itemize(collection, "U+0301", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); // COMBINING ACUTE ACCENT, CHEROKEE LETTER A, COMBINING ACUTE ACCENT itemize(collection, "U+0301 U+13A0 U+0301", &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(3, runs[1].end); - EXPECT_EQ(kCherokeeFont, getFontPath(runs[1])); + EXPECT_EQ(kCherokeeFont, getFontName(runs[1])); } TEST(FontCollectionItemizeTest, itemize_emoji) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; itemize(collection, "U+1F469 U+1F467", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -248,7 +249,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -256,7 +257,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -264,13 +265,13 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(5, runs[1].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[1])); + EXPECT_EQ(kEmojiFont, getFontName(runs[1])); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); @@ -280,19 +281,19 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(2, runs[1].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[1])); + EXPECT_EQ(kEmojiFont, getFontName(runs[1])); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); } TEST(FontCollectionItemizeTest, itemize_non_latin) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; // All Japanese Hiragana characters. @@ -300,7 +301,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -309,7 +310,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kKOFont, getFontPath(runs[0])); + EXPECT_EQ(kKOFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -319,7 +320,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -329,7 +330,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -339,19 +340,19 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(2, runs[1].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[1])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[1])); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(2, runs[2].start); EXPECT_EQ(3, runs[2].end); - EXPECT_EQ(kJAFont, getFontPath(runs[2])); + EXPECT_EQ(kJAFont, getFontName(runs[2])); EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeItalic()); @@ -360,7 +361,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -371,50 +372,50 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } TEST(FontCollectionItemizeTest, itemize_mixed) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; itemize(collection, "'a' U+4F60 'b' U+4F60 'c'", "en-US", &runs); ASSERT_EQ(5U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(2, runs[1].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[1])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[1])); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(2, runs[2].start); EXPECT_EQ(3, runs[2].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[2])); + EXPECT_EQ(kLatinFont, getFontName(runs[2])); EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(3, runs[3].start); EXPECT_EQ(4, runs[3].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[3])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[3])); EXPECT_FALSE(runs[3].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[3].fakedFont.fakery.isFakeItalic()); EXPECT_EQ(4, runs[4].start); EXPECT_EQ(5, runs[4].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[4])); + EXPECT_EQ(kLatinFont, getFontName(runs[4])); EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); } TEST(FontCollectionItemizeTest, itemize_variationSelector) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; // A glyph for U+4FAE is provided by both Japanese font and Simplified @@ -428,48 +429,48 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); itemize(collection, "U+4FAE U+FE00", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+4FAE U+4FAE U+FE00", "zh-Hans", &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(3, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); itemize(collection, "U+4FAE U+4FAE U+FE00 U+4FAE", "zh-Hans", &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(3, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); EXPECT_EQ(3, runs[2].start); EXPECT_EQ(4, runs[2].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[2])); // Validation selector after validation selector. itemize(collection, "U+4FAE U+FE00 U+FE00", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); // No font supports U+242EE U+FE0E. itemize(collection, "U+4FAE U+FE0E", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); // Surrogate pairs handling. // U+242EE is available in ja font and zh_Hant font. @@ -478,61 +479,61 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); itemize(collection, "U+242EE U+FE00", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+242EE U+242EE U+FE00", "zh-Hant", &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(5, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); itemize(collection, "U+242EE U+242EE U+FE00 U+242EE", "zh-Hant", &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(5, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); EXPECT_EQ(5, runs[2].start); EXPECT_EQ(7, runs[2].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[2])); // Validation selector after validation selector. itemize(collection, "U+242EE U+FE00 U+FE00", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); // No font supports U+242EE U+FE0E itemize(collection, "U+242EE U+FE0E", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); // Isolated variation selector supplement. itemize(collection, "U+FE00", "", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontName(runs[0])); itemize(collection, "U+FE00", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontName(runs[0])); // First font family (Regular.ttf) supports U+203C but doesn't support U+203C U+FE0F. // Emoji.ttf font supports U+203C U+FE0F. Emoji.ttf should be selected. @@ -540,18 +541,18 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); // First font family (Regular.ttf) supports U+203C U+FE0E. itemize(collection, "U+203C U+FE0E", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; // A glyph for U+845B is provided by both Japanese font and Simplified @@ -565,48 +566,48 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); itemize(collection, "U+845B U+E0100", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+845B U+845B U+E0100", "zh-Hans", &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(4, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); itemize(collection, "U+845B U+845B U+E0100 U+845B", "zh-Hans", &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); EXPECT_EQ(1, runs[1].start); EXPECT_EQ(4, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); EXPECT_EQ(4, runs[2].start); EXPECT_EQ(5, runs[2].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[2])); // Validation selector after validation selector. itemize(collection, "U+845B U+E0100 U+E0100", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); // No font supports U+845B U+E01E0. itemize(collection, "U+845B U+E01E0", "zh-Hans", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HansFont, getFontName(runs[0])); // Isolated variation selector supplement // Surrogate pairs handling. @@ -616,65 +617,65 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); itemize(collection, "U+242EE U+E0101", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+242EE U+242EE U+E0101", "zh-Hant", &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(6, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); itemize(collection, "U+242EE U+242EE U+E0101 U+242EE", "zh-Hant", &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(6, runs[1].end); - EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(kJAFont, getFontName(runs[1])); EXPECT_EQ(6, runs[2].start); EXPECT_EQ(8, runs[2].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[2])); // Validation selector after validation selector. itemize(collection, "U+242EE U+E0100 U+E0100", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(6, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); // No font supports U+242EE U+E01E0. itemize(collection, "U+242EE U+E01E0", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kZH_HantFont, getFontName(runs[0])); // Isolated variation selector supplement. itemize(collection, "U+E0100", "", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontName(runs[0])); itemize(collection, "U+E0100", "zh-Hant", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_no_crash) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; // Broken Surrogate pairs. Check only not crashing. @@ -698,7 +699,7 @@ TEST(FontCollectionItemizeTest, itemize_no_crash) { } TEST(FontCollectionItemizeTest, itemize_fakery) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; FontStyle kBoldStyle(FontStyle::Weight::BOLD); @@ -713,7 +714,7 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -722,7 +723,7 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -731,7 +732,7 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } @@ -740,7 +741,7 @@ TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code // point. - const std::string kVSTestFont = kTestFontDir "VariationSelectorTest-Regular.ttf"; + const std::string kVSTestFont = "VariationSelectorTest-Regular.ttf"; std::vector<std::shared_ptr<FontFamily>> families; families.push_back(buildFontFamily(kLatinFont)); @@ -754,72 +755,72 @@ TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kVSTestFont, getFontPath(runs[0])); + EXPECT_EQ(kVSTestFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_format_chars) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); std::vector<FontCollection::Run> runs; itemize(collection, "'a' U+061C 'b'", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "'a' U+200D 'b'", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+3042 U+061C U+3042", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+061C 'b'", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+061C U+3042", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontName(runs[0])); itemize(collection, "U+061C", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+061C U+061C U+061C", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+200D U+20E3", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); itemize(collection, "U+200D", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_EQ(kLatinFont, getFontName(runs[0])); itemize(collection, "U+20E3", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kEmojiFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_LocaleScore) { @@ -941,7 +942,8 @@ TEST(FontCollectionItemizeTest, itemize_LocaleScore) { std::vector<std::shared_ptr<FontFamily>> families; // Prepare first font which doesn't supports U+9AA8 - auto firstFamilyMinikinFont = std::make_shared<FreeTypeMinikinFontForTest>(kNoGlyphFont); + auto firstFamilyMinikinFont = + std::make_shared<FreeTypeMinikinFontForTest>(getTestFontPath(kNoGlyphFont)); std::vector<Font> fonts; fonts.push_back(Font::Builder(firstFamilyMinikinFont).build()); auto firstFamily = std::make_shared<FontFamily>( @@ -954,7 +956,8 @@ TEST(FontCollectionItemizeTest, itemize_LocaleScore) { std::unordered_map<MinikinFont*, int> fontLocaleIdxMap; for (size_t i = 0; i < testCase.fontLocales.size(); ++i) { - auto minikinFont = std::make_shared<FreeTypeMinikinFontForTest>(kJAFont); + auto minikinFont = + std::make_shared<FreeTypeMinikinFontForTest>(getTestFontPath(kJAFont)); std::vector<Font> fonts; fonts.push_back(Font::Builder(minikinFont).build()); auto family = @@ -1276,7 +1279,7 @@ TEST(FontCollectionItemizeTest, itemize_LocaleAndCoverage) { {"U+1F469", "zh-Hant,ja-Jpan,zh-Hans", kEmojiFont}, }; - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + auto collection = buildFontCollectionFromXml(kItemizeFontXml); for (auto testCase : testCases) { SCOPED_TRACE("Test for \"" + testCase.testString + "\" with locales " + @@ -1285,12 +1288,12 @@ TEST(FontCollectionItemizeTest, itemize_LocaleAndCoverage) { std::vector<FontCollection::Run> runs; itemize(collection, testCase.testString.c_str(), testCase.requestedLocales, &runs); ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(testCase.expectedFont, getFontPath(runs[0])); + EXPECT_EQ(testCase.expectedFont, getFontName(runs[0])); } } TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); std::vector<FontCollection::Run> runs; // U+00A9 is a text default emoji which is only available in TextEmojiFont.ttf. @@ -1299,7 +1302,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+00A9 is a text default emoji which is only available in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. @@ -1308,7 +1311,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); // Text emoji is specified but it is not available. Use color emoji instead. - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected. @@ -1316,7 +1319,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+2049 is a text default emoji which is not available either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. @@ -1324,7 +1327,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojifFont. // TextEmojiFont.ttf sohuld be selected. @@ -1332,7 +1335,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. @@ -1341,7 +1344,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); // Text emoji is specified but it is not available. Use color emoji instead. - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected even if U+23E9 is emoji default @@ -1350,7 +1353,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+23EA is a emoji default emoji but which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. @@ -1358,7 +1361,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1366,11 +1369,11 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kMixedEmojiFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); std::vector<FontCollection::Run> runs; // U+00A9 is a text default emoji which is available only in TextEmojiFont.ttf. @@ -1380,7 +1383,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); // Color emoji is specified but it is not available. Use text representaion instead. - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+00AE is a text default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. @@ -1388,7 +1391,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected even if U+203C is a text default @@ -1397,7 +1400,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+2049 is a text default emoji which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. @@ -1405,7 +1408,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. // TextEmojiFont.ttf should be selected. @@ -1414,7 +1417,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); // Color emoji is specified but it is not available. Use text representation instead. - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. @@ -1422,7 +1425,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected. @@ -1430,7 +1433,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // U+23EA is a emoji default emoji which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. @@ -1438,7 +1441,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1446,11 +1449,11 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kMixedEmojiFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); std::vector<FontCollection::Run> runs; // TextEmoji font is selected since it is listed before ColorEmoji font. @@ -1458,21 +1461,21 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); // If skin tone is specified, it should be colored. itemize(collection, "U+261D U+1F3FD", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // Still color font is selected if an emoji variation selector is specified. itemize(collection, "U+261D U+FE0F U+1F3FD", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); // Text font should be selected if a text variation selector is specified and skin tone is // rendered by itself. @@ -1480,14 +1483,14 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kTextEmojiFont, getFontName(runs[0])); EXPECT_EQ(2, runs[1].start); EXPECT_EQ(4, runs[1].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[1])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[1])); } TEST(FontCollectionItemizeTest, itemize_PrivateUseArea) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); std::vector<FontCollection::Run> runs; // Should not set nullptr to the result run. (Issue 26808815) @@ -1495,36 +1498,36 @@ TEST(FontCollectionItemizeTest, itemize_PrivateUseArea) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); itemize(collection, "U+FEE40 U+FE4C5", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontName(runs[0])); } TEST(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); std::vector<FontCollection::Run> runs; itemize(collection, "U+1F469 U+200D U+1F373", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); itemize(collection, "U+1F469 U+200D U+2695 U+FE0F", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); itemize(collection, "U+1F469 U+200D U+2695", &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(kColorEmojiFont, getFontName(runs[0])); } // For b/29585939 diff --git a/tests/unittest/FontCollectionTest.cpp b/tests/unittest/FontCollectionTest.cpp index 121a655..6b39508 100644 --- a/tests/unittest/FontCollectionTest.cpp +++ b/tests/unittest/FontCollectionTest.cpp @@ -38,7 +38,7 @@ namespace minikin { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = kTestFontDir "/VariationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = "VariationSelectorTest-Regular.ttf"; void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set<uint32_t>& vsSet) { for (uint32_t vs = 0xFE00; vs <= 0xE01EF; ++vs) { @@ -57,7 +57,7 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set } TEST(FontCollectionTest, hasVariationSelectorTest) { - std::shared_ptr<FontCollection> fc = buildFontCollection(kVsTestFont); + auto fc = buildFontCollection(kVsTestFont); EXPECT_FALSE(fc->hasVariationSelector(0x82A6, 0)); expectVSGlyphs(fc.get(), 0x82A6, @@ -74,10 +74,10 @@ TEST(FontCollectionTest, hasVariationSelectorTest) { expectVSGlyphs(fc.get(), 0x717D, std::set<uint32_t>({0xFE02, 0xE0102, 0xE0103})); } -const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; +const char kEmojiXmlFile[] = "emoji.xml"; TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); // Both text/color font have cmap format 14 subtable entry for VS15/VS16 respectively. EXPECT_TRUE(collection->hasVariationSelector(0x2623, 0xFE0E)); @@ -109,7 +109,7 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { } TEST(FontCollectionTest, newEmojiTest) { - std::shared_ptr<FontCollection> collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + auto collection = buildFontCollectionFromXml(kEmojiXmlFile); // U+2695, U+2640, U+2642 are not in emoji catrgory in Unicode 9 but they are now in emoji // category. Should return true even if U+FE0E was appended. @@ -123,8 +123,8 @@ TEST(FontCollectionTest, newEmojiTest) { TEST(FontCollectionTest, createWithVariations) { // This font has 'wdth' and 'wght' axes. - const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; - const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + const char kMultiAxisFont[] = "MultiAxis.ttf"; + const char kNoAxisFont[] = "Regular.ttf"; std::shared_ptr<FontCollection> multiAxisFc = buildFontCollection(kMultiAxisFont); std::shared_ptr<FontCollection> noAxisFc = buildFontCollection(kNoAxisFont); diff --git a/tests/unittest/FontFamilyTest.cpp b/tests/unittest/FontFamilyTest.cpp index 7cdc6ad..d0febc9 100644 --- a/tests/unittest/FontFamilyTest.cpp +++ b/tests/unittest/FontFamilyTest.cpp @@ -472,12 +472,12 @@ TEST(LocaleListTest, registerLocaleListTest) { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = kTestFontDir "VariationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = "VariationSelectorTest-Regular.ttf"; class FontFamilyTest : public testing::Test { public: virtual void SetUp() override { - if (access(kVsTestFont, R_OK) != 0) { + if (access(getTestFontPath(kVsTestFont).c_str(), R_OK) != 0) { FAIL() << "Unable to read " << kVsTestFont << ". " << "Please prepare the test data directory. " << "For more details, please see how_to_run.txt."; @@ -540,9 +540,8 @@ TEST_F(FontFamilyTest, hasVSTableTest) { const std::string fontPath; bool hasVSTable; } testCases[] = { - {kTestFontDir "Ja.ttf", true}, {kTestFontDir "ZhHant.ttf", true}, - {kTestFontDir "ZhHans.ttf", true}, {kTestFontDir "Italic.ttf", false}, - {kTestFontDir "Bold.ttf", false}, {kTestFontDir "BoldItalic.ttf", false}, + {"Ja.ttf", true}, {"ZhHant.ttf", true}, {"ZhHans.ttf", true}, + {"Italic.ttf", false}, {"Bold.ttf", false}, {"BoldItalic.ttf", false}, }; for (auto testCase : testCases) { @@ -558,8 +557,8 @@ TEST_F(FontFamilyTest, hasVSTableTest) { TEST_F(FontFamilyTest, createFamilyWithVariationTest) { // This font has 'wdth' and 'wght' axes. - const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; - const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + const char kMultiAxisFont[] = "MultiAxis.ttf"; + const char kNoAxisFont[] = "Regular.ttf"; std::shared_ptr<FontFamily> multiAxisFamily = buildFontFamily(kMultiAxisFont); std::shared_ptr<FontFamily> noAxisFamily = buildFontFamily(kNoAxisFont); @@ -610,16 +609,16 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { TEST_F(FontFamilyTest, coverageTableSelectionTest) { // This font supports U+0061. The cmap subtable is format 4 and its platform ID is 0 and // encoding ID is 1. - const char kUnicodeEncoding1Font[] = kTestFontDir "UnicodeBMPOnly.ttf"; + const char kUnicodeEncoding1Font[] = "UnicodeBMPOnly.ttf"; // This font supports U+0061. The cmap subtable is format 4 and its platform ID is 0 and // encoding ID is 3. - const char kUnicodeEncoding3Font[] = kTestFontDir "UnicodeBMPOnly2.ttf"; + const char kUnicodeEncoding3Font[] = "UnicodeBMPOnly2.ttf"; // This font has both cmap format 4 subtable which platform ID is 0 and encoding ID is 1 // and cmap format 14 subtable which platform ID is 0 and encoding ID is 10. // U+0061 is listed in both subtable but U+1F926 is only listed in latter. - const char kUnicodeEncoding4Font[] = kTestFontDir "UnicodeUCS4.ttf"; + const char kUnicodeEncoding4Font[] = "UnicodeUCS4.ttf"; std::shared_ptr<FontFamily> unicodeEnc1Font = buildFontFamily(kUnicodeEncoding1Font); std::shared_ptr<FontFamily> unicodeEnc3Font = buildFontFamily(kUnicodeEncoding3Font); @@ -648,7 +647,7 @@ std::string fontStyleToString(const FontStyle& style) { } TEST_F(FontFamilyTest, closestMatch) { - constexpr char ROBOTO[] = "/system/fonts/Roboto-Regular.ttf"; + constexpr char kTestFont[] = "Ascii.ttf"; constexpr FontStyle::Weight THIN = FontStyle::Weight::THIN; constexpr FontStyle::Weight LIGHT = FontStyle::Weight::LIGHT; @@ -719,7 +718,8 @@ TEST_F(FontFamilyTest, closestMatch) { std::vector<std::shared_ptr<MinikinFont>> dummyFonts; std::vector<Font> fonts; for (auto familyStyle : testCase.familyStyles) { - std::shared_ptr<MinikinFont> dummyFont(new FreeTypeMinikinFontForTest(ROBOTO)); + std::shared_ptr<MinikinFont> dummyFont( + new FreeTypeMinikinFontForTest(getTestFontPath(kTestFont))); dummyFonts.push_back(dummyFont); fonts.push_back(Font::Builder(dummyFont).setStyle(familyStyle).build()); } diff --git a/tests/unittest/LayoutTest.cpp b/tests/unittest/LayoutTest.cpp index 81abb1e..a87374b 100644 --- a/tests/unittest/LayoutTest.cpp +++ b/tests/unittest/LayoutTest.cpp @@ -49,7 +49,7 @@ protected: virtual ~LayoutTest() {} - virtual void SetUp() override { mCollection = buildFontCollection(kTestFontDir "Ascii.ttf"); } + virtual void SetUp() override { mCollection = buildFontCollection("Ascii.ttf"); } virtual void TearDown() override {} @@ -492,7 +492,7 @@ TEST_F(LayoutTest, measuredTextTest) { // U+005F (_): 0em // U+FFFD (invalid surrogate will be replaced to this): 7em // U+10331 (\uD800\uDF31): 10em - auto fc = buildFontCollection(kTestFontDir "/LayoutTestFont.ttf"); + auto fc = buildFontCollection("LayoutTestFont.ttf"); { MinikinPaint paint(fc); std::vector<uint16_t> text = utf8ToUtf16("I"); diff --git a/tests/unittest/MeasuredTextTest.cpp b/tests/unittest/MeasuredTextTest.cpp index c925a82..2cda52a 100644 --- a/tests/unittest/MeasuredTextTest.cpp +++ b/tests/unittest/MeasuredTextTest.cpp @@ -30,7 +30,7 @@ constexpr float CHAR_WIDTH = 10.0; // Mock implementation always returns 10.0 f TEST(MeasuredTextTest, RunTests) { constexpr uint32_t CHAR_COUNT = 6; constexpr float REPLACEMENT_WIDTH = 20.0f; - auto font = buildFontCollection(kTestFontDir "Ascii.ttf"); + auto font = buildFontCollection("Ascii.ttf"); MeasuredTextBuilder builder; @@ -59,7 +59,7 @@ TEST(MeasuredTextTest, RunTests) { TEST(MeasuredTextTest, buildLayoutTest) { std::vector<uint16_t> text = utf8ToUtf16("Hello, world."); Range range(0, text.size()); - auto font = buildFontCollection(kTestFontDir "Ascii.ttf"); + auto font = buildFontCollection("Ascii.ttf"); MinikinPaint paint(font); Bidi bidi = Bidi::FORCE_LTR; diff --git a/tests/util/FontTestUtils.cpp b/tests/util/FontTestUtils.cpp index 699d53b..a7cab75 100644 --- a/tests/util/FontTestUtils.cpp +++ b/tests/util/FontTestUtils.cpp @@ -45,8 +45,9 @@ std::string xmlTrim(const std::string& in) { } // namespace -std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const char* fontDir, const char* fontXml) { - xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); +std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const std::string& fontDir, + const std::string& xmlPath) { + xmlDoc* doc = xmlReadFile(xmlPath.c_str(), NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); std::vector<std::shared_ptr<FontFamily>> families; @@ -115,16 +116,12 @@ std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const char* fontDir, co return families; } -std::shared_ptr<FontCollection> getFontCollection(const char* fontDir, const char* fontXml) { - return std::make_shared<FontCollection>(getFontFamilies(fontDir, fontXml)); -} - std::shared_ptr<FontCollection> buildFontCollection(const std::string& filePath) { return std::make_shared<FontCollection>(buildFontFamily(filePath)); } std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath) { - auto font = std::make_shared<FreeTypeMinikinFontForTest>(filePath); + auto font = std::make_shared<FreeTypeMinikinFontForTest>(getTestFontPath(filePath)); std::vector<Font> fonts; fonts.push_back(Font::Builder(font).build()); return std::make_shared<FontFamily>(std::move(fonts)); diff --git a/tests/util/FontTestUtils.h b/tests/util/FontTestUtils.h index 532ed71..309ded1 100644 --- a/tests/util/FontTestUtils.h +++ b/tests/util/FontTestUtils.h @@ -21,6 +21,8 @@ #include "minikin/FontCollection.h" +#include "PathUtils.h" + namespace minikin { /** @@ -28,22 +30,29 @@ namespace minikin { * * This function reads an XML file and makes font families. */ -std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const char* fontDir, const char* fontXml); +std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const std::string& fontDir, + const std::string& xmlAbsPath); /** * Returns FontCollection from installed fonts. * * This function reads an XML file and makes font families and collections of them. + * The XML path and font files are needed to be in the test data directory. */ -std::shared_ptr<FontCollection> getFontCollection(const char* fontDir, const char* fontXml); +inline std::shared_ptr<FontCollection> buildFontCollectionFromXml(const std::string& xmlPath) { + return std::make_shared<FontCollection>( + getFontFamilies(getTestDataDir(), getTestDataDir() + xmlPath)); +} /** * Build new FontCollection from single file. + * The font file needs to be in the test data directory. */ std::shared_ptr<FontCollection> buildFontCollection(const std::string& filePath); /** * Build new FontFamily from single file. + * The font file needs to be in the test data directory. */ std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath); diff --git a/tests/util/FreeTypeMinikinFontForTest.cpp b/tests/util/FreeTypeMinikinFontForTest.cpp index b1ada2b..7f70772 100644 --- a/tests/util/FreeTypeMinikinFontForTest.cpp +++ b/tests/util/FreeTypeMinikinFontForTest.cpp @@ -61,7 +61,7 @@ void loadGlyphOrDie(uint32_t glyphId, float size, FT_Face face) { FreeTypeMinikinFontForTest::FreeTypeMinikinFontForTest(const std::string& font_path, int index) : MinikinFont(uniqueId++), mFontPath(font_path), mFontIndex(index) { int fd = open(font_path.c_str(), O_RDONLY); - LOG_ALWAYS_FATAL_IF(fd == -1); + LOG_ALWAYS_FATAL_IF(fd == -1, "Open failed: %s", font_path.c_str()); struct stat st = {}; LOG_ALWAYS_FATAL_IF(fstat(fd, &st) != 0); mFontSize = st.st_size; diff --git a/tests/util/PathUtils.cpp b/tests/util/PathUtils.cpp index 7e1826e..b08ff4b 100644 --- a/tests/util/PathUtils.cpp +++ b/tests/util/PathUtils.cpp @@ -24,12 +24,22 @@ namespace minikin { const char* SELF_EXE_PATH = "/proc/self/exe"; -std::string getTestFontPath(const std::string& fontFilePath) { +std::string getDirname(const std::string& path) { + const char* result = dirname(path.c_str()); + LOG_ALWAYS_FATAL_IF(result == nullptr, "dirname failed."); + return std::string(result); +} + +std::string getBasename(const std::string& path) { + const char* result = basename(path.c_str()); + LOG_ALWAYS_FATAL_IF(result == nullptr, "basename failed."); + return std::string(result); +} + +std::string getTestDataDir() { char buf[PATH_MAX] = {}; LOG_ALWAYS_FATAL_IF(readlink(SELF_EXE_PATH, buf, PATH_MAX) == -1, "readlink failed."); - const char* dir = dirname(buf); - LOG_ALWAYS_FATAL_IF(dir == nullptr, "dirname failed."); - return std::string(dir) + "/data/" + fontFilePath; + return getDirname(buf) + "/data/"; } } // namespace minikin diff --git a/tests/util/PathUtils.h b/tests/util/PathUtils.h index 5a0be0d..c757b84 100644 --- a/tests/util/PathUtils.h +++ b/tests/util/PathUtils.h @@ -21,7 +21,15 @@ namespace minikin { -std::string getTestFontPath(const std::string& fontFilePath); +std::string getDirname(const std::string& path); +std::string getBasename(const std::string& path); + +// Returns test data directory. +std::string getTestDataDir(); + +inline std::string getTestFontPath(const std::string& fontFilePath) { + return getTestDataDir() + fontFilePath; +} } // namespace minikin |