1 /* 2 * Copyright (c) 2024 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 "power_ext_intf_wrapper_test.h" 17 #include "power_ext_intf_wrapper.h" 18 #include "power_log.h" 19 #ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES 20 #include "power_state_machine_info.h" 21 #endif 22 23 namespace OHOS { 24 namespace PowerMgr { 25 using namespace testing; 26 using namespace testing::ext; 27 28 /** 29 * @tc.name: GetRebootCommandTest 30 * @tc.desc: test GetRebootCommand 31 * @tc.type: FUNC 32 */ 33 HWTEST_F(PowerExtIntfWrapperTest, GetRebootCommandTest, TestSize.Level0) 34 { 35 POWER_HILOGI(LABEL_TEST, "GetRebootCommandTest function start!"); 36 std::string rebootReason = "reboot_by_test"; 37 std::string rebootCmd; 38 PowerExtIntfWrapper::ErrCode code = PowerExtIntfWrapper::Instance().GetRebootCommand(rebootReason, rebootCmd); 39 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 40 POWER_HILOGI(LABEL_TEST, "GetRebootCommandTest function end!"); 41 } 42 43 /** 44 * @tc.name: SubscribeScreenLockCommonEventTest 45 * @tc.desc: test SubscribeScreenLockCommonEvent/UnSubscribeScreenLockCommonEvent 46 * @tc.type: FUNC 47 */ 48 HWTEST_F(PowerExtIntfWrapperTest, SubscribeScreenLockCommonEventTest, TestSize.Level0) 49 { 50 POWER_HILOGI(LABEL_TEST, "SubscribeScreenLockCommonEventTest function start!"); 51 PowerExtIntfWrapper::ErrCode code = PowerExtIntfWrapper::Instance().SubscribeScreenLockCommonEvent(); 52 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 53 code = PowerExtIntfWrapper::Instance().UnSubscribeScreenLockCommonEvent(); 54 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 55 POWER_HILOGI(LABEL_TEST, "SubscribeScreenLockCommonEventTest function end!"); 56 } 57 58 /** 59 * @tc.name: BlockHibernateUntilScrLckReadyTest 60 * @tc.desc: test BlockHibernateUntilScrLckReady 61 * @tc.type: FUNC 62 */ 63 HWTEST_F(PowerExtIntfWrapperTest, BlockHibernateUntilScrLckReadyTest, TestSize.Level0) 64 { 65 POWER_HILOGI(LABEL_TEST, "BlockHibernateUntilScrLckReadyTest function start!"); 66 PowerExtIntfWrapper::ErrCode code = PowerExtIntfWrapper::Instance().SubscribeScreenLockCommonEvent(); 67 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 68 code = PowerExtIntfWrapper::Instance().BlockHibernateUntilScrLckReady(); 69 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 70 code = PowerExtIntfWrapper::Instance().UnSubscribeScreenLockCommonEvent(); 71 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || code == PowerExtIntfWrapper::ErrCode::ERR_OK); 72 POWER_HILOGI(LABEL_TEST, "BlockHibernateUntilScrLckReadyTest function end!"); 73 } 74 75 /** 76 * @tc.name: SetScreenOnEventRulesTest 77 * @tc.desc: test SetScreenOnEventRules 78 * @tc.type: FUNC 79 */ 80 #ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES 81 HWTEST_F(PowerExtIntfWrapperTest, SetScreenOnEventRulesTest, TestSize.Level1) 82 { 83 POWER_HILOGI(LABEL_TEST, "SetScreenOnEventRulesTest function start!"); 84 StateChangeReason reason = StateChangeReason::STATE_CHANGE_REASON_PICKUP; 85 std::vector<StateChangeReason> WATCH_CUSTOMIZED_STATE_CHANGE_REASONS {StateChangeReason::STATE_CHANGE_REASON_PICKUP, 86 StateChangeReason::STATE_CHANGE_REASON_INCOMING_CALL, 87 StateChangeReason::STATE_CHANGE_REASON_BLUETOOTH_INCOMING_CALL}; 88 std::vector<WakeupDeviceType> WATCH_CUSTOMIZED_WAKEUP_DEVICE_TYPES {WakeupDeviceType::WAKEUP_DEVICE_PICKUP, 89 WakeupDeviceType::WAKEUP_DEVICE_INCOMING_CALL, 90 WakeupDeviceType::WAKEUP_DEVICE_BLUETOOTH_INCOMING_CALL}; 91 PowerExtIntfWrapper::ErrCode code = PowerExtIntfWrapper::Instance().SetScreenOnEventRules( 92 reason, WATCH_CUSTOMIZED_STATE_CHANGE_REASONS, WATCH_CUSTOMIZED_WAKEUP_DEVICE_TYPES); 93 EXPECT_TRUE(code == PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND || 94 code == PowerExtIntfWrapper::ErrCode::ERR_OK); 95 POWER_HILOGI(LABEL_TEST, "SetScreenOnEventRulesTest function end!"); 96 } 97 #endif 98 } // PowerMgr 99 } // OHOS