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