diff --git a/communication/BUILD.gn b/communication/BUILD.gn index a732eb404bf19af3338b4c9936a57ee98b2c1bcd..74a75e273c533ccc507a42e6aded7613809b9f39 100644 --- a/communication/BUILD.gn +++ b/communication/BUILD.gn @@ -27,6 +27,7 @@ group("communication") { "dsoftbus/rpc_request:ActsRpcRequestJsTest", "nfc_Controller:ActsNFCJSTest", "nfc_ErrorCode:ActsNFCErrorJSTest", + "nfc_SecureElement:ActsnfcSEServiceTest", "wifi_ErrorCode201:ActsErrorcode201Test", "wifi_ErrorCode202:ActsErrorcode202Test", "wifi_ErrorCode401:ActsErrorcode401Test", diff --git a/communication/bluetooth_gatt/signature/openharmony_sx.p7b b/communication/bluetooth_gatt/signature/openharmony_sx.p7b index 9a224618b8d226815a7c692e3b09197a6796b502..558d8cf611924e14579b365e6d031031ef46b528 100644 Binary files a/communication/bluetooth_gatt/signature/openharmony_sx.p7b and b/communication/bluetooth_gatt/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_gatt/src/main/config.json b/communication/bluetooth_gatt/src/main/config.json index 2309c75120be51feb4782be9abd0577afc97c151..43d1ed232171adc2add89e4a3d48314ca85861ca 100644 --- a/communication/bluetooth_gatt/src/main/config.json +++ b/communication/bluetooth_gatt/src/main/config.json @@ -88,47 +88,27 @@ "reqPermissions": [ { "name": "ohos.permission.USE_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" }, { "name": "ohos.permission.MANAGE_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" }, { "name": "ohos.permission.DISCOVER_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" }, { - "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + "name": "ohos.permission.LOCATION", + "reason": "" }, { - "name": "ohos.permission.LOCATION", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "" + }, + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "" }, { "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", diff --git a/communication/bluetooth_gatt/src/main/js/test/BtBleManager.test.js b/communication/bluetooth_gatt/src/main/js/test/BtBleManager.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6be445b98ff0d65428f5b317298383b1a9d9c85e --- /dev/null +++ b/communication/bluetooth_gatt/src/main/js/test/BtBleManager.test.js @@ -0,0 +1,1032 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.ble'; +import btAccess from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btBleManagerTest() { +describe('btBleManagerTest', function() { + let gattServer = null; + let gattClient = null; + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch(sta){ + case 0: + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); + btAccess.enableBluetooth(); + await sleep(10000); + break; + case 1: + console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); + break; + case 3: + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); + btAccess.enableBluetooth(); + await sleep(10000); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + + beforeAll(async function (done) { + console.info('beforeAll called') + gattServer = bluetooth.createGattServer(); + console.info('bluetooth ble create gattserver result:' + gattServer); + gattClient = bluetooth.createGattClientDevice('04:30:02:01:00:07'); + console.info('bluetooth ble create gattclientdevice result:' + gattClient); + done(); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done(); + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(async function (done) { + console.info('afterAll called') + gattClient.close(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api10. + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100', 0, async function (done) { + 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:32, + 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 + }], + includeDeviceName:false + } + 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 { + bluetooth.startAdvertising(setting,advData,advResponse); + console.info('[bluetooth_js]startAdvertising1 success'); + bluetooth.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising1 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100 + * @tc.name test gatt connect and disconnect + * @tc.desc Test api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100', 0, async function (done) { + try { + gattClient.connect(); + await sleep(2000); + gattClient.disconnect(); + } catch(error) { + console.error(`[bluetooth_js]disconnect failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200 + * @tc.name testGetConnectedBLEDevices + * @tc.desc Test api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200', 0, function () { + try { + let result = bluetooth.getConnectedBLEDevices(); + console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result) + + "length:" +result.length); + expect(true).assertTrue(result.length > 0); + } catch (error) { + console.error(`[bluetooth_js]getConnDev failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300 + * test Client BLEconnectStateChange + * @tc.desc Test on and off api10 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300', 0, async function (done) { + try { + function ConnectStateChanged(state) { + console.log('bluetooth connect state changed'); + let connectState = state.state; + console.info('[bluetooth_js] state changed' + connectState) + expect(true).assertEqual(connectState!=null); + } + gattClient.on('BLEConnectionStateChange', ConnectStateChanged); + gattClient.off("BLEConnectionStateChange"); + done(); + } catch (error) { + console.error(`[bluetooth_js]GattConnect failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100 + * @tc.name testgetRssiValue + * @tc.desc Test getRssiValue api10 by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100', 0, async function (done) { + try { + await gattClient.getRssiValue().then((data) => { + console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); + 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 error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200 + * @tc.name testgetRssiValue + * @tc.desc Test testGetDeviceName api10 by callback. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200', 0, async function (done) { + try { + 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(); + }); + }); + } + await getRssi(); + } catch (error) { + console.error(`[bluetooth_js]GetRssiValue error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + await sleep(2000); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100 + * @tc.name testGetDeviceName + * @tc.desc Test GetDeviceName api10 by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100', 0, async function (done) { + try { + await gattClient.getDeviceName().then((data) => { + console.info('[bluetooth_js] device name:' + JSON.stringify(data)) + expect(true).assertEqual(data != null); + done(); + }).catch(err => { + console.error('[bluetooth_js] bluetooth getDeviceName has error: '+ JSON.stringify(err)); + expect(err.code).assertEqual(2900099); + }); + } catch (error) { + console.error(`[bluetooth_js]GetDeviceName failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200 + * @tc.name testGetDeviceName + * @tc.desc Test testGetDeviceName api10 by callback. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200', 0, async function (done) { + try { + gattClient.getDeviceName((err, data)=> { + if (err) { + console.error('getname1 failed '); + } + console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); + expect(true).assertEqual(data != null); + }); + await sleep(2000); + done(); + } catch (error) { + console.error(`[bluetooth_js]GetDeviceName failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100 + * @tc.name testGetServices + * @tc.desc Test GetServices api10 by promise. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100', 0, async function (done) { + try { + 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(); + }); + } catch (error) { + console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200 + * @tc.name testGetServices + * @tc.desc Test GetServices api10 by callback. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200', 0, async function (done) { + try { + 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); + } + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100', 0, function (done) { + try { + gattClient.setBLEMtuSize(500); + console.info("[bluetooth_js]setBLEMtuSize success"); + } catch (error) { + console.error(`[bluetooth_js]MtuSize failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api10 by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900', 0, async function (done) { + let descriptors = []; + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc}; + descriptors[0] = descriptor; + + let bufferCCC = new ArrayBuffer(8); + let cccV = new Uint8Array(bufferCCC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: bufferCCC, descriptors:descriptors}; + try { + gattClient.readCharacteristicValue(characteristic); + done(); + } catch (error) { + console.error(`[bluetooth_js]readDescrValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api10 by callback. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000', 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 descriptors = []; + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc}; + descriptors[0] = descriptor; + + let bufferCCC = new ArrayBuffer(8); + let cccV = new Uint8Array(bufferCCC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: bufferCCC, descriptors:descriptors}; + try { + gattClient.readCharacteristicValue(characteristic, readCcc); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteristicValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100 + * @tc.name test characteristicReadOn + * @tc.desc Test On and off api10. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100', 0, async function (done) { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1123; + function ReadCharacteristicReq(CharacteristicReadRequest) { + let deviceId = CharacteristicReadRequest.deviceId; + let transId = CharacteristicReadRequest.transId; + let offset = CharacteristicReadRequest.offset; + let characteristicUuid = CharacteristicReadRequest.characteristicUuid; + + let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC}; + + try { + gattServer.sendResponse(serverResponse); + } catch (err) { + console.error("sendResponese errCode:" + err.code + ",errMessage:" + err.message); + } + } + + try { + await gattServer.on("characteristicRead", ReadCharacteristicReq); + done(); + } catch (err) { + console.error("characteristicReadOn errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + gattServer.off("characteristicRead"); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api10 by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300', 0, async function (done) { + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 11; + let descriptor = { + serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', + descriptorValue: bufferDesc + }; + try { + gattClient.readDescriptorValue(descriptor); + expect(true).assertFalse(); + done(); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api10 by callback. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400', 0, async function (done) { + function readDesc(code, BLEDescriptor) { + if (code.code != 0) { + return; + } + console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid); + let value = new Uint8Array(BLEDescriptor.descriptorValue); + console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 11; + let descriptor = { + serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', + descriptorValue: bufferDesc + }; + try { + gattClient.readDescriptorValue(descriptor, readDesc); + expect(true).assertFalse(); + done(); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500 + * @tc.name test ReadDescriptorOn + * @tc.desc Test On and Off api10. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500', 0, async function (done) { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1011; + function ReadDescriptorReq(DescriptorReadReq) { + let deviceId = DescriptorReadReq.deviceId; + let transId = DescriptorReadReq.transId; + let offset = DescriptorReadReq.offset; + let characteristicUuid = DescriptorReadReq.characteristicUuid; + + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferCCC}; + gattServer.sendResponse(serverResponse); + console.info("[bluetooth_js] DesRedon jsondata:" + + 'deviceId:' + deviceId + 'transId:' +transId + 'offset:' + + offset +'descriptorUuid:' + DescriptorReadReq.descriptorUuid + + 'characteristicUuid:' +characteristicUuid + + 'serviceUuid:' + DescriptorReadReq.serviceUuid); + expect(true).assertEqual(DescriptorReadReq != null); + } + await gattServer.on("descriptorRead", ReadDescriptorReq); + await gattServer.off("descriptorRead"); + } catch (error) { + console.error(`[bluetooth_js]readDescrValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800 + * @tc.name testWriteCharacteristicValue callback + * @tc.desc Test Client WriteCharacteristicValue api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic, bluetooth.GattWriteType.WRITE, (err, data) => { + console.info('writeCharacteristicValue err:' + JSON.stringify(err) + ',writeCharacteristicValue data:' + JSON.stringify(data)); + }); + } catch (error) { + console.error(`[bluetooth_js]writeCharacteristicValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900 + * @tc.name testWriteCharacteristicValue promise + * @tc.desc Test Client WriteCharacteristicValue api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic, bluetooth.GattWriteType.WRITE_NO_RESPONSE).then(() => { + console.info("writeCharacteristicValue"); + }, err => { + console.error("writeCharacteristicValue:errCode" + err.code + ",errMessage:" + err.message); + }); + } catch (error) { + console.error(`[bluetooth_js]writeCharacteristicValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000 + * @tc.name test characteristicWriteOn + * @tc.desc Test on and off api10. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000', 0, async function (done) { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + function WriteCharacteristicReq(CharacteristicWriteRequest) { + let deviceId = CharacteristicWriteRequest.deviceId; + let transId = CharacteristicWriteRequest.transId; + let offset = CharacteristicWriteRequest.offset; + let isPrepared = CharacteristicWriteRequest.isPrepared; + let needRsp = CharacteristicWriteRequest.needRsp; + let value = new Uint8Array(CharacteristicWriteRequest.value); + let characteristicUuid = CharacteristicWriteRequest.characteristicUuid; + let serviceUuid = CharacteristicWriteRequest.serviceUuid; + console.info('CharacteristicWriteRequest deviceId:' + deviceId); + console.info('CharacteristicWriteRequest transId:' + transId); + console.info('CharacteristicWriteRequest offset:' + offset); + console.info('CharacteristicWriteRequest isPrepared:' + isPrepared); + console.info('CharacteristicWriteRequest needRsp:' + needRsp); + console.info('CharacteristicWriteRequest value:' + value); + console.info('CharacteristicWriteRequest characteristicUuid:' + characteristicUuid); + console.info('CharacteristicWriteRequest serviceUuid:' + serviceUuid); + + cccValue[0] = value[0]; + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferCCC}; + gattServer.sendResponse(serverResponse); + } + gattServer.on("characteristicWrite", WriteCharacteristicReq); + gattServer.off("characteristicWrite"); + } catch (error) { + console.error(`[bluetooth_js]writeCharacteristicValue failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000 + * @tc.name testWriteDescriptorValue + * @tc.desc Test Client WriteDescriptorValue promsie api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000', 0, function () { + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 22; + let descriptor = { + serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', + descriptorValue: bufferDesc + }; + try { + gattClient.writeDescriptorValue(descriptor).then(() => { + console.info("writeDescriptorValue"); + }, err => { + console.error("writeDescriptorValue:errCode" + err.code + ",errMessage:" + err.message); + }); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100 + * @tc.name testWriteDescriptorValue + * @tc.desc Test Client WriteDescriptorValue callback api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100', 0, function () { + let bufferDesc = new ArrayBuffer(8); + let descV = new Uint8Array(bufferDesc); + descV[0] = 22; + let descriptor = { + serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', + descriptorValue: bufferDesc + }; + try { + gattClient.writeDescriptorValue(descriptor, (err, data) => { + console.info('writeDescriptorValue err:' + JSON.stringify(err) + ',writeDescriptorValue data:' + JSON.stringify(data)); + }); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200 + * @tc.name test WriteDescriptorOn + * @tc.desc Test on and off api10. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200', 0, async function (done) { + try { + let arrayBufferDesc = new ArrayBuffer(8); + let descValue = new Uint8Array(arrayBufferDesc); + function WriteDescriptorReq(DescriptorWriteRequest) { + let deviceId = DescriptorWriteRequest.deviceId; + let transId = DescriptorWriteRequest.transId; + let offset = DescriptorWriteRequest.offset; + let isPrepared = DescriptorWriteRequest.isPrepared; + let needRsp = DescriptorWriteRequest.needRsp; + let value = new Uint8Array(DescriptorWriteRequest.value); + let descriptorUuid = DescriptorWriteRequest.descriptorUuid; + descValue[0] = value[0]; + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferDesc}; + gattServer.sendResponse(serverResponse); + console.info("[bluetooth_js] desWriOn jsondata: " +'deviceId: ' + + deviceId + 'transId:' + transId + 'offset:' + offset +'descriptorUuid:' + + descriptorUuid + 'charUuid:' + DescriptorWriteRequest.characteristicUuid + + 'serviceUuid:' + DescriptorWriteRequest.serviceUuid + + 'value:' + DescriptorWriteRequest.value + 'needRsp' + + needRsp + 'isPrepared:' +isPrepared ); + expect(true).assertEqual(DescriptorWriteRequest != null); + } + gattServer.on("descriptorWrite", WriteDescriptorReq); + gattServer.off("descriptorWrite"); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400 + * @tc.name test BLECharacteristicChangeON + * @tc.desc Test On and off api10. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400', 0, async function (done) { + try { + function CharacteristicChange(CharacteristicChangeReq) { + let serviceUuid = CharacteristicChangeReq.serviceUuid; + let characteristicUuid = CharacteristicChangeReq.characteristicUuid; + let value = new Uint8Array(CharacteristicChangeReq.characteristicValue); + expect(true).assertEqual(CharacteristicChangeReq != null); + } + gattClient.on('BLECharacteristicChange', CharacteristicChange); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + gattClient.off('BLECharacteristicChange'); + } catch (error) { + console.error(`[bluetooth_js]BLECharacteristicChangeON failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100 + * @tc.name test setCharacteristicChangeNotification callback + * @tc.desc Test setCharacteristicChangeNotification api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + try { + gattClient.connect(); + gattClient.setCharacteristicChangeNotification(characteristic, true, (err) => { + console.info('setCharacteristicChangeNotification err:' + JSON.stringify(err)); + }); + done(); + } catch (err) { + console.error('setCharacteristicChangeNotification failed errCode: ' + err.code + ', errMessage: ' + err.message); + expect(true).assertEqual(err.code == '401' || err.code == '2900099'); + done(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200 + * @tc.name test setCharacteristicChangeNotification promise + * @tc.desc Test setCharacteristicChangeNotification api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + try { + gattClient.setCharacteristicChangeNotification(characteristic, true).then(() => { + console.info("setCharacteristicChangeNotification"); + }); + done(); + } catch (err) { + console.error('setCharacteristicChangeNotification failed errCode: ' + err.code + ', errMessage: ' + err.message); + expect(err.code).assertEqual('401'); + done(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300 + * @tc.name test setCharacteristicChangeIndication callback + * @tc.desc Test setCharacteristicChangeIndication api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + try { + gattClient.setCharacteristicChangeIndication(characteristic, true, (err) => { + console.info('setCharacteristicChangeIndication err:' + JSON.stringify(err)); + }); + done(); + } catch (err) { + console.error('setCharacteristicChangeIndication failed errCode: ' + err.code + ', errMessage: ' + err.message); + expect(err.code).assertEqual('401'); + done(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400 + * @tc.name test setCharacteristicChangeIndication promise + * @tc.desc Test setCharacteristicChangeIndication api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + try { + gattClient.setCharacteristicChangeIndication(characteristic, true).then(() => { + console.info("setCharacteristicChangeIndication"); + }); + done(); + } catch (err) { + console.error('setCharacteristicChangeIndication failed errCode: ' + err.code + ', errMessage: ' + err.message); + expect(err.code).assertEqual('401'); + done(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100 + * @tc.name test GattClientDevice on blemtuchange + * @tc.desc test GattClientDevice on blemtuchange api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100', 0, async function (done) { + let serverNumber = -1; + function onReceiveEvent(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth onReceiveEvent Number: ' + number); + serverNumber = number; + } + } + try { + gattClient.on('BLEMtuChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth mtu changed errCode:" + err.code + ",bluetooth mtu changed errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + gattClient.off('BLEMtuChange', onReceiveEvent); + done(); + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200 + * @tc.name test GattClientDevice off blemtuchange + * @tc.desc test GattClientDevice off blemtuchange api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200', 0, async function (done) { + let serverNumber = -1; + function onReceiveEvent(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth onReceiveEvent Number: ' + number); + serverNumber = number; + } + } + gattClient.on('BLEMtuChange', onReceiveEvent); + try { + gattClient.off('BLEMtuChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth mtu changed off errCode:" + err.code + ",bluetooth mtu changed off errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + +}) +} + + diff --git a/communication/bluetooth_gatt/src/main/js/test/BtBleService.test.js b/communication/bluetooth_gatt/src/main/js/test/BtBleService.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b814b6da21b6bcf5096a86e8af621ba2c5a97f46 --- /dev/null +++ b/communication/bluetooth_gatt/src/main/js/test/BtBleService.test.js @@ -0,0 +1,372 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.ble'; +import btAccess from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btBleServiceTest() { +describe('btBleServiceTest', function() { + + let gattServer = null; + let gattClient = null; + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch(sta){ + case 0: + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); + btAccess.enableBluetooth(); + await sleep(10000); + break; + case 1: + console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); + break; + case 3: + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); + btAccess.enableBluetooth(); + await sleep(10000); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(async function (done) { + console.info('beforeAll called') + await tryToEnableBt() + gattServer = bluetooth.createGattServer(); + console.info('bluetooth ble create gattserver result:' + gattServer); + gattClient = bluetooth.createGattClientDevice('04:30:02:01:00:00'); + console.info('bluetooth ble create gattclientdevice result:' + gattClient); + done() + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done(); + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + gattServer.close(); + }) + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100 + * @tc.name test Server connectStateChange + * @tc.desc Test on and off api10 . + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100', 0, async function (done) { + try { + function Connected(BLEConnectChangedState) { + let deviceId = BLEConnectChangedState.deviceId; + let status = BLEConnectChangedState.state; + console.info("[bluetooth_js] connectStateChange jsondata:" + +'deviceId:' + deviceId + 'status:' + status); + expect(true).assertEqual(BLEConnectChangedState !=null); + } + gattServer.on("connectStateChange", Connected); + gattServer.off("connectStateChange"); + } catch (error) { + console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100 + * @tc.name testAddService + * @tc.desc Test AddService api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: false, + characteristics:characteristics, includeServices:[]}; + try { + gattServer.addService(gattService); + } catch (error) { + console.error(`[bluetooth_js]AddService2 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200 + * @tc.name testAddService + * @tc.desc Test api10 401 - characteristics of service is null. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200', 0, async function (done) { + try { + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + } catch (error) { + console.error(`[bluetooth_js]AddService2 failed, code is ${error.code},message is ${error.message}`); + expect(true).assertEqual(error.code == '2900099' || error.code == '401'); + } + done(); + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100 + * @tc.name testNotifyCharacteristicChanged callback + * @tc.desc Test NotifyCharacteristicChanged api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false}; + try { + gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic, (err, data) => { + console.info('notifyCharacteristicChanged err:' + JSON.stringify(err) + ',notifyCharacteristicChanged data:' + JSON.stringify(data)); + }); + } catch (error) { + console.error('[bluetooth_js]notifyCharacteristicChanged1 failed, code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200 + * @tc.name testNotifyCharacteristicChanged promise + * @tc.desc Test NotifyCharacteristicChanged api10. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; + let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false}; + try { + gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic).then(() => { + console.info("notifyCharacteristicChanged"); + }, err => { + console.error("notifyCharacteristicChanged:errCode" + err.code + ",errMessage:" + err.message); + }); + } catch (error) { + console.error('[bluetooth_js]notifyCharacteristicChanged2 failed, code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100', 0, async function (done) { + try { + 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: 0, offset: 0, value: arrayBuffer}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done() + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200', 0, async function (done) { + try { + 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}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done() + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse 401 -null parameter. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300', 0, async function (done) { + try { + gattServer.sendResponse(); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]sendResponse3 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse 401 -error parameter. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let value = new Uint8Array(arrayBuffer); + value[0] = 1; + let ServerResponse = {transId: 1, + status: -1, offset: 0, value: arrayBuffer}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100 + * @tc.name test gattserver on blemtuchange + * @tc.desc test gattserver on blemtuchange api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100', 0, async function (done) { + try { + gattServer.on('BLEMtuChange', (err, data)=> { + console.info('BLEMtuChange on err ' + JSON.stringify(err)); + console.info('BLEMtuChange on value' + JSON.stringify(data)); + }) + } catch (err) { + console.error("bluetooth mtu changed on errCode:" + err.code + ",bluetooth mtu changed on errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + gattServer.off('BLEMtuChange', (err, data)=> { + console.info('BLEMtuChange off err ' + JSON.stringify(err)); + console.info('BLEMtuChange off value' + JSON.stringify(data)); + }) + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200 + * @tc.name test gattserver off blemtuchange + * @tc.desc test gattserver off blemtuchange api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200', 0, async function (done) { + gattServer.on('BLEMtuChange', (err, data)=> { + console.info('BLEMtuChange on err ' + JSON.stringify(err)); + console.info('BLEMtuChange on value' + JSON.stringify(data)); + }) + try { + gattServer.off('BLEMtuChange', (err, data)=> { + console.info('BLEMtuChange off err ' + JSON.stringify(err)); + console.info('BLEMtuChange off value' + JSON.stringify(data)); + }) + } catch (err) { + console.error("bluetooth mtu changed off errCode:" + err.code + ",bluetooth mtu changed off errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + +}) +} + + diff --git a/communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js b/communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js index e250ee0ea3cd7be59595f854226e00a392ce13fa..08d9bbe712a3151ff1034d3a18bcc236f0ba53e6 100644 --- a/communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js +++ b/communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js @@ -75,13 +75,14 @@ describe('btGattManagerTest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_GATTCLICONNECT_0100', 0, async function (done) { - let ret = gattClient.connect(); - await sleep(2000); - console.info('[bluetooth_js] gattClient connect' + ret) - expect(ret).assertFalse(); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt disconnect:' + disconnect); - expect(disconnect).assertEqual(false); + try { + gattClient.connect(); + await sleep(2000); + gattClient.disconnect(); + } catch (error) { + console.info('[bluetooth_js] gatt disconnect:' + disconnect); + expect(error.code).assertEqual('2900099'); + } done(); }) @@ -113,12 +114,14 @@ describe('btGattManagerTest', function() { console.info('[bluetooth_js] state changed' + connectState) expect(true).assertEqual(connectState!=null); } - await gattClient.on('BLEConnectionStateChange', ConnectStateChanged); - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient connect' + ret) - expect(ret).assertFalse(); - gattClient.disconnect(); - await sleep(2000); + try { + await gattClient.on('BLEConnectionStateChange', ConnectStateChanged); + gattClient.connect(); + gattClient.disconnect(); + } catch (error) { + console.info('[bluetooth_js] gatt disconnect:' + disconnect); + expect(error.code).assertEqual('2900099'); + } await gattClient.off("BLEConnectionStateChange"); done(); }) @@ -131,9 +134,7 @@ describe('btGattManagerTest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0100', 0, async function (done) { - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getrssi connect:' + JSON.stringify(ret)) - expect(ret).assertFalse(); + gattClient.connect(); try { await gattClient.getRssiValue().then((data) => { console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); @@ -150,14 +151,13 @@ describe('btGattManagerTest', function() { expect(true).assertEqual(b); done(); }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi disconnect:' + disconnect); - expect(disconnect).assertEqual(false); + gattClient.disconnect(); }catch (error) { - console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, + console.error(`[bluetooth_js]error, code is ${error.code}, message is ${error.message}`); + expect(error.code).assertEqual('2900099'); } - done() + done(); }) @@ -169,31 +169,32 @@ describe('btGattManagerTest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0200', 0, async function (done) { - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) - expect(ret).assertFalse(); - 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) - { + try { + gattClient.connect(); + 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(true).assertEqual(data!=null) - } - }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - await sleep(3000); - done() + } + expect(true).assertEqual(b); + } + else + { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(true).assertEqual(data!=null) + } + }); + gattClient.disconnect(); + } catch (error) { + console.error(`[bluetooth_js]error, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); }) /** @@ -204,22 +205,24 @@ describe('btGattManagerTest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0100', 0, async function (done) { - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret)) - expect(ret).assertFalse(); - await gattClient.getDeviceName().then((data) => { - console.info('[bluetooth_js] device name' + JSON.stringify(data)) - expect(true).assertEqual(data != null); - done(); - }).catch(err => { - console.error('bluetooth getDeviceName has error: '+ err); - expect(err.code).assertEqual(2900099); - done(); - }); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - + try { + gattClient.connect(); + await gattClient.getDeviceName().then((data) => { + console.info('[bluetooth_js] device name' + JSON.stringify(data)) + expect(true).assertEqual(data != null); + done(); + }).catch(err => { + console.error('bluetooth getDeviceName has error: '+ err); + expect(err.code).assertEqual(2900099); + done(); + }); + gattClient.disconnect(); + } catch (error) { + console.error(`[bluetooth_js]error, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); }) @@ -231,17 +234,19 @@ describe('btGattManagerTest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0200', 0, async function (done) { - let ret = gattClient.connect(); - console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret)) - expect(ret).assertFalse(); - gattClient.getDeviceName((err, data)=> { - console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); - console.info('[bluetooth_js]getname err code:'+JSON.stringify(err)); - expect(true).assertEqual(data != null); - let disconnect = gattClient.disconnect(); - console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect); - expect(disconnect).assertEqual(false); - }); + try { + gattClient.connect(); + gattClient.getDeviceName((err, data)=> { + console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); + console.info('[bluetooth_js]getname err code:'+JSON.stringify(err)); + expect(true).assertEqual(data != null); + gattClient.disconnect(); + }); + } catch (error) { + console.error(`[bluetooth_js]error, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } done(); }) @@ -253,21 +258,24 @@ describe('btGattManagerTest', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_GETSERVICE_0100', 0, async function (done) { - let ret = gattClient.connect(); - console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret)) - expect(ret).assertFalse(); - 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); + try { + gattClient.connect(); + 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(); + }); + gattClient.disconnect(); + } catch (error) { + console.error(`[bluetooth_js]error, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); }) /** diff --git a/communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js b/communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js index 937b62b44c8a18e7295eb60e7dea7af39e94000a..6d8276568d4545e8c2b47a91f2c78c207e06c3f3 100644 --- a/communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js +++ b/communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js @@ -81,13 +81,14 @@ describe('btGattServiceTest', function() { let status = BLEConnectChangedState.state; console.info("[bluetooth_js] connectStateChange jsondata:" +'deviceId:' + deviceId + 'status:' + status); - expect(true).assertEqual(BLEConnectChangedState !=null); - } - await gattServer.on("connectStateChange", Connected); - let ret = gattClient.connect(); - await sleep(2000); - console.info('[bluetooth_js] gattClient connect' + ret) - expect(ret).assertFalse(); + } + try { + await gattServer.on("connectStateChange", Connected); + gattClient.connect(); + } catch (error) { + console.error(`[bluetooth_js]code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } await gattServer.off("connectStateChange"); done(); }) diff --git a/communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js b/communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js index 0f09829d1eb1b1515ff4d77fa4d9295da5fc6289..b0f2ba5bee2ed5b7a4c5334223cb19496e9c6cef 100644 --- a/communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js +++ b/communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js @@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() { beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); - gattClient = bluetooth.BLE.createGattClientDevice("92:3A:C0:3A:4C:28"); + gattClient = bluetooth.BLE.createGattClientDevice('92:3A:C0:3A:4C:28'); }) beforeEach(async function(done) { console.info('beforeEach called') @@ -78,15 +78,21 @@ describe('btManagerGattManagerTest', function() { it('SUB_COMMUNICATION_BTMANAGER_GATTCONNECT_0100', 0, async function (done) { try { gattClient.connect(); - await sleep(2000); + console.info(`[bluetooth_js]connect success`); + } + catch(error) { + console.info(`[bluetooth_js]connect failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + try { gattClient.disconnect(); - expect(true).assertFalse(); - } catch(error) { - console.error(`[bluetooth_js]disconnect failed, code is ${error.code}, - message is ${error.message}`); + console.info(`[bluetooth_js]disconnect success`); + } + catch(error) { + console.info(`[bluetooth_js]disconnect failed, code is ${error.code},message is ${error.message}`); expect(error.code).assertEqual('2900099'); } - done() + done(); }) /** @@ -147,28 +153,16 @@ describe('btManagerGattManagerTest', function() { */ it('SUB_COMMUNICATION_BTMANAGER_GETRSSIVALUE_0100', 0, async function (done) { try { - await gattClient.getRssiValue().then((data) => { - console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); - 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(); - }); + + let gattRssi = gattClient.getRssiValue().then((data) => { + console.info('[bluetooth_js] gattRssi: ' + gattRssi); + console.info('[bluetooth_js] gattRssi data: ' + JSON.stringify(data)); + }) } catch (error) { - console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, - message is ${error.message}`); - expect(false).assertEqual(true); - done() + console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code},message is ${error.message}`); + expect(true).assertEqual(error.code == '2900099' || error.code == 2900099 || error.code == -1); } - + done(); }) /** @@ -195,7 +189,6 @@ describe('btManagerGattManagerTest', function() { else { console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); - expect(true).assertEqual(data!=null ); } resolve(); }); @@ -203,11 +196,9 @@ describe('btManagerGattManagerTest', function() { } await getRssi(); } catch (error) { - console.error(`[bluetooth_js]GetRssiValue_0200 error, code is ${error.code}, - message is ${error.message}`); - expect(false).assertEqual(true); + console.error(`[bluetooth_js]GetRssiValue_0200 error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); } - await sleep(2000); done(); }) @@ -250,14 +241,13 @@ describe('btManagerGattManagerTest', function() { console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); expect(true).assertEqual(data != null); }); - await sleep(2000); done(); } catch (error) { - console.error(`[bluetooth_js]GetDeviceName_0200 failed, code is ${error.code}, - message is ${error.message}`); - expect(true).assertFalse(); - done() - } + console.error(`[bluetooth_js]GetDeviceName_0200 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done(); + } + done(); }) /** @@ -279,11 +269,11 @@ describe('btManagerGattManagerTest', function() { done(); }); } catch (error) { - console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code}, - message is ${error.message}`); - expect(true).assertFalse(); - done() - } + console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done(); + } + done(); }) /** @@ -307,7 +297,7 @@ describe('btManagerGattManagerTest', function() { }); } catch (error) { console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code},message is ${error.message}`); - expect(true).assertFalse(); + expect(error.code).assertEqual('2900099'); done(); } done(); diff --git a/communication/bluetooth_gatt/src/main/js/test/List.test.js b/communication/bluetooth_gatt/src/main/js/test/List.test.js index 21c625aaf70f0a519497cb2a4c7ab5052ae90fb2..3f5268ed7abd15e6725f1b1b72c04441a6b2d799 100644 --- a/communication/bluetooth_gatt/src/main/js/test/List.test.js +++ b/communication/bluetooth_gatt/src/main/js/test/List.test.js @@ -19,12 +19,15 @@ import btGattServiceTest from './BtGattService.test.js' import btManagerGattAdvertTest from './BtManagerGattAdvertiser.test.js' import btManagerGattManagerTest from './BtManagerGattManager.test.js' import btManagerGattServiceTest from './BtManagerGattService.test.js' +import btBleManagerTest from './BtBleManager.test.js' +import btBleServiceTest from './BtBleService.test.js' export default function testsuite() { - btGattAdvertTest() + btBleManagerTest() + btBleServiceTest() + btManagerGattManagerTest() btManagerGattServiceTest() btGattServiceTest() - btManagerGattAdvertTest() - btManagerGattManagerTest() btGattManagerTest() - + btManagerGattAdvertTest() + btGattAdvertTest() } diff --git a/communication/bluetooth_profile/signature/openharmony_sx.p7b b/communication/bluetooth_profile/signature/openharmony_sx.p7b index 9a224618b8d226815a7c692e3b09197a6796b502..f3e2f56511e212f80631617a1b7fcd020f5ecc0c 100644 Binary files a/communication/bluetooth_profile/signature/openharmony_sx.p7b and b/communication/bluetooth_profile/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_profile/src/main/config.json b/communication/bluetooth_profile/src/main/config.json index be7e6e67b672c79944d9cde31ee3614848f82b80..829cb928149af354df30eb3502bc1afc15355601 100644 --- a/communication/bluetooth_profile/src/main/config.json +++ b/communication/bluetooth_profile/src/main/config.json @@ -106,10 +106,6 @@ "when": "inuse" } }, - { - "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, { "name": "ohos.permission.DISCOVER_BLUETOOTH", "reason": "", @@ -129,6 +125,16 @@ ], "when": "inuse" } + }, + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } } ], "testRunner": { diff --git a/communication/bluetooth_profile/src/main/js/test/BtA2dp.test.js b/communication/bluetooth_profile/src/main/js/test/BtA2dp.test.js new file mode 100644 index 0000000000000000000000000000000000000000..443cee28f82a8a6b49b3b1fb2a60fab2079e0e58 --- /dev/null +++ b/communication/bluetooth_profile/src/main/js/test/BtA2dp.test.js @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.a2dp'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btA2dpTest() { +describe('btA2dpTest', function() { + let A2dpSourceProfile = null; + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch (sta) { + case 0: + bluetooth.enableBluetooth(); + await sleep(10000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1)); + break; + case 1: + console.info('[bluetooth_js] bt turning on:' + JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:' + JSON.stringify(sta)); + break; + case 3: + bluetooth.enableBluetooth(); + await sleep(10000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + A2dpSourceProfile = bluetooth.createA2dpSrcProfile(); + }) + beforeEach(async function (done) { + console.info('beforeEach called') + await tryToEnableBt() + done(); + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100 + * @tc.name test getPlayingState + * @tc.desc Test getPlayingState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100', 0, async function (done) { + try { + let state = A2dpSourceProfile.getPlayingState('11:22:33:44:55:66'); + assert(true).assertEqual(state == bluetooth.PlayingState.STATE_NOT_PLAYING || state == bluetooth.PlayingState.STATE_PLAYING); + } catch (err) { + console.error("bluetooth a2dp getPlayingState errCode:" + err.code + ",bluetooth a2dp getPlayingState errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200 + * @tc.name test PlayingState + * @tc.desc Test PlayingState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200', 0, async function (done) { + let statePlaying = bluetooth.PlayingState.STATE_PLAYING; + console.info("[bluetooth_js]PlayingState: " + JSON.stringify(statePlaying)); + expect(statePlaying).assertEqual(1); + let stateNotPlaying = bluetooth.PlayingState.STATE_NOT_PLAYING; + console.info("[bluetooth_js]PlayingState: " + JSON.stringify(stateNotPlaying)); + expect(stateNotPlaying).assertEqual(0); + done(); + }) + +}) +} \ No newline at end of file diff --git a/communication/bluetooth_profile/src/main/js/test/BtBaseProfile.test.js b/communication/bluetooth_profile/src/main/js/test/BtBaseProfile.test.js new file mode 100644 index 0000000000000000000000000000000000000000..63a78adeb23d574ea70c74944efa02ae0d5838f0 --- /dev/null +++ b/communication/bluetooth_profile/src/main/js/test/BtBaseProfile.test.js @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import btAccess from '@ohos.bluetooth.access'; +import a2dp from '@ohos.bluetooth.a2dp'; +import hid from '@ohos.bluetooth.hid'; +import hfp from '@ohos.bluetooth.hfp'; +import pan from '@ohos.bluetooth.pan'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btBaseProfileTest() { +describe('btBaseProfileTest', function() { + let A2dpSourceProfile = null; + let HandsFreeAudioGatewayProfile = null; + let HidHostProfile = null; + let PanProfile = null; + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch (sta) { + case 0: + btAccess.enableBluetooth(); + await sleep(10000); + let sta1 = btAccess.getState(); + console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1)); + break; + case 1: + console.info('[bluetooth_js] bt turning on:' + JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:' + JSON.stringify(sta)); + break; + case 3: + btAccess.enableBluetooth(); + await sleep(10000); + let sta2 = btAccess.getState(); + console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + A2dpSourceProfile = a2dp.createA2dpSrcProfile(); + HandsFreeAudioGatewayProfile = hfp.createHfpAgProfile(); + HidHostProfile = hid.createHidHostProfile(); + PanProfile = pan.createPanProfile(); + expect(true).assertEqual(A2dpSourceProfile != null && HandsFreeAudioGatewayProfile != null && HidHostProfile != null && PanProfile != null); + }) + beforeEach(async function (done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100 + * @tc.name test getConnectedDevices + * @tc.desc Test getConnectedDevices api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100', 0, async function (done) { + try { + let devices = A2dpSourceProfile.getConnectedDevices(); + console.info("address of connected devices list:" + devices); + expect(true).assertEqual(devices != null); + } catch (err) { + console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200 + * @tc.name test getConnectionState + * @tc.desc Test getConnectionState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200', 0, async function (done) { + try { + let state = A2dpSourceProfile.getConnectionState("11:22:33:AA:BB:FF"); + console.info("the connection state:" + state); + expect(true).assertEqual(state == 0 || state == 1 || state == 2); + } catch (err) { + console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300 + * @tc.name test on type: 'connectionStateChange' + * @tc.desc Test on type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + try { + A2dpSourceProfile.on('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + A2dpSourceProfile.off('connectionStateChange', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400 + * @tc.name test off type: 'connectionStateChange' + * @tc.desc Test off type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + A2dpSourceProfile.on('connectionStateChange', onReceiveEvent); + try { + A2dpSourceProfile.off('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500 + * @tc.name test getConnectedDevices + * @tc.desc Test getConnectedDevices api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500', 0, async function (done) { + try { + let devices = HandsFreeAudioGatewayProfile.getConnectedDevices(); + console.info("address of connected devices list:" + devices); + expect(true).assertEqual(devices != null); + } catch (err) { + console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600 + * @tc.name test getConnectionState + * @tc.desc Test getConnectionState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600', 0, async function (done) { + try { + let state = HandsFreeAudioGatewayProfile.getConnectionState("11:22:33:AA:BB:FF"); + console.info("the connection state:" + state); + expect(true).assertEqual(state == 0 || state == 1 || state == 2); + } catch (err) { + console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700 + * @tc.name test on type: 'connectionStateChange' + * @tc.desc Test on type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + console.info('connection state change:'+ data.deviceId); + console.info('connection state change:'+ data.state); + } + try { + HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + HandsFreeAudioGatewayProfile.off('connectionStateChange', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800 + * @tc.name test off type: 'connectionStateChange' + * @tc.desc Test off type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent); + try { + HandsFreeAudioGatewayProfile.off('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900 + * @tc.name test getConnectedDevices + * @tc.desc Test getConnectedDevices api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900', 0, async function (done) { + try { + let devices = HidHostProfile.getConnectedDevices(); + console.info("address of connected devices list:" + devices); + expect(true).assertEqual(devices != null); + } catch (err) { + console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000 + * @tc.name test getConnectionState + * @tc.desc Test getConnectionState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000', 0, async function (done) { + try { + let state = HidHostProfile.getConnectionState("11:22:33:AA:BB:FF"); + console.info("the connection state:" + state); + expect(true).assertEqual(state == 0 || state == 1 || state == 2); + } catch (err) { + console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100 + * @tc.name test on type: 'connectionStateChange' + * @tc.desc Test on type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + try { + HidHostProfile.on('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + HidHostProfile.off('connectionStateChange', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200 + * @tc.name test off type: 'connectionStateChange' + * @tc.desc Test off type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + HidHostProfile.on('connectionStateChange', onReceiveEvent); + try { + HidHostProfile.off('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300 + * @tc.name test getConnectedDevices + * @tc.desc Test getConnectedDevices api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300', 0, async function (done) { + try { + let devices = PanProfile.getConnectedDevices(); + console.info("address of connected devices list:" + devices); + expect(true).assertEqual(devices != null); + } catch (err) { + console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400 + * @tc.name test getConnectionState + * @tc.desc Test getConnectionState api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400', 0, async function (done) { + try { + let state = PanProfile.getConnectionState("11:22:33:AA:BB:FF"); + console.info("the connection state:" + state); + expect(true).assertEqual(state == 0 || state == 1 || state == 2); + } catch (err) { + console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500 + * @tc.name test on type: 'connectionStateChange' + * @tc.desc Test on type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + try { + PanProfile.on('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + PanProfile.off('connectionStateChange', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600 + * @tc.name test off type: 'connectionStateChange' + * @tc.desc Test off type: 'connectionStateChange' api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600', 0, async function (done) { + function onReceiveEvent(data) { + console.info('connection state change:'+ JSON.stringify(data)); + } + PanProfile.on('connectionStateChange', onReceiveEvent); + try { + PanProfile.off('connectionStateChange', onReceiveEvent); + } catch (err) { + console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertFalse(); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1700 + * @tc.name test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile + * @tc.desc Test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile api10. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_1700', 0, async function (done) { + try { + let asp = a2dp.createA2dpSrcProfile(); + let hp = hfp.createHfpAgProfile(); + let hhp = hid.createHidHostProfile(); + let pp = pan.createPanProfile(); + expect(true).assertEqual(asp != null); + expect(true).assertEqual(hp != null); + expect(true).assertEqual(hhp != null); + expect(true).assertEqual(pp != null); + } catch (err) { + console.error("bluetooth createProfile errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) +}) +} \ No newline at end of file diff --git a/communication/bluetooth_profile/src/main/js/test/List.test.js b/communication/bluetooth_profile/src/main/js/test/List.test.js index 94509e607401cdd1d9fec7f92f1cfb671763c350..553dc4802a61e0058cde3ab3ef1470127b5f0302 100644 --- a/communication/bluetooth_profile/src/main/js/test/List.test.js +++ b/communication/bluetooth_profile/src/main/js/test/List.test.js @@ -17,9 +17,13 @@ import btHfpConnTest from './BluetoothHfp.test.js' import btA2dpConnTest from './BluetoothA2dp.test.js' import btManagerHfpConnTest from './BtManagerHfp.test.js' import btManagerA2dpConnTest from './BtManagerA2dp.test.js' +import btA2dpTest from './BtA2dp.test.js' +import btBaseProfileTest from './BtBaseProfile.test.js' export default function testsuite() { + btBaseProfileTest() btHfpConnTest() btA2dpConnTest() btManagerHfpConnTest() btManagerA2dpConnTest() + btA2dpTest() } diff --git a/communication/bluetooth_scanpairing/signature/openharmony_sx.p7b b/communication/bluetooth_scanpairing/signature/openharmony_sx.p7b index e895f69bf14a789a3eef5896fafecf91d4c6389f..558d8cf611924e14579b365e6d031031ef46b528 100644 Binary files a/communication/bluetooth_scanpairing/signature/openharmony_sx.p7b and b/communication/bluetooth_scanpairing/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_scanpairing/src/main/config.json b/communication/bluetooth_scanpairing/src/main/config.json index be7e6e67b672c79944d9cde31ee3614848f82b80..3b9f35f0dda234d94580f1f8b81fc2b8361237f4 100644 --- a/communication/bluetooth_scanpairing/src/main/config.json +++ b/communication/bluetooth_scanpairing/src/main/config.json @@ -106,10 +106,6 @@ "when": "inuse" } }, - { - "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, { "name": "ohos.permission.DISCOVER_BLUETOOTH", "reason": "", @@ -129,6 +125,24 @@ ], "when": "inuse" } + }, + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "" + }, + { + "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason": "" } ], "testRunner": { diff --git a/communication/bluetooth_scanpairing/src/main/js/test/BluetoothBle.test.js b/communication/bluetooth_scanpairing/src/main/js/test/BluetoothBle.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b2e4a218c6eae26db00489c57a3d930d5964d510 --- /dev/null +++ b/communication/bluetooth_scanpairing/src/main/js/test/BluetoothBle.test.js @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.ble'; +import btAccess from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function bluetoothBleTest() { +describe('bluetoothBleTest', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch(sta){ + case 0: + btAccess.enableBluetooth(); + await sleep(10000); + let sta1 = btAccess.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + break; + case 1: + console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); + break; + case 3: + btAccess.enableBluetooth(); + await sleep(10000); + let sta2 = btAccess.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done(); + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100 + * @tc.name test startBLEScan + * @tc.desc Test startBLEScan api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100', 0, async function (done) { + function onReceiveEvent(data) { + console.info('BLE scan device find result = '+ JSON.stringify(data)); + } + try { + bluetooth.on("BLEDeviceFind", onReceiveEvent); + bluetooth.startBLEScan( + [{ + deviceId:"00:11:22:33:44:55", + name:"test", + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" + }], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + bluetooth.off("BLEDeviceFind", onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200 + * @tc.name test stopBLEScan + * @tc.desc Test stopBLEScan api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200', 0, async function (done) { + try { + bluetooth.stopBLEScan(); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300 + * @tc.name test on-BLEDeviceFind + * @tc.desc Test on-BLEDeviceFind api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300', 0, async function (done) { + function onReceiveEvent(data) { + console.info('bluetooth device find = '+ JSON.stringify(data)); + } + try { + bluetooth.on('BLEDeviceFind', onReceiveEvent); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + bluetooth.off('BLEDeviceFind', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400 + * @tc.name test off-BLEDeviceFind + * @tc.desc Test off-BLEDeviceFind api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400', 0, async function (done) { + function onReceiveEvent(data) { + console.info('bluetooth device find = '+ JSON.stringify(data)); + } + bluetooth.on('BLEDeviceFind', onReceiveEvent); + try { + bluetooth.off('BLEDeviceFind', onReceiveEvent); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) +}) +} + diff --git a/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js b/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js new file mode 100644 index 0000000000000000000000000000000000000000..5d1ce1ec74213e61b889f407529ff99ec401e5ac --- /dev/null +++ b/communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js @@ -0,0 +1,443 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.connection'; +import btAccess from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btConnectionTest() { +describe('btConnectionTest', function() { + let Btname = { + LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + CHINESES_TEST2 :'测试蓝牙名称正常', + } + + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch (sta) { + case 0: + btAccess.enableBluetooth(); + await sleep(10000); + let sta1 = btAccess.getState(); + console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1)); + break; + case 1: + console.info('[bluetooth_js] bt turning on:' + JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:' + JSON.stringify(sta)); + break; + case 3: + btAccess.enableBluetooth(); + await sleep(10000); + let sta2 = btAccess.getState(); + console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function (done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100 + * @tc.name Test pinRequired and setDevicePairing true + * @tc.desc Test pinRequired off api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100', 0, async function (done) { + function onReceiveEvent(data) { + console.info('pin required = '+ JSON.stringify(data)); + } + try { + bluetooth.on('pinRequired', onReceiveEvent); + bluetooth.off('pinRequired', onReceiveEvent); + } catch (error) { + console.error(`[bluetooth_js]PairDevice error, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200 + * @tc.name test get PairedDevices + * @tc.desc Test getPairedDevices api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200', 0, async function (done) { + try { + let ret = bluetooth.getPairedDevices(); + console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret)); + expect(true).assertEqual(ret.length >= 0); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300 + * @tc.name test getRemoteDeviceName + * @tc.desc Test get RemoteDeviceName api 10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300', 0, async function (done) { + try { + let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00"); + console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret)); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400 + * @tc.name Test On pair StateChange + * @tc.desc Test bondStateChange ON api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400', 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"); + 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'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500 + * @tc.name Test setDevicePairingConfirmation + * @tc.desc Test setDevicePairingConfirmation api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500', 0, async function (done) { + function PinRequiredParam(data) { + console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); + bluetooth.setDevicePairingConfirmation(data.deviceId, false); + console.info("[bluetooth_js] setDevicePairingConfirmation data.deviceId:" + data.deviceId); + } + try { + bluetooth.on('pinRequired', PinRequiredParam); + await sleep(2000); + bluetooth.off('pinRequired', PinRequiredParam); + } catch (err) { + console.error("setDevicePairingConfirmation errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600 + * @tc.name test getRemoteDeviceClass + * @tc.desc Test get RemoteDeviceClass api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600', 0, async function (done) { + try { + let DeviceClass = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00"); + console.info('[bluetooth_js]getRemoteDeviceClass majorClass:' + DeviceClass.majorClass); + console.info('[bluetooth_js]getRemoteDeviceClass majorMinorClass:' + DeviceClass.majorMinorClass); + console.info('[bluetooth_js]getRemoteDeviceClass classOfDevice:' + DeviceClass.classOfDevice); + } catch (err) { + console.error("getRemoteDeviceClass errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700 + * @tc.name Test setDevicePinCode callback + * @tc.desc Test setDevicePinCode api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700', 0, async function (done) { + try { + bluetooth.setDevicePinCode('11:22:33:44:55:66', '12345', (err, data) => { + console.info('setDevicePinCode callback,device name err:' + JSON.stringify(err) + ',device name:' + JSON.stringify(data)); + }); + } catch (err) { + console.error("setDevicePinCode callback errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800 + * @tc.name Test setDevicePinCode promise + * @tc.desc Test setDevicePinCode api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800', 0, async function (done) { + try { + bluetooth.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => { + console.info('setDevicePinCode promise'); + }, error => { + console.info('setDevicePinCode promise: errCode:' + error.code + ',errMessage' + error.message); + }) + } catch (err) { + console.error("setDevicePinCode promise errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100 + * @tc.name TEST scanmode + * @tc.desc TEST scanmode api10 by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100', 0, async function (done) { + let state = btAccess.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state == 2) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_NONE,0); + expect(result).assertTrue(); + let getScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0100 newscanmode = '+ JSON.stringify(getScanMode)); + expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_NONE); + result=bluetooth.setBluetoothScanMode(oldScanMode,0); + expect(result).assertTrue(); + let getOldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0100 setoldscanmode = '+ JSON.stringify(getOldScanMode)); + expect(true).assertEqual(oldScanMode == getOldScanMode); + done(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200 + * @tc.name TEST scanmode + * @tc.desc TEST scanmode api by promise. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200', 0, async function (done) { + + let state = btAccess.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state == 2) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0); + expect(result).assertTrue(); + let getScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0200 newscanmode = '+ JSON.stringify(getScanMode)); + expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE); + result=bluetooth.setBluetoothScanMode(oldScanMode,0); + expect(result).assertTrue(); + let getOldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0200 setoldscanmode = '+ JSON.stringify(getOldScanMode)); + expect(true).assertEqual(oldScanMode == getOldScanMode); + done(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } + }) + + /** + * @tc.number SUB_COMMUNICATION_BTMANAGER_DISCOVERY_0100 + * @tc.name TEST bluetoothDeviceFind on&off + * @tc.desc TEST bluetoothDeviceFind api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_DISCOVERY_0100', 0, async function (done) { + function onReceiveEvent(data) { + console.info('[bluetooth_js] Device' + JSON.stringify(data) + + 'length' + data.length); + expect(true).assertTrue(data.length > 0); + } + try { + bluetooth.on("bluetoothDeviceFind", onReceiveEvent); + let result = bluetooth.startBluetoothDiscovery(); + await sleep(3000); + console.info('[bluetooth_js] startDiscovery' + result); + expect(result).assertTrue(); + bluetooth.off('bluetoothDeviceFind', onReceiveEvent); + result = bluetooth.stopBluetoothDiscovery(); + console.info('[bluetooth_js] stopDiscovery' + result); + expect(true).assertTrue(); + } catch (error) { + console.error(`[bluetooth_js]bluetoothDeviceFin error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100 + * @tc.name setLocalName + * @tc.desc Test setLocalName api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.LETTERS_TEST); + expect(result).assertTrue(); + await sleep(1000); + try { + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.LETTERS_TEST == getNewName); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200 + * @tc.name setLocalName + * @tc.desc Test setLocalName api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200', 0, async function (done) { + try { + let result = bluetooth.setLocalName(Btname.CHINESES_TEST2); + expect(result).assertTrue(); + await sleep(1000); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.CHINESES_TEST2 == getNewName); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100 + * @tc.name test getBtConnectionState + * @tc.desc Test getBtConnectionState api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100', 0, async function (done) { + try { + let connectionState = bluetooth.getBtConnectionState(); + expect(true).assertEqual(connectionState == 0 || connectionState == 1 || connectionState == 2 || connectionState == 3); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200 + * @tc.name getProfileConnectionState + * @tc.desc Test getProfileConnectionState api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200', 0, async function (done) { + try { + let result = bluetooth.getProfileConnectionState(1); + expect(true).assertEqual(result == 0 || result == 1 || result == 2 || result == 3); + } catch (err) { + console.error("getProfileConnectionState errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100 + * @tc.name BluetoothTransport + * @tc.desc Test BluetoothTransport api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100', 0, async function (done) { + try { + let TRANSPORT_BR_EDR = bluetooth.BluetoothTransport.TRANSPORT_BR_EDR; + let TRANSPORT_LE = bluetooth.BluetoothTransport.TRANSPORT_LE; + expect(TRANSPORT_BR_EDR).assertEqual(0); + expect(TRANSPORT_LE).assertEqual(1); + } catch (err) { + console.error("BluetoothTransport errCode:" + err.code + ",errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) +}) +} \ No newline at end of file diff --git a/communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js b/communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js index 014f1c2eb515b1d9efdcbe0a296cd8101c2dbaff..88136f7276ff97d1a909ea99d81905e75d3673bc 100644 --- a/communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js +++ b/communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js @@ -73,9 +73,8 @@ describe('btPairTest', function() { */ it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0100', 0, async function (done) { try{ - let result = bluetooth.pairDevice("11:22:55:66:33:44"); + bluetooth.pairDevice("11:22:55:66:33:44"); await sleep(3000); - expect(true).assertEqual(result == false); } catch(err) { console.error("pairDevice errCode:" + err.code + ",errMessage:" + err.message); expect(err.code).assertEqual('2900099'); @@ -229,13 +228,13 @@ describe('btPairTest', function() { it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0700', 0, async function (done) { function PinRequiredParam(data) { console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); - bluetooth.setDevicePairingConfirmation(data.deviceId, false); + let ret = bluetooth.setDevicePairingConfirmation(data.deviceId, false); + expect(ret).assertFalse(); } try { bluetooth.BLE.on('pinRequired', PinRequiredParam); - let result = bluetooth.pairDevice("11:22:55:66:33:44"); + bluetooth.pairDevice("99:55:22:88:66:11"); await sleep(2000); - expect(true).assertEqual(result == false); bluetooth.BLE.off('pinRequired', PinRequiredParam); } catch(err) { console.error("errCode:" + err.code + ",errMessage:" + err.message); @@ -254,13 +253,13 @@ describe('btPairTest', function() { it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0800', 0, async function (done) { function PinRequiredParam(data) { console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); - bluetooth.setDevicePairingConfirmation(data.deviceId, true); + let ret = bluetooth.setDevicePairingConfirmation(data.deviceId, true); + expect(ret).assertTrue(); } try { bluetooth.BLE.on('pinRequired', PinRequiredParam); - let result = bluetooth.pairDevice("11:22:55:66:33:44"); - await sleep(2000); - expect(true).assertEqual(result == false); + bluetooth.pairDevice("66:88:33:55:22:99"); + await sleep(1000); bluetooth.BLE.off('pinRequired', PinRequiredParam); } catch(err) { console.error("errCode:" + err.code + ",errMessage:" + err.message); @@ -282,12 +281,12 @@ describe('btPairTest', function() { +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); } bluetooth.BLE.on('bondStateChange', BondStateParam); - let result = bluetooth.pairDevice("11:22:55:66:33:44"); + bluetooth.pairDevice("58:62:22:23:69:54"); 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.BLE.off('bondStateChange', BondStateParam); - done() + done(); }) }) diff --git a/communication/bluetooth_scanpairing/src/main/js/test/List.test.js b/communication/bluetooth_scanpairing/src/main/js/test/List.test.js index 283570b7cc836ce694180c8e75af4483122e8539..cad39a3535c949027c7f484aba833eea829a4f1b 100644 --- a/communication/bluetooth_scanpairing/src/main/js/test/List.test.js +++ b/communication/bluetooth_scanpairing/src/main/js/test/List.test.js @@ -20,13 +20,18 @@ import btPairTest from './BtPair.test.js' import btScanModeTest from './BtScanMode.test.js' import btManagerDiscoveryTest from './BtManagerDiscovery.test.js' import btManagerPairTest from './BtManagerPair.test.js' +import bluetoothBleTest from './BluetoothBle.test.js' +import btConnectionTest from './BtConnection.test.js' -export default function testsuite() { +export default function testsuite() { + bluetoothBleTest() + btConnectionTest() + btPairTest() btBleScanTest() btDiscoveryTest() btManagerBleScanTest() - btPairTest() btScanModeTest() btManagerDiscoveryTest() btManagerPairTest() + } diff --git a/communication/bluetooth_standard/signature/openharmony_sx.p7b b/communication/bluetooth_standard/signature/openharmony_sx.p7b index 9a224618b8d226815a7c692e3b09197a6796b502..d894a46f7e2b42766e1ada2429afba8256142292 100644 Binary files a/communication/bluetooth_standard/signature/openharmony_sx.p7b and b/communication/bluetooth_standard/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_standard/src/main/config.json b/communication/bluetooth_standard/src/main/config.json index 2881d7e36b17fb50f9d69629c2008eee39328eab..43d1ed232171adc2add89e4a3d48314ca85861ca 100644 --- a/communication/bluetooth_standard/src/main/config.json +++ b/communication/bluetooth_standard/src/main/config.json @@ -88,47 +88,31 @@ "reqPermissions": [ { "name": "ohos.permission.USE_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + "reason": "" }, { "name": "ohos.permission.MANAGE_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" }, { "name": "ohos.permission.DISCOVER_BLUETOOTH", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" }, { "name": "ohos.permission.LOCATION", - "reason": "", - "usedScene": { - "ability": [ - "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" - ], - "when": "inuse" - } + "reason": "" + }, + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "" + }, + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "" + }, + { + "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason": "" } ], "testRunner": { diff --git a/communication/bluetooth_standard/src/main/js/test/BluetoothAccess.test.js b/communication/bluetooth_standard/src/main/js/test/BluetoothAccess.test.js new file mode 100644 index 0000000000000000000000000000000000000000..09a1630402b329615ee56a36aec023e3e95a181d --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BluetoothAccess.test.js @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btAccessTest() { +describe('btAccessTest', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(function() { + console.info('beforeEach called') + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100 + * @tc.name test enableBluetooth + * @tc.desc Test enableBluetooth api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100', 0, async function (done) { + let state = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth state = '+ JSON.stringify(state)); + if(state != bluetooth.BluetoothState.STATE_OFF) { + bluetooth.disableBluetooth(); + await sleep(10000); + let closeSt = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth disable state ='+ JSON.stringify(closeSt)); + expect(closeSt).assertEqual(bluetooth.BluetoothState.STATE_OFF); + } else { + console.info('[bluetooth_js] bluetooth state is OFF'); + } + try { + bluetooth.enableBluetooth(); + await sleep(10000); + } catch { + console.error(`[bluetooth_js] enable StateChange error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + let openSt = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth enable state ='+ JSON.stringify(openSt)); + expect(openSt).assertEqual(bluetooth.BluetoothState.STATE_ON); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200 + * @tc.name test disableBluetooth + * @tc.desc Test disableBluetooth api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200', 0, async function (done) { + let state = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth state = '+ JSON.stringify(state)); + if(state != bluetooth.BluetoothState.STATE_ON) { + bluetooth.enableBluetooth(); + await sleep(10000); + let openSt = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth enable state ='+ JSON.stringify(openSt)); + expect(openSt).assertEqual(bluetooth.BluetoothState.STATE_ON); + } else { + console.info('[bluetooth_js] bluetooth state is ON'); + } + try { + bluetooth.disableBluetooth(); + await sleep(10000); + } catch { + console.error(`[bluetooth_js] disable StateChange error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + let closeSt = bluetooth.getState(); + console.info('[bluetooth_js] bluetooth disable state ='+ JSON.stringify(closeSt)); + expect(closeSt).assertEqual(bluetooth.BluetoothState.STATE_OFF); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300 + * @tc.name test getState + * @tc.desc Test getState api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300', 0, async function (done) { + try { + let state = bluetooth.getState(); + expect(true).assertTrue(0 <= state <= 6); + } catch { + console.error("[bluetooth_js] bluetooth getState errCode:" + err.code + ",bluetooth getState errMessage:" + err.message); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400 + * @tc.name test on 'stateChange' + * @tc.desc Test on 'stateChange' api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400', 0, async function (done) { + function onReceiveEvent(data) { + console.info('bluetooth state001 =' + JSON.stringify(data)); + } + try { + await bluetooth.on('stateChange', onReceiveEvent); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state' + JSON.stringify(state)); + if (state != bluetooth.BluetoothState.STATE_ON) { + let enable = bluetooth.enableBluetooth(); + await sleep(10000); + console.info('[bluetooth_js] bluetooth enable' + JSON.stringify(enable)); + expect(enable).assertTrue(); + let state1 = bluetooth.getState(); + console.info('[bluetooth_js] enable state ' + JSON.stringify(state1)); + expect(state1).assertEqual(bluetooth.BluetoothState.STATE_ON); + } + } catch (error) { + console.error(`[bluetooth_js]enable StateChange error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + bluetooth.off('stateChange', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500 + * @tc.name test off 'stateChange' + * @tc.desc Test off 'stateChange' api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500', 0, async function (done) { + function onReceiveEvent(data) { + console.info('bluetooth state001 =' + JSON.stringify(data)); + } + try { + await bluetooth.on('stateChange', onReceiveEvent); + await sleep(3000); + await bluetooth.off('stateChange', onReceiveEvent); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001' + JSON.stringify(state)); + if (state != bluetooth.BluetoothState.STATE_OFF) { + let disable = bluetooth.disableBluetooth(); + await sleep(10000); + console.info('[bluetooth_js] bluetooth disable001' + JSON.stringify(disable)); + expect(disable).assertTrue(); + let state1 = bluetooth.getState(); + console.info('[bluetooth_js] disable state001 ' + JSON.stringify(state1)); + expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF); + } + } catch (error) { + console.error(`[bluetooth_js]disable StateChange error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600 + * @tc.name test BluetoothState + * @tc.desc Test BluetoothState api10 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600', 0, async function (done) { + let STATE_ON = bluetooth.BluetoothState.STATE_ON; + console.info("[bluetooth_js]STATE_ON : " + JSON.stringify(STATE_ON)); + expect(true).assertTrue(STATE_ON == 2); + let STATE_OFF = bluetooth.BluetoothState.STATE_OFF; + console.info("[bluetooth_js]STATE_OFF : " + JSON.stringify(STATE_OFF)); + expect(true).assertTrue(STATE_OFF == 0); + let STATE_TURNING_ON = bluetooth.BluetoothState.STATE_TURNING_ON; + console.info("[bluetooth_js]STATE_TURNING_ON : " + JSON.stringify(STATE_TURNING_ON)); + expect(true).assertTrue(STATE_TURNING_ON == 1); + let STATE_TURNING_OFF = bluetooth.BluetoothState.STATE_TURNING_OFF; + console.info("[bluetooth_js]STATE_TURNING_OFF : " + JSON.stringify(STATE_TURNING_OFF)); + expect(true).assertTrue(STATE_TURNING_OFF == 3); + let STATE_BLE_TURNING_ON = bluetooth.BluetoothState.STATE_BLE_TURNING_ON; + console.info("[bluetooth_js]STATE_BLE_TURNING_ON : " + JSON.stringify(STATE_BLE_TURNING_ON)); + expect(true).assertTrue(STATE_BLE_TURNING_ON == 4); + let STATE_BLE_ON = bluetooth.BluetoothState.STATE_BLE_ON; + console.info("[bluetooth_js]STATE_BLE_ON : " + JSON.stringify(STATE_BLE_ON)); + expect(true).assertTrue(STATE_BLE_ON == 5); + let STATE_BLE_TURNING_OFF = bluetooth.BluetoothState.STATE_BLE_TURNING_OFF; + console.info("[bluetooth_js]STATE_BLE_TURNING_OFF : " + JSON.stringify(STATE_BLE_TURNING_OFF)); + expect(true).assertTrue(STATE_BLE_TURNING_OFF == 6); + done(); + }) +}) +} \ No newline at end of file diff --git a/communication/bluetooth_standard/src/main/js/test/BluetoothConstant.test.js b/communication/bluetooth_standard/src/main/js/test/BluetoothConstant.test.js new file mode 100644 index 0000000000000000000000000000000000000000..30ad8f357f64e8dba65f201945e9cdaf53eed510 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BluetoothConstant.test.js @@ -0,0 +1,436 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.constant'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btConstantTest() { +describe('btConstantTest', function() { + + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(function() { + console.info('beforeEach called') + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0100 + * @tc.name test constant + * @tc.desc Test constant api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0100', 0, async function (done) { + let STATE_DISCONNECTED = bluetooth.ProfileConnectionState.STATE_DISCONNECTED; + console.info("[bluetooth_js]STATE_DISCONNECTED : " + JSON.stringify(STATE_DISCONNECTED)); + expect(true).assertTrue(STATE_DISCONNECTED == 0); + let STATE_CONNECTING = bluetooth.ProfileConnectionState.STATE_CONNECTING; + console.info("[bluetooth_js]STATE_CONNECTING : " + JSON.stringify(STATE_CONNECTING)); + expect(true).assertTrue(STATE_CONNECTING == 1); + let STATE_CONNECTED = bluetooth.ProfileConnectionState.STATE_CONNECTED; + console.info("[bluetooth_js]STATE_CONNECTED : " + JSON.stringify(STATE_CONNECTED)); + expect(true).assertTrue(STATE_CONNECTED == 2); + let STATE_DISCONNECTING = bluetooth.ProfileConnectionState.STATE_DISCONNECTING; + console.info("[bluetooth_js]STATE_DISCONNECTING : " + JSON.stringify(STATE_DISCONNECTING)); + expect(true).assertTrue(STATE_DISCONNECTING == 3); + done(); + }) + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0200 + * @tc.name test constant + * @tc.desc Test constant api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0200', 0, async function (done) { + let PROFILE_A2DP_SOURCE = bluetooth.ProfileId.PROFILE_A2DP_SOURCE; + console.info("[bluetooth_js]PROFILE_A2DP_SOURCE : " + JSON.stringify(PROFILE_A2DP_SOURCE)); + expect(true).assertTrue(PROFILE_A2DP_SOURCE == 1); + let PROFILE_HANDSFREE_AUDIO_GATEWAY = bluetooth.ProfileId.PROFILE_HANDSFREE_AUDIO_GATEWAY; + console.info("[bluetooth_js]PROFILE_HANDSFREE_AUDIO_GATEWAY : " + + JSON.stringify(PROFILE_HANDSFREE_AUDIO_GATEWAY)); + expect(true).assertTrue(PROFILE_HANDSFREE_AUDIO_GATEWAY == 4); + let PROFILE_HID_HOST = bluetooth.ProfileId.PROFILE_HID_HOST; + console.info("[bluetooth_js]PROFILE_HID_HOST : " + JSON.stringify(PROFILE_HID_HOST)); + expect(true).assertTrue(PROFILE_HID_HOST == 6); + let PROFILE_PAN_NETWORK = bluetooth.ProfileId.PROFILE_PAN_NETWORK; + console.info("[bluetooth_js]PROFILE_PAN_NETWORK : " + JSON.stringify(PROFILE_PAN_NETWORK)); + expect(true).assertTrue(PROFILE_PAN_NETWORK == 7); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0300 + * @tc.name test constant + * @tc.desc Test constant api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0300', 0, async function (done) { + let MAJOR_MISC = bluetooth.MajorClass.MAJOR_MISC; + console.info("[bluetooth_js]MAJOR_MISC : " + JSON.stringify(MAJOR_MISC)); + expect(true).assertTrue(MAJOR_MISC == 0x0000); + let MAJOR_COMPUTER = bluetooth.MajorClass.MAJOR_COMPUTER; + console.info("[bluetooth_js]MAJOR_COMPUTER : " + JSON.stringify(MAJOR_COMPUTER)); + expect(true).assertTrue(MAJOR_COMPUTER == 0x0100); + let MAJOR_PHONE = bluetooth.MajorClass.MAJOR_PHONE; + console.info("[bluetooth_js]MAJOR_PHONE : " + JSON.stringify(MAJOR_PHONE)); + expect(true).assertTrue(MAJOR_PHONE == 0x0200); + let MAJOR_NETWORKING = bluetooth.MajorClass.MAJOR_NETWORKING; + console.info("[bluetooth_js]MAJOR_NETWORKING : " + JSON.stringify(MAJOR_NETWORKING)); + expect(true).assertTrue(MAJOR_NETWORKING == 0x0300); + let MAJOR_AUDIO_VIDEO = bluetooth.MajorClass.MAJOR_AUDIO_VIDEO; + console.info("[bluetooth_js]MAJOR_AUDIO_VIDEO : " + JSON.stringify(MAJOR_AUDIO_VIDEO)); + expect(true).assertTrue(MAJOR_AUDIO_VIDEO == 0x0400); + let MAJOR_PERIPHERAL = bluetooth.MajorClass.MAJOR_PERIPHERAL; + console.info("[bluetooth_js]MAJOR_PERIPHERAL : " + JSON.stringify(MAJOR_PERIPHERAL)); + expect(true).assertTrue(MAJOR_PERIPHERAL == 0x0500); + let MAJOR_IMAGING = bluetooth.MajorClass.MAJOR_IMAGING; + console.info("[bluetooth_js]MAJOR_IMAGING : " + JSON.stringify(MAJOR_IMAGING)); + expect(true).assertTrue(MAJOR_IMAGING == 0x0600); + let MAJOR_WEARABLE = bluetooth.MajorClass.MAJOR_WEARABLE; + console.info("[bluetooth_js]MAJOR_WEARABLE : " + JSON.stringify(MAJOR_WEARABLE)); + expect(true).assertTrue(MAJOR_WEARABLE == 0x0700); + let MAJOR_TOY = bluetooth.MajorClass.MAJOR_TOY; + console.info("[bluetooth_js]MAJOR_TOY : " + JSON.stringify(MAJOR_TOY)); + expect(true).assertTrue(MAJOR_TOY == 0x0800); + let MAJOR_HEALTH = bluetooth.MajorClass.MAJOR_HEALTH; + console.info("[bluetooth_js]MAJOR_HEALTH : " + JSON.stringify(MAJOR_HEALTH)); + expect(true).assertTrue(MAJOR_HEALTH == 0x0900); + let MAJOR_UNCATEGORIZED = bluetooth.MajorClass.MAJOR_UNCATEGORIZED; + console.info("[bluetooth_js]MAJOR_UNCATEGORIZED : " + JSON.stringify(MAJOR_UNCATEGORIZED)); + expect(true).assertTrue(MAJOR_UNCATEGORIZED == 0x1F00); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0400 + * @tc.name test constant + * @tc.desc Test constant api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0800', 0, async function (done) { + let COMPUTER_UNCATEGORIZED = bluetooth.MajorMinorClass.COMPUTER_UNCATEGORIZED; + console.info("[bluetooth_js]COMPUTER_UNCATEGORIZED : " + + JSON.stringify(COMPUTER_UNCATEGORIZED)); + expect(true).assertTrue(COMPUTER_UNCATEGORIZED == 0x0100); + let COMPUTER_DESKTOP = bluetooth.MajorMinorClass.COMPUTER_DESKTOP; + console.info("[bluetooth_js]COMPUTER_DESKTOP : " + JSON.stringify(COMPUTER_DESKTOP)); + expect(true).assertTrue(COMPUTER_DESKTOP == 0x0104); + let COMPUTER_SERVER = bluetooth.MajorMinorClass.COMPUTER_SERVER; + console.info("[bluetooth_js]COMPUTER_SERVER : " + JSON.stringify(COMPUTER_SERVER)); + expect(true).assertTrue(COMPUTER_SERVER == 0x0108); + let COMPUTER_LAPTOP = bluetooth.MajorMinorClass.COMPUTER_LAPTOP; + console.info("[bluetooth_js]COMPUTER_LAPTOP : " + JSON.stringify(COMPUTER_LAPTOP)); + expect(true).assertTrue(COMPUTER_LAPTOP == 0x010C); + let COMPUTER_HANDHELD_PC_PDA = bluetooth.MajorMinorClass.COMPUTER_HANDHELD_PC_PDA; + console.info("[bluetooth_js]COMPUTER_HANDHELD_PC_PDA : " + + JSON.stringify(COMPUTER_HANDHELD_PC_PDA)); + expect(true).assertTrue(COMPUTER_HANDHELD_PC_PDA == 0x0110); + let COMPUTER_PALM_SIZE_PC_PDA = bluetooth.MajorMinorClass.COMPUTER_PALM_SIZE_PC_PDA; + console.info("[bluetooth_js]COMPUTER_PALM_SIZE_PC_PDA : " + + JSON.stringify(COMPUTER_PALM_SIZE_PC_PDA)); + expect(true).assertTrue(COMPUTER_PALM_SIZE_PC_PDA == 0x0114); + let COMPUTER_WEARABLE = bluetooth.MajorMinorClass.COMPUTER_WEARABLE; + console.info("[bluetooth_js]COMPUTER_WEARABLE : " + JSON.stringify(COMPUTER_WEARABLE)); + expect(true).assertTrue(COMPUTER_WEARABLE == 0x0118); + let COMPUTER_TABLET = bluetooth.MajorMinorClass.COMPUTER_TABLET; + console.info("[bluetooth_js]COMPUTER_TABLET : " + JSON.stringify(COMPUTER_TABLET)); + expect(true).assertTrue(COMPUTER_TABLET == 0x011C); + + let PHONE_UNCATEGORIZED = bluetooth.MajorMinorClass.PHONE_UNCATEGORIZED; + console.info("[bluetooth_js]PHONE_UNCATEGORIZED : " + + JSON.stringify(PHONE_UNCATEGORIZED)); + expect(true).assertTrue(PHONE_UNCATEGORIZED == 0x0200); + let PHONE_CELLULAR = bluetooth.MajorMinorClass.PHONE_CELLULAR; + console.info("[bluetooth_js]PHONE_CELLULAR : " + JSON.stringify(PHONE_CELLULAR)); + expect(true).assertTrue(PHONE_CELLULAR == 0x0204); + let PHONE_CORDLESS = bluetooth.MajorMinorClass.PHONE_CORDLESS; + console.info("[bluetooth_js]PHONE_CORDLESS : " + JSON.stringify(PHONE_CORDLESS)); + expect(true).assertTrue(PHONE_CORDLESS == 0x0208); + let PHONE_SMART = bluetooth.MajorMinorClass.PHONE_SMART; + console.info("[bluetooth_js]PHONE_SMART : " + JSON.stringify(PHONE_SMART)); + expect(true).assertTrue(PHONE_SMART == 0x020C); + let PHONE_MODEM_OR_GATEWAY = bluetooth.MajorMinorClass.PHONE_MODEM_OR_GATEWAY; + console.info("[bluetooth_js]PHONE_MODEM_OR_GATEWAY : " + + JSON.stringify(PHONE_MODEM_OR_GATEWAY)); + expect(true).assertTrue(PHONE_MODEM_OR_GATEWAY == 0x0210); + let PHONE_ISDN = bluetooth.MajorMinorClass.PHONE_ISDN; + console.info("[bluetooth_js]PHONE_ISDN : " + JSON.stringify(PHONE_ISDN)); + expect(true).assertTrue(PHONE_ISDN == 0x0214); + + let NETWORK_FULLY_AVAILABLE = bluetooth.MajorMinorClass.NETWORK_FULLY_AVAILABLE; + console.info("[bluetooth_js]NETWORK_FULLY_AVAILABLE : " + + JSON.stringify(NETWORK_FULLY_AVAILABLE)); + expect(true).assertTrue(NETWORK_FULLY_AVAILABLE == 0x0300); + let NETWORK_1_TO_17_UTILIZED = bluetooth.MajorMinorClass.NETWORK_1_TO_17_UTILIZED; + console.info("[bluetooth_js]NETWORK_1_TO_17_UTILIZED : " + + JSON.stringify(NETWORK_1_TO_17_UTILIZED)); + expect(true).assertTrue(NETWORK_1_TO_17_UTILIZED == 0x0320); + let NETWORK_17_TO_33_UTILIZED = bluetooth.MajorMinorClass.NETWORK_17_TO_33_UTILIZED; + console.info("[bluetooth_js]NETWORK_17_TO_33_UTILIZED : " + + JSON.stringify(NETWORK_17_TO_33_UTILIZED)); + expect(true).assertTrue(NETWORK_17_TO_33_UTILIZED == 0x0340); + let NETWORK_33_TO_50_UTILIZED = bluetooth.MajorMinorClass.NETWORK_33_TO_50_UTILIZED; + console.info("[bluetooth_js]NETWORK_33_TO_50_UTILIZED : " + + JSON.stringify(NETWORK_33_TO_50_UTILIZED)); + expect(true).assertTrue(NETWORK_33_TO_50_UTILIZED == 0x0360); + let NETWORK_60_TO_67_UTILIZED = bluetooth.MajorMinorClass.NETWORK_60_TO_67_UTILIZED; + console.info("[bluetooth_js]NETWORK_60_TO_67_UTILIZED : " + + JSON.stringify(NETWORK_60_TO_67_UTILIZED)); + expect(true).assertTrue(NETWORK_60_TO_67_UTILIZED == 0x0380); + let NETWORK_67_TO_83_UTILIZED = bluetooth.MajorMinorClass.NETWORK_67_TO_83_UTILIZED; + console.info("[bluetooth_js]NETWORK_67_TO_83_UTILIZED : " + + JSON.stringify(NETWORK_67_TO_83_UTILIZED)); + expect(true).assertTrue(NETWORK_67_TO_83_UTILIZED == 0x03A0); + let NETWORK_83_TO_99_UTILIZED = bluetooth.MajorMinorClass.NETWORK_83_TO_99_UTILIZED; + console.info("[bluetooth_js]NETWORK_83_TO_99_UTILIZED : " + + JSON.stringify(NETWORK_83_TO_99_UTILIZED)); + expect(true).assertTrue(NETWORK_83_TO_99_UTILIZED == 0x03C0); + let NETWORK_NO_SERVICE = bluetooth.MajorMinorClass.NETWORK_NO_SERVICE; + console.info("[bluetooth_js]NETWORK_NO_SERVICE : " + JSON.stringify(NETWORK_NO_SERVICE)); + expect(true).assertTrue(NETWORK_NO_SERVICE == 0x03E0); + + let AUDIO_VIDEO_UNCATEGORIZED = bluetooth.MajorMinorClass.AUDIO_VIDEO_UNCATEGORIZED; + console.info("[bluetooth_js]AUDIO_VIDEO_UNCATEGORIZED : " + + JSON.stringify(AUDIO_VIDEO_UNCATEGORIZED)); + expect(true).assertTrue(AUDIO_VIDEO_UNCATEGORIZED == 0x0400); + let AUDIO_VIDEO_WEARABLE_HEADSET = bluetooth.MajorMinorClass.AUDIO_VIDEO_WEARABLE_HEADSET; + console.info("[bluetooth_js]AUDIO_VIDEO_WEARABLE_HEADSET : " + + JSON.stringify(AUDIO_VIDEO_WEARABLE_HEADSET)); + expect(true).assertTrue(AUDIO_VIDEO_WEARABLE_HEADSET == 0x0404); + let AUDIO_VIDEO_HANDSFREE = bluetooth.MajorMinorClass.AUDIO_VIDEO_HANDSFREE; + console.info("[bluetooth_js]AUDIO_VIDEO_HANDSFREE : " + + JSON.stringify(AUDIO_VIDEO_HANDSFREE)); + expect(true).assertTrue(AUDIO_VIDEO_HANDSFREE == 0x0408); + let AUDIO_VIDEO_MICROPHONE = bluetooth.MajorMinorClass.AUDIO_VIDEO_MICROPHONE; + console.info("[bluetooth_js]AUDIO_VIDEO_MICROPHONE : " + JSON.stringify(AUDIO_VIDEO_MICROPHONE)); + expect(true).assertTrue(AUDIO_VIDEO_MICROPHONE == 0x0410); + let AUDIO_VIDEO_LOUDSPEAKER = bluetooth.MajorMinorClass.AUDIO_VIDEO_LOUDSPEAKER; + console.info("[bluetooth_js]AUDIO_VIDEO_LOUDSPEAKER : " + JSON.stringify(AUDIO_VIDEO_LOUDSPEAKER)); + expect(true).assertTrue(AUDIO_VIDEO_LOUDSPEAKER == 0x0414); + let AUDIO_VIDEO_HEADPHONES = bluetooth.MajorMinorClass.AUDIO_VIDEO_HEADPHONES; + console.info("[bluetooth_js]AUDIO_VIDEO_HEADPHONES : " + JSON.stringify(AUDIO_VIDEO_HEADPHONES)); + expect(true).assertTrue(AUDIO_VIDEO_HEADPHONES == 0x0418); + let AUDIO_VIDEO_PORTABLE_AUDIO = bluetooth.MajorMinorClass.AUDIO_VIDEO_PORTABLE_AUDIO; + console.info("[bluetooth_js]AUDIO_VIDEO_PORTABLE_AUDIO : " + + JSON.stringify(AUDIO_VIDEO_PORTABLE_AUDIO)); + expect(true).assertTrue(AUDIO_VIDEO_PORTABLE_AUDIO == 0x041C); + let AUDIO_VIDEO_CAR_AUDIO = bluetooth.MajorMinorClass.AUDIO_VIDEO_CAR_AUDIO; + console.info("[bluetooth_js]AUDIO_VIDEO_CAR_AUDIO : " + JSON.stringify(AUDIO_VIDEO_CAR_AUDIO)); + expect(true).assertTrue(AUDIO_VIDEO_CAR_AUDIO == 0x0420); + let AUDIO_VIDEO_SET_TOP_BOX = bluetooth.MajorMinorClass.AUDIO_VIDEO_SET_TOP_BOX; + console.info("[bluetooth_js]AUDIO_VIDEO_SET_TOP_BOX : " + JSON.stringify(AUDIO_VIDEO_SET_TOP_BOX)); + expect(true).assertTrue(AUDIO_VIDEO_SET_TOP_BOX == 0x0424); + let AUDIO_VIDEO_HIFI_AUDIO = bluetooth.MajorMinorClass.AUDIO_VIDEO_HIFI_AUDIO; + console.info("[bluetooth_js]AUDIO_VIDEO_HIFI_AUDIO : " + JSON.stringify(AUDIO_VIDEO_HIFI_AUDIO)); + expect(true).assertTrue(AUDIO_VIDEO_HIFI_AUDIO == 0x0428); + let AUDIO_VIDEO_VCR = bluetooth.MajorMinorClass.AUDIO_VIDEO_VCR; + console.info("[bluetooth_js]AUDIO_VIDEO_VCR : " + JSON.stringify(AUDIO_VIDEO_VCR)); + expect(true).assertTrue(AUDIO_VIDEO_VCR == 0x042C); + let AUDIO_VIDEO_VIDEO_CAMERA = bluetooth.MajorMinorClass.AUDIO_VIDEO_VIDEO_CAMERA; + console.info("[bluetooth_js]AUDIO_VIDEO_VIDEO_CAMERA : " + + JSON.stringify(AUDIO_VIDEO_VIDEO_CAMERA)); + expect(true).assertTrue(AUDIO_VIDEO_VIDEO_CAMERA == 0x0430); + let AUDIO_VIDEO_CAMCORDER = bluetooth.MajorMinorClass.AUDIO_VIDEO_CAMCORDER; + console.info("[bluetooth_js]AUDIO_VIDEO_CAMCORDER : " + JSON.stringify(AUDIO_VIDEO_CAMCORDER)); + expect(true).assertTrue(AUDIO_VIDEO_CAMCORDER == 0x0434); + let AUDIO_VIDEO_VIDEO_MONITOR = bluetooth.MajorMinorClass.AUDIO_VIDEO_VIDEO_MONITOR; + console.info("[bluetooth_js]AUDIO_VIDEO_VIDEO_MONITOR : " + + JSON.stringify(AUDIO_VIDEO_VIDEO_MONITOR)); + expect(true).assertTrue(AUDIO_VIDEO_VIDEO_MONITOR == 0x0438); + let AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = + bluetooth.MajorMinorClass.AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER; + console.info("[bluetooth_js]AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : " + + JSON.stringify(AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER)); + expect(true).assertTrue(AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER == 0x043C); + let AUDIO_VIDEO_VIDEO_CONFERENCING = bluetooth.MajorMinorClass.AUDIO_VIDEO_VIDEO_CONFERENCING; + console.info("[bluetooth_js]AUDIO_VIDEO_VIDEO_CONFERENCING : " + + JSON.stringify(AUDIO_VIDEO_VIDEO_CONFERENCING)); + expect(true).assertTrue(AUDIO_VIDEO_VIDEO_CONFERENCING == 0x0440); + let AUDIO_VIDEO_VIDEO_GAMING_TOY = bluetooth.MajorMinorClass.AUDIO_VIDEO_VIDEO_GAMING_TOY; + console.info("[bluetooth_js]AUDIO_VIDEO_VIDEO_GAMING_TOY : " + + JSON.stringify(AUDIO_VIDEO_VIDEO_GAMING_TOY)); + expect(true).assertTrue(AUDIO_VIDEO_VIDEO_GAMING_TOY == 0x0448); + + let PERIPHERAL_NON_KEYBOARD_NON_POINTING = + bluetooth.MajorMinorClass.PERIPHERAL_NON_KEYBOARD_NON_POINTING; + console.info("[bluetooth_js]PERIPHERAL_NON_KEYBOARD_NON_POINTING : " + + JSON.stringify(PERIPHERAL_NON_KEYBOARD_NON_POINTING)); + expect(true).assertTrue(PERIPHERAL_NON_KEYBOARD_NON_POINTING == 0x0500); + let PERIPHERAL_KEYBOARD = bluetooth.MajorMinorClass.PERIPHERAL_KEYBOARD; + console.info("[bluetooth_js]PERIPHERAL_KEYBOARD : " + JSON.stringify(PERIPHERAL_KEYBOARD)); + expect(true).assertTrue(PERIPHERAL_KEYBOARD == 0x0540); + let PERIPHERAL_POINTING_DEVICE = bluetooth.MajorMinorClass.PERIPHERAL_POINTING_DEVICE; + console.info("[bluetooth_js]PERIPHERAL_POINTING_DEVICE : " + + JSON.stringify(PERIPHERAL_POINTING_DEVICE)); + expect(true).assertTrue(PERIPHERAL_POINTING_DEVICE == 0x0580); + let PERIPHERAL_KEYBOARD_POINTING = bluetooth.MajorMinorClass.PERIPHERAL_KEYBOARD_POINTING; + console.info("[bluetooth_js]PERIPHERAL_KEYBOARD_POINTING : " + + JSON.stringify(PERIPHERAL_KEYBOARD_POINTING)); + expect(true).assertTrue(PERIPHERAL_KEYBOARD_POINTING == 0x05C0); + let PERIPHERAL_UNCATEGORIZED = bluetooth.MajorMinorClass.PERIPHERAL_UNCATEGORIZED; + console.info("[bluetooth_js]PERIPHERAL_UNCATEGORIZED : " + JSON.stringify(PERIPHERAL_UNCATEGORIZED)); + expect(true).assertTrue(PERIPHERAL_UNCATEGORIZED == 0x0500); + let PERIPHERAL_JOYSTICK = bluetooth.MajorMinorClass.PERIPHERAL_JOYSTICK; + console.info("[bluetooth_js]PERIPHERAL_JOYSTICK : " + JSON.stringify(PERIPHERAL_JOYSTICK)); + expect(true).assertTrue(PERIPHERAL_JOYSTICK == 0x0504); + let PERIPHERAL_GAMEPAD = bluetooth.MajorMinorClass.PERIPHERAL_GAMEPAD; + console.info("[bluetooth_js]PERIPHERAL_GAMEPAD : " + JSON.stringify(PERIPHERAL_GAMEPAD)); + expect(true).assertTrue(PERIPHERAL_GAMEPAD == 0x0508); + let PERIPHERAL_REMOTE_CONTROL = bluetooth.MajorMinorClass.PERIPHERAL_REMOTE_CONTROL; + console.info("[bluetooth_js]PERIPHERAL_REMOTE_CONTROL : " + JSON.stringify(PERIPHERAL_REMOTE_CONTROL)); + expect(true).assertTrue(PERIPHERAL_REMOTE_CONTROL == 0x05C0); + let PERIPHERAL_SENSING_DEVICE = bluetooth.MajorMinorClass.PERIPHERAL_SENSING_DEVICE; + console.info("[bluetooth_js]PERIPHERAL_SENSING_DEVICE : " + JSON.stringify(PERIPHERAL_SENSING_DEVICE)); + expect(true).assertTrue(PERIPHERAL_SENSING_DEVICE == 0x0510); + let PERIPHERAL_DIGITIZER_TABLET = bluetooth.MajorMinorClass.PERIPHERAL_DIGITIZER_TABLET; + console.info("[bluetooth_js]PERIPHERAL_DIGITIZER_TABLET : " + + JSON.stringify(PERIPHERAL_DIGITIZER_TABLET)); + expect(true).assertTrue(PERIPHERAL_DIGITIZER_TABLET == 0x0514); + let PERIPHERAL_CARD_READER = bluetooth.MajorMinorClass.PERIPHERAL_CARD_READER; + console.info("[bluetooth_js]PERIPHERAL_CARD_READER : " + JSON.stringify(PERIPHERAL_CARD_READER)); + expect(true).assertTrue(PERIPHERAL_CARD_READER == 0x0518); + let PERIPHERAL_DIGITAL_PEN = bluetooth.MajorMinorClass.PERIPHERAL_DIGITAL_PEN; + console.info("[bluetooth_js]PERIPHERAL_DIGITAL_PEN : " + JSON.stringify(PERIPHERAL_DIGITAL_PEN)); + expect(true).assertTrue(PERIPHERAL_DIGITAL_PEN == 0x051C); + let PERIPHERAL_SCANNER_RFID = bluetooth.MajorMinorClass.PERIPHERAL_SCANNER_RFID; + console.info("[bluetooth_js]PERIPHERAL_SCANNER_RFID : " + JSON.stringify(PERIPHERAL_SCANNER_RFID)); + expect(true).assertTrue(PERIPHERAL_SCANNER_RFID == 0x0520); + let PERIPHERAL_GESTURAL_INPUT = bluetooth.MajorMinorClass.PERIPHERAL_GESTURAL_INPUT; + console.info("[bluetooth_js]PERIPHERAL_GESTURAL_INPUT : " + + JSON.stringify(PERIPHERAL_GESTURAL_INPUT)); + expect(true).assertTrue(PERIPHERAL_GESTURAL_INPUT == 0x0522); + + let IMAGING_UNCATEGORIZED = bluetooth.MajorMinorClass.IMAGING_UNCATEGORIZED; + console.info("[bluetooth_js]IMAGING_UNCATEGORIZED : " + JSON.stringify(IMAGING_UNCATEGORIZED)); + expect(true).assertTrue(IMAGING_UNCATEGORIZED == 0x0600); + let IMAGING_DISPLAY = bluetooth.MajorMinorClass.IMAGING_DISPLAY; + console.info("[bluetooth_js]IMAGING_DISPLAY : " + JSON.stringify(IMAGING_DISPLAY)); + expect(true).assertTrue(IMAGING_DISPLAY == 0x0610); + let IMAGING_CAMERA = bluetooth.MajorMinorClass.IMAGING_CAMERA; + console.info("[bluetooth_js]IMAGING_CAMERA : " + JSON.stringify(IMAGING_CAMERA)); + expect(true).assertTrue(IMAGING_CAMERA == 0x0620); + let IMAGING_SCANNER = bluetooth.MajorMinorClass.IMAGING_SCANNER; + console.info("[bluetooth_js]IMAGING_SCANNER : " + JSON.stringify(IMAGING_SCANNER)); + expect(true).assertTrue(IMAGING_SCANNER == 0x0640); + let IMAGING_PRINTER = bluetooth.MajorMinorClass.IMAGING_PRINTER; + console.info("[bluetooth_js]IMAGING_PRINTER : " + JSON.stringify(IMAGING_PRINTER)); + expect(true).assertTrue(IMAGING_PRINTER == 0x0680); + + let WEARABLE_UNCATEGORIZED = bluetooth.MajorMinorClass.WEARABLE_UNCATEGORIZED; + console.info("[bluetooth_js]WEARABLE_UNCATEGORIZED : " + JSON.stringify(WEARABLE_UNCATEGORIZED)); + expect(true).assertTrue(WEARABLE_UNCATEGORIZED == 0x0700); + let WEARABLE_WRIST_WATCH = bluetooth.MajorMinorClass.WEARABLE_WRIST_WATCH; + console.info("[bluetooth_js]WEARABLE_WRIST_WATCH : " + JSON.stringify(WEARABLE_WRIST_WATCH)); + expect(true).assertTrue(WEARABLE_WRIST_WATCH == 0x0704); + let WEARABLE_PAGER = bluetooth.MajorMinorClass.WEARABLE_PAGER; + console.info("[bluetooth_js]WEARABLE_PAGER : " + JSON.stringify(WEARABLE_PAGER)); + expect(true).assertTrue(WEARABLE_PAGER == 0x0708); + let WEARABLE_JACKET = bluetooth.MajorMinorClass.WEARABLE_JACKET; + console.info("[bluetooth_js]WEARABLE_JACKET : " + JSON.stringify(WEARABLE_JACKET)); + expect(true).assertTrue(WEARABLE_JACKET == 0x070C); + let WEARABLE_HELMET = bluetooth.MajorMinorClass.WEARABLE_HELMET; + console.info("[bluetooth_js]WEARABLE_HELMET : " + JSON.stringify(WEARABLE_HELMET)); + expect(true).assertTrue(WEARABLE_HELMET == 0x0710); + let WEARABLE_GLASSES = bluetooth.MajorMinorClass.WEARABLE_GLASSES; + console.info("[bluetooth_js]WEARABLE_GLASSES : " + JSON.stringify(WEARABLE_GLASSES)); + expect(true).assertTrue(WEARABLE_GLASSES == 0x0714); + + let TOY_UNCATEGORIZED = bluetooth.MajorMinorClass.TOY_UNCATEGORIZED; + console.info("[bluetooth_js]TOY_UNCATEGORIZED : " + JSON.stringify(TOY_UNCATEGORIZED)); + expect(true).assertTrue(TOY_UNCATEGORIZED == 0x0800); + let TOY_ROBOT = bluetooth.MajorMinorClass.TOY_ROBOT; + console.info("[bluetooth_js]TOY_ROBOT : " + JSON.stringify(TOY_ROBOT)); + expect(true).assertTrue(TOY_ROBOT == 0x0804); + let TOY_VEHICLE = bluetooth.MajorMinorClass.TOY_VEHICLE; + console.info("[bluetooth_js]TOY_VEHICLE : " + JSON.stringify(TOY_VEHICLE)); + expect(true).assertTrue(TOY_VEHICLE == 0x0808); + let TOY_DOLL_ACTION_FIGURE = bluetooth.MajorMinorClass.TOY_DOLL_ACTION_FIGURE; + console.info("[bluetooth_js]TOY_DOLL_ACTION_FIGURE : " + JSON.stringify(TOY_DOLL_ACTION_FIGURE)); + expect(true).assertTrue(TOY_DOLL_ACTION_FIGURE == 0x080C); + let TOY_CONTROLLER = bluetooth.MajorMinorClass.TOY_CONTROLLER; + console.info("[bluetooth_js]TOY_CONTROLLER : " + JSON.stringify(TOY_CONTROLLER)); + expect(true).assertTrue(TOY_CONTROLLER == 0x0810); + let TOY_GAME = bluetooth.MajorMinorClass.TOY_GAME; + console.info("[bluetooth_js]TOY_GAME : " + JSON.stringify(TOY_GAME)); + expect(true).assertTrue(TOY_GAME == 0x0814); + + let HEALTH_UNCATEGORIZED = bluetooth.MajorMinorClass.HEALTH_UNCATEGORIZED; + console.info("[bluetooth_js]HEALTH_UNCATEGORIZED : " + JSON.stringify(HEALTH_UNCATEGORIZED)); + expect(true).assertTrue(HEALTH_UNCATEGORIZED == 0x0900); + let HEALTH_BLOOD_PRESSURE = bluetooth.MajorMinorClass.HEALTH_BLOOD_PRESSURE; + console.info("[bluetooth_js]HEALTH_BLOOD_PRESSURE : " + JSON.stringify(HEALTH_BLOOD_PRESSURE)); + expect(true).assertTrue(HEALTH_BLOOD_PRESSURE == 0x0904); + let HEALTH_THERMOMETER = bluetooth.MajorMinorClass.HEALTH_THERMOMETER; + console.info("[bluetooth_js]HEALTH_THERMOMETER : " + JSON.stringify(HEALTH_THERMOMETER)); + expect(true).assertTrue(HEALTH_THERMOMETER == 0x0908); + let HEALTH_WEIGHING = bluetooth.MajorMinorClass.HEALTH_WEIGHING; + console.info("[bluetooth_js]HEALTH_WEIGHING : " + JSON.stringify(HEALTH_WEIGHING)); + expect(true).assertTrue(HEALTH_WEIGHING == 0x090C); + let HEALTH_GLUCOSE = bluetooth.MajorMinorClass.HEALTH_GLUCOSE; + console.info("[bluetooth_js]HEALTH_GLUCOSE : " + JSON.stringify(HEALTH_GLUCOSE)); + expect(true).assertTrue(HEALTH_GLUCOSE == 0x0910); + let HEALTH_PULSE_OXIMETER = bluetooth.MajorMinorClass.HEALTH_PULSE_OXIMETER; + console.info("[bluetooth_js]HEALTH_PULSE_OXIMETER : " + JSON.stringify(HEALTH_PULSE_OXIMETER)); + expect(true).assertTrue(HEALTH_PULSE_OXIMETER == 0x0914); + let HEALTH_PULSE_RATE = bluetooth.MajorMinorClass.HEALTH_PULSE_RATE; + console.info("[bluetooth_js]HEALTH_PULSE_RATE : " + JSON.stringify(HEALTH_PULSE_RATE)); + expect(true).assertTrue(HEALTH_PULSE_RATE == 0x0918); + let HEALTH_DATA_DISPLAY = bluetooth.MajorMinorClass.HEALTH_DATA_DISPLAY; + console.info("[bluetooth_js]HEALTH_DATA_DISPLAY : " + JSON.stringify(HEALTH_DATA_DISPLAY)); + expect(true).assertTrue(HEALTH_DATA_DISPLAY == 0x091C); + let HEALTH_STEP_COUNTER = bluetooth.MajorMinorClass.HEALTH_STEP_COUNTER; + console.info("[bluetooth_js]HEALTH_STEP_COUNTER : " + JSON.stringify(HEALTH_STEP_COUNTER)); + expect(true).assertTrue(HEALTH_STEP_COUNTER == 0x0920); + let HEALTH_BODY_COMPOSITION_ANALYZER = bluetooth.MajorMinorClass.HEALTH_BODY_COMPOSITION_ANALYZER; + console.info("[bluetooth_js]HEALTH_BODY_COMPOSITION_ANALYZER : " + + JSON.stringify(HEALTH_BODY_COMPOSITION_ANALYZER)); + expect(true).assertTrue(HEALTH_BODY_COMPOSITION_ANALYZER == 0x0924); + let HEALTH_PEAK_FLOW_MONITOR = bluetooth.MajorMinorClass.HEALTH_PEAK_FLOW_MONITOR; + console.info("[bluetooth_js]HEALTH_PEAK_FLOW_MONITOR : " + JSON.stringify(HEALTH_PEAK_FLOW_MONITOR)); + expect(true).assertTrue(HEALTH_PEAK_FLOW_MONITOR == 0x0928); + let HEALTH_MEDICATION_MONITOR = bluetooth.MajorMinorClass.HEALTH_MEDICATION_MONITOR; + console.info("[bluetooth_js]HEALTH_MEDICATION_MONITOR : " + + JSON.stringify(HEALTH_MEDICATION_MONITOR)); + expect(true).assertTrue(HEALTH_MEDICATION_MONITOR == 0x092C); + let HEALTH_KNEE_PROSTHESIS = bluetooth.MajorMinorClass.HEALTH_KNEE_PROSTHESIS; + console.info("[bluetooth_js]HEALTH_KNEE_PROSTHESIS : " + JSON.stringify(HEALTH_KNEE_PROSTHESIS)); + expect(true).assertTrue(HEALTH_KNEE_PROSTHESIS == 0x0930); + let HEALTH_ANKLE_PROSTHESIS = bluetooth.MajorMinorClass.HEALTH_ANKLE_PROSTHESIS; + console.info("[bluetooth_js]HEALTH_ANKLE_PROSTHESIS : " + JSON.stringify(HEALTH_ANKLE_PROSTHESIS)); + expect(true).assertTrue(HEALTH_ANKLE_PROSTHESIS == 0x0934); + let HEALTH_GENERIC_HEALTH_MANAGER = bluetooth.MajorMinorClass.HEALTH_GENERIC_HEALTH_MANAGER; + console.info("[bluetooth_js]HEALTH_GENERIC_HEALTH_MANAGER : " + + JSON.stringify(HEALTH_GENERIC_HEALTH_MANAGER)); + expect(true).assertTrue(HEALTH_GENERIC_HEALTH_MANAGER == 0x0938); + let HEALTH_PERSONAL_MOBILITY_DEVICE = bluetooth.MajorMinorClass.HEALTH_PERSONAL_MOBILITY_DEVICE; + console.info("[bluetooth_js]HEALTH_PERSONAL_MOBILITY_DEVICE : " + + JSON.stringify(HEALTH_PERSONAL_MOBILITY_DEVICE)); + expect(true).assertTrue(HEALTH_PERSONAL_MOBILITY_DEVICE == 0x093C); + done(); + }) +}) +} \ No newline at end of file diff --git a/communication/bluetooth_standard/src/main/js/test/BtSocket.test.js b/communication/bluetooth_standard/src/main/js/test/BtSocket.test.js new file mode 100644 index 0000000000000000000000000000000000000000..fdabf0fff9df6062fdb51892dd75194210eb8573 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BtSocket.test.js @@ -0,0 +1,385 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bluetooth from '@ohos.bluetooth.socket'; +import btAccess from '@ohos.bluetooth.access'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function btSocketTest() { +describe('btSocketTest', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = btAccess.getState(); + switch (sta) { + case 0: + btAccess.enableBluetooth(); + await sleep(10000); + let sta1 = btAccess.getState(); + console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1)); + break; + case 1: + console.info('[bluetooth_js] bt turning on:' + JSON.stringify(sta)); + await sleep(3000); + break; + case 2: + console.info('[bluetooth_js] bt turn on:' + JSON.stringify(sta)); + break; + case 3: + btAccess.enableBluetooth(); + await sleep(10000); + let sta2 = btAccess.getState(); + console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function (done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100 + * @tc.name test SppListen + * @tc.desc Test SppListen api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100', 0, async function (done) { + let SppOptions = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code01: ' + code); + } else { + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + try { + await bluetooth.sppListen('server1', SppOptions, serverSocket); + } catch (error) { + console.error(`[bluetooth_js]SPPListen error, code is ${error.code},message is ${error.message}`); + expect(true).assertEqual(error == null); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200 + * @tc.name testSppAccept + * @tc.desc Test SppAccept api10 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200', 0, async function (done) { + let SppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code02: ' + code); + } else { + console.log('bluetooth serverSocket Number02:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + bluetooth.sppListen('server_accept', SppOption, serverSocket); + let clientNumber = -1; + function acceptClientSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth clientSocket Number: ' + number); + clientNumber = number; + expect(true).assertEqual(clientNumber != -1); + } + } + try { + bluetooth.sppAccept(serverNumber, acceptClientSocket); + } catch (error) { + console.error(`[bluetooth_js]SPPAccept error, code is ${error.code},message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300 + * @tc.name test SppConnect + * @tc.desc Test SppConnect api10 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300', 0, async function (done) { + let sppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: true, type: 0 + }; + try { + await bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function (code, number) { + if (code) { + console.info('[bluetooth_js] code is: ' + JSON.stringify(code)); + } else { + console.log('[bluetooth_js]sppConnect Number:' + + JSON.stringify(number)); + expect(true).assertEqual(number != null); + } + }); + } catch (error) { + console.error(`[bluetooth_js]SPPConnect error, code is ${error.code},message is ${error.message}`); + expect(true).assertEqual(error == null); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400 + * @tc.name test sppReadOn + * @tc.desc Test On and Off api10 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400', 0, async function (done) { + let SppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code01: ' + code); + } else { + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + + let clientNumber = -1; + function acceptClientSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth clientSocket Number: ' + number); + clientNumber = number; + expect(true).assertEqual(clientNumber != -1); + } + } + + function dataRead(dataBuffer) { + let data = new Uint8Array(dataBuffer); + console.log('bluetooth data is: ' + data[0]); + } + + + try { + bluetooth.sppListen('server04', SppOption, serverSocket); + bluetooth.sppAccept(serverNumber, acceptClientSocket); + bluetooth.on('sppRead', clientNumber, dataRead); + bluetooth.off('sppRead', clientNumber); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800 + * @tc.name test sppReadOn + * @tc.desc Test On and Off api10 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800', 0, async function (done) { + let SppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code01: ' + code); + } else { + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + let clientNumber = -1; + function acceptClientSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth clientSocket Number: ' + number); + clientNumber = number; + expect(true).assertEqual(clientNumber != -1); + } + } + function dataRead(dataBuffer) { + let data = new Uint8Array(dataBuffer); + console.log('bluetooth data is: ' + data[0]); + } + try { + bluetooth.sppListen('server08', SppOption, serverSocket); + bluetooth.sppAccept(serverNumber, acceptClientSocket); + bluetooth.on('sppRead', clientNumber, dataRead); + bluetooth.off('sppRead', clientNumber); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500 + * @tc.name testsppCloseServerSocket + * @tc.desc Test sppCloseServerSocket api10 by callback. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500', 0, async function (done) { + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code10: ' + JSON.stringify(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}; + await bluetooth.sppListen('server1', SppOption, serverSocket); + try { + bluetooth.sppCloseServerSocket(serverNumber); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(true).assertEqual(error == null); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600 + * @tc.name testsppCloseClientSocket + * @tc.desc Test sppCloseClientSocket api10 by callback. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600', 0, async function (done) { + let SppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code01: ' + code); + } else { + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + let clientNumber = -1; + function acceptClientSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth clientSocket Number: ' + number); + clientNumber = number; + expect(true).assertEqual(clientNumber != -1); + } + } + try { + bluetooth.sppListen('server06', SppOption, serverSocket); + bluetooth.sppAccept(serverNumber, acceptClientSocket); + bluetooth.sppCloseClientSocket(clientNumber); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700 + * @tc.name testSppWrite + * @tc.desc Test sppWrite api10 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700', 0, async function (done) { + let SppOption = { + uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: false, type: bluetooth.SppType.SPP_RFCOMM + }; + let serverNumber = -1; + function serverSocket(code, number) { + if (code) { + console.log('bluetooth error code01: ' + code); + } else { + console.log('bluetooth serverSocket Number:' + JSON.stringify(number)); + serverNumber = number; + expect(true).assertEqual(serverNumber != -1); + } + } + let clientNumber = -1; + function acceptClientSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth clientSocket Number: ' + number); + clientNumber = number; + expect(true).assertEqual(clientNumber != -1); + } + } + let arrayBuffer = new ArrayBuffer(8); + let data = new Uint8Array(arrayBuffer); + data[0] = 123; + try { + bluetooth.sppListen('server07', SppOption, serverSocket); + bluetooth.sppAccept(serverNumber, acceptClientSocket); + bluetooth.sppWrite(clientNumber, arrayBuffer); + } catch (err) { + console.error("errCode:" + err.code + ",errMessage:" + err.message); + expect(err.code).assertEqual('401'); + } + done(); + }) +}) +} \ No newline at end of file diff --git a/communication/bluetooth_standard/src/main/js/test/BtSpp.test.js b/communication/bluetooth_standard/src/main/js/test/BtSpp.test.js index 44d431ec8ba15b9e5df40f0ad7a735d05cf570e8..0c4bcca5a7e5c6fb6a8f0c910dea65d30020eed7 100644 --- a/communication/bluetooth_standard/src/main/js/test/BtSpp.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BtSpp.test.js @@ -81,9 +81,9 @@ describe('btSppTest', function() { serverNumber = number; expect(true).assertEqual(number!=null); } + done(); } - await bluetooth.sppListen('server1', SppOption, serverSocket); - done() + bluetooth.sppListen('server1', SppOption, serverSocket); }) /** @@ -105,9 +105,9 @@ describe('btSppTest', function() { serverNumber = number; expect(true).assertEqual(number!=null); } + done(); } - await bluetooth.sppListen('server1', sppOption, serverSocket); - done(); + bluetooth.sppListen('server1', sppOption, serverSocket); }) /** @@ -154,9 +154,9 @@ describe('btSppTest', function() { serverNumber = number; expect(true).assertEqual(serverNumber!=null); } + done(); } - await bluetooth.sppListen('server1', sppOption, serverSocket); - done(); + bluetooth.sppListen('server1', sppOption, serverSocket); }) /** @@ -175,9 +175,9 @@ describe('btSppTest', function() { console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number)); expect(true).assertEqual(number!=null); } + done(); } - await bluetooth.sppAccept(0, acceptClientSocket); - done(); + bluetooth.sppAccept(0, acceptClientSocket); }) /** diff --git a/communication/bluetooth_standard/src/main/js/test/List.test.js b/communication/bluetooth_standard/src/main/js/test/List.test.js index 7c5ca0d62262a041bd0fc939c1378c80d933e7d2..a070d9cca55f016a2429746f2886e8272b61be8c 100644 --- a/communication/bluetooth_standard/src/main/js/test/List.test.js +++ b/communication/bluetooth_standard/src/main/js/test/List.test.js @@ -13,14 +13,20 @@ * limitations under the License. */ +import btAccessTest from './BluetoothAccess.test.js' +import btManagerSwitchTest from './BtManagerSetSwitch.test.js' import btLocalNameTest from './BtSetLocalName.test.js' import btSwitchTest from './BtSetSwitch.test.js' import btSppTest from './BtSpp.test.js' import btSubscBleTest from './BtSysSubscBle.test.js' import btManagerSppTest from './BtManagerSpp.test.js' -import btManagerSwitchTest from './BtManagerSetSwitch.test.js' +import btSocketTest from './BtSocket.test.js' +import btConstantTest from './BluetoothConstant.test.js' export default function testsuite() { + btAccessTest() + btConstantTest() + btSocketTest() btLocalNameTest() btSwitchTest() btSppTest() diff --git a/communication/nfc_Controller/signature/openharmony_sx.p7b b/communication/nfc_Controller/signature/openharmony_sx.p7b index 0e5f3d2bf6baeb513ecc2a7f2e72cf1d65f4db45..c4b5472282ddd9ca3d887309bdcc3239a3a74ffa 100644 Binary files a/communication/nfc_Controller/signature/openharmony_sx.p7b and b/communication/nfc_Controller/signature/openharmony_sx.p7b differ diff --git a/communication/nfc_Controller/src/main/js/test/TagABFV.test.js b/communication/nfc_Controller/src/main/js/test/TagABFV.test.js index f1ff31472dd9ff2b5460d72ceae7b0706dea90ba..044b707417bd4840a2a42a87ddb8faafaa07a597 100644 --- a/communication/nfc_Controller/src/main/js/test/TagABFV.test.js +++ b/communication/nfc_Controller/src/main/js/test/TagABFV.test.js @@ -674,6 +674,36 @@ export default function nfcTagABFVTest() { } }) + /** + * @tc.number SUB_Communication_NFC_nfctage_js_2300 + * @tc.name Test registerForegroundDispatch + * @tc.desc This interface registerForegroundDispatch. + * @tc.size since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_nfctage_js_2300', 0, function () { + let elementName = { + "bundleName": "com.test.cardemulation", + "abilityName": "MainAbility", + "moduleName": "entry" + }; + let discTech = [1, 2, 4]; + try { + let recvNfcTagFunc = tagInfo => { + console.info("[NFC_test] controller1 nfc state receive state ->" + tagInfo); + expect(tagInfo != null).assertTrue(); + } + tag.registerForegroundDispatch(elementName, discTech, recvNfcTagFunc); + console.info('[NFC_test] nfc registerForegroundDispatch pass') + tag.unregisterForegroundDispatch(elementName); + console.info('[NFC_test] nfc unregisterForegroundDispatch pass') + } catch (error) { + console.info('nfc registerForegroundDispatch error' + error) + expect().assertFail(); + } + }) + console.info("*************[nfc_test] start nfc js unit test end*************"); }) } \ No newline at end of file diff --git a/communication/nfc_ErrorCode/signature/openharmony_sx.p7b b/communication/nfc_ErrorCode/signature/openharmony_sx.p7b index 0e5f3d2bf6baeb513ecc2a7f2e72cf1d65f4db45..c4b5472282ddd9ca3d887309bdcc3239a3a74ffa 100644 Binary files a/communication/nfc_ErrorCode/signature/openharmony_sx.p7b and b/communication/nfc_ErrorCode/signature/openharmony_sx.p7b differ diff --git a/communication/nfc_SecureElement/BUILD.gn b/communication/nfc_SecureElement/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1c50047373c3ea8da463be68e701381a9c1d14c2 --- /dev/null +++ b/communication/nfc_SecureElement/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsnfcSEServiceTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":nfc_js_assets", + ":nfc_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsnfcSEServiceTest" + part_name = "nfc" + subsystem_name = "communication" +} +ohos_js_assets("nfc_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("nfc_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/communication/nfc_SecureElement/Test.json b/communication/nfc_SecureElement/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..3ba506236f88743885c2db27a4d7232f6117d965 --- /dev/null +++ b/communication/nfc_SecureElement/Test.json @@ -0,0 +1,28 @@ +{ + "description": "Configuration for nfc js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "shell-timeout": "600000", + "testcase-timeout": "600000", + "bundle-name": "ohos.acts.communication.nfc.nfcdevice", + "package-name": "ohos.acts.communication.nfc.nfcdevice" + }, + "kits": [ + { + "test-file-name": [ + "ActsnfcSEServiceTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "svc nfc enable", + "power-shell wakeup", + "power-shell setmode 602" + ] + } + ] +} \ No newline at end of file diff --git a/communication/nfc_SecureElement/signature/openharmony_sx.p7b b/communication/nfc_SecureElement/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..c4b5472282ddd9ca3d887309bdcc3239a3a74ffa Binary files /dev/null and b/communication/nfc_SecureElement/signature/openharmony_sx.p7b differ diff --git a/communication/nfc_SecureElement/src/main/config.json b/communication/nfc_SecureElement/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c2fe619d9f4bd66d8860d66647a934cd0f09ebaf --- /dev/null +++ b/communication/nfc_SecureElement/src/main/config.json @@ -0,0 +1,105 @@ +{ + "app": { + "bundleName": "ohos.acts.communication.nfc.nfcdevice", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.communication.nfc.nfcdevice", + "name": ".entry", + "mainAbility": ".MainAbility", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "nfc_standard", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.NFC_CARD_EMULATION", + "reason": "use ohos.permission.SET_nfc_INFO" + }, + { + "name": "ohos.permission.NFC_TAG", + "reason": "use ohos.permission.NFC_TAG" + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "srcPath": "" + } +} diff --git a/communication/nfc_SecureElement/src/main/js/MainAbility/app.js b/communication/nfc_SecureElement/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..dc4c404a40e0095dc405638ea3ab78688aa84cc7 --- /dev/null +++ b/communication/nfc_SecureElement/src/main/js/MainAbility/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json b/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json b/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/communication/nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.css b/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..f709257c9c37edf2627fbd6d6ee68161fd4251a1 --- /dev/null +++ b/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.hml b/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..d28045f2adb8200db6a527b89b456112274416ec --- /dev/null +++ b/communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +