diff --git a/test/unittest/core/pattern/indexer/BUILD.gn b/test/unittest/core/pattern/indexer/BUILD.gn index d84404d426469148dbceacfdc0b9a0e08426d45f..db6b34476636bf1a1f73783100654a31b16a75fc 100644 --- a/test/unittest/core/pattern/indexer/BUILD.gn +++ b/test/unittest/core/pattern/indexer/BUILD.gn @@ -19,6 +19,7 @@ ace_unittest("indexer_test_ng") { "arcindexer_pattern_test_ng.cpp", "indexer_accessibility_test_ng.cpp", "indexer_layout_test_ng.cpp", + "indexer_pattern_test_ng.cpp", "indexer_select_test_ng.cpp", "indexer_test_ng.cpp", ] diff --git a/test/unittest/core/pattern/indexer/indexer_pattern_test_ng.cpp b/test/unittest/core/pattern/indexer/indexer_pattern_test_ng.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94bb790c536d74aecf5c33a10196b6f2068e4b3d --- /dev/null +++ b/test/unittest/core/pattern/indexer/indexer_pattern_test_ng.cpp @@ -0,0 +1,585 @@ +/* + * 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 "test/mock/base/mock_system_properties.h" +#include "test/mock/core/common/mock_font_manager.h" +#include "test/mock/core/common/mock_theme_manager.h" +#include "test/mock/core/pipeline/mock_pipeline_context.h" +#include "test/unittest/core/pattern/test_ng.h" + +#include "core/components_ng/pattern/indexer/indexer_model_ng.h" +#include "core/components_ng/pattern/indexer/indexer_pattern.h" +#include "core/components_ng/pattern/linear_layout/linear_layout_property.h" + +namespace OHOS::Ace::NG { +using namespace testing; +using namespace testing::ext; +class IndexerPatternTestNg : public TestNG { +public: + static void SetUpTestSuite(); + static void TearDownTestSuite(); +}; + +void IndexerPatternTestNg::SetUpTestSuite() +{ + TestNG::SetUpTestSuite(); +} + +void IndexerPatternTestNg::TearDownTestSuite() +{ + TestNG::TearDownTestSuite(); +} + +/** + * @tc.name: BuildArrayValueItemsTest001 + * @tc.desc: BuildArrayValueItems + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, BuildArrayValueItemsTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->BuildArrayValueItems(); + + auto layoutProperty = indexNode->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + auto result = layoutProperty->HasActualArrayValue(); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: CollapseArrayValueTest001 + * @tc.desc: CollapseArrayValue + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, CollapseArrayValueTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->maxContentHeight_ = 32.0f; + pattern->lastCollapsingMode_ = IndexerCollapsingMode::INVALID; + pattern->CollapseArrayValue(); + EXPECT_EQ(pattern->lastCollapsingMode_, IndexerCollapsingMode::NONE); +} + +/** + * @tc.name: CollapseArrayValueTest001 + * @tc.desc: CollapseArrayValue + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, CollapseArrayValueTest002, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->sharpItemCount_ = 12; + pattern->lastCollapsingMode_ = IndexerCollapsingMode::INVALID; + pattern->CollapseArrayValue(); + EXPECT_EQ(pattern->lastCollapsingMode_, IndexerCollapsingMode::FIVE); +} + +/** + * @tc.name: CollapseArrayValueTest001 + * @tc.desc: CollapseArrayValue + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, CollapseArrayValueTest003, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->maxContentHeight_ = 14.0f; + pattern->fullArrayValue_ = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + + auto layoutProperty = indexNode->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + + Dimension value(1.0f); + layoutProperty->UpdateItemSize(value); + + pattern->lastCollapsingMode_ = IndexerCollapsingMode::INVALID; + pattern->CollapseArrayValue(); + EXPECT_EQ(pattern->lastCollapsingMode_, IndexerCollapsingMode::SEVEN); +} + +/** + * @tc.name: CollapseArrayValueTest001 + * @tc.desc: CollapseArrayValue + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, CollapseArrayValueTest004, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->maxContentHeight_ = 12.0f; + pattern->fullArrayValue_ = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + + auto layoutProperty = indexNode->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + + Dimension value(1.0f); + layoutProperty->UpdateItemSize(value); + + pattern->lastCollapsingMode_ = IndexerCollapsingMode::INVALID; + pattern->CollapseArrayValue(); + EXPECT_EQ(pattern->lastCollapsingMode_, IndexerCollapsingMode::FIVE); +} + +/** + * @tc.name: GetAutoCollapseIndexTest001 + * @tc.desc: GetAutoCollapseIndex + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, GetAutoCollapseIndexTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + pattern->fullArrayValue_ = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K" }; + pattern->sharpItemCount_ = 2; + pattern->lastCollapsingMode_ = IndexerCollapsingMode::SEVEN; + + int32_t result1 = pattern->GetAutoCollapseIndex(2); + EXPECT_EQ(result1, 2); + EXPECT_EQ(pattern->collapsedIndex_, 0); + + int32_t result2 = pattern->GetAutoCollapseIndex(3); + EXPECT_EQ(result2, 4); + EXPECT_EQ(pattern->collapsedIndex_, 0); + + int32_t result3 = pattern->GetAutoCollapseIndex(7); + EXPECT_EQ(result3, 14); + EXPECT_EQ(pattern->collapsedIndex_, 0); + + int32_t result4 = pattern->GetAutoCollapseIndex(8); + EXPECT_EQ(result4, 15); + EXPECT_EQ(pattern->collapsedIndex_, 0); + + int32_t result5 = pattern->GetAutoCollapseIndex(9); + EXPECT_EQ(result5, 16); + EXPECT_EQ(pattern->collapsedIndex_, 0); + + int32_t result6 = pattern->GetAutoCollapseIndex(10); + EXPECT_EQ(result6, 17); + EXPECT_EQ(pattern->collapsedIndex_, 0); +} + +/** + * @tc.name: GetSkipChildIndexTest001 + * @tc.desc: GetSkipChildIndex + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, GetSkipChildIndexTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + int32_t step = -2; + auto result = pattern->GetSkipChildIndex(step); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: GetSkipChildIndexTest002 + * @tc.desc: GetSkipChildIndex + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, GetSkipChildIndexTest002, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + int32_t step = 2; + auto result = pattern->GetSkipChildIndex(step); + EXPECT_EQ(result, 2); +} + +/** + * @tc.name: GetSkipChildIndexTest002 + * @tc.desc: GetSkipChildIndex + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, GetSkipChildIndexTest003, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + int32_t step = 2; + pattern->itemCount_ = 1; + + auto result = pattern->GetSkipChildIndex(step); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: UpdateNormalStyleTest001 + * @tc.desc: UpdateNormalStyle + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateNormalStyleTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto renderContext = indexNode->GetRenderContext(); + ASSERT_NE(pattern, nullptr); + + pattern->UpdateNormalStyle(renderContext, 0, true); + + Color defaultValue = Color::BLACK; + auto result = renderContext->GetBackgroundColorValue(defaultValue); + EXPECT_EQ(result, Color::TRANSPARENT); +} + +/** + * @tc.name: UpdateNormalStyleTest002 + * @tc.desc: UpdateNormalStyle + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateNormalStyleTest002, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto renderContext = indexNode->GetRenderContext(); + ASSERT_NE(pattern, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + pattern->UpdateNormalStyle(renderContext, 0, true); + + auto value = Dimension(0.0, DimensionUnit::VP); + BorderRadiusProperty defaultValue = { value, value, value, value }; + auto result = renderContext->GetBorderRadiusValue(defaultValue); + EXPECT_NE(result.radiusTopLeft, value); + EXPECT_NE(result.radiusTopRight, value); + EXPECT_NE(result.radiusBottomRight, value); + EXPECT_NE(result.radiusBottomLeft, value); +} + +/** + * @tc.name: UpdateNormalStyleTest003 + * @tc.desc: UpdateNormalStyle + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateNormalStyleTest003, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto renderContext = indexNode->GetRenderContext(); + ASSERT_NE(pattern, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_SIXTEEN); + pattern->UpdateNormalStyle(renderContext, 0, true); + + auto value = Dimension(8.0, DimensionUnit::VP); + BorderRadiusProperty defaultValue = { value, value, value, value }; + auto result = renderContext->GetBorderRadiusValue(defaultValue); + EXPECT_NE(result.radiusTopLeft, value); + EXPECT_NE(result.radiusTopRight, value); + EXPECT_NE(result.radiusBottomRight, value); + EXPECT_NE(result.radiusBottomLeft, value); +} + +/** + * @tc.name: UpdateBubbleViewTest001 + * @tc.desc: UpdateBubbleView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleViewTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto layoutProperty = pattern->popupNode_->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + pattern->currentListData_ = { "1" }; + pattern->UpdateBubbleView(); + + auto value = CalcLength(0.0); + const auto& padding = layoutProperty->GetPaddingProperty(); + EXPECT_NE(padding, nullptr); + EXPECT_EQ(padding->left, value); + EXPECT_EQ(padding->right, value); + EXPECT_EQ(padding->top, CalcLength(4.0)); + EXPECT_EQ(padding->bottom, value); +} + +/** + * @tc.name: UpdateBubbleViewTest002 + * @tc.desc: UpdateBubbleView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleViewTest002, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto paintProperty = indexNode->GetPaintProperty(); + ASSERT_NE(paintProperty, nullptr); + + auto renderContext = pattern->popupNode_->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + pattern->currentListData_ = { "1" }; + Dimension popupValue(16.0f, DimensionUnit::VP); + paintProperty->UpdatePopupBorderRadius(popupValue); + pattern->UpdateBubbleView(); + + auto value = Dimension(0.0f, DimensionUnit::VP); + BorderRadiusProperty defaultValue = { value, value, value, value }; + auto result = renderContext->GetBorderRadiusValue(defaultValue); + EXPECT_EQ(result.radiusTopLeft, popupValue); + EXPECT_EQ(result.radiusTopRight, popupValue); + EXPECT_EQ(result.radiusBottomRight, popupValue); + EXPECT_EQ(result.radiusBottomLeft, popupValue); +} + +/** + * @tc.name: UpdateBubbleViewTest003 + * @tc.desc: UpdateBubbleView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleViewTest003, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto paintProperty = indexNode->GetPaintProperty(); + ASSERT_NE(paintProperty, nullptr); + + auto renderContext = pattern->popupNode_->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + pattern->currentListData_ = { "1" }; + Dimension popupValue(28.0f, DimensionUnit::VP); + pattern->UpdateBubbleView(); + + auto value = Dimension(0.0f, DimensionUnit::VP); + BorderRadiusProperty defaultValue = { value, value, value, value }; + auto result = renderContext->GetBorderRadiusValue(defaultValue); + EXPECT_EQ(result.radiusTopLeft, popupValue); + EXPECT_EQ(result.radiusTopRight, popupValue); + EXPECT_EQ(result.radiusBottomRight, popupValue); + EXPECT_EQ(result.radiusBottomLeft, popupValue); +} + +/** + * @tc.name: UpdateBubbleViewTest004 + * @tc.desc: UpdateBubbleView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleViewTest004, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto paintProperty = indexNode->GetPaintProperty(); + ASSERT_NE(paintProperty, nullptr); + + auto renderContext = pattern->popupNode_->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_SIXTEEN); + pattern->currentListData_ = { "1" }; + Dimension popupValue(16.0f, DimensionUnit::VP); + pattern->UpdateBubbleView(); + + auto value = Dimension(0.0f, DimensionUnit::VP); + BorderRadiusProperty defaultValue = { value, value, value, value }; + auto result = renderContext->GetBorderRadiusValue(defaultValue); + EXPECT_EQ(result.radiusTopLeft, popupValue); + EXPECT_EQ(result.radiusTopRight, popupValue); + EXPECT_EQ(result.radiusBottomRight, popupValue); + EXPECT_EQ(result.radiusBottomLeft, popupValue); +} + +/** + * @tc.name: UpdateBubbleBackgroundViewTest001 + * @tc.desc: UpdateBubbleBackgroundView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleBackgroundViewTest001, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto paintProperty = indexNode->GetPaintProperty(); + ASSERT_NE(paintProperty, nullptr); + + auto renderContext = pattern->popupNode_->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + auto pipeline = indexNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + + auto indexerTheme = pipeline->GetTheme(); + ASSERT_NE(indexerTheme, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + BlurStyleOption styleption; + styleption.blurStyle = BlurStyle::BACKGROUND_THIN; + paintProperty->UpdatePopupBackgroundBlurStyle(styleption); + pattern->UpdateBubbleBackgroundView(); + auto result = paintProperty->GetPopupBackgroundBlurStyle().has_value(); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: UpdateBubbleBackgroundViewTest002 + * @tc.desc: UpdateBubbleBackgroundView + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestNg, UpdateBubbleBackgroundViewTest002, TestSize.Level1) +{ + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto indexNode = AceType::DynamicCast(element); + ASSERT_NE(indexNode, nullptr); + + auto pattern = indexNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto paintProperty = indexNode->GetPaintProperty(); + ASSERT_NE(paintProperty, nullptr); + + auto renderContext = pattern->popupNode_->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + auto pipeline = indexNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + + auto indexerTheme = pipeline->GetTheme(); + ASSERT_NE(indexerTheme, nullptr); + + Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE); + pattern->UpdateBubbleBackgroundView(); + auto result = paintProperty->GetPopupBackgroundBlurStyle().has_value(); + EXPECT_EQ(result, false); + + BlurStyleOption styleption; + EXPECT_EQ(styleption.blurStyle, BlurStyle::COMPONENT_REGULAR); +} +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/pattern/tabs/tabs_pattern_test_ng.cpp b/test/unittest/core/pattern/tabs/tabs_pattern_test_ng.cpp index 3f5852b1c9d2512eb6f0480eeb07c3350517d338..9a626db423780d0df1f7df146708cc816f0fa160 100644 --- a/test/unittest/core/pattern/tabs/tabs_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/tabs/tabs_pattern_test_ng.cpp @@ -25,8 +25,8 @@ #include "base/geometry/ng/size_t.h" #include "core/components_ng/base/observer_handler.h" #include "core/components_ng/pattern/pattern.h" -#include "core/pipeline_ng/pipeline_context.h" #include "core/components_ng/pattern/tabs/tabs_node.h" +#include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { class TabPatternTestNg : public TabsTestNg { @@ -62,7 +62,7 @@ HWTEST_F(TabPatternTestNg, UpdateSwiperDisableSwipeTest001, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperPattern = swiperNode->GetPattern(); ASSERT_NE(swiperPattern, nullptr); @@ -85,7 +85,7 @@ HWTEST_F(TabPatternTestNg, SetAnimateModeTest001, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperPattern = swiperNode->GetPattern(); ASSERT_NE(swiperPattern, nullptr); @@ -108,7 +108,7 @@ HWTEST_F(TabPatternTestNg, UpdateSelectedStateTest001, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperPattern = swiperNode->GetPattern(); ASSERT_NE(swiperPattern, nullptr); @@ -143,7 +143,7 @@ HWTEST_F(TabPatternTestNg, UpdateSelectedStateTest002, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperPattern = swiperNode->GetPattern(); ASSERT_NE(swiperPattern, nullptr); @@ -206,7 +206,7 @@ HWTEST_F(TabPatternTestNg, RecoverInnerOnGestureRecognizerJudgeBeginTest001, Tes auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto targetComponent = swiperNode->GetTargetComponent().Upgrade(); CHECK_NULL_VOID(targetComponent); @@ -369,7 +369,7 @@ HWTEST_F(TabPatternTestNg, GetCurrentFocusNode001, TestSize.Level1) auto tabBarFocusHub = tabBarNode->GetFocusHub(); CHECK_NULL_VOID(tabBarFocusHub); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -402,7 +402,7 @@ HWTEST_F(TabPatternTestNg, GetCurrentFocusNode002, TestSize.Level1) auto tabBarFocusHub = tabBarNode->GetFocusHub(); CHECK_NULL_VOID(tabBarFocusHub); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -435,7 +435,7 @@ HWTEST_F(TabPatternTestNg, GetCurrentFocusNode003, TestSize.Level1) auto tabBarFocusHub = tabBarNode->GetFocusHub(); CHECK_NULL_VOID(tabBarFocusHub); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -468,7 +468,7 @@ HWTEST_F(TabPatternTestNg, GetCurrentFocusNode004, TestSize.Level1) auto tabBarFocusHub = tabBarNode->GetFocusHub(); CHECK_NULL_VOID(tabBarFocusHub); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -498,10 +498,10 @@ HWTEST_F(TabPatternTestNg, InitAccessibilityZIndexTest001, TestSize.Level1) auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); CHECK_NULL_VOID(tabBarNode); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperAccessibilityProperty = swiperNode->GetAccessibilityProperty(); ASSERT_NE(swiperAccessibilityProperty, nullptr); @@ -529,10 +529,10 @@ HWTEST_F(TabPatternTestNg, InitAccessibilityZIndexTest002, TestSize.Level1) auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); CHECK_NULL_VOID(tabBarNode); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto swiperAccessibilityProperty = swiperNode->GetAccessibilityProperty(); ASSERT_NE(swiperAccessibilityProperty, nullptr); @@ -563,10 +563,10 @@ HWTEST_F(TabPatternTestNg, InitAccessibilityZIndexTest003, TestSize.Level1) auto tabBarFocusHub = tabBarNode->GetFocusHub(); ASSERT_NE(tabBarFocusHub, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto tabBarAccessibilityProperty = tabBarNode->GetAccessibilityProperty(); ASSERT_NE(tabBarAccessibilityProperty, nullptr); @@ -594,10 +594,10 @@ HWTEST_F(TabPatternTestNg, InitAccessibilityZIndexTest004, TestSize.Level1) auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); CHECK_NULL_VOID(tabBarNode); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); - + auto tabBarAccessibilityProperty = tabBarNode->GetAccessibilityProperty(); ASSERT_NE(tabBarAccessibilityProperty, nullptr); @@ -654,7 +654,7 @@ HWTEST_F(TabPatternTestNg, FireTabContentStateCallbackTest001, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -681,7 +681,7 @@ HWTEST_F(TabPatternTestNg, FireTabContentStateCallbackTest002, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -708,7 +708,7 @@ HWTEST_F(TabPatternTestNg, FireTabContentStateCallbackTest003, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -736,14 +736,14 @@ HWTEST_F(TabPatternTestNg, FireTabContentStateCallbackTest004, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); auto child = swiperNode->GetChildren(); auto oldIndex = 1; auto nextIndex = static_cast(child.size()); - + tabsPattern->FireTabContentStateCallback(oldIndex, nextIndex); auto oldTabContentFunc = UIObserverHandler::GetInstance().tabContentStateHandleFunc_; EXPECT_NE(oldTabContentFunc, nullptr); @@ -764,7 +764,7 @@ HWTEST_F(TabPatternTestNg, RecordChangeEventTest001, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); CHECK_NULL_VOID(swiperNode); @@ -786,7 +786,7 @@ HWTEST_F(TabPatternTestNg, ProvideRestoreInfoTest001, TestSize.Level1) auto tabsNode = AceType::MakeRefPtr(V2::TABS_ETS_TAG, 2, tabsPattern, true); ASSERT_NE(tabsNode, nullptr); - + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); CHECK_NULL_VOID(tabBarNode); @@ -1037,7 +1037,7 @@ HWTEST_F(TabPatternTestNg, GetEdgeEffectTest001, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); ASSERT_NE(swiperNode, nullptr); - + auto swiperPaintProperty = swiperNode->GetPaintProperty(); ASSERT_NE(swiperPaintProperty, nullptr); @@ -1061,7 +1061,7 @@ HWTEST_F(TabPatternTestNg, GetEdgeEffectTest002, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); ASSERT_NE(swiperNode, nullptr); - + auto swiperPaintProperty = swiperNode->GetPaintProperty(); ASSERT_NE(swiperPaintProperty, nullptr); @@ -1085,7 +1085,7 @@ HWTEST_F(TabPatternTestNg, GetEdgeEffectTest003, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); ASSERT_NE(swiperNode, nullptr); - + auto swiperPaintProperty = swiperNode->GetPaintProperty(); ASSERT_NE(swiperPaintProperty, nullptr); @@ -1109,11 +1109,12 @@ HWTEST_F(TabPatternTestNg, GetEdgeEffectTest004, TestSize.Level1) auto swiperNode = AceType::DynamicCast(tabsNode->GetTabs()); ASSERT_NE(swiperNode, nullptr); - + auto swiperPaintProperty = swiperNode->GetPaintProperty(); ASSERT_NE(swiperPaintProperty, nullptr); - auto result = swiperPaintProperty->propEdgeEffect_.has_value();; + auto result = swiperPaintProperty->propEdgeEffect_.has_value(); + ; EXPECT_NE(result, false); } @@ -1122,27 +1123,27 @@ HWTEST_F(TabPatternTestNg, GetEdgeEffectTest004, TestSize.Level1) * @tc.desc: GetCurrentOffset * @tc.type: FUNC */ -HWTEST_F(TabPatternTestNg, GetCurrentOffset001, TestSize.Level1) +HWTEST_F(TabPatternTestNg, GetCurrentOffsetTest001, TestSize.Level1) { RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); CHECK_NULL_VOID(element); auto tabsNode = AceType::DynamicCast(element); ASSERT_NE(tabsNode, nullptr); - + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); ASSERT_NE(tabBarNode, nullptr); - + auto tabBarPattern = tabBarNode->GetPattern(); ASSERT_NE(tabBarPattern, nullptr); - + auto tabBarLayoutProperty = tabBarNode->GetLayoutProperty(); ASSERT_NE(tabBarLayoutProperty, nullptr); - + auto tabbarLayoutAlgorithm = AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); ASSERT_NE(tabbarLayoutAlgorithm, nullptr); - + ScrollableBarModeOptions layoutStyle; layoutStyle.nonScrollableLayoutStyle = LayoutStyle::ALWAYS_AVERAGE_SPLIT; tabbarLayoutAlgorithm->contentMainSize_ = 100.0f; @@ -1156,27 +1157,27 @@ HWTEST_F(TabPatternTestNg, GetCurrentOffset001, TestSize.Level1) * @tc.desc: GetCurrentOffset * @tc.type: FUNC */ -HWTEST_F(TabPatternTestNg, GetCurrentOffset002, TestSize.Level1) +HWTEST_F(TabPatternTestNg, GetCurrentOffsetTest002, TestSize.Level1) { RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); CHECK_NULL_VOID(element); - + auto tabsNode = AceType::DynamicCast(element); ASSERT_NE(tabsNode, nullptr); - + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); ASSERT_NE(tabBarNode, nullptr); - + auto tabBarPattern = tabBarNode->GetPattern(); ASSERT_NE(tabBarPattern, nullptr); - + auto tabBarLayoutProperty = tabBarNode->GetLayoutProperty(); ASSERT_NE(tabBarLayoutProperty, nullptr); - + auto tabbarLayoutAlgorithm = AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); ASSERT_NE(tabbarLayoutAlgorithm, nullptr); - + auto margin = 100.0f; ScrollableBarModeOptions option; option.margin = Dimension(margin); @@ -1194,31 +1195,31 @@ HWTEST_F(TabPatternTestNg, GetCurrentOffset002, TestSize.Level1) * @tc.desc: GetCurrentOffset * @tc.type: FUNC */ -HWTEST_F(TabPatternTestNg, GetCurrentOffset003, TestSize.Level1) +HWTEST_F(TabPatternTestNg, GetCurrentOffsetTest003, TestSize.Level1) { RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); CHECK_NULL_VOID(element); - + auto tabsNode = AceType::DynamicCast(element); ASSERT_NE(tabsNode, nullptr); - + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); ASSERT_NE(tabBarNode, nullptr); - + auto tabBarPattern = tabBarNode->GetPattern(); ASSERT_NE(tabBarPattern, nullptr); - + auto tabBarLayoutProperty = tabBarNode->GetLayoutProperty(); ASSERT_NE(tabBarLayoutProperty, nullptr); - + auto tabbarLayoutAlgorithm = AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); ASSERT_NE(tabbarLayoutAlgorithm, nullptr); - + auto margin = 100.0f; ScrollableBarModeOptions option; option.margin = Dimension(margin); - + ScrollableBarModeOptions layoutStyle; tabbarLayoutAlgorithm->axis_ = Axis::VERTICAL; tabbarLayoutAlgorithm->contentMainSize_ = 100.0f; @@ -1226,4 +1227,212 @@ HWTEST_F(TabPatternTestNg, GetCurrentOffset003, TestSize.Level1) auto currentOffset = tabbarLayoutAlgorithm->GetCurrentOffset(tabBarLayoutProperty, layoutStyle); EXPECT_EQ(currentOffset, 40.0f); } + +/** + * @tc.name: CheckBorderAndPaddingTest001 + * @tc.desc: CheckBorderAndPadding + * @tc.type: FUNC + */ +HWTEST_F(TabPatternTestNg, CheckBorderAndPaddingTest001, TestSize.Level1) +{ + auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId(); + auto frameNode = + FrameNode::GetOrCreateFrameNode(V2::TABS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + ViewStackProcessor::GetInstance()->Push(frameNode); + + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto tabsNode = AceType::DynamicCast(element); + CHECK_NULL_VOID(tabsNode); + + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); + ASSERT_NE(tabBarNode, nullptr); + + auto tabBarPattern = tabBarNode->GetPattern(); + ASSERT_NE(tabBarPattern, nullptr); + + auto tabbarLayoutAlgorithm = + AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); + ASSERT_NE(tabbarLayoutAlgorithm, nullptr); + + SizeF frameSize; + float width = 1.0f; + float height = 1.0f; + frameSize.SetWidth(width); + frameSize.SetWidth(height); + + PaddingPropertyF padding = { 1.0f, 1.0f, 1.0f, 1.0f }; + tabbarLayoutAlgorithm->CheckBorderAndPadding(frameSize, padding); + EXPECT_EQ(frameSize.Width(), 2.0f); + EXPECT_EQ(frameSize.Height(), 2.0f); +} + +/** + * @tc.name: CheckBorderAndPaddingTest002 + * @tc.desc: CheckBorderAndPadding + * @tc.type: FUNC + */ +HWTEST_F(TabPatternTestNg, CheckBorderAndPaddingTest002, TestSize.Level1) +{ + auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId(); + auto frameNode = + FrameNode::GetOrCreateFrameNode(V2::TABS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + ViewStackProcessor::GetInstance()->Push(frameNode); + + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto tabsNode = AceType::DynamicCast(element); + CHECK_NULL_VOID(tabsNode); + + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); + ASSERT_NE(tabBarNode, nullptr); + + auto tabBarPattern = tabBarNode->GetPattern(); + ASSERT_NE(tabBarPattern, nullptr); + + auto tabbarLayoutAlgorithm = + AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); + ASSERT_NE(tabbarLayoutAlgorithm, nullptr); + + SizeF frameSize; + float width = 2.0f; + float height = 2.0f; + frameSize.SetWidth(width); + frameSize.SetWidth(height); + + PaddingPropertyF padding = { -1.0f, -1.0f, -1.0f, -1.0f }; + tabbarLayoutAlgorithm->CheckBorderAndPadding(frameSize, padding); + EXPECT_EQ(frameSize.Width(), 2.0f); + EXPECT_EQ(frameSize.Height(), 2.0f); +} + +/** + * @tc.name: NeedAdaptForAgingTest001 + * @tc.desc: NeedAdaptForAging + * @tc.type: FUNC + */ +HWTEST_F(TabPatternTestNg, NeedAdaptForAgingTest001, TestSize.Level1) +{ + auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId(); + auto frameNode = + FrameNode::GetOrCreateFrameNode(V2::TABS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + ViewStackProcessor::GetInstance()->Push(frameNode); + + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto tabsNode = AceType::DynamicCast(element); + CHECK_NULL_VOID(tabsNode); + + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); + ASSERT_NE(tabBarNode, nullptr); + + auto tabBarPattern = tabBarNode->GetPattern(); + ASSERT_NE(tabBarPattern, nullptr); + + auto tabbarLayoutAlgorithm = + AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); + ASSERT_NE(tabbarLayoutAlgorithm, nullptr); + + auto pipeline = tabBarNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + pipeline->fontScale_ = 1.0f; + + auto result = tabbarLayoutAlgorithm->NeedAdaptForAging(tabBarNode); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: NeedAdaptForAgingTest002 + * @tc.desc: NeedAdaptForAging + * @tc.type: FUNC + */ +HWTEST_F(TabPatternTestNg, NeedAdaptForAgingTest002, TestSize.Level1) +{ + auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId(); + auto frameNode = + FrameNode::GetOrCreateFrameNode(V2::TABS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + ViewStackProcessor::GetInstance()->Push(frameNode); + + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto tabsNode = AceType::DynamicCast(element); + CHECK_NULL_VOID(tabsNode); + + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); + ASSERT_NE(tabBarNode, nullptr); + + auto tabBarPattern = tabBarNode->GetPattern(); + ASSERT_NE(tabBarPattern, nullptr); + + auto tabbarLayoutAlgorithm = + AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); + ASSERT_NE(tabbarLayoutAlgorithm, nullptr); + + auto pipeline = tabBarNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + pipeline->fontScale_ = 2.0f; + + auto result = tabbarLayoutAlgorithm->NeedAdaptForAging(tabBarNode); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: GetNoMinHeightLimitTest001 + * @tc.desc: GetNoMinHeightLimit + * @tc.type: FUNC + */ +HWTEST_F(TabPatternTestNg, GetNoMinHeightLimitTest001, TestSize.Level1) +{ + auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId(); + auto frameNode = + FrameNode::GetOrCreateFrameNode(V2::TABS_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + ViewStackProcessor::GetInstance()->Push(frameNode); + + RefPtr element = ViewStackProcessor::GetInstance()->GetMainElementNode(); + CHECK_NULL_VOID(element); + + auto tabsNode = AceType::DynamicCast(element); + CHECK_NULL_VOID(tabsNode); + + auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); + ASSERT_NE(tabBarNode, nullptr); + + auto tabBarPattern = tabBarNode->GetPattern(); + ASSERT_NE(tabBarPattern, nullptr); + + auto tabBarLayoutProperty = tabBarNode->GetLayoutProperty(); + ASSERT_NE(tabBarLayoutProperty, nullptr); + + auto tabbarLayoutAlgorithm = + AceType::DynamicCast(tabBarNode->GetPattern()->CreateLayoutAlgorithm()); + ASSERT_NE(tabbarLayoutAlgorithm, nullptr); + + RefPtr geometryNode = AceType::MakeRefPtr(); + ASSERT_NE(geometryNode, nullptr); + + LayoutWrapperNode layoutWrapper = LayoutWrapperNode(tabBarNode, geometryNode, tabBarNode->GetLayoutProperty()); + layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(tabbarLayoutAlgorithm)); + + auto pipeline = tabBarNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + pipeline->fontScale_ = 2.0f; + + bool result = false; + tabbarLayoutAlgorithm->tabBarStyle_ = TabBarStyle::SUBTABBATSTYLE; + result = tabbarLayoutAlgorithm->GetNoMinHeightLimit(&layoutWrapper); + EXPECT_EQ(result, true); + + tabbarLayoutAlgorithm->tabBarStyle_ = TabBarStyle::BOTTOMTABBATSTYLE; + result = tabbarLayoutAlgorithm->GetNoMinHeightLimit(&layoutWrapper); + EXPECT_EQ(result, false); +} } // namespace OHOS::Ace::NG \ No newline at end of file