diff --git a/BUILD.gn b/BUILD.gn index ee7c88d726042bd259b53cf108498450cd950218..a9a2123f65e03cd41d8f6913f1edc64b2cc61f3b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -219,6 +219,7 @@ group("mmi_tests") { "service/crown_transform_processor/test:CrownTransformProcessorTest", "service/fingerprint_event_processor/test:FingerprintEventProcessorTest", "service/fingerprint_event_processor/test:XKeyEventProcessorTest", + "service/fingersense_wrapper/test:FingersenseWrapperTest", "service/module_loader/test:ModuleLoaderTests", "service/mouse_event_normalize/test:MouseEventNormalizeEXTest", "service/mouse_event_normalize/test:MouseEventNormalizeTest", diff --git a/service/crown_transform_processor/test/BUILD.gn b/service/crown_transform_processor/test/BUILD.gn index c685b9d735323125adc8da104321ca2b6a95dcc2..ec096606ce6b7fe48874729de306a8a5361ebc9b 100644 --- a/service/crown_transform_processor/test/BUILD.gn +++ b/service/crown_transform_processor/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-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 @@ -31,10 +31,16 @@ ohos_unittest("CrownTransformProcessorTest") { "-Dprotected=public", ] + include_dirs = [ + "${mmi_path}/test/facility/libinput_interface/include", + "${mmi_path}/test/facility/mock/include", + ] + sources = [ "src/crown_transform_processor_test.cpp" ] deps = [ "${mmi_path}/service:libmmi-server", + "${mmi_path}/test/facility/libinput_interface:libinput_interface_sources", "${mmi_path}/test/facility/libinput_wrapper:libinput_wrapper_sources", "${mmi_path}/test/facility/virtual_device:virtual_device_sources", "${mmi_path}/util:libmmi-util", @@ -43,6 +49,7 @@ ohos_unittest("CrownTransformProcessorTest") { external_deps = [ "c_utils:utils", "data_share:datashare_consumer", + "googletest:gmock_main", "graphic_2d:2d_graphics", "graphic_2d:librender_service_client", "hilog:libhilog", diff --git a/service/crown_transform_processor/test/src/crown_transform_processor_test.cpp b/service/crown_transform_processor/test/src/crown_transform_processor_test.cpp index 5df22b71854adf5f4774d662e64d42c9276052a7..0074ac7e57600804c1eba06e316b24d66c3759a3 100644 --- a/service/crown_transform_processor/test/src/crown_transform_processor_test.cpp +++ b/service/crown_transform_processor/test/src/crown_transform_processor_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -21,267 +21,311 @@ #include "i_input_windows_manager.h" #include "input_device_manager.h" #include "input_event_handler.h" -#include "libinput.h" +#include "libinput_mock.h" #include "libinput_wrapper.h" +#include "libinput.h" #include "mmi_log.h" +#include "timer_manager.h" #include "window_info.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "CrownTransformProcessorTest" +using namespace testing::ext; +using namespace testing; + namespace OHOS { namespace MMI { -namespace { -using namespace testing::ext; +bool TimerManager::IsExist(int32_t timerId) +{ + return true; } + class CrownTransformProcessorTest : public testing::Test { public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - static void SetupCrown(); - static void CloseCrown(); - static void InitHandler(); - libinput_event *GetEvent(); - -private: - static GeneralCrown vCrown_; - static LibinputWrapper libinput_; + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); }; -GeneralCrown CrownTransformProcessorTest::vCrown_; -LibinputWrapper CrownTransformProcessorTest::libinput_; +void CrownTransformProcessorTest::SetUpTestCase() {} + +void CrownTransformProcessorTest::TearDownTestCase() {} -void CrownTransformProcessorTest::SetUpTestCase(void) +void CrownTransformProcessorTest::SetUp() {} + +void CrownTransformProcessorTest::TearDown() {} + +/* * + * @tc.name: CrownTransformProcessorTest_GetPointerEvent_001 + * @tc.desc: Test the funcation GetPointerEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_GetPointerEvent_001, TestSize.Level1) { - ASSERT_TRUE(libinput_.Init()); - SetupCrown(); - InitHandler(); + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + auto ret = processor->GetPointerEvent(); + ASSERT_NE(ret, nullptr); } -void CrownTransformProcessorTest::TearDownTestCase(void) +/* * + * @tc.name: CrownTransformProcessorTest_IsCrownEvent_001 + * @tc.desc: Test the funcation IsCrownEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_001, TestSize.Level1) { - CloseCrown(); + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + libinput_event *event = nullptr; + bool ret = processor->IsCrownEvent(event); + EXPECT_FALSE(ret); } -void CrownTransformProcessorTest::SetupCrown() +/* * + * @tc.name: CrownTransformProcessorTest_IsCrownEvent_002 + * @tc.desc: Test the funcation IsCrownEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_002, TestSize.Level1) { - ASSERT_TRUE(vCrown_.SetUp()); - MMI_HILOGD("Device node name:%{public}s", vCrown_.GetDevPath().c_str()); - ASSERT_TRUE(libinput_.AddPath(vCrown_.GetDevPath())); - - libinput_event *event = libinput_.Dispatch(); - ASSERT_TRUE(event != nullptr); - ASSERT_EQ(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED); - struct libinput_device *device = libinput_event_get_device(event); - ASSERT_TRUE(device != nullptr); - INPUT_DEV_MGR->OnInputDeviceAdded(device); + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_device *device = nullptr; + libinput_event_pointer touchpadButtonEvent; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(device)); + libinput_event event; + bool ret = processor->IsCrownEvent(&event); + EXPECT_FALSE(ret); } -void CrownTransformProcessorTest::CloseCrown() +/* * + * @tc.name: CrownTransformProcessorTest_IsCrownEvent_003 + * @tc.desc: Test the funcation IsCrownEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_003, TestSize.Level1) { - libinput_.RemovePath(vCrown_.GetDevPath()); - vCrown_.Close(); + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_device device; + libinput_event_pointer touchpadButtonEvent; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device)); + EXPECT_CALL(libinputMock, DeviceGetName).WillOnce(Return(const_cast("rotary_crown"))); + EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_POINTER_AXIS)); + libinput_event event; + bool ret = processor->IsCrownEvent(&event); + EXPECT_FALSE(ret); } -void CrownTransformProcessorTest::InitHandler() +/* * + * @tc.name: CrownTransformProcessorTest_IsCrownEvent_004 + * @tc.desc: Test the funcation IsCrownEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_004, TestSize.Level1) { - UDSServer udsServer; - std::shared_ptr inputHandler = InputHandler; - ASSERT_NO_FATAL_FAILURE(inputHandler->Init(udsServer)); + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_device device; + libinput_event_pointer touchpadButtonEvent; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device)); + EXPECT_CALL(libinputMock, DeviceGetName).WillOnce(Return(const_cast("Virtual Crown"))); + EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_NONE)); + libinput_event event; + bool ret = processor->IsCrownEvent(&event); + EXPECT_FALSE(ret); } -libinput_event *CrownTransformProcessorTest::GetEvent() +/* * + * @tc.name: CrownTransformProcessorTest_IsCrownEvent_005 + * @tc.desc: Test the funcation IsCrownEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_005, TestSize.Level1) { - libinput_event *event = nullptr; - libinput_event *evt = libinput_.Dispatch(); - while (evt != nullptr) { - auto type = libinput_event_get_type(evt); - if (type == LIBINPUT_EVENT_POINTER_AXIS) { - event = evt; - } - evt = libinput_.Dispatch(); - } - return event; + CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_device device; + libinput_event_pointer touchpadButtonEvent; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device)); + EXPECT_CALL(libinputMock, DeviceGetName).WillOnce(Return(const_cast("Other"))); + libinput_event event; + bool ret = processor->IsCrownEvent(&event); + EXPECT_FALSE(ret); } -/** - * @tc.name: CrownTransformProcessorTest_GetPointerEvent_001 - * @tc.desc: Test GetPointerEvent - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_001 + * @tc.desc: Test the funcation NormalizeRotateEvent + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_GetPointerEvent_001, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_001, TestSize.Level1) { CALL_TEST_DEBUG; - auto ret = CROWN_EVENT_HDR->GetPointerEvent(); - ASSERT_NE(ret, nullptr); + std::shared_ptr processor = std::make_shared(); + libinput_event *event = nullptr; + int32_t ret = processor->NormalizeRotateEvent(event); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } -/** - * @tc.name: CrownTransformProcessorTest_IsCrownEvent_002 - * @tc.desc: Test IsCrownEvent - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_002 + * @tc.desc: Test the funcation NormalizeRotateEvent + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_002, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_002, TestSize.Level1) { CALL_TEST_DEBUG; - vCrown_.SendEvent(EV_REL, REL_WHEEL, 5); - vCrown_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::string name = libinput_device_get_name(dev); - MMI_HILOGD("Pointer device:%{public}s", name.c_str()); - ASSERT_TRUE(CROWN_EVENT_HDR->IsCrownEvent(event)); + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_device *device = nullptr; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(device)); + libinput_event event; + int32_t ret = processor->NormalizeRotateEvent(&event); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } - -/** +/* * * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_003 - * @tc.desc: Test NormalizeRotateEvent - * @tc.type: FUNC + * @tc.desc: Test the funcation NormalizeRotateEvent + * @tc.type: Function * @tc.require: */ HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_003, TestSize.Level1) { CALL_TEST_DEBUG; - vCrown_.SendEvent(EV_REL, REL_WHEEL, 5); - vCrown_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::string name = libinput_device_get_name(dev); - MMI_HILOGD("Pointer device:%{public}s", name.c_str()); - int32_t result = CROWN_EVENT_HDR->NormalizeRotateEvent(event); - EXPECT_NE(result, RET_OK); + std::shared_ptr processor = std::make_shared(); + NiceMock libinputMock; + libinput_event_pointer touchpadButtonEvent; + libinput_device device; + EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device)); + libinput_event event; + int32_t ret = processor->NormalizeRotateEvent(&event); + EXPECT_EQ(ret, RET_ERR); } -/** - * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBegin_004 - * @tc.desc: Test HandleCrownRotateBegin - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBegin_001 + * @tc.desc: Test the funcation HandleCrownRotateBegin + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBegin_004, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBegin_001, TestSize.Level1) { CALL_TEST_DEBUG; - vCrown_.SendEvent(EV_REL, REL_WHEEL, 30); - vCrown_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::string name = libinput_device_get_name(dev); - MMI_HILOGD("Pointer device:%{public}s", name.c_str()); - struct libinput_event_pointer *rawPointerEvent = libinput_event_get_pointer_event(event); - ASSERT_TRUE(rawPointerEvent != nullptr); - int32_t result = CROWN_EVENT_HDR->HandleCrownRotateBegin(rawPointerEvent); - EXPECT_EQ(result, RET_OK); + std::shared_ptr processor = std::make_shared(); + libinput_event_pointer *rawPointerEvent = nullptr; + int32_t ret = processor->HandleCrownRotateBegin(rawPointerEvent); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } -/** - * @tc.name: CrownTransformProcessorTest_HandleCrownRotateUpdate_005 - * @tc.desc: Test HandleCrownRotateUpdate - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotateUpdate_001 + * @tc.desc: Test the funcation HandleCrownRotateUpdate + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateUpdate_005, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateUpdate_001, TestSize.Level1) { CALL_TEST_DEBUG; - vCrown_.SendEvent(EV_REL, REL_WHEEL, -30); - vCrown_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::string name = libinput_device_get_name(dev); - MMI_HILOGD("Pointer device:%{public}s", name.c_str()); - struct libinput_event_pointer *rawPointerEvent = libinput_event_get_pointer_event(event); - ASSERT_TRUE(rawPointerEvent != nullptr); - int32_t result = CROWN_EVENT_HDR->HandleCrownRotateUpdate(rawPointerEvent); - EXPECT_EQ(result, RET_OK); + std::shared_ptr processor = std::make_shared(); + libinput_event_pointer *rawPointerEvent = nullptr; + int32_t ret = processor->HandleCrownRotateUpdate(rawPointerEvent); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } -/** - * @tc.name: CrownTransformProcessorTest_HandleCrownRotateEnd_006 - * @tc.desc: Test HandleCrownRotateEnd - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotateEnd_001 + * @tc.desc: Test the funcation HandleCrownRotateEnd + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateEnd_006, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateEnd_001, TestSize.Level1) { CALL_TEST_DEBUG; - ASSERT_NO_FATAL_FAILURE(CROWN_EVENT_HDR->HandleCrownRotateEnd()); + std::shared_ptr processor = std::make_shared(); + int32_t ret = processor->HandleCrownRotateEnd(); + EXPECT_EQ(ret, RET_OK); } -/** - * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_007 - * @tc.desc: Test HandleCrownRotateBeginAndUpdate - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_001 + * @tc.desc: Test the funcation HandleCrownRotateBeginAndUpdate + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_007, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_001, TestSize.Level1) { CALL_TEST_DEBUG; - vCrown_.SendEvent(EV_REL, REL_WHEEL, 10); - vCrown_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::string name = libinput_device_get_name(dev); - MMI_HILOGD("Pointer device:%{public}s", name.c_str()); - struct libinput_event_pointer *rawPointerEvent = libinput_event_get_pointer_event(event); - ASSERT_TRUE(rawPointerEvent != nullptr); - int32_t result = CROWN_EVENT_HDR->HandleCrownRotateBeginAndUpdate(rawPointerEvent, - PointerEvent::POINTER_ACTION_AXIS_BEGIN); - EXPECT_EQ(result, RET_OK); + std::shared_ptr processor = std::make_shared(); + libinput_event_pointer *rawPointerEvent = nullptr; + int32_t action = 0; + int32_t ret = processor->HandleCrownRotateBeginAndUpdate(rawPointerEvent, action); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } -/** - * @tc.name: CrownTransformProcessorTest_HandleCrownRotatePostInner_008 - * @tc.desc: Test HandleCrownRotatePostInner - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_002 + * @tc.desc: Test the funcation HandleCrownRotateBeginAndUpdate + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotatePostInner_008, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_002, TestSize.Level1) { CALL_TEST_DEBUG; - double angularVelocity = 67.0; - double degree = 11.0; - int32_t action = PointerEvent::POINTER_ACTION_AXIS_UPDATE; - ASSERT_NO_FATAL_FAILURE(CROWN_EVENT_HDR->HandleCrownRotatePostInner(angularVelocity, degree, action)); + std::shared_ptr processor = std::make_shared(); + libinput_event_pointer *rawPointerEvent = nullptr; + int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN; + int32_t ret = processor->HandleCrownRotateBeginAndUpdate(rawPointerEvent, action); + EXPECT_EQ(ret, ERROR_NULL_POINTER); } -/** - * @tc.name: CrownTransformProcessorTest_DumpInner_009 - * @tc.desc: Test DumpInner - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_HandleCrownRotatePostInner_001 + * @tc.desc: Test the funcation HandleCrownRotatePostInner + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_DumpInner_009, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotatePostInner_001, TestSize.Level1) { CALL_TEST_DEBUG; - ASSERT_NO_FATAL_FAILURE(CROWN_EVENT_HDR->DumpInner()); + std::shared_ptr processor = std::make_shared(); + processor->pointerEvent_ = nullptr; + double velocity = 0; + double degree = 0; + int32_t action = 0; + EXPECT_NO_FATAL_FAILURE(processor->HandleCrownRotatePostInner(velocity, degree, action)); } -/** - * @tc.name: CrownTransformProcessorTest_Dump_010 - * @tc.desc: Test Dump - * @tc.type: FUNC +/* * + * @tc.name: CrownTransformProcessorTest_Dump_001 + * @tc.desc: Test the funcation Dump + * @tc.type: Function * @tc.require: */ -HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_Dump_010, TestSize.Level1) +HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_Dump_001, TestSize.Level1) { CALL_TEST_DEBUG; + std::shared_ptr processor = std::make_shared(); + processor->pointerEvent_ = nullptr; + int32_t fd = -1; std::vector args; - std::vector idNames; - int32_t fd = 0; - CROWN_EVENT_HDR->Dump(fd, args); - ASSERT_EQ(args, idNames); -} + EXPECT_NO_FATAL_FAILURE(processor->Dump(fd, args)); } -} \ No newline at end of file +} // namespace MMI +} // namespace OHOS diff --git a/service/fingersense_wrapper/test/BUILD.gn b/service/fingersense_wrapper/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3addeb0456d6e3f22cade768a5fff1b74206f280 --- /dev/null +++ b/service/fingersense_wrapper/test/BUILD.gn @@ -0,0 +1,110 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../multimodalinput_mini.gni") + +module_output_path = "input/input" + +ohos_unittest("FingersenseWrapperTest") { + module_out_path = module_output_path + + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = true + } + + defines = input_default_defines + defines += [ "OHOS_BUILD_ENABLE_FINGERSENSE" ] + + configs = [ + "${mmi_path}:coverage_flags", + "${mmi_path}/service:libmmi_server_config", + "${mmi_path}/service/filter:mmi_event_filter_config", + "${mmi_path}/common/anco/comm:mmi_anco_channel_config", + ] + + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] + + include_dirs = [ + "${mmi_path}/service/fingerprint_event_processor/include", + "${mmi_path}/service/event_handler/include", + "${mmi_path}/util/common/include", + "${mmi_path}/test/facility/event_monitor_handler_interface/include", + "${mmi_path}/test/facility/mock/include", + "${mmi_path}/util/network/include", + "${mmi_path}/service/monitor/include/event_monitor_handler.h", + "${mmi_path}/service/monitor/include/event_pre_monitor_handler.h", + "${mmi_path}/util/common/include/input_event_data_transformation.h", + "${mmi_path}/test/unittest/standalone/include/", + "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/interfaces/native/innerkits/event/include", + "${mmi_path}/service/nap_process/include", + "${mmi_path}/util/socket/include", + "$root_out_dir/diff_libinput_mmi/export_include", + ] + + sources = [ + "${mmi_path}/frameworks/proxy/events/src/input_event.cpp", + "${mmi_path}/frameworks/proxy/events/src/pointer_event.cpp", + "${mmi_path}/service/event_handler/src/input_event_handler.cpp", + "${mmi_path}/service/fingerprint_event_processor/src/fingerprint_event_processor.cpp", + "${mmi_path}/service/monitor/src/event_monitor_handler.cpp", + "${mmi_path}/service/monitor/src/event_pre_monitor_handler.cpp", + "${mmi_path}/service/subscriber/src/input_active_subscriber_handler.cpp", + "${mmi_path}/util/common/src/input_event_data_transformation.cpp", + "${mmi_path}/util/network/src/stream_buffer.cpp", + "src/fingersense_wrapper_test.cpp", + ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/service:libmmi-server", + "${mmi_path}/test/facility/mock:mmi_mock_sources", + "${mmi_path}/util:libmmi-util", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "config_policy:configpolicy_util", + "data_share:datashare_consumer", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "image_framework:image_native", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "preferences:native_preferences", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (security_component_enable) { + external_deps += [ "security_component_manager:libsecurity_component_sdk" ] + } + + if (resource_schedule_service_enabled) { + external_deps += [ "resource_schedule_service:ressched_client" ] + } +} diff --git a/service/fingersense_wrapper/test/src/fingersense_wrapper_test.cpp b/service/fingersense_wrapper/test/src/fingersense_wrapper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec109638fa27ac46800ae32cb10abfbf77fc1a0d --- /dev/null +++ b/service/fingersense_wrapper/test/src/fingersense_wrapper_test.cpp @@ -0,0 +1,284 @@ +/* + * 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 + +#include +#include "define_multimodal.h" +#include "fingersense_wrapper.h" +#include "pointer_event.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "FingersenseWrapperTest" + +namespace OHOS { +namespace MMI { +namespace { +using namespace testing; +using namespace testing::ext; + +const float EPSILON = 10.0; +} // namespace +class FingersenseWrapperTest : public testing::Test { +public: + static void SetUpTestCase(void){}; + static void TearDownTestCase(void){}; + void SetUp() + { + wrapper_ = std::make_shared(); + }; + void TearDown(){}; + + std::shared_ptr wrapper_; +}; + +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE +/* * + * @tc.name : CrownTransformProcessorTest_SaveTouchInfo_001 + * @tc.desc: Test the funcation SaveTouchInfo + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_001, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = 1; + wrapper_->SaveTouchInfo(pointX, pointY, toolType); + + EXPECT_EQ(wrapper_->touchInfos_.size(), 1); + EXPECT_EQ(wrapper_->touchInfos_[0].x, pointX); + EXPECT_EQ(wrapper_->touchInfos_[0].y, pointY); + EXPECT_EQ(wrapper_->touchInfos_[0].touch_type, toolType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_SaveTouchInfo_002 + * @tc.desc: Test the funcation SaveTouchInfo + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_002, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = 1; + size_t vectorSize = 10; + size_t maxVectorSize = 10; + + for (size_t i = 0; i < vectorSize; i++) { + TouchInfo touchInfo; + touchInfo.x = pointX; + touchInfo.y = pointY; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + } + + wrapper_->SaveTouchInfo(pointX, pointY, toolType); + EXPECT_EQ(wrapper_->touchInfos_.size(), maxVectorSize); +} + +/* * + * @tc.name : CrownTransformProcessorTest_SaveTouchInfo_003 + * @tc.desc: Test the funcation SaveTouchInfo + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_003, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = 1; + size_t vectorSize = 20; + size_t maxVectorSize = 10; + + for (size_t i = 0; i < vectorSize; i++) { + TouchInfo touchInfo; + touchInfo.x = pointX; + touchInfo.y = pointY; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + } + + wrapper_->SaveTouchInfo(pointX, pointY, toolType); + EXPECT_EQ(wrapper_->touchInfos_.size(), maxVectorSize); +} + +/* * + * @tc.name : CrownTransformProcessorTest_IsEqual_001 + * @tc.desc: Test the funcation IsEqual + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_IsEqual_001, TestSize.Level1) +{ + float a = 10.0f; + float b = 10.0f; + float epsilon = 0.001f; + + bool result = wrapper_->IsEqual(a, b, epsilon); + EXPECT_TRUE(result); +} + +/* * + * @tc.name : CrownTransformProcessorTest_IsEqual_002 + * @tc.desc: Test the funcation IsEqual + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_IsEqual_002, TestSize.Level1) +{ + float a = 10.0f; + float b = 10.1f; + float epsilon = 0.05f; + + bool result = wrapper_->IsEqual(a, b, epsilon); + EXPECT_FALSE(result); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_001 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_001, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_ERR); + EXPECT_FALSE(isKnuckleType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_002 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_002, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE; + TouchInfo touchInfo; + touchInfo.x = pointX; + touchInfo.y = pointY; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_OK); + EXPECT_TRUE(isKnuckleType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_003 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_003, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE; + TouchInfo touchInfo; + touchInfo.x = pointX; + touchInfo.y = pointY + EPSILON; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_ERR); + EXPECT_FALSE(isKnuckleType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_004 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_004, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE; + TouchInfo touchInfo; + touchInfo.x = pointX; + touchInfo.y = pointY + EPSILON * 2; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_ERR); + EXPECT_FALSE(isKnuckleType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_005 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_005, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE; + TouchInfo touchInfo; + touchInfo.x = pointX + EPSILON; + touchInfo.y = pointY; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_ERR); + EXPECT_FALSE(isKnuckleType); +} + +/* * + * @tc.name : CrownTransformProcessorTest_CheckKnuckleEvent_006 + * @tc.desc: Test the funcation CheckKnuckleEvent + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_006, TestSize.Level1) +{ + float pointX = 10.0f; + float pointY = 20.0f; + int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE; + TouchInfo touchInfo; + touchInfo.x = pointX + EPSILON * 2; + touchInfo.y = pointY; + touchInfo.touch_type = toolType; + wrapper_->touchInfos_.push_back(touchInfo); + bool isKnuckleType = false; + + int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType); + EXPECT_EQ(result, RET_ERR); + EXPECT_FALSE(isKnuckleType); +} +#endif // OHOS_BUILD_ENABLE_FINGERSENSE +} // namespace MMI +} // namespace OHOS