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