1 /*
2  * Copyright (c) 2022-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 "battery_callback_test.h"
17 #include "battery_config_test.h"
18 #include "battery_dump_test.h"
19 
20 #include <string>
21 #include <memory>
22 
23 #include "battery_callback.h"
24 #include "battery_config.h"
25 #include "battery_log.h"
26 
27 #ifdef GTEST
28 #define private   public
29 #define protected public
30 #endif
31 #include "battery_dump.h"
32 #include "battery_service.h"
33 #include "power_common.h"
34 
35 using namespace testing::ext;
36 
37 namespace OHOS {
38 namespace PowerMgr {
39 namespace {
40 sptr<BatteryService> g_service;
41 auto& g_configTest = BatteryConfig::GetInstance();
42 }
43 
HandleBatteryCallbackEvent(const OHOS::HDI::Battery::V2_0::BatteryInfo& event)44 int32_t HandleBatteryCallbackEvent(const OHOS::HDI::Battery::V2_0::BatteryInfo& event)
45 {
46     return ERR_OK;
47 }
48 
SetUpTestCase()49 void BatteryCallbackTest::SetUpTestCase()
50 {
51     g_service = DelayedSpSingleton<BatteryService>::GetInstance();
52 }
53 
TearDownTestCase()54 void BatteryCallbackTest::TearDownTestCase()
55 {
56     g_service = nullptr;
57 }
58 
SetUpTestCase()59 void BatteryDumpTest::SetUpTestCase()
60 {
61     g_service = DelayedSpSingleton<BatteryService>::GetInstance();
62     g_service->isBootCompleted_ = true;
63 }
64 
65 /**
66  * @tc.name: BatteryCallback001
67  * @tc.desc: Update BatteryInfo, the eventCb_ is valid
68  * @tc.type: FUNC
69  * @tc.require: issueI5YZR1
70  */
HWTEST_F(BatteryCallbackTest, BatteryCallback001, TestSize.Level1)71 HWTEST_F(BatteryCallbackTest, BatteryCallback001, TestSize.Level1)
72 {
73     BATTERY_HILOGI(LABEL_TEST, "BatteryCallback001 begin");
74     sptr<HDI::Battery::V2_0::IBatteryInterface> iBatteryInterface;
75     iBatteryInterface = HDI::Battery::V2_0::IBatteryInterface::Get();
76     sptr<HDI::Battery::V2_0::IBatteryCallback> callback = new BatteryCallback();
77     EXPECT_EQ(iBatteryInterface->Register(callback), HDF_SUCCESS);
78 
79     BatteryCallback::BatteryEventCallback eventCb = std::bind(&HandleBatteryCallbackEvent, std::placeholders::_1);
80     EXPECT_EQ(BatteryCallback::RegisterBatteryEvent(eventCb), HDF_SUCCESS);
81     HDI::Battery::V2_0::BatteryInfo event;
82     iBatteryInterface->GetBatteryInfo(event);
83     EXPECT_NE(callback->Update(event), HDF_FAILURE);
84     BATTERY_HILOGI(LABEL_TEST, "BatteryCallback001 end");
85 }
86 
87 /**
88  * @tc.name: BatteryCallback002
89  * @tc.desc: Update BatteryInfo, the eventCb_ is invalid
90  * @tc.type: FUNC
91  */
HWTEST_F(BatteryCallbackTest, BatteryCallback002, TestSize.Level1)92 HWTEST_F(BatteryCallbackTest, BatteryCallback002, TestSize.Level1)
93 {
94     BATTERY_HILOGI(LABEL_TEST, "BatteryCallback002 begin");
95     BatteryCallback::BatteryEventCallback eventCb = nullptr;
96     EXPECT_EQ(BatteryCallback::RegisterBatteryEvent(eventCb), HDF_SUCCESS);
97     HDI::Battery::V2_0::BatteryInfo event;
98     sptr<HDI::Battery::V2_0::IBatteryCallback> callback = new BatteryCallback();
99     EXPECT_EQ(callback->Update(event), HDF_FAILURE);
100     BATTERY_HILOGI(LABEL_TEST, "BatteryCallback002 end");
101 }
102 
103 /**
104  * @tc.name: BatteryConfig001
105  * @tc.desc: Parse config, and configPath parameter is real path
106  * @tc.type: FUNC
107  */
HWTEST_F(BatteryConfigTest, BatteryConfig001, TestSize.Level1)108 HWTEST_F(BatteryConfigTest, BatteryConfig001, TestSize.Level1)
109 {
110     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig001 begin");
111     EXPECT_TRUE(g_configTest.ParseConfig());
112     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig001 end");
113 }
114 
115 /**
116  * @tc.name: BatteryConfig002
117  * @tc.desc: Get battery light config
118  * @tc.type: FUNC
119  */
HWTEST_F(BatteryConfigTest, BatteryConfig002, TestSize.Level1)120 HWTEST_F(BatteryConfigTest, BatteryConfig002, TestSize.Level1)
121 {
122     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig002 begin");
123     const std::vector<BatteryConfig::LightConf> lightConf = g_configTest.GetLightConf();
124     EXPECT_TRUE(lightConf.size());
125 
126     uint32_t maxRgb = (255 << 16) | (255 << 8) | 255;
127     for (uint32_t i = 0; i < lightConf.size(); ++i) {
128         // The value ranges from 0 to 100
129         EXPECT_TRUE(lightConf[i].beginSoc >= 0 && lightConf[i].beginSoc <= 100);
130         EXPECT_TRUE(lightConf[i].endSoc >= 0 && lightConf[i].endSoc <= 100);
131         // The start range is smaller than the end range
132         EXPECT_TRUE(lightConf[i].beginSoc < lightConf[i].endSoc);
133         // The value ranges from 0 to maxRgb
134         EXPECT_TRUE(lightConf[i].rgb >= 0 && lightConf[i].rgb <= maxRgb);
135     }
136     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig002 end");
137 }
138 
139 /**
140  * @tc.name: BatteryConfig003
141  * @tc.desc: Get config Int value
142  * @tc.type: FUNC
143  */
HWTEST_F(BatteryConfigTest, BatteryConfig003, TestSize.Level1)144 HWTEST_F(BatteryConfigTest, BatteryConfig003, TestSize.Level1)
145 {
146     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig003 begin");
147     std::string key = "soc.warning";
148     if (!g_configTest.IsExist(key)) {
149         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig003 %{public}s does not exist", key.c_str());
150         return;
151     }
152     int32_t invalid = -1;
153     int32_t warnCapacity = g_configTest.GetInt(key, invalid);
154     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig003 warnCapacity=%{public}d", warnCapacity);
155     // The value ranges from 0 to 100
156     EXPECT_TRUE(warnCapacity >= 0 && warnCapacity <= 100);
157     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig003 end");
158 }
159 
160 /**
161  * @tc.name: BatteryConfig004
162  * @tc.desc: Get config Int value
163  * @tc.type: FUNC
164  */
HWTEST_F(BatteryConfigTest, BatteryConfig004, TestSize.Level1)165 HWTEST_F(BatteryConfigTest, BatteryConfig004, TestSize.Level1)
166 {
167     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig004 begin");
168     std::string key = "temperature.high";
169     if (!g_configTest.IsExist(key)) {
170         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig004 %{public}s does not exist", key.c_str());
171         return;
172     }
173     int32_t minTemp = -900; // (-90℃)
174     int32_t maxTemp = 900;  // (90℃)
175     int32_t highTemperature = g_configTest.GetInt(key, maxTemp);
176     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig004 highTemperature=%{public}d", highTemperature);
177     // The value ranges from -900 to 900
178     EXPECT_TRUE(highTemperature > minTemp && highTemperature < maxTemp);
179     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig004 end");
180 }
181 
182 /**
183  * @tc.name: BatteryConfig005
184  * @tc.desc: Get config Int value
185  * @tc.type: FUNC
186  */
HWTEST_F(BatteryConfigTest, BatteryConfig005, TestSize.Level1)187 HWTEST_F(BatteryConfigTest, BatteryConfig005, TestSize.Level1)
188 {
189     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig005 begin");
190     std::string key = "temperature.low";
191     if (!g_configTest.IsExist(key)) {
192         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig005 %{public}s does not exist", key.c_str());
193         return;
194     }
195     int32_t minTemp = -900; // (-90℃)
196     int32_t maxTemp = 900;  // (90℃)
197     int32_t lowTemperature = g_configTest.GetInt(key, minTemp);
198     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig005 lowTemperature=%{public}d", lowTemperature);
199     // The value ranges from -900 to 900
200     EXPECT_TRUE(lowTemperature < maxTemp && lowTemperature > minTemp);
201     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig005 end");
202 }
203 
204 /**
205  * @tc.name: BatteryConfig006
206  * @tc.desc: Get config Int value
207  * @tc.type: FUNC
208  */
HWTEST_F(BatteryConfigTest, BatteryConfig006, TestSize.Level1)209 HWTEST_F(BatteryConfigTest, BatteryConfig006, TestSize.Level1)
210 {
211     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig006 begin");
212     std::string key = "soc.shutdown";
213     if (!g_configTest.IsExist(key)) {
214         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig006 %{public}s does not exist", key.c_str());
215         return;
216     }
217     int32_t invalid = -1;
218     int32_t shtdwonCapacity = g_configTest.GetInt(key, invalid);
219     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig006 shtdwonCapacity=%{public}d", shtdwonCapacity);
220     // The value ranges from 0 to 100
221     EXPECT_TRUE(shtdwonCapacity >= 0 && shtdwonCapacity <= 100);
222     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig006 end");
223 }
224 
225 /**
226  * @tc.name: BatteryConfig007
227  * @tc.desc: Get config Int value
228  * @tc.type: FUNC
229  */
HWTEST_F(BatteryConfigTest, BatteryConfig007, TestSize.Level1)230 HWTEST_F(BatteryConfigTest, BatteryConfig007, TestSize.Level1)
231 {
232     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig007 begin");
233     std::string key = "soc.low";
234     if (!g_configTest.IsExist(key)) {
235         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig007 %{public}s does not exist", key.c_str());
236         return;
237     }
238     int32_t invalid = -1;
239     int32_t low_battery_event = g_configTest.GetInt(key, invalid);
240     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig007 low_battery_event=%{public}d", low_battery_event);
241     // The value ranges from 0 to 100
242     EXPECT_TRUE(low_battery_event >= 0 && low_battery_event <= 100);
243     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig007 end");
244 }
245 
246 /**
247  * @tc.name: BatteryConfig008
248  * @tc.desc: Get unknown configuration, return default value
249  * @tc.type: FUNC
250  */
HWTEST_F(BatteryConfigTest, BatteryConfig008, TestSize.Level1)251 HWTEST_F(BatteryConfigTest, BatteryConfig008, TestSize.Level1)
252 {
253     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig008 begin");
254     int32_t defValue = 100;
255     EXPECT_EQ(defValue, g_configTest.GetInt("XXXXXXXXX", defValue));
256     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig008 end");
257 }
258 
259 /**
260  * @tc.name: BatteryConfig009
261  * @tc.desc: Get a maximum nesting depth of 5 or more
262  * @tc.type: FUNC
263  */
HWTEST_F(BatteryConfigTest, BatteryConfig009, TestSize.Level1)264 HWTEST_F(BatteryConfigTest, BatteryConfig009, TestSize.Level1)
265 {
266     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig009 begin");
267     int32_t defValue = 200;
268     EXPECT_EQ(defValue, g_configTest.GetInt("X.X.X.X.X.X", defValue));
269     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig009 end");
270 }
271 
272 /**
273  * @tc.name: BatteryConfig010
274  * @tc.desc: Get empty configuration, return default value
275  * @tc.type: FUNC
276  */
HWTEST_F(BatteryConfigTest, BatteryConfig010, TestSize.Level1)277 HWTEST_F(BatteryConfigTest, BatteryConfig010, TestSize.Level1)
278 {
279     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig010 begin");
280     int32_t defValue = 300;
281     EXPECT_EQ(defValue, g_configTest.GetInt("", defValue));
282     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig010 end");
283 }
284 
285 /**
286  * @tc.name: BatteryConfig0011
287  * @tc.desc: Parse config, and configPath parameter is empty
288  * @tc.type: FUNC
289  * @tc.require: issueI5YZR1
290  */
HWTEST_F(BatteryConfigTest, BatteryConfig011, TestSize.Level1)291 HWTEST_F(BatteryConfigTest, BatteryConfig011, TestSize.Level1)
292 {
293     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig0011 begin");
294     EXPECT_TRUE(g_configTest.ParseConfig());
295     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig0011 end");
296 }
297 
298 /**
299  * @tc.name: BatteryConfig012
300  * @tc.desc: Get config Int value, paramter is real key
301  * @tc.type: FUNC
302  * @tc.require: issueI5YZR1
303  */
HWTEST_F(BatteryConfigTest, BatteryConfig012, TestSize.Level1)304 HWTEST_F(BatteryConfigTest, BatteryConfig012, TestSize.Level1)
305 {
306     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig0012 begin");
307     std::string key = "light.high.soc";
308     if (!g_configTest.IsExist(key)) {
309         BATTERY_HILOGI(LABEL_TEST, "BatteryConfig012 %{public}s does not exist", key.c_str());
310         return;
311     }
312     int32_t defVal = 90;
313     int32_t highSoc = g_configTest.GetInt(key, defVal);
314     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig012 highSoc=%{public}d", highSoc);
315     // The value ranges from 0 to 100
316     EXPECT_TRUE(highSoc >= 0 && highSoc <= 100);
317     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig0012 end");
318 }
319 
320 /**
321  * @tc.name: BatteryConfig0013
322  * @tc.desc: Get config Int value, paramter is invalid key
323  * @tc.type: FUNC
324  * @tc.require: issueI5YZR1
325  */
HWTEST_F(BatteryConfigTest, BatteryConfig013, TestSize.Level1)326 HWTEST_F(BatteryConfigTest, BatteryConfig013, TestSize.Level1)
327 {
328     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig013 begin");
329     std::string key = "invalid.key";
330     EXPECT_TRUE(!g_configTest.IsExist(key));
331     BATTERY_HILOGI(LABEL_TEST, "BatteryConfig013 end");
332 }
333 
334 /**
335  * @tc.name: BatteryDump001
336  * @tc.desc: Dump parameter is -i, Get battery information
337  * @tc.type: FUNC
338  * @tc.require: issueI5YZR1
339  */
HWTEST_F(BatteryDumpTest, BatteryDump001, TestSize.Level1)340 HWTEST_F(BatteryDumpTest, BatteryDump001, TestSize.Level1)
341 {
342     BATTERY_HILOGI(LABEL_TEST, "BatteryDump001 begin");
343     int32_t fd = 1;
344     std::vector<std::u16string> args;
345     std::u16string arg = u"-i";
346     args.push_back(arg);
347     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
348     BATTERY_HILOGI(LABEL_TEST, "BatteryDump001 end");
349 }
350 
351 /**
352  * @tc.name: BatteryDump002
353  * @tc.desc: Dump parameter is -u, MockUnplugged
354  * @tc.type: FUNC
355  * @tc.require: issueI5YZR1
356  */
HWTEST_F(BatteryDumpTest, BatteryDump002, TestSize.Level1)357 HWTEST_F(BatteryDumpTest, BatteryDump002, TestSize.Level1)
358 {
359     BATTERY_HILOGI(LABEL_TEST, "BatteryDump002 begin");
360     int32_t fd = 1;
361     std::vector<std::u16string> args;
362     std::u16string arg = u"-u";
363     args.push_back(arg);
364     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
365     BATTERY_HILOGI(LABEL_TEST, "BatteryDump002 end");
366 }
367 
368 /**
369  * @tc.name: BatteryDump003
370  * @tc.desc: Dump parameter is -r, Reset
371  * @tc.type: FUNC
372  * @tc.require: issueI5YZR1
373  */
HWTEST_F(BatteryDumpTest, BatteryDump003, TestSize.Level1)374 HWTEST_F(BatteryDumpTest, BatteryDump003, TestSize.Level1)
375 {
376     BATTERY_HILOGI(LABEL_TEST, "BatteryDump003 begin");
377     int32_t fd = 1;
378     std::vector<std::u16string> args;
379     std::u16string arg = u"-r";
380     args.push_back(arg);
381     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
382     BATTERY_HILOGI(LABEL_TEST, "BatteryDump003 end");
383 }
384 
385 /*
386  * @tc.name: BatteryDump004
387  * @tc.desc: Test functions Dump
388  * @tc.type: FUNC
389  * @tc.require: issueI5YZR1
390  */
HWTEST_F(BatteryDumpTest, BatteryDump004, TestSize.Level1)391 static HWTEST_F(BatteryDumpTest, BatteryDump004, TestSize.Level1)
392 {
393     BATTERY_HILOGI(LABEL_TEST, "BatteryDump004 begin");
394     int32_t fd = 1;
395     std::vector<std::u16string> args;
396     std::u16string arg = u"-l";
397     args.push_back(arg);
398     EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
399     BATTERY_HILOGI(LABEL_TEST, "BatteryDump004 end");
400 }
401 
402 /**
403  * @tc.name: BatteryDump005
404  * @tc.desc: Test functions Dump
405  * @tc.type: FUNC
406  * @tc.require: issueI5YZR1
407  */
HWTEST_F(BatteryDumpTest, BatteryDump005, TestSize.Level1)408 static HWTEST_F(BatteryDumpTest, BatteryDump005, TestSize.Level1)
409 {
410     BATTERY_HILOGI(LABEL_TEST, "BatteryDump005 begin");
411     int32_t fd = 1;
412     std::vector<std::u16string> args;
413     std::u16string arg = u"-ls";
414     args.push_back(arg);
415     EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
416     BATTERY_HILOGI(LABEL_TEST, "BatteryDump005 end");
417 }
418 
419 /**
420  * @tc.name: BatteryDump006
421  * @tc.desc: Test functions Dump
422  * @tc.type: FUNC
423  * @tc.require: issueI5YZR1
424  */
HWTEST_F(BatteryDumpTest, BatteryDump006, TestSize.Level1)425 static HWTEST_F(BatteryDumpTest, BatteryDump006, TestSize.Level1)
426 {
427     BATTERY_HILOGI(LABEL_TEST, "BatteryDump006 begin");
428     int32_t fd = 1;
429     std::vector<std::u16string> args;
430     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
431     BATTERY_HILOGI(LABEL_TEST, "BatteryDump006 end");
432 }
433 
434 /**
435  * @tc.name: BatteryDump007
436  * @tc.desc: Dump parameter is empty, Get battery information
437  * @tc.type: FUNC
438  * @tc.require: issueI5YZR1
439  */
HWTEST_F(BatteryDumpTest, BatteryDump007, TestSize.Level1)440 HWTEST_F(BatteryDumpTest, BatteryDump007, TestSize.Level1)
441 {
442     BATTERY_HILOGI(LABEL_TEST, "BatteryDump007 begin");
443     BatteryDump& batteryDump = BatteryDump::GetInstance();
444     int32_t fd = 1;
445     std::vector<std::u16string> args;
446     EXPECT_FALSE(batteryDump.GetBatteryInfo(fd, g_service, args));
447     BATTERY_HILOGI(LABEL_TEST, "BatteryDump007 end");
448 }
449 
450 /**
451  * @tc.name: BatteryDump008
452  * @tc.desc: Dump parameter is empty, MockUnplugged
453  * @tc.type: FUNC
454  * @tc.require: issueI5YZR1
455  */
HWTEST_F(BatteryDumpTest, BatteryDump008, TestSize.Level1)456 HWTEST_F(BatteryDumpTest, BatteryDump008, TestSize.Level1)
457 {
458     BATTERY_HILOGI(LABEL_TEST, "BatteryDump008 begin");
459     BatteryDump& batteryDump = BatteryDump::GetInstance();
460     int32_t fd = 1;
461     std::vector<std::u16string> args;
462     EXPECT_FALSE(batteryDump.MockUnplugged(fd, g_service, args));
463     BATTERY_HILOGI(LABEL_TEST, "BatteryDump008 end");
464 }
465 
466 /**
467  * @tc.name: BatteryDump009
468  * @tc.desc: Dump parameter is empty, Reset
469  * @tc.type: FUNC
470  * @tc.require: issueI5YZR1
471  */
HWTEST_F(BatteryDumpTest, BatteryDump009, TestSize.Level1)472 HWTEST_F(BatteryDumpTest, BatteryDump009, TestSize.Level1)
473 {
474     BATTERY_HILOGI(LABEL_TEST, "BatteryDump009 begin");
475     BatteryDump& batteryDump = BatteryDump::GetInstance();
476     int32_t fd = 1;
477     std::vector<std::u16string> args;
478     EXPECT_FALSE(batteryDump.Reset(fd, g_service, args));
479     BATTERY_HILOGI(LABEL_TEST, "BatteryDump009 end");
480 }
481 
482 /**
483  * @tc.name: BatteryDump010
484  * @tc.desc: Test functions Dump, capacity cmd normal
485  * @tc.type: FUNC
486  * @tc.require: issueI6Z8RB
487  */
HWTEST_F(BatteryDumpTest, BatteryDump010, TestSize.Level1)488 static HWTEST_F(BatteryDumpTest, BatteryDump010, TestSize.Level1)
489 {
490     BATTERY_HILOGI(LABEL_TEST, "BatteryDump010 begin");
491     int32_t fd = 1;
492     std::vector<std::u16string> args;
493     std::u16string argParam = u"--capacity";
494     std::u16string argCapacity = u"20";
495     args.push_back(argParam);
496     args.push_back(argCapacity);
497     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
498     BATTERY_HILOGI(LABEL_TEST, "BatteryDump010 end");
499 }
500 
501 /**
502  * @tc.name: BatteryDump011
503  * @tc.desc: Test functions Dump, capacity cmd invalid
504  * @tc.type: FUNC
505  * @tc.require: issueI6Z8RB
506  */
HWTEST_F(BatteryDumpTest, BatteryDump011, TestSize.Level1)507 static HWTEST_F(BatteryDumpTest, BatteryDump011, TestSize.Level1)
508 {
509     BATTERY_HILOGI(LABEL_TEST, "BatteryDump011 begin");
510     int32_t fd = 1;
511     std::vector<std::u16string> args;
512     std::u16string arg = u"--capacity";
513     args.push_back(arg);
514     EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
515     BATTERY_HILOGI(LABEL_TEST, "BatteryDump011 end");
516 }
517 
518 /**
519  * @tc.name: BatteryDump012
520  * @tc.desc: Test functions Dump, capacity out of range
521  * @tc.type: FUNC
522  * @tc.require: issueI6Z8RB
523  */
HWTEST_F(BatteryDumpTest, BatteryDump012, TestSize.Level1)524 static HWTEST_F(BatteryDumpTest, BatteryDump012, TestSize.Level1)
525 {
526     BATTERY_HILOGI(LABEL_TEST, "BatteryDump012 begin");
527     int32_t fd = 1;
528     std::vector<std::u16string> args;
529     std::u16string arg = u"--capacity 200";
530     args.push_back(arg);
531     EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
532     BATTERY_HILOGI(LABEL_TEST, "BatteryDump012 end");
533 }
534 
535 /**
536  * @tc.name: BatteryDump013
537  * @tc.desc: Dump parameter is empty, Capacity
538  * @tc.type: FUNC
539  * @tc.require: issueI5YZR1
540  */
HWTEST_F(BatteryDumpTest, BatteryDump013, TestSize.Level1)541 HWTEST_F(BatteryDumpTest, BatteryDump013, TestSize.Level1)
542 {
543     BATTERY_HILOGI(LABEL_TEST, "BatteryDump013 begin");
544     BatteryDump& batteryDump = BatteryDump::GetInstance();
545     int32_t fd = 1;
546     std::vector<std::u16string> args;
547     EXPECT_FALSE(batteryDump.MockCapacity(fd, g_service, args));
548     BATTERY_HILOGI(LABEL_TEST, "BatteryDump013 end");
549 }
550 
551 /**
552  * @tc.name: BatteryDump014
553  * @tc.desc: Dump parameter is empty, Uevent
554  * @tc.type: FUNC
555  */
HWTEST_F(BatteryDumpTest, BatteryDump014, TestSize.Level1)556 HWTEST_F(BatteryDumpTest, BatteryDump014, TestSize.Level1)
557 {
558     BATTERY_HILOGI(LABEL_TEST, "BatteryDump014 begin");
559     BatteryDump& batteryDump = BatteryDump::GetInstance();
560     int32_t fd = 1;
561     std::vector<std::u16string> args;
562     EXPECT_FALSE(batteryDump.MockUevent(fd, g_service, args));
563     BATTERY_HILOGI(LABEL_TEST, "BatteryDump014 end");
564 }
565 
566 /**
567  * @tc.name: BatteryDump015
568  * @tc.desc: Test functions Dump, Uevent cmd normal
569  * @tc.type: FUNC
570  */
HWTEST_F(BatteryDumpTest, BatteryDump015, TestSize.Level1)571 static HWTEST_F(BatteryDumpTest, BatteryDump015, TestSize.Level1)
572 {
573     BATTERY_HILOGI(LABEL_TEST, "BatteryDump015 begin");
574     int32_t fd = 1;
575     std::vector<std::u16string> args;
576     std::u16string argParam = u"--uevent";
577     std::u16string argCapacity = u"BATTERY_UNDER_VOLTAGE=3$sendcommonevent";
578     args.push_back(argParam);
579     args.push_back(argCapacity);
580     EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
581     BATTERY_HILOGI(LABEL_TEST, "BatteryDump015 end");
582 }
583 
584 /**
585  * @tc.name: BatteryDump016
586  * @tc.desc: Test functions Dump, Uevent cmd invalid
587  * @tc.type: FUNC
588  */
HWTEST_F(BatteryDumpTest, BatteryDump016, TestSize.Level1)589 static HWTEST_F(BatteryDumpTest, BatteryDump016, TestSize.Level1)
590 {
591     BATTERY_HILOGI(LABEL_TEST, "BatteryDump016 begin");
592     int32_t fd = 1;
593     std::vector<std::u16string> args;
594     std::u16string arg = u"--uevent";
595     args.push_back(arg);
596     EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
597     BATTERY_HILOGI(LABEL_TEST, "BatteryDump016 end");
598 }
599 } // namespace PowerMgr
600 } // namespace OHOS
601