1 /*
2 * Copyright (c) 2021 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 "usbd_function_test.h"
16 #include <iostream>
17 #include "hdf_log.h"
18 #include "if_system_ability_manager.h"
19 #include "system_ability_definition.h"
20 #include "usbd_client.h"
21
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::USB;
25 using namespace std;
26
27 const int SLEEP_TIME = 3;
28 const int TEST_PORT_ID = 1;
29 const int TEST_POWER_ROLE = 2;
30 const int TEST_DATAR_ROLE = 2;
31 const int USB_FUNCTION_ACM = 1;
32 const int USB_FUNCTION_ECM = 2;
33 const int USB_FUNCTION_HDC = 4;
34
SetUpTestCase(void)35 void UsbdFunctionTest::SetUpTestCase(void)
36 {
37 auto ret = UsbdClient::GetInstance().SetPortRole(TEST_PORT_ID, TEST_POWER_ROLE, TEST_DATAR_ROLE);
38 sleep(SLEEP_TIME);
39 HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
40 ASSERT_TRUE(ret == 0);
41 if (ret != 0) {
42 exit(0);
43 }
44 }
45
TearDownTestCase(void)46 void UsbdFunctionTest::TearDownTestCase(void) {}
47
SetUp(void)48 void UsbdFunctionTest::SetUp(void) {}
49
TearDown(void)50 void UsbdFunctionTest::TearDown(void) {}
51
52 /**
53 * @tc.name: UsbdGetCurrentFunctions001
54 * @tc.desc: Test functions to GetCurrentFunctions
55 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
56 * @tc.type: FUNC
57 */
58 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, Function | MediumTest | Level1)
59 {
60 int32_t funcs = 0;
61 auto ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs);
62 HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
63 ASSERT_TRUE(ret == 0);
64 }
65
66 /**
67 * @tc.name: UsbdGetCurrentFunctions002
68 * @tc.desc: Test functions to GetCurrentFunctions
69 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
70 * @tc.type: FUNC
71 */
72 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, Function | MediumTest | Level1)
73 {
74 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(1);
75 HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
76 ASSERT_TRUE(ret == 0);
77 int32_t funcs = 1;
78 ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs);
79 HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
80 ASSERT_TRUE(ret == 0);
81 }
82
83 /**
84 * @tc.name: UsbdSetCurrentFunctions001
85 * @tc.desc: Test functions to SetCurrentFunctions
86 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
87 * @tc.type: FUNC
88 */
89 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, Function | MediumTest | Level1)
90 {
91 int32_t funcs = 1;
92 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
93 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
94 ASSERT_TRUE(ret == 0);
95 }
96
97 /**
98 * @tc.name: UsbdSetCurrentFunctions002
99 * @tc.desc: Test functions to SetCurrentFunctions
100 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
101 * @tc.type: FUNC
102 */
103 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, Function | MediumTest | Level1)
104 {
105 int32_t funcs = -1;
106 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
107 HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d, funcs=%{public}d", __LINE__, ret, funcs);
108 ASSERT_TRUE(ret != 0);
109 }
110 /**
111 * @tc.name: UsbdSetCurrentFunctions003
112 * @tc.desc: Test functions to SetCurrentFunctions
113 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
114 * @tc.type: FUNC
115 */
116 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, Function | MediumTest | Level1)
117 {
118 int32_t funcs = USB_FUNCTION_ECM;
119 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
120 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
121 ASSERT_TRUE(ret == 0);
122 }
123
124 /**
125 * @tc.name: UsbdSetCurrentFunctions004
126 * @tc.desc: Test functions to SetCurrentFunctions
127 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
128 * @tc.type: FUNC
129 */
130 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, Function | MediumTest | Level1)
131 {
132 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
133 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
134 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
135 ASSERT_TRUE(ret == 0);
136 }
137
138 /**
139 * @tc.name: UsbdSetCurrentFunctions005
140 * @tc.desc: Test functions to SetCurrentFunctions
141 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
142 * @tc.type: FUNC
143 */
144 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, Function | MediumTest | Level1)
145 {
146 int32_t funcs = USB_FUNCTION_HDC;
147 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
148 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
149 ASSERT_TRUE(ret == 0);
150 }
151
152 /**
153 * @tc.name: UsbdSetCurrentFunctions006
154 * @tc.desc: Test functions to SetCurrentFunctions
155 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
156 * @tc.type: FUNC
157 */
158 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, Function | MediumTest | Level1)
159 {
160 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
161 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
162 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
163 ASSERT_TRUE(ret == 0);
164 }
165
166 /**
167 * @tc.name: UsbdSetCurrentFunctions007
168 * @tc.desc: Test functions to SetCurrentFunctions
169 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
170 * @tc.type: FUNC
171 */
172 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, Function | MediumTest | Level1)
173 {
174 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
175 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
176 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
177 ASSERT_TRUE(ret == 0);
178 }
179
180 /**
181 * @tc.name: UsbdSetPortRole001
182 * @tc.desc: Test functions to SetPortRole
183 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
184 * @tc.type: FUNC
185 */
186 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, Function | MediumTest | Level1)
187 {
188 auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1);
189 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
190 ASSERT_TRUE(ret == 0);
191 }
192
193 /**
194 * @tc.name: UsbdSetPortRole002
195 * @tc.desc: Test functions to SetPortRole
196 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
197 * @tc.type: FUNC
198 */
199 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, Function | MediumTest | Level1)
200 {
201 auto ret = UsbdClient::GetInstance().SetPortRole(2, 1, 1);
202 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
203 ASSERT_TRUE(ret != 0);
204 }
205
206 /**
207 * @tc.name: SetPortRole009
208 * @tc.desc: Test functions to SetPortRole
209 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
210 * @tc.type: FUNC
211 */
212 HWTEST_F(UsbdFunctionTest, SetPortRole09, Function | MediumTest | Level1)
213 {
214 auto ret = UsbdClient::GetInstance().SetPortRole(1, 2, 2);
215 HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
216 ASSERT_TRUE(ret == 0);
217 }
218
219 /**
220 * @tc.name: QueryPort001
221 * @tc.desc: Test functions to QueryPort
222 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
223 * @tc.type: FUNC
224 */
225 HWTEST_F(UsbdFunctionTest, QueryPort001, Function | MediumTest | Level1)
226 {
227 int32_t portId = 0;
228 int32_t powerRole = 0;
229 int32_t dataRole = 0;
230 int32_t mode = 0;
231 auto ret = UsbdClient::GetInstance().QueryPort(portId, powerRole, dataRole, mode);
232 HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
233 ASSERT_TRUE(ret == 0);
234 }
235