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 "gtest/gtest.h"
17 #include "charge_state_monitor.h"
18 #include "constraint_manager_adapter.h"
19 #include "state_manager_adapter.h"
20 #include "standby_service_impl.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DevStandbyMgr {
26 class ChargeStateMonitorTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
TearDown()31 void TearDown() override {}
32 };
33
TearDownTestCase()34 void ChargeStateMonitorTest::TearDownTestCase() {}
35
SetUpTestCase()36 void ChargeStateMonitorTest::SetUpTestCase() {}
37
SetUp()38 void ChargeStateMonitorTest::SetUp()
39 {
40 StandbyServiceImpl::GetInstance()->constraintManager_ = std::make_shared<ConstraintManagerAdapter>();
41 StandbyServiceImpl::GetInstance()->standbyStateManager_ = std::make_shared<StateManagerAdapter>();
42 }
43
44 /**
45 * @tc.name: Init
46 * @tc.desc: test Init.
47 * @tc.type: FUNC
48 * @tc.require:
49 */
50 HWTEST_F(ChargeStateMonitorTest, Init, TestSize.Level1)
51 {
52 std::shared_ptr<IConstraintMonitor> chargeMonitor = std::make_shared<ChargeStateMonitor>();
53 bool ret = chargeMonitor->Init();
54 EXPECT_EQ(ret, true);
55 }
56
57 /**
58 * @tc.name: StartMonitoring
59 * @tc.desc: test StartMonitoring.
60 * @tc.type: FUNC
61 * @tc.require:
62 */
63 HWTEST_F(ChargeStateMonitorTest, StartMonitoring, TestSize.Level1)
64 {
65 std::shared_ptr<IConstraintMonitor> chargeMonitor = std::make_shared<ChargeStateMonitor>();
66 chargeMonitor->StartMonitoring();
67 }
68
69 /**
70 * @tc.name: StopMonitoring
71 * @tc.desc: test StopMonitoring.
72 * @tc.type: FUNC
73 * @tc.require:
74 */
75 HWTEST_F(ChargeStateMonitorTest, StopMonitoring, TestSize.Level1)
76 {
77 std::shared_ptr<IConstraintMonitor> chargeMonitor = std::make_shared<ChargeStateMonitor>();
78 chargeMonitor->StopMonitoring();
79 }
80 } // namespace DevStandbyMgr
81 } // namespace OHOS
82