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