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