diff --git a/frameworks/proxy/events/test/input_manager_test.cpp b/frameworks/proxy/events/test/input_manager_test.cpp index 2c42eb98de2e56961963a2048e33df5c019ff892..89e4c668234ef55a7f1037cda562c1f1717f2d84 100755 --- a/frameworks/proxy/events/test/input_manager_test.cpp +++ b/frameworks/proxy/events/test/input_manager_test.cpp @@ -56,6 +56,9 @@ public: void TestMarkConsumedStep4(); void TestMarkConsumedStep5(); void TestMarkConsumedStep6(); + int32_t TestAddMonitor(std::shared_ptr consumer); + void TestRemoveMonitor(int32_t monitorId); + void TestMarkConsumed(int32_t monitorId, int32_t eventId); }; void InputManagerTest::SetUpTestCase() @@ -162,10 +165,10 @@ std::shared_ptr InputManagerTest::SetupPointerEvent005() pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT); - pointerEvent->SetPointerId(1); + pointerEvent->SetPointerId(0); pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT); PointerEvent::PointerItem item; - item.SetPointerId(1); + item.SetPointerId(0); item.SetDownTime(downTime); item.SetPressed(true); @@ -188,9 +191,9 @@ std::shared_ptr InputManagerTest::SetupPointerEvent006() CHKPP(pointerEvent); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - pointerEvent->SetPointerId(1); + pointerEvent->SetPointerId(0); PointerEvent::PointerItem item; - item.SetPointerId(1); + item.SetPointerId(0); item.SetDownTime(0); item.SetPressed(false); @@ -215,10 +218,10 @@ std::shared_ptr InputManagerTest::SetupPointerEvent007() pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT); - pointerEvent->SetPointerId(1); + pointerEvent->SetPointerId(0); pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT); PointerEvent::PointerItem item; - item.SetPointerId(1); + item.SetPointerId(0); item.SetDownTime(downTime); item.SetPressed(false); @@ -466,7 +469,7 @@ void InputManagerTest::TestMarkConsumedStep3(int32_t monitorId, int32_t eventId) { std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestUtil->SetRecvFlag(RECV_FLAG::RECV_MARK_CONSUMED); - InputManager::GetInstance()->MarkConsumed(monitorId, eventId); + TestMarkConsumed(monitorId, eventId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -535,6 +538,23 @@ void InputManagerTest::TestMarkConsumedStep6() std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } +int32_t InputManagerTest::TestAddMonitor(std::shared_ptr consumer) +{ + AccessMonitor monitor; + return InputManager::GetInstance()->AddMonitor(consumer); +} + +void InputManagerTest::TestRemoveMonitor(int32_t monitorId) +{ + AccessMonitor monitor; + InputManager::GetInstance()->RemoveMonitor(monitorId); +} + +void InputManagerTest::TestMarkConsumed(int32_t monitorId, int32_t eventId) +{ + AccessMonitor monitor; + InputManager::GetInstance()->MarkConsumed(monitorId, eventId); +} /** * @tc.name: MultimodalEventHandler_SimulateKeyEvent_001 * @tc.desc: Verify simulate the back key is long pressed and lifted @@ -1399,20 +1419,19 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_007, TestSize.Level1) HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_001, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = SetupPointerEvent001(); ASSERT_TRUE(pointerEvent != nullptr); auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1426,7 +1445,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_001, TestSize.Lev HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids(N_TEST_CASES); std::vector> cbs(N_TEST_CASES); @@ -1434,7 +1452,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Lev for (std::vector::size_type i = 0; i < N_TEST_CASES; i++) { cbs[i] = GetPtr(); ASSERT_TRUE(cbs[i] != nullptr); - ids[i] = InputManager::GetInstance()->AddMonitor(cbs[i]); + ids[i] = TestAddMonitor(cbs[i]); EXPECT_TRUE(IsValidHandlerId(ids[i])); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1447,7 +1465,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Lev MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); ASSERT_TRUE(!sPointerEs.empty()); if (IsValidHandlerId(id)) { - InputManager::GetInstance()->RemoveMonitor(id); + TestRemoveMonitor(id); } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1462,20 +1480,19 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Lev HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_003, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = SetupPointerEvent003(); ASSERT_TRUE(pointerEvent != nullptr); auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1489,10 +1506,9 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_003, TestSize.Lev HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -1505,7 +1521,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Lev TestMarkConsumedStep5(); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1519,10 +1535,9 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Lev HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -1534,7 +1549,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Lev TestMarkConsumedStep6(); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1548,7 +1563,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Lev HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1566,14 +1580,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.L int32_t monitorId { }; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1587,7 +1601,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.L HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1605,14 +1618,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.L int32_t monitorId { }; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1626,7 +1639,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.L HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1644,14 +1656,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.L int32_t monitorId { }; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1665,7 +1677,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.L HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1685,7 +1696,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.L auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); for (std::vector::size_type i = 0; i < N_TEST_CASES; ++i) { - ids[i] = InputManager::GetInstance()->AddMonitor(callBackPtr); + ids[i] = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(ids[i])); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1697,7 +1708,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.L MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); ASSERT_TRUE(!sPointerEs.empty()); if (IsValidHandlerId(id)) { - InputManager::GetInstance()->RemoveMonitor(id); + TestRemoveMonitor(id); } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1712,7 +1723,6 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.L HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_005, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1730,14 +1740,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_005, TestSize.L int32_t monitorId { }; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1921,10 +1931,9 @@ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_004, TestSize HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -1932,7 +1941,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1 TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -1946,10 +1955,9 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -1957,7 +1965,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1 TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1974,10 +1982,9 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - int32_t monitorId = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t monitorId = TestAddMonitor(callBackPtr); EXPECT_TRUE(IsValidHandlerId(monitorId)); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -1986,7 +1993,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1 TestSimulateInputEvent(pointerEvent); if (IsValidHandlerId(monitorId)) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + TestRemoveMonitor(monitorId); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -2000,15 +2007,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; const std::vector::size_type N_TEST_CASES { MAX_N_INPUT_HANDLERS - 1 }; std::vector ids; int32_t maxMonitor = 0; for (std::vector::size_type i = 0; i < N_TEST_CASES; ++i) { - auto callBackPtr = GetPtr(); + auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); - maxMonitor = InputManager::GetInstance()->AddMonitor(callBackPtr); + maxMonitor = TestAddMonitor(callBackPtr); if (IsValidHandlerId(maxMonitor)) { ids.push_back(maxMonitor); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -2024,7 +2030,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1 maxMonitor++; } if (IsValidHandlerId(id)) { - InputManager::GetInstance()->RemoveMonitor(id); + TestRemoveMonitor(id); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } } @@ -2040,13 +2046,12 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1 HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids; auto callBackPtr = GetPtr(); ASSERT_TRUE(callBackPtr != nullptr); for (std::vector::size_type i = 0; i < N_TEST_CASES; ++i) { - int32_t id = InputManager::GetInstance()->AddMonitor(callBackPtr); + int32_t id = TestAddMonitor(callBackPtr); if (IsValidHandlerId(id)) { ids.push_back(id); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); @@ -2064,7 +2069,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.L MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); ASSERT_TRUE(!sPointerEs.empty()); if (IsValidHandlerId(id)) { - InputManager::GetInstance()->RemoveMonitor(id); + TestRemoveMonitor(id); } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -2079,7 +2084,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.L HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_002, TestSize.Level1) { CALL_DEBUG_ENTER; - VerifyMonitor monitor; + AccessMonitor monitor; const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids; auto callBackPtr = GetPtr(); diff --git a/test/unittest/common/include/event_util_test.h b/test/unittest/common/include/event_util_test.h index 384f953121d99212f4eb0e814d847b24b1f4cef0..8d6fd725b1dd4a847ead467b1a6f05b34ec45f27 100755 --- a/test/unittest/common/include/event_util_test.h +++ b/test/unittest/common/include/event_util_test.h @@ -136,21 +136,24 @@ void TestSimulateInputEvent(EventType& event, const TestScene& testScene = TestS EXPECT_TRUE((static_cast(testScene) ^ TestUtil->CompareDump(event))); } -class VerifyMonitor { +class AccessMonitor { public: - VerifyMonitor() + AccessMonitor() { + currentID_ = GetSelfTokenID(); AccessTokenIDEx tokenIdEx = { 0 }; tokenIdEx = AccessTokenKit::AllocHapToken(infoManagerTestInfoParms_, infoManagerTestPolicyPrams_); - tokenID_ = tokenIdEx.tokenIdExStruct.tokenID; - SetSelfTokenID(tokenID_); + monitorID_ = tokenIdEx.tokenIdExStruct.tokenID; + SetSelfTokenID(monitorID_); } - ~VerifyMonitor() + ~AccessMonitor() { - AccessTokenKit::DeleteToken(tokenID_); + AccessTokenKit::DeleteToken(monitorID_); + SetSelfTokenID(currentID_); } private: - AccessTokenID tokenID_ = 0; + AccessTokenID currentID_ = 0; + AccessTokenID monitorID_ = 0; }; } // namespace MMI } // namespace OHOS