From 2cf74149a6388812986951a13f61a5bf4396f4a3 Mon Sep 17 00:00:00 2001 From: volcano6322 Date: Thu, 22 Feb 2024 15:46:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20power=5Flite=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: volcano6322 --- test/Interface_test/BUILD.gn | 19 +++ test/Interface_test/test/unittest/BUILD.gn | 39 ++++++ .../unittest/src/powermgr_interfaces_test.cpp | 130 ++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 test/Interface_test/BUILD.gn create mode 100644 test/Interface_test/test/unittest/BUILD.gn create mode 100644 test/Interface_test/test/unittest/src/powermgr_interfaces_test.cpp diff --git a/test/Interface_test/BUILD.gn b/test/Interface_test/BUILD.gn new file mode 100644 index 0000000..ae5ccde --- /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 0000000..6805f8c --- /dev/null +++ b/test/Interface_test/test/unittest/BUILD.gn @@ -0,0 +1,39 @@ +# 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/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 = [ + "//base/hiviewdfx/hilog_lite/interfaces/native/kits", + "//third_party/bounds_checking_function/include", + "//base/powermgr/powermgr_lite/interfaces/kits", + "//base/powermgr/powermgr_lite/interfaces/innerkits", + "//base/powermgr/powermgr_lite/frameworks/include", + ] + deps = [ + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/powermgr/powermgr_lite/frameworks:powermgr", + "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", + ] +} + +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 0000000..df305a9 --- /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, NULL); +}; + +/** + * @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 -- Gitee