UsbDevicePipeJsunit.test.js 44.4 KB
Newer Older
J
jiyong_sd 已提交
1
/*
L
lixiaofeng_154b 已提交
2
 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
J
jiyong_sd 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

L
lixiaofeng_154b 已提交
16
import usbManager from '@ohos.usbManager';
J
jiyong_sd 已提交
17 18 19
import CheckEmptyUtils from './CheckEmptyUtils.js';
import EventConstants from './EventConstants.js';
import parameter from '@ohos.systemparameter';
H
huyong 已提交
20
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
J
jiyong_sd 已提交
21 22 23 24 25 26 27 28 29 30 31

/* usb device pipe test */
export default function UsbDevicePipeJsFunctionsTest() {
describe('UsbDevicePipeJsFunctionsTest', function () {

  var gDeviceList
  var gPipe
  var portCurrentMode

  beforeAll(function () {
    console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************');
L
lixiaofeng_154b 已提交
32
    var Version = usbManager.getVersion()
J
jiyong_sd 已提交
33 34
    console.info('usb unit begin test getversion :' + Version)
    // version > 17  host currentMode = 2 device currentMode = 1
L
lixiaofeng_154b 已提交
35
    var usbPortList = usbManager.getPorts()
L
lixiaofeng_154b 已提交
36 37 38 39
    if (usbPortList == undefined) {
      portCurrentMode = 1;
      return
    }
L
lixiaofeng_154b 已提交
40
    gDeviceList = usbManager.getDevices();
J
jiyong_sd 已提交
41 42 43
    if (usbPortList.length > 0) {
      if (gDeviceList.length > 0) {
        if (usbPortList[0].status.currentMode == 1) {
L
lixiaofeng_154b 已提交
44
          usbManager.setPortRoles(usbPortList[0].id, usbManager.SOURCE, usbManager.HOST).then(data => {
J
jiyong_sd 已提交
45 46 47 48 49
            portCurrentMode = 2
            console.info('usb case setPortRoles return: ' + data);
          }).catch(error => {
            console.info('usb case setPortRoles error : ' + error);
          });
50
          CheckEmptyUtils.sleep(8000)
J
jiyong_sd 已提交
51 52 53 54 55 56 57
          console.log('*************Usb Unit switch to host Begin*************');
        }
      } else {
        portCurrentMode = 1
      }
    }

L
lixiaofeng_154b 已提交
58
    gDeviceList = usbManager.getDevices();
59 60 61
    gDeviceList[0].name;
    gDeviceList[0].version;
    gDeviceList[0].configs;
L
lixiaofeng_154b 已提交
62
    gPipe = usbManager.connectDevice(gDeviceList[0])
J
jiyong_sd 已提交
63 64 65 66 67 68 69 70 71 72 73
    console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe));
  })

  beforeEach(function () {
    console.info('beforeEach: *************Usb Unit Test Case*************');
  })
  afterEach(function () {
    console.info('afterEach: *************Usb Unit Test Case*************');
  })

  afterAll(function () {
L
lixiaofeng_154b 已提交
74
    var isPipClose = usbManager.closePipe(gPipe)
J
jiyong_sd 已提交
75 76 77 78 79 80 81 82
    console.info('usb unit close gPipe ret : ' + isPipClose);
    console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest End*************');
  })

  function findInitPoint(testParam, j) {
    var bfind = false
    for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) {
      var endpoint = testParam.config.interfaces[j].endpoints[k];
83 84 85
      endpoint.number = 1;
      endpoint.type = 2;
      endpoint.interfaceid = 1;
J
jiyong_sd 已提交
86 87
      if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) {
        bfind = true
L
lixiaofeng_154b 已提交
88
        if (endpoint.direction == usbManager.USB_REQUEST_DIR_TO_DEVICE) {
J
jiyong_sd 已提交
89 90
          testParam.maxOutSize = endpoint.maxPacketSize;
          testParam.outEndpoint = endpoint;
L
lixiaofeng_154b 已提交
91
        } else if (endpoint.direction == usbManager.USB_REQUEST_DIR_FROM_DEVICE) {
J
jiyong_sd 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
          testParam.maxInSize = endpoint.maxPacketSize;
          testParam.inEndpoint = endpoint
        }
      }
    }
    if (bfind) {
      testParam.interface = testParam.config.interfaces[j]
      return bfind
    }
    return false
  }

  function getFlag(testParam, j) {
    if (testParam.config.interfaces[j].endpoints.length == 0) {
      return false
    }

    if (testParam.config.interfaces[j].clazz != 10 ||
W
wuchengwen 已提交
110
      testParam.config.interfaces[j].subClass != 0 ||
J
jiyong_sd 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
      testParam.config.interfaces[j].protocol != 2) {
      return false
    }
    return true
  }

  function initPoint(testParam) {
    for (var j = 0; j < testParam.config.interfaces.length; j++) {
      if (getFlag(testParam, j) == true) {
        if (findInitPoint(testParam, j) == true) {
          break
        }
      }
    }
  }

