未验证 提交 f25a49e3 编写于 作者: O openharmony_ci 提交者: Gitee

!5044 【Bluetooth】脚本优化+18号问题处理

Merge pull request !5044 from 权力/myfeature
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothBLETest2() {
describe('bluetoothBLETest2', function() {
let gattServer = null;
let gattClient = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
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_BLUETOOTH_BLE_AdvertiseData_0100
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:150,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:20,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:16385,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:16400,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:19,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:-10,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:-127,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:1,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:10,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:-130,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:1,
connectable:false,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:70,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) {
let gattServer =bluetooth.BLE.createGattServer();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
gattServer.startAdvertising({
interval:1000,
txPower:-70,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
gattServer.stopAdvertising();
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothBLETest() {
describe('bluetoothBLETest', function() {
let gattServer = null;
let gattClient = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
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_BLUETOOTH_BLE_GattConnect_0100
* @tc.name test gatt connect and disconnect
* @tc.desc Test connect and disconnect api .
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
await sleep(2000);
console.info('[bluetooth_js] gattClient connect' + ret)
expect(ret).assertTrue();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0300
* @tc.name testGetConnectedBLEDevices
* @tc.desc Test getConnectedBLEDevices api .
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0300', 0, function () {
let result = bluetooth.BLE.getConnectedBLEDevices();
console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result)
+ "length:" +result.length);
expect(result.length).assertEqual(0);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100
* @tc.name testgetRssiValue
* @tc.desc Test getRssiValue api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getRssiValue().then((data) => {
console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data));
let rssiLength = Object.keys(data).length;
expect(rssiLength).assertEqual(0);
}).catch(err => {
console.error('bluetooth getRssiValue has error: '+ err);
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200
* @tc.name testgetRssiValue
* @tc.desc Test testGetDeviceName api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret))
expect(ret).assertTrue();
gattClient.getRssiValue((err, data)=> {
console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data));
expect(data).assertNull();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
await sleep(2000);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100
* @tc.name testGetDeviceName
* @tc.desc Test GetDeviceName api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getDeviceName().then((data) => {
console.info('[bluetooth_js] device name' + JSON.stringify(data))
expect(data).assertNull();
}).catch(err => {
console.error('bluetooth getDeviceName has error: '+ err);
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_getDeviceName_0200
* @tc.name testGetDeviceName
* @tc.desc Test testGetDeviceName api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
gattClient.getDeviceName((err, data)=> {
console.info('[bluetooth_js]getname value:'+JSON.stringify(data));
expect(data).assertNull();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
await sleep(2000);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100
* @tc.name testGetServices
* @tc.desc Test GetServices api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getServices().then((GattService) => {
console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService));
expect(GattService).assertNull();
}).catch(err => {
console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err));
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200
* @tc.name testGetServices
* @tc.desc Test GetServices api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js]gattClient getservices2 connect' + JSON.stringify(ret))
gattClient.getServices((code, data)=> {
if(code.code==0){
console.info("bluetooth services size is ", data.length)
expect(true).assertEqual(data.length >= 0);
} else {
console.info('[bluetooth_js] get services code ' + JSON.stringify(code));
expect(true).assertEqual(code.code == -1);
}
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(100);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(22);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(21);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(512);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(513);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readCharacteristicValue(characteristic).then((object) => {
if (object != null) {
console.error('bluetooth readCharacteristicValue promise object :'
+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js] readCharacteristicValue promise has error:'
+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) {
function readCcc(code, BLECharacteristic) {
if (code.code != 0) {
return;
}
console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid);
let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer};
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptor};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data = await gattClient.readCharacteristicValue(characteristic,readCcc);
console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data))
expect(true).assertEqual(data==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readDescriptorValue(descriptor).then((object) => {
if (object != null) {
console.error('readDescriptorValue promise object:'+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) {
function readDesc(code, BLEDescriptor) {
if (code.code != 0) {
console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid);
return;
}
console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid);
let value = new Uint8Array(BLEDescriptor.descriptorValue);
console.info('[bluetooth_js] descriptor value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data1 = await gattClient.readDescriptorValue(descriptor,readDesc);
console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1))
expect(true).assertEqual(data1==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue(characteristic);
console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue("123");
console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100
* @tc.name testWriteDescriptorValue
* @tc.desc Test Client WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200
* @tc.name testWriteDescriptorValue
* @tc.desc Test WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue("");
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setNotifyCharacteristicChanged(null, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret);
expect(ret).assertEqual(false);
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let SppType = {
SPP_RFCOMM : 0
}
let MatchMode = {
MATCH_MODE_AGGRESSIVE : 1,
MATCH_MODE_STICKY : 2
}
let MajorClass = {
MAJOR_MISC : 0x0000,
MAJOR_COMPUTER : 0x0100,
MAJOR_PHONE : 0x0200,
MAJOR_NETWORKING : 0x0300,
MAJOR_AUDIO_VIDEO : 0x0400,
MAJOR_PERIPHERAL : 0x0500,
MAJOR_IMAGING : 0x0600,
MAJOR_WEARABLE : 0x0700,
MAJOR_TOY : 0x0800,
MAJOR_HEALTH : 0x0900,
MAJOR_UNCATEGORIZED : 0x1F00
}
export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() {
let gattServer = null;
let gattClient = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
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_COMMUNACATION_bluetooth_ENABLE_0001
* @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_ENABLE_0001', 0, async function (done) {
let state = bluetooth.getState();
console.info('[bluetooth_js] getState On = '+ JSON.stringify(state));
expect(state).assertEqual(2);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_GET_CONNECTED_BLEDEVICES_0001
* @tc.name testGetConnectedBLEDevices
* @tc.desc Test getConnectedBLEDevices api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_GET_CONNECTED_BLEDEVICES_0001', 0, async function (done) {
let result = bluetooth.BLE.getConnectedBLEDevices();
console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result)+ "length:" +result.length);
expect(result.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_ADVERTISING_0001
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_ADVERTISING_0001', 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 promise = new Promise((resolve) => {
let gattServer = bluetooth.BLE.createGattServer()
gattServer.startAdvertising({
interval:150,
txPower:60,
connectable:true,
},{
serviceUuids:["12"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"1234",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["12"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"1794",
serviceValue:serviceValueBuffer.buffer
}],
});
resolve()
})
await promise.then(done)
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_STOP_ADVERTISING_0001
* @tc.name testStopAdvertising
* @tc.desc Test StopAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_STOP_ADVERTISING_0001', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_CONNRCT_0001
* @tc.name testConnect
* @tc.desc Test Connect api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_CONNRCT_0001', 0, async function (done) {
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
let ret = gattClient.connect();
expect(ret).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_RSSI_VALUE_CALLBACK
* @tc.name testGetRssiValue
* @tc.desc Test GetRssiValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_RSSI_VALUE_CALLBACK', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getRssiValue((err, data)=> {
console.info('[bluetooth_js] rssi err:' + JSON.stringify(err)+'value:'+JSON.stringify(data));
expect(data).assertNull();
});
resolve()
})
await promise.then(done)
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_RSSI_VALUE_PROMISE_0001
* @tc.name testGetRssiValue
* @tc.desc Test GetRssiValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_RSSI_VALUE_PROMISE_0001', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getRssiValue().then((data) => {
if (data != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data));
let rssiLength = Object.keys(data).length;
expect(rssiLength).assertEqual(0);
}
}).catch(err => {
console.error(`bluetooth getRssiValue has error: ${err}`);
expect(true).assertEqual(true);
});
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_DEVICE_NAME_PROMISE_0001
* @tc.name testGetDeviceName
* @tc.desc Test GetDeviceName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_DEVICE_NAME_PROMISE_0001', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getDeviceName().then((data) => {
console.info('[bluetooth_js] device name' + JSON.stringify(data))
expect(data).assertNull();
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_DEVICE_NAME_CALLBACK_0001
* @tc.name testGetDeviceName
* @tc.desc Test GetDeviceName api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_DEVICE_NAME_CALLBACK_0001', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getDeviceName((err, data)=> {
console.info('[bluetooth_js] device name' + JSON.stringify(data))
expect(data).assertNull();
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_GETSERVICES_CALLBACK_0001
* @tc.name testGetServices
* @tc.desc Test GetServices api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_GETSERVICES_CALLBACK_0001', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getServices((err, data)=> {
console.info('[bluetooth_js] device name err1 ' + JSON.stringify(err) +'name1' + JSON.stringify(data));
expect(true).assertEqual(err.code == -1);
done();
})
resolve()
})
await promise.then(done)
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_GETSERVICES_PROMISE_0001
* @tc.name testGetServices
* @tc.desc Test GetServices api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_GETSERVICES_PROMISE_0001', 0, async function (done) {
let promise = new Promise((resolve) => {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
gattClient.getServices().then((object) => {
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(err => {
console.error(`bluetooth getServices has error: ${err}`);
expect(true).assertEqual(true);
done();
});
resolve()
})
await promise.then(done)
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_SET_BLE_MTUSIZE_0001
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_SET_BLE_MTUSIZE_0001', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
let ret = gattClient.setBLEMtuSize(128);
console.info('[bluetooth_js] bluetooth setBLEMtuSize ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readCharacteristicValue(characteristic).then((object) => {
if (object != null) {
console.error('bluetooth readCharacteristicValue promise object :'
+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js] readCharacteristicValue promise has error:'
+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) {
function readCcc(code, BLECharacteristic) {
if (code.code != 0) {
return;
}
console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid);
let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer};
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptor};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data = await gattClient.readCharacteristicValue(characteristic,readCcc);
console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data))
expect(true).assertEqual(data==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_readDescriptor_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_readDescriptor_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readDescriptorValue(descriptor).then((object) => {
if (object != null) {
console.error('readDescriptorValue promise object:'+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_readDescriptor_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_readDescriptor_0200', 0, async function (done) {
function readDesc(code, BLEDescriptor) {
if (code.code != 0) {
console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid);
return;
}
console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid);
let value = new Uint8Array(BLEDescriptor.descriptorValue);
console.info('[bluetooth_js] descriptor value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data1 = await gattClient.readDescriptorValue(descriptor,readDesc);
console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1))
expect(true).assertEqual(data1==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue(characteristic);
console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue("123");
console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100
* @tc.name testWriteDescriptorValue
* @tc.desc Test Client WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200
* @tc.name testWriteDescriptorValue
* @tc.desc Test WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue("");
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setNotifyCharacteristicChanged(null, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true, includeServices: []};
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService a characteristics result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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};
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
characteristics[1] = characteristicN;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService more characteristics result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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:[]};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService not descriptors result : ' + ret);
expect(ret).assertFalse();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService a descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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};
let descriptor1 = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
descriptors[1] = descriptor1;
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService more descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isNotPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '',
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: '',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null serviceUuid result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '123@ad',
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: '123@ad',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'123@ad', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService invalid serviceUuid result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('123@ad');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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', descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret);
expect(ret).assertFalse();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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'};
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret);
expect(ret).assertFalse();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true,includeServices:[]};
let gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb',
isPrimary: false,includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService1 result : ' + ret);
expect(ret).assertTrue();
let retN = gattServer.addService(gattService1);
console.info('[bluetooth_js] bluetooth addService2 result : ' + retN);
expect(retN).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001888-0000-1000-8000-00805f9b34fb');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let ret1=gattServer.removeService('00001800-0000-1000-8000-00805f9b3442');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService result : ' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(2000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
let ret2=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(2000);
console.info('[bluetooth_js]removeService ret:'+ret2);
expect(ret2).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_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: descV};
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};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_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: descV};
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};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300', 0, async function (done) {
console.info('[bluetooth_js] SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200');
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', null);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let serverResponse = {deviceId: '00:11:22:33:44:55', transId: 1,
status: 0, offset: 0, value: arrayBuffer};
let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_GATTSERVER_CLOSE_0001
* @tc.name testBlePeripheralManagerClose
* @tc.desc Test BlePeripheralManagerClose api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_GATTSERVER_CLOSE_0001', 0, async function (done) {
try{
let gattServer = bluetooth.BLE.createGattServer()
let result = gattServer.close();
console.info("[bluetooth_js] GattserverClose res:"+ JSON.stringify(result));
expect(result).assertTrue();
}catch(error){
console.info("[bluetooth_js] GattserverClose err:" + JSON.stringify(error));
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_DISCONNRCT_0001
* @tc.name testDisConnect
* @tc.desc Test DisConnect api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_DISCONNRCT_0001', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
let ret = gattClient.disconnect();
console.info('[bluetooth_js] gatt disconnect ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_CLIENT_CLOSE_0001
* @tc.name testGattClientClose
* @tc.desc Test GattClientClose api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_CLIENT_CLOSE_0001', 0, async function (done) {
try{
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
let result = gattClient.close();
console.info("[bluetooth_js] GattclientClose result:" + JSON.stringify(result));
expect(result).assertTrue();
}catch(error){
console.info("[bluetooth_js] GattclientClose err:" + JSON.stringify(error));
expect(null).assertFail();
}
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothBLETest1() {
describe('bluetoothBLETest1', function() {
let gattServer = null;
let gattClient = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
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_BLUETOOTH_BLE_GetRssiValue_0100
* @tc.name testgetRssiValue
* @tc.desc Test getRssiValue api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getRssiValue().then((data) => {
console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data));
let rssiLength = Object.keys(data).length;
expect(rssiLength).assertEqual(0);
}).catch(err => {
console.error('bluetooth getRssiValue has error: '+ err);
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200
* @tc.name testgetRssiValue
* @tc.desc Test testGetDeviceName api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret))
expect(ret).assertTrue();
gattClient.getRssiValue((err, data)=> {
console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data));
expect(data).assertNull();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
await sleep(2000);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100
* @tc.name testGetDeviceName
* @tc.desc Test GetDeviceName api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getDeviceName().then((data) => {
console.info('[bluetooth_js] device name' + JSON.stringify(data))
expect(data).assertNull();
}).catch(err => {
console.error('bluetooth getDeviceName has error: '+ err);
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_getDeviceName_0200
* @tc.name testGetDeviceName
* @tc.desc Test testGetDeviceName api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
gattClient.getDeviceName((err, data)=> {
console.info('[bluetooth_js]getname value:'+JSON.stringify(data));
expect(data).assertNull();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
await sleep(2000);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100
* @tc.name testGetServices
* @tc.desc Test GetServices api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret))
expect(ret).assertTrue();
await gattClient.getServices().then((GattService) => {
console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService));
expect(GattService).assertNull();
}).catch(err => {
console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err));
expect(true).assertEqual(true);
});
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200
* @tc.name testGetServices
* @tc.desc Test GetServices api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.connect();
console.info('[bluetooth_js]gattClient getservices2 connect' + JSON.stringify(ret))
gattClient.getServices((code, data)=> {
if(code.code==0){
console.info("bluetooth services size is ", data.length)
expect(true).assertEqual(data.length >= 0);
} else {
console.info('[bluetooth_js] get services code ' + JSON.stringify(code));
expect(true).assertEqual(code.code == -1);
}
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(100);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(22);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(21);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(512);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setBLEMtuSize(513);
console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readCharacteristicValue(characteristic).then((object) => {
if (object != null) {
console.error('bluetooth readCharacteristicValue promise object :'
+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js] readCharacteristicValue promise has error:'
+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) {
function readCcc(code, BLECharacteristic) {
if (code.code != 0) {
return;
}
console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid);
let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer};
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptor};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data = await gattClient.readCharacteristicValue(characteristic,readCcc);
console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data))
expect(true).assertEqual(data==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.readDescriptorValue(descriptor).then((object) => {
if (object != null) {
console.error('readDescriptorValue promise object:'+JSON.stringify(object));
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(error => {
console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error));
expect(true).assertEqual(true);
done();
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) {
function readDesc(code, BLEDescriptor) {
if (code.code != 0) {
console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid);
return;
}
console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid);
let value = new Uint8Array(BLEDescriptor.descriptorValue);
console.info('[bluetooth_js] descriptor value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let data1 = await gattClient.readDescriptorValue(descriptor,readDesc);
console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1))
expect(true).assertEqual(data1==null);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 32;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue(characteristic);
console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200
* @tc.name testWriteCharacteristicValue
* @tc.desc Test Client WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeCharacteristicValue("123");
console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100
* @tc.name testWriteDescriptorValue
* @tc.desc Test Client WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () {
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200
* @tc.name testWriteDescriptorValue
* @tc.desc Test WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.writeDescriptorValue("");
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let arrayBufferNotify = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor;
descriptors[1] = descriptorNotify;
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors};
let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
let ret = gattClient.setNotifyCharacteristicChanged(null, false);
console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true, includeServices: []};
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret);
expect(ret).assertTrue();
await sleep(3000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService a characteristics result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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};
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
characteristics[1] = characteristicN;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService more characteristics result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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:[]};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService not descriptors result : ' + ret);
expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService a descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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};
let descriptor1 = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
descriptors[1] = descriptor1;
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService more descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isNotPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '',
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: '',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null serviceUuid result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '123@ad',
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: '123@ad',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'123@ad', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService invalid serviceUuid result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('123@ad');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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', descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret);
expect(ret).assertFalse();
await sleep(2000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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'};
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret);
expect(ret).assertFalse();
await sleep(2000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true,includeServices:[]};
let gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb',
isPrimary: false,includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService1 result : ' + ret);
expect(ret).assertTrue();
let retN = gattServer.addService(gattService1);
console.info('[bluetooth_js] bluetooth addService2 result : ' + retN);
expect(retN).assertTrue();
await sleep(2000);
let ret1=gattServer.removeService('00001888-0000-1000-8000-00805f9b34fb');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
let ret1=gattServer.removeService('00001800-0000-1000-8000-00805f9b3442');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300
* @tc.name testRemoveService
* @tc.desc Test RemoveService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300', 0, async function (done) {
let gattServer = bluetooth.BLE.createGattServer();
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: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
let ret2=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(2000);
console.info('[bluetooth_js]removeService ret:'+ret2);
expect(ret2).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_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: descV};
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};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_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: descV};
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};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300', 0, async function (done) {
console.info('[bluetooth_js] SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200');
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', null);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1,
status: 0, offset: 0, value: arrayBuffer};
let ret = gattServer.sendResponse(ServerResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
})
}
......@@ -13,7 +13,11 @@
* limitations under the License.
*/
import bluetoothhostTest from './BluetoothBle.test.js'
import bluetoothBLETest from './BleGattManager.test.js'
import bluetoothBLETest1 from './BleService.test.js'
import bluetoothBLETest2 from './BleAdvertiser.test.js'
export default function testsuite() {
bluetoothhostTest()
bluetoothBLETest()
bluetoothBLETest1()
bluetoothBLETest2()
}
......@@ -17,4 +17,4 @@
"cleanup-apps": true
}
]
}
\ No newline at end of file
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanDuty=
{
SCAN_MODE_LOW_POWER : 0,
SCAN_MODE_BALANCED : 1,
SCAN_MODE_LOW_LATENCY : 2,
};
let MatchMode=
{
MATCH_MODE_AGGRESSIVE : 1,
MATCH_MODE_STICKY : 2,
};
export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() {
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(5000);
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(3000);
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')
})
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_BLE_Scan_0100
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0100', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent)
bluetooth.BLE.startBLEScan(null);
await sleep(1000);
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0200
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0200', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off2');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0300
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0300', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{name:"blue_test"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off3');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0400
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0400', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result4'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off4');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0500
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0500', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off5');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0600
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0600', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
let ScanOptions= {
interval: 100,
dutyMode: ScanDuty.SCAN_MODE_BALANCED,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{}],ScanOptions);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off6');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off7');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0800
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0800', 0, async function (done) {
bluetooth.disableBluetooth();
await sleep(3000);
let state = bluetooth.getState();
console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state));
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data));
except(true).assertTrue(data.length=0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off8');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0900', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 0,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off7');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1000
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1000', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off10');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1100
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1100', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off11');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1200
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1200', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_STICKY,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off12');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1300
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1300', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{
deviceId:"11:22:33:44:55:66",
name:"test",
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
}],
{
interval: 500,
dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off13');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1400
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1400', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result14'+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{
serviceUuid:"00001812-0000-1000-8000-00805F9B34FB",
serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF",
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off14 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1500
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1500', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result15'+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{
serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB",
serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF",
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off15 ');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1600
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1600', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result16'+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
let ScanFilters= [];
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
const serviceDataArrayBuffer = new ArrayBuffer(1);
const serviceDataMaskArrayBuffer = new ArrayBuffer(1);
const serviceDataValue = new Uint8Array(serviceDataArrayBuffer);
const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer);
serviceDataValue[0] = '0xFF';
serviceDataMaskValue[0] = '0xFF';
let ScanFilter = {
serviceData:serviceDataValue,
serviceDataMask:serviceDataMaskValue,
}
ScanFilters[0]=ScanFilter;
bluetooth.BLE.startBLEScan(ScanFilters);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off16');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1700
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1700', 0, async function (done) {
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result17'+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
const manufactureDataArrayBuffer = new ArrayBuffer(29);
const manufactureDataMaskArrayBuffer = new ArrayBuffer(29);
const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer);
const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer);
for (let i = 0; i < 29; i++) {
manufactureDataValue[i] = '0xFF';
}
for (let i = 0; i < 29; i++) {
manufactureDataMaskValue[i] = '0xFF';
}
bluetooth.BLE.startBLEScan([{
manufactureId:0x0006,
manufactureData:manufactureDataValue,
manufactureDataMask:manufactureDataMaskValue,
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off17 ');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100
* @tc.name test gatt connect and disconnect
* @tc.desc Test connect and disconnect api .
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100', 0, async function (done) {
async function onReceiveEvent(ScanResult)
{
console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(ScanResult)
+ScanResult.deviceId+ScanResult.rssi+ ScanResult.data);
except(true).assertTrue(ScanResult.length>0);
await sleep(1000);
let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId);
let ret = gattClient.connect();
await sleep(2000);
console.info('[bluetooth_js] gattClient connect' + ret)
expect(ret).assertTrue();
let disconnect = gattClient.disconnect();
console.info('[bluetooth_js] gatt disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
}
await bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent);
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_STICKY,
}
);
console.info('[bluetooth_js] BLE scan offC');
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
bluetooth.BLE.stopBLEScan();
done()
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let BluetoothState=
{
STATE_OFF : 0,
STATE_TURNING_ON : 1,
STATE_ON : 2,
STATE_TURNING_OFF : 3,
STATE_BLE_TURNING_ON : 4,
STATE_BLE_ON : 5,
STATE_BLE_TURNING_OFF : 6,
}
let ScanMode =
{
SCAN_MODE_NONE : 0,
SCAN_MODE_CONNECTABLE : 1,
SCAN_MODE_GENERAL_DISCOVERABLE : 2,
SCAN_MODE_LIMITED_DISCOVERABLE : 3,
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
}
export default function bluetoothTEST() {
describe('bluetoothTEST', 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')
})
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) {
await sleep(1000);
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0500 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = 'my bluetooth';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0500 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600
* @tc.name TEST setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = 'bluetooth123';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0600 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0700 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = '蓝牙设备bluetooth';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0700 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0700 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1100 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = '蓝牙设备123';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1100 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1200 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = '蓝牙设备bluetooth12';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1200 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1200 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1400 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = '蓝牙设备*{bluetooth}';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
result=bluetooth.setLocalName(localName);
expect(result).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1400 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(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 == 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();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(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 == 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();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,40000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,40000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,20000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,30000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 4
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000', 0, async function (done) {
await tryToEnableBt();
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_1000 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(-1,0);
expect(result).assertFalse();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_1000 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == oldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400
* @tc.name testGetRemoteDeviceClass
* @tc.desc Test GetRemoteDeviceClass api 8.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400', 0, async function (done) {
console.info('[bluetooth_js] getRemoteDeviceClass start');
await tryToEnableBt();
let ret = bluetooth.getRemoteDeviceClass("00:11:22:33:44:55");
console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(ret) + 'majorClass:' +
ret.majorClass + 'majorMinorClass:'+ ret.majorMinorClass + 'classOfDevice:' + ret.classOfDevice);
expect(ret.majorClass).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
done();
} else {
expect(true).assertEqual(false);
done();
}
})
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00000000',
secure: true, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00000000-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500
* @tc.name testSppAccept
* @tc.desc Test SppAccept api 8 by callbck.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500', 0, async function (done) {
console.log("[bluetooth_js] spp accept start");
await tryToEnableBt();
function acceptClientSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] clientSocket Number: ' + number);
}
}
bluetooth.sppAccept(0, acceptClientSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600
* @tc.name testSppAccept
* @tc.desc Test SppAccept api 8 by callbck.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600', 0, async function (done) {
console.log("[bluetooth_js] spp accept start");
await tryToEnableBt();
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700
* @tc.name testSppConnect
* @tc.desc Test SppConnect api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700', 0, async function (done) {
console.info('[bluetooth_js] spp_connect start');
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800
* @tc.name testSppConnect
* @tc.desc Test SppConnect api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800', 0, async function (done) {
console.info('[bluetooth_js] spp_connect start');
await tryToEnableBt();
let sppOption = {uuid: '0000',
secure: false, type: 0};
bluetooth.sppConnect('ABC', sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:60,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:20,
txPower:60,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:16385,
txPower:60,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:16400,
txPower:60,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:19,
txPower:60,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-10,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-127,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:1,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:10,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-130,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:1,
connectable:false,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1700
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1700', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb-010203",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
console.info('[bluetooth_js] BLE advertising end');
gattServer.stopAdvertising();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "" ,
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2000
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2000', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "",
serviceValue : "",
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2400', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising end');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0200
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0200', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
let setting={
interval:1000,
txPower:-70,
connectable:true,
}
let advData={
serviceUuids : "00001888-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : "4567",
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001888-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
let advResponse ={
serviceUuids : "00001889-0000-1000-8000-00805f9b34fb",
manufactureData : {
manufactureId : 1789,
manufactureValue : manufactureValueBuffer.buffer,
},
serviceData :{
serviceUuid : "00001889-0000-1000-8000-00805f9b34fb",
serviceValue : serviceValueBuffer.buffer,
}
}
for(let i = 0;i<10;i++)
{
let gattServer =bluetooth.BLE.createGattServer();
gattServer.startAdvertising(setting,advData,advResponse);
gattServer.stopAdvertising();
console.info('[bluetooth_js] BLE advertising 第'+ JSON.stringify(i) +'次 end');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400', 0, async function (done) {
console.info('[bluetooth_js] BLE advertising start');
await tryToEnableBt();
let gattServer =bluetooth.BLE.createGattServer();
gattServer.stopAdvertising();
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let MajorMinorClass = {
COMPUTER_UNCATEGORIZED : 0x0100,
COMPUTER_DESKTOP : 0x0104,
COMPUTER_SERVER : 0x0108,
COMPUTER_LAPTOP : 0x010C,
COMPUTER_HANDHELD_PC_PDA : 0x0110,
COMPUTER_PALM_SIZE_PC_PDA : 0x0114,
COMPUTER_WEARABLE : 0x0118,
COMPUTER_TABLET : 0x011C,
PHONE_UNCATEGORIZED : 0x0200,
PHONE_CELLULAR : 0x0204,
PHONE_CORDLESS : 0x0208,
PHONE_SMART : 0x020C,
PHONE_MODEM_OR_GATEWAY : 0x0210,
PHONE_ISDN : 0x0214,
NETWORK_FULLY_AVAILABLE : 0x0300,
NETWORK_1_TO_17_UTILIZED : 0x0320,
NETWORK_17_TO_33_UTILIZED : 0x0340,
NETWORK_33_TO_50_UTILIZED : 0x0360,
NETWORK_60_TO_67_UTILIZED : 0x0380,
NETWORK_67_TO_83_UTILIZED : 0x03A0,
NETWORK_83_TO_99_UTILIZED : 0x03C0,
NETWORK_NO_SERVICE : 0x03E0,
AUDIO_VIDEO_UNCATEGORIZED : 0x0400,
AUDIO_VIDEO_WEARABLE_HEADSET : 0x0404,
AUDIO_VIDEO_HANDSFREE : 0x0408,
AUDIO_VIDEO_MICROPHONE : 0x0410,
AUDIO_VIDEO_LOUDSPEAKER : 0x0414,
AUDIO_VIDEO_HEADPHONES : 0x0418,
AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C,
AUDIO_VIDEO_CAR_AUDIO : 0x0420,
AUDIO_VIDEO_SET_TOP_BOX : 0x0424,
AUDIO_VIDEO_HIFI_AUDIO : 0x0428,
AUDIO_VIDEO_VCR : 0x042C,
AUDIO_VIDEO_VIDEO_CAMERA : 0x0430,
AUDIO_VIDEO_CAMCORDER : 0x0434,
AUDIO_VIDEO_VIDEO_MONITOR : 0x0438,
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C,
AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440,
AUDIO_VIDEO_VIDEO_GAMING_TOY : 0x0448,
PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500,
PERIPHERAL_KEYBOARD : 0x0540,
PERIPHERAL_POINTING_DEVICE : 0x0580,
PERIPHERAL_KEYBOARD_POINTING : 0x05C0,
PERIPHERAL_UNCATEGORIZED : 0x0500,
PERIPHERAL_JOYSTICK : 0x0504,
PERIPHERAL_GAMEPAD : 0x0508,
PERIPHERAL_REMOTE_CONTROL : 0x05C0,
PERIPHERAL_SENSING_DEVICE : 0x0510,
PERIPHERAL_DIGITIZER_TABLET : 0x0514,
PERIPHERAL_CARD_READER : 0x0518,
PERIPHERAL_DIGITAL_PEN : 0x051C,
PERIPHERAL_SCANNER_RFID : 0x0520,
PERIPHERAL_GESTURAL_INPUT : 0x0522,
IMAGING_UNCATEGORIZED : 0x0600,
IMAGING_DISPLAY : 0x0610,
IMAGING_CAMERA : 0x0620,
IMAGING_SCANNER : 0x0640,
IMAGING_PRINTER : 0x0680,
WEARABLE_UNCATEGORIZED : 0x0700,
WEARABLE_WRIST_WATCH : 0x0704,
WEARABLE_PAGER : 0x0708,
WEARABLE_JACKET : 0x070C,
WEARABLE_HELMET : 0x0710,
WEARABLE_GLASSES : 0x0714,
TOY_UNCATEGORIZED : 0x0800,
TOY_ROBOT : 0x0804,
TOY_VEHICLE : 0x0808,
TOY_DOLL_ACTION_FIGURE : 0x080C,
TOY_CONTROLLER : 0x0810,
TOY_GAME : 0x0814,
HEALTH_UNCATEGORIZED : 0x0900,
HEALTH_BLOOD_PRESSURE : 0x0904,
HEALTH_THERMOMETER : 0x0908,
HEALTH_WEIGHING : 0x090C,
HEALTH_GLUCOSE : 0x0910,
HEALTH_PULSE_OXIMETER : 0x0914,
HEALTH_PULSE_RATE : 0x0918,
HEALTH_DATA_DISPLAY : 0x091C,
HEALTH_STEP_COUNTER : 0x0920,
HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924,
HEALTH_PEAK_FLOW_MOITOR : 0x0928,
HEALTH_MEDICATION_MONITOR : 0x092C,
HEALTH_KNEE_PROSTHESIS : 0x0930,
HEALTH_ANKLE_PROSTHESIS : 0x0934,
HEALTH_GENERIC_HEALTH_MANAGER : 0x0938,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C
};
let ScanDuty=
{
SCAN_MODE_LOW_POWER : 0,
SCAN_MODE_BALANCED : 1,
SCAN_MODE_LOW_LATENCY : 2,
};
let MatchMode=
{
MATCH_MODE_AGGRESSIVE : 1,
MATCH_MODE_STICKY : 2,
};
export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() {
let gattServer = null;
let gattClient = null;
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
beforeEach(function () {
console.info('beforeEach called')
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
/**
* @tc.number SUB_COMMUNACATION_bluetooth_ENABLE_0001
* @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_ENABLE_0001', 0, async function (done) {
console.info('[bluetooth_js] enable start');
bluetooth.on("stateChange", onReceiveEvent);
function onReceiveEvent(data) {
if (data == bluetooth.BluetoothState.STATE_ON) {
console.info('enable bluetooth');
bluetooth.off('stateChange', result => {
expect(true).assertEqual(result ==null);
done();
});
}
}
await tryToEnableBt();
let state = bluetooth.getState();
expect(state).assertEqual(2);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001
* @tc.name testClassicStartBluetoothDiscovery
* @tc.desc Test ClassicStartBluetoothDiscovery api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
console.info('[bluetooth_js] discovery1 start');
await sleep(1000);
await tryToEnableBt();
bluetooth.on("bluetoothDeviceFind", onReceiveEvent)
function onReceiveEvent(data) {
console.info('[bluetooth_js] Device' + JSON.stringify(data)+ 'length' + data.length)
expect(true).assertTrue(data.length >= 0);
bluetooth.off('bluetoothDeviceFind', result => {
console.info("[bluetooth_js] bluetoothDeviceFind off1:" + JSON.stringify(result));
expect(true).assertEqual(true);
done();
})
}
bluetooth.startBluetoothDiscovery();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001', 0, async function (done) {
console.info('[bluetooth_js] BLE scan1 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result1 = '+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent)
bluetooth.BLE.startBLEScan([{}]);
await sleep(1000);
console.info('[bluetooth_js] BLE SCAN OFF01');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0002
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0002', 0, async function (done) {
console.info('[bluetooth_js] BLE scan2 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result2 = '+JSON.stringify(data ));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off2');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0003
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0003', 0, async function (done) {
console.info('[bluetooth_js] BLE scan3 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result3 = '+JSON.stringify(data));
except(true).assertTrue(data.length>0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{name:"blue_test"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off3');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0004
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0004', 0, async function (done) {
console.info('[bluetooth_js] BLE scan4 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data) {
console.info('[bluetooth_js] BLE scan device find result4 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length >= 0);}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan device find off4:');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0005
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0005', 0, async function (done) {
console.info('[bluetooth_js] BLE scan5 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result5 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
bluetooth.BLE.off("BLEDeviceFind");
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0006
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0006', 0, async function (done) {
console.info('[bluetooth_js] BLE scan6 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
consle.info('[bluetooth_js] BLE scan device find result6 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_BALANCED,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0007
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0007', 0, async function (done) {
console.info('[bluetooth_js] BLE scan7 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data) {
console.info('[bluetooth_js] BLE scan device find result7 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
await sleep(1000);
bluetooth.BLE.off('BLEDeviceFind');
await sleep(1000);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0008
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0008', 0, async function (done) {
console.info('[bluetooth_js] BLE scan8 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result8 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length >= 0);
}
bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent)
bluetooth.BLE.startBLEScan(
[{}],
{
interval: 0,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_STICKY,
}
);
await sleep(1000);
bluetooth.BLE.off('BLEDeviceFind');
await sleep(1000);
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0009
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0009', 0, async function (done) {
console.info('[bluetooth_js] BLE scan9 test start');
await sleep(2000);
await tryToEnableBt();
let disable = bluetooth.disableBluetooth();
console.info('[bluetooth_js] stopScan disable:' + JSON.stringify(disable));
expect(disable).assertTrue();
await sleep(3100);
let result1 = bluetooth.BLE.stopBLEScan();
console.info("[bluetooth_js] onStopBLEScan9 -> " + JSON.stringify(result1));
expect(result1).assertNull();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0010
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0010', 0, async function (done) {
console.info('[bluetooth_js] BLE scan10 test start');
await sleep(1000);
await tryToEnableBt();
let result1 = bluetooth.BLE.stopBLEScan();
console.info("[bluetooth_js] onStopBLEScan9 -> " + JSON.stringify(result1));
expect(result1).assertNull();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0011
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0011', 0, async function (done) {
console.info('[bluetooth_js] BLE scan11 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result11 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{
serviceUuid:"00001812-0000-1000-8000-00805F9B34FB",
serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF",
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off11 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0012
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0012', 0, async function (done) {
console.info('[bluetooth_js] BLE scan14 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result12 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{
serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB",
serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF",
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off12 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0013
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0013', 0, async function (done) {
console.info('[bluetooth_js] BLE scan13 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result13 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
const serviceDataArrayBuffer = new ArrayBuffer(1);
const serviceDataMaskArrayBuffer = new ArrayBuffer(1);
const serviceDataValue = new Uint8Array(serviceDataArrayBuffer);
const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer);
serviceDataValue[0] = '0xFF';
serviceDataMaskValue[0] = '0xFF';
bluetooth.BLE.startBLEScan([{
serviceData:serviceDataValue,
serviceDataMask:serviceDataMaskValue,
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off13 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0014
* @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0014', 0, async function (done) {
console.info('[bluetooth_js] BLE scan18 test start');
await sleep(1000);
await tryToEnableBt();
function onReceiveEvent(data)
{
console.info('[bluetooth_js] BLE scan device find result14 = '+ JSON.stringify(data));
expect(true).assertTrue(data.length > 0);
}
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
const manufactureDataArrayBuffer = new ArrayBuffer(29);
const manufactureDataMaskArrayBuffer = new ArrayBuffer(29);
const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer);
const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer);
for (let i = 0; i < 29; i++) {
manufactureDataValue[i] = '0xFF';
}
for (let i = 0; i < 29; i++) {
manufactureDataMaskValue[i] = '0xFF';
}
bluetooth.BLE.startBLEScan([{
manufactureData:manufactureDataValue,
manufactureDataMask:manufactureDataMaskValue,
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off14 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001
* @tc.name testClassicPairDevice
* @tc.desc Test ClassicPairDevice api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001', 0, async function (done) {
console.info('[bluetooth_js] pair device start');
await tryToEnableBt();
bluetooth.BLE.on('pinRequired', result => {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(result));
bluetooth.setDevicePairingConfirmation(result,false);
expect(true).assertEqual(result !=null);
done();
});
let enable3 = bluetooth.pairDevice("00:00:00:00:00:00")
bluetooth.BLE.off('pinRequired', result => {
console.info("[bluetooth_js] pinRequired off:" + JSON.stringify(result));
expect(true).assertEqual(true);
done();
});
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002
* @tc.name testClassicPairDevice
* @tc.desc Test ClassicPairDevice api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002', 0, async function (done) {
console.info('[bluetooth_js] pair device start');
await tryToEnableBt();
await bluetooth.BLE.on('bondStateChange', result => {
console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(result)
+'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state);
expect(true).assertEqual(result !=null);
done();
});
let BondState=
{
BOND_STATE_INVALID : 0,
BOND_STATE_BONDING : 1,
BOND_STATE_BONDED : 2
};
expect(BondState.BOND_STATE_INVALID == 0).assertTrue();
expect(BondState.BOND_STATE_BONDING == 1).assertTrue();
expect(BondState.BOND_STATE_BONDED == 2).assertTrue();
bluetooth.BLE.off('bondStateChange', result => {
expect(true).assertEqual(true);
done();
});
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
* @tc.name testSppListen
* @tc.desc Test SppListen api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
done();
} else {
expect(true).assertEqual(false);
done();
}
});
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001
* @tc.name testonCharacteristicReadOn
* @tc.desc Test CharacteristicReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] CharacteristicReadOn test start');
gattServer.on('characteristicRead', function (data) {
console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId +
'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' +
data.characteristicUuid + 'serviceUuid:' + data.serviceUuid);
let serverResponse = {
"deviceId": data.deviceId,
"transId": data.transId,
"status": 0,
"offset": data.offset,
"value": str2ab("characteristic read response", data.offset),
};
let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true");
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] characteristicRead test1 start');
gattServer.off('characteristicRead', function (data) {
console.info("[bluetooth_js] charaRead off data:" + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001
* @tc.name testonCharacteristicwriteOn
* @tc.desc Test CharacteristicwriteOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] CharacteristicwriteOn test start');
gattServer.on('characteristicWrite', function (data) {
console.info('[bluetooth_js] CharWriReq deviceId: ' + data.deviceId +
'transId:' + data.transId + 'offset:' + data.offset + 'isPrep:' + data.isPrep +
'charUuid:' + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid +
'value:' + data.value + 'needRsp' + data.needRsp);
if (data.value instanceof ArrayBuffer) {
console.log(`[bluetooth_js] value: ${ab2hex(data.value)}`)
}
if (data.needRsp == false) {
return;
}
console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`)
let serverResponse = {
"deviceId": data.deviceId,
"transId": data.transId,
"status": 0,
"offset": data.offset,
"value": data.value,
};
let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true");
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] characteristicWrite test1 start');
gattServer.off('characteristicWrite', function (data) {
console.info("[bluetooth_js] charaWrite off data2:" + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001
* @tc.name testDescriptorReadOn
* @tc.desc Test DescriptorReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] descriptorReadOn test start ...');
gattServer.on('descriptorRead', function (data) {
console.info("[bluetooth_js] DesRedon jsondata:" + JSON.stringify(data) +
'deviceId:' + data.deviceId + 'transId:' + data.transId + 'offset:' +
data.offset +'descriptorUuid:' + data.descriptorUuid + 'characteristicUuid:' +
data.characteristicUuid + 'serviceUuid:' + data.serviceUuid);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] descriptorReadOff test start ...');
gattServer.off('descriptorRead', function (data) {
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001
* @tc.name testDescriptorWriteOn
* @tc.desc Test DescriptorWriteOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] descriptorWriteOn test start ...');
gattServer.on('descriptorWrite', function (data) {
console.info("[bluetooth_js] desWriOn jsondata: " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'transId:' + data.transId + 'offset:' +
data.offset +'descriptorUuid:' + data.descriptorUuid +
'charUuid:' + data.characteristicUuid +'serviceUuid:' + data.serviceUuid +
'value:' + data.value + 'needRsp' + data.needRsp + 'isPrep:' + data.isPrep );
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] descriptorWriteOff test start ...');
gattServer.off('descriptorWrite', function (data) {
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001
* @tc.name testConnectStateChangeOn
* @tc.desc Test ConnectStateChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] ConnectStateChangeOn test start ...');
gattServer.on('connectStateChange', function (data) {
console.info("[bluetooth_js] connectStaOn jsonData -> " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] ConnectStateChangeOff test start ...');
gattServer.off('connectStateChange', function (data) {
console.info("[bluetooth_js] connectStateChange_off Data:" + JSON.stringify(data));
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001
* @tc.name testBLECharacteristicChangeOn
* @tc.desc Test BLECharacteristicChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] BLECharacteristicChangeOn test start ...');
gattClient.on('BLECharacteristicChange', function (data) {
console.info("[bluetooth_js] BLECharacteristicChange data " + JSON.stringify(data));
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] BLECharacteristicChangeOff test start');
gattClient.off('BLECharacteristicChange', function (data) {
console.info("[bluetooth_js] BLECharcChange_off data-> " + JSON.stringify(data));
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001
* @tc.name testBLEConnectionStateChangeOn
* @tc.desc Test BLEConnectionStateChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] BLEConnectionStateChangeOn test start');
gattClient.on('BLEConnectionStateChange', function (data) {
console.info("[bluetooth_js] BLEConnecStateChange_on data " + JSON.stringify(data)
+'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] BLEConnectionStateChangeOff test start');
gattClient.off('BLEConnectionStateChange', function (data) {
console.info("[bluetooth_js] BLEConneStateChange_off data-> " + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001
* @tc.name testonsppReadOn
* @tc.desc Test sppReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] sppReadOn test start');
bluetooth.on("sppRead",-1, (result) => {
console.info("[bluetooth_js] sppReadOn json_result -> " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] sppReadOff test start ...');
bluetooth.off("sppRead",-1, (result) => {
console.info("[bluetooth_js] sppReadOff json_result -> " + JSON.stringify(result));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let MajorMinorClass = {
COMPUTER_UNCATEGORIZED : 0x0100,
COMPUTER_DESKTOP : 0x0104,
COMPUTER_SERVER : 0x0108,
COMPUTER_LAPTOP : 0x010C,
COMPUTER_HANDHELD_PC_PDA : 0x0110,
COMPUTER_PALM_SIZE_PC_PDA : 0x0114,
COMPUTER_WEARABLE : 0x0118,
COMPUTER_TABLET : 0x011C,
PHONE_UNCATEGORIZED : 0x0200,
PHONE_CELLULAR : 0x0204,
PHONE_CORDLESS : 0x0208,
PHONE_SMART : 0x020C,
PHONE_MODEM_OR_GATEWAY : 0x0210,
PHONE_ISDN : 0x0214,
NETWORK_FULLY_AVAILABLE : 0x0300,
NETWORK_1_TO_17_UTILIZED : 0x0320,
NETWORK_17_TO_33_UTILIZED : 0x0340,
NETWORK_33_TO_50_UTILIZED : 0x0360,
NETWORK_60_TO_67_UTILIZED : 0x0380,
NETWORK_67_TO_83_UTILIZED : 0x03A0,
NETWORK_83_TO_99_UTILIZED : 0x03C0,
NETWORK_NO_SERVICE : 0x03E0,
AUDIO_VIDEO_UNCATEGORIZED : 0x0400,
AUDIO_VIDEO_WEARABLE_HEADSET : 0x0404,
AUDIO_VIDEO_HANDSFREE : 0x0408,
AUDIO_VIDEO_MICROPHONE : 0x0410,
AUDIO_VIDEO_LOUDSPEAKER : 0x0414,
AUDIO_VIDEO_HEADPHONES : 0x0418,
AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C,
AUDIO_VIDEO_CAR_AUDIO : 0x0420,
AUDIO_VIDEO_SET_TOP_BOX : 0x0424,
AUDIO_VIDEO_HIFI_AUDIO : 0x0428,
AUDIO_VIDEO_VCR : 0x042C,
AUDIO_VIDEO_VIDEO_CAMERA : 0x0430,
AUDIO_VIDEO_CAMCORDER : 0x0434,
AUDIO_VIDEO_VIDEO_MONITOR : 0x0438,
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C,
AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440,
AUDIO_VIDEO_VIDEO_GAMING_TOY : 0x0448,
PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500,
PERIPHERAL_KEYBOARD : 0x0540,
PERIPHERAL_POINTING_DEVICE : 0x0580,
PERIPHERAL_KEYBOARD_POINTING : 0x05C0,
PERIPHERAL_UNCATEGORIZED : 0x0500,
PERIPHERAL_JOYSTICK : 0x0504,
PERIPHERAL_GAMEPAD : 0x0508,
PERIPHERAL_REMOTE_CONTROL : 0x05C0,
PERIPHERAL_SENSING_DEVICE : 0x0510,
PERIPHERAL_DIGITIZER_TABLET : 0x0514,
PERIPHERAL_CARD_READER : 0x0518,
PERIPHERAL_DIGITAL_PEN : 0x051C,
PERIPHERAL_SCANNER_RFID : 0x0520,
PERIPHERAL_GESTURAL_INPUT : 0x0522,
IMAGING_UNCATEGORIZED : 0x0600,
IMAGING_DISPLAY : 0x0610,
IMAGING_CAMERA : 0x0620,
IMAGING_SCANNER : 0x0640,
IMAGING_PRINTER : 0x0680,
WEARABLE_UNCATEGORIZED : 0x0700,
WEARABLE_WRIST_WATCH : 0x0704,
WEARABLE_PAGER : 0x0708,
WEARABLE_JACKET : 0x070C,
WEARABLE_HELMET : 0x0710,
WEARABLE_GLASSES : 0x0714,
TOY_UNCATEGORIZED : 0x0800,
TOY_ROBOT : 0x0804,
TOY_VEHICLE : 0x0808,
TOY_DOLL_ACTION_FIGURE : 0x080C,
TOY_CONTROLLER : 0x0810,
TOY_GAME : 0x0814,
HEALTH_UNCATEGORIZED : 0x0900,
HEALTH_BLOOD_PRESSURE : 0x0904,
HEALTH_THERMOMETER : 0x0908,
HEALTH_WEIGHING : 0x090C,
HEALTH_GLUCOSE : 0x0910,
HEALTH_PULSE_OXIMETER : 0x0914,
HEALTH_PULSE_RATE : 0x0918,
HEALTH_DATA_DISPLAY : 0x091C,
HEALTH_STEP_COUNTER : 0x0920,
HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924,
HEALTH_PEAK_FLOW_MOITOR : 0x0928,
HEALTH_MEDICATION_MONITOR : 0x092C,
HEALTH_KNEE_PROSTHESIS : 0x0930,
HEALTH_ANKLE_PROSTHESIS : 0x0934,
HEALTH_GENERIC_HEALTH_MANAGER : 0x0938,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C
};
let ScanDuty=
{
SCAN_MODE_LOW_POWER : 0,
SCAN_MODE_BALANCED : 1,
SCAN_MODE_LOW_LATENCY : 2,
};
let MatchMode=
{
MATCH_MODE_AGGRESSIVE : 1,
MATCH_MODE_STICKY : 2,
};
export default function bluetoothTEST() {
describe('bluetoothTEST', function() {
let gattServer = null;
let gattClient = null;
beforeAll(function () {
console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
})
beforeEach(function () {
console.info('beforeEach called')
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
/**
* @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002
* @tc.name testClassicPairDevice
* @tc.desc Test ClassicPairDevice api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002', 0, async function (done) {
console.info('[bluetooth_js] pair device start');
await tryToEnableBt();
await bluetooth.BLE.on('bondStateChange', result => {
console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(result)
+'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state);
expect(true).assertEqual(result !=null);
done();
});
let BondState=
{
BOND_STATE_INVALID : 0,
BOND_STATE_BONDING : 1,
BOND_STATE_BONDED : 2
};
expect(BondState.BOND_STATE_INVALID == 0).assertTrue();
expect(BondState.BOND_STATE_BONDING == 1).assertTrue();
expect(BondState.BOND_STATE_BONDED == 2).assertTrue();
bluetooth.BLE.off('bondStateChange', result => {
expect(true).assertEqual(true);
done();
});
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001
* @tc.name testonCharacteristicReadOn
* @tc.desc Test CharacteristicReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] CharacteristicReadOn test start');
gattServer.on('characteristicRead', function (data) {
console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId +
'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' +
data.characteristicUuid + 'serviceUuid:' + data.serviceUuid);
let serverResponse = {
"deviceId": data.deviceId,
"transId": data.transId,
"status": 0,
"offset": data.offset,
"value": str2ab("characteristic read response", data.offset),
};
let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true");
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] characteristicRead test1 start');
gattServer.off('characteristicRead', function (data) {
console.info("[bluetooth_js] charaRead off data:" + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001
* @tc.name testonCharacteristicwriteOn
* @tc.desc Test CharacteristicwriteOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] CharacteristicwriteOn test start');
gattServer.on('characteristicWrite', function (data) {
console.info('[bluetooth_js] CharWriReq deviceId: ' + data.deviceId +
'transId:' + data.transId + 'offset:' + data.offset + 'isPrep:' + data.isPrep +
'charUuid:' + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid +
'value:' + data.value + 'needRsp' + data.needRsp);
if (data.value instanceof ArrayBuffer) {
console.log(`[bluetooth_js] value: ${ab2hex(data.value)}`)
}
if (data.needRsp == false) {
return;
}
console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`)
let serverResponse = {
"deviceId": data.deviceId,
"transId": data.transId,
"status": 0,
"offset": data.offset,
"value": data.value,
};
let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true");
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] characteristicWrite test1 start');
gattServer.off('characteristicWrite', function (data) {
console.info("[bluetooth_js] charaWrite off data2:" + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001
* @tc.name testDescriptorReadOn
* @tc.desc Test DescriptorReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] descriptorReadOn test start ...');
gattServer.on('descriptorRead', function (data) {
console.info("[bluetooth_js] DesRedon jsondata:" + JSON.stringify(data) +
'deviceId:' + data.deviceId + 'transId:' + data.transId + 'offset:' +
data.offset +'descriptorUuid:' + data.descriptorUuid + 'characteristicUuid:' +
data.characteristicUuid + 'serviceUuid:' + data.serviceUuid);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] descriptorReadOff test start ...');
gattServer.off('descriptorRead', function (data) {
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001
* @tc.name testDescriptorWriteOn
* @tc.desc Test DescriptorWriteOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] descriptorWriteOn test start ...');
gattServer.on('descriptorWrite', function (data) {
console.info("[bluetooth_js] desWriOn jsondata: " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'transId:' + data.transId + 'offset:' +
data.offset +'descriptorUuid:' + data.descriptorUuid +
'charUuid:' + data.characteristicUuid +'serviceUuid:' + data.serviceUuid +
'value:' + data.value + 'needRsp' + data.needRsp + 'isPrep:' + data.isPrep );
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] descriptorWriteOff test start ...');
gattServer.off('descriptorWrite', function (data) {
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001
* @tc.name testConnectStateChangeOn
* @tc.desc Test ConnectStateChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] ConnectStateChangeOn test start ...');
gattServer.on('connectStateChange', function (data) {
console.info("[bluetooth_js] connectStaOn jsonData -> " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] ConnectStateChangeOff test start ...');
gattServer.off('connectStateChange', function (data) {
console.info("[bluetooth_js] connectStateChange_off Data:" + JSON.stringify(data));
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001
* @tc.name testBLECharacteristicChangeOn
* @tc.desc Test BLECharacteristicChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] BLECharacteristicChangeOn test start ...');
gattClient.on('BLECharacteristicChange', function (data) {
console.info("[bluetooth_js] BLECharacteristicChange data " + JSON.stringify(data));
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] BLECharacteristicChangeOff test start');
gattClient.off('BLECharacteristicChange', function (data) {
console.info("[bluetooth_js] BLECharcChange_off data-> " + JSON.stringify(data));
expect(true).assertTrue();
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001
* @tc.name testBLEConnectionStateChangeOn
* @tc.desc Test BLEConnectionStateChangeOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] BLEConnectionStateChangeOn test start');
gattClient.on('BLEConnectionStateChange', function (data) {
console.info("[bluetooth_js] BLEConnecStateChange_on data " + JSON.stringify(data)
+'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] BLEConnectionStateChangeOff test start');
gattClient.off('BLEConnectionStateChange', function (data) {
console.info("[bluetooth_js] BLEConneStateChange_off data-> " + JSON.stringify(data));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001
* @tc.name testonsppReadOn
* @tc.desc Test sppReadOn api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] sppReadOn test start');
bluetooth.on("sppRead",-1, (result) => {
console.info("[bluetooth_js] sppReadOn json_result -> " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] sppReadOff test start ...');
bluetooth.off("sppRead",-1, (result) => {
console.info("[bluetooth_js] sppReadOff json_result -> " + JSON.stringify(result));
expect(true).assertEqual(true);
});
}catch(e) {
expect(null).assertFail();
}
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothhostTest2() {
describe('bluetoothhostTest2', function() {
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(5000);
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(3000);
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')
})
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_BR_Pair_0200
* @tc.name testStartpair
* @tc.desc Test pairDevice of use vailded address.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0200', 0, async function (done) {
function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId,false);
}
bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("SSS");
console.info("[bluetooth_js] onStartpair -> " + JSON.stringify(result));
expect(result).assertFalse();
bluetooth.BLE.off('pinRequired', PinRequiredParam);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0300
* @tc.name test getRemoteDeviceName
* @tc.desc Test get RemoteDeviceName
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0300', 0, async function (done) {
let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00");
console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret));
expect(ret.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400
* @tc.name test getRemoteDeviceClass
* @tc.desc Test get RemoteDeviceClass
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400', 0, async function (done) {
let MajorMinorClass = {
COMPUTER_UNCATEGORIZED : 0x0100,COMPUTER_DESKTOP : 0x0104,
COMPUTER_SERVER : 0x0108,COMPUTER_LAPTOP : 0x010C,
COMPUTER_HANDHELD_PC_PDA : 0x0110,COMPUTER_PALM_SIZE_PC_PDA : 0x0114,
COMPUTER_WEARABLE : 0x0118,COMPUTER_TABLET : 0x011C,
PHONE_UNCATEGORIZED : 0x0200,PHONE_CELLULAR : 0x0204,
PHONE_CORDLESS : 0x0208,PHONE_SMART : 0x020C,
PHONE_MODEM_OR_GATEWAY : 0x0210,PHONE_ISDN : 0x0214,
NETWORK_FULLY_AVAILABLE : 0x0300,NETWORK_1_TO_17_UTILIZED : 0x0320,
NETWORK_17_TO_33_UTILIZED : 0x0340,NETWORK_33_TO_50_UTILIZED : 0x0360,
NETWORK_60_TO_67_UTILIZED : 0x0380,NETWORK_67_TO_83_UTILIZED : 0x03A0,
NETWORK_83_TO_99_UTILIZED : 0x03C0,NETWORK_NO_SERVICE : 0x03E0,
AUDIO_VIDEO_UNCATEGORIZED : 0x0400,AUDIO_VIDEO_WEARABLE_HEADSET: 0x0404,
AUDIO_VIDEO_HANDSFREE : 0x0408,AUDIO_VIDEO_MICROPHONE : 0x0410,
AUDIO_VIDEO_LOUDSPEAKER : 0x0414,AUDIO_VIDEO_HEADPHONES : 0x0418,
AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C,AUDIO_VIDEO_CAR_AUDIO : 0x0420,
AUDIO_VIDEO_SET_TOP_BOX : 0x0424,AUDIO_VIDEO_HIFI_AUDIO : 0x0428,
AUDIO_VIDEO_VCR : 0x042C,AUDIO_VIDEO_VIDEO_CAMERA : 0x0430,
AUDIO_VIDEO_CAMCORDER : 0x0434,AUDIO_VIDEO_VIDEO_MONITOR : 0x0438,
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C,
AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440,AUDIO_VIDEO_VIDEO_GAMING_TOY: 0x0448,
PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500,
PERIPHERAL_KEYBOARD : 0x0540,PERIPHERAL_POINTING_DEVICE : 0x0580,
PERIPHERAL_KEYBOARD_POINTING : 0x05C0,PERIPHERAL_UNCATEGORIZED : 0x0500,
PERIPHERAL_JOYSTICK : 0x0504,PERIPHERAL_GAMEPAD : 0x0508,
PERIPHERAL_REMOTE_CONTROL : 0x05C0,PERIPHERAL_SENSING_DEVICE : 0x0510,
PERIPHERAL_DIGITIZER_TABLET : 0x0514,
PERIPHERAL_CARD_READER : 0x0518,PERIPHERAL_DIGITAL_PEN : 0x051C,
PERIPHERAL_SCANNER_RFID : 0x0520,PERIPHERAL_GESTURAL_INPUT : 0x0522,
IMAGING_UNCATEGORIZED : 0x0600,IMAGING_DISPLAY : 0x0610,
IMAGING_CAMERA : 0x0620,IMAGING_SCANNER : 0x0640,
IMAGING_PRINTER : 0x0680,WEARABLE_UNCATEGORIZED : 0x0700,
WEARABLE_WRIST_WATCH : 0x0704,WEARABLE_PAGER : 0x0708,
WEARABLE_JACKET : 0x070C,WEARABLE_HELMET : 0x0710,
WEARABLE_GLASSES : 0x0714,TOY_UNCATEGORIZED : 0x0800,
TOY_ROBOT : 0x0804,TOY_VEHICLE : 0x0808,
TOY_DOLL_ACTION_FIGURE : 0x080C,TOY_CONTROLLER : 0x0810,
TOY_GAME : 0x0814,HEALTH_UNCATEGORIZED : 0x0900,
HEALTH_BLOOD_PRESSURE : 0x0904,HEALTH_THERMOMETER : 0x0908,
HEALTH_WEIGHING : 0x090C,HEALTH_GLUCOSE : 0x0910,
HEALTH_PULSE_OXIMETER : 0x0914,HEALTH_PULSE_RATE : 0x0918,
HEALTH_DATA_DISPLAY : 0x091C,HEALTH_STEP_COUNTER : 0x0920,
HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924,
HEALTH_PEAK_FLOW_MOITOR : 0x0928,HEALTH_MEDICATION_MONITOR : 0x092C,
HEALTH_KNEE_PROSTHESIS : 0x0930,HEALTH_ANKLE_PROSTHESIS : 0x0934,
HEALTH_GENERIC_HEALTH_MANAGER : 0x0938,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C,
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C
};
let MajorClass = {
MAJOR_MISC : 0x0000,MAJOR_COMPUTER : 0x0100,
MAJOR_PHONE : 0x0200,MAJOR_NETWORKING : 0x0300,
MAJOR_AUDIO_VIDEO: 0x0400,MAJOR_PERIPHERAL : 0x0500,
MAJOR_IMAGING : 0x0600,MAJOR_WEARABLE : 0x0700,
MAJOR_TOY : 0x0800,MAJOR_HEALTH : 0x0900,
MAJOR_UNCATEGORIZED : 0x1F00
};
let DeviceClass = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00");
console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(DeviceClass)
+ 'majorClass:' +DeviceClass.majorClass + 'majorMinorClass:'+ DeviceClass.majorMinorClass
+ 'classOfDevice:' + DeviceClass.classOfDevice);
expect(DeviceClass.majorClass).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0500
* @tc.name test getRemoteDeviceClass
* @tc.desc Test get getRemoteDeviceClass
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0500', 0, async function (done) {
let ret = bluetooth.getRemoteDeviceName("1125445");
console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret));
expect(ret.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0600
* @tc.name test getPairedDevices
* @tc.desc Test get getPairedDevices
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0600', 0, async function (done) {
let ret = bluetooth.getPairedDevices();
console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret));
expect(ret.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0700
* @tc.name test pinRequired
* @tc.desc Test pinRequired and setDevicePairing false
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0700', 0, async function (done) {
function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId,false);
}
bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("00:00:00:00:00:00");
console.info("[bluetooth_js] onStartpair007 -> " + JSON.stringify(result));
expect(result).assertTrue();
bluetooth.BLE.off('pinRequired', PinRequiredParam);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0800
* @tc.name test pinRequired
* @tc.desc Test pinRequired and setDevicePairing true
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0800', 0, async function (done) {
function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId,true);
}
bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("00:00:00:00:00:00");
console.info("[bluetooth_js] onStartpair008 -> " + JSON.stringify(result));
expect(result).assertTrue();
bluetooth.BLE.off('pinRequired', PinRequiredParam);
done()
})
})
}
......@@ -13,9 +13,15 @@
* limitations under the License.
*/
import bluetoothTEST from './BluetoothADD.test.js'
import bluetoothhostTest from './BluetoothOn.test.js'
import bluetoothTEST from './BluetoothOn.test.js'
import bluetoothhostTest from './BleScanResult.test.js'
import bluetoothhostTest2 from './BluetoothPair.test.js'
import bluetoothhostTest1 from './bluetoothProfileAdd.test.js'
import bluetoothhostTest4 from './bluetoothSys.test.js'
export default function testsuite() {
bluetoothTEST()
bluetoothhostTest()
bluetoothTEST()
bluetoothhostTest2()
bluetoothhostTest1()
bluetoothhostTest4()
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothhostTest1() {
describe('bluetoothhostTest1', 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')
})
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001
* @tc.name testClassicGetBtConnectionState
* @tc.desc Test ClassicGetBtConnectionState api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001', 0, async function (done) {
console.info('[bluetooth_js] get connection state start');
await tryToEnableBt();
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3,
};
let connState = bluetooth.getBtConnectionState();
console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState));
expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState );
done();
})
})
}
/*
* 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';
import bluetoothsys from '@system.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothhostTest4() {
describe('bluetoothhostTest4', function() {
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(5000);
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(3000);
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')
})
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_COMMUNACATION_bluetooth_SUBSCRIBE_BLEFound_0001
* @tc.name testsubscribeBLEFound
* @tc.desc Test subscribeBLEFound api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SUBSCRIBE_BLEFound_0001', 0, async function (done) {
bluetoothsys.startBLEScan({
interval:0,
success() {
console.log('[bluetooth_js] startBLEScan1 success.');
bluetoothsys.subscribeBLEFound({
success(data) {
console.log('[bluetooth_js] bluetooth.subscribeBLEFound1 success.');
const [device] = data.devices;
console.log('[bluetooth_js] devices:'+ JSON.stringify(data.devices) + 'length:' + data.devices.length);
expect(true).assertTrue(data.devices.length >=0);
for (let i = 0; i < data.devices.length; i++) {
console.log(`subscribeBLEFound device, addrType: ${data.devices[i].addrType}`);
console.log(`subscribeBLEFound device, addr: ${data.devices[i].addr}`);
console.log(`subscribeBLEFound device, rssi: ${data.devices[i].rssi}`);
console.log(`subscribeBLEFound device, txpower: ${data.devices[i].txpower}`);
console.log(`subscribeBLEFound device, data: ${data.devices[i].data}`);
}
},
fail(code, data) {
console.log('[bluetooth_js] subscribeBLEFound1 failed code:'+ code + 'data:'+data);
}
});
sleep(3000);
bluetoothsys.unsubscribeBLEFound();
bluetoothsys.stopBLEScan({
success() {
console.log('[bluetooth_js] stopBLEScan success.');
},
fail(data, code) {
console.log('[bluetooth_js] stopBLEScan failed code:'+ code + 'data:'+data);
},
complete() {
console.log('[bluetooth_js] stopBLEScan complete.');
}
});
},
fail(code, data) {
console.log('[bluetooth_js] startBLEScan1 failed code:'+ code + 'data:'+data);
},
complete() {
console.log('[bluetooth_js] startBLEScan1 complete.');
}
});
done();
})
})
}
......@@ -5,7 +5,8 @@
"test-timeout": "600000",
"shell-timeout": "600000",
"bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"package-name": "ohos.acts.communication.bluetooth.bluetoothhost"
"package-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"testcase-timeout": 70000
},
"kits": [
{
......@@ -16,4 +17,4 @@
"cleanup-apps": true
}
]
}
\ No newline at end of file
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanMode =
{
SCAN_MODE_NONE : 0,
SCAN_MODE_CONNECTABLE : 1,
SCAN_MODE_GENERAL_DISCOVERABLE : 2,
SCAN_MODE_LIMITED_DISCOVERABLE : 3,
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
}
export default function bluetoothhostTest3() {
describe('bluetoothhostTest3', function() {
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(5000);
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(3000);
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')
})
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_BR_Discovery_0100
* @tc.name TEST DISCOVERY
* @tc.desc TEST DISCOVERY
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_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);
}
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();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300
* @tc.name TEST DISCOVERY
* @tc.desc TEST DISCOVERY api 8.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300', 0, async function (done) {
let result1 = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE,10);
expect(result1).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE);
let result = bluetooth.startBluetoothDiscovery();
await sleep(2000);
console.info('[bluetooth_js] startDiscovery1'+result);
expect(result).assertTrue();
let result2 = bluetooth.startBluetoothDiscovery();
console.info('[bluetooth_js] startDiscovery2'+result2);
expect(result2).assertFalse();
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanMode =
{
SCAN_MODE_NONE : 0,
SCAN_MODE_CONNECTABLE : 1,
SCAN_MODE_GENERAL_DISCOVERABLE : 2,
SCAN_MODE_LIMITED_DISCOVERABLE : 3,
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
}
export default function bluetoothhostTest2() {
describe('bluetoothhostTest2', function() {
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(5000);
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(3000);
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')
})
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_BR_ScanMode_0100
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(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 == 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();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(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 == 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();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,40000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,40000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,20000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,30000);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 4
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_1000 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(-1,0);
expect(result).assertFalse();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_1000 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == oldScanMode);
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let Btname = {
NUM_TEST :'012345678901234567890123456789012345678901234567890123'+
'45678901234567890123456789012345678901234567890123456789012345678901234567',
NUM_TEST1 :'0123456789012345678901234567890123456789012345678901'
+'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
+'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
+'01234567890123456789012345678912',
LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙',
SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×'
+'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓',
MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw',
MIXES2:'——◎◇◆□■△▲测试蓝牙',
MIXES3:'78453-、、。。◎◇◆□■△▲',
MIXES4:'hhhfdf-、、。。◎◇◆□■△▲',
MIXES5:'#01-5@<?;:!@$%^&*(1[]{【+-;:‘’“”测试=》《\'[6]',
MIXES6:'#01-567890@<>?/;:5675ASDF012345678!@'
+'$%^&*()9012378901[]{}【】566~·67890blue',
MIXES7:'0123456789012345678901234567890123456789012345678901'
+'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
+'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
+'012345678901234567890123456789123'
}
export default function bluetoothhostTest1() {
describe('bluetoothhostTest1', function() {
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(5000);
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(3000);
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')
})
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_BR_LocalName_0100
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100', 0, async function (done) {
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(localName));
expect(true).assertEqual(localName!=null);
let newName = 'bluetoothtest';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
let result1=bluetooth.setLocalName(localName);
expect(result1).assertTrue();
let getLocalName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0100 localName = '+ JSON.stringify(getLocalName));
expect(true).assertEqual(localName == getLocalName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.LETTERS_TEST);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.LETTERS_TEST == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.CHINESES_TEST);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0300 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.CHINESES_TEST == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.NUM_TEST);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0400 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.NUM_TEST == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.SYMBOL_TEST);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) {
let newName = 'my bluetooth';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0600 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700
* @tc.name setLocalName
* @tc.desc Test setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) {
let newName = 'bluetooth1234ABCDEFGH';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0700 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800', 0, async function (done) {
let newName = '蓝牙设备bluetooth';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0800 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES4);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0900 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES4 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES2);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1000 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES2 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES3);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES3 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) {
let newName = '蓝牙设备123';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1200 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300', 0, async function (done) {
let newName = '蓝牙设备bluetooth12';
let result = bluetooth.setLocalName(newName);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1300 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(newName == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES6);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES6 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1500 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES5);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1600 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.MIXES5 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.NUM_TEST1);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1700 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.NUM_TEST1 == getNewName);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800
* @tc.name TEST setLocalName
* @tc.desc TEST setLocalName api by promise.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.MIXES7);
expect(result).assertTrue();
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_1800 NewName = '+ JSON.stringify(getNewName));
expect(false).assertEqual(Btname.MIXES7 == getNewName);
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothhostTest4() {
describe('bluetoothhostTest4', function() {
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
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_BLUETOOTH_BR_SPP_0100
* @tc.name testSppListen
* @tc.desc Test secure SppListen
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100', 0, async function (done) {
let SppType = {
SPP_RFCOMM : 0
}
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: SppType.SPP_RFCOMM};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', SppOption, serverSocket);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200', 0, async function (done) {
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300', 0, async function (done) {
let sppOption = {uuid: '00000000',
secure: true, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400
* @tc.name testSppListen
* @tc.desc Test SppListen api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400', 0, async function (done) {
let sppOption = {uuid: '00000000-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] serverSocket Number: ' + number);
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500
* @tc.name testSppAccept
* @tc.desc Test SppAccept api 8 by callbck.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500', 0, async function (done) {
function acceptClientSocket(code, number) {
console.log('[bluetooth_js] error code: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js] clientSocket Number: ' + number);
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppAccept(0, acceptClientSocket);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600
* @tc.name testSppAccept
* @tc.desc Test SppAccept api 8 by callbck.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600', 0, async function (done) {
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber);
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700
* @tc.name testSppConnect
* @tc.desc Test SppConnect api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700', 0, async function (done) {
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppConnect Number:' + clientSocketNumber);
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800
* @tc.name testSppConnect
* @tc.desc Test SppConnect api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800', 0, async function (done) {
let sppOption = {uuid: '0000',
secure: false, type: 0};
bluetooth.sppConnect('ABC', sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber);
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0900
* @tc.name testSppConnect
* @tc.desc Test SppConnect api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0900', 0, async function (done) {
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppConnect('BT', sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber);
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000
* @tc.name testsppCloseServerSocket
* @tc.desc Test sppCloseServerSocket api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000', 0, async function (done) {
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppListen('server1', SppOption, serverSocket);
bluetooth.sppCloseServerSocket(serverNumber);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000
* @tc.name testsppCloseClientSocket
* @tc.desc Test sppCloseClientSocket api 8 by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1100', 0, async function (done) {
let clientNumber = -1;
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber);
clientNumber =clientSocketNumber;
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
bluetooth.sppCloseClientSocket(clientNumber);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200
* @tc.name testSppWrite
* @tc.desc Test sppWrite
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200', 0, async function (done) {
let clientNumber = -1;
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber);
clientNumber =clientSocketNumber;
expect(true).assertEqual(clientSocketNumber!=null);
} else {
expect(true).assertEqual(false);
}
});
let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer);
data[0] = 123;
let ret = bluetooth.sppWrite(clientNumber, arrayBuffer);
console.info('[bluetooth_js] bluetooth sppWrite ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let BluetoothState=
{
STATE_OFF : 0,
STATE_TURNING_ON : 1,
STATE_ON : 2,
STATE_TURNING_OFF : 3,
STATE_BLE_TURNING_ON : 4,
STATE_BLE_ON : 5,
STATE_BLE_TURNING_OFF : 6,
}
export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() {
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(5000);
let sta1 = bluetooth.getState();
console.info('[bluetooth_js] Reacquire bt state:'+ 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(3000);
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')
})
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_BR_Switch_0100
* @tc.name testEnableBluetooth and getState
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0100', 0, async function (done) {
let state = bluetooth.getState();
console.info('[bluetooth_js] get bluetooth state result'+ JSON.stringify(state));
if(state!=BluetoothState.STATE_ON)
{
let enable = bluetooth.enableBluetooth();
await sleep(3000);
console.info('[bluetooth_js] bluetooth enable result'+JSON.stringify(enable));
expect(enable).assertTrue();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] enable state1 '+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_ON);
}
let disable = bluetooth.disableBluetooth();
await sleep(3000);
console.info('[bluetooth_js] bluetooth disable result'+JSON.stringify(disable));
expect(disable).assertTrue();
let state2 = bluetooth.getState();
console.info('[bluetooth_js] disable state2 '+ JSON.stringify(state2));
expect(state2).assertEqual(BluetoothState.STATE_OFF);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300
* @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) {
let state = bluetooth.getState();
console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state));
expect(state).assertEqual(BluetoothState.STATE_ON);
if(state==BluetoothState.STATE_ON) {
let enable1=bluetooth.enableBluetooth();
await sleep(3000);
console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1));
expect(enable1).assertFalse();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] bt open state2='+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_ON);
}else{
console.info('[bluetooth_js]bluetooth open fail');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0400
* @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0400', 0, async function (done) {
let result1= bluetooth.disableBluetooth();
await sleep(3000);
console.info('[bluetooth_js] disable result'+ JSON.stringify(result1));
expect(result1).assertTrue();
let state = bluetooth.getState();
console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state));
expect(state).assertEqual(BluetoothState.STATE_OFF);
if(state == BluetoothState.STATE_OFF) {
let result2= bluetooth.disableBluetooth();
console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2));
expect(result2).assertFalse();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_OFF);
}
done();
})
})
}
/*
* 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let Btname = {
NUM_TEST :'012345678901234567890123456789012345678901234567890123'+
'45678901234567890123456789012345678901234567890123456789012345678901234567',
NUM_TEST1 :'01234567890123456789012345678901234567890123456'
+'7890123456789012345678901234567890123456789012345678901234567890123456789012345678',
LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙',
SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×'
+'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓',
MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw',
MIXES2:'——◎◇◆□■△▲测试蓝牙',
MIXES3:'78453-、、。。◎◇◆□■△▲',
MIXES4:'hhhfdf-、、。。◎◇◆□■△▲',
MIXES5:'#01-5@<?;:!@$%^&*(1[]{【+-;:‘’“”测试=》《\'[6]',
MIXES6:'#01-567890@<>?/;:5675ASDF012345678!@'
+'$%^&*()9012378901[]{}【】566~·67890blue',
MIXES7:'0123456789012345678901234567890123456789012345678901'
+'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
+'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
}
export default function bluetoothhostTest() {
describe('bluetoothhostTest', 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')
})
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
bluetooth.enableBluetooth();
await sleep(3000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_STATE_0001
* @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_STATE_0001', 0, async function (done) {
console.info('[bluetooth_js] getState start');
await tryToEnableBt();
let state = bluetooth.getState();
let BluetoothState=
{
STATE_OFF : 0,
STATE_TURNING_ON : 1,
STATE_ON : 2,
STATE_TURNING_OFF : 3,
STATE_BLE_TURNING_ON : 4,
STATE_BLE_ON : 5,
STATE_BLE_TURNING_OFF : 6,
} ;
console.info('[bluetooth_js] get bluetooth state result = '+ JSON.stringify(state));
expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON);
expect(BluetoothState.STATE_OFF != state).assertTrue();
expect(BluetoothState.STATE_TURNING_ON != state).assertTrue();
expect(BluetoothState.STATE_TURNING_OFF != state).assertTrue();
expect(BluetoothState.STATE_BLE_TURNING_ON != state).assertTrue();
expect(BluetoothState.STATE_BLE_ON != state).assertTrue();
expect(BluetoothState.STATE_BLE_TURNING_OFF != state).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001
* @tc.name testClassicSetLocalName
* @tc.desc Test ClassicSetLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001', 0, async function (done) {
console.info('[bluetooth_js] set localname start');
await tryToEnableBt();
let name = bluetooth.setLocalName('bluetooth_test');
console.info('[bluetooth_js] appInfoTest enable bluetooth result = '+ JSON.stringify(name));
expect(name).assertEqual(true);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_PAIR_0001
* @tc.name testStartpair
* @tc.desc Test Startpair api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_PAIR_0001', 0, async function (done) {
console.info('[bluetooth_js] Startpair test start ...');
await tryToEnableBt();
let result = bluetooth.pairDevice("00:00:00:00:00:00");
console.info("[bluetooth_js] onStartpair -> " + JSON.stringify(result));
expect(result).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001
* @tc.name testClassicGetLocalName
* @tc.desc Test ClassicGetLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001', 0, async function (done) {
console.info('[bluetooth_js] get localName start');
await tryToEnableBt();
let localName = bluetooth.getLocalName();
console.info('[bluetooth_js] get local Name result = ' + JSON.stringify(localName));
expect(localName).assertEqual('bluetooth_test');
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001
* @tc.name testClassicSetBluetoothScanMode
* @tc.desc Test ClassicSetBluetoothScanMode api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
console.info('[bluetooth_js] set scan mode start');
await tryToEnableBt();
let result = bluetooth.setBluetoothScanMode(1,10000);
let ScanDuty=
{
SCAN_MODE_LOW_POWER : 0,
SCAN_MODE_BALANCED : 1,
SCAN_MODE_BALANCED : 2,
};
expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_LOW_POWER) !=result );
expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_BALANCED) != result);
expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_BALANCED) != result );
expect(result).assertEqual(true);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001
* @tc.name testClassicGetBluetoothScanMode
* @tc.desc Test ClassicGetBluetoothScanMode api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
console.info('[bluetooth_js] get scan mode start');
await tryToEnableBt();
let result = bluetooth.setBluetoothScanMode(1,10000);
expect(result).assertEqual(true);
let ScanMode=
{
SCAN_MODE_NONE : 0,
SCAN_MODE_CONNECTABLE : 1,
SCAN_MODE_GENERAL_DISCOVERABLE : 2,
SCAN_MODE_LIMITED_DISCOVERABLE : 3,
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
};
let scanModeResult = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] get scan mode result2 = ' + JSON.stringify(scanModeResult));
expect(scanModeResult).assertEqual(1);
expect(true).assertTrue(ScanMode.SCAN_MODE_NONE != scanModeResult);
expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE != scanModeResult);
expect(true).assertTrue(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE != scanModeResult);
expect(true).assertTrue(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE != scanModeResult);
expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE != scanModeResult);
expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE != scanModeResult);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001
* @tc.name testClassicGetBtConnectionState
* @tc.desc Test ClassicGetBtConnectionState api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001', 0, async function (done) {
console.info('[bluetooth_js] get connection state start');
await tryToEnableBt();
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3,
};
let connState = bluetooth.getBtConnectionState();
console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState));
expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState );
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001
* @tc.name testClassicStartBluetoothDiscovery
* @tc.desc Test ClassicStartBluetoothDiscovery api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
console.info('[bluetooth_js] discovery start');
await tryToEnableBt();
let result = bluetooth.startBluetoothDiscovery();
console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(result));
expect(result).assertEqual(true);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001
* @tc.name testClassicStopBluetoothDiscovery
* @tc.desc Test ClassicStopBluetoothDiscovery api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
console.info('[bluetooth_js] stop discovery start');
await tryToEnableBt();
let result = bluetooth.stopBluetoothDiscovery();
console.info("stopBluetoothDiscovery :" + JSON.stringify(result));
expect(result).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001
* @tc.name testClassicGetPairedDevices
* @tc.desc Test ClassicGetPairedDevices api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001', 0, async function (done) {
console.info('[bluetooth_js] get paired devices start');
await tryToEnableBt();
let devices = bluetooth.getPairedDevices();
console.info('[bluetooth_js] get paired devices:' + JSON.stringify(devices) +'length:' + devices.length);
expect(devices.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
* @tc.name testSppListen
* @tc.desc Test SppListen api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) {
console.log("[bluetooth_js]: spp listen start");
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: 0};
bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
done();
} else {
expect(true).assertEqual(false);
done();
}
});
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001
* @tc.name testSppAccept
* @tc.desc Test SppAccept api by callbck.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001', 0, async function (done) {
console.log("[bluetooth_js] spp accept start");
await tryToEnableBt();
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001
* @tc.name testSppCloseServerSocket
* @tc.desc Test SppCloseServerSocket api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001', 0, async function (done) {
console.log("[bluetooth_js] spp closeServerSocket start");
await tryToEnableBt();
setTimeout(async ()=>{
bluetooth.sppCloseServerSocket(-1);
},3000);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001
* @tc.name testSppConnect
* @tc.desc Test SppConnect api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001', 0, async function (done) {
console.info('[bluetooth_js] spp_connect start');
await tryToEnableBt();
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppConnect(55, sppOption, function(code, clientSocketNumber) {
console.info('[bluetooth_js] code is: ' + code.code);
if (code.code == 0) {
expect(true).assertEqual(true);
} else {
expect(true).assertEqual(false);
}
});
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001
* @tc.name testSppWrite
* @tc.desc Test SppWrite api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001', 0, async function (done) {
console.info('[bluetooth_js] spp write start');
await tryToEnableBt();
let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer);
data[0] = 123;
let ret = bluetooth.sppWrite(-1, arrayBuffer);
console.info('[bluetooth_js] bluetooth sppWrite ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_CLOSE_CLIENT_SOCKET_0001
* @tc.name testSppCloseClientSocket
* @tc.desc Test SppCloseClientSocket api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SPP_CLOSE_CLIENT_SOCKET_0001', 0, async function (done) {
console.log("[bluetooth_js] spp closeClientSocket start");
await tryToEnableBt();
setTimeout(async ()=>{
bluetooth.sppCloseClientSocket(-1);
},3000);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001
* @tc.name testGetRemoteDeviceName
* @tc.desc Test GetRemoteDeviceName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001', 0, async function (done) {
console.info('[bluetooth_js] getRemoteDeviceName start');
await tryToEnableBt();
let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00");
console.info('[bluetooth_js] getRemoteDeviceName ret2 : ' + JSON.stringify(ret));
expect(ret.length).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001
* @tc.name testGetRemoteDeviceClass
* @tc.desc Test GetRemoteDeviceClass api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001', 0, async function (done) {
console.info('[bluetooth_js] getRemoteDeviceClass start');
await tryToEnableBt();
let ret = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00");
console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(ret) + 'majorClass:' +
ret.majorClass + 'majorMinorClass:'+ ret.majorMinorClass + 'classOfDevice:' + ret.classOfDevice);
expect(ret.majorClass).assertEqual(0);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.getLocalName();
let set = bluetooth.setLocalName('');
expect(set).assertFalse();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(localName==name);
console.info('[bluetooth_js] getLocalName result1 = ' + JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002', 0, async function (done) {
await tryToEnableBt();
let localName = bluetooth.getLocalName();
let name = bluetooth.setLocalName();
console.info('[bluetooth_js] getName result2 = '+ JSON.stringify(localName) +
'setName result2 =' + JSON.stringify(name));
expect(name).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0003
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0003', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.NUM_TEST);
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.NUM_TEST == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0004
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0004', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.NUM_TEST1);
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.NUM_TEST1 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.LETTERS_TEST);
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.LETTERS_TEST == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.CHINESES_TEST);
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.CHINESES_TEST == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0007
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0007', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.SYMBOL_TEST);
console.info('[bluetooth_js] setLocalName result7 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.SYMBOL_TEST == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0008
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0008', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES);
console.info('[bluetooth_js] setLocalName result8 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0009
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0009', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES2);
console.info('[bluetooth_js] setLocalName result9 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES2 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00010
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00010', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES3);
console.info('[bluetooth_js] setLocalName result10 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES3 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00011
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00011', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES4);
console.info('[bluetooth_js] setLocalName result11 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES4 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00012
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00012', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES5);
console.info('[bluetooth_js] setLocalName result12 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES5 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES6);
console.info('[bluetooth_js] setLocalName result13 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES6 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014
* @tc.name testsetLocalName
* @tc.desc Test setLocalName api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014', 0, async function (done) {
await tryToEnableBt();
let name = bluetooth.setLocalName(Btname.MIXES7);
console.info('[bluetooth_js] setLocalName result14 = '+ JSON.stringify(name));
expect(name).assertTrue();
let localName = bluetooth.getLocalName();
expect(true).assertTrue(Btname.MIXES7 == JSON.stringify(localName));
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DISABLE_0001
* @tc.name testdisablebluetooth
* @tc.desc Test disablebluetooth api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_DISABLE_0001', 0, async function (done) {
await tryToEnableBt();
console.info('[bluetooth_js] disable test start');
let disable = bluetooth.disableBluetooth();
console.info('[bluetooth_js] disable:' + JSON.stringify(disable));
expect(disable).assertTrue();
let state = bluetooth.getState();
console.info('[bluetooth_js] bt state:' + JSON.stringify(state));
done();
})
})
}
......@@ -13,7 +13,15 @@
* limitations under the License.
*/
import bluetoothhostTest from './Bluetooth.test.js'
import bluetoothhostTest from './BRSwitch.test.js'
import bluetoothhostTest1 from './BRSetLocalName.test.js'
import bluetoothhostTest2 from './BRScanMode.test.js'
import bluetoothhostTest3 from './BRDiscovery.test.js'
import bluetoothhostTest4 from './BRSpp.test.js'
export default function testsuite() {
bluetoothhostTest()
bluetoothhostTest1()
bluetoothhostTest2()
bluetoothhostTest3()
bluetoothhostTest4()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册