1 /*
2 * Copyright (c) 2021-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 "usb_core_test.h"
17 #include <csignal>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21
22 #include "hilog_wrapper.h"
23 #include "if_system_ability_manager.h"
24 #include "ipc_skeleton.h"
25 #include "iservice_registry.h"
26 #include "string_ex.h"
27 #include "system_ability_definition.h"
28 #include "usb_common_test.h"
29 #include "usb_errors.h"
30 #include "usb_srv_client.h"
31 #include "usb_srv_support.h"
32
33 using namespace testing::ext;
34 using namespace OHOS::USB;
35 using namespace OHOS;
36 using namespace std;
37 using namespace OHOS::USB::Common;
38
39 namespace OHOS {
40 namespace USB {
41 namespace Core {
42 #ifdef USB_MANAGER_FEATURE_DEVICE
43 constexpr int32_t USB_FUNCTION_INVALID = -1;
44 #endif // USB_MANAGER_FEATURE_DEVICE
45 constexpr int32_t USB_PORT_ID = 0;
46 constexpr int32_t USB_PORT_ID_INVALID = -1;
47 constexpr int32_t USB_POWER_ROLE_INVALID = -1;
48 constexpr int32_t USB_DATA_ROLE_INVALID = -1;
49
SetUpTestCase(void)50 void UsbCoreTest::SetUpTestCase(void)
51 {
52 UsbCommonTest::GrantPermissionSysNative();
53 USB_HILOGI(MODULE_USB_SERVICE, "Start UsbCoreTest");
54 }
55
TearDownTestCase(void)56 void UsbCoreTest::TearDownTestCase(void)
57 {
58 USB_HILOGI(MODULE_USB_SERVICE, "End UsbCoreTest");
59 }
60
SetUp(void)61 void UsbCoreTest::SetUp(void) {}
62
TearDown(void)63 void UsbCoreTest::TearDown(void) {}
64
65 #ifdef USB_MANAGER_FEATURE_DEVICE
66 /**
67 * @tc.name: GetCurrentFunctions001
68 * @tc.desc: Test functions to GetCurrentFunctions()
69 * @tc.type: FUNC
70 */
71 HWTEST_F(UsbCoreTest, GetCurrentFunctions001, TestSize.Level1)
72 {
73 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetCurrentFunctions001 : SetConfig");
74 auto &instance = UsbSrvClient::GetInstance();
75 int32_t funcs = static_cast<int32_t>(UsbSrvSupport::FUNCTION_NONE);
76 int32_t ret = instance.GetCurrentFunctions(funcs);
77 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::ret=%{public}d", ret);
78 ASSERT_EQ(0, ret);
79 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetCurrentFunctions001 : SetConfig");
80 }
81
82 /**
83 * @tc.name: GetCurrentFunctions002
84 * @tc.desc: Test functions to GetCurrentFunctions()
85 * @tc.type: FUNC
86 */
87 HWTEST_F(UsbCoreTest, GetCurrentFunctions002, TestSize.Level1)
88 {
89 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetCurrentFunctions002 : SetConfig");
90 UsbCommonTest::GrantPermissionNormalNative();
91 auto &instance = UsbSrvClient::GetInstance();
92 int32_t funcs = static_cast<int32_t>(UsbSrvSupport::FUNCTION_NONE);
93 int32_t ret = instance.GetCurrentFunctions(funcs);
94 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::ret=%{public}d", ret);
95 ASSERT_NE(ret, 0);
96 UsbCommonTest::GrantPermissionSysNative();
97 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetCurrentFunctions002 : SetConfig");
98 }
99
100 /**
101 * @tc.name: GetCurrentFunctions003
102 * @tc.desc: Test functions to GetCurrentFunctions()
103 * @tc.type: FUNC
104 */
105 HWTEST_F(UsbCoreTest, GetCurrentFunctions003, TestSize.Level1)
106 {
107 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetCurrentFunctions003 : SetConfig");
108 UsbCommonTest::GrantNormalPermissionNative();
109 auto &instance = UsbSrvClient::GetInstance();
110 int32_t funcs = static_cast<int32_t>(UsbSrvSupport::FUNCTION_NONE);
111 int32_t ret = instance.GetCurrentFunctions(funcs);
112 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::ret=%{public}d", ret);
113 ASSERT_EQ(ret, 0);
114 UsbCommonTest::GrantPermissionSysNative();
115 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetCurrentFunctions003 : SetConfig");
116 }
117
118 /**
119 * @tc.name: GetCurrentFunctions004
120 * @tc.desc: Test functions to GetCurrentFunctions()
121 * @tc.type: FUNC
122 */
123 HWTEST_F(UsbCoreTest, GetCurrentFunctions004, TestSize.Level1)
124 {
125 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetCurrentFunctions004 : SetConfig");
126 UsbCommonTest::GrantSysNoPermissionNative();
127 auto &instance = UsbSrvClient::GetInstance();
128 int32_t funcs = static_cast<int32_t>(UsbSrvSupport::FUNCTION_NONE);
129 int32_t ret = instance.GetCurrentFunctions(funcs);
130 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::ret=%{public}d", ret);
131 ASSERT_NE(ret, 0);
132 UsbCommonTest::GrantPermissionSysNative();
133 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetCurrentFunctions004 : SetConfig");
134 }
135
136 /**
137 * @tc.name: SetCurrentFunctions001
138 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
139 * @tc.type: FUNC
140 */
141 HWTEST_F(UsbCoreTest, SetCurrentFunctions001, TestSize.Level1)
142 {
143 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions001 : SetConfig");
144 auto &instance = UsbSrvClient::GetInstance();
145 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_ACM);
146 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
147 ASSERT_EQ(0, isok);
148 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions001 : SetConfig");
149 }
150
151 /**
152 * @tc.name: SetCurrentFunctions002
153 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
154 * @tc.type: FUNC
155 */
156 HWTEST_F(UsbCoreTest, SetCurrentFunctions002, TestSize.Level1)
157 {
158 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions002 : SetConfig");
159 auto &instance = UsbSrvClient::GetInstance();
160 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_ECM);
161 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
162 ASSERT_EQ(0, isok);
163 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions002 : SetConfig");
164 }
165
166 /**
167 * @tc.name: SetCurrentFunctions003
168 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
169 * @tc.type: FUNC
170 */
171 HWTEST_F(UsbCoreTest, SetCurrentFunctions003, TestSize.Level1)
172 {
173 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions003 : SetConfig");
174 auto &instance = UsbSrvClient::GetInstance();
175 int32_t funcs = UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_ECM;
176 int32_t isok = instance.SetCurrentFunctions(funcs);
177 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
178 ASSERT_EQ(0, isok);
179 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions003 : SetConfig");
180 }
181
182 /**
183 * @tc.name: SetCurrentFunctions004
184 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
185 * @tc.type: FUNC
186 */
187 HWTEST_F(UsbCoreTest, SetCurrentFunctions004, TestSize.Level1)
188 {
189 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions004 : SetConfig");
190 auto &instance = UsbSrvClient::GetInstance();
191 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_HDC);
192 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
193 ASSERT_EQ(0, isok);
194 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions004 : SetConfig");
195 }
196
197 /**
198 * @tc.name: SetCurrentFunctions005
199 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
200 * @tc.type: FUNC
201 */
202 HWTEST_F(UsbCoreTest, SetCurrentFunctions005, TestSize.Level1)
203 {
204 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions005 : SetConfig");
205 auto &instance = UsbSrvClient::GetInstance();
206 int32_t funcs = UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_HDC;
207 int32_t isok = instance.SetCurrentFunctions(funcs);
208 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
209 ASSERT_EQ(0, isok);
210 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions005 : SetConfig");
211 }
212
213 /**
214 * @tc.name: SetCurrentFunctions006
215 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
216 * @tc.type: FUNC
217 */
218 HWTEST_F(UsbCoreTest, SetCurrentFunctions006, TestSize.Level1)
219 {
220 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions006 : SetConfig");
221 auto &instance = UsbSrvClient::GetInstance();
222 int32_t funcs = UsbSrvSupport::FUNCTION_ECM | UsbSrvSupport::FUNCTION_HDC;
223 int32_t isok = instance.SetCurrentFunctions(funcs);
224 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
225 ASSERT_EQ(0, isok);
226 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions006 : SetConfig");
227 }
228
229 /**
230 * @tc.name: SetCurrentFunctions007
231 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
232 * @tc.type: FUNC
233 */
234 HWTEST_F(UsbCoreTest, SetCurrentFunctions007, TestSize.Level1)
235 {
236 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions007 : SetConfig");
237 auto &instance = UsbSrvClient::GetInstance();
238 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_MTP);
239 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
240 ASSERT_EQ(0, isok);
241 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions007 : SetConfig");
242 }
243
244 /**
245 * @tc.name: SetCurrentFunctions008
246 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
247 * @tc.type: FUNC
248 */
249 HWTEST_F(UsbCoreTest, SetCurrentFunctions008, TestSize.Level1)
250 {
251 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions008 : SetConfig");
252 auto &instance = UsbSrvClient::GetInstance();
253 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_PTP);
254 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
255 ASSERT_EQ(0, isok);
256 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions008 : SetConfig");
257 }
258
259 /**
260 * @tc.name: SetCurrentFunctions009
261 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
262 * @tc.type: FUNC
263 */
264 HWTEST_F(UsbCoreTest, SetCurrentFunctions009, TestSize.Level1)
265 {
266 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions009 : SetConfig");
267 auto &instance = UsbSrvClient::GetInstance();
268 int32_t funcs = UsbSrvSupport::FUNCTION_MTP | UsbSrvSupport::FUNCTION_HDC;
269 int32_t isok = instance.SetCurrentFunctions(funcs);
270 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
271 ASSERT_EQ(0, isok);
272 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions009 : SetConfig");
273 }
274
275 /**
276 * @tc.name: SetCurrentFunctions010
277 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
278 * @tc.type: FUNC
279 */
280 HWTEST_F(UsbCoreTest, SetCurrentFunctions010, TestSize.Level1)
281 {
282 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions010 : SetConfig");
283 auto &instance = UsbSrvClient::GetInstance();
284 int32_t funcs = UsbSrvSupport::FUNCTION_PTP | UsbSrvSupport::FUNCTION_HDC;
285 int32_t isok = instance.SetCurrentFunctions(funcs);
286 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
287 ASSERT_EQ(0, isok);
288 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions010 : SetConfig");
289 }
290
291 /**
292 * @tc.name: SetCurrentFunctions011
293 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
294 * @tc.type: FUNC
295 */
296 HWTEST_F(UsbCoreTest, SetCurrentFunctions011, TestSize.Level1)
297 {
298 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions011 : SetConfig");
299 auto &instance = UsbSrvClient::GetInstance();
300 int32_t funcs = UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_MTP | UsbSrvSupport::FUNCTION_HDC;
301 int32_t isok = instance.SetCurrentFunctions(funcs);
302 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
303 ASSERT_EQ(0, isok);
304 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions011 : SetConfig");
305 }
306
307 /**
308 * @tc.name: SetCurrentFunctions012
309 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
310 * @tc.type: FUNC
311 */
312 HWTEST_F(UsbCoreTest, SetCurrentFunctions012, TestSize.Level1)
313 {
314 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions012 : SetConfig");
315 auto &instance = UsbSrvClient::GetInstance();
316 int32_t funcs = UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_PTP | UsbSrvSupport::FUNCTION_HDC;
317 int32_t isok = instance.SetCurrentFunctions(funcs);
318 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
319 ASSERT_EQ(0, isok);
320 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions012 : SetConfig");
321 }
322
323 /**
324 * @tc.name: SetCurrentFunctions013
325 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
326 * @tc.type: FUNC
327 */
328 HWTEST_F(UsbCoreTest, SetCurrentFunctions013, TestSize.Level1)
329 {
330 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions013 : SetConfig");
331 auto &instance = UsbSrvClient::GetInstance();
332 int32_t isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_NONE);
333 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", isok);
334 ASSERT_EQ(0, isok);
335 USB_HILOGI(MODULE_USB_SERVICE, "the function was set to none successfully");
336 isok = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_HDC);
337 ASSERT_EQ(0, isok);
338 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions013 : SetConfig");
339 }
340
341 /**
342 * @tc.name: SetCurrentFunctions014
343 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
344 * @tc.type: FUNC
345 */
346 HWTEST_F(UsbCoreTest, SetCurrentFunctions014, TestSize.Level1)
347 {
348 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions014 : SetConfig");
349 UsbCommonTest::GrantPermissionNormalNative();
350 auto &instance = UsbSrvClient::GetInstance();
351 int32_t ret = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_HDC);
352 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", ret);
353 ASSERT_NE(ret, 0);
354 UsbCommonTest::GrantPermissionSysNative();
355 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions014 : SetConfig");
356 }
357
358 /**
359 * @tc.name: SetCurrentFunctions015
360 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
361 * @tc.type: FUNC
362 */
363 HWTEST_F(UsbCoreTest, SetCurrentFunctions015, TestSize.Level1)
364 {
365 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions015 : SetConfig");
366 UsbCommonTest::GrantNormalPermissionNative();
367 auto &instance = UsbSrvClient::GetInstance();
368 int32_t ret = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_HDC);
369 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", ret);
370 ASSERT_EQ(ret, 0);
371 UsbCommonTest::GrantPermissionSysNative();
372 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions015 : SetConfig");
373 }
374
375 /**
376 * @tc.name: SetCurrentFunctions016
377 * @tc.desc: Test functions to SetCurrentFunctions(int32_t funcs)
378 * @tc.type: FUNC
379 */
380 HWTEST_F(UsbCoreTest, SetCurrentFunctions016, TestSize.Level1)
381 {
382 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetCurrentFunctions016 : SetConfig");
383 UsbCommonTest::GrantSysNoPermissionNative();
384 auto &instance = UsbSrvClient::GetInstance();
385 int32_t ret = instance.SetCurrentFunctions(UsbSrvSupport::FUNCTION_HDC);
386 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::SetCurrentFunctions=%{public}d", ret);
387 ASSERT_NE(ret, 0);
388 UsbCommonTest::GrantPermissionSysNative();
389 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetCurrentFunctions016 : SetConfig");
390 }
391
392 /**
393 * @tc.name: UsbFunctionsFromString001
394 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
395 * @tc.type: FUNC
396 */
397 HWTEST_F(UsbCoreTest, UsbFunctionsFromString001, TestSize.Level1)
398 {
399 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString001 : SetConfig");
400 auto &instance = UsbSrvClient::GetInstance();
401 int32_t funcCode = instance.UsbFunctionsFromString(UsbSrvSupport::FUNCTION_NAME_NONE);
402 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
403 ASSERT_NE(UEC_SERVICE_INVALID_VALUE, funcCode);
404 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString001 : SetConfig");
405 }
406
407 /**
408 * @tc.name: UsbFunctionsFromString002
409 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
410 * @tc.type: FUNC
411 */
412 HWTEST_F(UsbCoreTest, UsbFunctionsFromString002, TestSize.Level1)
413 {
414 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString002 : SetConfig");
415 auto &instance = UsbSrvClient::GetInstance();
416 int32_t funcCode = instance.UsbFunctionsFromString(UsbSrvSupport::FUNCTION_NAME_HDC);
417 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
418 ASSERT_NE(UEC_SERVICE_INVALID_VALUE, funcCode);
419 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString002 : SetConfig");
420 }
421
422 /**
423 * @tc.name: UsbFunctionsFromString003
424 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
425 * @tc.type: FUNC
426 */
427 HWTEST_F(UsbCoreTest, UsbFunctionsFromString003, TestSize.Level1)
428 {
429 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString003 : SetConfig");
430 auto &instance = UsbSrvClient::GetInstance();
431 int32_t funcCode = instance.UsbFunctionsFromString(UsbSrvSupport::FUNCTION_NAME_ACM);
432 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
433 ASSERT_NE(UEC_SERVICE_INVALID_VALUE, funcCode);
434 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString003 : SetConfig");
435 }
436
437 /**
438 * @tc.name: UsbFunctionsFromString004
439 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
440 * @tc.type: FUNC
441 */
442 HWTEST_F(UsbCoreTest, UsbFunctionsFromString004, TestSize.Level1)
443 {
444 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString004 : SetConfig");
445 auto &instance = UsbSrvClient::GetInstance();
446 int32_t funcCode = instance.UsbFunctionsFromString(UsbSrvSupport::FUNCTION_NAME_ECM);
447 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
448 ASSERT_NE(UEC_SERVICE_INVALID_VALUE, funcCode);
449 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString004 : SetConfig");
450 }
451
452 /**
453 * @tc.name: UsbFunctionsFromString005
454 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
455 * @tc.type: FUNC
456 */
457 HWTEST_F(UsbCoreTest, UsbFunctionsFromString005, TestSize.Level1)
458 {
459 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString005 : SetConfig");
460 auto &instance = UsbSrvClient::GetInstance();
461 std::string funcs = "qwerts";
462 int32_t funcCode = instance.UsbFunctionsFromString(funcs);
463 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
464 ASSERT_EQ(UEC_SERVICE_INVALID_VALUE, funcCode);
465 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString005 : SetConfig");
466 }
467
468 /**
469 * @tc.name: UsbFunctionsFromString006
470 * @tc.desc: Test functions to UsbFunctionsFromString(string funcs)
471 * @tc.type: FUNC
472 */
473 HWTEST_F(UsbCoreTest, UsbFunctionsFromString006, TestSize.Level1)
474 {
475 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsFromString006 : SetConfig");
476 auto &instance = UsbSrvClient::GetInstance();
477 std::string funcs = "zxcbvx";
478 int32_t funcCode = instance.UsbFunctionsFromString(funcs);
479 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::functionsFromString=%{public}d", funcCode);
480 ASSERT_EQ(UEC_SERVICE_INVALID_VALUE, funcCode);
481 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsFromString006 : SetConfig");
482 }
483
484 /**
485 * @tc.name: UsbFunctionsToString001
486 * @tc.desc: Test functions to UsbFunctionsToString(int32_t funcs)
487 * @tc.type: FUNC
488 */
489 HWTEST_F(UsbCoreTest, UsbFunctionsToString001, TestSize.Level1)
490 {
491 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsToString001 : SetConfig");
492 auto &instance = UsbSrvClient::GetInstance();
493 std::string funcName = instance.UsbFunctionsToString(UsbSrvSupport::FUNCTION_NONE);
494 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbFunctionsToString=%{public}s", funcName.c_str());
495 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbFunctionsToString=%{public}zu", funcName.size());
496 ASSERT_TRUE(!(funcName.empty()));
497 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsToString001 : SetConfig");
498 }
499
500 /**
501 * @tc.name: UsbFunctionsToString002
502 * @tc.desc: Test functions to UsbFunctionsToString(int32_t funcs)
503 * @tc.type: FUNC
504 */
505 HWTEST_F(UsbCoreTest, UsbFunctionsToString002, TestSize.Level1)
506 {
507 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsToString002 : SetConfig");
508 auto &instance = UsbSrvClient::GetInstance();
509 std::string funcName = instance.UsbFunctionsToString(UsbSrvSupport::FUNCTION_HDC);
510 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::UsbFunctionsToString=%{public}s", funcName.c_str());
511 ASSERT_TRUE(!(funcName.empty()));
512 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsToString002 : SetConfig");
513 }
514
515 /**
516 * @tc.name: UsbFunctionsToString003
517 * @tc.desc: Test functions to UsbFunctionsToString(int32_t funcs)
518 * @tc.type: FUNC
519 */
520 HWTEST_F(UsbCoreTest, UsbFunctionsToString003, TestSize.Level1)
521 {
522 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsToString003 : SetConfig");
523 auto &instance = UsbSrvClient::GetInstance();
524 std::string funcName = instance.UsbFunctionsToString(UsbSrvSupport::FUNCTION_ACM);
525 USB_HILOGI(MODULE_USB_SERVICE, "UsbFunctionServiceTest::UsbFunctionsToString=%{public}s", funcName.c_str());
526 ASSERT_TRUE(!(funcName.empty()));
527 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsToString003 : SetConfig");
528 }
529
530 /**
531 * @tc.name: UsbFunctionsToString004
532 * @tc.desc: Test functions to UsbFunctionsToString(int32_t funcs)
533 * @tc.type: FUNC
534 */
535 HWTEST_F(UsbCoreTest, UsbFunctionsToString004, TestSize.Level1)
536 {
537 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsToString004 : SetConfig");
538 auto &instance = UsbSrvClient::GetInstance();
539 std::string funcName = instance.UsbFunctionsToString(UsbSrvSupport::FUNCTION_ECM);
540 USB_HILOGI(MODULE_USB_SERVICE, "UsbFunctionServiceTest::UsbFunctionsToString=%{public}s", funcName.c_str());
541 ASSERT_TRUE(!(funcName.empty()));
542 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsToString004 : SetConfig");
543 }
544
545 /**
546 * @tc.name: UsbFunctionsToString005
547 * @tc.desc: Test functions to UsbFunctionsToString(int32_t funcs)
548 * @tc.type: FUNC
549 */
550 HWTEST_F(UsbCoreTest, UsbFunctionsToString005, TestSize.Level1)
551 {
552 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : UsbFunctionsToString005 : SetConfig");
553 auto &instance = UsbSrvClient::GetInstance();
554 std::string funcName = instance.UsbFunctionsToString(USB_FUNCTION_INVALID);
555 USB_HILOGI(MODULE_USB_SERVICE, "UsbFunctionServiceTest::UsbFunctionsToString=%{public}s", funcName.c_str());
556 ASSERT_TRUE(!(funcName.empty()));
557 USB_HILOGI(MODULE_USB_SERVICE, "Case End : UsbFunctionsToString005 : SetConfig");
558 }
559 #endif // USB_MANAGER_FEATURE_DEVICE
560
561 /**
562 * @tc.name: GetPorts001
563 * @tc.desc: Test functions to GetPorts
564 * @tc.desc: int32_t GetPorts(std::vector<UsbPort *> &usbports);
565 * @tc.desc: 正向测试:参数正确
566 * @tc.type: FUNC
567 */
568 HWTEST_F(UsbCoreTest, GetPorts001, TestSize.Level1)
569 {
570 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetPorts001 : GetPorts");
571 auto &usbSrvClient = UsbSrvClient::GetInstance();
572 std::vector<UsbPort> portlist;
573 auto ports = usbSrvClient.GetPorts(portlist);
574 USB_HILOGD(MODULE_USB_SERVICE, "Get UsbPort size=%{public}zu", portlist.size());
575 ASSERT_NE(ports, 0);
576 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetPorts001 : GetPorts");
577 }
578
579 /**
580 * @tc.name: GetSupportedModes001
581 * @tc.desc: Test functions to GetSupportedModes
582 * @tc.desc: int32_t GetSupportedModes(int32_t portId, int32_t &result);
583 * @tc.desc: 正向测试:参数正确
584 * @tc.type: FUNC
585 */
586
587 HWTEST_F(UsbCoreTest, GetSupportedModes001, TestSize.Level1)
588 {
589 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetSupportedModes001 : GetSupportedModes");
590 auto &UsbSrvClient = UsbSrvClient::GetInstance();
591 int32_t result;
592 auto modes = UsbSrvClient.GetSupportedModes(UsbSrvSupport::PORT_MODE_NONE, result);
593 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", modes);
594 ASSERT_NE(modes, 0);
595 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetSupportedModes001 : GetSupportedModes");
596 }
597
598 /**
599 * @tc.name: GetSupportedModes002
600 * @tc.desc: Test functions to GetSupportedModes
601 * @tc.desc: int32_t GetSupportedModes(int32_t portId, int32_t &result);
602 * @tc.desc: 反向测试:portid错误
603 * @tc.type: FUNC
604 */
605
606 HWTEST_F(UsbCoreTest, GetSupportedModes002, TestSize.Level1)
607 {
608 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetSupportedModes002 : GetSupportedModes");
609 auto &UsbSrvClient = UsbSrvClient::GetInstance();
610 int32_t result;
611 auto modes = UsbSrvClient.GetSupportedModes(USB_PORT_ID_INVALID, result);
612 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", modes);
613 ASSERT_NE(modes, 0);
614 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetSupportedModes002 : GetSupportedModes");
615 }
616
617 /**
618 * @tc.name: GetSupportedModes003
619 * @tc.desc: Test functions to GetSupportedModes
620 * @tc.desc: int32_t GetSupportedModes(int32_t portId, int32_t &result);
621 * @tc.desc: 反向测试:portid错误
622 * @tc.type: FUNC
623 */
624
625 HWTEST_F(UsbCoreTest, GetSupportedModes003, TestSize.Level1)
626 {
627 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetSupportedModes003 : GetSupportedModes");
628 auto &UsbSrvClient = UsbSrvClient::GetInstance();
629 int32_t result = 0;
630 auto modes = UsbSrvClient.GetSupportedModes(0xFFFFFFFF, result); // 0xFFFFFFFF:Maximum anomaly portId
631 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", modes);
632 ASSERT_NE(modes, 0);
633 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetSupportedModes003 : GetSupportedModes");
634 }
635
636 /**
637 * @tc.name: GetSupportedModes004
638 * @tc.desc: Test functions to GetSupportedModes
639 * @tc.desc: int32_t GetSupportedModes(int32_t portId, int32_t &result);
640 * @tc.desc: 正向测试:参数正确
641 * @tc.type: FUNC
642 */
643
644 HWTEST_F(UsbCoreTest, GetSupportedModes004, TestSize.Level1)
645 {
646 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : GetSupportedModes004 : GetSupportedModes");
647 auto &UsbSrvClient = UsbSrvClient::GetInstance();
648 int32_t result;
649 auto modes = UsbSrvClient.GetSupportedModes(USB_PORT_ID, result);
650 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", modes);
651 ASSERT_NE(0, modes);
652 USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetSupportedModes004 : GetSupportedModes");
653 }
654
655 /**
656 * @tc.name: SetPortRole001
657 * @tc.desc: Test functions to SetPortRole
658 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
659 * @tc.desc: 正向测试:参数正确
660 * @tc.type: FUNC
661 */
662
663 HWTEST_F(UsbCoreTest, SetPortRole001, TestSize.Level1)
664 {
665 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole001 : SetPortRole");
666 auto &UsbSrvClient = UsbSrvClient::GetInstance();
667 auto ret = UsbSrvClient.SetPortRole(USB_PORT_ID, UsbSrvSupport::POWER_ROLE_SOURCE, UsbSrvSupport::DATA_ROLE_HOST);
668 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
669 ret = UsbCommonTest::SwitchErrCode(ret);
670 ASSERT_NE(0, ret);
671 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole001 : SetPortRole");
672 }
673
674 /**
675 * @tc.name: SetPortRole002
676 * @tc.desc: Test functions to SetPortRole
677 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
678 * @tc.desc: 反向测试:portid错误
679 * @tc.type: FUNC
680 */
681
682 HWTEST_F(UsbCoreTest, SetPortRole002, TestSize.Level1)
683 {
684 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole002 : SetPortRole");
685 auto &UsbSrvClient = UsbSrvClient::GetInstance();
686 auto ret = UsbSrvClient.SetPortRole(
687 USB_PORT_ID_INVALID, UsbSrvSupport::POWER_ROLE_SOURCE, UsbSrvSupport::DATA_ROLE_HOST);
688 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
689 ret = UsbCommonTest::SwitchErrCode(ret);
690 ASSERT_NE(ret, 0);
691 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole002 : SetPortRole");
692 }
693
694 /**
695 * @tc.name: SetPortRole003
696 * @tc.desc: Test functions to SetPortRole
697 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
698 * @tc.desc: 反向测试:powerRole错误
699 * @tc.type: FUNC
700 */
701
702 HWTEST_F(UsbCoreTest, SetPortRole003, TestSize.Level1)
703 {
704 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole003 : SetPortRole");
705 auto &UsbSrvClient = UsbSrvClient::GetInstance();
706 auto ret = UsbSrvClient.SetPortRole(
707 USB_PORT_ID, USB_POWER_ROLE_INVALID, UsbSrvSupport::DATA_ROLE_DEVICE);
708 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
709 ret = UsbCommonTest::SwitchErrCode(ret);
710 ASSERT_NE(ret, 0);
711 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole003 : SetPortRole");
712 }
713
714 /**
715 * @tc.name: SetPortRole004
716 * @tc.desc: Test functions to SetPortRole
717 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
718 * @tc.desc: 反向测试:dataRole错误
719 * @tc.type: FUNC
720 */
721 HWTEST_F(UsbCoreTest, SetPortRole004, TestSize.Level1)
722 {
723 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole004 : SetPortRole");
724 auto &UsbSrvClient = UsbSrvClient::GetInstance();
725 auto ret = UsbSrvClient.SetPortRole(
726 USB_PORT_ID, UsbSrvSupport::POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
727 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
728 ret = UsbCommonTest::SwitchErrCode(ret);
729 ASSERT_NE(ret, 0);
730 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole004 : SetPortRole");
731 }
732
733 /**
734 * @tc.name: SetPortRole005
735 * @tc.desc: Test functions to SetPortRole
736 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
737 * @tc.desc: 反向测试:参数异常,portId、powerRole错误
738 * @tc.type: FUNC
739 */
740 HWTEST_F(UsbCoreTest, SetPortRole005, TestSize.Level1)
741 {
742 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole005 : SetPortRole");
743 auto &UsbSrvClient = UsbSrvClient::GetInstance();
744 auto ret = UsbSrvClient.SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
745 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
746 ret = UsbCommonTest::SwitchErrCode(ret);
747 ASSERT_NE(ret, 0);
748 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole005 : SetPortRole");
749 }
750
751 /**
752 * @tc.name: SetPortRole006
753 * @tc.desc: Test functions to SetPortRole
754 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
755 * @tc.desc: 反向测试:powerRole、dataRole错误
756 * @tc.type: FUNC
757 */
758 HWTEST_F(UsbCoreTest, SetPortRole006, TestSize.Level1)
759 {
760 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole006 : SetPortRole");
761 auto &UsbSrvClient = UsbSrvClient::GetInstance();
762 auto ret = UsbSrvClient.SetPortRole(USB_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
763 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
764 ret = UsbCommonTest::SwitchErrCode(ret);
765 ASSERT_NE(ret, 0);
766 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole006 : SetPortRole");
767 }
768
769 /**
770 * @tc.name: SetPortRole007
771 * @tc.desc: Test functions to SetPortRole
772 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
773 * @tc.desc: 反向测试:powerRole、dataRole错误
774 * @tc.type: FUNC
775 */
776 HWTEST_F(UsbCoreTest, SetPortRole007, TestSize.Level1)
777 {
778 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole007 : SetPortRole");
779 auto &UsbSrvClient = UsbSrvClient::GetInstance();
780 auto ret = UsbSrvClient.SetPortRole(USB_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
781 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
782 ret = UsbCommonTest::SwitchErrCode(ret);
783 ASSERT_NE(ret, 0);
784 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole007 : SetPortRole");
785 }
786
787 /**
788 * @tc.name: SetPortRole008
789 * @tc.desc: Test functions to SetPortRole
790 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole);
791 * @tc.desc: 正向测试:参数正确
792 * @tc.type: FUNC
793 */
794 HWTEST_F(UsbCoreTest, SetPortRole008, TestSize.Level1)
795 {
796 USB_HILOGI(MODULE_USB_SERVICE, "Case Start : SetPortRole008 : SetPortRole");
797 auto &UsbSrvClient = UsbSrvClient::GetInstance();
798 auto ret = UsbSrvClient.SetPortRole(
799 USB_PORT_ID, UsbSrvSupport::DATA_ROLE_DEVICE, UsbSrvSupport::POWER_ROLE_SINK);
800 USB_HILOGI(MODULE_USB_SERVICE, "UsbCoreTest::status=%{public}d", ret);
801 ret = UsbCommonTest::SwitchErrCode(ret);
802 ASSERT_NE(0, ret);
803 USB_HILOGI(MODULE_USB_SERVICE, "Case End : SetPortRole008 : SetPortRole");
804 }
805 } // Core
806 } // USB
807 } // OHOS
808