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 #include "power_wakeup_controller_oninput_test.h"
16 #ifdef HAS_MULTIMODALINPUT_INPUT_PART
17 #include <input_manager.h>
18 #endif
19 #include "power_mgr_service.h"
20 #include "power_state_machine.h"
21 #include "wakeup_controller.h"
22
23 using namespace testing::ext;
24 using namespace OHOS::MMI;
25 using namespace OHOS::PowerMgr;
26 using namespace OHOS;
27 using namespace std;
28 static sptr<PowerMgrService> g_service;
29 static constexpr int32_t DISPLAY_POWER_MANAGER_ID = 3308;
30 static const std::string TEST_DEVICE_ID = "test_device_id";
31
SetUpTestCase(void)32 void PowerWakeupControllerOninputTest::SetUpTestCase(void)
33 {
34 g_service = DelayedSpSingleton<PowerMgrService>::GetInstance();
35 g_service->OnStart();
36 g_service->OnAddSystemAbility(DISPLAY_POWER_MANAGER_ID, TEST_DEVICE_ID);
37 }
38
TearDownTestCase(void)39 void PowerWakeupControllerOninputTest::TearDownTestCase(void)
40 {
41 g_service->OnStop();
42 DelayedSpSingleton<PowerMgrService>::DestroyInstance();
43 }
44
45 #ifdef HAS_MULTIMODALINPUT_INPUT_PART
GetInstance()46 MMI::InputManager *InputManager::GetInstance()
47 {
48 return nullptr;
49 }
50 #endif
51
52 namespace {
53 /**
54 * @tc.name: PowerWakeupControllerOninputTest001
55 * @tc.desc: test RegisterMonitor(exception)
56 * @tc.type: FUNC
57 * @tc.require: issueI7COGR
58 */
59 #ifdef HAS_MULTIMODALINPUT_INPUT_PART
60 HWTEST_F(PowerWakeupControllerOninputTest, PowerWakeupControllerOninputTest001, TestSize.Level0)
61 {
62 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerOninputTest001: start");
63 GTEST_LOG_(INFO) << "PowerWakeupControllerOninputTest001: start";
64 auto powerStateMachine = g_service->GetPowerStateMachine();
65 g_service->WakeupControllerInit();
66 auto wakeupController_ = g_service->GetWakeupController();
67 g_service->SwitchSubscriberInit();
68 g_service->InputMonitorInit();
69
70 wakeupController_->RegisterMonitor(PowerState::AWAKE);
71 EXPECT_TRUE(wakeupController_->monitorId_ != 0);
72 wakeupController_->RegisterMonitor(PowerState::INACTIVE);
73 EXPECT_TRUE(wakeupController_->monitorId_ != 0);
74 wakeupController_->RegisterMonitor(PowerState::UNKNOWN);
75 EXPECT_TRUE(wakeupController_->monitorId_ != 0);
76 powerStateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_APPLICATION);
77 wakeupController_->RegisterMonitor(PowerState::AWAKE);
78 EXPECT_TRUE(wakeupController_->monitorId_ != 0);
79 powerStateMachine->SetState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_APPLICATION);
80 wakeupController_->RegisterMonitor(PowerState::INACTIVE);
81 EXPECT_TRUE(wakeupController_->monitorId_ != 0);
82
83 g_service->InputMonitorCancel();
84 g_service->SwitchSubscriberCancel();
85 GTEST_LOG_(INFO) << "PowerWakeupControllerOninputTest001: end";
86 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerOninputTest001: end");
87 }
88 #endif
89 } // namespace