1 /* 2 * Copyright (c) 2023 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 "hilog/log.h" 18 #include "running_lock_framework.h" 19 #include "power_manage.h" 20 #include "power_screen_saver.h" 21 22 #undef LOG_TAG 23 #define LOG_TAG "POWERMGR_LITE" 24 25 using namespace std; 26 using namespace testing::ext; 27 28 namespace OHOS { 29 class PowermgrInterfacesTest : public testing::Test { 30 protected: SetUpTestCase(void)31 static void SetUpTestCase(void) {} TearDownTestCase(void)32 static void TearDownTestCase(void) {} 33 }; 34 35 /** 36 * @tc.name: PowermgrInterfacesTest001 37 * @tc.desc: Test the interface Powermgr::CreateRunningLock(). 38 * @tc.type: FUNC 39 */ 40 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest001, TestSize.Level0) 41 { 42 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest001 called"); 43 const char* name = "test_lock"; 44 RunningLockType type = RUNNINGLOCK_SCREEN; 45 RunningLockFlag flag = RUNNINGLOCK_FLAG_NONE; 46 const RunningLock* lock = CreateRunningLock(name, type, flag); 47 EXPECT_NE(lock, nullptr); 48 }; 49 50 /** 51 * @tc.name: PowermgrInterfacesTest002 52 * @tc.desc: Test the interface Powermgr::AcquireRunningLock(). 53 * @tc.type: FUNC 54 */ 55 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest002, TestSize.Level0) 56 { 57 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest002 called"); 58 const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); 59 bool ret = AcquireRunningLock(lock); 60 EXPECT_TRUE(ret); 61 }; 62 63 /** 64 * @tc.name: PowermgrInterfacesTest003 65 * @tc.desc: Test the interface Powermgr::ReleaseRunningLock(). 66 * @tc.type: FUNC 67 */ 68 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest003, TestSize.Level0) 69 { 70 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest003 called"); 71 const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); 72 bool ret = ReleaseRunningLock(lock); 73 EXPECT_TRUE(ret); 74 }; 75 76 /** 77 * @tc.name: PowermgrInterfacesTest004 78 * @tc.desc: Test the interface Powermgr::IsRunningLockHolding(). 79 * @tc.type: FUNC 80 */ 81 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest004, TestSize.Level0) 82 { 83 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest004 called"); 84 const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); 85 bool ret = AcquireRunningLock(lock); 86 EXPECT_TRUE(ret); 87 EXPECT_TRUE(IsRunningLockHolding(lock)); 88 }; 89 90 /** 91 * @tc.name: PowermgrInterfacesTest005 92 * @tc.desc: Test the interface Powermgr::DestroyRunningLock(). 93 * @tc.type: FUNC 94 */ 95 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest005, TestSize.Level0) 96 { 97 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest005 called"); 98 const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); 99 EXPECT_NE(lock, nullptr); 100 DestroyRunningLock(lock); 101 EXPECT_FALSE(IsRunningLockHolding(lock)); 102 }; 103 104 /** 105 * @tc.name: PowermgrInterfacesTest006 106 * @tc.desc: Test the interface Powermgr::SuspendDevice(). 107 * @tc.type: FUNC 108 */ 109 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest006, TestSize.Level0) 110 { 111 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest006 called"); 112 BOOL suspendImmed = true; 113 SuspendDevice(SUSPEND_DEVICE_REASON_TIMEOUT, suspendImmed); 114 EXPECT_NE(suspendImmed, false); 115 const char* details = "power_key"; 116 WakeupDevice(WAKEUP_DEVICE_POWER_BUTTON, details); 117 EXPECT_NE(details, nullptr); 118 }; 119 120 /** 121 * @tc.name: PowermgrInterfacesTest007 122 * @tc.desc: Test the interface Battery::GetBatTechnology 123 * @tc.type: FUNC 124 */ 125 HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest007, TestSize.Level0) 126 { 127 HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest007 called"); 128 EXPECT_EQ(SetScreenSaverState(true), true); 129 }; 130 };