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
16 #include "usbd_device_status_test.h"
17
18 #include <iostream>
19 #include <vector>
20
21 #include "UsbSubscriberTest.h"
22 #include "hdf_log.h"
23 #include "usbd_type.h"
24 #include "v1_1/iusb_interface.h"
25
26 const int SLEEP_TIME = 3;
27 const uint8_t BUS_NUM_INVALID = 255;
28 const uint8_t DEV_ADDR_INVALID = 255;
29 const uint8_t INTERFACEID_OK = 1;
30 const uint8_t INTERFACEID_OK_NEW = 0;
31 const uint8_t INTERFACEID_INVALID = 255;
32 const uint8_t POINTID_DIR_IN = USB_ENDPOINT_DIR_IN | 2;
33
34 using namespace testing::ext;
35 using namespace OHOS;
36 using namespace OHOS::USB;
37 using namespace std;
38 using namespace OHOS::HDI::Usb::V1_1;
39 namespace OHOS {
40 namespace USB {
41 UsbDev UsbdDeviceStatusTest::dev_ = {0, 0};
42 sptr<UsbSubscriberTest> UsbdDeviceStatusTest::subscriber_ = nullptr;
43 sptr<OHOS::HDI::Usb::V1_1::IUsbInterface> g_usbInterface = nullptr;
44
SwitchErrCode(int32_t ret)45 int32_t SwitchErrCode(int32_t ret)
46 {
47 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
48 }
49
SetUpTestCase(void)50 void UsbdDeviceStatusTest::SetUpTestCase(void)
51 {
52 g_usbInterface = OHOS::HDI::Usb::V1_1::IUsbInterface::Get();
53 if (g_usbInterface == nullptr) {
54 HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
55 exit(0);
56 }
57 auto ret = g_usbInterface->SetPortRole(1, 1, 1);
58 sleep(SLEEP_TIME);
59 HDF_LOGI("UsbdDeviceStatusTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
60 ret = SwitchErrCode(ret);
61 ASSERT_EQ(0, ret);
62 if (ret != 0) {
63 exit(0);
64 }
65
66 subscriber_ = new UsbSubscriberTest();
67 if (g_usbInterface->BindUsbdSubscriber(subscriber_) != HDF_SUCCESS) {
68 HDF_LOGE("%{public}s: bind usbd subscriber_ failed", __func__);
69 exit(0);
70 }
71
72 std::cout << "please connect device, press enter to continue" << std::endl;
73 int c;
74 while ((c = getchar()) != '\n' && c != EOF) {}
75 dev_ = {subscriber_->busNum_, subscriber_->devAddr_};
76
77 ret = g_usbInterface->OpenDevice(dev_);
78 HDF_LOGI("UsbdDeviceStatusTest::%{public}d OpenDevice=%{public}d", __LINE__, ret);
79 ASSERT_EQ(0, ret);
80 }
81
TearDownTestCase(void)82 void UsbdDeviceStatusTest::TearDownTestCase(void)
83 {
84 g_usbInterface->UnbindUsbdSubscriber(subscriber_);
85 dev_ = {subscriber_->busNum_, subscriber_->devAddr_};
86 auto ret = g_usbInterface->CloseDevice(dev_);
87 HDF_LOGI("UsbdDeviceStatusTest::%{public}d Close=%{public}d", __LINE__, ret);
88 ASSERT_EQ(0, ret);
89 }
90
SetUp(void)91 void UsbdDeviceStatusTest::SetUp(void) {}
92
TearDown(void)93 void UsbdDeviceStatusTest::TearDown(void) {}
94
95 /**
96 * @tc.name: UsbdGetDeviceSpeed001
97 * @tc.desc: Test functions to GetDeviceSpeed
98 * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
99 * @tc.desc: Positive test: parameters correctly
100 * @tc.type: FUNC
101 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed001, TestSize.Level1)102 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed001, TestSize.Level1)
103 {
104 struct UsbDev dev = dev_;
105 int32_t ret = -1;
106 uint8_t speed = 0;
107 ret = g_usbInterface->GetDeviceSpeed(dev, speed);
108 HDF_LOGI("UsbdGetDeviceSpeed001 %{public}d GetDeviceSpeed=%{public}d, speed=%{public}d", __LINE__, ret, speed);
109 EXPECT_EQ(0, ret);
110 }
111
112 /**
113 * @tc.name: UsbdGetDeviceSpeed002
114 * @tc.desc: Test functions to GetDeviceSpeed
115 * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
116 * @tc.desc: Negative test: parameters exception, busNum error
117 * @tc.type: FUNC
118 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed002, TestSize.Level1)119 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed002, TestSize.Level1)
120 {
121 struct UsbDev dev = dev_;
122 dev.busNum = BUS_NUM_INVALID;
123 uint8_t speed = 0;
124 auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
125 HDF_LOGI("UsbdGetDeviceSpeed002 %{public}d ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
126 EXPECT_NE(ret, 0);
127 }
128
129
130 /**
131 * @tc.name: UsbdGetDeviceSpeed003
132 * @tc.desc: Test functions to GetDeviceSpeed
133 * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
134 * @tc.desc: Negative test: parameters exception, devAddr error
135 * @tc.type: FUNC
136 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed003, TestSize.Level1)137 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed003, TestSize.Level1)
138 {
139 struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
140 uint8_t speed = 0;
141 auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
142 HDF_LOGI("UsbdGetDeviceSpeed003 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
143 EXPECT_NE(ret, 0);
144 }
145
146 /**
147 * @tc.name: UsbdGetDeviceSpeed004
148 * @tc.desc: Test functions to GetDeviceSpeed
149 * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
150 * @tc.desc: Negative test: parameters exception, busNum && devAddr error
151 * @tc.type: FUNC
152 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed004, TestSize.Level1)153 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed004, TestSize.Level1)
154 {
155 uint8_t speed = 0;
156 struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
157 auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
158 HDF_LOGI("UsbdGetDeviceSpeed004 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
159 EXPECT_NE(ret, 0);
160 }
161
162 /**
163 * @tc.name: UsbdGetInterfaceActiveStatus001
164 * @tc.desc: Test functions to GetInterfaceActiveStatus
165 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
166 * @tc.desc: Positive test: parameters correctly
167 * @tc.type: FUNC
168 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, TestSize.Level1)169 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, TestSize.Level1)
170 {
171 uint8_t interfaceId = INTERFACEID_OK_NEW;
172 struct UsbDev dev = dev_;
173 int32_t ret = -1;
174 bool unactived = 1;
175 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
176 HDF_LOGI("UsbdDeviceStatusTest::UsbdGetInterfaceActiveStatus %{public}d ClaimInterface=%{public}d", __LINE__, ret);
177 ASSERT_EQ(0, ret);
178 for (; interfaceId < INTERFACEID_INVALID; interfaceId++) {
179 ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
180 if (ret == 0) {
181 break;
182 }
183 }
184 HDF_LOGI("UsbdGetInterfaceActiveStatus001 %{public}d GetInterfaceActiveStatus=%{public}d, unactived=%{public}d",
185 __LINE__, ret, unactived);
186 EXPECT_EQ(0, ret);
187 }
188
189 /**
190 * @tc.name: UsbdGetInterfaceActiveStatus002
191 * @tc.desc: Test functions to GetInterfaceActiveStatus
192 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
193 * @tc.desc: Negative test: parameters exception, busNum error
194 * @tc.type: FUNC
195 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus002, TestSize.Level1)196 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus002, TestSize.Level1)
197 {
198 uint8_t interfaceId = INTERFACEID_OK;
199 struct UsbDev dev = dev_;
200 dev.busNum = BUS_NUM_INVALID;
201 bool unactived = 1;
202 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
203 HDF_LOGI("UsbdGetInterfaceActiveStatus002 %{public}d ret=%{public}d, unactived=%{public}d",
204 __LINE__, ret, unactived);
205 EXPECT_NE(ret, 0);
206 }
207
208 /**
209 * @tc.name: UsbdGetInterfaceActiveStatus003
210 * @tc.desc: Test functions to GetInterfaceActiveStatus
211 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
212 * @tc.desc: Negative test: parameters exception, devAddr error
213 * @tc.type: FUNC
214 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus003, TestSize.Level1)215 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus003, TestSize.Level1)
216 {
217 uint8_t interfaceId = INTERFACEID_OK;
218 struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
219 bool unactived = 1;
220 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
221 HDF_LOGI("UsbdGetInterfaceActiveStatus003 %{public}d, ret=%{public}d, unactived=%{public}d",
222 __LINE__, ret, unactived);
223 EXPECT_NE(ret, 0);
224 }
225
226 /**
227 * @tc.name: UsbdGetInterfaceActiveStatus004
228 * @tc.desc: Test functions to GetInterfaceActiveStatus
229 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
230 * @tc.desc: Negative test: parameters exception, interfaceid error
231 * @tc.type: FUNC
232 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus004, TestSize.Level1)233 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus004, TestSize.Level1)
234 {
235 uint8_t interfaceId = INTERFACEID_OK;
236 struct UsbDev dev = dev_;
237 interfaceId = INTERFACEID_INVALID;
238 bool unactived = 1;
239 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
240 HDF_LOGI("UsbdGetInterfaceActiveStatus004 %{public}d, ret=%{public}d, unactived=%{public}d",
241 __LINE__, ret, unactived);
242 EXPECT_NE(ret, 0);
243 }
244
245 /**
246 * @tc.name: UsbdGetInterfaceActiveStatus005
247 * @tc.desc: Test functions to GetInterfaceActiveStatus
248 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
249 * @tc.desc: Negative test: parameters exception, busNum && devAddr error
250 * @tc.type: FUNC
251 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus005, TestSize.Level1)252 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus005, TestSize.Level1)
253 {
254 uint8_t interfaceId = INTERFACEID_OK;
255 bool unactived = 1;
256 struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
257 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
258 HDF_LOGI("UsbdGetInterfaceActiveStatus005 %{public}d, ret=%{public}d, unactived=%{public}d",
259 __LINE__, ret, unactived);
260 EXPECT_NE(ret, 0);
261 }
262
263 /**
264 * @tc.name: UsbdGetInterfaceActiveStatus006
265 * @tc.desc: Test functions to GetInterfaceActiveStatus
266 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
267 * @tc.desc: Negative test: parameters exception, busNum && interfaceid error
268 * @tc.type: FUNC
269 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus006, TestSize.Level1)270 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus006, TestSize.Level1)
271 {
272 uint8_t interfaceId = INTERFACEID_INVALID;
273 bool unactived = 1;
274 struct UsbDev dev = {BUS_NUM_INVALID, dev_.devAddr};
275 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
276 HDF_LOGI("UsbdGetInterfaceActiveStatus006 %{public}d, ret=%{public}d, unactived=%{public}d",
277 __LINE__, ret, unactived);
278 EXPECT_NE(ret, 0);
279 }
280
281 /**
282 * @tc.name: UsbdGetInterfaceActiveStatus007
283 * @tc.desc: Test functions to GetInterfaceActiveStatus
284 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
285 * @tc.desc: Negative test: parameters exception, devAddr && interfaceid error
286 * @tc.type: FUNC
287 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus007, TestSize.Level1)288 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus007, TestSize.Level1)
289 {
290 uint8_t interfaceId = INTERFACEID_INVALID;
291 bool unactived = 1;
292 struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
293 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
294 HDF_LOGI("UsbdGetInterfaceActiveStatus007 %{public}d, ret=%{public}d, unactived=%{public}d",
295 __LINE__, ret, unactived);
296 EXPECT_NE(ret, 0);
297 }
298
299 /**
300 * @tc.name: UsbdGetInterfaceActiveStatus008
301 * @tc.desc: Test functions to GetInterfaceActiveStatus
302 * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
303 * @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceid error
304 * @tc.type: FUNC
305 */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus008, TestSize.Level1)306 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus008, TestSize.Level1)
307 {
308 uint8_t interfaceId = INTERFACEID_INVALID;
309 bool unactived = 1;
310 struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
311 auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
312 HDF_LOGI("UsbdGetInterfaceActiveStatus008 %{public}d, ret=%{public}d, unactived=%{public}d",
313 __LINE__, ret, unactived);
314 EXPECT_NE(ret, 0);
315 }
316
317 /**
318 * @tc.name: UsbdClearHalt001
319 * @tc.desc: Test functions to ClearHalt
320 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
321 * @tc.desc: Positive test: parameters correctly
322 * @tc.type: FUNC
323 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt001, TestSize.Level1)324 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt001, TestSize.Level1)
325 {
326 struct UsbDev dev = dev_;
327 int32_t ret = -1;
328 uint8_t interfaceId = INTERFACEID_OK;
329 uint8_t pointId = POINTID_DIR_IN;
330 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
331 HDF_LOGI("UsbdRequestTest::UsbdClearHalt001 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
332 ASSERT_EQ(0, ret);
333 struct UsbPipe pipe = {interfaceId, pointId};
334 ret = g_usbInterface->ClearHalt(dev, pipe);
335 HDF_LOGI("UsbdClearHalt001 %{public}d ClearHalt=%{public}d", __LINE__, ret);
336 EXPECT_TRUE(ret == 0);
337 }
338
339 /**
340 * @tc.name: UsbdClearHalt002
341 * @tc.desc: Test functions to ClearHalt
342 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
343 * @tc.desc: Negative test: parameters exception, busNum error
344 * @tc.type: FUNC
345 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt002, TestSize.Level1)346 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt002, TestSize.Level1)
347 {
348 struct UsbDev dev = dev_;
349 int32_t ret = -1;
350 uint8_t interfaceId = INTERFACEID_OK;
351 uint8_t pointId = POINTID_DIR_IN;
352 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
353 HDF_LOGI("UsbdRequestTest::UsbdClearHalt002 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
354 ASSERT_EQ(0, ret);
355 struct UsbPipe pipe = {interfaceId, pointId};
356 dev.busNum = BUS_NUM_INVALID;
357 ret = g_usbInterface->ClearHalt(dev, pipe);
358 HDF_LOGI("UsbdClearHalt002 %{public}d ClearHalt=%{public}d", __LINE__, ret);
359 EXPECT_NE(0, ret);
360 }
361
362 /**
363 * @tc.name: UsbdClearHalt003
364 * @tc.desc: Test functions to GetInterfaceActiveStatus
365 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
366 * @tc.desc: Negative test: parameters exception, devAddr error
367 * @tc.type: FUNC
368 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt003, TestSize.Level1)369 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt003, TestSize.Level1)
370 {
371 struct UsbDev dev = dev_;
372 int32_t ret = -1;
373 uint8_t interfaceId = INTERFACEID_OK;
374 uint8_t pointId = POINTID_DIR_IN;
375 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
376 HDF_LOGI("UsbdRequestTest::UsbdClearHalt003 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
377 ASSERT_EQ(0, ret);
378 struct UsbPipe pipe = {interfaceId, pointId};
379 dev.devAddr = DEV_ADDR_INVALID;
380 ret = g_usbInterface->ClearHalt(dev, pipe);
381 HDF_LOGI("UsbdClearHalt003 %{public}d ClearHalt=%{public}d", __LINE__, ret);
382 EXPECT_NE(0, ret);
383 }
384
385 /**
386 * @tc.name: UsbdClearHalt004
387 * @tc.desc: Test functions to ClearHalt
388 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
389 * @tc.desc: Negative test: parameters exception, interfaceid error
390 * @tc.type: FUNC
391 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt004, TestSize.Level1)392 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt004, TestSize.Level1)
393 {
394 struct UsbDev dev = dev_;
395 int32_t ret = -1;
396 uint8_t interfaceId = INTERFACEID_INVALID;
397 uint8_t pointId = POINTID_DIR_IN;
398 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
399 HDF_LOGI("UsbdRequestTest::UsbdClearHalt004 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
400 ASSERT_NE(0, ret);
401 struct UsbPipe pipe = {interfaceId, pointId};
402 ret = g_usbInterface->ClearHalt(dev, pipe);
403 HDF_LOGI("UsbdClearHalt004 %{public}d ClearHalt=%{public}d", __LINE__, ret);
404 EXPECT_NE(0, ret);
405 }
406
407 /**
408 * @tc.name: UsbdClearHalt005
409 * @tc.desc: Test functions to ClearHalt
410 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
411 * @tc.desc: Negative test: parameters exception, busNum && devAddr error
412 * @tc.type: FUNC
413 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt005, TestSize.Level1)414 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt005, TestSize.Level1)
415 {
416 struct UsbDev dev = dev_;
417 int32_t ret = -1;
418 uint8_t interfaceId = INTERFACEID_OK;
419 uint8_t pointId = POINTID_DIR_IN;
420 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
421 HDF_LOGI("UsbdRequestTest::UsbdClearHalt005 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
422 ASSERT_EQ(0, ret);
423 struct UsbPipe pipe = {interfaceId, pointId};
424 dev.busNum = BUS_NUM_INVALID;
425 dev.devAddr = DEV_ADDR_INVALID;
426 ret = g_usbInterface->ClearHalt(dev, pipe);
427 HDF_LOGI("UsbdClearHalt005 %{public}d ClearHalt=%{public}d", __LINE__, ret);
428 EXPECT_NE(0, ret);
429 }
430
431 /**
432 * @tc.name: UsbdClearHalt006
433 * @tc.desc: Test functions to ClearHalt
434 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
435 * @tc.desc: Negative test: parameters exception, busNum && interfaceid error
436 * @tc.type: FUNC
437 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt006, TestSize.Level1)438 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt006, TestSize.Level1)
439 {
440 struct UsbDev dev = dev_;
441 int32_t ret = -1;
442 uint8_t interfaceId = INTERFACEID_INVALID;
443 uint8_t pointId = POINTID_DIR_IN;
444 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
445 HDF_LOGI("UsbdRequestTest::UsbdClearHalt006 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
446 ASSERT_NE(0, ret);
447 struct UsbPipe pipe = {interfaceId, pointId};
448 dev.busNum = BUS_NUM_INVALID;
449 ret = g_usbInterface->ClearHalt(dev, pipe);
450 HDF_LOGI("UsbdClearHalt006 %{public}d ClearHalt=%{public}d", __LINE__, ret);
451 EXPECT_NE(0, ret);
452 }
453
454 /**
455 * @tc.name: UsbdClearHalt007
456 * @tc.desc: Test functions to ClearHalt
457 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
458 * @tc.desc: Negative test: parameters exception, devAddr && interfaceid error
459 * @tc.type: FUNC
460 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt007, TestSize.Level1)461 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt007, TestSize.Level1)
462 {
463 struct UsbDev dev = dev_;
464 int32_t ret = -1;
465 uint8_t interfaceId = INTERFACEID_INVALID;
466 uint8_t pointId = POINTID_DIR_IN;
467 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
468 HDF_LOGI("UsbdRequestTest::UsbdClearHalt007 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
469 ASSERT_NE(0, ret);
470 struct UsbPipe pipe = {interfaceId, pointId};
471 dev.devAddr = DEV_ADDR_INVALID;
472 ret = g_usbInterface->ClearHalt(dev, pipe);
473 HDF_LOGI("UsbdClearHalt005 %{public}d ClearHalt=%{public}d", __LINE__, ret);
474 EXPECT_NE(0, ret);
475 }
476
477 /**
478 * @tc.name: UsbdClearHalt008
479 * @tc.desc: Test functions to ClearHalt
480 * @tc.desc: int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe);
481 * @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceid error
482 * @tc.type: FUNC
483 */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt008, TestSize.Level1)484 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt008, TestSize.Level1)
485 {
486 struct UsbDev dev = dev_;
487 int32_t ret = -1;
488 uint8_t interfaceId = INTERFACEID_INVALID;
489 uint8_t pointId = POINTID_DIR_IN;
490 ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
491 HDF_LOGI("UsbdRequestTest::UsbdClearHalt008 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
492 ASSERT_NE(0, ret);
493 struct UsbPipe pipe = {interfaceId, pointId};
494 dev.busNum = BUS_NUM_INVALID;
495 dev.devAddr = DEV_ADDR_INVALID;
496 ret = g_usbInterface->ClearHalt(dev, pipe);
497 HDF_LOGI("UsbdClearHalt008 %{public}d ClearHalt=%{public}d", __LINE__, ret);
498 EXPECT_NE(0, ret);
499 }
500 } // USB
501 } // OHOS
502