From ec065e1e109a2b8cc0c7dca9cef89be7c19d3a03 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 17 Aug 2021 14:15:29 -0700 Subject: [PATCH] Fix Libtxt unit test errors found by ASAN Fixes https://github.com/flutter/flutter/issues/88198 Fixes https://github.com/flutter/flutter/issues/88199 --- third_party/txt/src/txt/paragraph_txt.cc | 3 +- third_party/txt/src/txt/text_style.cc | 2 + third_party/txt/tests/paragraph_unittests.cc | 64 +++++++++----------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/third_party/txt/src/txt/paragraph_txt.cc b/third_party/txt/src/txt/paragraph_txt.cc index ec14079fc62a1..a3b458cbfc4c1 100644 --- a/third_party/txt/src/txt/paragraph_txt.cc +++ b/third_party/txt/src/txt/paragraph_txt.cc @@ -1992,7 +1992,8 @@ Paragraph::Range ParagraphTxt::GetWordBoundary(size_t offset) { return Range(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(); diff --git a/third_party/txt/src/txt/text_style.cc b/third_party/txt/src/txt/text_style.cc index 0d1cacb184f89..c571f31eddaa8 100644 --- a/third_party/txt/src/txt/text_style.cc +++ b/third_party/txt/src/txt/text_style.cc @@ -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) { diff --git a/third_party/txt/tests/paragraph_unittests.cc b/third_party/txt/tests/paragraph_unittests.cc index c3cb242a12981..570ea3cbbec84 100644 --- a/third_party/txt/tests/paragraph_unittests.cc +++ b/third_party/txt/tests/paragraph_unittests.cc @@ -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, @@ -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); @@ -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); @@ -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); @@ -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); @@ -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);