From aec0a1f0df71cb94ea094a49d7be5f4b61323a9d Mon Sep 17 00:00:00 2001 From: wanghao505 Date: Wed, 4 Jun 2025 21:39:06 +0800 Subject: [PATCH 1/3] fix Signed-off-by: wanghao505 Change-Id: I2ad8181b8d0ce14780eb4e4b57d2bb15d3641d6b --- common/anco/comm/BUILD.gn | 2 + frameworks/proxy/BUILD.gn | 9 + libudev/test/test_device.h | 2 +- service/BUILD.gn | 1 + .../src/fingerprint_event_processor.cpp | 2 + .../fingerprint_event_processor/test/BUILD.gn | 92 ++++- .../test/ipc_blocklist.txt | 16 + .../fingerprint_event_processor_test copy.cpp | 321 ++++++++++++++++++ service/module_loader/test/BUILD.gn | 2 + service/touch_event_normalize/test/BUILD.gn | 1 + .../libinput_interface/include/libinput.h | 3 + .../include/libinput_interface.h | 1 + .../src/libinput_interface.cpp | 5 + test/facility/mock/include/libinput_mock.h | 1 + test/fuzztest/accountmanager_fuzzer/BUILD.gn | 1 + test/unittest/interfaces/BUILD.gn | 1 + 16 files changed, 458 insertions(+), 2 deletions(-) create mode 100644 service/fingerprint_event_processor/test/ipc_blocklist.txt create mode 100644 service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp diff --git a/common/anco/comm/BUILD.gn b/common/anco/comm/BUILD.gn index d67eed247..0d5ffdf68 100644 --- a/common/anco/comm/BUILD.gn +++ b/common/anco/comm/BUILD.gn @@ -67,6 +67,7 @@ ohos_source_set("mmi_anco_channel_proxy") { external_deps = [ "hilog:libhilog", "ipc:ipc_single", + "c_utils:utils", ] part_name = "${mmi_part_name}" @@ -105,6 +106,7 @@ ohos_source_set("mmi_anco_channel_stub") { external_deps = [ "hilog:libhilog", "ipc:ipc_single", + "c_utils:utils", ] part_name = "${mmi_part_name}" diff --git a/frameworks/proxy/BUILD.gn b/frameworks/proxy/BUILD.gn index 12043d958..dc23e15c1 100644 --- a/frameworks/proxy/BUILD.gn +++ b/frameworks/proxy/BUILD.gn @@ -437,6 +437,7 @@ ohos_unittest("InputMonitorManagerTest") { "${mmi_path}/service:libmmi-server", "${mmi_path}/service/filter:mmi_event_filter_service", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/proxy:libmmi-client", ] external_deps = [ @@ -505,6 +506,7 @@ ohos_unittest("InputManagerImplTest") { "${mmi_path}/service:libmmi-server", "${mmi_path}/service/filter:mmi_event_filter_service", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/proxy:libmmi-client", ] external_deps = [ @@ -709,11 +711,14 @@ ohos_unittest("KeyEventInputSubscribeManagerTest") { deps = [ "${mmi_path}/service:libmmi-server", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/proxy:libmmi-client", ] + external_deps = [ "ability_runtime:abilitykit_native", "c_utils:utils", "hilog:libhilog", + "eventhandler:libeventhandler", ] } @@ -740,10 +745,12 @@ ohos_unittest("LongPressEventSubscribeManagerTest") { "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", ] + external_deps = [ "ability_runtime:abilitykit_native", "c_utils:utils", "hilog:libhilog", + "eventhandler:libeventhandler", ] } @@ -770,9 +777,11 @@ ohos_unittest("InputDeviceImplTest") { "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", ] + external_deps = [ "ability_runtime:abilitykit_native", "hilog:libhilog", + "eventhandler:libeventhandler", ] } diff --git a/libudev/test/test_device.h b/libudev/test/test_device.h index 1e09caa4b..77dedae04 100644 --- a/libudev/test/test_device.h +++ b/libudev/test/test_device.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include class TestDevice { diff --git a/service/BUILD.gn b/service/BUILD.gn index b3ca0f810..4762fabce 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -3182,6 +3182,7 @@ ohos_unittest("JoystickTest") { "hisysevent:libhisysevent", "init:libbegetutil", "libinput:libinput-third-mmi", + "ipc:ipc_core", ] } diff --git a/service/fingerprint_event_processor/src/fingerprint_event_processor.cpp b/service/fingerprint_event_processor/src/fingerprint_event_processor.cpp index 33d791ad6..5945ba6eb 100644 --- a/service/fingerprint_event_processor/src/fingerprint_event_processor.cpp +++ b/service/fingerprint_event_processor/src/fingerprint_event_processor.cpp @@ -15,6 +15,8 @@ #include "fingerprint_event_processor.h" +#include "libinput.h" + #include "ability_manager_client.h" #include "dfx_hisysevent.h" #include "event_log_helper.h" diff --git a/service/fingerprint_event_processor/test/BUILD.gn b/service/fingerprint_event_processor/test/BUILD.gn index b3a9c1070..5526aed2d 100644 --- a/service/fingerprint_event_processor/test/BUILD.gn +++ b/service/fingerprint_event_processor/test/BUILD.gn @@ -18,6 +18,13 @@ import("../../../multimodalinput_mini.gni") module_output_path = "input/input" ohos_unittest("FingerprintEventProcessorTest") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "./ipc_blocklist.txt" + } module_out_path = module_output_path defines = input_default_defines @@ -64,6 +71,90 @@ ohos_unittest("FingerprintEventProcessorTest") { "${mmi_path}/util/common/src/input_event_data_transformation.cpp", "${mmi_path}/util/network/src/stream_buffer.cpp", "src/fingerprint_event_processor_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" ] + } +} + +ohos_unittest("XKeyEventProcessorTest") { + module_out_path = module_output_path + + defines = input_default_defines + defines += [ "OHOS_BUILD_ENABLE_X_KEY" ] + + 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/x_key_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/x_key_event_processor_test.cpp", ] @@ -90,7 +181,6 @@ ohos_unittest("FingerprintEventProcessorTest") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "libinput:libinput-third-mmi", "preferences:native_preferences", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/service/fingerprint_event_processor/test/ipc_blocklist.txt b/service/fingerprint_event_processor/test/ipc_blocklist.txt new file mode 100644 index 000000000..3ef2958d6 --- /dev/null +++ b/service/fingerprint_event_processor/test/ipc_blocklist.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2024 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. + +[cfi] +src:*third_party/googletest/googletest/include/* +src:*fingerprint_event_processor_test.cpp \ No newline at end of file diff --git a/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp b/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp new file mode 100644 index 000000000..cee7a6326 --- /dev/null +++ b/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp @@ -0,0 +1,321 @@ +/* + * Copyright (c) 2024 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 "error_multimodal.h" +#include "fingerprint_event_processor.h" +#include "input_event_handler.h" +#include "libinput_mock.h" +#include "mmi_log.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "FingerprintEventProcessorTest" + +namespace OHOS { +namespace MMI { +namespace { +using namespace testing; +using namespace testing::ext; +} +class FingerprintEventProcessorTest : public testing::Test { +public: + static void SetUpTestCase(void){}; + static void TearDownTestCase(void){}; + void SetUp(){}; + void TearDown(){}; +}; + +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT +/** + * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_EventIsNull + * @tc.desc: Test IsFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_IsFingerprintEvent_EventIsNull, TestSize.Level1) +{ + struct libinput_event* event = NULL; + EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsNotFingerprint + * @tc.desc: Test IsFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_IsFingerprintEvent_NameIsNotFingerprint, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + EXPECT_CALL(mock, GetDevice) + .WillRepeatedly(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillOnce(Return(const_cast("not_fingerprint_source_key"))) + .WillOnce(Return(const_cast("hw_fingerprint_mouse"))); + EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(&event)); + EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_001 + * @tc.desc: Test IsFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_001, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillOnce(Return(const_cast("fingerprint"))); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(100)); + EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(&event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_002 + * @tc.desc: Test IsFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_002, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillRepeatedly(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillRepeatedly(Return(const_cast("fingerprint"))); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillRepeatedly(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_UP)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_CLICK)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_RETOUCH)); + EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); + EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); + EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); + EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourceKey + * @tc.desc: Test HandleFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourceKey, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillOnce(Return(const_cast("fingerprint"))); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(100)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) + .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); + EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), ERR_OK); +} + +/** + * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourcePoint + * @tc.desc: Test HandleFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourcePoint, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + struct libinput_event_pointer rawPointerEvent; + InputHandler->BuildInputHandlerChain(); + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillOnce(Return(const_cast("hw_fingerprint_mouse"))); + EXPECT_CALL(mock, LibinputGetPointerEvent) + .WillOnce(Return(&rawPointerEvent)); + EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), RET_OK); +} + +/** + * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameNotFingerprintSourceKey_001 + * @tc.desc: Test HandleFingerprintEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_HandleFingerprintEvent_NameNotFingerprintSourceKey_001, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, DeviceGetName) + .WillOnce(Return(const_cast("not_fingerprint_source_key"))); + EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), MMI::PARAM_INPUT_INVALID); +} + +/** + * @tc.name: FingerprintEventProcessorTest_AnalyseKeyEvent_StateIsLibinputKeyStatePressed + * @tc.desc: Test AnalyseKeyEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_AnalyseKeyEvent_StateIsLibinputKeyStatePressed, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) + .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); +} + +/** + * @tc.name: FingerprintEventProcessorTest_AnalyseKeyEvent_StateNotLibinputKeyStatePressed + * @tc.desc: Test AnalyseKeyEvent + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, + FingerprintEventProcessorTest_AnalyseKeyEvent_StateNotLibinputKeyStatePressed, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillRepeatedly(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_UP)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_RETOUCH)) + .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_CLICK)) + .WillOnce(Return(100)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) + .WillRepeatedly(Return(LIBINPUT_KEY_STATE_RELEASED)); + InputHandler->BuildInputHandlerChain(); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); + EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), MMI::UNKNOWN_EVENT); +} + +/** + * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_001 + * @tc.desc: Test HandleFingerprintEvent (keyCode != KEY_POWER) Branch + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_001, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(100)); + ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_002 + * @tc.desc: Test HandleFingerprintEvent (keyAction == KeyEvent::KEY_ACTION_DOWN) Branch + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_002, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(116)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) + .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); + ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); +} + +/** + * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_003 + * @tc.desc: Test HandleFingerprintEvent (keyAction != KeyEvent::KEY_ACTION_DOWN) Branch + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_003, TestSize.Level1) +{ + NiceMock mock; + struct libinput_event event; + struct libinput_device device; + struct libinput_event_keyboard keyBoardEvent; + EXPECT_CALL(mock, GetDevice) + .WillOnce(Return(&device)); + EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) + .WillOnce(Return(&keyBoardEvent)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKey) + .WillOnce(Return(116)); + EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) + .WillOnce(Return(LIBINPUT_KEY_STATE_RELEASED)); + ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); +} + +#endif // OHOS_BUILD_ENABLE_FINGERPRINT +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/module_loader/test/BUILD.gn b/service/module_loader/test/BUILD.gn index 5636f6920..95d136ff1 100644 --- a/service/module_loader/test/BUILD.gn +++ b/service/module_loader/test/BUILD.gn @@ -60,6 +60,8 @@ ohos_unittest("PreferencesManagerTestWithMock") { "init:libbegetutil", "libxml2:libxml2", "preferences:native_preferences", + "c_utils:utils", + "hilog:libhilog", ] } diff --git a/service/touch_event_normalize/test/BUILD.gn b/service/touch_event_normalize/test/BUILD.gn index 322bac3b7..b05827a73 100644 --- a/service/touch_event_normalize/test/BUILD.gn +++ b/service/touch_event_normalize/test/BUILD.gn @@ -521,6 +521,7 @@ ohos_unittest("TouchTransformProcessorTestWithMock") { "${mmi_path}/test/facility/mock:mmi_mock_sources", "${mmi_path}/test/facility/virtual_device:virtual_device_sources", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/proxy:libmmi-client", ] external_deps = [ diff --git a/test/facility/libinput_interface/include/libinput.h b/test/facility/libinput_interface/include/libinput.h index d1f308691..225130143 100644 --- a/test/facility/libinput_interface/include/libinput.h +++ b/test/facility/libinput_interface/include/libinput.h @@ -166,6 +166,7 @@ struct libinput_event_touch; struct libinput_event_tablet_tool; struct libinput_event_gesture; struct libinput_tablet_tool; +struct libinput; enum libinput_event_type libinput_event_get_type(struct libinput_event *event); @@ -191,6 +192,8 @@ int32_t libinput_event_tablet_tool_get_twist(struct libinput_event_tablet_tool * struct libinput_device* libinput_event_get_device(struct libinput_event *event); +int32_t libinput_event_get_hand_feature(struct libinput_event *event); + uint64_t libinput_event_get_sensortime(struct libinput_event *event); struct libinput_event_keyboard* libinput_event_get_keyboard_event(struct libinput_event *event); diff --git a/test/facility/libinput_interface/include/libinput_interface.h b/test/facility/libinput_interface/include/libinput_interface.h index 7b22aeb33..6e189605c 100644 --- a/test/facility/libinput_interface/include/libinput_interface.h +++ b/test/facility/libinput_interface/include/libinput_interface.h @@ -116,6 +116,7 @@ public: virtual uint64_t TabletToolGetTimeUsec(struct libinput_event_tablet_tool *event) = 0; virtual double TabletToolGetPressure(struct libinput_event_tablet_tool *event) = 0; virtual int32_t TabletToolGetTwist(struct libinput_event_tablet_tool *event) = 0; + virtual int32_t GetHandFeature(struct libinput_event *event) = 0; virtual int32_t TouchEventGetBlobId(struct libinput_event_touch *event) = 0; virtual uint64_t TouchEventGetTime(struct libinput_event_touch *event) = 0; virtual int32_t TouchEventGetSeatSlot(struct libinput_event_touch *event) = 0; diff --git a/test/facility/libinput_interface/src/libinput_interface.cpp b/test/facility/libinput_interface/src/libinput_interface.cpp index 44864fafa..bec5f07bc 100644 --- a/test/facility/libinput_interface/src/libinput_interface.cpp +++ b/test/facility/libinput_interface/src/libinput_interface.cpp @@ -91,6 +91,11 @@ struct libinput_device* libinput_event_get_device(struct libinput_event *event) return g_instance->GetDevice(event); } +int32_t libinput_event_get_hand_feature(struct libinput_event *event) +{ + return g_instance->GetHandFeature(event); +} + uint64_t libinput_event_get_sensortime(struct libinput_event *event) { return g_instance->GetSensorTime(event); diff --git a/test/facility/mock/include/libinput_mock.h b/test/facility/mock/include/libinput_mock.h index 798171a4e..231b3f341 100644 --- a/test/facility/mock/include/libinput_mock.h +++ b/test/facility/mock/include/libinput_mock.h @@ -44,6 +44,7 @@ public: MOCK_METHOD(uint64_t, TabletToolGetTimeUsec, (struct libinput_event_tablet_tool *)); MOCK_METHOD(double, TabletToolGetPressure, (struct libinput_event_tablet_tool *)); MOCK_METHOD(int32_t, TabletToolGetTwist, (struct libinput_event_tablet_tool *)); + MOCK_METHOD(int32_t, GetHandFeature, (struct libinput_event *)); MOCK_METHOD(int32_t, TouchEventGetBlobId, (struct libinput_event_touch *)); MOCK_METHOD(uint64_t, TouchEventGetTime, (struct libinput_event_touch *)); MOCK_METHOD(int32_t, TouchEventGetSeatSlot, (struct libinput_event_touch *)); diff --git a/test/fuzztest/accountmanager_fuzzer/BUILD.gn b/test/fuzztest/accountmanager_fuzzer/BUILD.gn index bb9e15a72..56198bcc7 100644 --- a/test/fuzztest/accountmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/accountmanager_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("AccountManagerFuzzTest") { "ability_runtime:app_manager", "cJSON:cjson", "c_utils:utils", + "common_event_service:cesfwk_core", "data_share:datashare_consumer", "graphic_2d:2d_graphics", "graphic_2d:librender_service_client", diff --git a/test/unittest/interfaces/BUILD.gn b/test/unittest/interfaces/BUILD.gn index de0fa21fb..4f981a6b4 100644 --- a/test/unittest/interfaces/BUILD.gn +++ b/test/unittest/interfaces/BUILD.gn @@ -93,6 +93,7 @@ ohos_unittest("InputNativeHotkeyTest") { "googletest:gtest_main", "hilog:libhilog", "image_framework:image_native", + "eventhandler:libeventhandler", ] subsystem_name = "multimodalinput" -- Gitee From 71914139b19be1d87472a1bdd1a6f42c8bd1d309 Mon Sep 17 00:00:00 2001 From: wanghao505 Date: Wed, 4 Jun 2025 21:58:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanghao505 Change-Id: I1ac7c1bf057665b748b3df2d5235cc6eb7a214f5 --- frameworks/proxy/BUILD.gn | 2 + libudev/BUILD.gn | 2 - multimodalinput_mini.gni | 1 - .../fingerprint_event_processor/test/BUILD.gn | 7 - .../test/ipc_blocklist.txt | 16 - .../fingerprint_event_processor_test copy.cpp | 321 ------------------ 6 files changed, 2 insertions(+), 347 deletions(-) delete mode 100644 service/fingerprint_event_processor/test/ipc_blocklist.txt delete mode 100644 service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp diff --git a/frameworks/proxy/BUILD.gn b/frameworks/proxy/BUILD.gn index dc23e15c1..6b1f5d53c 100644 --- a/frameworks/proxy/BUILD.gn +++ b/frameworks/proxy/BUILD.gn @@ -168,6 +168,8 @@ ohos_shared_library("libmmi-client") { "samgr:samgr_proxy", ] + public_external_deps = ["eventhandler:libeventhandler"] + if (hitrace_enabled) { external_deps += [ "hitrace:hitrace_meter" ] } diff --git a/libudev/BUILD.gn b/libudev/BUILD.gn index a2ab7887a..cf0875d29 100644 --- a/libudev/BUILD.gn +++ b/libudev/BUILD.gn @@ -57,7 +57,6 @@ ohos_unittest("libudev-test") { module_out_path = output_path include_dirs = [ "${mmi_path}/util/common/include", - "${third_party_path}/libevdev", ] configs = [ @@ -81,7 +80,6 @@ ohos_unittest("libudev-test") { ohos_unittest("e2e-libudev-test") { module_out_path = output_path - include_dirs = [ "${third_party_path}/libevdev" ] sources = [ "test/e2e_udev_test.cpp" ] diff --git a/multimodalinput_mini.gni b/multimodalinput_mini.gni index a0be68373..d65f72dcc 100644 --- a/multimodalinput_mini.gni +++ b/multimodalinput_mini.gni @@ -23,7 +23,6 @@ ability_runtime_path = "//foundation/ability/ability_runtime" security_component_path = "//base/security" c_utils_root = "//commonlibrary/c_utils" hilog_root = "//base/hiviewdfx/hilog" -third_party_path = "//third_party" declare_args() { hitrace_enabled = false diff --git a/service/fingerprint_event_processor/test/BUILD.gn b/service/fingerprint_event_processor/test/BUILD.gn index 5526aed2d..b08c8543e 100644 --- a/service/fingerprint_event_processor/test/BUILD.gn +++ b/service/fingerprint_event_processor/test/BUILD.gn @@ -18,13 +18,6 @@ import("../../../multimodalinput_mini.gni") module_output_path = "input/input" ohos_unittest("FingerprintEventProcessorTest") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - blocklist = "./ipc_blocklist.txt" - } module_out_path = module_output_path defines = input_default_defines diff --git a/service/fingerprint_event_processor/test/ipc_blocklist.txt b/service/fingerprint_event_processor/test/ipc_blocklist.txt deleted file mode 100644 index 3ef2958d6..000000000 --- a/service/fingerprint_event_processor/test/ipc_blocklist.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2024 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. - -[cfi] -src:*third_party/googletest/googletest/include/* -src:*fingerprint_event_processor_test.cpp \ No newline at end of file diff --git a/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp b/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp deleted file mode 100644 index cee7a6326..000000000 --- a/service/fingerprint_event_processor/test/src/fingerprint_event_processor_test copy.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (c) 2024 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 "error_multimodal.h" -#include "fingerprint_event_processor.h" -#include "input_event_handler.h" -#include "libinput_mock.h" -#include "mmi_log.h" - -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "FingerprintEventProcessorTest" - -namespace OHOS { -namespace MMI { -namespace { -using namespace testing; -using namespace testing::ext; -} -class FingerprintEventProcessorTest : public testing::Test { -public: - static void SetUpTestCase(void){}; - static void TearDownTestCase(void){}; - void SetUp(){}; - void TearDown(){}; -}; - -#ifdef OHOS_BUILD_ENABLE_FINGERPRINT -/** - * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_EventIsNull - * @tc.desc: Test IsFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_IsFingerprintEvent_EventIsNull, TestSize.Level1) -{ - struct libinput_event* event = NULL; - EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsNotFingerprint - * @tc.desc: Test IsFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_IsFingerprintEvent_NameIsNotFingerprint, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - EXPECT_CALL(mock, GetDevice) - .WillRepeatedly(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillOnce(Return(const_cast("not_fingerprint_source_key"))) - .WillOnce(Return(const_cast("hw_fingerprint_mouse"))); - EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(&event)); - EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_001 - * @tc.desc: Test IsFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_001, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillOnce(Return(const_cast("fingerprint"))); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(100)); - EXPECT_FALSE(FingerprintEventHdr->IsFingerprintEvent(&event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_002 - * @tc.desc: Test IsFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_IsFingerprintEvent_NameIsFingerprintSourceKey_002, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillRepeatedly(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillRepeatedly(Return(const_cast("fingerprint"))); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillRepeatedly(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_UP)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_CLICK)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_RETOUCH)); - EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); - EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); - EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); - EXPECT_TRUE(FingerprintEventHdr->IsFingerprintEvent(&event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourceKey - * @tc.desc: Test HandleFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourceKey, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillOnce(Return(const_cast("fingerprint"))); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(100)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) - .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); - EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), ERR_OK); -} - -/** - * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourcePoint - * @tc.desc: Test HandleFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_HandleFingerprintEvent_NameIsFingerprintSourcePoint, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - struct libinput_event_pointer rawPointerEvent; - InputHandler->BuildInputHandlerChain(); - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillOnce(Return(const_cast("hw_fingerprint_mouse"))); - EXPECT_CALL(mock, LibinputGetPointerEvent) - .WillOnce(Return(&rawPointerEvent)); - EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), RET_OK); -} - -/** - * @tc.name: FingerprintEventProcessorTest_HandleFingerprintEvent_NameNotFingerprintSourceKey_001 - * @tc.desc: Test HandleFingerprintEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_HandleFingerprintEvent_NameNotFingerprintSourceKey_001, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, DeviceGetName) - .WillOnce(Return(const_cast("not_fingerprint_source_key"))); - EXPECT_EQ(FingerprintEventHdr->HandleFingerprintEvent(&event), MMI::PARAM_INPUT_INVALID); -} - -/** - * @tc.name: FingerprintEventProcessorTest_AnalyseKeyEvent_StateIsLibinputKeyStatePressed - * @tc.desc: Test AnalyseKeyEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_AnalyseKeyEvent_StateIsLibinputKeyStatePressed, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) - .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); -} - -/** - * @tc.name: FingerprintEventProcessorTest_AnalyseKeyEvent_StateNotLibinputKeyStatePressed - * @tc.desc: Test AnalyseKeyEvent - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, - FingerprintEventProcessorTest_AnalyseKeyEvent_StateNotLibinputKeyStatePressed, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillRepeatedly(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_DOWN)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_UP)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_RETOUCH)) - .WillOnce(Return(FingerprintEventProcessor::FINGERPRINT_CODE_CLICK)) - .WillOnce(Return(100)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) - .WillRepeatedly(Return(LIBINPUT_KEY_STATE_RELEASED)); - InputHandler->BuildInputHandlerChain(); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), ERR_OK); - EXPECT_EQ(FingerprintEventHdr->AnalyseKeyEvent(&event), MMI::UNKNOWN_EVENT); -} - -/** - * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_001 - * @tc.desc: Test HandleFingerprintEvent (keyCode != KEY_POWER) Branch - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_001, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(100)); - ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_002 - * @tc.desc: Test HandleFingerprintEvent (keyAction == KeyEvent::KEY_ACTION_DOWN) Branch - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_002, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(116)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) - .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED)); - ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); -} - -/** - * @tc.name: FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_003 - * @tc.desc: Test HandleFingerprintEvent (keyAction != KeyEvent::KEY_ACTION_DOWN) Branch - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(FingerprintEventProcessorTest, FingerprintEventProcessorTest_SetPowerAndVolumeKeyState_003, TestSize.Level1) -{ - NiceMock mock; - struct libinput_event event; - struct libinput_device device; - struct libinput_event_keyboard keyBoardEvent; - EXPECT_CALL(mock, GetDevice) - .WillOnce(Return(&device)); - EXPECT_CALL(mock, LibinputEventGetKeyboardEvent) - .WillOnce(Return(&keyBoardEvent)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKey) - .WillOnce(Return(116)); - EXPECT_CALL(mock, LibinputEventKeyboardGetKeyState) - .WillOnce(Return(LIBINPUT_KEY_STATE_RELEASED)); - ASSERT_NO_FATAL_FAILURE(FingerprintEventHdr->SetPowerAndVolumeKeyState(&event)); -} - -#endif // OHOS_BUILD_ENABLE_FINGERPRINT -} // namespace MMI -} // namespace OHOS \ No newline at end of file -- Gitee From ec305b28faaddf303fe8570006004c5952dc40d4 Mon Sep 17 00:00:00 2001 From: wanghao505 Date: Thu, 5 Jun 2025 13:58:56 +0800 Subject: [PATCH 3/3] fix test Signed-off-by: wanghao505 Change-Id: If520628ae59a64b52266056626309354c975d2c1 --- BUILD.gn | 1 + .../fingerprint_event_processor/test/BUILD.gn | 8 ++++++++ .../test/ipc_blocklist.txt | 16 ++++++++++++++++ .../test/src/x_key_event_processor_test.cpp | 7 ++----- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 service/fingerprint_event_processor/test/ipc_blocklist.txt diff --git a/BUILD.gn b/BUILD.gn index fd9d92871..034f27781 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -205,6 +205,7 @@ group("mmi_tests") { "service:mmi-service-tests", "service/crown_transform_processor/test:CrownTransformProcessorTest", "service/fingerprint_event_processor/test:FingerprintEventProcessorTest", + "service/fingerprint_event_processor/test:XKeyEventProcessorTest", "service/module_loader/test:ModuleLoaderTests", "service/mouse_event_normalize/test:MouseEventNormalizeTest", "service/subscriber/test:mmi_subscriber_tests", diff --git a/service/fingerprint_event_processor/test/BUILD.gn b/service/fingerprint_event_processor/test/BUILD.gn index b08c8543e..33c737dca 100644 --- a/service/fingerprint_event_processor/test/BUILD.gn +++ b/service/fingerprint_event_processor/test/BUILD.gn @@ -20,6 +20,14 @@ module_output_path = "input/input" ohos_unittest("FingerprintEventProcessorTest") { module_out_path = module_output_path + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = true + blocklist = "./ipc_blocklist.txt" + } + defines = input_default_defines defines += [ "OHOS_BUILD_ENABLE_FINGERPRINT" ] diff --git a/service/fingerprint_event_processor/test/ipc_blocklist.txt b/service/fingerprint_event_processor/test/ipc_blocklist.txt new file mode 100644 index 000000000..3b04b64df --- /dev/null +++ b/service/fingerprint_event_processor/test/ipc_blocklist.txt @@ -0,0 +1,16 @@ +# 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. + +[cfi] +src:*third_party/googletest/googletest/include/* +src:*fingerprint_event_processor_test.cpp \ No newline at end of file diff --git a/service/fingerprint_event_processor/test/src/x_key_event_processor_test.cpp b/service/fingerprint_event_processor/test/src/x_key_event_processor_test.cpp index a4c9e85be..aee78bce6 100644 --- a/service/fingerprint_event_processor/test/src/x_key_event_processor_test.cpp +++ b/service/fingerprint_event_processor/test/src/x_key_event_processor_test.cpp @@ -69,7 +69,6 @@ libinput_event *XKeyEventProcessorTest::GetEvent() HWTEST_F(XKeyEventProcessorTest, XKeyEventProcessorTest_IsXKeyEvent_001, TestSize.Level1) { libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); bool ret = XKeyEventHdr->IsXKeyEvent(event); EXPECT_FALSE(ret); } @@ -83,9 +82,8 @@ HWTEST_F(XKeyEventProcessorTest, XKeyEventProcessorTest_IsXKeyEvent_001, TestSiz HWTEST_F(XKeyEventProcessorTest, XKeyEventProcessorTest_HandleXKeyEvent_001, TestSize.Level1) { libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); int32_t ret = XKeyEventHdr->HandleXKeyEvent(event); - EXPECT_EQ(ret, 65142788); + EXPECT_EQ(ret, 65142786); } /** @@ -97,9 +95,8 @@ HWTEST_F(XKeyEventProcessorTest, XKeyEventProcessorTest_HandleXKeyEvent_001, Tes HWTEST_F(XKeyEventProcessorTest, XKeyEventProcessorTest_AnalyseKeyEvent_001, TestSize.Level1) { libinput_event *event = GetEvent(); - ASSERT_TRUE(event != nullptr); int32_t ret = XKeyEventHdr->AnalyseKeyEvent(event); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 65142786); } /** -- Gitee