/* * 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.bluetoothManager'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function btManagerGattAdvertTest() { describe('btManagerGattAdvertTest', function() { let gattServer = null; function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) } async function tryToEnableBt() { let sta = bluetooth.getState(); switch(sta){ case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); await sleep(3000); break; case 2: console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); break; case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } beforeAll(async function (done) { console.info('beforeAll called') await tryToEnableBt() gattServer = bluetooth.BLE.createGattServer(); done() }) beforeEach(async function (done) { console.info('beforeEach called') await tryToEnableBt() done() }) afterEach(function () { console.info('afterEach called') }) afterAll(function () { console.info('afterAll called') gattServer.close(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0100 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 0 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0100', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:150, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising1 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0200 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0200', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:32, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising2 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0300 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0300', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:10485, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising3 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0400 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0400', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:16384, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising4 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0500 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0500', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:32, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising5 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0800 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0800', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0900 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_0900', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:-127, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising9 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1000 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1000', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:1, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1100 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1100', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error('[bluetooth_js]startAdvertising11 error.code:'+JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); expect(error.code).assertEqual('401'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1200 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1200', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:-130, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error('[bluetooth_js]startAdvertising12 error.code:'+JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); expect(error.code).assertEqual('401'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1400 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1400', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:1, connectable:false, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1500 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1500', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:-10, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising15 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1800 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1800', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:1, connectable:true, } let advData={ serviceUuids:[""], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:[""], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[{ serviceUuid:"", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising18 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('401'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1900 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 2 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_1900', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:1, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:4567, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[{ manufactureId:1789, manufactureValue:manufactureValueBuffer.buffer }], serviceData:[], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising19 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_2100 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_2100', 0, async function (done) { let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; manufactureValueBuffer[2] = 3; manufactureValueBuffer[3] = 4; let serviceValueBuffer = new Uint8Array(4); serviceValueBuffer[0] = 4; serviceValueBuffer[1] = 6; serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ interval:1000, txPower:1, connectable:true, } let advData={ serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], manufactureData:[], serviceData:[{ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } let advResponse ={ serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], manufactureData:[], serviceData:[{ serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", serviceValue:serviceValueBuffer.buffer }], } try { gattServer.startAdvertising(setting,advData,advResponse); gattServer.stopAdvertising(); }catch(error) { console.error(`[bluetooth_js]startAdvertising21 failed, code is ${error.code}, message is ${error.message}`); expect(error.code).assertEqual('2900099'); } done(); }) /** * @tc.number SUB_COMMUNICATION_BTMANAGER_GATTADVERT_2200 * @tc.name testStartAdvertising * @tc.desc Test StartAdvertising api. * @tc.type Function * @tc.level Level 3 */ it('SUB_COMMUNICATION_BTMANAGER_GATTADVERT_2200', 0, function () { let isRet = true; try{ gattServer.stopAdvertising(); expect(isRet).assertTrue(); }catch(error){ console.info("[bluetooth_js] GattclientClose err:" + JSON.stringify(error)); let isRet = false; expect(isRet).assertFalse(); } }) }) }