UsbDevicePipeJsunit.test.js 26.4 KB
Newer Older
J
jiyong_sd 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * 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.
 */

import usb from '@ohos.usb';
import CheckEmptyUtils from './CheckEmptyUtils.js';
import EventConstants from './EventConstants.js';
import parameter from '@ohos.systemparameter';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'

/* 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*************');
    var Version = usb.getVersion()
    console.info('usb unit begin test getversion :' + Version)
    // version > 17  host currentMode = 2 device currentMode = 1
    var usbPortList = usb.getPorts()
    gDeviceList = usb.getDevices();
    if (usbPortList.length > 0) {
      if (gDeviceList.length > 0) {
        if (usbPortList[0].status.currentMode == 1) {
          usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => {
            portCurrentMode = 2
            console.info('usb case setPortRoles return: ' + data);
          }).catch(error => {
            console.info('usb case setPortRoles error : ' + error);
          });
46
          CheckEmptyUtils.sleep(8000)
J
jiyong_sd 已提交
47 48 49 50 51 52 53
          console.log('*************Usb Unit switch to host Begin*************');
        }
      } else {
        portCurrentMode = 1
      }
    }

54 55 56 57
    gDeviceList = usb.getDevices();
    gDeviceList[0].name;
    gDeviceList[0].version;
    gDeviceList[0].configs;
J
jiyong_sd 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    gPipe = usb.connectDevice(gDeviceList[0])
    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 () {
    var isPipClose = usb.closePipe(gPipe)
    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];
79 80 81
      endpoint.number = 1;
      endpoint.type = 2;
      endpoint.interfaceid = 1;
J
jiyong_sd 已提交
82 83 84 85 86
      if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) {
        bfind = true
        if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) {
          testParam.maxOutSize = endpoint.maxPacketSize;
          testParam.outEndpoint = endpoint;
W
wu 已提交
87
        } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) {
J
jiyong_sd 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
          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 ||
      testParam.config.interfaces[j].subclass != 0 ||
      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
        }
      }
    }
  }

123
  // Prefabrication transmission related parameters
J
jiyong_sd 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  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
  }

  /**
150 151 152
   * @tc.number: SUB_USB_JS_0630
   * @tc.name: bulkTransfer
   * @tc.desc: Positive test: bulk transfer, receive data
J
jiyong_sd 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
   */
  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
    }

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

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

  /**
186 187 188
   * @tc.number: SUB_USB_JS_0640
   * @tc.name: bulkTransfer
   * @tc.desc: Positive test: bulk transfer, send data
J
jiyong_sd 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
   */
  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
    }

    testParam.isClaimed = usb.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 parameter ' + JSON.stringify(testParam.sendData));
    } catch (e) {
      console.log('usb parameter getSync unexpected error: ' + e);
    }

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

  /**
228 229 230
   * @tc.number: SUB_USB_JS_0420
   * @tc.name: claimInterface
   * @tc.desc: Positive test: Get interface, and release
J
jiyong_sd 已提交
231 232 233 234 235 236 237 238 239
   */
  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) {
240
      console.info('usb 0420 case get_device_list is null')
J
jiyong_sd 已提交
241 242 243 244 245
      expect(gDeviceList.length).assertEqual(-1);
      return
    }

    if (gDeviceList[0].configs.length == 0) {
246
      console.info('usb 0420 case current device.configs.length = 0');
J
jiyong_sd 已提交
247 248 249 250 251 252 253 254 255
      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++) {
256 257 258 259 260
        //Attribute Prefabrication
        var interfaces = gDeviceList[0].configs[j].interfaces[k];
		    interfaces.id = 1;
		    interfaces.name = '';
		    interfaces.alternateSetting = 0;
J
jiyong_sd 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true)
        console.info('usb case claimInterface function return: ' + isClaim);
        expect(isClaim).assertEqual(0);
        if (isClaim == 0) {
          isClaim = usb.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k])
          console.info('usb case releaseInterface function return: ' + isClaim);
          expect(isClaim).assertEqual(0);
          gPipe = usb.connectDevice(gDeviceList[0])
        }
      }
    }

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

