diff --git a/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js index 0ecf7518f3f16c959ed1a71fbbc7f66512fcef46..a498ec0ec7a4bd8410d5fb43d8700f23e1f9c3b8 100644 --- a/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js @@ -648,6 +648,19 @@ describe('UsbDevicePipeJsFunctionsTest', function () { callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature') }) + function callControlTransferEx(pip, controlParam, timeout, caseName) { + usb.controlTransfer(pip, controlParam, timeout).then(data => { + 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); + } + /** * @tc.number: SUB_USB_JS_1140 * @tc.name: controlTransfer @@ -666,9 +679,13 @@ describe('UsbDevicePipeJsFunctionsTest', function () { return } try { - var maskCode = usb.controlTransfer("invalid"); - console.info('usb 1140 case controlTransfer return: ' + maskCode); - expect(false).assertTrue(); + usb.controlTransfer("invalid").then(data => { + 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(); + }); } catch (err) { console.info('usb 1140 catch err code: ' + err.code + ' message: ' + err.message); expect(err.code).assertEqual(401); @@ -694,7 +711,13 @@ describe('UsbDevicePipeJsFunctionsTest', function () { return } try { - var maskCode = usb.controlTransfer(); + usb.controlTransfer().then(data => { + 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(); + }); console.info('usb 1300 case controlTransfer return: ' + maskCode); expect(false).assertTrue(); } catch (err) { @@ -716,7 +739,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () { expect(false).assertFalse(); return } - var testParam = getTransferTestParam() + var testParam = getTransferTestParam(); if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { expect(false).assertTrue(); return @@ -726,14 +749,41 @@ describe('UsbDevicePipeJsFunctionsTest', function () { 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(); + callControlTransferEx(testParamPip, controlParam, timeout, 'SUB_USB_JS_1440 ClearFeature'); } 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'); } }) + + /** + * @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'); + } + }) }) } diff --git a/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js index 78470dd4993a16daef5ee4873833cb3296171554..c3ce499cd7159b3c2d41f4dcbbbb4348b919eadd 100644 --- a/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js @@ -1121,6 +1121,31 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { } }) + /** + * @tc.number: SUB_USB_JS_1580 + * @tc.name: releaseInterface + * @tc.desc: Negative test: release Interface, parameter iface type error + */ + it('SUB_USB_JS_1580', 0, function () { + console.info('usb SUB_USB_JS_1580 begin'); + if (portCurrentMode == 1) { + console.info('usb 1580 case get_device port is device') + expect(false).assertFalse(); + return + } + + var TmpInterface = "invalid"; + try { + var maskCode = usb.releaseInterface(gPipe, TmpInterface); + console.info('usb 1580 case releaseInterface return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1580 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1580 : PASS'); + } + }) + /** * @tc.number: SUB_USB_JS_0820 * @tc.name: setInterface @@ -1257,6 +1282,7 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { 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') @@ -1341,6 +1367,36 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { } }) + /** + * @tc.number: SUB_USB_JS_1550 + * @tc.name: setInterface + * @tc.desc: Negative test: Set device interface, parameter iface type error + */ + it('SUB_USB_JS_1550', 0, function () { + console.info('usb SUB_USB_JS_1550 begin'); + if (portCurrentMode == 1) { + console.info('usb case 1550 get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case 1550 get_device_list is null') + expect(false).assertTrue(); + return + } + + var TmpInterface = "invalid"; + try { + var maskCode = usb.setInterface(gPipe, TmpInterface); + console.info('usb 1550 case setInterface return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1550 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1550 : PASS'); + } + }) + /** * @tc.number: SUB_USB_JS_0760 * @tc.name: setConfiguration @@ -1537,15 +1593,10 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { try { 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_1470 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]; - var maskCode = usb.setConfiguration(testParamPip, TmpInterface); - console.info('usb 1470 case setConfiguration return: ' + maskCode); - expect(false).assertTrue(); - } + var TmpConfig = gDeviceList[0].configs[j]; + var maskCode = usb.setConfiguration(testParamPip, TmpConfig); + console.info('usb 1470 case setConfiguration return: ' + maskCode); + expect(false).assertTrue(); } } catch (err) { console.info('usb 1470 catch err code: ' + err.code + ' message: ' + err.message); @@ -1553,5 +1604,36 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { console.info('usb SUB_USB_JS_1470 : PASS'); } }) + + /** + * @tc.number: SUB_USB_JS_1540 + * @tc.name: setConfiguration + * @tc.desc: Negative test: Set Device Configuration, parameter pipe type error + */ + it('SUB_USB_JS_1540', 0, function () { + console.info('usb SUB_USB_JS_1540 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 + } + + var TmpConfig = "invalid"; + + try { + var maskCode = usb.setConfiguration(gPipe, TmpConfig); + console.info('usb 1540 case setConfiguration return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1540 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1540 : PASS'); + } + }) }) } diff --git a/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js index cc01812ea64ce51dc491a49c00326cbc09ccab23..d434b7b67533d5c58980c47408958b43217f5877 100644 --- a/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js @@ -223,7 +223,7 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number: SUB_USB_JS_1410 * @tc.name: setPortRoles - * @tc.desc: Negative test: parameter type exception + * @tc.desc: Negative test: parameter portId type exception */ it('SUB_USB_JS_1410', 0, function () { console.info('usb SUB_USB_JS_1410 begin'); @@ -277,6 +277,68 @@ describe('UsbPortJsFunctionsTestEx', function () { } }) + /** + * @tc.number: SUB_USB_JS_1590 + * @tc.name: setPortRoles + * @tc.desc: Negative test: parameter number exception, parameter powerRole type exception + */ + it('SUB_USB_JS_1590', 0, function () { + console.info('usb SUB_USB_JS_1590 begin'); + var portId = gPort.id; + var powerRole = "invalid"; + var dataRole = usb.DEVICE; + try { + var maskCode = usb.setPortRoles(portId, powerRole, dataRole); + console.info('usb 1590 case setPortRoles return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1590 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1590 : PASS'); + } + }) + + /** + * @tc.number: SUB_USB_JS_1600 + * @tc.name: setPortRoles + * @tc.desc: Negative test: parameter number exception, parameter dataRole type exception + */ + it('SUB_USB_JS_1600', 0, function () { + console.info('usb SUB_USB_JS_1600 begin'); + var portId = gPort.id; + var powerRole = usb.SINK; + var dataRole = "invalid"; + try { + var maskCode = usb.setPortRoles(portId, powerRole, dataRole); + console.info('usb 1600 case setPortRoles return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1600 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1600 : PASS'); + } + }) + + /** + * @tc.number: SUB_USB_JS_1610 + * @tc.name: setPortRoles + * @tc.desc: Negative test: parameter number exception, input two parameter + */ + it('SUB_USB_JS_1610', 0, function () { + console.info('usb SUB_USB_JS_1610 begin'); + var portId = gPort.id; + var powerRole = usb.SINK; + try { + var maskCode = usb.setPortRoles(portId, powerRole); + console.info('usb 1610 case setPortRoles return: ' + maskCode); + expect(false).assertTrue(); + } catch (err) { + console.info('usb 1610 catch err code: ' + err.code + ' message: ' + err.message); + expect(err.code).assertEqual(401); + console.info('usb SUB_USB_JS_1610 : PASS'); + } + }) + /** * @tc.number: SUB_USB_JS_1200 * @tc.name: getPorts