!38574 【TDD】新增toggle和slider的tdd用例

Merge pull request !38574 from 林昊/5_0723_addTDD
This commit is contained in:
openharmony_ci 2024-07-24 03:54:10 +00:00 committed by Gitee
commit 823072ae9a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 574 additions and 0 deletions

View File

@ -101,6 +101,16 @@ const OffsetF SLIDER_GLOBAL_OFFSET = { 200.0f, 200.0f };
const SizeF BLOCK_SIZE_F(10.0f, 10.0f);
const SizeF BLOCK_SIZE_F_ZREO(0.0f, 0.0f);
constexpr float SLIDER_NEGATIVE = -5.0f;
constexpr Dimension BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_1_WIDTH = 92.0_vp;
constexpr Dimension BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_1_HEIGHT = 52.0_vp;
constexpr Dimension BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_1_WIDTH = 48.0_vp;
constexpr Dimension BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_1_HEIGHT = 60.0_vp;
constexpr Dimension BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_2_WIDTH = 96.0_vp;
constexpr Dimension BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_2_HEIGHT = 56.0_vp;
constexpr Dimension BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_2_WIDTH = 48.0_vp;
constexpr Dimension BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_2_HEIGHT = 64.0_vp;
constexpr Dimension SUITABLEAGING_LEVEL_1_TEXT_FONT_SIZE = 25.0_vp;
constexpr Dimension SUITABLEAGING_LEVEL_2_TEXT_FONT_SIZE = 28.0_vp;
} // namespace
class SliderModifierTestNg : public testing::Test {
public:
@ -1520,4 +1530,165 @@ HWTEST_F(SliderModifierTestNg, SliderModelNgTest002, TestSize.Level1)
Dimension testResult = sliderModelNG.GetThickness(AceType::RawPtr(frameNode));
EXPECT_EQ(testResult, RADIUS);
}
/**
* @tc.name: SliderTipModifierTest002
* @tc.desc: TEST slider_tip_modifier PaintText
* @tc.type: FUNC
*/
HWTEST_F(SliderModifierTestNg, SliderTipModifierTest002, TestSize.Level1)
{
/**
* @tc.steps: step1. create frameNode and sliderTipModifier.
*/
RefPtr<SliderPattern> sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto frameNode = FrameNode::CreateFrameNode(V2::SLIDER_ETS_TAG, -1, sliderPattern);
ASSERT_NE(frameNode, nullptr);
auto sliderLayoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
ASSERT_NE(sliderLayoutProperty, nullptr);
SliderTipModifier sliderTipModifier(
[sliderPattern]() { return sliderPattern->GetBubbleVertexPosition(OffsetF(), 0.0f, SizeF()); });
/**
* @tc.steps: step2. set sliderTipModifier's axis is HORIZONTAL and call PaintText function.
* @tc.expected: text's offsetX is equal to half of vertex_'s width.
*/
sliderTipModifier.SetSliderGlobalOffset(SLIDER_GLOBAL_OFFSET);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(true);
Testing::MockCanvas canvas;
MockCanvasFunction(canvas);
DrawingContext context { canvas, SLIDER_WIDTH, SLIDER_HEIGHT };
sliderTipModifier.axis_ = Axis::HORIZONTAL;
sliderTipModifier.isMask_ = true;
auto paragraph = MockParagraph::GetOrCreateMockParagraph();
sliderTipModifier.SetParagraph(paragraph);
sliderTipModifier.PaintTip(context);
SizeF textSize = { 8, 8 };
/**
* @tc.steps: step2. set sliderTipModifier's axis is VERTICAL and call PaintText function.
*/
sliderTipModifier.axis_ = Axis::VERTICAL;
sliderTipModifier.isMask_ = true;
sliderTipModifier.PaintText(context);
sliderTipModifier.axis_ = Axis::HORIZONTAL;
sliderTipModifier.PaintText(context);
EXPECT_EQ(sliderTipModifier.textOffset_.GetY(), sliderTipModifier.vertex_.GetY() + textSize.Width() * HALF);
}
/**
* @tc.name: SliderTipModifierTest003
* @tc.desc: TEST SliderTipModifier::SetTipFlag
* @tc.type: FUNC
*/
HWTEST_F(SliderModifierTestNg, SliderTipModifierTest003, TestSize.Level1)
{
/**
* @tc.steps: step1. create frameNode and sliderTipModifier.
*/
RefPtr<SliderPattern> sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto frameNode = FrameNode::CreateFrameNode(V2::SLIDER_ETS_TAG, -1, sliderPattern);
ASSERT_NE(frameNode, nullptr);
auto sliderLayoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
ASSERT_NE(sliderLayoutProperty, nullptr);
SliderTipModifier sliderTipModifier(
[sliderPattern]() { return sliderPattern->GetBubbleVertexPosition(OffsetF(), 0.0f, SizeF()); });
/**
* @tc.steps: step2. set sliderTipModifier's axis is HORIZONTAL and call PaintText function.
* @tc.expected: text's offsetX is equal to half of vertex_'s width.
*/
sliderTipModifier.SetSliderGlobalOffset(SLIDER_GLOBAL_OFFSET);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(true);
sliderTipModifier.SetTipFlag(false);
EXPECT_EQ(sliderTipModifier.tipFlag_, true);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(false);
sliderTipModifier.SetTipFlag(true);
EXPECT_EQ(sliderTipModifier.tipFlag_, true);
}
/**
* @tc.name: SliderTipModifierTest004
* @tc.desc: TEST SliderTipModifier::BuildParagraph
* @tc.type: FUNC
*/
HWTEST_F(SliderModifierTestNg, SliderTipModifierTest00, TestSize.Level1)
{
/**
* @tc.steps: step1. create frameNode and sliderTipModifier.
*/
RefPtr<SliderPattern> sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto frameNode = FrameNode::CreateFrameNode(V2::SLIDER_ETS_TAG, -1, sliderPattern);
ASSERT_NE(frameNode, nullptr);
auto sliderLayoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
ASSERT_NE(sliderLayoutProperty, nullptr);
SliderTipModifier sliderTipModifier(
[sliderPattern]() { return sliderPattern->GetBubbleVertexPosition(OffsetF(), 0.0f, SizeF()); });
/**
* @tc.steps: step2. set sliderTipModifier's axis is HORIZONTAL and call PaintText function.
* @tc.expected: text's offsetX is equal to half of vertex_'s width.
*/
auto pipeline = MockPipelineContext::GetCurrent();
pipeline->SetFontScale(1.8f);
sliderTipModifier.SetSliderGlobalOffset(SLIDER_GLOBAL_OFFSET);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(true);
sliderTipModifier.BuildParagraph();
EXPECT_EQ(sliderTipModifier.textFontSize_, SUITABLEAGING_LEVEL_1_TEXT_FONT_SIZE);
pipeline->SetFontScale(2.5f);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(false);
sliderTipModifier.BuildParagraph();
EXPECT_EQ(sliderTipModifier.textFontSize_, SUITABLEAGING_LEVEL_2_TEXT_FONT_SIZE);
}
/**
* @tc.name: SliderTipModifierTest005
* @tc.desc: TEST SliderTipModifier::UpdateBubbleSize
* @tc.type: FUNC
*/
HWTEST_F(SliderModifierTestNg, SliderTipModifierTest005, TestSize.Level1)
{
/**
* @tc.steps: step1. create frameNode and sliderTipModifier.
*/
RefPtr<SliderPattern> sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto frameNode = FrameNode::CreateFrameNode(V2::SLIDER_ETS_TAG, -1, sliderPattern);
ASSERT_NE(frameNode, nullptr);
auto sliderLayoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
ASSERT_NE(sliderLayoutProperty, nullptr);
SliderTipModifier sliderTipModifier(
[sliderPattern]() { return sliderPattern->GetBubbleVertexPosition(OffsetF(), 0.0f, SizeF()); });
/**
* @tc.steps: step2. set sliderTipModifier's axis is HORIZONTAL and call PaintText function.
* @tc.expected: text's offsetX is equal to half of vertex_'s width.
*/
auto pipeline = MockPipelineContext::GetCurrent();
pipeline->SetFontScale(1.8f);
sliderTipModifier.SetSliderGlobalOffset(SLIDER_GLOBAL_OFFSET);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(true);
sliderTipModifier.UpdateBubbleSize();
float bubbleSizeHeight = static_cast<float>(BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_1_WIDTH.ConvertToPx());
float bubbleSizeWidth = static_cast<float>(BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_1_HEIGHT.ConvertToPx());
EXPECT_EQ(sliderTipModifier.bubbleSize_, SizeF(bubbleSizeHeight, bubbleSizeWidth));
sliderTipModifier.axis_ = Axis::VERTICAL;
sliderTipModifier.UpdateBubbleSize();
bubbleSizeHeight = static_cast<float>(BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_1_WIDTH.ConvertToPx());
bubbleSizeWidth = static_cast<float>(BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_1_HEIGHT.ConvertToPx());
EXPECT_EQ(sliderTipModifier.bubbleSize_, SizeF(bubbleSizeHeight, bubbleSizeWidth));
pipeline->SetFontScale(2.5f);
sliderTipModifier.tipFlag_ = AceType::MakeRefPtr<PropertyBool>(false);
sliderTipModifier.UpdateBubbleSize();
bubbleSizeHeight = static_cast<float>(BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_2_WIDTH.ConvertToPx());
bubbleSizeWidth = static_cast<float>(BUBBLE_VERTICAL_SUITABLEAGING_LEVEL_2_HEIGHT.ConvertToPx());
EXPECT_EQ(sliderTipModifier.bubbleSize_, SizeF(bubbleSizeHeight, bubbleSizeWidth));
sliderTipModifier.axis_ = Axis::HORIZONTAL;
sliderTipModifier.UpdateBubbleSize();
bubbleSizeHeight = static_cast<float>(BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_2_WIDTH.ConvertToPx());
bubbleSizeWidth = static_cast<float>(BUBBLE_HORIZONTAL_SUITABLEAGING_LEVEL_2_HEIGHT.ConvertToPx());
EXPECT_EQ(sliderTipModifier.bubbleSize_, SizeF(bubbleSizeHeight, bubbleSizeWidth));
}
} // namespace OHOS::Ace::NG

