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 const int SLEEP_TIME = 3;
23
24 const int TEST_PORT_ID = 1;
25 const int TEST_POWER_ROLE = 2;
26 const int TEST_DATAR_ROLE = 2;
27 const int USB_FUNCTION_ACM = 1;
28 const int USB_FUNCTION_ECM = 2;
29 const int USB_FUNCTION_HDC = 4;
30
31 using namespace testing::ext;
32 using namespace OHOS;
33 using namespace OHOS::USB;
34 using namespace std;
35
SetUpTestCase(void)36 void UsbdFunctionTest::SetUpTestCase(void)
37 {
38 auto ret = UsbdClient::GetInstance().SetPortRole(TEST_PORT_ID, TEST_POWER_ROLE, TEST_DATAR_ROLE);
39 sleep(SLEEP_TIME);
40 HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
41 ASSERT_TRUE(ret == 0);
42 if (ret != 0) {
43 exit(0);
44 }
45 }
46
TearDownTestCase(void)47 void UsbdFunctionTest::TearDownTestCase(void) {}
48
SetUp(void)49 void UsbdFunctionTest::SetUp(void) {}
50
TearDown(void)51 void UsbdFunctionTest::TearDown(void) {}
52
53 /**
54 * @tc.name: UsbdGetCurrentFunctions001
55 * @tc.desc: Test functions to GetCurrentFunctions
56 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
57 * @tc.desc: 正向测试:参数正确
58 * @tc.type: FUNC
59 */
60 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, TestSize.Level1)
61 {
62 int32_t funcs = 0;
63 auto ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs);
64 HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret);
65 ASSERT_TRUE(ret == 0);
66 }
67
68 /**
69 * @tc.name: UsbdGetCurrentFunctions002
70 * @tc.desc: Test functions to GetCurrentFunctions
71 * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs);
72 * @tc.desc: 正向测试:参数正确
73 * @tc.type: FUNC
74 */
75 HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, TestSize.Level1)
76 {
77 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(1);
78 HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
79 ASSERT_TRUE(ret == 0);
80 int32_t funcs = 1;
81 ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs);
82 HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret);
83 ASSERT_TRUE(ret == 0);
84 }
85
86 /**********************************************************************************************************/
87
88 /**
89 * @tc.name: UsbdSetCurrentFunctions001
90 * @tc.desc: Test functions to SetCurrentFunctions
91 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
92 * @tc.desc: 正向测试:参数正确
93 * @tc.type: FUNC
94 */
95 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, TestSize.Level1)
96 {
97 int32_t funcs = 1;
98 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
99 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret);
100 ASSERT_TRUE(ret == 0);
101 }
102
103 /**
104 * @tc.name: UsbdSetCurrentFunctions002
105 * @tc.desc: Test functions to SetCurrentFunctions
106 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
107 * @tc.desc: 反向测试:参数异常,funcs错误
108 * @tc.type: FUNC
109 */
110 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, TestSize.Level1)
111 {
112 int32_t funcs = -1;
113 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
114 HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d, funcs=%{public}d", __LINE__, ret, funcs);
115 ASSERT_TRUE(ret != 0);
116 }
117 /**
118 * @tc.name: UsbdSetCurrentFunctions003
119 * @tc.desc: Test functions to SetCurrentFunctions
120 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
121 * @tc.desc: 正向测试:参数正确
122 * @tc.type: FUNC
123 */
124 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, TestSize.Level1)
125 {
126 int32_t funcs = USB_FUNCTION_ECM;
127 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
128 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret);
129 ASSERT_TRUE(ret == 0);
130 }
131
132 /**
133 * @tc.name: UsbdSetCurrentFunctions004
134 * @tc.desc: Test functions to SetCurrentFunctions
135 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
136 * @tc.desc: 正向测试:参数正确
137 * @tc.type: FUNC
138 */
139 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, TestSize.Level1)
140 {
141 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM;
142 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
143 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret);
144 ASSERT_TRUE(ret == 0);
145 }
146
147 /**
148 * @tc.name: UsbdSetCurrentFunctions005
149 * @tc.desc: Test functions to SetCurrentFunctions
150 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
151 * @tc.desc: 正向测试:参数正确
152 * @tc.type: FUNC
153 */
154 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, TestSize.Level1)
155 {
156 int32_t funcs = USB_FUNCTION_HDC;
157 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
158 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret);
159 ASSERT_TRUE(ret == 0);
160 }
161
162 /**
163 * @tc.name: UsbdSetCurrentFunctions006
164 * @tc.desc: Test functions to SetCurrentFunctions
165 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
166 * @tc.desc: 正向测试:参数正确
167 * @tc.type: FUNC
168 */
169 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, TestSize.Level1)
170 {
171 int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC;
172 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
173 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret);
174 ASSERT_TRUE(ret == 0);
175 }
176
177 /**
178 * @tc.name: UsbdSetCurrentFunctions007
179 * @tc.desc: Test functions to SetCurrentFunctions
180 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
181 * @tc.desc: 正向测试:参数正确
182 * @tc.type: FUNC
183 */
184 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, TestSize.Level1)
185 {
186 int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC;
187 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
188 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret);
189 ASSERT_TRUE(ret == 0);
190 }
191
192 /**
193 * @tc.name: UsbdSetCurrentFunctions008
194 * @tc.desc: Test functions to SetCurrentFunctions
195 * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs)
196 * @tc.desc: 反向测试:参数异常,funcs错误
197 * @tc.type: FUNC
198 */
199 HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions008, TestSize.Level1)
200 {
201 int32_t funcs = 8;
202 auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs);
203 HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions008 %{public}d ret=%{public}d", __LINE__, ret);
204 ASSERT_TRUE(ret != 0);
205 }
206
207 /**
208 * @tc.name: UsbdSetPortRole001
209 * @tc.desc: Test functions to SetPortRole
210 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
211 * @tc.desc: 正向测试:参数正确
212 * @tc.type: FUNC
213 */
214 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, TestSize.Level1)
215 {
216 auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1);
217 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret);
218 ASSERT_TRUE(ret == 0);
219 }
220
221 /**
222 * @tc.name: UsbdSetPortRole002
223 * @tc.desc: Test functions to SetPortRole
224 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
225 * @tc.desc: 反向测试:参数异常,portId错误
226 * @tc.type: FUNC
227 */
228 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, TestSize.Level1)
229 {
230 auto ret = UsbdClient::GetInstance().SetPortRole(2, 1, 1);
231 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret);
232 ASSERT_TRUE(ret != 0);
233 }
234
235 /**
236 * @tc.name: UsbdSetPortRole003
237 * @tc.desc: Test functions to SetPortRole
238 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
239 * @tc.desc: 反向测试:参数异常,powerRole错误
240 * @tc.type: FUNC
241 */
242 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole003, TestSize.Level1)
243 {
244 auto ret = UsbdClient::GetInstance().SetPortRole(1, 4, 2);
245 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole003 %{public}d ret=%{public}d", __LINE__, ret);
246 ASSERT_TRUE(ret != 0);
247 }
248
249 /**
250 * @tc.name: UsbdSetPortRole004
251 * @tc.desc: Test functions to SetPortRole
252 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
253 * @tc.desc: 反向测试:参数异常,dataRole错误
254 * @tc.type: FUNC
255 */
256 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole004, TestSize.Level1)
257 {
258 auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 5);
259 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole004 %{public}d ret=%{public}d", __LINE__, ret);
260 ASSERT_TRUE(ret != 0);
261 }
262
263 /**
264 * @tc.name: UsbdSetPortRole005
265 * @tc.desc: Test functions to SetPortRole
266 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
267 * @tc.desc: 反向测试:参数异常,portId、powerRole错误
268 * @tc.type: FUNC
269 */
270 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole005, TestSize.Level1)
271 {
272 auto ret = UsbdClient::GetInstance().SetPortRole(1, 5, 5);
273 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole005 %{public}d ret=%{public}d", __LINE__, ret);
274 ASSERT_TRUE(ret != 0);
275 }
276
277 /**
278 * @tc.name: UsbdSetPortRole006
279 * @tc.desc: Test functions to SetPortRole
280 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
281 * @tc.desc: 反向测试:参数异常,portId、dataRole错误
282 * @tc.type: FUNC
283 */
284 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole006, TestSize.Level1)
285 {
286 auto ret = UsbdClient::GetInstance().SetPortRole(5, 1, 5);
287 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole006 %{public}d ret=%{public}d", __LINE__, ret);
288 ASSERT_TRUE(ret != 0);
289 }
290
291 /**
292 * @tc.name: UsbdSetPortRole007
293 * @tc.desc: Test functions to SetPortRole
294 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
295 * @tc.desc: 反向测试:powerRole、dataRole错误
296 * @tc.type: FUNC
297 */
298 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole007, TestSize.Level1)
299 {
300 auto ret = UsbdClient::GetInstance().SetPortRole(1, 5, 5);
301 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole007 %{public}d ret=%{public}d", __LINE__, ret);
302 ASSERT_TRUE(ret != 0);
303 }
304
305 /**
306 * @tc.name: UsbdSetPortRole008
307 * @tc.desc: Test functions to SetPortRole
308 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
309 * @tc.desc: 反向测试:portId、powerRole、dataRole错误
310 * @tc.type: FUNC
311 */
312 HWTEST_F(UsbdFunctionTest, UsbdSetPortRole008, TestSize.Level1)
313 {
314 auto ret = UsbdClient::GetInstance().SetPortRole(2, 5, 5);
315 HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole008 %{public}d ret=%{public}d", __LINE__, ret);
316 ASSERT_TRUE(ret != 0);
317 }
318
319 /**
320 * @tc.name: SetPortRole009
321 * @tc.desc: Test functions to SetPortRole
322 * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)
323 * @tc.desc: 正向测试:参数正确
324 * @tc.type: FUNC
325 */
326 HWTEST_F(UsbdFunctionTest, SetPortRole09, TestSize.Level1)
327 {
328 auto ret = UsbdClient::GetInstance().SetPortRole(1, 2, 2);
329 HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret);
330 ASSERT_TRUE(ret == 0);
331 }
332
333 /**
334 * @tc.name: QueryPort001
335 * @tc.desc: Test functions to QueryPort
336 * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode);
337 * @tc.desc: 正向测试:参数正确
338 * @tc.type: FUNC
339 */
340 HWTEST_F(UsbdFunctionTest, QueryPort001, TestSize.Level1)
341 {
342 int32_t portId = 0;
343 int32_t powerRole = 0;
344 int32_t dataRole = 0;
345 int32_t mode = 0;
346 auto ret = UsbdClient::GetInstance().QueryPort(portId, powerRole, dataRole, mode);
347 HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret);
348 ASSERT_TRUE(ret == 0);
349 }
350