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