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 ConstraintManagerAdapterTest : 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 ConstraintManagerAdapterTest::TearDownTestCase() {}
35 
SetUpTestCase()36 void ConstraintManagerAdapterTest::SetUpTestCase() {}
37 
SetUp()38 void ConstraintManagerAdapterTest::SetUp()
39 {
40     StandbyServiceImpl::GetInstance()->standbyStateManager_ = std::make_shared<StateManagerAdapter>();
41 }
42 
43 /**
44  * @tc.name: Init
45  * @tc.desc: test Init.
46  * @tc.type: FUNC
47  * @tc.require:
48  */
49 HWTEST_F(ConstraintManagerAdapterTest, Init, TestSize.Level1)
50 {
51     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
52     bool ret = constraintManagerAdapter->Init();
53     EXPECT_EQ(ret, true);
54 }
55 
56 /**
57  * @tc.name: UnInit
58  * @tc.desc: test UnInit.
59  * @tc.type: FUNC
60  * @tc.require:
61  */
62 HWTEST_F(ConstraintManagerAdapterTest, UnInit, TestSize.Level1)
63 {
64     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
65     bool ret = constraintManagerAdapter->UnInit();
66     EXPECT_EQ(ret, true);
67 }
68 
69 /**
70  * @tc.name: StartEvalution
71  * @tc.desc: test StartEvalution.
72  * @tc.type: FUNC
73  * @tc.require:
74  */
75 HWTEST_F(ConstraintManagerAdapterTest, StartEvalution001, TestSize.Level1)
76 {
77     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
78     ConstraintEvalParam params;
79     constraintManagerAdapter->isEvaluation_ = true;
80     constraintManagerAdapter->StartEvalution(params);
81 }
82 
83 /**
84  * @tc.name: StartEvalution
85  * @tc.desc: test StartEvalution.
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(ConstraintManagerAdapterTest, StartEvalution002, TestSize.Level1)
90 {
91     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
92     ConstraintEvalParam params;
93     constraintManagerAdapter->isEvaluation_ = false;
94     constraintManagerAdapter->constraintMap_.clear();
95     std::shared_ptr<StateManagerAdapter> stateManagerAdapter = std::make_shared<StateManagerAdapter>();
96     stateManagerAdapter->isEvalution_ = false;
97     constraintManagerAdapter->stateManager_ = stateManagerAdapter;
98     constraintManagerAdapter->StartEvalution(params);
99 }
100 
101 /**
102  * @tc.name: StartEvalution
103  * @tc.desc: test StartEvalution.
104  * @tc.type: FUNC
105  * @tc.require:
106  */
107 HWTEST_F(ConstraintManagerAdapterTest, StartEvalution003, TestSize.Level1)
108 {
109     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
110     ConstraintEvalParam params;
111     constraintManagerAdapter->isEvaluation_ = false;
112     std::shared_ptr<ChargeStateMonitor> monitor = nullptr;
113     constraintManagerAdapter->RegisterConstraintCallback(params, monitor);
114     constraintManagerAdapter->StartEvalution(params);
115 }
116 
117 /**
118  * @tc.name: StartEvalution
119  * @tc.desc: test StartEvalution.
120  * @tc.type: FUNC
121  * @tc.require:
122  */
123 HWTEST_F(ConstraintManagerAdapterTest, StartEvalution004, TestSize.Level1)
124 {
125     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
126     ConstraintEvalParam params;
127     constraintManagerAdapter->isEvaluation_ = false;
128     std::shared_ptr<ChargeStateMonitor> monitor = std::make_shared<ChargeStateMonitor>();
129     constraintManagerAdapter->RegisterConstraintCallback(params, monitor);
130     constraintManagerAdapter->StartEvalution(params);
131 }
132 
133 /**
134  * @tc.name: StopEvalution
135  * @tc.desc: test StopEvalution.
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(ConstraintManagerAdapterTest, StopEvalution001, TestSize.Level1)
140 {
141     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
142     constraintManagerAdapter->isEvaluation_ = false;
143     constraintManagerAdapter->StopEvalution();
144 }
145 
146 /**
147  * @tc.name: StopEvalution
148  * @tc.desc: test StopEvalution.
149  * @tc.type: FUNC
150  * @tc.require:
151  */
152 HWTEST_F(ConstraintManagerAdapterTest, StopEvalution002, TestSize.Level1)
153 {
154     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
155     constraintManagerAdapter->isEvaluation_ = true;
156     constraintManagerAdapter->curMonitor_ = nullptr;
157     constraintManagerAdapter->StopEvalution();
158 }
159 
160 /**
161  * @tc.name: StopEvalution
162  * @tc.desc: test StopEvalution.
163  * @tc.type: FUNC
164  * @tc.require:
165  */
166 HWTEST_F(ConstraintManagerAdapterTest, StopEvalution003, TestSize.Level1)
167 {
168     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
169     constraintManagerAdapter->isEvaluation_ = true;
170     constraintManagerAdapter->curMonitor_ = std::make_shared<ChargeStateMonitor>();
171     constraintManagerAdapter->StopEvalution();
172 }
173 
174 /**
175  * @tc.name: RegisterConstraintCallback
176  * @tc.desc: test RegisterConstraintCallback.
177  * @tc.type: FUNC
178  * @tc.require:
179  */
180 HWTEST_F(ConstraintManagerAdapterTest, RegisterConstraintCallback, TestSize.Level1)
181 {
182     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
183     ConstraintEvalParam params;
184     std::shared_ptr<ChargeStateMonitor> monitor = nullptr;
185     constraintManagerAdapter->RegisterConstraintCallback(params, monitor);
186 }
187 
188 /**
189  * @tc.name: ShellDump
190  * @tc.desc: test StopMonitoring.
191  * @tc.type: FUNC
192  * @tc.require:
193  */
194 HWTEST_F(ConstraintManagerAdapterTest, ShellDump, TestSize.Level1)
195 {
196     std::shared_ptr<ConstraintManagerAdapter> constraintManagerAdapter = std::make_shared<ConstraintManagerAdapter>();
197     std::vector<std::string> argsInStr;
198     string result;
199     constraintManagerAdapter->ShellDump(argsInStr, result);
200 }
201 }  // namespace DevStandbyMgr
202 }  // namespace OHOS
203