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 <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
24 #include "base/geometry/dimension.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components/common/layout/grid_system_manager.h"
27 #include "core/components_ng/layout/layout_property.h"
28 #include "core/components_ng/property/calc_length.h"
29 #include "core/components_ng/property/measure_property.h"
30 #include "core/components_ng/property/safe_area_insets.h"
31 #include "core/components_ng/property/grid_property.h"
32 #include "core/pipeline/base/element_register.h"
33
34
35 #undef private
36 #undef protected
37
38 using namespace testing;
39 using namespace testing::ext;
40
41 namespace OHOS::Ace::NG {
42 namespace {
43 const InspectorFilter filter;
44 const std::optional<float> ZERO { 0.0 };
45 const std::optional<int32_t> SPAN_ONE { -1 };
46 const std::optional<int32_t> OFFSET_ONE { -1 };
47 const std::optional<int> WIDTH_OPT { 10 };
48 const std::optional<int> HEIGHT_OPT { 5 };
49 const std::optional<int32_t> SPAN;
50 const std::optional<int32_t> OFFSET;
51
52 constexpr Dimension WIDTH = 1.0_vp;
53 constexpr Dimension HEIGHT = 2.0_vp;
54 constexpr Dimension TOPONE = 3.0_vp;
55 constexpr Dimension BOTTOMONE = 4.0_vp;
56
57 const std::string VALUE_TEST = "test";
58 const std::string STRING_TEST = "{\"top\":\"3.00vp\",\"right\":\"2.00vp\",\"bottom\":\"4.00vp\",\"left\":\"1.00vp\"}";
59
60 const auto FRAME_NODE_ROOT = FrameNode::CreateFrameNode("root", 1, AceType::MakeRefPtr<Pattern>(), true);
61 const auto FRAME_NODE_TEST = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<Pattern>(), true);
62
63 const CalcSize CALC_SIZE = { CalcLength(WIDTH), CalcLength(HEIGHT) };
64
65 LayoutConstraintF layoutConstraintF = {
66 .minSize = { 1, 1 },
67 .maxSize = { 10, 10 },
68 .percentReference = { 5, 5 },
69 .parentIdealSize = { 2, 2 },
70 };
71
72 SafeAreaExpandOpts expandOpts = {
73 .edges = SAFE_AREA_TYPE_SYSTEM,
74 .type = SAFE_AREA_EDGE_TOP,
75 };
76
77 SafeAreaInsets::Inset inset = {
78 .start = 0,
79 .end = 1,
80 };
81
82 SafeAreaInsets safeAreaInset(inset, inset, inset, inset);
83
MakeProperty(RefPtr<LayoutProperty> layoutProperty)84 void MakeProperty(RefPtr<LayoutProperty> layoutProperty)
85 {
86 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
87 layoutProperty->positionProperty_ = std::make_unique<PositionProperty>();
88 layoutProperty->flexItemProperty_ = std::make_unique<FlexItemProperty>();
89 layoutProperty->borderWidth_ = std::make_unique<BorderWidthProperty>();
90 layoutProperty->gridProperty_ = std::make_unique<GridProperty>();
91 layoutProperty->padding_ = std::make_unique<PaddingProperty>();
92 layoutProperty->margin_ = std::make_unique<MarginProperty>();
93 layoutProperty->safeAreaInsets_ = std::make_unique<SafeAreaInsets>();
94 layoutProperty->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
95 }
96
MakePadding()97 PaddingPropertyT<CalcLength> MakePadding()
98 {
99 PaddingPropertyT<CalcLength> paddingProperty;
100 paddingProperty.left = { CalcLength(WIDTH) };
101 paddingProperty.right = { CalcLength(HEIGHT) };
102 paddingProperty.top = { CalcLength(TOPONE) };
103 paddingProperty.bottom = { CalcLength(BOTTOMONE) };
104
105 return paddingProperty;
106 }
107 } // namespace
108
109 class LayoutPropertyTestNg : public testing::Test {
110 public:
SetUpTestSuite()111 static void SetUpTestSuite()
112 {
113 MockPipelineContext::SetUp();
114 }
TearDownTestSuite()115 static void TearDownTestSuite()
116 {
117 MockPipelineContext::TearDown();
118 }
119 };
120
121 /**
122 * @tc.name: ToJsonValue001
123 * @tc.desc: Test cast to LayoutPropertyTestNg
124 * @tc.type: FUNC
125 */
126 HWTEST_F(LayoutPropertyTestNg, ToJsonValue001, TestSize.Level1)
127 {
128 /**
129 * @tc.steps1 Create a layoutProperty and json.
130 */
131 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
132 auto json = JsonUtil::Create(true);
133
134 /**
135 * @tc.steps2 push the padding_ and margin_ is null.
136 * @tc.steps2 push the layoutDirection_ and propVisibility_ index is -1.
137 */
138 auto direction = static_cast<TextDirection>(-1);
139 auto visibility = static_cast<VisibleType>(-1);
140 layoutProperty->layoutDirection_ = direction;
141 layoutProperty->propVisibility_ = visibility;
142
143 /**
144 * @tc.steps3: call ToJsonValue with json.
145 * @tc.expected: Return expected results..
146 */
147 layoutProperty->ToJsonValue(json, filter);
148 EXPECT_EQ(json->GetString("padding"), "0.00vp");
149 EXPECT_EQ(json->GetString("margin"), "0.00vp");
150 EXPECT_EQ(json->GetString("visibility"), "Visibility.Visible");
151 EXPECT_EQ(json->GetString("direction"), "Direction.Ltr");
152
153 /**
154 * @tc.steps4: call Reset.
155 * @tc.expected: Return expected results..
156 */
157 layoutProperty->Reset();
158 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
159
160 /**
161 * @tc.steps5: call Clone, push calcLayoutConstraint_ is null.
162 * @tc.expected: Return expected results.
163 */
164 auto result = layoutProperty->Clone();
165 EXPECT_NE(result, nullptr);
166 }
167
168 /**
169 * @tc.name: ToJsonValue002
170 * @tc.desc: Test cast to LayoutPropertyTestNg
171 * @tc.type: FUNC
172 */
173 HWTEST_F(LayoutPropertyTestNg, ToJsonValue002, TestSize.Level1)
174 {
175 /**
176 * @tc.steps1 Create a layoutProperty and json.
177 */
178 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
179 auto json = JsonUtil::Create(true);
180
181 /**
182 * @tc.steps2: push padding_ and margin_ is not null.
183 * @tc.steps2: push layoutDirection_ is TextDirection::AUTO.
184 * @tc.steps2: push propVisibility_ is VisibleType::GONE.
185 */
186
187 auto paddingProperty = MakePadding();
188 MakeProperty(layoutProperty);
189 layoutProperty->padding_ = std::make_unique<PaddingProperty>(paddingProperty);
190 layoutProperty->margin_ = std::make_unique<MarginProperty>(paddingProperty);
191 layoutProperty->layoutDirection_ = TextDirection::RTL;
192 layoutProperty->propVisibility_ = VisibleType::INVISIBLE;
193
194 /**
195 * @tc.steps3: call ToJsonValue with json.
196 * @tc.expected: Return expected results.
197 */
198 layoutProperty->ToJsonValue(json, filter);
199 EXPECT_EQ(json->GetString("padding"), STRING_TEST);
200 EXPECT_EQ(json->GetString("margin"), STRING_TEST);
201 EXPECT_EQ(json->GetString("direction"), "Direction.Rtl");
202 EXPECT_EQ(json->GetString("visibility"), "Visibility.Hidden");
203
204 /**
205 * @tc.steps4: call Clone, push calcLayoutConstraint_ is not null.
206 * @tc.expected: Return expected results.
207 */
208 layoutProperty->FromJson(json);
209 auto result = layoutProperty->Clone();
210 EXPECT_NE(result, nullptr);
211 EXPECT_EQ(layoutProperty->propertyChangeFlag_, 3);
212 }
213
214 /**
215 * @tc.name: UpdateCalcLayoutProperty001
216 * @tc.desc: Test cast to LayoutPropertyTestNg
217 * @tc.type: FUNC
218 */
219 HWTEST_F(LayoutPropertyTestNg, UpdateCalcLayoutProperty001, TestSize.Level1)
220 {
221 /**
222 * @tc.steps1 Create a layoutProperty and constraint.
223 */
224 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
225 MeasureProperty constraint;
226
227 /**
228 * @tc.steps: step2. call UpdateCalcLayoutProperty, push constraint is null.
229 * @tc.expected: Return expected results..
230 */
231 layoutProperty->UpdateCalcLayoutProperty(std::move(constraint));
232 EXPECT_EQ(layoutProperty->propertyChangeFlag_, 1);
233
234 /**
235 * @tc.steps3: call ToJsonValue with json.
236 * @tc.expected: Return expected results..
237 */
238 auto json = JsonUtil::Create(true);
239 layoutProperty->FromJson(json);
240 EXPECT_EQ(json->GetString("padding"), "");
241 EXPECT_EQ(json->GetString("margin"), "");
242 }
243
244 /**
245 * @tc.name: UpdateLayoutConstraint001
246 * @tc.desc: Test cast to LayoutPropertyTestNg
247 * @tc.type: FUNC
248 */
249 HWTEST_F(LayoutPropertyTestNg, UpdateLayoutConstraint001, TestSize.Level1)
250 {
251 /**
252 * @tc.steps1 Create a layoutProperty and constraint.
253 */
254 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
255 MeasureProperty constraint;
256
257 /**
258 * @tc.steps2: call UpdateLayoutConstraint, push margin_ is null.
259 * @tc.expected: expected layoutProperty->propertyChangeFlag_ is 0.
260 */
261 layoutProperty->UpdateLayoutConstraint(std::move(layoutConstraintF));
262 EXPECT_EQ(layoutProperty->propertyChangeFlag_, 0);
263
264 /**
265 * @tc.steps3: push margin_ and calcLayoutConstraint_ is default value.
266 * @tc.steps3: call UpdateLayoutConstraint.
267 * @tc.expected: expected layoutProperty->measureType_ is nullopt.
268 */
269 MakeProperty(layoutProperty);
270 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>(constraint);
271 layoutProperty->UpdateLayoutConstraint(std::move(layoutConstraintF));
272 EXPECT_EQ(layoutProperty->measureType_, std::nullopt);
273
274 /**
275 * @tc.steps4: push calcLayoutConstraint_ maxSize minSize and selfIdealSize is has_value.
276 * @tc.steps4: call UpdateLayoutConstraint.
277 * @tc.expected: Return expected results.
278 */
279 constraint.maxSize = CALC_SIZE;
280 constraint.minSize = CALC_SIZE;
281 constraint.selfIdealSize = CALC_SIZE;
282 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>(constraint);
283 layoutProperty->magicItemProperty_.UpdateAspectRatio(1.0);
284 layoutProperty->measureType_ = MeasureType::MATCH_PARENT;
285 layoutProperty->UpdateLayoutConstraint(std::move(layoutConstraintF));
286 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value(), CALC_SIZE);
287 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value(), CALC_SIZE);
288 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->selfIdealSize.value(), CALC_SIZE);
289 }
290
291 /**
292 * @tc.name: CheckBorderAndPadding001
293 * @tc.desc: Test cast to LayoutPropertyTestNg
294 * @tc.type: FUNC
295 */
296 HWTEST_F(LayoutPropertyTestNg, CheckBorderAndPadding001, TestSize.Level1)
297 {
298 /**
299 * @tc.steps1 Create a layoutProperty.
300 */
301 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
302
303 /**
304 * @tc.steps2: call CheckBorderAndPadding.push selfIdealSize is {1,-1}.
305 * @tc.expected: Return expected results..
306 */
307 layoutConstraintF.selfIdealSize = { 1, -1 };
308 layoutProperty->layoutConstraint_ = layoutConstraintF;
309 layoutProperty->CheckBorderAndPadding();
310 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Width(), 1);
311 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Height(), 0);
312
313 /**
314 * @tc.steps3: call CheckBorderAndPadding.push selfIdealSize is {-1,1}.
315 * @tc.expected: Return expected results..
316 */
317 layoutConstraintF.selfIdealSize = { -1, 1 };
318 layoutProperty->layoutConstraint_ = layoutConstraintF;
319 layoutProperty->CheckBorderAndPadding();
320 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Width(), 0);
321 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Height(), 1);
322
323 /**
324 * @tc.steps4: call CreatePaddingAndBorder.
325 * @tc.expected: Return expected results..
326 */
327 PaddingPropertyF paddingPropertyF = layoutProperty->CreatePaddingAndBorder();
328 EXPECT_EQ(paddingPropertyF.left, ZERO);
329 EXPECT_EQ(paddingPropertyF.right, ZERO);
330 EXPECT_EQ(paddingPropertyF.top, ZERO);
331 EXPECT_EQ(paddingPropertyF.bottom, ZERO);
332 }
333
334 /**
335 * @tc.name: CheckAspectRatio001
336 * @tc.desc: Test cast to LayoutPropertyTestNg
337 * @tc.type: FUNC
338 */
339 HWTEST_F(LayoutPropertyTestNg, CheckAspectRatio001, TestSize.Level1)
340 {
341 /**
342 * @tc.steps1 Create a layoutProperty.
343 */
344 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
345
346 /**
347 * @tc.steps2: call CheckAspectRatio.push layoutConstraint_ is null.
348 * @tc.steps2: push AspectRatio is 1.0
349 * @tc.expected: Return expected results.
350 */
351 layoutProperty->magicItemProperty_.UpdateAspectRatio(1.0);
352 layoutProperty->CheckAspectRatio();
353 EXPECT_EQ(layoutProperty->layoutConstraint_, std::nullopt);
354
355 /**
356 * @tc.steps3: callback CheckAspectRatio.push layoutConstraint_ is not null.
357 * @tc.steps3: push selfIdealSize Width hasvalue.
358 * @tc.expected: Return expected results.
359 */
360 layoutConstraintF.maxSize = { 2, 4 };
361 layoutConstraintF.selfIdealSize.SetWidth(WIDTH_OPT);
362 layoutProperty->layoutConstraint_ = layoutConstraintF;
363 layoutProperty->CheckAspectRatio();
364 EXPECT_TRUE(layoutProperty->layoutConstraint_.has_value());
365 EXPECT_TRUE(layoutProperty->layoutConstraint_->selfIdealSize.Width().has_value());
366 EXPECT_TRUE(layoutProperty->layoutConstraint_->selfIdealSize.Height().has_value());
367 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Width(), 2);
368 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Height(), 2);
369 }
370
371 /**
372 * @tc.name: CheckAspectRatio002
373 * @tc.desc: Test cast to LayoutPropertyTestNg
374 * @tc.type: FUNC
375 */
376 HWTEST_F(LayoutPropertyTestNg, CheckAspectRatio002, TestSize.Level1)
377 {
378 /**
379 * @tc.steps1 Create a layoutProperty.
380 */
381 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
382 LayoutConstraintF constraintF;
383
384 /**
385 * @tc.steps2: call CheckAspectRatio, push AspectRatio is 0.5.
386 * @tc.steps2: push selfIdealSize Height hasvalue.
387 * @tc.expected: Return expected results.
388 */
389 constraintF.selfIdealSize.SetHeight(HEIGHT_OPT);
390 layoutProperty->layoutConstraint_ = constraintF;
391 layoutProperty->magicItemProperty_.UpdateAspectRatio(0.5);
392 layoutProperty->CheckAspectRatio();
393
394 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Width(), 2.5);
395 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Height(), 5);
396
397 /**
398 * @tc.steps3: call CheckAspectRatio, push AspectRatio is 1.0.
399 * @tc.steps3: push selfIdealSize maxSize hasvalue.
400 * @tc.expected: Return expected results.
401 */
402 constraintF.maxSize = { 1, 2 };
403 layoutProperty->layoutConstraint_ = constraintF;
404 layoutProperty->magicItemProperty_.UpdateAspectRatio(1.0);
405 layoutProperty->CheckAspectRatio();
406
407 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Width(), 1);
408 EXPECT_EQ(layoutProperty->layoutConstraint_->selfIdealSize.Height(), 1);
409 }
410
411 /**
412 * @tc.name: BuildGridProperty001
413 * @tc.desc: Test cast to LayoutPropertyTestNg
414 * @tc.type: FUNC
415 */
416 HWTEST_F(LayoutPropertyTestNg, BuildGridProperty001, TestSize.Level1)
417 {
418 /**
419 * @tc.steps1 Create a layoutProperty.
420 */
421 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
422
423 /**
424 * @tc.steps2: call BuildGridProperty, push gridProperty_ is null.
425 * @tc.expected: Return expected results.
426 */
427 layoutProperty->Reset();
428 layoutProperty->BuildGridProperty(FRAME_NODE_ROOT);
429 auto parent = FRAME_NODE_ROOT->GetAncestorNodeOfFrame(false);
430 EXPECT_EQ(parent, nullptr);
431
432 /**
433 * @tc.steps3: call BuildGridProperty, push gridProperty_ is hasvalue.
434 * @tc.expected: Return expected results.
435 */
436 layoutProperty->gridProperty_ = std::make_unique<GridProperty>();
437 FRAME_NODE_ROOT->SetParent(FRAME_NODE_TEST);
438 FRAME_NODE_ROOT->NotifyVisibleChange(VisibleType::INVISIBLE, VisibleType::VISIBLE);
439 layoutProperty->BuildGridProperty(FRAME_NODE_ROOT);
440 auto result = FRAME_NODE_ROOT->GetAncestorNodeOfFrame(false);
441 ASSERT_NE(result, nullptr);
442 EXPECT_EQ(result->GetTag(), VALUE_TEST);
443
444 /**
445 * @tc.steps4: call CreatePaddingAndBorder, push layoutConstraint_ is null.
446 * @tc.expected: Return paddingPropertyF left is ZERO.
447 */
448 PaddingPropertyF paddingPropertyF = layoutProperty->CreatePaddingAndBorder();
449 EXPECT_EQ(paddingPropertyF.left, ZERO);
450 EXPECT_EQ(paddingPropertyF.right, ZERO);
451 EXPECT_EQ(paddingPropertyF.top, ZERO);
452 EXPECT_EQ(paddingPropertyF.bottom, ZERO);
453 }
454
455 /**
456 * @tc.name: UpdateGridProperty001
457 * @tc.desc: Test cast to LayoutPropertyTestNg
458 * @tc.type: FUNC
459 */
460 HWTEST_F(LayoutPropertyTestNg, UpdateGridProperty001, TestSize.Level1)
461 {
462 /**
463 * @tc.steps1 Create a layoutProperty.
464 */
465 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
466
467 /**
468 * @tc.steps2: call UpdateGridProperty, push gridProperty_ is null, push span is null.
469 * @tc.expected: expected results propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
470 */
471 layoutProperty->UpdateGridProperty(SPAN, OFFSET, GridSizeType::UNDEFINED);
472 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
473
474 /**
475 * @tc.steps3: call UpdateGridProperty, push gridProperty_ is null, push span is -1.
476 * @tc.expected: expected results propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
477 */
478 layoutProperty->UpdateGridProperty(SPAN_ONE, OFFSET_ONE, GridSizeType::XS);
479 bool spanResult = layoutProperty->gridProperty_->UpdateSpan(SPAN_ONE.value(), GridSizeType::XS);
480 EXPECT_FALSE(spanResult);
481 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
482
483 /**
484 * @tc.steps4: call UpdateGridOffset, push gridProperty_ is null.
485 * @tc.expected: Return results.is false.
486 */
487 bool result = layoutProperty->UpdateGridOffset(FRAME_NODE_ROOT);
488 EXPECT_FALSE(result);
489
490 /**
491 * @tc.steps5: call UpdateGridProperty, push gridProperty_ is not null, push span is 1.
492 * @tc.expected: Return expected results.
493 */
494 layoutProperty->gridProperty_ = std::make_unique<GridProperty>();
495 layoutProperty->UpdateGridProperty(DEFAULT_GRID_SPAN, DEFAULT_GRID_OFFSET, GridSizeType::UNDEFINED);
496 EXPECT_FALSE(layoutProperty->layoutConstraint_.has_value());
497 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
498
499 /**
500 * @tc.steps6: call UpdateGridOffset, push gridProperty_ is not null.
501 * @tc.expected: Return expected results.
502 */
503 layoutProperty->gridProperty_->gridInfo_ =
504 GridSystemManager::GetInstance().GetInfoByType(GridColumnType::CAR_DIALOG);
505
506 bool result1 = layoutProperty->UpdateGridOffset(FRAME_NODE_ROOT);
507 EXPECT_EQ(layoutProperty->gridProperty_->GetOffset(), UNDEFINED_DIMENSION);
508 EXPECT_FALSE(result1);
509 }
510
511 /**
512 * @tc.name: UpdateGridProperty002
513 * @tc.desc: Test cast to LayoutPropertyTestNg
514 * @tc.type: FUNC
515 */
516 HWTEST_F(LayoutPropertyTestNg, UpdateGridProperty002, TestSize.Level1)
517 {
518 /**
519 * @tc.steps1 Create a layoutProperty.
520 */
521 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
522
523 /**
524 * @tc.steps2: call UpdateGridProperty, push gridProperty_ is not null, push span is not null.
525 * @tc.expected: expected results propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
526 */
527 std::optional<int32_t> spanTemp = 1;
528 std::optional<int32_t> offsetTemp = 1;
529 layoutProperty->UpdateGridProperty(spanTemp, offsetTemp, GridSizeType::UNDEFINED);
530 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
531
532 /**
533 * @tc.steps3: call UpdateGridOffset.
534 * @tc.expected: expected parent is false and return false.
535 */
536 auto framenodeTemp = FrameNode::CreateFrameNode("root", 2, AceType::MakeRefPtr<Pattern>(), true);
537 bool result1 = layoutProperty->UpdateGridOffset(framenodeTemp);
538 EXPECT_NE(layoutProperty->gridProperty_->GetOffset(), UNDEFINED_DIMENSION);
539 EXPECT_EQ(framenodeTemp->GetAncestorNodeOfFrame(false), nullptr);
540 EXPECT_FALSE(result1);
541 }
542
543 /**
544 * @tc.name: CreatePaddingAndBorderWithDefault001
545 * @tc.desc: Test cast to LayoutPropertyTestNg
546 * @tc.type: FUNC
547 */
548 HWTEST_F(LayoutPropertyTestNg, CreatePaddingAndBorderWithDefault001, TestSize.Level1)
549 {
550 /**
551 * @tc.steps1 Create a layoutProperty.
552 */
553 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
554
555 /**
556 * @tc.steps2: call CreatePaddingAndBorderWithDefault, push layoutConstraint_is null.
557 * @tc.expected: Return paddingPropertyF left == 1.0 + 3.0
558 */
559 PaddingPropertyF paddingPropertyF = layoutProperty->CreatePaddingAndBorderWithDefault(1.0, 2.0, 3.0, 4.0);
560 EXPECT_EQ(paddingPropertyF.left, 1.0 + 3.0);
561 EXPECT_EQ(paddingPropertyF.right, 1.0 + 3.0);
562
563 /**
564 * @tc.steps4: call CreateMargin, push layoutConstraint_ null.
565 * @tc.expected: Return margin is nullopt.
566 */
567 PaddingPropertyF margin = layoutProperty->CreateMargin();
568 EXPECT_EQ(margin.top, std::nullopt);
569 EXPECT_EQ(margin.bottom, std::nullopt);
570
571 /**
572 * @tc.steps5: call CreatePaddingAndBorderWithDefault, push layoutConstraint_is not null.
573 * @tc.expected: Return paddingProperty top == 2.0 + 4.0
574 */
575 LayoutConstraintF constraintF;
576 layoutProperty->layoutConstraint_ = constraintF;
577 PaddingPropertyF paddingPropertyT = layoutProperty->CreatePaddingAndBorderWithDefault(1.0, 2.0, 3.0, 4.0);
578 EXPECT_EQ(paddingPropertyT.top, 2.0 + 4.0);
579 EXPECT_EQ(paddingPropertyT.bottom, 2.0 + 4.0);
580
581 /**
582 * @tc.steps6: call CreatePaddingWithoutBorder, push layoutConstraint_is not null.
583 * @tc.expected: Return frameNodeHost left hasvalue.
584 */
585 auto paddingProperty = MakePadding();
586 layoutProperty->padding_ = std::make_unique<PaddingProperty>(paddingProperty);
587 PaddingPropertyF paddingTwo = layoutProperty->CreatePaddingWithoutBorder();
588 EXPECT_EQ(paddingTwo.left, 1);
589 EXPECT_EQ(paddingTwo.right, 2);
590 EXPECT_EQ(paddingTwo.top, 3);
591 EXPECT_EQ(paddingTwo.bottom, 4);
592 }
593
594 /**
595 * @tc.name: OnVisibilityUpdate001
596 * @tc.desc: Test cast to LayoutPropertyTestNg
597 * @tc.type: FUNC
598 */
599 HWTEST_F(LayoutPropertyTestNg, OnVisibilityUpdate001, TestSize.Level1)
600 {
601 /**
602 * @tc.steps1 Create a layoutProperty.
603 */
604 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
605
606 /**
607 * @tc.steps2: call OnVisibilityUpdate, push VisibleType::VISIBLE.
608 * @tc.expected: expected host is null.
609 */
610 layoutProperty->OnVisibilityUpdate(VisibleType::VISIBLE, false);
611 auto host = layoutProperty->GetHost();
612 EXPECT_EQ(host, nullptr);
613
614 /**
615 * @tc.steps3: call OnVisibilityUpdate and SetHost, push VisibleType::VISIBLE.
616 * @tc.expected: expected parent is null.
617 */
618 auto frameNodeHost = FrameNode::CreateFrameNode("host", 1, AceType::MakeRefPtr<Pattern>(), true);
619 layoutProperty->SetHost(frameNodeHost);
620 layoutProperty->OnVisibilityUpdate(VisibleType::INVISIBLE, true);
621 auto parent = layoutProperty->GetHost()->GetAncestorNodeOfFrame(false);
622 EXPECT_EQ(parent, nullptr);
623
624 /**
625 * @tc.steps4: call OnVisibilityUpdate and SetParent, push VisibleType::VISIBLE.
626 * @tc.expected: expected host_test is not null.
627 */
628 FRAME_NODE_ROOT->SetParent(FRAME_NODE_TEST);
629 layoutProperty->SetHost(FRAME_NODE_ROOT);
630 layoutProperty->OnVisibilityUpdate(VisibleType::VISIBLE, true);
631 auto host_test = layoutProperty->GetHost();
632 ASSERT_NE(host_test, nullptr);
633
634 /**
635 * @tc.steps5: call OnVisibilityUpdate, push VisibleType::GONE.
636 * @tc.expected: expected parent_test is not null.
637 */
638 layoutProperty->OnVisibilityUpdate(VisibleType::GONE);
639 auto parent_test = layoutProperty->GetHost()->GetAncestorNodeOfFrame(false);
640 ASSERT_NE(parent_test, nullptr);
641 }
642
643 /**
644 * @tc.name: CreateChildConstraint001
645 * @tc.desc: Test cast to LayoutPropertyTestNg
646 * @tc.type: FUNC
647 */
648 HWTEST_F(LayoutPropertyTestNg, CreateChildConstraint001, TestSize.Level1)
649 {
650 /**
651 * @tc.steps1 Create a layoutProperty.
652 */
653 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
654
655 /**
656 * @tc.steps2: call CreateChildConstraint, push layoutConstraint_is null.
657 * @tc.expected: Return oneResult parentIdealSize is null.
658 */
659 LayoutConstraintF oneResult = layoutProperty->CreateChildConstraint();
660 EXPECT_EQ(oneResult.parentIdealSize.Width(), std::nullopt);
661 EXPECT_EQ(oneResult.parentIdealSize.Height(), std::nullopt);
662
663 /**
664 * @tc.steps3: call CreateChildConstraint, push layoutConstraint_ selfIdealSize is {10, 1}.
665 * @tc.expected: Return twoResult maxSize and percentReference is {10, 1}.
666 */
667 layoutProperty->layoutConstraint_ = layoutConstraintF;
668 layoutProperty->contentConstraint_ = layoutConstraintF;
669 LayoutConstraintF twoResult = layoutProperty->CreateChildConstraint();
670 EXPECT_EQ(twoResult.maxSize.Width(), 10);
671 EXPECT_EQ(twoResult.maxSize.Height(), 1);
672 EXPECT_EQ(twoResult.percentReference.Width(), 10);
673 EXPECT_EQ(twoResult.percentReference.Height(), 1);
674
675 /**
676 * @tc.steps4: call CreateChildConstraint, push layoutConstraint_ selfIdealSize is default value.
677 * @tc.expected: Return threeResult percentReference is {0, 0}.
678 */
679 LayoutConstraintF constraintF;
680 layoutProperty->layoutConstraint_ = constraintF;
681 layoutProperty->contentConstraint_ = constraintF;
682 LayoutConstraintF threeResult = layoutProperty->CreateChildConstraint();
683 EXPECT_EQ(threeResult.percentReference.Width(), 0);
684 EXPECT_EQ(threeResult.percentReference.Height(), 0);
685 }
686
687 /**
688 * @tc.name: UpdateContentConstraint001
689 * @tc.desc: Test cast to LayoutPropertyTestNg
690 * @tc.type: FUNC
691 */
692 HWTEST_F(LayoutPropertyTestNg, UpdateContentConstraint001, TestSize.Level1)
693 {
694 /**
695 * @tc.steps1 Create a layoutProperty.
696 */
697 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
698
699 /**
700 * @tc.steps2: call CreateChildConstraint, push layoutConstraint_is null.
701 * @tc.expected: Return contentConstraint_ is nullopt.
702 */
703 layoutProperty->UpdateContentConstraint();
704 EXPECT_EQ(layoutProperty->layoutConstraint_, std::nullopt);
705 EXPECT_EQ(layoutProperty->contentConstraint_, std::nullopt);
706
707 /**
708 * @tc.steps3: call UpdateContentConstraint, push layoutConstraint_ is hasvalue, the parentIdealSize is null.
709 * @tc.expected: Return expected percentReference is {1, 0}.
710 */
711 LayoutConstraintF constraintF;
712 constraintF.percentReference = { 1, 0 };
713 layoutProperty->layoutConstraint_ = constraintF;
714 layoutProperty->UpdateContentConstraint();
715 EXPECT_EQ(layoutProperty->contentConstraint_->percentReference.Width(), 1);
716 EXPECT_EQ(layoutProperty->contentConstraint_->percentReference.Height(), 0);
717
718 /**
719 * @tc.steps4: call UpdateContentConstraint, push layoutConstraint_ is hasvalue, the parentIdealSize is {4, 4}.
720 * @tc.expected: Return expected percentReference is {4, 4}.
721 */
722 constraintF.parentIdealSize = { 4, 4 };
723 layoutProperty->layoutConstraint_ = constraintF;
724 MakeProperty(layoutProperty);
725 layoutProperty->UpdateContentConstraint();
726 EXPECT_EQ(layoutProperty->contentConstraint_->percentReference.Width(), 4);
727 EXPECT_EQ(layoutProperty->contentConstraint_->percentReference.Height(), 4);
728 }
729
730 /**
731 * @tc.name: UpdateSafeAreaExpandOpts001
732 * @tc.desc: Test cast to LayoutPropertyTestNg
733 * @tc.type: FUNC
734 */
735 HWTEST_F(LayoutPropertyTestNg, UpdateSafeAreaExpandOpts001, TestSize.Level1)
736 {
737 /**
738 * @tc.steps1 Create a layoutProperty.
739 */
740 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
741 SafeAreaExpandOpts opts;
742 SafeAreaInsets safeArea;
743
744 /**
745 * @tc.steps2: push safeAreaExpandOpts_ and safeAreaInsets_ is null.
746 * @tc.steps2: call UpdateSafeAreaExpandOpts and UpdateSafeAreaInsets.
747 * @tc.expected: Return safeAreaExpandOpts_ edges is 0.
748 */
749 layoutProperty->UpdateSafeAreaExpandOpts(opts);
750 layoutProperty->UpdateSafeAreaInsets(safeArea);
751 EXPECT_EQ(layoutProperty->safeAreaExpandOpts_->edges, SAFE_AREA_TYPE_NONE);
752 EXPECT_EQ(layoutProperty->safeAreaExpandOpts_->type, SAFE_AREA_EDGE_NONE);
753 EXPECT_EQ(layoutProperty->propertyChangeFlag_, 0);
754
755 /**
756 * @tc.steps3: push safeAreaExpandOpts_ and safeAreaInsets_ is not null.
757 * @tc.steps3: call UpdateSafeAreaExpandOpts and UpdateSafeAreaInsets.
758 * @tc.expected: Return safeAreaExpandOpts_ edges is 1.
759 */
760 layoutProperty->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>(opts);
761 layoutProperty->safeAreaInsets_ = std::make_unique<SafeAreaInsets>(safeArea);
762 layoutProperty->UpdateSafeAreaExpandOpts(expandOpts);
763 layoutProperty->UpdateSafeAreaInsets(safeAreaInset);
764 EXPECT_EQ(layoutProperty->safeAreaExpandOpts_->edges, SAFE_AREA_TYPE_SYSTEM);
765 EXPECT_EQ(layoutProperty->safeAreaExpandOpts_->type, SAFE_AREA_EDGE_TOP);
766 EXPECT_EQ(layoutProperty->propertyChangeFlag_, 3);
767 }
768
769 /**
770 * @tc.name: ResetCalcMinSize001
771 * @tc.desc: Test cast to ResetCalcMinSize
772 * @tc.type: FUNC
773 */
774 HWTEST_F(LayoutPropertyTestNg, ResetCalcMinSize001, TestSize.Level1)
775 {
776 /**
777 * @tc.steps1 Create a layoutProperty.
778 */
779 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
780 auto width = CalcLength::FromString("1px");
781 auto height = CalcLength::FromString("1px");
782 CalcSize calcSize(width, height);
783 MeasureProperty calcLayoutConstraint;
784 calcLayoutConstraint.UpdateMinSizeWithCheck(calcSize);
785
786 width = CalcLength::FromString("0px");
787 height = CalcLength::FromString("0px");
788 CalcSize resetCalcSize(width, height);
789
790 /**
791 * @tc.steps2 call ResetCalcMinSize with calcLayoutConstraint.
792 */
793 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
794 layoutProperty->ResetCalcMinSize();
795 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
796 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize, std::nullopt);
797
798 /**
799 * @tc.steps3 call ResetCalcMinSize with calcLayoutConstraint_ NULL.
800 */
801 layoutProperty->calcLayoutConstraint_.reset();
802 layoutProperty->ResetCalcMinSize();
803 EXPECT_FALSE(layoutProperty->calcLayoutConstraint_);
804 }
805
806 /**
807 * @tc.name: ResetCalcMinSize002
808 * @tc.desc: Test cast to ResetCalcMinSize(bool resetWidth)
809 * @tc.type: FUNC
810 */
811 HWTEST_F(LayoutPropertyTestNg, ResetCalcMinSize002, TestSize.Level1)
812 {
813 /**
814 * @tc.steps1 Create a layoutProperty.
815 */
816 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
817 auto width = CalcLength::FromString("1px");
818 auto height = CalcLength::FromString("1px");
819 CalcSize calcSize(width, height);
820 MeasureProperty calcLayoutConstraint;
821 calcLayoutConstraint.UpdateMinSizeWithCheck(calcSize);
822 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
823
824 /**
825 * @tc.steps2 call ResetCalcMinSize with resetWidth false calcLayoutConstraint.
826 */
827 layoutProperty->ResetCalcMinSize(false);
828 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
829 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value().Width(), width);
830 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value().Height(), std::nullopt);
831
832 /**
833 * @tc.steps3 call ResetCalcMinSize with resetWidth true calcLayoutConstraint.
834 */
835 calcLayoutConstraint.UpdateMinSizeWithCheck(calcSize);
836 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
837 layoutProperty->ResetCalcMinSize(true);
838 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
839 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value().Height(), height);
840 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->minSize.value().Width(), std::nullopt);
841
842 /**
843 * @tc.steps3 call ResetCalcMinSize with calcLayoutConstraint_ NULL.
844 */
845 layoutProperty->calcLayoutConstraint_.reset();
846 layoutProperty->ResetCalcMinSize();
847 EXPECT_FALSE(layoutProperty->calcLayoutConstraint_);
848 }
849
850 /**
851 * @tc.name: ResetCalcMinSize001
852 * @tc.desc: Test cast to ResetCalcMaxSize
853 * @tc.type: FUNC
854 */
855 HWTEST_F(LayoutPropertyTestNg, ResetCalcMaxSize001, TestSize.Level1)
856 {
857 /**
858 * @tc.steps1 Create a layoutProperty.
859 */
860 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
861 auto width = CalcLength::FromString("10px");
862 auto height = CalcLength::FromString("10px");
863 CalcSize calcSize(width, height);
864 MeasureProperty calcLayoutConstraint;
865 calcLayoutConstraint.UpdateMaxSizeWithCheck(calcSize);
866 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
867 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize, calcSize);
868
869 /**
870 * @tc.steps2 call ResetCalcMaxSize with calcLayoutConstraint.
871 */
872 layoutProperty->ResetCalcMaxSize();
873 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
874 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize, std::nullopt);
875
876 /**
877 * @tc.steps3 call ResetCalcMaxSize with calcLayoutConstraint_ NULL.
878 */
879 layoutProperty->calcLayoutConstraint_.reset();
880 layoutProperty->ResetCalcMaxSize();
881 EXPECT_FALSE(layoutProperty->calcLayoutConstraint_);
882 }
883
884 /**
885 * @tc.name: ResetCalcMaxSize002
886 * @tc.desc: Test cast to ResetCalcMaxSize(bool resetWidth)
887 * @tc.type: FUNC
888 */
889 HWTEST_F(LayoutPropertyTestNg, ResetCalcMaxSize002, TestSize.Level1)
890 {
891 /**
892 * @tc.steps1 Create a layoutProperty.
893 */
894 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
895 auto width = CalcLength::FromString("10px");
896 auto height = CalcLength::FromString("10px");
897 CalcSize calcSize(width, height);
898 MeasureProperty calcLayoutConstraint;
899 calcLayoutConstraint.UpdateMaxSizeWithCheck(calcSize);
900 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
901
902 /**
903 * @tc.steps2 call ResetCalcMaxSize with resetWidth false calcLayoutConstraint.
904 */
905 layoutProperty->ResetCalcMaxSize(false);
906 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
907 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value().Width(), width);
908 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value().Height(), std::nullopt);
909
910 /**
911 * @tc.steps3 call ResetCalcMaxSize with resetWidth true calcLayoutConstraint.
912 */
913 calcLayoutConstraint.UpdateMaxSizeWithCheck(calcSize);
914 layoutProperty->UpdateCalcLayoutProperty(calcLayoutConstraint);
915 layoutProperty->ResetCalcMaxSize(true);
916 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
917 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value().Height(), height);
918 EXPECT_EQ(layoutProperty->calcLayoutConstraint_->maxSize.value().Width(), std::nullopt);
919
920 /**
921 * @tc.steps3 call ResetCalcMaxSize with calcLayoutConstraint_ NULL.
922 */
923 layoutProperty->calcLayoutConstraint_.reset();
924 layoutProperty->ResetCalcMaxSize();
925 EXPECT_FALSE(layoutProperty->calcLayoutConstraint_);
926 }
927
928 /**
929 * @tc.name: UpdateFlexGrow001
930 * @tc.desc: Test cast to UpdateFlexGrow
931 * @tc.type: FUNC
932 */
933 HWTEST_F(LayoutPropertyTestNg, UpdateFlexGrow001, TestSize.Level1)
934 {
935 /**
936 * @tc.steps1 Create a layoutProperty.
937 */
938 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
939 EXPECT_FALSE(layoutProperty->flexItemProperty_);
940
941 layoutProperty->UpdateFlexGrow(1);
942 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
943 EXPECT_FALSE(layoutProperty->flexItemProperty_->GetTwoHorizontalDirectionAligned());
944 }
945
946 /**
947 * @tc.name: ResetFlexGrow001
948 * @tc.desc: Test cast to UpdateFlexGrow
949 * @tc.type: FUNC
950 */
951 HWTEST_F(LayoutPropertyTestNg, ResetFlexGrow001, TestSize.Level1)
952 {
953 /**
954 * @tc.steps1 Create a layoutProperty.
955 */
956 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
957
958 /**
959 * @tc.steps2 Call ResetFlexGrow without flexItemProperty_.
960 */
961 layoutProperty->ResetFlexGrow();
962 EXPECT_FALSE(layoutProperty->flexItemProperty_);
963
964 /**
965 * @tc.steps3 Call ResetFlexGrow with flexItemProperty_.
966 */
967 layoutProperty->UpdateFlexGrow(1.0);
968 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
969 layoutProperty->ResetFlexGrow();
970 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
971 }
972
973 /**
974 * @tc.name: ResetFlexShrink001
975 * @tc.desc: Test cast to ResetFlexShrink
976 * @tc.type: FUNC
977 */
978 HWTEST_F(LayoutPropertyTestNg, ResetFlexShrink001, TestSize.Level1)
979 {
980 /**
981 * @tc.steps1 Create a layoutProperty.
982 */
983 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
984
985 /**
986 * @tc.steps2 Call ResetFlexShrink without flexItemProperty_.
987 */
988 layoutProperty->ResetFlexShrink();
989 EXPECT_FALSE(layoutProperty->flexItemProperty_);
990
991 /**
992 * @tc.steps3 Call ResetFlexShrink with flexItemProperty_.
993 */
994 layoutProperty->UpdateFlexShrink(1.0);
995 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
996 layoutProperty->ResetFlexShrink();
997 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
998 }
999
1000 /**
1001 * @tc.name: UpdateFlexBasis001
1002 * @tc.desc: Test cast to UpdateFlexBasis
1003 * @tc.type: FUNC
1004 */
1005 HWTEST_F(LayoutPropertyTestNg, UpdateFlexBasis001, TestSize.Level1)
1006 {
1007 /**
1008 * @tc.steps1 Create a layoutProperty.
1009 */
1010 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1011
1012 /**
1013 * @tc.steps2 Call UpdateFlexBasis without flexItemProperty_.
1014 */
1015 auto flexBasis = Dimension::FromString("1px");
1016 layoutProperty->UpdateFlexBasis(flexBasis);
1017 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1018 }
1019
1020 /**
1021 * @tc.name: ResetAlignSelf001
1022 * @tc.desc: Test cast to ResetAlignSelf
1023 * @tc.type: FUNC
1024 */
1025 HWTEST_F(LayoutPropertyTestNg, ResetAlignSelf001, TestSize.Level1)
1026 {
1027 /**
1028 * @tc.steps1 Create a layoutProperty.
1029 */
1030 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1031
1032 /**
1033 * @tc.steps2 Call UpdateFlexBasis without flexItemProperty_.
1034 */
1035 layoutProperty->ResetAlignSelf();
1036 EXPECT_FALSE(layoutProperty->flexItemProperty_);
1037
1038 /**
1039 * @tc.steps3 Call UpdateFlexBasis with flexItemProperty_.
1040 */
1041 FlexAlign flexAlign = FlexAlign::CENTER;
1042 layoutProperty->UpdateAlignSelf(flexAlign);
1043 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1044 layoutProperty->ResetAlignSelf();
1045 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1046
1047 /**
1048 * @tc.steps4 reset propAlignSelf.
1049 */
1050 flexAlign = FlexAlign::CENTER;
1051 layoutProperty->flexItemProperty_->propAlignSelf.reset();
1052 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1053 layoutProperty->ResetAlignSelf();
1054 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1055 }
1056
1057 /**
1058 * @tc.name: UpdateDisplayIndex001
1059 * @tc.desc: Test cast to UpdateDisplayIndex
1060 * @tc.type: FUNC
1061 */
1062 HWTEST_F(LayoutPropertyTestNg, UpdateDisplayIndex001, TestSize.Level1)
1063 {
1064 /**
1065 * @tc.steps1 Create a layoutProperty.
1066 */
1067 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1068
1069 /**
1070 * @tc.steps2 Call UpdateFlexBasis without flexItemProperty_.
1071 */
1072 EXPECT_FALSE(layoutProperty->flexItemProperty_);
1073 layoutProperty->UpdateDisplayIndex(0);
1074 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
1075
1076 /**
1077 * @tc.steps3 Call UpdateFlexBasis with flexItemProperty_ again.
1078 * @tc.expect Update fail
1079 */
1080 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1081 layoutProperty->UpdateDisplayIndex(0);
1082 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1083 }
1084
1085 /**
1086 * @tc.name: SetOverlayOffset001
1087 * @tc.desc: Test cast to SetOverlayOffset
1088 * @tc.type: FUNC
1089 */
1090 HWTEST_F(LayoutPropertyTestNg, SetOverlayOffset001, TestSize.Level1)
1091 {
1092 /**
1093 * @tc.steps1 Create a layoutProperty.
1094 */
1095 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1096 layoutProperty->overlayOffsetX_ = Dimension::FromString("1px");
1097 layoutProperty->overlayOffsetY_ = Dimension::FromString("1px");
1098
1099 /**
1100 * @tc.steps2 Call UpdateFlexBasis with overlayOffsetX and overlayOffsetY.
1101 xChanged = false, yChanged = false.
1102 */
1103 auto overlayOffsetX = std::make_optional<Dimension>(Dimension::FromString("1px"));
1104 auto overlayOffsetY = std::make_optional<Dimension>(Dimension::FromString("1px"));
1105 layoutProperty->SetOverlayOffset(overlayOffsetX, overlayOffsetY);
1106 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1107
1108 /**
1109 * @tc.steps3 Call UpdateFlexBasis with overlayOffsetX and overlayOffsetY.
1110 @tc.expect: overlayOffsetX_ == overlayOffsetX and overlayOffsetY_ == overlayOffsetY
1111 */
1112 overlayOffsetX = std::make_optional<Dimension>(Dimension::FromString("2px"));
1113 overlayOffsetY = std::make_optional<Dimension>(Dimension::FromString("2px"));
1114 layoutProperty->SetOverlayOffset(overlayOffsetX, overlayOffsetY);
1115 EXPECT_EQ(layoutProperty->overlayOffsetX_, overlayOffsetX.value());
1116 EXPECT_EQ(layoutProperty->overlayOffsetY_, overlayOffsetY.value());
1117
1118 /**
1119 * @tc.steps3 Call UpdateFlexBasis with overlayOffsetX and overlayOffsetY.
1120 @tc.expect: overlayOffsetX_ == overlayOffsetX and overlayOffsetY_ == overlayOffsetY
1121 */
1122 overlayOffsetX = std::nullopt;
1123 overlayOffsetY = std::nullopt;
1124 layoutProperty->SetOverlayOffset(overlayOffsetX, overlayOffsetY);
1125 EXPECT_EQ(layoutProperty->overlayOffsetX_, Dimension::FromString("0.0px"));
1126 EXPECT_EQ(layoutProperty->overlayOffsetY_, Dimension::FromString("0.0px"));
1127 }
1128
1129 /**
1130 * @tc.name: UpdateAllGeometryTransition001
1131 * @tc.desc: Test cast to UpdateAllGeometryTransition
1132 * @tc.type: FUNC
1133 */
1134 HWTEST_F(LayoutPropertyTestNg, UpdateAllGeometryTransition001, TestSize.Level1)
1135 {
1136 /**
1137 * @tc.steps1 Create a layoutProperty.
1138 */
1139 auto parent = FrameNode::CreateFrameNode("parentNode", 0, AceType::MakeRefPtr<Pattern>());
1140 parent->GetLayoutProperty()->UpdateGeometryTransition("parent", true, true);
1141
1142 auto child = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>());
1143 child->GetLayoutProperty()->UpdateGeometryTransition("child", false, true);
1144 child->MountToParent(parent);
1145
1146 LayoutProperty::UpdateAllGeometryTransition(parent);
1147 EXPECT_TRUE(child->GetLayoutProperty()->GetGeometryTransition());
1148 }
1149
1150 /**
1151 * @tc.name: CreateMargin001
1152 * @tc.desc: Test cast to CreateMargin
1153 * @tc.type: FUNC
1154 */
1155 HWTEST_F(LayoutPropertyTestNg, CreateMargin001, TestSize.Level1)
1156 {
1157 /**
1158 * @tc.steps1 Create a layoutProperty.
1159 */
1160 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1161
1162 /**
1163 * @tc.steps2: call CreateMargin, push layoutConstraint_ null.
1164 * @tc.expected: Return margin is nullopt.
1165 */
1166 PaddingPropertyF margin = layoutProperty->CreateMargin();
1167 EXPECT_EQ(margin.top, std::nullopt);
1168 EXPECT_EQ(margin.bottom, std::nullopt);
1169
1170 /**
1171 * @tc.steps3: call CreatePaddingAndBorderWithDefault, push layoutConstraint_is null.
1172 * @tc.expected: Return paddingPropertyF left == 1.0 + 3.0
1173 */
1174 layoutProperty->margin_ = std::make_unique<MarginProperty>();
1175
1176 /**
1177 * @tc.steps4: call CreateMargin, push layoutConstraint_ null.
1178 * @tc.expected: Return margin is 0.
1179 */
1180 margin = layoutProperty->CreateMargin();
1181 EXPECT_FALSE(layoutProperty->layoutConstraint_.has_value());
1182 EXPECT_EQ(margin.top, std::nullopt);
1183 EXPECT_EQ(margin.bottom, std::nullopt);
1184 }
1185
1186 /**
1187 * @tc.name: GetAspectRatio001
1188 * @tc.desc: Test cast to GetAspectRatio
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(LayoutPropertyTestNg, GetAspectRatio001, TestSize.Level1)
1192 {
1193 /**
1194 * @tc.steps1 Create a layoutProperty.
1195 */
1196 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1197
1198 /**
1199 * @tc.steps2: set magicItemProperty_ is null.
1200 */
1201
1202 /**
1203 * @tc.steps4: call GetAspectRatio.
1204 * @tc.expected: Return fTemp is 0.
1205 */
1206 float fTemp = layoutProperty->GetAspectRatio();
1207 EXPECT_EQ(fTemp, 0.0f);
1208 }
1209
1210 /**
1211 * @tc.name: UpdateAspectRatio001
1212 * @tc.desc: Test cast to UpdateAspectRatio
1213 * @tc.type: FUNC
1214 */
1215 HWTEST_F(LayoutPropertyTestNg, UpdateAspectRatio001, TestSize.Level1)
1216 {
1217 /**
1218 * @tc.steps1 Create a layoutProperty.
1219 */
1220 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1221
1222 /**
1223 * @tc.steps2: create magicItemProperty_.
1224 */
1225 layoutProperty->magicItemProperty_.propAspectRatio = 1.0f;
1226
1227 /**
1228 * @tc.steps3: call UpdateAspectRatio.
1229 * @tc.expected: Update false and propertyChangeFlag_ is still PROPERTY_UPDATE_NORMAL.
1230 */
1231 layoutProperty->UpdateAspectRatio(1.0f);
1232 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1233 }
1234
1235 /**
1236 * @tc.name: UpdateAspectRatio002
1237 * @tc.desc: Test cast to UpdateAspectRatio
1238 * @tc.type: FUNC
1239 */
1240 HWTEST_F(LayoutPropertyTestNg, UpdateAspectRatio002, TestSize.Level1)
1241 {
1242 /**
1243 * @tc.steps1 Create a layoutProperty.
1244 */
1245 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1246
1247 /**
1248 * @tc.steps2: call UpdateAspectRatio.
1249 * @tc.expected: Update true and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1250 */
1251 layoutProperty->UpdateAspectRatio(1.0f);
1252 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1253 }
1254
1255 /**
1256 * @tc.name: ResetAspectRatio001
1257 * @tc.desc: Test cast to ResetAspectRatio
1258 * @tc.type: FUNC
1259 */
1260 HWTEST_F(LayoutPropertyTestNg, ResetAspectRatio001, TestSize.Level1)
1261 {
1262 /**
1263 * @tc.steps1 Create a layoutProperty.
1264 */
1265 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1266 layoutProperty->ResetAspectRatio();
1267
1268 /**
1269 * @tc.steps2: create magicItemProperty_.
1270 */
1271
1272 /**
1273 * @tc.steps3: call ResetAspectRatio.
1274 * @tc.expected: Reset success and propertyChangeFlag_ is still PROPERTY_UPDATE_NORMAL.
1275 */
1276 layoutProperty->ResetAspectRatio();
1277 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1278 EXPECT_FALSE(layoutProperty->magicItemProperty_.propAspectRatio.has_value());
1279
1280 /**
1281 * @tc.steps4: create propAspectRatio.
1282 */
1283 layoutProperty->magicItemProperty_.propAspectRatio = 1.0f;
1284
1285 /**
1286 * @tc.steps5: call ResetAspectRatio.
1287 * @tc.expected: Reset success and propertyChangeFlag_ is still PROPERTY_UPDATE_NORMAL.
1288 */
1289 layoutProperty->ResetAspectRatio();
1290 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1291 EXPECT_FALSE(layoutProperty->magicItemProperty_.propAspectRatio.has_value());
1292 }
1293
1294 /**
1295 * @tc.name: UpdateAllGeometryTransition002
1296 * @tc.desc: Test cast to UpdateAllGeometryTransition
1297 * @tc.type: FUNC
1298 */
1299 HWTEST_F(LayoutPropertyTestNg, UpdateAllGeometryTransition002, TestSize.Level1)
1300 {
1301 /**
1302 * @tc.steps1 Create a layoutProperty.
1303 */
1304 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1305
1306 /**
1307 * @tc.steps2 Create a weakparent.
1308 * @tc.expected: GetHost is not null
1309 */
1310 RefPtr<FrameNode> parent = FrameNode::CreateFrameNode("parentNode", 0, AceType::MakeRefPtr<Pattern>());
1311 WeakPtr<FrameNode> weakparent = AceType::WeakClaim(AceType::RawPtr(parent));
1312 layoutProperty->host_ = weakparent;
1313 EXPECT_NE(layoutProperty->GetHost(), nullptr);
1314
1315 /**
1316 * @tc.steps3 Create a weakGeo.
1317 * @tc.expected: GetGeometryTransition is not null
1318 */
1319 RefPtr<GeometryTransition> geo = AceType::MakeRefPtr<GeometryTransition>("test", true, true);
1320 WeakPtr<GeometryTransition> weakGeo = AceType::WeakClaim(AceType::RawPtr(geo));
1321 layoutProperty->geometryTransition_ = weakGeo;
1322 EXPECT_NE(layoutProperty->GetGeometryTransition(), nullptr);
1323
1324 /**
1325 * @tc.steps4 call UpdateGeometryTransition.
1326 * @tc.expected: geometryTransition_ is Changed to new
1327 */
1328 SystemProperties::debugEnabled_ = true;
1329 layoutProperty->UpdateGeometryTransition("test1", true, true);
1330 EXPECT_EQ(layoutProperty->geometryTransition_.Upgrade()->id_, "test1");
1331 }
1332
1333 /**
1334 * @tc.name: UpdateOuterBorderWidth001
1335 * @tc.desc: Test cast to UpdateOuterBorderWidth
1336 * @tc.type: FUNC
1337 */
1338 HWTEST_F(LayoutPropertyTestNg, UpdateOuterBorderWidth001, TestSize.Level1)
1339 {
1340 /**
1341 * @tc.steps1 Create a layoutProperty.
1342 */
1343 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1344
1345 /**
1346 * @tc.steps2: call UpdateOuterBorderWidth.
1347 * @tc.expected: Update false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1348 */
1349 BorderWidthProperty borderWidth;
1350 layoutProperty->UpdateOuterBorderWidth(borderWidth);
1351 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1352
1353 /**
1354 * @tc.steps3: create borderWidth_ and call UpdateOuterBorderWidth.
1355 * @tc.expected: Update true and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1356 */
1357 layoutProperty->outerBorderWidth_ = std::make_unique<BorderWidthProperty>();
1358 layoutProperty->outerBorderWidth_->leftDimen = Dimension(1.0f, DimensionUnit::PX);
1359 borderWidth.leftDimen = Dimension(2.0f, DimensionUnit::FP);
1360 layoutProperty->UpdateOuterBorderWidth(borderWidth);
1361 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1362 EXPECT_EQ(layoutProperty->outerBorderWidth_->leftDimen, Dimension(2.0f, DimensionUnit::FP));
1363 }
1364
1365 /**
1366 * @tc.name: ClearUserDefinedIdealSize001
1367 * @tc.desc: Test cast to ClearUserDefinedIdealSize
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(LayoutPropertyTestNg, ClearUserDefinedIdealSize001, TestSize.Level1)
1371 {
1372 /**
1373 * @tc.steps1 Create a layoutProperty.
1374 */
1375 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1376
1377 /**
1378 * @tc.steps2: call ClearUserDefinedIdealSize.
1379 * @tc.expected: Clear false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1380 */
1381 layoutProperty->ClearUserDefinedIdealSize(true, true);
1382 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1383
1384 /**
1385 * @tc.steps2: create calcLayoutConstraint_ and call ClearUserDefinedIdealSize.
1386 * @tc.expected: Clear false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1387 */
1388 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1389 layoutProperty->ClearUserDefinedIdealSize(true, true);
1390 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1391
1392 /**
1393 * @tc.steps3: set selfIdealSize.
1394 * @tc.expected: selfIdealSize has value is true.
1395 */
1396 auto width = CalcLength::FromString("10px");
1397 auto height = CalcLength::FromString("10px");
1398 CalcSize calcSize(width, height);
1399 layoutProperty->calcLayoutConstraint_->UpdateSelfIdealSizeWithCheck(calcSize);
1400 EXPECT_TRUE(layoutProperty->calcLayoutConstraint_->selfIdealSize.has_value());
1401
1402 /**
1403 * @tc.steps4: call ClearUserDefinedIdealSize.
1404 * @tc.expected: Clear success and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1405 */
1406 layoutProperty->ClearUserDefinedIdealSize(true, true);
1407 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1408 }
1409
1410 /**
1411 * @tc.name: UpdateMarginSelfIdealSize001
1412 * @tc.desc: Test cast to UpdateMarginSelfIdealSize
1413 * @tc.type: FUNC
1414 */
1415 HWTEST_F(LayoutPropertyTestNg, UpdateMarginSelfIdealSize001, TestSize.Level1)
1416 {
1417 /**
1418 * @tc.steps1 Create a layoutProperty.
1419 */
1420 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1421
1422 /**
1423 * @tc.steps2: call UpdateMarginSelfIdealSize.
1424 * @tc.expected: update true and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1425 */
1426 SizeF calcSize(1.0f, 2.0f);
1427 layoutProperty->UpdateMarginSelfIdealSize(calcSize);
1428 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1429
1430 /**
1431 * @tc.steps2: create calcLayoutConstraint_ and call ClearUserDefinedIdealSize.
1432 * @tc.expected: update false and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1433 */
1434 layoutProperty->layoutConstraint_ = LayoutConstraintF();
1435 layoutProperty->UpdateMarginSelfIdealSize(calcSize);
1436 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1437
1438 /**
1439 * @tc.steps3: set selfIdealSize.
1440 */
1441 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1442 OptionalSize<float> opSizeTemp(1.0f, 2.0f);
1443 layoutProperty->layoutConstraint_->selfIdealSize = opSizeTemp;
1444
1445 /**
1446 * @tc.steps4: call UpdateMarginSelfIdealSize.
1447 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1448 */
1449 layoutProperty->UpdateMarginSelfIdealSize(calcSize);
1450 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1451 }
1452
1453 /**
1454 * @tc.name: ResetCalcMinSize003
1455 * @tc.desc: Test cast to ResetCalcMinSize
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(LayoutPropertyTestNg, ResetCalcMinSize003, TestSize.Level1)
1459 {
1460 /**
1461 * @tc.steps1 Create a layoutProperty.
1462 */
1463 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1464
1465 /**
1466 * @tc.steps2: call UpdateMarginSelfIdealSize.
1467 * @tc.expected: update false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1468 */
1469 layoutProperty->ResetCalcMinSize();
1470 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1471
1472 /**
1473 * @tc.steps2: create calcLayoutConstraint_ and call ClearUserDefinedIdealSize.
1474 * @tc.expected: update false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1475 */
1476 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1477 layoutProperty->ResetCalcMinSize();
1478 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1479
1480 /**
1481 * @tc.steps3: set selfIdealSize.
1482 */
1483 layoutProperty->calcLayoutConstraint_->minSize = CALC_SIZE;
1484
1485 /**
1486 * @tc.steps4: call UpdateMarginSelfIdealSize.
1487 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1488 */
1489 layoutProperty->ResetCalcMinSize();
1490 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1491 }
1492
1493 /**
1494 * @tc.name: ResetCalcMaxSize003
1495 * @tc.desc: Test cast to ResetCalcMaxSize
1496 * @tc.type: FUNC
1497 */
1498 HWTEST_F(LayoutPropertyTestNg, ResetCalcMaxSize003, TestSize.Level1)
1499 {
1500 /**
1501 * @tc.steps1 Create a layoutProperty.
1502 */
1503 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1504
1505 /**
1506 * @tc.steps2: call UpdateMarginSelfIdealSize.
1507 * @tc.expected: update false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1508 */
1509 layoutProperty->ResetCalcMaxSize();
1510 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1511
1512 /**
1513 * @tc.steps2: create calcLayoutConstraint_ and call ClearUserDefinedIdealSize.
1514 * @tc.expected: update false and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1515 */
1516 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1517 layoutProperty->ResetCalcMaxSize();
1518 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1519
1520 /**
1521 * @tc.steps3: set selfIdealSize.
1522 */
1523 layoutProperty->calcLayoutConstraint_->maxSize = CALC_SIZE;
1524
1525 /**
1526 * @tc.steps4: call UpdateMarginSelfIdealSize.
1527 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1528 */
1529 layoutProperty->ResetCalcMaxSize();
1530 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1531 }
1532
1533 /**
1534 * @tc.name: UpdateFlexGrow002
1535 * @tc.desc: Test cast to UpdateFlexGrow
1536 * @tc.type: FUNC
1537 */
1538 HWTEST_F(LayoutPropertyTestNg, UpdateFlexGrow002, TestSize.Level1)
1539 {
1540 /**
1541 * @tc.steps1 Create a layoutProperty.
1542 */
1543 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1544
1545 /**
1546 * @tc.steps2 Call ResetFlexGrow without flexItemProperty_.
1547 */
1548 layoutProperty->UpdateFlexGrow(1.0);
1549
1550 /**
1551 * @tc.steps3 Call ResetFlexGrow with flexItemProperty_.
1552 */
1553 layoutProperty->UpdateFlexGrow(1.0);
1554 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1555
1556 /**
1557 * @tc.steps4 reset propertyChangeFlag_ and call UpdateFlexGrow.
1558 * @tc.expected: update fail and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1559 */
1560 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1561 layoutProperty->flexItemProperty_->propFlexGrow = 1.0f;
1562 layoutProperty->UpdateFlexGrow(1.0);
1563 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1564
1565 /**
1566 * @tc.steps4 call UpdateFlexGrow.
1567 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1568 */
1569 layoutProperty->UpdateFlexGrow(2.0);
1570 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1571 EXPECT_EQ(layoutProperty->flexItemProperty_->propFlexGrow, 2.0f);
1572 }
1573
1574 /**
1575 * @tc.name: ResetFlexGrow002
1576 * @tc.desc: Test cast to ResetFlexGrow
1577 * @tc.type: FUNC
1578 */
1579 HWTEST_F(LayoutPropertyTestNg, ResetFlexGrow002, TestSize.Level1)
1580 {
1581 /**
1582 * @tc.steps1 Create a layoutProperty.
1583 */
1584 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1585
1586 /**
1587 * @tc.steps2 Call ResetFlexGrow without flexItemProperty_.
1588 */
1589 layoutProperty->ResetFlexGrow();
1590 EXPECT_FALSE(layoutProperty->flexItemProperty_);
1591
1592 /**
1593 * @tc.steps3 Call ResetFlexGrow with flexItemProperty_.
1594 * @tc.expected: propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1595 */
1596 layoutProperty->flexItemProperty_ = std::make_unique<FlexItemProperty>();
1597 layoutProperty->ResetFlexGrow();
1598 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1599
1600 /**
1601 * @tc.steps4 set propFlexGrow and call ResetFlexGrow.
1602 * @tc.expected: propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1603 */
1604 layoutProperty->flexItemProperty_->propFlexGrow = 2.0f;
1605 layoutProperty->ResetFlexGrow();
1606 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1607 }
1608
1609 /**
1610 * @tc.name: UpdateFlexShrink001
1611 * @tc.desc: Test cast to UpdateFlexShrink
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(LayoutPropertyTestNg, UpdateFlexShrink001, TestSize.Level1)
1615 {
1616 /**
1617 * @tc.steps1 Create a layoutProperty.
1618 */
1619 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1620
1621 /**
1622 * @tc.steps2 Call ResetFlexGrow without flexItemProperty_.
1623 */
1624 layoutProperty->UpdateFlexShrink(1.0);
1625
1626 /**
1627 * @tc.steps3 Call ResetFlexGrow with flexItemProperty_.
1628 */
1629 layoutProperty->UpdateFlexShrink(1.0);
1630 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1631
1632 /**
1633 * @tc.steps4 reset propertyChangeFlag_ and call UpdateFlexGrow.
1634 * @tc.expected: update fail and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1635 */
1636 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1637 layoutProperty->flexItemProperty_->propFlexShrink = 1.0f;
1638 layoutProperty->UpdateFlexShrink(1.0);
1639 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1640
1641 /**
1642 * @tc.steps4 call UpdateFlexGrow.
1643 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1644 */
1645 layoutProperty->UpdateFlexShrink(2.0);
1646 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1647 EXPECT_EQ(layoutProperty->flexItemProperty_->propFlexShrink, 2.0f);
1648 }
1649
1650 /**
1651 * @tc.name: ResetFlexShrink002
1652 * @tc.desc: Test cast to ResetFlexShrink
1653 * @tc.type: FUNC
1654 */
1655 HWTEST_F(LayoutPropertyTestNg, ResetFlexShrink002, TestSize.Level1)
1656 {
1657 /**
1658 * @tc.steps1 Create a layoutProperty.
1659 */
1660 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1661
1662 /**
1663 * @tc.steps2 Call ResetFlexShrink without flexItemProperty_.
1664 */
1665 layoutProperty->ResetFlexShrink();
1666 EXPECT_FALSE(layoutProperty->flexItemProperty_);
1667
1668 /**
1669 * @tc.steps3 Call ResetFlexShrink with flexItemProperty_.
1670 * @tc.expected: propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1671 */
1672 layoutProperty->flexItemProperty_ = std::make_unique<FlexItemProperty>();
1673 layoutProperty->ResetFlexShrink();
1674 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1675
1676 /**
1677 * @tc.steps3 Set propFlexShrink and Call ResetFlexShrink with flexItemProperty_.
1678 * @tc.expected: propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1679 */
1680 layoutProperty->flexItemProperty_->propFlexShrink = 1.0f;
1681 layoutProperty->ResetFlexShrink();
1682 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1683 }
1684
1685 /**
1686 * @tc.name: UpdateFlexBasis002
1687 * @tc.desc: Test cast to UpdateFlexBasis
1688 * @tc.type: FUNC
1689 */
1690 HWTEST_F(LayoutPropertyTestNg, UpdateFlexBasis002, TestSize.Level1)
1691 {
1692 /**
1693 * @tc.steps1 Create a layoutProperty.
1694 */
1695 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1696
1697 /**
1698 * @tc.steps2 Call ResetFlexGrow without flexItemProperty_.
1699 */
1700 Dimension dim(1.0, DimensionUnit::PX);
1701 layoutProperty->UpdateFlexBasis(dim);
1702
1703 /**
1704 * @tc.steps3 Call ResetFlexGrow with flexItemProperty_.
1705 */
1706 layoutProperty->UpdateFlexBasis(dim);
1707 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL | PROPERTY_UPDATE_MEASURE);
1708
1709 /**
1710 * @tc.steps4 reset propertyChangeFlag_ and call UpdateFlexGrow.
1711 * @tc.expected: update fail and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1712 */
1713 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1714 layoutProperty->flexItemProperty_->propFlexBasis = dim;
1715 layoutProperty->UpdateFlexBasis(dim);
1716 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1717
1718 /**
1719 * @tc.steps4 call UpdateFlexGrow.
1720 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1721 */
1722 layoutProperty->UpdateFlexBasis(Dimension(2.0, DimensionUnit::VP));
1723 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1724 EXPECT_EQ(layoutProperty->flexItemProperty_->propFlexBasis, Dimension(2.0, DimensionUnit::VP));
1725 }
1726
1727 /**
1728 * @tc.name: UpdateAlignRules001
1729 * @tc.desc: Test cast to UpdateAlignRules
1730 * @tc.type: FUNC
1731 */
1732 HWTEST_F(LayoutPropertyTestNg, UpdateAlignRules001, TestSize.Level1)
1733 {
1734 /**
1735 * @tc.steps1 Create a layoutProperty.
1736 */
1737 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1738
1739 /**
1740 * @tc.steps2 Call UpdateAlignRules without flexItemProperty_.
1741 * @tc.expected: update success and propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE.
1742 */
1743 std::map<AlignDirection, AlignRule> firstItemAlignRules;
1744 AlignRule alignRule;
1745 alignRule.anchor = "test";
1746 alignRule.horizontal = HorizontalAlign::START;
1747 firstItemAlignRules[AlignDirection::LEFT] = alignRule;
1748
1749 layoutProperty->UpdateAlignRules(firstItemAlignRules);
1750 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_MEASURE);
1751
1752 /**
1753 * @tc.steps2 Call ResetFlexGrow again with flexItemProperty_.
1754 * @tc.expected: update fail and propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL.
1755 */
1756 layoutProperty->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1757 layoutProperty->UpdateAlignRules(firstItemAlignRules);
1758 EXPECT_EQ(layoutProperty->propertyChangeFlag_, PROPERTY_UPDATE_NORMAL);
1759 }
1760
1761 /**
1762 * @tc.name: GetPercentSensitive001
1763 * @tc.desc: Test cast to GetPercentSensitive
1764 * @tc.type: FUNC
1765 */
1766 HWTEST_F(LayoutPropertyTestNg, GetPercentSensitive001, TestSize.Level1)
1767 {
1768 /**
1769 * @tc.steps1 Create a layoutProperty.
1770 */
1771 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1772
1773 /**
1774 * @tc.steps2 Call GetPercentSensitive without contentConstraint_.
1775 */
1776 std::pair<bool, bool> res = layoutProperty->GetPercentSensitive();
1777 EXPECT_EQ(res.first, false);
1778 EXPECT_EQ(res.second, false);
1779
1780 /**
1781 * @tc.steps2 ReCall GetPercentSensitive with contentConstraint_ without calcLayoutConstraint_.
1782 */
1783 LayoutConstraintF layoutConstraintF;
1784 layoutConstraintF.maxSize = { 1.0, 1.0 };
1785 layoutProperty->contentConstraint_ = layoutConstraintF;
1786 res = layoutProperty->GetPercentSensitive();
1787 EXPECT_EQ(res.first, false);
1788 EXPECT_EQ(res.second, false);
1789
1790 /**
1791 * @tc.steps3 ReCall GetPercentSensitive with contentConstraint_ without calcLayoutConstraint_.
1792 */
1793 layoutConstraintF.maxSize = { Infinity<float>() / 2.0f, Infinity<float>() / 2.0f };
1794 layoutProperty->contentConstraint_ = layoutConstraintF;
1795 res = layoutProperty->GetPercentSensitive();
1796 EXPECT_EQ(res.first, false);
1797 EXPECT_EQ(res.second, false);
1798
1799 /**
1800 * @tc.steps4 ReCall GetPercentSensitive with contentConstraint_ with calcLayoutConstraint_.
1801 */
1802 CalcLength calcTemp("test1");
1803 calcTemp.dimension_ = Dimension(2.0f, DimensionUnit::PERCENT);
1804 layoutProperty->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1805 CalcSize cTemp;
1806 cTemp.width_ = calcTemp;
1807 cTemp.height_ = calcTemp;
1808 layoutProperty->calcLayoutConstraint_->selfIdealSize = cTemp;
1809 res = layoutProperty->GetPercentSensitive();
1810 EXPECT_EQ(res.first, true);
1811 EXPECT_EQ(res.second, true);
1812 }
1813
1814 /**
1815 * @tc.name: UpdatePercentSensitive001
1816 * @tc.desc: Test cast to UpdatePercentSensitive
1817 * @tc.type: FUNC
1818 */
1819 HWTEST_F(LayoutPropertyTestNg, UpdatePercentSensitive001, TestSize.Level1)
1820 {
1821 /**
1822 * @tc.steps1 Create a layoutProperty.
1823 */
1824 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1825
1826 /**
1827 * @tc.steps2 Call UpdatePercentSensitive without contentConstraint_.
1828 */
1829 std::pair<bool, bool> res = layoutProperty->UpdatePercentSensitive(false, false);
1830 EXPECT_EQ(res.first, false);
1831 EXPECT_EQ(res.second, false);
1832
1833 /**
1834 * @tc.steps3 ReCall UpdatePercentSensitive with contentConstraint_.
1835 */
1836 LayoutConstraintF layoutConstraintF;
1837 layoutConstraintF.maxSize = { 1.0, 1.0 };
1838 layoutProperty->contentConstraint_ = layoutConstraintF;
1839 res = layoutProperty->UpdatePercentSensitive(false, false);
1840 EXPECT_EQ(res.first, false);
1841 EXPECT_EQ(res.second, false);
1842
1843 /**
1844 * @tc.steps4 ReCall UpdatePercentSensitive with contentConstraint_ .
1845 */
1846 layoutConstraintF.maxSize = { Infinity<float>() / 2.0f, Infinity<float>() / 2.0f };
1847 layoutProperty->contentConstraint_ = layoutConstraintF;
1848 res = layoutProperty->UpdatePercentSensitive(false, false);
1849 EXPECT_EQ(res.first, false);
1850 EXPECT_EQ(res.second, false);
1851
1852 /**
1853 * @tc.steps5 ReCall UpdatePercentSensitive with contentConstraint_.
1854 */
1855 layoutConstraintF.maxSize = { Infinity<float>() / 2.0f, Infinity<float>() / 2.0f };
1856 layoutProperty->contentConstraint_ = layoutConstraintF;
1857 res = layoutProperty->UpdatePercentSensitive(true, true);
1858 EXPECT_EQ(res.first, true);
1859 EXPECT_EQ(res.second, true);
1860 }
1861
1862 /**
1863 * @tc.name: ConstraintEqual001
1864 * @tc.desc: Test cast to ConstraintEqual
1865 * @tc.type: FUNC
1866 */
1867 HWTEST_F(LayoutPropertyTestNg, ConstraintEqual001, TestSize.Level1)
1868 {
1869 /**
1870 * @tc.steps1 Create a layoutProperty.
1871 */
1872 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1873
1874 LayoutConstraintF preLayoutTemp;
1875 LayoutConstraintF preContentTemp;
1876
1877 /**
1878 * @tc.steps2 Call ConstraintEqual without preLayoutTemp,preLayoutTemp.
1879 */
1880 bool bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1065
1881 EXPECT_FALSE(bResult);
1882
1883 /**
1884 * @tc.steps3 Call ConstraintEqual with layoutConstraint_.
1885 */
1886 layoutProperty->layoutConstraint_ = preLayoutTemp;
1887 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1068
1888 EXPECT_FALSE(bResult);
1889
1890 /**
1891 * @tc.steps4 Call ConstraintEqual with contentConstraint_.
1892 */
1893 preLayoutTemp.maxSize.width_ = Infinity<float>() / 2.0f;
1894 preLayoutTemp.maxSize.height_ = Infinity<float>() / 2.0f;
1895 layoutProperty->contentConstraint_ = preContentTemp;
1896 layoutProperty->widthPercentSensitive_ = false;
1897 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1073
1898 EXPECT_TRUE(bResult);
1899
1900 /**
1901 * @tc.steps5 Call ConstraintEqual with contentConstraint_ and Width true Height false.
1902 */
1903 layoutProperty->widthPercentSensitive_ = true;
1904 layoutProperty->heightPercentSensitive_ = false;
1905 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1078
1906 EXPECT_TRUE(bResult);
1907
1908 /**
1909 * @tc.steps6 Call ConstraintEqual with contentConstraint_and Width true Height true.
1910 */
1911 layoutProperty->heightPercentSensitive_ = true;
1912 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1080
1913 EXPECT_FALSE(bResult);
1914 }
1915
1916 /**
1917 * @tc.name: ConstraintEqual002
1918 * @tc.desc: Test cast to ConstraintEqual002
1919 * @tc.type: FUNC
1920 */
1921 HWTEST_F(LayoutPropertyTestNg, ConstraintEqual002, TestSize.Level1)
1922 {
1923 /**
1924 * @tc.steps1 Create a layoutProperty.
1925 */
1926 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1927
1928 LayoutConstraintF preLayoutTemp;
1929 LayoutConstraintF preContentTemp;
1930
1931 /**
1932 * @tc.steps2 Call ConstraintEqual without preLayoutTemp,preLayoutTemp.
1933 */
1934 bool bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1065
1935 EXPECT_FALSE(bResult);
1936
1937 /**
1938 * @tc.steps3 Call ConstraintEqual with layoutConstraint_.
1939 */
1940 layoutProperty->layoutConstraint_ = preLayoutTemp;
1941 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1068
1942 EXPECT_FALSE(bResult);
1943
1944 /**
1945 * @tc.steps4 Call ConstraintEqual with contentConstraint_.
1946 */
1947 preContentTemp.maxSize.width_ = Infinity<float>() / 2.0f;
1948 preContentTemp.maxSize.height_ = Infinity<float>() / 2.0f;
1949 layoutProperty->contentConstraint_ = preContentTemp;
1950 layoutProperty->layoutConstraint_ = preLayoutTemp;
1951 layoutProperty->widthPercentSensitive_ = false;
1952 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1073
1953 EXPECT_TRUE(bResult);
1954
1955 /**
1956 * @tc.steps5 Call ConstraintEqual with contentConstraint_ and Width true Height false.
1957 */
1958 layoutProperty->widthPercentSensitive_ = true;
1959 layoutProperty->heightPercentSensitive_ = false;
1960 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1078
1961 EXPECT_TRUE(bResult);
1962
1963 /**
1964 * @tc.steps6 Call ConstraintEqual with contentConstraint_and Width true Height true.
1965 */
1966 layoutProperty->heightPercentSensitive_ = true;
1967 bResult = layoutProperty->ConstraintEqual(preLayoutTemp, preContentTemp); // 1080
1968 EXPECT_TRUE(bResult);
1969 }
1970 } // namespace OHOS::Ace::NG
1971