Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Fix Libtxt unit test errors found by ASAN #28146

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion third_party/txt/src/txt/paragraph_txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,8 @@ Paragraph::Range<size_t> ParagraphTxt::GetWordBoundary(size_t offset) {
return Range<size_t>(0, 0);
}

word_breaker_->setText(icu::UnicodeString(false, text_.data(), text_.size()));
icu::UnicodeString icu_text(false, text_.data(), text_.size());
word_breaker_->setText(icu_text);

int32_t prev_boundary = word_breaker_->preceding(offset + 1);
int32_t next_boundary = word_breaker_->next();
Expand Down
2 changes: 2 additions & 0 deletions third_party/txt/src/txt/text_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ bool TextStyle::equals(const TextStyle& other) const {
return false;
if (foreground != other.foreground)
return false;
if (font_families.size() != other.font_families.size())
return false;
if (text_shadows.size() != other.text_shadows.size())
return false;
for (size_t font_index = 0; font_index < font_families.size(); ++font_index) {
Expand Down
64 changes: 29 additions & 35 deletions third_party/txt/tests/paragraph_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2489,11 +2489,10 @@ 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_NEAR(
paragraph->records_[0].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[0].line()],
2.0);
ASSERT_NEAR(paragraph->records_[0].offset().x(),
paragraph->width_ -
paragraph->line_widths_[paragraph->records_[0].line()],
2.0);

// width_ takes the full available space, while longest_line_ wraps the glyphs
// as tightly as possible. Even though this text is more than one line long,
Expand All @@ -2506,37 +2505,33 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) {
ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
expected_y += 30;
ASSERT_NEAR(
paragraph->records_[2].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[2].line()],
2.0);
ASSERT_NEAR(paragraph->records_[2].offset().x(),
paragraph->width_ -
paragraph->line_widths_[paragraph->records_[2].line()],
2.0);

ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
expected_y += 30;
ASSERT_NEAR(
paragraph->records_[4].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[4].line()],
2.0);
ASSERT_NEAR(paragraph->records_[4].offset().x(),
paragraph->width_ -
paragraph->line_widths_[paragraph->records_[4].line()],
2.0);

ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
expected_y += 30 * 10;
ASSERT_NEAR(
paragraph->records_[6].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[6].line()],
2.0);
ASSERT_NEAR(paragraph->records_[6].offset().x(),
paragraph->width_ -
paragraph->line_widths_[paragraph->records_[6].line()],
2.0);

ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
ASSERT_NEAR(
paragraph->records_[26].offset().x(),
paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[26].line()],
2.0);
ASSERT_NEAR(paragraph->records_[26].offset().x(),
paragraph->width_ -
paragraph->line_widths_[paragraph->records_[26].line()],
2.0);

ASSERT_EQ(paragraph_style.text_align,
paragraph->GetParagraphStyle().text_align);
Expand Down Expand Up @@ -2609,7 +2604,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
expected_y += 30;
ASSERT_NEAR(paragraph->records_[0].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) /
paragraph->line_widths_[paragraph->records_[0].line()]) /
2,
2.0);

Expand All @@ -2618,7 +2613,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
expected_y += 30;
ASSERT_NEAR(paragraph->records_[2].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) /
paragraph->line_widths_[paragraph->records_[2].line()]) /
2,
2.0);

Expand All @@ -2627,7 +2622,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
expected_y += 30;
ASSERT_NEAR(paragraph->records_[4].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[4].line()]) /
paragraph->line_widths_[paragraph->records_[4].line()]) /
2,
2.0);

Expand All @@ -2636,18 +2631,17 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
expected_y += 30 * 10;
ASSERT_NEAR(paragraph->records_[6].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[6].line()]) /
paragraph->line_widths_[paragraph->records_[6].line()]) /
2,
2.0);

ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
ASSERT_NEAR(
paragraph->records_[26].offset().x(),
(paragraph->width_ -
paragraph->breaker_.getWidths()[paragraph->records_[26].line()]) /
2,
2.0);
ASSERT_NEAR(paragraph->records_[26].offset().x(),
(paragraph->width_ -
paragraph->line_widths_[paragraph->records_[26].line()]) /
2,
2.0);

ASSERT_EQ(paragraph_style.text_align,
paragraph->GetParagraphStyle().text_align);
Expand Down