1 /*
2 * Copyright (c) 2021-2024 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 {
64 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
65 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
66 ASSERT_EQ(0, ret);
67 }
68
SetUp(void)69 void UsbdFunctionTest::SetUp(void) {}
70
TearDown(void)71 void UsbdFunctionTest::TearDown(void) {}
72
73 /**
74 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0300
75 * @tc.desc: Test functions to GetCurrentFunctions
76 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
77 * @tc.desc: Positive test: parameters correctly
78 * @tc.type: FUNC
79 */
80 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0300, Function | MediumTest | Level1)
81 {
82 int32_t funcs = USB_FUNCTION_NONE;
83 auto ret = g_usbInterface->GetCurrentFunctions(funcs);
84 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0300 %{public}d ret=%{public}d", __LINE__, ret);
85 ASSERT_EQ(0, ret);
86 }
87
88 /**
89 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0400
90 * @tc.desc: Test functions to GetCurrentFunctions
91 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
92 * @tc.desc: Positive test: parameters correctly
93 * @tc.type: FUNC
94 */
95 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0400, Function | MediumTest | Level1)
96 {
97 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
98 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d SetCurrentFunctions=%{public}d",
99 __LINE__, ret);
100 ASSERT_EQ(0, ret);
101 int32_t funcs = USB_FUNCTION_NONE;
102 ret = g_usbInterface->GetCurrentFunctions(funcs);
103 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d ret=%{public}d", __LINE__, ret);
104 ASSERT_EQ(0, ret);
105 }
106
107 /**********************************************************************************************************/
108
109 /**
110 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0500
111 * @tc.desc: Test functions to SetCurrentFunctions
112 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
113 * @tc.desc: Positive test: parameters correctly
114 * @tc.type: FUNC
115 */
116 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0500, Function | MediumTest | Level1)
117 {
118 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
119 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0500 %{public}d SetCurrentFunctions=%{public}d",
120 __LINE__, ret);
121 ASSERT_EQ(0, ret);
122 }
123
124 /**
125 * @tc.name: SUB_USB_DeviceManager_HDI_Compatibility_1500
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, SUB_USB_DeviceManager_HDI_Compatibility_1500, Function | MediumTest | Level1)
132 {
133 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
134 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Compatibility_1500 %{public}d, ret=%{public}d",
135 __LINE__, ret);
136 ASSERT_NE(ret, 0);
137 }
138 /**
139 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0600
140 * @tc.desc: Test functions to SetCurrentFunctions
141 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
142 * @tc.desc: Positive test: parameters correctly
143 * @tc.type: FUNC
144 */
145 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0600, Function | MediumTest | Level1)
146 {
147 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
148 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0600 %{public}d ret=%{public}d", __LINE__, ret);
149 ASSERT_EQ(0, ret);
150 }
151
152 /**
153 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0700
154 * @tc.desc: Test functions to SetCurrentFunctions
155 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
156 * @tc.desc: Positive test: parameters correctly
157 * @tc.type: FUNC
158 */
159 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0700, Function | MediumTest | Level1)
160 {
161 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
162 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
163 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0700 %{public}d ret=%{public}d", __LINE__, ret);
164 ASSERT_EQ(0, ret);
165 }
166
167 /**
168 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0800
169 * @tc.desc: Test functions to SetCurrentFunctions
170 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
171 * @tc.desc: Positive test: parameters correctly
172 * @tc.type: FUNC
173 */
174 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0800, Function | MediumTest | Level1)
175 {
176 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
177 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
178 ASSERT_EQ(0, ret);
179 }
180
181 /**
182 * @tc.name: SUB_USB_DeviceManager_HDI_Func_0900
183 * @tc.desc: Test functions to SetCurrentFunctions
184 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
185 * @tc.desc: Positive test: parameters correctly
186 * @tc.type: FUNC
187 */
188 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0900, Function | MediumTest | Level1)
189 {
190 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
191 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
192 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0900 %{public}d ret=%{public}d", __LINE__, ret);
193 ASSERT_EQ(0, ret);
194 }
195
196 /**
197 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1000
198 * @tc.desc: Test functions to SetCurrentFunctions
199 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
200 * @tc.desc: Positive test: parameters correctly
201 * @tc.type: FUNC
202 */
203 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1000, Function | MediumTest | Level1)
204 {
205 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
206 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
207 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1000 %{public}d ret=%{public}d", __LINE__, ret);
208 ASSERT_EQ(0, ret);
209 }
210
211 /**
212 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1100
213 * @tc.desc: Test functions to SetCurrentFunctions
214 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
215 * @tc.desc: Positive test: parameters correctly
216 * @tc.type: FUNC
217 */
218 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1100, Function | MediumTest | Level1)
219 {
220 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
221 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1100 %{public}d ret=%{public}d", __LINE__, ret);
222 ASSERT_EQ(0, ret);
223 }
224
225 /**
226 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1400
227 * @tc.desc: Test functions to SetCurrentFunctions
228 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
229 * @tc.desc: Positive test: parameters correctly
230 * @tc.type: FUNC
231 */
232 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1400, Function | MediumTest | Level1)
233 {
234 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
235 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1400 %{public}d ret=%{public}d", __LINE__, ret);
236 ASSERT_EQ(0, ret);
237 }
238
239 /**
240 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1500
241 * @tc.desc: Test functions to SetCurrentFunctions
242 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
243 * @tc.desc: Positive test: parameters correctly
244 * @tc.type: FUNC
245 */
246 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1500, Function | MediumTest | Level1)
247 {
248 int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
249 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
250 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1500 %{public}d ret=%{public}d", __LINE__, ret);
251 ASSERT_EQ(0, ret);
252 }
253
254 /**
255 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1600
256 * @tc.desc: Test functions to SetCurrentFunctions
257 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
258 * @tc.desc: Positive test: parameters correctly
259 * @tc.type: FUNC
260 */
261 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1600, Function | MediumTest | Level1)
262 {
263 int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
264 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
265 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1600 %{public}d ret=%{public}d", __LINE__, ret);
266 ASSERT_EQ(0, ret);
267 }
268
269 /**
270 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1900
271 * @tc.desc: Test functions to SetCurrentFunctions
272 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
273 * @tc.desc: Positive test: parameters correctly
274 * @tc.type: FUNC
275 */
276 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1900, Function | MediumTest | Level1)
277 {
278 int32_t funcs = USB_FUNCTION_MTP;
279 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
280 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1900 %{public}d ret=%{public}d", __LINE__, ret);
281 ASSERT_EQ(0, ret);
282 }
283
284 /**
285 * @tc.name: SUB_USB_DeviceManager_HDI_Func_2000
286 * @tc.desc: Test functions to SetCurrentFunctions
287 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
288 * @tc.desc: Positive test: parameters correctly
289 * @tc.type: FUNC
290 */
291 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2000, Function | MediumTest | Level1)
292 {
293 int32_t funcs = USB_FUNCTION_PTP;
294 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
295 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2000 %{public}d ret=%{public}d", __LINE__, ret);
296 ASSERT_EQ(0, ret);
297 }
298
299 /**
300 * @tc.name: SUB_USB_DeviceManager_HDI_Func_2100
301 * @tc.desc: Test functions to SetCurrentFunctions
302 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
303 * @tc.desc: Positive test: parameters correctly
304 * @tc.type: FUNC
305 */
306 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2100, Function | MediumTest | Level1)
307 {
308 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
309 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
310 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2100 %{public}d ret=%{public}d", __LINE__, ret);
311 ASSERT_EQ(0, ret);
312 }
313
314 /**
315 * @tc.name: SUB_USB_DeviceManager_HDI_Func_2200
316 * @tc.desc: Test functions to SetCurrentFunctions
317 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
318 * @tc.desc: Positive test: parameters correctly
319 * @tc.type: FUNC
320 */
321 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2200, Function | MediumTest | Level1)
322 {
323 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
324 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
325 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2200 %{public}d ret=%{public}d", __LINE__, ret);
326 ASSERT_EQ(0, ret);
327 }
328
329 /**
330 * @tc.name: SUB_USB_DeviceManager_HDI_Func_2300
331 * @tc.desc: Test functions to SetCurrentFunctions
332 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
333 * @tc.desc: Positive test: parameters correctly
334 * @tc.type: FUNC
335 */
336 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2300, Function | MediumTest | Level1)
337 {
338 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
339 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
340 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2300 %{public}d ret=%{public}d", __LINE__, ret);
341 ASSERT_EQ(0, ret);
342 }
343
344 /**
345 * @tc.name: SUB_USB_DeviceManager_HDI_Func_2400
346 * @tc.desc: Test functions to SetCurrentFunctions
347 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
348 * @tc.desc: Positive test: parameters correctly
349 * @tc.type: FUNC
350 */
351 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2400, Function | MediumTest | Level1)
352 {
353 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
354 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
355 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2400 %{public}d ret=%{public}d", __LINE__, ret);
356 ASSERT_EQ(0, ret);
357 }
358
359 /**
360 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1700
361 * @tc.desc: Test functions to SetCurrentFunctions
362 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
363 * @tc.desc: Negative test: parameters exception, funcs error
364 * @tc.type: FUNC
365 */
366 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1700, Function | MediumTest | Level1)
367 {
368 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
369 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1700 %{public}d ret=%{public}d", __LINE__, ret);
370 ASSERT_NE(0, ret);
371 }
372
373 /**
374 * @tc.name: SUB_USB_DeviceManager_HDI_Func_1800
375 * @tc.desc: Test functions to SetCurrentFunctions
376 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
377 * @tc.desc: Positive test: parameters correctly
378 * @tc.type: FUNC
379 */
380 HWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1800, Function | MediumTest | Level1)
381 {
382 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
383 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1800 ret=%{public}d", ret);
384 ASSERT_EQ(0, ret);
385 HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
386 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
387 ASSERT_EQ(0, ret);
388 }
389
390 /**
391 * @tc.name: SUB_USB_PortManager_HDI_Func_0100
392 * @tc.desc: Test functions to SetPortRole
393 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
394 * @tc.desc: Positive test: parameters correctly
395 * @tc.type: FUNC
396 */
397 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Func_0100, Function | MediumTest | Level1)
398 {
399 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
400 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0100 %{public}d ret=%{public}d", __LINE__, ret);
401 ret = SwitchErrCode(ret);
402 ASSERT_EQ(0, ret);
403 }
404
405 /**
406 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0100
407 * @tc.desc: Test functions to SetPortRole
408 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
409 * @tc.desc: Negative test: parameters exception, portId error
410 * @tc.type: FUNC
411 */
412 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0100, Function | MediumTest | Level1)
413 {
414 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
415 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0100 %{public}d ret=%{public}d", __LINE__, ret);
416 ret = SwitchErrCode(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_usbInterface->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 ret = SwitchErrCode(ret);
432 ASSERT_NE(ret, 0);
433 }
434
435 /**
436 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0300
437 * @tc.desc: Test functions to SetPortRole
438 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
439 * @tc.desc: Negative test: parameters exception, dataRole error
440 * @tc.type: FUNC
441 */
442 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0300, Function | MediumTest | Level1)
443 {
444 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
445 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0300 %{public}d ret=%{public}d", __LINE__, ret);
446 ret = SwitchErrCode(ret);
447 ASSERT_NE(ret, 0);
448 }
449
450 /**
451 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0400
452 * @tc.desc: Test functions to SetPortRole
453 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
454 * @tc.desc: Negative test: parameters exception, powerRole error
455 * @tc.type: FUNC
456 */
457 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0400, Function | MediumTest | Level1)
458 {
459 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
460 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0400 %{public}d ret=%{public}d", __LINE__, ret);
461 ret = SwitchErrCode(ret);
462 ASSERT_NE(ret, 0);
463 }
464
465 /**
466 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0500
467 * @tc.desc: Test functions to SetPortRole
468 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
469 * @tc.desc: Negative test: parameters exception, portId && dataRole error
470 * @tc.type: FUNC
471 */
472 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0500, Function | MediumTest | Level1)
473 {
474 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
475 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0500 %{public}d ret=%{public}d", __LINE__, ret);
476 ret = SwitchErrCode(ret);
477 ASSERT_NE(ret, 0);
478 }
479
480 /**
481 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0600
482 * @tc.desc: Test functions to SetPortRole
483 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
484 * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
485 * @tc.type: FUNC
486 */
487 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0600, Function | MediumTest | Level1)
488 {
489 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
490 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0600 %{public}d ret=%{public}d", __LINE__, ret);
491 ret = SwitchErrCode(ret);
492 ASSERT_NE(ret, 0);
493 }
494
495 /**
496 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0700
497 * @tc.desc: Test functions to SetPortRole
498 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
499 * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
500 * @tc.type: FUNC
501 */
502 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0700, Function | MediumTest | Level1)
503 {
504 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
505 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0700 %{public}d ret=%{public}d", __LINE__, ret);
506 ret = SwitchErrCode(ret);
507 ASSERT_NE(ret, 0);
508 }
509
510 /**
511 * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0800
512 * @tc.desc: Test functions to SetPortRole
513 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
514 * @tc.desc: Positive test: parameters correctly
515 * @tc.type: FUNC
516 */
517 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0800, Function | MediumTest | Level1)
518 {
519 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
520 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0800 %{public}d ret=%{public}d", __LINE__, ret);
521 ret = SwitchErrCode(ret);
522 ASSERT_EQ(0, ret);
523 }
524
525 /**
526 * @tc.name: SUB_USB_PortManager_HDI_Func_0200
527 * @tc.desc: Test functions to QueryPort
528 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
529 * @tc.desc: Positive test: parameters correctly
530 * @tc.type: FUNC
531 */
532 HWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | Level1)
533 {
534 int32_t portId = DEFAULT_PORT_ID;
535 int32_t powerRole = POWER_ROLE_NONE;
536 int32_t dataRole = DATA_ROLE_NONE;
537 int32_t mode = PORT_MODE_NONE;
538 auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
539 HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0200 %{public}d ret=%{public}d", __LINE__, ret);
540 ASSERT_EQ(0, ret);
541 }
542 } // namespace
543