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 SLEEP_TIME = 3;
29 constexpr int32_t USB_FUNCTION_INVALID = -1;
30 constexpr int32_t USB_PORT_ID_INVALID = 2;
31 constexpr int32_t USB_POWER_ROLE_INVALID = 4;
32 constexpr int32_t USB_DATA_ROLE_INVALID = 5;
33 constexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
34
35 using namespace testing::ext;
36 using namespace OHOS;
37 using namespace std;
38 using namespace OHOS::HDI::Usb::V1_0;
39
40 namespace {
41 sptr<IUsbInterface> g_usbInterface = nullptr;
42
SetUpTestCase(void)43 void UsbdFunctionTest::SetUpTestCase(void)
44 {
45 g_usbInterface = IUsbInterface::Get();
46 if (g_usbInterface == nullptr) {
47 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
48 exit(0);
49 }
50 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
51 sleep(SLEEP_TIME);
52 HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
53 ASSERT_EQ(0, ret);
54 if (ret != 0) {
55 exit(0);
56 }
57 }
58
TearDownTestCase(void)59 void UsbdFunctionTest::TearDownTestCase(void) {}
60
SetUp(void)61 void UsbdFunctionTest::SetUp(void) {}
62
TearDown(void)63 void UsbdFunctionTest::TearDown(void) {}
64
65 /**
66 * @tc.name: UsbdGetCurrentFunctions001
67 * @tc.desc: Test functions to GetCurrentFunctions
68 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
69 * @tc.desc: Positive test: parameters correctly
70 * @tc.type: FUNC
71 */
72 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, TestSize.Level1)
73 {
74 int32_t func = USB_FUNCTION_NONE;
75 auto ret = g_usbInterface->GetCurrentFunctions(func);
76 HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
77 ASSERT_EQ(0, ret);
78 }
79
80 /**
81 * @tc.name: UsbdGetCurrentFunctions002
82 * @tc.desc: Test functions to GetCurrentFunctions
83 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
84 * @tc.desc: Positive test: parameters correctly
85 * @tc.type: FUNC
86 */
87 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, TestSize.Level1)
88 {
89 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
90 HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
91 ASSERT_EQ(0, ret);
92 int32_t func = USB_FUNCTION_NONE;
93 ret = g_usbInterface->GetCurrentFunctions(func);
94 HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
95 ASSERT_EQ(0, ret);
96 }
97
98 /**********************************************************************************************************/
99
100 /**
101 * @tc.name: UsbdSetCurrentFunctions001
102 * @tc.desc: Test functions to SetCurrentFunctions
103 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
104 * @tc.desc: Positive test: parameters correctly
105 * @tc.type: FUNC
106 */
107 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, TestSize.Level1)
108 {
109 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
110 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
111 ASSERT_EQ(0, ret);
112 }
113
114 /**
115 * @tc.name: UsbdSetCurrentFunctions002
116 * @tc.desc: Test functions to SetCurrentFunctions
117 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
118 * @tc.desc: Negative test: parameters exception, funcs error
119 * @tc.type: FUNC
120 */
121 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, TestSize.Level1)
122 {
123 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
124 HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d", __LINE__, ret);
125 ASSERT_NE(ret, 0);
126 }
127 /**
128 * @tc.name: UsbdSetCurrentFunctions003
129 * @tc.desc: Test functions to SetCurrentFunctions
130 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
131 * @tc.desc: Positive test: parameters correctly
132 * @tc.type: FUNC
133 */
134 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, TestSize.Level1)
135 {
136 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
137 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
138 ASSERT_EQ(0, ret);
139 }
140
141 /**
142 * @tc.name: UsbdSetCurrentFunctions004
143 * @tc.desc: Test functions to SetCurrentFunctions
144 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
145 * @tc.desc: Positive test: parameters correctly
146 * @tc.type: FUNC
147 */
148 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, TestSize.Level1)
149 {
150 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
151 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
152 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
153 ASSERT_EQ(0, ret);
154 }
155
156 /**
157 * @tc.name: UsbdSetCurrentFunctions005
158 * @tc.desc: Test functions to SetCurrentFunctions
159 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
160 * @tc.desc: Positive test: parameters correctly
161 * @tc.type: FUNC
162 */
163 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, TestSize.Level1)
164 {
165 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
166 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
167 ASSERT_EQ(0, ret);
168 }
169
170 /**
171 * @tc.name: UsbdSetCurrentFunctions006
172 * @tc.desc: Test functions to SetCurrentFunctions
173 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
174 * @tc.desc: Positive test: parameters correctly
175 * @tc.type: FUNC
176 */
177 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, TestSize.Level1)
178 {
179 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
180 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
181 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
182 ASSERT_EQ(0, ret);
183 }
184
185 /**
186 * @tc.name: UsbdSetCurrentFunctions007
187 * @tc.desc: Test functions to SetCurrentFunctions
188 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
189 * @tc.desc: Positive test: parameters correctly
190 * @tc.type: FUNC
191 */
192 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, TestSize.Level1)
193 {
194 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
195 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
196 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
197 ASSERT_EQ(0, ret);
198 }
199
200 /**
201 * @tc.name: UsbdSetCurrentFunctions008
202 * @tc.desc: Test functions to SetCurrentFunctions
203 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
204 * @tc.desc: Positive test: parameters correctly
205 * @tc.type: FUNC
206 */
207 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions008, TestSize.Level1)
208 {
209 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
210 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions008 %{public}d ret=%{public}d", __LINE__, ret);
211 ASSERT_EQ(0, ret);
212 }
213
214 /**
215 * @tc.name: UsbdSetCurrentFunctions009
216 * @tc.desc: Test functions to SetCurrentFunctions
217 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
218 * @tc.desc: Positive test: parameters correctly
219 * @tc.type: FUNC
220 */
221 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions009, TestSize.Level1)
222 {
223 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
224 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions009 %{public}d ret=%{public}d", __LINE__, ret);
225 ASSERT_EQ(0, ret);
226 }
227
228 /**
229 * @tc.name: UsbdSetCurrentFunctions010
230 * @tc.desc: Test functions to SetCurrentFunctions
231 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
232 * @tc.desc: Positive test: parameters correctly
233 * @tc.type: FUNC
234 */
235 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions010, TestSize.Level1)
236 {
237 int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
238 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
239 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions010 %{public}d ret=%{public}d", __LINE__, ret);
240 ASSERT_EQ(0, ret);
241 }
242
243 /**
244 * @tc.name: UsbdSetCurrentFunctions011
245 * @tc.desc: Test functions to SetCurrentFunctions
246 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
247 * @tc.desc: Positive test: parameters correctly
248 * @tc.type: FUNC
249 */
250 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions011, TestSize.Level1)
251 {
252 int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
253 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
254 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions011 %{public}d ret=%{public}d", __LINE__, ret);
255 ASSERT_EQ(0, ret);
256 }
257
258 /**
259 * @tc.name: UsbdSetCurrentFunctions012
260 * @tc.desc: Test functions to SetCurrentFunctions
261 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
262 * @tc.desc: Positive test: parameters correctly
263 * @tc.type: FUNC
264 */
265 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions012, TestSize.Level1)
266 {
267 int32_t funcs = USB_FUNCTION_MTP;
268 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
269 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions012 %{public}d ret=%{public}d", __LINE__, ret);
270 ASSERT_EQ(0, ret);
271 }
272
273 /**
274 * @tc.name: UsbdSetCurrentFunctions013
275 * @tc.desc: Test functions to SetCurrentFunctions
276 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
277 * @tc.desc: Positive test: parameters correctly
278 * @tc.type: FUNC
279 */
280 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions013, TestSize.Level1)
281 {
282 int32_t funcs = USB_FUNCTION_PTP;
283 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
284 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 %{public}d ret=%{public}d", __LINE__, ret);
285 ASSERT_EQ(0, ret);
286 }
287
288 /**
289 * @tc.name: UsbdSetCurrentFunctions014
290 * @tc.desc: Test functions to SetCurrentFunctions
291 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
292 * @tc.desc: Positive test: parameters correctly
293 * @tc.type: FUNC
294 */
295 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions014, TestSize.Level1)
296 {
297 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
298 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
299 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions014 %{public}d ret=%{public}d", __LINE__, ret);
300 ASSERT_EQ(0, ret);
301 }
302
303 /**
304 * @tc.name: UsbdSetCurrentFunctions015
305 * @tc.desc: Test functions to SetCurrentFunctions
306 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
307 * @tc.desc: Positive test: parameters correctly
308 * @tc.type: FUNC
309 */
310 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions015, TestSize.Level1)
311 {
312 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
313 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
314 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions015 %{public}d ret=%{public}d", __LINE__, ret);
315 ASSERT_EQ(0, ret);
316 }
317
318 /**
319 * @tc.name: UsbdSetCurrentFunctions016
320 * @tc.desc: Test functions to SetCurrentFunctions
321 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
322 * @tc.desc: Positive test: parameters correctly
323 * @tc.type: FUNC
324 */
325 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions016, TestSize.Level1)
326 {
327 int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
328 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
329 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions016 %{public}d ret=%{public}d", __LINE__, ret);
330 ASSERT_EQ(0, ret);
331 }
332
333 /**
334 * @tc.name: UsbdSetCurrentFunctions017
335 * @tc.desc: Test functions to SetCurrentFunctions
336 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
337 * @tc.desc: Positive test: parameters correctly
338 * @tc.type: FUNC
339 */
340 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions017, TestSize.Level1)
341 {
342 int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
343 auto ret = g_usbInterface->SetCurrentFunctions(funcs);
344 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions017 %{public}d ret=%{public}d", __LINE__, ret);
345 ASSERT_EQ(0, ret);
346 }
347
348 /**
349 * @tc.name: UsbdSetCurrentFunctions018
350 * @tc.desc: Test functions to SetCurrentFunctions
351 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
352 * @tc.desc: Negative test: parameters exception, funcs error
353 * @tc.type: FUNC
354 */
355 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions018, TestSize.Level1)
356 {
357 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
358 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions018 %{public}d ret=%{public}d", __LINE__, ret);
359 ASSERT_NE(ret, 0);
360 }
361
362 /**
363 * @tc.name: UsbdSetCurrentFunctions019
364 * @tc.desc: Test functions to SetCurrentFunctions
365 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
366 * @tc.desc: Positive test: parameters correctly
367 * @tc.type: FUNC
368 */
369 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions019, TestSize.Level1)
370 {
371 auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
372 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 ret=%{public}d", ret);
373 ASSERT_EQ(0, ret);
374 HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
375 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
376 ASSERT_EQ(0, ret);
377 }
378
379 /**
380 * @tc.name: UsbdSetPortRole001
381 * @tc.desc: Test functions to SetPortRole
382 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
383 * @tc.desc: Positive test: parameters correctly
384 * @tc.type: FUNC
385 */
386 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, TestSize.Level1)
387 {
388 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
389 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
390 ASSERT_EQ(0, ret);
391 }
392
393 /**
394 * @tc.name: UsbdSetPortRole002
395 * @tc.desc: Test functions to SetPortRole
396 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
397 * @tc.desc: Negative test: parameters exception, portId error
398 * @tc.type: FUNC
399 */
400 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, TestSize.Level1)
401 {
402 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
403 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
404 ASSERT_NE(ret, 0);
405 }
406
407 /**
408 * @tc.name: UsbdSetPortRole003
409 * @tc.desc: Test functions to SetPortRole
410 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
411 * @tc.desc: Negative test: parameters exception, powerRole error
412 * @tc.type: FUNC
413 */
414 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole003, TestSize.Level1)
415 {
416 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
417 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole003 %{public}d ret=%{public}d", __LINE__, ret);
418 ASSERT_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 ASSERT_NE(ret, 0);
433 }
434
435 /**
436 * @tc.name: UsbdSetPortRole005
437 * @tc.desc: Test functions to SetPortRole
438 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
439 * @tc.desc: Negative test: parameters exception, powerRole error
440 * @tc.type: FUNC
441 */
442 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole005, TestSize.Level1)
443 {
444 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
445 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole005 %{public}d ret=%{public}d", __LINE__, ret);
446 ASSERT_NE(ret, 0);
447 }
448
449 /**
450 * @tc.name: UsbdSetPortRole006
451 * @tc.desc: Test functions to SetPortRole
452 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
453 * @tc.desc: Negative test: parameters exception, portId && dataRole error
454 * @tc.type: FUNC
455 */
456 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole006, TestSize.Level1)
457 {
458 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
459 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole006 %{public}d ret=%{public}d", __LINE__, ret);
460 ASSERT_NE(ret, 0);
461 }
462
463 /**
464 * @tc.name: UsbdSetPortRole007
465 * @tc.desc: Test functions to SetPortRole
466 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
467 * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
468 * @tc.type: FUNC
469 */
470 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole007, TestSize.Level1)
471 {
472 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
473 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole007 %{public}d ret=%{public}d", __LINE__, ret);
474 ASSERT_NE(ret, 0);
475 }
476
477 /**
478 * @tc.name: UsbdSetPortRole008
479 * @tc.desc: Test functions to SetPortRole
480 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
481 * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
482 * @tc.type: FUNC
483 */
484 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole008, TestSize.Level1)
485 {
486 auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
487 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole008 %{public}d ret=%{public}d", __LINE__, ret);
488 ASSERT_NE(ret, 0);
489 }
490
491 /**
492 * @tc.name: SetPortRole009
493 * @tc.desc: Test functions to SetPortRole
494 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
495 * @tc.desc: Positive test: parameters correctly
496 * @tc.type: FUNC
497 */
498 HWTEST_F(UsbdFunctionTest, SetPortRole09, TestSize.Level1)
499 {
500 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
501 HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
502 ASSERT_EQ(0, ret);
503 }
504
505 /**
506 * @tc.name: QueryPort001
507 * @tc.desc: Test functions to QueryPort
508 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
509 * @tc.desc: Positive test: parameters correctly
510 * @tc.type: FUNC
511 */
512 HWTEST_F(UsbdFunctionTest, QueryPort001, TestSize.Level1)
513 {
514 int32_t portId = DEFAULT_PORT_ID;
515 int32_t powerRole = POWER_ROLE_NONE;
516 int32_t dataRole = DATA_ROLE_NONE;
517 int32_t mode = PORT_MODE_NONE;
518 auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
519 HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
520 ASSERT_EQ(0, ret);
521 }
522 } // namespace
523