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 bluetooth from '@ohos.bluetoothManager'; 17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 18 19export default function bluetoothBLETest6() { 20describe('bluetoothBLETest6', function() { 21 function sleep(delay) { 22 return new Promise(resovle => setTimeout(resovle, delay)) 23 } 24 25 async function tryToEnableBt() { 26 let sta = bluetooth.getState(); 27 switch(sta){ 28 case 0: 29 bluetooth.enableBluetooth(); 30 await sleep(10000); 31 let sta1 = bluetooth.getState(); 32 console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); 33 break; 34 case 1: 35 console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); 36 await sleep(3000); 37 break; 38 case 2: 39 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 40 break; 41 case 3: 42 bluetooth.enableBluetooth(); 43 await sleep(10000); 44 let sta2 = bluetooth.getState(); 45 console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); 46 break; 47 default: 48 console.info('[bluetooth_js] enable success'); 49 } 50 } 51 beforeAll(function () { 52 console.info('beforeAll called') 53 }) 54 beforeEach(async function(done) { 55 console.info('beforeEach called') 56 await tryToEnableBt() 57 done() 58 }) 59 afterEach(function () { 60 console.info('afterEach called') 61 }) 62 afterAll(function () { 63 console.info('afterAll called') 64 }) 65 66 /** 67 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0100 68 * @tc.name testClassicStartBLEScan 69 * @tc.desc Test startBLEScan 401 - Invalid parameter. 70 * @tc.size MEDIUM 71 * @ since 7 72 * @tc.type Function 73 * @tc.level Level 0 74 */ 75 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0100', 0, async function (done) { 76 try { 77 function onReceiveEvent(data) 78 { 79 console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data)); 80 expect(true).assertTrue(data.length>0); 81 } 82 bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) 83 bluetooth.BLE.startBLEScan(null); 84 await sleep(1000); 85 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 86 bluetooth.BLE.stopBLEScan(); 87 done(); 88 } catch (error) { 89 console.error('[bluetooth_js]Scan_0100 error.code:'+JSON.stringify(error.code)+ 90 'error.message:'+JSON.stringify(error.message)); 91 expect(true).assertFalse(); 92 done() 93 } 94 }) 95 96 /** 97 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0200 98 * @tc.name testClassicStartBLEScan 99 * @tc.desc Test ClassicStartBLEScan api. 100 * @tc.size MEDIUM 101 * @ since 7 102 * @tc.type Function 103 * @tc.level Level 2 104 */ 105 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0200', 0, async function (done) { 106 try { 107 function onReceiveEvent(data) 108 { 109 console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data)); 110 expect(true).assertTrue(data.length>0); 111 } 112 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 113 bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); 114 await sleep(1000); 115 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 116 bluetooth.BLE.stopBLEScan(); 117 done(); 118 } catch (error) { 119 console.error('[bluetooth_js]Scan_0200 error.code:'+JSON.stringify(error.code)+ 120 'error.message:'+JSON.stringify(error.message)); 121 expect(true).assertFalse(); 122 done() 123 } 124 }) 125 126 /** 127 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0300 128 * @tc.name testClassicStartBLEScan 129 * @tc.desc Test ClassicStartBLEScan api. 130 * @tc.size MEDIUM 131 * @ since 7 132 * @tc.type Function 133 * @tc.level Level 2 134 */ 135 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0300', 0, async function (done) { 136 try { 137 function onReceiveEvent(data) 138 { 139 console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data)); 140 expect(true).assertTrue(data.length>0); 141 } 142 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 143 bluetooth.BLE.startBLEScan([{name:"blue_test"}]); 144 await sleep(1000); 145 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 146 bluetooth.BLE.stopBLEScan(); 147 done(); 148 } catch (error) { 149 console.error('[bluetooth_js]Scan_0300 error.code:'+JSON.stringify(error.code)+ 150 'error.message:'+JSON.stringify(error.message)); 151 expect(true).assertFalse(); 152 done() 153 } 154 }) 155 156 /** 157 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0400 158 * @tc.name testClassicStartBLEScan 159 * @tc.desc Test ClassicStartBLEScan api. 160 * @tc.size MEDIUM 161 * @ since 7 162 * @tc.type Function 163 * @tc.level Level 3 164 */ 165 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0400', 0, async function (done) { 166 try { 167 function onReceiveEvent(data) 168 { 169 console.info('[bluetooth_js] BLEscan device result4'+JSON.stringify(data)); 170 expect(true).assertTrue(data.length>0); 171 } 172 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 173 bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]); 174 await sleep(1000); 175 console.info('[bluetooth_js] BLE scan off4'); 176 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 177 done(); 178 } catch (error) { 179 console.error('[bluetooth_js]Scan_0400 error.code:'+JSON.stringify(error.code)+ 180 'error.message:'+JSON.stringify(error.message)); 181 expect(true).assertFalse(); 182 done() 183 } 184 }) 185 186 /** 187 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0500 188 * @tc.name testClassicStartBLEScan 189 * @tc.desc Test ClassicStartBLEScan api. 190 * @tc.size MEDIUM 191 * @ since 7 192 * @tc.type Function 193 * @tc.level Level 3 194 */ 195 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0500', 0, async function (done) { 196 try { 197 function onReceiveEvent(data) 198 { 199 console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data)); 200 expect(true).assertTrue(data.length>0); 201 } 202 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 203 bluetooth.BLE.startBLEScan( 204 [{}], 205 { 206 interval: 100, 207 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 208 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 209 } 210 ); 211 await sleep(1000); 212 console.info('[bluetooth_js] BLE scan off5'); 213 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 214 bluetooth.BLE.stopBLEScan(); 215 done(); 216 } catch (error) { 217 console.error('[bluetooth_js]Scan_0500 error.code:'+JSON.stringify(error.code)+ 218 'error.message:'+JSON.stringify(error.message)); 219 expect(true).assertFalse(); 220 done() 221 } 222 }) 223 224 /** 225 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0600 226 * @tc.name testClassicStartBLEScan 227 * @tc.desc Test ClassicStartBLEScan api. 228 * @tc.size MEDIUM 229 * @ since 7 230 * @tc.type Function 231 * @tc.level Level 3 232 */ 233 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0600', 0, async function (done) { 234 try { 235 function onReceiveEvent(data) 236 { 237 console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data)); 238 expect(true).assertTrue(data.length>0); 239 } 240 let ScanOptions= { 241 interval: 100, 242 dutyMode: bluetooth.ScanDuty.SCAN_MODE_BALANCED, 243 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 244 } 245 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 246 bluetooth.BLE.startBLEScan([{}],ScanOptions); 247 await sleep(1000); 248 console.info('[bluetooth_js] BLE scan off6'); 249 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 250 bluetooth.BLE.stopBLEScan(); 251 done(); 252 } catch (error) { 253 console.error('[bluetooth_js]Scan_0600 error.code:'+JSON.stringify(error.code)+ 254 'error.message:'+JSON.stringify(error.message)); 255 expect(true).assertFalse(); 256 done() 257 } 258 }) 259 260 /** 261 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0700 262 * @tc.name testClassicStartBLEScan 263 * @tc.desc Test ClassicStartBLEScan api. 264 * @tc.size MEDIUM 265 * @ since 7 266 * @tc.type Function 267 * @tc.level Level 3 268 */ 269 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0700', 0, async function (done) { 270 try { 271 function onReceiveEvent(data) 272 { 273 console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data)); 274 expect(true).assertTrue(data.length>0); 275 } 276 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 277 bluetooth.BLE.startBLEScan( 278 [{}], 279 { 280 interval: 100, 281 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 282 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 283 } 284 ); 285 await sleep(1000); 286 console.info('[bluetooth_js] BLE scan off7'); 287 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 288 done(); 289 } catch (error) { 290 console.error('[bluetooth_js]Scan_0700 error.code:'+JSON.stringify(error.code)+ 291 'error.message:'+JSON.stringify(error.message)); 292 expect(true).assertFalse(); 293 done() 294 } 295 296 }) 297 298 /** 299 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_0700 300 * @tc.name testClassicStartBLEScan 301 * @tc.desc Test ClassicStartBLEScan api. 302 * @tc.size MEDIUM 303 * @ since 7 304 * @tc.type Function 305 * @tc.level Level 3 306 */ 307 it('COMMUNICATION_BLUETOOTH_BLE_Scan_0900', 0, async function (done) { 308 try { 309 function onReceiveEvent(data) 310 { 311 console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data)); 312 expect(true).assertTrue(data.length>0); 313 } 314 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 315 bluetooth.BLE.startBLEScan( 316 [{}], 317 { 318 interval: 0, 319 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 320 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 321 } 322 ); 323 await sleep(1000); 324 console.info('[bluetooth_js] BLE scan off7'); 325 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 326 bluetooth.BLE.stopBLEScan(); 327 done(); 328 } catch (error) { 329 console.error('[bluetooth_js]Scan_0900 error.code:'+JSON.stringify(error.code)+ 330 'error.message:'+JSON.stringify(error.message)); 331 expect(true).assertFalse(); 332 done() 333 } 334 335 }) 336 337 /** 338 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1000 339 * @tc.name testClassicStartBLEScan 340 * @tc.desc Test ClassicStartBLEScan api. 341 * @tc.size MEDIUM 342 * @ since 7 343 * @tc.type Function 344 * @tc.level Level 3 345 */ 346 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1000', 0, async function (done) { 347 try { 348 function onReceiveEvent(data) 349 { 350 console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data)); 351 expect(true).assertTrue(data.length>0); 352 } 353 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 354 bluetooth.BLE.startBLEScan( 355 [{}], 356 { 357 interval: 500, 358 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 359 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 360 } 361 ); 362 await sleep(1000); 363 console.info('[bluetooth_js] BLE scan off10'); 364 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 365 bluetooth.BLE.stopBLEScan(); 366 done(); 367 } catch (error) { 368 console.error('[bluetooth_js]Scan_1000 error.code:'+JSON.stringify(error.code)+ 369 'error.message:'+JSON.stringify(error.message)); 370 expect(true).assertFalse(); 371 done() 372 } 373 }) 374 375 /** 376 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1100 377 * @tc.name testClassicStartBLEScan 378 * @tc.desc Test ClassicStartBLEScan api. 379 * @tc.size MEDIUM 380 * @ since 7 381 * @tc.type Function 382 * @tc.level Level 3 383 */ 384 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1100', 0, async function (done) { 385 try { 386 function onReceiveEvent(data) 387 { 388 console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data)); 389 expect(true).assertTrue(data.length>0); 390 } 391 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 392 bluetooth.BLE.startBLEScan( 393 [{}], 394 { 395 interval: 500, 396 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 397 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 398 } 399 ); 400 await sleep(1000); 401 console.info('[bluetooth_js] BLE scan off11'); 402 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 403 bluetooth.BLE.stopBLEScan(); 404 done(); 405 } catch (error) { 406 console.error('[bluetooth_js]Scan_1100 error.code:'+JSON.stringify(error.code)+ 407 'error.message:'+JSON.stringify(error.message)); 408 expect(true).assertFalse(); 409 done() 410 } 411 412 }) 413 414 /** 415 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1200 416 * @tc.name testClassicStartBLEScan 417 * @tc.desc Test ClassicStartBLEScan api. 418 * @tc.size MEDIUM 419 * @ since 7 420 * @tc.type Function 421 * @tc.level Level 3 422 */ 423 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1200', 0, async function (done) { 424 try { 425 function onReceiveEvent(data) 426 { 427 console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data)); 428 expect(true).assertTrue(data.length>0); 429 } 430 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 431 bluetooth.BLE.startBLEScan( 432 [{}], 433 { 434 interval: 500, 435 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 436 matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, 437 } 438 ); 439 await sleep(1000); 440 console.info('[bluetooth_js] BLE scan off12'); 441 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 442 bluetooth.BLE.stopBLEScan(); 443 done(); 444 } catch (error) { 445 console.error('[bluetooth_js]Scan_1200 error.code:'+JSON.stringify(error.code)+ 446 'error.message:'+JSON.stringify(error.message)); 447 expect(true).assertFalse(); 448 done() 449 } 450 }) 451 452 /** 453 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1300 454 * @tc.name testClassicStartBLEScan 455 * @tc.desc Test ClassicStartBLEScan api. 456 * @tc.size MEDIUM 457 * @ since 7 458 * @tc.type Function 459 * @tc.level Level 3 460 */ 461 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1300', 0, async function (done) { 462 try { 463 function onReceiveEvent(data) 464 { 465 console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data)); 466 expect(true).assertTrue(data.length>0); 467 } 468 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 469 bluetooth.BLE.startBLEScan( 470 [{ 471 deviceId:"11:22:33:44:55:66", 472 name:"test", 473 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" 474 }], 475 { 476 interval: 500, 477 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 478 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 479 } 480 ); 481 await sleep(1000); 482 console.info('[bluetooth_js] BLE scan off13'); 483 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 484 bluetooth.BLE.stopBLEScan(); 485 done(); 486 } catch (error) { 487 console.error('[bluetooth_js]Scan_1300 error.code:'+JSON.stringify(error.code)+ 488 'error.message:'+JSON.stringify(error.message)); 489 expect(true).assertFalse(); 490 done() 491 } 492 493 }) 494 495 /* @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1400 496 * @tc.name testClassicStartBLEScan 497 * @tc.desc Test ClassicStartBLEScan api. 498 * @tc.size MEDIUM 499 * @ since 9 500 * @tc.type Function 501 * @tc.level Level 3 502 */ 503 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1400', 0, async function (done) { 504 try { 505 function onReceiveEvent(data) 506 { 507 console.info('[bluetooth_js] BLE scan device find result14'+ JSON.stringify(data)); 508 expect(true).assertTrue(data.length > 0); 509 } 510 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 511 bluetooth.BLE.startBLEScan([{ 512 serviceUuid:"00001812-0000-1000-8000-00805F9B34FB", 513 serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 514 }]); 515 await sleep(1000); 516 console.info('[bluetooth_js] BLE scan off14 '); 517 bluetooth.BLE.stopBLEScan(); 518 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 519 done(); 520 } catch (error) { 521 console.error('[bluetooth_js]Scan_1400 error.code:'+JSON.stringify(error.code)+ 522 'error.message:'+JSON.stringify(error.message)); 523 expect(true).assertFalse(); 524 done() 525 } 526 }) 527 528 /** 529 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1500 530 * @tc.name testClassicStartBLEScan 531 * @tc.desc Test ClassicStartBLEScan api. 532 * @tc.size MEDIUM 533 * @ since 9 534 * @tc.type Function 535 * @tc.level Level 2 536 */ 537 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1500', 0, async function (done) { 538 try { 539 function onReceiveEvent(data) 540 { 541 console.info('[bluetooth_js] BLE scan device find result15'+ JSON.stringify(data)); 542 expect(true).assertTrue(data.length > 0); 543 } 544 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 545 bluetooth.BLE.startBLEScan([{ 546 serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", 547 serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 548 549 }]); 550 await sleep(1000); 551 console.info('[bluetooth_js] BLE scan off15 '); 552 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 553 bluetooth.BLE.stopBLEScan(); 554 done(); 555 } catch (error) { 556 console.error('[bluetooth_js]Scan_1500 error.code:'+JSON.stringify(error.code)+ 557 'error.message:'+JSON.stringify(error.message)); 558 expect(true).assertFalse(); 559 done() 560 } 561 562 }) 563 564 /** 565 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1600 566 * @tc.name testClassicStartBLEScan 567 * @tc.desc Test ClassicStartBLEScan api. 568 * @tc.size MEDIUM 569 * @ since 9 570 * @tc.type Function 571 * @tc.level Level 2 572 */ 573 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1600', 0, async function (done) { 574 try { 575 function onReceiveEvent(data) 576 { 577 console.info('[bluetooth_js] BLE scan device find result16'+ JSON.stringify(data)); 578 expect(true).assertTrue(data.length > 0); 579 } 580 let ScanFilters= []; 581 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 582 const serviceDataArrayBuffer = new ArrayBuffer(1); 583 const serviceDataMaskArrayBuffer = new ArrayBuffer(1); 584 const serviceDataValue = new Uint8Array(serviceDataArrayBuffer); 585 const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer); 586 serviceDataValue[0] = '0xFF'; 587 serviceDataMaskValue[0] = '0xFF'; 588 let ScanFilter = { 589 serviceData:serviceDataArrayBuffer, 590 serviceDataMask:serviceDataMaskArrayBuffer, 591 } 592 ScanFilters[0]=ScanFilter; 593 bluetooth.BLE.startBLEScan(ScanFilters); 594 await sleep(1000); 595 console.info('[bluetooth_js] BLE scan off16'); 596 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 597 bluetooth.BLE.stopBLEScan(); 598 done(); 599 } catch (error) { 600 console.error('[bluetooth_js]Scan_1600 error.code:'+JSON.stringify(error.code)+ 601 'error.message:'+JSON.stringify(error.message)); 602 expect(true).assertFalse(); 603 done() 604 } 605 606 }) 607 608 /** 609 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1700 610 * @tc.name testClassicStartBLEScan 611 * @tc.desc Test ClassicStartBLEScan api. 612 * @tc.size MEDIUM 613 * @ since 9 614 * @tc.type Function 615 * @tc.level Level 2 616 */ 617 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1700', 0, async function (done) { 618 try { 619 function onReceiveEvent(data) 620 { 621 console.info('[bluetooth_js] BLE scan device find result17'+ JSON.stringify(data)); 622 expect(true).assertTrue(data.length > 0); 623 } 624 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 625 const manufactureDataArrayBuffer = new ArrayBuffer(29); 626 const manufactureDataMaskArrayBuffer = new ArrayBuffer(29); 627 const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer); 628 const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer); 629 for (let i = 0; i < 29; i++) { 630 manufactureDataValue[i] = '0xFF'; 631 } 632 for (let i = 0; i < 29; i++) { 633 manufactureDataMaskValue[i] = '0xFF'; 634 } 635 bluetooth.BLE.startBLEScan([{ 636 manufactureId:0x0006, 637 manufactureData:manufactureDataValue, 638 manufactureDataMask:manufactureDataMaskValue, 639 }]); 640 await sleep(1000); 641 expect(true).assertFalse(); 642 console.info('[bluetooth_js] BLE scan off17 '); 643 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 644 bluetooth.BLE.stopBLEScan(); 645 done(); 646 } catch (error) { 647 console.error('[bluetooth_js]Scan_1700 error.code:'+JSON.stringify(error.code)+ 648 'error.message:'+JSON.stringify(error.message)); 649 expect(error.code).assertEqual('401'); 650 done() 651 } 652 }) 653 654 /** 655 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1800 656 * @tc.name test gatt connect and disconnect 657 * @tc.desc Test connect and disconnect api . 658 * @tc.size MEDIUM 659 * @ since 7 660 * @tc.type Function 661 * @tc.level Level 2 662 */ 663 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1800', 0, async function (done) { 664 try { 665 async function onReceiveEvent(ScanResult) 666 { 667 console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(ScanResult) 668 +ScanResult.deviceId+ScanResult.rssi+ ScanResult.data); 669 expect(true).assertTrue(ScanResult.length>0); 670 await sleep(1000); 671 let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId); 672 let ret = gattClient.connect(); 673 await sleep(2000); 674 console.info('[bluetooth_js] gattClient connect' + ret) 675 expect(ret).assertTrue(); 676 let disconnect = gattClient.disconnect(); 677 console.info('[bluetooth_js] gatt disconnect:' + disconnect); 678 expect(disconnect).assertEqual(false); 679 } 680 await bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent); 681 bluetooth.BLE.startBLEScan( 682 [{}], 683 { 684 interval: 500, 685 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 686 matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, 687 } 688 ); 689 console.info('[bluetooth_js] BLE scan offC'); 690 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 691 bluetooth.BLE.stopBLEScan(); 692 done() 693 } catch (error) { 694 console.error('[bluetooth_js]Scan_1800 error.code:'+JSON.stringify(error.code)+ 695 'error.message:'+JSON.stringify(error.message)); 696 expect(true).assertFalse(); 697 done() 698 } 699 700 }) 701 702 /** 703 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1900 704 * @tc.name testClassicStartBLEScan 705 * @tc.desc Test startBLEScan 401 - Invalid parameter. 706 * @tc.size MEDIUM 707 * @ since 7 708 * @tc.type Function 709 * @tc.level Level 0 710 */ 711 it('COMMUNICATION_BLUETOOTH_BLE_Scan_1900', 0, async function (done) { 712 try { 713 bluetooth.BLE.startBLEScan(123); 714 expect(true).assertFalse(); 715 bluetooth.BLE.stopBLEScan(); 716 done(); 717 } catch (error) { 718 console.error('[bluetooth_js]Scan_1900 error.code:'+JSON.stringify(error.code)+ 719 'error.message:'+JSON.stringify(error.message)); 720 expect(error.code).assertEqual('401'); 721 done() 722 } 723 }) 724 725 /** 726 * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_2000 727 * @tc.name testClassicStartBLEScan 728 * @tc.desc Test startBLEScan 401 - Invalid parameter. 729 * @tc.size MEDIUM 730 * @ since 7 731 * @tc.type Function 732 * @tc.level Level 0 733 */ 734 it('COMMUNICATION_BLUETOOTH_BLE_Scan_2000', 0, async function (done) { 735 try { 736 bluetooth.BLE.startBLEScan([{ 737 serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", 738 serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 739 }]); 740 bluetooth.BLE.stopBLEScan("test"); 741 expect(true).assertFalse(); 742 done(); 743 } catch (error) { 744 console.error('[bluetooth_js]Scan_2000 error.code:'+JSON.stringify(error.code)+ 745 'error.message:'+JSON.stringify(error.message)); 746 expect(error.code).assertEqual('401'); 747 done() 748 } 749 }) 750}) 751} 752 753