• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "v1_0/iusb_interface.h"
23 #include "v1_0/usb_types.h"
24 
25 constexpr int32_t SLEEP_TIME = 3;
26 constexpr int32_t USB_FUNCTION_INVALID = -1;
27 constexpr int32_t USB_PORT_ID_INVALID = 2;
28 constexpr int32_t USB_POWER_ROLE_INVALID = 4;
29 constexpr int32_t USB_DATA_ROLE_INVALID = 5;
30 constexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
31 
32 using namespace testing::ext;
33 using namespace OHOS;
34 using namespace std;
35 using namespace OHOS::HDI::Usb::V1_0;
36 
37 namespace {
38 sptr<IUsbInterface> g_usbInterface = nullptr;
39 
SetUpTestCase(void)40 void UsbdFunctionTest::SetUpTestCase(void)
41 {
42     g_usbInterface = IUsbInterface::Get();
43     if (g_usbInterface == nullptr) {
44         HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
45         exit(0);
46     }
47     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
48     sleep(SLEEP_TIME);
49     HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
50     if (ret != 0) {
51         ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
52     } else {
53         ASSERT_EQ(0, ret);
54     }
55 }
56 
TearDownTestCase(void)57 void UsbdFunctionTest::TearDownTestCase(void)
58 {
59     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
60     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
61     ASSERT_EQ(0, ret);
62 }
63 
SetUp(void)64 void UsbdFunctionTest::SetUp(void) {}
65 
TearDown(void)66 void UsbdFunctionTest::TearDown(void) {}
67 
68 /**
69  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0300
70  * @tc.desc: Test functions to GetCurrentFunctions
71  * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
72  * @tc.desc: Positive test: parameters correctly
73  * @tc.type: FUNC
74  */
75 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0300, Function | MediumTest | Level1)
76 {
77     int32_t funcs = USB_FUNCTION_NONE;
78     auto ret = g_usbInterface->GetCurrentFunctions(funcs);
79     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0300 %{public}d ret=%{public}d", __LINE__, ret);
80     ASSERT_EQ(0, ret);
81 }
82 
83 /**
84  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0400
85  * @tc.desc: Test functions to GetCurrentFunctions
86  * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
87  * @tc.desc: Positive test: parameters correctly
88  * @tc.type: FUNC
89  */
90 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0400, Function | MediumTest | Level1)
91 {
92     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
93     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d SetCurrentFunctions=%{public}d",
94         __LINE__, ret);
95     ASSERT_EQ(0, ret);
96     int32_t funcs = USB_FUNCTION_NONE;
97     ret = g_usbInterface->GetCurrentFunctions(funcs);
98     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d ret=%{public}d", __LINE__, ret);
99     ASSERT_EQ(0, ret);
100 }
101 
102 /**********************************************************************************************************/
103 
104 /**
105  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0500
106  * @tc.desc: Test functions to SetCurrentFunctions
107  * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
108  * @tc.desc: Positive test: parameters correctly
109  * @tc.type: FUNC
110  */
111 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0500, Function | MediumTest | Level1)
112 {
113     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
114     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0500 %{public}d SetCurrentFunctions=%{public}d",
115         __LINE__, ret);
116     ASSERT_EQ(0, ret);
117 }
118 
119 /**
120  * @tc.name: SUB_USB_DeviceManager_HDI_Compatibility_1500
121  * @tc.desc: Test functions to SetCurrentFunctions
122  * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
123  * @tc.desc: Negative test: parameters exception, Funcs error
124  * @tc.type: FUNC
125  */
126 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Compatibility_1500, Function | MediumTest | Level1)
127 {
128     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
129     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Compatibility_1500 %{public}d, ret=%{public}d",
130         __LINE__, ret);
131     ASSERT_NE(ret, 0);
132 }
133 /**
134  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0600
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, SUB_USB_DeviceManager_HDI_Func_0600, Function | MediumTest | Level1)
141 {
142     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
143     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0600 %{public}d ret=%{public}d", __LINE__, ret);
144     ASSERT_EQ(0, ret);
145 }
146 
147 /**
148  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0700
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, SUB_USB_DeviceManager_HDI_Func_0700, Function | MediumTest | Level1)
155 {
156     int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
157     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
158     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0700 %{public}d ret=%{public}d", __LINE__, ret);
159     ASSERT_EQ(0, ret);
160 }
161 
162 /**
163  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0800
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, SUB_USB_DeviceManager_HDI_Func_0800, Function | MediumTest | Level1)
170 {
171     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
172     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
173     ASSERT_EQ(0, ret);
174 }
175 
176 /**
177  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0900
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, SUB_USB_DeviceManager_HDI_Func_0900, Function | MediumTest | Level1)
184 {
185     int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
186     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
187     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0900 %{public}d ret=%{public}d", __LINE__, ret);
188     ASSERT_EQ(0, ret);
189 }
190 
191 /**
192  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1000
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, SUB_USB_DeviceManager_HDI_Func_1000, Function | MediumTest | Level1)
199 {
200     int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
201     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
202     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1000 %{public}d ret=%{public}d", __LINE__, ret);
203     ASSERT_EQ(0, ret);
204 }
205 
206 /**
207  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1100
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, SUB_USB_DeviceManager_HDI_Func_1100, Function | MediumTest | Level1)
214 {
215     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
216     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1100 %{public}d ret=%{public}d", __LINE__, ret);
217     ASSERT_EQ(0, ret);
218 }
219 
220 /**
221  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1400
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, SUB_USB_DeviceManager_HDI_Func_1400, Function | MediumTest | Level1)
228 {
229     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
230     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1400 %{public}d ret=%{public}d", __LINE__, ret);
231     ASSERT_EQ(0, ret);
232 }
233 
234 /**
235  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1500
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, SUB_USB_DeviceManager_HDI_Func_1500, Function | MediumTest | Level1)
242 {
243     int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
244     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
245     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1500 %{public}d ret=%{public}d", __LINE__, ret);
246     ASSERT_EQ(0, ret);
247 }
248 
249 /**
250  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1600
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, SUB_USB_DeviceManager_HDI_Func_1600, Function | MediumTest | Level1)
257 {
258     int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
259     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
260     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1600 %{public}d ret=%{public}d", __LINE__, ret);
261     ASSERT_EQ(0, ret);
262 }
263 
264 /**
265  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1900
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, SUB_USB_DeviceManager_HDI_Func_1900, Function | MediumTest | Level1)
272 {
273     int32_t funcs = USB_FUNCTION_MTP;
274     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
275     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1900 %{public}d ret=%{public}d", __LINE__, ret);
276     ASSERT_EQ(0, ret);
277 }
278 
279 /**
280  * @tc.name: SUB_USB_DeviceManager_HDI_Func_2000
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, SUB_USB_DeviceManager_HDI_Func_2000, Function | MediumTest | Level1)
287 {
288     int32_t funcs = USB_FUNCTION_PTP;
289     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
290     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2000 %{public}d ret=%{public}d", __LINE__, ret);
291     ASSERT_EQ(0, ret);
292 }
293 
294 /**
295  * @tc.name: SUB_USB_DeviceManager_HDI_Func_2100
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, SUB_USB_DeviceManager_HDI_Func_2100, Function | MediumTest | Level1)
302 {
303     int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
304     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
305     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2100 %{public}d ret=%{public}d", __LINE__, ret);
306     ASSERT_EQ(0, ret);
307 }
308 
309 /**
310  * @tc.name: SUB_USB_DeviceManager_HDI_Func_2200
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, SUB_USB_DeviceManager_HDI_Func_2200, Function | MediumTest | Level1)
317 {
318     int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
319     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
320     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2200 %{public}d ret=%{public}d", __LINE__, ret);
321     ASSERT_EQ(0, ret);
322 }
323 
324 /**
325  * @tc.name: SUB_USB_DeviceManager_HDI_Func_2300
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, SUB_USB_DeviceManager_HDI_Func_2300, Function | MediumTest | Level1)
332 {
333     int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
334     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
335     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2300 %{public}d ret=%{public}d", __LINE__, ret);
336     ASSERT_EQ(0, ret);
337 }
338 
339 /**
340  * @tc.name: SUB_USB_DeviceManager_HDI_Func_2400
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, SUB_USB_DeviceManager_HDI_Func_2400, Function | MediumTest | Level1)
347 {
348     int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
349     auto ret = g_usbInterface->SetCurrentFunctions(funcs);
350     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2400 %{public}d ret=%{public}d", __LINE__, ret);
351     ASSERT_EQ(0, ret);
352 }
353 
354 /**
355  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1700
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, SUB_USB_DeviceManager_HDI_Func_1700, Function | MediumTest | Level1)
362 {
363     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
364     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1700 %{public}d ret=%{public}d", __LINE__, ret);
365     ASSERT_NE(0, ret);
366 }
367 
368 /**
369  * @tc.name: SUB_USB_DeviceManager_HDI_Func_1800
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, SUB_USB_DeviceManager_HDI_Func_1800, Function | MediumTest | Level1)
376 {
377     auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
378     HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1800 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: SUB_USB_PortManager_HDI_Func_0100
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, SUB_USB_PortManager_HDI_Func_0100, Function | MediumTest | Level1)
393 {
394     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
395     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0100 %{public}d ret=%{public}d", __LINE__, ret);
396     if (ret != 0) {
397         ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
398     } else {
399         ASSERT_EQ(0, ret);
400     }
401 }
402 
403 /**
404  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0100
405  * @tc.desc: Test functions to SetPortRole
406  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
407  * @tc.desc: Negative test: parameters exception, portId error
408  * @tc.type: FUNC
409  */
410 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0100, Function | MediumTest | Level1)
411 {
412     auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
413     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0100 %{public}d ret=%{public}d", __LINE__, ret);
414     ASSERT_NE(ret, 0);
415 }
416 
417 /**
418  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0200
419  * @tc.desc: Test functions to SetPortRole
420  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
421  * @tc.desc: Negative test: parameters exception, powerRole error
422  * @tc.type: FUNC
423  */
424 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0200, Function | MediumTest | Level1)
425 {
426     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
427     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0200 %{public}d ret=%{public}d", __LINE__, ret);
428     ASSERT_NE(ret, 0);
429 }
430 
431 /**
432  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0300
433  * @tc.desc: Test functions to SetPortRole
434  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
435  * @tc.desc: Negative test: parameters exception, dataRole error
436  * @tc.type: FUNC
437  */
438 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0300, Function | MediumTest | Level1)
439 {
440     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
441     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0300 %{public}d ret=%{public}d", __LINE__, ret);
442     ASSERT_NE(ret, 0);
443 }
444 
445 /**
446  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0400
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, SUB_USB_PortManager_HDI_Compatibility_0400, Function | MediumTest | Level1)
453 {
454     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
455     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0400 %{public}d ret=%{public}d", __LINE__, ret);
456     ASSERT_NE(ret, 0);
457 }
458 
459 /**
460  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0500
461  * @tc.desc: Test functions to SetPortRole
462  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
463  * @tc.desc: Negative test: parameters exception, portId && dataRole error
464  * @tc.type: FUNC
465  */
466 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0500, Function | MediumTest | Level1)
467 {
468     auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
469     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0500 %{public}d ret=%{public}d", __LINE__, ret);
470     ASSERT_NE(ret, 0);
471 }
472 
473 /**
474  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0600
475  * @tc.desc: Test functions to SetPortRole
476  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
477  * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
478  * @tc.type: FUNC
479  */
480 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0600, Function | MediumTest | Level1)
481 {
482     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
483     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0600 %{public}d ret=%{public}d", __LINE__, ret);
484     ASSERT_NE(ret, 0);
485 }
486 
487 /**
488  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0700
489  * @tc.desc: Test functions to SetPortRole
490  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
491  * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
492  * @tc.type: FUNC
493  */
494 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0700, Function | MediumTest | Level1)
495 {
496     auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
497     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0700 %{public}d ret=%{public}d", __LINE__, ret);
498     ASSERT_NE(ret, 0);
499 }
500 
501 /**
502  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0800
503  * @tc.desc: Test functions to SetPortRole
504  * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
505  * @tc.desc: Positive test: parameters correctly
506  * @tc.type: FUNC
507  */
508 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0800, Function | MediumTest | Level1)
509 {
510     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
511     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0800 %{public}d ret=%{public}d", __LINE__, ret);
512     if (ret != 0) {
513         ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
514     } else {
515         ASSERT_EQ(0, ret);
516     }
517 }
518 
519 /**
520  * @tc.name: SUB_USB_PortManager_HDI_Func_0200
521  * @tc.desc: Test functions to QueryPort
522  * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
523  * @tc.desc: Positive test: parameters correctly
524  * @tc.type: FUNC
525  */
526 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | Level1)
527 {
528     int32_t portId = DEFAULT_PORT_ID;
529     int32_t powerRole = POWER_ROLE_NONE;
530     int32_t dataRole = DATA_ROLE_NONE;
531     int32_t mode = PORT_MODE_NONE;
532     auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
533     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0200 %{public}d ret=%{public}d", __LINE__, ret);
534     ASSERT_EQ(0, ret);
535 }
536 } // namespace
537