1 /*
2 * Copyright (c) 2024-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_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
SetUpTestCase(void)37 void UsbdFunctionTestAdditional::SetUpTestCase(void)
38 {
39 g_usbInterface = IUsbInterface::Get();
40 if (g_usbInterface == nullptr) {
41 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
42 exit(0);
43 }
44 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
45 sleep(SLEEP_TIME);
46 HDF_LOGI("UsbdFunctionTestAdditional::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
47 if (ret != 0) {
48 ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
49 } else {
50 ASSERT_EQ(0, ret);
51 }
52 }
53
TearDownTestCase(void)54 void UsbdFunctionTestAdditional::TearDownTestCase(void)
55 {
56 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
57 HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
58 ASSERT_EQ(0, ret);
59 }
60
SetUp(void)61 void UsbdFunctionTestAdditional::SetUp(void) {}
62
TearDown(void)63 void UsbdFunctionTestAdditional::TearDown(void) {}
64
65 /**
66 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1200
67 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions013
68 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
69 * USB_FUNCTION_NONE,USB_FUNCTION_ACM.
70 */
71 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions013, Function | MediumTest | Level1)
72 {
73 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
74 ASSERT_EQ(0, ret);
75 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
76 ASSERT_EQ(0, ret);
77 }
78
79 /**
80 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1300
81 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions014
82 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
83 * USB_FUNCTION_NONE,USB_FUNCTION_ECM.
84 */
85 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions014, Function | MediumTest | Level1)
86 {
87 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
88 ASSERT_EQ(0, ret);
89 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
90 ASSERT_EQ(0, ret);
91 }
92
93 /**
94 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1400
95 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions015
96 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
97 * USB_FUNCTION_NONE,USB_FUNCTION_MTP.
98 */
99 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions015, Function | MediumTest | Level1)
100 {
101 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
102 ASSERT_EQ(0, ret);
103 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
104 ASSERT_EQ(0, ret);
105 }
106
107 /**
108 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1500
109 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions016
110 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
111 * USB_FUNCTION_NONE,USB_FUNCTION_PTP.
112 */
113 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions016, Function | MediumTest | Level1)
114 {
115 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
116 ASSERT_EQ(0, ret);
117 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_PTP);
118 ASSERT_EQ(0, ret);
119 }
120
121 /**
122 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1600
123 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions017
124 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
125 * USB_FUNCTION_NONE,USB_FUNCTION_RNDIS.
126 */
127 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions017, Function | MediumTest | Level1)
128 {
129 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
130 ASSERT_EQ(0, ret);
131 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
132 ASSERT_EQ(0, ret);
133 }
134
135 /**
136 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1700
137 * @tc.name: testHdiUsbFunctionTestSetCurrentFunctions018
138 * @tc.desc: Sets the list of functions (represented by bit field) supported by the current device.
139 * USB_FUNCTION_NONE,USB_FUNCTION_STORAGE.
140 */
141 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetCurrentFunctions018, Function | MediumTest | Level1)
142 {
143 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
144 ASSERT_EQ(0, ret);
145 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
146 ASSERT_EQ(0, ret);
147 }
148
149 /**
150 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1800
151 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions001
152 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
153 * Set USB_FUNCTION_ACM Check if the Get is correct.
154 */
155 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions001, Function | MediumTest | Level1)
156 {
157 int32_t funcs = USB_FUNCTION_NONE;
158 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
159 ASSERT_EQ(0, ret);
160 ret = g_usbInterface->GetCurrentFunctions(funcs);
161 ASSERT_EQ(0, ret);
162 ASSERT_EQ(USB_FUNCTION_ACM, funcs);
163 }
164
165 /**
166 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_1900
167 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions002
168 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
169 * Set USB_FUNCTION_ECM Check if the Get is correct.
170 */
171 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions002, Function | MediumTest | Level1)
172 {
173 int32_t funcs = USB_FUNCTION_NONE;
174 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
175 ASSERT_EQ(0, ret);
176 ret = g_usbInterface->GetCurrentFunctions(funcs);
177 ASSERT_EQ(0, ret);
178 ASSERT_EQ(USB_FUNCTION_ECM, funcs);
179 }
180
181 /**
182 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2000
183 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions003
184 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
185 * Set USB_FUNCTION_HDC Check if the Get is correct.
186 */
187 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions003, Function | MediumTest | Level1)
188 {
189 int32_t funcs = USB_FUNCTION_NONE;
190 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
191 ASSERT_EQ(0, ret);
192 ret = g_usbInterface->GetCurrentFunctions(funcs);
193 ASSERT_EQ(0, ret);
194 ASSERT_EQ(USB_FUNCTION_HDC, funcs);
195 }
196
197 /**
198 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2100
199 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions004
200 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
201 * Set USB_FUNCTION_MTP Check if the Get is correct.
202 */
203 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions004, Function | MediumTest | Level1)
204 {
205 int32_t funcs = USB_FUNCTION_NONE;
206 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
207 ASSERT_EQ(0, ret);
208 ret = g_usbInterface->GetCurrentFunctions(funcs);
209 ASSERT_EQ(0, ret);
210 ASSERT_EQ(USB_FUNCTION_MTP, funcs);
211 }
212
213 /**
214 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2200
215 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions005
216 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
217 * Set USB_FUNCTION_PTP Check if the Get is correct.
218 */
219 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions005, Function | MediumTest | Level1)
220 {
221 int32_t funcs = USB_FUNCTION_NONE;
222 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_PTP);
223 ASSERT_EQ(0, ret);
224 ret = g_usbInterface->GetCurrentFunctions(funcs);
225 ASSERT_EQ(0, ret);
226 ASSERT_EQ(USB_FUNCTION_PTP, funcs);
227 }
228
229 /**
230 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2300
231 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions006
232 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
233 * Set USB_FUNCTION_RNDIS Check if the Get is correct.
234 */
235 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions006, Function | MediumTest | Level1)
236 {
237 int32_t funcs = USB_FUNCTION_NONE;
238 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
239 ASSERT_EQ(0, ret);
240 ret = g_usbInterface->GetCurrentFunctions(funcs);
241 ASSERT_EQ(0, ret);
242 ASSERT_EQ(USB_FUNCTION_RNDIS, funcs);
243 }
244
245 /**
246 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2400
247 * @tc.name: testHdiUsbFunctionTestGetCurrentFunctions007
248 * @tc.desc: Obtains the list of functions (represented by bit field) supported by the current device.
249 * Set USB_FUNCTION_STORAGE Check if the Get is correct.
250 */
251 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestGetCurrentFunctions007, Function | MediumTest | Level1)
252 {
253 int32_t funcs = USB_FUNCTION_NONE;
254 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
255 ASSERT_EQ(0, ret);
256 ret = g_usbInterface->GetCurrentFunctions(funcs);
257 ASSERT_EQ(0, ret);
258 ASSERT_EQ(USB_FUNCTION_STORAGE, funcs);
259 }
260
261 /**
262 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2500
263 * @tc.name: testHdiUsbFunctionTestSetPortRole001
264 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
265 * (USB_PORT_ID_INVALID, POWER_ROLE_SINK, DATA_ROLE_DEVICE).
266 */
267 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole001, Function | MediumTest | Level2)
268 {
269 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
270 ASSERT_NE(ret, 0);
271 }
272
273 /**
274 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2600
275 * @tc.name: testHdiUsbFunctionTestSetPortRole002
276 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
277 * USB_POWER_ROLE_INVALID, DATA_ROLE_NONE).
278 */
279 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole002, Function | MediumTest | Level2)
280 {
281 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE);
282 ASSERT_NE(ret, 0);
283 }
284
285 /**
286 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2700
287 * @tc.name: testHdiUsbFunctionTestSetPortRole003
288 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
289 * POWER_ROLE_SINK, USB_DATA_ROLE_INVALID).
290 */
291 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole003, Function | MediumTest | Level2)
292 {
293 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID);
294 ASSERT_NE(ret, 0);
295 }
296
297 /**
298 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2800
299 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are (DEFAULT_PORT_ID,
300 * POWER_ROLE_NONE, USB_DATA_ROLE_INVALID).
301 */
302 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole004, Function | MediumTest | Level2)
303 {
304 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID);
305 ASSERT_NE(ret, 0);
306 }
307
308 /**
309 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_2900
310 * @tc.name: testHdiUsbFunctionTestSetPortRole005
311 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
312 * (USB_PORT_ID_INVALID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID).
313 */
314 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole005, Function | MediumTest | Level2)
315 {
316 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SINK, USB_DATA_ROLE_INVALID);
317 ASSERT_NE(ret, 0);
318 }
319
320 /**
321 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3000
322 * @tc.name: testHdiUsbFunctionTestSetPortRole006
323 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
324 * (USB_PORT_ID_INVALID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID).
325 */
326 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole006, Function | MediumTest | Level2)
327 {
328 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_NONE, USB_DATA_ROLE_INVALID);
329 ASSERT_NE(ret, 0);
330 }
331
332 /**
333 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3100
334 * @tc.name: testHdiUsbFunctionTestSetPortRole007
335 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
336 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE).
337 */
338 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole007, Function | MediumTest | Level2)
339 {
340 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_NONE);
341 ASSERT_NE(ret, 0);
342 }
343 /**
344 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3200
345 * @tc.name: testHdiUsbFunctionTestSetPortRole008
346 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
347 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST).
348 */
349 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole008, Function | MediumTest | Level2)
350 {
351 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
352 ASSERT_NE(ret, 0);
353 }
354
355 /**
356 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3300
357 * @tc.name: testHdiUsbFunctionTestSetPortRole009
358 * @tc.desc: Closes a USB device to release all system resources related to the device.The entries are
359 * (USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE).
360 */
361 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestSetPortRole009, Function | MediumTest | Level2)
362 {
363 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
364 ASSERT_NE(ret, 0);
365 }
366
367 /**
368 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3400
369 * @tc.name: testHdiUsbFunctionTestQueryPort001
370 * @tc.desc: Queries the current settings of a port.To see if portId is equal to DEFAULT_PORT_ID.
371 */
372 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort001, Function | MediumTest | Level1)
373 {
374 int32_t portId = 0;
375 int32_t powerRole = POWER_ROLE_NONE;
376 int32_t dataRole = DATA_ROLE_NONE;
377 int32_t mode = PORT_MODE_NONE;
378 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
379 if (ret != 0) {
380 ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
381 } else {
382 ASSERT_EQ(0, ret);
383 }
384 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
385 ASSERT_EQ(0, ret);
386 ASSERT_EQ(DEFAULT_PORT_ID, portId);
387 }
388
389 /**
390 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3500
391 * @tc.name: testHdiUsbFunctionTestQueryPort002
392 * @tc.desc: Queries the current settings of a port.To see if powerRole is equal to POWER_ROLE_SINK.
393 */
394 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort002, Function | MediumTest | Level1)
395 {
396 int32_t portId = DEFAULT_PORT_ID;
397 int32_t powerRole = POWER_ROLE_NONE;
398 int32_t dataRole = DATA_ROLE_NONE;
399 int32_t mode = PORT_MODE_NONE;
400 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
401 if (ret != 0) {
402 ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
403 } else {
404 ASSERT_EQ(0, ret);
405 }
406 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
407 ASSERT_EQ(0, ret);
408 ASSERT_EQ(POWER_ROLE_SINK, powerRole);
409 }
410
411 /**
412 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3600
413 * @tc.name: testHdiUsbFunctionTestQueryPort003
414 * @tc.desc: Queries the current settings of a port.To see if dataRole is equal to DATA_ROLE_DEVICE.
415 */
416 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort003, Function | MediumTest | Level1)
417 {
418 int32_t portId = DEFAULT_PORT_ID;
419 int32_t powerRole = POWER_ROLE_NONE;
420 int32_t dataRole = DATA_ROLE_NONE;
421 int32_t mode = PORT_MODE_NONE;
422 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
423 if (ret != 0) {
424 ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
425 } else {
426 ASSERT_EQ(0, ret);
427 }
428 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
429 ASSERT_EQ(0, ret);
430 ASSERT_EQ(DATA_ROLE_DEVICE, dataRole);
431 }
432
433 /**
434 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3700
435 * @tc.name: testHdiUsbFunctionTestQueryPort004
436 * @tc.desc: Queries the current settings of a port.To see if portId is equal to DEFAULT_PORT_ID.
437 */
438 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort004, Function | MediumTest | Level1)
439 {
440 int32_t portId = 0;
441 int32_t powerRole = POWER_ROLE_NONE;
442 int32_t dataRole = DATA_ROLE_NONE;
443 int32_t mode = PORT_MODE_NONE;
444 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
445 if (ret != 0) {
446 ASSERT_EQ(HDF_ERR_NOT_SUPPORT, ret);
447 } else {
448 ASSERT_EQ(0, ret);
449 }
450 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
451 ASSERT_EQ(0, ret);
452 ASSERT_EQ(DEFAULT_PORT_ID, portId);
453 }
454
455 /**
456 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3800
457 * @tc.name: testHdiUsbFunctionTestQueryPort005
458 * @tc.desc: Queries the current settings of a port.To see if powerRole is equal to DATA_ROLE_HOST.
459 */
460 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort005, Function | MediumTest | Level1)
461 {
462 int32_t portId = DEFAULT_PORT_ID;
463 int32_t powerRole = POWER_ROLE_NONE;
464 int32_t dataRole = DATA_ROLE_NONE;
465 int32_t mode = PORT_MODE_NONE;
466 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
467 if (ret == HDF_SUCCESS) {
468 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
469 ASSERT_EQ(0, ret);
470 ASSERT_EQ(POWER_ROLE_SOURCE, powerRole);
471 } else if (ret == HDF_ERR_NOT_SUPPORT) {
472 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
473 ASSERT_EQ(0, ret);
474 ASSERT_EQ(POWER_ROLE_SINK, powerRole);
475 }
476 }
477
478 /**
479 * @tc.number: SUB_USB_DeviceManager_HDI_FunctionTest_3900
480 * @tc.name: testHdiUsbFunctionTestQueryPort006
481 * @tc.desc: Queries the current settings of a port.To see if dataRole is equal to DATA_ROLE_HOST.
482 */
483 HWTEST_F(UsbdFunctionTestAdditional, testHdiUsbFunctionTestQueryPort006, Function | MediumTest | Level1)
484 {
485 int32_t portId = DEFAULT_PORT_ID;
486 int32_t powerRole = POWER_ROLE_NONE;
487 int32_t dataRole = DATA_ROLE_NONE;
488 int32_t mode = PORT_MODE_NONE;
489 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
490 if (ret == HDF_SUCCESS) {
491 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
492 ASSERT_EQ(0, ret);
493 ASSERT_EQ(DATA_ROLE_HOST, dataRole);
494 } else if (ret == HDF_ERR_NOT_SUPPORT) {
495 ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
496 ASSERT_EQ(0, ret);
497 ASSERT_EQ(DATA_ROLE_DEVICE, dataRole);
498 }
499 }
500
501 } // namespace
502