1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#include "usbd_function_test.h"
17094332d3Sopenharmony_ci
18094332d3Sopenharmony_ci#include <iostream>
19094332d3Sopenharmony_ci
20094332d3Sopenharmony_ci#include "hdf_log.h"
21094332d3Sopenharmony_ci#include "if_system_ability_manager.h"
22094332d3Sopenharmony_ci#include "system_ability_definition.h"
23094332d3Sopenharmony_ci#include "usbd_function.h"
24094332d3Sopenharmony_ci#include "usbd_port.h"
25094332d3Sopenharmony_ci#include "v1_0/iusb_interface.h"
26094332d3Sopenharmony_ci#include "v1_0/usb_types.h"
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_ciconstexpr int32_t SLEEP_TIME = 3;
29094332d3Sopenharmony_ciconstexpr int32_t USB_FUNCTION_INVALID = -1;
30094332d3Sopenharmony_ciconstexpr int32_t USB_PORT_ID_INVALID = 2;
31094332d3Sopenharmony_ciconstexpr int32_t USB_POWER_ROLE_INVALID = 4;
32094332d3Sopenharmony_ciconstexpr int32_t USB_DATA_ROLE_INVALID = 5;
33094332d3Sopenharmony_ciconstexpr int32_t USB_FUNCTION_UNSUPPORTED = 128;
34094332d3Sopenharmony_ci
35094332d3Sopenharmony_ciusing namespace testing::ext;
36094332d3Sopenharmony_ciusing namespace OHOS;
37094332d3Sopenharmony_ciusing namespace std;
38094332d3Sopenharmony_ciusing namespace OHOS::HDI::Usb::V1_0;
39094332d3Sopenharmony_ci
40094332d3Sopenharmony_cinamespace {
41094332d3Sopenharmony_cisptr<IUsbInterface> g_usbInterface = nullptr;
42094332d3Sopenharmony_ci
43094332d3Sopenharmony_ciint32_t SwitchErrCode(int32_t ret)
44094332d3Sopenharmony_ci{
45094332d3Sopenharmony_ci    return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
46094332d3Sopenharmony_ci}
47094332d3Sopenharmony_ci
48094332d3Sopenharmony_civoid UsbdFunctionTest::SetUpTestCase(void)
49094332d3Sopenharmony_ci{
50094332d3Sopenharmony_ci    g_usbInterface = IUsbInterface::Get();
51094332d3Sopenharmony_ci    if (g_usbInterface == nullptr) {
52094332d3Sopenharmony_ci        HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
53094332d3Sopenharmony_ci        exit(0);
54094332d3Sopenharmony_ci    }
55094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
56094332d3Sopenharmony_ci    sleep(SLEEP_TIME);
57094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
58094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
59094332d3Sopenharmony_ci    ASSERT_EQ(0, ret);
60094332d3Sopenharmony_ci    if (ret != 0) {
61094332d3Sopenharmony_ci        exit(0);
62094332d3Sopenharmony_ci    }
63094332d3Sopenharmony_ci}
64094332d3Sopenharmony_ci
65094332d3Sopenharmony_civoid UsbdFunctionTest::TearDownTestCase(void) {}
66094332d3Sopenharmony_ci
67094332d3Sopenharmony_civoid UsbdFunctionTest::SetUp(void) {}
68094332d3Sopenharmony_ci
69094332d3Sopenharmony_civoid UsbdFunctionTest::TearDown(void) {}
70094332d3Sopenharmony_ci
71094332d3Sopenharmony_ci/**
72094332d3Sopenharmony_ci * @tc.name: UsbdGetCurrentFunctions001
73094332d3Sopenharmony_ci * @tc.desc: Test functions to GetCurrentFunctions
74094332d3Sopenharmony_ci * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
75094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
76094332d3Sopenharmony_ci * @tc.type: FUNC
77094332d3Sopenharmony_ci */
78094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, TestSize.Level1)
79094332d3Sopenharmony_ci{
80094332d3Sopenharmony_ci    int32_t func = USB_FUNCTION_NONE;
81094332d3Sopenharmony_ci    auto ret = g_usbInterface->GetCurrentFunctions(func);
82094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
83094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
84094332d3Sopenharmony_ci}
85094332d3Sopenharmony_ci
86094332d3Sopenharmony_ci/**
87094332d3Sopenharmony_ci * @tc.name: UsbdGetCurrentFunctions002
88094332d3Sopenharmony_ci * @tc.desc: Test functions to GetCurrentFunctions
89094332d3Sopenharmony_ci * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
90094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
91094332d3Sopenharmony_ci * @tc.type: FUNC
92094332d3Sopenharmony_ci */
93094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, TestSize.Level1)
94094332d3Sopenharmony_ci{
95094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
96094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
97094332d3Sopenharmony_ci    ASSERT_EQ(0, ret);
98094332d3Sopenharmony_ci    int32_t func = USB_FUNCTION_NONE;
99094332d3Sopenharmony_ci    ret = g_usbInterface->GetCurrentFunctions(func);
100094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
101094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
102094332d3Sopenharmony_ci}
103094332d3Sopenharmony_ci
104094332d3Sopenharmony_ci/**********************************************************************************************************/
105094332d3Sopenharmony_ci
106094332d3Sopenharmony_ci/**
107094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions001
108094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
109094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
110094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
111094332d3Sopenharmony_ci * @tc.type: FUNC
112094332d3Sopenharmony_ci */
113094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, TestSize.Level1)
114094332d3Sopenharmony_ci{
115094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ACM);
116094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
117094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
118094332d3Sopenharmony_ci}
119094332d3Sopenharmony_ci
120094332d3Sopenharmony_ci/**
121094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions002
122094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
123094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
124094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, funcs error
125094332d3Sopenharmony_ci * @tc.type: FUNC
126094332d3Sopenharmony_ci */
127094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, TestSize.Level1)
128094332d3Sopenharmony_ci{
129094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_INVALID);
130094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d", __LINE__, ret);
131094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
132094332d3Sopenharmony_ci}
133094332d3Sopenharmony_ci/**
134094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions003
135094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
136094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
137094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
138094332d3Sopenharmony_ci * @tc.type: FUNC
139094332d3Sopenharmony_ci */
140094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, TestSize.Level1)
141094332d3Sopenharmony_ci{
142094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_ECM);
143094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
144094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
145094332d3Sopenharmony_ci}
146094332d3Sopenharmony_ci
147094332d3Sopenharmony_ci/**
148094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions004
149094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
150094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
151094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
152094332d3Sopenharmony_ci * @tc.type: FUNC
153094332d3Sopenharmony_ci */
154094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, TestSize.Level1)
155094332d3Sopenharmony_ci{
156094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
157094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
158094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
159094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
160094332d3Sopenharmony_ci}
161094332d3Sopenharmony_ci
162094332d3Sopenharmony_ci/**
163094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions005
164094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
165094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
166094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
167094332d3Sopenharmony_ci * @tc.type: FUNC
168094332d3Sopenharmony_ci */
169094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, TestSize.Level1)
170094332d3Sopenharmony_ci{
171094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
172094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
173094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
174094332d3Sopenharmony_ci}
175094332d3Sopenharmony_ci
176094332d3Sopenharmony_ci/**
177094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions006
178094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
179094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
180094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
181094332d3Sopenharmony_ci * @tc.type: FUNC
182094332d3Sopenharmony_ci */
183094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, TestSize.Level1)
184094332d3Sopenharmony_ci{
185094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
186094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
187094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
188094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
189094332d3Sopenharmony_ci}
190094332d3Sopenharmony_ci
191094332d3Sopenharmony_ci/**
192094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions007
193094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
194094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
195094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
196094332d3Sopenharmony_ci * @tc.type: FUNC
197094332d3Sopenharmony_ci */
198094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, TestSize.Level1)
199094332d3Sopenharmony_ci{
200094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
201094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
202094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
203094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
204094332d3Sopenharmony_ci}
205094332d3Sopenharmony_ci
206094332d3Sopenharmony_ci/**
207094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions008
208094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
209094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
210094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
211094332d3Sopenharmony_ci * @tc.type: FUNC
212094332d3Sopenharmony_ci */
213094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions008, TestSize.Level1)
214094332d3Sopenharmony_ci{
215094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_RNDIS);
216094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions008 %{public}d ret=%{public}d", __LINE__, ret);
217094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
218094332d3Sopenharmony_ci}
219094332d3Sopenharmony_ci
220094332d3Sopenharmony_ci/**
221094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions009
222094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
223094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
224094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
225094332d3Sopenharmony_ci * @tc.type: FUNC
226094332d3Sopenharmony_ci */
227094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions009, TestSize.Level1)
228094332d3Sopenharmony_ci{
229094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_STORAGE);
230094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions009 %{public}d ret=%{public}d", __LINE__, ret);
231094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
232094332d3Sopenharmony_ci}
233094332d3Sopenharmony_ci
234094332d3Sopenharmony_ci/**
235094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions010
236094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
237094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
238094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
239094332d3Sopenharmony_ci * @tc.type: FUNC
240094332d3Sopenharmony_ci */
241094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions010, TestSize.Level1)
242094332d3Sopenharmony_ci{
243094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_RNDIS | USB_FUNCTION_HDC;
244094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
245094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions010 %{public}d ret=%{public}d", __LINE__, ret);
246094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
247094332d3Sopenharmony_ci}
248094332d3Sopenharmony_ci
249094332d3Sopenharmony_ci/**
250094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions011
251094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
252094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
253094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
254094332d3Sopenharmony_ci * @tc.type: FUNC
255094332d3Sopenharmony_ci */
256094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions011, TestSize.Level1)
257094332d3Sopenharmony_ci{
258094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_STORAGE | USB_FUNCTION_HDC;
259094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
260094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions011 %{public}d ret=%{public}d", __LINE__, ret);
261094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
262094332d3Sopenharmony_ci}
263094332d3Sopenharmony_ci
264094332d3Sopenharmony_ci/**
265094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions012
266094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
267094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
268094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
269094332d3Sopenharmony_ci * @tc.type: FUNC
270094332d3Sopenharmony_ci */
271094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions012, TestSize.Level1)
272094332d3Sopenharmony_ci{
273094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP;
274094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
275094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions012 %{public}d ret=%{public}d", __LINE__, ret);
276094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
277094332d3Sopenharmony_ci}
278094332d3Sopenharmony_ci
279094332d3Sopenharmony_ci/**
280094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions013
281094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
282094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
283094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
284094332d3Sopenharmony_ci * @tc.type: FUNC
285094332d3Sopenharmony_ci */
286094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions013, TestSize.Level1)
287094332d3Sopenharmony_ci{
288094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP;
289094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
290094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 %{public}d ret=%{public}d", __LINE__, ret);
291094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
292094332d3Sopenharmony_ci}
293094332d3Sopenharmony_ci
294094332d3Sopenharmony_ci/**
295094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions014
296094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
297094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
298094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
299094332d3Sopenharmony_ci * @tc.type: FUNC
300094332d3Sopenharmony_ci */
301094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions014, TestSize.Level1)
302094332d3Sopenharmony_ci{
303094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_HDC;
304094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
305094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions014 %{public}d ret=%{public}d", __LINE__, ret);
306094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
307094332d3Sopenharmony_ci}
308094332d3Sopenharmony_ci
309094332d3Sopenharmony_ci/**
310094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions015
311094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
312094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
313094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
314094332d3Sopenharmony_ci * @tc.type: FUNC
315094332d3Sopenharmony_ci */
316094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions015, TestSize.Level1)
317094332d3Sopenharmony_ci{
318094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_HDC;
319094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
320094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions015 %{public}d ret=%{public}d", __LINE__, ret);
321094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
322094332d3Sopenharmony_ci}
323094332d3Sopenharmony_ci
324094332d3Sopenharmony_ci/**
325094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions016
326094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
327094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
328094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
329094332d3Sopenharmony_ci * @tc.type: FUNC
330094332d3Sopenharmony_ci */
331094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions016, TestSize.Level1)
332094332d3Sopenharmony_ci{
333094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_MTP | USB_FUNCTION_RNDIS;
334094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
335094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions016 %{public}d ret=%{public}d", __LINE__, ret);
336094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
337094332d3Sopenharmony_ci}
338094332d3Sopenharmony_ci
339094332d3Sopenharmony_ci/**
340094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions017
341094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
342094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
343094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
344094332d3Sopenharmony_ci * @tc.type: FUNC
345094332d3Sopenharmony_ci */
346094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions017, TestSize.Level1)
347094332d3Sopenharmony_ci{
348094332d3Sopenharmony_ci    int32_t funcs = USB_FUNCTION_PTP | USB_FUNCTION_RNDIS;
349094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(funcs);
350094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions017 %{public}d ret=%{public}d", __LINE__, ret);
351094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
352094332d3Sopenharmony_ci}
353094332d3Sopenharmony_ci
354094332d3Sopenharmony_ci/**
355094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions018
356094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
357094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
358094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, funcs error
359094332d3Sopenharmony_ci * @tc.type: FUNC
360094332d3Sopenharmony_ci */
361094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions018, TestSize.Level1)
362094332d3Sopenharmony_ci{
363094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_UNSUPPORTED);
364094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions018 %{public}d ret=%{public}d", __LINE__, ret);
365094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
366094332d3Sopenharmony_ci}
367094332d3Sopenharmony_ci
368094332d3Sopenharmony_ci/**
369094332d3Sopenharmony_ci * @tc.name: UsbdSetCurrentFunctions019
370094332d3Sopenharmony_ci * @tc.desc: Test functions to SetCurrentFunctions
371094332d3Sopenharmony_ci * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
372094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
373094332d3Sopenharmony_ci * @tc.type: FUNC
374094332d3Sopenharmony_ci */
375094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions019, TestSize.Level1)
376094332d3Sopenharmony_ci{
377094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_NONE);
378094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions013 ret=%{public}d", ret);
379094332d3Sopenharmony_ci    ASSERT_EQ(0, ret);
380094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::the function was set to none successfully");
381094332d3Sopenharmony_ci    ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_HDC);
382094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
383094332d3Sopenharmony_ci}
384094332d3Sopenharmony_ci
385094332d3Sopenharmony_ci/**
386094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole001
387094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
388094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
389094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
390094332d3Sopenharmony_ci * @tc.type: FUNC
391094332d3Sopenharmony_ci */
392094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, TestSize.Level1)
393094332d3Sopenharmony_ci{
394094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
395094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
396094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
397094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
398094332d3Sopenharmony_ci}
399094332d3Sopenharmony_ci
400094332d3Sopenharmony_ci/**
401094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole002
402094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
403094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
404094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, portId error
405094332d3Sopenharmony_ci * @tc.type: FUNC
406094332d3Sopenharmony_ci */
407094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, TestSize.Level1)
408094332d3Sopenharmony_ci{
409094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
410094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
411094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
412094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
413094332d3Sopenharmony_ci}
414094332d3Sopenharmony_ci
415094332d3Sopenharmony_ci/**
416094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole003
417094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
418094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
419094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole error
420094332d3Sopenharmony_ci * @tc.type: FUNC
421094332d3Sopenharmony_ci */
422094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole003, TestSize.Level1)
423094332d3Sopenharmony_ci{
424094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_DEVICE);
425094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole003 %{public}d ret=%{public}d", __LINE__, ret);
426094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
427094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
428094332d3Sopenharmony_ci}
429094332d3Sopenharmony_ci
430094332d3Sopenharmony_ci/**
431094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole004
432094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
433094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
434094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, dataRole error
435094332d3Sopenharmony_ci * @tc.type: FUNC
436094332d3Sopenharmony_ci */
437094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole004, TestSize.Level1)
438094332d3Sopenharmony_ci{
439094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
440094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole004 %{public}d ret=%{public}d", __LINE__, ret);
441094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
442094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
443094332d3Sopenharmony_ci}
444094332d3Sopenharmony_ci
445094332d3Sopenharmony_ci/**
446094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole005
447094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
448094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
449094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole error
450094332d3Sopenharmony_ci * @tc.type: FUNC
451094332d3Sopenharmony_ci */
452094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole005, TestSize.Level1)
453094332d3Sopenharmony_ci{
454094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, DATA_ROLE_HOST);
455094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole005 %{public}d ret=%{public}d", __LINE__, ret);
456094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
457094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
458094332d3Sopenharmony_ci}
459094332d3Sopenharmony_ci
460094332d3Sopenharmony_ci/**
461094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole006
462094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
463094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
464094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, portId && dataRole error
465094332d3Sopenharmony_ci * @tc.type: FUNC
466094332d3Sopenharmony_ci */
467094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole006, TestSize.Level1)
468094332d3Sopenharmony_ci{
469094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, POWER_ROLE_SOURCE, USB_DATA_ROLE_INVALID);
470094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole006 %{public}d ret=%{public}d", __LINE__, ret);
471094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
472094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
473094332d3Sopenharmony_ci}
474094332d3Sopenharmony_ci
475094332d3Sopenharmony_ci/**
476094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole007
477094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
478094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
479094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, powerRole && dataRole error
480094332d3Sopenharmony_ci * @tc.type: FUNC
481094332d3Sopenharmony_ci */
482094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole007, TestSize.Level1)
483094332d3Sopenharmony_ci{
484094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
485094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole007 %{public}d ret=%{public}d", __LINE__, ret);
486094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
487094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
488094332d3Sopenharmony_ci}
489094332d3Sopenharmony_ci
490094332d3Sopenharmony_ci/**
491094332d3Sopenharmony_ci * @tc.name: UsbdSetPortRole008
492094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
493094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
494094332d3Sopenharmony_ci * @tc.desc: Negative test: parameters exception, portId && powerRole && dataRole error
495094332d3Sopenharmony_ci * @tc.type: FUNC
496094332d3Sopenharmony_ci */
497094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, UsbdSetPortRole008, TestSize.Level1)
498094332d3Sopenharmony_ci{
499094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(USB_PORT_ID_INVALID, USB_POWER_ROLE_INVALID, USB_DATA_ROLE_INVALID);
500094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole008 %{public}d ret=%{public}d", __LINE__, ret);
501094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
502094332d3Sopenharmony_ci    EXPECT_NE(ret, 0);
503094332d3Sopenharmony_ci}
504094332d3Sopenharmony_ci
505094332d3Sopenharmony_ci/**
506094332d3Sopenharmony_ci * @tc.name: SetPortRole009
507094332d3Sopenharmony_ci * @tc.desc: Test functions to SetPortRole
508094332d3Sopenharmony_ci * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
509094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
510094332d3Sopenharmony_ci * @tc.type: FUNC
511094332d3Sopenharmony_ci */
512094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, SetPortRole09, TestSize.Level1)
513094332d3Sopenharmony_ci{
514094332d3Sopenharmony_ci    auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
515094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
516094332d3Sopenharmony_ci    ret = SwitchErrCode(ret);
517094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
518094332d3Sopenharmony_ci}
519094332d3Sopenharmony_ci
520094332d3Sopenharmony_ci/**
521094332d3Sopenharmony_ci * @tc.name: QueryPort001
522094332d3Sopenharmony_ci * @tc.desc: Test functions to QueryPort
523094332d3Sopenharmony_ci * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
524094332d3Sopenharmony_ci * @tc.desc: Positive test: parameters correctly
525094332d3Sopenharmony_ci * @tc.type: FUNC
526094332d3Sopenharmony_ci */
527094332d3Sopenharmony_ciHWTEST_F(UsbdFunctionTest, QueryPort001, TestSize.Level1)
528094332d3Sopenharmony_ci{
529094332d3Sopenharmony_ci    int32_t portId = DEFAULT_PORT_ID;
530094332d3Sopenharmony_ci    int32_t powerRole = POWER_ROLE_NONE;
531094332d3Sopenharmony_ci    int32_t dataRole = DATA_ROLE_NONE;
532094332d3Sopenharmony_ci    int32_t mode = PORT_MODE_NONE;
533094332d3Sopenharmony_ci    auto ret = g_usbInterface->QueryPort(portId, powerRole, dataRole, mode);
534094332d3Sopenharmony_ci    HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
535094332d3Sopenharmony_ci    EXPECT_EQ(0, ret);
536094332d3Sopenharmony_ci}
537094332d3Sopenharmony_ci} // namespace
538