127
  // Prefabrication transmission related parameters
J
jiyong_sd 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  function getTransferTestParam() {
    var testParam = {
      config: null,
      device: null,
      pip: null,
      inEndpoint: null,
      interface: null,
      outEndpoint: null,
      usbRequest: null,
      sendData: '',
      isClaimed: 0,
      maxInSize: 1024,
      maxOutSize: 1024
    }

    console.info('usb case  gDeviceList.length: ' + gDeviceList.length);
    for (var i = 0; i < gDeviceList.length; i++) {
      testParam.device = gDeviceList[i]
      testParam.config = testParam.device.configs[0]
      testParam.pip = gPipe
      initPoint(testParam)
    }
    return testParam
  }

  /**
154 155 156
   * @tc.number: SUB_USB_JS_0630
   * @tc.name: bulkTransfer
   * @tc.desc: Positive test: bulk transfer, receive data
J
jiyong_sd 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
   */
  it('SUB_USB_JS_0630', 0, function () {
    console.info('usb SUB_USB_JS_0630 begin');
    console.info('usb SUB_USB_JS_0630 portcurrentMode ret : ' + portCurrentMode)
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.interface == null || testParam.inEndpoint == null) {
      expect(false).assertTrue();
      return
    }

L
lixiaofeng_154b 已提交
172
    testParam.isClaimed = usbManager.claimInterface(testParam.pip, testParam.interface, true);
J
jiyong_sd 已提交
173 174 175 176
    expect(testParam.isClaimed).assertEqual(0);

    console.info('usb case readData begin');
    var tmpUint8Array = new Uint8Array(testParam.maxInSize);
L
lixiaofeng_154b 已提交
177
    usbManager.bulkTransfer(testParam.pip, testParam.inEndpoint, tmpUint8Array, 5000).then(data => {
J
jiyong_sd 已提交
178 179 180
      console.info('usb case readData tmpUint8Array buffer : ' + CheckEmptyUtils.ab2str(tmpUint8Array));
      console.info('usb case readData ret: ' + data);
      expect(data >= 0).assertTrue();
181
      console.info('usb case SUB_USB_JS_0630 :  PASS');
J
jiyong_sd 已提交
182 183 184 185
    }).catch(error => {
      console.info('usb case readData error : ' + JSON.stringify(error));
      expect(false).assertTrue();
    });
186
    CheckEmptyUtils.sleep(3000);
J
jiyong_sd 已提交
187 188 189
  })

  /**
190 191 192
   * @tc.number: SUB_USB_JS_0640
   * @tc.name: bulkTransfer
   * @tc.desc: Positive test: bulk transfer, send data
J
jiyong_sd 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206
   */
  it('SUB_USB_JS_0640', 0, function () {
    console.info('usb SUB_USB_JS_0640 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

L
lixiaofeng_154b 已提交
207
    testParam.isClaimed = usbManager.claimInterface(testParam.pip, testParam.interface, true);
J
jiyong_sd 已提交
208 209 210 211 212 213 214 215 216 217 218
    expect(testParam.isClaimed).assertEqual(0);

    testParam.sendData = 'send default';
    try {
      testParam.sendData = parameter.getSync('test_usb', 'default');
      console.log('usb parameter ' + JSON.stringify(testParam.sendData));
    } catch (e) {
      console.log('usb parameter getSync unexpected error: ' + e);
    }

    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
L
lixiaofeng_154b 已提交
219
    usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => {
J
jiyong_sd 已提交
220 221
      console.info('usb case SUB_USB_JS_0640 ret: ' + data);
      console.info('usb case SUB_USB_JS_0640 send data: ' + testParam.sendData);
222
      expect(data > 0).assertTrue();
J
jiyong_sd 已提交
223 224 225 226 227
      console.info('usb case SUB_USB_JS_0640 :  PASS');
    }).catch(error => {
      console.info('usb write error : ' + JSON.stringify(error));
      expect(false).assertTrue();
    });
228
    CheckEmptyUtils.sleep(3000);
J
jiyong_sd 已提交
229 230
  })

