diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js index 939bec17e65abf51928b80d1dc81c7403d5f9e06..903f1cab5f6be8519218275f8a5be33fa788a9a9 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js @@ -28,9 +28,8 @@ describe('UsbCoreJsFunctionsTest', function () { // version > 17 host currentMode = 2 device currentMode = 1 var usbPortList = usb.getPorts() if (usbPortList.length > 0) { - var DevMode = 1 - if (usbPortList[0].status.currentMode == DevMode) { - usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { console.info('usb case setPortRoles return: ' + data); }).catch(error => { console.info('usb case setPortRoles error : ' + error); @@ -269,7 +268,6 @@ describe('UsbCoreJsFunctionsTest', function () { expect(false).assertTrue(); return } - gPipe = usb.connectDevice(gDeviceList[0]) console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); var fileDescriptor = usb.getFileDescriptor(gPipe); @@ -280,4 +278,70 @@ describe('UsbCoreJsFunctionsTest', function () { console.info('usb SUB_USB_get_file_descriptor_01 : PASS'); }) + + /** + * @tc.number : SUB_USB_get_file_descriptor_02 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512 + */ + it('SUB_USB_get_file_descriptor_02', 0, function () { + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : 255, devAddress : 255} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_get_file_descriptor_02 : PASS'); + }) + + /** + * @tc.number : SUB_USB_get_file_descriptor_03 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数devAddress=512 + */ + it('SUB_USB_get_file_descriptor_03', 0, function () { + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : 255, devAddress : gPipe.devAddress} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_get_file_descriptor_03 : PASS'); + }) + /** + * @tc.number : SUB_USB_get_file_descriptor_04 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512,devAddress=512 + */ + it('SUB_USB_get_file_descriptor_04', 0, function () { + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : gPipe.busNum, devAddress : 255} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_get_file_descriptor_04 : PASS'); + }) + }) diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js index 38b2840c07259a5f25c558594f7b2376923d8152..52f444e49a12300b7854a5b86ca257af2d8c91f5 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js @@ -28,9 +28,8 @@ describe('UsbCoreJsFunctionsTestEx', function () { // version > 17 host currentMode = 2 device currentMode = 1 var usbPortList = usb.getPorts() if (usbPortList.length > 0) { - var DevMode = 1 - if (usbPortList[0].status.currentMode == DevMode) { - usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { console.info('usb case setPortRolesEx return: ' + data); }).catch(error => { console.info('usb case setPortRolesEx error : ' + error); diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js index e8dbb6ae26b16aa3befca68ed840851b5dd7c396..48000b642ec7989e85be5f4ac659f7c9c652068e 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js @@ -28,13 +28,11 @@ describe('UsbDevicePipeJsFunctionsTest', 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() if (usbPortList.length > 0) { - var DevMode = 1 - if (usbPortList[0].status.currentMode == DevMode) { - usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { console.info('usb case setPortRoles return: ' + data); }).catch(error => { console.info('usb case setPortRoles error : ' + error); @@ -67,10 +65,10 @@ describe('UsbDevicePipeJsFunctionsTest', function () { var endpoint = testParam.config.interfaces[j].endpoints[k]; if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { bfind = true - if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_OUT) { + if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { testParam.maxOutSize = endpoint.maxPacketSize; testParam.outEndpoint = endpoint; - } else if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_IN) { + } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { testParam.maxInSize = endpoint.maxPacketSize; testParam.inEndpoint = endpoint } @@ -385,7 +383,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () { } var timeout = 5000; - var controlParam = getTransferParam(6, ((1 << 7) | (0 << 5) | (0 & 0x1f)), (2 << 8), 0) + var controlParam = getTransferParam(6, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0) callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_01 GetDescriptor') }) @@ -403,7 +401,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () { } var timeout = 5000; - var controlParam = getTransferParam(0, 128, 0, 0) + var controlParam = getTransferParam(0, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_02 GetStatus') }) @@ -421,7 +419,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () { } var timeout = 5000; - var controlParam = getTransferParam(8, 128, 0, 0) + var controlParam = getTransferParam(8, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_03 GetConfiguration') }) @@ -439,7 +437,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () { } var timeout = 5000; - var controlParam = getTransferParam(10, 129, 0, 1) + var controlParam = getTransferParam(10, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1) callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_04 GetInterface') }) @@ -457,8 +455,79 @@ describe('UsbDevicePipeJsFunctionsTest', function () { } var timeout = 5000; - var controlParam = getTransferParam(1, 0, 0, 0) + var controlParam = getTransferParam(1, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_05 ClearFeature') }) + /** + * @tc.number : SUB_USB_control_transfer_test_06 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_06', 0, function () { + console.info('usb control_transfer_test_06 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_06 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_control_transfer_test_07 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_07', 0, function () { + console.info('usb control_transfer_test_07 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_07 ClearFeature') + }) + /** + * @tc.number : SUB_USB_control_transfer_test_08 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_08', 0, function () { + console.info('usb control_transfer_test_08 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_08 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_control_transfer_test_09 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_09', 0, function () { + console.info('usb control_transfer_test_09 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_09 ClearFeature') + }) + }) diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js index be70aaa16a7d1c1e1d17bfd7bf64c1fc6aa0d118..6a3796d8278d664e66f374e7f815253334b3d3f5 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js @@ -31,9 +31,8 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { // version > 17 host currentMode = 2 device currentMode = 1 var usbPortList = usb.getPorts() if (usbPortList.length > 0) { - var DevMode = 1 - if (usbPortList[0].status.currentMode == DevMode) { - usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { console.info('usb case setPortRoles return: ' + data); }).catch(error => { console.info('usb case setPortRoles error : ' + error); @@ -67,10 +66,10 @@ describe('UsbDevicePipeJsFunctionsTestEx', function () { if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { bfind = true - if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_OUT) { + if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { testParam.outEndpoint = endpoint; testParam.maxOutSize = endpoint.maxPacketSize; - } else if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_IN) { + } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { testParam.inEndpoint = endpoint testParam.maxInSize = endpoint.maxPacketSize; } diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js index 664f318ec9f9c645e715a8e3377969c5a4b3278e..8f3cd3ac0a4dab5fe3b7f9541fd4d038068c5e4e 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js @@ -27,9 +27,8 @@ describe('UsbFunctionsJsFunctionsTest', function () { // version > 17 host currentMode = 2 device currentMode = 1 var usbPortList = usb.getPorts() if (usbPortList.length > 0) { - var HostMode = 2 - if (usbPortList[0].status.currentMode == HostMode) { - usb.setPortRoles(usbPortList[0].id, 2, 2).then(data => { + if (usbPortList[0].status.currentMode == 2) { + usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { console.info('usb case setPortRoles return: ' + data); }).catch(error => { console.info('usb case setPortRoles error : ' + error); @@ -89,7 +88,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { var errStrMaskCode = 'none' var nMaskCode = usb.usbFunctionsFromString(errStrMaskCode) - expect(nMaskCode).assertEqual(0); + expect(nMaskCode).assertEqual(usb.NONE); console.info('usb case errStrMaskCode ' + errStrMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); @@ -122,7 +121,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_02 ACM 1', 1) + callSetCurFunction('set_current_functions_test_02 ACM 1', usb.ACM) }) /** @@ -137,7 +136,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_03 ECM 2', 2) + callSetCurFunction('set_current_functions_test_03 ECM 2', usb.ECM) }) /** @@ -152,7 +151,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_04 ACM ECM 3', 3) + callSetCurFunction('set_current_functions_test_04 ACM ECM 3', (usb.ACM | usb.ECM)) }) /** @@ -167,7 +166,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_05 HDC 4', 4) + callSetCurFunction('set_current_functions_test_05 HDC 4', usb.HDC) }) /** @@ -182,7 +181,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_06 ACM HDC 5', 5) + callSetCurFunction('set_current_functions_test_06 ACM HDC 5', (usb.HDC | usb.ACM)) }) /** @@ -197,7 +196,7 @@ describe('UsbFunctionsJsFunctionsTest', function () { console.info('usb case getCurrentFunctions return: ' + maskCode); var funcString = usb.usbFunctionsToString(maskCode); console.info('usb case funcString:' + funcString); - callSetCurFunction('set_current_functions_test_07 ECM HDC 6', 6) + callSetCurFunction('set_current_functions_test_07 ECM HDC 6', (usb.HDC | usb.ECM)) }) }) diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js index 0d69be19731ae8274c220c4cbae7783e2e4d5970..3ce664b45094445e167668ecbc78880977473fbe 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js @@ -26,9 +26,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { // 17 version host currentMode = 2 device currentMode = 1 var usbPortList = usb.getPorts() if (usbPortList.length > 0) { - var HostMode = 2 - if (usbPortList[0].status.currentMode == HostMode) { - usb.setPortRoles(usbPortList[0].id, 2, 2).then(data => { + if (usbPortList[0].status.currentMode == 2) { + usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { console.info('usb case setPortRoles return: ' + data); }).catch(error => { console.info('usb case setPortRoles error : ' + error); @@ -57,7 +56,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_01', 0, function () { console.info('usb usb_function_to_string_test_01 begin'); - var maskCode = 0 + var maskCode = usb.NONE + console.info('usb case maskCode : ' + usb.NONE); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('none'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -71,7 +71,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_02', 0, function () { console.info('usb usb_function_to_string_test_02 begin'); - var maskCode = 1 + var maskCode = usb.ACM + console.info('usb case maskCode : ' + usb.ACM); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('acm'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -85,7 +86,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_03', 0, function () { console.info('usb usb_function_to_string_test_02 begin'); - var maskCode = 2 + var maskCode = usb.ECM + console.info('usb case maskCode : ' + maskCode); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('ecm'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -99,7 +101,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_04', 0, function () { console.info('usb usb_function_to_string_test_02 begin'); - var maskCode = 3 + var maskCode = usb.ACM | usb.ECM + console.info('usb case maskCode : ' + maskCode); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('acm,ecm'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -113,7 +116,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_05', 0, function () { console.info('usb usb_function_to_string_test_05 begin'); - var maskCode = 4 + var maskCode = usb.HDC + console.info('usb case maskCode : ' + maskCode); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('hdc'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -127,7 +131,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_06', 0, function () { console.info('usb usb_function_to_string_test_06 begin'); - var maskCode = 5 + var maskCode = usb.ACM | usb.HDC + console.info('usb case maskCode : ' + maskCode); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('hdc,acm'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -141,7 +146,8 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { */ it('SUB_USB_usb_function_to_string_test_07', 0, function () { console.info('usb usb_function_to_string_test_07 begin'); - var maskCode = 6 + var maskCode = usb.ECM | usb.HDC + console.info('usb case maskCode : ' + maskCode); var strMaskCode = usb.usbFunctionsToString(maskCode) expect(strMaskCode).assertEqual('hdc,ecm'); console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); @@ -157,7 +163,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_01 begin'); var strMaskCode = 'none' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(0); + expect(nMaskCode).assertEqual(usb.NONE); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_to_string_test_01 : PASS'); }) @@ -171,7 +177,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_02 begin'); var strMaskCode = 'acm' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(1); + expect(nMaskCode).assertEqual(usb.ACM); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_02 : PASS'); }) @@ -185,7 +191,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_03 begin'); var strMaskCode = 'ecm' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(2); + expect(nMaskCode).assertEqual(usb.ECM); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_03 : PASS'); }) @@ -199,7 +205,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_04 begin'); var strMaskCode = 'acm,ecm' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(3); + expect(nMaskCode).assertEqual(usb.ACM | usb.ECM); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_04 : PASS'); }) @@ -213,7 +219,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_05 begin'); var strMaskCode = 'hdc' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(4); + expect(nMaskCode).assertEqual(usb.HDC); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_04 : PASS'); }) @@ -227,7 +233,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_06 begin'); var strMaskCode = 'acm,hdc' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(5); + expect(nMaskCode).assertEqual(usb.HDC | usb.ACM); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_06 : PASS'); }) @@ -241,7 +247,7 @@ describe('UsbFunctionsJsFunctionsTestEx', function () { console.info('usb usb_function_from_string_test_07 begin'); var strMaskCode = 'ecm,hdc' var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(6); + expect(nMaskCode).assertEqual(usb.HDC | usb.ECM); console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); console.info('usb usb_function_from_string_test_07 : PASS'); }) diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js index bbdd5af60886e7ea9b7f20047f63518b4c3ddd4a..c3f9f0cbb5bc622c2c2ce077aaa5fc44c4d8b370 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js @@ -93,7 +93,7 @@ describe('UsbPortJsFunctionsTest', function () { for (var i = 0; i < usbPortList.length; i++) { console.info('usb case set data role 2, data role 2'); - usb.setPortRoles(usbPortList[i].id, 2, 2).then(data => { + usb.setPortRoles(usbPortList[i].id, usb.SINK, usb.DEVICE).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -123,7 +123,7 @@ describe('UsbPortJsFunctionsTest', function () { for (var i = 0; i < usbPortList.length; i++) { console.info('usb case set data role 1, data role 1'); CheckEmptyUtils.sleep(5000) - usb.setPortRoles(usbPortList[i].id, 1, 1).then(data => { + usb.setPortRoles(usbPortList[i].id, usb.SOURCE, usb.HOST).then(data => { expect(data).assertTrue(); console.info('usb case setPortRoles return: ' + data); }).catch(error => { diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js index 6daa5f384e42c4e1424d33e6e4513a48a16e4454..2e0490d2d6e43c1735b86146c34611eb7165a2f9 100755 --- a/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js @@ -20,6 +20,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from /* usb core functions test */ describe('UsbPortJsFunctionsTestEx', function () { + var gPort; beforeAll(function () { console.log('*************Usb Unit UsbPortJsFunctionsTestEx Begin*************'); var Version = usb.getVersion() @@ -52,10 +53,10 @@ describe('UsbPortJsFunctionsTestEx', function () { } expect(usbPortList.length > 0).assertTrue(); - + gPort = usbPortList[0].id var portID = usbPortList[0].id + 10 var maskCode = usb.getSupportedModes(portID) - expect(maskCode).assertEqual(0); + expect(maskCode).assertEqual(usb.NONE); console.info('usb get_supported_modes_test_02 : PASS'); expect(true).assertTrue(); @@ -64,14 +65,14 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_03 * @tc.name : setPortRoles - * @tc.desc : Device模式下,dataRole参数错误 + * @tc.desc : dataRole参数错误 */ it('SUB_USB_set_port_roles_test_03', 0, function () { - var portId = 2; - var powerRole = 2; - var dataRole = -1; + var portId = gPort.id; + var powerRole = usb.SINK; + var dataRole = usb.NONE - 1; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(2, 2, -1).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -87,14 +88,14 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_04 * @tc.name : setPortRoles - * @tc.desc : Device模式下,portId,powerRole参数错误 + * @tc.desc : portId,powerRole参数错误 */ it('SUB_USB_set_port_roles_test_04', 0, function () { - var portId = -1; - var powerRole = -1; - var dataRole = 2; + var portId = gPort.id; + var powerRole = usb.NONE - 1; + var dataRole = usb.DEVICE; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, -1, 2).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -110,14 +111,14 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_05 * @tc.name : setPortRoles - * @tc.desc : Device模式下,portId,dataRole参数错误 + * @tc.desc : portId,dataRole参数错误 */ it('SUB_USB_set_port_roles_test_05', 0, function () { - var portId = -1; - var powerRole = 2; - var dataRole = -1; + var portId = gPort.id - 3; + var powerRole = usb.SINK; + var dataRole = usb.NONE - 1; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, 2, -1).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -133,14 +134,14 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_06 * @tc.name : setPortRoles - * @tc.desc : Device模式下,powerRole,dataRole参数错误 + * @tc.desc : powerRole,dataRole参数错误 */ it('SUB_USB_set_port_roles_test_06', 0, function () { - var portId = 2; - var powerRole = -1; - var dataRole = -1; + var portId = gPort.id; + var powerRole = usb.NONE - 1; + var dataRole = usb.NONE - 1; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(2, -1, -1).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -156,15 +157,15 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_07 * @tc.name : setPortRoles - * @tc.desc : Device模式下,portId,portId,dataRole参数错误 + * @tc.desc : portId,portId,dataRole参数错误 */ it('SUB_USB_set_port_roles_test_07', 0, function () { - var portId = -1; - var dataRole = -1; - var powerRole = -1; + var portId = gPort.id - 1; + var dataRole = usb.NONE - 1; + var powerRole = usb.NONE - 1; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, -1, -1).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles 07 return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -180,14 +181,14 @@ describe('UsbPortJsFunctionsTestEx', function () { /** * @tc.number : SUB_USB_set_port_roles_test_08 * @tc.name : setPortRoles - * @tc.desc : host模式下,portId参数错误 + * @tc.desc : portId参数错误 */ it('SUB_USB_set_port_roles_test_08', 0, function () { - var portId = -1; + var portId = gPort.id - 1; var powerRole = 1; var dataRole = 1; CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, 1, 1).then(data => { + usb.setPortRoles(portId, powerRole, dataRole).then(data => { console.info('usb case setPortRoles return: ' + data); expect(data).assertTrue(); }).catch(error => { @@ -200,188 +201,4 @@ describe('UsbPortJsFunctionsTestEx', function () { expect(true).assertTrue(); }) - /** - * @tc.number : SUB_USB_set_port_roles_test_09 - * @tc.name : setPortRoles - * @tc.desc : host模式下,powerRole参数错误 - */ - it('SUB_USB_set_port_roles_test_09', 0, function () { - var portId = 1; - var powerRole = -1; - var dataRole = 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(1, -1, 1).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_09: PASS'); - }) - - console.info('usb set_port_roles_test_09: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_10 - * @tc.name : setPortRoles - * @tc.desc : host模式下,dataRole参数错误 - */ - it('SUB_USB_set_port_roles_test_10', 0, function () { - var portId = 1; - var powerRole = 1; - var dataRole = -1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(1, -1, 1).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_10: PASS'); - }) - - console.info('usb set_port_roles_test_10: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_11 - * @tc.name : setPortRoles - * @tc.desc : host模式下,portId,powerRole参数错误 - */ - it('SUB_USB_set_port_roles_test_11', 0, function () { - var portId = -1; - var powerRole = -1; - var dataRole = 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, -1, 1).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_11: PASS'); - }) - - console.info('usb set_port_roles_test_11: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_12 - * @tc.name : setPortRoles - * @tc.desc : host模式下,portId,dataRole参数错误 - */ - it('SUB_USB_set_port_roles_test_12', 0, function () { - var portId = -1; - var powerRole = 1; - var dataRole = -1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, 1, -1).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_12: PASS'); - }) - - console.info('usb set_port_roles_test_12: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_13 - * @tc.name : setPortRoles - * @tc.desc : host模式下,powerRole,dataRole参数错误 - */ - it('SUB_USB_set_port_roles_test_13', 0, function () { - var portId = 1; - var powerRole = -1; - var dataRole = -1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(1, -1, -1).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_13: PASS'); - }) - - console.info('usb set_port_roles_test_13: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_14 - * @tc.name : setPortRoles - * @tc.desc : host模式下,portId,powerRole,dataRole参数错误 - */ - it('SUB_USB_set_port_roles_test_14', 0, function () { - var portId = -1; - var powerRole = -1; - var dataRole = -1; - CheckEmptyUtils.sleep(2000) - - usb.setPortRoles(-1, -1, -1).then(data => { - console.info('usb case setPortRoles 14 return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles 14 error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_14: PASS'); - }) - - console.info('usb set_port_roles_test_14: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_15 - * @tc.name : setPortRoles - * @tc.desc : Device模式下,portId参数错误 - */ - it('SUB_USB_set_port_roles_test_15', 0, function () { - var portId = -1; - var powerRole = 2; - var dataRole = 2; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(-1, 2, 2).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_15: PASS'); - }) - - console.info('usb set_port_roles_test_15: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_set_port_roles_test_16 - * @tc.name : setPortRoles - * @tc.desc : Device模式下,powerRole参数错误 - */ - it('SUB_USB_set_port_roles_test_16', 0, function () { - var portId = 2; - var powerRole = -1; - var dataRole = 2; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(2, -1, 2).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb set_port_roles_test_16: PASS'); - }) - - console.info('usb set_port_roles_test_16: PASS'); - expect(true).assertTrue(); - }) })