1 2/* 3 * Copyright (C) 2022 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import bluetooth from '@ohos.bluetooth'; 18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 19 20 21export default function bluetoothBLETest2() { 22describe('bluetoothBLETest2', function() { 23 let gattServer = null; 24 function sleep(delay) { 25 return new Promise(resovle => setTimeout(resovle, delay)) 26 } 27 28 async function tryToEnableBt() { 29 let sta = bluetooth.getState(); 30 switch(sta){ 31 case 0: 32 console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); 33 bluetooth.enableBluetooth(); 34 await sleep(1000); 35 break; 36 case 1: 37 console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); 38 await sleep(3000); 39 break; 40 case 2: 41 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 42 break; 43 case 3: 44 console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); 45 bluetooth.enableBluetooth(); 46 await sleep(1000); 47 break; 48 default: 49 console.info('[bluetooth_js] enable success'); 50 } 51 } 52 beforeAll(function () { 53 console.info('beforeAll called') 54 gattServer = bluetooth.BLE.createGattServer(); 55 }) 56 beforeEach(async function (done) { 57 console.info('beforeEach called') 58 await tryToEnableBt() 59 done() 60 61 }) 62 afterEach(function () { 63 console.info('afterEach called') 64 }) 65 afterAll(function () { 66 console.info('afterAll called') 67 gattServer.close(); 68 }) 69 70 /** 71 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100 72 * @tc.name testStartAdvertising 73 * @tc.desc Test StartAdvertising api. 74 * @tc.size MEDIUM 75 * @ since 7 76 * @tc.type Function 77 * @tc.level Level 0 78 */ 79 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) { 80 let manufactureValueBuffer = new Uint8Array(4); 81 manufactureValueBuffer[0] = 1; 82 manufactureValueBuffer[1] = 2; 83 manufactureValueBuffer[2] = 3; 84 manufactureValueBuffer[3] = 4; 85 let serviceValueBuffer = new Uint8Array(4); 86 serviceValueBuffer[0] = 4; 87 serviceValueBuffer[1] = 6; 88 serviceValueBuffer[2] = 7; 89 serviceValueBuffer[3] = 8; 90 let setting={ 91 interval:150, 92 txPower:-10, 93 connectable:true, 94 } 95 let advData={ 96 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 97 manufactureData:[{ 98 manufactureId:4567, 99 manufactureValue:manufactureValueBuffer.buffer 100 }], 101 serviceData:[{ 102 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 103 serviceValue:serviceValueBuffer.buffer 104 }], 105 } 106 let advResponse ={ 107 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 108 manufactureData:[{ 109 manufactureId:1789, 110 manufactureValue:manufactureValueBuffer.buffer 111 }], 112 serviceData:[{ 113 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 114 serviceValue:serviceValueBuffer.buffer 115 }], 116 } 117 try { 118 gattServer.startAdvertising(setting,advData,advResponse); 119 gattServer.stopAdvertising(); 120 }catch(e) { 121 expect(null).assertFail(); 122 } 123 done(); 124 }) 125 126 /** 127 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200 128 * @tc.name testStartAdvertising 129 * @tc.desc Test StartAdvertising api. 130 * @tc.size MEDIUM 131 * @ since 7 132 * @tc.type Function 133 * @tc.level Level 2 134 */ 135 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) { 136 let manufactureValueBuffer = new Uint8Array(4); 137 manufactureValueBuffer[0] = 1; 138 manufactureValueBuffer[1] = 2; 139 manufactureValueBuffer[2] = 3; 140 manufactureValueBuffer[3] = 4; 141 let serviceValueBuffer = new Uint8Array(4); 142 serviceValueBuffer[0] = 4; 143 serviceValueBuffer[1] = 6; 144 serviceValueBuffer[2] = 7; 145 serviceValueBuffer[3] = 8; 146 let setting={ 147 interval:20, 148 txPower:-10, 149 connectable:true, 150 } 151 let advData={ 152 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 153 manufactureData:[{ 154 manufactureId:4567, 155 manufactureValue:manufactureValueBuffer.buffer 156 }], 157 serviceData:[{ 158 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 159 serviceValue:serviceValueBuffer.buffer 160 }], 161 } 162 let advResponse ={ 163 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 164 manufactureData:[{ 165 manufactureId:1789, 166 manufactureValue:manufactureValueBuffer.buffer 167 }], 168 serviceData:[{ 169 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 170 serviceValue:serviceValueBuffer.buffer 171 }], 172 } 173 try { 174 gattServer.startAdvertising(setting,advData,advResponse); 175 gattServer.stopAdvertising(); 176 }catch(e) { 177 expect(null).assertFail(); 178 } 179 done(); 180 }) 181 182 /** 183 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300 184 * @tc.name testStartAdvertising 185 * @tc.desc Test StartAdvertising api. 186 * @tc.size MEDIUM 187 * @ since 7 188 * @tc.type Function 189 * @tc.level Level 3 190 */ 191 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) { 192 let manufactureValueBuffer = new Uint8Array(4); 193 manufactureValueBuffer[0] = 1; 194 manufactureValueBuffer[1] = 2; 195 manufactureValueBuffer[2] = 3; 196 manufactureValueBuffer[3] = 4; 197 let serviceValueBuffer = new Uint8Array(4); 198 serviceValueBuffer[0] = 4; 199 serviceValueBuffer[1] = 6; 200 serviceValueBuffer[2] = 7; 201 serviceValueBuffer[3] = 8; 202 let setting={ 203 interval:10485, 204 txPower:-10, 205 connectable:true, 206 } 207 let advData={ 208 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 209 manufactureData:[{ 210 manufactureId:4567, 211 manufactureValue:manufactureValueBuffer.buffer 212 }], 213 serviceData:[{ 214 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 215 serviceValue:serviceValueBuffer.buffer 216 }], 217 } 218 let advResponse ={ 219 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 220 manufactureData:[{ 221 manufactureId:1789, 222 manufactureValue:manufactureValueBuffer.buffer 223 }], 224 serviceData:[{ 225 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 226 serviceValue:serviceValueBuffer.buffer 227 }], 228 } 229 try { 230 gattServer.startAdvertising(setting,advData,advResponse); 231 gattServer.stopAdvertising(); 232 }catch(e) { 233 expect(null).assertFail(); 234 } 235 done(); 236 }) 237 238 /** 239 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400 240 * @tc.name testStartAdvertising 241 * @tc.desc Test StartAdvertising api. 242 * @tc.size MEDIUM 243 * @ since 7 244 * @tc.type Function 245 * @tc.level Level 3 246 */ 247 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) { 248 let manufactureValueBuffer = new Uint8Array(4); 249 manufactureValueBuffer[0] = 1; 250 manufactureValueBuffer[1] = 2; 251 manufactureValueBuffer[2] = 3; 252 manufactureValueBuffer[3] = 4; 253 let serviceValueBuffer = new Uint8Array(4); 254 serviceValueBuffer[0] = 4; 255 serviceValueBuffer[1] = 6; 256 serviceValueBuffer[2] = 7; 257 serviceValueBuffer[3] = 8; 258 let setting={ 259 interval:10500, 260 txPower:-10, 261 connectable:true, 262 } 263 let advData={ 264 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 265 manufactureData:[{ 266 manufactureId:4567, 267 manufactureValue:manufactureValueBuffer.buffer 268 }], 269 serviceData:[{ 270 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 271 serviceValue:serviceValueBuffer.buffer 272 }], 273 } 274 let advResponse ={ 275 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 276 manufactureData:[{ 277 manufactureId:1789, 278 manufactureValue:manufactureValueBuffer.buffer 279 }], 280 serviceData:[{ 281 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 282 serviceValue:serviceValueBuffer.buffer 283 }], 284 } 285 try { 286 gattServer.startAdvertising(setting,advData,advResponse); 287 gattServer.stopAdvertising(); 288 }catch(e) { 289 expect(null).assertFail(); 290 } 291 done(); 292 }) 293 294 /** 295 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500 296 * @tc.name testStartAdvertising 297 * @tc.desc Test StartAdvertising api. 298 * @tc.size MEDIUM 299 * @ since 7 300 * @tc.type Function 301 * @tc.level Level 3 302 */ 303 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) { 304 let manufactureValueBuffer = new Uint8Array(4); 305 manufactureValueBuffer[0] = 1; 306 manufactureValueBuffer[1] = 2; 307 manufactureValueBuffer[2] = 3; 308 manufactureValueBuffer[3] = 4; 309 let serviceValueBuffer = new Uint8Array(4); 310 serviceValueBuffer[0] = 4; 311 serviceValueBuffer[1] = 6; 312 serviceValueBuffer[2] = 7; 313 serviceValueBuffer[3] = 8; 314 let setting={ 315 interval:19, 316 txPower:-10, 317 connectable:true, 318 } 319 let advData={ 320 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 321 manufactureData:[{ 322 manufactureId:4567, 323 manufactureValue:manufactureValueBuffer.buffer 324 }], 325 serviceData:[{ 326 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 327 serviceValue:serviceValueBuffer.buffer 328 }], 329 } 330 let advResponse ={ 331 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 332 manufactureData:[{ 333 manufactureId:1789, 334 manufactureValue:manufactureValueBuffer.buffer 335 }], 336 serviceData:[{ 337 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 338 serviceValue:serviceValueBuffer.buffer 339 }], 340 } 341 try { 342 gattServer.startAdvertising(setting,advData,advResponse); 343 gattServer.stopAdvertising(); 344 }catch(e) { 345 expect(null).assertFail(); 346 } 347 done(); 348 }) 349 350 /** 351 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800 352 * @tc.name testStartAdvertising 353 * @tc.desc Test StartAdvertising api. 354 * @tc.size MEDIUM 355 * @ since 7 356 * @tc.type Function 357 * @tc.level Level 2 358 */ 359 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) { 360 let manufactureValueBuffer = new Uint8Array(4); 361 manufactureValueBuffer[0] = 1; 362 manufactureValueBuffer[1] = 2; 363 manufactureValueBuffer[2] = 3; 364 manufactureValueBuffer[3] = 4; 365 let serviceValueBuffer = new Uint8Array(4); 366 serviceValueBuffer[0] = 4; 367 serviceValueBuffer[1] = 6; 368 serviceValueBuffer[2] = 7; 369 serviceValueBuffer[3] = 8; 370 let setting={ 371 interval:1000, 372 txPower:-10, 373 connectable:true, 374 } 375 let advData={ 376 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 377 manufactureData:[{ 378 manufactureId:4567, 379 manufactureValue:manufactureValueBuffer.buffer 380 }], 381 serviceData:[{ 382 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 383 serviceValue:serviceValueBuffer.buffer 384 }], 385 } 386 let advResponse ={ 387 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 388 manufactureData:[{ 389 manufactureId:1789, 390 manufactureValue:manufactureValueBuffer.buffer 391 }], 392 serviceData:[{ 393 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 394 serviceValue:serviceValueBuffer.buffer 395 }], 396 } 397 try { 398 gattServer.startAdvertising(setting,advData,advResponse); 399 gattServer.stopAdvertising(); 400 }catch(e) { 401 expect(null).assertFail(); 402 } 403 done(); 404 }) 405 406 /** 407 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900 408 * @tc.name testStartAdvertising 409 * @tc.desc Test StartAdvertising api. 410 * @tc.size MEDIUM 411 * @ since 7 412 * @tc.type Function 413 * @tc.level Level 2 414 */ 415 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) { 416 let manufactureValueBuffer = new Uint8Array(4); 417 manufactureValueBuffer[0] = 1; 418 manufactureValueBuffer[1] = 2; 419 manufactureValueBuffer[2] = 3; 420 manufactureValueBuffer[3] = 4; 421 let serviceValueBuffer = new Uint8Array(4); 422 serviceValueBuffer[0] = 4; 423 serviceValueBuffer[1] = 6; 424 serviceValueBuffer[2] = 7; 425 serviceValueBuffer[3] = 8; 426 let setting={ 427 interval:1000, 428 txPower:-127, 429 connectable:true, 430 } 431 let advData={ 432 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 433 manufactureData:[{ 434 manufactureId:4567, 435 manufactureValue:manufactureValueBuffer.buffer 436 }], 437 serviceData:[{ 438 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 439 serviceValue:serviceValueBuffer.buffer 440 }], 441 } 442 let advResponse ={ 443 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 444 manufactureData:[{ 445 manufactureId:1789, 446 manufactureValue:manufactureValueBuffer.buffer 447 }], 448 serviceData:[{ 449 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 450 serviceValue:serviceValueBuffer.buffer 451 }], 452 } 453 try { 454 gattServer.startAdvertising(setting,advData,advResponse); 455 gattServer.stopAdvertising(); 456 }catch(e) { 457 expect(null).assertFail(); 458 } 459 done(); 460 }) 461 462 /** 463 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000 464 * @tc.name testStartAdvertising 465 * @tc.desc Test StartAdvertising api. 466 * @tc.size MEDIUM 467 * @ since 7 468 * @tc.type Function 469 * @tc.level Level 2 470 */ 471 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) { 472 let manufactureValueBuffer = new Uint8Array(4); 473 manufactureValueBuffer[0] = 1; 474 manufactureValueBuffer[1] = 2; 475 manufactureValueBuffer[2] = 3; 476 manufactureValueBuffer[3] = 4; 477 let serviceValueBuffer = new Uint8Array(4); 478 serviceValueBuffer[0] = 4; 479 serviceValueBuffer[1] = 6; 480 serviceValueBuffer[2] = 7; 481 serviceValueBuffer[3] = 8; 482 let setting={ 483 interval:1000, 484 txPower:1, 485 connectable:true, 486 } 487 let advData={ 488 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 489 manufactureData:[{ 490 manufactureId:4567, 491 manufactureValue:manufactureValueBuffer.buffer 492 }], 493 serviceData:[{ 494 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 495 serviceValue:serviceValueBuffer.buffer 496 }], 497 } 498 let advResponse ={ 499 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 500 manufactureData:[{ 501 manufactureId:1789, 502 manufactureValue:manufactureValueBuffer.buffer 503 }], 504 serviceData:[{ 505 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 506 serviceValue:serviceValueBuffer.buffer 507 }], 508 } 509 try { 510 gattServer.startAdvertising(setting,advData,advResponse); 511 gattServer.stopAdvertising(); 512 }catch(e) { 513 expect(null).assertFail(); 514 } 515 done(); 516 }) 517 518 /** 519 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100 520 * @tc.name testStartAdvertising 521 * @tc.desc Test StartAdvertising api. 522 * @tc.size MEDIUM 523 * @ since 7 524 * @tc.type Function 525 * @tc.level Level 3 526 */ 527 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) { 528 let manufactureValueBuffer = new Uint8Array(4); 529 manufactureValueBuffer[0] = 1; 530 manufactureValueBuffer[1] = 2; 531 manufactureValueBuffer[2] = 3; 532 manufactureValueBuffer[3] = 4; 533 let serviceValueBuffer = new Uint8Array(4); 534 serviceValueBuffer[0] = 4; 535 serviceValueBuffer[1] = 6; 536 serviceValueBuffer[2] = 7; 537 serviceValueBuffer[3] = 8; 538 let setting={ 539 interval:1000, 540 txPower:10, 541 connectable:true, 542 } 543 let advData={ 544 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 545 manufactureData:[{ 546 manufactureId:4567, 547 manufactureValue:manufactureValueBuffer.buffer 548 }], 549 serviceData:[{ 550 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 551 serviceValue:serviceValueBuffer.buffer 552 }], 553 } 554 let advResponse ={ 555 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 556 manufactureData:[{ 557 manufactureId:1789, 558 manufactureValue:manufactureValueBuffer.buffer 559 }], 560 serviceData:[{ 561 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 562 serviceValue:serviceValueBuffer.buffer 563 }], 564 } 565 try { 566 gattServer.startAdvertising(setting,advData,advResponse); 567 gattServer.stopAdvertising(); 568 }catch(e) { 569 expect(null).assertFail(); 570 } 571 done(); 572 }) 573 574 /** 575 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200 576 * @tc.name testStartAdvertising 577 * @tc.desc Test StartAdvertising api. 578 * @tc.size MEDIUM 579 * @ since 7 580 * @tc.type Function 581 * @tc.level Level 3 582 */ 583 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) { 584 let manufactureValueBuffer = new Uint8Array(4); 585 manufactureValueBuffer[0] = 1; 586 manufactureValueBuffer[1] = 2; 587 manufactureValueBuffer[2] = 3; 588 manufactureValueBuffer[3] = 4; 589 let serviceValueBuffer = new Uint8Array(4); 590 serviceValueBuffer[0] = 4; 591 serviceValueBuffer[1] = 6; 592 serviceValueBuffer[2] = 7; 593 serviceValueBuffer[3] = 8; 594 let setting={ 595 interval:1000, 596 txPower:-130, 597 connectable:true, 598 } 599 let advData={ 600 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 601 manufactureData:[{ 602 manufactureId:4567, 603 manufactureValue:manufactureValueBuffer.buffer 604 }], 605 serviceData:[{ 606 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 607 serviceValue:serviceValueBuffer.buffer 608 }], 609 } 610 let advResponse ={ 611 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 612 manufactureData:[{ 613 manufactureId:1789, 614 manufactureValue:manufactureValueBuffer.buffer 615 }], 616 serviceData:[{ 617 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 618 serviceValue:serviceValueBuffer.buffer 619 }], 620 } 621 try { 622 gattServer.startAdvertising(setting,advData,advResponse); 623 gattServer.stopAdvertising(); 624 }catch(e) { 625 expect(null).assertFail(); 626 } 627 done(); 628 }) 629 630 /** 631 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400 632 * @tc.name testStartAdvertising 633 * @tc.desc Test StartAdvertising api. 634 * @tc.size MEDIUM 635 * @ since 7 636 * @tc.type Function 637 * @tc.level Level 2 638 */ 639 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) { 640 let manufactureValueBuffer = new Uint8Array(4); 641 manufactureValueBuffer[0] = 1; 642 manufactureValueBuffer[1] = 2; 643 manufactureValueBuffer[2] = 3; 644 manufactureValueBuffer[3] = 4; 645 let serviceValueBuffer = new Uint8Array(4); 646 serviceValueBuffer[0] = 4; 647 serviceValueBuffer[1] = 6; 648 serviceValueBuffer[2] = 7; 649 serviceValueBuffer[3] = 8; 650 let setting={ 651 interval:1000, 652 txPower:1, 653 connectable:false, 654 } 655 let advData={ 656 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 657 manufactureData:[{ 658 manufactureId:4567, 659 manufactureValue:manufactureValueBuffer.buffer 660 }], 661 serviceData:[{ 662 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 663 serviceValue:serviceValueBuffer.buffer 664 }], 665 } 666 let advResponse ={ 667 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 668 manufactureData:[{ 669 manufactureId:1789, 670 manufactureValue:manufactureValueBuffer.buffer 671 }], 672 serviceData:[{ 673 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 674 serviceValue:serviceValueBuffer.buffer 675 }], 676 } 677 try { 678 gattServer.startAdvertising(setting,advData,advResponse); 679 gattServer.stopAdvertising(); 680 }catch(e) { 681 expect(null).assertFail(); 682 } 683 done(); 684 }) 685 686 /** 687 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500 688 * @tc.name testStartAdvertising 689 * @tc.desc Test StartAdvertising api. 690 * @tc.size MEDIUM 691 * @ since 7 692 * @tc.type Function 693 * @tc.level Level 3 694 */ 695 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) { 696 let manufactureValueBuffer = new Uint8Array(4); 697 manufactureValueBuffer[0] = 1; 698 manufactureValueBuffer[1] = 2; 699 manufactureValueBuffer[2] = 3; 700 manufactureValueBuffer[3] = 4; 701 let serviceValueBuffer = new Uint8Array(4); 702 serviceValueBuffer[0] = 4; 703 serviceValueBuffer[1] = 6; 704 serviceValueBuffer[2] = 7; 705 serviceValueBuffer[3] = 8; 706 let setting={ 707 interval:1000, 708 txPower:-7, 709 connectable:true, 710 } 711 let advData={ 712 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 713 manufactureData:[{ 714 manufactureId:4567, 715 manufactureValue:manufactureValueBuffer.buffer 716 }], 717 serviceData:[{ 718 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 719 serviceValue:serviceValueBuffer.buffer 720 }], 721 } 722 let advResponse ={ 723 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 724 manufactureData:[{ 725 manufactureId:1789, 726 manufactureValue:manufactureValueBuffer.buffer 727 }], 728 serviceData:[{ 729 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 730 serviceValue:serviceValueBuffer.buffer 731 }], 732 } 733 try { 734 gattServer.startAdvertising(setting,advData,advResponse); 735 gattServer.stopAdvertising(); 736 }catch(e) { 737 expect(null).assertFail(); 738 } 739 done(); 740 }) 741 742 /** 743 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600 744 * @tc.name testStartAdvertising 745 * @tc.desc Test StartAdvertising api. 746 * @tc.size MEDIUM 747 * @ since 7 748 * @tc.type Function 749 * @tc.level Level 1 750 */ 751 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) { 752 let manufactureValueBuffer = new Uint8Array(4); 753 manufactureValueBuffer[0] = 1; 754 manufactureValueBuffer[1] = 2; 755 manufactureValueBuffer[2] = 3; 756 manufactureValueBuffer[3] = 4; 757 let serviceValueBuffer = new Uint8Array(4); 758 serviceValueBuffer[0] = 4; 759 serviceValueBuffer[1] = 6; 760 serviceValueBuffer[2] = 7; 761 serviceValueBuffer[3] = 8; 762 let setting={ 763 interval:1000, 764 txPower:-7, 765 connectable:true, 766 } 767 let advData={ 768 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 769 manufactureData:[{ 770 manufactureId:4567, 771 manufactureValue:manufactureValueBuffer.buffer 772 }], 773 serviceData:[{ 774 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 775 serviceValue:serviceValueBuffer.buffer 776 }], 777 } 778 let advResponse ={ 779 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 780 manufactureData:[{ 781 manufactureId:1789, 782 manufactureValue:manufactureValueBuffer.buffer 783 }], 784 serviceData:[{ 785 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 786 serviceValue:serviceValueBuffer.buffer 787 }], 788 } 789 try { 790 gattServer.startAdvertising(setting,advData,advResponse); 791 gattServer.stopAdvertising(); 792 }catch(e) { 793 expect(null).assertFail(); 794 } 795 done(); 796 }) 797 798 /** 799 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800 800 * @tc.name testStartAdvertising 801 * @tc.desc Test StartAdvertising api. 802 * @tc.size MEDIUM 803 * @ since 7 804 * @tc.type Function 805 * @tc.level Level 2 806 */ 807 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800', 0, async function (done) { 808 let manufactureValueBuffer = new Uint8Array(4); 809 manufactureValueBuffer[0] = 1; 810 manufactureValueBuffer[1] = 2; 811 manufactureValueBuffer[2] = 3; 812 manufactureValueBuffer[3] = 4; 813 let serviceValueBuffer = new Uint8Array(4); 814 serviceValueBuffer[0] = 4; 815 serviceValueBuffer[1] = 6; 816 serviceValueBuffer[2] = 7; 817 serviceValueBuffer[3] = 8; 818 let setting={ 819 interval:1000, 820 txPower:1, 821 connectable:true, 822 } 823 let advData={ 824 serviceUuids:[""], 825 manufactureData:[{ 826 manufactureId:4567, 827 manufactureValue:manufactureValueBuffer.buffer 828 }], 829 serviceData:[{ 830 serviceUuid:"", 831 serviceValue:serviceValueBuffer.buffer 832 }], 833 } 834 let advResponse ={ 835 serviceUuids:[""], 836 manufactureData:[{ 837 manufactureId:1789, 838 manufactureValue:manufactureValueBuffer.buffer 839 }], 840 serviceData:[{ 841 serviceUuid:"", 842 serviceValue:serviceValueBuffer.buffer 843 }], 844 } 845 try { 846 gattServer.startAdvertising(setting,advData,advResponse); 847 gattServer.stopAdvertising(); 848 }catch(e) { 849 expect(null).assertFail(); 850 } 851 done(); 852 }) 853 854 /** 855 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900 856 * @tc.name testStartAdvertising 857 * @tc.desc Test StartAdvertising api. 858 * @tc.size MEDIUM 859 * @ since 7 860 * @tc.type Function 861 * @tc.level Level 2 862 */ 863 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900', 0, async function (done) { 864 let manufactureValueBuffer = new Uint8Array(4); 865 manufactureValueBuffer[0] = 1; 866 manufactureValueBuffer[1] = 2; 867 manufactureValueBuffer[2] = 3; 868 manufactureValueBuffer[3] = 4; 869 let serviceValueBuffer = new Uint8Array(4); 870 serviceValueBuffer[0] = 4; 871 serviceValueBuffer[1] = 6; 872 serviceValueBuffer[2] = 7; 873 serviceValueBuffer[3] = 8; 874 let setting={ 875 interval:1000, 876 txPower:1, 877 connectable:true, 878 } 879 let advData={ 880 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 881 manufactureData:[{ 882 manufactureId:4567, 883 manufactureValue:manufactureValueBuffer.buffer 884 }], 885 serviceData:[], 886 } 887 let advResponse ={ 888 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 889 manufactureData:[{ 890 manufactureId:1789, 891 manufactureValue:manufactureValueBuffer.buffer 892 }], 893 serviceData:[], 894 } 895 try { 896 gattServer.startAdvertising(setting,advData,advResponse); 897 gattServer.stopAdvertising(); 898 }catch(e) { 899 expect(null).assertFail(); 900 } 901 done(); 902 }) 903 904 905 /** 906 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100 907 * @tc.name testStartAdvertising 908 * @tc.desc Test StartAdvertising api. 909 * @tc.size MEDIUM 910 * @ since 7 911 * @tc.type Function 912 * @tc.level Level 3 913 */ 914 it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100', 0, async function (done) { 915 let manufactureValueBuffer = new Uint8Array(4); 916 manufactureValueBuffer[0] = 1; 917 manufactureValueBuffer[1] = 2; 918 manufactureValueBuffer[2] = 3; 919 manufactureValueBuffer[3] = 4; 920 let serviceValueBuffer = new Uint8Array(4); 921 serviceValueBuffer[0] = 4; 922 serviceValueBuffer[1] = 6; 923 serviceValueBuffer[2] = 7; 924 serviceValueBuffer[3] = 8; 925 let setting={ 926 interval:1000, 927 txPower:1, 928 connectable:true, 929 } 930 let advData={ 931 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 932 manufactureData:[], 933 serviceData:[{ 934 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 935 serviceValue:serviceValueBuffer.buffer 936 }], 937 } 938 let advResponse ={ 939 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 940 manufactureData:[], 941 serviceData:[{ 942 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 943 serviceValue:serviceValueBuffer.buffer 944 }], 945 } 946 try { 947 gattServer.startAdvertising(setting,advData,advResponse); 948 gattServer.stopAdvertising(); 949 }catch(e) { 950 expect(null).assertFail(); 951 } 952 done(); 953 }) 954 955 /** 956 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400 957 * @tc.name testStartAdvertising 958 * @tc.desc Test StartAdvertising api. 959 * @tc.size MEDIUM 960 * @ since 7 961 * @tc.type Function 962 * @tc.level Level 3 963 */ 964 it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400', 0, function () { 965 let isRet = true; 966 try{ 967 gattServer.stopAdvertising(); 968 expect(isRet).assertTrue(); 969 }catch(error){ 970 console.info("[bluetooth_js] GattclientClose err:" + JSON.stringify(error)); 971 let isRet = false; 972 expect(isRet).assertFalse(); 973 } 974 }) 975 976}) 977 978} 979 980