1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <limits> 18 #include <test_header.h> 19 20 #include "hgm_core.h" 21 #include "hgm_frame_rate_manager.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace { 29 constexpr int32_t waitTaskFinishNs = 100000; 30 } 31 class HgmPointerManagerTest : public testing::Test { 32 public: SetUpTestCase()33 static void SetUpTestCase() {} TearDownTestCase()34 static void TearDownTestCase() {} SetUp()35 void SetUp() {} TearDown()36 void TearDown() {} 37 HgmErrCode getPointerVoteInfo(VoteInfo& pointerVoteInfo); 38 }; 39 40 /** 41 * @tc.name: QuickClick 42 * @tc.desc: Verify the result of QuickClick function 43 * @tc.type: FUNC 44 * @tc.require: 45 */ 46 HWTEST_F(HgmPointerManagerTest, QuickClick, Function | SmallTest | Level1) 47 { 48 int32_t clickNum = 100; 49 auto pointerManager = HgmPointerManager(); 50 for (int i = 0; i < clickNum; i++) { 51 pointerManager.ChangeState(PointerState::POINTER_ACTIVE_STATE); 52 pointerManager.ChangeState(PointerState::POINTER_IDLE_STATE); 53 } 54 pointerManager.ChangeState(PointerState::POINTER_IDLE_STATE); 55 sleep(1); // wait for 1s for the async task to complete 56 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_IDLE_STATE); 57 } 58 59 /** 60 * @tc.name: ChangeState 61 * @tc.desc: Verify the result of ChangeState function 62 * @tc.type: FUNC 63 * @tc.require: 64 */ 65 HWTEST_F(HgmPointerManagerTest, ChangeState, Function | SmallTest | Level1) 66 { 67 PART("CaseDescription") { 68 auto pointerManager = HgmPointerManager(); 69 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_IDLE_STATE); 70 71 pointerManager.ChangeState(PointerState::POINTER_ACTIVE_STATE); 72 usleep(waitTaskFinishNs); 73 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 74 75 pointerManager.ChangeState(PointerState::POINTER_IDLE_STATE); 76 usleep(waitTaskFinishNs); 77 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_IDLE_STATE); 78 } 79 } 80 81 /** 82 * @tc.name: Active2IdleState 83 * @tc.desc: Verify the result of Active2IdleState function 84 * @tc.type: FUNC 85 * @tc.require: 86 */ 87 HWTEST_F(HgmPointerManagerTest, Active2IdleState, Function | SmallTest | Level1) 88 { 89 PART("CaseDescription") { 90 auto pointerManager = HgmPointerManager(); 91 const int32_t handleRsFrameUs = 1100000; 92 const int32_t handleRsFrameNum = 2; 93 const PointerState undefinedState = static_cast<PointerState>(100); 94 95 STEP("1. 3000ms timeout") { 96 pointerManager.ChangeState(PointerState::POINTER_ACTIVE_STATE); 97 usleep(waitTaskFinishNs); 98 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 99 100 for (int i = 0; i < handleRsFrameNum; i++) { 101 pointerManager.HandleRsFrame(); 102 usleep(handleRsFrameUs); 103 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 104 } 105 usleep(handleRsFrameUs); 106 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_IDLE_STATE); 107 } 108 STEP("State2String") { 109 pointerManager.State2String(undefinedState); 110 } 111 STEP("CheckChangeStateValid") { 112 pointerManager.CheckChangeStateValid(PointerState::POINTER_IDLE_STATE, undefinedState); 113 pointerManager.CheckChangeStateValid(undefinedState, PointerState::POINTER_IDLE_STATE); 114 } 115 STEP("ExecuteCallback") { 116 pointerManager.ExecuteCallback(nullptr); __anon772a53e60202() 117 pointerManager.ExecuteCallback([] () { usleep(1); }); 118 pointerManager.ExecuteCallback(nullptr); 119 } 120 } 121 } 122 123 /** 124 * @tc.name: HandleTimerResetEvent 125 * @tc.desc: Verify the result of HandleTimerResetEvent function 126 * @tc.type: FUNC 127 * @tc.require: 128 */ 129 HWTEST_F(HgmPointerManagerTest, HandleTimerResetEvent, Function | SmallTest | Level1) 130 { 131 PART("CaseDescription") { 132 auto pointerManager = HgmPointerManager(); 133 const int32_t activeTimeoutUs = 1300000; 134 const int32_t handleTimerResetTime = 1000000; 135 136 STEP("HandleMoveTimeOut") { 137 pointerManager.ChangeState(PointerState::POINTER_ACTIVE_STATE); 138 usleep(waitTaskFinishNs); 139 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 140 usleep(handleTimerResetTime - waitTaskFinishNs); 141 pointerManager.HandleTimerReset(); 142 usleep(handleTimerResetTime); 143 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 144 pointerManager.HandleTimerReset(); 145 usleep(handleTimerResetTime); 146 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_ACTIVE_STATE); 147 pointerManager.HandleTimerReset(); 148 usleep(activeTimeoutUs); 149 ASSERT_EQ(pointerManager.GetState(), PointerState::POINTER_IDLE_STATE); 150 } 151 } 152 } 153 } // namespace Rosen 154 } // namespace OHOS