1 /* 2 * Copyright (c) 2024 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 "text_base.h" 17 18 namespace OHOS::Ace::NG { 19 20 namespace {} // namespace 21 22 class TextTestFourNg : public TextBases { 23 public: 24 }; 25 26 /** 27 * @tc.name: UpdateFontFeature 28 * @tc.desc: test fontFeature. 29 * @tc.type: FUNC 30 */ 31 HWTEST_F(TextTestFourNg, UpdateFontFeature002, TestSize.Level1) 32 { 33 TextModelNG textModelNG; 34 textModelNG.Create(CREATE_VALUE); 35 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); 36 ASSERT_NE(frameNode, nullptr); 37 RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty(); 38 ASSERT_NE(layoutProperty, nullptr); 39 RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty); 40 ASSERT_NE(textLayoutProperty, nullptr); 41 42 textModelNG.SetFontFeature(FONT_FEATURE_VALUE_0); 43 EXPECT_EQ(textLayoutProperty->GetFontFeature(), FONT_FEATURE_VALUE_0); 44 textLayoutProperty->UpdateFontFeature(ParseFontFeatureSettings("\"ss01\" 1")); 45 TextModelNG::SetFontFeature(frameNode, FONT_FEATURE_VALUE_0); 46 EXPECT_EQ(textLayoutProperty->GetFontFeature(), FONT_FEATURE_VALUE_0); 47 } 48 49 /** 50 * @tc.name: SetLineSpacing 51 * @tc.desc: test setLineSpacing. 52 * @tc.type: FUNC 53 */ 54 HWTEST_F(TextTestFourNg, SetLineSpacing001, TestSize.Level1) 55 { 56 TextModelNG textModelNG; 57 textModelNG.Create(CREATE_VALUE); 58 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); 59 ASSERT_NE(frameNode, nullptr); 60 RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty(); 61 ASSERT_NE(layoutProperty, nullptr); 62 RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty); 63 ASSERT_NE(textLayoutProperty, nullptr); 64 65 textModelNG.SetLineSpacing(LINE_SPACING_VALUE); 66 EXPECT_EQ(textLayoutProperty->GetLineSpacing(), LINE_SPACING_VALUE); 67 TextModelNG::SetLineSpacing(frameNode, LINE_SPACING_VALUE_1); 68 EXPECT_EQ(textLayoutProperty->GetLineSpacing(), LINE_SPACING_VALUE_1); 69 } 70 71 /** 72 * @tc.name: TextLayoutAlgorithm 73 * @tc.desc: test TextLayoutAlgorithm. 74 * @tc.type: FUNC 75 */ 76 HWTEST_F(TextTestFourNg, TextLayoutAlgorithm001, TestSize.Level1) 77 { 78 /** 79 * @tc.steps: step1. create textFrameNode. 80 */ 81 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 82 ASSERT_NE(textFrameNode, nullptr); 83 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 84 ASSERT_NE(geometryNode, nullptr); 85 RefPtr<LayoutWrapperNode> layoutWrapper = 86 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty()); 87 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 88 ASSERT_NE(textPattern, nullptr); 89 90 /** 91 * @tc.steps: step2. construct spanItem_. 92 */ 93 std::list<RefPtr<SpanItem>> spans; 94 ConstructSpanItemList1(spans); 95 EXPECT_EQ(spans.size(), 4); 96 textPattern->spans_ = spans; 97 textPattern->isSpanStringMode_ = true; 98 99 /** 100 * @tc.steps: step3. call TextLayoutAlgorithm. 101 * @tc.expected: the spans of each paragraph are split correctly. 102 */ 103 auto textLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(textPattern->CreateLayoutAlgorithm()); 104 auto size = textLayoutAlgorithm->spans_.size(); 105 EXPECT_EQ(size, 3); 106 107 auto firstSpans = textLayoutAlgorithm->spans_.front(); 108 EXPECT_EQ(firstSpans.size(), 2); 109 110 auto endSpans = textLayoutAlgorithm->spans_.back(); 111 EXPECT_EQ(endSpans.size(), 1); 112 } 113 114 /** 115 * @tc.name: TextLayoutAlgorithm 116 * @tc.desc: test UpdateParagraphBySpan of MultipleParagraphLayoutAlgorithm. 117 * @tc.type: FUNC 118 */ 119 HWTEST_F(TextTestFourNg, UpdateParagraphBySpan001, TestSize.Level1) 120 { 121 /** 122 * @tc.steps: step1. create textLayoutAlgorithm. 123 * @tc.expected: the spans of each paragraph are split correctly. 124 */ 125 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 126 ASSERT_NE(textFrameNode, nullptr); 127 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 128 ASSERT_NE(geometryNode, nullptr); 129 RefPtr<LayoutWrapperNode> layoutWrapper = 130 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty()); 131 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 132 ASSERT_NE(textPattern, nullptr); 133 std::list<RefPtr<SpanItem>> spans; 134 ConstructSpanItemList1(spans); 135 textPattern->spans_ = spans; 136 textPattern->isSpanStringMode_ = true; 137 auto textLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(textPattern->CreateLayoutAlgorithm()); 138 EXPECT_EQ(textLayoutAlgorithm->spans_.size(), 3); 139 140 /** 141 * @tc.steps: step2. call MeasureContent. 142 * @tc.expected: the paragraphs are and paragraph style created correctly. 143 */ 144 LayoutConstraintF parentLayoutConstraint; 145 parentLayoutConstraint.maxSize = CONTAINER_SIZE; 146 textLayoutAlgorithm->MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper)); 147 auto paragraphs = textLayoutAlgorithm->paragraphManager_->GetParagraphs(); 148 EXPECT_EQ(paragraphs.size(), 3); 149 150 auto iter = paragraphs.begin(); 151 152 auto firstParagraph = *(iter); 153 ASSERT_NE(firstParagraph.paragraph, nullptr); 154 155 auto paragraphStyle = firstParagraph.paragraphStyle; 156 EXPECT_EQ(paragraphStyle.align, TextAlign::START); 157 EXPECT_EQ(paragraphStyle.maxLines, UINT32_MAX); 158 159 iter++; 160 auto secondParagraph = *(iter); 161 ASSERT_NE(secondParagraph.paragraph, nullptr); 162 paragraphStyle = secondParagraph.paragraphStyle; 163 EXPECT_EQ(paragraphStyle.align, TextAlign::END); 164 EXPECT_EQ(paragraphStyle.indent, Dimension(20.0f)); 165 EXPECT_EQ(paragraphStyle.wordBreak, WordBreak::BREAK_ALL); 166 EXPECT_EQ(paragraphStyle.textOverflow, TextOverflow::ELLIPSIS); 167 168 iter++; 169 auto thirdParagraph = *(iter); 170 ASSERT_NE(thirdParagraph.paragraph, nullptr); 171 } 172 173 /** 174 * @tc.name: InitKeyEvent001 175 * @tc.desc: test test_pattern.h InitKeyEvent. 176 * @tc.type: FUNC 177 */ 178 HWTEST_F(TextTestFourNg, InitKeyEvent001, TestSize.Level1) 179 { 180 /** 181 * @tc.steps: step1. create frameNode and pattern. 182 */ 183 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 184 ASSERT_NE(frameNode, nullptr); 185 auto textPattern = frameNode->GetPattern<TextPattern>(); 186 ASSERT_NE(textPattern, nullptr); 187 188 /** 189 * @tc.steps: step2. Initialize text and copyOption. 190 */ 191 TextModelNG textModelNG; 192 textModelNG.Create("123456789"); 193 textModelNG.SetCopyOption(CopyOptions::InApp); 194 195 /** 196 * @tc.steps: step3. test the param keyEventInitialized_ is or not true. 197 * @tc.expect: expect keyEventInitialized_ is true. 198 */ 199 textPattern->InitKeyEvent(); 200 EXPECT_TRUE(textPattern->keyEventInitialized_); 201 } 202 203 /** 204 * @tc.name: HandleKeyEvent001 205 * @tc.desc: test test_pattern.h HandleKeyEvent. 206 * @tc.type: FUNC 207 */ 208 HWTEST_F(TextTestFourNg, HandleKeyEvent001, TestSize.Level1) 209 { 210 /** 211 * @tc.steps: step1. create frameNode and pattern. 212 */ 213 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 214 ASSERT_NE(frameNode, nullptr); 215 auto textPattern = frameNode->GetPattern<TextPattern>(); 216 ASSERT_NE(textPattern, nullptr); 217 auto paragraph = MockParagraph::GetOrCreateMockParagraph(); 218 textPattern->pManager_->Reset(); 219 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 220 221 /** 222 * @tc.steps: step2. Initialize text and textSelector_. 223 */ 224 TextModelNG textModelNG; 225 textModelNG.Create("123456789"); 226 textPattern->copyOption_ = CopyOptions::InApp; 227 textPattern->textSelector_.Update(2, 6); 228 229 /** 230 * @tc.steps: step3. test the enter key is or not legal. 231 * @tc.expect: expect the key is legal. 232 */ 233 KeyEvent event; 234 event.action = KeyAction::UP; 235 EXPECT_FALSE(textPattern->HandleKeyEvent(event)); 236 event.action = KeyAction::DOWN; 237 std::vector<KeyCode> pressCodes = {}; 238 event.pressedCodes = pressCodes; 239 std::vector<KeyCode> ctrlCodes = { KeyCode::KEY_CTRL_LEFT, KeyCode::KEY_CTRL_RIGHT }; 240 for (auto ctrl : ctrlCodes) { 241 event.pressedCodes.clear(); 242 event.pressedCodes.push_back(ctrl); 243 event.pressedCodes.push_back(KeyCode::KEY_C); 244 event.code = KeyCode::KEY_C; 245 EXPECT_TRUE(textPattern->HandleKeyEvent(event)); 246 } 247 248 std::vector<KeyCode> shiftCodes = { KeyCode::KEY_SHIFT_LEFT, KeyCode::KEY_SHIFT_RIGHT }; 249 std::vector<KeyCode> eventCodes = { 250 KeyCode::KEY_DPAD_RIGHT, 251 KeyCode::KEY_DPAD_LEFT, 252 KeyCode::KEY_DPAD_UP, 253 KeyCode::KEY_DPAD_DOWN, 254 }; 255 for (auto shift : shiftCodes) { 256 for (auto code : eventCodes) { 257 event.pressedCodes.clear(); 258 event.pressedCodes.push_back(shift); 259 event.pressedCodes.push_back(code); 260 event.code = code; 261 EXPECT_TRUE(textPattern->HandleKeyEvent(event)); 262 } 263 } 264 } 265 266 /** 267 * @tc.name: GetTextRacePercent001 268 * @tc.desc: test GetTextRacePercent. 269 * @tc.type: FUNC 270 */ 271 HWTEST_F(TextTestFourNg, GetTextRacePercent001, TestSize.Level1) 272 { 273 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 274 ASSERT_NE(textFrameNode, nullptr); 275 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 276 ASSERT_NE(geometryNode, nullptr); 277 RefPtr<LayoutWrapperNode> layoutWrapper = 278 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty()); 279 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 280 ASSERT_NE(textPattern, nullptr); 281 RefPtr<TextContentModifier> textContentModifier = 282 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()), textPattern); 283 ASSERT_NE(textContentModifier, nullptr); 284 285 textContentModifier->GetTextRacePercent(); 286 textContentModifier->racePercentFloat_->Set(1.0f); 287 auto ret = textContentModifier->GetTextRacePercent(); 288 EXPECT_EQ(ret, 1.0f); 289 } 290 291 /** 292 * @tc.name: SetAdaptMaxFontSize001 293 * @tc.desc: test SetAdaptMaxFontSize. 294 * @tc.type: FUNC 295 */ 296 HWTEST_F(TextTestFourNg, SetAdaptMaxFontSize001, TestSize.Level1) 297 { 298 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 299 ASSERT_NE(textFrameNode, nullptr); 300 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 301 ASSERT_NE(geometryNode, nullptr); 302 RefPtr<LayoutWrapperNode> layoutWrapper = 303 AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty()); 304 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 305 ASSERT_NE(textPattern, nullptr); 306 auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>(); 307 ASSERT_NE(textLayoutProperty, nullptr); 308 auto frameNode = layoutWrapper->GetHostNode(); 309 auto pipeline = frameNode->GetContextRefPtr(); 310 TextStyle textStyle = CreateTextStyleUsingTheme( 311 textLayoutProperty->GetFontStyle(), textLayoutProperty->GetTextLineStyle(), pipeline->GetTheme<TextTheme>()); 312 313 RefPtr<TextContentModifier> textContentModifier = 314 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()), textPattern); 315 ASSERT_NE(textContentModifier, nullptr); 316 317 textContentModifier->SetAdaptMaxFontSize(ADAPT_MAX_FONT_SIZE_VALUE, textStyle); 318 EXPECT_EQ(textContentModifier->adaptMaxFontSize_, ADAPT_MAX_FONT_SIZE_VALUE); 319 } 320 321 /** 322 * @tc.name: PaintCustomSpan001 323 * @tc.desc: test PaintCustomSpan. 324 * @tc.type: FUNC 325 */ 326 HWTEST_F(TextTestFourNg, PaintCustomSpan001, TestSize.Level1) 327 { 328 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 329 ASSERT_NE(textFrameNode, nullptr); 330 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 331 ASSERT_NE(textPattern, nullptr); 332 RefPtr<TextContentModifier> textContentModifier = 333 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()), textPattern); 334 ASSERT_NE(textContentModifier, nullptr); 335 336 Testing::MockCanvas canvas; 337 EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return()); 338 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; 339 ParagraphStyle paragraphStyle; 340 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 341 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 }); 342 textContentModifier->PaintCustomSpan(context); 343 EXPECT_FALSE(textPattern->pManager_->GetParagraphs().empty()); 344 } 345 346 /** 347 * @tc.name: PaintImage001 348 * @tc.desc: test PaintImage 349 * @tc.type: FUNC 350 */ 351 HWTEST_F(TextTestFourNg, PaintImage001, TestSize.Level1) 352 { 353 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 354 ASSERT_NE(textFrameNode, nullptr); 355 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 356 ASSERT_NE(textPattern, nullptr); 357 RefPtr<TextContentModifier> textContentModifier = 358 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()), textPattern); 359 ASSERT_NE(textContentModifier, nullptr); 360 int32_t apiVersion = 12; 361 AceApplicationInfo::GetInstance().SetApiTargetVersion(apiVersion); 362 Testing::MockCanvas canvas; 363 EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return()); 364 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; 365 RSCanvas& rsCanvas = context.canvas; 366 float x = 50.0f; 367 float y = 100.0f; 368 textContentModifier->PaintImage(rsCanvas, x, y); 369 EXPECT_EQ(AceApplicationInfo::GetInstance().GetApiTargetVersion(), 12); 370 } 371 372 /** 373 * @tc.name: SetClip001 374 * @tc.desc: test SetClip 375 * @tc.type: FUNC 376 */ 377 HWTEST_F(TextTestFourNg, SetClip001, TestSize.Level1) 378 { 379 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 380 ASSERT_NE(textFrameNode, nullptr); 381 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 382 ASSERT_NE(textPattern, nullptr); 383 RefPtr<TextContentModifier> textContentModifier = 384 AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()), textPattern); 385 ASSERT_NE(textContentModifier, nullptr); 386 textContentModifier->clip_ = AccessibilityManager::MakeRefPtr<PropertyBool>(true); 387 textContentModifier->SetClip(true); 388 textContentModifier->clip_ = AccessibilityManager::MakeRefPtr<PropertyBool>(false); 389 textContentModifier->SetClip(true); 390 EXPECT_TRUE(textContentModifier->clip_); 391 } 392 393 /** 394 * @tc.name: TypedText001 395 * @tc.desc: test typed_text.h static functions. 396 * @tc.type: FUNC 397 */ 398 HWTEST_F(TextTestFourNg, TypedText001, TestSize.Level1) 399 { 400 /** 401 * @tc.steps: step1. create TypedText and create value. 402 */ 403 TypedText typedText; 404 const char* test = nullptr; 405 406 /** 407 * @tc.steps: step2. test GetUTF8OneCharacterSize and GetUTF8Next. 408 */ 409 uint32_t nextIndex = 2; 410 EXPECT_EQ(typedText.GetUTF8OneCharacterSize(test), 0); 411 EXPECT_EQ(typedText.GetUTF8Next(test, 1, nextIndex), 0); 412 413 /** 414 * @tc.steps: step3. change value and test again. 415 */ 416 const char* test1 = TEXT_CONTENT1; 417 EXPECT_EQ(typedText.GetUTF8OneCharacterSize(test1), 1); 418 EXPECT_EQ(typedText.GetUTF8Next(test1, 1, nextIndex), 105); 419 420 const char* test2 = TEXT_CONTENT2; 421 EXPECT_EQ(typedText.GetUTF8OneCharacterSize(test2), 1); 422 EXPECT_EQ(typedText.GetUTF8Next(test2, 1, nextIndex), 101); 423 424 /** 425 * @tc.steps: step4. test IsEmoji. 426 */ 427 EXPECT_EQ(typedText.IsEmoji(CODE1), false); 428 EXPECT_EQ(typedText.IsEmoji(CODE2), true); 429 EXPECT_EQ(typedText.IsEmoji(CODE3), true); 430 } 431 432 /** 433 * @tc.name: TextContentModifier003 434 * @tc.desc: test text_content_modifier.cpp onDraw function 435 * @tc.type: FUNC 436 */ 437 HWTEST_F(TextTestFourNg, TextContentModifier003, TestSize.Level1) 438 { 439 /** 440 * @tc.steps: step1. create textFrameNode and geometryNode. 441 */ 442 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 443 ASSERT_NE(textFrameNode, nullptr); 444 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 445 ASSERT_NE(geometryNode, nullptr); 446 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 447 ASSERT_NE(textPattern, nullptr); 448 auto textPaintMethod = textPattern->CreateNodePaintMethod(); 449 ASSERT_NE(textPaintMethod, nullptr); 450 auto textContentModifier = textPattern->GetContentModifier(); 451 ASSERT_NE(textContentModifier, nullptr); 452 453 /** 454 * @tc.steps: step2. set context. 455 */ 456 Testing::MockCanvas canvas; 457 EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return()); 458 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; 459 460 /** 461 * @tc.steps: step3. call onDraw function of textContentModifier. 462 * The ifPaintObscuration_ of textContentModifier is false. 463 */ 464 textContentModifier->onDraw(context); 465 EXPECT_EQ(textContentModifier->ifPaintObscuration_, false); 466 467 /** 468 * @tc.steps: step4. set ifPaintObscuration_ to true. 469 */ 470 textContentModifier->SetIfPaintObscuration(true); 471 472 /** 473 * @tc.steps: step5. call onDraw function of textContentModifier. 474 * The ifPaintObscuration_ of textContentModifier is true. 475 */ 476 textContentModifier->onDraw(context); 477 EXPECT_EQ(textContentModifier->ifPaintObscuration_, true); 478 479 /** 480 * @tc.steps: step6. call onDraw function of textContentModifier. 481 * The ifPaintObscuration_ of textContentModifier is true. 482 */ 483 textContentModifier->onDraw(context); 484 EXPECT_EQ(textContentModifier->ifPaintObscuration_, true); 485 486 /** 487 * @tc.steps: step7. set ifPaintObscuration_ to false. 488 */ 489 textContentModifier->SetIfPaintObscuration(false); 490 491 /** 492 * @tc.steps: step8. call onDraw function of textContentModifier. 493 * The ifPaintObscuration_ of textContentModifier is false. 494 */ 495 textContentModifier->onDraw(context); 496 EXPECT_EQ(textContentModifier->ifPaintObscuration_, false); 497 } 498 499 /** 500 * @tc.name: TextContentModifier004 501 * @tc.desc: test text_content_modifier.cpp DrawObscuration function 502 * @tc.type: FUNC 503 */ 504 HWTEST_F(TextTestFourNg, TextContentModifier004, TestSize.Level1) 505 { 506 /** 507 * @tc.steps: step1. create textFrameNode. 508 */ 509 auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 510 ASSERT_NE(textFrameNode, nullptr); 511 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 512 ASSERT_NE(textPattern, nullptr); 513 auto textPaintMethod = textPattern->CreateNodePaintMethod(); 514 ASSERT_NE(textPaintMethod, nullptr); 515 auto textContentModifier = textPattern->GetContentModifier(); 516 ASSERT_NE(textContentModifier, nullptr); 517 518 /** 519 * @tc.steps: step2. set context and paragraph. 520 * set defaultFontSize defaultTextColor and contentSize of textContentModifier. 521 * push one rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects. 522 */ 523 Testing::MockCanvas canvas; 524 EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return()); 525 EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas)); 526 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas)); 527 DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; 528 ParagraphStyle paragraphStyle; 529 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 530 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 }); 531 TextStyle textStyle; 532 textStyle.SetFontSize(ADAPT_FONT_SIZE_VALUE); 533 textStyle.SetTextColor(TEXT_COLOR_VALUE); 534 textContentModifier->SetDefaultAnimatablePropertyValue(textStyle); 535 SizeF contentSize(TEXT_CONTENT_SIZE, TEXT_CONTENT_SIZE); 536 textContentModifier->SetContentSize(contentSize); 537 std::vector<RectF> drawObscuredRects; 538 RectF textRect; 539 textRect.SetHeight(TEXT_RECT_WIDTH); 540 textRect.SetWidth(TEXT_RECT_WIDTH); 541 textRect.SetTop(TEXT_RECT_TOP_ONE); 542 drawObscuredRects.push_back(textRect); 543 textContentModifier->SetDrawObscuredRects(drawObscuredRects); 544 545 /** 546 * @tc.steps: step3. call DrawObscuration function of textContentModifier. 547 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects. 548 */ 549 textContentModifier->DrawObscuration(context); 550 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects); 551 552 /** 553 * @tc.steps: step4. push two rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects. 554 */ 555 drawObscuredRects.push_back(textRect); 556 textRect.SetTop(TEXT_RECT_TOP_TWO); 557 drawObscuredRects.push_back(textRect); 558 textContentModifier->SetDrawObscuredRects(drawObscuredRects); 559 560 /** 561 * @tc.steps: step5. call DrawObscuration function of textContentModifier. 562 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects. 563 */ 564 textContentModifier->DrawObscuration(context); 565 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects); 566 567 /** 568 * @tc.steps: step6. push three rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects. 569 */ 570 textRect.SetHeight(TEXT_RECT_SIZE_ZEOR); 571 drawObscuredRects.push_back(textRect); 572 textContentModifier->SetDrawObscuredRects(drawObscuredRects); 573 574 /** 575 * @tc.steps: step7. call DrawObscuration function of textContentModifier. 576 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects. 577 */ 578 textContentModifier->DrawObscuration(context); 579 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects); 580 581 /** 582 * @tc.steps: step8. push four rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects. 583 */ 584 textRect.SetWidth(TEXT_RECT_SIZE_ZEOR); 585 drawObscuredRects.push_back(textRect); 586 textContentModifier->SetDrawObscuredRects(drawObscuredRects); 587 588 /** 589 * @tc.steps: step9. call DrawObscuration function of textContentModifier. 590 * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects. 591 */ 592 textContentModifier->DrawObscuration(context); 593 EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects); 594 textPattern->pManager_->Reset(); 595 } 596 597 /** 598 * @tc.name: TextContentModifier005 599 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 600 * @tc.type: FUNC 601 */ 602 HWTEST_F(TextTestFourNg, TextContentModifier005, TestSize.Level1) 603 { 604 /** 605 * @tc.steps: step1. create textFrameNode and textPattern. 606 */ 607 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 608 ASSERT_NE(textFrameNode, nullptr); 609 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 610 ASSERT_NE(geometryNode, nullptr); 611 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 612 ASSERT_NE(textPattern, nullptr); 613 614 /** 615 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 616 */ 617 ParagraphStyle paragraphStyle; 618 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 619 ASSERT_NE(paragraph, nullptr); 620 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 621 std::vector<WeakPtr<FrameNode>> imageNodeList; 622 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 623 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0202() 624 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 625 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 626 textPattern->SetImageSpanNodeList(imageNodeList); 627 /** 628 * @tc.steps: step3. call CreateNodePaintMethod func. 629 * @tc.expected: The imageNodeList_ size is equal to 1. 630 */ 631 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 632 ASSERT_NE(textPaintMethod, nullptr); 633 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 634 auto paintProperty = textPattern->CreatePaintProperty(); 635 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 636 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 637 638 ASSERT_NE(textPaintMethod->textContentModifier_, nullptr); 639 EXPECT_EQ(textPaintMethod->textContentModifier_->imageNodeList_.size(), 1); 640 textPattern->pManager_->Reset(); 641 } 642 643 /** 644 * @tc.name: TextContentModifier006 645 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 646 * @tc.type: FUNC 647 */ 648 HWTEST_F(TextTestFourNg, TextContentModifier006, TestSize.Level1) 649 { 650 /** 651 * @tc.steps: step1. create textFrameNode and textPattern. 652 */ 653 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 654 ASSERT_NE(textFrameNode, nullptr); 655 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 656 ASSERT_NE(geometryNode, nullptr); 657 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 658 ASSERT_NE(textPattern, nullptr); 659 660 /** 661 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 662 */ 663 ParagraphStyle paragraphStyle; 664 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 665 ASSERT_NE(paragraph, nullptr); 666 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 667 668 /** 669 * @tc.steps: step3. call CreateNodePaintMethod func. 670 * @tc.expected: The imageNodeList_ size is equal to 0. 671 */ 672 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 673 ASSERT_NE(textPaintMethod, nullptr); 674 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 675 auto paintProperty = textPattern->CreatePaintProperty(); 676 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 677 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 678 679 ASSERT_NE(textPaintMethod->textContentModifier_, nullptr); 680 EXPECT_EQ(textPaintMethod->textContentModifier_->imageNodeList_.size(), 0); 681 textPattern->pManager_->Reset(); 682 } 683 684 /** 685 * @tc.name: TextContentModifier007 686 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 687 * @tc.type: FUNC 688 */ 689 HWTEST_F(TextTestFourNg, TextContentModifier007, TestSize.Level1) 690 { 691 /** 692 * @tc.steps: step1. create textFrameNode and textPattern. 693 */ 694 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 695 ASSERT_NE(textFrameNode, nullptr); 696 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 697 ASSERT_NE(geometryNode, nullptr); 698 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 699 ASSERT_NE(textPattern, nullptr); 700 /** 701 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 702 */ 703 ParagraphStyle paragraphStyle; 704 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 705 ASSERT_NE(paragraph, nullptr); 706 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 707 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 708 std::vector<WeakPtr<FrameNode>> imageNodeList; 709 for (int i = 0; i < 10; i++) { 710 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 711 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0302() 712 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 713 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 714 imageNodeLocalList.emplace_back(imageNode); 715 } 716 textPattern->SetImageSpanNodeList(imageNodeList); 717 718 /** 719 * @tc.steps: step3. call CreateNodePaintMethod func. 720 * @tc.expected: The imageNodeList_ size is equal to 10. 721 */ 722 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 723 ASSERT_NE(textPaintMethod, nullptr); 724 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 725 auto paintProperty = textPattern->CreatePaintProperty(); 726 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 727 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 728 ASSERT_NE(textPaintMethod, nullptr); 729 auto textContentModifier = textPaintMethod->textContentModifier_; 730 ASSERT_NE(textContentModifier, nullptr); 731 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 732 textPattern->pManager_->Reset(); 733 } 734 735 /** 736 * @tc.name: TextContentModifier008 737 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 738 * @tc.type: FUNC 739 */ 740 HWTEST_F(TextTestFourNg, TextContentModifier008, TestSize.Level1) 741 { 742 /** 743 * @tc.steps: step1. create textFrameNode and textPattern. 744 */ 745 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 746 ASSERT_NE(textFrameNode, nullptr); 747 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 748 ASSERT_NE(geometryNode, nullptr); 749 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 750 ASSERT_NE(textPattern, nullptr); 751 /** 752 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 753 */ 754 ParagraphStyle paragraphStyle; 755 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 756 ASSERT_NE(paragraph, nullptr); 757 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 758 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 759 std::vector<WeakPtr<FrameNode>> imageNodeList; 760 for (int i = 0; i < 100; i++) { 761 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 762 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0402() 763 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 764 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 765 imageNodeLocalList.emplace_back(imageNode); 766 } 767 textPattern->SetImageSpanNodeList(imageNodeList); 768 769 /** 770 * @tc.steps: step3. call CreateNodePaintMethod func. 771 * @tc.expected: The imageNodeList_ size is equal to 100. 772 */ 773 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 774 ASSERT_NE(textPaintMethod, nullptr); 775 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 776 auto paintProperty = textPattern->CreatePaintProperty(); 777 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 778 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 779 ASSERT_NE(textPaintMethod, nullptr); 780 auto textContentModifier = textPaintMethod->textContentModifier_; 781 ASSERT_NE(textContentModifier, nullptr); 782 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 100); 783 textPattern->pManager_->Reset(); 784 } 785 786 /** 787 * @tc.name: TextContentModifier009 788 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 789 * @tc.type: FUNC 790 */ 791 HWTEST_F(TextTestFourNg, TextContentModifier009, TestSize.Level1) 792 { 793 /** 794 * @tc.steps: step1. create textFrameNode and textPattern. 795 */ 796 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 797 ASSERT_NE(textFrameNode, nullptr); 798 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 799 ASSERT_NE(geometryNode, nullptr); 800 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 801 ASSERT_NE(textPattern, nullptr); 802 /** 803 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 804 */ 805 ParagraphStyle paragraphStyle; 806 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 807 ASSERT_NE(paragraph, nullptr); 808 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 809 std::vector<WeakPtr<FrameNode>> imageNodeList; 810 for (int i = 0; i < 10; i++) { 811 imageNodeList.emplace_back(nullptr); 812 } 813 textPattern->SetImageSpanNodeList(imageNodeList); 814 815 /** 816 * @tc.steps: step3. call CreateNodePaintMethod func. 817 * @tc.expected: The imageNodeList_ size is equal to 10. 818 */ 819 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 820 ASSERT_NE(textPaintMethod, nullptr); 821 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 822 auto paintProperty = textPattern->CreatePaintProperty(); 823 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 824 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 825 ASSERT_NE(textPaintMethod, nullptr); 826 auto textContentModifier = textPaintMethod->textContentModifier_; 827 ASSERT_NE(textContentModifier, nullptr); 828 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 829 textPattern->pManager_->Reset(); 830 } 831 832 /** 833 * @tc.name: TextContentModifier010 834 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 835 * @tc.type: FUNC 836 */ 837 HWTEST_F(TextTestFourNg, TextContentModifier010, TestSize.Level1) 838 { 839 /** 840 * @tc.steps: step1. create textFrameNode and textPattern. 841 */ 842 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 843 ASSERT_NE(textFrameNode, nullptr); 844 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 845 ASSERT_NE(geometryNode, nullptr); 846 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 847 ASSERT_NE(textPattern, nullptr); 848 /** 849 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 850 */ 851 ParagraphStyle paragraphStyle; 852 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 853 ASSERT_NE(paragraph, nullptr); 854 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 855 std::vector<WeakPtr<FrameNode>> imageNodeList; 856 for (int i = 0; i < 100; i++) { 857 imageNodeList.emplace_back(nullptr); 858 } 859 textPattern->SetImageSpanNodeList(imageNodeList); 860 861 /** 862 * @tc.steps: step3. call CreateNodePaintMethod func. 863 * @tc.expected: The imageNodeList_ size is equal to 100. 864 */ 865 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 866 ASSERT_NE(textPaintMethod, nullptr); 867 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 868 auto paintProperty = textPattern->CreatePaintProperty(); 869 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 870 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 871 ASSERT_NE(textPaintMethod, nullptr); 872 auto textContentModifier = textPaintMethod->textContentModifier_; 873 ASSERT_NE(textContentModifier, nullptr); 874 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 100); 875 textPattern->pManager_->Reset(); 876 } 877 878 /** 879 * @tc.name: TextContentModifier011 880 * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function 881 * @tc.type: FUNC 882 */ 883 HWTEST_F(TextTestFourNg, TextContentModifier011, TestSize.Level1) 884 { 885 /** 886 * @tc.steps: step1. create textFrameNode and textPattern. 887 */ 888 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 889 ASSERT_NE(textFrameNode, nullptr); 890 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 891 ASSERT_NE(geometryNode, nullptr); 892 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 893 ASSERT_NE(textPattern, nullptr); 894 /** 895 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 896 */ 897 ParagraphStyle paragraphStyle; 898 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 899 ASSERT_NE(paragraph, nullptr); 900 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 901 std::vector<WeakPtr<FrameNode>> imageNodeList; 902 for (int i = 0; i < 500; i++) { 903 imageNodeList.emplace_back(nullptr); 904 } 905 textPattern->SetImageSpanNodeList(imageNodeList); 906 907 /** 908 * @tc.steps: step3. call CreateNodePaintMethod func. 909 * @tc.expected: The imageNodeList_ size is equal to 500. 910 */ 911 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 912 ASSERT_NE(textPaintMethod, nullptr); 913 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 914 auto paintProperty = textPattern->CreatePaintProperty(); 915 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 916 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 917 ASSERT_NE(textPaintMethod, nullptr); 918 auto textContentModifier = textPaintMethod->textContentModifier_; 919 ASSERT_NE(textContentModifier, nullptr); 920 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 500); 921 textPattern->pManager_->Reset(); 922 } 923 924 /** 925 * @tc.name: TextContentModifier012 926 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 927 * @tc.type: FUNC 928 */ 929 HWTEST_F(TextTestFourNg, TextContentModifier012, TestSize.Level1) 930 { 931 /** 932 * @tc.steps: step1. create textFrameNode and textPattern. 933 */ 934 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 935 ASSERT_NE(textFrameNode, nullptr); 936 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 937 ASSERT_NE(geometryNode, nullptr); 938 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 939 ASSERT_NE(textPattern, nullptr); 940 /** 941 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 942 */ 943 ParagraphStyle paragraphStyle; 944 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 945 ASSERT_NE(paragraph, nullptr); 946 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 947 std::vector<WeakPtr<FrameNode>> imageNodeList; 948 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 949 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0502() 950 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 951 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 952 textPattern->SetImageSpanNodeList(imageNodeList); 953 auto layoutProperty = imageNode->GetLayoutProperty(); 954 ASSERT_NE(layoutProperty, nullptr); 955 layoutProperty->UpdateVisibility(VisibleType::VISIBLE, true); 956 /** 957 * @tc.steps: step3. call CreateNodePaintMethod func. 958 * @tc.expected: The imageNodeList_ size is equal to 1. 959 */ 960 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 961 ASSERT_NE(textPaintMethod, nullptr); 962 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 963 auto paintProperty = textPattern->CreatePaintProperty(); 964 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 965 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 966 ASSERT_NE(textPaintMethod, nullptr); 967 auto textContentModifier = textPaintMethod->textContentModifier_; 968 ASSERT_NE(textContentModifier, nullptr); 969 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 1); 970 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 971 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 972 auto imageNode = imageWeak.Upgrade(); 973 ASSERT_NE(imageNode, nullptr); 974 auto layoutProperty1 = imageNode->GetLayoutProperty(); 975 ASSERT_NE(layoutProperty, nullptr); 976 EXPECT_EQ(static_cast<int32_t>(layoutProperty1->GetVisibility().has_value() && 977 (layoutProperty1->GetVisibility().value() == VisibleType::INVISIBLE)), 1); 978 } 979 980 textPattern->pManager_->Reset(); 981 } 982 983 /** 984 * @tc.name: TextContentModifier013 985 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 986 * @tc.type: FUNC 987 */ 988 HWTEST_F(TextTestFourNg, TextContentModifier013, TestSize.Level1) 989 { 990 /** 991 * @tc.steps: step1. create textFrameNode and textPattern. 992 */ 993 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 994 ASSERT_NE(textFrameNode, nullptr); 995 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 996 ASSERT_NE(geometryNode, nullptr); 997 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 998 ASSERT_NE(textPattern, nullptr); 999 /** 1000 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1001 */ 1002 ParagraphStyle paragraphStyle; 1003 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1004 ASSERT_NE(paragraph, nullptr); 1005 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1006 std::vector<WeakPtr<FrameNode>> imageNodeList; 1007 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1008 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0602() 1009 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1010 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1011 textPattern->SetImageSpanNodeList(imageNodeList); 1012 auto layoutProperty = imageNode->GetLayoutProperty(); 1013 ASSERT_NE(layoutProperty, nullptr); 1014 layoutProperty->UpdateVisibility(VisibleType::VISIBLE, true); 1015 /** 1016 * @tc.steps: step3. call CreateNodePaintMethod func. 1017 * @tc.expected: The imageNodeList_ size is equal to 1. 1018 */ 1019 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1020 ASSERT_NE(textPaintMethod, nullptr); 1021 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1022 auto paintProperty = textPattern->CreatePaintProperty(); 1023 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1024 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1025 ASSERT_NE(textPaintMethod, nullptr); 1026 auto textContentModifier = textPaintMethod->textContentModifier_; 1027 ASSERT_NE(textContentModifier, nullptr); 1028 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1029 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 1); 1030 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1031 auto imageNode = imageWeak.Upgrade(); 1032 ASSERT_NE(imageNode, nullptr); 1033 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1034 ASSERT_NE(layoutProperty, nullptr); 1035 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1036 (layoutProperty2->GetVisibility().value() == VisibleType::VISIBLE)), 1); 1037 } 1038 1039 textPattern->pManager_->Reset(); 1040 } 1041 1042 /** 1043 * @tc.name: TextContentModifier014 1044 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1045 * @tc.type: FUNC 1046 */ 1047 HWTEST_F(TextTestFourNg, TextContentModifier014, TestSize.Level1) 1048 { 1049 /** 1050 * @tc.steps: step1. create textFrameNode and textPattern. 1051 */ 1052 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1053 ASSERT_NE(textFrameNode, nullptr); 1054 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1055 ASSERT_NE(geometryNode, nullptr); 1056 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1057 ASSERT_NE(textPattern, nullptr); 1058 /** 1059 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1060 */ 1061 ParagraphStyle paragraphStyle; 1062 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1063 ASSERT_NE(paragraph, nullptr); 1064 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1065 std::vector<WeakPtr<FrameNode>> imageNodeList; 1066 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1067 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0702() 1068 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1069 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1070 textPattern->SetImageSpanNodeList(imageNodeList); 1071 auto layoutProperty = imageNode->GetLayoutProperty(); 1072 ASSERT_NE(layoutProperty, nullptr); 1073 layoutProperty->UpdateVisibility(VisibleType::GONE, true); 1074 /** 1075 * @tc.steps: step3. call CreateNodePaintMethod func. 1076 * @tc.expected: The imageNodeList_ size is equal to 1. 1077 */ 1078 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1079 ASSERT_NE(textPaintMethod, nullptr); 1080 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1081 auto paintProperty = textPattern->CreatePaintProperty(); 1082 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1083 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1084 ASSERT_NE(textPaintMethod, nullptr); 1085 auto textContentModifier = textPaintMethod->textContentModifier_; 1086 ASSERT_NE(textContentModifier, nullptr); 1087 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1088 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 1); 1089 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1090 auto imageNode = imageWeak.Upgrade(); 1091 ASSERT_NE(imageNode, nullptr); 1092 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1093 ASSERT_NE(layoutProperty, nullptr); 1094 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1095 (layoutProperty2->GetVisibility().value() == VisibleType::GONE)), 1); 1096 } 1097 1098 textPattern->pManager_->Reset(); 1099 } 1100 1101 /** 1102 * @tc.name: TextContentModifier015 1103 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1104 * @tc.type: FUNC 1105 */ 1106 HWTEST_F(TextTestFourNg, TextContentModifier015, TestSize.Level1) 1107 { 1108 /** 1109 * @tc.steps: step1. create textFrameNode and textPattern. 1110 */ 1111 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1112 ASSERT_NE(textFrameNode, nullptr); 1113 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1114 ASSERT_NE(geometryNode, nullptr); 1115 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1116 ASSERT_NE(textPattern, nullptr); 1117 /** 1118 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1119 */ 1120 ParagraphStyle paragraphStyle; 1121 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1122 ASSERT_NE(paragraph, nullptr); 1123 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1124 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1125 std::vector<WeakPtr<FrameNode>> imageNodeList; 1126 for (int i = 0; i < 10; i++) { 1127 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1128 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0802() 1129 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1130 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1131 imageNodeLocalList.emplace_back(imageNode); 1132 } 1133 textPattern->SetImageSpanNodeList(imageNodeList); 1134 1135 /** 1136 * @tc.steps: step3. call CreateNodePaintMethod func. 1137 * @tc.expected: The imageNodeList_ size is equal to 10. 1138 */ 1139 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1140 ASSERT_NE(textPaintMethod, nullptr); 1141 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1142 auto paintProperty = textPattern->CreatePaintProperty(); 1143 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1144 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1145 ASSERT_NE(textPaintMethod, nullptr); 1146 auto textContentModifier = textPaintMethod->textContentModifier_; 1147 ASSERT_NE(textContentModifier, nullptr); 1148 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1149 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 1150 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1151 auto imageNode = imageWeak.Upgrade(); 1152 ASSERT_NE(imageNode, nullptr); 1153 auto layoutProperty1 = imageNode->GetLayoutProperty(); 1154 ASSERT_NE(layoutProperty1, nullptr); 1155 EXPECT_EQ(static_cast<int32_t>(layoutProperty1->GetVisibility().has_value() && 1156 (layoutProperty1->GetVisibility().value() == VisibleType::INVISIBLE)), 1); 1157 } 1158 1159 textPattern->pManager_->Reset(); 1160 } 1161 1162 /** 1163 * @tc.name: TextContentModifier016 1164 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1165 * @tc.type: FUNC 1166 */ 1167 HWTEST_F(TextTestFourNg, TextContentModifier016, TestSize.Level1) 1168 { 1169 /** 1170 * @tc.steps: step1. create textFrameNode and textPattern. 1171 */ 1172 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1173 ASSERT_NE(textFrameNode, nullptr); 1174 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1175 ASSERT_NE(geometryNode, nullptr); 1176 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1177 ASSERT_NE(textPattern, nullptr); 1178 /** 1179 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1180 */ 1181 ParagraphStyle paragraphStyle; 1182 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1183 ASSERT_NE(paragraph, nullptr); 1184 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1185 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1186 std::vector<WeakPtr<FrameNode>> imageNodeList; 1187 for (int i = 0; i < 10; i++) { 1188 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1189 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0902() 1190 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1191 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1192 imageNodeLocalList.emplace_back(imageNode); 1193 } 1194 textPattern->SetImageSpanNodeList(imageNodeList); 1195 1196 /** 1197 * @tc.steps: step3. call CreateNodePaintMethod func. 1198 * @tc.expected: The imageNodeList_ size is equal to 10. 1199 */ 1200 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1201 ASSERT_NE(textPaintMethod, nullptr); 1202 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1203 auto paintProperty = textPattern->CreatePaintProperty(); 1204 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1205 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1206 ASSERT_NE(textPaintMethod, nullptr); 1207 auto textContentModifier = textPaintMethod->textContentModifier_; 1208 ASSERT_NE(textContentModifier, nullptr); 1209 1210 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1211 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1212 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1213 auto imageNode = imageWeak.Upgrade(); 1214 ASSERT_NE(imageNode, nullptr); 1215 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1216 ASSERT_NE(layoutProperty2, nullptr); 1217 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1218 (layoutProperty2->GetVisibility().value() == VisibleType::VISIBLE)), 1); 1219 } 1220 1221 textPattern->pManager_->Reset(); 1222 } 1223 1224 /** 1225 * @tc.name: TextContentModifier017 1226 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1227 * @tc.type: FUNC 1228 */ 1229 HWTEST_F(TextTestFourNg, TextContentModifier017, TestSize.Level1) 1230 { 1231 /** 1232 * @tc.steps: step1. create textFrameNode and textPattern. 1233 */ 1234 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1235 ASSERT_NE(textFrameNode, nullptr); 1236 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1237 ASSERT_NE(geometryNode, nullptr); 1238 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1239 ASSERT_NE(textPattern, nullptr); 1240 /** 1241 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1242 */ 1243 ParagraphStyle paragraphStyle; 1244 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1245 ASSERT_NE(paragraph, nullptr); 1246 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1247 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1248 std::vector<WeakPtr<FrameNode>> imageNodeList; 1249 for (int i = 0; i < 10; i++) { 1250 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1251 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0a02() 1252 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1253 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1254 imageNodeLocalList.emplace_back(imageNode); 1255 } 1256 textPattern->SetImageSpanNodeList(imageNodeList); 1257 1258 /** 1259 * @tc.steps: step3. call CreateNodePaintMethod func. 1260 * @tc.expected: The imageNodeList_ size is equal to 10. 1261 */ 1262 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1263 ASSERT_NE(textPaintMethod, nullptr); 1264 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1265 auto paintProperty = textPattern->CreatePaintProperty(); 1266 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1267 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1268 ASSERT_NE(textPaintMethod, nullptr); 1269 auto textContentModifier = textPaintMethod->textContentModifier_; 1270 ASSERT_NE(textContentModifier, nullptr); 1271 1272 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1273 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1274 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1275 auto imageNode = imageWeak.Upgrade(); 1276 ASSERT_NE(imageNode, nullptr); 1277 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1278 ASSERT_NE(layoutProperty2, nullptr); 1279 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1280 (layoutProperty2->GetVisibility().value() == VisibleType::GONE)), 1); 1281 } 1282 1283 textPattern->pManager_->Reset(); 1284 } 1285 1286 /** 1287 * @tc.name: TextContentModifier018 1288 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1289 * @tc.type: FUNC 1290 */ 1291 HWTEST_F(TextTestFourNg, TextContentModifier018, TestSize.Level1) 1292 { 1293 /** 1294 * @tc.steps: step1. create textFrameNode and textPattern. 1295 */ 1296 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1297 ASSERT_NE(textFrameNode, nullptr); 1298 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1299 ASSERT_NE(geometryNode, nullptr); 1300 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1301 ASSERT_NE(textPattern, nullptr); 1302 /** 1303 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1304 */ 1305 ParagraphStyle paragraphStyle; 1306 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1307 ASSERT_NE(paragraph, nullptr); 1308 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1309 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1310 std::vector<WeakPtr<FrameNode>> imageNodeList; 1311 for (int i = 0; i < 100; i++) { 1312 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1313 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0b02() 1314 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1315 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1316 imageNodeLocalList.emplace_back(imageNode); 1317 } 1318 textPattern->SetImageSpanNodeList(imageNodeList); 1319 1320 /** 1321 * @tc.steps: step3. call CreateNodePaintMethod func. 1322 * @tc.expected: The imageNodeList_ size is equal to 100. 1323 */ 1324 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1325 ASSERT_NE(textPaintMethod, nullptr); 1326 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1327 auto paintProperty = textPattern->CreatePaintProperty(); 1328 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1329 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1330 ASSERT_NE(textPaintMethod, nullptr); 1331 auto textContentModifier = textPaintMethod->textContentModifier_; 1332 ASSERT_NE(textContentModifier, nullptr); 1333 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 100); 1334 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 1335 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1336 auto imageNode = imageWeak.Upgrade(); 1337 ASSERT_NE(imageNode, nullptr); 1338 auto layoutProperty1 = imageNode->GetLayoutProperty(); 1339 ASSERT_NE(layoutProperty1, nullptr); 1340 EXPECT_EQ(static_cast<int32_t>(layoutProperty1->GetVisibility().has_value() && 1341 (layoutProperty1->GetVisibility().value() == VisibleType::INVISIBLE)), 1); 1342 } 1343 1344 textPattern->pManager_->Reset(); 1345 } 1346 1347 /** 1348 * @tc.name: TextContentModifier019 1349 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1350 * @tc.type: FUNC 1351 */ 1352 HWTEST_F(TextTestFourNg, TextContentModifier019, TestSize.Level1) 1353 { 1354 /** 1355 * @tc.steps: step1. create textFrameNode and textPattern. 1356 */ 1357 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1358 ASSERT_NE(textFrameNode, nullptr); 1359 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1360 ASSERT_NE(geometryNode, nullptr); 1361 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1362 ASSERT_NE(textPattern, nullptr); 1363 /** 1364 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1365 */ 1366 ParagraphStyle paragraphStyle; 1367 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1368 ASSERT_NE(paragraph, nullptr); 1369 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1370 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1371 std::vector<WeakPtr<FrameNode>> imageNodeList; 1372 for (int i = 0; i < 100; i++) { 1373 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1374 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0c02() 1375 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1376 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1377 imageNodeLocalList.emplace_back(imageNode); 1378 } 1379 textPattern->SetImageSpanNodeList(imageNodeList); 1380 1381 /** 1382 * @tc.steps: step3. call CreateNodePaintMethod func. 1383 * @tc.expected: The imageNodeList_ size is equal to 100. 1384 */ 1385 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1386 ASSERT_NE(textPaintMethod, nullptr); 1387 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1388 auto paintProperty = textPattern->CreatePaintProperty(); 1389 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1390 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1391 ASSERT_NE(textPaintMethod, nullptr); 1392 auto textContentModifier = textPaintMethod->textContentModifier_; 1393 ASSERT_NE(textContentModifier, nullptr); 1394 1395 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1396 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 100); 1397 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1398 auto imageNode = imageWeak.Upgrade(); 1399 ASSERT_NE(imageNode, nullptr); 1400 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1401 ASSERT_NE(layoutProperty2, nullptr); 1402 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1403 (layoutProperty2->GetVisibility().value() == VisibleType::VISIBLE)), 1); 1404 } 1405 textPattern->pManager_->Reset(); 1406 } 1407 1408 /** 1409 * @tc.name: TextContentModifier020 1410 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1411 * @tc.type: FUNC 1412 */ 1413 HWTEST_F(TextTestFourNg, TextContentModifier020, TestSize.Level1) 1414 { 1415 /** 1416 * @tc.steps: step1. create textFrameNode and textPattern. 1417 */ 1418 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1419 ASSERT_NE(textFrameNode, nullptr); 1420 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1421 ASSERT_NE(geometryNode, nullptr); 1422 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1423 ASSERT_NE(textPattern, nullptr); 1424 /** 1425 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1426 */ 1427 ParagraphStyle paragraphStyle; 1428 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1429 ASSERT_NE(paragraph, nullptr); 1430 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1431 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1432 std::vector<WeakPtr<FrameNode>> imageNodeList; 1433 for (int i = 0; i < 100; i++) { 1434 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1435 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0d02() 1436 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1437 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1438 imageNodeLocalList.emplace_back(imageNode); 1439 } 1440 textPattern->SetImageSpanNodeList(imageNodeList); 1441 1442 /** 1443 * @tc.steps: step3. call CreateNodePaintMethod func. 1444 * @tc.expected: The imageNodeList_ size is equal to 100. 1445 */ 1446 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1447 ASSERT_NE(textPaintMethod, nullptr); 1448 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1449 auto paintProperty = textPattern->CreatePaintProperty(); 1450 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1451 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1452 ASSERT_NE(textPaintMethod, nullptr); 1453 auto textContentModifier = textPaintMethod->textContentModifier_; 1454 ASSERT_NE(textContentModifier, nullptr); 1455 1456 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1457 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 100); 1458 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1459 auto imageNode = imageWeak.Upgrade(); 1460 ASSERT_NE(imageNode, nullptr); 1461 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1462 ASSERT_NE(layoutProperty2, nullptr); 1463 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1464 (layoutProperty2->GetVisibility().value() == VisibleType::GONE)), 1); 1465 } 1466 textPattern->pManager_->Reset(); 1467 } 1468 1469 /** 1470 * @tc.name: TextContentModifier021 1471 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1472 * @tc.type: FUNC 1473 */ 1474 HWTEST_F(TextTestFourNg, TextContentModifier021, TestSize.Level1) 1475 { 1476 /** 1477 * @tc.steps: step1. create textFrameNode and textPattern. 1478 */ 1479 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1480 ASSERT_NE(textFrameNode, nullptr); 1481 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1482 ASSERT_NE(geometryNode, nullptr); 1483 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1484 ASSERT_NE(textPattern, nullptr); 1485 /** 1486 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1487 */ 1488 ParagraphStyle paragraphStyle; 1489 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1490 ASSERT_NE(paragraph, nullptr); 1491 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1492 std::vector<WeakPtr<FrameNode>> imageNodeList; 1493 for (int i = 0; i < 10; i++) { 1494 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1495 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0e02() 1496 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1497 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1498 } 1499 textPattern->SetImageSpanNodeList(imageNodeList); 1500 1501 /** 1502 * @tc.steps: step3. call CreateNodePaintMethod func. 1503 * @tc.expected: The imageNodeList_ size is equal to 10. 1504 */ 1505 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1506 ASSERT_NE(textPaintMethod, nullptr); 1507 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1508 auto paintProperty = textPattern->CreatePaintProperty(); 1509 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1510 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1511 ASSERT_NE(textPaintMethod, nullptr); 1512 auto textContentModifier = textPaintMethod->textContentModifier_; 1513 ASSERT_NE(textContentModifier, nullptr); 1514 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1515 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 1516 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1517 auto imageNode = imageWeak.Upgrade(); 1518 EXPECT_EQ(imageNode, nullptr); 1519 } 1520 1521 textPattern->pManager_->Reset(); 1522 } 1523 1524 /** 1525 * @tc.name: TextContentModifier022 1526 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1527 * @tc.type: FUNC 1528 */ 1529 HWTEST_F(TextTestFourNg, TextContentModifier022, TestSize.Level1) 1530 { 1531 /** 1532 * @tc.steps: step1. create textFrameNode and textPattern. 1533 */ 1534 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1535 ASSERT_NE(textFrameNode, nullptr); 1536 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1537 ASSERT_NE(geometryNode, nullptr); 1538 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1539 ASSERT_NE(textPattern, nullptr); 1540 /** 1541 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1542 */ 1543 ParagraphStyle paragraphStyle; 1544 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1545 ASSERT_NE(paragraph, nullptr); 1546 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1547 std::vector<WeakPtr<FrameNode>> imageNodeList; 1548 for (int i = 0; i < 10; i++) { 1549 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1550 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb0f02() 1551 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1552 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1553 } 1554 textPattern->SetImageSpanNodeList(imageNodeList); 1555 1556 /** 1557 * @tc.steps: step3. call CreateNodePaintMethod func. 1558 * @tc.expected: The imageNodeList_ size is equal to 10. 1559 */ 1560 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1561 ASSERT_NE(textPaintMethod, nullptr); 1562 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1563 auto paintProperty = textPattern->CreatePaintProperty(); 1564 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1565 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1566 ASSERT_NE(textPaintMethod, nullptr); 1567 auto textContentModifier = textPaintMethod->textContentModifier_; 1568 ASSERT_NE(textContentModifier, nullptr); 1569 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1570 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1571 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1572 auto imageNode = imageWeak.Upgrade(); 1573 EXPECT_EQ(imageNode, nullptr); 1574 } 1575 1576 textPattern->pManager_->Reset(); 1577 } 1578 1579 /** 1580 * @tc.name: TextContentModifier023 1581 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1582 * @tc.type: FUNC 1583 */ 1584 HWTEST_F(TextTestFourNg, TextContentModifier023, TestSize.Level1) 1585 { 1586 /** 1587 * @tc.steps: step1. create textFrameNode and textPattern. 1588 */ 1589 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1590 ASSERT_NE(textFrameNode, nullptr); 1591 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1592 ASSERT_NE(geometryNode, nullptr); 1593 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1594 ASSERT_NE(textPattern, nullptr); 1595 /** 1596 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1597 */ 1598 ParagraphStyle paragraphStyle; 1599 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1600 ASSERT_NE(paragraph, nullptr); 1601 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1602 std::vector<WeakPtr<FrameNode>> imageNodeList; 1603 for (int i = 0; i < 10; i++) { 1604 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1605 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb1002() 1606 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1607 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1608 } 1609 textPattern->SetImageSpanNodeList(imageNodeList); 1610 1611 /** 1612 * @tc.steps: step3. call CreateNodePaintMethod func. 1613 * @tc.expected: The imageNodeList_ size is equal to 10. 1614 */ 1615 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1616 ASSERT_NE(textPaintMethod, nullptr); 1617 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1618 auto paintProperty = textPattern->CreatePaintProperty(); 1619 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1620 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1621 ASSERT_NE(textPaintMethod, nullptr); 1622 auto textContentModifier = textPaintMethod->textContentModifier_; 1623 ASSERT_NE(textContentModifier, nullptr); 1624 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1625 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1626 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1627 auto imageNode = imageWeak.Upgrade(); 1628 EXPECT_EQ(imageNode, nullptr); 1629 } 1630 1631 textPattern->pManager_->Reset(); 1632 } 1633 1634 /** 1635 * @tc.name: TextContentModifier024 1636 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1637 * @tc.type: FUNC 1638 */ 1639 HWTEST_F(TextTestFourNg, TextContentModifier024, TestSize.Level1) 1640 { 1641 /** 1642 * @tc.steps: step1. create textFrameNode and textPattern. 1643 */ 1644 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1645 ASSERT_NE(textFrameNode, nullptr); 1646 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1647 ASSERT_NE(geometryNode, nullptr); 1648 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1649 ASSERT_NE(textPattern, nullptr); 1650 /** 1651 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1652 */ 1653 ParagraphStyle paragraphStyle; 1654 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1655 ASSERT_NE(paragraph, nullptr); 1656 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1657 std::vector<WeakPtr<FrameNode>> imageNodeList; 1658 for (int i = 0; i < 10; i++) { 1659 imageNodeList.emplace_back(nullptr); 1660 } 1661 textPattern->SetImageSpanNodeList(imageNodeList); 1662 1663 /** 1664 * @tc.steps: step3. call CreateNodePaintMethod func. 1665 * @tc.expected: The imageNodeList_ size is equal to 10. 1666 */ 1667 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1668 ASSERT_NE(textPaintMethod, nullptr); 1669 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1670 auto paintProperty = textPattern->CreatePaintProperty(); 1671 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1672 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1673 ASSERT_NE(textPaintMethod, nullptr); 1674 auto textContentModifier = textPaintMethod->textContentModifier_; 1675 ASSERT_NE(textContentModifier, nullptr); 1676 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1677 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 1678 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1679 auto imageNode = imageWeak.Upgrade(); 1680 EXPECT_EQ(imageNode, nullptr); 1681 } 1682 1683 textPattern->pManager_->Reset(); 1684 } 1685 1686 /** 1687 * @tc.name: TextContentModifier025 1688 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1689 * @tc.type: FUNC 1690 */ 1691 HWTEST_F(TextTestFourNg, TextContentModifier025, TestSize.Level1) 1692 { 1693 /** 1694 * @tc.steps: step1. create textFrameNode and textPattern. 1695 */ 1696 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1697 ASSERT_NE(textFrameNode, nullptr); 1698 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1699 ASSERT_NE(geometryNode, nullptr); 1700 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1701 ASSERT_NE(textPattern, nullptr); 1702 /** 1703 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1704 */ 1705 ParagraphStyle paragraphStyle; 1706 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1707 ASSERT_NE(paragraph, nullptr); 1708 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1709 std::vector<WeakPtr<FrameNode>> imageNodeList; 1710 for (int i = 0; i < 10; i++) { 1711 imageNodeList.emplace_back(nullptr); 1712 } 1713 textPattern->SetImageSpanNodeList(imageNodeList); 1714 1715 /** 1716 * @tc.steps: step3. call CreateNodePaintMethod func. 1717 * @tc.expected: The imageNodeList_ size is equal to 10. 1718 */ 1719 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1720 ASSERT_NE(textPaintMethod, nullptr); 1721 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1722 auto paintProperty = textPattern->CreatePaintProperty(); 1723 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1724 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1725 ASSERT_NE(textPaintMethod, nullptr); 1726 auto textContentModifier = textPaintMethod->textContentModifier_; 1727 ASSERT_NE(textContentModifier, nullptr); 1728 1729 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1730 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1731 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1732 auto imageNode = imageWeak.Upgrade(); 1733 EXPECT_EQ(imageNode, nullptr); 1734 } 1735 textPattern->pManager_->Reset(); 1736 } 1737 1738 /** 1739 * @tc.name: TextContentModifier026 1740 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1741 * @tc.type: FUNC 1742 */ 1743 HWTEST_F(TextTestFourNg, TextContentModifier026, TestSize.Level1) 1744 { 1745 /** 1746 * @tc.steps: step1. create textFrameNode and textPattern. 1747 */ 1748 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1749 ASSERT_NE(textFrameNode, nullptr); 1750 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1751 ASSERT_NE(geometryNode, nullptr); 1752 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1753 ASSERT_NE(textPattern, nullptr); 1754 /** 1755 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1756 */ 1757 ParagraphStyle paragraphStyle; 1758 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1759 ASSERT_NE(paragraph, nullptr); 1760 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1761 std::vector<WeakPtr<FrameNode>> imageNodeList; 1762 for (int i = 0; i < 10; i++) { 1763 imageNodeList.emplace_back(nullptr); 1764 } 1765 textPattern->SetImageSpanNodeList(imageNodeList); 1766 1767 /** 1768 * @tc.steps: step3. call CreateNodePaintMethod func. 1769 * @tc.expected: The imageNodeList_ size is equal to 10. 1770 */ 1771 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1772 ASSERT_NE(textPaintMethod, nullptr); 1773 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1774 auto paintProperty = textPattern->CreatePaintProperty(); 1775 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1776 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1777 ASSERT_NE(textPaintMethod, nullptr); 1778 auto textContentModifier = textPaintMethod->textContentModifier_; 1779 ASSERT_NE(textContentModifier, nullptr); 1780 1781 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1782 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 10); 1783 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1784 auto imageNode = imageWeak.Upgrade(); 1785 EXPECT_EQ(imageNode, nullptr); 1786 } 1787 textPattern->pManager_->Reset(); 1788 } 1789 1790 /** 1791 * @tc.name: TextContentModifier027 1792 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1793 * @tc.type: FUNC 1794 */ 1795 HWTEST_F(TextTestFourNg, TextContentModifier027, TestSize.Level1) 1796 { 1797 /** 1798 * @tc.steps: step1. create textFrameNode and textPattern. 1799 */ 1800 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1801 ASSERT_NE(textFrameNode, nullptr); 1802 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1803 ASSERT_NE(geometryNode, nullptr); 1804 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1805 ASSERT_NE(textPattern, nullptr); 1806 /** 1807 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1808 */ 1809 ParagraphStyle paragraphStyle; 1810 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1811 ASSERT_NE(paragraph, nullptr); 1812 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1813 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1814 std::vector<WeakPtr<FrameNode>> imageNodeList; 1815 for (int i = 0; i < 200; i++) { 1816 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1817 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb1102() 1818 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1819 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1820 imageNodeLocalList.emplace_back(imageNode); 1821 } 1822 textPattern->SetImageSpanNodeList(imageNodeList); 1823 1824 /** 1825 * @tc.steps: step3. call CreateNodePaintMethod func. 1826 * @tc.expected: The imageNodeList_ size is equal to 200. 1827 */ 1828 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1829 ASSERT_NE(textPaintMethod, nullptr); 1830 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1831 auto paintProperty = textPattern->CreatePaintProperty(); 1832 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1833 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1834 ASSERT_NE(textPaintMethod, nullptr); 1835 auto textContentModifier = textPaintMethod->textContentModifier_; 1836 ASSERT_NE(textContentModifier, nullptr); 1837 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 200); 1838 textContentModifier->UpdateImageNodeVisible(VisibleType::INVISIBLE); 1839 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1840 auto imageNode = imageWeak.Upgrade(); 1841 ASSERT_NE(imageNode, nullptr); 1842 auto layoutProperty1 = imageNode->GetLayoutProperty(); 1843 ASSERT_NE(layoutProperty1, nullptr); 1844 EXPECT_EQ(static_cast<int32_t>(layoutProperty1->GetVisibility().has_value() && 1845 (layoutProperty1->GetVisibility().value() == VisibleType::INVISIBLE)), 1); 1846 } 1847 1848 textPattern->pManager_->Reset(); 1849 } 1850 1851 /** 1852 * @tc.name: TextContentModifier028 1853 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1854 * @tc.type: FUNC 1855 */ 1856 HWTEST_F(TextTestFourNg, TextContentModifier028, TestSize.Level1) 1857 { 1858 /** 1859 * @tc.steps: step1. create textFrameNode and textPattern. 1860 */ 1861 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1862 ASSERT_NE(textFrameNode, nullptr); 1863 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1864 ASSERT_NE(geometryNode, nullptr); 1865 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1866 ASSERT_NE(textPattern, nullptr); 1867 /** 1868 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1869 */ 1870 ParagraphStyle paragraphStyle; 1871 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1872 ASSERT_NE(paragraph, nullptr); 1873 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1874 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1875 std::vector<WeakPtr<FrameNode>> imageNodeList; 1876 for (int i = 0; i < 200; i++) { 1877 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1878 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb1202() 1879 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1880 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1881 imageNodeLocalList.emplace_back(imageNode); 1882 } 1883 textPattern->SetImageSpanNodeList(imageNodeList); 1884 1885 /** 1886 * @tc.steps: step3. call CreateNodePaintMethod func. 1887 * @tc.expected: The imageNodeList_ size is equal to 200. 1888 */ 1889 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1890 ASSERT_NE(textPaintMethod, nullptr); 1891 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1892 auto paintProperty = textPattern->CreatePaintProperty(); 1893 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1894 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1895 ASSERT_NE(textPaintMethod, nullptr); 1896 auto textContentModifier = textPaintMethod->textContentModifier_; 1897 ASSERT_NE(textContentModifier, nullptr); 1898 1899 textContentModifier->UpdateImageNodeVisible(VisibleType::VISIBLE); 1900 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 200); 1901 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1902 auto imageNode = imageWeak.Upgrade(); 1903 ASSERT_NE(imageNode, nullptr); 1904 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1905 ASSERT_NE(layoutProperty2, nullptr); 1906 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1907 (layoutProperty2->GetVisibility().value() == VisibleType::VISIBLE)), 1); 1908 } 1909 textPattern->pManager_->Reset(); 1910 } 1911 1912 /** 1913 * @tc.name: TextContentModifier029 1914 * @tc.desc: test text_content_modifier.cpp UpdateImageNodeVisible function 1915 * @tc.type: FUNC 1916 */ 1917 HWTEST_F(TextTestFourNg, TextContentModifier029, TestSize.Level1) 1918 { 1919 /** 1920 * @tc.steps: step1. create textFrameNode and textPattern. 1921 */ 1922 auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>()); 1923 ASSERT_NE(textFrameNode, nullptr); 1924 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 1925 ASSERT_NE(geometryNode, nullptr); 1926 auto textPattern = textFrameNode->GetPattern<TextPattern>(); 1927 ASSERT_NE(textPattern, nullptr); 1928 /** 1929 * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList. 1930 */ 1931 ParagraphStyle paragraphStyle; 1932 RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current()); 1933 ASSERT_NE(paragraph, nullptr); 1934 textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 }); 1935 std::vector<RefPtr<FrameNode>> imageNodeLocalList; 1936 std::vector<WeakPtr<FrameNode>> imageNodeList; 1937 for (int i = 0; i < 200; i++) { 1938 auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, 1939 ElementRegister::GetInstance()->MakeUniqueId(), __anonf83c6adb1302() 1940 []() { return AceType::MakeRefPtr<ImagePattern>(); }); 1941 imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode))); 1942 imageNodeLocalList.emplace_back(imageNode); 1943 } 1944 textPattern->SetImageSpanNodeList(imageNodeList); 1945 1946 /** 1947 * @tc.steps: step3. call CreateNodePaintMethod func. 1948 * @tc.expected: The imageNodeList_ size is equal to 200. 1949 */ 1950 auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod()); 1951 ASSERT_NE(textPaintMethod, nullptr); 1952 RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext(); 1953 auto paintProperty = textPattern->CreatePaintProperty(); 1954 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty); 1955 textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper)); 1956 ASSERT_NE(textPaintMethod, nullptr); 1957 auto textContentModifier = textPaintMethod->textContentModifier_; 1958 ASSERT_NE(textContentModifier, nullptr); 1959 1960 textContentModifier->UpdateImageNodeVisible(VisibleType::GONE); 1961 EXPECT_EQ(textContentModifier->imageNodeList_.size(), 200); 1962 for (const auto& imageWeak : textContentModifier->imageNodeList_) { 1963 auto imageNode = imageWeak.Upgrade(); 1964 ASSERT_NE(imageNode, nullptr); 1965 auto layoutProperty2 = imageNode->GetLayoutProperty(); 1966 ASSERT_NE(layoutProperty2, nullptr); 1967 EXPECT_EQ(static_cast<int32_t>(layoutProperty2->GetVisibility().has_value() && 1968 (layoutProperty2->GetVisibility().value() == VisibleType::GONE)), 1); 1969 } 1970 textPattern->pManager_->Reset(); 1971 } 1972 } // namespace OHOS::Ace::NG 1973