H
huyong 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
  /**
   * @tc.number: SUB_USB_JS_0641
   * @tc.name: bulkTransfer
   * @tc.desc: Undefined
   */
  it('SUB_USB_JS_0641', 0, function () {
    console.info('usb SUB_USB_JS_0641 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    testParam.isClaimed = usbManager.claimInterface(testParam.pip, testParam.interface, true);
    expect(testParam.isClaimed).assertEqual(0);

    testParam.sendData = 'send default';
    try {
      testParam.sendData = parameter.getSync('test_usb', 'default');
      console.log('usb 0641 parameter ' + JSON.stringify(testParam.sendData));
    } catch (e) {
      console.log('usb 0641 parameter getSync unexpected error: ' + e);
    }

    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
    usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, undefined).then(data => {
      console.info('usb case SUB_USB_JS_0641 ret: ' + data);
      console.info('usb case SUB_USB_JS_0641 send data: ' + testParam.sendData);
      expect(data > 0).assertTrue();
      console.info('usb case SUB_USB_JS_0641 :  PASS');
    }).catch(error => {
      console.info('usb 0641 write error : ' + JSON.stringify(error));
      expect(false).assertTrue();
    });
    CheckEmptyUtils.sleep(3000);
  })

  /**
   * @tc.number: SUB_USB_JS_0642
   * @tc.name: bulkTransfer
   * @tc.desc: Null
   */
  it('SUB_USB_JS_0642', 0, function () {
    console.info('usb SUB_USB_JS_0642 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    testParam.isClaimed = usbManager.claimInterface(testParam.pip, testParam.interface, true);
    expect(testParam.isClaimed).assertEqual(0);

    testParam.sendData = 'send default';
    try {
      testParam.sendData = parameter.getSync('test_usb', 'default');
      console.log('usb 0642 parameter ' + JSON.stringify(testParam.sendData));
    } catch (e) {
      console.log('usb 0642 parameter getSync unexpected error: ' + e);
    }

    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
    usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, null).then(data => {
      console.info('usb case SUB_USB_JS_0642 ret: ' + data);
      console.info('usb case SUB_USB_JS_0642 send data: ' + testParam.sendData);
      expect(data > 0).assertTrue();
      console.info('usb case SUB_USB_JS_0642 :  PASS');
    }).catch(error => {
      console.info('usb 0642 write error : ' + JSON.stringify(error));
      expect(false).assertTrue();
    });
    CheckEmptyUtils.sleep(3000);
  })

  /**
   * @tc.number: SUB_USB_JS_0643
   * @tc.name: bulkTransfer
   * @tc.desc:
   */
  it('SUB_USB_JS_0643', 0, function () {
    console.info('usb SUB_USB_JS_0643 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    testParam.isClaimed = usbManager.claimInterface(testParam.pip, testParam.interface, true);
    expect(testParam.isClaimed).assertEqual(0);

    testParam.sendData = 'send default';
    try {
      testParam.sendData = parameter.getSync('test_usb', 'default');
      console.log('usb 0643 parameter ' + JSON.stringify(testParam.sendData));
    } catch (e) {
      console.log('usb 0643 parameter getSync unexpected error: ' + e);
    }

    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
    usbManager.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array).then(data => {
      console.info('usb case SUB_USB_JS_0643 ret: ' + data);
      console.info('usb case SUB_USB_JS_0643 send data: ' + testParam.sendData);
      expect(data > 0).assertTrue();
      console.info('usb case SUB_USB_JS_0643 :  PASS');
    }).catch(error => {
      console.info('usb 0643 write error : ' + JSON.stringify(error));
      expect(false).assertTrue();
    });
    CheckEmptyUtils.sleep(3000);
  })

J
jiyong_sd 已提交
357
  /**
358 359 360
   * @tc.number: SUB_USB_JS_0420
   * @tc.name: claimInterface
   * @tc.desc: Positive test: Get interface, and release
J
jiyong_sd 已提交
361 362 363 364 365 366 367 368 369
   */
  it('SUB_USB_JS_0420', 0, function () {
    console.info('usb SUB_USB_JS_0420 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
370
      console.info('usb 0420 case get_device_list is null')
J
jiyong_sd 已提交
371 372 373 374 375
      expect(gDeviceList.length).assertEqual(-1);
      return
    }

    if (gDeviceList[0].configs.length == 0) {
376
      console.info('usb 0420 case current device.configs.length = 0');
J
jiyong_sd 已提交
377 378 379 380 381 382 383 384 385
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      if (gDeviceList[0].configs[j].interfaces.length == 0) {
        console.info('usb case current device.configs.interfaces.length = 0');
      }
      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
386 387
        //Attribute Prefabrication
        var interfaces = gDeviceList[0].configs[j].interfaces[k];
H
huyong 已提交
388 389 390
        interfaces.id = 1;
        interfaces.name = '';
        interfaces.alternateSetting = 0;
L
lixiaofeng_154b 已提交
391
        var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true)
J
jiyong_sd 已提交
392 393 394
        console.info('usb case claimInterface function return: ' + isClaim);
        expect(isClaim).assertEqual(0);
        if (isClaim == 0) {
L
lixiaofeng_154b 已提交
395
          isClaim = usbManager.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
J
jiyong_sd 已提交
396 397
          console.info('usb case releaseInterface function return: ' + isClaim);
          expect(isClaim).assertEqual(0);
L
lixiaofeng_154b 已提交
398
          gPipe = usbManager.connectDevice(gDeviceList[0])
J
jiyong_sd 已提交
399 400 401 402 403 404 405
        }
      }
    }

    console.info('usb SUB_USB_JS_0420 :  PASS');
  })

