1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "usbd_function_test.h"
17
18 #include <iostream>
19
20 #include "hdf_log.h"
21 #include "if_system_ability_manager.h"
22 #include "system_ability_definition.h"
23 #include "usbd_function.h"
24 #include "usbd_port.h"
25 #include "v1_0/iusb_interface.h"
26 #include "v1_0/usb_types.h"
27
28 constexpr int32_t USB_FUNCTION_INVALID = -1;
29 constexpr int32_t USB_PORT_ID_INVALID = 2;
30 constexpr int32_t USB_POWER_ROLE_INVALID = 4;
31 constexpr int32_t USB_DATA_ROLE_INVALID = 5;
32 constexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
33
34 using namespace testing::ext;
35 using namespace OHOS;
36 using namespace std;
37 using namespace OHOS::HDI::Usb::V1_0;
38
39 namespace {
40 sptr<IUsbInterface> g_usbInterface = nullptr;
41
SwitchErrCode(int32_t ret)42 int32_t SwitchErrCode(int32_t ret)
43 {
44 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
45 }
46
SetUpTestCase(void)47 void UsbdFunctionTest::SetUpTestCase(void)
48 {
49 g_usbInterface = IUsbInterface::Get();
50 if (g_usbInterface == nullptr) {
51 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
52 exit(0);
53 }
54 }
55
TearDownTestCase(void)56 void UsbdFunctionTest::TearDownTestCase(void) {}
57
SetUp(void)58 void UsbdFunctionTest::SetUp(void) {}
59
TearDown(void)60 void UsbdFunctionTest::TearDown(void) {}
61
62 /**
63 * @tc.name: UsbdGetCurrentFunctions001
64 * @tc.desc: Test functions to GetCurrentFunctions
65 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
66 * @tc.desc: Positive test: parameters correctly
67 * @tc.type: FUNC
68 */
69 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, TestSize.Level1)
70 {
71 int32_t func = USB_FUNCTION_NONE;
72 auto ret = g_usbInterface->GetCurrentFunctions(func);
73 HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
74 EXPECT_EQ(0, ret);
75 }
76
77 /**
78 * @tc.name: UsbdGetCurrentFunctions002
79 * @tc.desc: Test functions to GetCurrentFunctions
80 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
81 * @tc.desc: Positive test: parameters correctly
82 * @tc.type: FUNC
83 */
84 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, TestSize.Level1)
85 {
86 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
87 HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
88 ASSERT_EQ(0, ret);
89 int32_t func = USB_FUNCTION_NONE;
90 ret = g_usbInterface->GetCurrentFunctions(func);
91 HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
92 EXPECT_EQ(0, ret);
93 }
94
95 /**********************************************************************************************************/
96
97 /**
98 * @tc.name: UsbdSetCurrentFunctions001
99 * @tc.desc: Test functions to SetCurrentFunctions
100 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
101 * @tc.desc: Positive test: parameters correctly
102 * @tc.type: FUNC
103 */
104 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, TestSize.Level1)
105 {
106 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
107 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
108 EXPECT_EQ(0, ret);
109 }
110
111 /**
112 * @tc.name: UsbdSetCurrentFunctions002
113 * @tc.desc: Test functions to SetCurrentFunctions
114 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
115 * @tc.desc: Negative test: parameters exception, funcs error
116 * @tc.type: FUNC
117 */
118 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, TestSize.Level1)
119 {
120 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
121 HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d", __LINE__, ret);
122 EXPECT_NE(ret, 0);
123 }
124 /**
125 * @tc.name: UsbdSetCurrentFunctions003
126 * @tc.desc: Test functions to SetCurrentFunctions
127 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
128 * @tc.desc: Positive test: parameters correctly
129 * @tc.type: FUNC
130 */
131 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, TestSize.Level1)
132 {
133 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
134 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
135 EXPECT_EQ(0, ret);
136 }
137
138 /**
139 * @tc.name: UsbdSetCurrentFunctions004
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, UsbdSetCurrentFunctions004, TestSize.Level1)
146 {
147 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
148 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
149 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
150 EXPECT_EQ(0, ret);
151 }
152
153 /**
154 * @tc.name: UsbdSetCurrentFunctions005
155 * @tc.desc: Test functions to SetCurrentFunctions
156 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
157 * @tc.desc: Positive test: parameters correctly
158 * @tc.type: FUNC
159 */
160 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, TestSize.Level1)
161 {
162 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
163 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
164 EXPECT_EQ(0, ret);
165 }
166
167 /**
168 * @tc.name: UsbdSetCurrentFunctions006
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, UsbdSetCurrentFunctions006, TestSize.Level1)
175 {
176 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
177 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
178 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
179 EXPECT_EQ(0, ret);
180 }
181
182 /**
183 * @tc.name: UsbdSetCurrentFunctions007
184 * @tc.desc: Test functions to SetCurrentFunctions
185 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
186 * @tc.desc: Positive test: parameters correctly
187 * @tc.type: FUNC
188 */
189 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, TestSize.Level1)
190 {
191 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
192 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
193 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
194 EXPECT_EQ(0, ret);
195 }
196
197 /**
198 * @tc.name: UsbdSetCurrentFunctions008
199 * @tc.desc: Test functions to SetCurrentFunctions
200 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
201 * @tc.desc: Positive test: parameters correctly
202 * @tc.type: FUNC
203 */
204 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions008, TestSize.Level1)
205 {
206 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
207 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions008 %{public}d ret=%{public}d", __LINE__, ret);
208 EXPECT_EQ(0, ret);
209 }
210
211 /**
212 * @tc.name: UsbdSetCurrentFunctions009
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, UsbdSetCurrentFunctions009, TestSize.Level1)
219 {
220 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
221 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions009 %{public}d ret=%{public}d", __LINE__, ret);
222 EXPECT_EQ(0, ret);
223 }
224
225 /**
226 * @tc.name: UsbdSetCurrentFunctions010
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, UsbdSetCurrentFunctions010, TestSize.Level1)
233 {
234 int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
235 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
236 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions010 %{public}d ret=%{public}d", __LINE__, ret);
237 EXPECT_EQ(0, ret);
238 }
239
240 /**
241 * @tc.name: UsbdSetCurrentFunctions011
242 * @tc.desc: Test functions to SetCurrentFunctions
243 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
244 * @tc.desc: Positive test: parameters correctly
245 * @tc.type: FUNC
246 */
247 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions011, TestSize.Level1)
248 {
249 int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
250 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
251 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions011 %{public}d ret=%{public}d", __LINE__, ret);
252 EXPECT_EQ(0, ret);
253 }
254
255 /**
256 * @tc.name: UsbdSetCurrentFunctions012
257 * @tc.desc: Test functions to SetCurrentFunctions
258 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
259 * @tc.desc: Positive test: parameters correctly
260 * @tc.type: FUNC
261 */
262 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions012, TestSize.Level1)
263 {
264 int32_t funcs = USB_FUNCTION_MTP;
265 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
266 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions012 %{public}d ret=%{public}d", __LINE__, ret);
267 EXPECT_EQ(0, ret);
268 }
269
270 /**
271 * @tc.name: UsbdSetCurrentFunctions013
272 * @tc.desc: Test functions to SetCurrentFunctions
273 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
274 * @tc.desc: Positive test: parameters correctly
275 * @tc.type: FUNC
276 */
277 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions013, TestSize.Level1)
278 {
279 int32_t funcs = USB_FUNCTION_PTP;
280 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
281 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 %{public}d ret=%{public}d", __LINE__, ret);
282 EXPECT_EQ(0, ret);
283 }
284
285 /**
286 * @tc.name: UsbdSetCurrentFunctions014
287 * @tc.desc: Test functions to SetCurrentFunctions
288 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
289 * @tc.desc: Positive test: parameters correctly
290 * @tc.type: FUNC
291 */
292 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions014, TestSize.Level1)
293 {
294 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
295 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
296 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions014 %{public}d ret=%{public}d", __LINE__, ret);
297 EXPECT_EQ(0, ret);
298 }
299
300 /**
301 * @tc.name: UsbdSetCurrentFunctions015
302 * @tc.desc: Test functions to SetCurrentFunctions
303 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
304 * @tc.desc: Positive test: parameters correctly
305 * @tc.type: FUNC
306 */
307 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions015, TestSize.Level1)
308 {
309 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
310 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
311 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions015 %{public}d ret=%{public}d", __LINE__, ret);
312 EXPECT_EQ(0, ret);
313 }
314
315 /**
316 * @tc.name: UsbdSetCurrentFunctions016
317 * @tc.desc: Test functions to SetCurrentFunctions
318 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
319 * @tc.desc: Positive test: parameters correctly
320 * @tc.type: FUNC
321 */
322 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions016, TestSize.Level1)
323 {
324 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
325 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
326 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions016 %{public}d ret=%{public}d", __LINE__, ret);
327 EXPECT_EQ(0, ret);
328 }
329
330 /**
331 * @tc.name: UsbdSetCurrentFunctions017
332 * @tc.desc: Test functions to SetCurrentFunctions
333 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
334 * @tc.desc: Positive test: parameters correctly
335 * @tc.type: FUNC
336 */
337 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions017, TestSize.Level1)
338 {
339 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
340 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
341 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions017 %{public}d ret=%{public}d", __LINE__, ret);
342 EXPECT_EQ(0, ret);
343 }
344
345 /**
346 * @tc.name: UsbdSetCurrentFunctions018
347 * @tc.desc: Test functions to SetCurrentFunctions
348 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
349 * @tc.desc: Negative test: parameters exception, funcs error
350 * @tc.type: FUNC
351 */
352 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions018, TestSize.Level1)
353 {
354 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
355 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions018 %{public}d ret=%{public}d", __LINE__, ret);
356 EXPECT_NE(ret, 0);
357 }
358
359 /**
360 * @tc.name: UsbdSetCurrentFunctions019
361 * @tc.desc: Test functions to SetCurrentFunctions
362 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
363 * @tc.desc: Positive test: parameters correctly
364 * @tc.type: FUNC
365 */
366 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions019, TestSize.Level1)
367 {
368 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
369 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 ret=%{public}d", ret);
370 ASSERT_EQ(0, ret);
371 HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
372 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
373 EXPECT_EQ(0, ret);
374 }
375
376 /**
377 * @tc.name: UsbdSetPortRole001
378 * @tc.desc: Test functions to SetPortRole
379 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
380 * @tc.desc: Positive test: parameters correctly
381 * @tc.type: FUNC
382 */
383 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, TestSize.Level1)
384 {
385 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
386 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
387 ret = SwitchErrCode(ret);
388 EXPECT_EQ(0, ret);
389 }
390
391 /**
392 * @tc.name: UsbdSetPortRole002
393 * @tc.desc: Test functions to SetPortRole
394 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
395 * @tc.desc: Negative test: parameters exception, portId error
396 * @tc.type: FUNC
397 */
398 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, TestSize.Level1)
399 {
400 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
401 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
402 ret = SwitchErrCode(ret);
403 EXPECT_NE(ret, 0);
404 }
405
406 /**
407 * @tc.name: UsbdSetPortRole003
408 * @tc.desc: Test functions to SetPortRole
409 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
410 * @tc.desc: Negative test: parameters exception, powerRole error
411 * @tc.type: FUNC
412 */
413 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole003, TestSize.Level1)
414 {
415 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
416 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole003 %{public}d ret=%{public}d", __LINE__, ret);
417 ret = SwitchErrCode(ret);
418 EXPECT_NE(ret, 0);
419 }
420
421 /**
422 * @tc.name: UsbdSetPortRole004
423 * @tc.desc: Test functions to SetPortRole
424 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
425 * @tc.desc: Negative test: parameters exception, dataRole error
426 * @tc.type: FUNC
427 */
428 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole004, TestSize.Level1)
429 {
430 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
431 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole004 %{public}d ret=%{public}d", __LINE__, ret);
432 ret = SwitchErrCode(ret);
433 EXPECT_NE(ret, 0);
434 }
435
436 /**
437 * @tc.name: UsbdSetPortRole005
438 * @tc.desc: Test functions to SetPortRole
439 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
440 * @tc.desc: Negative test: parameters exception, powerRole error
441 * @tc.type: FUNC
442 */
443 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole005, TestSize.Level1)
444 {
445 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
446 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole005 %{public}d ret=%{public}d", __LINE__, ret);
447 ret = SwitchErrCode(ret);
448 EXPECT_NE(ret, 0);
449 }
450
451 /**
452 * @tc.name: UsbdSetPortRole006
453 * @tc.desc: Test functions to SetPortRole
454 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
455 * @tc.desc: Negative test: parameters exception, portId && dataRole error
456 * @tc.type: FUNC
457 */
458 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole006, TestSize.Level1)
459 {
460 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
461 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole006 %{public}d ret=%{public}d", __LINE__, ret);
462 ret = SwitchErrCode(ret);
463 EXPECT_NE(ret, 0);
464 }
465
466 /**
467 * @tc.name: UsbdSetPortRole007
468 * @tc.desc: Test functions to SetPortRole
469 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
470 * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
471 * @tc.type: FUNC
472 */
473 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole007, TestSize.Level1)
474 {
475 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
476 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole007 %{public}d ret=%{public}d", __LINE__, ret);
477 ret = SwitchErrCode(ret);
478 EXPECT_NE(ret, 0);
479 }
480
481 /**
482 * @tc.name: UsbdSetPortRole008
483 * @tc.desc: Test functions to SetPortRole
484 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
485 * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
486 * @tc.type: FUNC
487 */
488 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole008, TestSize.Level1)
489 {
490 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
491 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole008 %{public}d ret=%{public}d", __LINE__, ret);
492 ret = SwitchErrCode(ret);
493 EXPECT_NE(ret, 0);
494 }
495
496 /**
497 * @tc.name: SetPortRole009
498 * @tc.desc: Test functions to SetPortRole
499 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
500 * @tc.desc: Positive test: parameters correctly
501 * @tc.type: FUNC
502 */
503 HWTEST_F(UsbdFunctionTest, SetPortRole09, TestSize.Level1)
504 {
505 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
506 HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
507 ret = SwitchErrCode(ret);
508 EXPECT_EQ(0, ret);
509 }
510
511 /**
512 * @tc.name: QueryPort001
513 * @tc.desc: Test functions to QueryPort
514 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
515 * @tc.desc: Positive test: parameters correctly
516 * @tc.type: FUNC
517 */
518 HWTEST_F(UsbdFunctionTest, QueryPort001, TestSize.Level1)
519 {
520 int32_t portId = DEFAULT_PORT_ID;
521 int32_t powerRole = POWER_ROLE_NONE;
522 int32_t dataRole = DATA_ROLE_NONE;
523 int32_t mode = PORT_MODE_NONE;
524 auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
525 HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
526 EXPECT_EQ(0, ret);
527 }
528
529 /**
530 * @tc.name: QueryPorts001
531 * @tc.desc: Test functions to QueryPorts
532 * @tc.desc: int32_t QueryPorts(std::vector<UsbPort>& portList);
533 * @tc.desc: Positive test: parameters correctly
534 * @tc.type: FUNC
535 */
536 HWTEST_F(UsbdFunctionTest, QueryPorts001, TestSize.Level1)
537 {
538 sptr<HDI::Usb::V2_0::IUsbPortInterface> usbPortInterface_ = nullptr;
539 usbPortInterface_ = HDI::Usb::V2_0::IUsbPortInterface::Get();
540 if (usbPortInterface_ == nullptr) {
541 HDF_LOGE("%{public}s:usbPortInterface_::Get() failed.", __func__);
542 exit(0);
543 }
544 std::vector<HDI::Usb::V2_0::UsbPort> portList;
545 auto ret = usbPortInterface_->QueryPorts(portList);
546 HDF_LOGI("UsbdFunctionTest::QueryPorts001 %{public}d ret=%{public}d", __LINE__, ret);
547 EXPECT_EQ(0, ret);
548 }
549 } // namespace
550