• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import usb from '@ohos.usb';
17import CheckEmptyUtils from './CheckEmptyUtils.js';
18import EventConstants from './EventConstants.js';
19import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
20
21/* usb device pipe test */
22describe('UsbDevicePipeJsFunctionsTestEx', function () {
23  var gDeviceList
24  var gPipe
25
26  beforeAll(function () {
27    console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx Begin*************');
28    var Version = usb.getVersion()
29    console.info('usb unit begin test getversion :' + Version)
30
31    // version > 17  host currentMode = 2 device currentMode = 1
32    var usbPortList = usb.getPorts()
33    if (usbPortList.length > 0) {
34      if (usbPortList[0].status.currentMode == 1) {
35        usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => {
36          console.info('usb case setPortRoles  return: ' + data);
37        }).catch(error => {
38          console.info('usb case setPortRoles  error : ' + error);
39        });
40
41        console.log('*************Usb Unit switch to host Ex Begin*************');
42        CheckEmptyUtils.sleep(3000)
43      }
44    }
45
46    gDeviceList = usb.getDevices();
47    gPipe = usb.connectDevice(gDeviceList[0])
48    console.info('usb unit connectDevice  gPipe ret : ' + JSON.stringify(gPipe));
49  })
50  beforeEach(function () {
51    console.info('beforeEach: *************Usb Unit Test Ex Case*************');
52  })
53  afterEach(function () {
54    console.info('afterEach: *************Usb Unit Test Ex Case*************');
55  })
56  afterAll(function () {
57    var isPipClose = usb.closePipe(gPipe)
58    console.info('usb unit close gPipe ret : ' + isPipClose);
59    console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx End*************');
60  })
61
62  function findInitPoint(testParam, j) {
63    var bfind = false
64    for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) {
65      var endpoint = testParam.config.interfaces[j].endpoints[k];
66      if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) {
67
68        bfind = true
69        if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) {
70          testParam.outEndpoint = endpoint;
71          testParam.maxOutSize = endpoint.maxPacketSize;
72        } else if (endpoint.direction == (usb.USB_REQUEST_DIR_FROM_DEVICE)) {
73          testParam.inEndpoint = endpoint
74          testParam.maxInSize = endpoint.maxPacketSize;
75        }
76      }
77    }
78    if (bfind) {
79      testParam.interface = testParam.config.interfaces[j]
80      return true
81    }
82    return false
83  }
84
85  function getFlag(testParam, j) {
86    if (testParam.config.interfaces[j].clazz != 10 ||
87      testParam.config.interfaces[j].subclass != 0 ||
88      testParam.config.interfaces[j].protocol != 2) {
89      return false
90    }
91
92    if (testParam.config.interfaces[j].endpoints.length == 0) {
93      return false
94    }
95
96    return true
97  }
98
99  function initPoint(testParam) {
100    for (var j = 0; j < testParam.config.interfaces.length; j++) {
101      if (getFlag(testParam, j)) {
102        if (findInitPoint(testParam, j)) {
103          break
104        }
105      }
106    }
107  }
108
109  // 预制传输相关参数
110  function getTransferTestParam() {
111    var testParam = {
112      device: null,
113      config: null,
114      pip: null,
115      inEndpoint: null,
116      outEndpoint: null,
117      interface: null,
118      usbRequest: null,
119      sendData: '',
120      isClaimed: 0,
121      maxInSize: 1024,
122      maxOutSize: 1024
123    }
124
125    console.info('usb case gDeviceList.length: ' + gDeviceList.length);
126    for (var i = 0; i < gDeviceList.length; i++) {
127      testParam.device = gDeviceList[i]
128      testParam.config = testParam.device.configs[0]
129      testParam.pip = gPipe
130      initPoint(testParam)
131    }
132    return testParam
133  }
134
135  /**
136   * @tc.number    : SUB_USB_bulk_transfer_test_03
137   * @tc.name      : bulkTransfer
138   * @tc.desc      : 反向测试 批量传输 发数据 修改 outEndpoint.address = 123
139   */
140  it('SUB_USB_bulk_transfer_test_03', 0, function () {
141    console.info('usb bulk_transfer_test_03 begin');
142    var testParam = getTransferTestParam()
143    if (testParam.interface == null || testParam.outEndpoint == null) {
144      expect(false).assertTrue();
145      return
146    }
147
148    testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true);
149    expect(testParam.isClaimed).assertEqual(0);
150
151    testParam.sendData = 'send time 13213213 wzy 03';
152    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
153    var TmpTestParam = testParam
154    TmpTestParam.outEndpoint.address = 123
155    usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => {
156      console.info('usb case bulk_transfer_test_03 ret: ' + data);
157      console.info('usb case bulk_transfer_test_03 :  PASS');
158      expect(data).assertEqual(-1);
159    }).catch(error => {
160      console.info('usb 03 write error : ' + JSON.stringify(error));
161      expect(false).assertFalse();
162      console.info('usb case bulk_transfer_test_03 :  PASS');
163    });
164  })
165
166  /**
167   * @tc.number    : SUB_USB_bulk_transfer_test_04
168   * @tc.name      : bulkTransfer
169   * @tc.desc      : 反向测试 批量传输 发数据 修改 outEndpoint.number = 123
170   */
171  it('SUB_USB_bulk_transfer_test_04', 0, function () {
172    console.info('usb bulk_transfer_test_04 begin');
173    var testParam = getTransferTestParam()
174    if (testParam.interface == null || testParam.outEndpoint == null) {
175      expect(false).assertTrue();
176      return
177    }
178
179    testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true);
180    expect(testParam.isClaimed).assertEqual(0);
181
182    testParam.sendData = 'send time 13213213 wzy  04';
183    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
184    var TmpTestParam = testParam
185    TmpTestParam.outEndpoint.number = 123
186    usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => {
187      console.info('usb case bulk_transfer_test_04 ret: ' + data);
188      console.info('usb case bulk_transfer_test_04 :  PASS');
189      expect(data).assertEqual(-1);
190    }).catch(error => {
191      console.info('usb 04 write error : ' + JSON.stringify(error));
192      expect(false).assertFalse();
193      console.info('usb case bulk_transfer_test_04 :  PASS');
194    });
195  })
196
197  /**
198   * @tc.number    : SUB_USB_bulk_transfer_test_05
199   * @tc.name      : bulkTransfer
200   * @tc.desc      : 反向测试 批量传输 发数据 修改 outEndpoint.type = 123
201   */
202  it('SUB_USB_bulk_transfer_test_05', 0, function () {
203    console.info('usb bulk_transfer_test_05 begin');
204    var testParam = getTransferTestParam()
205    if (testParam.interface == null || testParam.outEndpoint == null) {
206      expect(false).assertTrue();
207      return
208    }
209
210    testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true);
211    expect(testParam.isClaimed).assertEqual(0);
212
213    testParam.sendData = 'send time 13213213 wzy 05';
214    var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData);
215    var TmpTestParam = testParam
216    TmpTestParam.outEndpoint.type = 123
217    usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => {
218      console.info('usb case bulk_transfer_test_05 ret: ' + data);
219      console.info('usb case bulk_transfer_test_05 :  PASS');
220      expect(data).assertEqual(-1);
221    }).catch(error => {
222      console.info('usb 05 write error : ' + JSON.stringify(error));
223      expect(false).assertFalse();
224      console.info('usb case bulk_transfer_test_05 :  PASS');
225    });
226  })
227
228  /**
229   * @tc.number    : SUB_USB_claim_interface_test_02
230   * @tc.name      : claimInterface
231   * @tc.desc      : 反向测试 USBInterface传入异常id 获取接口 失败
232   */
233  it('SUB_USB_claim_interface_test_02', 0, function () {
234    console.info('usb claim_interface_test_02 begin');
235    if (gDeviceList.length == 0) {
236      console.info('usb case get_device_list is null')
237      expect(false).assertTrue();
238      return
239    }
240
241    if (gDeviceList[0].configs.length == 0) {
242      console.info('usb case 02 current device.configs.length = 0');
243      expect(false).assertTrue();
244      return
245    }
246
247    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
248      if (gDeviceList[0].configs[j].interfaces.length == 0) {
249        console.info('usb case 02 current device.configs.interfaces.length = 0');
250      }
251      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
252        var TmpInterface = gDeviceList[0].configs[j].interfaces[k]
253        TmpInterface.id = 123
254        var isClaim = usb.claimInterface(gPipe, TmpInterface, true)
255        console.info('usb case claimInterface function return: ' + isClaim);
256        expect(isClaim).assertLess(0);
257      }
258    }
259
260    console.info('usb claim_interface_test_02 :  PASS');
261    expect(true).assertTrue();
262  })
263
264  /**
265   * @tc.number    : SUB_USB_claim_interface_test_03
266   * @tc.name      : claimInterface
267   * @tc.desc      : 反向测试 USBInterface传入异常protocol 获取接口 失败
268   */
269  it('SUB_USB_claim_interface_test_03', 0, function () {
270    console.info('usb claim_interface_test_03 begin');
271    if (gDeviceList.length == 0) {
272      console.info('usb case get_device_list is null')
273      expect(false).assertTrue();
274      return
275    }
276
277    if (gDeviceList[0].configs.length == 0) {
278      console.info('usb case 03 current device.configs.length = 0');
279      expect(false).assertTrue();
280      return
281    }
282
283    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
284      if (gDeviceList[0].configs[j].interfaces.length == 0) {
285        console.info('usb case 03 current device.configs.interfaces.length = 0');
286      }
287      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
288        var TmpInterface = gDeviceList[0].configs[j].interfaces[k]
289        TmpInterface.protocol = 120
290        var isClaim = usb.claimInterface(gPipe, TmpInterface, true)
291        console.info('usb case claimInterface function return: ' + isClaim);
292        expect(isClaim).assertLess(0);
293      }
294    }
295
296    console.info('usb claim_interface_test_03 :  PASS');
297    expect(true).assertTrue();
298  })
299
300  /**
301   * @tc.number    : SUB_USB_claim_interface_test_04
302   * @tc.name      : claimInterface
303   * @tc.desc      : 反向测试 USBInterface传入异常clazz 获取接口 失败
304   */
305  it('SUB_USB_claim_interface_test_04', 0, function () {
306    console.info('usb claim_interface_test_04 begin');
307    if (gDeviceList.length == 0) {
308      console.info('usb case get_device_list is null')
309      expect(false).assertTrue();
310      return
311    }
312
313    if (gDeviceList[0].configs.length == 0) {
314      console.info('usb case 04 current device.configs.length = 0');
315      expect(false).assertTrue();
316      return
317    }
318
319    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
320      if (gDeviceList[0].configs[j].interfaces.length == 0) {
321        console.info('usb case 04 current device.configs.interfaces.length = 0');
322      }
323      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
324        var TmpInterface = gDeviceList[0].configs[j].interfaces[k]
325        TmpInterface.clazz = 784
326        var isClaim = usb.claimInterface(gPipe, TmpInterface, true)
327        console.info('usb case claimInterface function return: ' + isClaim);
328        expect(isClaim).assertLess(0);
329      }
330    }
331
332    console.info('usb claim_interface_test_04 :  PASS');
333    expect(true).assertTrue();
334  })
335
336  /**
337   * @tc.number    : SUB_USB_claim_interface_test_05
338   * @tc.name      : claimInterface
339   * @tc.desc      : 反向测试 USBInterface传入异常name 获取接口 失败
340   */
341  it('SUB_USB_claim_interface_test_05', 0, function () {
342    console.info('usb claim_interface_test_05 begin');
343    if (gDeviceList.length == 0) {
344      console.info('usb case get_device_list is null')
345      expect(false).assertTrue();
346      return
347    }
348
349    if (gDeviceList[0].configs.length == 0) {
350      console.info('usb case 05 current device.configs.length = 0');
351      expect(false).assertTrue();
352      return
353    }
354
355    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
356      if (gDeviceList[0].configs[j].interfaces.length == 0) {
357        console.info('usb case 05 current device.configs.interfaces.length = 0');
358      }
359      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
360        var TmpInterface = gDeviceList[0].configs[j].interfaces[k]
361        TmpInterface.name = '123sdf'
362        var isClaim = usb.claimInterface(gPipe, TmpInterface, true)
363        console.info('usb case claimInterface function return: ' + isClaim);
364        expect(isClaim).assertLess(0);
365      }
366    }
367
368    console.info('usb claim_interface_test_05 :  PASS');
369    expect(true).assertTrue();
370  })
371
372  /**
373   * @tc.number    : SUB_USB_claim_interface_test_06
374   * @tc.name      : claimInterface
375   * @tc.desc      : 反向测试 USBInterface传入异常subClass 获取接口 失败
376   */
377  it('SUB_USB_claim_interface_test_06', 0, function () {
378    console.info('usb claim_interface_test_06 begin');
379    if (gDeviceList.length == 0) {
380      console.info('usb case get_device_list is null')
381      expect(false).assertTrue();
382      return
383    }
384
385    if (gDeviceList[0].configs.length == 0) {
386      console.info('usb case 06 current device.configs.length = 0');
387      expect(false).assertTrue();
388      return
389    }
390
391    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
392      if (gDeviceList[0].configs[j].interfaces.length == 0) {
393        console.info('usb case 06 current device.configs.interfaces.length = 0');
394      }
395      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
396        var TmpInterface = gDeviceList[0].configs[j].interfaces[k]
397        TmpInterface.subClass = 1210
398        var isClaim = usb.claimInterface(gPipe, TmpInterface, true)
399        console.info('usb case claimInterface function return: ' + isClaim);
400        expect(isClaim).assertLess(0);
401      }
402    }
403
404    console.info('usb claim_interface_test_06 :  PASS');
405    expect(true).assertTrue();
406  })
407
408  /**
409   * @tc.number    : SUB_USB_release_interface_test_01
410   * @tc.name      : releaseInterface
411   * @tc.desc      : 反向测试 获取接口 release传入Interface的错误ID 并释放
412   */
413  it('SUB_USB_release_interface_test_01', 0, function () {
414    console.info('usb release_interface_test_01 begin');
415    if (gDeviceList.length == 0) {
416      console.info('usb case get_device_list is null')
417      expect(false).assertTrue();
418      return
419    }
420
421    if (gDeviceList[0].configs.length == 0) {
422      console.info('usb 01 case current device.configs.length = 0');
423      expect(false).assertTrue();
424      return
425    }
426    gPipe = usb.connectDevice(gDeviceList[0])
427    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
428      if (gDeviceList[0].configs[j].interfaces.length == 0) {
429        console.info('usb 01 case current device.configs.interfaces.length = 0');
430      }
431      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
432        var tmpInterface = gDeviceList[0].configs[j].interfaces[k]
433        tmpInterface.id = 134
434        var isClaim = usb.releaseInterface(gPipe, tmpInterface)
435        console.info('usb case releaseInterface function return: ' + isClaim);
436        expect(isClaim).assertLess(0);
437      }
438    }
439
440    console.info('usb release_interface_test_01 :  PASS');
441    expect(true).assertTrue();
442  })
443
444  /**
445   * @tc.number    : SUB_USB_release_interface_test_02
446   * @tc.name      : releaseInterface
447   * @tc.desc      : 反向测试 获取接口 release传入Interface的错误name 并释放
448   */
449  it('SUB_USB_release_interface_test_02', 0, function () {
450    console.info('usb release_interface_test_02 begin');
451    if (gDeviceList.length == 0) {
452      console.info('usb case get_device_list is null')
453      expect(false).assertTrue();
454      return
455    }
456
457    if (gDeviceList[0].configs.length == 0) {
458      console.info('usb 02 case current device.configs.length = 0');
459      expect(false).assertTrue();
460      return
461    }
462    gPipe = usb.connectDevice(gDeviceList[0])
463    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
464      if (gDeviceList[0].configs[j].interfaces.length == 0) {
465        console.info('usb 02 case current device.configs.interfaces.length = 0');
466      }
467      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
468        var tmpInterface = gDeviceList[0].configs[j].interfaces[k]
469        tmpInterface.name = '134wer'
470        var isClaim = usb.releaseInterface(gPipe, tmpInterface)
471        console.info('usb case releaseInterface function return: ' + isClaim);
472        expect(isClaim).assertLess(0);
473      }
474    }
475
476    console.info('usb release_interface_test_02 :  PASS');
477    expect(true).assertTrue();
478  })
479
480  /**
481   * @tc.number    : SUB_USB_release_interface_test_03
482   * @tc.name      : releaseInterface
483   * @tc.desc      : 反向测试 获取接口 release传入Interface的错误clazz 并释放
484   */
485  it('SUB_USB_release_interface_test_03', 0, function () {
486    console.info('usb release_interface_test_03 begin');
487    if (gDeviceList.length == 0) {
488      console.info('usb case get_device_list is null')
489      expect(false).assertTrue();
490      return
491    }
492
493    if (gDeviceList[0].configs.length == 0) {
494      console.info('usb 03 case current device.configs.length = 0');
495      expect(false).assertTrue();
496      return
497    }
498    gPipe = usb.connectDevice(gDeviceList[0])
499    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
500      if (gDeviceList[0].configs[j].interfaces.length == 0) {
501        console.info('usb 03 case current device.configs.interfaces.length = 0');
502      }
503      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
504        var tmpInterface = gDeviceList[0].configs[j].interfaces[k]
505        tmpInterface.clazz = 78
506        var isClaim = usb.releaseInterface(gPipe, tmpInterface)
507        console.info('usb case releaseInterface function return: ' + isClaim);
508        expect(isClaim).assertLess(0);
509      }
510    }
511
512    console.info('usb release_interface_test_03 :  PASS');
513    expect(true).assertTrue();
514  })
515
516  /**
517   * @tc.number    : SUB_USB_release_interface_test_04
518   * @tc.name      : releaseInterface
519   * @tc.desc      : 反向测试 获取接口 release传入Interface的错误protocol 并释放
520   */
521  it('SUB_USB_release_interface_test_04', 0, function () {
522    console.info('usb release_interface_test_04 begin');
523    if (gDeviceList.length == 0) {
524      console.info('usb case get_device_list is null')
525      expect(false).assertTrue();
526      return
527    }
528
529    if (gDeviceList[0].configs.length == 0) {
530      console.info('usb 04 case current device.configs.length = 0');
531      expect(false).assertTrue();
532      return
533    }
534    gPipe = usb.connectDevice(gDeviceList[0])
535    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
536      if (gDeviceList[0].configs[j].interfaces.length == 0) {
537        console.info('usb 04 case current device.configs.interfaces.length = 0');
538      }
539      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
540        var tmpInterface = gDeviceList[0].configs[j].interfaces[k]
541        tmpInterface.protocol = 124
542        var isClaim = usb.releaseInterface(gPipe, tmpInterface)
543        console.info('usb case releaseInterface function return: ' + isClaim);
544        expect(isClaim).assertLess(0);
545      }
546    }
547
548    console.info('usb release_interface_test_04 :  PASS');
549    expect(true).assertTrue();
550  })
551
552  /**
553   * @tc.number    : SUB_USB_release_interface_test_05
554   * @tc.name      : releaseInterface
555   * @tc.desc      : 反向测试 获取接口 release传入Interface的错误subClass 并释放
556   */
557  it('SUB_USB_release_interface_test_05', 0, function () {
558    console.info('usb release_interface_test_05 begin');
559    if (gDeviceList.length == 0) {
560      console.info('usb case get_device_list is null')
561      expect(false).assertTrue();
562      return
563    }
564
565    if (gDeviceList[0].configs.length == 0) {
566      console.info('usb 05 case current device.configs.length = 0');
567      expect(false).assertTrue();
568      return
569    }
570    gPipe = usb.connectDevice(gDeviceList[0])
571    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
572      if (gDeviceList[0].configs[j].interfaces.length == 0) {
573        console.info('usb 05 case current device.configs.interfaces.length = 0');
574      }
575      for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) {
576        var tmpInterface = gDeviceList[0].configs[j].interfaces[k]
577        tmpInterface.subClass = 784
578        var isClaim = usb.releaseInterface(gPipe, tmpInterface)
579        console.info('usb case releaseInterface function return: ' + isClaim);
580        expect(isClaim).assertLess(0);
581      }
582    }
583
584    console.info('usb release_interface_test_05 :  PASS');
585    expect(true).assertTrue();
586  })
587
588  /**
589   * @tc.number    : SUB_USB_set_interface_test_03
590   * @tc.name      : setInterface
591   * @tc.desc      : 反向测试 Interface的protocol 设置设备接口
592   */
593  it('SUB_USB_set_interface_test_03', 0, function () {
594    console.info('usb set_interface_test_03 begin');
595    if (gDeviceList.length == 0) {
596      console.info('usb case get_device_list is null')
597      expect(false).assertTrue()
598      return
599    }
600    gPipe = usb.connectDevice(gDeviceList[0])
601    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
602      var isClaimed = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true);
603
604      var tmpInterface = gDeviceList[0].configs[j].interfaces[0]
605      tmpInterface.protocol = 482
606      var ret = usb.setInterface(gPipe, tmpInterface)
607      expect(ret).assertLess(0)
608      console.info('usb case setInterface return : ' + ret)
609    }
610
611    console.info('usb set_interface_test_03 :  PASS');
612    expect(true).assertTrue();
613  })
614
615  /**
616   * @tc.number    : SUB_USB_set_interface_test_04
617   * @tc.name      : setInterface
618   * @tc.desc      : 反向测试 Interface的clazz 设置设备接口
619   */
620  it('SUB_USB_set_interface_test_04', 0, function () {
621    console.info('usb set_interface_test_04 begin');
622    if (gDeviceList.length == 0) {
623      console.info('usb case get_device_list is null')
624      expect(false).assertTrue()
625      return
626    }
627    gPipe = usb.connectDevice(gDeviceList[0])
628    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
629      var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
630
631      var tmpInterface = gDeviceList[0].configs[j].interfaces[0]
632      tmpInterface.clazz = 482
633      var ret = usb.setInterface(gPipe, tmpInterface)
634      expect(ret).assertLess(0)
635      console.info('usb case setInterface return : ' + ret)
636
637    }
638
639    console.info('usb set_interface_test_04 :  PASS');
640    expect(true).assertTrue();
641  })
642
643  /**
644   * @tc.number    : SUB_USB_set_interface_test_05
645   * @tc.name      : setInterface
646   * @tc.desc      : 反向测试 Interface的subClass 设置设备接口
647   */
648  it('SUB_USB_set_interface_test_05', 0, function () {
649    console.info('usb set_interface_test_05 begin');
650    if (gDeviceList.length == 0) {
651      console.info('usb case get_device_list is null')
652      expect(false).assertTrue()
653      return
654    }
655    gPipe = usb.connectDevice(gDeviceList[0])
656    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
657      var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
658
659      var tmpInterface = gDeviceList[0].configs[j].interfaces[0]
660      tmpInterface.subClass = 482
661      var ret = usb.setInterface(gPipe, tmpInterface)
662      expect(ret).assertLess(0)
663      console.info('usb case setInterface return : ' + ret)
664
665    }
666
667    console.info('usb set_interface_test_05 :  PASS');
668    expect(true).assertTrue();
669  })
670
671  /**
672   * @tc.number    : SUB_USB_set_interface_test_06
673   * @tc.name      : setInterface
674   * @tc.desc      : 反向测试 Interface的name 设置设备接口
675   */
676  it('SUB_USB_set_interface_test_06', 0, function () {
677    console.info('usb set_interface_test_05 begin');
678    if (gDeviceList.length == 0) {
679      console.info('usb case get_device_list is null')
680      expect(false).assertTrue()
681      return
682    }
683    gPipe = usb.connectDevice(gDeviceList[0])
684    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
685      var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true)
686
687      var tmpInterface = gDeviceList[0].configs[j].interfaces[0]
688      tmpInterface.name = 'wer32'
689      var ret = usb.setInterface(gPipe, tmpInterface)
690      expect(ret).assertLess(0)
691      console.info('usb case setInterface return : ' + ret)
692    }
693
694    console.info('usb set_interface_test_06 :  PASS');
695    expect(true).assertTrue();
696  })
697
698  /**
699   * @tc.number    : SUB_USB_set_configuration_test_03
700   * @tc.name      : setConfiguration
701   * @tc.desc      : 反向测试 USBConfig的name 赋值错误 设置设备接口
702   */
703  it('SUB_USB_set_configuration_test_03', 0, function () {
704    console.info('usb set_configuration_test_03 begin');
705    if (gDeviceList.length == 0) {
706      console.info('usb case get_device_list is null')
707      expect(false).assertTrue();
708      return
709    }
710    gPipe = usb.connectDevice(gDeviceList[0])
711    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
712      var config = gDeviceList[0].configs[j]
713      config.name = 'asdfsd'
714      var ret = usb.setConfiguration(gPipe, config)
715      console.info('usb case setConfiguration return : ' + ret);
716      expect(ret).assertEqual(0);
717    }
718
719    console.info('usb set_configuration_test_03 :  PASS');
720  })
721
722  /**
723   * @tc.number    : SUB_USB_set_configuration_test_04
724   * @tc.name      : setConfiguration
725   * @tc.desc      : 反向测试 USBConfig的name 赋值错误 设置设备接口
726   */
727  it('SUB_USB_set_configuration_test_04', 0, function () {
728    console.info('usb set_configuration_test_04 begin');
729    if (gDeviceList.length == 0) {
730      console.info('usb case get_device_list is null')
731      expect(false).assertTrue();
732      return
733    }
734
735    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
736      var config = gDeviceList[0].configs[j]
737      config.name = 'asdfsd'
738      config.id = 154
739      var ret = usb.setConfiguration(gPipe, config)
740      console.info('usb case setConfiguration return : ' + ret);
741      expect(ret).assertLess(0);
742    }
743
744    console.info('usb set_configuration_test_04 :  PASS');
745  })
746
747  /**
748   * @tc.number    : SUB_USB_set_configuration_test_05
749   * @tc.name      : setConfiguration
750   * @tc.desc      : 反向测试 USBConfig的attributes 赋值错误 设置设备接口
751   */
752  it('SUB_USB_set_configuration_test_05', 0, function () {
753    console.info('usb set_configuration_test_05 begin');
754    if (gDeviceList.length == 0) {
755      console.info('usb case get_device_list is null')
756      expect(false).assertTrue();
757      return
758    }
759
760    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
761      var config = gDeviceList[0].configs[j]
762      config.attributes = 154
763      var ret = usb.setConfiguration(gPipe, config)
764      console.info('usb case setConfiguration return : ' + ret);
765      expect(ret).assertLess(0);
766    }
767
768    console.info('usb set_configuration_test_05 :  PASS');
769  })
770
771/**
772   * @tc.number    : SUB_USB_set_configuration_test_06
773   * @tc.name      : setConfiguration
774   * @tc.desc      : 反向测试 USBConfig的name interval(1-16) 赋值错误 设置设备接口
775   */
776   it('SUB_USB_set_configuration_test_06', 0, function () {
777    console.info('usb set_configuration_test_06 begin');
778    if (gDeviceList.length == 0) {
779      console.info('usb case get_device_list is null')
780      expect(false).assertTrue();
781      return
782    }
783
784    for (var j = 0; j < gDeviceList[0].configs.length; j++) {
785      var config = gDeviceList[0].configs[j]
786      config.name = 'asdfsd'
787      config.interfaces[0].endpoints[0].interval = 0
788      var ret = usb.setConfiguration(gPipe, config)
789      console.info('usb case setConfiguration return : ' + ret);
790      expect(ret).assertLess(0);
791    }
792
793    console.info('usb set_configuration_test_06 :  PASS');
794  })
795})
796