H
huyong 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
  /**
   * @tc.number: SUB_USB_JS_1520
   * @tc.name: claimInterface
   * @tc.desc: Negative test: Get interface, parameter force type error
   */
  it('SUB_USB_JS_1520', 0, function () {
    console.info('usb SUB_USB_JS_1520 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case get_device_list is null')
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      if (gDeviceList[0].configs[j].interfaces.length == 0) {
        console.info('usb case SUB_USB_JS_1520 current device.configs.interfaces.length = 0');
      }
      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
        var TmpInterface = gDeviceList[0].configs[j].interfaces[k];
        console.info("usb case 1520 claimInterface TmpInterface.id return:" + TmpInterface.id);
        console.info("usb case 1520 claimInterface TmpInterface return:" + JSON.stringify(TmpInterface));
        var maskCode = usbManager.claimInterface(gPipe, TmpInterface, "invalid");
        console.info('usb 1520 case claimInterface return: ' + maskCode);
        expect(maskCode).assertEqual(0);
      }
    }
  })

  /**
   * @tc.number: SUB_USB_JS_0421
   * @tc.name: claimInterface
   * @tc.desc: Test the claimInterface() interface.
   * Undefined option arguments, use default options.
   */
  it('SUB_USB_JS_0421', 0, function () {
    console.info('usb SUB_USB_JS_0421 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0421 get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case 0421 get_device_list is null')
      expect(gDeviceList.length).assertEqual(-1);
      return
    }

    if (gDeviceList[0].configs.length == 0) {
      console.info('usb case 0421 current device.configs.length = 0');
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      if (gDeviceList[0].configs[j].interfaces.length == 0) {
        console.info('usb case 0421 current device.configs.interfaces.length = 0');
      }
      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
        //Attribute Prefabrication
        var interfaces = gDeviceList[0].configs[j].interfaces[k];
        var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], undefined)
        console.info('usb case 0421 claimInterface function return: ' + isClaim);
        expect(isClaim).assertEqual(0);
        if (isClaim == 0) {
          isClaim = usbManager.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
          console.info('usb case 0421 releaseInterface function return: ' + isClaim);
          expect(isClaim).assertEqual(0);
          gPipe = usbManager.connectDevice(gDeviceList[0])
        }
      }
    }
    console.info('usb SUB_USB_JS_0421 :  PASS');
  })

  /**
   * @tc.number: SUB_USB_JS_0422
   * @tc.name: claimInterface
   * @tc.desc: Test the claimInterface() interface.
   * Undefined option arguments, use default options.
   */
  it('SUB_USB_JS_0422', 0, function () {
    console.info('usb SUB_USB_JS_0422 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0422 get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case 0422 get_device_list is null')
      expect(gDeviceList.length).assertEqual(-1);
      return
    }

    if (gDeviceList[0].configs.length == 0) {
      console.info('usb case 0422 current device.configs.length = 0');
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      if (gDeviceList[0].configs[j].interfaces.length == 0) {
        console.info('usb case 0422 current device.configs.interfaces.length = 0');
      }
      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
        //Attribute Prefabrication
        var interfaces = gDeviceList[0].configs[j].interfaces[k];
        var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], null)
        console.info('usb case 0422 claimInterface function return: ' + isClaim);
        expect(isClaim).assertEqual(0);
        if (isClaim == 0) {
          isClaim = usbManager.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
          console.info('usb case 0422 releaseInterface function return: ' + isClaim);
          expect(isClaim).assertEqual(0);
          gPipe = usbManager.connectDevice(gDeviceList[0])
        }
      }
    }
    console.info('usb SUB_USB_JS_0422 :  PASS');
  })

  /**
   * @tc.number: SUB_USB_JS_0423
   * @tc.name: claimInterface
   * @tc.desc: Test the claimInterface() interface.
   * Undefined option arguments, use default options.
   */
  it('SUB_USB_JS_0423', 0, function () {
    console.info('usb SUB_USB_JS_0423 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0423 get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case 0423 get_device_list is null')
      expect(gDeviceList.length).assertEqual(-1);
      return
    }

    if (gDeviceList[0].configs.length == 0) {
      console.info('usb case 0423 current device.configs.length = 0');
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      if (gDeviceList[0].configs[j].interfaces.length == 0) {
        console.info('usb case 0423 current device.configs.interfaces.length = 0');
      }
      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
        //Attribute Prefabrication
        var interfaces = gDeviceList[0].configs[j].interfaces[k];
        var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
        console.info('usb case 0423 claimInterface function return: ' + isClaim);
        expect(isClaim).assertEqual(0);
        if (isClaim == 0) {
          isClaim = usbManager.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
          console.info('usb case 0423 releaseInterface function return: ' + isClaim);
          expect(isClaim).assertEqual(0);
          gPipe = usbManager.connectDevice(gDeviceList[0])
        }
      }
    }
    console.info('usb SUB_USB_JS_0423 :  PASS');
  })

