Add more testing for Paragraph and FontCollection.

Change-Id: Idec0077f44225f0af8bbcd6464d226555f79beae
This commit is contained in:
Gary Qian
2017-06-07 14:51:09 -07:00
parent 4e5639d921
commit d86d3c526a
5 changed files with 99 additions and 1 deletions

View File

@@ -20,6 +20,7 @@
#include <vector>
#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;

View File

@@ -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

View File

@@ -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

View File

@@ -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
} // namespace txt

View File

@@ -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());
}