提交 f8bb3cf2 编写于 作者: Q quanli

location update0830

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 49a9a0b3
......@@ -89,7 +89,7 @@ describe('bluetoothBLETest', function() {
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0300
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0200
* @tc.name testGetConnectedBLEDevices
* @tc.desc Test getConnectedBLEDevices api .
* @tc.size MEDIUM
......@@ -97,13 +97,40 @@ describe('bluetoothBLETest', function() {
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0300', 0, function () {
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0200', 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_Connect_0300
* test Client BLEconnectStateChange
* @tc.desc Test on and off api
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0300', 0, async function (done) {
function ConnectStateChanged(state) {
console.log('bluetooth connect state changed');
let connectState = state.state;
console.info('[bluetooth_js] state changed' + connectState)
expect(true).assertEqual(connectState!=null);
}
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
await gattClient.on('BLEConnectionStateChange', ConnectStateChanged);
let ret = gattClient.connect();
console.info('[bluetooth_js] gattClient connect' + ret)
expect(ret).assertTrue();
gattClient.disconnect();
await gattClient.off("BLEConnectionStateChange");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100
* @tc.name testgetRssiValue
......@@ -427,6 +454,37 @@ describe('bluetoothBLETest', function() {
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0300
* @tc.name test characteristicReadOn
* @tc.desc Test On and off api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0300', 0, async function (done) {
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1123;
function ReadCharacteristicReq(CharacteristicReadReq) {
let deviceId = CharacteristicReadReq.deviceId;
let transId = CharacteristicReadReq.transId;
let offset = CharacteristicReadReq.offset;
let characteristicUuid = CharacteristicReadReq.characteristicUuid;
let serverResponse = {deviceId: deviceId, transId: transId,
status: 0, offset: offset, value:arrayBufferCCC};
let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
}
let gattServer = bluetooth.BLE.createGattServer();
await gattServer.on("characteristicRead", ReadCharacteristicReq);
await gattServer.off("characteristicRead");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100
* @tc.name testReadDescriptorValue
......@@ -489,6 +547,41 @@ describe('bluetoothBLETest', function() {
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0300
* @tc.name test ReadDescriptorOn
* @tc.desc Test On and Off api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0300', 0, async function (done) {
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1011;
function ReadDescriptorReq(DescriptorReadReq) {
let deviceId = DescriptorReadReq.deviceId;
let transId = DescriptorReadReq.transId;
let offset = DescriptorReadReq.offset;
let characteristicUuid = DescriptorReadReq.characteristicUuid;
let serverResponse = {deviceId: deviceId, transId: transId,
status: 0, offset: offset, value:arrayBufferCCC};
let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js]sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
console.info("[bluetooth_js] DesRedon jsondata:" +
'deviceId:' + deviceId + 'transId:' +transId + 'offset:' +
offset +'descriptorUuid:' + DescriptorReadReq.descriptorUuid +
'characteristicUuid:' +characteristicUuid +
'serviceUuid:' + DescriptorReadReq.serviceUuid);
expect(true).assertEqual(DescriptorReadReq !=null);
}
let gattServer = bluetooth.BLE.createGattServer();
await gattServer.on("descriptorRead", ReadDescriptorReq);
await gattServer.off("descriptorRead");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100
* @tc.name testWriteCharacteristicValue
......@@ -532,6 +625,40 @@ describe('bluetoothBLETest', function() {
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0300
* @tc.name test characteristicWriteOn
* @tc.desc Test on and off api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0300', 0, async function (done) {
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
function WriteCharacteristicReq(CharacteristicWriteReq) {
let deviceId = CharacteristicWriteReq.deviceId;
let transId = CharacteristicWriteReq.transId;
let offset = CharacteristicWriteReq.offset;
let isPrep = CharacteristicWriteReq.isPrep;
let needRsp = CharacteristicWriteReq.needRsp;
let value = new Uint8Array(CharacteristicWriteReq.value);
let characteristicUuid = CharacteristicWriteReq.characteristicUuid;
cccValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId,
status: 0, offset: offset, value:arrayBufferCCC};
let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
}
let gattServer = bluetooth.BLE.createGattServer();
gattServer.on("characteristicWrite", WriteCharacteristicReq);
gattServer.off("characteristicWrite");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100
* @tc.name testWriteDescriptorValue
......@@ -567,6 +694,47 @@ describe('bluetoothBLETest', function() {
expect(ret).assertEqual(false);
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0300
* @tc.name test WriteDescriptorOn
* @tc.desc Test on and off api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0300', 0, async function (done) {
let arrayBufferDesc = new ArrayBuffer(8);
let descValue = new Uint8Array(arrayBufferDesc);
function WriteDescriptorReq(DescriptorWriteReq) {
let deviceId = DescriptorWriteReq.deviceId;
let transId = DescriptorWriteReq.transId;
let offset = DescriptorWriteReq.offset;
let isPrep = DescriptorWriteReq.isPrep;
let needRsp = DescriptorWriteReq.needRsp;
let value = new Uint8Array(DescriptorWriteReq.value);
let descriptorUuid = DescriptorWriteReq.descriptorUuid;
descValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId,
status: 0, offset: offset, value:arrayBufferDesc};
let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false);
console.info("[bluetooth_js] desWriOn jsondata: " +'deviceId: '
+ deviceId + 'transId:' + transId + 'offset:' + offset +'descriptorUuid:'
+ descriptorUuid + 'charUuid:' + DescriptorWriteReq.characteristicUuid +
'serviceUuid:' + DescriptorWriteReq.serviceUuid +
'value:' + DescriptorWriteReq.value + 'needRsp' +
needRsp + 'isPrep:' +isPrep );
expect(true).assertEqual(DescriptorWriteReq !=null);
}
let gattServer = bluetooth.BLE.createGattServer();
gattServer.on("descriptorWrite", WriteDescriptorReq);
gattServer.off("descriptorWrite");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100
* @tc.name testSetNotifyCharacteristicChanged
......@@ -647,7 +815,7 @@ describe('bluetoothBLETest', function() {
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
......@@ -657,6 +825,50 @@ describe('bluetoothBLETest', function() {
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0400
* @tc.name test BLECharacteristicChangeON
* @tc.desc Test On and off api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0400', 0, async function (done) {
let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
function CharacteristicChange(CharacteristicChangeReq) {
let serviceUuid = CharacteristicChangeReq.serviceUuid;
let characteristicUuid = CharacteristicChangeReq.characteristicUuid;
let value = new Uint8Array(CharacteristicChangeReq.characteristicValue);
expect(true).assertEqual(CharacteristicChangeReq !=null);
}
gattClient.on('BLECharacteristicChange', CharacteristicChange);
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let 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);
expect(ret).assertEqual(false);
gattClient.off('BLECharacteristicChange');
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300
* @tc.name testSetNotifyCharacteristicChanged
......@@ -676,3 +888,4 @@ describe('bluetoothBLETest', function() {
})
}
......@@ -68,6 +68,35 @@ describe('bluetoothBLETest1', function() {
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100
* @tc.name test Server connectStateChange
* @tc.desc Test on and off api .
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100', 0, async function (done) {
function Connected(BLEConnectChangedState) {
let deviceId = BLEConnectChangedState.deviceId;
let status = BLEConnectChangedState.state;
console.info("[bluetooth_js] connectStateChange jsondata:"
+'deviceId:' + deviceId + 'status:' + status);
expect(true).assertEqual(BLEConnectChangedState !=null);
}
let gattServer = bluetooth.BLE.createGattServer();
await gattServer.on("connectStateChange", Connected);
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();
await gattServer.off("connectStateChange");
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100
* @tc.name testAddService
......@@ -83,9 +112,9 @@ describe('bluetoothBLETest1', function() {
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret);
expect(ret).assertTrue();
await sleep(3000);
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(3000);
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
......@@ -474,7 +503,7 @@ describe('bluetoothBLETest1', function() {
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret);
expect(ret).assertFalse();
await sleep(2000);
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
......@@ -512,7 +541,7 @@ describe('bluetoothBLETest1', function() {
let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret);
expect(ret).assertFalse();
await sleep(2000);
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
......@@ -539,7 +568,7 @@ describe('bluetoothBLETest1', function() {
let retN = gattServer.addService(gattService1);
console.info('[bluetooth_js] bluetooth addService2 result : ' + retN);
expect(retN).assertTrue();
await sleep(2000);
await sleep(1000);
let ret1=gattServer.removeService('00001888-0000-1000-8000-00805f9b34fb');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
......@@ -599,7 +628,7 @@ describe('bluetoothBLETest1', function() {
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
let ret2=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(2000);
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret2);
expect(ret2).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 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();
})
})
}
......@@ -179,8 +179,8 @@ describe('bluetoothhostTest2', function() {
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0500
* @tc.name test getRemoteDeviceClass
* @tc.desc Test get getRemoteDeviceClass
* @tc.name test get RemoteDeviceName
* @tc.desc Test getRemoteDeviceName api
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
......@@ -195,8 +195,8 @@ describe('bluetoothhostTest2', function() {
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0600
* @tc.name test getPairedDevices
* @tc.desc Test get getPairedDevices
* @tc.name test get PairedDevices
* @tc.desc Test getPairedDevices api
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
......@@ -211,8 +211,8 @@ describe('bluetoothhostTest2', function() {
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0700
* @tc.name test pinRequired
* @tc.desc Test pinRequired and setDevicePairing false
* @tc.name Test pinRequired and setDevicePairing false
* @tc.desc Test pinRequired ON api
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
......@@ -224,7 +224,7 @@ describe('bluetoothhostTest2', function() {
bluetooth.setDevicePairingConfirmation(data.deviceId,false);
}
bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("00:00:00:00:00:00");
let result = bluetooth.pairDevice("11:22:55:66:33:44");
console.info("[bluetooth_js] onStartpair007 -> " + JSON.stringify(result));
expect(result).assertFalse();
bluetooth.BLE.off('pinRequired', PinRequiredParam);
......@@ -233,8 +233,8 @@ describe('bluetoothhostTest2', function() {
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0800
* @tc.name test pinRequired
* @tc.desc Test pinRequired and setDevicePairing true
* @tc.name Test pinRequired and setDevicePairing true
* @tc.desc Test pinRequired off api
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
......@@ -246,13 +246,43 @@ describe('bluetoothhostTest2', function() {
bluetooth.setDevicePairingConfirmation(data.deviceId,true);
}
bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("00:00:00:00:00:00");
let result = bluetooth.pairDevice("11:22:55:66:33:44");
console.info("[bluetooth_js] onStartpair008 -> " + JSON.stringify(result));
expect(result).assertFalse();
bluetooth.BLE.off('pinRequired', PinRequiredParam);
done()
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0900
* @tc.name Test On pair StateChange
* @tc.desc Test bondStateChange ON api
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0900', 0, async function (done) {
let BondState=
{
BOND_STATE_INVALID : 0,
BOND_STATE_BONDING : 1,
BOND_STATE_BONDED : 2
};
function BondStateParam(data) {
console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data)
+'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state);
}
bluetooth.BLE.on('bondStateChange', BondStateParam);
let result = bluetooth.pairDevice("11:22:55:66:33:44");
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', BondStateParam);
done()
})
})
}
......@@ -13,15 +13,13 @@
* limitations under the License.
*/
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()
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();
})
})
}
......@@ -17,14 +17,10 @@ import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ProfileId = {
PROFILE_A2DP_SINK : 0,
PROFILE_A2DP_SOURCE : 1,
PROFILE_AVRCP_CT : 2,
PROFILE_AVRCP_TG : 3,
PROFILE_HANDS_FREE_AUDIO_GATEWAY : 4,
PROFILE_HANDS_FREE_UNIT : 5,
PROFILE_HID_HOST : 6,
PROFILE_PAN_NETWORK : 7
}
......@@ -34,49 +30,16 @@ let PlayingState = {
STATE_PLAYING : 0x0001,
}
let a2dpSourceProfile = bluetooth.getProfile(1);
function on(ON_VALUE_TEST_ELEMENT) {
return new Promise((resolve, reject) => {
a2dpSourceProfile.on(ON_VALUE_TEST_ELEMENT, function (err, data) {
if (err != undefined) {
reject(err);
} else {
resolve(data);
}
})
});
}
function off(OFF_VALUE_TEST_ELEMENT) {
return new Promise((resolve, reject) => {
a2dpSourceProfile.off(OFF_VALUE_TEST_ELEMENT, function (err, data) {
if (err != undefined) {
reject(err);
} else {
resolve(data);
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3
}
})
});
}
export default function bluetoothhostTest_host_1() {
describe('bluetoothhostTest_host_1', 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))
}
......@@ -85,9 +48,10 @@ describe('bluetoothhostTest_host_1', function () {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
......@@ -97,122 +61,225 @@ describe('bluetoothhostTest_host_1', function () {
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);
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_A2DP_Conn_0100
* @tc.name test bluetooth Profile ConnectionState
* @tc.desc Test getBtConnectionState api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0100', 0, async function (done) {
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_DEVICE_JS_A2DP_GET_PROFILE_0001
* @tc.name testgetprofile
* @tc.desc Test getProfile api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0200
* @tc.name test A2DP Connect
* @tc.desc Test connect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 1
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_GET_PROFILE_0001', 0, async function (done) {
console.info('[bluetooth_js] a2dp get profile start');
await tryToEnableBt();
let proFile = bluetooth.getProfile(1);
console.info('[bluetooth_js] a2dp get profile result:' + JSON.stringify(proFile));
expect(proFile != null).assertEqual(true);
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0200', 0, async function (done) {
function StateChangeParam(data) {
console.info("[bluetooth_js] a2dp state " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
}
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
a2dpSrc.on('connectionStateChange', StateChangeParam);
let conn = a2dpSrc.connect('11:22:33:44:55:77');
await sleep(6000);
console.info('[bluetooth_js]a2dp connect result:' + JSON.stringify(conn));
expect(conn).assertTrue();
a2dpSrc.off('connectionStateChange', StateChangeParam);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_SOURCCE_PROFILE_CONN_0001
* @tc.name testa2dpSourceProfileconnect
* @tc.desc Test a2dpSourceProfile connect api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0300
* @tc.name test A2DP disconnect
* @tc.desc Test disconnect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_SOURCCE_PROFILE_CONN_0001', 0, async function (done) {
console.info('[bluetooth_js] a2dpSourceProfile the connect start');
await tryToEnableBt();
let conn = a2dpSourceProfile.connect('00:00:00:00:00:02');
expect(conn).assertTrue();
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0300', 0, async function (done) {
function StateChangeParam(data) {
console.info("[bluetooth_js] a2dp state " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
}
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
a2dpSrc.on('connectionStateChange', StateChangeParam);
await sleep(6000);
let disConn = a2dpSourceProfile.disconnect('00:00:00:00:00:02');
console.info('[bluetooth_js] a2dpSourceProfile disconnect:' + JSON.stringify(disConn));
expect(disConn).assertFalse();
let conn = a2dpSrc.disconnect('11:22:33:44:55:66');
console.info('[bluetooth_js]a2dp disconnect result:' + JSON.stringify(conn));
expect(conn).assertFalse();
a2dpSrc.off('connectionStateChange', StateChangeParam);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0400
* @tc.name test a invaild A2DP disconnect
* @tc.desc Test disconnect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0400', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let conn = a2dpSrc.disconnect('test');
console.info('[bluetooth_js]a2dp disconnect1 result:' + JSON.stringify(conn));
expect(conn).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_GET_PLAYING_STATE_0001
* @tc.name testgetPlayingState
* @tc.desc Test getPlayingState api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0500
* @tc.name test Get A2DP ConnectionState
* @tc.desc Test getProfileConnState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_GET_PLAYING_STATE_0001', 0, async function (done) {
console.info('[bluetooth_js] a2dpSourceProfile getPlayingState start');
await tryToEnableBt();
let state = a2dpSourceProfile.getPlayingState('00:00:00:00:00:02');
console.info('[bluetooth_js] a2dpSourceProfile the disconnect result:' + state);
await sleep(3000);
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0500', 0, async function (done) {
let a2dpSrcConn = bluetooth.getProfileConnState(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn));
expect(a2dpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0600
* @tc.name test a invaild A2DP Connect
* @tc.desc Test connect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0600', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
let conn = a2dpSrc.connect('test');
console.info('[bluetooth_js]a2dp invaild connect:' + JSON.stringify(conn));
expect(conn).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_GET_PROFILE_STATE_0001
* @tc.name testgetProfileState
* @tc.desc Test getProfileState api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0700
* @tc.name test getDevice A2DP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_GET_PROFILE_STATE_0001', 0, async function (done) {
console.info('[bluetooth_js] a2dpSourceProfile getProfileState start');
await tryToEnableBt();
let state = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js] a2dpSourceProfile state is:' + state);
expect(state).assertEqual(0);
await sleep(1000);
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0700', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let ret = a2dpSrc.getDeviceState('11:22:33:44:55:66');
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0800
* @tc.name test getDevice A2DP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0800', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let ret = a2dpSrc.getDeviceState('test');
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0900
* @tc.name test get A2DP Playing State
* @tc.desc Test getPlayingState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0900', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let state = a2dpSrc.getPlayingState('11:22:33:44:55:66');
console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state));
expect(state).assertEqual(PlayingState.STATE_NOT_PLAYING);
expect(true).assertEqual(state!=PlayingState.STATE_PLAYING);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_SOURCCE_PROFILE_ON_0001
* @tc.name testa2dpSourceProfileon
* @tc.desc Test a2dpSourceProfile on api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_1000
* @tc.name test getDevice A2DP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 1
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_A2DP_SOURCCE_PROFILE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] a2dpSourceProfile the on start');
on("connectionStateChange", function (data) {
console.info("[bluetooth_js] a2dpSource_on data " + JSON.stringify(data));
expect(true).assertEqual(data !=null);
console.info("[bluetooth_js] StateChangeParam deviceId" + data.deviceId +
"ProfileConnectionState" + data.state);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] a2dpSourceProfile the off test start');
off("connectionStateChange", function (data) {
console.info("[bluetooth_js] a2dpSource_off data-> " + JSON.stringify(data));
expect(true).assertEqual(data ==null);
});
}catch(e) {
expect(null).assertFail();
}
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_1000', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let retArray = a2dpSrc.getConnectionDevices();
expect(true).assertEqual(retArray.length>=0);
done();
})
})
}
......@@ -16,59 +16,23 @@
import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let hfpGatewayProfile = bluetooth.getProfile(4);
let ProfileId = {
PROFILE_A2DP_SINK : 0,
PROFILE_A2DP_SOURCE : 1,
PROFILE_AVRCP_CT : 2,
PROFILE_AVRCP_TG : 3,
PROFILE_HANDS_FREE_AUDIO_GATEWAY : 4,
PROFILE_HANDS_FREE_UNIT : 5,
PROFILE_HID_HOST : 6,
PROFILE_PAN_NETWORK : 7
}
function on(ON_VALUE_TEST_ELEMENT) {
return new Promise((resolve, reject) => {
hfpGatewayProfile.on(ON_VALUE_TEST_ELEMENT, function (err, data) {
if (err != undefined) {
reject(err);
} else {
resolve(data);
}
})
});
}
function off(OFF_VALUE_TEST_ELEMENT) {
return new Promise((resolve, reject) => {
hfpGatewayProfile.off(OFF_VALUE_TEST_ELEMENT, function (err, data) {
if (err != undefined) {
reject(err);
} else {
resolve(data);
}
})
});
}
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3,
};
export default function bluetoothhostTest_host_3() {
describe('bluetoothhostTest_host_3', 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))
}
......@@ -77,9 +41,10 @@ describe('bluetoothhostTest_host_3', function () {
let sta = bluetooth.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
bluetooth.enableBluetooth();
await sleep(3000);
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));
......@@ -89,84 +54,185 @@ describe('bluetoothhostTest_host_3', function () {
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);
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_HFP_Conn_1100
* @tc.name test Get HFP ConnectionState
* @tc.desc Test getProfileConnState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1100', 0, async function (done) {
let hfpSrcConn =
bluetooth.getProfileConnState(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
console.info('[bluetooth_js]get hfp result:' + JSON.stringify(hfpSrcConn));
expect(hfpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_GET_PROFILE_0001
* @tc.name testgetprofile
* @tc.desc Test getProfile api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200
* @tc.name test getDevice HFP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_HFP_GET_PROFILE_0001', 0, async function (done) {
console.info('[bluetooth_js] hfp get profile start');
await tryToEnableBt();
let proFile = bluetooth.getProfile(4);
console.info('[bluetooth_js] get profile:' + JSON.stringify(proFile));
expect(proFile != null).assertEqual(true);
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpSrc.getDeviceState('11:22:33:44:55:66');
console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret));
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300
* @tc.name test getDevice HFP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpSrc.getDeviceState('bluetooth1');
console.info('[bluetooth_js]hfp get valid mac DeviceState:' + JSON.stringify(ret));
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_HFP_GATWAY_PROFILE_CONN_0001
* @tc.name testhfpGatewayProfileconnect
* @tc.desc Test hfpGatewayProfile connect api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1400
* @tc.name test HFP Connect
* @tc.desc Test connect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 1
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_HFP_GATWAY_PROFILE_CONN_0001', 0, async function (done) {
console.info('[bluetooth_js] hfpGatewayProfile the connect start');
await tryToEnableBt();
let conn = hfpGatewayProfile.connect('00:00:00:00:00:01');
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1400', 0, async function (done) {
function StateChangeParam(data) {
console.info("[bluetooth_js] hfp state " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
}
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpSrc.on('connectionStateChange', StateChangeParam);
let conn = hfpSrc.connect('11:22:33:44:55:66');
await sleep(6000);
console.info('[bluetooth_js]hfp connect result:' + JSON.stringify(conn));
expect(conn).assertTrue();
await sleep(2000);
let disConn = hfpGatewayProfile.disconnect('00:00:00:00:00:01');
console.info('[bluetooth_js] hfpGatewayProfile disconnect:' + disConn);
expect(disConn).assertTrue();
await sleep(2000);
hfpSrc.off('connectionStateChange', StateChangeParam);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_DEVICE_JS_HFP_GATWAY_PROFILE_ON_0001
* @tc.name testhfpGatewayProfileon
* @tc.desc Test hfpGatewayProfile on api.
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1500
* @tc.name test HFP disconnect
* @tc.desc Test disconnect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
*/
it('SUB_COMMUNACATION_bluetooth_DEVICE_JS_HFP_GATWAY_PROFILE_ON_0001', 0, async function (done) {
try {
await tryToEnableBt();
console.info('[bluetooth_js] hfpGatewayProfile the on start');
on("connectionStateChange", function (data) {
console.info("[bluetooth_js] hfpGateway_on data " + JSON.stringify(data));
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1500', 0, async function (done) {
function StateChangeParam(data) {
console.info("[bluetooth_js] hfp state " + JSON.stringify(data) +
'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null);
});
}catch(e) {
expect(null).assertFail();
}
try {
console.info('[bluetooth_js] hfpGatewayProfile the off test start');
off("connectionStateChange", function (data) {
console.info("[bluetooth_js] hfpGateway_off data-> " + JSON.stringify(data));
expect(true).assertEqual(data ==null);
});
}catch(e) {
expect(null).assertFail();
}
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpSrc.on('connectionStateChange', StateChangeParam);
await sleep(10000);
let conn = hfpSrc.disconnect('11:22:33:44:55:66');
console.info('[bluetooth_js]hfp disconnect result:' + JSON.stringify(conn));
expect(conn).assertFalse();
hfpSrc.off('connectionStateChange', StateChangeParam);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600
* @tc.name test a invaild HFP Connect
* @tc.desc Test connect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let conn1 = hfpSrc.connect('test');
console.info('[bluetooth_js]hfp vaild MAC disconnect :' + JSON.stringify(conn1));
expect(conn1).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700
* @tc.name test a invaild HFP disconnect
* @tc.desc Test disconnect api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
console.info('[bluetooth_js]hfp get profile result:' + JSON.stringify(hfpSrc));
let conn = hfpSrc.disconnect('test');
console.info('[bluetooth_js]hfp disconnect1 result:' + JSON.stringify(conn));
expect(conn).assertFalse();
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800
* @tc.name test getDevice HFP State.
* @tc.desc Test getDeviceState api.
* @tc.size MEDIUM
* @ since 8
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let retArray = hfpSrc.getConnectionDevices();
console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray));
expect(true).assertEqual(retArray.length>=0);
done();
})
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -80,14 +79,14 @@ describe('bluetoothhostTest4', function() {
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code: ' + code);
console.log('bluetooth error code01: ' + code);
}else{
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', SppOption, serverSocket);
await bluetooth.sppListen('server1', SppOption, serverSocket);
done()
})
......@@ -105,14 +104,14 @@ describe('bluetoothhostTest4', function() {
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code: ' + code);
console.log('[bluetooth_js] error code02: ' + code);
}else{
console.log('[bluetooth_js] serverSocket Number: ' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
await bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
......@@ -129,17 +128,15 @@ describe('bluetoothhostTest4', function() {
secure: true, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code: ' + code);
console.log('[bluetooth_js] error code03: ' + JSON.stringify(code));
}else{
console.log('[bluetooth_js] serverSocket Number: '+JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
await bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
......@@ -156,9 +153,8 @@ describe('bluetoothhostTest4', function() {
secure: false, type: 0};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code: ' + code);
console.log('[bluetooth_js] error code04: ' + JSON.stringify(code));
}else{
console.log('[bluetooth_js] serverSocket Number:'+ JSON.stringify(number));
......@@ -166,7 +162,7 @@ describe('bluetoothhostTest4', function() {
expect(true).assertEqual(serverNumber!=null);
}
}
bluetooth.sppListen('server1', sppOption, serverSocket);
await bluetooth.sppListen('server1', sppOption, serverSocket);
done();
})
......@@ -182,13 +178,13 @@ describe('bluetoothhostTest4', function() {
function acceptClientSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code: ' + code);
console.log('[bluetooth_js] error code05: ' + JSON.stringify(code));
}else{
console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number));
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppAccept(0, acceptClientSocket);
await bluetooth.sppAccept(0, acceptClientSocket);
done();
})
......@@ -201,9 +197,9 @@ describe('bluetoothhostTest4', function() {
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600', 0, async function (done) {
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
await bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppAccept Number:'
+ JSON.stringify(clientSocketNumber));
......@@ -224,13 +220,13 @@ describe('bluetoothhostTest4', function() {
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) {
await bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, number) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppConnect Number:'
+ JSON.stringify(clientSocketNumber));
expect(true).assertEqual(clientSocketNumber!=null);
+ JSON.stringify(number));
expect(true).assertEqual(number!=null);
}
});
done();
......@@ -247,9 +243,9 @@ describe('bluetoothhostTest4', function() {
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) {
await bluetooth.sppConnect('ABC', sppOption, function(code, clientSocketNumber) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppConnect Number'
+ JSON.stringify(clientSocketNumber));
......@@ -270,9 +266,9 @@ describe('bluetoothhostTest4', function() {
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) {
await bluetooth.sppConnect('BT', sppOption, function(code, clientSocketNumber) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppConnect Number'
+ JSON.stringify(clientSocketNumber));
......@@ -294,7 +290,7 @@ describe('bluetoothhostTest4', function() {
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code: ' + code);
console.log('bluetooth error code10: ' + JSON.stringify(code));
}else{
console.log('bluetooth serverSocket Number:'+ JSON.stringify(number));
serverNumber = number;
......@@ -304,7 +300,7 @@ describe('bluetoothhostTest4', function() {
}
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppListen('server1', SppOption, serverSocket);
await bluetooth.sppListen('server1', SppOption, serverSocket);
bluetooth.sppCloseServerSocket(serverNumber);
done();
})
......@@ -319,9 +315,9 @@ describe('bluetoothhostTest4', function() {
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1100', 0, async function (done) {
let clientNumber = -1;
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
await bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppAccept Number:'
+ JSON.stringify(clientSocketNumber));
......@@ -343,9 +339,9 @@ describe('bluetoothhostTest4', function() {
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200', 0, async function (done) {
let clientNumber = -1;
bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
await bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
if (code) {
console.info('[bluetooth_js] code is: ' + code);
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppAccept Number:'
+ JSON.stringify(clientSocketNumber));
......@@ -362,7 +358,37 @@ describe('bluetoothhostTest4', function() {
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1300
* @tc.name test sppReadOn
* @tc.desc Test On and Off Api
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1300', 0, async function (done) {
let clientNumber = -1;
function acceptClientSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code13: ' + JSON.stringify(code));
}else{
console.log('[bluetooth_js]clientSocke Number:' + JSON.stringify(number));
clientNumber = number;
expect(true).assertEqual(number!=null);
}
}
await bluetooth.sppAccept(0, acceptClientSocket);
function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]);
}
await bluetooth.on('sppRead', clientNumber, dataRead);
await bluetooth.off('sppRead', clientNumber, dataRead);
done();
})
})
}
......@@ -82,25 +82,30 @@ describe('bluetoothhostTest', function() {
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0100', 0, async function (done) {
function onReceiveEvent(data) {
console.info('bluetooth state001 ='+ JSON.stringify(data));
}
await bluetooth.on('stateChange', onReceiveEvent);
let state = bluetooth.getState();
console.info('[bluetooth_js] get bluetooth state result'+ JSON.stringify(state));
console.info('[bluetooth_js] get bluetooth state001'+ 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));
await sleep(5000);
console.info('[bluetooth_js] bluetooth enable001'+JSON.stringify(enable));
expect(enable).assertTrue();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] enable state1 '+ JSON.stringify(state1));
console.info('[bluetooth_js] enable state001 '+ 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));
console.info('[bluetooth_js] bluetooth disable001'+JSON.stringify(disable));
expect(disable).assertTrue();
let state2 = bluetooth.getState();
console.info('[bluetooth_js] disable state2 '+ JSON.stringify(state2));
console.info('[bluetooth_js] disable state001 '+ JSON.stringify(state2));
expect(state2).assertEqual(BluetoothState.STATE_OFF);
await bluetooth.off('stateChange', onReceiveEvent);
done()
})
......
......@@ -90,13 +90,13 @@ describe('geolocationTest_4', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0001
* @tc.number SUB_HSS_LocationSystem_CountryCode_0100
* @tc.name Test getCountryCode
* @tc.desc Obtaining Country Code Information
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0001', 0, async function (done) {
it('SUB_HSS_LocationSystem_CountryCode_0100', 0, async function (done) {
await geolocation.getCountryCode().then((result) => {
console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result));
console.info("[lbs_js] country :" + result.country);
......@@ -113,13 +113,13 @@ describe('geolocationTest_4', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0002
* @tc.number SUB_HSS_LocationSystem_CountryCode_0200
* @tc.name Test getCountryCode
* @tc.desc Obtaining Country Code Information
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0002', 0, async function (done) {
it('SUB_HSS_LocationSystem_CountryCode_0200', 0, async function (done) {
function getCountryCodeCallback() {
return new Promise((resolve, reject) => {
geolocation.getCountryCode((err) => {
......@@ -137,13 +137,13 @@ describe('geolocationTest_4', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0003
* @tc.number SUB_HSS_LocationSystem_CountryCode_0300
* @tc.name getCountryCode_on_off
* @tc.desc The interception country code is changed.
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0003', 0, async function (done) {
it('SUB_HSS_LocationSystem_CountryCode_0300', 0, async function (done) {
console.info("[lbs_js]countryCodeChange");
geolocation.on('countryCodeChange', function (data) {
console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) );
......
......@@ -83,14 +83,14 @@ describe('geolocationTest_geo2', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_systemapi_0001
* @tc.number SUB_HSS_LocationSystem_systemapi_0100
* @tc.name Test getLocation
* @tc.desc Obtains the geographical location of a device..
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_systemapi_0001', 0, async function (done) {
it('SUB_HSS_LocationSystem_systemapi_0100', 0, async function (done) {
geolocations.getLocation({
timeout:30000,
coordType:'wgs84',
......@@ -127,14 +127,14 @@ describe('geolocationTest_geo2', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_systemapi_0002
* @tc.number SUB_HSS_LocationSystem_systemapi_0200
* @tc.name Test subscribe and unsubscribe
* @tc.desc Test subscribe api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_systemapi_0002', 0, async function (done) {
it('SUB_HSS_LocationSystem_systemapi_0200', 0, async function (done) {
geolocations.subscribe({
coordType:'wgs84',
success: function(data) {
......@@ -152,14 +152,14 @@ describe('geolocationTest_geo2', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_systemapi_0003
* @tc.number SUB_HSS_LocationSystem_systemapi_0300
* @tc.name test getLocationType
* @tc.desc Subscribing to geographical location information .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_systemapi_0003', 0, async function (done) {
it('SUB_HSS_LocationSystem_systemapi_0300', 0, async function (done) {
geolocations.getLocationType({
success: function(data) {
console.log('success get location type:' + JSON.stringify(data));
......@@ -178,14 +178,14 @@ describe('geolocationTest_geo2', function () {
})
/**
* @tc.number SUB_HSS_LocationSystem_systemapi_0004
* @tc.number SUB_HSS_LocationSystem_systemapi_0400
* @tc.name Test getSupportedCoordTypes
* @tc.desc Obtains the geographical location of a device..
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_systemapi_0004', 0, function () {
it('SUB_HSS_LocationSystem_systemapi_0400', 0, function () {
let types = geolocations.getSupportedCoordTypes();
console.info('[lbs_js] getSupportedCoordTypes result: ' + JSON.stringify(types));
expect(true).assertEqual(types.length !=0);
......@@ -197,9 +197,3 @@ describe('geolocationTest_geo2', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册