• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <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 
SwitchErrCode(int32_t ret)40 int32_t SwitchErrCode(int32_t ret)
41 {
42     return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
43 }
44 
SetUpTestCase(void)45 void UsbdFunctionTest::SetUpTestCase(void)
46 {
47     g_usbInterface = IUsbInterface::Get();
48     if (g_usbInterface == nullptr) {
49         HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
50         exit(0);
51     }
52     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
53     sleep(SLEEP_TIME);
54     HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
55     ret = SwitchErrCode(ret);
56     ASSERT_EQ(0, ret);
57     if (ret != 0) {
58         exit(0);
59     }
60 }
61 
TearDownTestCase(void)62 void UsbdFunctionTest::TearDownTestCase(void) {}
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     ret = SwitchErrCode(ret);
397     ASSERT_EQ(0, ret);
398 }
399 
400 /**
401  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0100
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, SUB_USB_PortManager_HDI_Compatibility_0100, Function | MediumTest | Level1)
408 {
409     auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
410     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0100 %{public}d ret=%{public}d", __LINE__, ret);
411     ret = SwitchErrCode(ret);
412     ASSERT_NE(ret, 0);
413 }
414 
415 /**
416  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0200
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, SUB_USB_PortManager_HDI_Compatibility_0200, Function | MediumTest | Level1)
423 {
424     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
425     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0200 %{public}d ret=%{public}d", __LINE__, ret);
426     ret = SwitchErrCode(ret);
427     ASSERT_NE(ret, 0);
428 }
429 
430 /**
431  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0300
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, SUB_USB_PortManager_HDI_Compatibility_0300, Function | MediumTest | Level1)
438 {
439     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
440     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0300 %{public}d ret=%{public}d", __LINE__, ret);
441     ret = SwitchErrCode(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     ret = SwitchErrCode(ret);
457     ASSERT_NE(ret, 0);
458 }
459 
460 /**
461  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0500
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, SUB_USB_PortManager_HDI_Compatibility_0500, Function | MediumTest | Level1)
468 {
469     auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
470     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0500 %{public}d ret=%{public}d", __LINE__, ret);
471     ret = SwitchErrCode(ret);
472     ASSERT_NE(ret, 0);
473 }
474 
475 /**
476  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0600
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, SUB_USB_PortManager_HDI_Compatibility_0600, Function | MediumTest | Level1)
483 {
484     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
485     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0600 %{public}d ret=%{public}d", __LINE__, ret);
486     ret = SwitchErrCode(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_usbInterface->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     ret = SwitchErrCode(ret);
502     ASSERT_NE(ret, 0);
503 }
504 
505 /**
506  * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0800
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, SUB_USB_PortManager_HDI_Compatibility_0800, Function | MediumTest | Level1)
513 {
514     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
515     HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0800 %{public}d ret=%{public}d", __LINE__, ret);
516     ret = SwitchErrCode(ret);
517     ASSERT_EQ(0, ret);
518 }
519 
520 /**
521  * @tc.name: SUB_USB_PortManager_HDI_Func_0200
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, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | 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::SUB_USB_PortManager_HDI_Func_0200 %{public}d ret=%{public}d", __LINE__, ret);
535     ASSERT_EQ(0, ret);
536 }
537 } // namespace
538