577
  function getTransferParam(iCmd, iReqTarType, iReqType, iValue, iIndex) {
J
jiyong_sd 已提交
578 579
    var tmpUint8Array = new Uint8Array(512);
    var requestCmd = iCmd
580
    var requestTargetType = iReqTarType
J
jiyong_sd 已提交
581 582 583 584 585
    var requestType = iReqType
    var value = iValue;
    var index = iIndex;
    var controlParam = {
      request: requestCmd,
586
      target: requestTargetType,
J
jiyong_sd 已提交
587 588 589 590 591 592 593 594 595
      reqType: requestType,
      value: value,
      index: index,
      data: tmpUint8Array
    }
    return controlParam
  }

  /**
596 597 598
   * @tc.number: SUB_USB_JS_0740
   * @tc.name: setConfiguration
   * @tc.desc: Positive test: Set Device Configuration
J
jiyong_sd 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612
   */
  it('SUB_USB_JS_0740', 0, function () {
    console.info('usb SUB_USB_JS_0740 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case get_device_list is null')
      expect(false).assertTrue();
      return
    }

L
lixiaofeng_154b 已提交
613
    gPipe = usbManager.connectDevice(gDeviceList[0])
J
jiyong_sd 已提交
614
    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
615 616 617 618 619 620
      var configs = gDeviceList[0].configs[j];
      configs.id = 1;
      configs.name = '';
      configs.maxPower = 1;
      configs.isRemoteWakeup = true;
      configs.isSelfPowered = true;
L
lixiaofeng_154b 已提交
621
      var ret = usbManager.setConfiguration(gPipe, gDeviceList[0].configs[j])
J
jiyong_sd 已提交
622 623 624 625 626 627 628 629
      console.info('usb case setConfiguration return : ' + ret);
      expect(ret).assertEqual(0);
    }

    console.info('usb SUB_USB_JS_0740 :  PASS');
  })

  /**
630 631
   * @tc.number: SUB_USB_JS_0750
   * @tc.name: setConfiguration
L
lixiaofeng_154b 已提交
632
   * @tc.desc: Negative test: Set Device Configuration, USBConfig id error
J
jiyong_sd 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
   */
  it('SUB_USB_JS_0750', 0, function () {
    console.info('usb SUB_USB_JS_0750 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case get_device_list is null')
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
      var config = JSON.parse(JSON.stringify(gDeviceList[0].configs[j]));
      config.id = 255
L
lixiaofeng_154b 已提交
650
      var ret = usbManager.setConfiguration(gPipe, config)
J
jiyong_sd 已提交
651 652 653 654 655 656 657 658
      console.info('usb case setConfiguration return : ' + ret);
      expect(ret).assertLess(0);
    }

    console.info('usb SUB_USB_JS_0750 :  PASS');
  })

  /**
659 660 661
   * @tc.number: SUB_USB_JS_0800
   * @tc.name: setInterface
   * @tc.desc: Positive test: Set device interface
J
jiyong_sd 已提交
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
   */
  it('SUB_USB_JS_0800', 0, function () {
    console.info('usb SUB_USB_JS_0800 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case get_device_list is null')
      expect(false).assertTrue();
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
L
lixiaofeng_154b 已提交
677
      var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
J
jiyong_sd 已提交
678 679
      expect(isClaim).assertEqual(0)
      if (isClaim == 0) {
L
lixiaofeng_154b 已提交
680
        var ret = usbManager.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0])
J
jiyong_sd 已提交
681
        console.info('usb case setInterface return : ' + ret);
682
        expect(ret).assertEqual(0);
J
jiyong_sd 已提交
683 684 685 686 687 688 689
      }
    }

    console.info('usb SUB_USB_JS_0800 :  PASS');
  })

  /**
690 691 692
   * @tc.number: SUB_USB_JS_0810
   * @tc.name: setInterface
   * @tc.desc: Negative test: Set device interface, error tmpInterface.id
J
jiyong_sd 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
   */
  it('SUB_USB_JS_0810', 0, function () {
    console.info('usb SUB_USB_JS_0810 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    if (gDeviceList.length == 0) {
      console.info('usb case get_device_list is null')
      expect(false).assertTrue()
      return
    }

    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
L
lixiaofeng_154b 已提交
708
      var isClaim = usbManager.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
J
jiyong_sd 已提交
709 710 711 712
      expect(isClaim).assertEqual(0)
      if (isClaim == 0) {
        var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0]));
        tmpInterface.id = 234
