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