View File

@ -13,12 +13,14 @@
* limitations under the License.
*/
#include <type_traits>
#include "gtest/gtest.h"
#define private public
#define protected public
#include "test/mock/base/mock_task_executor.h"
#include "test/mock/core/render/mock_paragraph.h"
#include "test/mock/core/common/mock_container.h"
#include "base/geometry/axis.h"
#include "base/geometry/dimension.h"
@ -44,6 +46,7 @@
#include "test/mock/core/common/mock_theme_manager.h"
#include "core/components_v2/inspector/inspector_constants.h"
#include "test/mock/core/pipeline/mock_pipeline_context.h"
#include "core/components_ng/pattern/root/root_pattern.h"
using namespace testing;
using namespace testing::ext;
@ -100,6 +103,9 @@ constexpr Dimension TRACK_BORDER_RADIUS = 5.0_px;
const OffsetF SLIDER_GLOBAL_OFFSET = { 200.0f, 200.0f };
const SizeF BLOCK_SIZE_F(10.0f, 10.0f);
const SizeF BLOCK_SIZE_F_ZREO(0.0f, 0.0f);
const Offset SLIDER_OFFSET = { 200, 200 };
constexpr float MIN_LABEL = 10.0f;
constexpr float MAX_LABEL = 20.0f;
} // namespace
class SliderPatternTestNg : public testing::Test {
public:
@ -118,11 +124,13 @@ private:
void SliderPatternTestNg::SetUpTestSuite()
{
MockPipelineContext::SetUp();
MockContainer::SetUp();
}
void SliderPatternTestNg::TearDownTestSuite()
{
MockPipelineContext::TearDown();
MockContainer::TearDown();
}
void SliderPatternTestNg::TearDown()
@ -927,4 +935,257 @@ HWTEST_F(SliderPatternTestNg, SliderPatternTest014, TestSize.Level1)
sliderPattern->SetBuilderFunc(node);
sliderPattern->BuildContentModifierNode();
}
/**
* @tc.name: SliderPatternTest015
* @tc.desc: SliderPattern::OnWindowSizeChanged.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest015, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
sliderPaintProperty->UpdateValue(VALUE);
sliderPaintProperty->UpdateMin(MIN);
sliderPaintProperty->UpdateMax(MAX);
sliderPaintProperty->UpdateStep(STEP);
sliderPattern->OnWindowSizeChanged(FRAME_WIDTH, FRAME_HEIGHT, WindowSizeChangeReason::RESIZE);
/**
* @tc.steps: step2. Set parameters to pattern builderFunc
*/
int32_t setApiVersion = 13;
int32_t rollbackApiVersion = MockContainer::Current()->GetApiTargetVersion();
MockContainer::Current()->SetApiTargetVersion(setApiVersion);
sliderPattern->OnWindowSizeChanged(FRAME_WIDTH, FRAME_HEIGHT, WindowSizeChangeReason::ROTATION);
MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
EXPECT_TRUE(sliderPattern->skipGestureEvents_);
}
/**
* @tc.name: SliderPatternTest016
* @tc.desc: SliderPattern::HandleTouchUp.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest016, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
sliderPaintProperty->UpdateValue(VALUE);
sliderPaintProperty->UpdateMin(MIN);
sliderPaintProperty->UpdateMax(MAX);
sliderPaintProperty->UpdateStep(STEP);
sliderPattern->lastTouchLocation_ = SLIDER_OFFSET;
sliderPattern->bubbleFlag_ = false;
sliderPattern->isFocusActive_ = true;
sliderPattern->sliderInteractionMode_ = SliderModelNG::SliderInteraction::SLIDE_AND_CLICK_UP;
sliderPattern->HandleTouchUp(SLIDER_OFFSET, SourceType::TOUCH);
EXPECT_TRUE(sliderPattern->allowDragEvents_);
/**
* @tc.steps: step2. Set parameters to pattern builderFunc
*/
sliderPattern->bubbleFlag_ = true;
sliderPattern->isFocusActive_ = false;
sliderPattern->sliderInteractionMode_ = SliderModelNG::SliderInteraction::SLIDE_ONLY;
sliderPattern->HandleTouchUp(SLIDER_OFFSET, SourceType::NONE);
EXPECT_FALSE(sliderPattern->bubbleFlag_);
}
/**
* @tc.name: SliderPatternTest017
* @tc.desc: SliderPattern::HandleTouchUp.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest017, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
GestureEvent SliderInfo;
SliderInfo.inputEventType_ = InputEventType::AXIS;
SliderInfo.localLocation_ = Offset(MIN_LABEL, MAX_LABEL);
SliderInfo.SetOffsetX(.0);
SliderInfo.SetOffsetY(1.0);
SliderInfo.SetSourceTool(SourceTool::MOUSE);
sliderPattern->HandlingGestureEvent(SliderInfo);
sliderPattern->direction_ = Axis::VERTICAL;
sliderPattern->HandlingGestureEvent(SliderInfo);
EXPECT_FALSE(sliderPattern->panMoveFlag_);
/**
* @tc.steps: step2. Set parameters to pattern builderFunc
*/
sliderPattern->bubbleFlag_ = true;
sliderPattern->isFocusActive_ = false;
sliderPattern->sliderInteractionMode_ = SliderModelNG::SliderInteraction::SLIDE_ONLY;
sliderPattern->direction_ = Axis::VERTICAL;
sliderPattern->fingerId_ = 2;
SliderInfo.inputEventType_ = InputEventType::TOUCH_SCREEN;
FingerInfo fingerInfoFst;
fingerInfoFst.fingerId_ = 1;
FingerInfo fingerInfoScd;
fingerInfoScd.fingerId_ = 2;
SliderInfo.fingerList_.push_back(fingerInfoFst);
SliderInfo.fingerList_.push_back(fingerInfoScd);
sliderPattern->HandlingGestureEvent(SliderInfo);
EXPECT_TRUE(sliderPattern->panMoveFlag_);
}
/**
* @tc.name: SliderPatternTest018
* @tc.desc: SliderPattern::StartAnimation.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest018, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
sliderPattern->sliderContentModifier_ =
AceType::MakeRefPtr<SliderContentModifier>(SliderContentModifier::Parameters(), nullptr, nullptr);
sliderPattern->sliderContentModifier_->isVisible_ = true;
sliderPattern->StartAnimation();
EXPECT_TRUE(sliderPattern->sliderContentModifier_->GetVisible());
/**
* @tc.steps: step2. Set parameters to pattern builderFunc
*/
sliderPattern->sliderContentModifier_->isVisible_ = false;
sliderPattern->isVisibleArea_ = true;
sliderPattern->isVisible_ = true;
sliderPattern->isShow_ = true;
sliderPattern->StartAnimation();
EXPECT_TRUE(sliderPattern->sliderContentModifier_->GetVisible());
}
/**
* @tc.name: SliderPatternTest019
* @tc.desc: SliderPattern::UpdateTipState.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest019, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
sliderPattern->sliderContentModifier_ =
AceType::MakeRefPtr<SliderContentModifier>(SliderContentModifier::Parameters(), nullptr, nullptr);
sliderPattern->focusFlag_ = true;
sliderPattern->UpdateTipState();
/**
* @tc.steps: step2. Set parameters to pattern builderFunc
*/
sliderPattern->showTips_ = true;
sliderPattern->isVisibleArea_ = true;
sliderPattern->isVisible_ = true;
sliderPattern->isShow_ = true;
sliderPattern->UpdateTipState();
EXPECT_FALSE(sliderPattern->isFocusActive_);
}
/**
* @tc.name: SliderPatternTest020
* @tc.desc: SliderPattern::OnIsFocusActiveUpdate.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest020, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
sliderPattern->sliderContentModifier_ =
AceType::MakeRefPtr<SliderContentModifier>(SliderContentModifier::Parameters(), nullptr, nullptr);
sliderPattern->focusFlag_ = false;
sliderPattern->OnIsFocusActiveUpdate(true);
EXPECT_FALSE(sliderPattern->isFocusActive_);
/**
* @tc.steps: step2. Set focusFlag_ = true and bubbleFlag_ showBubble.
*/
sliderPattern->focusFlag_ = true;
sliderPattern->showTips_ = false;
sliderPattern->bubbleFlag_ = false;
sliderPattern->OnIsFocusActiveUpdate(true);
EXPECT_TRUE(sliderPattern->isFocusActive_);
}
/**
* @tc.name: SliderPatternTest021
* @tc.desc: SliderPattern::UseContentModifier.
* @tc.type: FUNC
*/
HWTEST_F(SliderPatternTestNg, SliderPatternTest021, TestSize.Level1)
{
/**
* @tc.steps: step1. Init Slider node.
*/
auto sliderPattern = AceType::MakeRefPtr<SliderPattern>();
ASSERT_NE(sliderPattern, nullptr);
auto sliderNode = AceType::MakeRefPtr<FrameNode>(V2::SLIDER_ETS_TAG, -1, sliderPattern);
sliderPattern->AttachToFrameNode(sliderNode);
ASSERT_NE(sliderNode, nullptr);
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
ASSERT_NE(sliderPaintProperty, nullptr);
auto host = sliderPattern->GetHost();
ASSERT_NE(host, nullptr);
auto hub = host->GetEventHub<EventHub>();
ASSERT_NE(hub, nullptr);
auto gestureHub = hub->GetOrCreateGestureEventHub();
ASSERT_NE(gestureHub, nullptr);
/**
* @tc.steps: step2. Set contentModifierNode_ and call UseContentModifier.
*/
auto modifierNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
sliderPattern->contentModifierNode_ = modifierNode;
sliderPattern->InitTouchEvent(gestureHub);
sliderPattern->InitPanEvent(gestureHub);
RefPtr<EventHub> eventHub = AccessibilityManager::MakeRefPtr<EventHub>();
RefPtr<FocusHub> focusHub = AccessibilityManager::MakeRefPtr<FocusHub>(eventHub, FocusType::DISABLE, false);
sliderPattern->InitOnKeyEvent(focusHub);
auto inputEventHub = eventHub->GetInputEventHub();
sliderPattern->InitMouseEvent(inputEventHub);
EXPECT_EQ(sliderPattern->hoverEvent_, nullptr);
EXPECT_EQ(sliderPattern->mouseEvent_, nullptr);
}
} // namespace OHOS::Ace::NG

