1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <functional>
17 #include <optional>
18
19 #include "gtest/gtest.h"
20 #include "core/components_ng/pattern/text_field/text_selector.h"
21
22 #define private public
23 #define protected public
24
25 #include "base/geometry/dimension.h"
26 #include "base/memory/ace_type.h"
27 #include "base/memory/referenced.h"
28 #include "core/components/common/layout/constants.h"
29 #include "core/components_ng/base/frame_node.h"
30 #include "core/components_ng/base/geometry_node.h"
31 #include "core/components_ng/base/view_stack_processor.h"
32 #include "core/components_ng/layout/layout_property.h"
33 #include "core/components_ng/pattern/image/image_pattern.h"
34 #include "core/components_ng/pattern/pattern.h"
35 #include "core/components_ng/pattern/root/root_pattern.h"
36 #include "core/components_ng/pattern/text/text_accessibility_property.h"
37 #include "core/components_ng/pattern/text/text_content_modifier.h"
38 #include "core/components_ng/pattern/text/text_layout_property.h"
39 #include "core/components_ng/pattern/text/text_model_ng.h"
40 #include "core/components_ng/pattern/text/text_paint_method.h"
41 #include "core/components_ng/pattern/text/text_pattern.h"
42 #include "core/components_ng/render/adapter/txt_paragraph.h"
43 #include "core/components_ng/render/paragraph.h"
44 #include "core/components_ng/test/mock/render/mock_render_context.h"
45 #include "core/components_ng/test/mock/rosen/mock_canvas.h"
46 #include "core/components_ng/test/mock/theme/mock_theme_manager.h"
47 #include "core/components_ng/test/pattern/text/mock/mock_txt_paragraph.h"
48 #include "core/components_v2/inspector/inspector_constants.h"
49 #include "core/event/mouse_event.h"
50 #include "core/pipeline_ng/test/mock/mock_pipeline_base.h"
51 #include "frameworks/base/window/drag_window.h"
52 #include "frameworks/core/components_ng/pattern/root/root_pattern.h"
53 #undef private
54 #undef protected
55 #include "core/components_ng/pattern/text/span_model_ng.h"
56
57 using namespace testing;
58 using namespace testing::ext;
59
60 namespace OHOS::Ace::NG {
61 namespace {
62 constexpr float RK356_WIDTH = 720.0f;
63 constexpr float RK356_HEIGHT = 1136.0f;
64 constexpr float RK356_LOW_WIDTH = 50.0f;
65 constexpr float RK356_LOW_HEIGHT = 20.0f;
66 constexpr float TEXT_WIDTH = 100.0f;
67 constexpr float TEXT_HEIGHT = 75.0f;
68 constexpr float LARGE_WIDTH = 1000000.0f;
69 constexpr float DIMENSION = 10.0f;
70 constexpr float CONTEXT_WIDTH_VALUE = 10.0f;
71 constexpr float CONTEXT_LARGE_WIDTH_VALUE = 10000.0f;
72 constexpr float CONTEXT_HEIGHT_VALUE = 10.0f;
73 constexpr float BASE_LINE_OFFSET_VALUE = 1.0;
74 constexpr float BASE_LINE_OFFSET = 20.f;
75 constexpr double RECT_X_VALUE = 1.0;
76 constexpr double RECT_SECOND_X_VALUE = 2.0;
77 constexpr double RECT_Y_VALUE = 1.0;
78 constexpr double RECT_WIDTH_VALUE = 5.0;
79 constexpr double RECT_HEIGHT_VALUE = 10.0;
80 constexpr double BLURRADIUS_VALUE = 0.0;
81 constexpr double SPREADRADIUS_VALUE = 0.0;
82 constexpr double ADAPT_OFFSETY_VALUE = 5.0;
83 constexpr double ADAPT_OFFSETX_VALUE = 5.0;
84 const std::string TEXT_CONTENT = "text";
85 constexpr int32_t TEXT_ERROR = -1;
86 constexpr int32_t TEXT_SIZE_INT = 10;
87 constexpr int32_t MAX_LINES = 500;
88 constexpr int32_t SELECTED_COLOR = 0;
89 constexpr Dimension BASELINE_OFFSET_VALUE = Dimension(20, DimensionUnit::PX);
90 constexpr Dimension ADAPT_MIN_FONT_SIZE_VALUE = Dimension(50, DimensionUnit::PX);
91 constexpr Dimension ADAPT_OVER_MIN_FONT_SIZE_VALUE = Dimension(100, DimensionUnit::PX);
92 constexpr Dimension ADAPT_ZERO_FONT_SIZE_VALUE = Dimension(0, DimensionUnit::PX);
93 constexpr Dimension ADAPT_MAX_FONT_SIZE_VALUE_S = Dimension(80, DimensionUnit::PX);
94 constexpr Dimension ADAPT_FONT_SIZE_STEP_VALUE = Dimension(10, DimensionUnit::PX);
95 const std::string CREATE_VALUE = "Hello World";
96 const SizeF CONTAINER_SIZE(RK356_WIDTH, RK356_HEIGHT);
97 const SizeF CONTAINER_LOW_SIZE(RK356_LOW_WIDTH, RK356_LOW_HEIGHT);
98 const SizeF TEXT_SIZE(TEXT_WIDTH, TEXT_HEIGHT);
99 const SizeF LARGE_CONTAINER_SIZE(LARGE_WIDTH, TEXT_HEIGHT);
100 constexpr Dimension ADAPT_LINE_HEIGHT_VALUE = Dimension(10, DimensionUnit::PX);
101 constexpr Dimension ADAPT_FONT_SIZE_VALUE = Dimension(30, DimensionUnit::PX);
102 constexpr Dimension ADAPT_BASE_LINE_OFFSET_VALUE = Dimension(10, DimensionUnit::PX);
103 const Dimension FONT_SIZE_VALUE = Dimension(20.1, DimensionUnit::PX);
104 const Color TEXT_COLOR_VALUE = Color::FromRGB(255, 100, 100);
105 const SizeT<float> LARGE_SIZE = SizeT<float>(10000.0f, 1000.0f);
106 const Ace::FontStyle ITALIC_FONT_STYLE_VALUE = Ace::FontStyle::ITALIC;
107 const Ace::FontWeight FONT_WEIGHT_VALUE = Ace::FontWeight::W100;
108 const std::vector<std::string> FONT_FAMILY_VALUE = { "cursive" };
109 const Ace::TextAlign TEXT_ALIGN_VALUE = Ace::TextAlign::CENTER;
110 const Ace::TextOverflow TEXT_OVERFLOW_VALUE = Ace::TextOverflow::CLIP;
111 const uint32_t MAX_LINES_VALUE = 10;
112 const Dimension LINE_HEIGHT_VALUE = Dimension(20.1, DimensionUnit::PX);
113 const Ace::TextDecoration TEXT_DECORATION_VALUE = Ace::TextDecoration::INHERIT;
114 const Color TEXT_DECORATION_COLOR_VALUE = Color::FromRGB(255, 100, 100);
115 const Ace::TextCase TEXT_CASE_VALUE = Ace::TextCase::LOWERCASE;
116 const Dimension ADAPT_MAX_FONT_SIZE_VALUE = Dimension(200, DimensionUnit::PX);
117 const Dimension LETTER_SPACING = Dimension(10, DimensionUnit::PX);
118 const Dimension TEXT_INDENT = Dimension(5, DimensionUnit::PX);
119 const Dimension ADAPT_UPDATE_FONTSIZE_VALUE = Dimension(50, DimensionUnit::PX);
120 const std::string ROOT_TAG("root");
121 constexpr int32_t NODE_ID = 143;
122 const Color FOREGROUND_COLOR_VALUE = Color::FOREGROUND;
123 const RectF CONTENT_RECT(3.0, 3.0, TEXT_WIDTH, TEXT_HEIGHT);
124 constexpr int32_t ROOT_NODE_ID = 113;
125 const std::string EMPTY_TEXT = "";
126 constexpr int32_t UNKNOWN_REASON = 1;
127 constexpr float TEXT_RECT_SIZE_ZEOR = 0.0f;
128 constexpr float TEXT_RECT_WIDTH = 10.0f;
129 constexpr float TEXT_RECT_TOP_ONE = 10.0f;
130 constexpr float TEXT_RECT_TOP_TWO = 20.0f;
131 constexpr float TEXT_CONTENT_SIZE = 50.0f;
132 const std::string TEXT_DEFAULT_VALUE = "{\"style\":\"FontStyle.Normal\",\"size\":\"16.00fp\",\"weight\":"
133 "\"FontWeight.Normal\",\"family\":\"HarmonyOS Sans\"}";
134 const std::string TEXT_EQUALS_VALUE =
135 R"({"style":"FontStyle.Italic","size":"20.10px","weight":"FontWeight.Bold","family":"cursive"})";
136
137 using OnClickCallback = std::function<void(const BaseEventInfo* info)>;
138 using DragDropBaseCallback = std::function<DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>;
onClickFunc(const BaseEventInfo * info)139 void onClickFunc(const BaseEventInfo* info) {};
onRemoteMessage()140 void onRemoteMessage() {};
141 const CopyOptions copyOption = CopyOptions::None;
OnDragStartFunction(const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)142 DragDropBaseInfo OnDragStartFunction(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)
143 {
144 DragDropBaseInfo temp;
145 return temp;
146 };
OnDragDropFunction(const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)147 void OnDragDropFunction(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&) {};
148
TestUpdateScenario(const RefPtr<TextPattern> & pattern)149 void TestUpdateScenario(const RefPtr<TextPattern>& pattern)
150 {
151 ASSERT_NE(pattern, nullptr);
152 auto layoutProperty = pattern->GetLayoutProperty<TextLayoutProperty>();
153 ASSERT_NE(layoutProperty, nullptr);
154 layoutProperty->UpdateFontSize(ADAPT_UPDATE_FONTSIZE_VALUE);
155 pattern->BeforeCreateLayoutWrapper();
156 auto host = pattern->GetHost();
157 ASSERT_NE(host, nullptr);
158 for (const auto& child : host->GetChildren()) {
159 auto spanNode = AceType::DynamicCast<SpanNode>(child);
160 ASSERT_NE(spanNode, nullptr);
161 auto inheritPropertyInfo = spanNode->CaculateInheritPropertyInfo();
162 auto iter = inheritPropertyInfo.find(PropertyInfo::FONTSIZE);
163 if (iter != inheritPropertyInfo.end()) {
164 EXPECT_EQ(spanNode->GetFontSize().value(), ADAPT_UPDATE_FONTSIZE_VALUE);
165 }
166 }
167 }
168 } // namespace
169
170 struct TestProperty {
171 std::optional<Dimension> fontSizeValue = std::nullopt;
172 std::optional<Color> textColorValue = std::nullopt;
173 std::optional<Ace::FontStyle> italicFontStyleValue = std::nullopt;
174 std::optional<Ace::FontWeight> fontWeightValue = std::nullopt;
175 std::optional<std::vector<std::string>> fontFamilyValue = std::nullopt;
176 std::optional<Ace::TextAlign> textAlignValue = std::nullopt;
177 std::optional<Ace::TextOverflow> textOverflowValue = std::nullopt;
178 std::optional<uint32_t> maxLinesValue = std::nullopt;
179 std::optional<Dimension> lineHeightValue = std::nullopt;
180 std::optional<Ace::TextDecoration> textDecorationValue = std::nullopt;
181 std::optional<Color> textDecorationColorValue = std::nullopt;
182 std::optional<Dimension> baselineOffsetValue = std::nullopt;
183 std::optional<Ace::TextCase> textCaseValue = std::nullopt;
184 std::optional<Dimension> adaptMinFontSize = std::nullopt;
185 std::optional<Dimension> adaptMaxFontSize = std::nullopt;
186 std::optional<Dimension> letterSpacing = std::nullopt;
187 std::optional<Dimension> textIndent = std::nullopt;
188 };
189
190 class TextTestNg : public testing::Test {
191 public:
192 void SetUp() override;
193 void TearDown() override;
194 void InitTextObject();
195 RefPtr<SpanNode> CreateSpanNodeWithSetDefaultProperty(const std::string& content);
196
197 protected:
198 static RefPtr<FrameNode> CreateTextParagraph(const std::string& createValue, const TestProperty& testProperty);
199 static void SetContentModifier(TextContentModifier& textContentModifier);
200 static void SetPaintMethodModifier(TextPaintMethod& textPaintMethod);
201 static void UpdateTextLayoutProperty(RefPtr<TextLayoutProperty> textLayoutProperty);
202 };
203
SetUp()204 void TextTestNg::SetUp()
205 {
206 MockPipelineBase::SetUp();
207 InitTextObject();
208 }
209
TearDown()210 void TextTestNg::TearDown()
211 {
212 MockPipelineBase::TearDown();
213 MockTxtParagraph::SetCanConstruct();
214 }
215
InitTextObject()216 void TextTestNg::InitTextObject() {}
217
CreateSpanNodeWithSetDefaultProperty(const std::string & content)218 RefPtr<SpanNode> TextTestNg::CreateSpanNodeWithSetDefaultProperty(const std::string& content)
219 {
220 SpanModelNG spanModelNG;
221 spanModelNG.Create(content);
222 spanModelNG.SetFontSize(FONT_SIZE_VALUE);
223 spanModelNG.SetTextColor(TEXT_COLOR_VALUE);
224 spanModelNG.SetItalicFontStyle(ITALIC_FONT_STYLE_VALUE);
225 spanModelNG.SetFontWeight(FONT_WEIGHT_VALUE);
226 spanModelNG.SetFontFamily(FONT_FAMILY_VALUE);
227 spanModelNG.SetTextDecoration(TEXT_DECORATION_VALUE);
228 spanModelNG.SetTextDecorationColor(TEXT_DECORATION_COLOR_VALUE);
229 spanModelNG.SetTextCase(TEXT_CASE_VALUE);
230 spanModelNG.SetLetterSpacing(LETTER_SPACING);
231 spanModelNG.SetLineHeight(LINE_HEIGHT_VALUE);
232 return AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->Finish());
233 }
234
CreateTextParagraph(const std::string & createValue,const TestProperty & testProperty)235 RefPtr<FrameNode> TextTestNg::CreateTextParagraph(const std::string& createValue, const TestProperty& testProperty)
236 {
237 TextModelNG textModel;
238 textModel.Create(createValue);
239 if (testProperty.fontSizeValue.has_value()) {
240 textModel.SetFontSize(testProperty.fontSizeValue.value());
241 }
242 if (testProperty.textColorValue.has_value()) {
243 textModel.SetTextColor(testProperty.textColorValue.value());
244 }
245 if (testProperty.italicFontStyleValue.has_value()) {
246 textModel.SetItalicFontStyle(testProperty.italicFontStyleValue.value());
247 }
248 if (testProperty.fontWeightValue.has_value()) {
249 textModel.SetFontWeight(testProperty.fontWeightValue.value());
250 }
251 if (testProperty.fontFamilyValue.has_value()) {
252 textModel.SetFontFamily(testProperty.fontFamilyValue.value());
253 }
254 if (testProperty.textAlignValue.has_value()) {
255 textModel.SetTextAlign(testProperty.textAlignValue.value());
256 }
257 if (testProperty.textOverflowValue.has_value()) {
258 textModel.SetTextOverflow(testProperty.textOverflowValue.value());
259 }
260 if (testProperty.maxLinesValue.has_value()) {
261 textModel.SetMaxLines(testProperty.maxLinesValue.value());
262 }
263 if (testProperty.lineHeightValue.has_value()) {
264 textModel.SetLineHeight(testProperty.lineHeightValue.value());
265 }
266 if (testProperty.textDecorationValue.has_value()) {
267 textModel.SetTextDecoration(testProperty.textDecorationValue.value());
268 }
269 if (testProperty.textDecorationColorValue.has_value()) {
270 textModel.SetTextDecorationColor(testProperty.textDecorationColorValue.value());
271 }
272 if (testProperty.baselineOffsetValue.has_value()) {
273 textModel.SetBaselineOffset(testProperty.baselineOffsetValue.value());
274 }
275 if (testProperty.textCaseValue.has_value()) {
276 textModel.SetTextCase(testProperty.textCaseValue.value());
277 }
278 if (testProperty.adaptMinFontSize.has_value()) {
279 textModel.SetAdaptMinFontSize(testProperty.adaptMinFontSize.value());
280 }
281 if (testProperty.adaptMaxFontSize.has_value()) {
282 textModel.SetAdaptMaxFontSize(testProperty.adaptMaxFontSize.value());
283 }
284 if (testProperty.letterSpacing.has_value()) {
285 textModel.SetLetterSpacing(testProperty.letterSpacing.value());
286 }
287 if (testProperty.textIndent.has_value()) {
288 textModel.SetTextIndent(testProperty.textIndent.value());
289 }
290
291 RefPtr<UINode> element = ViewStackProcessor::GetInstance()->Finish(); // TextView pop
292 return AceType::DynamicCast<FrameNode>(element);
293 }
294
SetContentModifier(TextContentModifier & textContentModifier)295 void TextTestNg::SetContentModifier(TextContentModifier& textContentModifier)
296 {
297 textContentModifier.SetFontWeight(Ace::FontWeight::W200);
298 textContentModifier.SetTextColor(TEXT_COLOR_VALUE);
299 textContentModifier.SetTextDecorationColor(TEXT_COLOR_VALUE);
300 Shadow textShadow;
301 textShadow.SetBlurRadius(BLURRADIUS_VALUE);
302 textShadow.SetColor(TEXT_COLOR_VALUE);
303 textShadow.SetSpreadRadius(SPREADRADIUS_VALUE);
304 textShadow.SetOffsetX(ADAPT_OFFSETX_VALUE);
305 textShadow.SetOffsetY(ADAPT_OFFSETY_VALUE);
306 textContentModifier.SetTextShadow(textShadow);
307 textContentModifier.SetFontSize(ADAPT_FONT_SIZE_VALUE);
308 textContentModifier.SetBaselineOffset(BASELINE_OFFSET_VALUE);
309 OffsetF paintOffset;
310 textContentModifier.SetPrintOffset(paintOffset);
311 }
312
SetPaintMethodModifier(TextPaintMethod & textPaintMethod)313 void TextTestNg::SetPaintMethodModifier(TextPaintMethod& textPaintMethod)
314 {
315 textPaintMethod.textContentModifier_->fontSize_ = ADAPT_FONT_SIZE_VALUE;
316 textPaintMethod.textContentModifier_->fontWeight_ = FontWeight::LIGHTER;
317 textPaintMethod.textContentModifier_->textColor_ = TEXT_COLOR_VALUE;
318 Shadow textShadow;
319 textPaintMethod.textContentModifier_->textShadow_ = textShadow;
320 textPaintMethod.textContentModifier_->textDecorationColorAlpha_ =
321 AceType::MakeRefPtr<AnimatablePropertyFloat>(1.0f);
322 textPaintMethod.textContentModifier_->textDecoration_ = TextDecoration::NONE;
323 textPaintMethod.textContentModifier_->baselineOffset_ = BASELINE_OFFSET_VALUE;
324 }
325
UpdateTextLayoutProperty(RefPtr<TextLayoutProperty> textLayoutProperty)326 void TextTestNg::UpdateTextLayoutProperty(RefPtr<TextLayoutProperty> textLayoutProperty)
327 {
328 textLayoutProperty->UpdateTextOverflow(TextOverflow::MARQUEE);
329 textLayoutProperty->UpdateFontSize(ADAPT_FONT_SIZE_VALUE);
330 textLayoutProperty->UpdateFontWeight(Ace::FontWeight::W200);
331 textLayoutProperty->UpdateTextColor(TEXT_COLOR_VALUE);
332 Shadow textShadow;
333 textShadow.SetBlurRadius(BLURRADIUS_VALUE);
334 textShadow.SetColor(TEXT_COLOR_VALUE);
335 textShadow.SetSpreadRadius(SPREADRADIUS_VALUE);
336 textShadow.SetOffsetX(ADAPT_OFFSETX_VALUE);
337 textShadow.SetOffsetY(ADAPT_OFFSETY_VALUE);
338 textLayoutProperty->UpdateTextShadow(textShadow);
339 textLayoutProperty->UpdateTextDecorationColor(TEXT_COLOR_VALUE);
340 textLayoutProperty->UpdateTextDecoration(TextDecoration::OVERLINE);
341 textLayoutProperty->UpdateBaselineOffset(ADAPT_BASE_LINE_OFFSET_VALUE);
342 }
343
Init()344 std::pair<RefPtr<FrameNode>, RefPtr<TextPattern>> Init()
345 {
346 TextModelNG textModelNG;
347 textModelNG.Create(CREATE_VALUE);
348 auto pattern = AceType::MakeRefPtr<TextPattern>();
349 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
350 frameNode->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
351 pattern->AttachToFrameNode(frameNode);
352 auto host = pattern->GetHost();
353 auto pipeline = host->GetContext();
354 pipeline->rootNode_ =
355 FrameNode::CreateFrameNodeWithTree(V2::ROOT_ETS_TAG, ROOT_NODE_ID, Referenced::MakeRefPtr<RootPattern>());
356 ;
357 auto clipboard = ClipboardProxy::GetInstance()->GetClipboard(pipeline->GetTaskExecutor());
358 pattern->clipboard_ = clipboard;
359 return { frameNode, pattern };
360 }
361
362 /**
363 * @tc.name: TextFrameNodeCreator001
364 * @tc.desc: Test all the properties of text.
365 * @tc.type: FUNC
366 */
367 HWTEST_F(TextTestNg, TextFrameNodeCreator001, TestSize.Level1)
368 {
369 TestProperty testProperty;
370 testProperty.fontSizeValue = std::make_optional(FONT_SIZE_VALUE);
371 testProperty.textColorValue = std::make_optional(TEXT_COLOR_VALUE);
372 testProperty.italicFontStyleValue = std::make_optional(ITALIC_FONT_STYLE_VALUE);
373 testProperty.fontWeightValue = std::make_optional(FONT_WEIGHT_VALUE);
374 testProperty.fontFamilyValue = std::make_optional(FONT_FAMILY_VALUE);
375 testProperty.textAlignValue = std::make_optional(TEXT_ALIGN_VALUE);
376 testProperty.textOverflowValue = std::make_optional(TEXT_OVERFLOW_VALUE);
377 testProperty.maxLinesValue = std::make_optional(MAX_LINES_VALUE);
378 testProperty.lineHeightValue = std::make_optional(LINE_HEIGHT_VALUE);
379 testProperty.textDecorationValue = std::make_optional(TEXT_DECORATION_VALUE);
380 testProperty.textDecorationColorValue = std::make_optional(TEXT_DECORATION_COLOR_VALUE);
381 testProperty.baselineOffsetValue = std::make_optional(BASELINE_OFFSET_VALUE);
382 testProperty.textCaseValue = std::make_optional(TEXT_CASE_VALUE);
383 testProperty.adaptMinFontSize = std::make_optional(ADAPT_MIN_FONT_SIZE_VALUE);
384 testProperty.adaptMaxFontSize = std::make_optional(ADAPT_MAX_FONT_SIZE_VALUE);
385 testProperty.textIndent = std::make_optional(TEXT_INDENT);
386
387 RefPtr<FrameNode> frameNode = CreateTextParagraph(CREATE_VALUE, testProperty);
388 ASSERT_NE(frameNode, nullptr);
389 RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
390 ASSERT_NE(layoutProperty, nullptr);
391 RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
392 ASSERT_NE(textLayoutProperty, nullptr);
393 EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
394 const std::unique_ptr<FontStyle>& fontStyle = textLayoutProperty->GetFontStyle();
395 ASSERT_NE(fontStyle, nullptr);
396 const std::unique_ptr<TextLineStyle>& textLineStyle = textLayoutProperty->GetTextLineStyle();
397 ASSERT_NE(textLineStyle, nullptr);
398 TextStyle textStyle = CreateTextStyleUsingTheme(fontStyle, textLineStyle, nullptr);
399 EXPECT_EQ(textStyle.GetFontSize(), FONT_SIZE_VALUE);
400 EXPECT_EQ(textStyle.GetTextColor(), TEXT_COLOR_VALUE);
401 EXPECT_EQ(textStyle.GetFontStyle(), ITALIC_FONT_STYLE_VALUE);
402 EXPECT_EQ(textStyle.GetFontWeight(), FONT_WEIGHT_VALUE);
403 EXPECT_EQ(textStyle.GetFontFamilies(), FONT_FAMILY_VALUE);
404 EXPECT_EQ(textStyle.GetTextAlign(), TEXT_ALIGN_VALUE);
405 EXPECT_EQ(textStyle.GetTextOverflow(), TEXT_OVERFLOW_VALUE);
406 EXPECT_EQ(textStyle.GetMaxLines(), MAX_LINES_VALUE);
407 EXPECT_EQ(textStyle.GetLineHeight(), LINE_HEIGHT_VALUE);
408 EXPECT_EQ(textStyle.GetTextDecoration(), TEXT_DECORATION_VALUE);
409 EXPECT_EQ(textStyle.GetTextDecorationColor(), TEXT_DECORATION_COLOR_VALUE);
410 EXPECT_EQ(textStyle.GetBaselineOffset(), BASELINE_OFFSET_VALUE);
411 EXPECT_EQ(textStyle.GetTextCase(), TEXT_CASE_VALUE);
412 EXPECT_EQ(textStyle.GetAdaptMinFontSize(), ADAPT_MIN_FONT_SIZE_VALUE);
413 EXPECT_EQ(textStyle.GetAdaptMaxFontSize(), ADAPT_MAX_FONT_SIZE_VALUE);
414 EXPECT_EQ(textStyle.GetAdaptTextSize(),
415 testProperty.adaptMinFontSize.has_value() || testProperty.adaptMaxFontSize.has_value());
416
417 /**
418 * @tc.cases: case2. renderContext has foreground color and modifier will foreground color flag
419 */
420 frameNode->GetRenderContext()->UpdateForegroundColor(Color::RED);
421 textStyle = CreateTextStyleUsingThemeWithText(frameNode, fontStyle, textLineStyle, nullptr);
422 EXPECT_EQ(textStyle.GetTextColor(), FOREGROUND_COLOR_VALUE);
423 }
424
425 /**
426 * @tc.name: TextFrameNodeCreator002
427 * @tc.desc: Test all the property of text.
428 * @tc.type: FUNC
429 */
430 HWTEST_F(TextTestNg, TextFrameNodeCreator002, TestSize.Level1)
431 {
432 TestProperty testProperty;
433 testProperty.letterSpacing = std::make_optional(LETTER_SPACING);
434 testProperty.baselineOffsetValue = std::make_optional(BASELINE_OFFSET_VALUE);
435 auto frameNode = CreateTextParagraph(CREATE_VALUE, testProperty);
436 ASSERT_NE(frameNode, nullptr);
437 auto layoutProperty = frameNode->GetLayoutProperty();
438 ASSERT_NE(layoutProperty, nullptr);
439 auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
440 ASSERT_NE(textLayoutProperty, nullptr);
441 EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
442 const std::unique_ptr<FontStyle>& fontStyle = textLayoutProperty->GetFontStyle();
443 ASSERT_NE(fontStyle, nullptr);
444 const std::unique_ptr<TextLineStyle>& textLineStyle = textLayoutProperty->GetTextLineStyle();
445 ASSERT_NE(textLineStyle, nullptr);
446 auto textStyle = CreateTextStyleUsingTheme(fontStyle, textLineStyle, nullptr);
447 EXPECT_EQ(textStyle.GetLetterSpacing(), LETTER_SPACING);
448 }
449
450 /**
451 * @tc.name: TextFrameNodeCreator003
452 * @tc.desc: Test all the fontWeight and events of text.
453 * @tc.type: FUNC
454 */
455 HWTEST_F(TextTestNg, TextFrameNodeCreator003, TestSize.Level1)
456 {
457 TextModelNG textModelNG;
458 textModelNG.Create(CREATE_VALUE);
459 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
460 ASSERT_NE(frameNode, nullptr);
461 RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
462 ASSERT_NE(layoutProperty, nullptr);
463 RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
464 ASSERT_NE(textLayoutProperty, nullptr);
465 EXPECT_EQ(textLayoutProperty->GetContentValue(), CREATE_VALUE);
466 textModelNG.SetFontWeight(FontWeight::LIGHTER);
467 textModelNG.SetLineHeight(LINE_HEIGHT_VALUE);
468 const std::unique_ptr<FontStyle>& fontStyle = textLayoutProperty->GetFontStyle();
469 ASSERT_NE(textLayoutProperty, nullptr);
470 const std::unique_ptr<TextLineStyle>& textLineStyle = textLayoutProperty->GetTextLineStyle();
471 ASSERT_NE(textLayoutProperty, nullptr);
472 TextStyle textStyle = CreateTextStyleUsingTheme(fontStyle, textLineStyle, nullptr);
473
474 textModelNG.SetFontWeight(FontWeight::LIGHTER);
475 textStyle.SetFontWeight(FontWeight::W100);
476 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W100);
477 textModelNG.SetFontWeight(FontWeight::REGULAR);
478 textStyle.SetFontWeight(FontWeight::W400);
479 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W400);
480 textModelNG.SetFontWeight(FontWeight::NORMAL);
481 textStyle.SetFontWeight(FontWeight::W400);
482 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W400);
483 textModelNG.SetFontWeight(FontWeight::MEDIUM);
484 textStyle.SetFontWeight(FontWeight::W500);
485 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W500);
486 textModelNG.SetFontWeight(FontWeight::BOLD);
487 textStyle.SetFontWeight(FontWeight::W700);
488 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W700);
489 textModelNG.SetFontWeight(FontWeight::BOLDER);
490 textStyle.SetFontWeight(FontWeight::W900);
491 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W900);
492 textModelNG.SetFontWeight(FontWeight::W900);
493 textStyle.SetFontWeight(FontWeight::W900);
494 EXPECT_EQ(textStyle.GetFontWeight(), FontWeight::W900);
495
496 textModelNG.SetOnClick(onClickFunc);
497 textModelNG.SetRemoteMessage(onRemoteMessage);
498 textModelNG.SetCopyOption(copyOption);
499 textModelNG.SetOnDragStart(OnDragStartFunction);
500 textModelNG.SetOnDragEnter(OnDragDropFunction);
501 textModelNG.SetOnDragMove(OnDragDropFunction);
502 textModelNG.SetOnDragLeave(OnDragDropFunction);
503 textModelNG.SetOnDrop(OnDragDropFunction);
504 }
505
506 /**
507 * @tc.name: OnAttachToFrameNode001
508 * @tc.desc: Test TextPattern OnAttachToFrameNode when GetHost is nullptr.
509 * @tc.type: FUNC
510 */
511 HWTEST_F(TextTestNg, OnAttachToFrameNode001, TestSize.Level1)
512 {
513 TextModelNG textModelNG;
514 textModelNG.Create(CREATE_VALUE);
515
516 auto pattern = AceType::MakeRefPtr<TextPattern>();
517 pattern->OnAttachToFrameNode();
518 EXPECT_EQ(pattern->longPressEvent_, nullptr);
519 }
520
521 /**
522 * @tc.name: OnDetachFromFrameNode001
523 * @tc.desc: Test TextPattern OnDetachFromFrameNode when FrameNode is nullptr.
524 * @tc.type: FUNC
525 */
526 HWTEST_F(TextTestNg, OnDetachFromFrameNode001, TestSize.Level1)
527 {
528 auto pattern = AceType::MakeRefPtr<TextPattern>();
529 pattern->selectOverlayProxy_ = nullptr;
530 pattern->OnDetachFromFrameNode(nullptr);
531 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
532 }
533
534 /**
535 * @tc.name: OnDetachFromFrameNode002
536 * @tc.desc: Test TextPattern OnDetachFromFrameNode when SelectOverlayProxy is not nullptr.
537 * @tc.type: FUNC
538 */
539 HWTEST_F(TextTestNg, OnDetachFromFrameNode002, TestSize.Level1)
540 {
541 TextModelNG textModelNG;
542 textModelNG.Create(CREATE_VALUE);
543
544 auto pattern = AceType::MakeRefPtr<TextPattern>();
545 /**
546 * @tc.steps: step1. construct a SelectOverlayManager
547 */
548 SelectOverlayInfo selectOverlayInfo;
549 selectOverlayInfo.singleLineHeight = NODE_ID;
550 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
551 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
552
553 /**
554 * @tc.steps: step2. call CreateAndShowSelectOverlay
555 * @tc.expected: return the proxy which has the right SelectOverlayId
556 */
557 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
558 pattern->selectOverlayProxy_ = proxy;
559 pattern->OnDetachFromFrameNode(nullptr);
560 EXPECT_NE(pattern->selectOverlayProxy_, nullptr);
561 }
562
563 /**
564 * @tc.name: OnDetachFromFrameNode003
565 * @tc.desc: Test TextPattern OnDetachFromFrameNode when SelectOverlayProxy is not nullptr with wrong selectOverlayId.
566 * @tc.type: FUNC
567 */
568 HWTEST_F(TextTestNg, OnDetachFromFrameNode003, TestSize.Level1)
569 {
570 TextModelNG textModelNG;
571 textModelNG.Create(CREATE_VALUE);
572
573 auto pattern = AceType::MakeRefPtr<TextPattern>();
574 /**
575 * @tc.steps: step1. construct a SelectOverlayManager
576 */
577 SelectOverlayInfo selectOverlayInfo;
578 selectOverlayInfo.singleLineHeight = NODE_ID;
579 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
580 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
581
582 /**
583 * @tc.steps: step2. call CreateAndShowSelectOverlay
584 * @tc.expected: return the proxy which has the right SelectOverlayId
585 */
586 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
587 pattern->selectOverlayProxy_ = proxy;
588 proxy->selectOverlayId_ = 1;
589 pattern->OnDetachFromFrameNode(nullptr);
590 EXPECT_NE(pattern->selectOverlayProxy_, nullptr);
591 }
592
593 /**
594 * @tc.name: OnHandleMoveDone001
595 * @tc.desc: Test TextPattern OnHandleMoveDone
596 * @tc.type: FUNC
597 */
598 HWTEST_F(TextTestNg, OnHandleMoveDone001, TestSize.Level1)
599 {
600 /**
601 * @tc.steps: step1. create frameNode and pattern
602 */
603 auto [frameNode, pattern] = Init();
604 pattern->textSelector_.Update(0, TEXT_SIZE_INT);
605
606 /**
607 * @tc.steps: step2. call OnHandleMoveDone when SelectOverlayProxy is nullptr.
608 * @tc.expected: the function exits normally
609 */
610 RectF handleRect = CONTENT_RECT;
611 pattern->OnHandleMoveDone(handleRect, true);
612 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
613 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), TEXT_SIZE_INT);
614
615 /**
616 * @tc.steps: step3. construct a SelectOverlayManager
617 */
618 SelectOverlayInfo selectOverlayInfo;
619 selectOverlayInfo.singleLineHeight = NODE_ID;
620 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
621 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
622
623 /**
624 * @tc.steps: step4. call CreateAndShowSelectOverlay
625 * @tc.expected: return the proxy which has the right SelectOverlayId
626 */
627 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
628 pattern->selectOverlayProxy_ = proxy;
629 EXPECT_NE(pattern->selectOverlayProxy_, nullptr);
630
631 /**
632 * @tc.steps: step5. call OnHandleMoveDone when SelectOverlayProxy is not nullptr.
633 * @tc.expected: the OnHandleMoveDone function exits normally
634 */
635 bool isFirstHandle[2] = { true, false };
636 for (int i = 0; i < 2; i++) {
637 pattern->OnHandleMoveDone(handleRect, isFirstHandle[i]);
638 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
639 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), TEXT_SIZE_INT);
640 }
641 }
642
643 /**
644 * @tc.name: ShowSelectOverlay001
645 * @tc.desc: Test TextPattern ShowSelectOverlay when SelectOverlayProxy is not nullptr.
646 * @tc.type: FUNC
647 */
648 HWTEST_F(TextTestNg, ShowSelectOverlay001, TestSize.Level1)
649 {
650 auto [frameNode, pattern] = Init();
651 /**
652 * @tc.steps: step1. construct a SelectOverlayManager
653 */
654 SelectOverlayInfo selectOverlayInfo;
655 selectOverlayInfo.singleLineHeight = NODE_ID;
656 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
657 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
658
659 /**
660 * @tc.steps: step2. call CreateAndShowSelectOverlay
661 * @tc.expected: return the proxy which has the right SelectOverlayId
662 */
663 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
664 auto current = selectOverlayManager->selectOverlayItem_.Upgrade();
665 ASSERT_NE(current, nullptr);
666 proxy->selectOverlayId_ = current->GetId();
667 pattern->selectOverlayProxy_ = proxy;
668 ASSERT_NE(pattern->selectOverlayProxy_, nullptr);
669 RectF firstHandle = CONTENT_RECT;
670 RectF secondHandle = CONTENT_RECT;
671 pattern->ShowSelectOverlay(firstHandle, secondHandle);
672 EXPECT_NE(pattern->selectOverlayProxy_, nullptr);
673 }
674
675 /**
676 * @tc.name: ShowSelectOverlay002
677 * @tc.desc: Test TextPattern ShowSelectOverlay when SelectOverlayProxy is nullptr.
678 * @tc.type: FUNC
679 */
680 HWTEST_F(TextTestNg, ShowSelectOverlay002, TestSize.Level1)
681 {
682 TextModelNG textModelNG;
683 textModelNG.Create(CREATE_VALUE);
684
685 auto pattern = AceType::MakeRefPtr<TextPattern>();
686 pattern->selectOverlayProxy_ = nullptr;
687 RectF firstHandle;
688 RectF secondHandle;
689 pattern->ShowSelectOverlay(firstHandle, secondHandle);
690 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
691 }
692
693 /**
694 * @tc.name: OnModifyDone001
695 * @tc.desc: Test TextPattern OnModifyDone when frameNode is not nullptr.
696 * @tc.type: FUNC
697 */
698 HWTEST_F(TextTestNg, OnModifyDone001, TestSize.Level1)
699 {
700 TextModelNG textModelNG;
701 textModelNG.Create(CREATE_VALUE);
702
703 auto pattern = AceType::MakeRefPtr<TextPattern>();
704 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
705 ASSERT_NE(frameNode, nullptr);
706 pattern->AttachToFrameNode(frameNode);
707 pattern->selectOverlayProxy_ = nullptr;
708 pattern->OnModifyDone();
709 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
710 }
711
712 /**
713 * @tc.name: OnModifyDone002
714 * @tc.desc: Test TextPattern OnModifyDone longPressEvent.
715 * @tc.type: FUNC
716 */
717 HWTEST_F(TextTestNg, OnModifyDone002, TestSize.Level1)
718 {
719 TextModelNG textModelNG;
720 textModelNG.Create(CREATE_VALUE);
721
722 /**
723 * @tc.steps: step1. create textFrameNode.
724 */
725 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
726 ASSERT_NE(textFrameNode, nullptr);
727 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
728 ASSERT_NE(geometryNode, nullptr);
729 auto textPattern = textFrameNode->GetPattern<TextPattern>();
730 ASSERT_NE(textPattern, nullptr);
731 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
732 ASSERT_NE(textLayoutProperty, nullptr);
733
734 /**
735 * @tc.steps: step2. set textLayoutProperty.
736 * copyOption: CopyOptions::InApp
737 */
738 textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
739 textLayoutProperty->UpdateContent(TEXT_CONTENT);
740
741 /**
742 * @tc.steps: step3. check the longPressEvent.
743 * @tc.expected: longPressEvent is triggered
744 */
745 textPattern->OnModifyDone();
746 EXPECT_NE(textPattern->longPressEvent_, nullptr);
747 EXPECT_EQ(textPattern->textForDisplay_, TEXT_CONTENT);
748 }
749
750 /**
751 * @tc.name: OnDirtyLayoutWrapperSwap001
752 * @tc.desc: Test TextPattern OnDirtyLayoutWrapperSwap when skipMeasure is true.
753 * @tc.type: FUNC
754 */
755 HWTEST_F(TextTestNg, OnDirtyLayoutWrapperSwap001, TestSize.Level1)
756 {
757 TextModelNG textModelNG;
758 textModelNG.Create(CREATE_VALUE);
759
760 auto pattern = AceType::MakeRefPtr<TextPattern>();
761 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
762 ASSERT_NE(frameNode, nullptr);
763 pattern->AttachToFrameNode(frameNode);
764 pattern->selectOverlayProxy_ = nullptr;
765 DirtySwapConfig config;
766 config.skipMeasure = true;
767 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
768 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
769 ASSERT_NE(layoutWrapper, nullptr);
770 auto rowLayoutAlgorithm = pattern->CreateLayoutAlgorithm();
771 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
772 auto ret = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
773 EXPECT_FALSE(ret);
774 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
775 }
776
777 /**
778 * @tc.name: OnDirtyLayoutWrapperSwap002
779 * @tc.desc: Test TextPattern OnDirtyLayoutWrapperSwap when skipMeasure is fasle.
780 * @tc.type: FUNC
781 */
782 HWTEST_F(TextTestNg, OnDirtyLayoutWrapperSwap002, TestSize.Level1)
783 {
784 TextModelNG textModelNG;
785 textModelNG.Create(CREATE_VALUE);
786
787 auto pattern = AceType::MakeRefPtr<TextPattern>();
788 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
789 ASSERT_NE(frameNode, nullptr);
790 pattern->AttachToFrameNode(frameNode);
791 pattern->selectOverlayProxy_ = nullptr;
792 DirtySwapConfig config;
793 config.skipMeasure = false;
794 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
795 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
796 ASSERT_NE(layoutWrapper, nullptr);
797 auto rowLayoutAlgorithm = pattern->CreateLayoutAlgorithm();
798 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
799 auto ret = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
800 EXPECT_FALSE(ret);
801 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
802 }
803
804 /**
805 * @tc.name: OnDirtyLayoutWrapperSwap003
806 * @tc.desc: Test TextPattern OnDirtyLayoutWrapperSwap when skipMeasure is fasle and paragraph is not nullptr.
807 * @tc.type: FUNC
808 */
809 HWTEST_F(TextTestNg, OnDirtyLayoutWrapperSwap003, TestSize.Level1)
810 {
811 TextModelNG textModelNG;
812 textModelNG.Create(CREATE_VALUE);
813
814 auto pattern = AceType::MakeRefPtr<TextPattern>();
815 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
816 ASSERT_NE(frameNode, nullptr);
817 pattern->AttachToFrameNode(frameNode);
818 pattern->selectOverlayProxy_ = nullptr;
819
820 DirtySwapConfig config;
821 config.skipMeasure = false;
822 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
823 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
824 ASSERT_NE(layoutWrapper, nullptr);
825
826 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
827 TextStyle textStyle;
828 LayoutConstraintF contentConstraint;
829 auto ret = rowLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
830 EXPECT_TRUE(ret);
831 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
832 ret = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
833 EXPECT_TRUE(ret);
834 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
835 }
836
837 /**
838 * @tc.name: BeforeCreateLayoutWrapper001
839 * @tc.desc: Test TextPattern BeforeCreateLayoutWrapper when paragraph is not nullptr.
840 * @tc.type: FUNC
841 */
842 HWTEST_F(TextTestNg, BeforeCreateLayoutWrapper001, TestSize.Level1)
843 {
844 TextModelNG textModelNG;
845 textModelNG.Create(CREATE_VALUE);
846
847 auto pattern = AceType::MakeRefPtr<TextPattern>();
848 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
849 ASSERT_NE(frameNode, nullptr);
850 pattern->AttachToFrameNode(frameNode);
851 pattern->selectOverlayProxy_ = nullptr;
852
853 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
854 TextStyle textStyle;
855 LayoutConstraintF contentConstraint;
856 auto ret = rowLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
857 EXPECT_TRUE(ret);
858 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
859 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
860 ASSERT_NE(layoutWrapper, nullptr);
861 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
862 pattern->BeforeCreateLayoutWrapper();
863 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
864 }
865
866 /**
867 * @tc.name: BeforeCreateLayoutWrapper002
868 * @tc.desc: Test TextPattern BeforeCreateLayoutWrapper when frameNode child is empty.
869 * @tc.type: FUNC
870 */
871 HWTEST_F(TextTestNg, BeforeCreateLayoutWrapper002, TestSize.Level1)
872 {
873 TextModelNG textModelNG;
874 textModelNG.Create(CREATE_VALUE);
875
876 auto pattern = AceType::MakeRefPtr<TextPattern>();
877 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
878 ASSERT_NE(frameNode, nullptr);
879
880 pattern->AttachToFrameNode(frameNode);
881 pattern->selectOverlayProxy_ = nullptr;
882
883 auto rowLayoutAlgorithm = pattern->CreateLayoutAlgorithm();
884 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
885 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
886 ASSERT_NE(layoutWrapper, nullptr);
887 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
888 pattern->BeforeCreateLayoutWrapper();
889 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
890 }
891
892 /**
893 * @tc.name: BeforeCreateLayoutWrapper003
894 * @tc.desc: Test TextPattern BeforeCreateLayoutWrapper when paragraph is nullptr.
895 * @tc.type: FUNC
896 */
897 HWTEST_F(TextTestNg, BeforeCreateLayoutWrapper003, TestSize.Level1)
898 {
899 TextModelNG textModelNG;
900 textModelNG.Create(CREATE_VALUE);
901
902 auto pattern = AceType::MakeRefPtr<TextPattern>();
903 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
904 ASSERT_NE(frameNode, nullptr);
905 pattern->AttachToFrameNode(frameNode);
906 pattern->selectOverlayProxy_ = nullptr;
907
908 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
909 TextStyle textStyle;
910 LayoutConstraintF contentConstraint;
911 auto ret = rowLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
912 EXPECT_TRUE(ret);
913
914 DirtySwapConfig config;
915 config.skipMeasure = false;
916 auto layoutWrapper =
917 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, AceType::MakeRefPtr<GeometryNode>(), nullptr);
918 ASSERT_NE(layoutWrapper, nullptr);
919 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
920 ret = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
921 EXPECT_TRUE(ret);
922 pattern->BeforeCreateLayoutWrapper();
923 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
924 }
925
926 /**
927 * @tc.name: BeforeCreateLayoutWrapper004
928 * @tc.desc: Test TextPattern BeforeCreateLayoutWrapper when frameNode child is not empty.
929 * @tc.type: FUNC
930 */
931 HWTEST_F(TextTestNg, BeforeCreateLayoutWrapper004, TestSize.Level1)
932 {
933 TextModelNG textModelNG;
934 textModelNG.Create(CREATE_VALUE);
935
936 auto pattern = AceType::MakeRefPtr<TextPattern>();
937 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
938 ASSERT_NE(frameNode, nullptr);
939
940 auto patternChild = AceType::MakeRefPtr<TextPattern>();
941 auto frameNodeChild = FrameNode::CreateFrameNode("Test", 1, patternChild);
942 ASSERT_NE(frameNodeChild, nullptr);
943
944 frameNode->AddChild(frameNodeChild);
945 pattern->AttachToFrameNode(frameNode);
946 pattern->selectOverlayProxy_ = nullptr;
947
948 auto rowLayoutAlgorithm = pattern->CreateLayoutAlgorithm();
949 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
950 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
951 ASSERT_NE(layoutWrapper, nullptr);
952 layoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
953 pattern->BeforeCreateLayoutWrapper();
954 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
955 }
956
957 /**
958 * @tc.name: DumpInfo001
959 * @tc.desc: Test TextPattern DumpInfo.
960 * @tc.type: FUNC
961 */
962 HWTEST_F(TextTestNg, DumpInfo001, TestSize.Level1)
963 {
964 TextModelNG textModelNG;
965 textModelNG.Create(CREATE_VALUE);
966
967 auto pattern = AceType::MakeRefPtr<TextPattern>();
968 pattern->selectOverlayProxy_ = nullptr;
969 pattern->DumpInfo();
970 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
971 }
972
973 /**
974 * @tc.name: OnHandleMove001
975 * @tc.desc: Test TextPattern OnHandleMove when SelectOverlayProxy is not nullptr.
976 * @tc.type: FUNC
977 */
978 HWTEST_F(TextTestNg, OnHandleMove001, TestSize.Level1)
979 {
980 TextModelNG textModelNG;
981 textModelNG.Create(CREATE_VALUE);
982
983 auto pattern = AceType::MakeRefPtr<TextPattern>();
984 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
985 pattern->AttachToFrameNode(frameNode);
986 /**
987 * @tc.steps: step1. construct a SelectOverlayManager
988 */
989 SelectOverlayInfo selectOverlayInfo;
990 selectOverlayInfo.singleLineHeight = NODE_ID;
991 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
992 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
993
994 /**
995 * @tc.steps: step2. call CreateAndShowSelectOverlay
996 * @tc.expected: return the proxy which has the right SelectOverlayId
997 */
998 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
999 pattern->selectOverlayProxy_ = proxy;
1000 EXPECT_NE(pattern->selectOverlayProxy_, nullptr);
1001 }
1002
1003 /**
1004 * @tc.name: TextCreatParagraphTest001
1005 * @tc.desc: Correctly create Paragraph only Set content.
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(TextTestNg, TextCreatParagraphTest001, TestSize.Level1)
1009 {
1010 /**
1011 * @tc.steps: step1. create textFrameNode.
1012 */
1013
1014 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1015 ASSERT_NE(textFrameNode, nullptr);
1016 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1017 ASSERT_NE(geometryNode, nullptr);
1018 RefPtr<LayoutWrapperNode> layoutWrapper =
1019 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1020 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1021 ASSERT_NE(textPattern, nullptr);
1022 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1023 ASSERT_NE(textLayoutProperty, nullptr);
1024
1025 /**
1026 * @tc.steps: step2. set Content.
1027 */
1028
1029 textLayoutProperty->UpdateContent(CREATE_VALUE);
1030
1031 /**
1032 * @tc.steps: step3. create textLayoutAlgorithm.
1033 */
1034
1035 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1036 EXPECT_FALSE(textLayoutAlgorithm == nullptr);
1037 LayoutConstraintF parentLayoutConstraint;
1038 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1039 auto sizeX =
1040 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1041
1042 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1043 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1044
1045 /**
1046 * @tc.steps: step4. check if it correctly create paragraph and the width and height.
1047 */
1048
1049 auto paragraph = textLayoutAlgorithm->GetParagraph();
1050 ASSERT_NE(paragraph, nullptr);
1051 EXPECT_TRUE(paragraph->GetMaxWidth() == 150.0);
1052 EXPECT_TRUE(sizeX->Height() == 50.0);
1053 }
1054
1055 /**
1056 * @tc.name: TextLayoutTest001
1057 * @tc.desc: Set content , width and height to Text and the check result.
1058 * @tc.type: FUNC
1059 */
1060 HWTEST_F(TextTestNg, TextLayoutTest001, TestSize.Level1)
1061 {
1062 /**
1063 * @tc.steps: step1. create textFrameNode.
1064 */
1065
1066 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1067 ASSERT_NE(textFrameNode, nullptr);
1068 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1069 ASSERT_NE(geometryNode, nullptr);
1070 RefPtr<LayoutWrapperNode> layoutWrapper =
1071 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1072 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1073 ASSERT_NE(textPattern, nullptr);
1074 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1075 ASSERT_NE(textLayoutProperty, nullptr);
1076
1077 /**
1078 * @tc.steps: step2. set textLayoutProperty.
1079 * content: CREATE_VALUE
1080 * width: 100.0f
1081 * height: 75.0f
1082 */
1083
1084 textLayoutProperty->UpdateContent(CREATE_VALUE);
1085 LayoutConstraintF parentLayoutConstraint;
1086 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1087 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1088
1089 /**
1090 * @tc.steps: step3. create textLayoutAlgorithm.
1091 */
1092
1093 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1094 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1095 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1096 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1097
1098 /**
1099 * @tc.steps: step4. check the size.
1100 */
1101
1102 auto paragraph = textLayoutAlgorithm->GetParagraph();
1103 EXPECT_EQ(paragraph->GetMaxWidth(), TEXT_WIDTH);
1104 }
1105
1106 /**
1107 * @tc.name: TextLayoutTest002
1108 * @tc.desc: set baselineOffset and maxsize of Text check height
1109 * @tc.type: FUNC
1110 */
1111 HWTEST_F(TextTestNg, TextLayoutTest002, TestSize.Level1)
1112 {
1113 /**
1114 * @tc.steps: step1. create textFrameNode.
1115 */
1116
1117 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1118 ASSERT_NE(textFrameNode, nullptr);
1119 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1120 ASSERT_NE(geometryNode, nullptr);
1121 RefPtr<LayoutWrapperNode> layoutWrapper =
1122 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1123 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1124 ASSERT_NE(textPattern, nullptr);
1125 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1126 ASSERT_NE(textLayoutProperty, nullptr);
1127
1128 /**
1129 * @tc.steps: step2. set textLayoutProperty.
1130 * baselineOffset: 20_px
1131 */
1132
1133 textLayoutProperty->UpdateContent(CREATE_VALUE);
1134 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1135 LayoutConstraintF parentLayoutConstraint;
1136 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1137
1138 /**
1139 * @tc.steps: step3. create textLayoutAlgorithm.
1140 */
1141
1142 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1143 auto sizeX =
1144 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1145
1146 /**
1147 * @tc.steps: step4. check the size.
1148 */
1149
1150 EXPECT_EQ(sizeX->Height(), BASELINE_OFFSET_VALUE.Value() + 50.0);
1151 }
1152
1153 /**
1154 * @tc.name: TextLayoutTest003
1155 * @tc.desc: set minFontSize and maxFontSize of Text check then check
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(TextTestNg, TextLayoutTest003, TestSize.Level1)
1159 {
1160 /**
1161 * @tc.steps: step1. create textFrameNode.
1162 */
1163
1164 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1165 ASSERT_NE(textFrameNode, nullptr);
1166 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1167 ASSERT_NE(geometryNode, nullptr);
1168 RefPtr<LayoutWrapperNode> layoutWrapper =
1169 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1170 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1171 ASSERT_NE(textPattern, nullptr);
1172 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1173 ASSERT_NE(textLayoutProperty, nullptr);
1174
1175 /**
1176 * @tc.steps: step2. set textLayoutProperty.
1177 * minFontSize: 50_px
1178 * macFontSize: 80_px
1179 */
1180
1181 LayoutConstraintF parentLayoutConstraint;
1182 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1183
1184 TextStyle textStyle;
1185 textStyle.SetTextAlign(TextAlign::CENTER);
1186 textStyle.SetAdaptTextSize(ADAPT_MIN_FONT_SIZE_VALUE, ADAPT_MAX_FONT_SIZE_VALUE_S);
1187 textStyle.SetAdaptFontSizeStep(ADAPT_FONT_SIZE_STEP_VALUE);
1188
1189 auto pipeline = textFrameNode->GetContext();
1190
1191 /**
1192 * @tc.steps: step3. create textLayoutAlgorithm.
1193 */
1194
1195 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1196 auto result =
1197 textLayoutAlgorithm->AdaptMinTextSize(textStyle, CREATE_VALUE, parentLayoutConstraint, pipeline, nullptr);
1198
1199 /**
1200 * @tc.steps: step4. check the fontSize.
1201 */
1202
1203 EXPECT_TRUE(result);
1204 }
1205
1206 /**
1207 * @tc.name: TextLayoutTest004
1208 * @tc.desc: set minFontSize and maxFontSize of Text check then check
1209 * @tc.type: FUNC
1210 */
1211 HWTEST_F(TextTestNg, TextLayoutTest004, TestSize.Level1)
1212 {
1213 /**
1214 * @tc.steps: step1. create textFrameNode.
1215 */
1216
1217 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1218 ASSERT_NE(textFrameNode, nullptr);
1219 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1220 ASSERT_NE(geometryNode, nullptr);
1221 RefPtr<LayoutWrapperNode> layoutWrapper =
1222 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1223 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1224 ASSERT_NE(textPattern, nullptr);
1225 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1226 ASSERT_NE(textLayoutProperty, nullptr);
1227
1228 /**
1229 * @tc.steps: step2. set textLayoutProperty.
1230 * minFontSize: 50_px
1231 * macFontSize: 80_px
1232 */
1233
1234 LayoutConstraintF parentLayoutConstraint;
1235 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1236
1237 TextStyle textStyle;
1238 textStyle.SetMaxLines(MAX_LINES);
1239 textStyle.SetTextAlign(TextAlign::CENTER);
1240 textStyle.SetAdaptTextSize(ADAPT_MIN_FONT_SIZE_VALUE, ADAPT_MAX_FONT_SIZE_VALUE_S);
1241 textStyle.SetAdaptFontSizeStep(ADAPT_FONT_SIZE_STEP_VALUE);
1242
1243 auto pipeline = textFrameNode->GetContext();
1244
1245 /**
1246 * @tc.steps: step3. create textLayoutAlgorithm.
1247 */
1248
1249 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1250 auto result =
1251 textLayoutAlgorithm->AdaptMinTextSize(textStyle, CREATE_VALUE, parentLayoutConstraint, pipeline, nullptr);
1252
1253 /**
1254 * @tc.steps: step4. check the fontSize.
1255 */
1256
1257 EXPECT_TRUE(result);
1258 }
1259
1260 /**
1261 * @tc.name: TextLayoutTest005
1262 * @tc.desc: set minFontSize and maxFontSize of Text check then check when maxFontSize >= minFontSize
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(TextTestNg, TextLayoutTest005, TestSize.Level1)
1266 {
1267 /**
1268 * @tc.steps: step1. create textFrameNode.
1269 */
1270
1271 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1272 ASSERT_NE(textFrameNode, nullptr);
1273 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1274 ASSERT_NE(geometryNode, nullptr);
1275 RefPtr<LayoutWrapperNode> layoutWrapper =
1276 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1277 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1278 ASSERT_NE(textPattern, nullptr);
1279 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1280 ASSERT_NE(textLayoutProperty, nullptr);
1281
1282 /**
1283 * @tc.steps: step2. set textLayoutProperty.
1284 * minFontSize: 50_px
1285 * macFontSize: 80_px
1286 */
1287
1288 LayoutConstraintF parentLayoutConstraint;
1289 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1290
1291 TextStyle textStyle;
1292 textStyle.SetMaxLines(MAX_LINES);
1293 textStyle.SetTextAlign(TextAlign::CENTER);
1294 textStyle.SetAdaptTextSize(ADAPT_MAX_FONT_SIZE_VALUE_S, ADAPT_MIN_FONT_SIZE_VALUE);
1295 textStyle.SetAdaptFontSizeStep(ADAPT_FONT_SIZE_STEP_VALUE);
1296
1297 auto pipeline = textFrameNode->GetContext();
1298
1299 /**
1300 * @tc.steps: step3. create textLayoutAlgorithm.
1301 */
1302
1303 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1304 auto result =
1305 textLayoutAlgorithm->AdaptMinTextSize(textStyle, CREATE_VALUE, parentLayoutConstraint, pipeline, nullptr);
1306
1307 /**
1308 * @tc.steps: step4. check the fontSize.
1309 */
1310
1311 EXPECT_TRUE(result);
1312 }
1313
1314 /**
1315 * @tc.name: TextLayoutTest006
1316 * @tc.desc: set baselineOffset and maxsize of Text check height when paragraph_ is not nullptr.
1317 * @tc.type: FUNC
1318 */
1319 HWTEST_F(TextTestNg, TextLayoutTest006, TestSize.Level1)
1320 {
1321 /**
1322 * @tc.steps: step1. create textFrameNode.
1323 */
1324
1325 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1326 ASSERT_NE(textFrameNode, nullptr);
1327 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1328 ASSERT_NE(geometryNode, nullptr);
1329 RefPtr<LayoutWrapperNode> layoutWrapper =
1330 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1331 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1332 ASSERT_NE(textPattern, nullptr);
1333 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1334 ASSERT_NE(textLayoutProperty, nullptr);
1335
1336 /**
1337 * @tc.steps: step2. set textLayoutProperty.
1338 * baselineOffset: 20_px
1339 */
1340
1341 textLayoutProperty->UpdateContent(CREATE_VALUE);
1342 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1343 LayoutConstraintF parentLayoutConstraint;
1344 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1345
1346 /**
1347 * @tc.steps: step3. create textLayoutAlgorithm.
1348 */
1349
1350 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1351 TextStyle textStyle;
1352 LayoutConstraintF contentConstraint;
1353 auto ret = textLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
1354 EXPECT_TRUE(ret);
1355 auto sizeX =
1356 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1357
1358 /**
1359 * @tc.steps: step4. check the size.
1360 */
1361
1362 EXPECT_EQ(sizeX->Height(), BASELINE_OFFSET_VALUE.Value() + 50.0);
1363 }
1364
1365 /**
1366 * @tc.name: TextLayoutTest007
1367 * @tc.desc: set baselineOffset and maxsize of Text check height when AdaptTextSize is disable.
1368 * contentConstraint.maxSize.IsPositive() is false.
1369 * @tc.type: FUNC
1370 */
1371 HWTEST_F(TextTestNg, TextLayoutTest007, TestSize.Level1)
1372 {
1373 /**
1374 * @tc.steps: step1. create textFrameNode.
1375 */
1376
1377 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1378 ASSERT_NE(textFrameNode, nullptr);
1379 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1380 ASSERT_NE(geometryNode, nullptr);
1381 RefPtr<LayoutWrapperNode> layoutWrapper =
1382 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1383 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1384 ASSERT_NE(textPattern, nullptr);
1385 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1386 ASSERT_NE(textLayoutProperty, nullptr);
1387
1388 /**
1389 * @tc.steps: step2. set textLayoutProperty.
1390 * baselineOffset: 20_px
1391 */
1392
1393 textLayoutProperty->UpdateContent(CREATE_VALUE);
1394 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1395 LayoutConstraintF parentLayoutConstraint;
1396 parentLayoutConstraint.maxSize.SetHeight(-1.0);
1397
1398 /**
1399 * @tc.steps: step3. create textLayoutAlgorithm.
1400 */
1401
1402 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1403 TextStyle textStyle;
1404 Dimension adaptMinFontSize(DIMENSION, DimensionUnit::PERCENT);
1405 textStyle.SetAdaptMinFontSize(adaptMinFontSize);
1406 auto ret = textLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", parentLayoutConstraint, nullptr);
1407 EXPECT_TRUE(ret);
1408 auto sizeX =
1409 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1410
1411 /**
1412 * @tc.steps: step4. check the size.
1413 */
1414
1415 EXPECT_EQ(sizeX, std::nullopt);
1416 }
1417
1418 /**
1419 * @tc.name: TextLayoutTest008
1420 * @tc.desc: set baselineOffset and maxsize of Text check height when AdaptTextSize is disable.
1421 * @tc.type: FUNC
1422 */
1423 HWTEST_F(TextTestNg, TextLayoutTest008, TestSize.Level1)
1424 {
1425 /**
1426 * @tc.steps: step1. create textFrameNode.
1427 */
1428
1429 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1430 ASSERT_NE(textFrameNode, nullptr);
1431 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1432 ASSERT_NE(geometryNode, nullptr);
1433 RefPtr<LayoutWrapperNode> layoutWrapper =
1434 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1435 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1436 ASSERT_NE(textPattern, nullptr);
1437 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1438 ASSERT_NE(textLayoutProperty, nullptr);
1439
1440 /**
1441 * @tc.steps: step2. set textLayoutProperty.
1442 * baselineOffset: 20_px
1443 */
1444
1445 textLayoutProperty->UpdateContent(CREATE_VALUE);
1446 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1447 LayoutConstraintF parentLayoutConstraint;
1448 parentLayoutConstraint.selfIdealSize.SetWidth(-1.0);
1449 parentLayoutConstraint.maxSize.SetHeight(1.0);
1450 parentLayoutConstraint.maxSize.SetWidth(1.0);
1451
1452 /**
1453 * @tc.steps: step3. create textLayoutAlgorithm.
1454 */
1455
1456 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1457 TextStyle textStyle;
1458 Dimension adaptMinFontSize(DIMENSION, DimensionUnit::PERCENT);
1459 textStyle.SetAdaptMinFontSize(adaptMinFontSize);
1460 auto ret = textLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", parentLayoutConstraint, nullptr);
1461 EXPECT_TRUE(ret);
1462 auto sizeX =
1463 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1464
1465 /**
1466 * @tc.steps: step4. check the size.
1467 */
1468
1469 EXPECT_EQ(sizeX->Height(), 1.0);
1470 }
1471
1472 /**
1473 * @tc.name: ToJsonValue001
1474 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1475 * @tc.type: FUNC
1476 */
1477 HWTEST_F(TextTestNg, ToJsonValue001, TestSize.Level1)
1478 {
1479 /**
1480 * @tc.steps: step1. create textFrameNode.
1481 */
1482 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1483 ASSERT_NE(textFrameNode, nullptr);
1484 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1485 ASSERT_NE(geometryNode, nullptr);
1486 RefPtr<LayoutWrapperNode> layoutWrapper =
1487 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1488 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1489 ASSERT_NE(textPattern, nullptr);
1490 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1491 ASSERT_NE(textLayoutProperty, nullptr);
1492
1493 /**
1494 * @tc.steps: step2. run ToJsonValue().
1495 */
1496 auto json = std::make_unique<JsonValue>();
1497 textLayoutProperty->ToJsonValue(json);
1498 }
1499
1500 /**
1501 * @tc.name: ToJsonValue002
1502 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(TextTestNg, ToJsonValue002, TestSize.Level1)
1506 {
1507 /**
1508 * @tc.steps: step1. create textFrameNode.
1509 */
1510 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1511 ASSERT_NE(textFrameNode, nullptr);
1512 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1513 ASSERT_NE(geometryNode, nullptr);
1514 RefPtr<LayoutWrapperNode> layoutWrapper =
1515 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1516 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1517 ASSERT_NE(textPattern, nullptr);
1518 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1519 ASSERT_NE(textLayoutProperty, nullptr);
1520
1521 /**
1522 * @tc.steps: step2. run ToJsonValue().
1523 */
1524 Dimension dim(DIMENSION);
1525 textLayoutProperty->UpdateAdaptMinFontSize(dim);
1526 textLayoutProperty->UpdateAdaptMaxFontSize(dim);
1527 textLayoutProperty->UpdateLetterSpacing(dim);
1528 textLayoutProperty->UpdateTextBaseline(TextBaseline::IDEOGRAPHIC);
1529 auto json = std::make_unique<JsonValue>();
1530 textLayoutProperty->ToJsonValue(json);
1531 }
1532
1533 /**
1534 * @tc.name: ToJsonValue003
1535 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1536 * @tc.type: FUNC
1537 */
1538 HWTEST_F(TextTestNg, ToJsonValue003, TestSize.Level1)
1539 {
1540 /**
1541 * @tc.steps: step1. create textFrameNode.
1542 */
1543 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1544 ASSERT_NE(textFrameNode, nullptr);
1545 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1546 ASSERT_NE(geometryNode, nullptr);
1547 RefPtr<LayoutWrapperNode> layoutWrapper =
1548 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1549 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1550 ASSERT_NE(textPattern, nullptr);
1551 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1552 ASSERT_NE(textLayoutProperty, nullptr);
1553
1554 /**
1555 * @tc.steps: step2. run ToJsonValue().
1556 */
1557 Dimension dim(DIMENSION);
1558 textLayoutProperty->UpdateAdaptMinFontSize(dim);
1559 textLayoutProperty->UpdateAdaptMaxFontSize(dim);
1560 textLayoutProperty->UpdateLetterSpacing(dim);
1561 textLayoutProperty->UpdateTextBaseline(TextBaseline::TOP);
1562 auto json = std::make_unique<JsonValue>();
1563 textLayoutProperty->ToJsonValue(json);
1564 }
1565
1566 /**
1567 * @tc.name: ToJsonValue004
1568 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1569 * @tc.type: FUNC
1570 */
1571 HWTEST_F(TextTestNg, ToJsonValue004, TestSize.Level1)
1572 {
1573 /**
1574 * @tc.steps: step1. create textFrameNode.
1575 */
1576 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1577 ASSERT_NE(textFrameNode, nullptr);
1578 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1579 ASSERT_NE(geometryNode, nullptr);
1580 RefPtr<LayoutWrapperNode> layoutWrapper =
1581 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1582 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1583 ASSERT_NE(textPattern, nullptr);
1584 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1585 ASSERT_NE(textLayoutProperty, nullptr);
1586
1587 /**
1588 * @tc.steps: step2. run ToJsonValue().
1589 */
1590 Dimension dim(DIMENSION);
1591 textLayoutProperty->UpdateAdaptMinFontSize(dim);
1592 textLayoutProperty->UpdateAdaptMaxFontSize(dim);
1593 textLayoutProperty->UpdateLetterSpacing(dim);
1594 textLayoutProperty->UpdateTextBaseline(TextBaseline::BOTTOM);
1595 auto json = std::make_unique<JsonValue>();
1596 textLayoutProperty->ToJsonValue(json);
1597 }
1598
1599 /**
1600 * @tc.name: ToJsonValue005
1601 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1602 * @tc.type: FUNC
1603 */
1604 HWTEST_F(TextTestNg, ToJsonValue005, TestSize.Level1)
1605 {
1606 /**
1607 * @tc.steps: step1. create textFrameNode.
1608 */
1609 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1610 ASSERT_NE(textFrameNode, nullptr);
1611 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1612 ASSERT_NE(geometryNode, nullptr);
1613 RefPtr<LayoutWrapperNode> layoutWrapper =
1614 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1615 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1616 ASSERT_NE(textPattern, nullptr);
1617 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1618 ASSERT_NE(textLayoutProperty, nullptr);
1619
1620 /**
1621 * @tc.steps: step2. run ToJsonValue().
1622 */
1623 Dimension dim(DIMENSION);
1624 textLayoutProperty->UpdateAdaptMinFontSize(dim);
1625 textLayoutProperty->UpdateAdaptMaxFontSize(dim);
1626 textLayoutProperty->UpdateLetterSpacing(dim);
1627 textLayoutProperty->UpdateTextBaseline(TextBaseline::MIDDLE);
1628 auto json = std::make_unique<JsonValue>();
1629 textLayoutProperty->ToJsonValue(json);
1630 }
1631
1632 /**
1633 * @tc.name: ToJsonValue006
1634 * @tc.desc: Test TextLayoutProperty ToJsonValue.
1635 * @tc.type: FUNC
1636 */
1637 HWTEST_F(TextTestNg, ToJsonValue006, TestSize.Level1)
1638 {
1639 /**
1640 * @tc.steps: step1. create textFrameNode.
1641 */
1642 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1643 ASSERT_NE(textFrameNode, nullptr);
1644 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1645 ASSERT_NE(geometryNode, nullptr);
1646 RefPtr<LayoutWrapperNode> layoutWrapper =
1647 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1648 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1649 ASSERT_NE(textPattern, nullptr);
1650 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1651 ASSERT_NE(textLayoutProperty, nullptr);
1652
1653 /**
1654 * @tc.steps: step2. run ToJsonValue().
1655 */
1656 Dimension dim(DIMENSION);
1657 textLayoutProperty->UpdateAdaptMinFontSize(dim);
1658 textLayoutProperty->UpdateAdaptMaxFontSize(dim);
1659 textLayoutProperty->UpdateLetterSpacing(dim);
1660 textLayoutProperty->UpdateTextBaseline(TextBaseline::HANGING);
1661 auto json = std::make_unique<JsonValue>();
1662 textLayoutProperty->ToJsonValue(json);
1663 }
1664
1665 /**
1666 * @tc.name: DidExceedMaxLines001
1667 * @tc.desc: Test TextLayoutAlgorithm DidExceedMaxLines.
1668 * @tc.type: FUNC
1669 */
1670 HWTEST_F(TextTestNg, DidExceedMaxLines001, TestSize.Level1)
1671 {
1672 /**
1673 * @tc.steps: step1. create textFrameNode.
1674 */
1675
1676 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1677 ASSERT_NE(textFrameNode, nullptr);
1678 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1679 ASSERT_NE(geometryNode, nullptr);
1680 RefPtr<LayoutWrapperNode> layoutWrapper =
1681 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1682 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1683 ASSERT_NE(textPattern, nullptr);
1684 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1685 ASSERT_NE(textLayoutProperty, nullptr);
1686
1687 /**
1688 * @tc.steps: step2. set textLayoutProperty.
1689 * baselineOffset: 20_px
1690 */
1691
1692 textLayoutProperty->UpdateContent(CREATE_VALUE);
1693 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1694 LayoutConstraintF parentLayoutConstraint;
1695 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1696
1697 /**
1698 * @tc.steps: step3. create textLayoutAlgorithm.
1699 */
1700
1701 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1702 TextStyle textStyle;
1703 LayoutConstraintF contentConstraint;
1704 auto ret = textLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
1705 EXPECT_TRUE(ret);
1706 SizeF maxSize;
1707 ret = textLayoutAlgorithm->DidExceedMaxLines(maxSize);
1708
1709 /**
1710 * @tc.steps: step4. check the size.
1711 */
1712
1713 EXPECT_TRUE(ret);
1714 }
1715
1716 /**
1717 * @tc.name: DidExceedMaxLines002
1718 * @tc.desc: Test TextLayoutAlgorithm DidExceedMaxLines.
1719 * @tc.type: FUNC
1720 */
1721 HWTEST_F(TextTestNg, DidExceedMaxLines002, TestSize.Level1)
1722 {
1723 /**
1724 * @tc.steps: step1. create textFrameNode.
1725 */
1726
1727 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1728 ASSERT_NE(textFrameNode, nullptr);
1729 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1730 ASSERT_NE(geometryNode, nullptr);
1731 RefPtr<LayoutWrapperNode> layoutWrapper =
1732 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1733 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1734 ASSERT_NE(textPattern, nullptr);
1735 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1736 ASSERT_NE(textLayoutProperty, nullptr);
1737
1738 /**
1739 * @tc.steps: step2. set textLayoutProperty.
1740 * baselineOffset: 20_px
1741 */
1742
1743 textLayoutProperty->UpdateContent(CREATE_VALUE);
1744 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1745 LayoutConstraintF parentLayoutConstraint;
1746 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1747
1748 /**
1749 * @tc.steps: step3. create textLayoutAlgorithm.
1750 */
1751
1752 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1753 TextStyle textStyle;
1754 textStyle.SetMaxLines(MAX_LINES);
1755 LayoutConstraintF contentConstraint;
1756 auto ret = textLayoutAlgorithm->CreateParagraphAndLayout(textStyle, "", contentConstraint, nullptr);
1757 EXPECT_TRUE(ret);
1758 SizeF maxSize;
1759 ret = textLayoutAlgorithm->DidExceedMaxLines(maxSize);
1760
1761 /**
1762 * @tc.steps: step4. check the size.
1763 */
1764
1765 EXPECT_TRUE(ret);
1766 }
1767
1768 /**
1769 * @tc.name: TextLayoutAlgorithmTest001
1770 * @tc.desc: test text_layout_algorithm.cpp:Set textHeightAdaptivePolicy to MIN_FONT_SIZE_FIRST
1771 * @tc.type: FUNC
1772 */
1773 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest001, TestSize.Level1)
1774 {
1775 /**
1776 * @tc.steps: step1. create textFrameNode.
1777 */
1778 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1779 ASSERT_NE(textFrameNode, nullptr);
1780 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1781 ASSERT_NE(geometryNode, nullptr);
1782 RefPtr<LayoutWrapperNode> layoutWrapper =
1783 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1784 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1785 ASSERT_NE(textPattern, nullptr);
1786 textPattern->textContentModifier_ = AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
1787 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1788 ASSERT_NE(textLayoutProperty, nullptr);
1789
1790 /**
1791 * @tc.steps: step2. set textLayoutProperty.
1792 */
1793 textLayoutProperty->UpdateContent(CREATE_VALUE);
1794 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST);
1795 LayoutConstraintF parentLayoutConstraint;
1796 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1797 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1798
1799 /**
1800 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent function.
1801 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
1802 */
1803 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1804 // set TextHeightAdaptivePolicy MAX_LINES_FIRST
1805 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
1806 MockTxtParagraph::SetCanConstruct(false);
1807 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1808 // set SetCanConstruct true
1809 MockTxtParagraph::SetCanConstruct(true);
1810 auto contentSize =
1811 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1812 textLayoutAlgorithm->baselineOffset_ = BASE_LINE_OFFSET;
1813 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1814 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1815 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
1816 }
1817
1818 /**
1819 * @tc.name: TextLayoutAlgorithmTest002
1820 * @tc.desc: test text_layout_algorithm.cpp:Set textHeightAdaptivePolicy to LAYOUT_CONSTRAINT_FIRST and set lineHeight
1821 * @tc.type: FUNC
1822 */
1823 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest002, TestSize.Level1)
1824 {
1825 /**
1826 * @tc.steps: step1. create textFrameNode.
1827 */
1828 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1829 ASSERT_NE(textFrameNode, nullptr);
1830 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1831 ASSERT_NE(geometryNode, nullptr);
1832 auto textLayoutProperty = textFrameNode->GetLayoutProperty<TextLayoutProperty>();
1833 ASSERT_NE(textLayoutProperty, nullptr);
1834 RefPtr<LayoutWrapperNode> layoutWrapper =
1835 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textLayoutProperty);
1836 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1837 ASSERT_NE(textPattern, nullptr);
1838
1839 /**
1840 * @tc.steps: step2. set textLayoutProperty.
1841 */
1842 textLayoutProperty->UpdateContent(CREATE_VALUE);
1843 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST);
1844 LayoutConstraintF parentLayoutConstraint;
1845 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1846 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1847 textLayoutProperty->UpdateAdaptMinFontSize(ADAPT_MIN_FONT_SIZE_VALUE);
1848 textLayoutProperty->UpdateLineHeight(ADAPT_LINE_HEIGHT_VALUE);
1849 textLayoutProperty->UpdateFontSize(ADAPT_FONT_SIZE_VALUE);
1850 textLayoutProperty->UpdateFontWeight(Ace::FontWeight::W200);
1851 textLayoutProperty->UpdateTextColor(TEXT_COLOR_VALUE);
1852 Shadow textShadow;
1853 textLayoutProperty->UpdateTextShadow(textShadow);
1854 textLayoutProperty->UpdateTextDecorationColor(TEXT_COLOR_VALUE);
1855 textLayoutProperty->UpdateTextDecoration(TextDecoration::OVERLINE);
1856 textLayoutProperty->UpdateBaselineOffset(BASELINE_OFFSET_VALUE);
1857
1858 /**
1859 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent/SetPropertyToModifier function.
1860 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
1861 */
1862 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1863 auto contentSize =
1864 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1865 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1866 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1867 auto frameNode = layoutWrapper->GetHostNode();
1868 auto pipeline = frameNode->GetContext();
1869 TextStyle textStyle = CreateTextStyleUsingTheme(
1870 textLayoutProperty->GetFontStyle(), textLayoutProperty->GetTextLineStyle(), pipeline->GetTheme<TextTheme>());
1871 textPattern->textContentModifier_ =
1872 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(std::move(textStyle)));
1873 auto contentModifier = textPattern->GetContentModifier();
1874 textLayoutAlgorithm->SetPropertyToModifier(textLayoutProperty, contentModifier);
1875 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
1876 }
1877
1878 /**
1879 * @tc.name: TextLayoutAlgorithmTest003
1880 * @tc.desc: test text_layout_algorithm.cpp:Set textHeightAdaptivePolicy to MIN_FONT_SIZE_FIRST, minFontSize and
1881 * fontSize are equal
1882 * @tc.type: FUNC
1883 */
1884 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest003, TestSize.Level1)
1885 {
1886 /**
1887 * @tc.steps: step1. create textFrameNode.
1888 */
1889 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1890 ASSERT_NE(textFrameNode, nullptr);
1891 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1892 ASSERT_NE(geometryNode, nullptr);
1893 RefPtr<LayoutWrapperNode> layoutWrapper =
1894 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1895 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1896 ASSERT_NE(textPattern, nullptr);
1897 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1898 ASSERT_NE(textLayoutProperty, nullptr);
1899
1900 /**
1901 * @tc.steps: step2. set textLayoutProperty.
1902 */
1903 textLayoutProperty->UpdateContent(CREATE_VALUE);
1904 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST);
1905 LayoutConstraintF parentLayoutConstraint;
1906 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1907 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
1908 textLayoutProperty->UpdateAdaptMinFontSize(ADAPT_MIN_FONT_SIZE_VALUE);
1909 textLayoutProperty->UpdateFontSize(ADAPT_MIN_FONT_SIZE_VALUE);
1910 textLayoutProperty->UpdateLineHeight(ADAPT_LINE_HEIGHT_VALUE);
1911
1912 /**
1913 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent function.
1914 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
1915 */
1916 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1917 auto contentSize =
1918 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1919 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1920 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1921 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
1922 }
1923
1924 /**
1925 * @tc.name: TextLayoutAlgorithmTest004
1926 * @tc.desc: test text_layout_algorithm.cpp:Set textHeightAdaptivePolicy to LAYOUT_CONSTRAINT_FIRST and set lineHeight,
1927 * the height of text is bigger than the height of container
1928 * @tc.type: FUNC
1929 */
1930 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest004, TestSize.Level1)
1931 {
1932 /**
1933 * @tc.steps: step1. create textFrameNode.
1934 */
1935 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1936 ASSERT_NE(textFrameNode, nullptr);
1937 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1938 ASSERT_NE(geometryNode, nullptr);
1939 RefPtr<LayoutWrapperNode> layoutWrapper =
1940 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1941 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1942 ASSERT_NE(textPattern, nullptr);
1943 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1944 ASSERT_NE(textLayoutProperty, nullptr);
1945
1946 /**
1947 * @tc.steps: step2. set textLayoutProperty.
1948 */
1949 textLayoutProperty->UpdateContent(CREATE_VALUE);
1950 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST);
1951 LayoutConstraintF parentLayoutConstraint;
1952 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1953 parentLayoutConstraint.maxSize = CONTAINER_LOW_SIZE;
1954 textLayoutProperty->UpdateAdaptMinFontSize(ADAPT_OVER_MIN_FONT_SIZE_VALUE);
1955 textLayoutProperty->UpdateLineHeight(ADAPT_LINE_HEIGHT_VALUE);
1956
1957 /**
1958 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent function.
1959 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
1960 */
1961 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
1962 auto contentSize =
1963 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
1964 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
1965 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
1966 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
1967 }
1968
1969 /**
1970 * @tc.name: TextLayoutAlgorithmTest005
1971 * @tc.desc: test text_layout_algorithm.cpp:Set textHeightAdaptivePolicy to LAYOUT_CONSTRAINT_FIRST and set lineHeight,
1972 * the height of text is bigger than the height of container,set maxlines.
1973 * @tc.type: FUNC
1974 */
1975 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest005, TestSize.Level1)
1976 {
1977 /**
1978 * @tc.steps: step1. create textFrameNode.
1979 */
1980 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1981 ASSERT_NE(textFrameNode, nullptr);
1982 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1983 ASSERT_NE(geometryNode, nullptr);
1984 RefPtr<LayoutWrapperNode> layoutWrapper =
1985 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
1986 auto textPattern = textFrameNode->GetPattern<TextPattern>();
1987 ASSERT_NE(textPattern, nullptr);
1988 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1989 ASSERT_NE(textLayoutProperty, nullptr);
1990
1991 /**
1992 * @tc.steps: step2. set textLayoutProperty.
1993 */
1994 textLayoutProperty->UpdateContent(CREATE_VALUE);
1995 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST);
1996 LayoutConstraintF parentLayoutConstraint;
1997 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
1998 parentLayoutConstraint.maxSize = CONTAINER_LOW_SIZE;
1999 textLayoutProperty->UpdateAdaptMinFontSize(ADAPT_OVER_MIN_FONT_SIZE_VALUE);
2000 textLayoutProperty->UpdateLineHeight(ADAPT_LINE_HEIGHT_VALUE);
2001 textLayoutProperty->UpdateMaxLines(MAX_LINES);
2002
2003 /**
2004 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent function.
2005 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
2006 */
2007 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
2008 auto contentSize =
2009 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
2010 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
2011 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
2012 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
2013 }
2014
2015 /**
2016 * @tc.name: TextPaintMethodTest001
2017 * @tc.desc: test text_paint_method.cpp :set textOverflow to MARQUEE
2018 * @tc.type: FUNC
2019 */
2020 HWTEST_F(TextTestNg, TextPaintMethodTest001, TestSize.Level1)
2021 {
2022 /**
2023 * @tc.steps: step1. create textFrameNode.
2024 */
2025 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2026 ASSERT_NE(textFrameNode, nullptr);
2027 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2028 ASSERT_NE(geometryNode, nullptr);
2029 RefPtr<LayoutWrapperNode> layoutWrapper =
2030 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2031 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2032 ASSERT_NE(textPattern, nullptr);
2033 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2034 ASSERT_NE(textLayoutProperty, nullptr);
2035
2036 /**
2037 * @tc.steps: step2. set theme.
2038 */
2039 auto pipeline = PipelineContext::GetCurrentContext();
2040 auto theme = AceType::MakeRefPtr<MockThemeManager>();
2041 pipeline->SetThemeManager(theme);
2042 EXPECT_CALL(*theme, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<TextTheme>()));
2043
2044 /**
2045 * @tc.steps: step3. create textPaintMethod and call UpdateContentModifier function.
2046 * @tc.expected: textContentModifier_'s paragraph_ is equal to textPaintMethod's paragraph_.
2047 * The return value of GetOverlayModifier is not null.
2048 */
2049 auto pattern = textFrameNode->GetPattern<Pattern>();
2050 AceType::DynamicCast<TextPattern>(pattern)->textSelector_.Update(0, -1);
2051 ParagraphStyle paragraphStyle;
2052 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2053 RefPtr<TextContentModifier> textContentModifier =
2054 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
2055 RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
2056 TextPaintMethod textPaintMethod(
2057 pattern, paragraph, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
2058 UpdateTextLayoutProperty(textLayoutProperty);
2059 RefPtr<RenderContext> renderContext = RenderContext::Create();
2060 auto paintProperty = textPattern->CreatePaintProperty();
2061 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
2062 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
2063 SetPaintMethodModifier(textPaintMethod);
2064 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
2065 textPaintMethod.textContentModifier_->textDecoration_ = TextDecoration::UNDERLINE;
2066 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
2067 EXPECT_EQ(textPaintMethod.textContentModifier_->paragraph_, textPaintMethod.paragraph_);
2068 ASSERT_NE(textPaintMethod.GetOverlayModifier(AceType::RawPtr(paintWrapper)), nullptr);
2069 }
2070
2071 /**
2072 * @tc.name: TextContentModifier001
2073 * @tc.desc: test text_content_modifier.cpp onDraw function.
2074 * @tc.type: FUNC
2075 */
2076 HWTEST_F(TextTestNg, TextContentModifier001, TestSize.Level1)
2077 {
2078 /**
2079 * @tc.steps: step1. create textFrameNode.
2080 */
2081 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2082 ASSERT_NE(textFrameNode, nullptr);
2083 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2084 ASSERT_NE(geometryNode, nullptr);
2085 RefPtr<LayoutWrapperNode> layoutWrapper =
2086 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2087 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2088 ASSERT_NE(textPattern, nullptr);
2089 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2090 ASSERT_NE(textLayoutProperty, nullptr);
2091
2092 /**
2093 * @tc.steps: step2. call onDraw function.
2094 * @tc.expected: The member variable value of textContentModifier is the value set above
2095 */
2096 auto frameNode = layoutWrapper->GetHostNode();
2097 auto pipeline = frameNode->GetContext();
2098 TextStyle textStyle = CreateTextStyleUsingTheme(
2099 textLayoutProperty->GetFontStyle(), textLayoutProperty->GetTextLineStyle(), pipeline->GetTheme<TextTheme>());
2100 TextContentModifier textContentModifier(std::optional<TextStyle>(std::move(textStyle)));
2101 textStyle.SetTextDecorationColor(TEXT_COLOR_VALUE);
2102 SetContentModifier(textContentModifier);
2103 auto pattern = textFrameNode->GetPattern<Pattern>();
2104 ParagraphStyle paragraphStyle;
2105 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2106 RefPtr<TextContentModifier> contentModifier =
2107 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
2108 RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
2109 TextPaintMethod textPaintMethod(pattern, paragraph, BASE_LINE_OFFSET_VALUE, contentModifier, textOverlayModifier);
2110 // set pipelineContext nullptr
2111 MockPipelineBase::TearDown();
2112 textContentModifier.SetFontSize(ADAPT_FONT_SIZE_VALUE);
2113 textContentModifier.SetBaselineOffset(BASELINE_OFFSET_VALUE);
2114 MockPipelineBase::SetUp();
2115 Testing::MockCanvas canvas;
2116 EXPECT_CALL(canvas, ClipRect(_, _)).WillRepeatedly(Return());
2117 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
2118 textContentModifier.SetParagraph(paragraph);
2119 // call onDraw function(textRacing_ = true)
2120 textContentModifier.StartTextRace();
2121 context.width = CONTEXT_LARGE_WIDTH_VALUE;
2122 textContentModifier.onDraw(context);
2123 // call onDraw function(textRacing_ = false)
2124 textContentModifier.StopTextRace();
2125 textContentModifier.onDraw(context);
2126 EXPECT_EQ(textContentModifier.fontSizeFloat_->Get(), ADAPT_FONT_SIZE_VALUE.Value());
2127 EXPECT_EQ(textContentModifier.baselineOffsetFloat_->Get(), BASELINE_OFFSET_VALUE.Value());
2128 EXPECT_EQ(textContentModifier.paragraph_, paragraph);
2129 }
2130
2131 /**
2132 * @tc.name: TextContentModifier002
2133 * @tc.desc: test text_content_modifier.cpp ModifyTextStyle function.
2134 * @tc.type: FUNC
2135 */
2136 HWTEST_F(TextTestNg, TextContentModifier002, TestSize.Level1)
2137 {
2138 /**
2139 * @tc.steps: step1. create textFrameNode.
2140 */
2141 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2142 ASSERT_NE(textFrameNode, nullptr);
2143 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2144 ASSERT_NE(geometryNode, nullptr);
2145 RefPtr<LayoutWrapperNode> layoutWrapper =
2146 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2147 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2148 ASSERT_NE(textPattern, nullptr);
2149 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2150 ASSERT_NE(textLayoutProperty, nullptr);
2151
2152 /**
2153 * @tc.steps: step2. call ModifyTextStyle function.
2154 * @tc.expected: The member variable value of textContentModifier is the value set above
2155 */
2156 auto frameNode = layoutWrapper->GetHostNode();
2157 auto pipeline = frameNode->GetContext();
2158 TextStyle textStyle = CreateTextStyleUsingTheme(
2159 textLayoutProperty->GetFontStyle(), textLayoutProperty->GetTextLineStyle(), pipeline->GetTheme<TextTheme>());
2160 TextContentModifier textContentModifier(std::optional<TextStyle>(std::move(textStyle)));
2161 textStyle.SetTextDecorationColor(TEXT_COLOR_VALUE);
2162 SetContentModifier(textContentModifier);
2163 auto pattern = textFrameNode->GetPattern<Pattern>();
2164 ParagraphStyle paragraphStyle;
2165 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2166 RefPtr<TextContentModifier> contentModifier =
2167 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
2168 RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
2169 TextPaintMethod textPaintMethod(pattern, paragraph, BASE_LINE_OFFSET_VALUE, contentModifier, textOverlayModifier);
2170 // set pipelineContext nullptr
2171 MockPipelineBase::TearDown();
2172 textContentModifier.SetFontSize(ADAPT_FONT_SIZE_VALUE);
2173 textContentModifier.SetBaselineOffset(BASELINE_OFFSET_VALUE);
2174 MockPipelineBase::SetUp();
2175 // set textDecorationAnimatable_ true
2176 textContentModifier.textDecorationAnimatable_ = true;
2177 textContentModifier.textDecoration_ = TextDecoration::UNDERLINE;
2178 textContentModifier.SetTextDecoration(TextDecoration::NONE);
2179 textContentModifier.ModifyTextStyle(textStyle);
2180 // set textDecorationColorAlpha_ value
2181 textContentModifier.textDecorationColorAlpha_ = AceType::MakeRefPtr<AnimatablePropertyFloat>(1000.0f);
2182 textContentModifier.ModifyTextStyle(textStyle);
2183 // set textDecorationAnimatable_ false
2184 textContentModifier.SetTextDecoration(TextDecoration::LINE_THROUGH);
2185 textContentModifier.ModifyTextStyle(textStyle);
2186 EXPECT_EQ(textContentModifier.fontSizeFloat_->Get(), ADAPT_FONT_SIZE_VALUE.Value());
2187 EXPECT_EQ(textContentModifier.baselineOffsetFloat_->Get(), BASELINE_OFFSET_VALUE.Value());
2188 EXPECT_EQ(textStyle.GetFontSize().Value(), textContentModifier.fontSizeFloat_->Get());
2189 }
2190
2191 /**
2192 * @tc.name: TextLayoutAlgorithmTest006
2193 * @tc.desc: text_layout_algorithm.cpp:Set TextOverflow to MARQUEE
2194 * @tc.type: FUNC
2195 */
2196 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest006, TestSize.Level1)
2197 {
2198 /**
2199 * @tc.steps: step1. create textFrameNode.
2200 */
2201 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2202 ASSERT_NE(textFrameNode, nullptr);
2203 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2204 ASSERT_NE(geometryNode, nullptr);
2205 RefPtr<LayoutWrapperNode> layoutWrapper =
2206 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2207 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2208 ASSERT_NE(textPattern, nullptr);
2209 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2210 ASSERT_NE(textLayoutProperty, nullptr);
2211
2212 /**
2213 * @tc.steps: step2. set textLayoutProperty.
2214 */
2215 textLayoutProperty->UpdateContent(CREATE_VALUE);
2216 LayoutConstraintF parentLayoutConstraint;
2217 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
2218 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
2219 textLayoutProperty->UpdateTextOverflow(TextOverflow::MARQUEE);
2220
2221 /**
2222 * @tc.steps: step3. create textLayoutAlgorithm and call MeasureContent function.
2223 * @tc.expected: The width of the return value of MeasureContent is equal to 100.0f
2224 */
2225 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
2226 auto contentSize =
2227 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
2228 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
2229 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
2230 EXPECT_EQ(contentSize.value().Width(), 100.0f);
2231 }
2232
2233 /**
2234 * @tc.name: TextLayoutAlgorithmTest007
2235 * @tc.desc: text_layout_algorithm.cpp:set TextHeightAdaptivePolicy to LAYOUT_CONSTRAINT_FIRST and set minFontSize to
2236 * zero. ADAPT_ZERO_FONT_SIZE_VALUE
2237 * @tc.type: FUNC
2238 */
2239 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest007, TestSize.Level1)
2240 {
2241 /**
2242 * @tc.steps: step1. create textFrameNode.
2243 */
2244 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2245 ASSERT_NE(textFrameNode, nullptr);
2246 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2247 ASSERT_NE(geometryNode, nullptr);
2248 RefPtr<LayoutWrapperNode> layoutWrapper =
2249 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2250 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2251 ASSERT_NE(textPattern, nullptr);
2252 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2253 ASSERT_NE(textLayoutProperty, nullptr);
2254
2255 /**
2256 * @tc.steps: step2. set textLayoutProperty.
2257 */
2258 textLayoutProperty->UpdateContent(CREATE_VALUE);
2259 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST);
2260 LayoutConstraintF parentLayoutConstraint;
2261 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
2262 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
2263 textLayoutProperty->UpdateAdaptMinFontSize(ADAPT_ZERO_FONT_SIZE_VALUE);
2264 textLayoutProperty->UpdateLineHeight(ADAPT_LINE_HEIGHT_VALUE);
2265 textLayoutProperty->UpdateMaxLines(MAX_LINES);
2266
2267 /**
2268 * @tc.steps: step3. create textLayoutAlgorithm.
2269 * @tc.expected: The width of the return value of MeasureContent is equal to maxWidth of paragraph_
2270 */
2271 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
2272 auto contentSize =
2273 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
2274 textLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
2275 textLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
2276 EXPECT_EQ(contentSize.value().Width(), textLayoutAlgorithm->paragraph_->GetMaxWidth());
2277 }
2278
2279 /**
2280 * @tc.name: TextLayoutAlgorithmTest008
2281 * @tc.desc: text_layout_algorithm.cpp:call AdaptMaxTextSize
2282 * @tc.type: FUNC
2283 */
2284 HWTEST_F(TextTestNg, TextLayoutAlgorithmTest008, TestSize.Level1)
2285 {
2286 /**
2287 * @tc.steps: step1. create textFrameNode.
2288 */
2289 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2290 ASSERT_NE(textFrameNode, nullptr);
2291 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2292 ASSERT_NE(geometryNode, nullptr);
2293 RefPtr<LayoutWrapperNode> layoutWrapper =
2294 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2295 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2296 ASSERT_NE(textPattern, nullptr);
2297 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2298 ASSERT_NE(textLayoutProperty, nullptr);
2299
2300 auto frameNode = layoutWrapper->GetHostNode();
2301 auto pipeline = frameNode->GetContext();
2302 TextStyle textStyle = CreateTextStyleUsingTheme(
2303 textLayoutProperty->GetFontStyle(), textLayoutProperty->GetTextLineStyle(), pipeline->GetTheme<TextTheme>());
2304 textStyle.SetAdaptFontSizeStep(ADAPT_FONT_SIZE_STEP_VALUE);
2305
2306 /**
2307 * @tc.steps: step2. create textLayoutAlgorithm and call AdaptMaxTextSize.
2308 * @tc.expected: when maxFontSize < minFontSize,The return value of AdaptMaxTextSize is false.
2309 * when create paragraph failed,The return value of AdaptMaxTextSize is false.
2310 * when increase font size,The return value of AdaptMaxTextSize is true.
2311 * when set NormalizeToPx false,The return value of AdaptMaxTextSize is false.
2312 */
2313 LayoutConstraintF parentLayoutConstraint;
2314 parentLayoutConstraint.selfIdealSize.SetSize(TEXT_SIZE);
2315 parentLayoutConstraint.maxSize = CONTAINER_SIZE;
2316 auto textLayoutAlgorithm = AceType::MakeRefPtr<TextLayoutAlgorithm>();
2317
2318 MockTxtParagraph::SetCanConstruct(false);
2319
2320 // maxFontSize < minFontSize
2321 textStyle.SetAdaptMaxFontSize(ADAPT_MIN_FONT_SIZE_VALUE);
2322 textStyle.SetAdaptMinFontSize(ADAPT_MAX_FONT_SIZE_VALUE);
2323 EXPECT_EQ(
2324 textLayoutAlgorithm->AdaptMaxTextSize(textStyle, "abc", parentLayoutConstraint, pipeline, nullptr), false);
2325
2326 // create paragraph failed
2327 textStyle.SetAdaptMaxFontSize(ADAPT_MAX_FONT_SIZE_VALUE);
2328 textStyle.SetAdaptMinFontSize(ADAPT_MIN_FONT_SIZE_VALUE);
2329 EXPECT_EQ(
2330 textLayoutAlgorithm->AdaptMaxTextSize(textStyle, "abc", parentLayoutConstraint, pipeline, nullptr), false);
2331
2332 MockTxtParagraph::SetCanConstruct(true);
2333
2334 // increase font size
2335 std::vector<bool> didExceedMaxLines = { false, true };
2336 MockTxtParagraph::SetDidExceedMaxLines(didExceedMaxLines);
2337 EXPECT_EQ(textLayoutAlgorithm->AdaptMaxTextSize(textStyle, "abc", parentLayoutConstraint, pipeline, nullptr), true);
2338 didExceedMaxLines.clear();
2339 MockTxtParagraph::SetDidExceedMaxLines(didExceedMaxLines);
2340
2341 // set NormalizeToPx false
2342 textStyle.adaptFontSizeStep_.SetUnit(DimensionUnit::CALC);
2343 EXPECT_EQ(
2344 textLayoutAlgorithm->AdaptMaxTextSize(textStyle, "abc", parentLayoutConstraint, pipeline, nullptr), false);
2345 }
2346
2347 /**
2348 * @tc.name: TextOverlayModifierTest001
2349 * @tc.desc: test text_overlay_modifier.cpp.
2350 * @tc.type: FUNC
2351 */
2352 HWTEST_F(TextTestNg, TextOverlayModifierTest001, TestSize.Level1)
2353 {
2354 /**
2355 * @tc.steps: step1. create textOverlayModifier and call text_overlay_modifier.cpp function.
2356 * @tc.expected: The member variable value of textOverlayModifier is the value set above
2357 */
2358 TextOverlayModifier textOverlayModifier;
2359 OffsetF paintOffset;
2360 textOverlayModifier.SetPrintOffset(paintOffset);
2361 textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
2362 std::vector<Rect> rectList;
2363 rectList.push_back(Rect(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
2364 textOverlayModifier.SetSelectedRects(rectList);
2365 // change selectedRects_ and call IsSelectedRectsChanged function
2366 Rect secondRect(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE);
2367 textOverlayModifier.selectedRects_[0] = secondRect;
2368 Testing::MockCanvas canvas;
2369 EXPECT_CALL(canvas, Save()).WillRepeatedly(Return());
2370 EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
2371 EXPECT_CALL(canvas, DrawRect(_)).WillRepeatedly(Return());
2372 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
2373 EXPECT_CALL(canvas, Restore()).WillRepeatedly(Return());
2374 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
2375 RectF contentRect;
2376 textOverlayModifier.SetContentRect(contentRect);
2377 textOverlayModifier.onDraw(context);
2378 EXPECT_EQ(textOverlayModifier.paintOffset_->Get(), paintOffset);
2379 EXPECT_EQ(textOverlayModifier.selectedColor_->Get(), SELECTED_COLOR);
2380 EXPECT_EQ(textOverlayModifier.IsSelectedRectsChanged(rectList), true);
2381 EXPECT_EQ(textOverlayModifier.contentRect_, contentRect);
2382 }
2383
2384 /**
2385 * @tc.name: TextPaintMethodTest002
2386 * @tc.desc: test text_paint_method.cpp without setting textOverflow
2387 * @tc.type: FUNC
2388 */
2389 HWTEST_F(TextTestNg, TextPaintMethodTest002, TestSize.Level1)
2390 {
2391 /**
2392 * @tc.steps: step1. create textFrameNode and textLayoutProperty.
2393 */
2394 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2395 ASSERT_NE(textFrameNode, nullptr);
2396 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2397 ASSERT_NE(geometryNode, nullptr);
2398 RefPtr<LayoutWrapperNode> layoutWrapper =
2399 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2400 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2401 ASSERT_NE(textPattern, nullptr);
2402 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2403 ASSERT_NE(textLayoutProperty, nullptr);
2404
2405 /**
2406 * @tc.steps: step2. create textPaintMethod and update textLayoutProperty.
2407 */
2408 auto pattern = textFrameNode->GetPattern<Pattern>();
2409 ParagraphStyle paragraphStyle;
2410 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2411 RefPtr<TextContentModifier> textContentModifier =
2412 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
2413 RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
2414 TextPaintMethod textPaintMethod(
2415 pattern, paragraph, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
2416 textLayoutProperty->UpdateFontSize(ADAPT_FONT_SIZE_VALUE);
2417 textLayoutProperty->UpdateFontWeight(Ace::FontWeight::W200);
2418 textLayoutProperty->UpdateTextColor(TEXT_COLOR_VALUE);
2419 Shadow textShadow;
2420 textShadow.SetBlurRadius(BLURRADIUS_VALUE);
2421 textShadow.SetColor(TEXT_COLOR_VALUE);
2422 textShadow.SetSpreadRadius(SPREADRADIUS_VALUE);
2423 textShadow.SetOffsetX(ADAPT_OFFSETX_VALUE);
2424 textShadow.SetOffsetY(ADAPT_OFFSETY_VALUE);
2425 textLayoutProperty->UpdateTextShadow(textShadow);
2426 textLayoutProperty->UpdateTextDecorationColor(TEXT_COLOR_VALUE);
2427 textLayoutProperty->UpdateTextDecoration(TextDecoration::OVERLINE);
2428 textLayoutProperty->UpdateBaselineOffset(ADAPT_BASE_LINE_OFFSET_VALUE);
2429
2430 /**
2431 * @tc.steps: step3. call UpdateContentModifier,UpdateOverlayModifier and GetOverlayModifier.
2432 * @tc.expected: The return value of GetOverlayModifier is not empty
2433 */
2434 RefPtr<RenderContext> renderContext = RenderContext::Create();
2435 auto paintProperty = textPattern->CreatePaintProperty();
2436 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
2437 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
2438 textPaintMethod.UpdateOverlayModifier(AceType::RawPtr(paintWrapper));
2439 auto OverlayModifier = textPaintMethod.GetOverlayModifier(AceType::RawPtr(paintWrapper));
2440 ASSERT_NE(OverlayModifier, nullptr);
2441 }
2442
2443 /**
2444 * @tc.name: TextAccessibilityPropertyGetText001
2445 * @tc.desc: Test GetText of text.
2446 * @tc.type: FUNC
2447 */
2448 HWTEST_F(TextTestNg, TextAccessibilityPropertyGetText001, TestSize.Level1)
2449 {
2450 TextModelNG textModel;
2451 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
2452 ASSERT_NE(frameNode, nullptr);
2453 auto textPattern = frameNode->GetPattern<TextPattern>();
2454 ASSERT_NE(textPattern, nullptr);
2455 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
2456 ASSERT_NE(textAccessibilityProperty, nullptr);
2457
2458 auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
2459 ASSERT_NE(textLayoutProperty, nullptr);
2460 textLayoutProperty->UpdateContent(CREATE_VALUE);
2461 EXPECT_EQ(textAccessibilityProperty->GetText(), CREATE_VALUE);
2462
2463 auto spanNode = SpanNode::GetOrCreateSpanNode(ElementRegister::GetInstance()->MakeUniqueId());
2464 frameNode->AddChild(spanNode);
2465 textPattern->textForDisplay_ = TEXT_CONTENT;
2466 EXPECT_EQ(textAccessibilityProperty->GetText(), TEXT_CONTENT);
2467 }
2468
2469 /**
2470 * @tc.name: TextAccessibilityPropertyIsSelected001
2471 * @tc.desc: Test IsSelected of text.
2472 * @tc.type: FUNC
2473 */
2474 HWTEST_F(TextTestNg, TextAccessibilityPropertyIsSelected001, TestSize.Level1)
2475 {
2476 TextModelNG textModel;
2477 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
2478 ASSERT_NE(frameNode, nullptr);
2479 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
2480 ASSERT_NE(textAccessibilityProperty, nullptr);
2481 EXPECT_FALSE(textAccessibilityProperty->IsSelected());
2482 textAccessibilityProperty->SetSelected(true);
2483 EXPECT_TRUE(textAccessibilityProperty->IsSelected());
2484 }
2485
2486 /**
2487 * @tc.name: TextAccessibilityPropertyGetTextSelectionStart001
2488 * @tc.desc: Test GetTextSelectionStart of text.
2489 * @tc.type: FUNC
2490 */
2491 HWTEST_F(TextTestNg, TextAccessibilityPropertyGetTextSelectionStart001, TestSize.Level1)
2492 {
2493 TextModelNG textModel;
2494 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
2495 ASSERT_NE(frameNode, nullptr);
2496 auto textPattern = frameNode->GetPattern<TextPattern>();
2497 ASSERT_NE(textPattern, nullptr);
2498 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
2499 ASSERT_NE(textAccessibilityProperty, nullptr);
2500 EXPECT_EQ(textAccessibilityProperty->GetTextSelectionStart(), TEXT_ERROR);
2501 textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
2502 EXPECT_EQ(textAccessibilityProperty->GetTextSelectionStart(), 0);
2503 }
2504
2505 /**
2506 * @tc.name: TextAccessibilityPropertyGetTextSelectionEnd001
2507 * @tc.desc: Test GetTextSelectionEnd of text.
2508 * @tc.type: FUNC
2509 */
2510 HWTEST_F(TextTestNg, TextAccessibilityPropertyGetTextSelectionEnd001, TestSize.Level1)
2511 {
2512 TextModelNG textModel;
2513 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
2514 ASSERT_NE(frameNode, nullptr);
2515 auto textPattern = frameNode->GetPattern<TextPattern>();
2516 ASSERT_NE(textPattern, nullptr);
2517 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
2518 ASSERT_NE(textAccessibilityProperty, nullptr);
2519 EXPECT_EQ(textAccessibilityProperty->GetTextSelectionEnd(), TEXT_ERROR);
2520 textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
2521 EXPECT_EQ(textAccessibilityProperty->GetTextSelectionEnd(), TEXT_SIZE_INT);
2522 }
2523
2524 /**
2525 * @tc.name: TextAccessibilityPropertyGetSupportAction001
2526 * @tc.desc: Test GetSupportAction of text.
2527 * @tc.type: FUNC
2528 */
2529 HWTEST_F(TextTestNg, TextAccessibilityPropertyGetSupportAction001, TestSize.Level1)
2530 {
2531 TextModelNG textModel;
2532 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
2533 ASSERT_NE(frameNode, nullptr);
2534 auto textPattern = frameNode->GetPattern<TextPattern>();
2535 ASSERT_NE(textPattern, nullptr);
2536 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
2537 ASSERT_NE(textAccessibilityProperty, nullptr);
2538 auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
2539 ASSERT_NE(textLayoutProperty, nullptr);
2540 textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
2541 textAccessibilityProperty->ResetSupportAction();
2542 std::unordered_set<AceAction> supportAceActions = textAccessibilityProperty->GetSupportAction();
2543 uint64_t actions = 0, expectActions = 0;
2544 expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_COPY);
2545 expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SET_SELECTION);
2546 expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_CLEAR_SELECTION);
2547 for (auto action : supportAceActions) {
2548 actions |= 1UL << static_cast<uint32_t>(action);
2549 }
2550 EXPECT_EQ(actions, expectActions);
2551 }
2552
2553 /**
2554 * @tc.name: TextModelNgTest001
2555 * @tc.desc: test text_model_ng.cpp SetHeightAdaptivePolicy and SetTextShadow
2556 * @tc.type: FUNC
2557 */
2558 HWTEST_F(TextTestNg, TextModelNgTest001, TestSize.Level1)
2559 {
2560 /**
2561 * @tc.steps: step1. create textFrameNode.
2562 */
2563 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2564 ASSERT_NE(textFrameNode, nullptr);
2565 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2566 ASSERT_NE(textPattern, nullptr);
2567 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2568 ASSERT_NE(textLayoutProperty, nullptr);
2569
2570 /**
2571 * @tc.steps: step2. call SetHeightAdaptivePolicy and SetTextShadow.
2572 * @tc.expected: The HeightAdaptivePolicyValue of textLayoutProperty is MAX_LINES_FIRST.
2573 * The TextShadowValue of textLayoutProperty is textShadow.
2574 */
2575 TextModelNG text;
2576 text.Create("text");
2577 text.SetHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
2578 Shadow textShadow;
2579 text.SetTextShadow(textShadow);
2580 EXPECT_EQ(textLayoutProperty->GetHeightAdaptivePolicyValue(TextHeightAdaptivePolicy::MAX_LINES_FIRST),
2581 TextHeightAdaptivePolicy::MAX_LINES_FIRST);
2582 EXPECT_EQ(textLayoutProperty->GetTextShadowValue(textShadow), textShadow);
2583 }
2584
2585 /**
2586 * @tc.name: TextPatternTest001
2587 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2588 * @tc.type: FUNC
2589 */
2590 HWTEST_F(TextTestNg, TextPatternTest001, TestSize.Level1)
2591 {
2592 /**
2593 * @tc.steps: step1. create textFrameNode and textPattern.
2594 */
2595 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2596 ASSERT_NE(textFrameNode, nullptr);
2597 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2598 ASSERT_NE(textPattern, nullptr);
2599
2600 /**
2601 * @tc.steps: step2. call CreateNodePaintMethod function.
2602 * @tc.expected: The return value of CreateNodePaintMethod is not empty.
2603 * textPattern's textContentModifier_ is not empty.
2604 * textPattern's textOverlayModifier_ is not empty.
2605 */
2606 auto nodePaintMethod = textPattern->CreateNodePaintMethod();
2607 ASSERT_NE(nodePaintMethod, nullptr);
2608 ASSERT_NE(textPattern->textContentModifier_, nullptr);
2609 ASSERT_NE(textPattern->textOverlayModifier_, nullptr);
2610 }
2611
2612 /**
2613 * @tc.name: TextPatternTest002
2614 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2615 * @tc.type: FUNC
2616 */
2617 HWTEST_F(TextTestNg, TextPatternTest002, TestSize.Level1)
2618 {
2619 /**
2620 * @tc.steps: step1. create textFrameNode and textPattern.
2621 */
2622 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2623 ASSERT_NE(textFrameNode, nullptr);
2624 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2625 ASSERT_NE(textPattern, nullptr);
2626
2627 /**
2628 * @tc.steps: step2. call CreateLayoutProperty function.
2629 * @tc.expected: The return value of CreateLayoutProperty is not empty.
2630 */
2631 RefPtr<LayoutProperty> textLayoutProperty = textPattern->CreateLayoutProperty();
2632 ASSERT_NE(textLayoutProperty, nullptr);
2633 }
2634
2635 /**
2636 * @tc.name: TextPatternTest003
2637 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2638 * @tc.type: FUNC
2639 */
2640 HWTEST_F(TextTestNg, TextPatternTest003, TestSize.Level1)
2641 {
2642 /**
2643 * @tc.steps: step1. create textFrameNode and textPattern.
2644 */
2645 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2646 ASSERT_NE(textFrameNode, nullptr);
2647 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2648 ASSERT_NE(textPattern, nullptr);
2649
2650 /**
2651 * @tc.steps: step2. call CreateLayoutAlgorithm function.
2652 * @tc.expected: The return value of CreateLayoutAlgorithm is not empty.
2653 */
2654 RefPtr<LayoutAlgorithm> textLayoutAlgorithm = textPattern->CreateLayoutAlgorithm();
2655 ASSERT_NE(textLayoutAlgorithm, nullptr);
2656 }
2657
2658 /**
2659 * @tc.name: TextPatternTest004
2660 * @tc.desc: Test the CopyOption value while in Marquee state.
2661 * @tc.type: FUNC
2662 */
2663 HWTEST_F(TextTestNg, TextPatternTest004, TestSize.Level1)
2664 {
2665 /**
2666 * @tc.steps: step1. create textFrameNode and textPattern.
2667 */
2668 auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
2669 ASSERT_NE(textFrameNode, nullptr);
2670 auto textPattern = textFrameNode->GetPattern<TextPattern>();
2671 ASSERT_NE(textPattern, nullptr);
2672
2673 /**
2674 * @tc.steps: step2. set the TextOverflow value to Marquee.
2675 */
2676 auto textLayoutProperty = textFrameNode->GetLayoutProperty<TextLayoutProperty>();
2677 ASSERT_NE(textLayoutProperty, nullptr);
2678 textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
2679 textLayoutProperty->UpdateTextOverflow(TextOverflow::MARQUEE);
2680
2681 /**
2682 * @tc.steps: step3. call OnModifyDone function.
2683 * @tc.expected: The copyOption_ value is equal to CopyOptions::None.
2684 */
2685 textPattern->OnModifyDone();
2686 EXPECT_EQ(textPattern->copyOption_, CopyOptions::None);
2687 }
2688
2689 /**
2690 * @tc.name: CreateParagraph001
2691 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2692 * @tc.type: FUNC
2693 */
2694 HWTEST_F(TextTestNg, CreateParagraph001, TestSize.Level1)
2695 {
2696 TextModelNG textModelNG;
2697 textModelNG.Create(CREATE_VALUE);
2698
2699 auto pattern = AceType::MakeRefPtr<TextPattern>();
2700 ASSERT_NE(pattern, nullptr);
2701 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
2702 ASSERT_NE(frameNode, nullptr);
2703 pattern->AttachToFrameNode(frameNode);
2704
2705 DirtySwapConfig config;
2706 config.skipMeasure = false;
2707 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
2708 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
2709 ASSERT_NE(layoutWrapper, nullptr);
2710 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
2711 TextStyle textStyle;
2712 LayoutConstraintF contentConstraint;
2713 auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", nullptr);
2714 EXPECT_TRUE(ret);
2715 }
2716
2717 /**
2718 * @tc.name: Layout001
2719 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2720 * @tc.type: FUNC
2721 */
2722 HWTEST_F(TextTestNg, Layout001, TestSize.Level1)
2723 {
2724 TextModelNG textModelNG;
2725 textModelNG.Create(CREATE_VALUE);
2726 auto* stack = ViewStackProcessor::GetInstance();
2727 auto nodeId = stack->ClaimNodeId();
2728 auto pattern = AceType::MakeRefPtr<TextPattern>();
2729 ASSERT_NE(pattern, nullptr);
2730 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
2731 ASSERT_NE(frameNode, nullptr);
2732 pattern->AttachToFrameNode(frameNode);
2733
2734 DirtySwapConfig config;
2735 config.skipMeasure = false;
2736 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
2737 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
2738 ASSERT_NE(layoutWrapper, nullptr);
2739
2740 layoutWrapper->children_.push_back(layoutWrapper);
2741 auto imageSpanNode = FrameNode::GetOrCreateFrameNode(
__anonda3610500202() 2742 V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
2743 ASSERT_NE(imageSpanNode, nullptr);
2744 pattern->AddChildSpanItem(imageSpanNode);
2745 frameNode->AddChild(imageSpanNode);
2746 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
2747 TextStyle textStyle;
2748 LayoutConstraintF contentConstraint;
2749 auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", AccessibilityManager::RawPtr(layoutWrapper));
2750 EXPECT_TRUE(ret);
2751 rowLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
2752 frameNode->AddChild(nullptr);
2753 pattern->AddChildSpanItem(nullptr);
2754 rowLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
2755 ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", nullptr);
2756 EXPECT_TRUE(ret);
2757 }
2758
2759 /**
2760 * @tc.name: ApplyIndents001
2761 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2762 * @tc.type: FUNC
2763 */
2764 HWTEST_F(TextTestNg, ApplyIndents001, TestSize.Level1)
2765 {
2766 TextModelNG textModelNG;
2767 textModelNG.Create(CREATE_VALUE);
2768
2769 auto pattern = AceType::MakeRefPtr<TextPattern>();
2770 ASSERT_NE(pattern, nullptr);
2771 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
2772 ASSERT_NE(frameNode, nullptr);
2773 pattern->AttachToFrameNode(frameNode);
2774
2775 DirtySwapConfig config;
2776 config.skipMeasure = false;
2777 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
2778 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
2779 ASSERT_NE(layoutWrapper, nullptr);
2780 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
2781 auto spanNode = AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
2782 TextStyle textStyle;
2783 LayoutConstraintF contentConstraint;
2784 rowLayoutAlgorithm->ApplyIndents(textStyle, RECT_WIDTH_VALUE);
2785 auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", nullptr);
2786 EXPECT_TRUE(ret);
2787 }
2788
2789 /**
2790 * @tc.name: AddChildSpanItem001
2791 * @tc.desc: test text_pattern.h CreateNodePaintMethod function
2792 * @tc.type: FUNC
2793 */
2794 HWTEST_F(TextTestNg, AddChildSpanItem001, TestSize.Level1)
2795 {
2796 TextModelNG textModelNG;
2797 textModelNG.Create(CREATE_VALUE);
2798
2799 auto pattern = AceType::MakeRefPtr<TextPattern>();
2800 ASSERT_NE(pattern, nullptr);
2801 auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
2802 ASSERT_NE(frameNode, nullptr);
2803 pattern->AttachToFrameNode(frameNode);
2804
2805 DirtySwapConfig config;
2806 config.skipMeasure = false;
2807 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
2808 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
2809 ASSERT_NE(layoutWrapper, nullptr);
2810 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
2811 auto spanNode = AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
2812 TextStyle textStyle;
2813 RefPtr<UINode> element = ViewStackProcessor::GetInstance()->Finish();
2814 pattern->AddChildSpanItem(element);
2815 auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", nullptr);
2816 EXPECT_TRUE(ret);
2817 }
2818
2819 /**
2820 * @tc.name: ShowSelectOverlay003
2821 * @tc.desc: test text_pattern.h ShowSelectOverlay function
2822 * @tc.type: FUNC
2823 */
2824 HWTEST_F(TextTestNg, ShowSelectOverlay003, TestSize.Level1)
2825 {
2826 auto [frameNode, pattern] = Init();
2827 GestureEvent info;
2828 info.localLocation_ = Offset(1, 1);
2829 // copyOption = None
2830 pattern->HandleLongPress(info);
2831 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
2832
2833 pattern->copyOption_ = CopyOptions::Distributed;
2834 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
2835 pattern->textForDisplay_ = "test";
2836 pattern->textSelector_.Update(0, 20);
2837
2838 pattern->ShowSelectOverlay(pattern->textSelector_.firstHandle, pattern->textSelector_.secondHandle);
2839 EXPECT_NE(pattern->textSelector_.GetTextStart(), -1);
2840 EXPECT_NE(pattern->textSelector_.GetTextEnd(), -1);
2841 }
2842
2843 /**
2844 * @tc.name: ShowSelectOverlay004
2845 * @tc.desc: test text_pattern.h ShowSelectOverlay function when menuOptionItems_ is not nullptr
2846 * @tc.type: FUNC
2847 */
2848 HWTEST_F(TextTestNg, ShowSelectOverlay004, TestSize.Level1)
2849 {
2850 /**
2851 * @tc.steps: step1. create frameNode and pattern
2852 */
2853 auto [frameNode, pattern] = Init();
2854 GestureEvent info;
2855 info.localLocation_ = Offset(1, 1);
2856 pattern->HandleLongPress(info);
2857 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
2858 /**
2859 * @tc.steps: step2. construct menuOptionItems
2860 */
2861 pattern->copyOption_ = CopyOptions::InApp;
2862 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
2863 pattern->textForDisplay_ = "test";
2864 pattern->textSelector_.Update(0, 20);
2865 std::vector<MenuOptionsParam> menuOptionItems;
2866 MenuOptionsParam menuOptionItem1;
2867 menuOptionItem1.content = "test1";
__anonda3610500302(const std::string&) 2868 menuOptionItem1.action = [](const std::string&) {};
2869 menuOptionItems.emplace_back(menuOptionItem1);
2870 pattern->menuOptionItems_ = menuOptionItems;
2871
2872 /**
2873 * @tc.steps: step2. call ShowSelectOverlay function
2874 * @tc.expected: the property of selectInfo is assigned.
2875 */
2876 pattern->ShowSelectOverlay(pattern->textSelector_.firstHandle, pattern->textSelector_.secondHandle);
2877 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
2878 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
2879 }
2880
2881 /**
2882 * @tc.name: IsDraggable001
2883 * @tc.desc: test text_pattern.h Draggable function
2884 * @tc.type: FUNC
2885 */
2886 HWTEST_F(TextTestNg, IsDraggable001, TestSize.Level1)
2887 {
2888 auto [host, pattern] = Init();
2889
2890 pattern->copyOption_ = CopyOptions::Distributed;
2891 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
2892 host->draggable_ = true;
2893 host->eventHub_->SetOnDragStart(
__anonda3610500402(const RefPtr<Ace::DragEvent>&, const std::string&) 2894 [](const RefPtr<Ace::DragEvent>&, const std::string&) -> DragDropInfo { return {}; });
2895
2896 /**
2897 * @tc.steps: step1. set selected rect to [0, 0] - [20, 20]
2898 * @tc.expected: return true if the location is in region
2899 */
2900 pattern->textSelector_.Update(0, 20);
2901 EXPECT_TRUE(pattern->IsDraggable(Offset(1, 1)));
2902
2903 /**
2904 * @tc.expected: return false if the location is not in region
2905 */
2906 EXPECT_FALSE(pattern->IsDraggable(Offset(21, 21)));
2907
2908 /**
2909 * @tc.steps: step2. text not selected
2910 * @tc.expected: return false
2911 */
2912 pattern->textSelector_.Update(-1);
2913 EXPECT_FALSE(pattern->IsDraggable(Offset(1, 1)));
2914 }
2915
2916 /**
2917 * @tc.name: DragBase001
2918 * @tc.desc: test text_pattern.h DragBase function
2919 * @tc.type: FUNC
2920 */
2921 HWTEST_F(TextTestNg, DragBase001, TestSize.Level1)
2922 {
2923 auto [frameNode, pattern] = Init();
2924
2925 // test ResetSelection should reset textSelector
2926 pattern->CreateHandles();
2927 pattern->textSelector_.Update(0, 20);
2928 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
2929 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
2930 pattern->CloseSelectOverlay();
2931 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
2932 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
2933 pattern->ResetSelection();
2934 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
2935 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
2936
2937 // test GetTextBoxes and GetLineHeight
2938 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
2939 pattern->textSelector_.Update(0, 20);
2940 auto boxes = pattern->GetTextBoxes();
2941 EXPECT_EQ(boxes.size(), 1);
2942 EXPECT_EQ(boxes[0].rect_.GetLeft(), 0);
2943 EXPECT_EQ(boxes[0].rect_.GetRight(), 20);
2944
2945 auto height = pattern->GetLineHeight();
2946 EXPECT_EQ(height, 20);
2947 }
2948
2949 /**
2950 * @tc.name: UpdateChildProperty001
2951 * @tc.desc: test UpdateChildProperty function
2952 * @tc.type: FUNC
2953 */
2954 HWTEST_F(TextTestNg, UpdateChildProperty001, TestSize.Level1)
2955 {
2956 TestProperty testProperty;
2957 testProperty.fontSizeValue = std::make_optional(FONT_SIZE_VALUE);
2958 testProperty.textColorValue = std::make_optional(TEXT_COLOR_VALUE);
2959 testProperty.italicFontStyleValue = std::make_optional(ITALIC_FONT_STYLE_VALUE);
2960 testProperty.fontWeightValue = std::make_optional(FONT_WEIGHT_VALUE);
2961 testProperty.textDecorationValue = std::make_optional(TEXT_DECORATION_VALUE);
2962 testProperty.textDecorationColorValue = std::make_optional(TEXT_DECORATION_COLOR_VALUE);
2963 testProperty.textCaseValue = std::make_optional(TEXT_CASE_VALUE);
2964 testProperty.letterSpacing = std::make_optional(LETTER_SPACING);
2965 testProperty.lineHeightValue = std::make_optional(LINE_HEIGHT_VALUE);
2966 testProperty.fontFamilyValue = std::make_optional(FONT_FAMILY_VALUE);
2967 /**
2968 * @tc.steps: step1. create text FrameNode and SpanNode, Update parent FrameNode properties
2969 * @tc.expected: Successfully created parent Node and child Node
2970 */
2971 auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
2972 ASSERT_NE(host, nullptr);
2973 SpanModelNG spanModelNG;
2974 spanModelNG.Create("span1");
2975 auto firstChild = ViewStackProcessor::GetInstance()->Finish();
2976 spanModelNG.Create("span2");
2977 auto secondChild = ViewStackProcessor::GetInstance()->Finish();
2978
2979 /**
2980 * @tc.steps: step2. SpanNode mount to parent
2981 */
2982 host->AddChild(firstChild);
2983 host->AddChild(secondChild);
2984
2985 /**
2986 * @tc.steps: step3. called BeforeCreateLayoutWrapper function to UpdateChildProperty
2987 * @tc.expected: child count is not empty, Child inherits parent property
2988 */
2989 auto pattern = host->GetPattern<TextPattern>();
2990 ASSERT_NE(pattern, nullptr);
2991 pattern->BeforeCreateLayoutWrapper();
2992 EXPECT_EQ(host->GetChildren().size(), 2);
2993 for (const auto& child : host->GetChildren()) {
2994 auto spanNode = AceType::DynamicCast<SpanNode>(child);
2995 ASSERT_NE(spanNode, nullptr);
2996 EXPECT_EQ(spanNode->GetFontSize().value(), FONT_SIZE_VALUE);
2997 EXPECT_EQ(spanNode->GetTextColor().value(), TEXT_COLOR_VALUE);
2998 EXPECT_EQ(spanNode->GetItalicFontStyle().value(), ITALIC_FONT_STYLE_VALUE);
2999 EXPECT_EQ(spanNode->GetFontWeight().value(), FONT_WEIGHT_VALUE);
3000 EXPECT_EQ(spanNode->GetTextDecoration().value(), TEXT_DECORATION_VALUE);
3001 EXPECT_EQ(spanNode->GetTextDecorationColor().value(), TEXT_DECORATION_COLOR_VALUE);
3002 EXPECT_EQ(spanNode->GetTextCase().value(), TEXT_CASE_VALUE);
3003 EXPECT_EQ(spanNode->GetLetterSpacing().value(), LETTER_SPACING);
3004 EXPECT_EQ(spanNode->GetLineHeight().value(), LINE_HEIGHT_VALUE);
3005 EXPECT_EQ(spanNode->GetFontFamily().value(), FONT_FAMILY_VALUE);
3006 }
3007
3008 /**
3009 * @tc.steps: step4. Update parent fontsize property, called BeforeCreateLayoutWrapper again
3010 * @tc.expected: Child update fontsize property
3011 */
3012 TestUpdateScenario(pattern);
3013 }
3014
3015 /**
3016 * @tc.name: UpdateChildProperty002
3017 * @tc.desc: test UpdateChildProperty function
3018 * @tc.type: FUNC
3019 */
3020 HWTEST_F(TextTestNg, UpdateChildProperty002, TestSize.Level1)
3021 {
3022 TestProperty testProperty;
3023 /**
3024 * @tc.steps: step1. create text FrameNode and SpanNode, Update child FrameNode properties
3025 * @tc.expected: Successfully created parent Node and child Node
3026 */
3027 auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
3028 ASSERT_NE(host, nullptr);
3029 auto firstChild = CreateSpanNodeWithSetDefaultProperty("SPANNODE");
3030 auto secondChild = CreateSpanNodeWithSetDefaultProperty("spanNode");
3031
3032 /**
3033 * @tc.steps: step2. SpanNode mount to parent
3034 */
3035 host->AddChild(firstChild);
3036 host->AddChild(secondChild);
3037
3038 /**
3039 * @tc.steps: step3. called BeforeCreateLayoutWrapper function to UpdateChildProperty
3040 * @tc.expected: child count is not empty, Child use owner property
3041 */
3042 auto pattern = host->GetPattern<TextPattern>();
3043 ASSERT_NE(pattern, nullptr);
3044 pattern->BeforeCreateLayoutWrapper();
3045 EXPECT_EQ(host->GetChildren().size(), 2);
3046 for (const auto& child : host->GetChildren()) {
3047 auto spanNode = AceType::DynamicCast<SpanNode>(child);
3048 ASSERT_NE(spanNode, nullptr);
3049 EXPECT_EQ(spanNode->GetFontSize().value(), FONT_SIZE_VALUE);
3050 EXPECT_EQ(spanNode->GetTextColor().value(), TEXT_COLOR_VALUE);
3051 EXPECT_EQ(spanNode->GetItalicFontStyle().value(), ITALIC_FONT_STYLE_VALUE);
3052 EXPECT_EQ(spanNode->GetFontWeight().value(), FONT_WEIGHT_VALUE);
3053 EXPECT_EQ(spanNode->GetTextDecoration().value(), TEXT_DECORATION_VALUE);
3054 EXPECT_EQ(spanNode->GetTextDecorationColor().value(), TEXT_DECORATION_COLOR_VALUE);
3055 EXPECT_EQ(spanNode->GetTextCase().value(), TEXT_CASE_VALUE);
3056 EXPECT_EQ(spanNode->GetLetterSpacing().value(), LETTER_SPACING);
3057 EXPECT_EQ(spanNode->GetLineHeight().value(), LINE_HEIGHT_VALUE);
3058 EXPECT_EQ(spanNode->GetFontFamily().value(), FONT_FAMILY_VALUE);
3059 }
3060
3061 /**
3062 * @tc.steps: step4. Update parent fontsize property, called BeforeCreateLayoutWrapper again
3063 * @tc.expected: Child use owner property
3064 */
3065 TestUpdateScenario(pattern);
3066 }
3067
3068 /**
3069 * @tc.name: InitSurfaceChangedTest001
3070 * @tc.desc: test InitSurfaceChangedCallback function
3071 * @tc.type: FUNC
3072 */
3073 HWTEST_F(TextTestNg, InitSurfaceChangedTest001, TestSize.Level1)
3074 {
3075 TestProperty testProperty;
3076 /**
3077 * @tc.steps: step1. create text FrameNode and SpanNode, Update child FrameNode properties
3078 * @tc.expected: Successfully created parent Node and child Node
3079 */
3080 auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
3081 ASSERT_NE(host, nullptr);
3082 /**
3083 * @tc.steps: step2. get text pattern called InitSurfaceChangedCallback function.
3084 * @tc.expected: HasSurfaceChangedCallback return true.
3085 */
3086 auto pattern = host->GetPattern<TextPattern>();
3087 pattern->InitSurfaceChangedCallback();
3088 EXPECT_TRUE(pattern->HasSurfaceChangedCallback());
3089 }
3090
3091 /**
3092 * @tc.name: HandleClickEvent001
3093 * @tc.desc: test test_pattern.h HandleClickEvent function with valid textSelector
3094 * @tc.type: FUNC
3095 */
3096 HWTEST_F(TextTestNg, HandleClickEvent001, TestSize.Level1)
3097 {
3098 /**
3099 * @tc.steps: step1. create frameNode and pattern
3100 */
3101 auto [frameNode, pattern] = Init();
3102 pattern->textSelector_.Update(0, 20);
3103
3104 /**
3105 * @tc.steps: step2. create GestureEvent and call HandleClickEvent function
3106 * @tc.expected: selectOverlay is closed
3107 */
3108 GestureEvent info;
3109 info.localLocation_ = Offset(0, 0);
3110 pattern->HandleClickEvent(info);
3111 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
3112 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
3113 }
3114
3115 /**
3116 * @tc.name: HandleClickEvent002
3117 * @tc.desc: test test_pattern.h HandleClickEvent function when spanItemChildren is not nullptr.
3118 * @tc.type: FUNC
3119 */
3120 HWTEST_F(TextTestNg, HandleClickEvent002, TestSize.Level1)
3121 {
3122 /**
3123 * @tc.steps: step1. create frameNode and pattern
3124 */
3125 auto [frameNode, pattern] = Init();
3126
3127 /**
3128 * @tc.steps: step2. construct spanItemChildren
3129 */
3130 std::list<RefPtr<SpanItem>> spanItemChildren;
3131 auto spanItemChild1 = AceType::MakeRefPtr<SpanItem>();
3132 spanItemChildren.emplace_back(spanItemChild1);
3133 pattern->spanItemChildren_ = spanItemChildren;
3134
3135 /**
3136 * @tc.steps: step3. create paragraph
3137 */
3138 ParagraphStyle paragraphStyle;
3139 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3140 ASSERT_NE(paragraph, nullptr);
3141 pattern->paragraph_ = paragraph;
3142
3143 /**
3144 * @tc.steps: step4. create GestureEvent and call HandleClickEvent function with invalid textSelector
3145 * @tc.expected: function run rightly
3146 */
3147 pattern->textSelector_.Update(-2, -2);
3148 GestureEvent info;
3149 info.localLocation_ = Offset(0, 0);
3150 pattern->HandleClickEvent(info);
3151 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -2);
3152 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -2);
3153 }
3154
3155 /**
3156 * @tc.name: HandleMouseEvent001
3157 * @tc.desc: test test_pattern.h HandleMouseEvent function when copyOption is none
3158 * @tc.type: FUNC
3159 */
3160 HWTEST_F(TextTestNg, HandleMouseEvent001, TestSize.Level1)
3161 {
3162 /**
3163 * @tc.steps: step1. create frameNode and pattern
3164 */
3165 auto [frameNode, pattern] = Init();
3166
3167 /**
3168 * @tc.steps: step2.call OnVisibleChange function
3169 * @tc.expected: selectOverlay is closed
3170 */
3171 pattern->CreateHandles();
3172 pattern->textSelector_.Update(0, 20);
3173 pattern->OnVisibleChange(false);
3174 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
3175 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
3176
3177 /**
3178 * @tc.steps: step3. create MouseEvent and call HandleMouseEvent function when copyOption is none
3179 * @tc.expected: selectOverlay is closed
3180 */
3181 MouseInfo info;
3182 info.localLocation_ = Offset(1, 1);
3183 pattern->copyOption_ = copyOption;
3184 pattern->HandleMouseEvent(info);
3185 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
3186 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
3187 }
3188
3189 /**
3190 * @tc.name: HandleMouseEvent002
3191 * @tc.desc: test test_pattern.h HandleMouseEvent function when copyOption is not none
3192 * @tc.type: FUNC
3193 */
3194 HWTEST_F(TextTestNg, HandleMouseEvent002, TestSize.Level1)
3195 {
3196 /**
3197 * @tc.steps: step1. create frameNode and pattern
3198 */
3199 auto [frameNode, pattern] = Init();
3200 pattern->textForDisplay_ = "test";
3201 pattern->textSelector_.Update(0, 3);
3202 pattern->copyOption_ = CopyOptions::InApp;
3203
3204 /**
3205 * @tc.steps: step2. create paragraph
3206 */
3207 ParagraphStyle paragraphStyle;
3208 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3209 ASSERT_NE(paragraph, nullptr);
3210 pattern->paragraph_ = paragraph;
3211
3212 /**
3213 * @tc.steps: step3. create MouseInfo and call HandleMouseEvent function
3214 * @tc.expected: selectOverlay is not closed
3215 */
3216 MouseInfo info;
3217 info.localLocation_ = Offset(2, 2);
3218 info.button_ = MouseButton::RIGHT_BUTTON;
3219 info.action_ = MouseAction::PRESS;
3220 pattern->HandleMouseEvent(info);
3221 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3222 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 1);
3223 }
3224
3225 /**
3226 * @tc.name: HandleOnCopy001
3227 * @tc.desc: test test_pattern.h HandleOnCopy function
3228 * @tc.type: FUNC
3229 */
3230 HWTEST_F(TextTestNg, HandleOnCopy001, TestSize.Level1)
3231 {
3232 /**
3233 * @tc.steps: step1. create frameNode and pattern
3234 */
3235 auto [frameNode, pattern] = Init();
3236
3237 /**
3238 * @tc.steps: step2. call HandleOnCopy function when textSelector is valid and textStart is equal to textEnd
3239 * @tc.steps: step3. call HandleOnCopy function when textSelector is not valid and textStart < 0
3240 * @tc.expected: selectOverlay is closed
3241 */
3242 std::vector<std::vector<int32_t>> params = { { 2, 2 }, { -1, 20 } };
3243 for (int turn = 0; turn < params.size(); turn++) {
3244 pattern->textSelector_.Update(params[turn][0], params[turn][1]);
3245 pattern->HandleOnCopy();
3246 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
3247 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
3248 }
3249 }
3250
3251 /**
3252 * @tc.name: HandleOnCopy002
3253 * @tc.desc: test test_pattern.h HandleOnCopy function
3254 * @tc.type: FUNC
3255 */
3256 HWTEST_F(TextTestNg, HandleOnCopy002, TestSize.Level1)
3257 {
3258 /**
3259 * @tc.steps: step1. create frameNode and pattern
3260 */
3261 auto [frameNode, pattern] = Init();
3262
3263 /**
3264 * @tc.steps: step2. call HandleOnCopy function with valid textSelector and copyOption
3265 * @tc.expected: selectOverlay is closed
3266 */
3267 pattern->textSelector_.Update(0, 6);
3268 pattern->textForDisplay_ = "TestHandleOnCopy";
3269 pattern->copyOption_ = CopyOptions::InApp;
3270 pattern->HandleOnCopy();
3271 EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
3272 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
3273 }
3274
3275 /**
3276 * @tc.name: HandlePanStart001
3277 * @tc.desc: test text_pattern.h HandlePanStart function when IsDraggable is false
3278 * @tc.type: FUNC
3279 */
3280 HWTEST_F(TextTestNg, HandlePanStart001, TestSize.Level1)
3281 {
3282 /**
3283 * @tc.steps: step1. create frameNode and pattern
3284 */
3285 auto [frameNode, pattern] = Init();
3286 pattern->copyOption_ = copyOption;
3287 pattern->textSelector_.Update(0, 20);
3288 GestureEvent info;
3289 info.localLocation_ = Offset(1, 1);
3290 /**
3291 * @tc.steps: step2. call HandlePanStart function
3292 * @tc.expected: The function exits normally
3293 */
3294 pattern->HandlePanStart(info);
3295 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3296 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
3297 }
3298
3299 /**
3300 * @tc.name: HandlePanStart002
3301 * @tc.desc: test text_pattern.h HandlePanStart function when IsDraggable is true
3302 * @tc.type: FUNC
3303 */
3304 HWTEST_F(TextTestNg, HandlePanStart002, TestSize.Level1)
3305 {
3306 /**
3307 * @tc.steps: step1. create frameNode and pattern
3308 */
3309 auto [frameNode, pattern] = Init();
3310 frameNode->draggable_ = true;
3311 pattern->copyOption_ = CopyOptions::InApp;
3312 pattern->textSelector_.Update(0, 3);
3313 pattern->textForDisplay_ = TEXT_CONTENT;
3314 pattern->selectOverlayProxy_ = nullptr;
3315 GestureEvent info;
3316 info.localLocation_ = Offset(1.0, 1.0);
3317
3318 /**
3319 * @tc.steps: step2. create paragraph
3320 */
3321 ParagraphStyle paragraphStyle;
3322 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3323 ASSERT_NE(paragraph, nullptr);
3324 pattern->paragraph_ = paragraph;
3325
3326 /**
3327 * @tc.steps: step3. call HandlePanStart function
3328 * @tc.expected: The function exits normally
3329 */
3330 pattern->HandlePanStart(info);
3331 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3332 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
3333 }
3334
3335 /**
3336 * @tc.name: HandleLongPress001
3337 * @tc.desc: test text_pattern.h HandleLongPress function when IsDraggable is false
3338 * @tc.type: FUNC
3339 */
3340 HWTEST_F(TextTestNg, HandleLongPress001, TestSize.Level1)
3341 {
3342 /**
3343 * @tc.steps: step1. create frameNode and pattern
3344 */
3345 auto [frameNode, pattern] = Init();
3346 frameNode->draggable_ = false;
3347 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
3348 pattern->copyOption_ = CopyOptions::InApp;
3349 pattern->textSelector_.Update(0, 3);
3350 pattern->textForDisplay_ = TEXT_CONTENT;
3351 GestureEvent info;
3352 info.localLocation_ = Offset(1, 1);
3353 EXPECT_FALSE(pattern->IsDraggable(info.GetLocalLocation()));
3354
3355 /**
3356 * @tc.steps: step2. call HandleLongPress function
3357 * @tc.expected: The function exits normally
3358 */
3359 pattern->HandleLongPress(info);
3360 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3361 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 1);
3362 }
3363
3364 /**
3365 * @tc.name: HandleLongPress002
3366 * @tc.desc: test text_pattern.h HandleLongPress function when IsDraggable is true
3367 * @tc.type: FUNC
3368 */
3369 HWTEST_F(TextTestNg, HandleLongPress002, TestSize.Level1)
3370 {
3371 /**
3372 * @tc.steps: step1. create frameNode and pattern
3373 */
3374 auto [frameNode, pattern] = Init();
3375
3376 frameNode->draggable_ = true;
3377 frameNode->eventHub_->SetOnDragStart(
__anonda3610500502(const RefPtr<Ace::DragEvent>&, const std::string&) 3378 [](const RefPtr<Ace::DragEvent>&, const std::string&) -> DragDropInfo { return {}; });
3379 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
3380 pattern->copyOption_ = CopyOptions::InApp;
3381 pattern->textSelector_.Update(0, 3);
3382 pattern->textForDisplay_ = TEXT_CONTENT;
3383 GestureEvent info;
3384 info.localLocation_ = Offset(1, 1);
3385 /**
3386 * @tc.steps: step2. call HandleLongPress function
3387 * @tc.expected: The function exits normally
3388 */
3389 pattern->HandleLongPress(info);
3390 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3391 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
3392 }
3393
3394 /**
3395 * @tc.name: HandlePanUpdateAndEnd001
3396 * @tc.desc: test text_pattern.h HandlePanUpdate function
3397 * @tc.type: FUNC
3398 */
3399 HWTEST_F(TextTestNg, HandlePanUpdateAndEnd001, TestSize.Level1)
3400 {
3401 /**
3402 * @tc.steps: step1. create frameNode and pattern
3403 */
3404 auto [frameNode, pattern] = Init();
3405 pattern->copyOption_ = CopyOptions::InApp;
3406 pattern->textSelector_.Update(0, 20);
3407 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
3408 GestureEvent info;
3409 info.localLocation_ = Offset(1, 1);
3410
3411 /**
3412 * @tc.steps: step2. construct dragWindow_
3413 */
3414 auto host = pattern->GetHost();
3415 ASSERT_NE(host, nullptr);
3416 auto pipelineContext = host->GetContext();
3417 ASSERT_NE(pipelineContext, nullptr);
3418 auto rect = pipelineContext->GetCurrentWindowRect();
3419 auto contentRect_ = CONTENT_RECT;
3420 // create textdrag window
3421 auto dragWindow = DragWindow::CreateTextDragWindow("APP_DRAG_WINDOW",
3422 static_cast<int32_t>(host->GetPaintRectOffset().GetX() + rect.Left()),
3423 static_cast<int32_t>(host->GetPaintRectOffset().GetY() + rect.Top()),
3424 static_cast<int32_t>(contentRect_.Width() + contentRect_.GetX()), contentRect_.Height() + contentRect_.GetY());
3425
3426 pattern->dragWindow_ = dragWindow;
3427
3428 /**
3429 * @tc.steps: step3. call HandlePanUpdate function
3430 * @tc.expected: The function exits normally
3431 */
3432 pattern->HandlePanUpdate(info);
3433 EXPECT_NE(pattern->textSelector_.GetTextStart(), -1);
3434 EXPECT_NE(pattern->textSelector_.GetTextEnd(), -1);
3435
3436 /**
3437 * @tc.steps: step4. construct dragProxy_
3438 */
3439 // draw select text on drag window
3440 pattern->dragWindow_->DrawTextNG(pattern->paragraph_, pattern);
3441 // add select data to clipboard
3442 auto manager = pipelineContext->GetDragDropManager();
3443 ASSERT_NE(manager, nullptr);
3444 auto dragDropProxy = manager->CreateTextDragDropProxy();
3445 ASSERT_NE(dragDropProxy, nullptr);
3446 pattern->dragDropProxy_ = dragDropProxy;
3447
3448 /**
3449 * @tc.steps: step5. call HandlePanEnd function
3450 * @tc.expected: The function exits normally
3451 */
3452 pattern->HandlePanEnd(info);
3453 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3454 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
3455 }
3456
3457 /**
3458 * @tc.name: HandleOnSelectAll001
3459 * @tc.desc: Test TextPattern HandleOnSelectAll when selectOverlayProxy is nullptr.
3460 * @tc.type: FUNC
3461 */
3462 HWTEST_F(TextTestNg, HandleOnSelectAll001, TestSize.Level1)
3463 {
3464 /**
3465 * @tc.steps: step1. create frameNode and pattern
3466 */
3467 auto [frameNode, pattern] = Init();
3468 pattern->textForDisplay_ = "TestHandleOnSelectAll";
3469 pattern->selectOverlayProxy_ = nullptr;
3470
3471 /**
3472 * @tc.steps: step2. create paragraph
3473 */
3474 ParagraphStyle paragraphStyle;
3475 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3476 ASSERT_NE(paragraph, nullptr);
3477 pattern->paragraph_ = paragraph;
3478
3479 /**
3480 * @tc.steps: step3. call HandleOnSelectAll
3481 * @tc.expected:The function exits normally
3482 */
3483 pattern->HandleOnSelectAll();
3484 EXPECT_EQ(pattern->selectOverlayProxy_, nullptr);
3485 }
3486
3487 /**
3488 * @tc.name: HandleOnSelectAll002
3489 * @tc.desc: Test TextPattern HandleOnSelectAll when selectOverlayProxy is not nullptr.
3490 * @tc.type: FUNC
3491 */
3492 HWTEST_F(TextTestNg, HandleOnSelectAll002, TestSize.Level1)
3493 {
3494 /**
3495 * @tc.steps: step1. create frameNode and pattern
3496 */
3497 auto [frameNode, pattern] = Init();
3498 /**
3499 * @tc.steps: step2. construct a SelectOverlayManager and rootNode
3500 */
3501 SelectOverlayInfo selectOverlayInfo;
3502 selectOverlayInfo.singleLineHeight = NODE_ID;
3503 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
3504 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
3505
3506 /**
3507 * @tc.steps: step3. call CreateAndShowSelectOverlay
3508 * @tc.expected: return the proxy which has the right SelectOverlayId
3509 */
3510 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
3511 pattern->selectOverlayProxy_ = proxy;
3512 pattern->textForDisplay_ = "TestHandleOnSelectAll";
3513
3514 /**
3515 * @tc.steps: step4. call HandleOnSelectAll
3516 * @tc.expected:textSelector updates successfully
3517 */
3518 pattern->HandleOnSelectAll();
3519 EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
3520 EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 21);
3521
3522 /**
3523 * @tc.steps: step5. call CloseSelectOverlay
3524 * @tc.expected: Related function is called
3525 */
3526 pattern->CloseSelectOverlay();
3527 EXPECT_FALSE(pattern->selectOverlayProxy_->IsClosed());
3528 }
3529
3530 /**
3531 * @tc.name: PerformActionTest001
3532 * @tc.desc: Text Accessibility PerformAction test Select ClearSelection and Copy.
3533 * @tc.type: FUNC
3534 */
3535 HWTEST_F(TextTestNg, PerformActionTest001, TestSize.Level1)
3536 {
3537 /**
3538 * @tc.steps: step1. Create text, get text frameNode and pattern, set callback function.
3539 * @tc.expected: FrameNode and pattern is not null, related function is called.
3540 */
3541 MockPipelineBase::GetCurrent()->rootNode_ =
3542 FrameNode::CreateFrameNodeWithTree(V2::ROOT_ETS_TAG, 0, AceType::MakeRefPtr<RootPattern>());
3543 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
3544 ASSERT_NE(frameNode, nullptr);
3545 auto textPattern = frameNode->GetPattern<TextPattern>();
3546 ASSERT_NE(textPattern, nullptr);
3547 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
3548 ASSERT_NE(textLayoutProperty, nullptr);
3549 textLayoutProperty->UpdateCopyOption(CopyOptions::None);
3550 textPattern->SetAccessibilityAction();
3551
3552 /**
3553 * @tc.steps: step2. Get text accessibilityProperty to call callback function.
3554 * @tc.expected: Related function is called.
3555 */
3556 auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
3557 ASSERT_NE(textAccessibilityProperty, nullptr);
3558
3559 /**
3560 * @tc.steps: step3. When text CopyOptions is None, call the callback function in textAccessibilityProperty.
3561 * @tc.expected: Related function is called.
3562 */
3563 RectF rect(0.0f, 0.0f, 0.0f, 0.0f);
3564 EXPECT_CALL(*AceType::DynamicCast<MockRenderContext>(frameNode->renderContext_),
3565 GetPaintRectWithTransform())
3566 .WillRepeatedly(Return(rect));
3567 EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, TEXT_SIZE_INT));
3568 EXPECT_TRUE(textAccessibilityProperty->ActActionClearSelection());
3569 EXPECT_TRUE(textAccessibilityProperty->ActActionCopy());
3570
3571 /**
3572 * @tc.steps: step4. When text CopyOptions is InApp, call the callback function in textAccessibilityProperty.
3573 * @tc.expected: Related function is called.
3574 */
3575 textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
3576 EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(-1, -1));
3577 EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, TEXT_SIZE_INT));
3578 EXPECT_TRUE(textAccessibilityProperty->ActActionClearSelection());
3579 EXPECT_TRUE(textAccessibilityProperty->ActActionCopy());
3580 }
3581
3582 /**
3583 * @tc.name: TextSelectorTest001
3584 * @tc.desc: test Update function in TextSelector
3585 * @tc.type: FUNC
3586 */
3587 HWTEST_F(TextTestNg, TextSelectorTest001, TestSize.Level1)
3588 {
3589 /**
3590 * @tc.steps: step1. Create Text.
3591 */
3592 TextModelNG textModel;
3593 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
3594 ASSERT_NE(frameNode, nullptr);
3595 auto textPattern = frameNode->GetPattern<TextPattern>();
3596 ASSERT_NE(textPattern, nullptr);
3597
3598 /**
3599 * @tc.steps: step2. set callback function.
3600 */
3601 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
3602 ASSERT_NE(textLayoutProperty, nullptr);
3603 textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
3604 textPattern->OnModifyDone();
3605
3606 /**
3607 * @tc.steps: step3. call callback function.
3608 * @tc.expected: textSelector_ update successfully.
3609 */
3610 textPattern->textSelector_.Update(0);
3611 EXPECT_EQ(textPattern->textSelector_.baseOffset, 0);
3612
3613 textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
3614 EXPECT_EQ(textPattern->textSelector_.baseOffset, 0);
3615 EXPECT_EQ(textPattern->textSelector_.destinationOffset, TEXT_SIZE_INT);
3616 }
3617
3618 /**
3619 * @tc.name: TextPaintMethodTest003
3620 * @tc.desc: test text_paint_method.cpp UpdateContentModifier function
3621 * @tc.type: FUNC
3622 */
3623 HWTEST_F(TextTestNg, TextPaintMethodTest003, TestSize.Level1)
3624 {
3625 /**
3626 * @tc.steps: step1. create textFrameNode and geometryNode.
3627 */
3628 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
3629 ASSERT_NE(textFrameNode, nullptr);
3630 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
3631 ASSERT_NE(geometryNode, nullptr);
3632 auto textPattern = textFrameNode->GetPattern<TextPattern>();
3633 ASSERT_NE(textPattern, nullptr);
3634 auto renderContext = textFrameNode->GetRenderContext();
3635 ASSERT_NE(renderContext, nullptr);
3636 auto paintProperty = textPattern->CreatePaintProperty();
3637 ASSERT_NE(paintProperty, nullptr);
3638
3639 /**
3640 * @tc.steps: step2. set textForDisplay_ to EMPTY_TEXT.
3641 */
3642 textPattern->textForDisplay_ = EMPTY_TEXT;
3643
3644 /**
3645 * @tc.steps: step3. create textPaintMethod and call UpdateContentModifier function.
3646 * @tc.expected: The drawObscuredRects_ of textContentModifier is empty.
3647 */
3648 ParagraphStyle paragraphStyle;
3649 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3650 RefPtr<TextContentModifier> textContentModifier =
3651 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
3652 RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
3653 TextPaintMethod textPaintMethod(
3654 textPattern, paragraph, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
3655 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
3656 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
3657 EXPECT_EQ(textContentModifier->drawObscuredRects_, std::vector<Rect>());
3658
3659 /**
3660 * @tc.steps: step4. set textForDisplay_ to CREATE_VALUE.
3661 */
3662 textPattern->textForDisplay_ = CREATE_VALUE;
3663
3664 /**
3665 * @tc.steps: step5. call UpdateContentModifier function.
3666 * @tc.expected: The drawObscuredRects_ of textContentModifier is not empty.
3667 */
3668 textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
3669 EXPECT_NE(textContentModifier->drawObscuredRects_, std::vector<Rect>());
3670
3671 /**
3672 * @tc.steps: step6. push UNKNOWN_REASON and PLACEHOLDER to reasons.
3673 * set obscured of renderContext to reasons.
3674 */
3675 std::vector<ObscuredReasons> reasons;
3676 reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
3677 reasons.push_back(ObscuredReasons::PLACEHOLDER);
3678 renderContext->UpdateObscured(reasons);
3679
3680 /**
3681 * @tc.steps: step7. call OnModifyDone function.
3682 * @tc.expected: The obscured of renderContext is reasons.
3683 */
3684 textPattern->OnModifyDone();
3685 EXPECT_EQ(renderContext->GetObscured(), reasons);
3686 }
3687
3688 /**
3689 * @tc.name: TextContentModifier003
3690 * @tc.desc: test text_content_modifier.cpp onDraw function
3691 * @tc.type: FUNC
3692 */
3693 HWTEST_F(TextTestNg, TextContentModifier003, TestSize.Level1)
3694 {
3695 /**
3696 * @tc.steps: step1. create textFrameNode and geometryNode.
3697 */
3698 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
3699 ASSERT_NE(textFrameNode, nullptr);
3700 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
3701 ASSERT_NE(geometryNode, nullptr);
3702 auto textPattern = textFrameNode->GetPattern<TextPattern>();
3703 ASSERT_NE(textPattern, nullptr);
3704 auto textPaintMethod = textPattern->CreateNodePaintMethod();
3705 ASSERT_NE(textPaintMethod, nullptr);
3706 auto textContentModifier = textPattern->GetContentModifier();
3707 ASSERT_NE(textContentModifier, nullptr);
3708
3709 /**
3710 * @tc.steps: step2. set context.
3711 */
3712 Testing::MockCanvas canvas;
3713 EXPECT_CALL(canvas, ClipRect(_, _)).WillRepeatedly(Return());
3714 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
3715
3716 /**
3717 * @tc.steps: step3. call onDraw function of textContentModifier.
3718 * @tc.expected: The obscuredReasons_ of textContentModifier is empty.
3719 * The ifHaveSpanItemChildren_ of textContentModifier is false.
3720 */
3721 textContentModifier->onDraw(context);
3722 EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
3723 EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
3724
3725 /**
3726 * @tc.steps: step4. set ifHaveSpanItemChildren_ to true.
3727 */
3728 textContentModifier->SetIfHaveSpanItemChildren(true);
3729
3730 /**
3731 * @tc.steps: step5. call onDraw function of textContentModifier.
3732 * @tc.expected: The obscuredReasons_ of textContentModifier is empty.
3733 * The ifHaveSpanItemChildren_ of textContentModifier is true.
3734 */
3735 textContentModifier->onDraw(context);
3736 EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
3737 EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
3738
3739 /**
3740 * @tc.steps: step6. push UNKNOWN_REASON and PLACEHOLDER to reasons.
3741 * set obscuredReasons_ to reasons.
3742 */
3743 std::vector<ObscuredReasons> reasons;
3744 reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
3745 reasons.push_back(ObscuredReasons::PLACEHOLDER);
3746 textContentModifier->SetObscured(reasons);
3747
3748 /**
3749 * @tc.steps: step7. call onDraw function of textContentModifier.
3750 * @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
3751 * The ifHaveSpanItemChildren_ of textContentModifier is true.
3752 */
3753 textContentModifier->onDraw(context);
3754 EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
3755 EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
3756
3757 /**
3758 * @tc.steps: step8. set ifHaveSpanItemChildren_ to false.
3759 */
3760 textContentModifier->SetIfHaveSpanItemChildren(false);
3761
3762 /**
3763 * @tc.steps: step9. call onDraw function of textContentModifier.
3764 * @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
3765 * The ifHaveSpanItemChildren_ of textContentModifier is false.
3766 */
3767 textContentModifier->onDraw(context);
3768 EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
3769 EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
3770 }
3771
3772 /**
3773 * @tc.name: TextContentModifier004
3774 * @tc.desc: test text_content_modifier.cpp DrawObscuration function
3775 * @tc.type: FUNC
3776 */
3777 HWTEST_F(TextTestNg, TextContentModifier004, TestSize.Level1)
3778 {
3779 /**
3780 * @tc.steps: step1. create textFrameNode.
3781 */
3782 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
3783 ASSERT_NE(textFrameNode, nullptr);
3784 auto textPattern = textFrameNode->GetPattern<TextPattern>();
3785 ASSERT_NE(textPattern, nullptr);
3786 auto textPaintMethod = textPattern->CreateNodePaintMethod();
3787 ASSERT_NE(textPaintMethod, nullptr);
3788 auto textContentModifier = textPattern->GetContentModifier();
3789 ASSERT_NE(textContentModifier, nullptr);
3790
3791 /**
3792 * @tc.steps: step2. set context and paragraph.
3793 * set defaultFontSize defaultTextColor and contentSize of textContentModifier.
3794 * push one rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
3795 */
3796 Testing::MockCanvas canvas;
3797 EXPECT_CALL(canvas, ClipRect(_, _)).WillRepeatedly(Return());
3798 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
3799 ParagraphStyle paragraphStyle;
3800 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
3801 textContentModifier->SetParagraph(paragraph);
3802 TextStyle textStyle;
3803 textStyle.SetFontSize(ADAPT_FONT_SIZE_VALUE);
3804 textStyle.SetTextColor(TEXT_COLOR_VALUE);
3805 textContentModifier->SetDefaultFontSize(textStyle);
3806 textContentModifier->SetDefaultTextColor(textStyle);
3807 SizeF contentSize(TEXT_CONTENT_SIZE, TEXT_CONTENT_SIZE);
3808 textContentModifier->SetContentSize(contentSize);
3809 std::vector<Rect> drawObscuredRects;
3810 Rect textRect;
3811 textRect.SetHeight(TEXT_RECT_WIDTH);
3812 textRect.SetWidth(TEXT_RECT_WIDTH);
3813 textRect.SetTop(TEXT_RECT_TOP_ONE);
3814 drawObscuredRects.push_back(textRect);
3815 textContentModifier->SetDrawObscuredRects(drawObscuredRects);
3816
3817 /**
3818 * @tc.steps: step3. call DrawObscuration function of textContentModifier.
3819 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
3820 */
3821 textContentModifier->DrawObscuration(context);
3822 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
3823
3824 /**
3825 * @tc.steps: step4. push two rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
3826 */
3827 drawObscuredRects.push_back(textRect);
3828 textRect.SetTop(TEXT_RECT_TOP_TWO);
3829 drawObscuredRects.push_back(textRect);
3830 textContentModifier->SetDrawObscuredRects(drawObscuredRects);
3831
3832 /**
3833 * @tc.steps: step5. call DrawObscuration function of textContentModifier.
3834 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
3835 */
3836 textContentModifier->DrawObscuration(context);
3837 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
3838
3839 /**
3840 * @tc.steps: step6. push three rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
3841 */
3842 textRect.SetHeight(TEXT_RECT_SIZE_ZEOR);
3843 drawObscuredRects.push_back(textRect);
3844 textContentModifier->SetDrawObscuredRects(drawObscuredRects);
3845
3846 /**
3847 * @tc.steps: step7. call DrawObscuration function of textContentModifier.
3848 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
3849 */
3850 textContentModifier->DrawObscuration(context);
3851 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
3852
3853 /**
3854 * @tc.steps: step8. push four rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
3855 */
3856 textRect.SetWidth(TEXT_RECT_SIZE_ZEOR);
3857 drawObscuredRects.push_back(textRect);
3858 textContentModifier->SetDrawObscuredRects(drawObscuredRects);
3859
3860 /**
3861 * @tc.steps: step9. call DrawObscuration function of textContentModifier.
3862 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
3863 */
3864 textContentModifier->DrawObscuration(context);
3865 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
3866 }
3867
3868 /*
3869 * @tc.name: TextModelSetFont001
3870 * @tc.desc: Test if SetFont is successful
3871 * @tc.type: FUNC
3872 */
3873 HWTEST_F(TextTestNg, TextModelSetFont001, TestSize.Level1)
3874 {
3875 /**
3876 * @tc.steps: step1. Initialize textModelNG and FrameNode
3877 */
3878 TextModelNG textModelNG;
3879 textModelNG.Create(CREATE_VALUE);
3880 Font font;
3881 font.fontSize = FONT_SIZE_VALUE;
3882 font.fontWeight = FontWeight::BOLD;
3883 font.fontFamilies = FONT_FAMILY_VALUE;
3884 font.fontStyle = ITALIC_FONT_STYLE_VALUE;
3885 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
3886 ASSERT_NE(frameNode, nullptr);
3887 auto layoutProperty = frameNode->GetLayoutProperty();
3888 ASSERT_NE(layoutProperty, nullptr);
3889 auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
3890 ASSERT_NE(textLayoutProperty, nullptr);
3891
3892 /**
3893 * @tc.steps: step2. call SetFont and Gets the relevant properties of the Font
3894 * @tc.expected: step2. Check the font value
3895 */
3896 textModelNG.SetFont(font);
3897 EXPECT_EQ(textLayoutProperty->GetFontSize(), FONT_SIZE_VALUE);
3898 EXPECT_EQ(textLayoutProperty->GetFontWeight().value(), FontWeight::BOLD);
3899 EXPECT_EQ(textLayoutProperty->GetFontFamily(), FONT_FAMILY_VALUE);
3900 EXPECT_EQ(textLayoutProperty->GetItalicFontStyle(), ITALIC_FONT_STYLE_VALUE);
3901 }
3902
3903 /**
3904 * @tc.name: TextModelGetFont001
3905 * @tc.desc: Test if GetFont is successful
3906 * @tc.type: FUNC
3907 */
3908 HWTEST_F(TextTestNg, TextModelGetFont001, TestSize.Level1)
3909 {
3910 /**
3911 * @tc.steps: step1. Initialize textModelNG and FrameNode
3912 */
3913 TextModelNG textModelNG;
3914 textModelNG.Create(CREATE_VALUE);
3915 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
3916 ASSERT_NE(frameNode, nullptr);
3917 auto layoutProperty = frameNode->GetLayoutProperty();
3918 ASSERT_NE(layoutProperty, nullptr);
3919 auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
3920 ASSERT_NE(textLayoutProperty, nullptr);
3921
3922 /**
3923 * @tc.steps: step2. not set and Gets the relevant properties of the Font
3924 * @tc.expected: step2. Check the font value
3925 */
3926 EXPECT_EQ(textLayoutProperty->GetFont(), TEXT_DEFAULT_VALUE);
3927
3928 /**
3929 * @tc.steps: step2. call SetFont and Gets the relevant properties of the Font
3930 * @tc.expected: step2. Check the font value
3931 */
3932 Font font;
3933 font.fontSize = FONT_SIZE_VALUE;
3934 font.fontWeight = FontWeight::BOLD;
3935 font.fontFamilies = FONT_FAMILY_VALUE;
3936 font.fontStyle = ITALIC_FONT_STYLE_VALUE;
3937 textModelNG.SetFont(font);
3938 EXPECT_EQ(textLayoutProperty->GetFont(), TEXT_EQUALS_VALUE);
3939 }
3940
3941 /**
3942 * @tc.name: BetweenSelectedPosition001
3943 * @tc.desc: test text_pattern.cpp BetweenSelectedPosition function
3944 * @tc.type: FUNC
3945 */
3946 HWTEST_F(TextTestNg, BetweenSelectedPosition001, TestSize.Level1)
3947 {
3948 /**
3949 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
3950 */
3951 auto [host, pattern] = Init();
3952 pattern->copyOption_ = CopyOptions::Distributed;
3953 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
3954 host->draggable_ = true;
3955 host->eventHub_->SetOnDragStart(
__anonda3610500602(const RefPtr<Ace::DragEvent>&, const std::string&) 3956 [](const RefPtr<Ace::DragEvent>&, const std::string&) -> DragDropInfo { return {}; });
3957
3958 /**
3959 * @tc.steps: step2. set selected rect to [0, 0] - [20, 20]
3960 */
3961 pattern->textSelector_.Update(0, 20);
3962
3963 /**
3964 * @tc.steps: step3. construct 3 groups cases and corresponding expected results.
3965 * @tc.expected: Running the BetweenSelectedPosition function and check the result with expected results.
3966 */
3967 std::vector<Offset> cases = {
3968 Offset(1, 1), Offset(21, 21)
3969 };
3970 std::vector<bool> exceptResults = {
3971 true, false
3972 };
3973 for (uint32_t turn = 0; turn < cases.size(); ++turn) {
3974 EXPECT_EQ(pattern->BetweenSelectedPosition(cases[turn]), exceptResults[turn]);
3975 }
3976 }
3977
3978 /**
3979 * @tc.name: OnHandleMove002
3980 * @tc.desc: test text_pattern.cpp OnHandleMove function
3981 * @tc.type: FUNC
3982 */
3983 HWTEST_F(TextTestNg, OnHandleMove002, TestSize.Level1)
3984 {
3985 /**
3986 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
3987 */
3988 auto [host, pattern] = Init();
3989 auto pipeline = host->GetContext();
3990 pattern->paragraph_ = AceType::MakeRefPtr<TxtParagraph>(ParagraphStyle {}, nullptr);
3991 SelectOverlayInfo selectOverlayInfo;
3992 selectOverlayInfo.singleLineHeight = NODE_ID;
3993 auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
3994 auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
3995 auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr);
3996 pattern->selectOverlayProxy_ = proxy;
3997 pipeline->rootNode_->GetGeometryNode()->SetFrameOffset({3.0, 5.0});
3998
3999 /**
4000 * @tc.steps: step3. construct 3 groups cases and corresponding expected results.
4001 * @tc.expected: Running the OnHandleMove function and check the result with expected results.
4002 */
4003 std::vector<RectF> handleRects = {
4004 {1.0, 2.0, 3.0, 4.0}, {5.0, 6.0, 7.0, 8.0}, {-9.0, -10.0, 11.0, 12.0}
4005 };
4006 std::vector<vector<TextSelector>> expectResults = {
4007 {TextSelector(0, -1), TextSelector(0, 0)},
4008 {TextSelector(0, 0), TextSelector(0, 0)},
4009 {TextSelector(0, 0), TextSelector(0, 0)}
4010 };
4011 for (uint32_t turn = 0; turn < handleRects.size(); ++turn) {
4012 pattern->OnHandleMove(handleRects[turn], true);
4013 EXPECT_EQ(pattern->textSelector_, expectResults[turn][0]);
4014 pattern->OnHandleMove(handleRects[turn], false);
4015 EXPECT_EQ(pattern->textSelector_, expectResults[turn][1]);
4016 }
4017 }
4018
4019 /**
4020 * @tc.name: GetGlobalOffset001
4021 * @tc.desc: test text_pattern.cpp GetGlobalOffset function
4022 * @tc.type: FUNC
4023 */
4024 HWTEST_F(TextTestNg, GetGlobalOffset001, TestSize.Level1)
4025 {
4026 /**
4027 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4028 */
4029 auto [host, pattern] = Init();
4030 auto pipeline = host->GetContext();
4031
4032 /**
4033 * @tc.steps: step3. construct 3 groups cases and corresponding expected results.
4034 * @tc.expected: Running GetGlobalOffset function and check the result with expected results.
4035 */
4036 std::vector<OffsetF> offsetCases = {
4037 {3.0, 5.0}, {4.0, 5.0}, {6.0, 7.0}
4038 };
4039 std::vector<Offset> expectResults = {
4040 {-3.0, -5.0}, {-4.0, -5.0}, {-6.0, -7.0}
4041 };
4042 for (uint32_t turn = 0; turn < offsetCases.size(); ++turn) {
4043 pipeline->rootNode_->GetGeometryNode()->SetFrameOffset(offsetCases[turn]);
4044 Offset tmp;
4045 pattern->GetGlobalOffset(tmp);
4046 EXPECT_EQ(tmp, expectResults[turn]);
4047 }
4048 }
4049
4050 /**
4051 * @tc.name: CreateImageSpanAndLayout001
4052 * @tc.desc: test text_layout_algorithm.cpp CreateImageSpanAndLayout function
4053 * @tc.type: FUNC
4054 */
4055 HWTEST_F(TextTestNg, CreateImageSpanAndLayout001, TestSize.Level1)
4056 {
4057 /**
4058 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4059 */
4060 auto [frameNode, pattern] = Init();
4061 auto pipeline = frameNode->GetContext();
4062 TextModelNG textModelNG;
4063 textModelNG.Create(CREATE_VALUE);
4064 auto* stack = ViewStackProcessor::GetInstance();
4065 auto nodeId = stack->ClaimNodeId();
4066
4067 /**
4068 * @tc.steps: step2. Add Text and Image Span.
4069 */
4070 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
4071 frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
4072 ASSERT_NE(layoutWrapper, nullptr);
4073 layoutWrapper->children_.push_back(layoutWrapper);
4074
4075 auto textSpanNode = CreateSpanNodeWithSetDefaultProperty("this is a test.");
4076 ASSERT_NE(textSpanNode, nullptr);
4077 pattern->AddChildSpanItem(textSpanNode);
4078 frameNode->AddChild(textSpanNode);
4079 nodeId = stack->ClaimNodeId();
4080 auto imageSpanNode = FrameNode::GetOrCreateFrameNode(
__anonda3610500702() 4081 V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
4082 ASSERT_NE(imageSpanNode, nullptr);
4083 pattern->AddChildSpanItem(imageSpanNode);
4084 frameNode->AddChild(imageSpanNode);
4085
4086 /**
4087 * @tc.steps: step3. Init TextLayoutAlgorithm and Paragraph, then run the CreateImageSpanAndLayout Func.
4088 * @tc.expected: Construct result is True.
4089 */
4090 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
4091 TextStyle textStyle;
4092 LayoutConstraintF contentConstraint;
4093 rowLayoutAlgorithm->CreateParagraph(textStyle, "", nullptr);
4094 auto ret = rowLayoutAlgorithm->CreateImageSpanAndLayout(
4095 textStyle, "", contentConstraint, AccessibilityManager::RawPtr(layoutWrapper));
4096 EXPECT_TRUE(ret);
4097 }
4098
4099 /**
4100 * @tc.name: ApplyIndents002
4101 * @tc.desc: test text_layout_algorithm.cpp ApplyIndents function
4102 * @tc.type: FUNC
4103 */
4104 HWTEST_F(TextTestNg, ApplyIndents002, TestSize.Level1)
4105 {
4106 /**
4107 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4108 */
4109 auto [host, pattern] = Init();
4110 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
4111
4112 /**
4113 * @tc.steps: step2. construct textStyle with TextIndent 5.
4114 */
4115 TextStyle textStyle;
4116 textStyle.SetTextIndent(Dimension(5));
4117 rowLayoutAlgorithm->CreateParagraph(textStyle, "This is a test.", nullptr);
4118
4119 /**
4120 * @tc.steps: step3. run the ApplyIndents Func.
4121 * @tc.expected: paragraph_.rawPtr_ is nullptr.
4122 */
4123 rowLayoutAlgorithm->ApplyIndents(textStyle, 10.0);
4124 EXPECT_NE(rowLayoutAlgorithm->paragraph_.rawPtr_, nullptr);
4125 }
4126
4127 /**
4128 * @tc.name: ApplyIndents003
4129 * @tc.desc: test text_layout_algorithm.cpp ApplyIndents function
4130 * @tc.type: FUNC
4131 */
4132 HWTEST_F(TextTestNg, ApplyIndents003, TestSize.Level1)
4133 {
4134 /**
4135 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4136 */
4137 auto [host, pattern] = Init();
4138 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
4139
4140 /**
4141 * @tc.steps: step2. construct textStyle with TextIndent 5 and type is DimensionUnit::PERCENT.
4142 */
4143 TextStyle textStyle;
4144 textStyle.SetTextIndent(Dimension(5, DimensionUnit::PERCENT));
4145 rowLayoutAlgorithm->CreateParagraph(textStyle, "This is a test.", nullptr);
4146
4147 /**
4148 * @tc.steps: step3. run the ApplyIndents Func.
4149 * @tc.expected: paragraph_.rawPtr_ is nullptr.
4150 */
4151 rowLayoutAlgorithm->ApplyIndents(textStyle, 10.0);
4152 EXPECT_NE(rowLayoutAlgorithm->paragraph_.rawPtr_, nullptr);
4153 }
4154
4155 /**
4156 * @tc.name: SetDraggable001
4157 * @tc.desc: test text_model_ng.cpp SetDraggable function
4158 * @tc.type: FUNC
4159 */
4160 HWTEST_F(TextTestNg, SetDraggable001, TestSize.Level1)
4161 {
4162 /**
4163 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4164 */
4165 TextModelNG textModelNG;
4166 textModelNG.Create(CREATE_VALUE);
4167 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
4168
4169 /**
4170 * @tc.steps: step3. construct 2 groups cases and corresponding expected results.
4171 * @tc.expected: Running SetDraggable function and check the result with expected results.
4172 */
4173 std::vector<bool> cases = { true, false };
4174 std::vector<bool> expectResult = { true, false };
4175 for (uint32_t turn = 0; turn < cases.size(); ++turn) {
4176 textModelNG.SetDraggable(cases[turn]);
4177 EXPECT_EQ(frameNode->IsDraggable(), expectResult[turn]);
4178 }
4179 }
4180
4181 /**
4182 * @tc.name: SetMenuOptionItems001
4183 * @tc.desc: test text_model_ng.cpp SetMenuOptionItems function
4184 * @tc.type: FUNC
4185 */
4186 HWTEST_F(TextTestNg, SetMenuOptionItems001, TestSize.Level1)
4187 {
4188 /**
4189 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4190 */
4191 auto [host, pattern] = Init();
4192 TextModelNG textModelNG;
4193 textModelNG.Create(CREATE_VALUE);
4194 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
4195
4196 /**
4197 * @tc.steps: step2. construct menuOptionItems.
4198 * @tc.expected: Running SetMenuOptionItems function and check the result.
4199 */
4200 std::vector<MenuOptionsParam> menuOptionItems;
4201 MenuOptionsParam menuOptionItem1;
4202 menuOptionItem1.content = "test1";
__anonda3610500802(const std::string&) 4203 menuOptionItem1.action = [](const std::string&) {};
4204 menuOptionItems.emplace_back(menuOptionItem1);
4205 pattern->menuOptionItems_ = menuOptionItems;
4206 textModelNG.SetMenuOptionItems(std::move(menuOptionItems));
4207 EXPECT_EQ(pattern->menuOptionItems_.size(), 1);
4208 EXPECT_EQ(pattern->menuOptionItems_[0].ToString(), menuOptionItem1.ToString());
4209 }
4210
4211 /**
4212 * @tc.name: ClearOnClick001
4213 * @tc.desc: test text_model_ng.cpp ClearOnClick function
4214 * @tc.type: FUNC
4215 */
4216 HWTEST_F(TextTestNg, ClearOnClick001, TestSize.Level1)
4217 {
4218 /**
4219 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4220 */
4221 auto [host, pattern] = Init();
4222 TextModelNG textModelNG;
4223 textModelNG.Create(CREATE_VALUE);
4224 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
4225
4226 /**
4227 * @tc.steps: step2. Running ClearOnClick function.
4228 * @tc.expected: the onClick_ will be nullptr.
4229 */
4230 textModelNG.ClearOnClick();
4231 EXPECT_EQ(pattern->onClick_, nullptr);
4232 }
4233
4234 /**
4235 * @tc.name: SetFontSize001
4236 * @tc.desc: test text_model_ng.cpp SetFontSize function
4237 * @tc.type: FUNC
4238 */
4239 HWTEST_F(TextTestNg, SetFontSize001, TestSize.Level1)
4240 {
4241 /**
4242 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4243 */
4244 auto [host, pattern] = Init();
4245 TextModelNG textModelNG;
4246 textModelNG.Create(CREATE_VALUE);
4247 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
4248
4249 /**
4250 * @tc.steps: step2. Run SetFontSize with isvalid data.
4251 * @tc.expected: the fontsize will be Dimension(0).
4252 */
4253 textModelNG.SetFontSize(Dimension(-1));
4254 RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
4255 ASSERT_NE(layoutProperty, nullptr);
4256 RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
4257 ASSERT_NE(textLayoutProperty, nullptr);
4258 const std::unique_ptr<FontStyle>& fontStyle = textLayoutProperty->GetFontStyle();
4259 ASSERT_NE(fontStyle, nullptr);
4260 EXPECT_EQ(fontStyle->GetFontSize().value(), Dimension(0));
4261 }
4262
4263 /**
4264 * @tc.name: GetLineCount001
4265 * @tc.desc: test text_layout_algorithm.cpp GetLineCount function
4266 * @tc.type: FUNC
4267 */
4268 HWTEST_F(TextTestNg, GetLineCount001, TestSize.Level1)
4269 {
4270 /**
4271 * @tc.steps: step1. create frameNode and pattern and some environment for running process.
4272 */
4273 auto [frameNode, pattern] = Init();
4274 auto pipeline = frameNode->GetContext();
4275
4276 /**
4277 * @tc.steps: step2. Create Paragraph
4278 */
4279 auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
4280 TextStyle textStyle;
4281 LayoutConstraintF contentConstraint;
4282 rowLayoutAlgorithm->CreateParagraph(textStyle, "This is a test.", nullptr);
4283
4284 /**
4285 * @tc.steps: step3. GetLineCount.
4286 * @tc.expected: linecount will be 1.
4287 */
4288 EXPECT_EQ(rowLayoutAlgorithm->GetLineCount(), 1);
4289 }
4290 } // namespace OHOS::Ace::NG
4291