19762338dSopenharmony_ci/*
29762338dSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49762338dSopenharmony_ci * you may not use this file except in compliance with the License.
59762338dSopenharmony_ci * You may obtain a copy of the License at
69762338dSopenharmony_ci *
79762338dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
89762338dSopenharmony_ci *
99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129762338dSopenharmony_ci * See the License for the specific language governing permissions and
139762338dSopenharmony_ci * limitations under the License.
149762338dSopenharmony_ci */
159762338dSopenharmony_ci
169762338dSopenharmony_ci#include <iostream>
179762338dSopenharmony_ci
189762338dSopenharmony_ci#include "hdf_log.h"
199762338dSopenharmony_ci#include "if_system_ability_manager.h"
209762338dSopenharmony_ci#include "system_ability_definition.h"
219762338dSopenharmony_ci#include "usbd_function_test.h"
229762338dSopenharmony_ci#include "v1_0/iusb_interface.h"
239762338dSopenharmony_ci#include "v1_0/usb_types.h"
249762338dSopenharmony_ci
259762338dSopenharmony_ciconstexpr int32_t SLEEP_TIME = 3;
269762338dSopenharmony_ciconstexpr int32_t USB_FUNCTION_INVALID = -1;
279762338dSopenharmony_ciconstexpr int32_t USB_PORT_ID_INVALID = 2;
289762338dSopenharmony_ciconstexpr int32_t USB_POWER_ROLE_INVALID = 4;
299762338dSopenharmony_ciconstexpr int32_t USB_DATA_ROLE_INVALID = 5;
309762338dSopenharmony_ciconstexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
319762338dSopenharmony_ci
329762338dSopenharmony_ciusing namespace testing::ext;
339762338dSopenharmony_ciusing namespace OHOS;
349762338dSopenharmony_ciusing namespace std;
359762338dSopenharmony_ciusing namespace OHOS::HDI::Usb::V1_0;
369762338dSopenharmony_ci
379762338dSopenharmony_cinamespace {
389762338dSopenharmony_cisptr<IUsbInterface> g_usbInterface = nullptr;
399762338dSopenharmony_ci
409762338dSopenharmony_ciint32_t SwitchErrCode(int32_t ret)
419762338dSopenharmony_ci{
429762338dSopenharmony_ci    return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
439762338dSopenharmony_ci}
449762338dSopenharmony_ci
459762338dSopenharmony_civoid UsbdFunctionTest::SetUpTestCase(void)
469762338dSopenharmony_ci{
479762338dSopenharmony_ci    g_usbInterface = IUsbInterface::Get();
489762338dSopenharmony_ci    if (g_usbInterface == nullptr) {
499762338dSopenharmony_ci        HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
509762338dSopenharmony_ci        exit(0);
519762338dSopenharmony_ci    }
529762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
539762338dSopenharmony_ci    sleep(SLEEP_TIME);
549762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
559762338dSopenharmony_ci    ret = SwitchErrCode(ret);
569762338dSopenharmony_ci    ASSERT_EQ(0, ret);
579762338dSopenharmony_ci    if (ret != 0) {
589762338dSopenharmony_ci        exit(0);
599762338dSopenharmony_ci    }
609762338dSopenharmony_ci}
619762338dSopenharmony_ci
629762338dSopenharmony_civoid UsbdFunctionTest::TearDownTestCase(void)
639762338dSopenharmony_ci{
649762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
659762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
669762338dSopenharmony_ci    ASSERT_EQ(0, ret);
679762338dSopenharmony_ci}
689762338dSopenharmony_ci
699762338dSopenharmony_civoid UsbdFunctionTest::SetUp(void) {}
709762338dSopenharmony_ci
719762338dSopenharmony_civoid UsbdFunctionTest::TearDown(void) {}
729762338dSopenharmony_ci
739762338dSopenharmony_ci/**
749762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0300
759762338dSopenharmony_ci * @tc.desc: Test functions to GetCurrentFunctions
769762338dSopenharmony_ci * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
779762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
789762338dSopenharmony_ci * @tc.type: FUNC
799762338dSopenharmony_ci */
809762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0300, Function | MediumTest | Level1)
819762338dSopenharmony_ci{
829762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_NONE;
839762338dSopenharmony_ci    auto ret = g_usbInterface->GetCurrentFunctions(funcs);
849762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0300 %{public}d ret=%{public}d", __LINE__, ret);
859762338dSopenharmony_ci    ASSERT_EQ(0, ret);
869762338dSopenharmony_ci}
879762338dSopenharmony_ci
889762338dSopenharmony_ci/**
899762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0400
909762338dSopenharmony_ci * @tc.desc: Test functions to GetCurrentFunctions
919762338dSopenharmony_ci * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
929762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
939762338dSopenharmony_ci * @tc.type: FUNC
949762338dSopenharmony_ci */
959762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0400, Function | MediumTest | Level1)
969762338dSopenharmony_ci{
979762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
989762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d SetCurrentFunctions=%{public}d",
999762338dSopenharmony_ci        __LINE__, ret);
1009762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1019762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_NONE;
1029762338dSopenharmony_ci    ret = g_usbInterface->GetCurrentFunctions(funcs);
1039762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0400 %{public}d ret=%{public}d", __LINE__, ret);
1049762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1059762338dSopenharmony_ci}
1069762338dSopenharmony_ci
1079762338dSopenharmony_ci/**********************************************************************************************************/
1089762338dSopenharmony_ci
1099762338dSopenharmony_ci/**
1109762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0500
1119762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1129762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1139762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
1149762338dSopenharmony_ci * @tc.type: FUNC
1159762338dSopenharmony_ci */
1169762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0500, Function | MediumTest | Level1)
1179762338dSopenharmony_ci{
1189762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
1199762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0500 %{public}d SetCurrentFunctions=%{public}d",
1209762338dSopenharmony_ci        __LINE__, ret);
1219762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1229762338dSopenharmony_ci}
1239762338dSopenharmony_ci
1249762338dSopenharmony_ci/**
1259762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Compatibility_1500
1269762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1279762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1289762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, Funcs error
1299762338dSopenharmony_ci * @tc.type: FUNC
1309762338dSopenharmony_ci */
1319762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Compatibility_1500, Function | MediumTest | Level1)
1329762338dSopenharmony_ci{
1339762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
1349762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Compatibility_1500 %{public}d, ret=%{public}d",
1359762338dSopenharmony_ci        __LINE__, ret);
1369762338dSopenharmony_ci    ASSERT_NE(ret, 0);
1379762338dSopenharmony_ci}
1389762338dSopenharmony_ci/**
1399762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0600
1409762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1419762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1429762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
1439762338dSopenharmony_ci * @tc.type: FUNC
1449762338dSopenharmony_ci */
1459762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0600, Function | MediumTest | Level1)
1469762338dSopenharmony_ci{
1479762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
1489762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0600 %{public}d ret=%{public}d", __LINE__, ret);
1499762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1509762338dSopenharmony_ci}
1519762338dSopenharmony_ci
1529762338dSopenharmony_ci/**
1539762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0700
1549762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1559762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1569762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
1579762338dSopenharmony_ci * @tc.type: FUNC
1589762338dSopenharmony_ci */
1599762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0700, Function | MediumTest | Level1)
1609762338dSopenharmony_ci{
1619762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
1629762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
1639762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0700 %{public}d ret=%{public}d", __LINE__, ret);
1649762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1659762338dSopenharmony_ci}
1669762338dSopenharmony_ci
1679762338dSopenharmony_ci/**
1689762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0800
1699762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1709762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1719762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
1729762338dSopenharmony_ci * @tc.type: FUNC
1739762338dSopenharmony_ci */
1749762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0800, Function | MediumTest | Level1)
1759762338dSopenharmony_ci{
1769762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
1779762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0800 %{public}d ret=%{public}d", __LINE__, ret);
1789762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1799762338dSopenharmony_ci}
1809762338dSopenharmony_ci
1819762338dSopenharmony_ci/**
1829762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_0900
1839762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1849762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
1859762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
1869762338dSopenharmony_ci * @tc.type: FUNC
1879762338dSopenharmony_ci */
1889762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_0900, Function | MediumTest | Level1)
1899762338dSopenharmony_ci{
1909762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
1919762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
1929762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_0900 %{public}d ret=%{public}d", __LINE__, ret);
1939762338dSopenharmony_ci    ASSERT_EQ(0, ret);
1949762338dSopenharmony_ci}
1959762338dSopenharmony_ci
1969762338dSopenharmony_ci/**
1979762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1000
1989762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
1999762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2009762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2019762338dSopenharmony_ci * @tc.type: FUNC
2029762338dSopenharmony_ci */
2039762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1000, Function | MediumTest | Level1)
2049762338dSopenharmony_ci{
2059762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
2069762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
2079762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1000 %{public}d ret=%{public}d", __LINE__, ret);
2089762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2099762338dSopenharmony_ci}
2109762338dSopenharmony_ci
2119762338dSopenharmony_ci/**
2129762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1100
2139762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2149762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2159762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2169762338dSopenharmony_ci * @tc.type: FUNC
2179762338dSopenharmony_ci */
2189762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1100, Function | MediumTest | Level1)
2199762338dSopenharmony_ci{
2209762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
2219762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1100 %{public}d ret=%{public}d", __LINE__, ret);
2229762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2239762338dSopenharmony_ci}
2249762338dSopenharmony_ci
2259762338dSopenharmony_ci/**
2269762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1400
2279762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2289762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2299762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2309762338dSopenharmony_ci * @tc.type: FUNC
2319762338dSopenharmony_ci */
2329762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1400, Function | MediumTest | Level1)
2339762338dSopenharmony_ci{
2349762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
2359762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1400 %{public}d ret=%{public}d", __LINE__, ret);
2369762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2379762338dSopenharmony_ci}
2389762338dSopenharmony_ci
2399762338dSopenharmony_ci/**
2409762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1500
2419762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2429762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2439762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2449762338dSopenharmony_ci * @tc.type: FUNC
2459762338dSopenharmony_ci */
2469762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1500, Function | MediumTest | Level1)
2479762338dSopenharmony_ci{
2489762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
2499762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
2509762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1500 %{public}d ret=%{public}d", __LINE__, ret);
2519762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2529762338dSopenharmony_ci}
2539762338dSopenharmony_ci
2549762338dSopenharmony_ci/**
2559762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1600
2569762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2579762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2589762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2599762338dSopenharmony_ci * @tc.type: FUNC
2609762338dSopenharmony_ci */
2619762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1600, Function | MediumTest | Level1)
2629762338dSopenharmony_ci{
2639762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
2649762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
2659762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1600 %{public}d ret=%{public}d", __LINE__, ret);
2669762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2679762338dSopenharmony_ci}
2689762338dSopenharmony_ci
2699762338dSopenharmony_ci/**
2709762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1900
2719762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2729762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2739762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2749762338dSopenharmony_ci * @tc.type: FUNC
2759762338dSopenharmony_ci */
2769762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1900, Function | MediumTest | Level1)
2779762338dSopenharmony_ci{
2789762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP;
2799762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
2809762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1900 %{public}d ret=%{public}d", __LINE__, ret);
2819762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2829762338dSopenharmony_ci}
2839762338dSopenharmony_ci
2849762338dSopenharmony_ci/**
2859762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_2000
2869762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
2879762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
2889762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
2899762338dSopenharmony_ci * @tc.type: FUNC
2909762338dSopenharmony_ci */
2919762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2000, Function | MediumTest | Level1)
2929762338dSopenharmony_ci{
2939762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP;
2949762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
2959762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2000 %{public}d ret=%{public}d", __LINE__, ret);
2969762338dSopenharmony_ci    ASSERT_EQ(0, ret);
2979762338dSopenharmony_ci}
2989762338dSopenharmony_ci
2999762338dSopenharmony_ci/**
3009762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_2100
3019762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3029762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3039762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3049762338dSopenharmony_ci * @tc.type: FUNC
3059762338dSopenharmony_ci */
3069762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2100, Function | MediumTest | Level1)
3079762338dSopenharmony_ci{
3089762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
3099762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
3109762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2100 %{public}d ret=%{public}d", __LINE__, ret);
3119762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3129762338dSopenharmony_ci}
3139762338dSopenharmony_ci
3149762338dSopenharmony_ci/**
3159762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_2200
3169762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3179762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3189762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3199762338dSopenharmony_ci * @tc.type: FUNC
3209762338dSopenharmony_ci */
3219762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2200, Function | MediumTest | Level1)
3229762338dSopenharmony_ci{
3239762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
3249762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
3259762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2200 %{public}d ret=%{public}d", __LINE__, ret);
3269762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3279762338dSopenharmony_ci}
3289762338dSopenharmony_ci
3299762338dSopenharmony_ci/**
3309762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_2300
3319762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3329762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3339762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3349762338dSopenharmony_ci * @tc.type: FUNC
3359762338dSopenharmony_ci */
3369762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2300, Function | MediumTest | Level1)
3379762338dSopenharmony_ci{
3389762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
3399762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
3409762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2300 %{public}d ret=%{public}d", __LINE__, ret);
3419762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3429762338dSopenharmony_ci}
3439762338dSopenharmony_ci
3449762338dSopenharmony_ci/**
3459762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_2400
3469762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3479762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3489762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3499762338dSopenharmony_ci * @tc.type: FUNC
3509762338dSopenharmony_ci */
3519762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_2400, Function | MediumTest | Level1)
3529762338dSopenharmony_ci{
3539762338dSopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
3549762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
3559762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_2400 %{public}d ret=%{public}d", __LINE__, ret);
3569762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3579762338dSopenharmony_ci}
3589762338dSopenharmony_ci
3599762338dSopenharmony_ci/**
3609762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1700
3619762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3629762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3639762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, funcs error
3649762338dSopenharmony_ci * @tc.type: FUNC
3659762338dSopenharmony_ci */
3669762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1700, Function | MediumTest | Level1)
3679762338dSopenharmony_ci{
3689762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
3699762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1700 %{public}d ret=%{public}d", __LINE__, ret);
3709762338dSopenharmony_ci    ASSERT_NE(0, ret);
3719762338dSopenharmony_ci}
3729762338dSopenharmony_ci
3739762338dSopenharmony_ci/**
3749762338dSopenharmony_ci * @tc.name: SUB_USB_DeviceManager_HDI_Func_1800
3759762338dSopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
3769762338dSopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
3779762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3789762338dSopenharmony_ci * @tc.type: FUNC
3799762338dSopenharmony_ci */
3809762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_DeviceManager_HDI_Func_1800, Function | MediumTest | Level1)
3819762338dSopenharmony_ci{
3829762338dSopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
3839762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_DeviceManager_HDI_Func_1800 ret=%{public}d", ret);
3849762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3859762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
3869762338dSopenharmony_ci    ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
3879762338dSopenharmony_ci    ASSERT_EQ(0, ret);
3889762338dSopenharmony_ci}
3899762338dSopenharmony_ci
3909762338dSopenharmony_ci/**
3919762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Func_0100
3929762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
3939762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
3949762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
3959762338dSopenharmony_ci * @tc.type: FUNC
3969762338dSopenharmony_ci */
3979762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Func_0100, Function | MediumTest | Level1)
3989762338dSopenharmony_ci{
3999762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
4009762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0100 %{public}d ret=%{public}d", __LINE__, ret);
4019762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4029762338dSopenharmony_ci    ASSERT_EQ(0, ret);
4039762338dSopenharmony_ci}
4049762338dSopenharmony_ci
4059762338dSopenharmony_ci/**
4069762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0100
4079762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4089762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4099762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, portId error
4109762338dSopenharmony_ci * @tc.type: FUNC
4119762338dSopenharmony_ci */
4129762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0100, Function | MediumTest | Level1)
4139762338dSopenharmony_ci{
4149762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
4159762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0100 %{public}d ret=%{public}d", __LINE__, ret);
4169762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4179762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4189762338dSopenharmony_ci}
4199762338dSopenharmony_ci
4209762338dSopenharmony_ci/**
4219762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0200
4229762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4239762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4249762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole error
4259762338dSopenharmony_ci * @tc.type: FUNC
4269762338dSopenharmony_ci */
4279762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0200, Function | MediumTest | Level1)
4289762338dSopenharmony_ci{
4299762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
4309762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0200 %{public}d ret=%{public}d", __LINE__, ret);
4319762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4329762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4339762338dSopenharmony_ci}
4349762338dSopenharmony_ci
4359762338dSopenharmony_ci/**
4369762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0300
4379762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4389762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4399762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, dataRole error
4409762338dSopenharmony_ci * @tc.type: FUNC
4419762338dSopenharmony_ci */
4429762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0300, Function | MediumTest | Level1)
4439762338dSopenharmony_ci{
4449762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
4459762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0300 %{public}d ret=%{public}d", __LINE__, ret);
4469762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4479762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4489762338dSopenharmony_ci}
4499762338dSopenharmony_ci
4509762338dSopenharmony_ci/**
4519762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0400
4529762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4539762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4549762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole error
4559762338dSopenharmony_ci * @tc.type: FUNC
4569762338dSopenharmony_ci */
4579762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0400, Function | MediumTest | Level1)
4589762338dSopenharmony_ci{
4599762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
4609762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0400 %{public}d ret=%{public}d", __LINE__, ret);
4619762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4629762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4639762338dSopenharmony_ci}
4649762338dSopenharmony_ci
4659762338dSopenharmony_ci/**
4669762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0500
4679762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4689762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4699762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, portId && dataRole error
4709762338dSopenharmony_ci * @tc.type: FUNC
4719762338dSopenharmony_ci */
4729762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0500, Function | MediumTest | Level1)
4739762338dSopenharmony_ci{
4749762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
4759762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0500 %{public}d ret=%{public}d", __LINE__, ret);
4769762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4779762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4789762338dSopenharmony_ci}
4799762338dSopenharmony_ci
4809762338dSopenharmony_ci/**
4819762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0600
4829762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4839762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4849762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
4859762338dSopenharmony_ci * @tc.type: FUNC
4869762338dSopenharmony_ci */
4879762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0600, Function | MediumTest | Level1)
4889762338dSopenharmony_ci{
4899762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
4909762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0600 %{public}d ret=%{public}d", __LINE__, ret);
4919762338dSopenharmony_ci    ret = SwitchErrCode(ret);
4929762338dSopenharmony_ci    ASSERT_NE(ret, 0);
4939762338dSopenharmony_ci}
4949762338dSopenharmony_ci
4959762338dSopenharmony_ci/**
4969762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0700
4979762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
4989762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
4999762338dSopenharmony_ci * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
5009762338dSopenharmony_ci * @tc.type: FUNC
5019762338dSopenharmony_ci */
5029762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0700, Function | MediumTest | Level1)
5039762338dSopenharmony_ci{
5049762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
5059762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0700 %{public}d ret=%{public}d", __LINE__, ret);
5069762338dSopenharmony_ci    ret = SwitchErrCode(ret);
5079762338dSopenharmony_ci    ASSERT_NE(ret, 0);
5089762338dSopenharmony_ci}
5099762338dSopenharmony_ci
5109762338dSopenharmony_ci/**
5119762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Compatibility_0800
5129762338dSopenharmony_ci * @tc.desc: Test functions to SetPortRole
5139762338dSopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
5149762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
5159762338dSopenharmony_ci * @tc.type: FUNC
5169762338dSopenharmony_ci */
5179762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Compatibility_0800, Function | MediumTest | Level1)
5189762338dSopenharmony_ci{
5199762338dSopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
5209762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Compatibility_0800 %{public}d ret=%{public}d", __LINE__, ret);
5219762338dSopenharmony_ci    ret = SwitchErrCode(ret);
5229762338dSopenharmony_ci    ASSERT_EQ(0, ret);
5239762338dSopenharmony_ci}
5249762338dSopenharmony_ci
5259762338dSopenharmony_ci/**
5269762338dSopenharmony_ci * @tc.name: SUB_USB_PortManager_HDI_Func_0200
5279762338dSopenharmony_ci * @tc.desc: Test functions to QueryPort
5289762338dSopenharmony_ci * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
5299762338dSopenharmony_ci * @tc.desc: Positive test: parameters correctly
5309762338dSopenharmony_ci * @tc.type: FUNC
5319762338dSopenharmony_ci */
5329762338dSopenharmony_ciHWTEST_F(UsbdFunctionTest, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | Level1)
5339762338dSopenharmony_ci{
5349762338dSopenharmony_ci    int32_t portId = DEFAULT_PORT_ID;
5359762338dSopenharmony_ci    int32_t powerRole = POWER_ROLE_NONE;
5369762338dSopenharmony_ci    int32_t dataRole = DATA_ROLE_NONE;
5379762338dSopenharmony_ci    int32_t mode = PORT_MODE_NONE;
5389762338dSopenharmony_ci    auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
5399762338dSopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SUB_USB_PortManager_HDI_Func_0200 %{public}d ret=%{public}d", __LINE__, ret);
5409762338dSopenharmony_ci    ASSERT_EQ(0, ret);
5419762338dSopenharmony_ci}
5429762338dSopenharmony_ci} // namespace
543