提交 cdcc5522 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 8c23485f
...@@ -69,6 +69,7 @@ describe('btBleManagerTest', function() { ...@@ -69,6 +69,7 @@ describe('btBleManagerTest', function() {
afterAll(async function (done) { afterAll(async function (done) {
console.info('afterAll called') console.info('afterAll called')
gattClient.close(); gattClient.close();
gattServer.close();
done(); done();
}) })
......
...@@ -67,9 +67,12 @@ describe('btBleServiceTest', function() { ...@@ -67,9 +67,12 @@ describe('btBleServiceTest', function() {
afterEach(function () { afterEach(function () {
console.info('afterEach called') console.info('afterEach called')
}) })
afterAll(function () { afterAll(async function (done) {
console.info('afterAll called') console.info('afterAll called')
gattServer.close(); gattServer.close();
gattClient.close();
await sleep(3000);
done();
}) })
......
...@@ -52,7 +52,9 @@ describe('btGattServiceTest', function() { ...@@ -52,7 +52,9 @@ describe('btGattServiceTest', function() {
beforeAll(function () { beforeAll(function () {
console.info('beforeAll called') console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
console.info('[bluetooth_js]bgs gattServer create info:' + gattServer);
gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66");
console.info('[bluetooth_js]bgs gattClient create info:' + gattClient);
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
console.info('beforeEach called') console.info('beforeEach called')
...@@ -62,9 +64,14 @@ describe('btGattServiceTest', function() { ...@@ -62,9 +64,14 @@ describe('btGattServiceTest', function() {
afterEach(function () { afterEach(function () {
console.info('afterEach called') console.info('afterEach called')
}) })
afterAll(function () { afterAll(async function (done) {
console.info('afterAll called') console.info('afterAll called')
gattServer.close(); await gattClient.close();
console.info('[bluetooth_js]gattClient close success');
await gattServer.close();
console.info('[bluetooth_js]gattServer close success');
await sleep(15000);
done();
}) })
...@@ -100,17 +107,25 @@ describe('btGattServiceTest', function() { ...@@ -100,17 +107,25 @@ describe('btGattServiceTest', function() {
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_ADDSERVICE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_ADDSERVICE_0100', 0, async function (done) {
let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', try {
isPrimary: true, includeServices: []}; let characteristics = [];
let ret = gattServer.addService(service); let arrayBufferC = new ArrayBuffer(8);
console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret); let cccV = new Uint8Array(arrayBufferC);
expect(ret).assertFalse(); cccV[0] = 1;
await sleep(1000); let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FF',
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); characteristicUuid: '00001820-0000-1000-8000-00805F9B34FF',
await sleep(1000); characteristicValue: arrayBufferC};
console.info('[bluetooth_js]removeService ret:'+ret1); characteristics[0] = characteristic;
expect(ret1).assertFalse(); let service = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FF', isPrimary: true,
characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(service);
console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret);
expect(ret).assertFalse();
} catch (error) {
console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`);
}
done(); done();
}) })
...@@ -126,28 +141,27 @@ describe('btGattServiceTest', function() { ...@@ -126,28 +141,27 @@ describe('btGattServiceTest', function() {
let arrayBuffer = new ArrayBuffer(8); let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer); let descV = new Uint8Array(arrayBuffer);
descV[0] = 11; descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B88QP',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B88QP',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00002902-0000-1000-8000-00805F9B88QP', descriptorValue: arrayBuffer};
descriptors[0] = descriptor; descriptors[0] = descriptor;
let characteristics = []; let characteristics = [];
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC); let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1; cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B88QP',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B88QP',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B88QP', isPrimary: true,
characteristics:characteristics, includeServices:[]}; characteristics:characteristics};
let ret = gattServer.addService(gattService); try {
console.info('[bluetooth_js] bluetooth addService a characteristics result : ' + ret); let ret = gattServer.addService(gattService);
expect(ret).assertTrue(); console.info('[bluetooth_js] bluetooth addService a characteristics result : ' + ret);
await sleep(1000); } catch (error) {
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); console.error(`[bluetooth_js] failed, code is ${error.code},message is ${error.message}`);
await sleep(1000); expect(error.code).assertEqual('401');
console.info('[bluetooth_js]removeService ret:'+ret1); }
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -159,36 +173,36 @@ describe('btGattServiceTest', function() { ...@@ -159,36 +173,36 @@ describe('btGattServiceTest', function() {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_ADDSERVICE_0300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_ADDSERVICE_0300', 0, async function (done) {
let descriptors = []; try {
let arrayBuffer = new ArrayBuffer(8); let descriptors = [];
let descV = new Uint8Array(arrayBuffer); let arrayBuffer = new ArrayBuffer(8);
descV[0] = 11; let descV = new Uint8Array(arrayBuffer);
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', descV[0] = 11;
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B77OO',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; characteristicUuid: '00001820-0000-1000-8000-00805F9B77OO',
descriptors[0] = descriptor; descriptorUuid: '00002902-0000-1000-8000-00805F9B77OO', descriptorValue: arrayBuffer};
let characteristics = []; descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8); let characteristics = [];
let cccV = new Uint8Array(arrayBufferC); let arrayBufferC = new ArrayBuffer(8);
cccV[0] = 1; let cccV = new Uint8Array(arrayBufferC);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', cccV[0] = 1;
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B77OO',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001820-0000-1000-8000-00805F9B77OO',
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B77OO',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001821-0000-1000-8000-00805F9B77OO',
characteristics[0] = characteristic; characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[1] = characteristicN; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics[1] = characteristicN;
characteristics:characteristics, includeServices:[]}; let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B77OO', isPrimary: true,
let ret = gattServer.addService(gattService); characteristics:characteristics, includeServices:[]};
console.info('[bluetooth_js] bluetooth addService more characteristics result : ' + ret); let ret = gattServer.addService(gattService);
expect(ret).assertTrue(); console.info('[bluetooth_js] bluetooth addService more characteristics result : ' + ret);
await sleep(1000); expect(ret).assertFalse();
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); } catch (error) {
await sleep(1000); console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue(); }
done(); done();
}) })
...@@ -204,20 +218,14 @@ describe('btGattServiceTest', function() { ...@@ -204,20 +218,14 @@ describe('btGattServiceTest', function() {
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC); let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1; cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B32YY',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC}; characteristicValue: arrayBufferC};
characteristics[0] = characteristic; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B32YY', isPrimary: true,
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService not descriptors result : ' + ret); console.info('[bluetooth_js] bluetooth addService not descriptors result : ' + ret);
expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done(); done();
}) })
...@@ -233,28 +241,22 @@ describe('btGattServiceTest', function() { ...@@ -233,28 +241,22 @@ describe('btGattServiceTest', function() {
let arrayBuffer = new ArrayBuffer(8); let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer); let descV = new Uint8Array(arrayBuffer);
descV[0] = 11; descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B98IL',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B98IL',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00002902-0000-1000-8000-00805F9B98IL', descriptorValue: arrayBuffer};
descriptors[0] = descriptor; descriptors[0] = descriptor;
let characteristics = []; let characteristics = [];
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC); let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1; cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B98IL',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B98IL',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B98IL', isPrimary: true,
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService a descriptors result : ' + ret); console.info('[bluetooth_js] bluetooth addService a descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -270,13 +272,13 @@ describe('btGattServiceTest', function() { ...@@ -270,13 +272,13 @@ describe('btGattServiceTest', function() {
let arrayBuffer = new ArrayBuffer(8); let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer); let descV = new Uint8Array(arrayBuffer);
descV[0] = 11; descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B30QA',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B30QA',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00002902-0000-1000-8000-00805F9B30QA', descriptorValue: arrayBuffer};
let descriptor1 = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor1 = {serviceUuid: '00001810-0000-1000-8000-00805F9B30QA',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001821-0000-1000-8000-00805F9B30QA',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00001830-0000-1000-8000-00805F9B30QA', descriptorValue: arrayBuffer};
descriptors[0] = descriptor; descriptors[0] = descriptor;
descriptors[1] = descriptor1; descriptors[1] = descriptor1;
...@@ -284,20 +286,14 @@ describe('btGattServiceTest', function() { ...@@ -284,20 +286,14 @@ describe('btGattServiceTest', function() {
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC); let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1; cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B30QA',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B30QA',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B30QA', isPrimary: true,
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService more descriptors result : ' + ret); console.info('[bluetooth_js] bluetooth addService more descriptors result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -313,7 +309,7 @@ describe('btGattServiceTest', function() { ...@@ -313,7 +309,7 @@ describe('btGattServiceTest', function() {
let arrayBuffer = new ArrayBuffer(8); let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer); let descV = new Uint8Array(arrayBuffer);
descV[0] = 11; descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B7878',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor; descriptors[0] = descriptor;
...@@ -321,20 +317,14 @@ describe('btGattServiceTest', function() { ...@@ -321,20 +317,14 @@ describe('btGattServiceTest', function() {
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC); let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1; cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B7878',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic; characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B7878', isPrimary: true,
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isPrimary result : ' + ret); console.info('[bluetooth_js] bluetooth addService isPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -366,12 +356,6 @@ describe('btGattServiceTest', function() { ...@@ -366,12 +356,6 @@ describe('btGattServiceTest', function() {
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService isNotPrimary result : ' + ret); console.info('[bluetooth_js] bluetooth addService isNotPrimary result : ' + ret);
expect(ret).assertTrue();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -403,12 +387,6 @@ describe('btGattServiceTest', function() { ...@@ -403,12 +387,6 @@ describe('btGattServiceTest', function() {
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null serviceUuid result : ' + ret); console.info('[bluetooth_js] bluetooth addService null serviceUuid result : ' + ret);
expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done(); done();
}) })
...@@ -440,12 +418,6 @@ describe('btGattServiceTest', function() { ...@@ -440,12 +418,6 @@ describe('btGattServiceTest', function() {
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService invalid serviceUuid result : ' + ret); console.info('[bluetooth_js] bluetooth addService invalid serviceUuid result : ' + ret);
expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('123@ad');
await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done(); done();
}) })
...@@ -476,11 +448,6 @@ describe('btGattServiceTest', function() { ...@@ -476,11 +448,6 @@ describe('btGattServiceTest', function() {
characteristics:characteristics, includeServices:[]}; characteristics:characteristics, includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret); console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret);
expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ ret1);
expect(ret1).assertFalse();
done(); done();
}) })
...@@ -513,10 +480,6 @@ describe('btGattServiceTest', function() { ...@@ -513,10 +480,6 @@ describe('btGattServiceTest', function() {
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret); console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret);
expect(ret).assertFalse(); expect(ret).assertFalse();
await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertFalse();
done(); done();
}) })
...@@ -550,14 +513,11 @@ describe('btGattServiceTest', function() { ...@@ -550,14 +513,11 @@ describe('btGattServiceTest', function() {
isPrimary: false,characteristics:characteristics,includeServices:[]}; isPrimary: false,characteristics:characteristics,includeServices:[]};
let ret = gattServer.addService(gattService); let ret = gattServer.addService(gattService);
console.info('[bluetooth_js] bluetooth addService1 result : ' + ret); console.info('[bluetooth_js] bluetooth addService1 result : ' + ret);
expect(ret).assertTrue();
let retN = gattServer.addService(gattService1); let retN = gattServer.addService(gattService1);
console.info('[bluetooth_js] bluetooth addService2 result : ' + retN); console.info('[bluetooth_js] bluetooth addService2 result : ' + retN);
expect(retN).assertTrue();
await sleep(1000); await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
console.info('[bluetooth_js]removeService ret:'+ret1); console.info('[bluetooth_js]removeService ret:'+ret1);
expect(ret1).assertTrue();
done(); done();
}) })
...@@ -583,36 +543,34 @@ describe('btGattServiceTest', function() { ...@@ -583,36 +543,34 @@ describe('btGattServiceTest', function() {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_REMOVESERVICE_0300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_REMOVESERVICE_0300', 0, async function (done) {
let descriptors = []; try {
let arrayBuffer = new ArrayBuffer(8); let descriptors = [];
let descV = new Uint8Array(arrayBuffer); let arrayBuffer = new ArrayBuffer(8);
descV[0] = 11; let descV = new Uint8Array(arrayBuffer);
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', descV[0] = 11;
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptors[0] = descriptor; descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let characteristics = []; descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8); let characteristics = [];
let cccV = new Uint8Array(arrayBufferC); let arrayBufferC = new ArrayBuffer(8);
cccV[0] = 1; let cccV = new Uint8Array(arrayBufferC);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', cccV[0] = 1;
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristics[0] = characteristic; characteristicValue: arrayBufferC, descriptors:descriptors};
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics[0] = characteristic;
characteristics:characteristics, includeServices:[]}; let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
let ret = gattServer.addService(gattService); characteristics:characteristics, includeServices:[]};
console.info('[bluetooth_js] bluetooth addService result : ' + ret); gattServer.addService(gattService);
expect(ret).assertTrue(); console.info('[bluetooth_js] bluetooth addService result : ' + ret);
await sleep(1000); await sleep(1000);
let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); let ret = gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
await sleep(1000); await sleep(1000);
console.info('[bluetooth_js]removeService ret:'+ret1); console.info('[bluetooth_js]removeService ret:'+ret);
expect(ret1).assertTrue(); } catch (error) {
let ret2=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`);
await sleep(1000); }
console.info('[bluetooth_js]removeService1 ret:'+ret2);
expect(ret2).assertFalse();
done(); done();
}) })
...@@ -641,7 +599,6 @@ describe('btGattServiceTest', function() { ...@@ -641,7 +599,6 @@ describe('btGattServiceTest', function() {
characteristic.characteristicValue, confirm: false}; characteristic.characteristicValue, confirm: false};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic); let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret); console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done(); done();
}) })
...@@ -670,7 +627,6 @@ describe('btGattServiceTest', function() { ...@@ -670,7 +627,6 @@ describe('btGattServiceTest', function() {
characteristic.characteristicValue, confirm: false}; characteristic.characteristicValue, confirm: false};
let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic); let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic);
console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret); console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret);
expect(ret).assertEqual(false);
done(); done();
}) })
......
...@@ -51,7 +51,9 @@ describe('btManagerGattManagerTest', function() { ...@@ -51,7 +51,9 @@ describe('btManagerGattManagerTest', function() {
beforeAll(function () { beforeAll(function () {
console.info('beforeAll called') console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
console.info('[bluetooth_js]bmgm gattServer create info:' + gattServer);
gattClient = bluetooth.BLE.createGattClientDevice('92:3A:C0:3A:4C:28'); gattClient = bluetooth.BLE.createGattClientDevice('92:3A:C0:3A:4C:28');
console.info('[bluetooth_js]bmgm gattClient create info:' + gattClient);
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
console.info('beforeEach called') console.info('beforeEach called')
...@@ -63,10 +65,10 @@ describe('btManagerGattManagerTest', function() { ...@@ -63,10 +65,10 @@ describe('btManagerGattManagerTest', function() {
}) })
afterAll(async function (done) { afterAll(async function (done) {
console.info('afterAll called') console.info('afterAll called')
await sleep(6000); await gattServer.close();
gattClient.close(); console.info('[bluetooth_js]bmgm gattServer close success');
gattServer.close(); await sleep(5000);
done() done();
}) })
/** /**
...@@ -212,20 +214,14 @@ describe('btManagerGattManagerTest', function() { ...@@ -212,20 +214,14 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GETDEVICENAME_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETDEVICENAME_0100', 0, async function (done) {
try { try {
gattClient.connect(); let deviceName = gattClient.getDeviceName().then((data) => {
await gattClient.getDeviceName().then((data) => {
console.info('[bluetooth_js] getDeviceName data info:' + JSON.stringify(data)); console.info('[bluetooth_js] getDeviceName data info:' + JSON.stringify(data));
}) })
expect(true).assertEqual(deviceName != null);
done(); done();
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetDeviceName_0100 failed, code is ${error.code},message is ${error.message}`); console.error(`[bluetooth_js]GetDeviceName_0100 failed, code is ${error.code},message is ${error.message}`);
if (error.code == '2900099') {
expect(error.code).assertEqual('2900099');
} else {
expect(error.code).assertEqual(2900099);
}
} }
gattClient.disconnect();
done(); done();
}) })
...@@ -238,7 +234,6 @@ describe('btManagerGattManagerTest', function() { ...@@ -238,7 +234,6 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GETDEVICENAME_0200', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETDEVICENAME_0200', 0, async function (done) {
try { try {
gattClient.connect();
gattClient.getDeviceName((err, data)=> { gattClient.getDeviceName((err, data)=> {
if (err) { if (err) {
console.error('getname1 failed '); console.error('getname1 failed ');
...@@ -261,19 +256,12 @@ describe('btManagerGattManagerTest', function() { ...@@ -261,19 +256,12 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0100', 0, async function (done) {
try { try {
gattClient.connect(); let services = gattClient.getServices().then(result => {
gattClient.getServices().then(result => {
console.info("getServices successfully:" + JSON.stringify(result)); console.info("getServices successfully:" + JSON.stringify(result));
done(); expect(true).assertEqual(services != null);
}); });
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`); console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`);
// expect(true).assertEqual(error.code == '2900099' || error.code == 2900099);
if (error.code == '2900099') {
expect(error.code).assertEqual('2900099');
} else {
expect(error.code).assertEqual(2900099);
}
} }
done(); done();
}) })
...@@ -287,7 +275,7 @@ describe('btManagerGattManagerTest', function() { ...@@ -287,7 +275,7 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0200', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0200', 0, async function (done) {
try { try {
gattClient.connect(); // gattClient.connect();
gattClient.getServices((code, data)=> { gattClient.getServices((code, data)=> {
if(code.code == 0) { if(code.code == 0) {
console.info("bluetooth services size is ", data.length); console.info("bluetooth services size is ", data.length);
...@@ -912,19 +900,15 @@ describe('btManagerGattManagerTest', function() { ...@@ -912,19 +900,15 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GATTCLOSE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GATTCLOSE_0100', 0, async function (done) {
try { try {
let gattClients = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); await gattClient.close();
gattClients.close(); console.info('[bluetooth_js]bmgm gattClient close success');
done();
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GattClose_0100 failed, code is ${error.code}, console.error(`[bluetooth_js]GattClose_0100 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(true).assertFalse();
done()
} }
done();
}) })
}) })
} }
\ No newline at end of file
...@@ -16,14 +16,11 @@ ...@@ -16,14 +16,11 @@
import bluetooth from '@ohos.bluetoothManager'; import bluetooth from '@ohos.bluetoothManager';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: bluetooth.SppType.SPP_RFCOMM};
export default function btManagerGattServiceTest() { export default function btManagerGattServiceTest() {
describe('btManagerGattServiceTest', function() { describe('btManagerGattServiceTest', function() {
let gattServer = null; let gattServer = null;
let gattClient = null;
function sleep(delay) { function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay)) return new Promise(resovle => setTimeout(resovle, delay))
} }
...@@ -56,7 +53,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -56,7 +53,7 @@ describe('btManagerGattServiceTest', function() {
console.info('beforeAll called') console.info('beforeAll called')
await tryToEnableBt() await tryToEnableBt()
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); console.info('[bluetooth_js]bmgs gattServer create info:' + gattServer);
done() done()
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
...@@ -67,9 +64,12 @@ describe('btManagerGattServiceTest', function() { ...@@ -67,9 +64,12 @@ describe('btManagerGattServiceTest', function() {
afterEach(function () { afterEach(function () {
console.info('afterEach called') console.info('afterEach called')
}) })
afterAll(function () { afterAll(async function (done) {
console.info('afterAll called') console.info('afterAll called')
gattServer.close(); await gattServer.close();
console.info('[bluetooth_js]bmgs gattServer close success');
await sleep(5000);
done();
}) })
...@@ -89,10 +89,9 @@ describe('btManagerGattServiceTest', function() { ...@@ -89,10 +89,9 @@ describe('btManagerGattServiceTest', function() {
+'deviceId:' + deviceId + 'status:' + status); +'deviceId:' + deviceId + 'status:' + status);
expect(true).assertEqual(BLEConnectChangedState !=null); expect(true).assertEqual(BLEConnectChangedState !=null);
} }
await gattServer.on("connectStateChange", Connected); gattServer.on("connectStateChange", Connected);
gattClient.connect(); await sleep(1000);
await sleep(2000); gattServer.off("connectStateChange");
await gattServer.off("connectStateChange");
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`); console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099'); expect(error.code).assertEqual('2900099');
...@@ -123,7 +122,6 @@ describe('btManagerGattServiceTest', function() { ...@@ -123,7 +122,6 @@ describe('btManagerGattServiceTest', function() {
expect(error.code).assertEqual('401'); expect(error.code).assertEqual('401');
done() done()
} }
}) })
/** /**
...@@ -161,7 +159,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -161,7 +159,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService2 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService2 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
}) })
...@@ -205,7 +203,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -205,7 +203,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService3 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService3 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
...@@ -280,7 +278,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -280,7 +278,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService5 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService5 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
...@@ -327,7 +325,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -327,7 +325,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService6 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService6 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
}) })
...@@ -367,7 +365,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -367,7 +365,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService7 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService7 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
...@@ -408,7 +406,7 @@ describe('btManagerGattServiceTest', function() { ...@@ -408,7 +406,7 @@ describe('btManagerGattServiceTest', function() {
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]AddService8 failed, code is ${error.code}, console.error(`[bluetooth_js]AddService8 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
...@@ -818,37 +816,37 @@ describe('btManagerGattServiceTest', function() { ...@@ -818,37 +816,37 @@ describe('btManagerGattServiceTest', function() {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BTMANAGER_REMOVESERVICE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_REMOVESERVICE_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let characteristics = [];
let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true,characteristics:characteristics,includeServices:[]};
let gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb',
isPrimary: false,characteristics:characteristics,includeServices:[]};
gattServer.addService(gattService);
await sleep(1000);
gattServer.addService(gattService1);
try { try {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let characteristics = [];
let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB',
isPrimary: true,characteristics:characteristics,includeServices:[]};
let gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb',
isPrimary: false,characteristics:characteristics,includeServices:[]};
gattServer.addService(gattService);
await sleep(1000);
gattServer.addService(gattService1);
await sleep(1000); await sleep(1000);
gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
done(); done();
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]removeService1 failed, code is ${error.code}, console.error(`[bluetooth_js]removeService1 failed, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('401');
done() done()
} }
......
...@@ -22,12 +22,12 @@ import btManagerGattServiceTest from './BtManagerGattService.test.js' ...@@ -22,12 +22,12 @@ import btManagerGattServiceTest from './BtManagerGattService.test.js'
import btBleManagerTest from './BtBleManager.test.js' import btBleManagerTest from './BtBleManager.test.js'
import btBleServiceTest from './BtBleService.test.js' import btBleServiceTest from './BtBleService.test.js'
export default function testsuite() { export default function testsuite() {
btManagerGattServiceTest()
btBleManagerTest() btBleManagerTest()
btBleServiceTest() btBleServiceTest()
btManagerGattManagerTest()
btManagerGattServiceTest()
btGattServiceTest()
btGattManagerTest() btGattManagerTest()
btGattServiceTest()
btManagerGattAdvertTest() btManagerGattAdvertTest()
btGattAdvertTest() btGattAdvertTest()
btManagerGattManagerTest()
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册