diff --git a/build/gn/BUILD.gn b/build/gn/BUILD.gn index cc5706575a43d18e17a068a409316885ead9d02c..982900bf800b5efe9880894bd227726f57ce31b5 100644 --- a/build/gn/BUILD.gn +++ b/build/gn/BUILD.gn @@ -17,3 +17,8 @@ group("ft_mmi") { ] } +group("ft_test") { + deps = [ + "//input/frameworks/proxy/events/test/ft_build:ft_inputManagerTest", + ] +} diff --git a/build/gn/configs/system_libs/BUILD.gn b/build/gn/configs/system_libs/BUILD.gn index 58338cbded9d23fbfbeb844f560e7f31a1c2609d..2985c45ee31e1940d11cab738fd3c836e7d7e894 100644 --- a/build/gn/configs/system_libs/BUILD.gn +++ b/build/gn/configs/system_libs/BUILD.gn @@ -55,3 +55,10 @@ config("syspara_config") { include_dirs = [ "${sys_inc}/syspara" ] libs = [ "beget_proxy", "begetutil" ] } + +config("image_config") { + visibility = [ ":*" ] + + include_dirs = [ "${sys_inc}/image" ] + libs = [ "image_native" ] +} \ No newline at end of file diff --git a/input/frameworks/proxy/events/test/ft_build/BUILD.gn b/input/frameworks/proxy/events/test/ft_build/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c6e6752759e84e7ca1dce71154738df22576ef97 --- /dev/null +++ b/input/frameworks/proxy/events/test/ft_build/BUILD.gn @@ -0,0 +1,125 @@ +# Copyright (c) 2023 Huawei Technologies 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/gn/fangtian.gni") +import("//input/ft_multimodalinput_mini.gni") + +group("ft_inputManagerTest") { + if (input_test_case) { + deps = [ + ":InputManagerTest", + ":InputManagerAnrTest", + ] + } +} + +if (input_test_case) { + config("input_manager_test_config") { + include_dirs = [ + "/usr/include/ftengine/wm", + "/usr/include/ftengine/dm", + "${mmi_path}/frameworks/proxy/events/test", + "${mmi_path}/frameworks/proxy/events/include", + "${mmi_path}/stub", + "${mmi_path}/frameworks/proxy/event_handler/include", + "${mmi_path}/frameworks/proxy/module_loader/include", + "${mmi_path}/interfaces/native/innerkits/common/include", + "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/test/unittest/common/include", + "${mmi_path}/util/network/include", + "${mmi_path}/util/socket/include", + ] + + defines = [ "FT_DISBALE_MONITER" ] + if (input_feature_pointer_drawing) { + defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] + } + if (input_feature_input_cooperation) { + defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] + } + if (input_feature_keyboard) { + defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] + } + if (input_feature_mouse) { + defines += [ "OHOS_BUILD_ENABLE_POINTER" ] + } + if (input_feature_touchscreen) { + defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] + } + if (input_feature_interceptor) { + defines += [ "OHOS_BUILD_ENABLE_INTERCEPTOR" ] + } + if (input_feature_monitor) { + defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] + } + if (input_feature_joystick) { + defines += [ "OHOS_BUILD_ENABLE_JOYSTICK" ] + } + } + + ft_executable("InputManagerAnrTest") { + sources = [ + "${mmi_path}/test/unittest/common/src/event_util_test.cpp", + "${mmi_path}/test/unittest/common/src/system_info.cpp", + "${mmi_path}/test/unittest/common/src/window_utils_test.cpp", + "../ft_input_manager_anr_test.cpp", + ] + + configs = [ + ":input_manager_test_config", + ] + + deps = [ + "${mmi_path}/frameworks/proxy/ft_build:libmmi-client", + "${mmi_path}/util/ft_build:libmmi-util", + ] + + libs = [ "gtest" ] + + public_configs = [ + "//build/gn/configs/system_libs:hilog_config", + "//build/gn/configs/system_libs:ipc_core_config", + "//build/gn/configs/system_libs:eventhandler_config", + "//build/gn/configs/system_libs:wm_config", + "//build/gn/configs/system_libs:image_config", + ] + } + + ft_executable("InputManagerTest") { + sources = [ + "${mmi_path}/test/unittest/common/src/event_util_test.cpp", + "${mmi_path}/test/unittest/common/src/system_info.cpp", + "${mmi_path}/test/unittest/common/src/window_utils_test.cpp", + "../ft_input_manager_test.cpp", + ] + + configs = [ + ":input_manager_test_config", + ] + + deps = [ + "${mmi_path}/frameworks/proxy/ft_build:libmmi-client", + "${mmi_path}/util/ft_build:libmmi-util", + ] + + libs = [ "gtest" ] + + public_configs = [ + "//build/gn/configs/system_libs:hilog_config", + "//build/gn/configs/system_libs:ipc_core_config", + "//build/gn/configs/system_libs:eventhandler_config", + "//build/gn/configs/system_libs:wm_config", + "//build/gn/configs/system_libs:image_config", + ] + } +} \ No newline at end of file diff --git a/input/frameworks/proxy/events/test/ft_input_manager_anr_test.cpp b/input/frameworks/proxy/events/test/ft_input_manager_anr_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ebe35d14463da7d0fe5923220c10c34495de3bd --- /dev/null +++ b/input/frameworks/proxy/events/test/ft_input_manager_anr_test.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2023 Huawei Technologies 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 "event_log_helper.h" +#include "event_util_test.h" +#include "input_handler_type.h" +#include "mmi_log.h" +#include "multimodal_event_handler.h" +#include "system_info.h" +#include "util.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerAnrTest" }; +constexpr int32_t TIME_WAIT_FOR_OP = 100; +constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000; +} // namespace + +class InputManagerTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + static void SetUpTestCase(); + std::shared_ptr SetupPointerEvent001(); +}; + +void InputManagerTest::SetUpTestCase() +{ + ASSERT_TRUE(TestUtil->Init()); +} + +void InputManagerTest::SetUp() +{ + TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS); +} + +void InputManagerTest::TearDown() +{ + TestUtil->AddEventDump(""); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); +} + +std::shared_ptr InputManagerTest::SetupPointerEvent001() +{ + auto pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT); + pointerEvent->SetPointerId(0); + pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetDownTime(downTime); + item.SetPressed(true); + item.SetDisplayX(50); + item.SetDisplayY(50); + item.SetWindowX(70); + item.SetWindowY(70); + item.SetWidth(0); + item.SetHeight(0); + item.SetPressure(0); + item.SetDeviceId(0); + pointerEvent->AddPointerItem(item); + return pointerEvent; +} + +/** + * @tc.name: InputManagerTest_SetAnrObserver + * @tc.desc: Verify the observer for events + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SetAnrObserver) +{ + class IAnrObserverTest : public IAnrObserver { + public: + IAnrObserverTest() : IAnrObserver() {} + virtual ~IAnrObserverTest() {} + void OnAnr(int32_t pid) const override { + MMI_HILOGD("pid=%{public}d is ANR!", pid); + isAnr = true; + }; + mutable bool isAnr = false; + }; + + class NoMarkEventProcess : public IInputEventConsumer { + public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override { }; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override { + MMI_HILOGI("recv pointerEvent, but do not process it!"); + }; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override { }; + }; + + auto runner = AppExecFwk::EventRunner::Create(true); + ASSERT_TRUE(runner != nullptr); + auto eventHandler = std::make_shared(runner); + ASSERT_TRUE(eventHandler != nullptr); + uint64_t runnerThreadId = 0; + + auto fun = [&runnerThreadId]() { + runnerThreadId = GetThisThreadId(); + MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId); + ASSERT_TRUE(runnerThreadId != 0); + }; + eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + auto consumer = GetPtr(); + ASSERT_TRUE(consumer != nullptr); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler); + + std::shared_ptr observer = std::make_shared(); + MMI::InputManager::GetInstance()->SetAnrObserver(observer); + + for (int i = 0; i < 2; i++) { + auto pointerEvent = SetupPointerEvent001(); + ASSERT_TRUE(pointerEvent != nullptr); + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + sleep(5); // over 5s, MMIServer believes that anr has occurred + } + EXPECT_EQ(observer->isAnr, true); +} +} // namespace MMI +} // namespace OHOS + +int main(int argc, char *argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/input/frameworks/proxy/events/test/ft_input_manager_test.cpp b/input/frameworks/proxy/events/test/ft_input_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..328997135bd0ca018a998478eb760906678dd5a6 --- /dev/null +++ b/input/frameworks/proxy/events/test/ft_input_manager_test.cpp @@ -0,0 +1,347 @@ +/* + * Copyright (c) 2023 Huawei Technologies 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 "event_log_helper.h" +#include "event_util_test.h" +#include "input_handler_type.h" +#include "mmi_log.h" +#include "multimodal_event_handler.h" +#include "system_info.h" +#include "util.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerTest" }; +constexpr int32_t TIME_WAIT_FOR_OP = 100; +constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000; +} // namespace + +class InputManagerTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + static void SetUpTestCase(); + std::string GetEventDump(); + std::shared_ptr SetupPointerEvent001(); +}; + +void InputManagerTest::SetUpTestCase() +{ + ASSERT_TRUE(TestUtil->Init()); +} + +void InputManagerTest::SetUp() +{ + TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS); +} + +void InputManagerTest::TearDown() +{ + TestUtil->AddEventDump(""); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); +} + +std::string InputManagerTest::GetEventDump() +{ + return TestUtil->GetEventDump(); +} + +std::shared_ptr InputManagerTest::SetupPointerEvent001() +{ + auto pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT); + pointerEvent->SetPointerId(0); + pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetDownTime(downTime); + item.SetPressed(true); + + item.SetDisplayX(50); + item.SetDisplayY(50); + item.SetWindowX(70); + item.SetWindowY(70); + + item.SetWidth(0); + item.SetHeight(0); + item.SetPressure(0); + item.SetDeviceId(0); + pointerEvent->AddPointerItem(item); + return pointerEvent; +} + +/** + * @tc.name: InputManagerTest_SubscribeKeyEvent_01 + * @tc.desc: Verify subscribe KEYCODE_1 key event. + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_01) +{ + CALL_DEBUG_ENTER; + ASSERT_TRUE(MMIEventHdl.InitClient()); + std::set preKeys; + std::shared_ptr keyOption1 = std::make_shared(); + keyOption1->SetPreKeys(preKeys); + keyOption1->SetFinalKey(KeyEvent::KEYCODE_1); + keyOption1->SetFinalKeyDown(true); + keyOption1->SetFinalKeyDownDuration(0); + int32_t subscribeId1 = -1; + subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, + [](std::shared_ptr keyEvent) { + EventLogHelper::PrintEventData(keyEvent); + MMI_HILOGD("Subscribe key event KEYCODE_1 down trigger callback"); + }); + + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); +} + +/** + * @tc.name: InputManagerTest_SimulateKeyEvent_001 + * @tc.desc: Verify simulate the back home is pressed + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_001) +{ + CALL_DEBUG_ENTER; + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = -1; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectDownEvent); +#endif // OHOS_BUILD_ENABLE_KEYBOARD +} + +/** + * @tc.name: InputManagerTest_SimulateKeyEvent_002 + * @tc.desc: Verify simulate the back key is pressed and lifted + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_002) +{ + CALL_DEBUG_ENTER; + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = 0; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_BACK); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_BACK); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectDownEvent); +#endif // OHOS_BUILD_ENABLE_KEYBOARD + + std::shared_ptr injectUpEvent = KeyEvent::Create(); + ASSERT_TRUE(injectUpEvent != nullptr); + KeyEvent::KeyItem kitUp; + kitUp.SetKeyCode(KeyEvent::KEYCODE_BACK); + kitUp.SetPressed(false); + kitUp.SetDownTime(downTime); + injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_BACK); + injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP); + injectUpEvent->RemoveReleasedKeyItems(kitUp); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectUpEvent); +#endif // OHOS_BUILD_ENABLE_KEYBOARD +} + +/** + * @tc.name: InputManagerTest_SimulateKeyEvent_003 + * @tc.desc: Verify simulate key exception event + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_003) +{ + CALL_DEBUG_ENTER; + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_UNKNOWN); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_UNKNOWN); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectDownEvent, TestScene::EXCEPTION_TEST); +#endif // OHOS_BUILD_ENABLE_KEYBOARD +} + +/** + * @tc.name: InputManagerTest_SimulateKeyEvent_004 + * @tc.desc: Verify simulate the fn key is long pressed and lifted + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_004) +{ + CALL_DEBUG_ENTER; + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_FN); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_FN); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectDownEvent); +#endif // OHOS_BUILD_ENABLE_KEYBOARD + + std::shared_ptr injectUpEvent = KeyEvent::Create(); + ASSERT_TRUE(injectUpEvent != nullptr); + downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitUp; + kitUp.SetKeyCode(KeyEvent::KEYCODE_FN); + kitUp.SetPressed(false); + kitUp.SetDownTime(downTime); + injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_FN); + injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP); + injectUpEvent->RemoveReleasedKeyItems(kitUp); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + TestSimulateInputEvent(injectUpEvent); +#endif // OHOS_BUILD_ENABLE_KEYBOARD +} + +/** + * @tc.name: InputManagerTest_ListenSimulateInputEvent + * @tc.desc: Verify the Listener for simulate input event + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, ListenSimulateInputEvent) +{ + class WindowEventConsumerTmp : public IInputEventConsumer { + public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override { }; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override + { + PointerEvent::PointerItem pointerItem; + int32_t pointId = pointerEvent->GetPointerId(); + if (!pointerEvent->GetPointerItem(pointId, pointerItem)) { + return; + } + pointerId = pointerItem.GetPointerId(); + x = pointerItem.GetDisplayX(); + y = pointerItem.GetDisplayY(); + pointerEvent->MarkProcessed(); + }; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override { }; + mutable int32_t pointerId { -1 }; + mutable int32_t x { -1 }; + mutable int32_t y { -1 }; + }; + + auto runner = AppExecFwk::EventRunner::Create(true); + ASSERT_TRUE(runner != nullptr); + auto eventHandler = std::make_shared(runner); + ASSERT_TRUE(eventHandler != nullptr); + uint64_t runnerThreadId = 0; + + auto fun = [&runnerThreadId]() { + runnerThreadId = GetThisThreadId(); + MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId); + ASSERT_TRUE(runnerThreadId != 0); + }; + eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + auto consumer = GetPtr(); + ASSERT_TRUE(consumer != nullptr); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler); + + auto pointerEvent = SetupPointerEvent001(); + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + EXPECT_EQ(consumer->pointerId, 0); + EXPECT_EQ(consumer->x, 50); + EXPECT_EQ(consumer->y, 50); +} + +/** + * @tc.name: InputManagerTest_PrintKeyInfo + * @tc.desc: Verify the Listener for key input event + * @tc.type: FUNC + * @tc.require: + */ +TEST_F(InputManagerTest, PrintKeyInfo) +{ + class PrintKeyInfoConsumer : public IInputEventConsumer { + public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override { + std::vector eventItems { keyEvent->GetKeyItems() }; + printf("KeyCode:%s,KeyAction:%s\n", + keyEvent->KeyCodeToString(keyEvent->GetKeyCode()), + keyEvent->ActionToString(keyEvent->GetKeyAction())); + keyEvent->MarkProcessed(); + }; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override { + pointerEvent->MarkProcessed(); + }; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override { + axisEvent->MarkProcessed(); + }; + }; + + auto runner = AppExecFwk::EventRunner::Create(true); + ASSERT_TRUE(runner != nullptr); + auto eventHandler = std::make_shared(runner); + ASSERT_TRUE(eventHandler != nullptr); + uint64_t runnerThreadId = 0; + + auto fun = [&runnerThreadId]() { + runnerThreadId = GetThisThreadId(); + MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId); + ASSERT_TRUE(runnerThreadId != 0); + }; + eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + auto consumer = GetPtr(); + ASSERT_TRUE(consumer != nullptr); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler); + + printf("请在30秒内按键盘任意键进行测试:\n"); + sleep(30); + printf("测试结束\n"); +} +} // namespace MMI +} // namespace OHOS + +int main(int argc, char *argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/input/ft_multimodalinput_mini.gni b/input/ft_multimodalinput_mini.gni index 2529d2566e84b4131893a432c564ea1c7f42382c..060a0c0c982aaac3ba38b8a62ad86a83341995cc 100644 --- a/input/ft_multimodalinput_mini.gni +++ b/input/ft_multimodalinput_mini.gni @@ -28,6 +28,7 @@ declare_args() { input_feature_input_device = false input_feature_input_cooperation = false input_touchpad_event = false + input_test_case = false if (defined(global_parts_info) && defined(global_parts_info.resourceschedule_resource_schedule_service)) { @@ -49,4 +50,5 @@ print("input_feature_joystick = ${input_feature_joystick}") print("input_feature_touchscreen = ${input_feature_touchscreen}") print("input_feature_input_device = ${input_feature_input_device}") print("input_feature_input_cooperation = ${input_feature_input_cooperation}") -print("input_touchpad_event = ${input_touchpad_event}") \ No newline at end of file +print("input_touchpad_event = ${input_touchpad_event}") +print("input_test_case = ${input_test_case}") \ No newline at end of file diff --git a/input/interfaces/native/innerkits/event/include/i_anr_observer.h b/input/interfaces/native/innerkits/event/include/i_anr_observer.h index 60e29ba228c5dc870384b06004f6740288bb7f50..a7c9d6f45263c80c375a01e8008949752c966a53 100644 --- a/input/interfaces/native/innerkits/event/include/i_anr_observer.h +++ b/input/interfaces/native/innerkits/event/include/i_anr_observer.h @@ -22,7 +22,7 @@ class IAnrObserver { public: IAnrObserver() = default; virtual ~IAnrObserver() = default; - virtual void OnAnr(int32_t pid) const; + virtual void OnAnr(int32_t pid) const = 0; }; } // namespace MMI } // namespace OHOS diff --git a/input/test/unittest/common/include/event_util_test.h b/input/test/unittest/common/include/event_util_test.h index 5e411a85d576cb12951e427c51e064cf87f43c73..b17cad15ac726f8b6a9348054899fe6d7e08016d 100644 --- a/input/test/unittest/common/include/event_util_test.h +++ b/input/test/unittest/common/include/event_util_test.h @@ -25,9 +25,11 @@ #include +#ifndef FT_DISBALE_MONITER #include "accesstoken_kit.h" #include "nativetoken_kit.h" #include "token_setproc.h" +#endif // FT_DISBALE_MONITER #include "input_manager.h" #include "singleton.h" @@ -35,6 +37,8 @@ namespace OHOS { namespace MMI { + +#ifndef FT_DISBALE_MONITER using namespace Security::AccessToken; using Security::AccessToken::AccessTokenID; namespace { @@ -72,6 +76,8 @@ HapInfoParams infoManagerTestInfoParms_ = { .appIDDesc = "InputManagerTest" }; } // namespace +#endif // FT_DISBALE_MONITER + enum class TestScene : int32_t { NORMAL_TEST = 0, EXCEPTION_TEST, @@ -159,6 +165,7 @@ void TestSimulateInputEvent(EventType& event, const TestScene& testScene = TestS EXPECT_TRUE((static_cast(testScene) ^ TestUtil->CompareDump(event))); } void DumpWindowData(const std::shared_ptr& pointerEvent); +#ifndef FT_DISBALE_MONITER class AccessMonitor { public: AccessMonitor() @@ -178,6 +185,7 @@ private: AccessTokenID currentId_ { 0 }; AccessTokenID monitorId_ { 0 }; }; +#endif // FT_DISBALE_MONITER } // namespace MMI } // namespace OHOS diff --git a/input/test/unittest/common/src/event_util_test.cpp b/input/test/unittest/common/src/event_util_test.cpp index b444714efca709775afe135de030e2c0bdcc4411..1a04f5e7f366d8d961ad5d6a2d76c4855339b16a 100644 --- a/input/test/unittest/common/src/event_util_test.cpp +++ b/input/test/unittest/common/src/event_util_test.cpp @@ -30,60 +30,74 @@ constexpr int32_t SEC_TO_NANOSEC = 1000000000; void InputEventConsumer::OnInputEvent(std::shared_ptr keyEvent) const { CALL_DEBUG_ENTER; + ASSERT_TRUE(keyEvent != nullptr); RECV_FLAG flag = TestUtil->GetRecvFlag(); if (flag == RECV_FLAG::RECV_FOCUS || flag == RECV_FLAG::RECV_MARK_CONSUMED) { - keyEvent->MarkProcessed(); - ASSERT_TRUE(keyEvent != nullptr); TestUtil->AddEventDump(TestUtil->DumpInputEvent(keyEvent)); } + keyEvent->MarkProcessed(); } void InputEventConsumer::OnInputEvent(std::shared_ptr pointerEvent) const { CALL_DEBUG_ENTER; RECV_FLAG flag = TestUtil->GetRecvFlag(); + ASSERT_TRUE(pointerEvent != nullptr); if (flag == RECV_FLAG::RECV_FOCUS || flag == RECV_FLAG::RECV_MARK_CONSUMED) { - pointerEvent->MarkProcessed(); - ASSERT_TRUE(pointerEvent != nullptr); auto pointerAction = pointerEvent->GetPointerAction(); if (pointerAction != PointerEvent::POINTER_ACTION_ENTER_WINDOW && pointerAction != PointerEvent::POINTER_ACTION_LEAVE_WINDOW) { TestUtil->AddEventDump(TestUtil->DumpInputEvent(pointerEvent)); } } + pointerEvent->MarkProcessed(); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const { CALL_DEBUG_ENTER; + ASSERT_TRUE(pointerEvent != nullptr); if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); - ASSERT_TRUE(pointerEvent != nullptr); TestUtil->AddEventDump(TestUtil->DumpInputEvent(pointerEvent)); lastPointerEventId_ = pointerEvent->GetId(); } + pointerEvent->MarkProcessed(); } void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { CALL_DEBUG_ENTER; + ASSERT_TRUE(keyEvent != nullptr); if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); - ASSERT_TRUE(keyEvent != nullptr); TestUtil->AddEventDump(TestUtil->DumpInputEvent(keyEvent)); } + keyEvent->MarkProcessed(); } void WindowEventConsumer::OnInputEvent(std::shared_ptr keyEvent) const { + ASSERT_TRUE(keyEvent != nullptr); threadId_ = GetThisThreadId(); MMI_HILOGD("Consumer callback keyEvent is threadId:%{public}" PRIu64, threadId_); + keyEvent->MarkProcessed(); +} + +void WindowEventConsumer::OnInputEvent(std::shared_ptr axisEvent) const +{ + ASSERT_TRUE(axisEvent != nullptr); + threadId_ = GetThisThreadId(); + MMI_HILOGD("Consumer callback axisEvent is threadId:%{public}" PRIu64, threadId_); + axisEvent->MarkProcessed(); } void WindowEventConsumer::OnInputEvent(std::shared_ptr pointerEvent) const { + ASSERT_TRUE(pointerEvent != nullptr); threadId_ = GetThisThreadId(); MMI_HILOGD("Consumer callback pointerEvent is threadId:%{public}" PRIu64, threadId_); + pointerEvent->MarkProcessed(); } uint64_t WindowEventConsumer::GetConsumerThreadId()