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 #include <iostream>
16 
17 #include "hdf_log.h"
18 #include "if_system_ability_manager.h"
19 #include "system_ability_definition.h"
20 #include "usbd_auto_function_test.h"
21 #include "v1_0/iusb_interface.h"
22 #include "v1_0/usb_types.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace std;
27 using namespace OHOS::HDI::Usb::V1_0;
28 
29 namespace {
30 sptr<IUsbInterface> g_usbInterface = nullptr;
31 
SetUpTestCase(void)32 void UsbdAutoFunctionTest::SetUpTestCase(void)
33 {
34     g_usbInterface = IUsbInterface::Get();
35     if (g_usbInterface == nullptr) {
36         HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
37     }
38 }
39 
TearDownTestCase(void)40 void UsbdAutoFunctionTest::TearDownTestCase(void) {}
41 
SetUp(void)42 void UsbdAutoFunctionTest::SetUp(void) {}
43 
TearDown(void)44 void UsbdAutoFunctionTest::TearDown(void) {}
45 
46 /**
47  * @tc.name: SUB_USB_DeviceManager_HDI_Func_0300
48  * @tc.desc: Test functions to GetCurrentFunctions
49  * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
50  * @tc.desc: Positive test: parameters correctly
51  * @tc.type: FUNC
52  */
HWTEST_F(UsbdAutoFunctionTest, SUB_USB_DeviceManager_HDI_Func_0300, Function | MediumTest | Level1)53 HWTEST_F(UsbdAutoFunctionTest, SUB_USB_DeviceManager_HDI_Func_0300, Function | MediumTest | Level1)
54 {
55     int32_t funcs = USB_FUNCTION_NONE;
56     auto ret = g_usbInterface->GetCurrentFunctions(funcs);
57     HDF_LOGI("UsbdAutoFunctionTest::SUB_USB_DeviceManager_HDI_Func_0300 %{public}d ret=%{public}d", __LINE__, ret);
58     ASSERT_EQ(0, ret);
59 }
60 
61 /**
62  * @tc.name: SUB_USB_PortManager_HDI_Func_0200
63  * @tc.desc: Test functions to QueryPort
64  * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
65  * @tc.desc: Positive test: parameters correctly
66  * @tc.type: FUNC
67  */
HWTEST_F(UsbdAutoFunctionTest, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | Level1)68 HWTEST_F(UsbdAutoFunctionTest, SUB_USB_PortManager_HDI_Func_0200, Function | MediumTest | Level1)
69 {
70     int32_t portId = DEFAULT_PORT_ID;
71     int32_t powerRole = POWER_ROLE_NONE;
72     int32_t dataRole = DATA_ROLE_NONE;
73     int32_t mode = PORT_MODE_NONE;
74     auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
75     HDF_LOGI("UsbdAutoFunctionTest::SUB_USB_PortManager_HDI_Func_0200 %{public}d ret=%{public}d", __LINE__, ret);
76     ASSERT_EQ(0, ret);
77 }
78 } // namespace
79