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 "UTTest_dm_dfx.h"
17
18 namespace OHOS {
19 namespace DistributedHardware {
20 constexpr const char* ARGS_HELP_INFO = "-help";
21 constexpr const char* HIDUMPER_GET_TRUSTED_LIST_INFO = "-getTrustlist";
SetUp()22 void DmDfxTest::SetUp()
23 {
24 }
TearDown()25 void DmDfxTest::TearDown()
26 {
27 }
SetUpTestCase()28 void DmDfxTest::SetUpTestCase()
29 {
30 }
TearDownTestCase()31 void DmDfxTest::TearDownTestCase()
32 {
33 }
34
35 namespace {
36
37 /**
38 * @tc.name: ShowHelp_001
39 * @tc.desc: Return DM_OK
40 * @tc.type: FUNC
41 * @tc.require: AR000GHSJK
42 */
43 HWTEST_F(DmDfxTest, ShowHelp_001, testing::ext::TestSize.Level0)
44 {
45 std::string result = "";
46 int32_t ret = HiDumpHelper::GetInstance().ShowHelp(result);
47 EXPECT_EQ(ret, DM_OK);
48 }
49
50 /**
51 * @tc.name: ShowIllealInfomation_001
52 * @tc.desc: Return DM_OK
53 * @tc.type: FUNC
54 * @tc.require: AR000GHSJK
55 */
56 HWTEST_F(DmDfxTest, ShowIllealInfomation_001, testing::ext::TestSize.Level0)
57 {
58 std::string result = "";
59 int32_t ret = HiDumpHelper::GetInstance().ShowIllealInfomation(result);
60 EXPECT_EQ(ret, DM_OK);
61 }
62
63 /**
64 * @tc.name: GetArgsType_001
65 * @tc.desc: Return ERR_DM_FAILED
66 * @tc.type: FUNC
67 * @tc.require: AR000GHSJK
68 */
69 HWTEST_F(DmDfxTest, GetArgsType_001, testing::ext::TestSize.Level0)
70 {
71 std::vector<std::string> args;
72 std::vector<HidumperFlag> Flag;
73 int32_t ret = HiDumpHelper::GetInstance().GetArgsType(args, Flag);
74 EXPECT_EQ(ret, ERR_DM_FAILED);
75 }
76
77 /**
78 * @tc.name: GetArgsType_002
79 * @tc.desc: Return ERR_DM_FAILED
80 * @tc.type: FUNC
81 * @tc.require: AR000GHSJK
82 */
83 HWTEST_F(DmDfxTest, GetArgsType_002, testing::ext::TestSize.Level0)
84 {
85 std::string str = std::string(ARGS_HELP_INFO);
86 std::vector<std::string> args;
87 args.push_back(str);
88 std::vector<HidumperFlag> Flag;
89 int32_t ret = HiDumpHelper::GetInstance().GetArgsType(args, Flag);
90 EXPECT_EQ(ret, ERR_DM_FAILED);
91 }
92
93 /**
94 * @tc.name: SetNodeInfo_001
95 * @tc.desc: HiDumpHelper::GetInstance().nodeInfo_.size() plus 1
96 * @tc.type: FUNC
97 * @tc.require: AR000GHSJK
98 */
99 HWTEST_F(DmDfxTest, SetNodeInfo_001, testing::ext::TestSize.Level0)
100 {
101 DmDeviceInfo deviceInfo;
102 HiDumpHelper::GetInstance().SetNodeInfo(deviceInfo);
103 EXPECT_EQ(HiDumpHelper::GetInstance().nodeInfos_.size(), 1);
104 }
105
106 /**
107 * @tc.name: ShowAllLoadTrustedList_001
108 * @tc.desc: Return DM_OK
109 * @tc.type: FUNC
110 * @tc.require: AR000GHSJK
111 */
112 HWTEST_F(DmDfxTest, ShowAllLoadTrustedList_001, testing::ext::TestSize.Level0)
113 {
114 std::string result = "";
115 int32_t ret = HiDumpHelper::GetInstance().ShowAllLoadTrustedList(result);
116 EXPECT_TRUE(!result.empty());
117 EXPECT_EQ(ret, DM_OK);
118 }
119
120 /**
121 * @tc.name: ShowAllLoadTrustedList_002
122 * @tc.desc: Return DM_OK
123 * @tc.type: FUNC
124 * @tc.require: AR000GHSJK
125 */
126 HWTEST_F(DmDfxTest, ShowAllLoadTrustedList_002, testing::ext::TestSize.Level0)
127 {
128 std::string result = "";
129 DmDeviceInfo deviceInfo;
130 deviceInfo.deviceTypeId = 1;
131 deviceInfo.range = 11;
132 HiDumpHelper::GetInstance().nodeInfos_.push_back(deviceInfo);
133 int32_t ret = HiDumpHelper::GetInstance().ShowAllLoadTrustedList(result);
134 EXPECT_TRUE(!result.empty());
135 EXPECT_EQ(ret, DM_OK);
136 }
137
138 /**
139 * @tc.name: GetDeviceType_001
140 * @tc.desc: set deviceTypeId id 8, Return string is not empty
141 * @tc.type: FUNC
142 * @tc.require: AR000GHSJK
143 */
144 HWTEST_F(DmDfxTest, GetDeviceType_001, testing::ext::TestSize.Level0)
145 {
146 int32_t deviceTypeId = 8;
147 std::string ret = HiDumpHelper::GetInstance().GetDeviceType(deviceTypeId);
148 EXPECT_TRUE(!ret.empty());
149 }
150
151 /**
152 * @tc.name: GetDeviceType_002
153 * @tc.desc: set deviceTypeId id 10000, Return string is not empty
154 * @tc.type: FUNC
155 * @tc.require: AR000GHSJK
156 */
157 HWTEST_F(DmDfxTest, GetDeviceType_002, testing::ext::TestSize.Level0)
158 {
159 int32_t deviceTypeId = 10000;
160 std::string ret = HiDumpHelper::GetInstance().GetDeviceType(deviceTypeId);
161 EXPECT_TRUE(ret.empty());
162 }
163
164 /**
165 * @tc.name: ProcessDump_001
166 * @tc.desc: Return DM_OK
167 * @tc.type: FUNC
168 * @tc.require: AR000GHSJK
169 */
170 HWTEST_F(DmDfxTest, ProcessDump_001, testing::ext::TestSize.Level0)
171 {
172 HidumperFlag flag = HidumperFlag::HIDUMPER_GET_HELP;
173 std::string result;
174 int32_t ret = HiDumpHelper::GetInstance().ProcessDump(flag, result);
175 EXPECT_EQ(ret, DM_OK);
176 }
177
178 /**
179 * @tc.name: ProcessDump_002
180 * @tc.desc: Return DM_OK
181 * @tc.type: FUNC
182 * @tc.require: AR000GHSJK
183 */
184 HWTEST_F(DmDfxTest, ProcessDump_002, testing::ext::TestSize.Level0)
185 {
186 HidumperFlag flag = HidumperFlag::HIDUMPER_GET_TRUSTED_LIST;
187 std::string result;
188 int32_t ret = HiDumpHelper::GetInstance().ProcessDump(flag, result);
189 EXPECT_EQ(ret, DM_OK);
190 }
191
192 /**
193 * @tc.name: ProcessDump_003
194 * @tc.desc: Return DM_OK
195 * @tc.type: FUNC
196 * @tc.require: AR000GHSJK
197 */
198 HWTEST_F(DmDfxTest, ProcessDump_003, testing::ext::TestSize.Level0)
199 {
200 HidumperFlag flag = HidumperFlag::HIDUMPER_UNKNOWN;
201 std::string result;
202 int32_t ret = HiDumpHelper::GetInstance().ProcessDump(flag, result);
203 EXPECT_EQ(ret, DM_OK);
204 }
205
206 /**
207 * @tc.name: HiDump_001
208 * @tc.desc: Return DM_OK
209 * @tc.type: FUNC
210 * @tc.require: AR000GHSJK
211 */
212 HWTEST_F(DmDfxTest, HiDump_001, testing::ext::TestSize.Level0)
213 {
214 std::vector<std::string> args;
215 std::string result;
216 int32_t ret = HiDumpHelper::GetInstance().HiDump(args, result);
217 EXPECT_EQ(ret, DM_OK);
218 }
219
220 /**
221 * @tc.name: HiDump_002
222 * @tc.desc: Return DM_OK
223 * @tc.type: FUNC
224 * @tc.require: AR000GHSJK
225 */
226 HWTEST_F(DmDfxTest, HiDump_002, testing::ext::TestSize.Level0)
227 {
228 std::string str = "argsTest";
229 std::vector<std::string> args;
230 args.push_back(str);
231 std::string result;
232 int32_t ret = HiDumpHelper::GetInstance().HiDump(args, result);
233 EXPECT_EQ(ret, DM_OK);
234 }
235
236 /**
237 * @tc.name: HiDump_003
238 * @tc.desc: Return DM_OK
239 * @tc.type: FUNC
240 * @tc.require: AR000GHSJK
241 */
242 HWTEST_F(DmDfxTest, HiDump_003, testing::ext::TestSize.Level0)
243 {
244 std::string str = std::string(HIDUMPER_GET_TRUSTED_LIST_INFO);
245 std::vector<std::string> args;
246 args.push_back(str);
247 std::string result;
248 int32_t ret = HiDumpHelper::GetInstance().HiDump(args, result);
249 EXPECT_EQ(ret, DM_OK);
250 }
251 } // namespace
252 } // namespace DistributedHardware
253 } // namespace OHOS