From d86d3c526a1e24716b404b85e52278b528935167 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 7 Jun 2017 14:51:09 -0700 Subject: [PATCH] Add more testing for Paragraph and FontCollection. Change-Id: Idec0077f44225f0af8bbcd6464d226555f79beae --- engine/src/flutter/src/styled_runs.h | 9 ++++++ engine/src/flutter/src/text_style.cc | 28 ++++++++++++++++ engine/src/flutter/src/text_style.h | 2 ++ .../tests/txt/font_collection_unittests.cc | 29 ++++++++++++++++- .../flutter/tests/txt/paragraph_unittests.cc | 32 +++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index 781e1eb69b..8b757658a4 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -20,6 +20,7 @@ #include #include "lib/txt/src/text_style.h" +#include "third_party/gtest/include/gtest/gtest_prod.h" namespace txt { @@ -54,6 +55,14 @@ class StyledRuns { Run GetRun(size_t index) const; private: + FRIEND_TEST(RenderTest, SimpleParagraph); + FRIEND_TEST(RenderTest, SimpleRedParagraph); + FRIEND_TEST(RenderTest, RainbowParagraph); + FRIEND_TEST(RenderTest, DefaultStyleParagraph); + FRIEND_TEST(RenderTest, BoldParagraph); + FRIEND_TEST(RenderTest, LinebreakParagraph); + FRIEND_TEST(RenderTest, ItalicsParagraph); + struct IndexedRun { size_t style_index = 0; size_t start = 0; diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc index d7d0ab7a2d..bacb9a55fe 100644 --- a/engine/src/flutter/src/text_style.cc +++ b/engine/src/flutter/src/text_style.cc @@ -15,3 +15,31 @@ */ #include "lib/txt/src/text_style.h" +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace txt { + +bool TextStyle::equals(TextStyle& other) { + if (color != other.color) + return false; + if (font_weight != other.font_weight) + return false; + if (font_style != other.font_style) + return false; + if (fake_bold != other.fake_bold) + return false; + if (font_family != other.font_family) + return false; + if (letter_spacing != other.letter_spacing) + return false; + if (word_spacing != other.word_spacing) + return false; + if (height != other.height) + return false; + + return true; +} + +} // namespace txt diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 21c122abfe..13b322f2c9 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -40,6 +40,8 @@ class TextStyle { double letter_spacing = 0.0; double word_spacing = 0.0; double height = 1.0; + + bool equals(TextStyle& other); }; } // namespace txt diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index ab15710e96..4a069a3661 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -69,6 +69,33 @@ TEST(FontCollection, GetFamilyNames) { txt::FontCollection::GetFamilyNames(txt::GetFontDir()); ASSERT_EQ(names.size(), 19ull); + + ASSERT_EQ(names.count("Roboto"), 1ull); + ASSERT_EQ(names.count("Homemade Apple"), 1ull); + + ASSERT_EQ(names.count("KoreanFont Test"), 1ull); + ASSERT_EQ(names.count("JapaneseFont Test"), 1ull); + ASSERT_EQ(names.count("EmojiFont Test"), 1ull); + ASSERT_EQ(names.count("ItalicFont Test"), 1ull); + ASSERT_EQ(names.count("VariationSelector Test"), 1ull); + ASSERT_EQ(names.count("ColorEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("TraditionalChinese Test"), 1ull); + ASSERT_EQ(names.count("Sample Font"), 1ull); + ASSERT_EQ(names.count("MultiAxisFont Test"), 1ull); + ASSERT_EQ(names.count("TextEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("No Cmap Format 14 Subtable Test"), 1ull); + ASSERT_EQ(names.count("ColorTextMixedEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("BoldFont Test"), 1ull); + ASSERT_EQ(names.count("EmptyFont Test"), 1ull); + ASSERT_EQ(names.count("SimplifiedChinese Test"), 1ull); + ASSERT_EQ(names.count("BoldItalicFont Test"), 1ull); + ASSERT_EQ(names.count("RegularFont Test"), 1ull); + + ASSERT_EQ(names.count("Not a real font!"), 0ull); + ASSERT_EQ(names.count(""), 0ull); + ASSERT_EQ(names.count("Helvetica"), 0ull); + ASSERT_EQ(names.count("TimesNewRoman"), 0ull); + ASSERT_EQ(names.count("Arial"), 0ull); } -} // namespace txt \ No newline at end of file +} // namespace txt diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 11b816241b..344418efa2 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -52,6 +52,10 @@ TEST_F(RenderTest, SimpleParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -82,6 +86,10 @@ TEST_F(RenderTest, SimpleRedParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -158,6 +166,16 @@ TEST_F(RenderTest, RainbowParagraph) { for (size_t i = 0; i < u16_text1.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text1[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 4ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 4ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style1)); + ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style2)); + ASSERT_TRUE(paragraph->runs_.styles_[2].equals(text_style3)); + ASSERT_TRUE(paragraph->runs_.styles_[3].equals(text_style4)); + ASSERT_EQ(paragraph->records_[0].color(), text_style1.color); + ASSERT_EQ(paragraph->records_[1].color(), text_style2.color); + ASSERT_EQ(paragraph->records_[2].color(), text_style3.color); + ASSERT_EQ(paragraph->records_[3].color(), text_style4.color); ASSERT_TRUE(Snapshot()); } @@ -188,6 +206,8 @@ TEST_F(RenderTest, DefaultStyleParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 0ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 0ull); ASSERT_TRUE(Snapshot()); } @@ -223,6 +243,10 @@ TEST_F(RenderTest, BoldParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -283,6 +307,10 @@ TEST_F(RenderTest, LinebreakParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -315,6 +343,10 @@ TEST_F(RenderTest, ItalicsParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); }