From de5c37281525893b2657260e5345652b99e6474f Mon Sep 17 00:00:00 2001 From: lishengming14 Date: Tue, 24 Jun 2025 15:24:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=88=86=E6=94=AF=E6=97=8B=E8=BD=AC=E9=80=BB=E8=BE=91=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lishengming14 --- .../include/input_windows_manager.h | 2 +- .../test/input_windows_manager_ex_test.cpp | 177 ++++++++++++++++++ service/window_manager/test/mock.h | 12 ++ 3 files changed, 190 insertions(+), 1 deletion(-) diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index 8aaba17ee8..b72d9c4d8d 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -283,7 +283,7 @@ private: #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER std::vector HandleHardwareCursor(std::shared_ptr &physicalDisplayInfo, - int32_t physicalX, int32_t physicalY); + int32_t physicalX, int32_t physicalY); int32_t UpdateMouseTarget(std::shared_ptr pointerEvent); void UpdatePointerEvent(int32_t logicalX, int32_t logicalY, const std::shared_ptr& pointerEvent, const WindowInfo& touchWindow); diff --git a/service/window_manager/test/input_windows_manager_ex_test.cpp b/service/window_manager/test/input_windows_manager_ex_test.cpp index e2d90dbbb3..b3a7a0efbb 100644 --- a/service/window_manager/test/input_windows_manager_ex_test.cpp +++ b/service/window_manager/test/input_windows_manager_ex_test.cpp @@ -4340,5 +4340,182 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SkipPrivacyProtectionW isSkip = false; EXPECT_FALSE(inputWindowsManager->SkipPrivacyProtectionWindow(pointerEvent, isSkip)); } + +#ifdef OHOS_BUILD_ENABLE_POINTER +/** + * @tc.name: InputWindowsManagerTest_HandleHardWareCursorTest001 + * @tc.desc: Test the funcation HandleHardWareCursor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_HandleHardWareCursorTest001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr physicalDisplayInfo = std::make_shared(); + ASSERT_NE(physicalDisplayInfo, nullptr); + physicalDisplayInfo->direction = Direction::DIRECTION0; + physicalDisplayInfo->displayDirection = Direction::DIRECTION0; + physicalDisplayInfo->validWidth = 1024; + physicalDisplayInfo->validHeight = 768; + + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillOnce(Return(false)); + std::vector result = inputWindowsManager->HandleHardwareCursor(physicalDisplayInfo, 512, 384); + EXPECT_EQ(result[0], 512); + EXPECT_EQ(result[1], 384); +} + +/** + * @tc.name: InputWindowsManagerTest_HandleHardWareCursorTest002 + * @tc.desc: Test the funcation HandleHardWareCursor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_HandleHardWareCursorTest002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr physicalDisplayInfo = std::make_shared(); + ASSERT_NE(physicalDisplayInfo, nullptr); + physicalDisplayInfo->direction = Direction::DIRECTION90; + physicalDisplayInfo->displayDirection = Direction::DIRECTION0; + physicalDisplayInfo->validWidth = 1024; + physicalDisplayInfo->validHeight = 768; + + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + std::vector result = inputWindowsManager->HandleHardwareCursor(physicalDisplayInfo, 512, 384); +} + + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest015 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest015, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(true)); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest016 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest016, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(false)); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest017 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest017, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(true)); + EXPECT_CALL(*messageParcelMock_, HandleHardwareCursor(_, _, _)).WillOnce(Return(std::vector({ 1 }))); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +#endif /* OHOS_BUILD_ENABLE_POINTER */ + } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/test/mock.h b/service/window_manager/test/mock.h index a74054a843..02cc8ea3f3 100644 --- a/service/window_manager/test/mock.h +++ b/service/window_manager/test/mock.h @@ -54,6 +54,12 @@ public: virtual bool IsWindowRotation() = 0; virtual int32_t GetDisplayId() = 0; virtual std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) = 0; + virtual std::optional SelectWindowInfo(int32_t logicalX, int32_t logicalY, + const std::shared_ptr& pointerEvent) = 0; + virtual bool UpdateDisplayId(int32_t& displayId) = 0; + virtual bool GetHardCursorEnabled() = 0; + virtual std::vector HandleHardwareCursor(std::shared_ptr &physicalDisplayInfo, + int32_t physicalX, int32_t physicalY) = 0; public: static inline std::shared_ptr messageParcel = nullptr; }; @@ -71,6 +77,12 @@ public: MOCK_METHOD0(IsSceneBoardEnabled, bool()); MOCK_METHOD0(IsWindowRotation, bool()); MOCK_METHOD0(GetDisplayId, int32_t()); + MOCK_METHOD3(SelectWindowInfo, std::optional(int32_t logicalX, int32_t logicalY, + const std::shared_ptr& pointerEvent)); + MOCK_METHOD1(UpdateDisplayId, bool(int32_t& displayId)); + MOCK_METHOD0(GetHardCursorEnabled, bool()); + MOCK_METHOD3(HandleHardwareCursor, std::vector(std::shared_ptr &physicalDisplayInfo, + int32_t physicalX, int32_t physicalY)); }; } // namespace MMI } // namespace OHOS -- Gitee