From 181d37c37722086cd357542923e0446e4c60247e Mon Sep 17 00:00:00 2001 From: quanli Date: Thu, 3 Aug 2023 04:23:30 +0800 Subject: [PATCH] quanli1@huawei.com Signed-off-by: quanli --- .../src/main/js/test/BtConnection.test.js | 48 +++++++++++++++++-- .../main/js/test/openLogicalChannel.test.js | 2 +- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js b/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js index 5d1ce1ec7..5ce6a936c 100644 --- a/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js +++ b/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js @@ -84,7 +84,7 @@ describe('btConnectionTest', function() { bluetooth.on('pinRequired', onReceiveEvent); bluetooth.off('pinRequired', onReceiveEvent); } catch (error) { - console.error(`[bluetooth_js]PairDevice error, code is ${error.code}, + console.error(`[bluetooth_js]pinRequired error, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } @@ -130,8 +130,8 @@ describe('btConnectionTest', function() { /** * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400 - * @tc.name Test On pair StateChange - * @tc.desc Test bondStateChange ON api10 + * @tc.name Test pairDevice callback + * @tc.desc Test pairDevice callback api10 * @tc.type Function * @tc.level Level 3 */ @@ -142,15 +142,21 @@ describe('btConnectionTest', function() { } try { bluetooth.on('bondStateChange', BondStateParam); - bluetooth.pairDevice("11:22:55:66:33:44"); + bluetooth.pairDevice("11:22:55:66:33:44", err => { + if (err) { + console.info('pairDevice errCode: ' + err.code + ', errMessage: ' + err.message); + } + console.info('pairDevice, err: ' + JSON.stringify(err)); + }); + bluetooth.off('bondStateChange', BondStateParam); expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue(); expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue(); expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue(); - bluetooth.off('bondStateChange', BondStateParam); } catch (err) { console.error("errCode:" + err.code + ",errMessage:" + err.message); expect(error.code).assertEqual('2900099'); } + bluetooth.off('bondStateChange', BondStateParam); done(); }) @@ -238,6 +244,37 @@ describe('btConnectionTest', function() { done(); }) + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0900 + * @tc.name Test pairDevice promise + * @tc.desc Test pairDevice promise api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0900', 0, async function (done) { + function BondStateParam(data) { + console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data) + +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); + } + try { + bluetooth.on('bondStateChange', BondStateParam); + bluetooth.pairDevice("11:22:55:66:33:44").then((data) => { + console.info('pairDevice info success'); + }, err => { + console.info('pairDevice:errCode' + err.code + ', errMessage: ' + err.message); + }); + bluetooth.off('bondStateChange', BondStateParam); + expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue(); + expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue(); + expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue(); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + bluetooth.off('bondStateChange', BondStateParam); + done(); + }) + /** * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100 * @tc.name TEST scanmode @@ -335,6 +372,7 @@ describe('btConnectionTest', function() { console.error(`[bluetooth_js]bluetoothDeviceFin error, code is ${error.code},message is ${error.message}`); expect(error.code).assertEqual('2900099'); } + bluetooth.off('bluetoothDeviceFind', onReceiveEvent); done(); }) diff --git a/communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js b/communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js index c386aa920..15e2fc39d 100644 --- a/communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js +++ b/communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js @@ -250,7 +250,7 @@ export default function openLogicalChanneltest() { if (nfcOmaReaderList == undefined) { console.log("[NFC_test]23 This function is not supported because the phone NFC chip is ST chip."); } else { - nfcOmaChannel.close(); + nfcOmaSession.closeChannels(); console.info("[NFC_test] 23 The closeChannel test is successfully" ); let isChannelClosed = nfcOmaChannel.isClosed(); console.info("[NFC_test]23 Check whether the channel is disabled: " + isChannelClosed); -- GitLab