1 /* 2 * Copyright (c) 2024 iSoftStone Information Technology (Group) 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 <optional> 17 18 #include "gtest/gtest.h" 19 20 #define protected public 21 #define private public 22 #include "test/mock/core/pipeline/mock_pipeline_context.h" 23 #include "test/mock/core/render/mock_render_context.h" 24 25 #include "base/geometry/dimension.h" 26 #include "core/components/common/layout/constants.h" 27 #include "core/components_ng/layout/layout_property.h" 28 #include "core/components_ng/pattern/custom/custom_measure_layout_node.h" 29 #include "core/components_ng/property/measure_utils.h" 30 31 #undef private 32 #undef protected 33 34 using namespace testing; 35 using namespace testing::ext; 36 37 namespace OHOS::Ace::NG { 38 namespace { 39 LayoutConstraintF layoutConstraintF = { 40 .minSize = {1, 1}, 41 .maxSize = {10, 10}, 42 .percentReference = {5, 5}, 43 .parentIdealSize = {2, 2}, 44 }; 45 constexpr Dimension WIDTH = 1.0_vp; 46 constexpr Dimension HEIGHT = 2.0_vp; 47 const CalcSize CALC_SIZE = {CalcLength(WIDTH), CalcLength(HEIGHT)}; 48 } // namespace 49 50 class LayoutPropertyTestNgTwo : public testing::Test { 51 public: SetUpTestSuite()52 static void SetUpTestSuite() 53 { 54 MockPipelineContext::SetUp(); 55 } TearDownTestSuite()56 static void TearDownTestSuite() 57 { 58 MockPipelineContext::TearDown(); 59 } 60 }; 61 62 /** 63 * @tc.name: CheckLocalizedBorderImageOutset001 64 * @tc.desc: Test CheckLocalizedBorderImageOutset when borderImageStart_ has value 65 * @tc.type: FUNC 66 */ 67 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageOutset001, TestSize.Level1) 68 { 69 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 70 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 71 layoutProperty->SetHost(frameNodeHost); 72 73 auto renderContext = frameNodeHost->GetRenderContext(); 74 ASSERT_NE(renderContext, nullptr); 75 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 76 auto outsetDimension = Dimension(5.0); 77 borderImage->SetEdgeOutset(BorderImageDirection::START, outsetDimension); 78 renderContext->UpdateBorderImage(borderImage); 79 80 auto textDirection = TextDirection::LTR; 81 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 82 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageOutset(), outsetDimension); 83 84 textDirection = TextDirection::RTL; 85 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 86 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageOutset(), outsetDimension); 87 } 88 89 /** 90 * @tc.name: CheckLocalizedBorderImageOutset002 91 * @tc.desc: Test CheckLocalizedBorderImageOutset when borderImageEnd_ has value 92 * @tc.type: FUNC 93 */ 94 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageOutset002, TestSize.Level1) 95 { 96 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 97 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 98 layoutProperty->SetHost(frameNodeHost); 99 100 auto renderContext = frameNodeHost->GetRenderContext(); 101 ASSERT_NE(renderContext, nullptr); 102 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 103 auto outsetDimension = Dimension(5.0); 104 borderImage->SetEdgeOutset(BorderImageDirection::END, outsetDimension); 105 renderContext->UpdateBorderImage(borderImage); 106 107 auto textDirection = TextDirection::LTR; 108 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 109 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageOutset(), outsetDimension); 110 111 textDirection = TextDirection::RTL; 112 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 113 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageOutset(), outsetDimension); 114 } 115 116 /** 117 * @tc.name: CheckLocalizedBorderImageOutset003 118 * @tc.desc: Test CheckLocalizedBorderImageOutset When neither borderImageStart_ nor borderImageEnd_ has a value 119 * @tc.type: FUNC 120 */ 121 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageOutset003, TestSize.Level1) 122 { 123 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 124 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 125 layoutProperty->SetHost(frameNodeHost); 126 127 auto renderContext = frameNodeHost->GetRenderContext(); 128 ASSERT_NE(renderContext, nullptr); 129 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 130 renderContext->UpdateBorderImage(borderImage); 131 132 auto textDirection = TextDirection::LTR; 133 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 134 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageOutset().IsValid()); 135 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageOutset().IsValid()); 136 } 137 138 /** 139 * @tc.name: CheckLocalizedBorderImageWidth001 140 * @tc.desc: Test CheckLocalizedBorderImageWidth when borderImageStart_ has value 141 * @tc.type: FUNC 142 */ 143 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageWidth001, TestSize.Level1) 144 { 145 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 146 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 147 layoutProperty->SetHost(frameNodeHost); 148 149 auto renderContext = frameNodeHost->GetRenderContext(); 150 ASSERT_NE(renderContext, nullptr); 151 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 152 auto widthDimension = Dimension(5.0); 153 borderImage->SetEdgeWidth(BorderImageDirection::START, widthDimension); 154 renderContext->UpdateBorderImage(borderImage); 155 156 auto textDirection = TextDirection::LTR; 157 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 158 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageWidth(), widthDimension); 159 160 textDirection = TextDirection::RTL; 161 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 162 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageWidth(), widthDimension); 163 } 164 165 /** 166 * @tc.name: CheckLocalizedBorderImageWidth002 167 * @tc.desc: Test CheckLocalizedBorderImageWidth when borderImageEnd_ has value 168 * @tc.type: FUNC 169 */ 170 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageWidth002, TestSize.Level1) 171 { 172 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 173 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 174 layoutProperty->SetHost(frameNodeHost); 175 176 auto renderContext = frameNodeHost->GetRenderContext(); 177 ASSERT_NE(renderContext, nullptr); 178 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 179 auto widthDimension = Dimension(5.0); 180 borderImage->SetEdgeWidth(BorderImageDirection::END, widthDimension); 181 renderContext->UpdateBorderImage(borderImage); 182 183 auto textDirection = TextDirection::LTR; 184 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 185 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageWidth(), widthDimension); 186 187 textDirection = TextDirection::RTL; 188 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 189 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageWidth(), widthDimension); 190 } 191 192 /** 193 * @tc.name: CheckLocalizedBorderImageWidth003 194 * @tc.desc: Test CheckLocalizedBorderImageWidth When neither borderImageStart_ nor borderImageEnd_ has a value 195 * @tc.type: FUNC 196 */ 197 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageWidth003, TestSize.Level1) 198 { 199 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 200 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 201 layoutProperty->SetHost(frameNodeHost); 202 203 auto renderContext = frameNodeHost->GetRenderContext(); 204 ASSERT_NE(renderContext, nullptr); 205 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 206 renderContext->UpdateBorderImage(borderImage); 207 208 auto textDirection = TextDirection::LTR; 209 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 210 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageWidth().IsValid()); 211 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageWidth().IsValid()); 212 } 213 214 /** 215 * @tc.name: CheckLocalizedBorderImageSlice001 216 * @tc.desc: Test CheckLocalizedBorderImageSlice when borderImageStart_ has value 217 * @tc.type: FUNC 218 */ 219 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageSlice001, TestSize.Level1) 220 { 221 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 222 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 223 layoutProperty->SetHost(frameNodeHost); 224 225 auto renderContext = frameNodeHost->GetRenderContext(); 226 ASSERT_NE(renderContext, nullptr); 227 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 228 auto sliceDimension = Dimension(5.0); 229 borderImage->SetEdgeSlice(BorderImageDirection::START, sliceDimension); 230 renderContext->UpdateBorderImage(borderImage); 231 232 auto textDirection = TextDirection::LTR; 233 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 234 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageSlice(), sliceDimension); 235 236 textDirection = TextDirection::RTL; 237 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 238 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageSlice(), sliceDimension); 239 } 240 241 /** 242 * @tc.name: CheckLocalizedBorderImageSlice002 243 * @tc.desc: Test CheckLocalizedBorderImageSlice when borderImageEnd_ has value 244 * @tc.type: FUNC 245 */ 246 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageSlice002, TestSize.Level1) 247 { 248 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 249 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 250 layoutProperty->SetHost(frameNodeHost); 251 252 auto renderContext = frameNodeHost->GetRenderContext(); 253 ASSERT_NE(renderContext, nullptr); 254 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 255 auto sliceDimension = Dimension(5.0); 256 borderImage->SetEdgeSlice(BorderImageDirection::END, sliceDimension); 257 renderContext->UpdateBorderImage(borderImage); 258 259 auto textDirection = TextDirection::LTR; 260 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 261 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageSlice(), sliceDimension); 262 263 textDirection = TextDirection::RTL; 264 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 265 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageSlice(), sliceDimension); 266 } 267 268 /** 269 * @tc.name: CheckLocalizedBorderImageSlice003 270 * @tc.desc: Test CheckLocalizedBorderImageSlice When neither borderImageStart_ nor borderImageEnd_ has a value 271 * @tc.type: FUNC 272 */ 273 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageSlice003, TestSize.Level1) 274 { 275 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 276 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 277 layoutProperty->SetHost(frameNodeHost); 278 279 auto renderContext = frameNodeHost->GetRenderContext(); 280 ASSERT_NE(renderContext, nullptr); 281 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 282 renderContext->UpdateBorderImage(borderImage); 283 284 auto textDirection = TextDirection::LTR; 285 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 286 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageSlice().IsValid()); 287 EXPECT_FALSE(borderImage->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageSlice().IsValid()); 288 } 289 290 /** 291 * @tc.name: CheckLocalizedEdgeColors001 292 * @tc.desc: Test CheckLocalizedEdgeColors when startColor has value 293 * @tc.type: FUNC 294 */ 295 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeColors001, TestSize.Level1) 296 { 297 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 298 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 299 layoutProperty->SetHost(frameNodeHost); 300 301 auto renderContext = frameNodeHost->GetRenderContext(); 302 ASSERT_NE(renderContext, nullptr); 303 BorderColorProperty borderColorProperty; 304 borderColorProperty.startColor = std::make_optional<Color>(Color::BLUE); 305 renderContext->UpdateBorderColor(borderColorProperty); 306 307 auto textDirection = TextDirection::LTR; 308 layoutProperty->CheckLocalizedEdgeColors(textDirection); 309 ASSERT_NE(renderContext->GetBorder(), nullptr); 310 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().leftColor.value(), Color::BLUE); 311 312 textDirection = TextDirection::RTL; 313 layoutProperty->CheckLocalizedEdgeColors(textDirection); 314 ASSERT_NE(renderContext->GetBorder(), nullptr); 315 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().rightColor.value(), Color::BLUE); 316 } 317 318 /** 319 * @tc.name: CheckLocalizedEdgeColors002 320 * @tc.desc: Test CheckLocalizedEdgeColors when endColor,topColor,bottomColor all have values 321 * @tc.type: FUNC 322 */ 323 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeColors002, TestSize.Level1) 324 { 325 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 326 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 327 layoutProperty->SetHost(frameNodeHost); 328 329 auto renderContext = frameNodeHost->GetRenderContext(); 330 ASSERT_NE(renderContext, nullptr); 331 BorderColorProperty borderColorProperty; 332 borderColorProperty.endColor = std::make_optional<Color>(Color::BLUE); 333 borderColorProperty.topColor = std::make_optional<Color>(Color::RED); 334 borderColorProperty.bottomColor = std::make_optional<Color>(Color::GREEN); 335 renderContext->UpdateBorderColor(borderColorProperty); 336 337 auto textDirection = TextDirection::LTR; 338 layoutProperty->CheckLocalizedEdgeColors(textDirection); 339 ASSERT_NE(renderContext->GetBorder(), nullptr); 340 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().rightColor.value(), Color::BLUE); 341 342 textDirection = TextDirection::RTL; 343 layoutProperty->CheckLocalizedEdgeColors(textDirection); 344 ASSERT_NE(renderContext->GetBorder(), nullptr); 345 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().leftColor.value(), Color::BLUE); 346 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().topColor.value(), Color::RED); 347 } 348 349 /** 350 * @tc.name: CheckLocalizedEdgeColors003 351 * @tc.desc: Test CheckLocalizedEdgeColors When neither startColor nor endColor has a value 352 * @tc.type: FUNC 353 */ 354 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeColors003, TestSize.Level1) 355 { 356 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 357 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 358 layoutProperty->SetHost(frameNodeHost); 359 360 auto renderContext = frameNodeHost->GetRenderContext(); 361 ASSERT_NE(renderContext, nullptr); 362 BorderColorProperty borderColorProperty; 363 renderContext->UpdateBorderColor(borderColorProperty); 364 365 auto textDirection = TextDirection::LTR; 366 layoutProperty->CheckLocalizedEdgeColors(textDirection); 367 ASSERT_NE(renderContext->GetBorder(), nullptr); 368 EXPECT_EQ(renderContext->GetBorder()->GetBorderColorValue().multiValued, false); 369 } 370 371 /** 372 * @tc.name: CheckLocalizedEdgeWidths001 373 * @tc.desc: Test CheckLocalizedEdgeWidths when startDimen,topDimen,bottomDimen,leftDimen all have values 374 * @tc.type: FUNC 375 */ 376 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeWidths001, TestSize.Level1) 377 { 378 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 379 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 380 layoutProperty->SetHost(frameNodeHost); 381 382 auto renderContext = frameNodeHost->GetRenderContext(); 383 ASSERT_NE(renderContext, nullptr); 384 BorderWidthProperty borderWidth; 385 auto startDimen = Dimension(5.0); 386 borderWidth.startDimen = std::make_optional<Dimension>(5.0); 387 borderWidth.topDimen = std::make_optional<Dimension>(6.0); 388 borderWidth.bottomDimen = std::make_optional<Dimension>(7.0); 389 borderWidth.leftDimen = std::make_optional<Dimension>(8.0); 390 renderContext->UpdateBorderWidth(borderWidth); 391 392 auto textDirection = TextDirection::LTR; 393 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, textDirection); 394 ASSERT_NE(layoutProperty->GetBorderWidthProperty(), nullptr); 395 EXPECT_EQ(layoutProperty->GetBorderWidthProperty()->leftDimen, startDimen); 396 397 textDirection = TextDirection::RTL; 398 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, textDirection); 399 ASSERT_NE(layoutProperty->GetBorderWidthProperty(), nullptr); 400 EXPECT_EQ(layoutProperty->GetBorderWidthProperty()->rightDimen, startDimen); 401 } 402 403 /** 404 * @tc.name: CheckLocalizedEdgeWidths002 405 * @tc.desc: Test CheckLocalizedEdgeWidths when endDimen,rightDimen have values 406 * @tc.type: FUNC 407 */ 408 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeWidths002, TestSize.Level1) 409 { 410 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 411 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 412 layoutProperty->SetHost(frameNodeHost); 413 414 auto renderContext = frameNodeHost->GetRenderContext(); 415 ASSERT_NE(renderContext, nullptr); 416 BorderWidthProperty borderWidth; 417 auto endDimen = Dimension(5.0); 418 borderWidth.endDimen = std::make_optional<Dimension>(5.0); 419 borderWidth.rightDimen = std::make_optional<Dimension>(6.0); 420 renderContext->UpdateBorderWidth(borderWidth); 421 422 auto textDirection = TextDirection::LTR; 423 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, textDirection); 424 ASSERT_NE(layoutProperty->GetBorderWidthProperty(), nullptr); 425 EXPECT_EQ(layoutProperty->GetBorderWidthProperty()->rightDimen, endDimen); 426 427 textDirection = TextDirection::RTL; 428 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, textDirection); 429 ASSERT_NE(layoutProperty->GetBorderWidthProperty(), nullptr); 430 EXPECT_EQ(layoutProperty->GetBorderWidthProperty()->leftDimen, endDimen); 431 } 432 433 /** 434 * @tc.name: CheckLocalizedEdgeWidths003 435 * @tc.desc: Test CheckLocalizedEdgeWidths When neither startDimen nor endDimen has a value 436 * @tc.type: FUNC 437 */ 438 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedEdgeWidths003, TestSize.Level1) 439 { 440 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 441 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 442 layoutProperty->SetHost(frameNodeHost); 443 444 auto renderContext = frameNodeHost->GetRenderContext(); 445 ASSERT_NE(renderContext, nullptr); 446 BorderWidthProperty borderWidth; 447 renderContext->UpdateBorderWidth(borderWidth); 448 449 auto textDirection = TextDirection::LTR; 450 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, textDirection); 451 ASSERT_NE(renderContext->GetBorder(), nullptr); 452 EXPECT_EQ(renderContext->GetBorder()->GetBorderWidthValue().multiValued, false); 453 } 454 455 /** 456 * @tc.name: CheckLocalizedMargin001 457 * @tc.desc: Test CheckLocalizedMargin when start,top,bottom,left have values 458 * @tc.type: FUNC 459 */ 460 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedMargin001, TestSize.Level1) 461 { 462 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 463 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 464 layoutProperty->SetHost(frameNodeHost); 465 466 PaddingPropertyT<CalcLength> paddingProperty; 467 paddingProperty.start = std::make_optional<CalcLength>(5.0); 468 paddingProperty.top = std::make_optional<CalcLength>(6.0); 469 paddingProperty.bottom = std::make_optional<CalcLength>(7.0); 470 paddingProperty.left = std::make_optional<CalcLength>(8.0); 471 layoutProperty->UpdateMargin(paddingProperty); 472 473 auto textDirection = TextDirection::LTR; 474 layoutProperty->CheckLocalizedMargin(layoutProperty, textDirection); 475 auto& marginProperty = layoutProperty->GetMarginProperty(); 476 ASSERT_NE(marginProperty, nullptr); 477 EXPECT_EQ(marginProperty->left.value(), CalcLength(5.0)); 478 479 textDirection = TextDirection::RTL; 480 layoutProperty->CheckLocalizedMargin(layoutProperty, textDirection); 481 ASSERT_NE(marginProperty, nullptr); 482 EXPECT_EQ(marginProperty->right.value(), CalcLength(5.0)); 483 } 484 485 /** 486 * @tc.name: CheckLocalizedMargin002 487 * @tc.desc: Test CheckLocalizedMargin when end,right have values 488 * @tc.type: FUNC 489 */ 490 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedMargin002, TestSize.Level1) 491 { 492 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 493 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 494 layoutProperty->SetHost(frameNodeHost); 495 496 PaddingPropertyT<CalcLength> paddingProperty; 497 paddingProperty.end = std::make_optional<CalcLength>(5.0); 498 paddingProperty.right = std::make_optional<CalcLength>(6.0); 499 layoutProperty->UpdateMargin(paddingProperty); 500 501 auto textDirection = TextDirection::LTR; 502 layoutProperty->CheckLocalizedMargin(layoutProperty, textDirection); 503 auto& marginProperty = layoutProperty->GetMarginProperty(); 504 ASSERT_NE(marginProperty, nullptr); 505 EXPECT_EQ(marginProperty->right.value(), CalcLength(5.0)); 506 507 textDirection = TextDirection::RTL; 508 layoutProperty->CheckLocalizedMargin(layoutProperty, textDirection); 509 ASSERT_NE(marginProperty, nullptr); 510 EXPECT_EQ(marginProperty->left.value(), CalcLength(5.0)); 511 } 512 513 /** 514 * @tc.name: CheckLocalizedMargin003 515 * @tc.desc: Test CheckLocalizedMargin When neither start nor end has a value 516 * @tc.type: FUNC 517 */ 518 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedMargin003, TestSize.Level1) 519 { 520 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 521 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 522 layoutProperty->SetHost(frameNodeHost); 523 524 PaddingPropertyT<CalcLength> paddingProperty; 525 layoutProperty->UpdateMargin(paddingProperty); 526 527 auto textDirection = TextDirection::LTR; 528 layoutProperty->CheckLocalizedMargin(layoutProperty, textDirection); 529 auto& marginProperty = layoutProperty->GetMarginProperty(); 530 ASSERT_NE(marginProperty, nullptr); 531 EXPECT_FALSE(marginProperty->right.has_value()); 532 EXPECT_FALSE(marginProperty->left.has_value()); 533 } 534 535 /** 536 * @tc.name: CheckLocalizedPadding001 537 * @tc.desc: Test CheckLocalizedPadding when start,top,bottom,left have values 538 * @tc.type: FUNC 539 */ 540 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedPadding001, TestSize.Level1) 541 { 542 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 543 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 544 layoutProperty->SetHost(frameNodeHost); 545 546 PaddingPropertyT<CalcLength> paddingProperty; 547 paddingProperty.start = std::make_optional<CalcLength>(5.0); 548 paddingProperty.top = std::make_optional<CalcLength>(6.0); 549 paddingProperty.bottom = std::make_optional<CalcLength>(7.0); 550 paddingProperty.left = std::make_optional<CalcLength>(8.0); 551 layoutProperty->UpdatePadding(paddingProperty); 552 553 auto textDirection = TextDirection::LTR; 554 layoutProperty->CheckLocalizedPadding(layoutProperty, textDirection); 555 auto& padding = layoutProperty->GetPaddingProperty(); 556 ASSERT_NE(padding, nullptr); 557 EXPECT_EQ(padding->left.value(), CalcLength(5.0)); 558 559 textDirection = TextDirection::RTL; 560 layoutProperty->CheckLocalizedPadding(layoutProperty, textDirection); 561 ASSERT_NE(padding, nullptr); 562 EXPECT_EQ(padding->right.value(), CalcLength(5.0)); 563 } 564 565 /** 566 * @tc.name: CheckLocalizedPadding002 567 * @tc.desc: Test CheckLocalizedPadding when end,right have values 568 * @tc.type: FUNC 569 */ 570 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedPadding002, TestSize.Level1) 571 { 572 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 573 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 574 layoutProperty->SetHost(frameNodeHost); 575 576 PaddingPropertyT<CalcLength> paddingProperty; 577 paddingProperty.end = std::make_optional<CalcLength>(5.0); 578 paddingProperty.right = std::make_optional<CalcLength>(6.0); 579 layoutProperty->UpdatePadding(paddingProperty); 580 581 auto textDirection = TextDirection::LTR; 582 layoutProperty->CheckLocalizedPadding(layoutProperty, textDirection); 583 auto& padding = layoutProperty->GetPaddingProperty(); 584 ASSERT_NE(padding, nullptr); 585 EXPECT_EQ(padding->right.value(), CalcLength(5.0)); 586 587 textDirection = TextDirection::RTL; 588 layoutProperty->CheckLocalizedPadding(layoutProperty, textDirection); 589 ASSERT_NE(padding, nullptr); 590 EXPECT_EQ(padding->left.value(), CalcLength(5.0)); 591 } 592 593 /** 594 * @tc.name: CheckLocalizedPadding003 595 * @tc.desc: Test CheckLocalizedPadding When neither start nor end has a value 596 * @tc.type: FUNC 597 */ 598 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedPadding003, TestSize.Level1) 599 { 600 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 601 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 602 layoutProperty->SetHost(frameNodeHost); 603 604 PaddingPropertyT<CalcLength> paddingProperty; 605 layoutProperty->UpdatePadding(paddingProperty); 606 607 auto textDirection = TextDirection::LTR; 608 layoutProperty->CheckLocalizedPadding(layoutProperty, textDirection); 609 auto& padding = layoutProperty->GetPaddingProperty(); 610 ASSERT_NE(padding, nullptr); 611 EXPECT_FALSE(padding->right.has_value()); 612 EXPECT_FALSE(padding->left.has_value()); 613 } 614 615 /** 616 * @tc.name: LocalizedPaddingOrMarginChange001 617 * @tc.desc: Test LocalizedPaddingOrMarginChange 618 * @tc.type: FUNC 619 */ 620 HWTEST_F(LayoutPropertyTestNgTwo, LocalizedPaddingOrMarginChange001, TestSize.Level1) 621 { 622 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 623 624 PaddingPropertyT<CalcLength> paddingProperty1; 625 std::unique_ptr<PaddingProperty> PaddingProperty2 = std::make_unique<PaddingProperty>(); 626 627 layoutProperty->LocalizedPaddingOrMarginChange(paddingProperty1, PaddingProperty2); 628 629 paddingProperty1.end = std::make_optional<CalcLength>(5.0); 630 layoutProperty->LocalizedPaddingOrMarginChange(paddingProperty1, PaddingProperty2); 631 EXPECT_EQ(PaddingProperty2->end.value(), CalcLength(5.0)); 632 633 paddingProperty1.start = std::make_optional<CalcLength>(5.0); 634 layoutProperty->LocalizedPaddingOrMarginChange(paddingProperty1, PaddingProperty2); 635 EXPECT_EQ(PaddingProperty2->start.value(), CalcLength(5.0)); 636 } 637 638 /** 639 * @tc.name: CheckLocalizedOuterBorderColor001 640 * @tc.desc: Test CheckLocalizedOuterBorderColor when startColor has value 641 * @tc.type: FUNC 642 */ 643 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedOuterBorderColor001, TestSize.Level1) 644 { 645 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 646 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 647 layoutProperty->SetHost(frameNodeHost); 648 649 auto renderContext = frameNodeHost->GetRenderContext(); 650 ASSERT_NE(renderContext, nullptr); 651 BorderColorProperty borderColorProperty; 652 borderColorProperty.startColor = std::make_optional<Color>(Color::BLUE); 653 renderContext->UpdateOuterBorderColor(borderColorProperty); 654 655 auto textDirection = TextDirection::LTR; 656 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 657 ASSERT_NE(renderContext->GetOuterBorder(), nullptr); 658 EXPECT_EQ(renderContext->GetOuterBorder()->GetOuterBorderColorValue().leftColor.value(), Color::BLUE); 659 660 textDirection = TextDirection::RTL; 661 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 662 ASSERT_NE(renderContext->GetOuterBorder(), nullptr); 663 EXPECT_EQ(renderContext->GetOuterBorder()->GetOuterBorderColorValue().rightColor.value(), Color::BLUE); 664 } 665 666 /** 667 * @tc.name: CheckLocalizedOuterBorderColor002 668 * @tc.desc: Test CheckLocalizedOuterBorderColor when endColor,topColor,bottomColor have values 669 * @tc.type: FUNC 670 */ 671 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedOuterBorderColor002, TestSize.Level1) 672 { 673 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 674 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 675 layoutProperty->SetHost(frameNodeHost); 676 677 auto renderContext = frameNodeHost->GetRenderContext(); 678 ASSERT_NE(renderContext, nullptr); 679 BorderColorProperty borderColorProperty; 680 borderColorProperty.endColor = std::make_optional<Color>(Color::BLUE); 681 borderColorProperty.topColor = std::make_optional<Color>(Color::RED); 682 borderColorProperty.bottomColor = std::make_optional<Color>(Color::GREEN); 683 renderContext->UpdateOuterBorderColor(borderColorProperty); 684 685 auto textDirection = TextDirection::LTR; 686 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 687 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 688 ASSERT_NE(renderContext->GetOuterBorder(), nullptr); 689 EXPECT_EQ(renderContext->GetOuterBorder()->GetOuterBorderColorValue().rightColor.value(), Color::BLUE); 690 691 textDirection = TextDirection::RTL; 692 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 693 ASSERT_NE(renderContext->GetOuterBorder(), nullptr); 694 EXPECT_EQ(renderContext->GetOuterBorder()->GetOuterBorderColorValue().leftColor.value(), Color::BLUE); 695 } 696 697 /** 698 * @tc.name: CheckLocalizedOuterBorderColor003 699 * @tc.desc: Test CheckLocalizedOuterBorderColor When neither startColor nor endColor has a value 700 * @tc.type: FUNC 701 */ 702 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedOuterBorderColor003, TestSize.Level1) 703 { 704 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 705 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 706 layoutProperty->SetHost(frameNodeHost); 707 708 auto renderContext = frameNodeHost->GetRenderContext(); 709 ASSERT_NE(renderContext, nullptr); 710 BorderColorProperty borderColorProperty; 711 renderContext->UpdateOuterBorderColor(borderColorProperty); 712 713 auto textDirection = TextDirection::LTR; 714 layoutProperty->CheckLocalizedOuterBorderColor(textDirection); 715 ASSERT_NE(renderContext->GetOuterBorder(), nullptr); 716 EXPECT_FALSE(renderContext->GetOuterBorder()->GetOuterBorderColorValue().rightColor.has_value()); 717 EXPECT_FALSE(renderContext->GetOuterBorder()->GetOuterBorderColorValue().leftColor.has_value()); 718 } 719 720 /** 721 * @tc.name: CheckLocalizedBorderRadiuses001 722 * @tc.desc: Test CheckLocalizedBorderRadiuses when radiusTopStart,radiusTopEnd, 723 * radiusBottomStart,radiusBottomEnd have values 724 * @tc.type: FUNC 725 */ 726 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderRadiuses001, TestSize.Level1) 727 { 728 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 729 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 730 layoutProperty->SetHost(frameNodeHost); 731 732 BorderRadiusProperty borderRadius; 733 borderRadius.radiusTopStart = std::make_optional<Dimension>(5.0); 734 borderRadius.radiusTopEnd = std::make_optional<Dimension>(6.0); 735 borderRadius.radiusBottomStart = std::make_optional<Dimension>(7.0); 736 borderRadius.radiusBottomEnd = std::make_optional<Dimension>(8.0); 737 738 auto renderContext = frameNodeHost->GetRenderContext(); 739 ASSERT_NE(renderContext, nullptr); 740 renderContext->UpdateBorderRadius(borderRadius); 741 742 auto textDirection = TextDirection::LTR; 743 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 744 ASSERT_NE(renderContext->GetBorder(), nullptr); 745 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopLeft.value(), Dimension(5.0)); 746 747 textDirection = TextDirection::RTL; 748 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 749 ASSERT_NE(renderContext->GetBorder(), nullptr); 750 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopRight.value(), Dimension(5.0)); 751 } 752 753 /** 754 * @tc.name: CheckLocalizedBorderRadiuses002 755 * @tc.desc: Test CheckLocalizedBorderRadiuses when radiusTopStart,radiusTopEnd, 756 * radiusBottomStart,radiusBottomEnd have no values 757 * @tc.type: FUNC 758 */ 759 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderRadiuses002, TestSize.Level1) 760 { 761 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 762 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 763 layoutProperty->SetHost(frameNodeHost); 764 765 BorderRadiusProperty borderRadius; 766 auto renderContext = frameNodeHost->GetRenderContext(); 767 ASSERT_NE(renderContext, nullptr); 768 renderContext->UpdateBorderRadius(borderRadius); 769 770 auto textDirection = TextDirection::LTR; 771 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 772 ASSERT_NE(renderContext->GetBorder(), nullptr); 773 EXPECT_FALSE(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopLeft.has_value()); 774 EXPECT_FALSE(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopRight.has_value()); 775 } 776 777 /** 778 * @tc.name: CheckLocalizedBorderRadiuses003 779 * @tc.desc: Test CheckLocalizedBorderRadiuses When one of radiusTopStart,radiusTopEnd, 780 * radiusBottomStart,radiusBottomEnd has a value 781 * @tc.type: FUNC 782 */ 783 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderRadiuses003, TestSize.Level1) 784 { 785 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 786 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 787 layoutProperty->SetHost(frameNodeHost); 788 789 auto radiusTopStart = Dimension(5.0); 790 auto radiusTopEnd = Dimension(6.0); 791 auto radiusBottomStart = Dimension(7.0); 792 auto radiusBottomEnd = Dimension(8.0); 793 794 BorderRadiusProperty borderRadius; 795 auto renderContext = frameNodeHost->GetRenderContext(); 796 ASSERT_NE(renderContext, nullptr); 797 borderRadius.radiusTopStart = std::make_optional<Dimension>(radiusTopStart); 798 renderContext->UpdateBorderRadius(borderRadius); 799 800 auto textDirection = TextDirection::LTR; 801 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 802 ASSERT_NE(renderContext->GetBorder(), nullptr); 803 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopLeft.value(), radiusTopStart); 804 805 borderRadius.radiusTopStart = std::nullopt; 806 borderRadius.radiusTopEnd = std::make_optional<Dimension>(radiusTopEnd); 807 renderContext->GetBorder()->UpdateBorderRadius(borderRadius); 808 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 809 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusTopRight.value(), radiusTopEnd); 810 811 borderRadius.radiusTopEnd = std::nullopt; 812 borderRadius.radiusBottomStart = std::make_optional<Dimension>(radiusBottomStart); 813 renderContext->GetBorder()->UpdateBorderRadius(borderRadius); 814 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 815 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusBottomLeft.value(), radiusBottomStart); 816 817 borderRadius.radiusBottomStart = std::nullopt; 818 borderRadius.radiusBottomEnd = std::make_optional<Dimension>(radiusBottomEnd); 819 renderContext->GetBorder()->UpdateBorderRadius(borderRadius); 820 layoutProperty->CheckLocalizedBorderRadiuses(textDirection); 821 EXPECT_EQ(renderContext->GetBorder()->GetBorderRadiusValue().radiusBottomRight.value(), radiusBottomEnd); 822 } 823 824 /** 825 * @tc.name: CheckOffsetLocalizedEdges001 826 * @tc.desc: Test CheckOffsetLocalizedEdges 827 * @tc.type: FUNC 828 */ 829 HWTEST_F(LayoutPropertyTestNgTwo, CheckOffsetLocalizedEdges001, TestSize.Level1) 830 { 831 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 832 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 833 layoutProperty->SetHost(frameNodeHost); 834 835 auto top = CalcDimension(1.0); 836 auto bottom = CalcDimension(2.0); 837 auto start = CalcDimension(3.0); 838 auto end = CalcDimension(4.0); 839 840 EdgesParam edges; 841 edges.SetTop(top); 842 edges.SetBottom(bottom); 843 edges.start = start; 844 edges.end = end; 845 846 auto renderContext = frameNodeHost->GetRenderContext(); 847 ASSERT_NE(renderContext, nullptr); 848 renderContext->UpdateOffsetEdges(edges); 849 850 auto textDirection = TextDirection::LTR; 851 layoutProperty->CheckOffsetLocalizedEdges(textDirection); 852 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 853 EXPECT_EQ(renderContext->GetPositionProperty()->GetOffsetEdgesValue().left.value(), start); 854 855 textDirection = TextDirection::RTL; 856 layoutProperty->CheckOffsetLocalizedEdges(textDirection); 857 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 858 EXPECT_EQ(renderContext->GetPositionProperty()->GetOffsetEdgesValue().left.value(), end); 859 } 860 861 /** 862 * @tc.name: CheckOffsetLocalizedEdges002 863 * @tc.desc: Test CheckOffsetLocalizedEdges 864 * @tc.type: FUNC 865 */ 866 HWTEST_F(LayoutPropertyTestNgTwo, CheckOffsetLocalizedEdges002, TestSize.Level1) 867 { 868 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 869 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 870 layoutProperty->SetHost(frameNodeHost); 871 872 EdgesParam edges; 873 874 auto renderContext = frameNodeHost->GetRenderContext(); 875 ASSERT_NE(renderContext, nullptr); 876 renderContext->UpdateOffsetEdges(edges); 877 878 auto textDirection = TextDirection::LTR; 879 layoutProperty->CheckOffsetLocalizedEdges(textDirection); 880 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 881 EXPECT_FALSE(renderContext->GetPositionProperty()->GetOffsetEdgesValue().left.has_value()); 882 EXPECT_FALSE(renderContext->GetPositionProperty()->GetOffsetEdgesValue().right.has_value()); 883 } 884 885 /** 886 * @tc.name: CheckPositionLocalizedEdges001 887 * @tc.desc: Test CheckPositionLocalizedEdges 888 * @tc.type: FUNC 889 */ 890 HWTEST_F(LayoutPropertyTestNgTwo, CheckPositionLocalizedEdges001, TestSize.Level1) 891 { 892 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 893 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 894 layoutProperty->SetHost(frameNodeHost); 895 896 auto top = CalcDimension(1.0); 897 auto bottom = CalcDimension(2.0); 898 auto start = CalcDimension(3.0); 899 auto end = CalcDimension(4.0); 900 901 EdgesParam edges; 902 edges.SetTop(top); 903 edges.SetBottom(bottom); 904 edges.start = start; 905 edges.end = end; 906 907 auto renderContext = frameNodeHost->GetRenderContext(); 908 ASSERT_NE(renderContext, nullptr); 909 renderContext->UpdatePositionEdges(edges); 910 911 auto textDirection = TextDirection::LTR; 912 layoutProperty->CheckPositionLocalizedEdges(textDirection); 913 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 914 EXPECT_EQ(renderContext->GetPositionProperty()->GetPositionEdgesValue().left.value(), start); 915 916 textDirection = TextDirection::RTL; 917 layoutProperty->CheckPositionLocalizedEdges(textDirection); 918 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 919 EXPECT_EQ(renderContext->GetPositionProperty()->GetPositionEdgesValue().left.value(), end); 920 } 921 922 /** 923 * @tc.name: CheckPositionLocalizedEdges002 924 * @tc.desc: Test CheckPositionLocalizedEdges 925 * @tc.type: FUNC 926 */ 927 HWTEST_F(LayoutPropertyTestNgTwo, CheckPositionLocalizedEdges002, TestSize.Level1) 928 { 929 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 930 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 931 layoutProperty->SetHost(frameNodeHost); 932 933 EdgesParam edges; 934 935 auto renderContext = frameNodeHost->GetRenderContext(); 936 ASSERT_NE(renderContext, nullptr); 937 renderContext->UpdatePositionEdges(edges); 938 939 auto textDirection = TextDirection::LTR; 940 layoutProperty->CheckPositionLocalizedEdges(textDirection); 941 ASSERT_NE(renderContext->GetPositionProperty(), nullptr); 942 EXPECT_FALSE(renderContext->GetPositionProperty()->GetPositionEdgesValue().left.has_value()); 943 EXPECT_FALSE(renderContext->GetPositionProperty()->GetPositionEdgesValue().right.has_value()); 944 } 945 946 /** 947 * @tc.name: ConstraintEqual001 948 * @tc.desc: Test ConstraintEqual when preContentConstraint is nullopt 949 * @tc.type: FUNC 950 */ 951 HWTEST_F(LayoutPropertyTestNgTwo, ConstraintEqual001, TestSize.Level1) 952 { 953 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 954 955 auto preLayoutConstraint = std::make_optional<LayoutConstraintF>(); 956 auto preContentConstraint = std::make_optional<LayoutConstraintF>(); 957 preContentConstraint = std::nullopt; 958 959 layoutProperty->layoutConstraint_ = preLayoutConstraint; 960 bool bResult = layoutProperty->ConstraintEqual(preLayoutConstraint, preContentConstraint); 961 EXPECT_FALSE(bResult); 962 } 963 964 /** 965 * @tc.name: UpdateAllGeometryTransition001 966 * @tc.desc: Test UpdateAllGeometryTransition 967 * @tc.type: FUNC 968 */ 969 HWTEST_F(LayoutPropertyTestNgTwo, UpdateAllGeometryTransition001, TestSize.Level1) 970 { 971 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 972 973 auto parentId = ElementRegister::GetInstance()->MakeUniqueId(); 974 auto parent = CustomNode::CreateCustomNode(parentId, "parent"); 975 layoutProperty->UpdateAllGeometryTransition(parent); 976 977 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 978 layoutProperty->UpdateAllGeometryTransition(frameNodeHost); 979 EXPECT_FALSE(layoutProperty->GetGeometryTransition()); 980 } 981 982 /** 983 * @tc.name: FromJson001 984 * @tc.desc: Test FromJson 985 * @tc.type: FUNC 986 */ 987 HWTEST_F(LayoutPropertyTestNgTwo, FromJson001, TestSize.Level1) 988 { 989 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 990 991 auto json = JsonUtil::Create(true); 992 json->Put("padding", "0.0"); 993 json->Put("margin", "0.0"); 994 json->Put("direction", "Direction.Rtl"); 995 layoutProperty->FromJson(json); 996 997 EXPECT_EQ(layoutProperty->GetNonAutoLayoutDirection(), TextDirection::RTL); 998 } 999 1000 /** 1001 * @tc.name: UpdateSafeAreaPadding001 1002 * @tc.desc: Test UpdateSafeAreaPadding 1003 * @tc.type: FUNC 1004 */ 1005 HWTEST_F(LayoutPropertyTestNgTwo, UpdateSafeAreaPadding001, TestSize.Level1) 1006 { 1007 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1008 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1009 layoutProperty->SetHost(frameNodeHost); 1010 1011 PaddingProperty paddingProperty; 1012 layoutProperty->ResetSafeAreaPadding(); 1013 layoutProperty->UpdateSafeAreaPadding(paddingProperty); 1014 EXPECT_TRUE(layoutProperty->GetSafeAreaPaddingProperty()); 1015 1016 paddingProperty.start = std::make_optional<CalcLength>(5.0); 1017 layoutProperty->UpdateSafeAreaPadding(paddingProperty); 1018 layoutProperty->ResetSafeAreaPadding(); 1019 EXPECT_FALSE(layoutProperty->GetSafeAreaPaddingProperty()); 1020 } 1021 1022 /** 1023 * @tc.name: PixelRoundToJsonValue001 1024 * @tc.desc: Test PixelRoundToJsonValue 1025 * @tc.type: FUNC 1026 */ 1027 HWTEST_F(LayoutPropertyTestNgTwo, PixelRoundToJsonValue001, TestSize.Level1) 1028 { 1029 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1030 const std::string VALUE = "PixelRoundCalcPolicy.FORCE_CEIL"; 1031 1032 layoutProperty->pixelRoundFlag_ = static_cast<uint16_t>(PixelRoundPolicy::FORCE_CEIL_START); 1033 auto res = layoutProperty->PixelRoundToJsonValue(); 1034 auto jsonValue = JsonUtil::ParseJsonString(res); 1035 ASSERT_NE(jsonValue, nullptr); 1036 EXPECT_EQ(jsonValue->GetString("start"), VALUE); 1037 1038 layoutProperty->pixelRoundFlag_ = static_cast<uint16_t>(PixelRoundPolicy::FORCE_CEIL_TOP); 1039 res = layoutProperty->PixelRoundToJsonValue(); 1040 jsonValue = JsonUtil::ParseJsonString(res); 1041 ASSERT_NE(jsonValue, nullptr); 1042 EXPECT_EQ(jsonValue->GetString("top"), VALUE); 1043 1044 layoutProperty->pixelRoundFlag_ = static_cast<uint16_t>(PixelRoundPolicy::FORCE_CEIL_END); 1045 res = layoutProperty->PixelRoundToJsonValue(); 1046 jsonValue = JsonUtil::ParseJsonString(res); 1047 ASSERT_NE(jsonValue, nullptr); 1048 EXPECT_EQ(jsonValue->GetString("end"), VALUE); 1049 1050 layoutProperty->pixelRoundFlag_ = static_cast<uint16_t>(PixelRoundPolicy::FORCE_CEIL_BOTTOM); 1051 res = layoutProperty->PixelRoundToJsonValue(); 1052 jsonValue = JsonUtil::ParseJsonString(res); 1053 ASSERT_NE(jsonValue, nullptr); 1054 EXPECT_EQ(jsonValue->GetString("bottom"), VALUE); 1055 } 1056 1057 /** 1058 * @tc.name: CheckLocalizedBorderImageSlice004 1059 * @tc.desc: Test CheckLocalizedBorderImageSlice when Api is 12 and 14 1060 * @tc.type: FUNC 1061 */ 1062 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageSlice004, TestSize.Level1) 1063 { 1064 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1065 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1066 layoutProperty->SetHost(frameNodeHost); 1067 1068 auto renderContext = frameNodeHost->GetRenderContext(); 1069 ASSERT_NE(renderContext, nullptr); 1070 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 1071 auto sliceDimension = Dimension(5.0); 1072 auto widthDimension = Dimension(5.0); 1073 int32_t settingApiVersion = 12; 1074 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1075 borderImage->SetEdgeSlice(BorderImageDirection::LEFT, sliceDimension); 1076 borderImage->SetEdgeWidth(BorderImageDirection::START, widthDimension); 1077 renderContext->UpdateBorderImage(borderImage); 1078 1079 auto textDirection = TextDirection::RTL; 1080 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 1081 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageSlice(), Dimension(0.0)); 1082 1083 settingApiVersion = 14; 1084 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1085 auto borderImage1 = AceType::MakeRefPtr<BorderImage>(); 1086 borderImage1->SetEdgeSlice(BorderImageDirection::LEFT, sliceDimension); 1087 borderImage1->SetEdgeWidth(BorderImageDirection::START, widthDimension); 1088 renderContext->UpdateBorderImage(borderImage1); 1089 1090 layoutProperty->CheckLocalizedBorderImageSlice(textDirection); 1091 EXPECT_EQ(borderImage1->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageSlice(), sliceDimension); 1092 } 1093 1094 /** 1095 * @tc.name: CheckLocalizedBorderImageWidth004 1096 * @tc.desc: Test CheckLocalizedBorderImageWidth when Api is 12 and 14 1097 * @tc.type: FUNC 1098 */ 1099 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageWidth004, TestSize.Level1) 1100 { 1101 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1102 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1103 layoutProperty->SetHost(frameNodeHost); 1104 1105 auto renderContext = frameNodeHost->GetRenderContext(); 1106 ASSERT_NE(renderContext, nullptr); 1107 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 1108 auto sliceDimension = Dimension(5.0); 1109 auto widthDimension = Dimension(5.0); 1110 int32_t settingApiVersion = 12; 1111 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1112 borderImage->SetEdgeSlice(BorderImageDirection::START, sliceDimension); 1113 borderImage->SetEdgeWidth(BorderImageDirection::LEFT, widthDimension); 1114 renderContext->UpdateBorderImage(borderImage); 1115 1116 auto textDirection = TextDirection::RTL; 1117 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 1118 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageWidth(), Dimension(0.0)); 1119 1120 settingApiVersion = 14; 1121 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1122 auto borderImage1 = AceType::MakeRefPtr<BorderImage>(); 1123 borderImage1->SetEdgeSlice(BorderImageDirection::START, sliceDimension); 1124 borderImage1->SetEdgeWidth(BorderImageDirection::LEFT, widthDimension); 1125 renderContext->UpdateBorderImage(borderImage); 1126 layoutProperty->CheckLocalizedBorderImageWidth(textDirection); 1127 EXPECT_EQ(borderImage1->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageWidth(), widthDimension); 1128 } 1129 1130 /** 1131 * @tc.name: CheckLocalizedBorderImageOutset004 1132 * @tc.desc: Test CheckLocalizedBorderImageOutset when Api is 12 and 14 1133 * @tc.type: FUNC 1134 */ 1135 HWTEST_F(LayoutPropertyTestNgTwo, CheckLocalizedBorderImageOutset004, TestSize.Level1) 1136 { 1137 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1138 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1139 layoutProperty->SetHost(frameNodeHost); 1140 1141 auto renderContext = frameNodeHost->GetRenderContext(); 1142 ASSERT_NE(renderContext, nullptr); 1143 auto borderImage = AceType::MakeRefPtr<BorderImage>(); 1144 auto outsetDimension = Dimension(5.0); 1145 auto widthDimension = Dimension(5.0); 1146 int32_t settingApiVersion = 12; 1147 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1148 borderImage->SetEdgeOutset(BorderImageDirection::LEFT, outsetDimension); 1149 borderImage->SetEdgeWidth(BorderImageDirection::START, widthDimension); 1150 renderContext->UpdateBorderImage(borderImage); 1151 1152 auto textDirection = TextDirection::RTL; 1153 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 1154 EXPECT_EQ(borderImage->GetBorderImageEdge(BorderImageDirection::RIGHT).GetBorderImageOutset(), Dimension(0.0)); 1155 1156 settingApiVersion = 14; 1157 AceApplicationInfo::GetInstance().SetApiTargetVersion(settingApiVersion); 1158 renderContext->UpdateBorderImage(borderImage); 1159 auto borderImage1 = AceType::MakeRefPtr<BorderImage>(); 1160 borderImage1->SetEdgeOutset(BorderImageDirection::LEFT, outsetDimension); 1161 borderImage1->SetEdgeWidth(BorderImageDirection::START, widthDimension); 1162 layoutProperty->CheckLocalizedBorderImageOutset(textDirection); 1163 EXPECT_EQ(borderImage1->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageOutset(), outsetDimension); 1164 } 1165 1166 HWTEST_F(LayoutPropertyTestNgTwo, UpdateLayoutConstraint001, TestSize.Level1) 1167 { 1168 /** 1169 * @tc.steps1 Create a layoutProperty and constraint. 1170 */ 1171 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1172 MeasureProperty constraint; 1173 constraint.maxSize = CALC_SIZE; 1174 constraint.minSize = CALC_SIZE; 1175 constraint.selfIdealSize = CALC_SIZE; 1176 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>(constraint); 1177 layoutProperty->magicItemProperty_.UpdateAspectRatio(1.0); 1178 layoutProperty->measureType_ = MeasureType::MATCH_PARENT; 1179 auto frameNode = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1180 ASSERT_NE(frameNode, nullptr); 1181 auto customMeasureLayoutNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(2, V2::TEXT_ETS_TAG); 1182 ASSERT_NE(customMeasureLayoutNode, nullptr); 1183 frameNode->parent_ = customMeasureLayoutNode; 1184 layoutProperty->SetHost(frameNode); 1185 LayoutPolicyProperty layoutPolicyProperty; 1186 layoutPolicyProperty.widthLayoutPolicy_ = LayoutCalPolicy::FIX_AT_IDEAL_SIZE; 1187 layoutPolicyProperty.heightLayoutPolicy_ = LayoutCalPolicy::FIX_AT_IDEAL_SIZE; 1188 layoutProperty->layoutPolicy_ = layoutPolicyProperty; 1189 layoutProperty->UpdateLayoutConstraint(std::move(layoutConstraintF)); 1190 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value(), CALC_SIZE); 1191 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value(), CALC_SIZE); 1192 } 1193 1194 HWTEST_F(LayoutPropertyTestNgTwo, UpdateLayoutConstraint002, TestSize.Level1) 1195 { 1196 /** 1197 * @tc.steps1 Create a layoutProperty and constraint. 1198 */ 1199 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1200 MeasureProperty constraint; 1201 constraint.maxSize = CALC_SIZE; 1202 constraint.minSize = CALC_SIZE; 1203 constraint.selfIdealSize = CALC_SIZE; 1204 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>(constraint); 1205 layoutProperty->magicItemProperty_.UpdateAspectRatio(1.0); 1206 layoutProperty->measureType_ = MeasureType::MATCH_PARENT; 1207 auto frameNode = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1208 ASSERT_NE(frameNode, nullptr); 1209 auto customMeasureLayoutNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(2, V2::TEXT_ETS_TAG); 1210 ASSERT_NE(customMeasureLayoutNode, nullptr); 1211 frameNode->parent_ = customMeasureLayoutNode; 1212 layoutProperty->SetHost(frameNode); 1213 LayoutPolicyProperty layoutPolicyProperty; 1214 layoutPolicyProperty.widthLayoutPolicy_ = LayoutCalPolicy::NO_MATCH; 1215 layoutPolicyProperty.heightLayoutPolicy_ = LayoutCalPolicy::NO_MATCH; 1216 layoutProperty->layoutPolicy_ = layoutPolicyProperty; 1217 layoutProperty->UpdateLayoutConstraint(std::move(layoutConstraintF)); 1218 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value(), CALC_SIZE); 1219 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value(), CALC_SIZE); 1220 } 1221 1222 /** 1223 * @tc.name: CheckBackgroundLayoutSafeAreaEdges001 1224 * @tc.desc: Test CheckBackgroundLayoutSafeAreaEdges 1225 * @tc.type: FUNC 1226 */ 1227 HWTEST_F(LayoutPropertyTestNgTwo, CheckBackgroundLayoutSafeAreaEdges001, TestSize.Level1) 1228 { 1229 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1230 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true); 1231 layoutProperty->SetHost(frameNodeHost); 1232 1233 layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_ = LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP; 1234 layoutProperty->CheckBackgroundLayoutSafeAreaEdges(TextDirection::LTR); 1235 EXPECT_EQ( 1236 layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_, LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP); 1237 EXPECT_EQ(layoutProperty->localizedBackgroundIgnoresLayoutSafeAreaEdges_, 1238 LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP); 1239 layoutProperty->CheckBackgroundLayoutSafeAreaEdges(TextDirection::RTL); 1240 EXPECT_EQ( 1241 layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_, LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP); 1242 EXPECT_EQ(layoutProperty->localizedBackgroundIgnoresLayoutSafeAreaEdges_, 1243 LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_TOP); 1244 1245 layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_ = LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM; 1246 layoutProperty->CheckBackgroundLayoutSafeAreaEdges(TextDirection::LTR); 1247 EXPECT_EQ(layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_, 1248 LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1249 EXPECT_EQ(layoutProperty->localizedBackgroundIgnoresLayoutSafeAreaEdges_, 1250 LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1251 layoutProperty->CheckBackgroundLayoutSafeAreaEdges(TextDirection::RTL); 1252 EXPECT_EQ(layoutProperty->backgroundIgnoresLayoutSafeAreaEdges_, 1253 LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1254 EXPECT_EQ(layoutProperty->localizedBackgroundIgnoresLayoutSafeAreaEdges_, 1255 LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1256 } 1257 1258 /** 1259 * @tc.name: CheckIgnoreLayoutSafeArea 1260 * @tc.desc: Test CheckIgnoreLayoutSafeArea 1261 * @tc.type: FUNC 1262 */ 1263 HWTEST_F(LayoutPropertyTestNgTwo, CheckIgnoreLayoutSafeArea, TestSize.Level1) 1264 { 1265 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1266 layoutProperty->ignoreLayoutSafeAreaOpts_ = std::make_unique<IgnoreLayoutSafeAreaOpts>(); 1267 1268 layoutProperty->ignoreLayoutSafeAreaOpts_->rawEdges = LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP; 1269 layoutProperty->CheckIgnoreLayoutSafeArea(TextDirection::LTR); 1270 EXPECT_EQ( 1271 layoutProperty->ignoreLayoutSafeAreaOpts_->edges, LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_TOP); 1272 layoutProperty->CheckIgnoreLayoutSafeArea(TextDirection::RTL); 1273 EXPECT_EQ(layoutProperty->ignoreLayoutSafeAreaOpts_->edges, LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_TOP); 1274 1275 layoutProperty->ignoreLayoutSafeAreaOpts_->rawEdges = LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM; 1276 layoutProperty->CheckIgnoreLayoutSafeArea(TextDirection::LTR); 1277 EXPECT_EQ( 1278 layoutProperty->ignoreLayoutSafeAreaOpts_->edges, LAYOUT_SAFE_AREA_EDGE_END | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1279 layoutProperty->CheckIgnoreLayoutSafeArea(TextDirection::RTL); 1280 EXPECT_EQ( 1281 layoutProperty->ignoreLayoutSafeAreaOpts_->edges, LAYOUT_SAFE_AREA_EDGE_START | LAYOUT_SAFE_AREA_EDGE_BOTTOM); 1282 } 1283 1284 /** 1285 * @tc.name: TestIsIgnoreOptsValid 1286 * @tc.desc: Test IsIgnoreOptsValid 1287 * @tc.type: FUNC 1288 */ 1289 HWTEST_F(LayoutPropertyTestNgTwo, TestIsIgnoreOptsValid, TestSize.Level0) 1290 { 1291 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1292 layoutProperty->ignoreLayoutSafeAreaOpts_ = std::make_unique<IgnoreLayoutSafeAreaOpts>(); 1293 EXPECT_EQ(layoutProperty->IsIgnoreOptsValid(), false); 1294 layoutProperty->ignoreLayoutSafeAreaOpts_->type = LAYOUT_SAFE_AREA_TYPE_KEYBOARD; 1295 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_VERTICAL; 1296 EXPECT_EQ(layoutProperty->IsIgnoreOptsValid(), true); 1297 } 1298 1299 /** 1300 * @tc.name: TestIsExpandConstraintNeeded 1301 * @tc.desc: Test IsExpandConstraintNeeded 1302 * @tc.type: FUNC 1303 */ 1304 HWTEST_F(LayoutPropertyTestNgTwo, TestIsExpandConstraintNeeded, TestSize.Level1) 1305 { 1306 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1307 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), false); 1308 layoutProperty->layoutPolicy_ = NG::LayoutPolicyProperty(); 1309 layoutProperty->ignoreLayoutSafeAreaOpts_ = std::make_unique<IgnoreLayoutSafeAreaOpts>(); 1310 layoutProperty->ignoreLayoutSafeAreaOpts_->type = LAYOUT_SAFE_AREA_TYPE_SYSTEM; 1311 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_ALL; 1312 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), false); 1313 1314 layoutProperty->layoutPolicy_->widthLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; 1315 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_VERTICAL; 1316 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), false); 1317 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_HORIZONTAL; 1318 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), true); 1319 1320 layoutProperty->layoutPolicy_->widthLayoutPolicy_ = LayoutCalPolicy::NO_MATCH; 1321 layoutProperty->layoutPolicy_->heightLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; 1322 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), false); 1323 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_VERTICAL; 1324 EXPECT_EQ(layoutProperty->IsExpandConstraintNeeded(), true); 1325 } 1326 1327 /** 1328 * @tc.name: TestMirrorOffset 1329 * @tc.desc: Test PaddingPropertyT MirrorOffset. 1330 * @tc.type: FUNC 1331 */ 1332 HWTEST_F(LayoutPropertyTestNgTwo, TestMirrorOffset, TestSize.Level1) 1333 { 1334 PaddingPropertyF edges = { 1335 .left = 10.0f, 1336 .right = 20.0f, 1337 .top = 30.0f, 1338 .bottom = 40.0f 1339 }; 1340 OffsetF expectedRes(-20.0f, 30.0f); 1341 EXPECT_EQ(edges.MirrorOffset(), expectedRes); 1342 } 1343 1344 /** 1345 * @tc.name: TestGenIgnoreOpts 1346 * @tc.desc: Test GenIgnoreOpts. 1347 * @tc.type: FUNC 1348 */ 1349 HWTEST_F(LayoutPropertyTestNgTwo, TestGenIgnoreOpts, TestSize.Level1) 1350 { 1351 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1352 IgnoreLayoutSafeAreaOpts expectedRes = { 1353 .type = NG::LAYOUT_SAFE_AREA_TYPE_NONE, 1354 .edges = NG::LAYOUT_SAFE_AREA_EDGE_NONE 1355 }; 1356 EXPECT_EQ(layoutProperty->GenIgnoreOpts(), expectedRes); 1357 layoutProperty->ignoreLayoutSafeAreaOpts_ = std::make_unique<IgnoreLayoutSafeAreaOpts>(); 1358 layoutProperty->ignoreLayoutSafeAreaOpts_->type = LAYOUT_SAFE_AREA_TYPE_SYSTEM; 1359 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_ALL; 1360 expectedRes = { 1361 .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM, 1362 .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL 1363 }; 1364 EXPECT_EQ(layoutProperty->GenIgnoreOpts(), expectedRes); 1365 } 1366 1367 /** 1368 * @tc.name: ExpandConstraintWithSafeAreaTest001 1369 * @tc.desc: Test ExpandConstraintWithSafeArea. 1370 * @tc.type: FUNC 1371 */ 1372 HWTEST_F(LayoutPropertyTestNgTwo, ExpandConstraintWithSafeAreaTest001, TestSize.Level1) 1373 { 1374 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1375 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), false); 1376 layoutProperty->SetHost(frameNodeHost); 1377 layoutProperty->ExpandConstraintWithSafeArea(); 1378 1379 layoutProperty->ignoreLayoutSafeAreaOpts_ = std::make_unique<IgnoreLayoutSafeAreaOpts>(); 1380 layoutProperty->ignoreLayoutSafeAreaOpts_->type = LAYOUT_SAFE_AREA_TYPE_SYSTEM; 1381 layoutProperty->ignoreLayoutSafeAreaOpts_->edges = LAYOUT_SAFE_AREA_EDGE_ALL; 1382 layoutProperty->layoutPolicy_->widthLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; 1383 layoutProperty->layoutPolicy_->heightLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; 1384 layoutProperty->ExpandConstraintWithSafeArea(); 1385 1386 frameNodeHost->SetIgnoreLayoutProcess(true); 1387 frameNodeHost->SetRootMeasureNode(true); 1388 frameNodeHost->SetEscapeDelayForIgnore(true); 1389 layoutProperty->ExpandConstraintWithSafeArea(); 1390 1391 auto parent = FrameNode::CreateFrameNode("parent", 0, AceType::MakeRefPtr<Pattern>(), true); 1392 frameNodeHost->MountToParent(parent); 1393 layoutProperty->ExpandConstraintWithSafeArea(); 1394 1395 EXPECT_EQ(frameNodeHost->GetIgnoreLayoutProcess(), true); 1396 } 1397 1398 /** 1399 * @tc.name: TestConvertSafeAreaPadding 1400 * @tc.desc: Test ConvertWithResidueToPaddingPropertyF 1401 * @tc.type: FUNC 1402 */ 1403 HWTEST_F(LayoutPropertyTestNgTwo, TestConvertSafeAreaPadding, TestSize.Level1) 1404 { 1405 std::unique_ptr<PaddingProperty> safeAreaPadding = std::make_unique<PaddingProperty>(); 1406 *safeAreaPadding = { 1407 .left = CalcLength(50, DimensionUnit::VP), 1408 .right = CalcLength(50, DimensionUnit::VP), 1409 .top = CalcLength(50, DimensionUnit::VP), 1410 .bottom = CalcLength(50, DimensionUnit::VP) 1411 }; 1412 ScaleProperty scaleProperty = { 1413 .vpScale = 3.25, 1414 .fpScale = 1.0, 1415 .lpxScale = 1.0 1416 }; 1417 PaddingPropertyF fract = { 1418 .left = 0.4f + 0.4f, 1419 .right = 0.4f + 0.4f, 1420 .top = 0.4f + 0.4f, 1421 .bottom = 0.4f + 0.4f 1422 }; 1423 PaddingPropertyF expectedRes = { 1424 .left = 163.0f, 1425 .right = 163.0f, 1426 .top = 163.0f, 1427 .bottom = 163.0f 1428 }; 1429 auto res = ConvertWithResidueToPaddingPropertyF(safeAreaPadding, scaleProperty, fract); 1430 EXPECT_EQ(res, expectedRes); 1431 } 1432 1433 /** 1434 * @tc.name: UpdateLocalizedAlignment001 1435 * @tc.desc: Test cast to UpdateLocalizedAlignment 1436 * @tc.type: FUNC 1437 */ 1438 HWTEST_F(LayoutPropertyTestNgTwo, UpdateLocalizedAlignment001, TestSize.Level1) 1439 { 1440 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1441 EXPECT_FALSE(layoutProperty->positionProperty_); 1442 layoutProperty->UpdateLocalizedAlignment("top_start"); 1443 auto align = layoutProperty->GetPositionProperty()->GetLocalizedAlignment().value_or("center"); 1444 EXPECT_EQ(align, "top_start"); 1445 1446 layoutProperty->UpdateLocalizedAlignment("bottom_end"); 1447 auto align1 = layoutProperty->GetPositionProperty()->GetLocalizedAlignment().value_or("center"); 1448 EXPECT_EQ(align1, "bottom_end"); 1449 } 1450 1451 /** 1452 * @tc.name: UpdateIsMirrorable001 1453 * @tc.desc: Test cast to UpdateIsMirrorable 1454 * @tc.type: FUNC 1455 */ 1456 HWTEST_F(LayoutPropertyTestNgTwo, UpdateIsMirrorable001, TestSize.Level1) 1457 { 1458 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1459 layoutProperty->UpdateIsMirrorable(true); 1460 auto isMirrorable = layoutProperty->GetPositionProperty()->GetIsMirrorable().value_or(false); 1461 EXPECT_EQ(isMirrorable, true); 1462 1463 layoutProperty->UpdateIsMirrorable(false); 1464 auto isMirrorable1 = layoutProperty->GetPositionProperty()->GetIsMirrorable().value_or(false); 1465 EXPECT_EQ(isMirrorable1, false); 1466 } 1467 1468 /** 1469 * @tc.name: CheckCalcLayoutConstraintTest01 1470 * @tc.desc: Test CheckCalcLayoutConstraint() 1471 * @tc.type: FUNC 1472 */ 1473 HWTEST_F(LayoutPropertyTestNgTwo, CheckCalcLayoutConstraintTest01, TestSize.Level1) 1474 { 1475 /** 1476 * @tc.steps: step1. Create layoutProperty and update calcConstraint 1477 */ 1478 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1479 layoutProperty->layoutConstraint_ = LayoutConstraintF(); 1480 MeasureProperty userConstraint = { 1481 .minSize = CalcSize(CalcLength("calc(10%)"), CalcLength("calc(10%)")), 1482 .maxSize = CalcSize(CalcLength("calc(90%)"), CalcLength("calc(90%)")), 1483 .selfIdealSize = CalcSize(CalcLength("calc(50%)"), CalcLength("calc(50%)")), 1484 }; 1485 layoutProperty->UpdateCalcLayoutProperty(userConstraint); 1486 ASSERT_NE(layoutProperty->calcLayoutConstraint_, nullptr); 1487 LayoutConstraintF parentConstraint = { 1488 .scaleProperty = {.vpScale = 1.0, .fpScale = 1.0, .lpxScale = 1.0}, 1489 .percentReference = { 100, 100 } 1490 }; 1491 layoutProperty->CheckCalcLayoutConstraint(parentConstraint); 1492 /** 1493 * @tc.expected: layoutConstraint_ has correct maxSize, minSize and selfIdealSize. 1494 * calcLayoutConstraint_ has cache for minSize, maxSize and selfIdealSize 1495 */ 1496 EXPECT_EQ(layoutProperty->layoutConstraint_->maxSize, SizeF(90, 90)) 1497 << layoutProperty->layoutConstraint_->maxSize.ToString(); 1498 EXPECT_EQ(layoutProperty->layoutConstraint_->minSize, SizeF(10, 10)) 1499 << layoutProperty->layoutConstraint_->minSize.ToString(); 1500 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize, OptionalSizeF(50, 50)) 1501 << layoutProperty->layoutConstraint_->maxSize.ToString(); 1502 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preMaxSize.has_value()); 1503 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preMinSize.has_value()); 1504 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preMinSize, 1505 CalcSize(CalcLength("calc(10%)"), CalcLength("calc(10%)"))) 1506 << layoutProperty->calcLayoutConstraint_->preMinSize.value().ToString(); 1507 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preMaxSize, 1508 CalcSize(CalcLength("calc(90%)"), CalcLength("calc(90%)"))) 1509 << layoutProperty->calcLayoutConstraint_->preMaxSize.value().ToString(); 1510 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preSelfIdealSize.has_value()); 1511 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preSelfIdealSize, 1512 CalcSize(CalcLength("calc(50%)"), CalcLength("calc(50%)"))) 1513 << layoutProperty->calcLayoutConstraint_->preSelfIdealSize.value().ToString(); 1514 } 1515 1516 /** 1517 * @tc.name: CheckCalcLayoutConstraintTest02 1518 * @tc.desc: Test CheckCalcLayoutConstraint() 1519 * @tc.type: FUNC 1520 */ 1521 HWTEST_F(LayoutPropertyTestNgTwo, CheckCalcLayoutConstraintTest02, TestSize.Level1) 1522 { 1523 /** 1524 * @tc.steps: step1. Create layoutProperty and update calcConstraint 1525 */ 1526 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 1527 layoutProperty->layoutConstraint_ = LayoutConstraintF(); 1528 MeasureProperty userConstraint = { 1529 .minSize = CalcSize(CalcLength("calc(10%)"), CalcLength("calc(10%)")), 1530 .maxSize = CalcSize(CalcLength("calc(90%)"), CalcLength("calc(90%)")), 1531 .selfIdealSize = CalcSize(CalcLength("calc(50%)"), CalcLength("calc(50%)")), 1532 }; 1533 layoutProperty->UpdateCalcLayoutProperty(userConstraint); 1534 ASSERT_NE(layoutProperty->calcLayoutConstraint_, nullptr); 1535 LayoutConstraintF parentConstraint = { 1536 .scaleProperty = {.vpScale = 1.0, .fpScale = 1.0, .lpxScale = 1.0}, 1537 .percentReference = { 100, 100 } 1538 }; 1539 layoutProperty->CheckCalcLayoutConstraint(parentConstraint); 1540 /** 1541 * @tc.steps: step2. layoutProperty update new calcConstraint 1542 */ 1543 userConstraint = { 1544 .minSize = CalcSize(CalcLength("calc(20%)"), CalcLength("calc(20%)")), 1545 .maxSize = CalcSize(CalcLength("calc(80%)"), CalcLength("calc(80%)")), 1546 .selfIdealSize = CalcSize(CalcLength("calc(40%)"), CalcLength("calc(40%)")), 1547 }; 1548 layoutProperty->UpdateCalcLayoutProperty(userConstraint); 1549 layoutProperty->CheckCalcLayoutConstraint(parentConstraint); 1550 /** 1551 * @tc.expected: layoutConstraint_ has correct maxSize, minSize and selfIdealSize. 1552 * calcLayoutConstraint_ has cache for minSize, maxSize and selfIdealSize 1553 */ 1554 EXPECT_EQ(layoutProperty->layoutConstraint_->maxSize, SizeF(80, 80)) 1555 << layoutProperty->layoutConstraint_->maxSize.ToString(); 1556 EXPECT_EQ(layoutProperty->layoutConstraint_->minSize, SizeF(20, 20)) 1557 << layoutProperty->layoutConstraint_->minSize.ToString(); 1558 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize, OptionalSizeF(50, 50)) 1559 << layoutProperty->layoutConstraint_->maxSize.ToString(); 1560 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preMinSize.has_value()); 1561 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preMinSize, 1562 CalcSize(CalcLength("calc(20%)"), CalcLength("calc(20%)"))) 1563 << layoutProperty->calcLayoutConstraint_->preMinSize.value().ToString(); 1564 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preMaxSize.has_value()); 1565 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preMaxSize, 1566 CalcSize(CalcLength("calc(80%)"), CalcLength("calc(80%)"))) 1567 << layoutProperty->calcLayoutConstraint_->preMaxSize.value().ToString(); 1568 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->preSelfIdealSize.has_value()); 1569 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->preSelfIdealSize, 1570 CalcSize(CalcLength("calc(40%)"), CalcLength("calc(40%)"))) 1571 << layoutProperty->calcLayoutConstraint_->preSelfIdealSize.value().ToString(); 1572 } 1573 }