diff --git a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js index ca11022046512d597180ac4c7cd6b1b68138a423..c674eb8ed29b0648f02a72b31e1fc24e62c9ff39 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -119,11 +119,11 @@ describe('bluetoothBLETest', function() { console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret)) expect(ret).assertTrue(); await gattClient.getRssiValue().then((data) => { - console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data)); + console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); let rssiLength = Object.keys(data).length; expect(rssiLength).assertEqual(0); - }).catch(err => { - console.error('bluetooth getRssiValue has error: '+ err); + }).catch(error => { + console.info('bluetooth getRssiValue has error: '+ JSON.stringify(error)); expect(true).assertEqual(true); }); let disconnect = gattClient.disconnect(); @@ -146,15 +146,17 @@ describe('bluetoothBLETest', function() { let ret = gattClient.connect(); console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) expect(ret).assertTrue(); - gattClient.getRssiValue((err, data)=> { - console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); - expect(data).assertNull(); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - }); - await sleep(2000); - done(); + let promise = new Promise((resolve) => { + gattClient.getRssiValue((err, data)=> { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(data).assertNull(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + resolve() + }) + await promise.then(done) }) /** @@ -353,37 +355,40 @@ describe('bluetoothBLETest', function() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { + let promise = new Promise((resolve) => { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; descriptors[0] = descriptor; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); cccValue[0] = 32; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferCCC, descriptors:descriptors}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - await gattClient.readCharacteristicValue(characteristic).then((object) => { - if (object != null) { - console.error('bluetooth readCharacteristicValue promise object :' - +JSON.stringify(object)); + let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); + gattClient.readCharacteristicValue(characteristic).then((object) => { + if (object != null) { + expect(true).assertEqual(true); + } else { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + expect(null).assertFail(); + } + done(); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); expect(true).assertEqual(true); - } else { - console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object)); - expect(null).assertFail(); - } - done(); - }).catch(error => { - console.error('[bluetooth_js] readCharacteristicValue promise has error:' - +JSON.stringify(error)); - expect(true).assertEqual(true); - done(); + done(); + }); + resolve() }) + await promise.then(done) }) /** @@ -400,6 +405,7 @@ describe('bluetoothBLETest', function() { return; } console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); + expect(true).assertEqual(data==null); let value = new Uint8Array(BLECharacteristic.characteristicValue); console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); @@ -408,7 +414,8 @@ describe('bluetoothBLETest', function() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer}; + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue:arrayBuffer}; let arrayBufferCCC = new ArrayBuffer(8); let cccValue = new Uint8Array(arrayBufferCCC); cccValue[0] = 32; @@ -416,9 +423,7 @@ describe('bluetoothBLETest', function() { characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferCCC, descriptors:descriptor}; let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let data = await gattClient.readCharacteristicValue(characteristic,readCcc); - console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data)) - expect(true).assertEqual(data==null); + gattClient.readCharacteristicValue(characteristic,readCcc); done() }) @@ -435,7 +440,8 @@ describe('bluetoothBLETest', function() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); await gattClient.readDescriptorValue(descriptor).then((object) => { if (object != null) { @@ -443,12 +449,12 @@ describe('bluetoothBLETest', function() { expect(true).assertEqual(true); } else { - console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object)); + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); expect(null).assertFail(); } done(); - }).catch(error => { - console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error)); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); expect(true).assertEqual(true); done(); }) @@ -466,7 +472,7 @@ describe('bluetoothBLETest', function() { function readDesc(code, BLEDescriptor) { if (code.code != 0) { console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); - return; + expect(true).assertEqual(BLEDescriptor.descriptorUuid==null); } console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid); let value = new Uint8Array(BLEDescriptor.descriptorValue); @@ -479,9 +485,7 @@ describe('bluetoothBLETest', function() { let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let data1 = await gattClient.readDescriptorValue(descriptor,readDesc); - console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1)) - expect(true).assertEqual(data1==null); + gattClient.readDescriptorValue(descriptor,readDesc); done() }) @@ -653,6 +657,22 @@ describe('bluetoothBLETest', function() { done(); }) + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattClose_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.close(); + console.info('[bluetooth_js] gattClient close ret:' + ret); + expect(ret).assertEqual(true); + done(); + }) + }) } diff --git a/communication/bluetooth_ble/src/main/js/test/BleService.test.js b/communication/bluetooth_ble/src/main/js/test/BleService.test.js index 914327d160e1cda649d33bd199581d21e00efac6..9d77ff315ef9a995f17fd3d9a304d978447e236b 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleService.test.js @@ -67,554 +67,6 @@ describe('bluetoothBLETest1', function() { gattServer.close(); }) - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100 - * @tc.name testgetRssiValue - * @tc.desc Test getRssiValue api by promise. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret)) - expect(ret).assertTrue(); - await gattClient.getRssiValue().then((data) => { - console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data)); - let rssiLength = Object.keys(data).length; - expect(rssiLength).assertEqual(0); - }).catch(err => { - console.error('bluetooth getRssiValue has error: '+ err); - expect(true).assertEqual(true); - }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200 - * @tc.name testgetRssiValue - * @tc.desc Test testGetDeviceName api by callback. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) - expect(ret).assertTrue(); - gattClient.getRssiValue((err, data)=> { - console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); - expect(data).assertNull(); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - }); - await sleep(2000); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100 - * @tc.name testGetDeviceName - * @tc.desc Test GetDeviceName api by promise. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret)) - expect(ret).assertTrue(); - await gattClient.getDeviceName().then((data) => { - console.info('[bluetooth_js] device name' + JSON.stringify(data)) - expect(data).assertNull(); - }).catch(err => { - console.error('bluetooth getDeviceName has error: '+ err); - expect(true).assertEqual(true); - }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - done(); - }) - - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_getDeviceName_0200 - * @tc.name testGetDeviceName - * @tc.desc Test testGetDeviceName api by callback. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret)) - expect(ret).assertTrue(); - gattClient.getDeviceName((err, data)=> { - console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); - expect(data).assertNull(); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - }); - await sleep(2000); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100 - * @tc.name testGetServices - * @tc.desc Test GetServices api by promise. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret)) - expect(ret).assertTrue(); - await gattClient.getServices().then((GattService) => { - console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); - expect(GattService).assertNull(); - }).catch(err => { - console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); - expect(true).assertEqual(true); - }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200 - * @tc.name testGetServices - * @tc.desc Test GetServices api by callback. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.connect(); - console.info('[bluetooth_js]gattClient getservices2 connect' + JSON.stringify(ret)) - gattClient.getServices((code, data)=> { - if(code.code==0){ - console.info("bluetooth services size is ", data.length) - expect(true).assertEqual(data.length >= 0); - } else { - console.info('[bluetooth_js] get services code ' + JSON.stringify(code)); - expect(true).assertEqual(code.code == -1); - } - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - }); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100 - * @tc.name testSetBLEMtuSize - * @tc.desc Test SetBLEMtuSize api. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setBLEMtuSize(100); - console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200 - * @tc.name testSetBLEMtuSize - * @tc.desc Test SetBLEMtuSize api. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setBLEMtuSize(22); - console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300 - * @tc.name testSetBLEMtuSize - * @tc.desc Test SetBLEMtuSize api. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setBLEMtuSize(21); - console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400 - * @tc.name testSetBLEMtuSize - * @tc.desc Test SetBLEMtuSize api. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setBLEMtuSize(512); - console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500 - * @tc.name testSetBLEMtuSize - * @tc.desc Test SetBLEMtuSize api. - * @tc.size MEDIUM - * @ since 7 - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setBLEMtuSize(513); - console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100 - * @tc.name testReadDescriptorValue - * @tc.desc Test ReadDescriptorValue api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; - descriptors[0] = descriptor; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 32; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptors}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - await gattClient.readCharacteristicValue(characteristic).then((object) => { - if (object != null) { - console.error('bluetooth readCharacteristicValue promise object :' - +JSON.stringify(object)); - expect(true).assertEqual(true); - } else { - console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object)); - expect(null).assertFail(); - } - done(); - }).catch(error => { - console.error('[bluetooth_js] readCharacteristicValue promise has error:' - +JSON.stringify(error)); - expect(true).assertEqual(true); - done(); - }) - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200 - * @tc.name testReadDescriptorValue - * @tc.desc Test ReadDescriptorValue api by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) { - function readCcc(code, BLECharacteristic) { - if (code.code != 0) { - return; - } - console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); - let value = new Uint8Array(BLECharacteristic.characteristicValue); - console.log('bluetooth characteristic value: ' - + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); - } - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer}; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 32; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptor}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let data = await gattClient.readCharacteristicValue(characteristic,readCcc); - console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data)) - expect(true).assertEqual(data==null); - done() - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100 - * @tc.name testReadDescriptorValue - * @tc.desc Test ReadDescriptorValue api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - await gattClient.readDescriptorValue(descriptor).then((object) => { - if (object != null) { - console.error('readDescriptorValue promise object:'+JSON.stringify(object)); - expect(true).assertEqual(true); - - } else { - console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object)); - expect(null).assertFail(); - } - done(); - }).catch(error => { - console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error)); - expect(true).assertEqual(true); - done(); - }) - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200 - * @tc.name testReadDescriptorValue - * @tc.desc Test ReadDescriptorValue api by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) { - function readDesc(code, BLEDescriptor) { - if (code.code != 0) { - console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); - return; - } - console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid); - let value = new Uint8Array(BLEDescriptor.descriptorValue); - console.info('[bluetooth_js] descriptor value: ' - + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); - } - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let data1 = await gattClient.readDescriptorValue(descriptor,readDesc); - console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1)) - expect(true).assertEqual(data1==null); - done() - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100 - * @tc.name testWriteCharacteristicValue - * @tc.desc Test Client WriteCharacteristicValue api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () { - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; - descriptors[0] = descriptor; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 32; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptors}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.writeCharacteristicValue(characteristic); - console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200 - * @tc.name testWriteCharacteristicValue - * @tc.desc Test Client WriteCharacteristicValue api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.writeCharacteristicValue("123"); - console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100 - * @tc.name testWriteDescriptorValue - * @tc.desc Test Client WriteDescriptorValue api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () { - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.writeDescriptorValue(descriptor); - console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200 - * @tc.name testWriteDescriptorValue - * @tc.desc Test WriteDescriptorValue api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.writeDescriptorValue(""); - console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); - expect(ret).assertEqual(false); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100 - * @tc.name testSetNotifyCharacteristicChanged - * @tc.desc Test SetNotifyCharacteristicChanged api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let arrayBufferNotify = new ArrayBuffer(8); - let descNotifyValue = new Uint8Array(arrayBufferNotify); - descNotifyValue[0] = 1 - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBuffer}; - let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBufferNotify}; - descriptors[0] = descriptor; - descriptors[1] = descriptorNotify; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 1; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptors}; - let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true); - console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); - expect(ret).assertEqual(false); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200 - * @tc.name testSetNotifyCharacteristicChanged - * @tc.desc Test SetNotifyCharacteristicChanged api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let arrayBufferNotify = new ArrayBuffer(8); - let descNotifyValue = new Uint8Array(arrayBufferNotify); - descNotifyValue[0] = 1 - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBuffer}; - let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBufferNotify}; - descriptors[0] = descriptor; - descriptors[1] = descriptorNotify; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 1; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptors}; - let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false); - console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); - expect(ret).assertEqual(false); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300 - * @tc.name testSetNotifyCharacteristicChanged - * @tc.desc Test SetNotifyCharacteristicChanged api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) { - let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); - let ret = gattClient.setNotifyCharacteristicChanged(null, false); - console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret); - expect(ret).assertEqual(false); - done(); - }) /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100 diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js index bf469ef91a3640edfc15edafd393e3a629e6df71..f09a96f4497b387d33566b07cbf46ac56a2780ed 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -226,7 +226,7 @@ describe('bluetoothhostTest2', function() { bluetooth.BLE.on('pinRequired', PinRequiredParam); let result = bluetooth.pairDevice("00:00:00:00:00:00"); console.info("[bluetooth_js] onStartpair007 -> " + JSON.stringify(result)); - expect(result).assertTrue(); + expect(result).assertFalse(); bluetooth.BLE.off('pinRequired', PinRequiredParam); done() }) @@ -248,7 +248,7 @@ describe('bluetoothhostTest2', function() { bluetooth.BLE.on('pinRequired', PinRequiredParam); let result = bluetooth.pairDevice("00:00:00:00:00:00"); console.info("[bluetooth_js] onStartpair008 -> " + JSON.stringify(result)); - expect(result).assertTrue(); + expect(result).assertFalse(); bluetooth.BLE.off('pinRequired', PinRequiredParam); done() }) diff --git a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js index da557b6e22ef996fa99827343dd111219808760b..4f70490126f1f126882b84a89a1d69eedc54b94c 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js @@ -79,9 +79,10 @@ describe('bluetoothhostTest4', function() { secure: true, type: SppType.SPP_RFCOMM}; let serverNumber = -1; function serverSocket(code, number) { - console.log('bluetooth error code: ' + code.code); - if (code.code == 0) { - console.log('bluetooth serverSocket Number: ' + number); + if (code) { + console.log('bluetooth error code: ' + code); + }else{ + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); serverNumber = number; expect(true).assertEqual(number!=null); } @@ -103,11 +104,12 @@ describe('bluetoothhostTest4', function() { secure: false, type: 0}; let serverNumber = -1; function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - expect(true).assertEqual(number!=null); + if (code) { + console.log('[bluetooth_js] error code: ' + code); + }else{ + console.log('[bluetooth_js] serverSocket Number: ' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(number!=null); } } bluetooth.sppListen('server1', sppOption, serverSocket); @@ -127,12 +129,15 @@ describe('bluetoothhostTest4', function() { secure: true, type: 0}; let serverNumber = -1; function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - expect(true).assertEqual(number!=null); - } + + if (code) { + console.log('[bluetooth_js] error code: ' + code); + + }else{ + console.log('[bluetooth_js] serverSocket Number: '+JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber!=null); + } } bluetooth.sppListen('server1', sppOption, serverSocket); done(); @@ -151,11 +156,14 @@ describe('bluetoothhostTest4', function() { secure: false, type: 0}; let serverNumber = -1; function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - expect(true).assertEqual(number!=null); + + if (code) { + console.log('[bluetooth_js] error code: ' + code); + + }else{ + console.log('[bluetooth_js] serverSocket Number:'+ JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber!=null); } } bluetooth.sppListen('server1', sppOption, serverSocket); @@ -172,11 +180,13 @@ describe('bluetoothhostTest4', function() { */ it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500', 0, async function (done) { function acceptClientSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] clientSocket Number: ' + number); - expect(true).assertEqual(number!=null); - } + + if (code) { + console.log('[bluetooth_js] error code: ' + code); + }else{ + console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number)); + expect(true).assertEqual(number!=null); + } } bluetooth.sppAccept(0, acceptClientSocket); done(); @@ -191,13 +201,13 @@ describe('bluetoothhostTest4', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600', 0, async function (done) { - bluetooth.sppAccept(-1, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); - expect(true).assertEqual(clientSocketNumber!=null); + bluetooth.sppAccept(-1, function(code, clientSocketNumber) { + if (code) { + console.info('[bluetooth_js] code is: ' + code); } else { - expect(true).assertEqual(false); + console.log('[bluetooth_js]sppAccept Number:' + + JSON.stringify(clientSocketNumber)); + expect(true).assertEqual(clientSocketNumber!=null); } }); done(); @@ -215,12 +225,12 @@ describe('bluetoothhostTest4', function() { let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: true, type: 0}; bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppConnect Number:' + clientSocketNumber); - expect(true).assertEqual(clientSocketNumber!=null); + if (code) { + console.info('[bluetooth_js] code is: ' + code); } else { - expect(true).assertEqual(false); + console.log('[bluetooth_js]sppConnect Number:' + + JSON.stringify(clientSocketNumber)); + expect(true).assertEqual(clientSocketNumber!=null); } }); done(); @@ -238,12 +248,12 @@ describe('bluetoothhostTest4', function() { let sppOption = {uuid: '0000', secure: false, type: 0}; bluetooth.sppConnect('ABC', sppOption, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber); - expect(true).assertEqual(clientSocketNumber!=null); + if (code) { + console.info('[bluetooth_js] code is: ' + code); } else { - expect(true).assertEqual(false); + console.log('[bluetooth_js]sppConnect Number' + + JSON.stringify(clientSocketNumber)); + expect(true).assertEqual(clientSocketNumber!=null); } }); done(); @@ -261,12 +271,12 @@ describe('bluetoothhostTest4', function() { let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: true, type: 0}; bluetooth.sppConnect('BT', sppOption, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber); - expect(true).assertEqual(clientSocketNumber!=null); + if (code) { + console.info('[bluetooth_js] code is: ' + code); } else { - expect(true).assertEqual(false); + console.log('[bluetooth_js]sppConnect Number' + + JSON.stringify(clientSocketNumber)); + expect(true).assertEqual(clientSocketNumber!=null); } }); done(); @@ -283,11 +293,14 @@ describe('bluetoothhostTest4', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000', 0, async function (done) { let serverNumber = -1; function serverSocket(code, number) { - console.log('bluetooth error code: ' + code.code); - if (code.code == 0) { - console.log('bluetooth serverSocket Number: ' + number); + if (code) { + console.log('bluetooth error code: ' + code); + }else{ + console.log('bluetooth serverSocket Number:'+ JSON.stringify(number)); serverNumber = number; + expect(true).assertEqual(serverNumber!=null); } + } let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: true, type: 0}; @@ -307,13 +320,13 @@ describe('bluetoothhostTest4', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1100', 0, async function (done) { let clientNumber = -1; bluetooth.sppAccept(-1, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); + if (code) { + console.info('[bluetooth_js] code is: ' + code); + } else { + console.log('[bluetooth_js]sppAccept Number:' + + JSON.stringify(clientSocketNumber)); clientNumber =clientSocketNumber; expect(true).assertEqual(clientSocketNumber!=null); - } else { - expect(true).assertEqual(false); } }); bluetooth.sppCloseClientSocket(clientNumber); @@ -331,13 +344,13 @@ describe('bluetoothhostTest4', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200', 0, async function (done) { let clientNumber = -1; bluetooth.sppAccept(-1, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); + if (code) { + console.info('[bluetooth_js] code is: ' + code); + } else { + console.log('[bluetooth_js]sppAccept Number:' + + JSON.stringify(clientSocketNumber)); clientNumber =clientSocketNumber; expect(true).assertEqual(clientSocketNumber!=null); - } else { - expect(true).assertEqual(false); } }); let arrayBuffer = new ArrayBuffer(8); diff --git a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js index 154c321cfc67e77ca2cda94766a73c8962b21801..9801165b80ff89460c7a0a5c6067ead7ce324ebd 100644 --- a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js @@ -888,7 +888,8 @@ describe('geolocationTest_geo3', function () { ' longitude: ' + result.longitude +' altitude: ' + result.altitude +' accuracy: ' + result.accuracy+' speed: ' + result.speed + 'timeStamp: ' + result.timeStamp+'direction:' + result.direction+' timeSinceBoot: ' - + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize); + + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize + +'isFromMock'+ result.isFromMock); }).catch((error) => { console.info("[lbs_js] getLastLocation promise then error:" + JSON.stringify(error)); console.info('[lbs_js] not support now');