Skip to content

Commit

Permalink
libtxt: update the unit tests and benchmarks (flutter#5523)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
jason-simmons authored Jun 13, 2018
1 parent efd6663 commit 408f1e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
5 changes: 3 additions & 2 deletions third_party/txt/benchmarks/paragraph_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/txt/benchmarks/txt_run_all_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
69 changes: 38 additions & 31 deletions third_party/txt/tests/paragraph_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion third_party/txt/tests/txt_run_all_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 408f1e5

Please sign in to comment.