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 "battery_dump_test.h"
17 #include "battery_dump.h"
18 #include "power_common.h"
19 #include <memory>
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace PowerMgr {
25 namespace {
26 sptr<BatteryService> g_service;
27 }
SetUpTestCase()28 void BatteryDumpTest::SetUpTestCase()
29 {
30 g_service = DelayedSpSingleton<BatteryService>::GetInstance();
31 }
32
33 /**
34 * @tc.name: BatteryDump001
35 * @tc.desc: Dump parameter is -i, Get battery information
36 * @tc.type: FUNC
37 * @tc.require: issueI5YZR1
38 */
39 HWTEST_F(BatteryDumpTest, BatteryDump001, TestSize.Level1)
40 {
41 int32_t fd = 1;
42 std::vector<std::u16string> args;
43 std::u16string arg = u"-i";
44 args.push_back(arg);
45 EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
46 }
47
48 /**
49 * @tc.name: BatteryDump002
50 * @tc.desc: Dump parameter is -u, MockUnplugged
51 * @tc.type: FUNC
52 * @tc.require: issueI5YZR1
53 */
54 HWTEST_F(BatteryDumpTest, BatteryDump002, TestSize.Level1)
55 {
56 int32_t fd = 1;
57 std::vector<std::u16string> args;
58 std::u16string arg = u"-u";
59 args.push_back(arg);
60 EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
61 }
62
63 /**
64 * @tc.name: BatteryDump003
65 * @tc.desc: Dump parameter is -r, ResetPlugged
66 * @tc.type: FUNC
67 * @tc.require: issueI5YZR1
68 */
69 HWTEST_F(BatteryDumpTest, BatteryDump003, TestSize.Level1)
70 {
71 int32_t fd = 1;
72 std::vector<std::u16string> args;
73 std::u16string arg = u"-r";
74 args.push_back(arg);
75 EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
76 }
77
78 /**
79 * @tc.name: BatteryDump004
80 * @tc.desc: Test functions Dump
81 * @tc.type: FUNC
82 * @tc.require: issueI5YZR1
83 */
84 static HWTEST_F(BatteryDumpTest, BatteryDump004, TestSize.Level1)
85 {
86 int32_t fd = 1;
87 std::vector<std::u16string> args;
88 std::u16string arg = u"-d";
89 args.push_back(arg);
90 EXPECT_EQ(g_service->Dump(fd, args), ERR_OK);
91 }
92
93 /*
94 * @tc.name: BatteryDump005
95 * @tc.desc: Test functions Dump
96 * @tc.type: FUNC
97 * @tc.require: issueI5YZR1
98 */
99 static HWTEST_F(BatteryDumpTest, BatteryDump005, TestSize.Level1)
100 {
101 int32_t fd = 1;
102 std::vector<std::u16string> args;
103 std::u16string arg = u"-l";
104 args.push_back(arg);
105 EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
106 }
107
108 /**
109 * @tc.name: BatteryDump006
110 * @tc.desc: Test functions Dump
111 * @tc.type: FUNC
112 * @tc.require: issueI5YZR1
113 */
114 static HWTEST_F(BatteryDumpTest, BatteryDump006, TestSize.Level1)
115 {
116 int32_t fd = 1;
117 std::vector<std::u16string> args;
118 std::u16string arg = u"-ls";
119 args.push_back(arg);
120 EXPECT_EQ(g_service->Dump(fd, args), ERR_NO_INIT);
121 }
122
123 /**
124 * @tc.name: BatteryDump007
125 * @tc.desc: Test functions Dump
126 * @tc.type: FUNC
127 * @tc.require: issueI5YZR1
128 */
129 static HWTEST_F(BatteryDumpTest, BatteryDump007, TestSize.Level1)
130 {
131 int32_t fd = 1;
132 std::vector<std::u16string> args;
133 g_service->Dump(fd, args);
134 }
135
136 /**
137 * @tc.name: BatteryDump008
138 * @tc.desc: Dump parameter is empty, Get battery information
139 * @tc.type: FUNC
140 * @tc.require: issueI5YZR1
141 */
142 HWTEST_F(BatteryDumpTest, BatteryDump008, TestSize.Level1)
143 {
144 BatteryDump& batteryDump = BatteryDump::GetInstance();
145 int32_t fd = 1;
146 std::vector<std::u16string> args;
147 EXPECT_FALSE(batteryDump.GetBatteryInfo(fd, g_service, args));
148 }
149
150 /**
151 * @tc.name: BatteryDump009
152 * @tc.desc: Dump parameter is -h, DumpBatteryHelp
153 * @tc.type: FUNC
154 * @tc.require: issueI5YZR1
155 */
156 HWTEST_F(BatteryDumpTest, BatteryDump009, TestSize.Level1)
157 {
158 BatteryDump& batteryDump = BatteryDump::GetInstance();
159 int32_t fd = 1;
160 std::vector<std::u16string> args;
161 std::u16string arg = u"-h";
162 args.push_back(arg);
163 EXPECT_TRUE(batteryDump.DumpBatteryHelp(fd, args));
164 }
165
166 /**
167 * @tc.name: BatteryDump010
168 * @tc.desc: Dump parameter is empty, GDumpBatteryHelp
169 * @tc.type: FUNC
170 * @tc.require: issueI5YZR1
171 */
172 HWTEST_F(BatteryDumpTest, BatteryDump010, TestSize.Level1)
173 {
174 BatteryDump& batteryDump = BatteryDump::GetInstance();
175 int32_t fd = 1;
176 std::vector<std::u16string> args;
177 EXPECT_FALSE(batteryDump.DumpBatteryHelp(fd, args));
178 }
179
180 /**
181 * @tc.name: BatteryDump011
182 * @tc.desc: Dump parameter is empty, MockUnplugged
183 * @tc.type: FUNC
184 * @tc.require: issueI5YZR1
185 */
186 HWTEST_F(BatteryDumpTest, BatteryDump011, TestSize.Level1)
187 {
188 BatteryDump& batteryDump = BatteryDump::GetInstance();
189 int32_t fd = 1;
190 std::vector<std::u16string> args;
191 EXPECT_FALSE(batteryDump.MockUnplugged(fd, g_service, args));
192 }
193
194 /**
195 * @tc.name: BatteryDump012
196 * @tc.desc: Dump parameter is empty, ResetPlugged
197 * @tc.type: FUNC
198 * @tc.require: issueI5YZR1
199 */
200 HWTEST_F(BatteryDumpTest, BatteryDump013, TestSize.Level1)
201 {
202 BatteryDump& batteryDump = BatteryDump::GetInstance();
203 int32_t fd = 1;
204 std::vector<std::u16string> args;
205 EXPECT_FALSE(batteryDump.ResetPlugged(fd, g_service, args));
206 }
207 } // namespace PowerMgr
208 } // namespace OHOS
209