276
  function getTransferParam(iCmd, iReqTarType, iReqType, iValue, iIndex) {
J
jiyong_sd 已提交
277 278
    var tmpUint8Array = new Uint8Array(512);
    var requestCmd = iCmd
279
    var requestTargetType = iReqTarType
J
jiyong_sd 已提交
280 281 282 283 284
    var requestType = iReqType
    var value = iValue;
    var index = iIndex;
    var controlParam = {
      request: requestCmd,
285
      target: requestTargetType,
J
jiyong_sd 已提交
286 287 288 289 290 291 292 293 294
      reqType: requestType,
      value: value,
      index: index,
      data: tmpUint8Array
    }
    return controlParam
  }

  /**
295 296 297
   * @tc.number: SUB_USB_JS_0740
   * @tc.name: setConfiguration
   * @tc.desc: Positive test: Set Device Configuration
J
jiyong_sd 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
   */
  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
    }

    gPipe = usb.connectDevice(gDeviceList[0])
    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
314 315 316 317 318 319
      var configs = gDeviceList[0].configs[j];
      configs.id = 1;
      configs.name = '';
      configs.maxPower = 1;
      configs.isRemoteWakeup = true;
      configs.isSelfPowered = true;
J
jiyong_sd 已提交
320 321 322 323 324 325 326 327 328
      var ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j])
      console.info('usb case setConfiguration return : ' + ret);
      expect(ret).assertEqual(0);
    }

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

  /**
329 330 331
   * @tc.number: SUB_USB_JS_0750
   * @tc.name: setConfiguration
   * @tc.desc: Negative test: Set Device Configuration
J
jiyong_sd 已提交
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 357
   */
  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
      var ret = usb.setConfiguration(gPipe, config)
      console.info('usb case setConfiguration return : ' + ret);
      expect(ret).assertLess(0);
    }

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

  /**
358 359 360
   * @tc.number: SUB_USB_JS_0800
   * @tc.name: setInterface
   * @tc.desc: Positive test: Set device interface
J
jiyong_sd 已提交
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
   */
  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++) {
      var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
      expect(isClaim).assertEqual(0)
      if (isClaim == 0) {
        var ret = usb.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0])
        console.info('usb case setInterface return : ' + ret);
381
        expect(ret).assertEqual(0);
J
jiyong_sd 已提交
382 383 384 385 386 387 388
      }
    }

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

  /**
389 390 391
   * @tc.number: SUB_USB_JS_0810
   * @tc.name: setInterface
   * @tc.desc: Negative test: Set device interface, error tmpInterface.id
J
jiyong_sd 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
   */
  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++) {
      var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
      expect(isClaim).assertEqual(0)
      if (isClaim == 0) {
        var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0]));
        tmpInterface.id = 234
        var ret = usb.setInterface(gPipe, tmpInterface)
        console.info('usb case setInterface return : ' + ret)
414
        expect(ret).assertLess(0)
J
jiyong_sd 已提交
415 416 417 418 419 420 421 422 423 424
      }
    }

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

  function callControlTransfer(pip, controlParam, timeout, caseName) {
    usb.controlTransfer(pip, controlParam, timeout).then(data => {
      console.info('usb controlTransfer ret data : ' + data + ' ' + caseName);
      console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName);
425
      expect(data >= 0).assertTrue();
J
jiyong_sd 已提交
426 427 428
      console.info('usb' + caseName + ':  PASS');
    }).catch(error => {
      console.info('usb controlTransfer error : ' + JSON.stringify(error));
429
      console.info('usb' + caseName + ':  FAILED');
J
jiyong_sd 已提交
430 431
      expect(false).assertTrue();
    });
432
    CheckEmptyUtils.sleep(3000);
J
jiyong_sd 已提交
433 434 435
  }

  /**
436 437 438
   * @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 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
   */
  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;
W
wu 已提交
454
    var controlParam = getTransferParam(6, usb.USB_REQUEST_TARGET_DEVICE, (usb.USB_REQUEST_DIR_FROM_DEVICE)
J
jiyong_sd 已提交
455 456 457 458 459
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor')
  })

  /**
460 461 462
   * @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 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
   */
  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;
W
wu 已提交
478
    var controlParam = getTransferParam(0, usb.USB_REQUEST_TARGET_DEVICE, (usb.USB_REQUEST_DIR_FROM_DEVICE)
J
jiyong_sd 已提交
479 480 481 482 483
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus')
  })

  /**
484 485 486
   * @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 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
   */
  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;
W
wu 已提交
502
    var controlParam = getTransferParam(8, usb.USB_REQUEST_TARGET_DEVICE, (usb.USB_REQUEST_DIR_FROM_DEVICE)
J
jiyong_sd 已提交
503 504 505 506 507
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration')
  })

  /**
508 509 510
   * @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 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
   */
  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;
