1 /*
2 * Copyright (c) 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_PORT_ID_INVALID = 2;
27 constexpr int32_t USB_POWER_ROLE_INVALID = 4;
28 constexpr int32_t USB_DATA_ROLE_INVALID = 5;
29 using namespace testing::ext;
30 using namespace OHOS;
31 using namespace std;
32 using namespace OHOS::HDI::Usb::V1_0;
33
34 namespace {
35 sptr<IUsbInterface> g_usbInterface = nullptr;
36
SwitchErrCode(int32_t ret)37 int32_t SwitchErrCode(int32_t ret)
38 {
39 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
40 }
41
SetUpTestCase(void)42 void UsbdFunctionTestAdditional::SetUpTestCase(void)
43 {
44 g_usbInterface = IUsbInterface::Get();
45 if (g_usbInterface == nullptr) {
46 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
47 exit(0);
48 }
49 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
50 sleep(SLEEP_TIME);
51 HDF_LOGI("UsbdFunctionTestAdditional::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
52 ret = SwitchErrCode(ret);
53 ASSERT_EQ(0, ret);
54 if (ret != 0) {
55 exit(0);
56 }
57 }
58
TearDownTestCase(void)59 void UsbdFunctionTestAdditional::TearDownTestCase(void)
60 {
61 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
62 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
63 ASSERT_EQ(0, ret);
64 }
65
SetUp(void)66 void UsbdFunctionTestAdditional::SetUp(void) {}
67
TearDown(void)68 void UsbdFunctionTestAdditional::TearDown(void) {}
69
70 /**
71 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0100
72 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions001
73 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
74 * funcs = USB_FUNCTION_ACM | USB_FUNCTION_MTP.
75 */
76 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions001, Function | MediumTest | Level1)
77 {
78 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_MTP;
79 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
80 ASSERT_EQ(0, ret);
81 }
82
83 /**
84 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0200
85 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions002
86 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
87 * funcs = USB_FUNCTION_ACM | USB_FUNCTION_PTP.
88 */
89 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions002, Function | MediumTest | Level1)
90 {
91 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_PTP;
92 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
93 ASSERT_EQ(0, ret);
94 }
95
96 /**
97 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0300
98 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions003
99 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
100 * funcs = USB_FUNCTION_ACM | USB_FUNCTION_RNDIS.
101 */
102 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions003, Function | MediumTest | Level1)
103 {
104 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_RNDIS;
105 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
106 ASSERT_EQ(0, ret);
107 }
108
109 /**
110 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0400
111 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions004
112 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
113 * funcs = USB_FUNCTION_ACM | USB_FUNCTION_STORAGE.
114 */
115 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions004, Function | MediumTest | Level1)
116 {
117 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_STORAGE;
118 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
119 ASSERT_EQ(0, ret);
120 }
121
122 /**
123 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0500
124 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions005
125 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
126 * funcs = USB_FUNCTION_ECM | USB_FUNCTION_MTP.
127 */
128 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions005, Function | MediumTest | Level1)
129 {
130 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_MTP;
131 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
132 ASSERT_EQ(0, ret);
133 }
134
135 /**
136 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0600
137 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions006
138 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
139 * funcs = USB_FUNCTION_ECM | USB_FUNCTION_PTP.
140 */
141 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions006, Function | MediumTest | Level1)
142 {
143 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_PTP;
144 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
145 ASSERT_EQ(0, ret);
146 }
147
148 /**
149 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0700
150 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions007
151 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
152 * funcs = USB_FUNCTION_ECM | USB_FUNCTION_RNDIS.
153 */
154 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions007, Function | MediumTest | Level1)
155 {
156 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_RNDIS;
157 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
158 ASSERT_EQ(0, ret);
159 }
160
161 /**
162 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0800
163 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions008
164 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
165 * funcs = USB_FUNCTION_ECM | USB_FUNCTION_STORAGE.
166 */
167 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions008, Function | MediumTest | Level1)
168 {
169 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_STORAGE;
170 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
171 ASSERT_EQ(0, ret);
172 }
173
174 /**
175 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_0900
176 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions009
177 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
178 * funcs = USB_FUNCTION_MTP | USB_FUNCTION_PTP.
179 */
180 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions009, Function | MediumTest | Level1)
181 {
182 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_PTP;
183 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
184 ASSERT_EQ(0, ret);
185 }
186
187 /**
188 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1000
189 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions010
190 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
191 * funcs = USB_FUNCTION_MTP | USB_FUNCTION_STORAGE.
192 */
193 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions010, Function | MediumTest | Level1)
194 {
195 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_STORAGE;
196 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
197 ASSERT_EQ(0, ret);
198 }
199
200 /**
201 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1100
202 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions011
203 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
204 * funcs = USB_FUNCTION_PTP | USB_FUNCTION_STORAGE.
205 */
206 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions011, Function | MediumTest | Level1)
207 {
208 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_STORAGE;
209 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
210 ASSERT_EQ(0, ret);
211 }
212
213 /**
214 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1200
215 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions013
216 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
217 * USB_FUNCTION_NONE,USB_FUNCTION_ACM.
218 */
219 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions013, Function | MediumTest | Level1)
220 {
221 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
222 ASSERT_EQ(0, ret);
223 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
224 ASSERT_EQ(0, ret);
225 }
226
227 /**
228 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1300
229 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions014
230 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
231 * USB_FUNCTION_NONE,USB_FUNCTION_ECM.
232 */
233 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions014, Function | MediumTest | Level1)
234 {
235 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
236 ASSERT_EQ(0, ret);
237 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
238 ASSERT_EQ(0, ret);
239 }
240
241 /**
242 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1400
243 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions015
244 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
245 * USB_FUNCTION_NONE,USB_FUNCTION_MTP.
246 */
247 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions015, Function | MediumTest | Level1)
248 {
249 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
250 ASSERT_EQ(0, ret);
251 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
252 ASSERT_EQ(0, ret);
253 }
254
255 /**
256 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1500
257 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions016
258 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
259 * USB_FUNCTION_NONE,USB_FUNCTION_PTP.
260 */
261 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions016, Function | MediumTest | Level1)
262 {
263 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
264 ASSERT_EQ(0, ret);
265 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_PTP);
266 ASSERT_EQ(0, ret);
267 }
268
269 /**
270 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1600
271 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions017
272 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
273 * USB_FUNCTION_NONE,USB_FUNCTION_RNDIS.
274 */
275 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions017, Function | MediumTest | Level1)
276 {
277 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
278 ASSERT_EQ(0, ret);
279 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
280 ASSERT_EQ(0, ret);
281 }
282
283 /**
284 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1700
285 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions018
286 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
287 * USB_FUNCTION_NONE,USB_FUNCTION_STORAGE.
288 */
289 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions018, Function | MediumTest | Level1)
290 {
291 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
292 ASSERT_EQ(0, ret);
293 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
294 ASSERT_EQ(0, ret);
295 }
296
297 /**
298 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1800
299 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions001
300 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
301 * Set USB_FUNCTION_ACM Check if the Get is correct.
302 */
303 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions001, Function | MediumTest | Level1)
304 {
305 int32_t funcs = USB_FUNCTION_NONE;
306 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
307 ASSERT_EQ(0, ret);
308 ret = g_usbInterface->GetCurrentFunctions(funcs);
309 ASSERT_EQ(0, ret);
310 ASSERT_EQ(USB_FUNCTION_ACM, funcs);
311 }
312
313 /**
314 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1900
315 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions002
316 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
317 * Set USB_FUNCTION_ECM Check if the Get is correct.
318 */
319 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions002, Function | MediumTest | Level1)
320 {
321 int32_t funcs = USB_FUNCTION_NONE;
322 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
323 ASSERT_EQ(0, ret);
324 ret = g_usbInterface->GetCurrentFunctions(funcs);
325 ASSERT_EQ(0, ret);
326 ASSERT_EQ(USB_FUNCTION_ECM, funcs);
327 }
328
329 /**
330 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2000
331 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions003
332 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
333 * Set USB_FUNCTION_HDC Check if the Get is correct.
334 */
335 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions003, Function | MediumTest | Level1)
336 {
337 int32_t funcs = USB_FUNCTION_NONE;
338 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
339 ASSERT_EQ(0, ret);
340 ret = g_usbInterface->GetCurrentFunctions(funcs);
341 ASSERT_EQ(0, ret);
342 ASSERT_EQ(USB_FUNCTION_HDC, funcs);
343 }
344
345 /**
346 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2100
347 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions004
348 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
349 * Set USB_FUNCTION_MTP Check if the Get is correct.
350 */
351 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions004, Function | MediumTest | Level1)
352 {
353 int32_t funcs = USB_FUNCTION_NONE;
354 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
355 ASSERT_EQ(0, ret);
356 ret = g_usbInterface->GetCurrentFunctions(funcs);
357 ASSERT_EQ(0, ret);
358 ASSERT_EQ(USB_FUNCTION_MTP, funcs);
359 }
360
361 /**
362 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2200
363 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions005
364 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
365 * Set USB_FUNCTION_PTP Check if the Get is correct.
366 */
367 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions005, Function | MediumTest | Level1)
368 {
369 int32_t funcs = USB_FUNCTION_NONE;
370 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_PTP);
371 ASSERT_EQ(0, ret);
372 ret = g_usbInterface->GetCurrentFunctions(funcs);
373 ASSERT_EQ(0, ret);
374 ASSERT_EQ(USB_FUNCTION_PTP, funcs);
375 }
376
377 /**
378 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2300
379 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions006
380 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
381 * Set USB_FUNCTION_RNDIS Check if the Get is correct.
382 */
383 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions006, Function | MediumTest | Level1)
384 {
385 int32_t funcs = USB_FUNCTION_NONE;
386 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
387 ASSERT_EQ(0, ret);
388 ret = g_usbInterface->GetCurrentFunctions(funcs);
389 ASSERT_EQ(0, ret);
390 ASSERT_EQ(USB_FUNCTION_RNDIS, funcs);
391 }
392
393 /**
394 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2400
395 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions007
396 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
397 * Set USB_FUNCTION_STORAGE Check if the Get is correct.
398 */
399 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions007, Function | MediumTest | Level1)
400 {
401 int32_t funcs = USB_FUNCTION_NONE;
402 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
403 ASSERT_EQ(0, ret);
404 ret = g_usbInterface->GetCurrentFunctions(funcs);
405 ASSERT_EQ(0, ret);
406 ASSERT_EQ(USB_FUNCTION_STORAGE, funcs);
407 }
408
409 /**
410 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2500
411 * @tc.name: testHdiUsbFunctionTestSetPortRole001
412 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
413 * (USB_PORT_ID_INVALID, POWER_ROLE_SINK, DATA_ROLE_DEVICE).
414 */
415 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole001, Function | MediumTest | Level2)
416 {
417 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
418 ret = SwitchErrCode(ret);
419 ASSERT_NE(ret, 0);
420 }
421
422 /**
423 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2600
424 * @tc.name: testHdiUsbFunctionTestSetPortRole002
425 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
426 * USB_POWER_ROLE_INVALID, DATA_ROLE_NONE).
427 */
428 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole002, Function | MediumTest | Level2)
429 {
430 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE);
431 ret = SwitchErrCode(ret);
432 ASSERT_NE(ret, 0);
433 }
434
435 /**
436 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2700
437 * @tc.name: testHdiUsbFunctionTestSetPortRole003
438 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
439 * POWER_ROLE_SINK, USB_DATA_ROLE_INVALID).
440 */
441 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole003, Function | MediumTest | Level2)
442 {
443 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID);
444 ret = SwitchErrCode(ret);
445 ASSERT_NE(ret, 0);
446 }
447
448 /**
449 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2800
450 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
451 * POWER_ROLE_NONE, USB_DATA_ROLE_INVALID).
452 */
453 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole004, Function | MediumTest | Level2)
454 {
455 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID);
456 ret = SwitchErrCode(ret);
457 ASSERT_NE(ret, 0);
458 }
459
460 /**
461 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2900
462 * @tc.name: testHdiUsbFunctionTestSetPortRole005
463 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
464 * (USB_PORT_ID_INVALID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID).
465 */
466 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole005, Function | MediumTest | Level2)
467 {
468 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID);
469 ret = SwitchErrCode(ret);
470 ASSERT_NE(ret, 0);
471 }
472
473 /**
474 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3000
475 * @tc.name: testHdiUsbFunctionTestSetPortRole006
476 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
477 * (USB_PORT_ID_INVALID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID).
478 */
479 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole006, Function | MediumTest | Level2)
480 {
481 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID);
482 ret = SwitchErrCode(ret);
483 ASSERT_NE(ret, 0);
484 }
485
486 /**
487 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3100
488 * @tc.name: testHdiUsbFunctionTestSetPortRole007
489 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
490 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE).
491 */
492 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole007, Function | MediumTest | Level2)
493 {
494 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE);
495 ret = SwitchErrCode(ret);
496 ASSERT_NE(ret, 0);
497 }
498 /**
499 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3200
500 * @tc.name: testHdiUsbFunctionTestSetPortRole008
501 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
502 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST).
503 */
504 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole008, Function | MediumTest | Level2)
505 {
506 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
507 ret = SwitchErrCode(ret);
508 ASSERT_NE(ret, 0);
509 }
510
511 /**
512 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3300
513 * @tc.name: testHdiUsbFunctionTestSetPortRole009
514 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
515 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE).
516 */
517 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole009, Function | MediumTest | Level2)
518 {
519 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
520 ret = SwitchErrCode(ret);
521 ASSERT_NE(ret, 0);
522 }
523
524 /**
525 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3400
526 * @tc.name: testHdiUsbFunctionTestQueryPort001
527 * @tc.desc: Queries the current settings of a port.To see if portId is equal to DEFAULT_PORT_ID.
528 */
529 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort001, Function | MediumTest | Level1)
530 {
531 int32_t portId = 0;
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_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
536 ret = SwitchErrCode(ret);
537 ASSERT_EQ(0, ret);
538 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
539 ASSERT_EQ(0, ret);
540 ASSERT_EQ(DEFAULT_PORT_ID, portId);
541 }
542
543 /**
544 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3500
545 * @tc.name: testHdiUsbFunctionTestQueryPort002
546 * @tc.desc: Queries the current settings of a port.To see if powerRole is equal to POWER_ROLE_SINK.
547 */
548 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort002, Function | MediumTest | Level1)
549 {
550 int32_t portId = DEFAULT_PORT_ID;
551 int32_t powerRole = POWER_ROLE_NONE;
552 int32_t dataRole = DATA_ROLE_NONE;
553 int32_t mode = PORT_MODE_NONE;
554 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
555 ret = SwitchErrCode(ret);
556 ASSERT_EQ(0, ret);
557 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
558 ASSERT_EQ(0, ret);
559 ASSERT_EQ(POWER_ROLE_SINK, powerRole);
560 }
561
562 /**
563 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3600
564 * @tc.name: testHdiUsbFunctionTestQueryPort003
565 * @tc.desc: Queries the current settings of a port.To see if dataRole is equal to DATA_ROLE_DEVICE.
566 */
567 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort003, Function | MediumTest | Level1)
568 {
569 int32_t portId = DEFAULT_PORT_ID;
570 int32_t powerRole = POWER_ROLE_NONE;
571 int32_t dataRole = DATA_ROLE_NONE;
572 int32_t mode = PORT_MODE_NONE;
573 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
574 ret = SwitchErrCode(ret);
575 ASSERT_EQ(0, ret);
576 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
577 ASSERT_EQ(0, ret);
578 ASSERT_EQ(DATA_ROLE_DEVICE, dataRole);
579 }
580
581 /**
582 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3700
583 * @tc.name: testHdiUsbFunctionTestQueryPort004
584 * @tc.desc: Queries the current settings of a port.To see if portId is equal to DEFAULT_PORT_ID.
585 */
586 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort004, Function | MediumTest | Level1)
587 {
588 int32_t portId = 0;
589 int32_t powerRole = POWER_ROLE_NONE;
590 int32_t dataRole = DATA_ROLE_NONE;
591 int32_t mode = PORT_MODE_NONE;
592 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
593 ret = SwitchErrCode(ret);
594 ASSERT_EQ(0, ret);
595 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
596 ASSERT_EQ(0, ret);
597 ASSERT_EQ(DEFAULT_PORT_ID, portId);
598 }
599
600 /**
601 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3800
602 * @tc.name: testHdiUsbFunctionTestQueryPort005
603 * @tc.desc: Queries the current settings of a port.To see if powerRole is equal to DATA_ROLE_HOST.
604 */
605 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort005, Function | MediumTest | Level1)
606 {
607 int32_t portId = DEFAULT_PORT_ID;
608 int32_t powerRole = POWER_ROLE_NONE;
609 int32_t dataRole = DATA_ROLE_NONE;
610 int32_t mode = PORT_MODE_NONE;
611 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
612 if (ret == HDF_SUCCESS) {
613 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
614 ASSERT_EQ(0, ret);
615 ASSERT_EQ(POWER_ROLE_SOURCE, powerRole);
616 } else if (ret == HDF_ERR_NOT_SUPPORT) {
617 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
618 ASSERT_EQ(0, ret);
619 ASSERT_EQ(POWER_ROLE_SINK, powerRole);
620 }
621 }
622
623 /**
624 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3900
625 * @tc.name: testHdiUsbFunctionTestQueryPort006
626 * @tc.desc: Queries the current settings of a port.To see if dataRole is equal to DATA_ROLE_HOST.
627 */
628 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort006, Function | MediumTest | Level1)
629 {
630 int32_t portId = DEFAULT_PORT_ID;
631 int32_t powerRole = POWER_ROLE_NONE;
632 int32_t dataRole = DATA_ROLE_NONE;
633 int32_t mode = PORT_MODE_NONE;
634 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
635 if (ret == HDF_SUCCESS) {
636 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
637 ASSERT_EQ(0, ret);
638 ASSERT_EQ(DATA_ROLE_HOST, dataRole);
639 } else if (ret == HDF_ERR_NOT_SUPPORT) {
640 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
641 ASSERT_EQ(0, ret);
642 ASSERT_EQ(DATA_ROLE_DEVICE, dataRole);
643 }
644 }
645
646 } // namespace
647