libtxt: update the unit tests and benchmarks (flutter/engine#5523)

* pass a locale to GetMinikinFontCollectionForFamily
* provide the ICU data file path
* loosen checks based on the Minikin LineBreaker's line widths
  (LineBreaker widths do not exactly match the advances calculated during layout)
This commit is contained in:
Jason Simmons
2018-06-13 15:33:59 -07:00
committed by GitHub
parent 3877686f88
commit 929f5df0f5
4 changed files with 43 additions and 35 deletions

View File

@@ -373,7 +373,7 @@ static void BM_ParagraphMinikinDoLayout(benchmark::State& state) {
paint.wordSpacing = text_style.word_spacing;
auto collection = GetTestFontCollection()->GetMinikinFontCollectionForFamily(
text_style.font_family);
text_style.font_family, "en-US");
while (state.KeepRunning()) {
minikin::Layout layout;
@@ -413,7 +413,8 @@ static void BM_ParagraphMinikinAddStyleRun(benchmark::State& state) {
while (state.KeepRunning()) {
for (int i = 0; i < 20; ++i) {
breaker.addStyleRun(
&paint, font_collection->GetMinikinFontCollectionForFamily("Roboto"),
&paint,
font_collection->GetMinikinFontCollectionForFamily("Roboto", "en-US"),
font, state.range(0) / 20 * i, state.range(0) / 20 * (i + 1), false);
}
}

View File

@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
}
FXL_DCHECK(txt::GetFontDir().length() > 0);
fml::icu::InitializeICU();
fml::icu::InitializeICU("icudtl.dat");
::benchmark::RunSpecifiedBenchmarks();
}

View File

@@ -419,41 +419,46 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) {
ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
expected_y += 30;
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[0].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[0].line()]);
paragraph->breaker_.getWidths()[paragraph->records_[0].line()],
2.0);
ASSERT_TRUE(paragraph->records_[1].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y);
expected_y += 30;
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[1].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[1].line()]);
paragraph->breaker_.getWidths()[paragraph->records_[1].line()],
2.0);
ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
expected_y += 30;
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[2].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[2].line()]);
paragraph->breaker_.getWidths()[paragraph->records_[2].line()],
2.0);
ASSERT_TRUE(paragraph->records_[3].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y);
expected_y += 30 * 10;
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[3].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[3].line()]);
paragraph->breaker_.getWidths()[paragraph->records_[3].line()],
2.0);
ASSERT_TRUE(paragraph->records_[13].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y);
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[13].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[13].line()]);
paragraph->breaker_.getWidths()[paragraph->records_[13].line()],
2.0);
ASSERT_EQ(paragraph_style.text_align,
paragraph->GetParagraphStyle().text_align);
@@ -523,45 +528,47 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
expected_y += 30;
ASSERT_DOUBLE_EQ(
paragraph->records_[0].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) /
2);
ASSERT_NEAR(paragraph->records_[0].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) /
2,
2.0);
ASSERT_TRUE(paragraph->records_[1].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y);
expected_y += 30;
ASSERT_DOUBLE_EQ(
paragraph->records_[1].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[1].line()]) /
2);
ASSERT_NEAR(paragraph->records_[1].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[1].line()]) /
2,
2.0);
ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
expected_y += 30;
ASSERT_EQ(paragraph->records_[2].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) /
2);
ASSERT_NEAR(paragraph->records_[2].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) /
2,
2.0);
ASSERT_TRUE(paragraph->records_[3].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y);
expected_y += 30 * 10;
ASSERT_DOUBLE_EQ(
paragraph->records_[3].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[3].line()]) /
2);
ASSERT_NEAR(paragraph->records_[3].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[3].line()]) /
2,
2.0);
ASSERT_TRUE(paragraph->records_[13].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y);
ASSERT_DOUBLE_EQ(
ASSERT_NEAR(
paragraph->records_[13].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[13].line()]) /
2);
2,
2.0);
ASSERT_EQ(paragraph_style.text_align,
paragraph->GetParagraphStyle().text_align);

View File

@@ -36,7 +36,7 @@ int main(int argc, char** argv) {
}
FXL_DCHECK(txt::GetFontDir().length() > 0);
fml::icu::InitializeICU();
fml::icu::InitializeICU("icudtl.dat");
SkGraphics::Init();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();