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