L
lixiaofeng_154b 已提交
713
        var ret = usbManager.setInterface(gPipe, tmpInterface)
J
jiyong_sd 已提交
714
        console.info('usb case setInterface return : ' + ret)
715
        expect(ret).assertLess(0)
J
jiyong_sd 已提交
716 717 718 719 720 721 722
      }
    }

    console.info('usb SUB_USB_JS_0810 :  PASS');
  })

  function callControlTransfer(pip, controlParam, timeout, caseName) {
L
lixiaofeng_154b 已提交
723
    usbManager.controlTransfer(pip, controlParam, timeout).then(data => {
J
jiyong_sd 已提交
724 725
      console.info('usb controlTransfer ret data : ' + data + ' ' + caseName);
      console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName);
726
      expect(data >= 0).assertTrue();
J
jiyong_sd 已提交
727 728
      console.info('usb' + caseName + ':  PASS');
    }).catch(error => {
H
huyong 已提交
729
      console.info('usb ' + caseName + ' controlTransfer error : ' + JSON.stringify(error));
730
      console.info('usb' + caseName + ':  FAILED');
J
jiyong_sd 已提交
731 732
      expect(false).assertTrue();
    });
733
    CheckEmptyUtils.sleep(3000);
J
jiyong_sd 已提交
734 735 736
  }

  /**
737 738 739
   * @tc.number: SUB_USB_JS_0540
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, GetDescriptor: cmd 6 target 2 reqType 128 value 512 index 0
J
jiyong_sd 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
   */
  it('SUB_USB_JS_0540', 0, function () {
    console.info('usb SUB_USB_JS_0540 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
755 756 757
    var controlParam = getTransferParam(6, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0);
J
jiyong_sd 已提交
758 759 760 761
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor')
  })

  /**
762 763 764
   * @tc.number: SUB_USB_JS_0550
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, GetStatus: cmd 0 target 0 reqType 128 value 0 index 0
J
jiyong_sd 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
   */
  it('SUB_USB_JS_0550', 0, function () {
    console.info('usb SUB_USB_JS_0550 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
780 781 782
    var controlParam = getTransferParam(0, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
J
jiyong_sd 已提交
783 784 785
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus')
  })

H
huyong 已提交
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
  /**
   * @tc.number: SUB_USB_JS_0551
   * @tc.name: controlTransfer
   * @tc.desc: Test the bulkTransfer interface
   * Undefined option arguments, use default options.
   */
  it('SUB_USB_JS_0551', 0, function () {
    console.info('usb SUB_USB_JS_0551 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0551 get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var controlParam = getTransferParam(0, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
    callControlTransfer(testParam.pip, controlParam, undefined, 'SUB_USB_JS_0551 GetStatus')
  })

  /**
   * @tc.number: SUB_USB_JS_0552
   * @tc.name: controlTransfer
   * @tc.desc: Test the bulkTransfer interface
   * Null option arguments, use default options.
   */
  it('SUB_USB_JS_0552', 0, function () {
    console.info('usb SUB_USB_JS_0552 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0552 get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var controlParam = getTransferParam(0, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
    callControlTransfer(testParam.pip, controlParam, null, 'SUB_USB_JS_0552 GetStatus')
  })

  /**
   * @tc.number: SUB_USB_JS_0553
   * @tc.name: controlTransfer
   * @tc.desc: Test the bulkTransfer interface
   * Ignore option arguments.
   */
  it('SUB_USB_JS_0553', 0, function () {
    console.info('usb SUB_USB_JS_0553 begin');
    if (portCurrentMode == 1) {
      console.info('usb case 0553 get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var controlParam = getTransferParam(0, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
    usbManager.controlTransfer(testParam.pip, controlParam).then(data => {
      console.info('usb controlTransfer ret data : ' + data + ' ' + 'SUB_USB_JS_0553 GetStatus');
      console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + 'SUB_USB_JS_0553 GetStatus');
      expect(data >= 0).assertTrue();
      console.info('usb' + 'SUB_USB_JS_0553 GetStatus' + ':  PASS');
    }).catch(error => {
      console.info('usb 0553 controlTransfer error : ' + JSON.stringify(error));
      console.info('usb' + 'SUB_USB_JS_0553 GetStatus' + ':  FAILED');
      expect(false).assertTrue();
    });
    CheckEmptyUtils.sleep(3000);
  })

J
jiyong_sd 已提交
871
  /**
872 873 874
   * @tc.number: SUB_USB_JS_0560
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, GetConfiguration: cmd 8 target 0 reqType 128 value 0 index 0
J
jiyong_sd 已提交
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
   */
  it('SUB_USB_JS_0560', 0, function () {
    console.info('usb SUB_USB_JS_0560 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
890 891 892
    var controlParam = getTransferParam(8, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
J
jiyong_sd 已提交
893 894 895 896
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration')
  })

  /**
897 898 899
   * @tc.number: SUB_USB_JS_0570
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, GetInterface: cmd 10 target 0 reqType 129 value 0 index 1
J
jiyong_sd 已提交
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
   */
  it('SUB_USB_JS_0570', 0, function () {
    console.info('usb SUB_USB_JS_0570 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
915 916 917
    var controlParam = getTransferParam(10, usbManager.USB_REQUEST_TARGET_INTERFACE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1);
J
jiyong_sd 已提交
918 919 920 921
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface')
  })

  /**
922 923 924
   * @tc.number: SUB_USB_JS_0580
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, ClearFeature: cmd 1 target 0 reqType 0 value 0 index 0
J
jiyong_sd 已提交
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
   */
  it('SUB_USB_JS_0580', 0, function () {
    console.info('usb SUB_USB_JS_0580 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
940 941 942
    var controlParam = getTransferParam(1, usbManager.USB_REQUEST_TARGET_DEVICE,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0);
J
jiyong_sd 已提交
943 944 945 946
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature')
  })

  /**
947 948 949
   * @tc.number: SUB_USB_JS_0590
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, ClearFeature: cmd 255 target 1 reqType 129 value 512 index 0
J
jiyong_sd 已提交
950
   */
951
  it('SUB_USB_JS_0590', 0, function () {
J
jiyong_sd 已提交
952 953 954 955 956 957 958 959 960 961 962 963 964
    console.info('usb SUB_USB_JS_0590 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
965 966 967
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_INTERFACE,
      (usbManager.USB_REQUEST_DIR_FROM_DEVICE) | (usbManager.USB_REQUEST_TYPE_STANDARD << 5)
      | (usbManager.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0);
J
jiyong_sd 已提交
968 969 970 971
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature')
  })

  /**
972 973 974
   * @tc.number: SUB_USB_JS_0600
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, ClearFeature: cmd 255 target 2 reqType 34 value 512 index 0
J
jiyong_sd 已提交
975
   */
976
  it('SUB_USB_JS_0600', 0, function () {
J
jiyong_sd 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989
    console.info('usb SUB_USB_JS_0600 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }

    var timeout = 5000;
L
lixiaofeng_154b 已提交
990 991 992
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_ENDPOINT,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_CLASS << 5)
      | (usbManager.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0);
J
jiyong_sd 已提交
993 994 995 996
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature')
  })

  /**
997 998 999
   * @tc.number: SUB_USB_JS_0610
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, ClearFeature: cmd 255 target 3 reqType 67 value 512 index 0
J
jiyong_sd 已提交
1000
   */
1001
  it('SUB_USB_JS_0610', 0, function () {
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
    console.info('usb SUB_USB_JS_0610 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
J
jiyong_sd 已提交
1013

1014
    var timeout = 5000;
L
lixiaofeng_154b 已提交
1015 1016 1017
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_OTHER,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_VENDOR << 5)
      | (usbManager.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0);
1018 1019
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature')
  })
J
jiyong_sd 已提交
1020 1021

  /**
1022 1023 1024
   * @tc.number: SUB_USB_JS_0620
   * @tc.name: controlTransfer
   * @tc.desc: Positive test: control transfer, ClearFeature: cmd 255 target 3 reqType 35 value 0 index 0
J
jiyong_sd 已提交
1025
   */
1026
  it('SUB_USB_JS_0620', 0, function () {
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
    console.info('usb SUB_USB_JS_0620 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
J
jiyong_sd 已提交
1038

1039
    var timeout = 5000;
L
lixiaofeng_154b 已提交
1040 1041 1042
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_OTHER,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_CLASS << 5)
      | (usbManager.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0);
1043 1044
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature')
  })
J
jiyong_sd 已提交
1045

L
lixiaofeng_154b 已提交
1046
  function callControlTransferEx(pip, controlParam, timeout, caseName) {
L
lixiaofeng_154b 已提交
1047
    usbManager.controlTransfer(pip, controlParam, timeout).then(data => {
L
lixiaofeng_154b 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
      console.info('usb controlTransfer ret data : ' + data + ' ' + caseName);
      expect(false).assertTrue();
      console.info('usb' + caseName + ':  FAILED');
    }).catch(error => {
      console.info('usb controlTransfer error : ' + JSON.stringify(error));
      console.info('usb' + caseName + ':  FAILED');
      expect(false).assertTrue();
    });
    CheckEmptyUtils.sleep(3000);
  }

1059
  /**
1060 1061 1062
   * @tc.number: SUB_USB_JS_1140
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter number exception, input a parameter
1063
   */
1064
  it('SUB_USB_JS_1140', 0, function () {
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
    console.info('usb SUB_USB_JS_1140 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
    try {
L
lixiaofeng_154b 已提交
1077
      usbManager.controlTransfer("invalid").then(data => {
L
lixiaofeng_154b 已提交
1078 1079 1080 1081 1082 1083
        console.info('usb 1140 case controlTransfer ret data : ' + data);
        expect(false).assertTrue();
      }).catch(error => {
        console.info('usb 1140 case controlTransfer error : ' + JSON.stringify(error));
        expect(false).assertTrue();
      });
1084
    } catch (err) {
1085
      console.info('usb 1140 catch err code: ' + err.code + ' message: ' + err.message);
1086 1087 1088 1089
      expect(err.code).assertEqual(401);
      console.info('usb SUB_USB_JS_1140 :  PASS');
    }
  })
1090 1091

  /**
1092 1093 1094
   * @tc.number: SUB_USB_JS_1300
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter number exception, necessary parameters not input
1095
   */
1096
  it('SUB_USB_JS_1300', 0, function () {
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
    console.info('usb SUB_USB_JS_1300 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
    try {
L
lixiaofeng_154b 已提交
1109
      usbManager.controlTransfer().then(data => {
L
lixiaofeng_154b 已提交
1110 1111 1112 1113 1114 1115
        console.info('usb 1300 case controlTransfer ret data : ' + data);
        expect(false).assertTrue();
      }).catch(error => {
        console.info('usb 1300 case controlTransfer error : ' + JSON.stringify(error));
        expect(false).assertTrue();
      });
1116 1117 1118 1119 1120 1121
    } catch (err) {
      console.info('usb 1300 catch err code: ' + err.code + ' message: ' + err.message);
      expect(err.code).assertEqual(401);
      console.info('usb SUB_USB_JS_1300 :  PASS');
    }
  })
1122 1123 1124 1125 1126 1127

  /**
   * @tc.number: SUB_USB_JS_1440
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter pipe type error
   */
H
huyong 已提交
1128
  it('SUB_USB_JS_1440', 0, function () {
1129 1130 1131 1132 1133 1134
    console.info('usb SUB_USB_JS_1440 begin');
    if (portCurrentMode == 1) {
      console.info('usb case get_device port is device')
      expect(false).assertFalse();
      return
    }
L
lixiaofeng_154b 已提交
1135
    var testParam = getTransferTestParam();
1136 1137 1138 1139 1140 1141
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
    var testParamPip = "invalid";
    var timeout = 5000;
L
lixiaofeng_154b 已提交
1142 1143 1144
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_OTHER,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_CLASS << 5)
      | (usbManager.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0);
1145
    try {
L
lixiaofeng_154b 已提交
1146
      callControlTransferEx(testParamPip, controlParam, timeout, 'SUB_USB_JS_1440 ClearFeature');
1147 1148 1149 1150 1151 1152
    } catch (err) {
      console.info('usb 1440 catch err code: ' + err.code + ' message: ' + err.message);
      expect(err.code).assertEqual(401);
      console.info('usb SUB_USB_JS_1440 :  PASS');
    }
  })
L
lixiaofeng_154b 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181

  /**
   * @tc.number: SUB_USB_JS_1560
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer,
   * parameter contrlparam type error(The controlParam should have the data property)
   */
  it('SUB_USB_JS_1560', 0, function () {
    console.info('usb SUB_USB_JS_1560 begin');
    if (portCurrentMode == 1) {
      console.info('usb 1560 case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
    var controlParam = "invalid";
    var timeout = 5000;
    try {
      callControlTransferEx(testParam.pip, controlParam, timeout, 'SUB_USB_JS_1560 ClearFeature');
    } catch (err) {
      console.info('usb 1560 catch err code: ' + err.code + ' message: ' + err.message);
      expect(err.code).assertEqual(401);
      console.info('usb SUB_USB_JS_1560 :  PASS');
    }
  })
L
lixiaofeng_154b 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200

  /**
   * @tc.number: SUB_USB_JS_1570
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter timeout type error
   */
  it('SUB_USB_JS_1570', 0, function () {
    console.info('usb SUB_USB_JS_1570 begin');
    if (portCurrentMode == 1) {
      console.info('usb 1570 case get_device port is device')
      expect(false).assertFalse();
      return
    }
    var testParam = getTransferTestParam()
    if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) {
      expect(false).assertTrue();
      return
    }
    var timeout = "invalid";
L
lixiaofeng_154b 已提交
1201 1202 1203
    var controlParam = getTransferParam(255, usbManager.USB_REQUEST_TARGET_OTHER,
      (usbManager.USB_REQUEST_DIR_TO_DEVICE) | (usbManager.USB_REQUEST_TYPE_CLASS << 5)
      | (usbManager.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0);
H
huyong 已提交
1204
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_1570 ClearFeature');
L
lixiaofeng_154b 已提交
1205
  })
J
jiyong_sd 已提交
1206 1207
})
}