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 "test/unittest/core/base/view_abstract_test_ng.h" 17 18 using namespace testing; 19 using namespace testing::ext; 20 21 namespace OHOS::Ace::NG { 22 /** 23 * @tc.name: ViewAbstractTest031 24 * @tc.desc: Test the operation of View_Abstract 25 * @tc.type: FUNC 26 */ 27 28 /** 29 * @tc.name: SetPixelRoundTest 30 * @tc.desc: Test the operation of SetPixelRound. 31 * @tc.type: FUNC 32 */ 33 HWTEST_F(ViewAbstractTestNg, SetPixelRoundTest, TestSize.Level1) 34 { 35 /** 36 * @tc.steps: step1. Create a FrameNode object. 37 * @tc.steps: step2. Call SetPixelRound with value 2. 38 * @tc.expected: The PixelRound property of the FrameNode is set to 0. 39 */ 40 ViewStackProcessor viewStackProcessor; 41 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 42 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 43 uint8_t value = 2; 44 ViewAbstract::SetPixelRound(AceType::RawPtr(frameNode), value); 45 ASSERT_EQ(frameNode->GetLayoutProperty()->GetPixelRound(), value); 46 } 47 48 /** 49 * @tc.name: SetDashGapTest 50 * @tc.desc: Test the operation of SetDashGap method. 51 * @tc.type: FUNC 52 */ 53 HWTEST_F(ViewAbstractTestNg, SetDashGapTest, TestSize.Level1) 54 { 55 /** 56 * @tc.steps: Build a object viewAbstract and set visual state. 57 */ 58 ViewStackProcessor viewStackProcessor; 59 int32_t index = 1; 60 auto state = static_cast<VisualState>(index); 61 viewStackProcessor.GetInstance()->SetVisualState(state); 62 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 63 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 64 ASSERT_NE(frameNode, nullptr); 65 66 /** 67 * @tc.steps: Build a object viewAbstract and set visual state. 68 * @tc.expected: The value is not changed. 69 */ 70 ViewAbstract::SetDashGap(Dimension(3)); 71 ASSERT_NE(frameNode->GetRenderContext()->GetDashGap()->rightDimen, Dimension(3)); 72 73 /** 74 * @tc.steps: Set visual state to null and SetDashGap 75 * @tc.expected: The value is changed as expected. 76 */ 77 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 78 ViewAbstract::SetDashGap(Dimension(4)); 79 ASSERT_EQ(frameNode->GetRenderContext()->GetDashGap()->rightDimen, Dimension(4)); 80 } 81 82 /** 83 * @tc.name: SetDashGapWithFrameNodeTest 84 * @tc.desc: Test the operation of SetDashGap method with FrameNode. 85 * @tc.type: FUNC 86 */ 87 HWTEST_F(ViewAbstractTestNg, SetDashGapWithFrameNodeTest, TestSize.Level1) 88 { 89 /** 90 * @tc.steps: Build a object viewAbstract and set visual state. 91 */ 92 ViewStackProcessor viewStackProcessor; 93 int32_t index = 1; 94 auto state = static_cast<VisualState>(index); 95 viewStackProcessor.GetInstance()->SetVisualState(state); 96 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 97 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 98 ASSERT_NE(frameNode, nullptr); 99 100 /** 101 * @tc.steps: Set visual state to null and SetDashGap 102 * @tc.expected: The value is changed as expected. 103 */ 104 ViewAbstract::SetDashGap(AceType::RawPtr(frameNode), Dimension(2)); 105 auto dashGapOpt = frameNode->GetRenderContext()->GetDashGap(); 106 ASSERT_EQ(dashGapOpt->rightDimen, Dimension(2)); 107 } 108 109 /** 110 * @tc.name: SetDashGapWithBorderWidthPropertyTest 111 * @tc.desc: Test the operation of SetDashGap method with BorderWidthProperty. 112 * @tc.type: FUNC 113 */ 114 HWTEST_F(ViewAbstractTestNg, SetDashGapWithBorderWidthPropertyTest, TestSize.Level1) 115 { 116 /** 117 * @tc.steps: Build a object viewAbstract and set visual state. 118 */ 119 ViewStackProcessor viewStackProcessor; 120 int32_t index = 1; 121 auto state = static_cast<VisualState>(index); 122 viewStackProcessor.GetInstance()->SetVisualState(state); 123 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 124 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 125 ASSERT_NE(frameNode, nullptr); 126 127 /** 128 * @tc.steps: Build a object dashGap . 129 */ 130 BorderWidthProperty dashGap1; 131 dashGap1.SetBorderWidth(Dimension(3)); 132 133 /** 134 * @tc.steps: SetDashGap. 135 * @tc.expected: The value is not changed. 136 */ 137 ViewAbstract::SetDashGap(dashGap1); 138 ASSERT_NE(frameNode->GetRenderContext()->GetDashGap()->rightDimen, Dimension(3)); 139 140 /** 141 * @tc.steps: Set visual state to null and SetDashGap 142 * @tc.expected: The value is changed as expected. 143 */ 144 BorderWidthProperty dashGap2; 145 dashGap2.SetBorderWidth(Dimension(2)); 146 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 147 ViewAbstract::SetDashGap(dashGap2); 148 ASSERT_EQ(frameNode->GetRenderContext()->GetDashGap()->rightDimen, Dimension(2)); 149 } 150 151 /** 152 * @tc.name: SetDashGapWithFrameNodePropertyTest 153 * @tc.desc: Test the operation of SetDashGap method with FrameNode. 154 * @tc.type: FUNC 155 */ 156 HWTEST_F(ViewAbstractTestNg, SetDashGapWithFrameNodePropertyTest, TestSize.Level1) 157 { 158 /** 159 * @tc.steps: Build a object viewAbstract and set visual state. 160 */ 161 ViewStackProcessor viewStackProcessor; 162 int32_t index = 1; 163 auto state = static_cast<VisualState>(index); 164 viewStackProcessor.GetInstance()->SetVisualState(state); 165 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 166 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 167 ASSERT_NE(frameNode, nullptr); 168 169 /** 170 * @tc.steps: Set visual state to null and SetDashGap 171 * @tc.expected: The value is changed as expected. 172 */ 173 BorderWidthProperty dashGap; 174 dashGap.SetBorderWidth(Dimension(2)); 175 ViewAbstract::SetDashGap(AceType::RawPtr(frameNode), dashGap); 176 auto dashGapOpt = frameNode->GetRenderContext()->GetDashGap(); 177 ASSERT_EQ(dashGapOpt->rightDimen, Dimension(2)); 178 } 179 180 /** 181 * @tc.name: SetDashWidthFrameNodePropertyTest 182 * @tc.desc: Test the operation of SetDashGap method with FrameNode. 183 * @tc.type: FUNC 184 */ 185 HWTEST_F(ViewAbstractTestNg, SetDashWidthFrameNodePropertyTest, TestSize.Level1) 186 { 187 /** 188 * @tc.steps: Build a object viewAbstract and set visual state. 189 */ 190 ViewStackProcessor viewStackProcessor; 191 int32_t index = 1; 192 auto state = static_cast<VisualState>(index); 193 viewStackProcessor.GetInstance()->SetVisualState(state); 194 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 195 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 196 ASSERT_NE(frameNode, nullptr); 197 198 /** 199 * @tc.steps: Set visual state to null and SetDashGap 200 * @tc.expected: The value is changed as expected. 201 */ 202 BorderWidthProperty dashGap; 203 dashGap.SetBorderWidth(Dimension(2)); 204 ViewAbstract::SetDashWidth(AceType::RawPtr(frameNode), dashGap); 205 auto dashGapOpt = frameNode->GetRenderContext()->GetDashWidth(); 206 ASSERT_EQ(dashGapOpt->rightDimen, Dimension(2)); 207 } 208 209 /** 210 * @tc.name: SetDashWidthWithDimensionTest 211 * @tc.desc: Test the operation of SetDashWidth method with Dimension. 212 * @tc.type: FUNC 213 */ 214 HWTEST_F(ViewAbstractTestNg, SetDashWidthWithDimensionTest, TestSize.Level1) 215 { 216 /** 217 * @tc.steps: Build a object viewAbstract and set visual state. 218 */ 219 ViewStackProcessor viewStackProcessor; 220 int32_t index = 1; 221 auto state = static_cast<VisualState>(index); 222 viewStackProcessor.GetInstance()->SetVisualState(state); 223 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 224 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 225 ASSERT_NE(frameNode, nullptr); 226 227 /** 228 * @tc.steps: Build a object viewAbstract and set visual state. 229 * @tc.expected: The value is not changed. 230 */ 231 ViewAbstract::SetDashWidth(Dimension(3)); 232 ASSERT_NE(frameNode->GetRenderContext()->GetDashWidth()->rightDimen, Dimension(3)); 233 234 /** 235 * @tc.steps: Set visual state to null and SetDashGap 236 * @tc.expected: The value is changed as expected. 237 */ 238 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 239 ViewAbstract::SetDashWidth(Dimension(4)); 240 ASSERT_EQ(frameNode->GetRenderContext()->GetDashWidth()->rightDimen, Dimension(4)); 241 } 242 243 /** 244 * @tc.name: SetDashWidthWithFrameNodeAndDimensionTest 245 * @tc.desc: Test the operation of SetDashWidth method with FrameNode and Dimension. 246 * @tc.type: FUNC 247 */ 248 HWTEST_F(ViewAbstractTestNg, SetDashWidthWithFrameNodeAndDimensionTest, TestSize.Level1) 249 { 250 /** 251 * @tc.steps: Build a object viewAbstract and set visual state. 252 */ 253 ViewStackProcessor viewStackProcessor; 254 int32_t index = 1; 255 auto state = static_cast<VisualState>(index); 256 viewStackProcessor.GetInstance()->SetVisualState(state); 257 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 258 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 259 ASSERT_NE(frameNode, nullptr); 260 261 /** 262 * @tc.steps: Set visual state to null and SetDashGap 263 * @tc.expected: The value is changed as expected. 264 */ 265 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 266 ViewAbstract::SetDashWidth(AceType::RawPtr(frameNode), Dimension(2)); 267 ASSERT_EQ(frameNode->GetRenderContext()->GetDashWidth()->rightDimen, Dimension(2)); 268 } 269 270 /** 271 * @tc.name: SetDashWidthWithBorderWidthPropertyTest 272 * @tc.desc: Test the operation of SetDashWidth method with BorderWidthProperty. 273 * @tc.type: FUNC 274 */ 275 HWTEST_F(ViewAbstractTestNg, SetDashWidthWithBorderWidthPropertyTest, TestSize.Level1) 276 { 277 /** 278 * @tc.steps: Build a object viewAbstract and set visual state. 279 */ 280 ViewStackProcessor viewStackProcessor; 281 int32_t index = 1; 282 auto state = static_cast<VisualState>(index); 283 viewStackProcessor.GetInstance()->SetVisualState(state); 284 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 285 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 286 ASSERT_NE(frameNode, nullptr); 287 288 BorderWidthProperty dashGap1; 289 dashGap1.SetBorderWidth(Dimension(2)); 290 291 /** 292 * @tc.steps: Build a object viewAbstract and set visual state. 293 * @tc.expected: The value is not changed. 294 */ 295 ViewAbstract::SetDashWidth(dashGap1); 296 ASSERT_NE(frameNode->GetRenderContext()->GetDashWidth()->rightDimen, Dimension(2)); 297 298 /** 299 * @tc.steps: Set visual state to null and check the current visual state process 300 * @tc.expected: The value is changed as expected. 301 */ 302 BorderWidthProperty dashGap2; 303 dashGap2.SetBorderWidth(Dimension(3)); 304 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 305 ViewAbstract::SetDashWidth(dashGap2); 306 ASSERT_EQ(frameNode->GetRenderContext()->GetDashWidth()->rightDimen, Dimension(3)); 307 } 308 309 /** 310 * @tc.name: ViewAbstractDisableOnAttachTest 311 * @tc.desc: Test the operation of View_Abstract. 312 * @tc.type: FUNC 313 */ 314 HWTEST_F(ViewAbstractTestNg, ViewAbstractDisableOnAttachTest, TestSize.Level1) 315 { 316 /** 317 * @tc.steps: step1. create framenode and check callback; 318 * @tc.expected: callback is not null. 319 */ 320 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 321 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 322 323 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 324 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 325 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 326 ASSERT_NE(frameNode, nullptr); 327 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 328 ASSERT_NE(node, nullptr); __anonb33fe1900102() 329 std::function<void()> onAttachCallback = []() {}; 330 ViewAbstract::SetOnAttach(AceType::RawPtr(node), std::move(onAttachCallback)); 331 auto eventHub = node->GetEventHub<EventHub>(); 332 auto& callback = eventHub->onAttach_; 333 EXPECT_NE(callback, nullptr); 334 335 /** 336 * @tc.steps: step2. Disable callback. 337 * @tc.expected: callback is null. 338 */ 339 ViewAbstract::DisableOnAttach(); 340 EXPECT_EQ(callback, nullptr); 341 } 342 343 /** 344 * @tc.name: ViewAbstractDisableOnDetachTest 345 * @tc.desc: Test the operation of View_Abstract. 346 * @tc.type: FUNC 347 */ 348 HWTEST_F(ViewAbstractTestNg, ViewAbstractDisableOnDetachTest, TestSize.Level1) 349 { 350 /** 351 * @tc.steps: step1. create framenode and check callback; 352 * @tc.expected: callback is not null. 353 */ 354 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 355 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 356 357 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 358 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 359 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 360 ASSERT_NE(frameNode, nullptr); 361 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 362 ASSERT_NE(node, nullptr); __anonb33fe1900202() 363 std::function<void()> onDetachCallback = []() {}; 364 ViewAbstract::SetOnDetach(AceType::RawPtr(node), std::move(onDetachCallback)); 365 auto eventHub = node->GetEventHub<EventHub>(); 366 auto& callback = eventHub->onDetach_; 367 EXPECT_NE(callback, nullptr); 368 369 /** 370 * @tc.steps: step2. Disable callback. 371 * @tc.expected: callback is null. 372 */ 373 ViewAbstract::DisableOnDetach(); 374 EXPECT_EQ(callback, nullptr); 375 } 376 377 /** 378 * @tc.name: ViewAbstractDisableOnAttachByFrameNodeTest 379 * @tc.desc: Test the operation of View_Abstract. 380 * @tc.type: FUNC 381 */ 382 HWTEST_F(ViewAbstractTestNg, ViewAbstractDisableOnAttachByFrameNodeTest, TestSize.Level1) 383 { 384 /** 385 * @tc.steps: step1. create framenode and check callback; 386 * @tc.expected: callback is not null. 387 */ 388 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 389 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 390 391 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 392 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 393 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 394 ASSERT_NE(frameNode, nullptr); 395 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 396 ASSERT_NE(node, nullptr); __anonb33fe1900302() 397 std::function<void()> onAttachCallback = []() {}; 398 ViewAbstract::SetOnAttach(AceType::RawPtr(node), std::move(onAttachCallback)); 399 auto eventHub = node->GetEventHub<EventHub>(); 400 auto& callback = eventHub->onAttach_; 401 EXPECT_NE(callback, nullptr); 402 403 /** 404 * @tc.steps: step2. Disable callback. 405 * @tc.expected: callback is null. 406 */ 407 ViewAbstract::DisableOnAttach(AceType::RawPtr(node)); 408 EXPECT_EQ(callback, nullptr); 409 } 410 411 /** 412 * @tc.name: ViewAbstractDisableOnDetachByFrameNodeTest 413 * @tc.desc: Test the operation of View_Abstract. 414 * @tc.type: FUNC 415 */ 416 HWTEST_F(ViewAbstractTestNg, ViewAbstractDisableOnDetachByFrameNodeTest, TestSize.Level1) 417 { 418 /** 419 * @tc.steps: step1. create framenode and check callback; 420 * @tc.expected: callback is not null. 421 */ 422 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 423 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 424 425 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 426 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 427 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 428 ASSERT_NE(frameNode, nullptr); 429 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 430 ASSERT_NE(node, nullptr); __anonb33fe1900402() 431 std::function<void()> onDetachCallback = []() {}; 432 ViewAbstract::SetOnDetach(AceType::RawPtr(node), std::move(onDetachCallback)); 433 auto eventHub = node->GetEventHub<EventHub>(); 434 auto& callback = eventHub->onDetach_; 435 EXPECT_NE(callback, nullptr); 436 437 /** 438 * @tc.steps: step2. Disable callback. 439 * @tc.expected: callback is null. 440 */ 441 ViewAbstract::DisableOnDetach(AceType::RawPtr(node)); 442 EXPECT_EQ(callback, nullptr); 443 } 444 445 /** 446 * @tc.name: ViewAbstractTouchIntercept001 447 * @tc.desc: Test setting touch intercept function on a specific frame node 448 * @tc.type: FUNC 449 */ 450 HWTEST_F(ViewAbstractTestNg, ViewAbstractTouchIntercept001, TestSize.Level1) 451 { 452 /** 453 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 454 */ 455 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 456 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 457 ASSERT_NE(frameNode, nullptr); 458 TouchInterceptFunc touchInterceptFunc; 459 ViewAbstract::SetOnTouchIntercept(std::move(touchInterceptFunc)); 460 461 /** 462 * @tc.steps: step2. Verify that the touch intercept function has been set. 463 * @tc.expected: The touch intercept function should be set correctly. 464 */ 465 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 466 ASSERT_NE(gestureHub, nullptr); 467 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 468 } 469 470 /** 471 * @tc.name: ViewAbstractTouchIntercept002 472 * @tc.desc: Test setting touch intercept function on the main frame node 473 * @tc.type: FUNC 474 */ 475 HWTEST_F(ViewAbstractTestNg, ViewAbstractTouchIntercept002, TestSize.Level1) 476 { 477 /** 478 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 479 */ 480 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 481 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 482 ASSERT_NE(frameNode, nullptr); 483 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 484 ASSERT_NE(node, nullptr); 485 TouchInterceptFunc touchInterceptFunc; 486 ViewAbstract::SetOnTouchIntercept(AceType::RawPtr(node), std::move(touchInterceptFunc)); 487 488 /** 489 * @tc.steps: step2. Verify that the touch intercept function has been set. 490 * @tc.expected: The touch intercept function should be set correctly. 491 */ 492 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 493 ASSERT_NE(gestureHub, nullptr); 494 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 495 } 496 497 /** 498 * @tc.name: ViewAbstractRecognizerParallel001 499 * @tc.desc: Test setting ShouldBuiltInRecognizerParallelWith function 500 * @tc.type: FUNC 501 */ 502 HWTEST_F(ViewAbstractTestNg, ViewAbstractRecognizerParallel001, TestSize.Level1) 503 { 504 /** 505 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 506 */ 507 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 508 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 509 ASSERT_NE(frameNode, nullptr); 510 511 NG::ShouldBuiltInRecognizerParallelWithFunc shouldBuiltInRecognizerParallelWithFunc; 512 ViewAbstract::SetShouldBuiltInRecognizerParallelWith(std::move(shouldBuiltInRecognizerParallelWithFunc)); 513 514 /** 515 * @tc.steps: step2. Verify that the touch intercept function has been set. 516 * @tc.expected: The touch intercept function should be set correctly. 517 */ 518 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 519 ASSERT_NE(gestureHub, nullptr); 520 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 521 } 522 523 /** 524 * @tc.name: ViewAbstractGestureRecognizerJudge001 525 * @tc.desc: Test setting OnGestureRecognizerJudgeBegin function 526 * @tc.type: FUNC 527 */ 528 HWTEST_F(ViewAbstractTestNg, ViewAbstractGestureRecognizerJudge001, TestSize.Level1) 529 { 530 /** 531 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 532 */ 533 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 534 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 535 ASSERT_NE(frameNode, nullptr); 536 537 GestureRecognizerJudgeFunc gestureRecognizerJudgeFunc; 538 ViewAbstract::SetOnGestureRecognizerJudgeBegin(std::move(gestureRecognizerJudgeFunc), false); 539 540 /** 541 * @tc.steps: step2. Verify that the touch intercept function has been set. 542 * @tc.expected: The touch intercept function should be set correctly. 543 */ 544 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 545 ASSERT_NE(gestureHub, nullptr); 546 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 547 } 548 549 /** 550 * @tc.name: ViewAbstractOnTouchTest001 551 * @tc.desc: Test setting OnTouchTest function 552 * @tc.type: FUNC 553 */ 554 HWTEST_F(ViewAbstractTestNg, ViewAbstractOnTouchTest001, TestSize.Level1) 555 { 556 /** 557 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 558 */ 559 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 560 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 561 ASSERT_NE(frameNode, nullptr); 562 563 NG::OnChildTouchTestFunc onChildTouchTest; 564 ViewAbstract::SetOnTouchTestFunc(std::move(onChildTouchTest)); 565 566 /** 567 * @tc.steps: step2. Verify that the touch intercept function has been set. 568 * @tc.expected: The touch intercept function should be set correctly. 569 */ 570 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 571 ASSERT_NE(gestureHub, nullptr); 572 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 573 } 574 575 /** 576 * @tc.name: ViewAbstractFocusBoxStyle001 577 * @tc.desc: Test setting focus box style 578 * @tc.type: FUNC 579 */ 580 HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusBoxStyle001, TestSize.Level1) 581 { 582 /** 583 * @tc.steps: step1. Create a new frame node and set the touch intercept function. 584 */ 585 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 586 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 587 ASSERT_NE(frameNode, nullptr); 588 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 589 ASSERT_NE(node, nullptr); 590 591 NG::FocusBoxStyle style; 592 ViewAbstract::SetFocusBoxStyle(std::move(style)); 593 594 /** 595 * @tc.steps: step2. Verify that the touch intercept function has been set. 596 * @tc.expected: The touch intercept function should be set correctly. 597 */ 598 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub(); 599 ASSERT_NE(focusHub, nullptr); 600 EXPECT_NE(ViewStackProcessor::GetInstance()->GetMainElementNode(), nullptr); 601 } 602 603 /** 604 * @tc.name: ViewAbstractFocusScopeId001 605 * @tc.desc: Test setting focus scope ID 606 * @tc.type: FUNC 607 */ 608 HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopeId001, TestSize.Level1) 609 { 610 /** 611 * @tc.steps: step1. Push main frame node and set the focus scope ID. 612 */ 613 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 614 std::string focusScopeId = "focusScope1"; 615 bool isGroup = true; 616 ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub()->focusType_ = FocusType::SCOPE; 617 ViewAbstract::SetFocusScopeId(focusScopeId, isGroup, true); 618 619 /** 620 * @tc.steps: step2. Verify that the focus scope ID has been set. 621 * @tc.expected: The focus scope ID should be set correctly. 622 */ 623 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub(); 624 ASSERT_NE(focusHub, nullptr); 625 EXPECT_EQ(focusHub->focusScopeId_, focusScopeId); 626 627 /** 628 * @tc.steps: step3. Finish view stack. 629 */ 630 ViewStackProcessor::GetInstance()->Finish(); 631 } 632 633 /** 634 * @tc.name: ViewAbstractFocusScopePriority001 635 * @tc.desc: Test setting focus scope priority 636 * @tc.type: FUNC 637 */ 638 HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopePriority001, TestSize.Level1) 639 { 640 /** 641 * @tc.steps: step1. Push main frame node and set the focus scope priority. 642 */ 643 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 644 std::string focusScopeId = "focusScope1"; 645 uint32_t focusPriority = 1; 646 ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub()->isFocusScope_ = true; 647 ViewAbstract::SetFocusScopePriority(focusScopeId, focusPriority); 648 649 /** 650 * @tc.steps: step2. Verify that the focus scope priority has been set. 651 * @tc.expected: The focus scope priority should be set correctly. 652 */ 653 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub(); 654 ASSERT_NE(focusHub, nullptr); 655 EXPECT_EQ(focusHub->focusScopeId_, focusScopeId); 656 657 /** 658 * @tc.steps: step3. Finish view stack. 659 */ 660 ViewStackProcessor::GetInstance()->Finish(); 661 } 662 663 /** 664 * @tc.name: ViewAbstractFocusScopeIdWithFrameNode001 665 * @tc.desc: Test setting focus scope ID with frame node 666 * @tc.type: FUNC 667 */ 668 HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopeIdWithFrameNode001, TestSize.Level1) 669 { 670 /** 671 * @tc.steps: step1. Create a new frame node and set the focus scope ID. 672 */ 673 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 674 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish()); 675 std::string focusScopeId = "focusScope2"; 676 bool isGroup = true; 677 ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub()->focusType_ = FocusType::SCOPE; 678 ViewAbstract::SetFocusScopeId(AceType::RawPtr(frameNode), focusScopeId, isGroup, true); 679 680 /** 681 * @tc.steps: step2. Verify that the focus scope ID has been set. 682 * @tc.expected: The focus scope ID should be set correctly. 683 */ 684 auto focusHub = frameNode->GetOrCreateFocusHub(); 685 ASSERT_NE(focusHub, nullptr); 686 687 /** 688 * @tc.steps: step3. Finish view stack. 689 */ 690 ViewStackProcessor::GetInstance()->Finish(); 691 } 692 693 /** 694 * @tc.name: ViewAbstractFocusScopePriorityWithFrameNode001 695 * @tc.desc: Test setting focus scope priority with frame node 696 * @tc.type: FUNC 697 */ 698 HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopePriorityWithFrameNode001, TestSize.Level1) 699 { 700 /** 701 * @tc.steps: step1. Create a new frame node and set the focus scope priority. 702 */ 703 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish()); 704 std::string focusScopeId = "focusScope2"; 705 uint32_t focusPriority = 2; 706 ViewAbstract::SetFocusScopePriority(AceType::RawPtr(frameNode), focusScopeId, focusPriority); 707 708 /** 709 * @tc.steps: step2. Verify that the focus scope priority has been set. 710 * @tc.expected: The focus scope priority should be set correctly. 711 */ 712 auto focusHub = frameNode->GetOrCreateFocusHub(); 713 ASSERT_NE(focusHub, nullptr); 714 EXPECT_EQ(focusHub->focusScopeId_, focusScopeId); 715 716 /** 717 * @tc.steps: step3. Finish view stack. 718 */ 719 ViewStackProcessor::GetInstance()->Finish(); 720 } 721 722 /** 723 * @tc.name: ViewAbstractOnAttach001 724 * @tc.desc: Test setting onAttach function 725 * @tc.type: FUNC 726 */ 727 HWTEST_F(ViewAbstractTestNg, ViewAbstractOnAttach001, TestSize.Level1) 728 { 729 /** 730 * @tc.steps: step1. create framenode and check callback; 731 * @tc.expected: callback is not null. 732 */ 733 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 734 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 735 736 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 737 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 738 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 739 ASSERT_NE(frameNode, nullptr); 740 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 741 ASSERT_NE(node, nullptr); __anonb33fe1900502() 742 std::function<void()> onAttachCallback = []() {}; 743 ViewAbstract::SetOnAttach(AceType::RawPtr(node), std::move(onAttachCallback)); 744 auto eventHub = node->GetEventHub<EventHub>(); 745 auto& callback = eventHub->onAttach_; 746 EXPECT_NE(callback, nullptr); 747 748 /** 749 * @tc.steps: step2. Disable callback. 750 * @tc.expected: callback is null. 751 */ 752 ViewAbstract::DisableOnAttach(AceType::RawPtr(node)); 753 EXPECT_EQ(callback, nullptr); 754 755 /** 756 * @tc.steps: step3. Finish view stack. 757 */ 758 ViewStackProcessor::GetInstance()->Finish(); 759 } 760 761 /** 762 * @tc.name: ViewAbstractOnDetach001 763 * @tc.desc: Test setting onDetach function 764 * @tc.type: FUNC 765 */ 766 HWTEST_F(ViewAbstractTestNg, ViewAbstractOnDetach001, TestSize.Level1) 767 { 768 /** 769 * @tc.steps: step1. create framenode and check callback; 770 * @tc.expected: callback is not null. 771 */ 772 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 773 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 774 775 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 776 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 777 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 778 ASSERT_NE(frameNode, nullptr); 779 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 780 ASSERT_NE(node, nullptr); __anonb33fe1900602() 781 std::function<void()> onDetachCallback = []() {}; 782 ViewAbstract::SetOnDetach(std::move(onDetachCallback)); 783 auto eventHub = node->GetEventHub<EventHub>(); 784 auto& callback = eventHub->onDetach_; 785 EXPECT_NE(callback, nullptr); 786 787 /** 788 * @tc.steps: step2. Disable callback. 789 * @tc.expected: callback is null. 790 */ 791 ViewAbstract::DisableOnDetach(AceType::RawPtr(node)); 792 EXPECT_EQ(callback, nullptr); 793 794 /** 795 * @tc.steps: step3. Finish view stack. 796 */ 797 ViewStackProcessor::GetInstance()->Finish(); 798 } 799 800 /** 801 * @tc.name: ViewAbstractOnAttach002 802 * @tc.desc: Test setting onAttach callback 803 * @tc.type: FUNC 804 */ 805 HWTEST_F(ViewAbstractTestNg, ViewAbstractOnAttach002, TestSize.Level1) 806 { 807 /** 808 * @tc.steps: step1. create framenode and check callback; 809 * @tc.expected: callback is not null. 810 */ 811 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 812 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_CHILD); 813 814 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 815 EXPECT_EQ(strcmp(topFrameNodeOne->GetTag().c_str(), TAG_CHILD), 0); 816 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 817 ASSERT_NE(frameNode, nullptr); 818 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 819 ASSERT_NE(node, nullptr); __anonb33fe1900702() 820 std::function<void()> onAttachCallback = []() {}; 821 ViewAbstract::SetOnAttach(std::move(onAttachCallback)); 822 auto eventHub = node->GetEventHub<EventHub>(); 823 auto& callback = eventHub->onAttach_; 824 EXPECT_NE(callback, nullptr); 825 826 /** 827 * @tc.steps: step2. Disable callback. 828 * @tc.expected: callback is null. 829 */ 830 ViewAbstract::DisableOnAttach(AceType::RawPtr(node)); 831 EXPECT_EQ(callback, nullptr); 832 833 /** 834 * @tc.steps: step3. Finish view stack. 835 */ 836 ViewStackProcessor::GetInstance()->Finish(); 837 } 838 839 /** 840 * @tc.name: ViewAbstractBgDynamicBrightness001 841 * @tc.desc: Test setting background dynamic brightness option 842 * @tc.type: FUNC 843 */ 844 HWTEST_F(ViewAbstractTestNg, ViewAbstractBgDynamicBrightness001, TestSize.Level1) 845 { 846 /** 847 * @tc.steps: Build a object viewAbstract and set visual state. 848 */ 849 ViewStackProcessor viewStackProcessor; 850 int32_t index = 1; 851 auto state = static_cast<VisualState>(index); 852 viewStackProcessor.GetInstance()->SetVisualState(state); 853 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 854 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 855 ASSERT_NE(frameNode, nullptr); 856 857 /** 858 * @tc.steps: Build a object viewAbstract and set visual state. 859 * @tc.expected: The foreground effect is not changed. 860 */ 861 BrightnessOption brightnessOption; 862 ViewAbstract::SetBgDynamicBrightness(brightnessOption); 863 ASSERT_FALSE(frameNode->GetRenderContext()->GetBgDynamicBrightnessOption().has_value()); 864 865 /** 866 * @tc.steps: Set visual state to null and check the current visual state process 867 * @tc.expected: The foreground effect is changed as expected. 868 */ 869 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 870 ViewAbstract::SetBgDynamicBrightness(brightnessOption); 871 ASSERT_TRUE(frameNode->GetRenderContext()->GetBgDynamicBrightnessOption().has_value()); 872 } 873 874 /** 875 * @tc.name: ViewAbstractFgDynamicBrightness001 876 * @tc.desc: Test setting foreground dynamic brightness option 877 * @tc.type: FUNC 878 */ 879 HWTEST_F(ViewAbstractTestNg, ViewAbstractFgDynamicBrightness001, TestSize.Level1) 880 { 881 /** 882 * @tc.steps: Build a object viewAbstract and set visual state. 883 */ 884 ViewStackProcessor viewStackProcessor; 885 int32_t index = 1; 886 auto state = static_cast<VisualState>(index); 887 viewStackProcessor.GetInstance()->SetVisualState(state); 888 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 889 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 890 ASSERT_NE(frameNode, nullptr); 891 892 /** 893 * @tc.steps: Build a object viewAbstract and set visual state. 894 * @tc.expected: The foreground effect is not changed. 895 */ 896 BrightnessOption brightnessOption; 897 ViewAbstract::SetFgDynamicBrightness(brightnessOption); 898 ASSERT_FALSE(frameNode->GetRenderContext()->GetFgDynamicBrightnessOption().has_value()); 899 900 /** 901 * @tc.steps: Set visual state to null and check the current visual state process 902 * @tc.expected: The foreground effect is changed as expected. 903 */ 904 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 905 ViewAbstract::SetFgDynamicBrightness(brightnessOption); 906 ASSERT_TRUE(frameNode->GetRenderContext()->GetFgDynamicBrightnessOption().has_value()); 907 } 908 909 /** 910 * @tc.name: ViewAbstractBgDynamicBrightness002 911 * @tc.desc: Test setting background dynamic brightness option 912 * @tc.type: FUNC 913 */ 914 HWTEST_F(ViewAbstractTestNg, ViewAbstractBgDynamicBrightness002, TestSize.Level1) 915 { 916 /** 917 * @tc.steps: step1. Create a new frame node and set the background dynamic brightness option. 918 */ 919 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish()); 920 ViewStackProcessor viewStackProcessor; 921 int32_t index = 1; 922 auto state = static_cast<VisualState>(index); 923 viewStackProcessor.GetInstance()->SetVisualState(state); 924 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 925 926 /** 927 * @tc.steps: Build a object viewAbstract and set visual state. 928 * @tc.expected: The foreground effect is not changed. 929 */ 930 BrightnessOption brightnessOption; 931 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 932 ASSERT_NE(node, nullptr); 933 ViewAbstract::SetBgDynamicBrightness(AceType::RawPtr(node), brightnessOption); 934 935 /** 936 * @tc.steps: Set visual state to null and check the current visual state process 937 * @tc.expected: The foreground effect is changed as expected. 938 */ 939 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 940 ViewAbstract::SetBgDynamicBrightness(AceType::RawPtr(node), brightnessOption); 941 ASSERT_TRUE(frameNode->GetRenderContext()->GetBgDynamicBrightnessOption().has_value()); 942 } 943 944 /** 945 * @tc.name: ViewAbstractFgDynamicBrightness002 946 * @tc.desc: Test setting foreground dynamic brightness option 947 * @tc.type: FUNC 948 */ 949 HWTEST_F(ViewAbstractTestNg, ViewAbstractFgDynamicBrightness002, TestSize.Level1) 950 { 951 /** 952 * @tc.steps: step1. Create a new frame node and set the background dynamic brightness option. 953 */ 954 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish()); 955 ViewStackProcessor viewStackProcessor; 956 int32_t index = 1; 957 auto state = static_cast<VisualState>(index); 958 viewStackProcessor.GetInstance()->SetVisualState(state); 959 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 960 961 /** 962 * @tc.steps: Build a object viewAbstract and set visual state. 963 * @tc.expected: The foreground effect is not changed. 964 */ 965 BrightnessOption brightnessOption; 966 auto node = AceType::DynamicCast<NG::FrameNode>(frameNode); 967 ASSERT_NE(node, nullptr); 968 ViewAbstract::SetFgDynamicBrightness(AceType::RawPtr(node), brightnessOption); 969 970 /** 971 * @tc.steps: Set visual state to null and check the current visual state process 972 * @tc.expected: The foreground effect is changed as expected. 973 */ 974 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 975 ViewAbstract::SetFgDynamicBrightness(AceType::RawPtr(node), brightnessOption); 976 ASSERT_TRUE(frameNode->GetRenderContext()->GetFgDynamicBrightnessOption().has_value()); 977 } 978 979 /** 980 * @tc.name: ViewAbstractSystemBarEffect001 981 * @tc.desc: Test setting system bar effect 982 * @tc.type: FUNC 983 */ 984 HWTEST_F(ViewAbstractTestNg, ViewAbstractSystemBarEffect001, TestSize.Level1) 985 { 986 /** 987 * @tc.steps: step1. Push main frame node and set the system bar effect. 988 */ 989 ViewStackProcessor viewStackProcessor; 990 int32_t index = 1; 991 auto state = static_cast<VisualState>(index); 992 viewStackProcessor.GetInstance()->SetVisualState(state); 993 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 994 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 995 ASSERT_NE(frameNode, nullptr); 996 997 /** 998 * @tc.steps: using a unCurrent visual state Process and set value 999 * @tc.expected: The valueis not changed. 1000 */ 1001 ViewAbstract::SetSystemBarEffect(true); 1002 ASSERT_FALSE(frameNode->GetRenderContext()->GetSystemBarEffect()); 1003 1004 /** 1005 * @tc.steps: Set visual state to null and check the current visual state process 1006 * @tc.expected: The value is changed as expected. 1007 */ 1008 ViewStackProcessor::GetInstance()->visualState_ = std::nullopt; 1009 ViewAbstract::SetSystemBarEffect(true); 1010 ASSERT_TRUE(frameNode->GetRenderContext()->GetSystemBarEffect()); 1011 } 1012 1013 /** 1014 * @tc.name: ViewAbstractSystemBarEffect002 1015 * @tc.desc: Test setting system bar effect 1016 * @tc.type: FUNC 1017 */ 1018 HWTEST_F(ViewAbstractTestNg, ViewAbstractSystemBarEffect002, TestSize.Level1) 1019 { 1020 /** 1021 * @tc.steps: step1. Push main frame node and set the system bar effect. 1022 */ 1023 ViewStackProcessor viewStackProcessor; 1024 int32_t index = 1; 1025 auto state = static_cast<VisualState>(index); 1026 viewStackProcessor.GetInstance()->SetVisualState(state); 1027 auto topFrameNodeOne = ViewStackProcessor::GetInstance()->GetMainElementNode(); 1028 auto frameNode = AceType::DynamicCast<FrameNode>(topFrameNodeOne); 1029 ASSERT_NE(frameNode, nullptr); 1030 1031 /** 1032 * @tc.steps: Set visual state to null and check the current visual state process 1033 * @tc.expected: The value is changed as expected. 1034 */ 1035 ViewAbstract::SetSystemBarEffect(nullptr, false); 1036 ASSERT_FALSE(frameNode->GetRenderContext()->GetSystemBarEffect()); 1037 } 1038 1039 /** 1040 * @tc.name: ViewAbstractPositionEdges002 1041 * @tc.desc: Test setting position edges 1042 * @tc.type: FUNC 1043 */ 1044 HWTEST_F(ViewAbstractTestNg, ViewAbstractPositionEdges002, TestSize.Level1) 1045 { 1046 /** 1047 * @tc.steps: step1. create and put mainNode, then build some necessary params. 1048 */ 1049 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 1050 1051 /** 1052 * @tc.steps: step2. get node in ViewStackProcessor. 1053 * @tc.expected: node is not null. 1054 */ 1055 auto rootFrameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); 1056 EXPECT_NE(rootFrameNode, nullptr); 1057 1058 /** 1059 * @tc.steps: step3. use ViewAbstract::SetPositionEdges. 1060 * @tc.expected: success set render property PositionEdges value. 1061 */ 1062 EdgesParam edges; 1063 CalcDimension bottom(30, DimensionUnit::VP); 1064 CalcDimension right(20, DimensionUnit::VP); 1065 edges.SetBottom(bottom); 1066 edges.SetRight(right); 1067 ViewAbstract::SetPositionEdges(nullptr, edges); 1068 1069 EXPECT_NE(FRAME_NODE_ROOT->GetRenderContext(), nullptr); 1070 EXPECT_EQ(FRAME_NODE_ROOT->GetRenderContext() 1071 ->GetPositionEdgesValue(EdgesParam {}).bottom.value_or(Dimension {}).ConvertToVp(), 0.0f); 1072 EXPECT_EQ(FRAME_NODE_ROOT->GetRenderContext() 1073 ->GetPositionEdgesValue(EdgesParam {}).right.value_or(Dimension {}).ConvertToVp(), 0.0f); 1074 1075 /** 1076 * @tc.steps: step5. finish view stack. 1077 */ 1078 ViewStackProcessor::GetInstance()->Finish(); 1079 } 1080 1081 /** 1082 * @tc.name: ViewAbstractOffsetEdges002 1083 * @tc.desc: test offset attribute, use Edges type. 1084 * @tc.type: FUNC 1085 */ 1086 HWTEST_F(ViewAbstractTestNg, ViewAbstractOffset002, TestSize.Level1) 1087 { 1088 /** 1089 * @tc.steps: step1. create and put mainNode, then build some necessary params. 1090 */ 1091 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 1092 1093 /** 1094 * @tc.steps: step2. get node in ViewStackProcessor. 1095 * @tc.expected: node is not null. 1096 */ 1097 auto rootFrameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); 1098 EXPECT_NE(rootFrameNode, nullptr); 1099 1100 /** 1101 * @tc.steps: step3. use ViewAbstract::SetOffsetEdges. 1102 * @tc.expected: success set render property offsetEdges value. 1103 */ 1104 EdgesParam edges; 1105 CalcDimension top(30, DimensionUnit::VP); 1106 CalcDimension left(20, DimensionUnit::VP); 1107 edges.SetTop(top); 1108 edges.SetLeft(left); 1109 ViewAbstract::SetOffsetEdges(nullptr, edges); 1110 1111 EXPECT_NE(FRAME_NODE_ROOT->GetRenderContext(), nullptr); 1112 EXPECT_EQ(FRAME_NODE_ROOT->GetRenderContext() 1113 ->GetOffsetEdgesValue(EdgesParam {}).top.value_or(Dimension {}).ConvertToVp(), 0.0f); 1114 EXPECT_EQ(FRAME_NODE_ROOT->GetRenderContext() 1115 ->GetOffsetEdgesValue(EdgesParam {}).left.value_or(Dimension {}).ConvertToVp(), 0.0f); 1116 1117 /** 1118 * @tc.steps: step5. finish view stack. 1119 */ 1120 ViewStackProcessor::GetInstance()->Finish(); 1121 } 1122 1123 /** 1124 * @tc.name: ViewAbstractTest043 1125 * @tc.desc: Test the operation of View_Abstract 1126 * @tc.type: FUNC 1127 */ 1128 HWTEST_F(ViewAbstractTestNg, ViewAbstractTest043, TestSize.Level1) 1129 { 1130 /** 1131 * @tc.steps: step1.ClearStack. 1132 */ 1133 auto state = static_cast<VisualState>(INDEX); 1134 ViewStackProcessor::GetInstance()->SetVisualState(state); 1135 ViewStackProcessor::GetInstance()->ClearStack(); 1136 1137 /** 1138 * @tc.steps: step2. related function is called. 1139 */ 1140 CalcDimension dimensionRadius(0.0); 1141 ViewAbstract::SetLightPosition(dimensionRadius, dimensionRadius, dimensionRadius); 1142 ViewAbstract::SetLightPosition(nullptr, dimensionRadius, dimensionRadius, dimensionRadius); 1143 ViewAbstract::SetLightIntensity(RATIO); 1144 ViewAbstract::SetLightIntensity(nullptr, RATIO); 1145 ViewAbstract::SetIlluminatedBorderWidth(ZERO); 1146 ViewAbstract::SetIlluminatedBorderWidth(nullptr, ZERO); 1147 ViewAbstract::SetDisplayIndex(INDEX); 1148 ViewAbstract::SetDisplayIndex(nullptr, INDEX); 1149 ViewAbstract::SetGrayScale(RADIUS); 1150 ViewAbstract::SetGrayScale(nullptr, RADIUS); 1151 OHOS::Rosen::VisualEffect* visualEffect; 1152 ViewAbstract::SetVisualEffect(visualEffect); 1153 OHOS::Rosen::Filter* backgroundFilter; 1154 ViewAbstract::SetBackgroundFilter(backgroundFilter); 1155 OHOS::Rosen::Filter* foregroundFilter; 1156 ViewAbstract::SetForegroundFilter(foregroundFilter); 1157 OHOS::Rosen::Filter* compositingFilter; 1158 ViewAbstract::SetCompositingFilter(compositingFilter); 1159 ViewAbstract::SetDynamicDim(1.0f); 1160 ViewAbstract::SetSystemBarEffect(false); 1161 ViewAbstract::SetSystemBarEffect(nullptr, false); 1162 ImageResizableSlice slice; 1163 ViewAbstract::SetBackgroundImageResizableSlice(slice); 1164 ViewAbstract::SetBackgroundImageResizableSlice(nullptr, slice); 1165 MotionBlurOption motionBlurOption; 1166 motionBlurOption.radius = 5; 1167 motionBlurOption.anchor.x = 0.5; 1168 motionBlurOption.anchor.y = 0.5; 1169 ViewAbstract::SetMotionBlur(motionBlurOption); 1170 ViewAbstract::SetLayoutWeight(AceType::RawPtr(FRAME_NODE_REGISTER), TEN); 1171 1172 /** 1173 * @tc.expected: Return expected results. 1174 */ 1175 bool result = ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess(); 1176 EXPECT_FALSE(result); 1177 } 1178 1179 /** 1180 * @tc.name: ViewAbstractDisallowDropForcedly001 1181 * @tc.desc: Test setting disallow drop forcedly 1182 * @tc.type: FUNC 1183 */ 1184 HWTEST_F(ViewAbstractTestNg, ViewAbstractDisallowDropForcedly001, TestSize.Level1) 1185 { 1186 /** 1187 * @tc.steps: step1. Push main frame node and set the disallow drop forcedly. 1188 */ 1189 ViewStackProcessor::GetInstance()->Push(FRAME_NODE_ROOT); 1190 bool isDisallowDropForcedly = true; 1191 ViewAbstract::SetDisallowDropForcedly(isDisallowDropForcedly); 1192 1193 /** 1194 * @tc.steps: step2. Verify that the disallow drop forcedly has been set. 1195 * @tc.expected: The disallow drop forcedly should be set correctly. 1196 */ 1197 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); 1198 ASSERT_NE(frameNode, nullptr); 1199 EXPECT_EQ(frameNode->isDisallowDropForcedly_, isDisallowDropForcedly); 1200 1201 /** 1202 * @tc.steps: step3. Finish view stack. 1203 */ 1204 ViewStackProcessor::GetInstance()->Finish(); 1205 } 1206 } // namespace OHOS::Ace::NG