1 /*
2 * Copyright (c) 2022 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 "power_mgr_client_adapter_impl.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21 using namespace OHOS;
22 using namespace OHOS::PowerMgr;
23 using namespace OHOS::NWeb;
24
25 namespace OHOS::NWeb {
26 class PowerMgrClientAdapterImplTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase(void)34 void PowerMgrClientAdapterImplTest::SetUpTestCase(void)
35 {}
36
TearDownTestCase(void)37 void PowerMgrClientAdapterImplTest::TearDownTestCase(void)
38 {}
39
SetUp(void)40 void PowerMgrClientAdapterImplTest::SetUp(void)
41 {}
42
TearDown(void)43 void PowerMgrClientAdapterImplTest::TearDown(void)
44 {}
45
46 /**
47 * @tc.name: PowerMgrClientAdapterImplTest_001.
48 * @tc.desc: test lock type.
49 * @tc.type: FUNC
50 * @tc.require:
51 */
52 HWTEST_F(PowerMgrClientAdapterImplTest, PowerMgrClientAdapterImplTest_001, TestSize.Level1)
53 {
54 std::unique_ptr<PowerMgrClientAdapterImpl> powerMgrImpl = std::make_unique<PowerMgrClientAdapterImpl>();
55 EXPECT_NE(powerMgrImpl, nullptr);
56 std::shared_ptr<RunningLockAdapter> runLockAdapter = powerMgrImpl->CreateRunningLock("screen",
57 RunningLockAdapterType::SCREEN);
58 EXPECT_NE(runLockAdapter, nullptr);
59 EXPECT_FALSE(runLockAdapter->IsUsed());
60 EXPECT_NE(runLockAdapter->Lock(1), -1);
61 EXPECT_NE(runLockAdapter->UnLock(), -1);
62 runLockAdapter = powerMgrImpl->CreateRunningLock("backgroud", RunningLockAdapterType::BACKGROUND);
63 EXPECT_NE(runLockAdapter, nullptr);
64 runLockAdapter = powerMgrImpl->CreateRunningLock("proximity_screen_control",
65 RunningLockAdapterType::PROXIMITY_SCREEN_CONTROL);
66 EXPECT_NE(runLockAdapter, nullptr);
67 runLockAdapter = powerMgrImpl->CreateRunningLock("butt", RunningLockAdapterType::BUTT);
68 EXPECT_NE(runLockAdapter, nullptr);
69 }
70
71 /**
72 * @tc.name: PowerMgrClientAdapterImplTest_002.
73 * @tc.desc: test running lock, exception cases.
74 * @tc.type: FUNC
75 * @tc.require:
76 */
77 HWTEST_F(PowerMgrClientAdapterImplTest, PowerMgrClientAdapterImplTest_002, TestSize.Level1)
78 {
79 std::shared_ptr<RunningLockAdapter> runLockAdapter = std::make_shared<RunningLockAdapterImpl>(nullptr);
80 EXPECT_NE(runLockAdapter, nullptr);
81 EXPECT_FALSE(runLockAdapter->IsUsed());
82 EXPECT_EQ(runLockAdapter->Lock(1), -1);
83 EXPECT_EQ(runLockAdapter->UnLock(), -1);
84 }
85 }