1 /*
2 * Copyright (c) 2021-2023 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 "usbd_function_test.h"
17
18 #include <iostream>
19
20 #include "hdf_log.h"
21 #include "if_system_ability_manager.h"
22 #include "system_ability_definition.h"
23 #include "usbd_function.h"
24 #include "usbd_port.h"
25 #include "v1_0/iusb_interface.h"
26 #include "v1_0/usb_types.h"
27
28 constexpr int32_t SLEEP_TIME = 3;
29 constexpr int32_t USB_FUNCTION_INVALID = -1;
30 constexpr int32_t USB_PORT_ID_INVALID = 2;
31 constexpr int32_t USB_POWER_ROLE_INVALID = 4;
32 constexpr int32_t USB_DATA_ROLE_INVALID = 5;
33 constexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
34
35 using namespace testing::ext;
36 using namespace OHOS;
37 using namespace std;
38 using namespace OHOS::HDI::Usb::V1_0;
39
40 namespace {
41 sptr<IUsbInterface> g_usbInterface = nullptr;
42
SwitchErrCode(int32_t ret)43 int32_t SwitchErrCode(int32_t ret)
44 {
45 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
46 }
47
SetUpTestCase(void)48 void UsbdFunctionTest::SetUpTestCase(void)
49 {
50 g_usbInterface = IUsbInterface::Get();
51 if (g_usbInterface == nullptr) {
52 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
53 exit(0);
54 }
55 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
56 sleep(SLEEP_TIME);
57 HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
58 ret = SwitchErrCode(ret);
59 ASSERT_EQ(0, ret);
60 if (ret != 0) {
61 exit(0);
62 }
63 }
64
TearDownTestCase(void)65 void UsbdFunctionTest::TearDownTestCase(void) {}
66
SetUp(void)67 void UsbdFunctionTest::SetUp(void) {}
68
TearDown(void)69 void UsbdFunctionTest::TearDown(void) {}
70
71 /**
72 * @tc.name: UsbdGetCurrentFunctions001
73 * @tc.desc: Test functions to GetCurrentFunctions
74 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
75 * @tc.desc: Positive test: parameters correctly
76 * @tc.type: FUNC
77 */
78 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, TestSize.Level1)
79 {
80 int32_t func = USB_FUNCTION_NONE;
81 auto ret = g_usbInterface->GetCurrentFunctions(func);
82 HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
83 ASSERT_EQ(0, ret);
84 }
85
86 /**
87 * @tc.name: UsbdGetCurrentFunctions002
88 * @tc.desc: Test functions to GetCurrentFunctions
89 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
90 * @tc.desc: Positive test: parameters correctly
91 * @tc.type: FUNC
92 */
93 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, TestSize.Level1)
94 {
95 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
96 HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
97 ASSERT_EQ(0, ret);
98 int32_t func = USB_FUNCTION_NONE;
99 ret = g_usbInterface->GetCurrentFunctions(func);
100 HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
101 ASSERT_EQ(0, ret);
102 }
103
104 /**********************************************************************************************************/
105
106 /**
107 * @tc.name: UsbdSetCurrentFunctions001
108 * @tc.desc: Test functions to SetCurrentFunctions
109 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
110 * @tc.desc: Positive test: parameters correctly
111 * @tc.type: FUNC
112 */
113 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, TestSize.Level1)
114 {
115 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
116 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
117 ASSERT_EQ(0, ret);
118 }
119
120 /**
121 * @tc.name: UsbdSetCurrentFunctions002
122 * @tc.desc: Test functions to SetCurrentFunctions
123 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
124 * @tc.desc: Negative test: parameters exception, funcs error
125 * @tc.type: FUNC
126 */
127 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, TestSize.Level1)
128 {
129 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
130 HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d", __LINE__, ret);
131 ASSERT_NE(ret, 0);
132 }
133 /**
134 * @tc.name: UsbdSetCurrentFunctions003
135 * @tc.desc: Test functions to SetCurrentFunctions
136 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
137 * @tc.desc: Positive test: parameters correctly
138 * @tc.type: FUNC
139 */
140 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, TestSize.Level1)
141 {
142 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
143 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
144 ASSERT_EQ(0, ret);
145 }
146
147 /**
148 * @tc.name: UsbdSetCurrentFunctions004
149 * @tc.desc: Test functions to SetCurrentFunctions
150 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
151 * @tc.desc: Positive test: parameters correctly
152 * @tc.type: FUNC
153 */
154 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, TestSize.Level1)
155 {
156 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
157 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
158 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
159 ASSERT_EQ(0, ret);
160 }
161
162 /**
163 * @tc.name: UsbdSetCurrentFunctions005
164 * @tc.desc: Test functions to SetCurrentFunctions
165 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
166 * @tc.desc: Positive test: parameters correctly
167 * @tc.type: FUNC
168 */
169 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, TestSize.Level1)
170 {
171 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
172 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
173 ASSERT_EQ(0, ret);
174 }
175
176 /**
177 * @tc.name: UsbdSetCurrentFunctions006
178 * @tc.desc: Test functions to SetCurrentFunctions
179 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
180 * @tc.desc: Positive test: parameters correctly
181 * @tc.type: FUNC
182 */
183 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, TestSize.Level1)
184 {
185 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
186 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
187 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
188 ASSERT_EQ(0, ret);
189 }
190
191 /**
192 * @tc.name: UsbdSetCurrentFunctions007
193 * @tc.desc: Test functions to SetCurrentFunctions
194 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
195 * @tc.desc: Positive test: parameters correctly
196 * @tc.type: FUNC
197 */
198 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, TestSize.Level1)
199 {
200 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
201 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
202 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
203 ASSERT_EQ(0, ret);
204 }
205
206 /**
207 * @tc.name: UsbdSetCurrentFunctions008
208 * @tc.desc: Test functions to SetCurrentFunctions
209 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
210 * @tc.desc: Positive test: parameters correctly
211 * @tc.type: FUNC
212 */
213 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions008, TestSize.Level1)
214 {
215 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
216 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions008 %{public}d ret=%{public}d", __LINE__, ret);
217 ASSERT_EQ(0, ret);
218 }
219
220 /**
221 * @tc.name: UsbdSetCurrentFunctions009
222 * @tc.desc: Test functions to SetCurrentFunctions
223 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
224 * @tc.desc: Positive test: parameters correctly
225 * @tc.type: FUNC
226 */
227 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions009, TestSize.Level1)
228 {
229 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
230 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions009 %{public}d ret=%{public}d", __LINE__, ret);
231 ASSERT_EQ(0, ret);
232 }
233
234 /**
235 * @tc.name: UsbdSetCurrentFunctions010
236 * @tc.desc: Test functions to SetCurrentFunctions
237 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
238 * @tc.desc: Positive test: parameters correctly
239 * @tc.type: FUNC
240 */
241 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions010, TestSize.Level1)
242 {
243 int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
244 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
245 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions010 %{public}d ret=%{public}d", __LINE__, ret);
246 ASSERT_EQ(0, ret);
247 }
248
249 /**
250 * @tc.name: UsbdSetCurrentFunctions011
251 * @tc.desc: Test functions to SetCurrentFunctions
252 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
253 * @tc.desc: Positive test: parameters correctly
254 * @tc.type: FUNC
255 */
256 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions011, TestSize.Level1)
257 {
258 int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
259 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
260 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions011 %{public}d ret=%{public}d", __LINE__, ret);
261 ASSERT_EQ(0, ret);
262 }
263
264 /**
265 * @tc.name: UsbdSetCurrentFunctions012
266 * @tc.desc: Test functions to SetCurrentFunctions
267 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
268 * @tc.desc: Positive test: parameters correctly
269 * @tc.type: FUNC
270 */
271 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions012, TestSize.Level1)
272 {
273 int32_t funcs = USB_FUNCTION_MTP;
274 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
275 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions012 %{public}d ret=%{public}d", __LINE__, ret);
276 ASSERT_EQ(0, ret);
277 }
278
279 /**
280 * @tc.name: UsbdSetCurrentFunctions013
281 * @tc.desc: Test functions to SetCurrentFunctions
282 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
283 * @tc.desc: Positive test: parameters correctly
284 * @tc.type: FUNC
285 */
286 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions013, TestSize.Level1)
287 {
288 int32_t funcs = USB_FUNCTION_PTP;
289 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
290 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 %{public}d ret=%{public}d", __LINE__, ret);
291 ASSERT_EQ(0, ret);
292 }
293
294 /**
295 * @tc.name: UsbdSetCurrentFunctions014
296 * @tc.desc: Test functions to SetCurrentFunctions
297 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
298 * @tc.desc: Positive test: parameters correctly
299 * @tc.type: FUNC
300 */
301 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions014, TestSize.Level1)
302 {
303 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
304 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
305 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions014 %{public}d ret=%{public}d", __LINE__, ret);
306 ASSERT_EQ(0, ret);
307 }
308
309 /**
310 * @tc.name: UsbdSetCurrentFunctions015
311 * @tc.desc: Test functions to SetCurrentFunctions
312 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
313 * @tc.desc: Positive test: parameters correctly
314 * @tc.type: FUNC
315 */
316 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions015, TestSize.Level1)
317 {
318 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
319 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
320 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions015 %{public}d ret=%{public}d", __LINE__, ret);
321 ASSERT_EQ(0, ret);
322 }
323
324 /**
325 * @tc.name: UsbdSetCurrentFunctions016
326 * @tc.desc: Test functions to SetCurrentFunctions
327 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
328 * @tc.desc: Positive test: parameters correctly
329 * @tc.type: FUNC
330 */
331 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions016, TestSize.Level1)
332 {
333 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
334 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
335 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions016 %{public}d ret=%{public}d", __LINE__, ret);
336 ASSERT_EQ(0, ret);
337 }
338
339 /**
340 * @tc.name: UsbdSetCurrentFunctions017
341 * @tc.desc: Test functions to SetCurrentFunctions
342 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
343 * @tc.desc: Positive test: parameters correctly
344 * @tc.type: FUNC
345 */
346 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions017, TestSize.Level1)
347 {
348 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
349 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
350 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions017 %{public}d ret=%{public}d", __LINE__, ret);
351 ASSERT_EQ(0, ret);
352 }
353
354 /**
355 * @tc.name: UsbdSetCurrentFunctions018
356 * @tc.desc: Test functions to SetCurrentFunctions
357 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
358 * @tc.desc: Negative test: parameters exception, funcs error
359 * @tc.type: FUNC
360 */
361 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions018, TestSize.Level1)
362 {
363 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
364 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions018 %{public}d ret=%{public}d", __LINE__, ret);
365 ASSERT_NE(ret, 0);
366 }
367
368 /**
369 * @tc.name: UsbdSetCurrentFunctions019
370 * @tc.desc: Test functions to SetCurrentFunctions
371 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
372 * @tc.desc: Positive test: parameters correctly
373 * @tc.type: FUNC
374 */
375 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions019, TestSize.Level1)
376 {
377 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
378 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 ret=%{public}d", ret);
379 ASSERT_EQ(0, ret);
380 HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
381 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
382 ASSERT_EQ(0, ret);
383 }
384
385 /**
386 * @tc.name: UsbdSetPortRole001
387 * @tc.desc: Test functions to SetPortRole
388 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
389 * @tc.desc: Positive test: parameters correctly
390 * @tc.type: FUNC
391 */
392 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, TestSize.Level1)
393 {
394 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
395 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
396 ret = SwitchErrCode(ret);
397 ASSERT_EQ(0, ret);
398 }
399
400 /**
401 * @tc.name: UsbdSetPortRole002
402 * @tc.desc: Test functions to SetPortRole
403 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
404 * @tc.desc: Negative test: parameters exception, portId error
405 * @tc.type: FUNC
406 */
407 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, TestSize.Level1)
408 {
409 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
410 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
411 ret = SwitchErrCode(ret);
412 ASSERT_NE(ret, 0);
413 }
414
415 /**
416 * @tc.name: UsbdSetPortRole003
417 * @tc.desc: Test functions to SetPortRole
418 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
419 * @tc.desc: Negative test: parameters exception, powerRole error
420 * @tc.type: FUNC
421 */
422 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole003, TestSize.Level1)
423 {
424 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
425 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole003 %{public}d ret=%{public}d", __LINE__, ret);
426 ret = SwitchErrCode(ret);
427 ASSERT_NE(ret, 0);
428 }
429
430 /**
431 * @tc.name: UsbdSetPortRole004
432 * @tc.desc: Test functions to SetPortRole
433 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
434 * @tc.desc: Negative test: parameters exception, dataRole error
435 * @tc.type: FUNC
436 */
437 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole004, TestSize.Level1)
438 {
439 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
440 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole004 %{public}d ret=%{public}d", __LINE__, ret);
441 ret = SwitchErrCode(ret);
442 ASSERT_NE(ret, 0);
443 }
444
445 /**
446 * @tc.name: UsbdSetPortRole005
447 * @tc.desc: Test functions to SetPortRole
448 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
449 * @tc.desc: Negative test: parameters exception, powerRole error
450 * @tc.type: FUNC
451 */
452 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole005, TestSize.Level1)
453 {
454 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
455 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole005 %{public}d ret=%{public}d", __LINE__, ret);
456 ret = SwitchErrCode(ret);
457 ASSERT_NE(ret, 0);
458 }
459
460 /**
461 * @tc.name: UsbdSetPortRole006
462 * @tc.desc: Test functions to SetPortRole
463 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
464 * @tc.desc: Negative test: parameters exception, portId && dataRole error
465 * @tc.type: FUNC
466 */
467 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole006, TestSize.Level1)
468 {
469 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
470 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole006 %{public}d ret=%{public}d", __LINE__, ret);
471 ret = SwitchErrCode(ret);
472 ASSERT_NE(ret, 0);
473 }
474
475 /**
476 * @tc.name: UsbdSetPortRole007
477 * @tc.desc: Test functions to SetPortRole
478 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
479 * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
480 * @tc.type: FUNC
481 */
482 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole007, TestSize.Level1)
483 {
484 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
485 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole007 %{public}d ret=%{public}d", __LINE__, ret);
486 ret = SwitchErrCode(ret);
487 ASSERT_NE(ret, 0);
488 }
489
490 /**
491 * @tc.name: UsbdSetPortRole008
492 * @tc.desc: Test functions to SetPortRole
493 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
494 * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
495 * @tc.type: FUNC
496 */
497 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole008, TestSize.Level1)
498 {
499 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
500 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole008 %{public}d ret=%{public}d", __LINE__, ret);
501 ret = SwitchErrCode(ret);
502 ASSERT_NE(ret, 0);
503 }
504
505 /**
506 * @tc.name: SetPortRole009
507 * @tc.desc: Test functions to SetPortRole
508 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
509 * @tc.desc: Positive test: parameters correctly
510 * @tc.type: FUNC
511 */
512 HWTEST_F(UsbdFunctionTest, SetPortRole09, TestSize.Level1)
513 {
514 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
515 HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
516 ret = SwitchErrCode(ret);
517 ASSERT_EQ(0, ret);
518 }
519
520 /**
521 * @tc.name: QueryPort001
522 * @tc.desc: Test functions to QueryPort
523 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
524 * @tc.desc: Positive test: parameters correctly
525 * @tc.type: FUNC
526 */
527 HWTEST_F(UsbdFunctionTest, QueryPort001, TestSize.Level1)
528 {
529 int32_t portId = DEFAULT_PORT_ID;
530 int32_t powerRole = POWER_ROLE_NONE;
531 int32_t dataRole = DATA_ROLE_NONE;
532 int32_t mode = PORT_MODE_NONE;
533 auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
534 HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
535 ASSERT_EQ(0, ret);
536 }
537 } // namespace
538