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