diff --git a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js index 89121e872a5d832a99f06adfa3cc024390101a81..d8339e9c7b914ec20d0fd127404b984161c12923 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js @@ -79,44 +79,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 0 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:150, - txPower:60, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:150, + txPower:60, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -129,44 +136,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:20, - txPower:60, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:20, + txPower:60, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -179,44 +193,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:16385, - txPower:60, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:16385, + txPower:60, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -229,44 +250,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:16400, - txPower:60, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:16400, + txPower:60, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -279,47 +307,54 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:19, - txPower:60, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:19, + txPower:60, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) - /** + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. @@ -329,44 +364,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:-10, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -379,44 +421,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:-127, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-127, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -429,44 +478,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:1, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -479,44 +535,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:10, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -529,44 +592,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:-130, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-130, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -579,44 +649,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:1, - connectable:false, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:false, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -629,44 +706,51 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:70, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:70, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); }) /** @@ -679,45 +763,234 @@ describe('bluetoothBLETest2', function() { * @tc.level Level 1 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) { - let gattServer =bluetooth.BLE.createGattServer(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - gattServer.startAdvertising({ - interval:1000, - txPower:-70, - connectable:true, - },{ - serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:4567, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - },{ - serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], - manufactureData:[{ - manufactureId:1789, - manufactureValue:manufactureValueBuffer.buffer - }], - serviceData:[{ - serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", - serviceValue:serviceValueBuffer.buffer - }], - }); - gattServer.stopAdvertising(); - done(); - }) + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:70, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:[""], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:[""], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400', 0, function () { + let isRet = true; + try{ + let gattServer =bluetooth.BLE.createGattServer(); + gattServer.stopAdvertising(); + expect(isRet).assertTrue(); + }catch(error){ + console.info("[bluetooth_js] GattclientClose err:" + JSON.stringify(error)); + let isRet = false; + expect(isRet).assertFalse(); + } + }) }) 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 aae85447c2a72613314f8f2f446b0c47c16ab338..972da8c07f4cf7dd9ad3ac605fc7b77e68640701 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -130,7 +130,6 @@ describe('bluetoothBLETest', function() { done() }) - /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100 * @tc.name testgetRssiValue @@ -149,14 +148,16 @@ describe('bluetoothBLETest', function() { console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); let rssiLength = Object.keys(data).length; expect(rssiLength).assertEqual(0); + done(); }).catch(error => { console.info('bluetooth getRssiValue has error: '+ JSON.stringify(error)); expect(true).assertEqual(true); + done(); }); let disconnect = gattClient.disconnect(); console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect); expect(disconnect).assertEqual(false); - done(); + }) /** @@ -203,14 +204,16 @@ describe('bluetoothBLETest', function() { await gattClient.getDeviceName().then((data) => { console.info('[bluetooth_js] device name' + JSON.stringify(data)) expect(data).assertNull(); + done(); }).catch(err => { console.error('bluetooth getDeviceName has error: '+ err); expect(true).assertEqual(true); + done(); }); let disconnect = gattClient.disconnect(); console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); expect(disconnect).assertEqual(false); - done(); + }) @@ -256,14 +259,15 @@ describe('bluetoothBLETest', function() { await gattClient.getServices().then((GattService) => { console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); expect(GattService).assertNull(); + done(); }).catch(err => { console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); expect(true).assertEqual(true); + done(); }); let disconnect = gattClient.disconnect(); console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); expect(disconnect).assertEqual(false); - done(); }) /** @@ -383,39 +387,35 @@ describe('bluetoothBLETest', function() { * @tc.level Level 2 */ 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}; - 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("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}`); + 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("00:00:00:00:00:00"); + gattClient.readCharacteristicValue(characteristic).then((object) => { + if (object != null) { expect(true).assertEqual(true); - done(); - }); - resolve() + } 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); + done(); }) - await promise.then(done) }) /** @@ -450,7 +450,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"); - gattClient.readCharacteristicValue(characteristic,readCcc); + await gattClient.readCharacteristicValue(characteristic,readCcc); done() }) @@ -611,7 +611,7 @@ describe('bluetoothBLETest', function() { expect(ret).assertEqual(false); }) - /** + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200 * @tc.name testWriteCharacteristicValue * @tc.desc Test Client WriteCharacteristicValue api. @@ -736,7 +736,7 @@ describe('bluetoothBLETest', function() { done() }) - /** + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100 * @tc.name testSetNotifyCharacteristicChanged * @tc.desc Test SetNotifyCharacteristicChanged api. @@ -889,4 +889,3 @@ describe('bluetoothBLETest', function() { }) } - 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 e0f0b39b705d7b1c4e0dbb12859ffbabd129d5a8..277795b8ab96bb65c50f15e60fba549d8c3c33ae 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleService.test.js @@ -218,7 +218,7 @@ describe('bluetoothBLETest1', function() { cccV[0] = 1; let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferC, descriptors:[]}; + characteristicValue: arrayBufferC}; characteristics[0] = characteristic; let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]}; @@ -505,7 +505,7 @@ describe('bluetoothBLETest1', function() { expect(ret).assertFalse(); await sleep(1000); let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); - console.info('[bluetooth_js]removeService ret:'+ret1); + console.info('[bluetooth_js]removeService ret:'+ ret1); expect(ret1).assertFalse(); done(); }) @@ -711,7 +711,7 @@ describe('bluetoothBLETest1', function() { }) /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200 + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100 * @tc.name testSendResponse success * @tc.desc Test SendResponse api. * @tc.size MEDIUM @@ -730,6 +730,26 @@ describe('bluetoothBLETest1', function() { done(); }) + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200', 0, async function (done) { + let arrayBuffer = new ArrayBuffer(8); + let value = new Uint8Array(arrayBuffer); + value[0] = 1; + let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1, + status: -1, offset: 0, value: arrayBuffer}; + let ret = gattServer.sendResponse(ServerResponse); + console.info('[bluetooth_js] sendResponse ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + }) } diff --git a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js index 0e508b7fa634b2c57abedb96a383d9c24a23ab84..edffde0b249b0dd553df59963876504a00b4d75e 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js @@ -91,23 +91,14 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 3 + * @tc.level Level 1 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100', 0, async function (done) { - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = 'bluetoothtest'; - let result = bluetooth.setLocalName(newName); + let result = bluetooth.setLocalName(Btname.LETTERS_TEST); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - let result1=bluetooth.setLocalName(localName); - expect(result1).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0100 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); + expect(true).assertEqual(Btname.LETTERS_TEST == getNewName); done(); }) @@ -118,14 +109,14 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.LETTERS_TEST); + let result = bluetooth.setLocalName(Btname.CHINESES_TEST); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.LETTERS_TEST == getNewName); + expect(true).assertEqual(Btname.CHINESES_TEST == getNewName); done(); }) @@ -136,50 +127,51 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 3 + * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.CHINESES_TEST); + let result = bluetooth.setLocalName(Btname.NUM_TEST); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0300 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.CHINESES_TEST == getNewName); + expect(true).assertEqual(Btname.NUM_TEST == getNewName); done(); }) - /** + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400 * @tc.name setLocalName * @tc.desc Test setLocalName api by promise. * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 2 + * @tc.level Level 1 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.NUM_TEST); + let result = bluetooth.setLocalName(Btname.SYMBOL_TEST); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0400 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.NUM_TEST == getNewName); + expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName); done(); }) - /** + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500 * @tc.name setLocalName * @tc.desc Test setLocalName api by promise. * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.SYMBOL_TEST); + let newName = 'my bluetooth'; + let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName); + expect(true).assertEqual(newName == getNewName); done(); }) @@ -190,10 +182,10 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 2 + * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) { - let newName = 'my bluetooth'; + let newName = 'bluetooth1234ABCDEFGH'; let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); @@ -204,15 +196,15 @@ describe('bluetoothhostTest1', function() { /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700 - * @tc.name setLocalName - * @tc.desc Test setLocalName api by promise. + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. * @tc.size MEDIUM * @ since 8 * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) { - let newName = 'bluetooth1234ABCDEFGH'; + let newName = '蓝牙设备bluetooth'; let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); @@ -230,13 +222,12 @@ describe('bluetoothhostTest1', function() { * @tc.type Function * @tc.level Level 3 */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800', 0, async function (done) { - let newName = '蓝牙设备bluetooth'; - let result = bluetooth.setLocalName(newName); + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES4); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0800 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); + expect(true).assertEqual(Btname.MIXES4 == getNewName); done(); }) @@ -249,12 +240,12 @@ describe('bluetoothhostTest1', function() { * @tc.type Function * @tc.level Level 3 */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES4); + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES2); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0900 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES4 == getNewName); + expect(true).assertEqual(Btname.MIXES2 == getNewName); done(); }) @@ -268,11 +259,11 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES2); + let result = bluetooth.setLocalName(Btname.MIXES3); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1000 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES2 == getNewName); + expect(true).assertEqual(Btname.MIXES3 == getNewName); done(); }) @@ -283,14 +274,15 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 3 + * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES3); + let newName = '蓝牙设备123'; + let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES3 == getNewName); + expect(true).assertEqual(newName == getNewName); done(); }) @@ -301,14 +293,14 @@ describe('bluetoothhostTest1', function() { * @tc.size MEDIUM * @ since 8 * @tc.type Function - * @tc.level Level 2 + * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) { - let newName = '蓝牙设备123'; + let newName = '蓝牙设备bluetooth12'; let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1200 NewName = '+ JSON.stringify(getNewName)); + console.info('[bluetooth_js] LocalName1200 NewName = '+ JSON.stringify(getNewName)); expect(true).assertEqual(newName == getNewName); done(); }) @@ -322,13 +314,12 @@ describe('bluetoothhostTest1', function() { * @tc.type Function * @tc.level Level 3 */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300', 0, async function (done) { - let newName = '蓝牙设备bluetooth12'; - let result = bluetooth.setLocalName(newName); + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES6); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1300 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); + expect(true).assertEqual(Btname.MIXES6 == getNewName); done(); }) @@ -341,12 +332,13 @@ describe('bluetoothhostTest1', function() { * @tc.type Function * @tc.level Level 3 */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES6); + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES6 == getNewName); + expect(true).assertEqual(Btname.MIXES == getNewName); + done(); }) @@ -360,12 +352,11 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES); + let result = bluetooth.setLocalName(Btname.MIXES5); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1500 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES == getNewName); - + expect(true).assertEqual(Btname.MIXES5 == getNewName); done(); }) @@ -379,11 +370,11 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES5); + let result = bluetooth.setLocalName(Btname.NUM_TEST1); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1600 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.MIXES5 == getNewName); + expect(true).assertEqual(Btname.NUM_TEST1 == getNewName); done(); }) @@ -397,11 +388,11 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.NUM_TEST1); + let result = bluetooth.setLocalName(Btname.MIXES7); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_1700 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.NUM_TEST1 == getNewName); + expect(false).assertEqual(Btname.MIXES7 == getNewName); done(); }) @@ -415,14 +406,43 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.MIXES7); + let name = bluetooth.getLocalName(); + let set = bluetooth.setLocalName(''); + expect(set).assertFalse(); + let localName = bluetooth.getLocalName(); + expect(true).assertTrue(localName==name); + console.info('[bluetooth_js] getLocalName1800=' + JSON.stringify(localName)); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1900 + * @tc.name set LocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1900', 0, async function (done) { + let localName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1900 localName = '+ JSON.stringify(localName)); + expect(true).assertEqual(localName!=null); + let newName = 'bluetoothtest'; + let result = bluetooth.setLocalName(newName); expect(result).assertTrue(); let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1800 NewName = '+ JSON.stringify(getNewName)); - expect(false).assertEqual(Btname.MIXES7 == getNewName); + console.info('[bluetooth_js] LocalName_1900 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(newName == getNewName); + let result1=bluetooth.setLocalName(localName); + expect(result1).assertTrue(); + let getLocalName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalNam1900 localName ='+ JSON.stringify(getLocalName)); + expect(true).assertEqual(localName == getLocalName); done(); }) }) } +