1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import bluetoothBle from '@ohos.bluetooth.ble'; 17import btAccess from '@ohos.bluetooth.access'; 18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 19import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest' 20 21export default function btBleManagerTest() { 22describe('btBleManagerTest', function() { 23 let gattS: bluetoothBle.GattServer; 24 let gattC: bluetoothBle.GattClientDevice; 25 let PERMISSION_TEXT:string = "允许"; 26 let OPEN_BT_TEXT:string = "开启"; 27 function sleep(delay) { 28 return new Promise(resovle => setTimeout(resovle, delay)) 29 } 30 31 async function openPhone() { 32 try{ 33 let drivers = Driver.create(); 34 console.info('[bluetooth_js] bt driver create:'+ drivers); 35 await drivers.delayMs(1000); 36 await drivers.wakeUpDisplay(); 37 await drivers.delayMs(5000); 38 await drivers.swipe(1500, 1000, 1500, 100); 39 await drivers.delayMs(10000); 40 } catch (error) { 41 console.info('[bluetooth_js] driver error info:'+ error); 42 } 43 } 44 45 async function tryToEnableBt() { 46 let sta = btAccess.getState(); 47 switch(sta){ 48 case 0: 49 console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); 50 btAccess.enableBluetooth(); 51 await clickRequestPermission(OPEN_BT_TEXT); 52 await sleep(10000); 53 break; 54 case 1: 55 console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); 56 await sleep(3000); 57 break; 58 case 2: 59 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 60 break; 61 case 3: 62 console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); 63 btAccess.enableBluetooth(); 64 await clickRequestPermission(OPEN_BT_TEXT); 65 await sleep(10000); 66 break; 67 default: 68 console.info('[bluetooth_js] enable success'); 69 } 70 } 71 72 async function clickRequestPermission(text:string) { 73 console.info('[bluetooth_js] clickRequestPermission start'); 74 let driver = Driver.create(); 75 await driver.delayMs(3000); 76 try { 77 let button = await driver.findComponent(ON.text(text)); 78 await button.click(); 79 await driver.delayMs(3000); 80 console.info('[bluetooth_js] clickRequestPermission end'); 81 } catch (err) { 82 console.info('[bluetooth_js] clickRequestPermission failed. ' + err); 83 } 84 try { 85 let button1 = await driver.findComponent(ON.text("允许")); 86 await button1.click(); 87 await driver.delayMs(3000); 88 console.info('[bluetooth_js] click 允许 end'); 89 } catch (err) { 90 console.info('[bluetooth_js] click 允许 failed. ' + err); 91 } 92 } 93 94 beforeAll(async function (done) { 95 await clickRequestPermission(PERMISSION_TEXT); 96 await openPhone(); 97 await tryToEnableBt() 98 gattS = bluetoothBle.createGattServer(); 99 console.info('bluetooth ble create gattserver result:' + gattS); 100 gattC = bluetoothBle.createGattClientDevice('04:30:02:01:00:07'); 101 console.info('bluetooth ble create gattclientdevice result:' + gattC); 102 console.info('beforeAll called') 103 done(); 104 }) 105 beforeEach(async function(done) { 106 console.info('beforeEach called') 107 await tryToEnableBt() 108 done(); 109 }) 110 afterEach(function () { 111 console.info('afterEach called') 112 }) 113 afterAll(async function (done) { 114 console.info('afterAll called') 115 gattC.close(); 116 console.info('bluetooth gattC close success'); 117 gattS.close(); 118 console.info('bluetooth gattS close success'); 119 done(); 120 }) 121 122 /** 123 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100 124 * @tc.name testStartAdvertising 125 * @tc.desc Test StartAdvertising api10. 126 * @tc.type Function 127 * @tc.size MediumTest 128 * @tc.level Level 0 129 */ 130 it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100', 0, async function (done) { 131 let manufactureValueBuffer = new Uint8Array(4); 132 manufactureValueBuffer[0] = 1; 133 manufactureValueBuffer[1] = 2; 134 manufactureValueBuffer[2] = 3; 135 manufactureValueBuffer[3] = 4; 136 let serviceValueBuffer = new Uint8Array(4); 137 serviceValueBuffer[0] = 4; 138 serviceValueBuffer[1] = 6; 139 serviceValueBuffer[2] = 7; 140 serviceValueBuffer[3] = 8; 141 let setting={ 142 interval:32, 143 txPower:1, 144 connectable:true, 145 } 146 let advData={ 147 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 148 manufactureData:[{ 149 manufactureId:4567, 150 manufactureValue:manufactureValueBuffer.buffer 151 }], 152 serviceData:[{ 153 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 154 serviceValue:serviceValueBuffer.buffer 155 }], 156 includeDeviceName:false 157 } 158 let advResponse ={ 159 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 160 manufactureData:[{ 161 manufactureId:1789, 162 manufactureValue:manufactureValueBuffer.buffer 163 }], 164 serviceData:[{ 165 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 166 serviceValue:serviceValueBuffer.buffer 167 }], 168 } 169 try { 170 bluetoothBle.startAdvertising(setting,advData,advResponse); 171 console.info('[bluetooth_js]startAdvertising1 success'); 172 bluetoothBle.stopAdvertising(); 173 }catch(error) { 174 console.error(`[bluetooth_js]startAdvertising1 failed, code is ${error.code},message is ${error.message}`); 175 expect(Number(error.code)).assertEqual(2900099); 176 } 177 done(); 178 }) 179 180 /** 181 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100 182 * @tc.name testConnect 183 * @tc.desc Test api10. 184 * @tc.type Function 185 * @tc.size MediumTest 186 * @tc.level Level 2 187 */ 188 it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100', 0, async function (done) { 189 try { 190 gattC.connect(); 191 await sleep(2000); 192 gattC.disconnect(); 193 } catch(error) { 194 console.error(`[bluetooth_js]disconnect failed, code is ${error.code},message is ${error.message}`); 195 expect(Number(error.code)).assertEqual(2900099); 196 } 197 done(); 198 }) 199 200 /** 201 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200 202 * @tc.name testGetConnectedBLEDevices 203 * @tc.desc Test api10. 204 * @tc.type Function 205 * @tc.size MediumTest 206 * @tc.level Level 2 207 */ 208 it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200', 0, async function (done) { 209 try { 210 let result = bluetoothBle.getConnectedBLEDevices(); 211 console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result) 212 + "length:" +result.length); 213 expect(result != null).assertTrue(); 214 } catch (error) { 215 console.error(`[bluetooth_js]getConnDev failed, code is ${error.code},message is ${error.message}`); 216 expect(Number(error.code)).assertEqual(2900099); 217 } 218 done(); 219 }) 220 221 /** 222 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300 223 * @tc.name testBLEconnectStateChange 224 * @tc.desc Test on and off api10 225 * @tc.type Function 226 * @tc.size MediumTest 227 * @tc.level Level 2 228 */ 229 it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300', 0, async function (done) { 230 try { 231 function ConnectStateChanged(state) { 232 console.log('bluetooth connect state changed'); 233 let connectState = state.state; 234 console.info('[bluetooth_js] state changed' + connectState) 235 expect(true).assertEqual(connectState != null); 236 } 237 gattC.on('BLEConnectionStateChange', ConnectStateChanged); 238 gattC.off("BLEConnectionStateChange"); 239 done(); 240 } catch (error) { 241 console.error(`[bluetooth_js]GattConnect failed, code is ${error.code},message is ${error.message}`); 242 expect(Number(error.code)).assertEqual(2900099); 243 } 244 done(); 245 }) 246 247 /** 248 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100 249 * @tc.name testGetRssiValue 250 * @tc.desc Test getRssiValue api10 by promise. 251 * @tc.type Function 252 * @tc.size MediumTest 253 * @tc.level Level 2 254 */ 255 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100', 0, async function (done) { 256 try { 257 await gattC.getRssiValue().then((data) => { 258 console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); 259 expect(true).assertEqual(data != null); 260 done(); 261 }).catch(err => { 262 console.info('bluetooth getRssiValue has error: '+ JSON.stringify(err)); 263 let b=false; 264 if(err.code==2900099||err.code==-1) 265 { 266 b=true 267 } 268 expect(true).assertEqual(b); 269 done(); 270 }); 271 } catch (error) { 272 console.error(`[bluetooth_js]GetRssiValue error, code is ${error.code},message is ${error.message}`); 273 expect(Number(error.code)).assertEqual(2900099); 274 } 275 done(); 276 }) 277 278 /** 279 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200 280 * @tc.name testgetRssiValue 281 * @tc.desc Test testGetDeviceName api10 by callback. 282 * @tc.type Function 283 * @tc.size MediumTest 284 * @tc.level Level 2 285 */ 286 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200', 0, async function (done) { 287 try { 288 function getRssi() { 289 return new Promise<void>((resolve,reject) => { 290 gattC.getRssiValue((err, data)=> { 291 if (err) { 292 console.error('getRssi failed' + err); 293 reject(err.code); 294 } else 295 { 296 console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); 297 expect(true).assertEqual(data != null); 298 } 299 resolve(); 300 }); 301 }); 302 } 303 await getRssi().then((data) => { 304 console.info("[bluetooth_js]02 getRssiValue done"); 305 done(); 306 }) 307 .catch(e => { 308 console.info("[bluetooth_js]02 getRssiValue failed" + e); 309 expect(2900099).assertEqual(e); 310 done(); 311 }) 312 } catch (error) { 313 console.error(`[bluetooth_js]GetRssiValue error, code is ${error.code},message is ${error.message}`); 314 } 315 done(); 316 }) 317 318 /** 319 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100 320 * @tc.name testGetDeviceName 321 * @tc.desc Test GetDeviceName api10 by promise. 322 * @tc.type Function 323 * @tc.size MediumTest 324 * @tc.level Level 2 325 */ 326 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100', 0, async function (done) { 327 try { 328 await gattC.getDeviceName().then((data) => { 329 console.info('[bluetooth_js] device name:' + JSON.stringify(data)) 330 expect(true).assertEqual(data != null); 331 done(); 332 }).catch(err => { 333 console.error('[bluetooth_js] bluetooth getDeviceName has error: '+ JSON.stringify(err)); 334 expect(err.code).assertEqual(2900099); 335 done(); 336 }); 337 } catch (error) { 338 console.error(`[bluetooth_js]GetDeviceName failed, code is ${error.code},message is ${error.message}`); 339 expect(Number(error.code)).assertEqual(2900099); 340 } 341 done(); 342 }) 343 344 /** 345 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200 346 * @tc.name testGetDeviceName 347 * @tc.desc Test testGetDeviceName api10 by callback. 348 * @tc.type Function 349 * @tc.size MediumTest 350 * @tc.level Level 2 351 */ 352 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200', 0, async function (done) { 353 try { 354 function getName() { 355 return new Promise<void>((resolve,reject) => { 356 gattC.getDeviceName((err, data)=> { 357 if (err) { 358 console.error('getName failed' + err); 359 reject(err.code); 360 } else 361 { 362 console.info('[bluetooth_js]getName value:'+JSON.stringify(data)); 363 expect(true).assertEqual(data != null); 364 } 365 resolve(); 366 }); 367 }); 368 } 369 await getName().then((data) => { 370 console.info("[bluetooth_js]02 getDeviceName done"); 371 done(); 372 }) 373 .catch(e => { 374 console.info("[bluetooth_js]02 getDeviceName failed" + e); 375 expect(2900099).assertEqual(e); 376 done(); 377 }) 378 } catch (error) { 379 console.error(`[bluetooth_js]getDeviceName error, code is ${error.code},message is ${error.message}`); 380 } 381 done(); 382 }) 383 384 /** 385 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100 386 * @tc.name testGetServices 387 * @tc.desc Test GetServices api10 by promise. 388 * @tc.type Function 389 * @tc.size MediumTest 390 * @tc.level Level 3 391 */ 392 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100', 0, async function (done) { 393 try { 394 await gattC.getServices().then((GattService) => { 395 console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); 396 expect(GattService).assertNull(); 397 done(); 398 }).catch(err => { 399 console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); 400 done(); 401 }); 402 } catch (error) { 403 console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`); 404 expect(Number(error.code)).assertEqual(2900099); 405 } 406 done(); 407 }) 408 409 /** 410 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200 411 * @tc.name testGetServices 412 * @tc.desc Test GetServices api10 by callback. 413 * @tc.type Function 414 * @tc.size MediumTest 415 * @tc.level Level 3 416 */ 417 it('SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200', 0, async function (done) { 418 try { 419 function getService() { 420 return new Promise<void>((resolve,reject) => { 421 gattC.getServices((err, data)=> { 422 if (err) { 423 console.error('getService failed' + err); 424 reject(err.code); 425 } else 426 { 427 console.info('[bluetooth_js]getService value:'+JSON.stringify(data)); 428 expect(true).assertEqual(data != null); 429 } 430 resolve(); 431 }); 432 }); 433 } 434 await getService().then((data) => { 435 console.info("[bluetooth_js]02 getServices done"); 436 done(); 437 }) 438 .catch(e => { 439 console.info("[bluetooth_js]02 getServices failed" + e); 440 expect(2900099).assertEqual(e); 441 done(); 442 }) 443 } catch (error) { 444 console.error(`[bluetooth_js]getServices error, code is ${error.code},message is ${error.message}`); 445 } 446 done(); 447 }) 448 449 /** 450 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100 451 * @tc.name testSetBLEMtuSize 452 * @tc.desc Test SetBLEMtuSize api10. 453 * @tc.type Function 454 * @tc.size MediumTest 455 * @tc.level Level 1 456 */ 457 it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100', 0, function (done) { 458 try { 459 gattC.setBLEMtuSize(500); 460 console.info("[bluetooth_js]setBLEMtuSize success"); 461 } catch (error) { 462 console.error(`[bluetooth_js]MtuSize failed, code is ${error.code},message is ${error.message}`); 463 expect(Number(error.code)).assertEqual(2900099); 464 } 465 done(); 466 }) 467 468 /** 469 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900 470 * @tc.name testReadDescriptorValue 471 * @tc.desc Test ReadDescriptorValue api10 by promise. 472 * @tc.type Function 473 * @tc.size MediumTest 474 * @tc.level Level 2 475 */ 476 it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900', 0, async function (done) { 477 let descriptors = []; 478 let bufferDesc = new ArrayBuffer(8); 479 let descV = new Uint8Array(bufferDesc); 480 descV[0] = 11; 481 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 482 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 483 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc}; 484 descriptors[0] = descriptor; 485 486 let bufferCCC = new ArrayBuffer(8); 487 let cccV = new Uint8Array(bufferCCC); 488 cccV[0] = 1; 489 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 490 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 491 characteristicValue: bufferCCC, descriptors:descriptors}; 492 try { 493 gattC.readCharacteristicValue(characteristic); 494 done(); 495 } catch (error) { 496 console.error(`[bluetooth_js]readDescrValue failed, code is ${error.code},message is ${error.message}`); 497 expect(Number(error.code)).assertEqual(401); 498 } 499 done(); 500 }) 501 502 /** 503 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000 504 * @tc.name testReadDescriptorValue 505 * @tc.desc Test ReadDescriptorValue api10 by callback. 506 * @tc.type Function 507 * @tc.size MediumTest 508 * @tc.level Level 2 509 */ 510 it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000', 0, async function(done) { 511 function readCcc(code, BLECharacteristic) { 512 if (code.code != 0) { 513 return; 514 } 515 console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid); 516 let value = new Uint8Array(BLECharacteristic.characteristicValue); 517 console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); 518 } 519 520 let descriptors = []; 521 let bufferDesc = new ArrayBuffer(8); 522 let descV = new Uint8Array(bufferDesc); 523 descV[0] = 11; 524 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 525 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 526 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc}; 527 descriptors[0] = descriptor; 528 529 let bufferCCC = new ArrayBuffer(8); 530 let cccV = new Uint8Array(bufferCCC); 531 cccV[0] = 1; 532 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 533 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 534 characteristicValue: bufferCCC, descriptors:descriptors}; 535 try { 536 gattC.readCharacteristicValue(characteristic, readCcc); 537 done(); 538 } catch (error) { 539 console.error(`[bluetooth_js]readCharacteristicValue failed, code is ${error.code},message is ${error.message}`); 540 expect(Number(error.code)).assertEqual(401); 541 } 542 done(); 543 }) 544 545 /** 546 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100 547 * @tc.name testCharacteristicReadOn 548 * @tc.desc Test On and off api10. 549 * @tc.type Function 550 * @tc.size MediumTest 551 * @tc.level Level 3 552 */ 553 it('SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100', 0, async function (done) { 554 let arrayBufferCCC = new ArrayBuffer(8); 555 let cccValue = new Uint8Array(arrayBufferCCC); 556 cccValue[0] = 1123; 557 function ReadCharacteristicReq(CharacteristicReadRequest) { 558 let deviceId = CharacteristicReadRequest.deviceId; 559 let transId = CharacteristicReadRequest.transId; 560 let offset = CharacteristicReadRequest.offset; 561 let characteristicUuid = CharacteristicReadRequest.characteristicUuid; 562 563 let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC}; 564 565 try { 566 gattS.sendResponse(serverResponse); 567 } catch (err) { 568 console.error("sendResponese errCode:" + err.code + ",errMessage:" + err.message); 569 } 570 } 571 572 try { 573 await gattS.on("characteristicRead", ReadCharacteristicReq); 574 done(); 575 } catch (err) { 576 console.info("characteristicReadOn errCode:" + err.code + ",errMessage:" + err.message); 577 expect(Number(err.code)).assertEqual(2900099); 578 } 579 gattS.off("characteristicRead"); 580 done(); 581 }) 582 583 /** 584 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300 585 * @tc.name testReadDescriptorValue 586 * @tc.desc Test ReadDescriptorValue api10 by promise. 587 * @tc.type Function 588 * @tc.size MediumTest 589 * @tc.level Level 2 590 */ 591 it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300', 0, async function (done) { 592 let bufferDesc = new ArrayBuffer(8); 593 let descV = new Uint8Array(bufferDesc); 594 descV[0] = 11; 595 let descriptor = { 596 serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 597 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 598 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', 599 descriptorValue: bufferDesc 600 }; 601 try { 602 gattC.readDescriptorValue(descriptor); 603 expect(true).assertFalse(); 604 done(); 605 } catch (err) { 606 console.error("errCode:" + err.code + ",errMessage:" + err.message); 607 expect(Number(err.code)).assertEqual(401); 608 done(); 609 } 610 }) 611 612 /** 613 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400 614 * @tc.name testReadDescriptorValue 615 * @tc.desc Test ReadDescriptorValue api10 by callback. 616 * @tc.type Function 617 * @tc.size MediumTest 618 * @tc.level Level 2 619 */ 620 it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400', 0, async function (done) { 621 function readDesc(code, BLEDescriptor) { 622 if (code.code != 0) { 623 return; 624 } 625 console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid); 626 let value = new Uint8Array(BLEDescriptor.descriptorValue); 627 console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); 628 } 629 630 let bufferDesc = new ArrayBuffer(8); 631 let descV = new Uint8Array(bufferDesc); 632 descV[0] = 11; 633 let descriptor = { 634 serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 635 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 636 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', 637 descriptorValue: bufferDesc 638 }; 639 try { 640 gattC.readDescriptorValue(descriptor, readDesc); 641 expect(true).assertFalse(); 642 done(); 643 } catch (err) { 644 console.error("errCode:" + err.code + ",errMessage:" + err.message); 645 expect(Number(err.code)).assertEqual(401); 646 done(); 647 } 648 }) 649 650 /** 651 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500 652 * @tc.name testReadDescriptorOn 653 * @tc.desc Test On and Off api10. 654 * @tc.type Function 655 * @tc.size MediumTest 656 * @tc.level Level 3 657 */ 658 it('SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500', 0, async function (done) { 659 try { 660 let arrayBufferCCC = new ArrayBuffer(8); 661 let cccValue = new Uint8Array(arrayBufferCCC); 662 cccValue[0] = 1011; 663 function ReadDescriptorReq(DescriptorReadReq) { 664 let deviceId = DescriptorReadReq.deviceId; 665 let transId = DescriptorReadReq.transId; 666 let offset = DescriptorReadReq.offset; 667 let characteristicUuid = DescriptorReadReq.characteristicUuid; 668 669 let serverResponse = {deviceId: deviceId, transId: transId, 670 status: 0, offset: offset, value:arrayBufferCCC}; 671 gattS.sendResponse(serverResponse); 672 console.info("[bluetooth_js] DesRedon jsondata:" + 673 'deviceId:' + deviceId + 'transId:' +transId + 'offset:' + 674 offset +'descriptorUuid:' + DescriptorReadReq.descriptorUuid + 675 'characteristicUuid:' +characteristicUuid + 676 'serviceUuid:' + DescriptorReadReq.serviceUuid); 677 expect(true).assertEqual(DescriptorReadReq != null); 678 } 679 await gattS.on("descriptorRead", ReadDescriptorReq); 680 await gattS.off("descriptorRead"); 681 done(); 682 } catch (error) { 683 console.error(`[bluetooth_js]readDescrValue failed, code is ${error.code},message is ${error.message}`); 684 expect(Number(error.code)).assertEqual(2900099); 685 } 686 done(); 687 }) 688 689 /** 690 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800 691 * @tc.name testWriteCharacteristicValue 692 * @tc.desc Test Client WriteCharacteristicValue api10. 693 * @tc.type Function 694 * @tc.size MediumTest 695 * @tc.level Level 2 696 */ 697 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800', 0, async function (done) { 698 let descriptors = []; 699 let arrayBuffer = new ArrayBuffer(8); 700 let desValue = new Uint8Array(arrayBuffer); 701 desValue[0] = 11; 702 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 703 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 704 descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', 705 descriptorValue: arrayBuffer}; 706 descriptors[0] = descriptor; 707 let arrayBufferCCC = new ArrayBuffer(8); 708 let cccValue = new Uint8Array(arrayBufferCCC); 709 cccValue[0] = 32; 710 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 711 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 712 characteristicValue: arrayBufferCCC, descriptors:descriptors}; 713 try { 714 function wrCharacteristicVal() { 715 return new Promise<void>((resolve,reject) => { 716 gattC.writeCharacteristicValue(characteristic, bluetoothBle.GattWriteType.WRITE, (err, data)=> { 717 if (err) { 718 console.info('wrCharacteristicVal failed' + err); 719 reject(err.code); 720 } else 721 { 722 console.info('[bluetooth_js]wrCharacteristicVal value:'+JSON.stringify(data)); 723 expect(true).assertEqual(data != null); 724 } 725 resolve(); 726 }); 727 }); 728 } 729 await wrCharacteristicVal().then((data) => { 730 console.info("[bluetooth_js]18 writeCharacteristicValue done"); 731 done(); 732 }) 733 .catch(e => { 734 console.info("[bluetooth_js]18 writeCharacteristicValue failed" + e); 735 expect(Number(e.code)).assertEqual(401); 736 done(); 737 }) 738 } catch (error) { 739 console.error(`[bluetooth_js]writeCharacteristicValue error, code is ${error.code},message is ${error.message}`); 740 expect(Number(error.code)).assertEqual(401); 741 } 742 done(); 743 }) 744 745 /** 746 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900 747 * @tc.name testWriteCharacteristicValue 748 * @tc.desc Test Client WriteCharacteristicValue api10. 749 * @tc.type Function 750 * @tc.size MediumTest 751 * @tc.level Level 2 752 */ 753 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900', 0, async function (done) { 754 try { 755 let descriptors = []; 756 let arrayBuffer = new ArrayBuffer(8); 757 let desValue = new Uint8Array(arrayBuffer); 758 desValue[0] = 11; 759 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 760 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 761 descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', 762 descriptorValue: arrayBuffer}; 763 descriptors[0] = descriptor; 764 let arrayBufferCCC = new ArrayBuffer(8); 765 let cccValue = new Uint8Array(arrayBufferCCC); 766 cccValue[0] = 32; 767 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 768 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 769 characteristicValue: arrayBufferCCC, descriptors:descriptors}; 770 gattC.writeCharacteristicValue(characteristic, bluetoothBle.GattWriteType.WRITE_NO_RESPONSE).then(() => { 771 console.info("writeCharacteristicValue"); 772 done(); 773 }, err => { 774 console.error("writeCharacteristicValue:errCode" + err.code + ",errMessage:" + err.message); 775 done(); 776 }); 777 } catch (error) { 778 console.error(`[bluetooth_js]writeCharacteristicValue failed, code is ${error.code},message is ${error.message}`); 779 expect(Number(error.code)).assertEqual(401); 780 } 781 done(); 782 }) 783 784 /** 785 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000 786 * @tc.name testCharacteristicWriteOn 787 * @tc.desc Test on and off api10. 788 * @tc.type Function 789 * @tc.size MediumTest 790 * @tc.level Level 3 791 */ 792 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000', 0, async function (done) { 793 try { 794 let arrayBufferCCC = new ArrayBuffer(8); 795 let cccValue = new Uint8Array(arrayBufferCCC); 796 function WriteCharacteristicReq(CharacteristicWriteRequest) { 797 let deviceId = CharacteristicWriteRequest.deviceId; 798 let transId = CharacteristicWriteRequest.transId; 799 let offset = CharacteristicWriteRequest.offset; 800 let isPrepared = CharacteristicWriteRequest.isPrepared; 801 let needRsp = CharacteristicWriteRequest.needRsp; 802 let value = new Uint8Array(CharacteristicWriteRequest.value); 803 let characteristicUuid = CharacteristicWriteRequest.characteristicUuid; 804 let serviceUuid = CharacteristicWriteRequest.serviceUuid; 805 console.info('CharacteristicWriteRequest deviceId:' + deviceId); 806 console.info('CharacteristicWriteRequest transId:' + transId); 807 console.info('CharacteristicWriteRequest offset:' + offset); 808 console.info('CharacteristicWriteRequest isPrepared:' + isPrepared); 809 console.info('CharacteristicWriteRequest needRsp:' + needRsp); 810 console.info('CharacteristicWriteRequest value:' + value); 811 console.info('CharacteristicWriteRequest characteristicUuid:' + characteristicUuid); 812 console.info('CharacteristicWriteRequest serviceUuid:' + serviceUuid); 813 814 cccValue[0] = value[0]; 815 let serverResponse = {deviceId: deviceId, transId: transId, 816 status: 0, offset: offset, value:arrayBufferCCC}; 817 gattS.sendResponse(serverResponse); 818 } 819 gattS.on("characteristicWrite", WriteCharacteristicReq); 820 gattS.off("characteristicWrite"); 821 done(); 822 } catch (error) { 823 console.error(`[bluetooth_js]writeCharacteristicValue failed, code is ${error.code},message is ${error.message}`); 824 expect(Number(error.code)).assertEqual(2900099); 825 } 826 done(); 827 }) 828 829 /** 830 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000 831 * @tc.name testWriteDescriptorValue 832 * @tc.desc Test Client WriteDescriptorValue promsie api10. 833 * @tc.type Function 834 * @tc.size MediumTest 835 * @tc.level Level 2 836 */ 837 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000', 0, async function (done) { 838 let bufferDesc = new ArrayBuffer(8); 839 let descV = new Uint8Array(bufferDesc); 840 descV[0] = 22; 841 let descriptor = { 842 serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 843 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 844 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', 845 descriptorValue: bufferDesc 846 }; 847 try { 848 gattC.writeDescriptorValue(descriptor).then(() => { 849 console.info("writeDescriptorValue"); 850 done(); 851 }, err => { 852 console.error("writeDescriptorValue:errCode" + err.code + ",errMessage:" + err.message); 853 done(); 854 }); 855 } catch (error) { 856 console.error(`[bluetooth_js]writeDescriptorValue failed, code is ${error.code}, 857 message is ${error.message}`); 858 expect(Number(error.code)).assertEqual(401); 859 } 860 done(); 861 }) 862 863 /** 864 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100 865 * @tc.name testWriteDescriptorValue 866 * @tc.desc Test Client WriteDescriptorValue callback api10. 867 * @tc.type Function 868 * @tc.size MediumTest 869 * @tc.level Level 2 870 */ 871 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100', 0, async function (done) { 872 let bufferDesc = new ArrayBuffer(8); 873 let descV = new Uint8Array(bufferDesc); 874 descV[0] = 22; 875 let descriptor = { 876 serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 877 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 878 descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', 879 descriptorValue: bufferDesc 880 }; 881 try { 882 function wrDescriptorVal() { 883 return new Promise<void>((resolve,reject) => { 884 gattC.writeDescriptorValue(descriptor, (err, data)=> { 885 if (err) { 886 console.error('Descriptor failed' + err); 887 reject(err.code); 888 } else 889 { 890 console.info('[bluetooth_js]Descriptor value:'+JSON.stringify(data)); 891 expect(true).assertEqual(data != null); 892 } 893 resolve(); 894 }); 895 }); 896 } 897 await wrDescriptorVal().then((data) => { 898 console.info("[bluetooth_js]11 writeDescriptorValue done"); 899 done(); 900 }) 901 .catch(e => { 902 console.info("[bluetooth_js]11 writeDescriptorValue failed" + e); 903 expect(Number(e.code)).assertEqual(401); 904 done(); 905 }) 906 } catch (error) { 907 console.error(`[bluetooth_js]writeDescriptorValue error, code is ${error.code},message is ${error.message}`); 908 expect(Number(error.code)).assertEqual(401); 909 } 910 done(); 911 }) 912 913 /** 914 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200 915 * @tc.name testWriteDescriptorOn 916 * @tc.desc Test on and off api10. 917 * @tc.type Function 918 * @tc.size MediumTest 919 * @tc.level Level 3 920 */ 921 it('SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200', 0, async function (done) { 922 try { 923 let arrayBufferDesc = new ArrayBuffer(8); 924 let descValue = new Uint8Array(arrayBufferDesc); 925 function WriteDescriptorReq(DescriptorWriteRequest) { 926 let deviceId = DescriptorWriteRequest.deviceId; 927 let transId = DescriptorWriteRequest.transId; 928 let offset = DescriptorWriteRequest.offset; 929 let isPrepared = DescriptorWriteRequest.isPrepared; 930 let needRsp = DescriptorWriteRequest.needRsp; 931 let value = new Uint8Array(DescriptorWriteRequest.value); 932 let descriptorUuid = DescriptorWriteRequest.descriptorUuid; 933 descValue[0] = value[0]; 934 let serverResponse = {deviceId: deviceId, transId: transId, 935 status: 0, offset: offset, value:arrayBufferDesc}; 936 gattS.sendResponse(serverResponse); 937 console.info("[bluetooth_js] desWriOn jsondata: " +'deviceId: ' 938 + deviceId + 'transId:' + transId + 'offset:' + offset +'descriptorUuid:' 939 + descriptorUuid + 'charUuid:' + DescriptorWriteRequest.characteristicUuid + 940 'serviceUuid:' + DescriptorWriteRequest.serviceUuid + 941 'value:' + DescriptorWriteRequest.value + 'needRsp' + 942 needRsp + 'isPrepared:' +isPrepared ); 943 expect(true).assertEqual(DescriptorWriteRequest != null); 944 } 945 gattS.on("descriptorWrite", WriteDescriptorReq); 946 gattS.off("descriptorWrite"); 947 done(); 948 } catch (error) { 949 console.error(`[bluetooth_js]writeDescriptorValue failed, code is ${error.code}, 950 message is ${error.message}`); 951 expect(Number(error.code)).assertEqual(2900099); 952 } 953 done(); 954 }) 955 956 /** 957 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400 958 * @tc.name testBLECharacteristicChangeON 959 * @tc.desc Test On and off api10. 960 * @tc.type Function 961 * @tc.size MediumTest 962 * @tc.level Level 3 963 */ 964 it('SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400', 0, async function (done) { 965 try { 966 function CharacteristicChange(CharacteristicChangeReq) { 967 let serviceUuid = CharacteristicChangeReq.serviceUuid; 968 let characteristicUuid = CharacteristicChangeReq.characteristicUuid; 969 let value = new Uint8Array(CharacteristicChangeReq.characteristicValue); 970 expect(true).assertEqual(CharacteristicChangeReq != null); 971 } 972 gattC.on('BLECharacteristicChange', CharacteristicChange); 973 let descriptors = []; 974 let arrayBuffer = new ArrayBuffer(8); 975 let desValue = new Uint8Array(arrayBuffer); 976 desValue[0] = 11; 977 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 978 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 979 descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', 980 descriptorValue: arrayBuffer}; 981 descriptors[0] = descriptor;; 982 let arrayBufferCCC = new ArrayBuffer(8); 983 let cccValue = new Uint8Array(arrayBufferCCC); 984 cccValue[0] = 1; 985 gattC.off('BLECharacteristicChange'); 986 done(); 987 } catch (error) { 988 console.error(`[bluetooth_js]BLECharacteristicChangeON failed, code is ${error.code}, 989 message is ${error.message}`); 990 expect(Number(error.code)).assertEqual(2900099); 991 } 992 done(); 993 }) 994 995 /** 996 * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100 997 * @tc.name testSetCharacteristicChangeNotification 998 * @tc.desc Test setCharacteristicChangeNotification api10 999 * @tc.type Function 1000 * @tc.size MediumTest 1001 * @tc.level Level 0 1002 */ 1003 it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100', 0, async function (done) { 1004 let descriptors = []; 1005 let arrayBuffer = new ArrayBuffer(8); 1006 let descV = new Uint8Array(arrayBuffer); 1007 descV[0] = 11; 1008 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1009 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 1010 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 1011 descriptors[0] = descriptor; 1012 let arrayBufferC = new ArrayBuffer(8); 1013 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1014 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 1015 try { 1016 function setCCN() { 1017 return new Promise<void>((resolve,reject) => { 1018 gattC.setCharacteristicChangeNotification(characteristic, false, (err, data)=> { 1019 if (err) { 1020 console.error('setCCN failed' + err); 1021 reject(err.code); 1022 } else 1023 { 1024 console.info('[bluetooth_js]setCCN value:'+JSON.stringify(data)); 1025 expect(true).assertEqual(data != null); 1026 } 1027 resolve(); 1028 }); 1029 }); 1030 } 1031 await setCCN().then((data) => { 1032 console.info("[bluetooth_js]01 setCharacteristicChangeNotification done"); 1033 done(); 1034 }) 1035 .catch(e => { 1036 console.info("[bluetooth_js]01 setCharacteristicChangeNotification failed" + e); 1037 expect(Number(e.code)).assertEqual(401); 1038 done(); 1039 }) 1040 } catch (error) { 1041 console.error(`[bluetooth_js]setCharacteristicChangeNotification error, code is ${error.code},message is ${error.message}`); 1042 expect(Number(error.code)).assertEqual(401); 1043 } 1044 done(); 1045 }) 1046 1047 /** 1048 * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200 1049 * @tc.name testSetCharacteristicChangeNotification 1050 * @tc.desc Test setCharacteristicChangeNotification api10 1051 * @tc.type Function 1052 * @tc.size MediumTest 1053 * @tc.level Level 0 1054 */ 1055 it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200', 0, async function (done) { 1056 let descriptors = []; 1057 let arrayBuffer = new ArrayBuffer(8); 1058 let descV = new Uint8Array(arrayBuffer); 1059 descV[0] = 11; 1060 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1061 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 1062 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 1063 descriptors[0] = descriptor; 1064 let arrayBufferC = new ArrayBuffer(8); 1065 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1066 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 1067 try { 1068 gattC.setCharacteristicChangeNotification(characteristic, true).then(() => { 1069 console.info("setCharacteristicChangeNotification"); 1070 }); 1071 done(); 1072 } catch (err) { 1073 console.error('setCharacteristicChangeNotification failed errCode: ' + err.code + ', errMessage: ' + err.message); 1074 expect(Number(err.code)).assertEqual(401); 1075 done(); 1076 } 1077 done(); 1078 }) 1079 1080 /** 1081 * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300 1082 * @tc.name testSetCharacteristicChangeIndication 1083 * @tc.desc Test setCharacteristicChangeIndication api10 1084 * @tc.type Function 1085 * @tc.size MediumTest 1086 * @tc.level Level 0 1087 */ 1088 it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300', 0, async function (done) { 1089 let descriptors = []; 1090 let arrayBuffer = new ArrayBuffer(8); 1091 let descV = new Uint8Array(arrayBuffer); 1092 descV[0] = 11; 1093 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1094 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 1095 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 1096 descriptors[0] = descriptor; 1097 let arrayBufferC = new ArrayBuffer(8); 1098 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1099 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 1100 try { 1101 function setCCI() { 1102 return new Promise<void>((resolve,reject) => { 1103 gattC.setCharacteristicChangeIndication(characteristic, false, (err, data)=> { 1104 if (err) { 1105 console.error('setCCI failed' + err); 1106 reject(err.code); 1107 } else 1108 { 1109 console.info('[bluetooth_js]setCCI value:'+JSON.stringify(data)); 1110 expect(true).assertEqual(data != null); 1111 } 1112 resolve(); 1113 }); 1114 }); 1115 } 1116 await setCCI().then((data) => { 1117 console.info("[bluetooth_js]03 setCharacteristicChangeIndication done"); 1118 done(); 1119 }); 1120 } catch (error) { 1121 console.error(`[bluetooth_js]setCharacteristicChangeIndication error, code is ${error.code},message is ${error.message}`); 1122 expect(Number(error.code)).assertEqual(401); 1123 } 1124 done(); 1125 }) 1126 1127 /** 1128 * @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400 1129 * @tc.name testSetCharacteristicChangeIndication 1130 * @tc.desc Test setCharacteristicChangeIndication api10 1131 * @tc.type Function 1132 * @tc.size MediumTest 1133 * @tc.level Level 0 1134 */ 1135 it('SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400', 0, async function (done) { 1136 let descriptors = []; 1137 let arrayBuffer = new ArrayBuffer(8); 1138 let descV = new Uint8Array(arrayBuffer); 1139 descV[0] = 11; 1140 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1141 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 1142 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 1143 descriptors[0] = descriptor; 1144 let arrayBufferC = new ArrayBuffer(8); 1145 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 1146 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 1147 try { 1148 gattC.setCharacteristicChangeIndication(characteristic, true).then(() => { 1149 console.info("setCharacteristicChangeIndication"); 1150 done(); 1151 }); 1152 done(); 1153 } catch (err) { 1154 console.error('setCharacteristicChangeIndication failed errCode: ' + err.code + ', errMessage: ' + err.message); 1155 expect(Number(err.code)).assertEqual(401); 1156 done(); 1157 } 1158 done(); 1159 }) 1160 1161 /** 1162 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLEC_MTUCHANGE_0100 1163 * @tc.name testOnBLEMtuChange 1164 * @tc.desc test GattClientDevice on blemtuchange api10. 1165 * @tc.type Function 1166 * @tc.size MediumTest 1167 * @tc.level Level 1 1168 */ 1169 it('SUB_COMMUNICATION_BLUETOOTHBLEC_MTUCHANGE_0100', 0, async function (done) { 1170 try { 1171 gattC.on('BLEMtuChange', (mtu: number) => { 1172 console.info('BLEMtuChange, mtu: ' + mtu); 1173 }); 1174 } catch (err) { 1175 console.info("bluetooth mtu changed errCode:" + err.code + ",bluetooth mtu changed errMessage:" + err.message); 1176 expect(Number(err.code)).assertEqual(2900099); 1177 } 1178 gattC.off('BLEMtuChange'); 1179 done(); 1180 1181 }) 1182 1183 /** 1184 * @tc.number SUB_COMMUNICATION_BLUETOOTHBLEC_MTUCHANGE_0200 1185 * @tc.name testOnBLEMtuChange 1186 * @tc.desc test GattClientDevice off blemtuchange api10 1187 * @tc.type Function 1188 * @tc.size MediumTest 1189 * @tc.level Level 1 1190 */ 1191 it('SUB_COMMUNICATION_BLUETOOTHBLEC_MTUCHANGE_0200', 0, async function (done) { 1192 gattC.on('BLEMtuChange', (mtu: number) => { 1193 console.info('BLEMtuChange, mtu: ' + mtu); 1194 }); 1195 try { 1196 gattC.off('BLEMtuChange'); 1197 } catch (err) { 1198 console.info("bluetooth mtu changed off errCode:" + err.code + ",bluetooth mtu changed off errMessage:" + err.message); 1199 expect(Number(err.code)).assertEqual(2900099); 1200 } 1201 done(); 1202 }) 1203 1204}) 1205}