View File

@ -35,6 +35,7 @@
#include "test/mock/core/common/mock_theme_manager.h"
#include "core/components_v2/inspector/inspector_constants.h"
#include "test/mock/core/pipeline/mock_pipeline_context.h"
#include "core/components_ng/pattern/root/root_pattern.h"
using namespace testing;
using namespace testing::ext;
@ -1731,4 +1732,145 @@ HWTEST_F(ToggleTestNg, SwitchPatternTest001, TestSize.Level1)
pattern->OnAfterModifyDone();
}
/**
* @tc.name: ToggleModelTest007
* @tc.desc: Test ToggleModelNG::ReplaceAllChild
* @tc.type: FUNC
*/
HWTEST_F(ToggleTestNg, ToggleModelTest007, TestSize.Level1)
{
/**
* @tc.steps: step1. create toggle and get frameNode.
*/
ToggleModelNG toggleModelNG;
toggleModelNG.CreateFrameNode(0, ToggleType::CHECKBOX, true);
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(frameNode, nullptr);
/**
* @tc.steps: step2. create oldframenode with RootPattern and call ReplaceAllChild.
*/
auto oldFrameNodeRoot = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
auto childRootNode = FrameNode::CreateFrameNode(V2::BUTTON_ETS_TAG, 1, AceType::MakeRefPtr<ButtonPattern>());
childRootNode->MountToParent(oldFrameNodeRoot);
toggleModelNG.ReplaceAllChild(oldFrameNodeRoot);
auto children = oldFrameNodeRoot->GetChildren();
EXPECT_EQ(children.size(), 1);
}
/**
* @tc.name: ToggleModelTest008
* @tc.desc: Test ToggleModelNG::ReplaceAllChild
* @tc.type: FUNC
*/
HWTEST_F(ToggleTestNg, ToggleModelTest008, TestSize.Level1)
{
/**
* @tc.steps: step1. create toggle and get frameNode.
*/
ToggleModelNG toggleModelNG;
toggleModelNG.CreateFrameNode(1, ToggleType::CHECKBOX, true);
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(frameNode, nullptr);
/**
* @tc.steps: step2 - 1. create oldframenode with switchPattern and call ReplaceAllChild.
*/
auto oldFrameNodeSwitch = FrameNode::CreateFrameNode(V2::SWITCH_ETS_TAG, 1, AceType::MakeRefPtr<SwitchPattern>());
auto childNode = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, 1, AceType::MakeRefPtr<ButtonPattern>());
childNode->MountToParent(oldFrameNodeSwitch);
auto switchPattern = oldFrameNodeSwitch->GetPattern<SwitchPattern>();
ASSERT_NE(switchPattern, nullptr);
auto modifierNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
switchPattern->contentModifierNode_ = modifierNode;
switchPattern->nodeId_ = childNode->GetId();
toggleModelNG.ReplaceAllChild(oldFrameNodeSwitch);
auto children = oldFrameNodeSwitch->GetChildren();
EXPECT_EQ(children.size(), 1);
}
/**
* @tc.name: ToggleModelTest009
* @tc.desc: Test ToggleModelNG::ReplaceAllChild
* @tc.type: FUNC
*/
HWTEST_F(ToggleTestNg, ToggleModelTest009, TestSize.Level1)
{
/**
* @tc.steps: step1. create toggle and get frameNode.
*/
ToggleModelNG toggleModelNG;
toggleModelNG.CreateFrameNode(0, ToggleType::SWITCH, true);
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(frameNode, nullptr);
/**
* @tc.steps: step2 - 2. create oldframenode with checkboxPattern and call ReplaceAllChild.
*/
auto oldFrameNodeCheckbox =
FrameNode::CreateFrameNode(V2::CHECKBOX_ETS_TAG, 1, AceType::MakeRefPtr<CheckBoxPattern>());
auto childCheckboxNode = FrameNode::CreateFrameNode(V2::BUTTON_ETS_TAG, 1, AceType::MakeRefPtr<ButtonPattern>());
childCheckboxNode->MountToParent(oldFrameNodeCheckbox);
auto checkboxPattern = oldFrameNodeCheckbox->GetPattern<CheckBoxPattern>();
ASSERT_NE(checkboxPattern, nullptr);
auto modifierNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
checkboxPattern->contentModifierNode_ = modifierNode;
toggleModelNG.ReplaceAllChild(oldFrameNodeCheckbox);
auto children = oldFrameNodeCheckbox->GetChildren();
EXPECT_EQ(children.size(), 1);
}
/**
* @tc.name: ToggleModelTest010
* @tc.desc: Test ToggleModelNG::ReplaceAllChild
* @tc.type: FUNC
*/
HWTEST_F(ToggleTestNg, ToggleModelTest010, TestSize.Level1)
{
/**
* @tc.steps: step1. create toggle and get frameNode.
*/
ToggleModelNG toggleModelNG;
toggleModelNG.CreateFrameNode(0, ToggleType::SWITCH, true);
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(frameNode, nullptr);
/**
* @tc.steps: step2 - 3. create oldframenode with toggleButtonPattern and call ReplaceAllChild.
*/
auto oldFrameNodeToggle =
FrameNode::CreateFrameNode(V2::TOGGLE_ETS_TAG, 1, AceType::MakeRefPtr<ToggleButtonPattern>());
auto childToggleNode = FrameNode::CreateFrameNode(V2::BUTTON_ETS_TAG, 1, AceType::MakeRefPtr<ButtonPattern>());
childToggleNode->MountToParent(oldFrameNodeToggle);
auto togglePattern = oldFrameNodeToggle->GetPattern<ToggleButtonPattern>();
ASSERT_NE(togglePattern, nullptr);
auto modifierNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
togglePattern->contentModifierNode_ = modifierNode;
togglePattern->nodeId_ = childToggleNode->GetId();
toggleModelNG.ReplaceAllChild(oldFrameNodeToggle);
auto children = oldFrameNodeToggle->GetChildren();
EXPECT_EQ(children.size(), 1);
}
/**
* @tc.name: ToggleModelTest011
* @tc.desc: Test ToggleModelNG::SetUnselectedColor
* @tc.type: FUNC
*/
HWTEST_F(ToggleTestNg, ToggleModelTest011, TestSize.Level1)
{
/**
* @tc.steps: step1. create toggle and get frameNode.
*/
ToggleModelNG toggleModelNG;
toggleModelNG.Create(TOGGLE_TYPE[2], IS_ON);
auto switchFrameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(switchFrameNode, nullptr);
/**
* @tc.steps: step2. set Modifer.
*/
ToggleModelNG toggleModelNGEx;
toggleModelNGEx.SetUnselectedColor(AceType::RawPtr(switchFrameNode), SELECTED_COLOR);
toggleModelNGEx.SetTrackBorderRadius(AceType::RawPtr(switchFrameNode), TOGGLE_WIDTH);
toggleModelNGEx.ResetTrackBorderRadius(AceType::RawPtr(switchFrameNode));
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
ASSERT_NE(frameNode, nullptr);
}
} // namespace OHOS::Ace::NG