提交 4edd41c2 编写于 作者: J jiyong_sd

Adapt to the new framework

Signed-off-by: Njiyong_sd <jiyong@huawei.com>
Change-Id: Ib4c5af6df24971ab3fd22b85bdb8a38107c6f240
上级 a3f2bbca
......@@ -9,7 +9,7 @@
# 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.
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsBluetoothBleJsTest") {
......@@ -23,7 +23,9 @@ ohos_js_hap_suite("ActsBluetoothBleJsTest") {
hap_name = "ActsBluetoothBleHapTest"
}
ohos_js_assets("bluetooth_js_assets") {
source_dir = "./src/main/js/default"
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("bluetooth_resources") {
sources = [ "./src/main/resources" ]
......
{
"description": "Configuration for bluetooth js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsBluetoothBleHapTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"description": "Configuration for bluetooth js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "600000",
"bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"package-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"testcase-timeout": 70000
},
"kits": [
{
"test-file-name": [
"ActsBluetoothBleHapTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.communication.bluetooth.bluetoothhost",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
"app": {
"bundleName": "ohos.acts.communication.bluetooth.bluetoothhost",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"name": ".entry",
"deviceType": [
"phone"
],
"name": "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.USE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}
]
}
}
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.USE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ No newline at end of file
{
"strings": {
"hello": "Hello",
"world": "World"
}
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
/*
* 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
/*
* 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.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
console.info('onReady finish')
},
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* 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 {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
title: "",
myTimeout:70000
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
this.timeout = this.myTimeout
configService.setConfig(this)
require('../../test/List.test')
core.execute()
},
onReady() {
console.info('onReady finish')
},
}
/*
* 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 'deccjsunit/index'
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
}
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');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] getConnectedBLEDevices test start ...');
await tryToEnableBt();
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) {
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 promise = new Promise((resolve) => {
let gattServer = bluetooth.BLE.createGattServer()
let start = 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
}],
});
console.info('[bluetooth_js] startAdv res: ' + JSON.stringify(start));
expect(start).assertNull();
resolve()
})
await promise.then(done)
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) {
console.info('[bluetooth_js] BLE stop advertising start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer();
let stop = gattServer.stopAdvertising();
expect(true).assertTrue();
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) {
console.info('[bluetooth_js] gatt connect start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get rssi1 start');
await tryToEnableBt();
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)
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) {
console.info('[bluetooth_js] BLE get rssi start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get device name promise start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get device name callback start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] getServices callback start');
await tryToEnableBt();
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)
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) {
console.info('[bluetooth_js] getServices promise start');
await tryToEnableBt();
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)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0001
* @tc.name testReadCharacteristicValue
* @tc.desc Test ReadCharacteristicValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] readCharacteristicValue promise start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readCharacteristicValue(characteristic).then((object) => {
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue promise data:' + JSON.stringify(data));
expect(null).assertFail();
}
done();
}).catch(err => {
console.error(`bluetooth readCharacteristicValue promise has error: ${err}`);
expect(true).assertEqual(true);
done();
});
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0002
* @tc.name testReadCharacteristicValue
* @tc.desc Test ReadCharacteristicValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0002', 0, async function (done) {
console.info('[bluetooth_js] readCharacteristicValue callback start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readCharacteristicValue(characteristic,(err, data)=> {
if (err) {
console.error(`bluetooth readCharacteristicValue callback has error: ${err}`);
expect(true).assertEqual(true);
done();
return;
}
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue callback data:' + JSON.stringify(data));
expect(null).assertFail();
}
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0001
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] readDescriptorValue promise start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readDescriptorValue(descriptor).then((object) => {
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] BLEDescriptor promise data:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(err => {
console.error(`bluetooth readDescriptorValue promise has error: ${err}`);
expect(true).assertEqual(true);
done();
});
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0002
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0002', 0, async function (done) {
console.info('[bluetooth_js] readDescriptorValue callback start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readDescriptorValue(descriptor,(err, data)=> {
if (err) {
console.error(`bluetooth readDescriptorValue callback has error: ${err}`);
expect(true).assertEqual(true);
done();
return;
}
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] BLEDescriptor callback data:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_WRITE_CHARACT_VALUE_0001
* @tc.name testWriteCharacteristicValue
* @tc.desc Test WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_WRITE_CHARACT_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] writeCharacteristicValue start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
let ret = gattClient.writeCharacteristicValue(characteristic);
console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_WRITE_DESC_VALUE_0001
* @tc.name testWriteDescriptorValue
* @tc.desc Test WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_WRITE_DESC_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] writeDescriptorValue start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
resolve()
})
await promise.then(done)
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) {
console.info('[bluetooth_js] setBLEMtuSize start');
await tryToEnableBt();
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_COMMUNACATION_bluetooth_GATT_SET_NOTIFY_CHARA_CHANGED_0001
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_SET_NOTIFY_CHARA_CHANGED_0001', 0, async function (done) {
console.info('[bluetooth_js] setNotifyCharacteristicChanged start');
await tryToEnableBt();
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
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_COMMUNACATION_bluetooth_GATT_ADD_SERVICE_0001
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_ADD_SERVICE_0001', 0, async function (done) {
console.info('[bluetooth_js] addService start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let characteristics = [];
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};
characteristics[0] = characteristic;
let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true, characteristics: characteristics, includeServices: []};
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService ret : ' + ret);
expect(ret).assertTrue();
await sleep(3500);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_NOTIFY_CHARA_CHANGED_0001
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_NOTIFY_CHARA_CHANGED_0001', 0, async function (done) {
console.info('[bluetooth_js] notifyCharacteristicChanged start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer()
let descriptors = [];
let arrayBufferDesc = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBufferDesc);
desValue[0] = 11;
let arrayBufferNotifyDesc = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotifyDesc);
descNotifyValue[0] = 1
let
descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: desValue};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: descNotifyValue};
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: cccValue,
descriptors:descriptors,confirm:'false'};
let ret = gattServer.notifyCharacteristicChanged('00:00:00:00:00:00', characteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_SEND_RESPONSE_0001
* @tc.name testSendResponse
* @tc.desc Test SendResponse api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_SEND_RESPONSE_0001', 0, async function (done) {
console.info('[bluetooth_js] sendResponse start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer()
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let serverResponse = {deviceId: '00:00:00:00:00', 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) {
console.info('[bluetooth_js] GattserverClose test start ...');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] gatt disconnect start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] GattclientClose test start ...');
await tryToEnableBt();
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'
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;
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');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] getConnectedBLEDevices test start ...');
await tryToEnableBt();
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) {
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 promise = new Promise((resolve) => {
let gattServer = bluetooth.BLE.createGattServer()
let start = 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
}],
});
console.info('[bluetooth_js] startAdv res: ' + JSON.stringify(start));
expect(start).assertNull();
resolve()
})
await promise.then(done)
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) {
console.info('[bluetooth_js] BLE stop advertising start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer();
let stop = gattServer.stopAdvertising();
expect(true).assertTrue();
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) {
console.info('[bluetooth_js] gatt connect start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get rssi1 start');
await tryToEnableBt();
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)
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) {
console.info('[bluetooth_js] BLE get rssi start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get device name promise start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] BLE get device name callback start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] getServices callback start');
await tryToEnableBt();
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)
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) {
console.info('[bluetooth_js] getServices promise start');
await tryToEnableBt();
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)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0001
* @tc.name testReadCharacteristicValue
* @tc.desc Test ReadCharacteristicValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] readCharacteristicValue promise start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readCharacteristicValue(characteristic).then((object) => {
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue promise data:' + JSON.stringify(data));
expect(null).assertFail();
}
done();
}).catch(err => {
console.error(`bluetooth readCharacteristicValue promise has error: ${err}`);
expect(true).assertEqual(true);
done();
});
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0002
* @tc.name testReadCharacteristicValue
* @tc.desc Test ReadCharacteristicValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_CHARA_VALUE_0002', 0, async function (done) {
console.info('[bluetooth_js] readCharacteristicValue callback start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readCharacteristicValue(characteristic,(err, data)=> {
if (err) {
console.error(`bluetooth readCharacteristicValue callback has error: ${err}`);
expect(true).assertEqual(true);
done();
return;
}
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] readCharacValue callback data:' + JSON.stringify(data));
expect(null).assertFail();
}
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0001
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] readDescriptorValue promise start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readDescriptorValue(descriptor).then((object) => {
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] BLEDescriptor promise data:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
}).catch(err => {
console.error(`bluetooth readDescriptorValue promise has error: ${err}`);
expect(true).assertEqual(true);
done();
});
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0002
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api by callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_READ_DESCRI_VALUE_0002', 0, async function (done) {
console.info('[bluetooth_js] readDescriptorValue callback start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
gattClient.readDescriptorValue(descriptor,(err, data)=> {
if (err) {
console.error(`bluetooth readDescriptorValue callback has error: ${err}`);
expect(true).assertEqual(true);
done();
return;
}
if (object != null) {
expect(true).assertEqual(true);
} else {
console.info('[bluetooth_js] BLEDescriptor callback data:' + JSON.stringify(object));
expect(null).assertFail();
}
done();
})
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_WRITE_CHARACT_VALUE_0001
* @tc.name testWriteCharacteristicValue
* @tc.desc Test WriteCharacteristicValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_WRITE_CHARACT_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] writeCharacteristicValue start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
let ret = gattClient.writeCharacteristicValue(characteristic);
console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret);
expect(ret).assertEqual(false);
resolve()
})
await promise.then(done)
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_WRITE_DESC_VALUE_0001
* @tc.name testWriteDescriptorValue
* @tc.desc Test WriteDescriptorValue api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_WRITE_DESC_VALUE_0001', 0, async function (done) {
console.info('[bluetooth_js] writeDescriptorValue start');
await tryToEnableBt();
let promise = new Promise((resolve) => {
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("00:00:00:00:00:00");
let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
expect(ret).assertEqual(false);
resolve()
})
await promise.then(done)
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) {
console.info('[bluetooth_js] setBLEMtuSize start');
await tryToEnableBt();
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_COMMUNACATION_bluetooth_GATT_SET_NOTIFY_CHARA_CHANGED_0001
* @tc.name testSetNotifyCharacteristicChanged
* @tc.desc Test SetNotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_SET_NOTIFY_CHARA_CHANGED_0001', 0, async function (done) {
console.info('[bluetooth_js] setNotifyCharacteristicChanged start');
await tryToEnableBt();
let gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00");
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_COMMUNACATION_bluetooth_GATT_ADD_SERVICE_0001
* @tc.name testAddService
* @tc.desc Test AddService api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_ADD_SERVICE_0001', 0, async function (done) {
console.info('[bluetooth_js] addService start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer();
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let characteristics = [];
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};
characteristics[0] = characteristic;
let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true, characteristics: characteristics, includeServices: []};
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService ret : ' + ret);
expect(ret).assertTrue();
await sleep(3500);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_NOTIFY_CHARA_CHANGED_0001
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test NotifyCharacteristicChanged api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_NOTIFY_CHARA_CHANGED_0001', 0, async function (done) {
console.info('[bluetooth_js] notifyCharacteristicChanged start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer()
let descriptors = [];
let arrayBufferDesc = new ArrayBuffer(8);
let desValue = new Uint8Array(arrayBufferDesc);
desValue[0] = 11;
let arrayBufferNotifyDesc = new ArrayBuffer(8);
let descNotifyValue = new Uint8Array(arrayBufferNotifyDesc);
descNotifyValue[0] = 1
let
descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: desValue};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: descNotifyValue};
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: cccValue,
descriptors:descriptors,confirm:'false'};
let ret = gattServer.notifyCharacteristicChanged('00:00:00:00:00:00', characteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done();
})
/**
* @tc.number SUB_COMMUNACATION_bluetooth_GATT_SEND_RESPONSE_0001
* @tc.name testSendResponse
* @tc.desc Test SendResponse api.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNACATION_bluetooth_GATT_SEND_RESPONSE_0001', 0, async function (done) {
console.info('[bluetooth_js] sendResponse start');
await tryToEnableBt();
let gattServer = bluetooth.BLE.createGattServer()
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let serverResponse = {deviceId: '00:00:00:00:00', 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) {
console.info('[bluetooth_js] GattserverClose test start ...');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] gatt disconnect start');
await tryToEnableBt();
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) {
console.info('[bluetooth_js] GattclientClose test start ...');
await tryToEnableBt();
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();
})
})
}
......@@ -13,4 +13,7 @@
* limitations under the License.
*/
require('./BluetoothOn.test.js')
import bluetoothhostTest from './BluetoothBle.test.js'
export default function testsuite() {
bluetoothhostTest()
}
......@@ -7,6 +7,22 @@
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
......@@ -9,7 +9,7 @@
# 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.
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsBluetoothOnJsTest") {
......@@ -23,7 +23,9 @@ ohos_js_hap_suite("ActsBluetoothOnJsTest") {
hap_name = "ActsBluetoothOnHapTest"
}
ohos_js_assets("bluetooth_js_assets") {
source_dir = "./src/main/js/default"
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("bluetooth_resources") {
sources = [ "./src/main/resources" ]
......
{
"description": "Configuration for bluetooth js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsBluetoothOnHapTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"description": "Configuration for bluetooth js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "600000",
"bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"package-name": "ohos.acts.communication.bluetooth.bluetoothhost",
"testcase-timeout": 70000
},
"kits": [
{
"test-file-name": [
"ActsBluetoothOnHapTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.communication.bluetooth.bluetoothhost",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
"app": {
"bundleName": "ohos.acts.communication.bluetooth.bluetoothhost",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"name": ".entry",
"deviceType": [
"phone"
],
"name": "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.USE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}
]
}
}
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.USE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
console.info('onReady finish')
},
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* 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 {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
title: "",
myTimeout:70000
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
this.timeout = this.myTimeout
configService.setConfig(this)
require('../../test/List.test')
core.execute()
},
onReady() {
console.info('onReady finish')
},
}
/*
* 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 'deccjsunit/index'
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,
};
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")
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_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
};
let enable4 = bluetooth.pairDevice("00:00:00:00:00:00")
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 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")
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_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
};
let enable4 = bluetooth.pairDevice("00:00:00:00:00:00")
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();
})
})
}
......@@ -13,4 +13,7 @@
* limitations under the License.
*/
require('./BluetoothBle.test.js')
import bluetoothhostTest from './BluetoothOn.test.js'
export default function testsuite() {
bluetoothhostTest()
}
......@@ -7,6 +7,22 @@
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册