1/* 2 * Copyright (c) 2024 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 16import usbManager from '@ohos.usbManager'; 17import { UiDriver, BY } from '@ohos.UiTest'; 18import CheckEmptyUtils from './CheckEmptyUtils.js'; 19import EventConstants from './EventConstants.js'; 20import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 21 22 23export default function UsbApiTransferCompatJsunitTest() { 24describe('UsbApiTransferCompatJsunitTest', function () { 25 26 const TAG = "[UsbApiTransferCompatJsunitTest]"; 27 const PARAM_NULLSTRING = ""; 28 const PARAM_ERRCODE = 401; 29 let gDeviceList; 30 let devices; 31 let testParam; 32 let gPipe; 33 let tmpPipe = { 34 busNum: null, 35 devAddress: null 36 }; 37 let isDeviceConnected; 38 function deviceConnected() { 39 if (gDeviceList.length > 0) { 40 console.info(TAG, "Test USB device is connected"); 41 return true; 42 } 43 console.info(TAG, "Test USB device is not connected"); 44 return false; 45 } 46 47 beforeAll(async function () { 48 console.log(TAG, '*************Usb Unit UsbApiTransferCompatJsunitTest Begin*************'); 49 const Version = usbManager.getVersion(); 50 console.info(TAG, 'usb unit begin test getversion :' + Version); 51 52 // version > 17 host currentMode = 2 device currentMode = 1 53 gDeviceList = usbManager.getDevices(); 54 isDeviceConnected = deviceConnected(); 55 if (isDeviceConnected) { 56 let hasRight = usbManager.hasRight(gDeviceList[0].name); 57 if (!hasRight) { 58 console.info(TAG, `beforeAll: usb requestRight start`); 59 await getPermission(); 60 CheckEmptyUtils.sleep(1000); 61 await driveFn(); 62 CheckEmptyUtils.sleep(1000); 63 } 64 devices = gDeviceList[0]; 65 tmpPipe.busNum = devices.busNum; 66 tmpPipe.devAddress = devices.devAddress; 67 console.info(TAG, 'beforeAll usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); 68 } 69 }) 70 71 beforeEach(function () { 72 console.info(TAG, 'beforeEach: *************Usb Unit Test CaseEx*************'); 73 gDeviceList = usbManager.getDevices(); 74 if (isDeviceConnected) { 75 devices = gDeviceList[0]; 76 console.info(TAG, 'beforeEach return devices : ' + JSON.stringify(devices)); 77 gPipe = usbManager.connectDevice(devices); 78 console.info(TAG, 'beforeEach return gPipe : ' + JSON.stringify(gPipe)); 79 testParam = getTransferTestParam(); 80 console.info(TAG, 'beforeEach return testParam : ' + JSON.stringify(testParam)); 81 } 82 83 }) 84 85 afterEach(function () { 86 console.info(TAG, 'afterEach: *************Usb Unit Test CaseEx*************'); 87 devices = null; 88 testParam = null; 89 gPipe = null; 90 console.info(TAG, 'afterEach return devices : ' + JSON.stringify(devices)); 91 console.info(TAG, 'afterEach return testParam : ' + JSON.stringify(testParam)); 92 console.info(TAG, 'afterEach return gPipe : ' + JSON.stringify(gPipe)); 93 }) 94 95 afterAll(function () { 96 console.log(TAG, '*************Usb Unit UsbApiTransferCompatJsunitTest End*************'); 97 }) 98 99 async function driveFn() { 100 console.info('**************driveFn**************'); 101 try { 102 let driver = await UiDriver.create(); 103 console.info(TAG, ` come in driveFn`); 104 console.info(TAG, `driver is ${JSON.stringify(driver)}`); 105 CheckEmptyUtils.sleep(1000); 106 let button = await driver.findComponent(BY.text('允许')); 107 console.info(TAG, `button is ${JSON.stringify(button)}`); 108 CheckEmptyUtils.sleep(1000); 109 await button.click(); 110 } catch (err) { 111 console.info(TAG, 'err is ' + err); 112 return; 113 } 114 } 115 116 async function getPermission() { 117 console.info('**************getPermission**************'); 118 try { 119 usbManager.requestRight(gDeviceList[0].name).then(hasRight => { 120 console.info(TAG, `usb requestRight success, hasRight: ${hasRight}`); 121 }) 122 } catch (err) { 123 console.info(TAG, `usb getPermission to requestRight hasRight fail: `, err); 124 return 125 } 126 } 127 128 function findInitPoint(testParam, j) { 129 var bfind = false; 130 for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { 131 var endpoint = testParam.config.interfaces[j].endpoints[k]; 132 if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { 133 bfind = true 134 if (endpoint.direction == usbManager.USB_REQUEST_DIR_TO_DEVICE) { 135 testParam.maxOutSize = endpoint.maxPacketSize; 136 testParam.outEndpoint = endpoint; 137 } else if (endpoint.direction == usbManager.USB_REQUEST_DIR_FROM_DEVICE) { 138 testParam.maxInSize = endpoint.maxPacketSize; 139 testParam.inEndpoint = endpoint; 140 } 141 } 142 } 143 if (bfind) { 144 testParam.interface = testParam.config.interfaces[j]; 145 return bfind; 146 } 147 return false; 148 } 149 150 function getFlag(testParam, j) { 151 if (testParam.config.interfaces[j].endpoints.length == 0) { 152 return false; 153 } 154 155 if (testParam.config.interfaces[j].clazz != 10 || 156 testParam.config.interfaces[j].subClass != 0 || 157 testParam.config.interfaces[j].protocol != 2) { 158 return false; 159 } 160 return true; 161 } 162 163 function initPoint(testParam) { 164 for (var j = 0; j < testParam.config.interfaces.length; j++) { 165 if (getFlag(testParam, j) == true) { 166 if (findInitPoint(testParam, j) == true) { 167 break 168 } 169 } 170 } 171 } 172 173 // Prefabrication transmission related parameters 174 function getTransferTestParam() { 175 testParam = { 176 config: null, 177 device: null, 178 pip: null, 179 inEndpoint: null, 180 interface: null, 181 outEndpoint: null, 182 usbRequest: null, 183 sendData: '', 184 isClaimed: 0, 185 maxInSize: 1024, 186 maxOutSize: 1024 187 } 188 189 console.info(TAG, 'usb case gDeviceList.length: ' + gDeviceList.length); 190 for (var i = 0; i < gDeviceList.length; i++) { 191 testParam.device = gDeviceList[i]; 192 testParam.config = testParam.device.configs[0]; 193 testParam.pip = gPipe; 194 initPoint(testParam); 195 } 196 return testParam; 197 } 198 199 function getControlTransferParam(iReqType, iReq, iValue, iIndex, iLength) { 200 let tmpUint8Array = new Uint8Array(512); 201 202 let requestparam = { 203 bmRequestType: iReqType, 204 bRequest: iReq, 205 wValue: iValue, 206 wIndex: iIndex, 207 wLength: iLength, 208 data: tmpUint8Array 209 } 210 return requestparam; 211 } 212 213 function toClaimInterface(testCaseName, pip, tInterface) { 214 let ret = usbManager.claimInterface(pip, tInterface, true); 215 console.info(TAG, `usb ${testCaseName} claimInterface ret: ${ret}`); 216 expect(ret).assertEqual(0); 217 } 218 219 function toReleaseInterface(testCaseName) { 220 gDeviceList = usbManager.getDevices(); 221 testParam = getTransferTestParam(); 222 let ret = usbManager.releaseInterface(tmpPipe, testParam.interface); 223 console.info(TAG, `usb ${testCaseName} releaseInterface ret: ${ret}`); 224 expect(ret).assertEqual(0); 225 } 226 227 /** 228 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1000 229 * @tc.name : testBulkTransferCompat001 230 * @tc.desc : Negative test: send data, pipe busNum +1000 231 * @tc.size : MediumTest 232 * @tc.type : Function 233 * @tc.level : Level 3 234 */ 235 it('testBulkTransferCompat001', 0, async function () { 236 console.info(TAG, 'usb testBulkTransferCompat001 begin'); 237 if (!isDeviceConnected) { 238 expect(isDeviceConnected).assertFalse(); 239 return 240 } 241 242 if (testParam.interface == null || testParam.outEndpoint == null) { 243 expect(testParam.interface == null).assertFalse(); 244 expect(testParam.outEndpoint == null).assertFalse(); 245 return 246 } 247 248 toClaimInterface('testBulkTransferCompat001', testParam.pip, testParam.interface); 249 testParam.sendData = 'send time 13213213 wzy 03'; 250 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 251 testParam.pip.busNum = testParam.pip.busNum + 1000; 252 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 253 console.info(TAG, 'usb [', testParam.pip.busNum, '] bulkTransfer send ret: ' + data); 254 expect(data).assertEqual(-1); 255 }).catch (error => { 256 console.info(TAG, 'usb testBulkTransferCompat001 send error : ' + JSON.stringify(error)); 257 expect(error !== null).assertFalse(); 258 }); 259 toReleaseInterface('testBulkTransferCompat001'); 260 }) 261 262 /** 263 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1100 264 * @tc.name : testBulkTransferCompat002 265 * @tc.desc : Negative test: send data, pipe devAddress +1000 266 * @tc.size : MediumTest 267 * @tc.type : Function 268 * @tc.level : Level 3 269 */ 270 it('testBulkTransferCompat002', 0, async function () { 271 console.info(TAG, 'usb testBulkTransferCompat002 begin'); 272 if (!isDeviceConnected) { 273 expect(isDeviceConnected).assertFalse(); 274 return 275 } 276 277 if (testParam.interface == null || testParam.outEndpoint == null) { 278 expect(testParam.interface == null).assertFalse(); 279 expect(testParam.outEndpoint == null).assertFalse(); 280 return 281 } 282 283 toClaimInterface('testBulkTransferCompat002', testParam.pip, testParam.interface); 284 testParam.sendData = 'send time 13213213 wzy 03'; 285 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 286 testParam.pip.devAddress = testParam.pip.devAddress + 1000; 287 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 288 console.info(TAG, 'usb [', testParam.pip.devAddress, '] bulkTransfer send ret: ' + data); 289 expect(data).assertEqual(-1); 290 }).catch (error => { 291 console.info(TAG, 'usb testBulkTransferCompat002 send error : ' + JSON.stringify(error)); 292 expect(error !== null).assertFalse(); 293 }); 294 toReleaseInterface('testBulkTransferCompat002'); 295 }) 296 297 /** 298 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1200 299 * @tc.name : testBulkTransferCompat003 300 * @tc.desc : Negative test: send data, pipe busNum -1 301 * @tc.size : MediumTest 302 * @tc.type : Function 303 * @tc.level : Level 3 304 */ 305 it('testBulkTransferCompat003', 0, async function () { 306 console.info(TAG, 'usb testBulkTransferCompat003 begin'); 307 if (!isDeviceConnected) { 308 expect(isDeviceConnected).assertFalse(); 309 return 310 } 311 312 if (testParam.interface == null || testParam.outEndpoint == null) { 313 expect(testParam.interface == null).assertFalse(); 314 expect(testParam.outEndpoint == null).assertFalse(); 315 return 316 } 317 318 toClaimInterface('testBulkTransferCompat003', testParam.pip, testParam.interface); 319 testParam.sendData = 'send time 13213213 wzy 03'; 320 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 321 testParam.pip.busNum = -1; 322 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 323 console.info(TAG, 'usb [', testParam.pip.busNum, '] bulkTransfer send ret: ' + data); 324 expect(data).assertEqual(-1); 325 }).catch (error => { 326 console.info(TAG, 'usb testBulkTransferCompat003 send error : ' + JSON.stringify(error)); 327 expect(error !== null).assertFalse(); 328 }); 329 toReleaseInterface('testBulkTransferCompat003'); 330 }) 331 332 /** 333 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1300 334 * @tc.name : testBulkTransferCompat004 335 * @tc.desc : Negative test: send data, pipe devAddress -1 336 * @tc.size : MediumTest 337 * @tc.type : Function 338 * @tc.level : Level 3 339 */ 340 it('testBulkTransferCompat004', 0, async function () { 341 console.info(TAG, 'usb testBulkTransferCompat004 begin'); 342 if (!isDeviceConnected) { 343 expect(isDeviceConnected).assertFalse(); 344 return 345 } 346 347 if (testParam.interface == null || testParam.outEndpoint == null) { 348 expect(testParam.interface == null).assertFalse(); 349 expect(testParam.outEndpoint == null).assertFalse(); 350 return 351 } 352 353 toClaimInterface('testBulkTransferCompat004', testParam.pip, testParam.interface); 354 testParam.sendData = 'send time 13213213 wzy 03'; 355 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 356 testParam.pip.devAddress = -1; 357 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 358 console.info(TAG, 'usb [', testParam.pip.devAddress, '] bulkTransfer send ret: ' + data); 359 expect(data).assertEqual(-1); 360 }).catch (error => { 361 console.info(TAG, 'usb testBulkTransferCompat004 send error : ' + JSON.stringify(error)); 362 expect(error !== null).assertFalse(); 363 }); 364 toReleaseInterface('testBulkTransferCompat004'); 365 }) 366 367 /** 368 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1400 369 * @tc.name : testBulkTransferCompat005 370 * @tc.desc : Negative test: send data, endpoint address +10 371 * @tc.size : MediumTest 372 * @tc.type : Function 373 * @tc.level : Level 3 374 */ 375 it('testBulkTransferCompat005', 0, async function () { 376 console.info(TAG, 'usb testBulkTransferCompat005 begin'); 377 if (!isDeviceConnected) { 378 expect(isDeviceConnected).assertFalse(); 379 return 380 } 381 382 if (testParam.interface == null || testParam.outEndpoint == null) { 383 expect(testParam.interface == null).assertFalse(); 384 expect(testParam.outEndpoint == null).assertFalse(); 385 return 386 } 387 388 toClaimInterface('testBulkTransferCompat005', testParam.pip, testParam.interface); 389 testParam.sendData = 'send time 13213213 wzy 03'; 390 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 391 testParam.outEndpoint.address = testParam.outEndpoint.address + 10; 392 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 393 console.info(TAG, 'usb [', testParam.outEndpoint.address, '] bulkTransfer send ret: ' + data); 394 expect(data).assertEqual(-1); 395 }).catch (error => { 396 console.info(TAG, 'usb testBulkTransferCompat005 send error : ' + JSON.stringify(error)); 397 expect(error !== null).assertFalse(); 398 }); 399 toReleaseInterface('testBulkTransferCompat005'); 400 }) 401 402 /** 403 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1500 404 * @tc.name : testBulkTransferCompat006 405 * @tc.desc : Negative test: send data, endpoint number +10 406 * @tc.size : MediumTest 407 * @tc.type : Function 408 * @tc.level : Level 3 409 */ 410 it('testBulkTransferCompat006', 0, async function () { 411 console.info(TAG, 'usb testBulkTransferCompat006 begin'); 412 if (!isDeviceConnected) { 413 expect(isDeviceConnected).assertFalse(); 414 return 415 } 416 417 if (testParam.interface == null || testParam.outEndpoint == null) { 418 expect(testParam.interface == null).assertFalse(); 419 expect(testParam.outEndpoint == null).assertFalse(); 420 return 421 } 422 423 toClaimInterface('testBulkTransferCompat006', testParam.pip, testParam.interface); 424 testParam.sendData = 'send time 13213213 wzy 03'; 425 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 426 testParam.outEndpoint.number = testParam.outEndpoint.number + 10; 427 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 428 console.info(TAG, 'usb [', testParam.outEndpoint.number, '] bulkTransfer send ret: ' + data); 429 expect(data >= 0).assertTrue(); 430 }).catch (error => { 431 console.info(TAG, 'usb testBulkTransferCompat006 send error : ' + JSON.stringify(error)); 432 expect(error !== null).assertFalse(); 433 }); 434 toReleaseInterface('testBulkTransferCompat006'); 435 }) 436 437 /** 438 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1600 439 * @tc.name : testBulkTransferCompat007 440 * @tc.desc : Negative test: send data, endpoint type +10 441 * @tc.size : MediumTest 442 * @tc.type : Function 443 * @tc.level : Level 3 444 */ 445 it('testBulkTransferCompat007', 0, async function () { 446 console.info(TAG, 'usb testBulkTransferCompat007 begin'); 447 if (!isDeviceConnected) { 448 expect(isDeviceConnected).assertFalse(); 449 return 450 } 451 452 if (testParam.interface == null || testParam.outEndpoint == null) { 453 expect(testParam.interface == null).assertFalse(); 454 expect(testParam.outEndpoint == null).assertFalse(); 455 return 456 } 457 458 toClaimInterface('testBulkTransferCompat007', testParam.pip, testParam.interface); 459 testParam.sendData = 'send time 13213213 wzy 03'; 460 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 461 testParam.outEndpoint.type = testParam.outEndpoint.type + 10; 462 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 463 console.info(TAG, 'usb [', testParam.outEndpoint.type, '] bulkTransfer send ret: ' + data); 464 expect(data >= 0).assertTrue(); 465 }).catch (error => { 466 console.info(TAG, 'usb testBulkTransferCompat007 send error : ' + JSON.stringify(error)); 467 expect(error !== null).assertFalse(); 468 }); 469 toReleaseInterface('testBulkTransferCompat007'); 470 }) 471 472 /** 473 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1700 474 * @tc.name : testBulkTransferCompat008 475 * @tc.desc : Negative test: send data, endpoint address -1 476 * @tc.size : MediumTest 477 * @tc.type : Function 478 * @tc.level : Level 3 479 */ 480 it('testBulkTransferCompat008', 0, async function () { 481 console.info(TAG, 'usb testBulkTransferCompat008 begin'); 482 if (!isDeviceConnected) { 483 expect(isDeviceConnected).assertFalse(); 484 return 485 } 486 487 if (testParam.interface == null || testParam.outEndpoint == null) { 488 expect(testParam.interface == null).assertFalse(); 489 expect(testParam.outEndpoint == null).assertFalse(); 490 return 491 } 492 493 toClaimInterface('testBulkTransferCompat008', testParam.pip, testParam.interface); 494 testParam.sendData = 'send time 13213213 wzy 03'; 495 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 496 testParam.outEndpoint.address = -1; 497 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 498 console.info(TAG, 'usb [', testParam.outEndpoint.address, '] bulkTransfer send ret: ' + data); 499 expect(data).assertEqual(-1); 500 }).catch (error => { 501 console.info(TAG, 'usb testBulkTransferCompat008 send error : ' + JSON.stringify(error)); 502 expect(error !== null).assertFalse(); 503 }); 504 toReleaseInterface('testBulkTransferCompat008'); 505 }) 506 507 /** 508 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1800 509 * @tc.name : testBulkTransferCompat009 510 * @tc.desc : Negative test: send data, endpoint number -1 511 * @tc.size : MediumTest 512 * @tc.type : Function 513 * @tc.level : Level 3 514 */ 515 it('testBulkTransferCompat009', 0, async function () { 516 console.info(TAG, 'usb testBulkTransferCompat009 begin'); 517 if (!isDeviceConnected) { 518 expect(isDeviceConnected).assertFalse(); 519 return 520 } 521 522 if (testParam.interface == null || testParam.outEndpoint == null) { 523 expect(testParam.interface == null).assertFalse(); 524 expect(testParam.outEndpoint == null).assertFalse(); 525 return 526 } 527 528 toClaimInterface('testBulkTransferCompat009', testParam.pip, testParam.interface); 529 testParam.sendData = 'send time 13213213 wzy 03'; 530 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 531 testParam.outEndpoint.number = -1; 532 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 533 console.info(TAG, 'usb [', testParam.outEndpoint.number, '] bulkTransfer send ret: ' + data); 534 expect(data >= 0).assertTrue(); 535 }).catch (error => { 536 console.info(TAG, 'usb testBulkTransferCompat009 send error : ' + JSON.stringify(error)); 537 expect(error !== null).assertFalse(); 538 }); 539 toReleaseInterface('testBulkTransferCompat009'); 540 }) 541 542 /** 543 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_1900 544 * @tc.name : testBulkTransferCompat010 545 * @tc.desc : Negative test: send data, endpoint type -1 546 * @tc.size : MediumTest 547 * @tc.type : Function 548 * @tc.level : Level 3 549 */ 550 it('testBulkTransferCompat010', 0, async function () { 551 console.info(TAG, 'usb testBulkTransferCompat010 begin'); 552 if (!isDeviceConnected) { 553 expect(isDeviceConnected).assertFalse(); 554 return 555 } 556 557 if (testParam.interface == null || testParam.outEndpoint == null) { 558 expect(testParam.interface == null).assertFalse(); 559 expect(testParam.outEndpoint == null).assertFalse(); 560 return 561 } 562 563 toClaimInterface('testBulkTransferCompat010', testParam.pip, testParam.interface); 564 testParam.sendData = 'send time 13213213 wzy 03'; 565 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 566 testParam.outEndpoint.type = -1; 567 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 568 console.info(TAG, 'usb [', testParam.outEndpoint.type, '] bulkTransfer send ret: ' + data); 569 expect(data >= 0).assertTrue(); 570 }).catch (error => { 571 console.info(TAG, 'usb testBulkTransferCompat010 send error : ' + JSON.stringify(error)); 572 expect(error !== null).assertFalse(); 573 }); 574 toReleaseInterface('testBulkTransferCompat010'); 575 }) 576 577 /** 578 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2000 579 * @tc.name : testBulkTransferCompat011 580 * @tc.desc : Negative test: send data, endpoint attributes +10 581 * @tc.size : MediumTest 582 * @tc.type : Function 583 * @tc.level : Level 3 584 */ 585 it('testBulkTransferCompat011', 0, async function () { 586 console.info(TAG, 'usb testBulkTransferCompat011 begin'); 587 if (!isDeviceConnected) { 588 expect(isDeviceConnected).assertFalse(); 589 return 590 } 591 592 if (testParam.interface == null || testParam.outEndpoint == null) { 593 expect(testParam.interface == null).assertFalse(); 594 expect(testParam.outEndpoint == null).assertFalse(); 595 return 596 } 597 598 toClaimInterface('testBulkTransferCompat011', testParam.pip, testParam.interface); 599 testParam.sendData = 'send time 13213213 wzy 03'; 600 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 601 testParam.outEndpoint.attributes = testParam.outEndpoint.attributes + 10; 602 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 603 console.info(TAG, 'usb [', testParam.outEndpoint.attributes, '] bulkTransfer send ret: ' + data); 604 expect(data >= 0).assertTrue(); 605 }).catch (error => { 606 console.info(TAG, 'usb testBulkTransferCompat011 send error : ' + JSON.stringify(error)); 607 expect(error !== null).assertFalse(); 608 }); 609 toReleaseInterface('testBulkTransferCompat011'); 610 }) 611 612 /** 613 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2100 614 * @tc.name : testBulkTransferCompat012 615 * @tc.desc : Negative test: send data, endpoint attributes -1 616 * @tc.size : MediumTest 617 * @tc.type : Function 618 * @tc.level : Level 3 619 */ 620 it('testBulkTransferCompat012', 0, async function () { 621 console.info(TAG, 'usb testBulkTransferCompat012 begin'); 622 if (!isDeviceConnected) { 623 expect(isDeviceConnected).assertFalse(); 624 return 625 } 626 627 if (testParam.interface == null || testParam.outEndpoint == null) { 628 expect(testParam.interface == null).assertFalse(); 629 expect(testParam.outEndpoint == null).assertFalse(); 630 return 631 } 632 633 toClaimInterface('testBulkTransferCompat012', testParam.pip, testParam.interface); 634 testParam.sendData = 'send time 13213213 wzy 03'; 635 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 636 testParam.outEndpoint.attributes = -1; 637 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 638 console.info(TAG, 'usb [', testParam.outEndpoint.attributes, '] bulkTransfer send ret: ' + data); 639 expect(data >= 0).assertTrue(); 640 }).catch (error => { 641 console.info(TAG, 'usb testBulkTransferCompat012 send error : ' + JSON.stringify(error)); 642 expect(error !== null).assertFalse(); 643 }); 644 toReleaseInterface('testBulkTransferCompat012'); 645 }) 646 647 /** 648 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2200 649 * @tc.name : testBulkTransferCompat013 650 * @tc.desc : Negative test: send data, endpoint interval +10 651 * @tc.size : MediumTest 652 * @tc.type : Function 653 * @tc.level : Level 3 654 */ 655 it('testBulkTransferCompat013', 0, async function () { 656 console.info(TAG, 'usb testBulkTransferCompat013 begin'); 657 if (!isDeviceConnected) { 658 expect(isDeviceConnected).assertFalse(); 659 return 660 } 661 662 if (testParam.interface == null || testParam.outEndpoint == null) { 663 expect(testParam.interface == null).assertFalse(); 664 expect(testParam.outEndpoint == null).assertFalse(); 665 return 666 } 667 668 toClaimInterface('testBulkTransferCompat013', testParam.pip, testParam.interface); 669 testParam.sendData = 'send time 13213213 wzy 03'; 670 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 671 testParam.outEndpoint.interval = testParam.outEndpoint.interval + 10; 672 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 673 console.info(TAG, 'usb [', testParam.outEndpoint.interval, '] bulkTransfer send ret: ' + data); 674 expect(data >= 0).assertTrue(); 675 }).catch (error => { 676 console.info(TAG, 'usb testBulkTransferCompat013 send error : ' + JSON.stringify(error)); 677 expect(error !== null).assertFalse(); 678 }); 679 toReleaseInterface('testBulkTransferCompat013'); 680 }) 681 682 /** 683 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2300 684 * @tc.name : testBulkTransferCompat014 685 * @tc.desc : Negative test: send data, endpoint interval -1 686 * @tc.size : MediumTest 687 * @tc.type : Function 688 * @tc.level : Level 3 689 */ 690 it('testBulkTransferCompat014', 0, async function () { 691 console.info(TAG, 'usb testBulkTransferCompat014 begin'); 692 if (!isDeviceConnected) { 693 expect(isDeviceConnected).assertFalse(); 694 return 695 } 696 697 if (testParam.interface == null || testParam.outEndpoint == null) { 698 expect(testParam.interface == null).assertFalse(); 699 expect(testParam.outEndpoint == null).assertFalse(); 700 return 701 } 702 703 toClaimInterface('testBulkTransferCompat014', testParam.pip, testParam.interface); 704 testParam.sendData = 'send time 13213213 wzy 03'; 705 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 706 testParam.outEndpoint.interval = -1; 707 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 708 console.info(TAG, 'usb [', testParam.outEndpoint.interval, '] bulkTransfer send ret: ' + data); 709 expect(data >= 0).assertTrue(); 710 }).catch (error => { 711 console.info(TAG, 'usb testBulkTransferCompat014 send error : ' + JSON.stringify(error)); 712 expect(error !== null).assertFalse(); 713 }); 714 toReleaseInterface('testBulkTransferCompat014'); 715 }) 716 717 /** 718 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2400 719 * @tc.name : testBulkTransferCompat015 720 * @tc.desc : Negative test: send data, endpoint maxPacketSize +10 721 * @tc.size : MediumTest 722 * @tc.type : Function 723 * @tc.level : Level 3 724 */ 725 it('testBulkTransferCompat015', 0, async function () { 726 console.info(TAG, 'usb testBulkTransferCompat015 begin'); 727 if (!isDeviceConnected) { 728 expect(isDeviceConnected).assertFalse(); 729 return 730 } 731 732 if (testParam.interface == null || testParam.outEndpoint == null) { 733 expect(testParam.interface == null).assertFalse(); 734 expect(testParam.outEndpoint == null).assertFalse(); 735 return 736 } 737 738 toClaimInterface('testBulkTransferCompat015', testParam.pip, testParam.interface); 739 testParam.sendData = 'send time 13213213 wzy 03'; 740 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 741 testParam.outEndpoint.maxPacketSize = testParam.outEndpoint.maxPacketSize + 10; 742 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 743 console.info(TAG, 'usb [', testParam.outEndpoint.maxPacketSize, '] bulkTransfer send ret: ' + data); 744 expect(data >= 0).assertTrue(); 745 }).catch (error => { 746 console.info(TAG, 'usb testBulkTransferCompat015 send error : ' + JSON.stringify(error)); 747 expect(error !== null).assertFalse(); 748 }); 749 toReleaseInterface('testBulkTransferCompat015'); 750 }) 751 752 /** 753 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2500 754 * @tc.name : testBulkTransferCompat016 755 * @tc.desc : Negative test: send data, endpoint maxPacketSize -1 756 * @tc.size : MediumTest 757 * @tc.type : Function 758 * @tc.level : Level 3 759 */ 760 it('testBulkTransferCompat016', 0, async function () { 761 console.info(TAG, 'usb testBulkTransferCompat016 begin'); 762 if (!isDeviceConnected) { 763 expect(isDeviceConnected).assertFalse(); 764 return 765 } 766 767 if (testParam.interface == null || testParam.outEndpoint == null) { 768 expect(testParam.interface == null).assertFalse(); 769 expect(testParam.outEndpoint == null).assertFalse(); 770 return 771 } 772 773 toClaimInterface('testBulkTransferCompat016', testParam.pip, testParam.interface); 774 testParam.sendData = 'send time 13213213 wzy 03'; 775 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 776 testParam.outEndpoint.maxPacketSize = -1; 777 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 778 console.info(TAG, 'usb [', testParam.outEndpoint.maxPacketSize, '] bulkTransfer send ret: ' + data); 779 expect(data >= 0).assertTrue(); 780 }).catch (error => { 781 console.info(TAG, 'usb testBulkTransferCompat016 send error : ' + JSON.stringify(error)); 782 expect(error !== null).assertFalse(); 783 }); 784 toReleaseInterface('testBulkTransferCompat016'); 785 }) 786 787 /** 788 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2600 789 * @tc.name : testBulkTransferCompat017 790 * @tc.desc : Negative test: send data, endpoint direction +10 791 * @tc.size : MediumTest 792 * @tc.type : Function 793 * @tc.level : Level 3 794 */ 795 it('testBulkTransferCompat017', 0, async function () { 796 console.info(TAG, 'usb testBulkTransferCompat017 begin'); 797 if (!isDeviceConnected) { 798 expect(isDeviceConnected).assertFalse(); 799 return 800 } 801 802 if (testParam.interface == null || testParam.outEndpoint == null) { 803 expect(testParam.interface == null).assertFalse(); 804 expect(testParam.outEndpoint == null).assertFalse(); 805 return 806 } 807 808 toClaimInterface('testBulkTransferCompat017', testParam.pip, testParam.interface); 809 testParam.sendData = 'send time 13213213 wzy 03'; 810 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 811 testParam.outEndpoint.direction = testParam.outEndpoint.direction + 10; 812 try { 813 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 814 console.info(TAG, 'usb [', testParam.outEndpoint.direction, '] bulkTransfer send ret: ' + data); 815 expect(data !== null).assertFalse(); 816 }) 817 } catch (err) { 818 console.info(TAG, 'usb testBulkTransferCompat017 send error : ', err.code, ', message: ', err.message); 819 expect(err.code).assertEqual(PARAM_ERRCODE); 820 } 821 toReleaseInterface('testBulkTransferCompat017'); 822 }) 823 824 /** 825 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2700 826 * @tc.name : testBulkTransferCompat018 827 * @tc.desc : Negative test: send data, endpoint direction -1 828 * @tc.size : MediumTest 829 * @tc.type : Function 830 * @tc.level : Level 3 831 */ 832 it('testBulkTransferCompat018', 0, async function () { 833 console.info(TAG, 'usb testBulkTransferCompat018 begin'); 834 if (!isDeviceConnected) { 835 expect(isDeviceConnected).assertFalse(); 836 return 837 } 838 839 if (testParam.interface == null || testParam.outEndpoint == null) { 840 expect(testParam.interface == null).assertFalse(); 841 expect(testParam.outEndpoint == null).assertFalse(); 842 return 843 } 844 845 toClaimInterface('testBulkTransferCompat018', testParam.pip, testParam.interface); 846 testParam.sendData = 'send time 13213213 wzy 03'; 847 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 848 testParam.outEndpoint.direction = -1; 849 try { 850 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 851 console.info(TAG, 'usb [', testParam.outEndpoint.direction, '] bulkTransfer send ret: ' + data); 852 expect(data !== null).assertFalse(); 853 }) 854 } catch (err) { 855 console.info(TAG, 'usb testBulkTransferCompat018 send error : ', err.code, ', message: ', err.message); 856 expect(err.code).assertEqual(PARAM_ERRCODE); 857 } 858 toReleaseInterface('testBulkTransferCompat018'); 859 }) 860 861 /** 862 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2800 863 * @tc.name : testBulkTransferCompat019 864 * @tc.desc : Negative test: send data, endpoint interfaceId +10 865 * @tc.size : MediumTest 866 * @tc.type : Function 867 * @tc.level : Level 3 868 */ 869 it('testBulkTransferCompat019', 0, async function () { 870 console.info(TAG, 'usb testBulkTransferCompat019 begin'); 871 if (!isDeviceConnected) { 872 expect(isDeviceConnected).assertFalse(); 873 return 874 } 875 876 if (testParam.interface == null || testParam.outEndpoint == null) { 877 expect(testParam.interface == null).assertFalse(); 878 expect(testParam.outEndpoint == null).assertFalse(); 879 return 880 } 881 882 toClaimInterface('testBulkTransferCompat019', testParam.pip, testParam.interface); 883 testParam.sendData = 'send time 13213213 wzy 03'; 884 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 885 testParam.outEndpoint.interfaceId = testParam.outEndpoint.interfaceId + 10; 886 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 887 console.info(TAG, 'usb [', testParam.outEndpoint.interfaceId, '] bulkTransfer send ret: ' + data); 888 expect(data).assertEqual(-1); 889 }).catch (error => { 890 console.info(TAG, 'usb testBulkTransferCompat019 send error : ' + JSON.stringify(error)); 891 expect(error !== null).assertFalse(); 892 }); 893 toReleaseInterface('testBulkTransferCompat019'); 894 }) 895 896 /** 897 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_2900 898 * @tc.name : testBulkTransferCompat020 899 * @tc.desc : Negative test: send data, endpoint interfaceId -1 900 * @tc.size : MediumTest 901 * @tc.type : Function 902 * @tc.level : Level 3 903 */ 904 it('testBulkTransferCompat020', 0, async function () { 905 console.info(TAG, 'usb testBulkTransferCompat020 begin'); 906 if (!isDeviceConnected) { 907 expect(isDeviceConnected).assertFalse(); 908 return 909 } 910 911 if (testParam.interface == null || testParam.outEndpoint == null) { 912 expect(testParam.interface == null).assertFalse(); 913 expect(testParam.outEndpoint == null).assertFalse(); 914 return 915 } 916 917 toClaimInterface('testBulkTransferCompat020', testParam.pip, testParam.interface); 918 testParam.sendData = 'send time 13213213 wzy 03'; 919 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 920 testParam.outEndpoint.interfaceId = -1; 921 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { 922 console.info(TAG, 'usb [', testParam.outEndpoint.interfaceId, '] bulkTransfer send ret: ' + data); 923 expect(data).assertEqual(-1); 924 }).catch (error => { 925 console.info(TAG, 'usb testBulkTransferCompat020 send error : ' + JSON.stringify(error)); 926 expect(error !== null).assertFalse(); 927 }); 928 toReleaseInterface('testBulkTransferCompat020'); 929 }) 930 931 /** 932 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_3000 933 * @tc.name : testBulkTransferCompat021 934 * @tc.desc : Negative test: send data, timeout is "" 935 * @tc.size : MediumTest 936 * @tc.type : Function 937 * @tc.level : Level 3 938 */ 939 it('testBulkTransferCompat021', 0, async function () { 940 console.info(TAG, 'usb testBulkTransferCompat021 begin'); 941 if (!isDeviceConnected) { 942 expect(isDeviceConnected).assertFalse(); 943 return 944 } 945 946 if (testParam.interface == null || testParam.outEndpoint == null) { 947 expect(testParam.interface == null).assertFalse(); 948 expect(testParam.outEndpoint == null).assertFalse(); 949 return 950 } 951 952 toClaimInterface('testBulkTransferCompat021', testParam.pip, testParam.interface); 953 testParam.sendData = 'send time 13213213 wzy 03'; 954 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 955 let timeout = PARAM_NULLSTRING; 956 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, timeout).then(data => { 957 console.info(TAG, 'usb [timeout:""] bulkTransfer send ret: ' + data); 958 expect(data >= 0).assertTrue(); 959 }).catch (error => { 960 console.info(TAG, 'usb testBulkTransferCompat021 send error : ' + JSON.stringify(error)); 961 expect(error !== null).assertFalse(); 962 }); 963 toReleaseInterface('testBulkTransferCompat021'); 964 }) 965 966 /** 967 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_3100 968 * @tc.name : testBulkTransferCompat022 969 * @tc.desc : Negative test: Enter five parameters 970 * @tc.size : MediumTest 971 * @tc.type : Function 972 * @tc.level : Level 3 973 */ 974 it('testBulkTransferCompat022', 0, async function () { 975 console.info(TAG, 'usb testBulkTransferCompat022 begin'); 976 if (!isDeviceConnected) { 977 expect(isDeviceConnected).assertFalse(); 978 return 979 } 980 981 if (testParam.interface == null || testParam.outEndpoint == null) { 982 expect(testParam.interface == null).assertFalse(); 983 expect(testParam.outEndpoint == null).assertFalse(); 984 return 985 } 986 987 toClaimInterface('testBulkTransferCompat022', testParam.pip, testParam.interface); 988 testParam.sendData = 'send time 13213213 wzy 03'; 989 let tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); 990 let timeout = 5000; 991 await usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, timeout, 992 testParam.pip).then(data => { 993 console.info(TAG, 'usb [timeout:""] bulkTransfer send ret: ' + data); 994 expect(data >= 0).assertTrue(); 995 }).catch (error => { 996 console.info(TAG, 'usb testBulkTransferCompat022 send error : ' + JSON.stringify(error)); 997 expect(error !== null).assertFalse(); 998 }); 999 toReleaseInterface('testBulkTransferCompat022'); 1000 }) 1001 1002 /** 1003 * @tc.number : SUB_USB_HostManager_JS_TranCompatibility_3200 1004 * @tc.name : testUsbControlTransferCompat001 1005 * @tc.desc : Negative test: Enter four parameters 1006 * @tc.size : MediumTest 1007 * @tc.type : Function 1008 * @tc.level : Level 3 1009 */ 1010 it('testUsbControlTransferCompat001', 0, async function () { 1011 console.info(TAG, 'usb testUsbControlTransferCompat001 begin'); 1012 if (!isDeviceConnected) { 1013 expect(isDeviceConnected).assertFalse(); 1014 return 1015 } 1016 1017 if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { 1018 expect(testParam.inEndpoint == null).assertFalse(); 1019 expect(testParam.interface == null).assertFalse(); 1020 expect(testParam.outEndpoint == null).assertFalse(); 1021 return 1022 } 1023 1024 let requestparam = getControlTransferParam(0x80, 0x60, (0x01 << 8 | 0), 0, 18); 1025 let timeout = 5000; 1026 1027 await usbManager.usbControlTransfer(testParam.pip, requestparam, timeout, testParam.pip).then(data => { 1028 console.info(TAG, 'usb [Enter four parameters] usbControlTransfer data: ' + data); 1029 console.info(TAG, 'usb [Enter four parameters] usbControlTransfer buffer data: ' + requestparam.data); 1030 expect(data >= 0).assertTrue(); 1031 }).catch (error => { 1032 console.info(TAG, 'usb testUsbControlTransferCompat001 send error : ' + JSON.stringify(error)); 1033 expect(error !== null).assertFalse(); 1034 }); 1035 }) 1036 1037}) 1038}