1 /*
2 * Copyright (c) 2023-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 <algorithm>
17 #include <cmath>
18 #include <cstdio>
19 #include <gtest/gtest.h>
20 #include <fcntl.h>
21 #include <functional>
22 #include <securec.h>
23 #include <unistd.h>
24
25 #include <fstream>
26 #include "v2_0/battery_interface_proxy.h"
27 #include "v2_0/ibattery_callback.h"
28 #include "v2_0/types.h"
29
30 using namespace OHOS::HDI::Battery;
31 using namespace OHOS::HDI::Battery::V2_0;
32 using namespace testing::ext;
33 using namespace OHOS;
34
35 namespace {
36 class BatteryCallback : public HDI::Battery::V2_0::IBatteryCallback {
37 public:
BatteryCallback()38 BatteryCallback(){};
39 ~BatteryCallback() override{};
40 int32_t Update(const HDI::Battery::V2_0::BatteryInfo &event) override
41 {
42 (void)event;
43 return 0;
44 };
45 };
46
47 sptr<IBatteryInterface> g_batteryInterface = nullptr;
48 sptr<IBatteryCallback> g_callback = new BatteryCallback();
49 } // namespace
50
51 class HdfBatteryHdiTestAdditional : public testing::Test {
52 public:
53 static void SetUpTestCase();
54 static void TearDownTestCase();
55 void SetUp();
56 void TearDown();
57 };
58
SetUpTestCase(void)59 void HdfBatteryHdiTestAdditional::SetUpTestCase(void) { g_batteryInterface = IBatteryInterface::Get(true); }
60
TearDownTestCase(void)61 void HdfBatteryHdiTestAdditional::TearDownTestCase(void) {}
62
SetUp(void)63 void HdfBatteryHdiTestAdditional::SetUp(void) {}
64
TearDown(void)65 void HdfBatteryHdiTestAdditional::TearDown(void) {}
66
CreateFile(std::string path, std::string content)67 std::string CreateFile(std::string path, std::string content)
68 {
69 std::ofstream stream(path.c_str());
70 if (!stream.is_open()) {
71 printf("Cannot create file");
72 return nullptr;
73 }
74 stream << content.c_str() << std::endl;
75 stream.close();
76 return path;
77 }
78
79 namespace {
80 /**
81 * @tc.number: SUB_Powermgr_Battery_HDI_ChangePath_0200
82 * @tc.name: testChangePath001
83 * @tc.desc: Verify the reliability of the ChangePath function.
84 */
HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath001, TestSize.Level2)85 HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath001, TestSize.Level2)
86 {
87 std::string path = "";
88 EXPECT_EQ(HDF_SUCCESS, g_batteryInterface->ChangePath(path));
89 }
90
91 /**
92 * @tc.number: SUB_Powermgr_Battery_HDI_ChangePath_0300
93 * @tc.name: testChangePath002
94 * @tc.desc: Verify the reliability of the ChangePath function.
95 */
HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath002, TestSize.Level2)96 HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath002, TestSize.Level2)
97 {
98 EXPECT_EQ(HDF_SUCCESS, g_batteryInterface->ChangePath(nullptr));
99 }
100
101 /**
102 * @tc.number: SUB_Powermgr_Battery_HDI_ChangePath_0400
103 * @tc.name: testChangePath003
104 * @tc.desc: Verify the reliability of the ChangePath function.
105 */
HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath003, TestSize.Level2)106 HWTEST_F(HdfBatteryHdiTestAdditional, testChangePath003, TestSize.Level2)
107 {
108 std::string path = "test test test";
109 EXPECT_EQ(HDF_SUCCESS, g_batteryInterface->ChangePath(path));
110 }
111
112 /**
113 * @tc.number: SUB_Powermgr_Battery_HDI_GetCapacity_0200
114 * @tc.name: testGetCapacity001
115 * @tc.desc: Verify the stability of the GetCapacity function.
116 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetCapacity001, TestSize.Level1)117 HWTEST_F(HdfBatteryHdiTestAdditional, testGetCapacity001, TestSize.Level1)
118 {
119 int capacity;
120 for (uint32_t i = 0; i < 1000; i++) {
121 g_batteryInterface->GetCapacity(capacity);
122 EXPECT_TRUE(capacity <= 100 && capacity >= 0);
123 }
124 }
125
126 /**
127 * @tc.number: SUB_Powermgr_Battery_HDI_GetVoltage_0200
128 * @tc.name: testGetVoltage001
129 * @tc.desc: Verify the stability of the GetVoltage function.
130 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetVoltage001, TestSize.Level1)131 HWTEST_F(HdfBatteryHdiTestAdditional, testGetVoltage001, TestSize.Level1)
132 {
133 int voltage;
134 for (uint32_t i = 0; i < 1000; i++) {
135 g_batteryInterface->GetVoltage(voltage);
136 EXPECT_TRUE(voltage >= 0);
137 }
138 }
139
140 /**
141 * @tc.number: SUB_Powermgr_Battery_HDI_GetTemperature_0200
142 * @tc.name: testGetTemperature001
143 * @tc.desc: Verify the stability of the GetTemperature function.
144 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetTemperature001, TestSize.Level1)145 HWTEST_F(HdfBatteryHdiTestAdditional, testGetTemperature001, TestSize.Level1)
146 {
147 int temperature;
148 for (uint32_t i = 0; i < 1000; i++) {
149 g_batteryInterface->GetTemperature(temperature);
150 EXPECT_TRUE(temperature >= 0 && temperature <= 600);
151 }
152 }
153
154 /**
155 * @tc.number: SUB_Powermgr_Battery_HDI_GetHealthState_0200
156 * @tc.name: testGetHealthState001
157 * @tc.desc: Verify the stability of the GetHealthState function.
158 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetHealthState001, TestSize.Level1)159 HWTEST_F(HdfBatteryHdiTestAdditional, testGetHealthState001, TestSize.Level1)
160 {
161 OHOS::HDI::Battery::V2_0::BatteryHealthState healthState = OHOS::HDI::Battery::V2_0::BatteryHealthState(0);
162 for (uint32_t i = 0; i < 1000; i++) {
163 g_batteryInterface->GetHealthState(healthState);
164 EXPECT_TRUE(healthState >= 0 && healthState <= 6);
165 }
166 }
167
168 /**
169 * @tc.number: SUB_Powermgr_Battery_HDI_GetPluggedType_0200
170 * @tc.name: testGetPluggedType001
171 * @tc.desc: Verify the stability of the GetPluggedType function.
172 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetPluggedType001, TestSize.Level1)173 HWTEST_F(HdfBatteryHdiTestAdditional, testGetPluggedType001, TestSize.Level1)
174 {
175 OHOS::HDI::Battery::V2_0::BatteryPluggedType pluggedType = OHOS::HDI::Battery::V2_0::BatteryPluggedType(0);
176 for (uint32_t i = 0; i < 1000; i++) {
177 g_batteryInterface->GetPluggedType(pluggedType);
178 EXPECT_TRUE(pluggedType >= OHOS::HDI::Battery::V2_0::BatteryPluggedType::PLUGGED_TYPE_NONE &&
179 pluggedType <= OHOS::HDI::Battery::V2_0::BatteryPluggedType::PLUGGED_TYPE_BUTT);
180 }
181 }
182
183 /**
184 * @tc.number: SUB_Powermgr_Battery_HDI_GetChargeState_0200
185 * @tc.name: testGetChargeState001
186 * @tc.desc: Verify the stability of the GetChargeState function.
187 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetChargeState001, TestSize.Level1)188 HWTEST_F(HdfBatteryHdiTestAdditional, testGetChargeState001, TestSize.Level1)
189 {
190 OHOS::HDI::Battery::V2_0::BatteryChargeState chargeState = OHOS::HDI::Battery::V2_0::BatteryChargeState(0);
191 for (uint32_t i = 0; i < 1000; i++) {
192 g_batteryInterface->GetChargeState(chargeState);
193 EXPECT_TRUE(chargeState >= 0 && chargeState <= 4);
194 }
195 }
196
197 /**
198 * @tc.number: SUB_Powermgr_Battery_HDI_GetPresent_0200
199 * @tc.name: testGetPresent001
200 * @tc.desc: Verify the stability of the GetPresent function.
201 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetPresent001, TestSize.Level1)202 HWTEST_F(HdfBatteryHdiTestAdditional, testGetPresent001, TestSize.Level1)
203 {
204 bool present = false;
205 for (uint32_t i = 0; i < 1000; i++) {
206 EXPECT_TRUE(HDF_SUCCESS == g_batteryInterface->GetPresent(present));
207 }
208 }
209
210 /**
211 * @tc.number: SUB_Powermgr_Battery_HDI_GetTechnology_0200
212 * @tc.name: testGetTechnology001
213 * @tc.desc: Verify the stability of the GetTechnology function.
214 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetTechnology001, TestSize.Level1)215 HWTEST_F(HdfBatteryHdiTestAdditional, testGetTechnology001, TestSize.Level1)
216 {
217 std::string technology;
218 for (uint32_t i = 0; i < 1000; i++) {
219 g_batteryInterface->GetTechnology(technology);
220 EXPECT_FALSE(technology.empty());
221 }
222 }
223
224 /**
225 * @tc.number: SUB_Powermgr_Battery_HDI_GetTotalEnergy_0200
226 * @tc.name: testGetTotalEnergy001
227 * @tc.desc: Verify the stability of the GetTotalEnergy function.
228 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetTotalEnergy001, TestSize.Level1)229 HWTEST_F(HdfBatteryHdiTestAdditional, testGetTotalEnergy001, TestSize.Level1)
230 {
231 int32_t totalEnergy = -1;
232 for (uint32_t i = 0; i < 1000; i++) {
233 g_batteryInterface->GetTotalEnergy(totalEnergy);
234 EXPECT_TRUE(totalEnergy >= 0);
235 }
236 }
237
238 /**
239 * @tc.number: SUB_Powermgr_Battery_HDI_GetCurrentAverage_0200
240 * @tc.name: testGetCurrentAverage001
241 * @tc.desc: Verify the stability of the GetCurrentAverage function.
242 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetCurrentAverage001, TestSize.Level1)243 HWTEST_F(HdfBatteryHdiTestAdditional, testGetCurrentAverage001, TestSize.Level1)
244 {
245 int32_t curAverage = -1;
246 int32_t ret = 0;
247 for (uint32_t i = 0; i < 1000; i++) {
248 ret = g_batteryInterface->GetCurrentAverage(curAverage);
249 if (ret != 0) {
250 EXPECT_NE(0, curAverage);
251 } else {
252 EXPECT_EQ(ret, HDF_SUCCESS);
253 }
254 }
255 }
256
257 /**
258 * @tc.number: SUB_Powermgr_Battery_HDI_GetCurrentNow_0200
259 * @tc.name: testGetCurrentNow001
260 * @tc.desc: Verify the stability of the GetCurrentNow function.
261 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetCurrentNow001, TestSize.Level1)262 HWTEST_F(HdfBatteryHdiTestAdditional, testGetCurrentNow001, TestSize.Level1)
263 {
264 int32_t nowCurr = -1;
265 for (uint32_t i = 0; i < 1000; i++) {
266 g_batteryInterface->GetCurrentNow(nowCurr);
267 EXPECT_TRUE(nowCurr != -1);
268 }
269 }
270
271 /**
272 * @tc.number: SUB_Powermgr_Battery_HDI_GetRemainEnergy_0200
273 * @tc.name: testGetRemainEnergy001
274 * @tc.desc: Verify the stability of the GetRemainEnergy function.
275 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetRemainEnergy001, TestSize.Level1)276 HWTEST_F(HdfBatteryHdiTestAdditional, testGetRemainEnergy001, TestSize.Level1)
277 {
278 int32_t remainEnergy = -1;
279 for (uint32_t i = 0; i < 1000; i++) {
280 g_batteryInterface->GetRemainEnergy(remainEnergy);
281 EXPECT_TRUE(remainEnergy >= 0);
282 }
283 }
284
285 /**
286 * @tc.number: SUB_Powermgr_Battery_HDI_GetBatteryInfo_0200
287 * @tc.name: testGetBatteryInfo001
288 * @tc.desc: Verify the stability of the GetBatteryInfo function.
289 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetBatteryInfo001, TestSize.Level1)290 HWTEST_F(HdfBatteryHdiTestAdditional, testGetBatteryInfo001, TestSize.Level1)
291 {
292 OHOS::HDI::Battery::V2_0::BatteryInfo event = {
293 .capacity = -1,
294 };
295 for (uint32_t i = 0; i < 1000; i++) {
296 g_batteryInterface->GetBatteryInfo(event);
297 EXPECT_TRUE(-1 != event.capacity);
298 }
299 }
300
301 /**
302 * @tc.number: SUB_Powermgr_Battery_HDI_GetChargeType_0200
303 * @tc.name: testGetChargeType001
304 * @tc.desc: Verify the stability of the GetChargeType function.
305 */
HWTEST_F(HdfBatteryHdiTestAdditional, testGetChargeType001, TestSize.Level1)306 HWTEST_F(HdfBatteryHdiTestAdditional, testGetChargeType001, TestSize.Level1)
307 {
308 OHOS::HDI::Battery::V2_0::ChargeType chargeType = OHOS::HDI::Battery::V2_0::ChargeType(0);
309 for (uint32_t i = 0; i < 1000; i++) {
310 g_batteryInterface->GetChargeType(chargeType);
311 EXPECT_TRUE(chargeType >= OHOS::HDI::Battery::V2_0::ChargeType::CHARGE_TYPE_NONE &&
312 chargeType <= OHOS::HDI::Battery::V2_0::ChargeType::CHARGE_TYPE_WIRELESS_SUPER_QUICK);
313 }
314 }
315
316 /**
317 * @tc.number: SUB_Powermgr_Battery_HDI_Register_0200
318 * @tc.name: testBatteryRegister001
319 * @tc.desc: Verify the reliability of the Register function.
320 */
HWTEST_F(HdfBatteryHdiTestAdditional, testBatteryRegister001, TestSize.Level2)321 HWTEST_F(HdfBatteryHdiTestAdditional, testBatteryRegister001, TestSize.Level2)
322 {
323 EXPECT_NE(0, g_batteryInterface->Register(nullptr));
324 }
325
326 /**
327 * @tc.number: SUB_Powermgr_Battery_HDI_UnRegister_0200
328 * @tc.name: testBatteryUnRegister001
329 * @tc.desc: Verify the stability of the UnRegister function.
330 */
HWTEST_F(HdfBatteryHdiTestAdditional, testBatteryUnRegister001, TestSize.Level2)331 HWTEST_F(HdfBatteryHdiTestAdditional, testBatteryUnRegister001, TestSize.Level2)
332 {
333 EXPECT_EQ(0, g_batteryInterface->UnRegister());
334 }
335
336 /**
337 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0300
338 * @tc.name: testSetChargingLimit001
339 * @tc.desc: Verify the reliability of the SetChargingLimit function.
340 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit001, TestSize.Level1)341 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit001, TestSize.Level1)
342 {
343 std::string currentPath = "/data/service/el0/battery/current_limit";
344 CreateFile(currentPath, "");
345 ChargingLimit scLimit;
346 scLimit.type = TYPE_CURRENT;
347 scLimit.protocol = "sc";
348 scLimit.value = 1100;
349 std::vector<ChargingLimit> chargeLimitList;
350 chargeLimitList.push_back(scLimit);
351 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
352 EXPECT_EQ(true, result == HDF_SUCCESS);
353 }
354
355 /**
356 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0400
357 * @tc.name: testSetChargingLimit002
358 * @tc.desc: Verify the reliability of the SetChargingLimit function.
359 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit002, TestSize.Level1)360 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit002, TestSize.Level1)
361 {
362 std::string voltagePath = "/data/service/el0/battery/voltage_limit";
363 CreateFile(voltagePath, "");
364 ChargingLimit scLimit;
365 scLimit.type = TYPE_VOLTAGE;
366 scLimit.protocol = "sc";
367 scLimit.value = 3000;
368 std::vector<ChargingLimit> chargeLimitList;
369 chargeLimitList.push_back(scLimit);
370 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
371 EXPECT_EQ(true, result == HDF_SUCCESS);
372 }
373
374 /**
375 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0500
376 * @tc.name: testSetChargingLimit003
377 * @tc.desc: Verify the reliability of the SetChargingLimit function.
378 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit003, TestSize.Level1)379 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit003, TestSize.Level1)
380 {
381 std::string currentPath = "/data/service/el0/battery/current_limit";
382 CreateFile(currentPath, "");
383 ChargingLimit scLimit;
384 scLimit.type = TYPE_CURRENT;
385 scLimit.protocol = "sc";
386 scLimit.value = 1000;
387 ChargingLimit buckLimit;
388 buckLimit.type = TYPE_CURRENT;
389 buckLimit.protocol = "buck";
390 buckLimit.value = 1100;
391 ChargingLimit testLimit;
392 testLimit.type = TYPE_CURRENT;
393 testLimit.protocol = "test";
394 testLimit.value = 1200;
395 std::vector<ChargingLimit> chargeLimitList;
396 chargeLimitList.push_back(scLimit);
397 chargeLimitList.push_back(buckLimit);
398 chargeLimitList.push_back(testLimit);
399 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
400 EXPECT_EQ(true, result == HDF_SUCCESS);
401
402 std::string line;
403 std::string chargeLimitStr;
404 std::string writeChargeInfo = scLimit.protocol + " " + std::to_string(scLimit.value) + "\n" + buckLimit.protocol +
405 " " + std::to_string(buckLimit.value) + "\n" + testLimit.protocol + " " +
406 std::to_string(testLimit.value) + "\n";
407 std::ifstream fin(currentPath.c_str());
408 if (fin) {
409 while (getline(fin, line)) {
410 chargeLimitStr += line + "\n";
411 }
412 }
413 EXPECT_EQ(true, chargeLimitStr == writeChargeInfo);
414 }
415
416 /**
417 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0600
418 * @tc.name: testSetChargingLimit004
419 * @tc.desc: Verify the reliability of the SetChargingLimit function.
420 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit004, TestSize.Level1)421 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit004, TestSize.Level1)
422 {
423 std::string voltagePath = "/data/service/el0/battery/voltage_limit";
424 CreateFile(voltagePath, "");
425 ChargingLimit scLimit;
426 scLimit.type = TYPE_VOLTAGE;
427 scLimit.protocol = "sc";
428 scLimit.value = 2000;
429 ChargingLimit buckLimit;
430 buckLimit.type = TYPE_VOLTAGE;
431 buckLimit.protocol = "buck";
432 buckLimit.value = 3000;
433 ChargingLimit testLimit;
434 testLimit.type = TYPE_VOLTAGE;
435 testLimit.protocol = "test";
436 testLimit.value = 4000;
437 std::vector<ChargingLimit> chargeLimitList;
438 chargeLimitList.push_back(scLimit);
439 chargeLimitList.push_back(buckLimit);
440 chargeLimitList.push_back(testLimit);
441 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
442 EXPECT_EQ(true, result == HDF_SUCCESS);
443
444 std::string line;
445 std::string voltageLimitStr;
446 std::string writeVoltageInfo = scLimit.protocol + " " + std::to_string(scLimit.value) + "\n" + buckLimit.protocol +
447 " " + std::to_string(buckLimit.value) + "\n" + testLimit.protocol + " " +
448 std::to_string(testLimit.value) + "\n";
449 std::ifstream fin(voltagePath.c_str());
450 if (fin) {
451 while (getline(fin, line)) {
452 voltageLimitStr += line + "\n";
453 }
454 }
455 EXPECT_EQ(true, voltageLimitStr == writeVoltageInfo);
456 }
457
458 /**
459 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0700
460 * @tc.name: testSetChargingLimit005
461 * @tc.desc: Verify the reliability of the SetChargingLimit function.
462 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit005, TestSize.Level1)463 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit005, TestSize.Level1)
464 {
465 int32_t result = HDF_SUCCESS;
466 ChargingLimit scLimit;
467 scLimit.type = TYPE_CURRENT;
468 scLimit.protocol = "sc";
469 scLimit.value = 1100;
470 std::vector<ChargingLimit> chargeLimitList;
471 chargeLimitList.push_back(scLimit);
472 for (uint32_t i = 0; i < 1000; i++) {
473 result = g_batteryInterface->SetChargingLimit(chargeLimitList);
474 EXPECT_EQ(true, result == HDF_SUCCESS);
475 }
476 }
477
478 /**
479 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0800
480 * @tc.name: testSetChargingLimit006
481 * @tc.desc: Verify the reliability of the SetChargingLimit function.
482 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit006, TestSize.Level1)483 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit006, TestSize.Level1)
484 {
485 int32_t result = HDF_SUCCESS;
486 ChargingLimit scLimit;
487 scLimit.type = TYPE_VOLTAGE;
488 scLimit.protocol = "sc";
489 scLimit.value = 3000;
490 std::vector<ChargingLimit> chargeLimitList;
491 chargeLimitList.push_back(scLimit);
492 for (uint32_t i = 0; i < 1000; i++) {
493 result = g_batteryInterface->SetChargingLimit(chargeLimitList);
494 EXPECT_EQ(true, result == HDF_SUCCESS);
495 }
496 }
497
498 /**
499 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_0900
500 * @tc.name: testSetChargingLimit007
501 * @tc.desc: Verify the reliability of the SetChargingLimit function.
502 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit007, TestSize.Level2)503 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit007, TestSize.Level2)
504 {
505 ChargingLimit scLimit;
506 scLimit.type = TYPE_CURRENT;
507 scLimit.protocol = "sc";
508 scLimit.value = 0;
509 std::vector<ChargingLimit> chargeLimitList;
510 chargeLimitList.push_back(scLimit);
511 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
512 EXPECT_EQ(true, result == HDF_SUCCESS);
513 }
514
515 /**
516 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_1000
517 * @tc.name: testSetChargingLimit008
518 * @tc.desc: Verify the reliability of the SetChargingLimit function.
519 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit008, TestSize.Level2)520 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit008, TestSize.Level2)
521 {
522 ChargingLimit scLimit;
523 scLimit.type = TYPE_VOLTAGE;
524 scLimit.protocol = "sc";
525 scLimit.value = 0;
526 std::vector<ChargingLimit> chargeLimitList;
527 chargeLimitList.push_back(scLimit);
528 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
529 EXPECT_EQ(true, result == HDF_SUCCESS);
530 }
531
532 /**
533 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_1100
534 * @tc.name: testSetChargingLimit009
535 * @tc.desc: Verify the reliability of the SetChargingLimit function.
536 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit009, TestSize.Level2)537 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit009, TestSize.Level2)
538 {
539 ChargingLimit scLimit;
540 scLimit.type = TYPE_CURRENT;
541 scLimit.protocol = "sc";
542 scLimit.value = -1;
543 std::vector<ChargingLimit> chargeLimitList;
544 chargeLimitList.push_back(scLimit);
545 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
546 EXPECT_EQ(true, result == HDF_SUCCESS);
547 }
548
549 /**
550 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_1200
551 * @tc.name: testSetChargingLimit010
552 * @tc.desc: Verify the reliability of the SetChargingLimit function.
553 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit010, TestSize.Level2)554 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit010, TestSize.Level2)
555 {
556 ChargingLimit scLimit;
557 scLimit.type = TYPE_VOLTAGE;
558 scLimit.protocol = "sc";
559 scLimit.value = -1;
560 std::vector<ChargingLimit> chargeLimitList;
561 chargeLimitList.push_back(scLimit);
562 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
563 EXPECT_EQ(true, result == HDF_SUCCESS);
564 }
565
566 /**
567 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_1300
568 * @tc.name: testSetChargingLimit011
569 * @tc.desc: Verify the reliability of the SetChargingLimit function.
570 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit011, TestSize.Level2)571 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit011, TestSize.Level2)
572 {
573 ChargingLimit scLimit;
574 scLimit.type = TYPE_CURRENT;
575 scLimit.protocol = "";
576 scLimit.value = 1000;
577 std::vector<ChargingLimit> chargeLimitList;
578 chargeLimitList.push_back(scLimit);
579 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
580 EXPECT_EQ(true, result == HDF_SUCCESS);
581 }
582
583 /**
584 * @tc.number: SUB_Powermgr_Battery_HDI_SetChargingLimit_1400
585 * @tc.name: testSetChargingLimit012
586 * @tc.desc: Verify the reliability of the SetChargingLimit function.
587 */
HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit012, TestSize.Level2)588 HWTEST_F(HdfBatteryHdiTestAdditional, testSetChargingLimit012, TestSize.Level2)
589 {
590 ChargingLimit scLimit;
591 scLimit.type = TYPE_VOLTAGE;
592 scLimit.protocol = "";
593 scLimit.value = 3000;
594 std::vector<ChargingLimit> chargeLimitList;
595 chargeLimitList.push_back(scLimit);
596 int32_t result = g_batteryInterface->SetChargingLimit(chargeLimitList);
597 EXPECT_EQ(true, result == HDF_SUCCESS);
598 }
599 } // namespace
600