W
wu 已提交
526
    var controlParam = getTransferParam(10, usb.USB_REQUEST_TARGET_INTERFACE, (usb.USB_REQUEST_DIR_FROM_DEVICE)
J
jiyong_sd 已提交
527 528 529 530 531
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface')
  })

  /**
532 533 534
   * @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 已提交
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
   */
  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;
W
wu 已提交
550
    var controlParam = getTransferParam(1, usb.USB_REQUEST_TARGET_DEVICE, (usb.USB_REQUEST_DIR_TO_DEVICE)
J
jiyong_sd 已提交
551 552 553 554 555
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature')
  })

  /**
556 557 558
   * @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 已提交
559
   */
560
  it('SUB_USB_JS_0590', 0, function () {
J
jiyong_sd 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573
    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;
W
wu 已提交
574
    var controlParam = getTransferParam(255, usb.USB_REQUEST_TARGET_INTERFACE, (usb.USB_REQUEST_DIR_FROM_DEVICE)
J
jiyong_sd 已提交
575 576 577 578 579
        | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature')
  })

  /**
580 581 582
   * @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 已提交
583
   */
584
  it('SUB_USB_JS_0600', 0, function () {
J
jiyong_sd 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597
    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;
W
wu 已提交
598
    var controlParam = getTransferParam(255, usb.USB_REQUEST_TARGET_ENDPOINT, (usb.USB_REQUEST_DIR_TO_DEVICE)
J
jiyong_sd 已提交
599 600 601 602 603
        | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature')
  })

  /**
604 605 606
   * @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 已提交
607
   */
608
  it('SUB_USB_JS_0610', 0, function () {
609 610 611 612 613 614 615 616 617 618 619
    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 已提交
620

621
    var timeout = 5000;
W
wu 已提交
622
    var controlParam = getTransferParam(255, usb.USB_REQUEST_TARGET_OTHER, (usb.USB_REQUEST_DIR_TO_DEVICE)
623 624 625
        | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature')
  })
J
jiyong_sd 已提交
626 627

  /**
628 629 630
   * @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 已提交
631
   */
632
  it('SUB_USB_JS_0620', 0, function () {
633 634 635 636 637 638 639 640 641 642 643
    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 已提交
644

645
    var timeout = 5000;
W
wu 已提交
646
    var controlParam = getTransferParam(255, usb.USB_REQUEST_TARGET_OTHER, (usb.USB_REQUEST_DIR_TO_DEVICE)
647 648 649
        | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0)
    callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature')
  })
J
jiyong_sd 已提交
650

651
  /**
652 653 654
   * @tc.number: SUB_USB_JS_1140
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter number exception, input a parameter
655
   */
656
  it('SUB_USB_JS_1140', 0, function () {
657 658 659 660 661 662 663 664 665 666 667 668 669
    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 {
      var maskCode = usb.controlTransfer("invalid");
670
      console.info('usb 1140 case controlTransfer return: ' + maskCode);
671 672
      expect(false).assertTrue();
    } catch (err) {
673
      console.info('usb 1140 catch err code: ' + err.code + ' message: ' + err.message);
674 675 676 677
      expect(err.code).assertEqual(401);
      console.info('usb SUB_USB_JS_1140 :  PASS');
    }
  })
678 679

  /**
680 681 682
   * @tc.number: SUB_USB_JS_1300
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter number exception, necessary parameters not input
683
   */
684
  it('SUB_USB_JS_1300', 0, function () {
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
    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 {
      var maskCode = usb.controlTransfer();
      console.info('usb 1300 case controlTransfer return: ' + maskCode);
      expect(false).assertTrue();
    } 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');
    }
  })
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737

  /**
   * @tc.number: SUB_USB_JS_1440
   * @tc.name: controlTransfer
   * @tc.desc: Negative test: control transfer, parameter pipe type error
   */
   it('SUB_USB_JS_1440', 0, function () {
    console.info('usb SUB_USB_JS_1440 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 testParamPip = "invalid";
    var timeout = 5000;
    var controlParam = getTransferParam(255, usb.USB_REQUEST_TARGET_OTHER, (usb.USB_REQUEST_DIR_TO_DEVICE)
        | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0);
    try {
      var maskCode = usb.controlTransfer(testParamPip, controlParam, timeout);
      console.info('usb 1440 case controlTransfer return: ' + maskCode);
      expect(false).assertTrue();
    } 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');
    }
  })
J
jiyong_sd 已提交
738 739
})
}