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