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 3fcc1d88092175732e6fe8db3a5a9ef55fa2c391..0e8cc094ef22cd9914f4e7453e42b3a219a9bb9f 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -143,28 +143,34 @@ describe('bluetoothBLETest', function() { let ret = gattClient.connect(); console.info('[bluetooth_js] gattClient getrssi connect:' + JSON.stringify(ret)) expect(ret).assertTrue(); - try { - 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); - done(); - }).catch(error => { - console.info('bluetooth getRssiValue has error: '+ JSON.stringify(error)); - expect(error.code).assertEqual('2900099'); - done(); - }); - }catch (error) { - console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, - message is ${error.message}`); - } - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi disconnect:' + disconnect); - expect(disconnect).assertEqual(false); + try { + 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); + done(); + }).catch(error => { + console.info('bluetooth getRssiValue has error: '+ JSON.stringify(error)); + let b=false; + if(err.code==2900099||err.code==-1) + { + b=true + } + expect(true).assertEqual(b); + done(); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }catch (error) { + console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, + message is ${error.message}`); + } done() - }) - /** + + + /** * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200 * @tc.name testgetRssiValue * @tc.desc Test testGetDeviceName api by callback. @@ -177,17 +183,28 @@ describe('bluetoothBLETest', function() { let ret = gattClient.connect(); console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) expect(ret).assertTrue(); - let promise = new Promise((resolve) => { - gattClient.getRssiValue((err, data)=> { + gattClient.getRssiValue((err, data)=> { + if(err) + { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(err)); + let b=false; + if(err.code==2900099||err.code==-1) + { + b=true + } + expect(true).assertEqual(b); + } + else + { 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) + expect(true).assertEqual(data!=null) + } + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + await sleep(3000); + done() }) /** diff --git a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js index 0d7b75f6da22a3827a3b52d6f524a60f37bdbb5d..23791fba81a9b4dff993d3409f3df49a2e8e3645 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js @@ -157,18 +157,23 @@ describe('bluetoothBLETest', function() { try { await gattClient.getRssiValue().then((data) => { console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); - let rssiLength = Object.keys(data).length; - console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(rssiLength)); - expect(rssiLength).assertEqual(0); + expect(true).assertEqual(data!=null); done(); }).catch(err => { console.info('bluetooth getRssiValue has error: '+ JSON.stringify(err)); + // expect(true).assertEqual(error.code==2900099||error.code==-1); + let b=false; + if(err.code==2900099||err.code==-1) + { + b=true + } + expect(true).assertEqual(b); done(); }); } catch (error) { console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, message is ${error.message}`); - expect(error.code).assertEqual('2900099'); + expect(false).assertEqual(true); done() } @@ -185,23 +190,35 @@ describe('bluetoothBLETest', function() { */ it('COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) { try { - let promise = new Promise((resolve) => { - gattClient.getRssiValue((err, data)=> { - if (err) { - console.error('getRssi failed '); - } - console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); - expect(true).assertFalse(); + function getRssi() { + return new Promise((resolve,reject) => { + gattClient.getRssiValue((err, data)=> { + if (err) { + console.error('getRssi failed '); + let b=false; + if(err.code==2900099||err.code==-1) + { + b=true + } + expect(true).assertEqual(b); + } + else + { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(true).assertEqual(data!=null ); + } + resolve(); + }); }); - resolve() - }) - await promise.then(done) + } + await getRssi(); } catch (error) { console.error(`[bluetooth_js]GetRssiValue_0200 error, code is ${error.code}, message is ${error.message}`); - expect(error.code).assertEqual('2900099'); - done() - } + expect(false).assertEqual(true); + } + await sleep(2000); + done(); }) /**