diff --git a/test/unittest/core/pattern/scroll/scroll_accessibility_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_accessibility_test_ng.cpp index 662bacdb88148ca2f63127423a7e09d16ef409b3..b4219a2b22c0cc1460b881f838d0894980d6db08 100644 --- a/test/unittest/core/pattern/scroll/scroll_accessibility_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_accessibility_test_ng.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include "scroll_test_ng.h" #include "test/mock/core/animation/mock_animation_manager.h" @@ -187,4 +188,216 @@ HWTEST_F(ScrollAccessibilityTestNg, PerformActionTest003, TestSize.Level1) accessibilityProperty_->ActActionScrollBackward(AccessibilityScrollType::SCROLL_HALF); EXPECT_TRUE(TickPosition(0)); } + +/** + * @tc.name: IsScrollable001 + * @tc.desc: Test ScrollAccessibilityProperty IsScrollable + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, IsScrollable001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is not equal to NONE makes the IsScrollable function return true + * and set scrollableDistance_ of scrollPattern greater than 0 + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::HORIZONTAL); + scrollPattern->scrollableDistance_ = 2.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + + /** + * @tc.steps: step3. Calling the IsScrollable function + * @tc.expected: The result of calling the function returns true + */ + auto result = scrollAccessibilityProperty->IsScrollable(); + EXPECT_TRUE(result); +} + +/** + * @tc.name: IsScrollable002 + * @tc.desc: Test ScrollAccessibilityProperty IsScrollable + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, IsScrollable002, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is not equal to NONE makes the IsScrollable function return true + * and set scrollableDistance_ of scrollPattern to 0 or less + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::HORIZONTAL); + scrollPattern->scrollableDistance_ = -2.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + + /** + * @tc.steps: step3. Calling the IsScrollable function + * @tc.expected: The result of calling the function returns false + */ + auto result = scrollAccessibilityProperty->IsScrollable(); + EXPECT_FALSE(result); +} + +/** + * @tc.name: IsScrollable003 + * @tc.desc: Test ScrollAccessibilityProperty IsScrollable + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, IsScrollable003, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is equal to NONE makes the IsScrollable function return false + * and set scrollableDistance_ of scrollPattern greater than 0 + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::NONE); + scrollPattern->scrollableDistance_ = 2.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + + /** + * @tc.steps: step3. Calling the IsScrollable function + * @tc.expected: The result of calling the function returns false + */ + auto result = scrollAccessibilityProperty->IsScrollable(); + EXPECT_FALSE(result); +} + +/** + * @tc.name: SetSpecificSupportAction001 + * @tc.desc: Test ScrollAccessibilityProperty SetSpecificSupportAction + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, SetSpecificSupportAction001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is not equal to NONE + * set scrollableDistance_ of scrollPattern greater than 0 makes the IsScrollable function return true + * set currentOffset_ of scrollPattern less than 0 makes the IsAtTop function return false + * and set currentOffset_ less than or equal to -scrollableDistance_ makes the IsAtBottom function return true + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::FREE); + scrollPattern->scrollableDistance_ = 2.0f; + scrollPattern->currentOffset_ = -4.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + scrollAccessibilityProperty->supportActions_ = static_cast(AceAction::ACTION_FOCUS); + + /** + * @tc.steps: step3. Calling the SetSpecificSupportAction function + * @tc.expected: The supportActions_ to be expectActions + */ + auto expectActions = static_cast(AceAction::ACTION_FOCUS) | + (1UL << static_cast(AceAction::ACTION_SCROLL_BACKWARD)); + + scrollAccessibilityProperty->SetSpecificSupportAction(); + EXPECT_EQ(scrollAccessibilityProperty->supportActions_, expectActions); +} + +/** + * @tc.name: SetSpecificSupportAction002 + * @tc.desc: Test ScrollAccessibilityProperty SetSpecificSupportAction + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, SetSpecificSupportAction002, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is not equal to NONE + * set scrollableDistance_ of scrollPattern greater than 0 makes the IsScrollable function return true + * set currentOffset_ of scrollPattern less than 0 makes the IsAtTop function return true + * and set currentOffset_ less than or equal to -scrollableDistance_ makes the IsAtBottom function return false + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::FREE); + scrollPattern->scrollableDistance_ = 2.0f; + scrollPattern->currentOffset_ = 1.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + scrollAccessibilityProperty->supportActions_ = static_cast(AceAction::ACTION_CLICK); + + /** + * @tc.steps: step3. Calling the SetSpecificSupportAction function + * @tc.expected: The supportActions_ to be expectActions + */ + auto expectActions = static_cast(AceAction::ACTION_CLICK) | + (1UL << static_cast(AceAction::ACTION_SCROLL_FORWARD)); + scrollAccessibilityProperty->SetSpecificSupportAction(); + EXPECT_EQ(scrollAccessibilityProperty->supportActions_, expectActions); +} + +/** + * @tc.name: SetSpecificSupportAction003 + * @tc.desc: Test ScrollAccessibilityProperty SetSpecificSupportAction + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, SetSpecificSupportAction003, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + RefPtr scrollAccessibilityProperty = + AceType::MakeRefPtr(); + + /** + * @tc.steps: step2. Set axis is equal to NONE makes the IsScrollable function return false + */ + RefPtr scrollPattern = AceType::MakeRefPtr(); + scrollPattern->SetAxis(Axis::NONE); + scrollPattern->scrollableDistance_ = 2.0f; + scrollPattern->currentOffset_ = 1.0f; + auto scrollNode = FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, 1, scrollPattern); + ASSERT_NE(scrollNode, nullptr); + WeakPtr host = std::move(scrollNode); + scrollAccessibilityProperty->host_ = host; + scrollAccessibilityProperty->supportActions_ |= static_cast(AceAction::ACTION_NONE); + + /** + * @tc.steps: step3. Calling the SetSpecificSupportAction function + * @tc.expected: The supportActions_ is unchanged + */ + scrollAccessibilityProperty->SetSpecificSupportAction(); + EXPECT_EQ(scrollAccessibilityProperty->supportActions_, static_cast(AceAction::ACTION_NONE)); +} } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp index 58b9a9a972348b3c4d8a5796959befca37daafe6..a8434a4fb5be8a39ada254254a673a5c8079c4f8 100644 --- a/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp @@ -817,4 +817,154 @@ HWTEST_F(ScrollLayoutTestNg, UseInitialOffset003, TestSize.Level1) scrollLayoutAlgorithm->UseInitialOffset(axis, selfSize, rawPtr); EXPECT_EQ(scrollLayoutAlgorithm->GetCurrentOffset(), 1.0f); } + +/** + * @tc.name: UpdateScrollAlignment001 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to TOP_LEFT + */ + Alignment scrollAlignment = Alignment::TOP_LEFT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be TOP_RIGHT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::TOP_RIGHT); +} + +/** + * @tc.name: UpdateScrollAlignment002 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment002, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to TOP_RIGHT + */ + Alignment scrollAlignment = Alignment::TOP_RIGHT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be TOP_LEFT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::TOP_LEFT); +} + +/** + * @tc.name: UpdateScrollAlignment003 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment003, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to BOTTOM_LEFT + */ + Alignment scrollAlignment = Alignment::BOTTOM_LEFT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be BOTTOM_RIGHT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::BOTTOM_RIGHT); +} + +/** + * @tc.name: UpdateScrollAlignment004 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment004, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to BOTTOM_RIGHT + */ + Alignment scrollAlignment = Alignment::BOTTOM_RIGHT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be BOTTOM_LEFT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::BOTTOM_LEFT); +} + +/** + * @tc.name: UpdateScrollAlignment005 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment005, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to CENTER_RIGHT + */ + Alignment scrollAlignment = Alignment::CENTER_RIGHT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be CENTER_LEFT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::CENTER_LEFT); +} + +/** + * @tc.name: UpdateScrollAlignment006 + * @tc.desc: Test ScrollLayoutAlgorithm UpdateScrollAlignment + * @tc.type: FUNC + */ +HWTEST_F(ScrollModelNGTestNg, UpdateScrollAlignment006, TestSize.Level1) +{ + /** + * @tc.steps: step1. Construct the objects for test preparation + */ + ScrollLayoutAlgorithm scrollLayoutAlgorithm(2.0f); + + /** + * @tc.steps: step2. Set scrollAlignment to CENTER_LEFT + */ + Alignment scrollAlignment = Alignment::CENTER_LEFT; + + /** + * @tc.steps: step3. Calling the UpdateScrollAlignment function + * @tc.expected: The scrollAlignment to be CENTER_RIGHT + */ + scrollLayoutAlgorithm.UpdateScrollAlignment(scrollAlignment); + EXPECT_EQ(scrollAlignment, Alignment::CENTER_RIGHT); +} } // namespace OHOS::Ace::NG