From 59eb658e2b8bf0876b127e805dc771a69d1718d9 Mon Sep 17 00:00:00 2001 From: WangJiazhen Date: Thu, 17 Jul 2025 19:27:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=85=AC=E5=85=B1=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WangJiazhen --- .../jsview/canvas/js_canvas_renderer.cpp | 2 + frameworks/core/components_ng/layout/BUILD.gn | 1 + .../layout/drawing_layout_utils.cpp | 42 ++++ .../layout/drawing_layout_utils.h | 27 +++ .../canvas/canvas_layout_algorithm.cpp | 26 +-- .../pattern/canvas/canvas_layout_algorithm.h | 2 - .../pattern/shape/shape_layout_algorithm.cpp | 58 ++---- .../pattern/shape/shape_layout_algorithm.h | 4 - .../pattern/video/video_layout_algorithm.cpp | 26 +-- .../pattern/video/video_layout_algorithm.h | 3 +- .../xcomponent_layout_algorithm.cpp | 27 +-- .../xcomponent/xcomponent_layout_algorithm.h | 3 - test/unittest/BUILD.gn | 1 + test/unittest/core/layout/BUILD.gn | 7 + .../layout/drawing_layout_utils_test_ng.cpp | 190 ++++++++++++++++++ .../core/pattern/canvas/canvas_test_ng.cpp | 134 ------------ .../pattern/shape/shape_pattern_test_ng.cpp | 40 ---- .../pattern/video/video_property_test_ng.cpp | 151 -------------- .../xcomponent_property_test_ng.cpp | 131 ------------ 19 files changed, 291 insertions(+), 584 deletions(-) create mode 100644 frameworks/core/components_ng/layout/drawing_layout_utils.cpp create mode 100644 frameworks/core/components_ng/layout/drawing_layout_utils.h create mode 100644 test/unittest/core/layout/drawing_layout_utils_test_ng.cpp diff --git a/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp b/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp index 0796013cefa..247990ea887 100644 --- a/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp @@ -1236,6 +1236,7 @@ void JSCanvasRenderer::JsArc(const JSCallbackInfo& info) info.GetDoubleArg(2, param.radius, isJudgeSpecialValue_) && // Index2: the 3rd arg. info.GetDoubleArg(3, param.startAngle, isJudgeSpecialValue_) && // Index3: the 4th arg. info.GetDoubleArg(4, param.endAngle, isJudgeSpecialValue_)) { // Index4: the 5th arg. + info.GetBooleanArg(5, param.anticlockwise); // Non mandatory parameter with default value 'false' double density = GetDensity(); param.x *= density; @@ -1257,6 +1258,7 @@ void JSCanvasRenderer::JsEllipse(const JSCallbackInfo& info) info.GetDoubleArg(4, param.rotation, isJudgeSpecialValue_) && // Index4: the 5th arg. info.GetDoubleArg(5, param.startAngle, isJudgeSpecialValue_) && // Index5: the 6th arg. info.GetDoubleArg(6, param.endAngle, isJudgeSpecialValue_)) { // Index6: the 7th arg. + info.GetBooleanArg(7, param.anticlockwise); // Non mandatory parameter with default value 'false' double density = GetDensity(); param.x *= density; diff --git a/frameworks/core/components_ng/layout/BUILD.gn b/frameworks/core/components_ng/layout/BUILD.gn index c5d9d66daad..a974c12eb09 100644 --- a/frameworks/core/components_ng/layout/BUILD.gn +++ b/frameworks/core/components_ng/layout/BUILD.gn @@ -17,6 +17,7 @@ import( build_component_ng("layout_ng") { sources = [ "box_layout_algorithm.cpp", + "drawing_layout_utils.cpp", "layout_algorithm.cpp", "layout_property.cpp", "layout_wrapper.cpp", diff --git a/frameworks/core/components_ng/layout/drawing_layout_utils.cpp b/frameworks/core/components_ng/layout/drawing_layout_utils.cpp new file mode 100644 index 00000000000..1542e9dfb4b --- /dev/null +++ b/frameworks/core/components_ng/layout/drawing_layout_utils.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/layout/drawing_layout_utils.h" + +namespace OHOS::Ace::NG { +void MeasureLayoutPolicySize(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size) +{ + const auto& layoutProperty = layoutWrapper->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + auto layoutPolicy = layoutProperty->GetLayoutPolicyProperty(); + CHECK_NULL_VOID(layoutPolicy.has_value()); + + if (layoutPolicy->IsWidthMatch() && contentConstraint.parentIdealSize.Width().has_value()) { + // if width is matchParent using parentIdealSize + size.SetWidth(contentConstraint.parentIdealSize.Width().value()); + } else if (layoutPolicy->IsWidthAdaptive()) { + // if width is wrapContent or fixAtIdealSize set width 0.0 + size.SetWidth(0.0); + } + + if (layoutPolicy->IsHeightMatch() && contentConstraint.parentIdealSize.Height().has_value()) { + // if height is matchParent using parentIdealSize + size.SetHeight(contentConstraint.parentIdealSize.Height().value()); + } else if (layoutPolicy->IsHeightAdaptive()) { + // if height is wrapContent or fixAtIdealSize set height 0.0 + size.SetHeight(0.0); + } +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/layout/drawing_layout_utils.h b/frameworks/core/components_ng/layout/drawing_layout_utils.h new file mode 100644 index 00000000000..6bacb2cab69 --- /dev/null +++ b/frameworks/core/components_ng/layout/drawing_layout_utils.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_DRAWING_LAYOUT_UTILS_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_DRAWING_LAYOUT_UTILS_H + +#include "base/memory/ace_type.h" +#include "core/components_ng/layout/layout_wrapper_node.h" +#include "core/components_ng/property/layout_constraint.h" + +namespace OHOS::Ace::NG { +void MeasureLayoutPolicySize(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size); +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_DRAWING_LAYOUT_UTILS_H diff --git a/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.cpp index 5dd5e33dcf9..09c31732157 100644 --- a/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.cpp @@ -15,6 +15,7 @@ #include "core/components_ng/pattern/canvas/canvas_layout_algorithm.h" +#include "core/components_ng/layout/drawing_layout_utils.h" #include "core/components_ng/pattern/canvas/canvas_pattern.h" namespace OHOS::Ace::NG { @@ -34,31 +35,6 @@ std::optional CanvasLayoutAlgorithm::MeasureContent( return canvasSize; } -void CanvasLayoutAlgorithm::MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size) -{ - const auto& layoutProperty = layoutWrapper->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto layoutPolicy = layoutProperty->GetLayoutPolicyProperty(); - CHECK_NULL_VOID(layoutPolicy.has_value()); - - if (layoutPolicy->IsWidthMatch() && contentConstraint.parentIdealSize.Width().has_value()) { - // if width is matchParent - size.SetWidth(contentConstraint.parentIdealSize.Width().value()); - } else if (layoutPolicy->IsWidthAdaptive()) { - // if width is wrapContent or fixAtIdealSize set width 0.0 - size.SetWidth(0.0); - } - - if (layoutPolicy->IsHeightMatch() && contentConstraint.parentIdealSize.Height().has_value()) { - // if height is matchParent - size.SetHeight(contentConstraint.parentIdealSize.Height().value()); - } else if (layoutPolicy->IsHeightAdaptive()) { - // if height is wrapContent or fixAtIdealSize set height 0.0 - size.SetHeight(0.0); - } -} - void CanvasLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) { BoxLayoutAlgorithm::Layout(layoutWrapper); diff --git a/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.h b/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.h index 6bedf82e794..a5a94953bd2 100644 --- a/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/canvas/canvas_layout_algorithm.h @@ -31,8 +31,6 @@ public: std::optional MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; - void MeasureLayoutPolicySize(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size); - void Layout(LayoutWrapper* layoutWrapper) override; private: diff --git a/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.cpp index 041bf0e6124..8380474b9aa 100644 --- a/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.cpp @@ -16,9 +16,9 @@ #include "frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.h" #include "core/components_ng/base/frame_node.h" +#include "core/components_ng/layout/drawing_layout_utils.h" namespace OHOS::Ace::NG { - std::optional ShapeLayoutAlgorithm::MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) { @@ -28,49 +28,23 @@ std::optional ShapeLayoutAlgorithm::MeasureContent( CHECK_NULL_RETURN(layoutProperty, std::nullopt); auto measureType = layoutProperty->GetMeasureType(MeasureType::MATCH_CONTENT); OptionalSizeF contentSize; - do { - // Use idealSize first if it is valid. - contentSize.UpdateSizeWithCheck(contentConstraint.selfIdealSize); - if (contentSize.IsValid()) { - break; - } - - if (measureType == MeasureType::MATCH_PARENT) { - contentSize.UpdateIllegalSizeWithCheck(contentConstraint.parentIdealSize); - // use max is parent ideal size is invalid. - contentSize.UpdateIllegalSizeWithCheck(contentConstraint.percentReference); - break; - } - - // wrap content case use min size default. - contentSize.UpdateIllegalSizeWithCheck(contentConstraint.minSize); - - MeasureLayoutPolicySize(contentConstraint, layoutProperty, contentSize); - } while (false); - return contentSize.ConvertToSizeT(); -} - -void ShapeLayoutAlgorithm::MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, const RefPtr layoutProperty, OptionalSizeF& size) -{ - CHECK_NULL_VOID(layoutProperty); - auto layoutPolicy = layoutProperty->GetLayoutPolicyProperty(); - CHECK_NULL_VOID(layoutPolicy.has_value()); - - if (layoutPolicy->IsWidthMatch() && contentConstraint.parentIdealSize.Width().has_value()) { - // if width is matchParent - size.SetWidth(contentConstraint.parentIdealSize.Width()); - } else if (layoutPolicy->IsWidthAdaptive()) { - // if width is wrapContent or fixAtIdealSize set width 0.0 - size.SetWidth(0.0); + // Use idealSize first if it is valid. + contentSize.UpdateSizeWithCheck(contentConstraint.selfIdealSize); + if (contentSize.IsValid()) { + return contentSize.ConvertToSizeT(); } - if (layoutPolicy->IsHeightMatch() && contentConstraint.parentIdealSize.Height().has_value()) { - // if height is matchParent - size.SetHeight(contentConstraint.parentIdealSize.Height()); - } else if (layoutPolicy->IsHeightAdaptive()) { - // if height is wrapContent or fixAtIdealSize set height 0.0 - size.SetHeight(0.0); + if (measureType == MeasureType::MATCH_PARENT) { + contentSize.UpdateIllegalSizeWithCheck(contentConstraint.parentIdealSize); + // use max is parent ideal size is invalid. + contentSize.UpdateIllegalSizeWithCheck(contentConstraint.percentReference); + return contentSize.ConvertToSizeT(); } + + // wrap content case use min size default. + contentSize.UpdateIllegalSizeWithCheck(contentConstraint.minSize); + SizeF size = contentSize.ConvertToSizeT(); + MeasureLayoutPolicySize(contentConstraint, layoutWrapper, size); + return size; } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.h b/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.h index 35b7c7f7602..7f188f5c3b7 100644 --- a/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/shape/shape_layout_algorithm.h @@ -28,10 +28,6 @@ public: std::optional MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; - - void MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, const RefPtr layoutProperty, OptionalSizeF& size); - private: ACE_DISALLOW_COPY_AND_MOVE(ShapeLayoutAlgorithm); }; diff --git a/frameworks/core/components_ng/pattern/video/video_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/video/video_layout_algorithm.cpp index c144d30f476..4091704f3b7 100644 --- a/frameworks/core/components_ng/pattern/video/video_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/video/video_layout_algorithm.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/video/video_layout_algorithm.h" #include "core/components/video/video_theme.h" +#include "core/components_ng/layout/drawing_layout_utils.h" #include "core/components_ng/pattern/video/video_pattern.h" namespace OHOS::Ace::NG { @@ -120,29 +121,4 @@ std::optional VideoLayoutAlgorithm::MeasureContent( return layoutSize; } -void VideoLayoutAlgorithm::MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size) -{ - const auto& layoutProperty = layoutWrapper->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto layoutPolicy = layoutProperty->GetLayoutPolicyProperty(); - CHECK_NULL_VOID(layoutPolicy.has_value()); - - if (layoutPolicy->IsWidthMatch() && contentConstraint.parentIdealSize.Width().has_value()) { - // if width is matchParent - size.SetWidth(contentConstraint.parentIdealSize.Width().value()); - } else if (layoutPolicy->IsWidthAdaptive()) { - // if width is wrapContent or fixAtIdealSize set width 0.0 - size.SetWidth(0.0); - } - - if (layoutPolicy->IsHeightMatch() && contentConstraint.parentIdealSize.Height().has_value()) { - // if height is matchParent - size.SetHeight(contentConstraint.parentIdealSize.Height().value()); - } else if (layoutPolicy->IsHeightAdaptive()) { - // if height is wrapContent or fixAtIdealSize set height 0.0 - size.SetHeight(0.0); - } -} - } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/video/video_layout_algorithm.h b/frameworks/core/components_ng/pattern/video/video_layout_algorithm.h index 82b374da294..ecb6be009fc 100644 --- a/frameworks/core/components_ng/pattern/video/video_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/video/video_layout_algorithm.h @@ -31,9 +31,8 @@ public: std::optional MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; - void MeasureLayoutPolicySize(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, SizeF& size); - void Measure(LayoutWrapper* layoutWrapper) override; + void Layout(LayoutWrapper* layoutWrapper) override; private: diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.cpp index a25333caf31..3ebe1c2a748 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.cpp @@ -14,6 +14,7 @@ */ #include "base/utils/utils.h" +#include "core/components_ng/layout/drawing_layout_utils.h" #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/linear_layout/linear_layout_utils.h" @@ -31,34 +32,10 @@ std::optional XComponentLayoutAlgorithm::MeasureContent( if (contentConstraint.selfIdealSize.IsValid()) { layoutSize = contentConstraint.selfIdealSize.ConvertToSizeT(); } - MeasureLayoutPolicySize(contentConstraint, layoutProperty, layoutSize); + MeasureLayoutPolicySize(contentConstraint, layoutWrapper, layoutSize); return layoutSize; } -void XComponentLayoutAlgorithm::MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, RefPtr layoutProperty, SizeF& size) -{ - CHECK_NULL_VOID(layoutProperty); - auto layoutPolicy = layoutProperty->GetLayoutPolicyProperty(); - CHECK_NULL_VOID(layoutPolicy.has_value()); - - if (layoutPolicy->IsWidthMatch() && contentConstraint.parentIdealSize.Width().has_value()) { - // if width is matchParent - size.SetWidth(contentConstraint.parentIdealSize.Width().value()); - } else if (layoutPolicy->IsWidthAdaptive()) { - // if width is wrapContent or fixAtIdealSize set width 0.0 - size.SetWidth(0.0); - } - - if (layoutPolicy->IsHeightMatch() && contentConstraint.parentIdealSize.Height().has_value()) { - // if height is matchParent - size.SetHeight(contentConstraint.parentIdealSize.Height().value()); - } else if (layoutPolicy->IsHeightAdaptive()) { - // if height is wrapContent or fixAtIdealSize set height 0.0 - size.SetHeight(0.0); - } -} - void XComponentLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) { auto layoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h index ac51e8c49a3..7931f3e55e2 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h @@ -36,9 +36,6 @@ public: std::optional MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; - void MeasureLayoutPolicySize( - const LayoutConstraintF& contentConstraint, RefPtr layoutProperty, SizeF& size); - void Measure(LayoutWrapper* layoutWrapper) override; void Layout(LayoutWrapper* layoutWrapper) override; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 2b2368a8a1c..6588c9ba5ae 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -357,6 +357,7 @@ ohos_source_set("ace_components_layout") { subsystem_name = ace_engine_subsystem part_name = ace_engine_part sources = [ + "$ace_root/frameworks/core/components_ng/layout/drawing_layout_utils.cpp", "$ace_root/frameworks/core/components_ng/layout/box_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/layout/layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/layout/layout_property.cpp", diff --git a/test/unittest/core/layout/BUILD.gn b/test/unittest/core/layout/BUILD.gn index 4d34214480a..85192f01c74 100644 --- a/test/unittest/core/layout/BUILD.gn +++ b/test/unittest/core/layout/BUILD.gn @@ -51,9 +51,16 @@ ace_unittest("layout_wrapper_node_test_ng") { sources = [ "layout_wrapper_node_test_ng.cpp" ] } +ace_unittest("drawing_layout_utils_test_ng") { + type = "new" + module_output = "layout" + sources = [ "drawing_layout_utils_test_ng.cpp" ] +} + group("core_layout_unittest") { testonly = true deps = [ + ":drawing_layout_utils_test_ng", ":layout_property_test_ng", ":layout_wrapper_build_test_ng", ":layout_wrapper_node_test_ng", diff --git a/test/unittest/core/layout/drawing_layout_utils_test_ng.cpp b/test/unittest/core/layout/drawing_layout_utils_test_ng.cpp new file mode 100644 index 00000000000..5784bcfd417 --- /dev/null +++ b/test/unittest/core/layout/drawing_layout_utils_test_ng.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2025 iSoftStone Information Technology (Group) Co.,Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "gtest/gtest.h" + +#define protected public +#define private public +#include "test/mock/core/pipeline/mock_pipeline_context.h" + +#include "base/memory/ace_type.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/ui_node.h" +#include "core/components_ng/layout/drawing_layout_utils.h" +#include "core/components_ng/layout/layout_wrapper.h" +#include "core/components_ng/layout/layout_wrapper_builder.h" +#include "core/components_ng/layout/layout_wrapper_node.h" +#include "core/components_ng/pattern/custom/custom_node.h" +#include "core/components_ng/property/layout_constraint.h" + + +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Ace::NG { +class DrawingLayoutUtilsTestNg : public testing::Test { +public: + static void SetUpTestSuite() + { + MockPipelineContext::SetUp(); + } + static void TearDownTestSuite() + { + MockPipelineContext::TearDown(); + } +}; + +/** + * @tc.name: MeasureLayoutPolicySizeTest001 + * @tc.desc: Test MeasureLayoutPolicySize + * @tc.type: FUNC + */ +HWTEST_F(DrawingLayoutUtilsTestNg, MeasureLayoutPolicySizeTest001, TestSize.Level1) +{ + auto node = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 0, AceType::MakeRefPtr()); + RefPtr geometryNode = AceType::MakeRefPtr(); + RefPtr layoutProperty = node->GetLayoutProperty(); + LayoutWrapperNode layoutWrapper = LayoutWrapperNode(node, geometryNode, layoutProperty); + LayoutConstraintF layoutConstraint; + + /** + * @tc.steps1: Width is matchParent + * @tc.expected: the return size of MeasureLayoutPolicySize is (300, 1000) + */ + SizeF size = SizeF(1000.0f, 1000.0f); + layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 300); + EXPECT_EQ(size.Height(), 1000); + + /** + * @tc.steps2: Height is matchParent + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 400) + */ + size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 400); + + /** + * @tc.steps3: Width and Height are NO_MATCH + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) + */ + size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 1000); + + /** + * @tc.steps4: layoutPolicy has no value + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) + */ + layoutProperty->layoutPolicy_ = std::nullopt; + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 1000); + + /** + * @tc.steps5: layoutProperty is nullptr + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) + */ + layoutProperty.Reset(); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 1000); +} + +/** + * @tc.name: MeasureLayoutPolicySizeTest002 + * @tc.desc: Test MeasureLayoutPolicySize + * @tc.type: FUNC + */ +HWTEST_F(DrawingLayoutUtilsTestNg, MeasureLayoutPolicySizeTest002, TestSize.Level1) +{ + auto node = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 0, AceType::MakeRefPtr()); + RefPtr geometryNode = AceType::MakeRefPtr(); + RefPtr layoutProperty = node->GetLayoutProperty(); + LayoutWrapperNode layoutWrapper = LayoutWrapperNode(node, geometryNode, layoutProperty); + LayoutConstraintF layoutConstraint; + + /** + * @tc.steps1: Width is WrapContent + * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) + */ + SizeF size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 0); + EXPECT_EQ(size.Height(), 1000); + + /** + * @tc.steps2: Height is WrapContent + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) + */ + size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 0); + + /** + * @tc.steps3: Width is fixIdealSize + * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) + */ + size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 0); + EXPECT_EQ(size.Height(), 1000); + + /** + * @tc.steps4: Height is fixIdealSize + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) + */ + size = SizeF(1000.0f, 1000.0f); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 0); + + /** + * @tc.steps5: Width and Height are matchParent and parentIdealSize is null + * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) + */ + size = SizeF(1000.0f, 1000.0f); + layoutConstraint.parentIdealSize.Reset(); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); + layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); + MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); + EXPECT_EQ(size.Width(), 1000); + EXPECT_EQ(size.Height(), 1000); +} +} // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/canvas/canvas_test_ng.cpp b/test/unittest/core/pattern/canvas/canvas_test_ng.cpp index 78e0eb5e45c..d056aad85cd 100644 --- a/test/unittest/core/pattern/canvas/canvas_test_ng.cpp +++ b/test/unittest/core/pattern/canvas/canvas_test_ng.cpp @@ -275,140 +275,6 @@ HWTEST_F(CanvasTestNg, MeasureContentTest001, TestSize.Level1) EXPECT_EQ(pattern->canvasSize_->height_, 960.0f); } -/** - * @tc.name: MeasureLayoutPolicySizeTest001 - * @tc.desc: CanvasLayoutAlgorithm::MeasureLayoutPolicySize - * @tc.type: FUNC - */ -HWTEST_F(CanvasTestNg, MeasureLayoutPolicySizeTest001, TestSize.Level1) -{ - auto* stack = ViewStackProcessor::GetInstance(); - auto nodeId = stack->ClaimNodeId(); - auto frameNode = FrameNode::GetOrCreateFrameNode( - V2::CANVAS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); - auto pattern = frameNode->GetPattern(); - RefPtr canvasLayoutAlgorithm = AceType::MakeRefPtr(); - LayoutConstraintF layoutConstraint; - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, nullptr, frameNode->GetLayoutProperty()); - auto layoutProperty = frameNode->GetLayoutProperty(); - ASSERT_TRUE(layoutProperty); - - /** - * @tc.steps1: Width is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (300, 1000) - */ - SizeF size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 300); - EXPECT_EQ(size.Height(), 1000); - - /** - * @tc.steps2: Height is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 400) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 400); - - /** - * @tc.steps3: Width and Height are NO_MATCH - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 1000); - - /** - * @tc.steps4: layoutPolicy has no value - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - layoutProperty->layoutPolicy_ = std::nullopt; - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 1000); - - /** - * @tc.steps5: layoutProperty is nullptr - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - layoutProperty.Reset(); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 1000); -} - -/** - * @tc.name: MeasureLayoutPolicySizeTest002 - * @tc.desc: CanvasLayoutAlgorithm::MeasureLayoutPolicySize - * @tc.type: FUNC - */ -HWTEST_F(CanvasTestNg, MeasureLayoutPolicySizeTest002, TestSize.Level1) -{ - auto* stack = ViewStackProcessor::GetInstance(); - auto nodeId = stack->ClaimNodeId(); - auto frameNode = FrameNode::GetOrCreateFrameNode( - V2::CANVAS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); - auto pattern = frameNode->GetPattern(); - RefPtr canvasLayoutAlgorithm = AceType::MakeRefPtr(); - LayoutConstraintF layoutConstraint; - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, nullptr, frameNode->GetLayoutProperty()); - auto layoutProperty = frameNode->GetLayoutProperty(); - ASSERT_TRUE(layoutProperty); - - /** - * @tc.steps1: Width is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - SizeF size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 0); - EXPECT_EQ(size.Height(), 1000); - - /** - * @tc.steps2: Height is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 0); - - /** - * @tc.steps3: Width is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 0); - EXPECT_EQ(size.Height(), 1000); - - /** - * @tc.steps4: Height is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); - canvasLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size.Width(), 1000); - EXPECT_EQ(size.Height(), 0); -} - /** * @tc.name: CanvasPatternTest006 * @tc.desc: GetQuality diff --git a/test/unittest/core/pattern/shape/shape_pattern_test_ng.cpp b/test/unittest/core/pattern/shape/shape_pattern_test_ng.cpp index 194ed99e54b..4f9ba327847 100755 --- a/test/unittest/core/pattern/shape/shape_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/shape/shape_pattern_test_ng.cpp @@ -584,45 +584,5 @@ HWTEST_F(ShapePatternTestNg, MeasureContent004, TestSize.Level1) size = layoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); ASSERT_TRUE(size.has_value()); EXPECT_EQ(size.value(), SizeF(500, 600)); - - /** - * @tc.steps4: Width is matchParent - * @tc.expected: the return value of MeasureContent is (100, 50) - */ - layoutProperty->measureType_ = MeasureType::MATCH_CONTENT; - contentConstraint.parentIdealSize = OptionalSizeF(100, 200); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - size = layoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); - ASSERT_TRUE(size.has_value()); - EXPECT_EQ(size.value(), SizeF(100, 50)); - - /** - * @tc.steps5: Height is matchParent - * @tc.expected: the return value of MeasureContent is (50, 200) - */ - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); - size = layoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); - ASSERT_TRUE(size.has_value()); - EXPECT_EQ(size.value(), SizeF(50, 200)); - - /** - * @tc.steps6: Width and Height is not matchParent - * @tc.expected: the return value of MeasureContent is (50, 50) - */ - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - size = layoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); - ASSERT_TRUE(size.has_value()); - EXPECT_EQ(size.value(), SizeF(50, 50)); - - /** - * @tc.steps7: layoutPolicy has no value - * @tc.expected: the return value of MeasureContent is (50, 50) - */ - layoutProperty->layoutPolicy_ = std::nullopt; - size = layoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); - ASSERT_TRUE(size.has_value()); - EXPECT_EQ(size.value(), SizeF(50, 50)); } } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/video/video_property_test_ng.cpp b/test/unittest/core/pattern/video/video_property_test_ng.cpp index c7574c23614..040bb69b164 100755 --- a/test/unittest/core/pattern/video/video_property_test_ng.cpp +++ b/test/unittest/core/pattern/video/video_property_test_ng.cpp @@ -465,157 +465,6 @@ HWTEST_F(VideoPropertyTestNg, VideoMeasureTest005, TestSize.Level1) EXPECT_EQ(videoSize, SCREEN_SIZE_MEDIUM); } -/** - * @tc.name: VideoMeasureTest006 - * @tc.desc: Create Video, and invoke its Measure and layout function, and test its child/children layout algorithm. - * @tc.type: FUNC - */ -HWTEST_F(VideoPropertyTestNg, VideoMeasureTest006, TestSize.Level1) -{ - VideoModelNG video; - auto videoController = AceType::MakeRefPtr(); - video.Create(videoController); - - auto frameNodeTemp = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(frameNodeTemp, nullptr); - auto videoPatternTemp = AceType::DynamicCast(frameNodeTemp->GetPattern()); - ASSERT_NE(videoPatternTemp, nullptr); - EXPECT_CALL(*(AceType::DynamicCast(videoPatternTemp->mediaPlayer_)), IsMediaPlayerValid()) - .WillRepeatedly(Return(false)); - - auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode()); - ASSERT_NE(frameNode, nullptr); - EXPECT_EQ(frameNode->GetTag(), V2::VIDEO_ETS_TAG); - auto layoutProperty = frameNode->GetLayoutProperty(); - EXPECT_NE(layoutProperty, nullptr); - - // Create LayoutWrapper and set videoLayoutAlgorithm. - RefPtr geometryNode = AceType::MakeRefPtr(); - ASSERT_NE(geometryNode, nullptr); - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, geometryNode, layoutProperty); - auto videoPattern = frameNode->GetPattern(); - ASSERT_NE(videoPattern, nullptr); - RefPtr videoLayoutAlgorithm = AceType::MakeRefPtr(); - layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(videoLayoutAlgorithm)); - - /** - * @tc.steps1: Width is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (300, 1000) - */ - LayoutConstraintF layoutConstraint; - SizeF size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(300, 1000)); - - /** - * @tc.steps2: Height is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 400) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(1000, 400)); - - /** - * @tc.steps3: Width and Height is not matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(1000, 1000)); - - /** - * @tc.steps4: layoutPolicy has no value - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - layoutProperty->layoutPolicy_ = std::nullopt; - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(1000, 1000)); -} - -/** - * @tc.name: VideoMeasureTest007 - * @tc.desc: Create Video, and invoke its Measure and layout function, and test its child/children layout algorithm. - * @tc.type: FUNC - */ -HWTEST_F(VideoPropertyTestNg, VideoMeasureTest007, TestSize.Level1) -{ - VideoModelNG video; - auto videoController = AceType::MakeRefPtr(); - video.Create(videoController); - - auto frameNodeTemp = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(frameNodeTemp, nullptr); - auto videoPatternTemp = AceType::DynamicCast(frameNodeTemp->GetPattern()); - ASSERT_NE(videoPatternTemp, nullptr); - EXPECT_CALL(*(AceType::DynamicCast(videoPatternTemp->mediaPlayer_)), IsMediaPlayerValid()) - .WillRepeatedly(Return(false)); - - auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode()); - ASSERT_NE(frameNode, nullptr); - EXPECT_EQ(frameNode->GetTag(), V2::VIDEO_ETS_TAG); - auto layoutProperty = frameNode->GetLayoutProperty(); - EXPECT_NE(layoutProperty, nullptr); - - // Create LayoutWrapper and set videoLayoutAlgorithm. - RefPtr geometryNode = AceType::MakeRefPtr(); - ASSERT_NE(geometryNode, nullptr); - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, geometryNode, layoutProperty); - auto videoPattern = frameNode->GetPattern(); - ASSERT_NE(videoPattern, nullptr); - RefPtr videoLayoutAlgorithm = AceType::MakeRefPtr(); - layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(videoLayoutAlgorithm)); - - /** - * @tc.steps1: Width is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - LayoutConstraintF layoutConstraint; - SizeF size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(0, 1000)); - - /** - * @tc.steps2: Height is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(1000, 0)); - - /** - * @tc.steps3: Width is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(0, 1000)); - - /** - * @tc.steps4: Height is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); - videoLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, &layoutWrapper, size); - EXPECT_EQ(size, SizeF(1000, 0)); -} - /** * @tc.name: VideoFullScreenTest015 * @tc.desc: Create Video, and invoke its MeasureContent function to calculate the content size when it is fullscreen. diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp index ac85cd204c8..ccd4df5c264 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp @@ -372,137 +372,6 @@ HWTEST_F(XComponentPropertyTestNg, XComponentLayoutAlgorithmTest005, TestSize.Le childLayoutWrapper2->GetGeometryNode()->GetFrameOffset(), OffsetF(CHILD_OFFSET_WIDTH, CHILD_OFFSET_HEIGHT)); } -/** - * @tc.name: XComponentLayoutAlgorithmTest006 - * @tc.desc: Test XComponent measure functions when width or height is LayoutPolicy. - * @tc.type: FUNC - */ -HWTEST_F(XComponentPropertyTestNg, XComponentLayoutAlgorithmTest006, TestSize.Level1) -{ - std::shared_ptr const xComponentController; - XComponentModelNG xComponent; - xComponent.Create(XCOMPONENT_ID, XCOMPONENT_SURFACE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); - xComponent.SetSoPath(XCOMPONENT_SO_PATH); - auto frameNode = AceType::DynamicCast(ViewStackProcessor::GetInstance()->Finish()); - EXPECT_TRUE(frameNode != nullptr && frameNode->GetTag() == V2::XCOMPONENT_ETS_TAG); - // Create LayoutWrapper and set XComponentLayoutAlgorithm. - RefPtr geometryNode = AceType::MakeRefPtr(); - ASSERT_TRUE(geometryNode); - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, geometryNode, frameNode->GetLayoutProperty()); - auto layoutProperty = frameNode->GetLayoutProperty(); - auto xComponentPattern = frameNode->GetPattern(); - ASSERT_TRUE(xComponentPattern); - RefPtr xComponentLayoutAlgorithm = AceType::MakeRefPtr(); - layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(xComponentLayoutAlgorithm)); - - /** - * @tc.steps1: Width is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (300, 1000) - */ - LayoutConstraintF layoutConstraint; - SizeF size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(300, 1000)); - - /** - * @tc.steps2: Height is matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 400) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::MATCH_PARENT, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(1000, 400)); - - /** - * @tc.steps3: Width and Height is not matchParent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(1000, 1000)); - - /** - * @tc.steps4: layoutPolicy has no value - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 1000) - */ - layoutProperty->layoutPolicy_ = std::nullopt; - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(1000, 1000)); -} - -/** - * @tc.name: XComponentLayoutAlgorithmTest007 - * @tc.desc: Test XComponent measure functions when width or height is LayoutPolicy. - * @tc.type: FUNC - */ -HWTEST_F(XComponentPropertyTestNg, XComponentLayoutAlgorithmTest007, TestSize.Level1) -{ - std::shared_ptr const xComponentController; - XComponentModelNG xComponent; - xComponent.Create(XCOMPONENT_ID, XCOMPONENT_SURFACE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); - xComponent.SetSoPath(XCOMPONENT_SO_PATH); - auto frameNode = AceType::DynamicCast(ViewStackProcessor::GetInstance()->Finish()); - EXPECT_TRUE(frameNode != nullptr && frameNode->GetTag() == V2::XCOMPONENT_ETS_TAG); - // Create LayoutWrapper and set XComponentLayoutAlgorithm. - RefPtr geometryNode = AceType::MakeRefPtr(); - ASSERT_TRUE(geometryNode); - LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, geometryNode, frameNode->GetLayoutProperty()); - auto layoutProperty = frameNode->GetLayoutProperty(); - auto xComponentPattern = frameNode->GetPattern(); - ASSERT_TRUE(xComponentPattern); - RefPtr xComponentLayoutAlgorithm = AceType::MakeRefPtr(); - layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(xComponentLayoutAlgorithm)); - - /** - * @tc.steps1: Width is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - LayoutConstraintF layoutConstraint; - SizeF size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(0, 1000)); - - /** - * @tc.steps2: Height is WrapContent - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::WRAP_CONTENT, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(1000, 0)); - - /** - * @tc.steps3: Width is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (0, 1000) - */ - size = SizeF(1000.0f, 1000.0f); - layoutConstraint.parentIdealSize = OptionalSizeF(300.0f, 400.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(0, 1000)); - - /** - * @tc.steps4: Height is fixIdealSize - * @tc.expected: the return size of MeasureLayoutPolicySize is (1000, 0) - */ - size = SizeF(1000.0f, 1000.0f); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, true); - layoutProperty->UpdateLayoutPolicyProperty(LayoutCalPolicy::FIX_AT_IDEAL_SIZE, false); - xComponentLayoutAlgorithm->MeasureLayoutPolicySize(layoutConstraint, layoutProperty, size); - EXPECT_EQ(size, SizeF(1000, 0)); -} - /** * @tc.name: XComponentControllerSetExtControllerTest012 * @tc.desc: Test XComponent type = XComponentType::SURFACE, ResetExtController, SetExtController -- Gitee