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 #include "base/utils/utils.h"
21 #define protected public
22 #define private public
23 
24 #include "test/mock/core/pipeline/mock_pipeline_context.h"
25 
26 #include "base/geometry/ng/size_t.h"
27 #include "core/components_ng/base/frame_node.h"
28 #include "core/components_ng/base/view_stack_processor.h"
29 #include "core/components_ng/layout/box_layout_algorithm.h"
30 #include "core/components_ng/layout/layout_wrapper.h"
31 #include "core/components_ng/layout/layout_wrapper_builder.h"
32 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
33 #include "core/components_ng/property/measure_property.h"
34 #include "core/components_ng/property/measure_utils.h"
35 #include "core/components_ng/property/property.h"
36 #undef private
37 #undef protected
38 
39 using namespace testing;
40 using namespace testing::ext;
41 
42 namespace OHOS::Ace::NG {
43 namespace {
44 const float RK356_WIDTH = 720.0f;
45 const float RK356_HEIGHT = 1136.0f;
46 
47 const float ROW_HEIGHT = 120.0f;
48 const float NOPADDING = 0.0f;
49 
50 const float BIG_ITEM_WIDTH = 180.0f;
51 const float BIG_ITEM_HEIGHT = 75.0f;
52 const float ZERO = 0.0f;
53 
54 const float CONTAINER_WIDTH = 300.0f;
55 const float CONTAINER_HEIGHT = 300.0f;
56 
57 const OffsetF OFFSET_TOP_LEFT = OffsetF(ZERO, ZERO);
58 const SizeF FRAME_SIZE(CONTAINER_WIDTH, CONTAINER_HEIGHT);
59 
60 const SizeF CONTAINER_SIZE(RK356_WIDTH, RK356_HEIGHT);
61 const SizeF BIG_ITEM_SIZE(BIG_ITEM_WIDTH, BIG_ITEM_HEIGHT);
62 
CreatlayoutWrapper()63 RefPtr<LayoutWrapperNode> CreatlayoutWrapper()
64 {
65     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
66     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
67 
68     RefPtr<LayoutWrapperNode> layoutWrapper =
69         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
70     return layoutWrapper;
71 }
72 
CreatChildlayoutWrapper()73 RefPtr<LayoutWrapperNode> CreatChildlayoutWrapper()
74 {
75     auto firstFrameNode = FrameNode::CreateFrameNode("one", 1, AceType::MakeRefPtr<Pattern>());
76     RefPtr<GeometryNode> firstGeometryNode = AceType::MakeRefPtr<GeometryNode>();
77     firstGeometryNode->Reset();
78     RefPtr<LayoutWrapperNode> firstLayoutWrapper =
79         AceType::MakeRefPtr<LayoutWrapperNode>(firstFrameNode, firstGeometryNode, firstFrameNode->GetLayoutProperty());
80     return firstLayoutWrapper;
81 }
82 } // namespace
83 
84 class BoxLayoutAlgorithmTestNg : public testing::Test {
85 public:
SetUpTestCase()86     static void SetUpTestCase()
87     {
88         MockPipelineContext::SetUp();
89     }
TearDownTestCase()90     static void TearDownTestCase()
91     {
92         MockPipelineContext::TearDown();
93     }
94 };
95 
96 /**
97  * @tc.name: BoxLayoutAlgorithmTest_Measure001
98  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_Measure001, TestSize.Level1)
102 {
103     /**
104      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
105      */
106     auto layoutWrapper = CreatlayoutWrapper();
107 
108     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
109     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
110     ASSERT_NE(rowLayoutPattern, nullptr);
111     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
112     ASSERT_NE(rowLayoutAlgorithm, nullptr);
113     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
114 
115     /**
116      * @tc.steps: step2. layout parameter initialization.
117      */
118     LayoutConstraintF parentLayoutConstraint;
119     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
120     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
121     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
122     PaddingProperty noPadding;
123     noPadding.left = CalcLength(NOPADDING);
124     noPadding.right = CalcLength(NOPADDING);
125     noPadding.top = CalcLength(NOPADDING);
126     noPadding.bottom = CalcLength(NOPADDING);
127 
128     /**
129      * @tc.steps: step3. Perform element updates.
130      */
131     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
132     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
133     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
134 
135     /**
136      * @tc.steps: step4. creat a childLayoutWrapper and add to layoutWrapper.
137      */
138     auto childLayoutWrapper = CreatChildlayoutWrapper();
139     layoutWrapper->AppendChild(childLayoutWrapper);
140     BoxLayoutAlgorithm boxLayoutAlgorithm;
141 
142     boxLayoutAlgorithm.Measure(AccessibilityManager::RawPtr(layoutWrapper));
143 
144     /**
145      * @tc.steps: step5. call SetIsLayoutFullScreen.
146      * @tc.expected: expect the pipe is return true.
147      */
148     PipelineBase::GetCurrentContext()->SetIsLayoutFullScreen(true);
149     auto pipe = PipelineContext::GetCurrentContext()->safeAreaManager_->isFullScreen_;
150     boxLayoutAlgorithm.Measure(AccessibilityManager::RawPtr(layoutWrapper));
151     EXPECT_FALSE(pipe);
152 }
153 
154 /**
155  * @tc.name: BoxLayoutAlgorithmTest_Measure002
156  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
157  * @tc.type: FUNC
158  */
159 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_Measure002, TestSize.Level1)
160 {
161     /**
162      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
163      */
164     auto layoutWrapper = CreatlayoutWrapper();
165 
166     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
167     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
168     ASSERT_NE(rowLayoutPattern, nullptr);
169     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
170     ASSERT_NE(rowLayoutAlgorithm, nullptr);
171     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
172 
173     /**
174      * @tc.steps: step2. layout parameter initialization.
175      */
176     LayoutConstraintF parentLayoutConstraint;
177     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
178     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
179     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
180     PaddingProperty noPadding;
181     noPadding.left = CalcLength(NOPADDING);
182     noPadding.right = CalcLength(NOPADDING);
183     noPadding.top = CalcLength(NOPADDING);
184     noPadding.bottom = CalcLength(NOPADDING);
185 
186     /**
187      * @tc.steps: step3. Perform element updates.
188      */
189     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
190     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
191     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
192     BoxLayoutAlgorithm boxLayoutAlgorithm;
193 
194     /**
195      * @tc.steps: step4. call SetIsLayoutFullScreen and SetIsAppWindow.
196      * @tc.expected: expect the pipe and pipe1 is return false.
197      */
198     PipelineBase::GetCurrentContext()->SetIsLayoutFullScreen(false);
199     PipelineBase::GetCurrentContext()->SetIsAppWindow(false);
200     auto pipe = PipelineContext::GetCurrentContext()->safeAreaManager_->isFullScreen_;
201     auto pipe1 = PipelineBase::GetCurrentContext()->isAppWindow_;
202     boxLayoutAlgorithm.Measure(AccessibilityManager::RawPtr(layoutWrapper));
203     EXPECT_FALSE(pipe);
204     EXPECT_FALSE(pipe1);
205 }
206 
207 /**
208  * @tc.name: BoxLayoutAlgorithmTest_Layout003
209  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
210  * @tc.type: FUNC
211  */
212 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_Layout003, TestSize.Level1)
213 {
214     /**
215      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
216      */
217     auto layoutWrapper = CreatlayoutWrapper();
218 
219     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
220     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
221     ASSERT_NE(rowLayoutPattern, nullptr);
222     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
223     ASSERT_NE(rowLayoutAlgorithm, nullptr);
224     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
225 
226     /**
227      * @tc.steps: step2. layout parameter initialization.
228      */
229     LayoutConstraintF parentLayoutConstraint;
230     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
231     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
232     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
233     PaddingProperty noPadding;
234     noPadding.left = CalcLength(NOPADDING);
235     noPadding.right = CalcLength(NOPADDING);
236     noPadding.top = CalcLength(NOPADDING);
237     noPadding.bottom = CalcLength(NOPADDING);
238 
239     /**
240      * @tc.steps: step3. Perform element updates.
241      */
242     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
243     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
244     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
245 
246     /**
247      * @tc.steps: step4. creat a childLayoutWrapper and add to layoutWrapper.
248      */
249     auto childLayoutWrapper = CreatChildlayoutWrapper();
250     layoutWrapper->AppendChild(childLayoutWrapper);
251     BoxLayoutAlgorithm boxLayoutAlgorithm;
252     boxLayoutAlgorithm.Layout(AccessibilityManager::RawPtr(layoutWrapper));
253 
254     /**
255      * @tc.steps: step5. call SetIsLayoutFullScreen and SetIsAppWindow.
256      * @tc.expected: expect the AppWindow and LayoutFullScreen is true.
257      */
258     PipelineBase::GetCurrentContext()->SetIsAppWindow(true);
259     PipelineBase::GetCurrentContext()->SetIsLayoutFullScreen(true);
260     auto LayoutFullScreen = PipelineContext::GetCurrentContext()->safeAreaManager_->isFullScreen_;
261     auto AppWindow = PipelineBase::GetCurrentContext()->isAppWindow_;
262     boxLayoutAlgorithm.PerformLayout(AccessibilityManager::RawPtr(layoutWrapper));
263     EXPECT_FALSE(LayoutFullScreen);
264     EXPECT_TRUE(AppWindow);
265 }
266 
267 /**
268  * @tc.name: BoxLayoutAlgorithmTest_Layout004
269  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
270  * @tc.type: FUNC
271  */
272 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_Layout004, TestSize.Level1)
273 {
274     /**
275      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
276      */
277     auto layoutWrapper = CreatlayoutWrapper();
278 
279     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
280     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
281     ASSERT_NE(rowLayoutPattern, nullptr);
282     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
283     ASSERT_NE(rowLayoutAlgorithm, nullptr);
284     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
285 
286     /**
287      * @tc.steps: step2. layout parameter initialization.
288      */
289     LayoutConstraintF parentLayoutConstraint;
290     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
291     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
292     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
293     PaddingProperty noPadding;
294     noPadding.left = CalcLength(NOPADDING);
295     noPadding.right = CalcLength(NOPADDING);
296     noPadding.top = CalcLength(NOPADDING);
297     noPadding.bottom = CalcLength(NOPADDING);
298 
299     /**
300      * @tc.steps: step3. Perform element updates.
301      */
302     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
303     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
304     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
305 
306     /**
307      * @tc.steps: step4. creat a childLayoutWrapper and add to layoutWrapper.
308      */
309     auto childLayoutWrapper = CreatChildlayoutWrapper();
310     layoutWrapper->AppendChild(childLayoutWrapper);
311     BoxLayoutAlgorithm boxLayoutAlgorithm;
312 
313     /**
314      * @tc.steps: step5. call SetIsLayoutFullScreen and SetIsAppWindow.
315      * @tc.expected: expect the pipe and pipe1 is return false.
316      */
317     PipelineBase::GetCurrentContext()->SetIsLayoutFullScreen(false);
318     PipelineBase::GetCurrentContext()->SetIsAppWindow(false);
319     boxLayoutAlgorithm.Layout(AccessibilityManager::RawPtr(layoutWrapper));
320     auto pipe = PipelineContext::GetCurrentContext()->safeAreaManager_->isFullScreen_;
321     auto pipe1 = PipelineBase::GetCurrentContext()->isAppWindow_;
322     EXPECT_FALSE(pipe);
323     EXPECT_FALSE(pipe1);
324 
325     PipelineBase::GetCurrentContext()->SetIsLayoutFullScreen(true);
326     PipelineBase::GetCurrentContext()->SetIsAppWindow(false);
327     boxLayoutAlgorithm.PerformLayout(AccessibilityManager::RawPtr(layoutWrapper));
328     auto pipe2 = PipelineContext::GetCurrentContext()->safeAreaManager_->isFullScreen_;
329     EXPECT_FALSE(pipe2);
330 }
331 
332 /**
333  * @tc.name: BoxLayoutAlgorithmTest_MeasureContent005
334  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
335  * @tc.type: FUNC
336  */
337 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_MeasureContent005, TestSize.Level1)
338 {
339     /**
340      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
341      */
342     auto layoutWrapper = CreatlayoutWrapper();
343 
344     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
345     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
346     ASSERT_NE(rowLayoutPattern, nullptr);
347     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
348     ASSERT_NE(rowLayoutAlgorithm, nullptr);
349     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
350 
351     /**
352      * @tc.steps: step2. layout parameter initialization.
353      */
354     LayoutConstraintF parentLayoutConstraint;
355     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
356     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
357     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
358     PaddingProperty noPadding;
359     noPadding.left = CalcLength(NOPADDING);
360     noPadding.right = CalcLength(NOPADDING);
361     noPadding.top = CalcLength(NOPADDING);
362     noPadding.bottom = CalcLength(NOPADDING);
363 
364     /**
365      * @tc.steps: step3. Perform element updates.
366      */
367     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
368     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
369     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
370 
371     /**
372      * @tc.steps: step5. call MeasureContent.
373      * @tc.expected: expect the host is null.
374      */
375     BoxLayoutAlgorithm boxLayoutAlgorithm;
376     auto host = layoutWrapper->GetHostNode();
377     boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
378     EXPECT_EQ(host, nullptr);
379 
380     /**
381      * @tc.steps: step6. call MeasureContent.
382      * @tc.expected: expect the host1 is not null.
383      */
384     layoutWrapper->hostNode_ = rowFrameNode;
385     boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
386     auto host1 = layoutWrapper->GetHostNode();
387     ASSERT_NE(host1, nullptr);
388 }
389 
390 /**
391  * @tc.name: BoxLayoutAlgorithmTest_PerformLayout006
392  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
393  * @tc.type: FUNC
394  */
395 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformLayout006, TestSize.Level1)
396 {
397     /**
398      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
399      */
400     auto layoutWrapper = CreatlayoutWrapper();
401 
402     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
403     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
404     ASSERT_NE(rowLayoutPattern, nullptr);
405     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
406     ASSERT_NE(rowLayoutAlgorithm, nullptr);
407     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
408 
409     /**
410      * @tc.steps: step2. layout parameter initialization.
411      */
412     LayoutConstraintF parentLayoutConstraint;
413     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
414     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
415     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
416     PaddingProperty noPadding;
417     noPadding.left = CalcLength(NOPADDING);
418     noPadding.right = CalcLength(NOPADDING);
419     noPadding.top = CalcLength(NOPADDING);
420     noPadding.bottom = CalcLength(NOPADDING);
421 
422     /**
423      * @tc.steps: step3. Perform element updates.
424      */
425     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
426     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
427     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
428 
429     /**
430      * @tc.steps: step4. creat a childLayoutWrapper and add to layoutWrapper.
431      */
432     auto childLayoutWrapper = CreatChildlayoutWrapper();
433     layoutWrapper->AppendChild(childLayoutWrapper);
434 
435     /**
436      * @tc.steps: step5. call PerformLayout.
437      * @tc.expected: expect the positionProperty_ is not null.
438      */
439     BoxLayoutAlgorithm boxLayoutAlgorithm;
440     layoutWrapper->GetLayoutProperty()->positionProperty_ = std::make_unique<PositionProperty>();
441     boxLayoutAlgorithm.PerformLayout(AccessibilityManager::RawPtr(layoutWrapper));
442     EXPECT_NE(layoutWrapper->GetLayoutProperty()->positionProperty_, nullptr);
443 
444     /**
445      * @tc.steps: step6. call PerformLayout.
446      * @tc.expected: expect the content_ is not null.
447      */
448     SizeF size { 0.1, 0.1 };
449     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
450     layoutWrapper->GetGeometryNode()->SetContentSize(size);
451     boxLayoutAlgorithm.PerformLayout(AccessibilityManager::RawPtr(layoutWrapper));
452     EXPECT_NE(layoutWrapper->GetGeometryNode()->content_, nullptr);
453 }
454 
455 /**
456  * @tc.name: BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList007
457  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
458  * @tc.type: FUNC
459  */
460 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList007, TestSize.Level1)
461 {
462     /**
463      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
464      */
465     auto layoutWrapper = CreatlayoutWrapper();
466 
467     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
468     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
469     ASSERT_NE(rowLayoutPattern, nullptr);
470     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
471     ASSERT_NE(rowLayoutAlgorithm, nullptr);
472     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
473 
474     /**
475      * @tc.steps: step2. layout parameter initialization.
476      */
477     LayoutConstraintF parentLayoutConstraint;
478     PaddingProperty noPadding;
479     noPadding.left = CalcLength(NOPADDING);
480     noPadding.right = CalcLength(NOPADDING);
481     noPadding.top = CalcLength(NOPADDING);
482     noPadding.bottom = CalcLength(NOPADDING);
483 
484     /**
485      * @tc.steps: step3. Perform element updates.
486      */
487     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
488     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
489     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
490 
491     BoxLayoutAlgorithm boxLayoutAlgorithm;
492     std::list<RefPtr<LayoutWrapper>> childList;
493     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
494 
495     /**
496      * @tc.steps: step4. call SetOptionalSize.
497      * @tc.expected: expect the size is nullopt.
498      */
499     const auto& layoutConstraint = layoutWrapper->GetLayoutProperty()->GetLayoutConstraint();
500     parentLayoutConstraint.selfIdealSize.SetOptionalSize(layoutConstraint->selfIdealSize);
501     auto size = parentLayoutConstraint.selfIdealSize.width_;
502     auto size1 = parentLayoutConstraint.selfIdealSize.height_;
503     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
504     EXPECT_EQ(size, std::nullopt);
505     EXPECT_EQ(size1, std::nullopt);
506 }
507 
508 /**
509  * @tc.name: BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList008
510  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
511  * @tc.type: FUNC
512  */
513 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList008, TestSize.Level1)
514 {
515     /**
516      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
517      */
518     auto layoutWrapper = CreatlayoutWrapper();
519 
520     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
521     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
522     ASSERT_NE(rowLayoutPattern, nullptr);
523     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
524     ASSERT_NE(rowLayoutAlgorithm, nullptr);
525     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
526 
527     /**
528      * @tc.steps: step2. layout parameter initialization.
529      */
530     LayoutConstraintF parentLayoutConstraint;
531     PaddingProperty noPadding;
532     noPadding.left = CalcLength(NOPADDING);
533     noPadding.right = CalcLength(NOPADDING);
534     noPadding.top = CalcLength(NOPADDING);
535     noPadding.bottom = CalcLength(NOPADDING);
536 
537     /**
538      * @tc.steps: step3. Perform element updates.
539      */
540     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
541     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
542     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
543 
544     /**
545      * @tc.steps: step4. call SetOptionalSize.
546      * @tc.expected: expect the size is same with .
547      */
548     BoxLayoutAlgorithm boxLayoutAlgorithm;
549     std::list<RefPtr<LayoutWrapper>> childList;
550     layoutWrapper->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_PARENT);
551     auto type = layoutWrapper->GetLayoutProperty()->measureType_;
552     const auto& layoutConstraint = layoutWrapper->GetLayoutProperty()->GetLayoutConstraint();
553     parentLayoutConstraint.selfIdealSize.SetOptionalSize(layoutConstraint->parentIdealSize);
554     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
555     EXPECT_EQ(type, MeasureType::MATCH_PARENT);
556 
557     /**
558      * @tc.steps: step5. call SetContentSize.
559      * @tc.expected: expect the layoutWrapper->GetGeometryNode()->content_ is not null .
560      */
561     SizeF size { 0.1, 0.1 };
562     layoutWrapper->GetGeometryNode()->SetContentSize(size);
563     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(
564         AccessibilityManager::RawPtr(layoutWrapper), layoutWrapper->GetAllChildrenWithBuild());
565     EXPECT_NE(layoutWrapper->GetGeometryNode()->content_, nullptr);
566 }
567 
568 /**
569  * @tc.name: BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList009
570  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
571  * @tc.type: FUNC
572  */
573 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList009, TestSize.Level1)
574 {
575     /**
576      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
577      */
578     auto layoutWrapper = CreatlayoutWrapper();
579 
580     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
581     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
582     ASSERT_NE(rowLayoutPattern, nullptr);
583     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
584     ASSERT_NE(rowLayoutAlgorithm, nullptr);
585     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
586 
587     /**
588      * @tc.steps: step2. layout parameter initialization.
589      */
590     LayoutConstraintF parentLayoutConstraint;
591     PaddingProperty noPadding;
592     noPadding.left = CalcLength(NOPADDING);
593     noPadding.right = CalcLength(NOPADDING);
594     noPadding.top = CalcLength(NOPADDING);
595     noPadding.bottom = CalcLength(NOPADDING);
596 
597     /**
598      * @tc.steps: step3. Perform element updates.
599      */
600     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
601     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
602     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
603 
604     /**
605      * @tc.steps: step1. pushback firstLayoutWrapper to childlist .
606      * @tc.expected: expect list child is not null.
607      */
608     BoxLayoutAlgorithm boxLayoutAlgorithm;
609     auto childLayoutWrapper = CreatChildlayoutWrapper();
610 
611     std::list<RefPtr<LayoutWrapper>> childList;
612     childList.push_back(childLayoutWrapper);
613     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
614     EXPECT_NE(&childList, nullptr);
615 }
616 
617 /**
618  * @tc.name: BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList010
619  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
620  * @tc.type: FUNC
621  */
622 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList010, TestSize.Level1)
623 {
624     /**
625      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
626      */
627     auto layoutWrapper = CreatlayoutWrapper();
628 
629     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
630     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
631     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
632     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
633 
634     /**
635      * @tc.steps: step2. layout parameter initialization.
636      */
637     LayoutConstraintF parentLayoutConstraint;
638     parentLayoutConstraint.parentIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
639 
640     PaddingProperty noPadding;
641     noPadding.left = CalcLength(NOPADDING);
642     noPadding.right = CalcLength(NOPADDING);
643     noPadding.top = CalcLength(NOPADDING);
644     noPadding.bottom = CalcLength(NOPADDING);
645 
646     /**
647      * @tc.steps: step3. Perform element updates.
648      */
649     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
650     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
651     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
652 
653     /**
654      * @tc.steps: step4. parentIdealSize is Valid.
655      * @tc.expected: expect the size is same with parentIdealSize .
656      */
657     BoxLayoutAlgorithm boxLayoutAlgorithm;
658     std::list<RefPtr<LayoutWrapper>> childList;
659     layoutWrapper->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_PARENT);
660     auto type = layoutWrapper->GetLayoutProperty()->measureType_;
661     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
662     EXPECT_EQ(type, MeasureType::MATCH_PARENT);
663 }
664 
665 /**
666  * @tc.name: BoxLayoutAlgorithmTest_MeasureContent011
667  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
668  * @tc.type: FUNC
669  */
670 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_MeasureContent011, TestSize.Level1)
671 {
672     /**
673      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
674      */
675     auto layoutWrapper = CreatlayoutWrapper();
676     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<Pattern>());
677 
678     /**
679      * @tc.steps: step2. layout parameter initialization.
680      */
681     LayoutConstraintF parentLayoutConstraint;
682     parentLayoutConstraint.maxSize = CONTAINER_SIZE;
683     parentLayoutConstraint.percentReference = CONTAINER_SIZE;
684     PaddingProperty noPadding;
685     noPadding.left = CalcLength(NOPADDING);
686     noPadding.right = CalcLength(NOPADDING);
687     noPadding.top = CalcLength(NOPADDING);
688     noPadding.bottom = CalcLength(NOPADDING);
689 
690     /**
691      * @tc.steps: step3. Perform element updates.
692      */
693     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
694     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
695     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
696 
697     /**
698      * @tc.steps: step5. call MeasureContent.
699      * @tc.expected: expect the host is null.
700      */
701     BoxLayoutAlgorithm boxLayoutAlgorithm;
702     auto host = layoutWrapper->GetHostNode();
703     boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
704     EXPECT_EQ(host, nullptr);
705 
706     /**
707      * @tc.steps: step6. call MeasureContent and set measureType_ = MeasureType::MATCH_PARENT.
708      * @tc.expected: expect the host1 is not null.
709      */
710     layoutWrapper->hostNode_ = rowFrameNode;
711     const auto& layoutProperty = layoutWrapper->GetLayoutProperty();
712     layoutProperty->measureType_ = MeasureType::MATCH_PARENT;
713     boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
714     auto host1 = layoutWrapper->GetHostNode();
715     EXPECT_TRUE(host1->IsAtomicNode());
716 
717     /**
718      * @tc.steps: step7. selfIdealSize is not Valid.
719      * expected: return percentReference.
720      */
721     parentLayoutConstraint.percentReference.SetSizeT(SizeF(RK356_WIDTH, ROW_HEIGHT));
722     std::optional<SizeF> sizeTemp =
723         boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
724 
725     EXPECT_EQ(sizeTemp.value().width_, parentLayoutConstraint.percentReference.width_);
726     EXPECT_EQ(sizeTemp.value().height_, parentLayoutConstraint.percentReference.height_);
727 
728     /**
729      * @tc.steps: step8. set measureType_ other.
730      * expected: return minSize.
731      */
732     parentLayoutConstraint.minSize.SetSizeT(SizeF(RK356_WIDTH + 1, ROW_HEIGHT + 1));
733     layoutProperty->measureType_ = MeasureType::MATCH_CONTENT;
734     sizeTemp = boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
735     EXPECT_EQ(sizeTemp.value().width_, parentLayoutConstraint.minSize.width_);
736     EXPECT_EQ(sizeTemp.value().height_, parentLayoutConstraint.minSize.height_);
737 
738     /**
739      * @tc.steps: step9. set selfIdealSize valid.
740      * expected: return selfIdealSize.
741      */
742     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH - 1, ROW_HEIGHT - 1));
743     sizeTemp = boxLayoutAlgorithm.MeasureContent(parentLayoutConstraint, AccessibilityManager::RawPtr(layoutWrapper));
744     EXPECT_EQ(sizeTemp.value().width_, parentLayoutConstraint.selfIdealSize.width_);
745     EXPECT_EQ(sizeTemp.value().height_, parentLayoutConstraint.selfIdealSize.height_);
746 }
747 
748 /**
749  * @tc.name: BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList012
750  * @tc.desc: Set one index value into BoxLayoutAlgorithmTestNg and get it.
751  * @tc.type: FUNC
752  */
753 HWTEST_F(BoxLayoutAlgorithmTestNg, BoxLayoutAlgorithmTest_PerformMeasureSelfWithChildList012, TestSize.Level1)
754 {
755     /**
756      * @tc.steps: step1. creat a layoutwrapper and SetLayoutAlgorithm for it.
757      */
758     auto layoutWrapper = CreatlayoutWrapper();
759 
760     auto rowFrameNode = FrameNode::CreateFrameNode("test", 0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
761     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
762     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
763     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
764 
765     /**
766      * @tc.steps: step2. layout parameter initialization.
767      */
768     PaddingProperty noPadding;
769     noPadding.left = CalcLength(NOPADDING);
770     noPadding.right = CalcLength(NOPADDING);
771     noPadding.top = CalcLength(NOPADDING);
772     noPadding.bottom = CalcLength(NOPADDING);
773 
774     /**
775      * @tc.steps: step3. Perform element updates.
776      */
777     LayoutConstraintF parentLayoutConstraint;
778     layoutWrapper->GetLayoutProperty()->UpdatePadding(noPadding);
779     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
780     layoutWrapper->GetLayoutProperty()->UpdateContentConstraint();
781 
782     /**
783      * @tc.steps: step4. parentIdealSize is Valid.
784      * @tc.expected: expect the size is same with layoutWrapper3 .
785      */
786     BoxLayoutAlgorithm boxLayoutAlgorithm;
787     std::list<RefPtr<LayoutWrapper>> childList;
788     childList = layoutWrapper->GetAllChildrenWithBuild();
789     childList.push_front(nullptr);
790     auto layoutWrapper2 = CreatlayoutWrapper();
791     layoutWrapper2->GetLayoutProperty()->propVisibility_ = VisibleType::GONE;
792     childList.push_front(layoutWrapper2);
793     auto layoutWrapper3 = CreatChildlayoutWrapper();
794     layoutWrapper3->GetGeometryNode()->frame_.rect_.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
795     childList.push_front(layoutWrapper3);
796     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
797     EXPECT_FALSE(layoutWrapper->GetGeometryNode()->content_);
798     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.height_, ROW_HEIGHT);
799     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.width_, RK356_WIDTH);
800 
801     /**
802      * @tc.steps: step4. selfIdealSize isn't Valid and height is true.
803      * @tc.expected: expect the size is same with layoutWrapper3 .
804      */
805     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(0.0, ROW_HEIGHT));
806     layoutWrapper->GetLayoutProperty()->calcLayoutConstraint_ = nullptr;
807     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
808     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
809     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.height_, ROW_HEIGHT);
810     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.width_, 0);
811 
812     /**
813      * @tc.steps: step4. parentIdealSize isn't Valid and width is true.
814      * @tc.expected: expect the size is same with layoutWrapper3 .
815      */
816     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, 0.0));
817     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
818     boxLayoutAlgorithm.PerformMeasureSelfWithChildList(AccessibilityManager::RawPtr(layoutWrapper), childList);
819     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.height_, 0);
820     EXPECT_EQ(layoutWrapper->GetGeometryNode()->frame_.rect_.width_, RK356_WIDTH);
821 }
822 } // namespace OHOS::Ace::NG
823