From 2d561ab52980b935b3bc801430cc4ca9b2b0994c Mon Sep 17 00:00:00 2001 From: kangchongtao Date: Fri, 31 Mar 2023 17:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Etdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kangchongtao Change-Id: I32eb44a62130c0f8b6d7c55f89da4c0e516444a5 Signed-off-by: kangchongtao --- .../test/pattern/swiper/BUILD.gn | 1 + .../pattern/swiper/swiper_pattern_test_ng.cpp | 91 +++++++++++++++++++ test/fuzztest/imageloader_fuzzer/BUILD.gn | 3 - 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 frameworks/core/components_ng/test/pattern/swiper/swiper_pattern_test_ng.cpp diff --git a/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn b/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn index 7e2521550e5..b980ae07c98 100644 --- a/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn @@ -138,6 +138,7 @@ ohos_unittest("swiper_pattern_test_ng") { "$ace_root/frameworks/core/components_ng/property/accessibility_property.cpp", "swiper_accessibility_property_test_ng.cpp", "swiper_indicator_pattern_test_ng.cpp", + "swiper_pattern_test_ng.cpp", ] deps = [ diff --git a/frameworks/core/components_ng/test/pattern/swiper/swiper_pattern_test_ng.cpp b/frameworks/core/components_ng/test/pattern/swiper/swiper_pattern_test_ng.cpp new file mode 100644 index 00000000000..b523f23c36d --- /dev/null +++ b/frameworks/core/components_ng/test/pattern/swiper/swiper_pattern_test_ng.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 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 "gtest/gtest.h" + +#define private public +#define protected public +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/swiper/swiper_pattern.h" +#include "core/animation/animator.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Ace::NG { +namespace { +} // namespace + +class SwiperPatternTestNg : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; +}; + +/** + * @tc.name: SwiperEvent001 + * @tc.desc: HandleTouchDown + * @tc.type: FUNC + */ +HWTEST_F(SwiperPatternTestNg, SwiperEvent001, TestSize.Level1) +{ + auto* stack = ViewStackProcessor::GetInstance(); + auto swiperNode = FrameNode::GetOrCreateFrameNode( + "Swiper", 0, []() { return AceType::MakeRefPtr(); }); + stack->Push(swiperNode); + TouchLocationInfo touchLocationInfo("down", 0); + touchLocationInfo.SetTouchType(TouchType::DOWN); + std::list infoList; + infoList.emplace_back(touchLocationInfo); + TouchEventInfo touchEventInfo("down"); + touchEventInfo.touches_ = infoList; + auto pattern = swiperNode->GetPattern(); + pattern->HandleTouchEvent(touchEventInfo); + EXPECT_FALSE(pattern->indicatorDoingAnimation_); + const char* name = "HandleTouchDown"; + pattern->controller_ = AceType::MakeRefPtr(name); + pattern->controller_->status_ = Animator::Status::RUNNING; + pattern->springController_ = AceType::MakeRefPtr(name); + pattern->springController_->status_ = Animator::Status::RUNNING; + pattern->HandleTouchEvent(touchEventInfo); + EXPECT_FALSE(pattern->indicatorDoingAnimation_); + + touchLocationInfo.SetTouchType(TouchType::UP); + pattern->HandleTouchEvent(touchEventInfo); + pattern->controller_ = nullptr; + pattern->springController_ = nullptr; + touchLocationInfo.SetTouchType(TouchType::CANCEL); + pattern->HandleTouchEvent(touchEventInfo); + EXPECT_FALSE(pattern->indicatorDoingAnimation_); +} + +/** + * @tc.name: SwiperEvent002 + * @tc.desc: HandleTouchDown + * @tc.type: FUNC + */ +HWTEST_F(SwiperPatternTestNg, SwiperEvent002, TestSize.Level1) +{ + auto* stack = ViewStackProcessor::GetInstance(); + auto swiperNode = FrameNode::GetOrCreateFrameNode( + "Swiper", 0, []() { return AceType::MakeRefPtr(); }); + stack->Push(swiperNode); + auto pattern = swiperNode->GetPattern(); + auto eventHub = AceType::MakeRefPtr(); + auto gestureEventHub = AceType::MakeRefPtr(AceType::WeakClaim(AceType::RawPtr(eventHub))); + pattern->InitPanEvent(gestureEventHub); + EXPECT_EQ(pattern->direction_, Axis::HORIZONTAL); +} +} // namespace OHOS::Ace::NG diff --git a/test/fuzztest/imageloader_fuzzer/BUILD.gn b/test/fuzztest/imageloader_fuzzer/BUILD.gn index 7d3440a6a26..d14be24e844 100644 --- a/test/fuzztest/imageloader_fuzzer/BUILD.gn +++ b/test/fuzztest/imageloader_fuzzer/BUILD.gn @@ -80,9 +80,6 @@ ohos_fuzztest("ImageLoaderFuzzTest") { "$ace_root/frameworks/core/common/test/mock/mock_watch_dog.cpp", "$ace_root/frameworks/core/event/back_end_event_manager.cpp", - #"theme_constants_test.cpp", - "$ace_root/frameworks/core/components/test/unittest/theme/theme_mock.cpp", - # mock #"$ace_root/frameworks/base/test/mock/mock_system_properties.cpp",