diff --git a/frameworks/core/components_ng/layout/box_layout_algorithm.cpp b/frameworks/core/components_ng/layout/box_layout_algorithm.cpp index 01c7a49154e5e4cb76a0c38d5fb505fd4eaf443d..023cd02286a8afe7c5791ee44ef81c08307c69ff 100644 --- a/frameworks/core/components_ng/layout/box_layout_algorithm.cpp +++ b/frameworks/core/components_ng/layout/box_layout_algorithm.cpp @@ -128,6 +128,7 @@ void BoxLayoutAlgorithm::PerformMeasureSelfWithChildList( isContentNoEnabledFixed = layoutWrapper->GetHostNode() && layoutWrapper->GetHostNode()->GetPattern() && layoutWrapper->GetHostNode()->GetPattern()->IsContentNoEnabledFixed(); } + fixIdealSize.UpdateIllegalSizeWithCheck(contentSize); } else { // use the max child size. auto childFrame = SizeF(); diff --git a/frameworks/core/components_ng/pattern/blank/blank_pattern.h b/frameworks/core/components_ng/pattern/blank/blank_pattern.h index 52938d26de85e8c9529aaf80b5124a893a2f2e2c..9e0a1c4ec58d04fca955f210fbf2209789813c5e 100644 --- a/frameworks/core/components_ng/pattern/blank/blank_pattern.h +++ b/frameworks/core/components_ng/pattern/blank/blank_pattern.h @@ -66,6 +66,11 @@ public: return true; } + bool IsEnableFix() override + { + return true; + } + private: RefPtr GetParentFrameNode(RefPtr node); }; diff --git a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp index c638e738b0c615b6a6a396fd439edc6323df55e8..f60c041c24e95f68526abd6867af0fef1350dffc 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp @@ -65,8 +65,30 @@ std::optional DividerLayoutAlgorithm::MeasureContent( constrainSize.Constrain(contentConstraint.minSize, contentConstraint.maxSize); dividerLength_ = constrainSize.Height(); } + auto layoutPolicy = dividerLayoutProperty->GetLayoutPolicyProperty(); + if (layoutPolicy.has_value()) { + UpdateConstraintSizeByLayoutPolicy(layoutPolicy.value(), constrainSize, strokeWidth); + } return constrainSize; } +void DividerLayoutAlgorithm::UpdateConstraintSizeByLayoutPolicy( + NG::LayoutPolicyProperty& layoutPolicy, SizeF& constrainSize, Dimension& strokeWidth) +{ + if ((layoutPolicy.IsWidthWrap() || layoutPolicy.IsWidthFix()) && !vertical_) { + constrainSize.SetWidth(0.0f); + } + if ((layoutPolicy.IsHeightWrap() || layoutPolicy.IsHeightFix()) && vertical_) { + constrainSize.SetHeight(0.0f); + } + if (layoutPolicy.IsHeightFix() && !vertical_) { + constrainSize.SetHeight(strokeWidth.ConvertToPx()); + dividerLength_ = constrainSize.Width(); + } + if (layoutPolicy.IsWidthFix() && vertical_) { + constrainSize.SetWidth(strokeWidth.ConvertToPx()); + dividerLength_ = constrainSize.Height(); + } +} float DividerLayoutAlgorithm::GetConstrainStrokeWidth() const { return constrainStrokeWidth_; diff --git a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.h b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.h index 41995ccd1479278d5eb3a0dfc47605bf843294fe..637eae320065ba7b7ffa3e62297b13cf3e49e1d3 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.h @@ -16,6 +16,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_LAYOUT_ALGORITHM_H #include "core/components_ng/layout/box_layout_algorithm.h" +#include "core/components_ng/property/layout_policy_property.h" namespace OHOS::Ace::NG { // DividerLayoutAlgorithm acts as the underlying divider layout. @@ -33,6 +34,8 @@ public: float GetDividerLength() const; bool GetVertical() const; bool GetStrokeWidthLimitation() const; + void UpdateConstraintSizeByLayoutPolicy( + NG::LayoutPolicyProperty& layoutPolicy, SizeF& constrainSize, Dimension& strokeWidth); private: float constrainStrokeWidth_ = 0; diff --git a/frameworks/core/components_ng/pattern/divider/divider_pattern.h b/frameworks/core/components_ng/pattern/divider/divider_pattern.h index fc125a4177a6ad4373bb772e5bfb6a723faf0d5d..d5de76d124af9030d13609d53c37c22ea3708368 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_pattern.h +++ b/frameworks/core/components_ng/pattern/divider/divider_pattern.h @@ -75,6 +75,11 @@ public: return true; } + bool IsEnableFix() override + { + return true; + } + private: bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; float constrainStrokeWidth_ = 0; diff --git a/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.cpp index 88d51834dace0d0a9bda338200ce5ad5827c1c33..c3d57f970e416f3ef7d37590c9925bade41a14e8 100644 --- a/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.cpp @@ -616,10 +616,13 @@ bool FlexLayoutAlgorithm::HandleBlankFirstTimeMeasure( Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN))) { return false; } - + auto blankLayoutProperty = childLayoutWrapper->GetLayoutProperty(); // if constainer is self adaptive, secondaryMeasure won't happen, blank can call Measure directly if (selfAdaptive_ || isInfiniteLayout_) { childLayoutWrapper->Measure(child.layoutConstraint); + if (CheckBlankIllegality(blankLayoutProperty)) { + childLayoutWrapper->GetGeometryNode()->SetFrameSize(SizeF(0.0f, 0.0f)); + } UpdateAllocatedSize(childLayoutWrapper, crossAxisSize_); CheckSizeValidity(childLayoutWrapper); if (!isInfiniteLayout_) { @@ -632,7 +635,6 @@ bool FlexLayoutAlgorithm::HandleBlankFirstTimeMeasure( // min size should not participate in the first measure of blank auto mainAxisSize = 0.0f; auto crossAxisSize = 0.0f; - auto blankLayoutProperty = childLayoutWrapper->GetLayoutProperty(); childLayoutWrapper->GetHostNode()->GetPattern()->BeforeCreateLayoutWrapper(); if (blankLayoutProperty) { const auto& calcConstraint = blankLayoutProperty->GetCalcLayoutConstraint(); @@ -642,6 +644,10 @@ bool FlexLayoutAlgorithm::HandleBlankFirstTimeMeasure( mainAxisSize = std::max(IsHorizontal(direction_) ? size.Width() : size.Height(), 0.0f); crossAxisSize = std::max(IsHorizontal(direction_) ? size.Height() : size.Width(), 0.0f); } + if (CheckBlankIllegality(blankLayoutProperty)) { + mainAxisSize = 0.0f; + crossAxisSize = 0.0f; + } } childLayoutWrapper->GetGeometryNode()->SetFrameSize( IsHorizontal(direction_) ? SizeF(mainAxisSize, crossAxisSize) : SizeF(crossAxisSize, mainAxisSize)); @@ -680,6 +686,12 @@ void FlexLayoutAlgorithm::SecondMeasureInGrowOrShrink() continue; } childLayoutWrapper->Measure(child.layoutConstraint); + if (childLayoutWrapper->GetHostTag() == V2::BLANK_ETS_TAG) { + auto blankLayoutProperty = childLayoutWrapper->GetLayoutProperty(); + if (CheckBlankIllegality(blankLayoutProperty)) { + childLayoutWrapper->GetGeometryNode()->SetFrameSize(SizeF(0.0f, 0.0f)); + } + } crossAxisSize_ = std::max(crossAxisSize_, GetChildCrossAxisSize(childLayoutWrapper)); CheckBaselineProperties(child.layoutWrapper); ++iter; @@ -701,6 +713,13 @@ void FlexLayoutAlgorithm::SecondMeasureInGrowOrShrink() } } +bool FlexLayoutAlgorithm::CheckBlankIllegality(const RefPtr& blankLayoutProperty) +{ + CHECK_NULL_RETURN(blankLayoutProperty, false); + auto layoutPolicy = blankLayoutProperty->GetLayoutPolicyProperty(); + return layoutPolicy.has_value() && (layoutPolicy.value().IsWrap() || layoutPolicy.value().IsFix()); +} + void FlexLayoutAlgorithm::SecondaryMeasureByProperty( FlexItemProperties& flexItemProperties, LayoutWrapper* layoutWrapper) { diff --git a/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.h b/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.h index 335c64cd4062c8d5360112eea8c027c8696a5392..dd55bdf4e02cd1be1c3e99101a2b7b38afb18e5c 100644 --- a/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/flex/flex_layout_algorithm.h @@ -89,6 +89,7 @@ private: void MeasureAdaptiveLayoutChildren(LayoutWrapper* layoutWrapper, SizeF& realSize); void MeasureAndCleanMagicNodes(LayoutWrapper* containerLayoutWrapper, FlexItemProperties& flexItemProperties); bool HandleBlankFirstTimeMeasure(const MagicLayoutNode& child, FlexItemProperties& flexItemProperties); + bool CheckBlankIllegality(const RefPtr& blankLayoutProperty); void UpdateFlexProperties(FlexItemProperties& flexItemProperties, const RefPtr& layoutWrapper); void SecondaryMeasureByProperty(FlexItemProperties& flexItemProperties, LayoutWrapper* layoutWrapper); void UpdateLayoutConstraintOnMainAxis(LayoutConstraintF& layoutConstraint, float size); diff --git a/test/unittest/core/pattern/divider/divider_new_test_ng.cpp b/test/unittest/core/pattern/divider/divider_new_test_ng.cpp index ef1aa4c4830c193127197b4bf0daf8e6412eb5b0..e247c35b429f9c14af8bf5d0d133b35a717fc23a 100644 --- a/test/unittest/core/pattern/divider/divider_new_test_ng.cpp +++ b/test/unittest/core/pattern/divider/divider_new_test_ng.cpp @@ -65,4 +65,306 @@ HWTEST_F(DividerNewTestNG, DividerLengthTest02, TestSize.Level1) auto pattern = OHOS::Ace::AceType::DynamicCast(frameNode->GetPattern()); EXPECT_EQ(pattern->dividerLength_, 100.0f); } + +/** + * @tc.name: LayoutPolicyTest001 + * @tc.desc: test the measure result when setting matchParent. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest001, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(500)); + ViewAbstract::SetHeight(CalcLength(300)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .width(LayoutPolicy.matchParent) + .height(LayoutPolicy.matchParent) + } + .width("500px") + .height("300px") + */ + + // Expect stack's width is 500, height is 300 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(500.0f, 300.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 500, height is 300 and offset is [0.0, 0.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(500.0f, 300.0f)); + EXPECT_EQ(offset1, OffsetF(0.0f, 0.0f)); +} + +/** + * @tc.name: LayoutPolicyTest002 + * @tc.desc: test the measure result when setting matchParent and parent has padding. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest002, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(500)); + ViewAbstract::SetHeight(CalcLength(300)); + ViewAbstract::SetPadding(CalcLength(20)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .width(LayoutPolicy.matchParent) + .height(LayoutPolicy.matchParent) + } + .width("500px") + .height("300px") + .padding("20px") + */ + + // Expect stack's width is 500, height is 300 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(500.0f, 300.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 460, height is 260 and offset is [20.0, 20.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(460.0f, 260.0f)); + EXPECT_EQ(offset1, OffsetF(20.0f, 20.0f)); +} + +/** + * @tc.name: LayoutPolicyTest003 + * @tc.desc: test the measure result when setting wrapContent. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest003, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(200)); + ViewAbstract::SetHeight(CalcLength(200)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); + model.StrokeWidth(Dimension(20)); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .strokeWidth("20px") + .width(LayoutPolicy.wrapContent) + .height(LayoutPolicy.wrapContent) + } + .width("200px") + .height("200px") + */ + + // Expect stack's width is 200, height is 200 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(200.0f, 200.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 0, height is 20 and offset is [100.0, 90.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(0.0f, 20.0f)); + EXPECT_EQ(offset1, OffsetF(100.0f, 90.0f)); +} + +/** + * @tc.name: LayoutPolicyTest004 + * @tc.desc: test the measure result when setting wrapContent. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest004, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(200)); + ViewAbstract::SetHeight(CalcLength(200)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); + model.Vertical(true); + model.StrokeWidth(Dimension(20)); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .strokeWidth("20px") + .width(LayoutPolicy.wrapContent) + .height(LayoutPolicy.wrapContent) + .vertical(true) + } + .width("200px") + .height("200px") + */ + + // Expect stack's width is 200, height is 200 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(200.0f, 200.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 20, height is 0 and offset is [90.0, 100.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(20.0f, 0.0f)); + EXPECT_EQ(offset1, OffsetF(90.0f, 100.0f)); +} + +/** + * @tc.name: LayoutPolicyTest005 + * @tc.desc: test the measure result when setting fixAtIdealSize. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest005, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(200)); + ViewAbstract::SetHeight(CalcLength(200)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); + model.StrokeWidth(Dimension(20)); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .strokeWidth("20px") + .width(LayoutPolicy.fixAtIdealSize) + .height(LayoutPolicy.fixAtIdealSize) + } + .width("200px") + .height("200px") + */ + + // Expect stack's width is 200, height is 200 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(200.0f, 200.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 0, height is 20 and offset is [100.0, 90.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(0.0f, 20.0f)); + EXPECT_EQ(offset1, OffsetF(100.0f, 90.0f)); +} + +/** + * @tc.name: LayoutPolicyTest006 + * @tc.desc: test the measure result when setting fixAtIdealSize. + * @tc.type: FUNC + */ +HWTEST_F(DividerNewTestNG, LayoutPolicyTest006, TestSize.Level1) +{ + RefPtr divider; + auto stack = CreateStack([this, ÷r](StackModelNG model) { + ViewAbstract::SetWidth(CalcLength(200)); + ViewAbstract::SetHeight(CalcLength(200)); + divider = CreateDivider([this](DividerModelNG model) { + ViewAbstractModelNG model1; + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); + model1.UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); + model.Vertical(true); + model.StrokeWidth(Dimension(20)); + }); + }); + ASSERT_NE(stack, nullptr); + ASSERT_EQ(stack->GetChildren().size(), 1); + CreateLayoutTask(stack); + + /* corresponding ets code: + Stack() { + Divider() + .strokeWidth("20px") + .width(LayoutPolicy.fixAtIdealSize) + .height(LayoutPolicy.fixAtIdealSize) + .vertical(true) + } + .width("200px") + .height("200px") + */ + + // Expect stack's width is 200, height is 200 and offset is [0.0, 0.0]. + auto geometryNode = stack->GetGeometryNode(); + ASSERT_NE(geometryNode, nullptr); + auto size = geometryNode->GetFrameSize(); + auto offset = geometryNode->GetFrameOffset(); + EXPECT_EQ(size, SizeF(200.0f, 200.0f)); + EXPECT_EQ(offset, OffsetF(0.0f, 0.0f)); + + // Expect divider's width is 20, height is 0 and offset is [90.0, 100.0]. + auto geometryNode1 = divider->GetGeometryNode(); + ASSERT_NE(geometryNode1, nullptr); + auto size1 = geometryNode1->GetFrameSize(); + auto offset1 = geometryNode1->GetFrameOffset(); + EXPECT_EQ(size1, SizeF(20.0f, 0.0f)); + EXPECT_EQ(offset1, OffsetF(90.0f, 100.0f)); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/pattern/stack/stack_base_test_ng.cpp b/test/unittest/core/pattern/stack/stack_base_test_ng.cpp index e0b08e9abc4cabc5c50258a1af45e2200fe0b784..f442aa08d7b0ae5ebc421656cd0e1d63b95c1b11 100644 --- a/test/unittest/core/pattern/stack/stack_base_test_ng.cpp +++ b/test/unittest/core/pattern/stack/stack_base_test_ng.cpp @@ -35,16 +35,4 @@ void StackBaseTestNG::SetUp() void StackBaseTestNG::TearDown() {} -RefPtr StackBaseTestNG::CreateStack(const std::function& callback) -{ - StackModelNG model; - model.Create(); - if (callback) { - callback(model); - } - RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); - ViewStackProcessor::GetInstance()->PopContainer(); - return AceType::DynamicCast(element); -} - } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/stack/stack_base_test_ng.h b/test/unittest/core/pattern/stack/stack_base_test_ng.h index 5f91cd9f577ca95c659bdc644253ed8484d6fbbe..558c9918d0a66263be5bb38d1a2e84290bd90391 100644 --- a/test/unittest/core/pattern/stack/stack_base_test_ng.h +++ b/test/unittest/core/pattern/stack/stack_base_test_ng.h @@ -33,7 +33,6 @@ public: static void TearDownTestSuite(); void SetUp() override; void TearDown() override; - RefPtr CreateStack(const std::function& callback); }; } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/test_ng.cpp b/test/unittest/core/pattern/test_ng.cpp index d33913b9541bdfa4289f9ff56243b755adaf25d3..8b3775043420c6c5c5557d6fa576bd9ad2fae1b6 100644 --- a/test/unittest/core/pattern/test_ng.cpp +++ b/test/unittest/core/pattern/test_ng.cpp @@ -182,6 +182,18 @@ RefPtr TestNG::CreateColumn(const std::function& return AceType::DynamicCast(element); } +RefPtr TestNG::CreateStack(const std::function& callback) +{ + StackModelNG model; + model.Create(); + if (callback) { + callback(model); + } + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + ViewStackProcessor::GetInstance()->PopContainer(); + return AceType::DynamicCast(element); +} + void TestNG::SetSize(std::optional axis, const CalcLength& crossSize, const CalcLength& mainSize) { if (axis.has_value() && axis.value() == Axis::HORIZONTAL) { diff --git a/test/unittest/core/pattern/test_ng.h b/test/unittest/core/pattern/test_ng.h index 0c11a69eff873e31c3a9a26ec8b9a940b78d5b17..6ecea64715cd5eaba222542004746601437944d1 100644 --- a/test/unittest/core/pattern/test_ng.h +++ b/test/unittest/core/pattern/test_ng.h @@ -26,8 +26,9 @@ #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern//linear_layout/column_model_ng.h" #include "core/components_ng/pattern//linear_layout/row_model_ng.h" -#include "core/components_ng/pattern/text/text_model_ng.h" #include "core/components_ng/pattern/scrollable/scrollable.h" +#include "core/components_ng/pattern/stack/stack_model_ng.h" +#include "core/components_ng/pattern/text/text_model_ng.h" namespace OHOS::Ace::NG { using namespace testing; @@ -57,6 +58,7 @@ public: RefPtr CreateText(const std::u16string& content, const std::function& callback); RefPtr CreateRow(const std::function& callback); RefPtr CreateColumn(const std::function& callback); + RefPtr CreateStack(const std::function& callback); void SetSize(std::optional axis, const CalcLength& crossSize, const CalcLength& mainSize); AssertionResult IsExist(const RefPtr& frameNode, int32_t index); AssertionResult IsExistAndActive(const RefPtr& frameNode, int32_t index);