1 /* 2 * Copyright (c) 2023 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 <memory> 17 #include <optional> 18 19 #include "gtest/gtest.h" 20 21 #define protected public 22 #define private public 23 24 #include "test/mock/core/pipeline/mock_pipeline_context.h" 25 26 #include "base/geometry/ng/size_t.h" 27 #include "base/geometry/size.h" 28 #include "base/log/log.h" 29 #include "base/utils/utils.h" 30 #include "core/components_ng/property/measure_property.h" 31 #include "core/components_ng/property/measure_utils.h" 32 33 #undef protected 34 #undef private 35 36 using namespace testing; 37 using namespace testing::ext; 38 39 namespace OHOS::Ace::NG { 40 namespace { 41 constexpr float PERCENT_REFERENCE = 1.0; 42 constexpr float TEST_VALUE = 30.0; 43 constexpr bool USING_MAX_SIZE_TRUE = true; 44 constexpr bool USING_MAX_SIZE_FALSE = false; 45 const Dimension WIDTH { 50.0, DimensionUnit::PX }; 46 const Dimension HEIGHT { 100.0, DimensionUnit::PX }; 47 const Dimension CALC_TEST { 10.0, DimensionUnit::CALC }; 48 const Dimension BORDER_WIDTH_PX { 10.0, DimensionUnit::PX }; 49 const Dimension BORDER_WIDTH_VP { 10.0, DimensionUnit::VP }; 50 const Dimension BORDER_WIDTH_PRECISION { 0.99999, DimensionUnit::PX }; 51 const Dimension BORDER_WIDTH_PRECISION_LOW { 0.00001, DimensionUnit::PX }; 52 const CalcSize TEST_CALC_SIZE { NG::CalcLength(WIDTH), NG::CalcLength(HEIGHT) }; 53 const CalcLength CALC_LENGTH_WIDTH_PX { 20.0, DimensionUnit::PX }; 54 const CalcLength CALC_LENGTH_CALC { 10.0, DimensionUnit::CALC }; 55 const CalcLength PADDING_LENGTH_PX { 10.0, DimensionUnit::PX }; 56 const CalcLength PADDING_LENGTH_VP { 10.0, DimensionUnit::VP }; 57 const SizeF TEST_SIZE { 50.0, 50.0 }; 58 const SizeF TEST_MIN_SIZE { 10.0, 10.0 }; 59 const SizeF TEST_SELF_SIZE = { 1.0, 1.0 }; 60 SizeF TEST_MAX_SIZE { 100.0, 100.0 }; 61 SizeF ADD_SIZE = { 10.0, 10.0 }; 62 SizeF AXIS_SIZE = { 20.0, 10.0 }; 63 SizeF CHILDREN_SIZE = { 10, 20 }; 64 const OffsetF TEST_OFFSET = { 10.0, 20.0 }; 65 OptionalSizeF TEST_OPTIONAL_SIZE = { 10.0, 10.0 }; 66 const PaddingPropertyF TEST_PROPERTY { 10.0, 10.0, 10.0, 10.0 }; 67 PaddingPropertyF PADDING_PROPERTY = { 0, 0, 0, 0 }; 68 PaddingPropertyF TEST_PADDING_PROPERTY = { 0, 0, 0, 0 }; 69 const BorderWidthPropertyF PRECISION_BORDER_WIDTH_PROPERTY { 1.0, 1.0, 1.0, 1.0 }; 70 const BorderWidthPropertyF PRECISION_LOW_BORDER_WIDTH_PROPERTY { 0.0, 0.0, 0.0, 0.0 }; 71 const BorderWidthPropertyF BORDER_WIDTH_PROPERTY { 10.0, 10.0, 10.0, 10.0 }; 72 const Axis AXIS_HORIZONTAL = Axis::HORIZONTAL; 73 const Axis AXIS_VERTICAL = Axis::VERTICAL; 74 const MeasureType MEASURE_TYPE_MATCH_PARENT = MeasureType::MATCH_PARENT; 75 const MeasureType MEASURE_TYPE_MATCH_CONTENT = MeasureType::MATCH_CONTENT; 76 const MeasureType MEASURE_TYPE_CROSS_AXIS = MeasureType::MATCH_PARENT_CROSS_AXIS; 77 const MeasureType MEASURE_TYPE_MAIN_AXIS = MeasureType::MATCH_PARENT_MAIN_AXIS; 78 } // namespace 79 class MeasureUtilsTestNg : public testing::Test { 80 public: SetUpTestSuite()81 static void SetUpTestSuite() 82 { 83 MockPipelineContext::SetUp(); 84 } TearDownTestSuite()85 static void TearDownTestSuite() 86 { 87 MockPipelineContext::TearDown(); 88 } 89 }; 90 91 /** 92 * @tc.name: MeasureUtilsTestNg001 93 * @tc.desc: Test cast to MeasureUtilsTestNg. 94 * @tc.type: FUNC 95 */ 96 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg001, TestSize.Level1) 97 { 98 /** 99 * @tc.steps: step1. create scaleProperty. 100 */ 101 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 102 103 /** 104 * @tc.steps: step2. call ConvertToSize and set input size is TEST_SIZE. 105 * @tc.expected: the return size is the same as TEST_SIZE. 106 */ 107 SizeF retSize = ConvertToSize(TEST_CALC_SIZE, std::move(scaleProperty), TEST_SIZE); 108 EXPECT_EQ(retSize.width_, WIDTH.value_); 109 EXPECT_EQ(retSize.height_, HEIGHT.value_); 110 } 111 112 /** 113 * @tc.name: MeasureUtilsTestNg002 114 * @tc.desc: Test cast to MeasureUtilsTestNg. 115 * @tc.type: FUNC 116 */ 117 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg002, TestSize.Level1) 118 { 119 /** 120 * @tc.steps: step1. create scaleProperty. 121 */ 122 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 123 124 /** 125 * @tc.steps: step2. call ConvertToOptionalSize and set input size is TEST_SIZE. 126 * @tc.expected: the return size is the same as TEST_SIZE. 127 */ 128 OptionalSizeF retSize = ConvertToOptionalSize(TEST_CALC_SIZE, std::move(scaleProperty), TEST_SIZE); 129 EXPECT_EQ(retSize.width_, WIDTH.value_); 130 EXPECT_EQ(retSize.height_, HEIGHT.value_); 131 } 132 133 /** 134 * @tc.name: MeasureUtilsTestNg003 135 * @tc.desc: Test cast to MeasureUtilsTestNg. 136 * @tc.type: FUNC 137 */ 138 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg003, TestSize.Level1) 139 { 140 /** 141 * @tc.steps: step1. create scaleProperty. 142 */ 143 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 144 145 /** 146 * @tc.steps: step2. call ConvertToPx and set input value is CALC_LENGTH_WIDTH. 147 * @tc.expected: the return size is the same as input value. 148 */ 149 std::optional<float> retSize = ConvertToPx(CALC_LENGTH_WIDTH_PX, std::move(scaleProperty), PERCENT_REFERENCE); 150 EXPECT_EQ(retSize, CALC_LENGTH_WIDTH_PX.dimension_.value_); 151 152 /** 153 * @tc.steps: step3. call ConvertToPx and set input value is CALC_LENGTH_CALC. 154 * @tc.expected: the return value is nullopt. 155 */ 156 retSize = ConvertToPx(CALC_LENGTH_CALC, std::move(scaleProperty), PERCENT_REFERENCE); 157 EXPECT_EQ(retSize, std::nullopt); 158 } 159 160 /** 161 * @tc.name: MeasureUtilsTestNg004 162 * @tc.desc: Test cast to MeasureUtilsTestNg. 163 * @tc.type: FUNC 164 */ 165 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg004, TestSize.Level1) 166 { 167 /** 168 * @tc.steps: step1. create scaleProperty and testCalcSize. 169 */ 170 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 171 std::optional<CalcLength> testCalcSize; 172 173 /** 174 * @tc.steps: step2. call ConvertToPx and set input value is null. 175 * @tc.expected: the return value is nullopt. 176 */ 177 std::optional<float> retSize = ConvertToPx(testCalcSize, std::move(scaleProperty), PERCENT_REFERENCE); 178 EXPECT_EQ(retSize, std::nullopt); 179 180 /** 181 * @tc.steps: step3. call ConvertToPx and set input value is CALC_LENGTH_CALC. 182 * @tc.expected: the return value is nullopt. 183 */ 184 testCalcSize = std::make_optional<CalcLength>(CALC_TEST); 185 retSize = ConvertToPx(testCalcSize, std::move(scaleProperty), PERCENT_REFERENCE); 186 EXPECT_EQ(retSize, std::nullopt); 187 } 188 189 /** 190 * @tc.name: MeasureUtilsTestNg005 191 * @tc.desc: Test cast to MeasureUtilsTestNg. 192 * @tc.type: FUNC 193 */ 194 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg005, TestSize.Level1) 195 { 196 /** 197 * @tc.steps: step1. create scaleProperty. 198 */ 199 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 200 201 /** 202 * @tc.steps: step2. call ConvertToPx and set input value is WIDTH. 203 * @tc.expected: the return value is the same as WIDTH.value_. 204 */ 205 std::optional<float> retSize = ConvertToPx(WIDTH, std::move(scaleProperty), PERCENT_REFERENCE); 206 EXPECT_EQ(retSize, WIDTH.value_); 207 208 /** 209 * @tc.steps: step3. call ConvertToPx and set input value is CALC_TEST. 210 * @tc.expected: the return value is nullopt. 211 */ 212 retSize = ConvertToPx(CALC_TEST, std::move(scaleProperty), PERCENT_REFERENCE); 213 EXPECT_EQ(retSize, std::nullopt); 214 } 215 216 /** 217 * @tc.name: MeasureUtilsTestNg006 218 * @tc.desc: Test cast to MeasureUtilsTestNg. 219 * @tc.type: FUNC 220 */ 221 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg006, TestSize.Level1) 222 { 223 /** 224 * @tc.steps: step1. call ConstrainSize. 225 * @tc.expected: the return value is the same as TEST_SIZE. 226 */ 227 SizeF retSize = ConstrainSize(TEST_SIZE, TEST_MIN_SIZE, TEST_MAX_SIZE); 228 EXPECT_EQ(retSize, TEST_SIZE); 229 230 /** 231 * @tc.steps: step2. call ConstrainSize and set TEST_MIN_SIZE.width_ is 0. 232 * @tc.expected: the return value is the same as TEST_SIZE. 233 */ 234 TEST_MAX_SIZE = { 0, 0 }; 235 236 retSize = ConstrainSize(TEST_SIZE, TEST_MIN_SIZE, TEST_MAX_SIZE); 237 EXPECT_EQ(retSize, TEST_SIZE); 238 } 239 240 /** 241 * @tc.name: MeasureUtilsTestNg007 242 * @tc.desc: Test cast to MeasureUtilsTestNg. 243 * @tc.type: FUNC 244 */ 245 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg007, TestSize.Level1) 246 { 247 /** 248 * @tc.steps: step1. create scaleProperty and testPadding. 249 */ 250 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 251 PaddingProperty testPadding; 252 253 /** 254 * @tc.steps: step2. call ConvertToMarginPropertyF and set input margin is null. 255 */ 256 std::unique_ptr<MarginProperty> testMarginProperty = nullptr; 257 PaddingPropertyF retProperty = 258 ConvertToMarginPropertyF(testMarginProperty, std::move(scaleProperty), PERCENT_REFERENCE); 259 260 /** 261 * @tc.steps: step3. set testMarginProperty is not null. 262 */ 263 testPadding.left = PADDING_LENGTH_PX; 264 testPadding.right = PADDING_LENGTH_PX; 265 testPadding.top = PADDING_LENGTH_PX; 266 testPadding.bottom = PADDING_LENGTH_PX; 267 testMarginProperty = std::make_unique<MarginProperty>(std::move(testPadding)); 268 269 /** 270 * @tc.steps: step4. call ConvertToMarginPropertyF. 271 * @tc.expected: the return value is the same as TEST_PROPERTY. 272 */ 273 retProperty = ConvertToMarginPropertyF(testMarginProperty, std::move(scaleProperty), PERCENT_REFERENCE); 274 EXPECT_EQ(retProperty, TEST_PROPERTY); 275 } 276 277 /** 278 * @tc.name: MeasureUtilsTestNg008 279 * @tc.desc: Test cast to MeasureUtilsTestNg. 280 * @tc.type: FUNC 281 */ 282 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg008, TestSize.Level1) 283 { 284 /** 285 * @tc.steps: step1. create scaleProperty and testPadding. 286 */ 287 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 288 PaddingProperty testPadding; 289 290 /** 291 * @tc.steps: step2. set testMarginProperty is not null. 292 */ 293 testPadding.left = PADDING_LENGTH_PX; 294 testPadding.right = PADDING_LENGTH_PX; 295 testPadding.top = PADDING_LENGTH_PX; 296 testPadding.bottom = PADDING_LENGTH_PX; 297 MarginProperty testMarginProperty = testPadding; 298 299 /** 300 * @tc.steps: step3. call ConvertToMarginPropertyF and set input margin is PaddingProperty. 301 * @tc.expected: the return value is the same as TEST_PROPERTY. 302 */ 303 PaddingPropertyF retProperty = 304 ConvertToMarginPropertyF(testMarginProperty, std::move(scaleProperty), PERCENT_REFERENCE); 305 EXPECT_EQ(retProperty, TEST_PROPERTY); 306 } 307 308 /** 309 * @tc.name: MeasureUtilsTestNg009 310 * @tc.desc: Test cast to MeasureUtilsTestNg. 311 * @tc.type: FUNC 312 */ 313 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg009, TestSize.Level1) 314 { 315 /** 316 * @tc.steps: step1. create scaleProperty and testPadding. 317 */ 318 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 319 PaddingProperty testPadding; 320 321 /** 322 * @tc.steps: step2. call ConvertToBorderWidthPropertyF and set input borderWidth is null. 323 */ 324 std::unique_ptr<BorderWidthProperty> testBorderWidthProperty = nullptr; 325 BorderWidthPropertyF retProperty = 326 ConvertToBorderWidthPropertyF(testBorderWidthProperty, std::move(scaleProperty), PERCENT_REFERENCE); 327 328 /** 329 * @tc.steps: step3. set testBorderWidthProperty is not null. 330 */ 331 BorderWidthPropertyT<Dimension> testPropertyT; 332 333 testPropertyT.leftDimen = BORDER_WIDTH_PX; 334 testPropertyT.rightDimen = BORDER_WIDTH_PX; 335 testPropertyT.topDimen = BORDER_WIDTH_PX; 336 testPropertyT.bottomDimen = BORDER_WIDTH_PX; 337 338 testBorderWidthProperty = std::make_unique<BorderWidthProperty>(std::move(testPropertyT)); 339 340 /** 341 * @tc.steps: step4. call ConvertToMarginPropertyF. 342 * @tc.expected: the return value is the same as BORDER_WIDTH_PROPERTY. 343 */ 344 retProperty = ConvertToBorderWidthPropertyF(testBorderWidthProperty, std::move(scaleProperty), PERCENT_REFERENCE); 345 EXPECT_EQ(retProperty, BORDER_WIDTH_PROPERTY); 346 } 347 348 /** 349 * @tc.name: MeasureUtilsTestNg010 350 * @tc.desc: Test cast to MeasureUtilsTestNg. 351 * @tc.type: FUNC 352 */ 353 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg010, TestSize.Level1) 354 { 355 /** 356 * @tc.steps: step1. create scaleProperty and testPadding. 357 */ 358 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 359 PaddingProperty testPadding; 360 361 /** 362 * @tc.steps: step2. call ConvertToBorderWidthPropertyF and set borderWidth Dimension is null. 363 * @tc.expected: the return value is std::nullopt. 364 */ 365 BorderWidthPropertyT<Dimension> testPropertyT; 366 367 std::unique_ptr<BorderWidthProperty> testBorderWidthProperty = 368 std::make_unique<BorderWidthProperty>(std::move(testPropertyT)); 369 BorderWidthPropertyF retProperty = 370 ConvertToBorderWidthPropertyF(testBorderWidthProperty, std::move(scaleProperty), PERCENT_REFERENCE); 371 EXPECT_EQ(retProperty.leftDimen, std::nullopt); 372 373 /** 374 * @tc.steps: step3. set testPropertyT DimensionUnit is VP. 375 */ 376 testPropertyT.leftDimen = BORDER_WIDTH_VP; 377 testPropertyT.rightDimen = BORDER_WIDTH_VP; 378 testPropertyT.topDimen = BORDER_WIDTH_VP; 379 testPropertyT.bottomDimen = BORDER_WIDTH_VP; 380 381 testBorderWidthProperty = std::make_unique<BorderWidthProperty>(std::move(testPropertyT)); 382 383 /** 384 * @tc.steps: step4. call ConvertToBorderWidthPropertyF. 385 * @tc.expected: the return value is the same as BORDER_WIDTH_PROPERTY. 386 */ 387 retProperty = ConvertToBorderWidthPropertyF(testBorderWidthProperty, std::move(scaleProperty), PERCENT_REFERENCE); 388 EXPECT_EQ(retProperty, BORDER_WIDTH_PROPERTY); 389 390 /** 391 * @tc.steps: step5. set testPropertyT.leftDimen is CALC_TEST and call ConvertToBorderWidthPropertyF. 392 * @tc.expected: retProperty.leftDimen is std::nullopt. 393 */ 394 testPropertyT.leftDimen = CALC_TEST; 395 testBorderWidthProperty = std::make_unique<BorderWidthProperty>(std::move(testPropertyT)); 396 retProperty = ConvertToBorderWidthPropertyF(testBorderWidthProperty, std::move(scaleProperty), PERCENT_REFERENCE); 397 EXPECT_EQ(retProperty.leftDimen, std::nullopt); 398 } 399 400 /** 401 * @tc.name: MeasureUtilsTestNg011 402 * @tc.desc: Test cast to MeasureUtilsTestNg. 403 * @tc.type: FUNC 404 */ 405 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg011, TestSize.Level1) 406 { 407 /** 408 * @tc.steps: step1. create scaleProperty and testPadding. 409 */ 410 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 411 PaddingProperty testPadding; 412 413 /** 414 * @tc.steps: step2. call UpdatePaddingPropertyF and set input Padding is null. 415 * @tc.expected: testPaddingPropertyF is not update. 416 */ 417 UpdatePaddingPropertyF(testPadding, std::move(scaleProperty), TEST_SELF_SIZE, PADDING_PROPERTY); 418 EXPECT_EQ(PADDING_PROPERTY, TEST_PADDING_PROPERTY); 419 420 /** 421 * @tc.steps: step3. set testPadding.left is PADDING_LENGTH_PX. 422 */ 423 testPadding.left = PADDING_LENGTH_PX; 424 testPadding.right = PADDING_LENGTH_PX; 425 testPadding.top = PADDING_LENGTH_PX; 426 testPadding.bottom = PADDING_LENGTH_PX; 427 TEST_PADDING_PROPERTY = { 10.0, 10.0, 10.0, 10.0 }; 428 429 /** 430 * @tc.steps: step2. call UpdatePaddingPropertyF and set input Padding is not null. 431 * @tc.expected: step2. testPaddingPropertyF is update and it value is the same as testPadding. 432 */ 433 UpdatePaddingPropertyF(testPadding, std::move(scaleProperty), TEST_SELF_SIZE, PADDING_PROPERTY); 434 EXPECT_EQ(PADDING_PROPERTY, TEST_PADDING_PROPERTY); 435 } 436 437 /** 438 * @tc.name: MeasureUtilsTestNg012 439 * @tc.desc: Test cast to MeasureUtilsTestNg. 440 * @tc.type: FUNC 441 */ 442 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg012, TestSize.Level1) 443 { 444 /** 445 * @tc.steps: step1. create scaleProperty and testPadding. 446 */ 447 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 448 PaddingProperty testPadding; 449 PADDING_PROPERTY = { 0, 0, 0, 0 }; 450 TEST_PADDING_PROPERTY = { 10.0, 10.0, 10.0, 10.0 }; 451 452 /** 453 * @tc.steps: step2. set testPadding.left is PADDING_LENGTH_VP. 454 */ 455 testPadding.left = PADDING_LENGTH_VP; 456 testPadding.right = PADDING_LENGTH_VP; 457 testPadding.top = PADDING_LENGTH_VP; 458 testPadding.bottom = PADDING_LENGTH_VP; 459 460 /** 461 * @tc.steps: step3. call UpdatePaddingPropertyF and set input Padding DimensionUnit is VP. 462 * @tc.expected: testPaddingPropertyF is not update. 463 */ 464 UpdatePaddingPropertyF(testPadding, std::move(scaleProperty), TEST_SELF_SIZE, PADDING_PROPERTY); 465 EXPECT_EQ(PADDING_PROPERTY, TEST_PADDING_PROPERTY); 466 } 467 468 /** 469 * @tc.name: MeasureUtilsTestNg013 470 * @tc.desc: Test cast to MeasureUtilsTestNg. 471 * @tc.type: FUNC 472 */ 473 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg013, TestSize.Level1) 474 { 475 /** 476 * @tc.steps: step1. call AddPaddingToSize and set input Padding is zero. 477 * @tc.expected: the testSize is not changed. 478 */ 479 PADDING_PROPERTY = { 0, 0, 0, 0 }; 480 481 AddPaddingToSize(PADDING_PROPERTY, ADD_SIZE); 482 EXPECT_EQ(ADD_SIZE.width_, 10.0); 483 EXPECT_EQ(ADD_SIZE.height_, 10.0); 484 485 /** 486 * @tc.steps: step2. call AddPaddingToSize and set input Padding is not zero. 487 * @tc.expected: the testSize is changed into expected values. 488 */ 489 PADDING_PROPERTY = { 10.0, 20.0, 30.0, 40.0 }; 490 491 AddPaddingToSize(PADDING_PROPERTY, ADD_SIZE); 492 EXPECT_EQ(ADD_SIZE.width_, 40.0); 493 EXPECT_EQ(ADD_SIZE.height_, 80.0); 494 } 495 496 /** 497 * @tc.name: MeasureUtilsTestNg014 498 * @tc.desc: Test cast to MeasureUtilsTestNg. 499 * @tc.type: FUNC 500 */ 501 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg014, TestSize.Level1) 502 { 503 /** 504 * @tc.steps: step1. call MinusPaddingToSize and set input Padding is zero. 505 * @tc.expected: the testSize is not changed. 506 */ 507 PADDING_PROPERTY = { 0, 0, 0, 0 }; 508 ADD_SIZE = { 100.0, 100.0 }; 509 510 MinusPaddingToSize(PADDING_PROPERTY, ADD_SIZE); 511 EXPECT_EQ(ADD_SIZE.width_, 100.0); 512 EXPECT_EQ(ADD_SIZE.height_, 100.0); 513 514 /** 515 * @tc.steps: step2. call MinusPaddingToSize and set input Padding is not zero. 516 * @tc.expected: the testSize is changed into expected values. 517 */ 518 PADDING_PROPERTY = { 10.0, 20.0, 30.0, 40.0 }; 519 520 MinusPaddingToSize(PADDING_PROPERTY, ADD_SIZE); 521 EXPECT_EQ(ADD_SIZE.width_, 70.0); 522 EXPECT_EQ(ADD_SIZE.height_, 30.0); 523 } 524 525 /** 526 * @tc.name: MeasureUtilsTestNg015 527 * @tc.desc: Test cast to MeasureUtilsTestNg. 528 * @tc.type: FUNC 529 */ 530 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg015, TestSize.Level1) 531 { 532 /** 533 * @tc.steps: step1. call AddPaddingToSize and set input Padding is zero. 534 * @tc.expected: the testOptionalSize is not changed. 535 */ 536 PADDING_PROPERTY = { 0, 0, 0, 0 }; 537 538 AddPaddingToSize(PADDING_PROPERTY, TEST_OPTIONAL_SIZE); 539 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 10.0); 540 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 10.0); 541 542 /** 543 * @tc.steps: step2. call AddPaddingToSize and set input Padding is not zero. 544 * @tc.expected: the testOptionalSize is changed into expected values. 545 */ 546 PADDING_PROPERTY = { 40.0, 30.0, 20.0, 10.0 }; 547 548 AddPaddingToSize(PADDING_PROPERTY, TEST_OPTIONAL_SIZE); 549 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 80.0); 550 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 40.0); 551 } 552 553 /** 554 * @tc.name: MeasureUtilsTestNg016 555 * @tc.desc: Test cast to MeasureUtilsTestNg. 556 * @tc.type: FUNC 557 */ 558 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg016, TestSize.Level1) 559 { 560 /** 561 * @tc.steps: step1. call MinusPaddingToSize and set input Padding is zero. 562 * @tc.expected: the testOptionalSize is not changed. 563 */ 564 PADDING_PROPERTY = { 0, 0, 0, 0 }; 565 TEST_OPTIONAL_SIZE = { 100.0, 100.0 }; 566 567 MinusPaddingToSize(PADDING_PROPERTY, TEST_OPTIONAL_SIZE); 568 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 100.0); 569 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 100.0); 570 571 /** 572 * @tc.steps: step2. call MinusPaddingToSize and set input Padding is not zero. 573 * @tc.expected: the testOptionalSize is changed into expected values. 574 */ 575 PADDING_PROPERTY = { 40.0, 30.0, 20.0, 10.0 }; 576 577 MinusPaddingToSize(PADDING_PROPERTY, TEST_OPTIONAL_SIZE); 578 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 30.0); 579 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 70.0); 580 } 581 582 /** 583 * @tc.name: MeasureUtilsTestNg017 584 * @tc.desc: Test cast to MeasureUtilsTestNg. 585 * @tc.type: FUNC 586 */ 587 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg017, TestSize.Level1) 588 { 589 /** 590 * @tc.steps: step1. call GetMainAxisOffset and set input Axis is HORIZONTAL. 591 * @tc.expected: the return value is equal to TEST_OFFSET.x_. 592 */ 593 float retMainOffset = GetMainAxisOffset(TEST_OFFSET, AXIS_HORIZONTAL); 594 EXPECT_EQ(retMainOffset, TEST_OFFSET.x_); 595 596 /** 597 * @tc.steps: step2. call GetMainAxisOffset and set input Axis is HORIZONTAL. 598 * @tc.expected: the return value is equal to TEST_OFFSET.y_. 599 */ 600 retMainOffset = GetMainAxisOffset(TEST_OFFSET, AXIS_VERTICAL); 601 EXPECT_EQ(retMainOffset, TEST_OFFSET.y_); 602 } 603 604 /** 605 * @tc.name: MeasureUtilsTestNg018 606 * @tc.desc: Test cast to MeasureUtilsTestNg. 607 * @tc.type: FUNC 608 */ 609 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg018, TestSize.Level1) 610 { 611 /** 612 * @tc.steps: step1. call GetMainAxisSize and set input Axis is AXIS_HORIZONTAL. 613 * @tc.expected: the return value is equal to AXIS_SIZE.Width. 614 */ 615 float retMainSize = GetMainAxisSize(AXIS_SIZE, AXIS_HORIZONTAL); 616 EXPECT_EQ(retMainSize, AXIS_SIZE.width_); 617 618 /** 619 * @tc.steps: step2. call GetMainAxisSize and set input Axis is AXIS_VERTICAL. 620 * @tc.expected: the return value is equal to AXIS_SIZE.Height. 621 */ 622 retMainSize = GetMainAxisSize(AXIS_SIZE, AXIS_VERTICAL); 623 EXPECT_EQ(retMainSize, AXIS_SIZE.height_); 624 } 625 626 /** 627 * @tc.name: MeasureUtilsTestNg019 628 * @tc.desc: Test cast to MeasureUtilsTestNg. 629 * @tc.type: FUNC 630 */ 631 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg019, TestSize.Level1) 632 { 633 /** 634 * @tc.steps: step1. call GetCrossAxisSize and set input Axis is AXIS_HORIZONTAL. 635 * @tc.expected: the return value is equal to AXIS_SIZE.Height. 636 */ 637 float retCrossSize = GetCrossAxisSize(AXIS_SIZE, AXIS_HORIZONTAL); 638 EXPECT_EQ(retCrossSize, AXIS_SIZE.height_); 639 640 /** 641 * @tc.steps: step2. call GetCrossAxisSize and set input Axis is AXIS_VERTICAL. 642 * @tc.expected: the return value is equal to AXIS_SIZE.Width. 643 */ 644 retCrossSize = GetCrossAxisSize(AXIS_SIZE, AXIS_VERTICAL); 645 EXPECT_EQ(retCrossSize, AXIS_SIZE.width_); 646 } 647 648 /** 649 * @tc.name: MeasureUtilsTestNg020 650 * @tc.desc: Test cast to MeasureUtilsTestNg. 651 * @tc.type: FUNC 652 */ 653 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg020, TestSize.Level1) 654 { 655 /** 656 * @tc.steps: step1. call SetCrossAxisSize and set input Axis is AXIS_HORIZONTAL. 657 * @tc.expected: AXIS_SIZE.height_ is set to the TEST_VALUE. 658 */ 659 SetCrossAxisSize(TEST_VALUE, AXIS_HORIZONTAL, AXIS_SIZE); 660 EXPECT_EQ(AXIS_SIZE.height_, TEST_VALUE); 661 662 /** 663 * @tc.steps: step2. call SetCrossAxisSize and set input Axis is AXIS_VERTICAL. 664 * @tc.expected: AXIS_SIZE.width_ is set to the TEST_VALUE. 665 */ 666 AXIS_SIZE = { 10.0, 20.0 }; 667 668 SetCrossAxisSize(TEST_VALUE, AXIS_VERTICAL, AXIS_SIZE); 669 EXPECT_EQ(AXIS_SIZE.width_, TEST_VALUE); 670 } 671 672 /** 673 * @tc.name: MeasureUtilsTestNg021 674 * @tc.desc: Test cast to MeasureUtilsTestNg. 675 * @tc.type: FUNC 676 */ 677 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg021, TestSize.Level1) 678 { 679 /** 680 * @tc.steps: step1. call SetCrossAxisSize and set input Axis is AXIS_HORIZONTAL. 681 * @tc.expected: TEST_OPTIONAL_SIZE.width_ is set to the TEST_VALUE. 682 */ 683 TEST_OPTIONAL_SIZE = { 10.0, 20.0 }; 684 685 SetMainAxisSize(TEST_VALUE, AXIS_HORIZONTAL, TEST_OPTIONAL_SIZE); 686 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 20.0); 687 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 30.0); 688 689 /** 690 * @tc.steps: step2. call SetCrossAxisSize and set input Axis is VERTICAL. 691 * @tc.expected: TEST_OPTIONAL_SIZE.height_ is set to the TEST_VALUE. 692 */ 693 TEST_OPTIONAL_SIZE = { 10.0, 20.0 }; 694 695 SetMainAxisSize(TEST_VALUE, AXIS_VERTICAL, TEST_OPTIONAL_SIZE); 696 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 30.0); 697 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 10.0); 698 } 699 700 /** 701 * @tc.name: MeasureUtilsTestNg022 702 * @tc.desc: Test cast to MeasureUtilsTestNg. 703 * @tc.type: FUNC 704 */ 705 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg022, TestSize.Level1) 706 { 707 /** 708 * @tc.steps: step1. call GetMainAxisSize and set input Axis is AXIS_HORIZONTAL. 709 * @tc.expected: the return value is equal to TEST_OPTIONAL_SIZE.width_. 710 */ 711 TEST_OPTIONAL_SIZE = { 10.0, 20.0 }; 712 713 std::optional<float> retMainSize = GetMainAxisSize(TEST_OPTIONAL_SIZE, AXIS_HORIZONTAL); 714 EXPECT_EQ(retMainSize, TEST_OPTIONAL_SIZE.width_); 715 716 /** 717 * @tc.steps: step2. call GetMainAxisSize and set input Axis is AXIS_VERTICAL. 718 * @tc.expected: the return value is equal to TEST_OPTIONAL_SIZE.height_. 719 */ 720 retMainSize = GetMainAxisSize(TEST_OPTIONAL_SIZE, AXIS_VERTICAL); 721 EXPECT_EQ(retMainSize, TEST_OPTIONAL_SIZE.height_); 722 } 723 724 /** 725 * @tc.name: MeasureUtilsTestNg023 726 * @tc.desc: Test cast to MeasureUtilsTestNg. 727 * @tc.type: FUNC 728 */ 729 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg023, TestSize.Level1) 730 { 731 /** 732 * @tc.steps: step1. call GetCrossAxisSize and set input Axis is AXIS_HORIZONTAL. 733 * @tc.expected: the return value is equal to TEST_OPTIONAL_SIZE.height_. 734 */ 735 std::optional<float> retCrossSize = GetCrossAxisSize(TEST_OPTIONAL_SIZE, AXIS_HORIZONTAL); 736 EXPECT_EQ(retCrossSize, TEST_OPTIONAL_SIZE.height_); 737 738 /** 739 * @tc.steps: step2. call GetCrossAxisSize and set input Axis is AXIS_VERTICAL. 740 * @tc.expected: the return value is equal to TEST_OPTIONAL_SIZE.width_. 741 */ 742 retCrossSize = GetCrossAxisSize(TEST_OPTIONAL_SIZE, AXIS_VERTICAL); 743 EXPECT_EQ(retCrossSize, TEST_OPTIONAL_SIZE.width_); 744 } 745 746 /** 747 * @tc.name: MeasureUtilsTestNg024 748 * @tc.desc: Test cast to MeasureUtilsTestNg. 749 * @tc.type: FUNC 750 */ 751 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg024, TestSize.Level1) 752 { 753 /** 754 * @tc.steps: step1. call SetCrossAxisSize and set input Axis is AXIS_HORIZONTAL. 755 * @tc.expected: TEST_OPTIONAL_SIZE.height_ is set to the TEST_VALUE. 756 */ 757 SetCrossAxisSize(TEST_VALUE, AXIS_HORIZONTAL, TEST_OPTIONAL_SIZE); 758 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 30.0); 759 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 10.0); 760 761 /** 762 * @tc.steps: step2. call SetCrossAxisSize and set input Axis is AXIS_VERTICAL. 763 * @tc.expected: TEST_OPTIONAL_SIZE.width_ is set to the TEST_VALUE. 764 */ 765 TEST_OPTIONAL_SIZE = { 10.0, 20.0 }; 766 767 SetCrossAxisSize(TEST_VALUE, AXIS_VERTICAL, TEST_OPTIONAL_SIZE); 768 EXPECT_EQ(TEST_OPTIONAL_SIZE.height_, 20.0); 769 EXPECT_EQ(TEST_OPTIONAL_SIZE.width_, 30.0); 770 } 771 772 /** 773 * @tc.name: MeasureUtilsTestNg025 774 * @tc.desc: Test cast to MeasureUtilsTestNg. 775 * @tc.type: FUNC 776 */ 777 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg025, TestSize.Level1) 778 { 779 /** 780 * @tc.steps: step1. call CreateIdealSize and set input usingMaxSize is USING_MAX_SIZE_TRUE. 781 * @tc.expected: the return retIdealSize is the same as layoutConstraint.maxSize. 782 */ 783 LayoutConstraintF layoutConstraint; 784 785 SizeF retIdealSize = 786 CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MATCH_PARENT, USING_MAX_SIZE_TRUE); 787 EXPECT_EQ(retIdealSize, layoutConstraint.maxSize); 788 789 /** 790 * @tc.steps: step2. call CreateIdealSize and set input usingMaxSize is USING_MAX_SIZE_FALSE. 791 * @tc.expected: the return retIdealSize.width_ and retIdealSize.height_ is not equal 0. 792 */ 793 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_VERTICAL, MEASURE_TYPE_MATCH_PARENT, USING_MAX_SIZE_FALSE); 794 EXPECT_NE(retIdealSize.width_, 0); 795 EXPECT_NE(retIdealSize.height_, 0); 796 } 797 798 /** 799 * @tc.name: MeasureUtilsTestNg026 800 * @tc.desc: Test cast to MeasureUtilsTestNg. 801 * @tc.type: FUNC 802 */ 803 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg026, TestSize.Level1) 804 { 805 /** 806 * @tc.steps: step1. create layoutConstraint. 807 */ 808 LayoutConstraintF layoutConstraint; 809 810 /** 811 * @tc.steps: step1. call CreateIdealSize and set layoutConstraint.maxSize.height_ is 100. 812 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.maxSize.height_. 813 */ 814 layoutConstraint.maxSize = { 100.0, 100.0 }; 815 OptionalSizeF retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_CROSS_AXIS); 816 EXPECT_EQ(retIdealSize.height_, layoutConstraint.maxSize.height_); 817 818 /** 819 * @tc.steps: step2. call CreateIdealSize and set layoutConstraint.parentIdealSize.height_ is 20. 820 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.parentIdealSize.height_. 821 */ 822 layoutConstraint.parentIdealSize = { 10.0, 20.0 }; 823 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_CROSS_AXIS); 824 EXPECT_EQ(retIdealSize.height_, layoutConstraint.parentIdealSize.height_); 825 } 826 827 /** 828 * @tc.name: MeasureUtilsTestNg027 829 * @tc.desc: Test cast to MeasureUtilsTestNg. 830 * @tc.type: FUNC 831 */ 832 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg027, TestSize.Level1) 833 { 834 /** 835 * @tc.steps: step1. create layoutConstraint. 836 */ 837 LayoutConstraintF layoutConstraint; 838 839 /** 840 * @tc.steps: step2. call CreateIdealSize and set layoutConstraint.maxSize.width_ is 100. 841 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.maxSize.width_. 842 */ 843 layoutConstraint.maxSize = { 100.0, 100.0 }; 844 OptionalSizeF retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MAIN_AXIS); 845 EXPECT_EQ(retIdealSize.width_, layoutConstraint.maxSize.width_); 846 847 /** 848 * @tc.steps: step3. call CreateIdealSize and set layoutConstraint.parentIdealSize.width_ is 20. 849 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.parentIdealSize.width_. 850 */ 851 layoutConstraint.parentIdealSize = { 20.0, 10.0 }; 852 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MAIN_AXIS); 853 EXPECT_EQ(retIdealSize.width_, layoutConstraint.parentIdealSize.width_); 854 855 /** 856 * @tc.steps: step4. call CreateIdealSize and set testMeasureType is MEASURE_TYPE_MATCH_CONTENT. 857 * @tc.expected: the return retIdealSize is the same as testOptionalSize. 858 */ 859 OptionalSizeF testOptionalSize; 860 861 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MATCH_CONTENT); 862 EXPECT_EQ(retIdealSize, testOptionalSize); 863 864 /** 865 * @tc.steps: step5. call CreateIdealSize and set layoutConstraint.selfIdealSize.width_ is 20. 866 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.selfIdealSize.width_ and return is 867 * Valid. 868 */ 869 layoutConstraint.selfIdealSize = { 20.0, 10.0 }; 870 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MAIN_AXIS); 871 EXPECT_EQ(retIdealSize.width_, layoutConstraint.selfIdealSize.width_); 872 EXPECT_TRUE(retIdealSize.IsValid()); 873 874 /** 875 * @tc.steps: step6. call CreateIdealSize and set layoutConstraint.selfIdealSize.width_ is 20 and measure type = 876 * MEASURE_TYPE_CROSS_AXIS.. 877 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.selfIdealSize.width_ 878 */ 879 layoutConstraint.selfIdealSize.Reset(); 880 layoutConstraint.selfIdealSize.SetHeight(20.0); 881 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_CROSS_AXIS); 882 EXPECT_EQ(retIdealSize.height_, layoutConstraint.selfIdealSize.height_); 883 884 /** 885 * @tc.steps: step7. call CreateIdealSize and set layoutConstraint.selfIdealSize.width_ is 20 and measure type = 886 * MEASURE_TYPE_MAIN_AXIS. 887 * @tc.expected: the return retIdealSize.height_ is the same as layoutConstraint.selfIdealSize.width_ 888 */ 889 layoutConstraint.selfIdealSize.Reset(); 890 layoutConstraint.selfIdealSize.SetWidth(20.0); 891 retIdealSize = CreateIdealSize(layoutConstraint, AXIS_HORIZONTAL, MEASURE_TYPE_MAIN_AXIS); 892 EXPECT_EQ(retIdealSize.width_, layoutConstraint.selfIdealSize.width_); 893 } 894 895 /** 896 * @tc.name: MeasureUtilsTestNg028 897 * @tc.desc: Test cast to MeasureUtilsTestNg. 898 * @tc.type: FUNC 899 */ 900 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg028, TestSize.Level1) 901 { 902 /** 903 * @tc.steps: step1. create testPadding. 904 */ 905 PaddingPropertyF testPadding; 906 907 /** 908 * @tc.steps: step2. call CreateChildrenConstraint and set testPadding to have no value. 909 * @tc.expected: the input CHILDREN_SIZE is not changed. 910 */ 911 CreateChildrenConstraint(CHILDREN_SIZE, testPadding); 912 EXPECT_EQ(CHILDREN_SIZE.width_, 10.0); 913 EXPECT_EQ(CHILDREN_SIZE.height_, 20.0); 914 915 /** 916 * @tc.steps: step3. call CreateChildrenConstraint and set testPadding to have no value. 917 * @tc.expected: step1. the input CHILDREN_SIZE is changed to the expected value. 918 */ 919 testPadding = TEST_PROPERTY; 920 921 CreateChildrenConstraint(CHILDREN_SIZE, testPadding); 922 EXPECT_EQ(CHILDREN_SIZE.width_, -10.0); 923 EXPECT_EQ(CHILDREN_SIZE.height_, 0); 924 } 925 926 /** 927 * @tc.name: MeasureUtilsTestNg029 928 * @tc.desc: Test cast to MeasureUtilsTestNg. 929 * @tc.type: FUNC 930 */ 931 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg029, TestSize.Level1) 932 { 933 /** 934 * @tc.steps: step1. create testPadding. 935 */ 936 PaddingProperty testPadding; 937 std::optional<CalcDimension> top, bottom, left, right; 938 939 /** 940 * @tc.steps: step2. call ConvertToCalcPaddingProperty and set testPadding to have no value. 941 * @tc.expected: the input CHILDREN_SIZE is not changed. 942 */ 943 PaddingProperty res = ConvertToCalcPaddingProperty(top, bottom, left, right); 944 EXPECT_EQ(testPadding, res); 945 946 /** 947 * @tc.steps: step3. call ConvertToCalcPaddingProperty and set testPadding to have CalcValue. 948 * @tc.expected: step1. the input CHILDREN_SIZE is changed to the expected value. 949 */ 950 top = CALC_TEST; 951 bottom = CALC_TEST; 952 left = CALC_TEST; 953 right = CALC_TEST; 954 testPadding.top = NG::CalcLength(top.value().CalcValue()); 955 testPadding.bottom = NG::CalcLength(bottom.value().CalcValue()); 956 testPadding.left = NG::CalcLength(left.value().CalcValue()); 957 testPadding.right = NG::CalcLength(right.value().CalcValue()); 958 res = ConvertToCalcPaddingProperty(top, bottom, left, right); 959 EXPECT_EQ(testPadding, res); 960 961 /** 962 * @tc.steps: step4. call ConvertToCalcPaddingProperty and set testPadding to have value. 963 * @tc.expected: step1. the input CHILDREN_SIZE is changed to the expected value. 964 */ 965 top = BORDER_WIDTH_PX; 966 bottom = BORDER_WIDTH_PX; 967 left = BORDER_WIDTH_PX; 968 right = BORDER_WIDTH_PX; 969 testPadding.top = NG::CalcLength(top.value()); 970 testPadding.bottom = NG::CalcLength(bottom.value()); 971 testPadding.left = NG::CalcLength(left.value()); 972 testPadding.right = NG::CalcLength(right.value()); 973 res = ConvertToCalcPaddingProperty(top, bottom, left, right); 974 EXPECT_EQ(testPadding, res); 975 } 976 977 /** 978 * @tc.name: MeasureUtilsTestNg030 979 * @tc.desc: Test cast to MeasureUtilsTestNg. 980 * @tc.type: FUNC 981 */ 982 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg030, TestSize.Level1) 983 { 984 /** 985 * @tc.steps: step1. create testPadding and sizeF. 986 */ 987 PaddingPropertyF testPadding; 988 testPadding.left = 1.0f; 989 testPadding.right = 2.0f; 990 testPadding.top = 3.0f; 991 testPadding.bottom = 4.0f; 992 993 SizeF temp_size { 50.0, 50.0 }; 994 995 /** 996 * @tc.steps: step2. call MinusPaddingToNonNegativeSize. 997 * @expected: excute succuss. 998 */ 999 MinusPaddingToNonNegativeSize(testPadding, temp_size); 1000 EXPECT_EQ(temp_size.width_, 47); 1001 EXPECT_EQ(temp_size.height_, 43); 1002 } 1003 1004 /** 1005 * @tc.name: MeasureUtilsTestNg031 1006 * @tc.desc: Test cast to MeasureUtilsTestNg. 1007 * @tc.type: FUNC 1008 */ 1009 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg031, TestSize.Level1) 1010 { 1011 /** 1012 * @tc.steps: step1. create OptionalSizeF,MeasureProperty and SizeF. 1013 */ 1014 OptionalSizeF frameSize = { 10.0, 10.0 }; 1015 std::unique_ptr<MeasureProperty> calcLayoutConstraint = std::make_unique<MeasureProperty>(); 1016 SizeF percentReference = { 20, 20 }; 1017 1018 /** 1019 * @tc.steps: step2. call UpdateOptionSizeByCalcLayoutConstraint with out MeasureProperty. 1020 * @expected: frameResult is equal with frameSize. 1021 */ 1022 OptionalSizeF frameResult = UpdateOptionSizeByCalcLayoutConstraint(frameSize, nullptr, percentReference); 1023 EXPECT_EQ(frameResult.Height(), 10); 1024 EXPECT_EQ(frameResult.Width(), 10); 1025 1026 /** 1027 * @tc.steps: step3. call UpdateOptionSizeByCalcLayoutConstraint with MeasureProperty 1028 * without calcLayoutConstraintMaxMinSize. 1029 * @expected: update fail 1030 */ 1031 frameResult = UpdateOptionSizeByCalcLayoutConstraint(frameSize, calcLayoutConstraint, percentReference); 1032 EXPECT_EQ(frameResult.Height(), 10); 1033 EXPECT_EQ(frameResult.Width(), 10); 1034 1035 /** 1036 * @tc.steps: step4. call UpdateOptionSizeByCalcLayoutConstraint with MeasureProperty without maxSize. 1037 * @expected: update fail 1038 */ 1039 calcLayoutConstraint->maxSize = std::make_optional<CalcSize>(); 1040 calcLayoutConstraint->maxSize->width_.reset(); 1041 calcLayoutConstraint->maxSize->height_.reset(); 1042 frameResult = UpdateOptionSizeByCalcLayoutConstraint(frameSize, calcLayoutConstraint, percentReference); 1043 EXPECT_EQ(frameResult.Height(), 10); 1044 EXPECT_EQ(frameResult.Width(), 10); 1045 1046 /** 1047 * @tc.steps: step5. call UpdateOptionSizeByCalcLayoutConstraint with MeasureProperty 1048 * and with calcLayoutConstraintMaxMinSize. 1049 * @expected: update seccuess 1050 */ 1051 calcLayoutConstraint->maxSize = std::make_optional<CalcSize>(CalcLength(50.0), CalcLength(100.0)); 1052 calcLayoutConstraint->minSize = std::make_optional<CalcSize>(CalcLength(15), CalcLength(15)); 1053 frameResult = UpdateOptionSizeByCalcLayoutConstraint(frameSize, calcLayoutConstraint, percentReference); 1054 EXPECT_EQ(frameResult.Height(), 15); 1055 EXPECT_EQ(frameResult.Width(), 15); 1056 } 1057 1058 /** 1059 * @tc.name: MeasureUtilsTestNg032 1060 * @tc.desc: Test cast to MeasureUtilsTestNg. 1061 * @tc.type: FUNC 1062 */ 1063 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg032, TestSize.Level1) 1064 { 1065 /** 1066 * @tc.steps: step1. create OptionalSizeF and axis. 1067 */ 1068 LayoutConstraintF layoutConstraint; 1069 Axis axis = Axis::HORIZONTAL; 1070 1071 layoutConstraint.selfIdealSize = { 10.0, 10.0 }; 1072 layoutConstraint.parentIdealSize = { 10.0, 30.0 }; 1073 layoutConstraint.percentReference = { 20.0, 20.0 }; 1074 layoutConstraint.maxSize = { Infinity<float>(), Infinity<float>() }; 1075 layoutConstraint.minSize = { 0, 0 }; 1076 1077 /** 1078 * @tc.steps: step2. call CreateIdealSizeByPercentRef with selfIdealSize Valid. 1079 * @expected: result is equal with selfIdealSize 1080 */ 1081 OptionalSizeF optionResult = CreateIdealSizeByPercentRef(layoutConstraint, axis, MEASURE_TYPE_MATCH_PARENT, true); 1082 EXPECT_EQ(optionResult.Height(), 10.0); 1083 EXPECT_EQ(optionResult.Width(), 10.0); 1084 1085 /** 1086 * @tc.steps: step3. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1087 * and Measure is MEASURE_TYPE_MATCH_PARENT. 1088 */ 1089 layoutConstraint.selfIdealSize.Reset(); 1090 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, axis, MEASURE_TYPE_MATCH_PARENT, true); 1091 EXPECT_EQ(optionResult.Height(), 30.0); 1092 EXPECT_EQ(optionResult.Width(), 10.0); 1093 1094 /** 1095 * @tc.steps: step4. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1096 * and Measure is MEASURE_TYPE_CROSS_AXIS. 1097 * @expected: height set success. 1098 */ 1099 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, axis, MEASURE_TYPE_CROSS_AXIS, true); 1100 EXPECT_EQ(optionResult.Height(), 30.0); 1101 EXPECT_EQ(optionResult.Width(), std::nullopt); 1102 1103 /** 1104 * @tc.steps: step5. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1105 * and Measure is MEASURE_TYPE_CROSS_AXIS. 1106 */ 1107 layoutConstraint.parentIdealSize.Reset(); 1108 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, axis, MEASURE_TYPE_CROSS_AXIS, true); 1109 EXPECT_EQ(optionResult.Height(), 20.0); 1110 EXPECT_EQ(optionResult.Width(), std::nullopt); 1111 1112 /** 1113 * @tc.steps: step6. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1114 * and Measure is MEASURE_TYPE_MAIN_AXIS. 1115 */ 1116 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, Axis::VERTICAL, MEASURE_TYPE_MAIN_AXIS, true); 1117 EXPECT_EQ(optionResult.Height(), 20); 1118 EXPECT_EQ(optionResult.Width(), std::nullopt); 1119 1120 /** 1121 * @tc.steps: step7. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1122 * and Measure is MEASURE_TYPE_MAIN_AXIS. 1123 */ 1124 layoutConstraint.parentIdealSize = { 10.0, 30.0 }; 1125 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, Axis::HORIZONTAL, MEASURE_TYPE_MAIN_AXIS, true); 1126 EXPECT_EQ(optionResult.Height(), std::nullopt); 1127 EXPECT_EQ(optionResult.Width(), 10.0); 1128 1129 /** 1130 * @tc.steps: step8. call CreateIdealSizeByPercentRef withOut selfIdealSize Valid 1131 * and Measure is MEASURE_TYPE_MATCH_CONTENT. 1132 */ 1133 optionResult = CreateIdealSizeByPercentRef(layoutConstraint, axis, MEASURE_TYPE_MATCH_CONTENT, false); 1134 EXPECT_EQ(optionResult.Height(), std::nullopt); 1135 EXPECT_EQ(optionResult.Width(), std::nullopt); 1136 } 1137 1138 /** 1139 * @tc.name: MeasureUtilsTestNg033 1140 * @tc.desc: Test cast to MeasureUtilsTestNg. 1141 * @tc.type: FUNC 1142 */ 1143 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg033, TestSize.Level1) 1144 { 1145 /** 1146 * @tc.steps: step1. create scaleProperty and set testPropertyT DimensionUnit is PRECISION. 1147 */ 1148 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 1149 BorderWidthPropertyT<Dimension> testPropertyT; 1150 1151 testPropertyT.leftDimen = BORDER_WIDTH_PRECISION; 1152 testPropertyT.rightDimen = BORDER_WIDTH_PRECISION; 1153 testPropertyT.topDimen = BORDER_WIDTH_PRECISION; 1154 testPropertyT.bottomDimen = BORDER_WIDTH_PRECISION; 1155 1156 /** 1157 * @tc.steps: step2. call ConvertToBorderWidthPropertyF. 1158 * @tc.expected: the return value is the same as PRECISION_BORDER_WIDTH_PROPERTY. 1159 */ 1160 BorderWidthPropertyF retProperty = ConvertToBorderWidthPropertyF(testPropertyT, scaleProperty, PERCENT_REFERENCE); 1161 EXPECT_EQ(retProperty, PRECISION_BORDER_WIDTH_PROPERTY); 1162 } 1163 1164 /** 1165 * @tc.name: MeasureUtilsTestNg034 1166 * @tc.desc: Test cast to MeasureUtilsTestNg. 1167 * @tc.type: FUNC 1168 */ 1169 HWTEST_F(MeasureUtilsTestNg, MeasureUtilsTestNg034, TestSize.Level1) 1170 { 1171 /** 1172 * @tc.steps: step1. create scaleProperty and set testPropertyT DimensionUnit is PRECISION. 1173 */ 1174 ScaleProperty scaleProperty = ScaleProperty::CreateScaleProperty(); 1175 BorderWidthPropertyT<Dimension> testPropertyT; 1176 1177 testPropertyT.leftDimen = BORDER_WIDTH_PRECISION_LOW; 1178 testPropertyT.rightDimen = BORDER_WIDTH_PRECISION_LOW; 1179 testPropertyT.topDimen = BORDER_WIDTH_PRECISION_LOW; 1180 testPropertyT.bottomDimen = BORDER_WIDTH_PRECISION_LOW; 1181 1182 /** 1183 * @tc.steps: step2. call ConvertToBorderWidthPropertyF. 1184 * @tc.expected: the return value is the same as PRECISION_BORDER_WIDTH_PROPERTY. 1185 */ 1186 BorderWidthPropertyF retProperty = ConvertToBorderWidthPropertyF(testPropertyT, scaleProperty, PERCENT_REFERENCE); 1187 EXPECT_EQ(retProperty, PRECISION_LOW_BORDER_WIDTH_PROPERTY); 1188 } 1189 1190 /** 1191 * @tc.name: AdjacentExpandToRectTest 1192 * @tc.desc: Test cast to AdjacentExpandToRect. 1193 * @tc.type: FUNC 1194 */ 1195 HWTEST_F(MeasureUtilsTestNg, AdjacentExpandToRectTest, TestSize.Level1) 1196 { 1197 RectF adjustingRect(20.0f, 10.0f, 60.0f, 100.0f); 1198 RectF frameRect(10.0f, 10.0f, 100.0f, 100.0f); 1199 PaddingPropertyF frameExpand = { 1200 .left = 10.0f, 1201 .right = 20.0f, 1202 .top = 30.0f, 1203 .bottom = 40.0f 1204 }; 1205 PaddingPropertyF expectRes = { 1206 .left = std::nullopt, 1207 .right = std::nullopt, 1208 .top = 30.0f, 1209 .bottom = 40.0f 1210 }; 1211 auto filteredExpand = AdjacentExpandToRect(adjustingRect, frameExpand, frameRect); 1212 EXPECT_EQ(filteredExpand, expectRes); 1213 } 1214 } // namespace OHOS::Ace::NG 1215