diff --git a/bundle.json b/bundle.json index 0a5301a879b7025102b9f7d2d7ef870930c94ced..6fd61b755a4e16b7011b4d9e2281995f2e0ff4fc 100644 --- a/bundle.json +++ b/bundle.json @@ -51,7 +51,9 @@ "//base/powermgr/powermgr_lite:powermgr_lite" ], "inner_kits": [], - "test": [] + "test": [ + "//base/powermgr/powermgr_lite/test/Interface_test:unittest" + ] } } } diff --git a/test/Interface_test/BUILD.gn b/test/Interface_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d01522950db6e92a6a4b38bcb4f9b649d2b80b5f --- /dev/null +++ b/test/Interface_test/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/lite/config/component/lite_component.gni") +import("//build/lite/ndk/ndk.gni") + +group("unittest") { + deps = [ "./test/unittest:unittest" ] +} diff --git a/test/Interface_test/test/unittest/BUILD.gn b/test/Interface_test/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cd392cbeeaef099d60520cee66f8919311249440 --- /dev/null +++ b/test/Interface_test/test/unittest/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/powermgr/powermgr_lite/powermgr.gni") +import("//build/lite/config/test.gni") + +unittest("powermgr_lite_test_interface") { + output_extension = "bin" + output_dir = "$root_out_dir/test/unittest/powermgr_test_lite" + + sources = [ "src/powermgr_interfaces_test.cpp" ] + + include_dirs = [ + "${powermgr_kits_path}", + "${powermgr_innerkits_path}", + "${powermgr_frameworks_path}/include", + ] + deps = [ + "${powermgr_frameworks_path}:powermgr", + "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", + ] + external_deps = [ "hilog_lite:hilog_shared" ] +} + +group("unittest") { + deps = [ ":powermgr_lite_test_interface" ] +} diff --git a/test/Interface_test/test/unittest/src/powermgr_interfaces_test.cpp b/test/Interface_test/test/unittest/src/powermgr_interfaces_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..111518294e590b75c47c75a336753efa8968dc89 --- /dev/null +++ b/test/Interface_test/test/unittest/src/powermgr_interfaces_test.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "hilog/log.h" +#include "running_lock_framework.h" +#include "power_manage.h" +#include "power_screen_saver.h" + +#undef LOG_TAG +#define LOG_TAG "POWERMGR_LITE" + +using namespace std; +using namespace testing::ext; + +namespace OHOS { +class PowermgrInterfacesTest : public testing::Test { +protected: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} +}; + +/** + * @tc.name: PowermgrInterfacesTest001 + * @tc.desc: Test the interface Powermgr::CreateRunningLock(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest001, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest001 called"); + const char* name = "test_lock"; + RunningLockType type = RUNNINGLOCK_SCREEN; + RunningLockFlag flag = RUNNINGLOCK_FLAG_NONE; + const RunningLock* lock = CreateRunningLock(name, type, flag); + EXPECT_NE(lock, nullptr); +}; + +/** + * @tc.name: PowermgrInterfacesTest002 + * @tc.desc: Test the interface Powermgr::AcquireRunningLock(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest002, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest002 called"); + const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); + bool ret = AcquireRunningLock(lock); + EXPECT_TRUE(ret); +}; + +/** + * @tc.name: PowermgrInterfacesTest003 + * @tc.desc: Test the interface Powermgr::ReleaseRunningLock(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest003, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest003 called"); + const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); + bool ret = ReleaseRunningLock(lock); + EXPECT_TRUE(ret); +}; + +/** + * @tc.name: PowermgrInterfacesTest004 + * @tc.desc: Test the interface Powermgr::IsRunningLockHolding(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest004, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest004 called"); + const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); + bool ret = AcquireRunningLock(lock); + EXPECT_TRUE(ret); + EXPECT_TRUE(IsRunningLockHolding(lock)); +}; + +/** + * @tc.name: PowermgrInterfacesTest005 + * @tc.desc: Test the interface Powermgr::DestroyRunningLock(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest005, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest005 called"); + const RunningLock* lock = CreateRunningLock("test_lock", RUNNINGLOCK_SCREEN, RUNNINGLOCK_FLAG_NONE); + EXPECT_NE(lock, nullptr); + DestroyRunningLock(lock); + EXPECT_FALSE(IsRunningLockHolding(lock)); +}; + +/** + * @tc.name: PowermgrInterfacesTest006 + * @tc.desc: Test the interface Powermgr::SuspendDevice(). + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest006, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest006 called"); + BOOL suspendImmed = true; + SuspendDevice(SUSPEND_DEVICE_REASON_TIMEOUT, suspendImmed); + EXPECT_NE(suspendImmed, false); + const char* details = "power_key"; + WakeupDevice(WAKEUP_DEVICE_POWER_BUTTON, details); + EXPECT_NE(details, nullptr); +}; + +/** + * @tc.name: PowermgrInterfacesTest007 + * @tc.desc: Test the interface Battery::GetBatTechnology + * @tc.type: FUNC + */ +HWTEST_F(PowermgrInterfacesTest, PowermgrInterfacesTest007, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_APP, "PowermgrInterfacesTest007 called"); + EXPECT_EQ(SetScreenSaverState(true), true); +}; +}; \ No newline at end of file