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 bluetoothManager from '@ohos.bluetoothManager'; 17import bluetooth from '@ohos.bluetooth'; 18import a2dp from '@ohos.bluetooth.a2dp'; 19import access from '@ohos.bluetooth.access'; 20import ble from '@ohos.bluetooth.ble'; 21import socket from '@ohos.bluetooth.socket'; 22import connection from '@ohos.bluetooth.connection'; 23import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Level, Size } from '@ohos/hypium'; 24import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest' 25 26let gattServer = null; 27let gattClient = null; 28let BleScanner = null; 29let closeUnsupport = false; 30function sleep(delay) { 31 return new Promise(resovle => setTimeout(resovle, delay)); 32} 33 34async function tryToDisableBt() { 35 let sta = bluetoothManager.getState(); 36 switch(sta){ 37 case 0: 38 console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); 39 break; 40 case 1: 41 console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); 42 bluetoothManager.disableBluetooth(); 43 await clickTheWindow(CLOSE_BT_TEXT); 44 await sleep(3000); 45 break; 46 case 2: 47 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 48 bluetoothManager.disableBluetooth(); 49 await clickTheWindow(CLOSE_BT_TEXT); 50 await sleep(3000); 51 break; 52 case 3: 53 console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); 54 await sleep(3000); 55 break; 56 default: 57 console.info('[bluetooth_js] enable success'); 58 } 59} 60 61async function tryToEnableBt() { 62 let sta = bluetoothManager.getState(); 63 switch(sta){ 64 case 0: 65 bluetoothManager.enableBluetooth(); 66 await clickTheWindow(OPEN_BT_TEXT); 67 let sta1 = bluetoothManager.getState(); 68 console.info('[bluetooth_js] bt turn off and enableBt:'+ JSON.stringify(sta1)); 69 break; 70 case 1: 71 console.info('[bluetooth_js] bt turning on and sleep 3s:'+ JSON.stringify(sta)); 72 await sleep(3000); 73 break; 74 case 2: 75 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 76 break; 77 case 3: 78 btAccess.enableBluetooth(); 79 await clickTheWindow(OPEN_BT_TEXT); 80 let sta2 = bluetoothManager.getState(); 81 console.info('[bluetooth_js] bt turning off and enableBt:'+ JSON.stringify(sta2)); 82 break; 83 default: 84 console.info('[bluetooth_js] state undefined'); 85 } 86 } 87 88async function openPhone() { 89 try{ 90 let drivers = Driver.create(); 91 console.info('[bluetooth_js] bt driver create:'+ drivers); 92 await drivers.delayMs(1000); 93 await drivers.wakeUpDisplay(); 94 await drivers.delayMs(5000); 95 await drivers.swipe(1500, 1000, 1500, 100); 96 await drivers.delayMs(10000); 97 } catch (error) { 98 console.info('[bluetooth_js] driver error info:'+ error); 99 } 100} 101 102let CLOSE_BT_TEXT = "关闭"; 103let OPEN_BT_TEXT = "开启"; 104 105async function clickTheWindow(text) { 106 console.info('[bluetooth_js] clickTheWindow start'); 107 let driver = Driver.create(); 108 await driver.delayMs(3000); 109 try { 110 let button = await driver.findComponent(ON.text(text)); 111 await button.click(); 112 await driver.delayMs(3000); 113 console.info('[bluetooth_js] click sucess'); 114 } catch (err) { 115 console.info('[bluetooth_js] click failed. ' + JSON.stringify(err)); 116 } 117} 118export default function btManagerError003Test() { 119 describe('btManagerError003Test', function() { 120 beforeAll(async function (done) { 121 console.info('beforeAll start'); 122 let PERMISSION_TEXT = "允许"; 123 await sleep(2000); 124 await openPhone(); 125 await clickTheWindow(PERMISSION_TEXT); 126 gattServer = ble.createGattServer(); 127 gattClient = ble.createGattClientDevice("11:22:33:44:55:66"); 128 BleScanner = ble.createBleScanner(); 129 console.info('beforeAll end'); 130 done(); 131 }) 132 beforeEach(async function(done) { 133 console.info('beforeEach start'); 134 try { 135 await tryToDisableBt(); 136 } catch (error) { 137 console.error('[bluetooth_js]tryToDisableBt get error:'+JSON.stringify(error)+ 'error.code = :'+JSON.stringify(error.code)); 138 if (Number(error.code) == 801) { 139 closeUnsupport = true; 140 } 141 } 142 console.info('beforeEach end'); 143 done(); 144 }) 145 afterEach(function () { 146 console.info('afterEach called') 147 }) 148 afterAll(async function (done) { 149 console.info('afterAll start') 150 try { 151 await tryToEnableBt(); 152 } catch (error) { 153 console.error('[bluetooth_js]tryToEnableBt get error:'+JSON.stringify(error)+ 'error.code = :'+JSON.stringify(error.code)); 154 } 155 console.info('afterAll end') 156 done(); 157 }) 158 159 /** 160 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0100 161 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0100 162 * @tc.desc Test 2900003 - Bluetooth switch is off. 163 * @tc.type Function 164 * @tc.size MediumTest 165 * @tc.level Level 2 166 */ 167 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 168 if (!closeUnsupport) { 169 await sleep(3000); 170 try { 171 let sta = bluetoothManager.getState(); 172 console.info('[bluetooth_js] bt getState:'+ JSON.stringify(sta)); 173 let connState = bluetoothManager.getBtConnectionState(); 174 console.info('[bluetooth_js] get bt connection state result' 175 + JSON.stringify(connState)); 176 expect(true).assertFalse(); 177 done(); 178 } catch (error) { 179 console.error('[bluetooth_js]getBtConnectionState error.code:' 180 +JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); 181 expect(Number(error.code)).assertEqual(2900003); 182 done() 183 } 184 } else { 185 expect(true).assertTrue(); 186 } 187 done(); 188 }) 189 190 /** 191 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0200 192 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0200 193 * @tc.desc Test 2900003 - Bluetooth switch is off 194 * @tc.type Function 195 * @tc.size MediumTest 196 * @tc.level Level 2 197 */ 198 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 199 if (!closeUnsupport) { 200 try { 201 bluetoothManager.pairDevice("11:22:55:66:33:44"); 202 expect(true).assertFalse(); 203 done() 204 } catch (error) { 205 console.error('[bluetooth_js]pairDevice error.code:'+JSON.stringify(error.code)+ 206 'error.message:'+JSON.stringify(error.message)); 207 expect(Number(error.code)).assertEqual(2900003); 208 done() 209 } 210 } else { 211 expect(true).assertTrue(); 212 } 213 done(); 214 }) 215 216 /** 217 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0300 218 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0300 219 * @tc.desc Test 2900003 - Bluetooth switch is off 220 * @tc.type Function 221 * @tc.size MediumTest 222 * @tc.level Level 3 223 */ 224 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 225 if (!closeUnsupport) { 226 try { 227 let ret = bluetoothManager.getRemoteDeviceName("00:00:00:00:00:00"); 228 console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret)); 229 expect(ret.length).assertEqual(0); 230 expect(true).assertFalse(); 231 done() 232 } catch (error) { 233 console.error('[bluetooth_js]getRemoteDeviceName error.code:'+JSON.stringify(error.code)+ 234 'error.message:'+JSON.stringify(error.message)); 235 expect(Number(error.code)).assertEqual(2900003); 236 done() 237 } 238 } else { 239 expect(true).assertTrue(); 240 } 241 done(); 242 }) 243 244 /** 245 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0400 246 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0400 247 * @tc.desc Test 2900003 - Bluetooth switch is off 248 * @tc.type Function 249 * @tc.size MediumTest 250 * @tc.level Level 3 251 */ 252 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 253 if (!closeUnsupport) { 254 try { 255 let DeviceClass = bluetoothManager.getRemoteDeviceClass("00:00:00:00:00:00"); 256 console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(DeviceClass) 257 + 'majorClass:' +DeviceClass.majorClass + 'majorMinorClass:'+ DeviceClass.majorMinorClass 258 + 'classOfDevice:' + DeviceClass.classOfDevice); 259 expect(true).assertFalse(); 260 done() 261 } catch (error) { 262 console.error('[bluetooth_js]getRemoteDeviceClass error.code:'+JSON.stringify(error.code)+ 263 'error.message:'+JSON.stringify(error.message)); 264 expect(Number(error.code)).assertEqual(2900003); 265 done() 266 } 267 } else { 268 expect(true).assertTrue(); 269 } 270 done(); 271 }) 272 273 /** 274 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0500 275 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0500 276 * @tc.desc Test 2900003 - Bluetooth switch is off 277 * @tc.type Function 278 * @tc.size MediumTest 279 * @tc.level Level 3 280 */ 281 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 282 if (!closeUnsupport) { 283 try { 284 let ret = bluetoothManager.getPairedDevices(); 285 console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret)); 286 expect(true).assertFalse(); 287 done() 288 } catch (error) { 289 console.error('[bluetooth_js]getPairedDevices error.code:'+JSON.stringify(error.code)+ 290 'error.message:'+JSON.stringify(error.message)); 291 expect(Number(error.code)).assertEqual(2900003); 292 done() 293 } 294 } else { 295 expect(true).assertTrue(); 296 } 297 done(); 298 }) 299 300 /** 301 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0600 302 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0600 303 * @tc.desc Test 2900003 - Bluetooth switch is off. 304 * @tc.type Function 305 * @tc.size MediumTest 306 * @tc.level Level 3 307 */ 308 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 309 if (!closeUnsupport) { 310 try { 311 let a2dpSrcConn = bluetoothManager.getProfileConnectionState(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE); 312 console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn)); 313 expect(true).assertFalse(); 314 done() 315 } catch (error) { 316 console.error('[bluetooth_js]getProfileConnState error.code:'+JSON.stringify(error.code)+ 317 'error.message:'+JSON.stringify(error.message)); 318 expect(Number(error.code)).assertEqual(2900003); 319 done() 320 } 321 } else { 322 expect(true).assertTrue(); 323 } 324 done(); 325 }) 326 327 /** 328 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0700 329 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0700 330 * @tc.desc Test 2900003 - Bluetooth switch is off 331 * @tc.type Function 332 * @tc.size MediumTest 333 * @tc.level Level 3 334 */ 335 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 336 if (!closeUnsupport) { 337 try { 338 bluetoothManager.setDevicePairingConfirmation("11:22:55:66:33:44",false); 339 expect(true).assertFalse(); 340 done() 341 } catch (error) { 342 console.error('[bluetooth_js]setDevicePairingConfirmation error.code:' 343 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 344 expect(Number(error.code)).assertEqual(2900003); 345 done() 346 } 347 } else { 348 expect(true).assertTrue(); 349 } 350 done(); 351 }) 352 353 /** 354 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0800 355 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0800 356 * @tc.desc Test 2900003 - Bluetooth switch is off. 357 * @tc.type Function 358 * @tc.size MediumTest 359 * @tc.level Level 2 360 */ 361 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 362 if (!closeUnsupport) { 363 try { 364 let newName = 'my bluetooth'; 365 bluetoothManager.setLocalName(newName); 366 expect(true).assertFalse(); 367 done() 368 } catch (error) { 369 console.error('[bluetooth_js]setLocalName error.code:' 370 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 371 expect(Number(error.code)).assertEqual(2900003); 372 done() 373 } 374 } else { 375 expect(true).assertTrue(); 376 } 377 done(); 378 }) 379 380 /** 381 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0900 382 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0900 383 * @tc.desc TEST 2900003 - Bluetooth switch is off. 384 * @tc.type Function 385 * @tc.size MediumTest 386 * @tc.level Level 2 387 */ 388 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 389 if (!closeUnsupport) { 390 try { 391 bluetoothManager.setBluetoothScanMode(bluetoothManager.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0); 392 expect(true).assertFalse(); 393 done() 394 } catch (error) { 395 console.error('[bluetooth_js]setBluetoothScanMode error.code:' 396 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 397 expect(Number(error.code)).assertEqual(2900003); 398 done() 399 } 400 } else { 401 expect(true).assertTrue(); 402 } 403 done(); 404 }) 405 406 /** 407 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1000 408 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1000 409 * @tc.desc TEST 2900003 - Bluetooth switch is off. 410 * @tc.type Function 411 * @tc.size MediumTest 412 * @tc.level Level 2 413 */ 414 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 415 if (!closeUnsupport) { 416 try { 417 let oldScanMode = bluetoothManager.getBluetoothScanMode(); 418 console.info('[bluetooth_js] getBluetoothScanMode = '+ JSON.stringify(oldScanMode)); 419 expect(true).assertFalse(); 420 done() 421 } catch (error) { 422 console.error('[bluetooth_js]getBluetoothScanMode error.code:' 423 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 424 expect(Number(error.code)).assertEqual(2900003); 425 done() 426 } 427 } else { 428 expect(true).assertTrue(); 429 } 430 done(); 431 }) 432 433 /** 434 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1100 435 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1100 436 * @tc.desc TEST 2900003 - Bluetooth switch is off. 437 * @tc.type Function 438 * @tc.size MediumTest 439 * @tc.level Level 2 440 */ 441 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 442 if (!closeUnsupport) { 443 try { 444 bluetoothManager.startBluetoothDiscovery(); 445 expect(true).assertFalse(); 446 done() 447 } catch (error) { 448 console.error('[bluetooth_js]startBluetoothDiscovery error.code:' 449 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 450 expect(Number(error.code)).assertEqual(2900003); 451 done() 452 } 453 } else { 454 expect(true).assertTrue(); 455 } 456 done(); 457 }) 458 459 /** 460 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1200 461 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1200 462 * @tc.desc TEST 2900003 - Bluetooth switch is off. 463 * @tc.type Function 464 * @tc.size MediumTest 465 * @tc.level Level 2 466 */ 467 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 468 if (!closeUnsupport) { 469 try { 470 bluetoothManager.stopBluetoothDiscovery(); 471 expect(true).assertFalse(); 472 done() 473 } catch (error) { 474 console.error('[bluetooth_js]stopBluetoothDiscovery error.code:' 475 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 476 expect(Number(error.code)).assertEqual(2900003); 477 done() 478 } 479 } else { 480 expect(true).assertTrue(); 481 } 482 done(); 483 }) 484 485 /** 486 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1600 487 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1600 488 * @tc.desc Test 2900003 - Bluetooth switch is off. 489 * @tc.type Function 490 * @tc.size MediumTest 491 * @tc.level Level 1 492 */ 493 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 494 if (!closeUnsupport) { 495 try { 496 let hfpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); 497 let retArray = hfpSrc.getConnectionDevices(); 498 console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); 499 expect(true).assertFalse(); 500 done() 501 } catch (error) { 502 console.error('[bluetooth_js]getConnectionDevices error.code:' 503 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 504 expect(Number(error.code)).assertEqual(2900003); 505 done() 506 } 507 } else { 508 expect(true).assertTrue(); 509 } 510 done(); 511 }) 512 513 /** 514 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1700 515 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1700 516 * @tc.desc Test 2900003 - Bluetooth switch is off. 517 * @tc.type Function 518 * @tc.size MediumTest 519 * @tc.level Level 1 520 */ 521 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 522 if (!closeUnsupport) { 523 try { 524 let hfpSrc = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); 525 let ret = hfpSrc.getDeviceState('11:22:33:44:55:66'); 526 console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret)); 527 expect(true).assertFalse(); 528 done() 529 } catch (error) { 530 console.error('[bluetooth_js]getDeviceState error.code:' 531 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 532 expect(Number(error.code)).assertEqual(2900003); 533 done() 534 } 535 } else { 536 expect(true).assertTrue(); 537 } 538 done(); 539 }) 540 541 /** 542 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1800 543 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1800 544 * @tc.desc Test 2900003 - Bluetooth switch is off. 545 * @tc.type Function 546 * @tc.size MediumTest 547 * @tc.level Level 1 548 */ 549 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 550 if (!closeUnsupport) { 551 try { 552 let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE); 553 a2dpSrc.connect('11:22:33:44:55:77'); 554 expect(true).assertFalse(); 555 done() 556 } catch (error) { 557 console.error('[bluetooth_js]A2DPconnect error.code:' 558 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 559 expect(Number(error.code)).assertEqual(2900003); 560 done() 561 } 562 } else { 563 expect(true).assertTrue(); 564 } 565 done(); 566 }) 567 568 569 /** 570 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1900 571 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1900 572 * @tc.desc Test 2900003 - Bluetooth switch is off. 573 * @tc.type Function 574 * @tc.size MediumTest 575 * @tc.level Level 3 576 */ 577 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 578 if (!closeUnsupport) { 579 try { 580 let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE); 581 a2dpSrc.disconnect('11:22:33:44:55:77'); 582 expect(true).assertFalse(); 583 done() 584 } catch (error) { 585 console.error('[bluetooth_js]A2DPdisconnect error.code:' 586 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 587 expect(Number(error.code)).assertEqual(2900003); 588 done() 589 } 590 } else { 591 expect(true).assertTrue(); 592 } 593 done(); 594 }) 595 596 /** 597 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2000 598 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2000 599 * @tc.desc Test 2900003 - Bluetooth switch is off. 600 * @tc.type Function 601 * @tc.size MediumTest 602 * @tc.level Level 3 603 */ 604 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 605 if (!closeUnsupport) { 606 try { 607 let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE); 608 console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); 609 let state = a2dpSrc.getPlayingState('11:22:33:44:55:66'); 610 console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state)); 611 expect(true).assertFalse(); 612 done() 613 } catch (error) { 614 console.error('[bluetooth_js]getPlayingState error.code:' 615 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 616 expect(Number(error.code)).assertEqual(2900003); 617 done() 618 } 619 } else { 620 expect(true).assertTrue(); 621 } 622 done(); 623 }) 624 625 /** 626 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2100 627 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2100 628 * @tc.desc Test 2900003 - Bluetooth switch is off. 629 * @tc.type Function 630 * @tc.size MediumTest 631 * @tc.level Level 1 632 */ 633 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 634 if (!closeUnsupport) { 635 try { 636 let hfpSrc = 637 bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); 638 hfpSrc.connect('11:22:33:44:55:77'); 639 expect(true).assertFalse(); 640 done() 641 } catch (error) { 642 console.error('[bluetooth_js]HFPconnect error.code:' 643 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 644 expect(Number(error.code)).assertEqual(2900003); 645 done() 646 } 647 } else { 648 expect(true).assertTrue(); 649 } 650 done(); 651 }) 652 653 /** 654 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2200 655 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2200 656 * @tc.desc Test 2900003 - Bluetooth switch is off. 657 * @tc.type Function 658 * @tc.size MediumTest 659 * @tc.level Level 3 660 */ 661 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 662 if (!closeUnsupport) { 663 try { 664 let hfpSrc = 665 bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); 666 hfpSrc.disconnect('11:22:33:44:55:77'); 667 expect(true).assertFalse(); 668 done() 669 } catch (error) { 670 console.error('[bluetooth_js]HFPdisconnect error.code:' 671 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 672 expect(Number(error.code)).assertEqual(2900003); 673 done() 674 } 675 } else { 676 expect(true).assertTrue(); 677 } 678 done(); 679 }) 680 681 /** 682 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2800 683 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2800 684 * @tc.desc Test 2900003 - Bluetooth switch is off. 685 * @tc.type Function 686 * @tc.size MediumTest 687 * @tc.level Level 2 688 */ 689 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 690 if (!closeUnsupport) { 691 try { 692 bluetoothManager.BLE.startBLEScan( 693 [{ 694 deviceId:"11:22:33:44:55:66", 695 name:"test", 696 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" 697 }], 698 { 699 interval: 500, 700 dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER, 701 matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE, 702 } 703 ); 704 expect(true).assertFalse(); 705 done() 706 } catch (error) { 707 console.error('[bluetooth_js]startBLEScan error.code:' 708 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 709 expect(Number(error.code)).assertEqual(2900003); 710 done() 711 } 712 } else { 713 expect(true).assertTrue(); 714 } 715 done(); 716 }) 717 718 /** 719 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2900 720 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2900 721 * @tc.desc Test 2900003 - Bluetooth switch is off. 722 * @tc.type Function 723 * @tc.size MediumTest 724 * @tc.level Level 2 725 */ 726 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 727 if (!closeUnsupport) { 728 try { 729 bluetoothManager.BLE.stopBLEScan(); 730 expect(true).assertFalse(); 731 done() 732 } catch (error) { 733 console.error('[bluetooth_js]startBLEScan error.code:' 734 +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); 735 expect(Number(error.code)).assertEqual(2900003); 736 done() 737 } 738 } else { 739 expect(true).assertTrue(); 740 } 741 done(); 742 }) 743 744 /** 745 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3000 746 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3000 747 * @tc.desc Test 2900003 - Bluetooth switch is off. 748 * @tc.type Function 749 * @tc.size MediumTest 750 * @tc.level Level 0 751 */ 752 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 753 let manufactureValueBuffer = new Uint8Array(4); 754 manufactureValueBuffer[0] = 1; 755 manufactureValueBuffer[1] = 2; 756 manufactureValueBuffer[2] = 3; 757 manufactureValueBuffer[3] = 4; 758 let serviceValueBuffer = new Uint8Array(4); 759 serviceValueBuffer[0] = 4; 760 serviceValueBuffer[1] = 6; 761 serviceValueBuffer[2] = 7; 762 serviceValueBuffer[3] = 8; 763 let setting={ 764 interval:32, 765 txPower:-10, 766 connectable:true, 767 } 768 let advData={ 769 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 770 manufactureData:[{ 771 manufactureId:4567, 772 manufactureValue:manufactureValueBuffer.buffer 773 }], 774 serviceData:[{ 775 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 776 serviceValue:serviceValueBuffer.buffer 777 }], 778 } 779 let advResponse ={ 780 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 781 manufactureData:[{ 782 manufactureId:1789, 783 manufactureValue:manufactureValueBuffer.buffer 784 }], 785 serviceData:[{ 786 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 787 serviceValue:serviceValueBuffer.buffer 788 }], 789 } 790 if (!closeUnsupport) { 791 try { 792 ble.startAdvertising(setting,advData,advResponse); 793 expect(true).assertFalse(); 794 }catch(error) { 795 console.error('[bluetooth_js]startAdvertising error.code:'+JSON.stringify(error.code)+ 796 'error.message:'+JSON.stringify(error.message)); 797 expect(Number(error.code)).assertEqual(2900003); 798 } 799 } else { 800 expect(true).assertTrue(); 801 } 802 await sleep(2000); 803 done(); 804 }) 805 806 /** 807 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3100 808 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3100 809 * @tc.desc Test 2900003 - Bluetooth switch is off. 810 * @tc.type Function 811 * @tc.size MediumTest 812 * @tc.level Level 0 813 */ 814 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 815 let manufactureValueBuffer = new Uint8Array(4); 816 manufactureValueBuffer[0] = 1; 817 manufactureValueBuffer[1] = 2; 818 manufactureValueBuffer[2] = 3; 819 manufactureValueBuffer[3] = 4; 820 let serviceValueBuffer = new Uint8Array(4); 821 serviceValueBuffer[0] = 4; 822 serviceValueBuffer[1] = 6; 823 serviceValueBuffer[2] = 7; 824 serviceValueBuffer[3] = 8; 825 let advData={ 826 serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], 827 manufactureData:[{ 828 manufactureId:4567, 829 manufactureValue:manufactureValueBuffer.buffer 830 }], 831 serviceData:[{ 832 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 833 serviceValue:serviceValueBuffer.buffer 834 }], 835 } 836 let advResponse ={ 837 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 838 manufactureData:[{ 839 manufactureId:1789, 840 manufactureValue:manufactureValueBuffer.buffer 841 }], 842 serviceData:[{ 843 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 844 serviceValue:serviceValueBuffer.buffer 845 }], 846 } 847 if (!closeUnsupport) { 848 try { 849 ble.stopAdvertising(); 850 expect(true).assertFalse(); 851 }catch(error) { 852 console.error('[bluetooth_js]stopAdvertising error.code:'+JSON.stringify(error.code)+ 853 'error.message:'+JSON.stringify(error.message)); 854 expect(Number(error.code)).assertEqual(2900003); 855 } 856 } else { 857 expect(true).assertTrue(); 858 } 859 done(); 860 }) 861 862 /** 863 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3200 864 * @tc.name SUB_COMMUNICATION_BTMANAGER_SwitchOff_3200 865 * @tc.desc Test 2900003 - Bluetooth switch is off. 866 * @tc.type Function 867 * @tc.size MediumTest 868 * @tc.level Level 2 869 */ 870 it('SUB_COMMUNICATION_BTMANAGER_SwitchOff_3200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 871 if (!closeUnsupport) { 872 try { 873 let descriptors = []; 874 let arrayBuffer = new ArrayBuffer(8); 875 let descV = new Uint8Array(arrayBuffer); 876 descV[0] = 11; 877 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 878 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 879 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 880 descriptors[0] = descriptor; 881 let characteristics = []; 882 let arrayBufferC = new ArrayBuffer(8); 883 let cccV = new Uint8Array(arrayBufferC); 884 cccV[0] = 1; 885 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 886 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 887 characteristicValue: arrayBufferC, descriptors:descriptors}; 888 characteristics[0] = characteristic; 889 let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, 890 characteristics:characteristics, includeServices:[]}; 891 gattServer.addService(gattService); 892 expect(true).assertFalse(); 893 done(); 894 } catch (error) { 895 console.error(`[bluetooth_js]AddService failed, code is ${error.code}, 896 message is ${error.message}`); 897 expect(Number(error.code)).assertEqual(2900003); 898 done() 899 } 900 } else { 901 expect(true).assertTrue(); 902 } 903 done(); 904 }) 905 906 /** 907 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3300 908 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3300 909 * @tc.desc Test 2900003 - Bluetooth switch is off. 910 * @tc.type Function 911 * @tc.size MediumTest 912 * @tc.level Level 2 913 */ 914 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 915 if (!closeUnsupport) { 916 try { 917 gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); 918 expect(true).assertFalse(); 919 done(); 920 } catch (error) { 921 console.error(`[bluetooth_js]removeService failed, code is ${error.code}, 922 message is ${error.message}`); 923 expect(Number(error.code)).assertEqual(401); 924 done() 925 } 926 } else { 927 expect(true).assertTrue(); 928 } 929 done(); 930 }) 931 932 /** 933 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3400 934 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3400 935 * @tc.desc Test 2900003 - Bluetooth switch is off. 936 * @tc.type Function 937 * @tc.size MediumTest 938 * @tc.level Level 3 939 */ 940 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 941 if (!closeUnsupport) { 942 try { 943 gattServer.close(); 944 expect(true).assertFalse(); 945 done(); 946 } catch (error) { 947 console.error(`[bluetooth_js]close failed, code is ${error.code}, 948 message is ${error.message}`); 949 expect(Number(error.code)).assertEqual(2900003); 950 done() 951 } 952 } else { 953 expect(true).assertTrue(); 954 } 955 done(); 956 }) 957 958 /** 959 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3600 960 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3600 961 * @tc.desc Test 2900003 - Bluetooth switch is off. 962 * @tc.type Function 963 * @tc.size MediumTest 964 * @tc.level Level 1 965 */ 966 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 967 if (!closeUnsupport) { 968 try { 969 let arrayBuffer = new ArrayBuffer(8); 970 let value = new Uint8Array(arrayBuffer); 971 value[0] = 1; 972 let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1, 973 status: 0, offset: 0, value: arrayBuffer}; 974 gattServer.sendResponse(ServerResponse); 975 expect(true).assertFalse(); 976 done(); 977 } catch (error) { 978 console.error(`[bluetooth_js]sendResponse failed, code is ${error.code}, 979 message is ${error.message}`); 980 expect(Number(error.code)).assertEqual(2900003); 981 done() 982 } 983 } else { 984 expect(true).assertTrue(); 985 } 986 done(); 987 }) 988 989 /** 990 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3700 991 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3700 992 * @tc.desc Test 2900003 - Bluetooth switch is off 993 * @tc.type Function 994 * @tc.size MediumTest 995 * @tc.level Level 3 996 */ 997 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 998 if (!closeUnsupport) { 999 try { 1000 gattClient.connect(); 1001 await sleep(2000); 1002 expect(true).assertFalse(); 1003 } catch(error) { 1004 console.error(`[bluetooth_js]connect failed, code is ${error.code}, 1005 message is ${error.message}`); 1006 expect(Number(error.code)).assertEqual(2900003); 1007 } 1008 } else { 1009 expect(true).assertTrue(); 1010 } 1011 done() 1012 }) 1013 1014 /** 1015 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3800 1016 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3800 1017 * @tc.desc Test 2900003 - Bluetooth switch is off 1018 * @tc.type Function 1019 * @tc.size MediumTest 1020 * @tc.level Level 3 1021 */ 1022 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1023 if (!closeUnsupport) { 1024 try { 1025 gattClient.disconnect(); 1026 expect(true).assertFalse(); 1027 } catch(error) { 1028 console.error(`[bluetooth_js]disconnect failed, code is ${error.code}, 1029 message is ${error.message}`); 1030 expect(Number(error.code)).assertEqual(2900003); 1031 } 1032 } else { 1033 expect(true).assertTrue(); 1034 } 1035 done() 1036 }) 1037 1038 /** 1039 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3900 1040 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3900 1041 * @tc.desc Test 2900003 - Bluetooth switch is off 1042 * @tc.type Function 1043 * @tc.size MediumTest 1044 * @tc.level Level 3 1045 */ 1046 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1047 if (!closeUnsupport) { 1048 try { 1049 gattClient.close(); 1050 expect(true).assertFalse(); 1051 } catch(error) { 1052 console.error(`[bluetooth_js]gattClient close failed, code is ${error.code}, 1053 message is ${error.message}`); 1054 expect(Number(error.code)).assertEqual(2900003); 1055 } 1056 } else { 1057 expect(true).assertTrue(); 1058 } 1059 done() 1060 }) 1061 1062 /** 1063 * @tc.number SUB_COMMUNICATION_BTMANAGER_BLESCAN_0800 1064 * @tc.name SUB_COMMUNICATION_BTMANAGER_BLESCAN_0800 1065 * @tc.desc Test ClassicStartBLEScan api. 1066 * @tc.type Function 1067 * @tc.size MediumTest 1068 * @tc.level Level 3 1069 */ 1070 it('SUB_COMMUNICATION_BTMANAGER_BLESCAN_0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1071 if (!closeUnsupport) { 1072 function onReceiveEvent(data) 1073 { 1074 console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data)); 1075 expect(data.length = 0).assertTrue(); 1076 } 1077 try { 1078 let state = bluetoothManager.getState(); 1079 console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state)); 1080 if(state == bluetoothManager.BluetoothState.STATE_ON) { 1081 let result2= bluetoothManager.disableBluetooth(); 1082 await clickTheWindow(CLOSE_BT_TEXT); 1083 console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2)); 1084 let state1 = bluetoothManager.getState(); 1085 console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1)); 1086 expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF); 1087 } 1088 console.info('[bluetooth_js] BLE BLEDeviceFind on start!'); 1089 bluetoothManager.BLE.on("BLEDeviceFind", onReceiveEvent) 1090 bluetoothManager.BLE.startBLEScan( 1091 [{}], 1092 { 1093 interval: 100, 1094 dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER, 1095 matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE, 1096 } 1097 ); 1098 await sleep(1000); 1099 console.info('[bluetooth_js] BLE scan off8'); 1100 bluetoothManager.BLE.stopBLEScan(); 1101 done(); 1102 } catch (error) { 1103 console.error('[bluetooth_js]Scan_0800 error.code:'+JSON.stringify(error.code)+ 1104 'error.message:'+JSON.stringify(error.message)); 1105 expect(Number(error.code)).assertEqual(2900003); 1106 } 1107 console.info('[bluetooth_js] BLE BLEDeviceFind off start!'); 1108 bluetoothManager.BLE.off('BLEDeviceFind', onReceiveEvent); 1109 } else { 1110 expect(true).assertTrue(); 1111 } 1112 await sleep(2000); 1113 done(); 1114 }) 1115 1116 /** 1117 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_4000 1118 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_4000 1119 * @tc.desc Test ClassicStartBLEScan api. 1120 * @tc.type Function 1121 * @tc.size MediumTest 1122 * @tc.level Level 3 1123 */ 1124 it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_4000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1125 if (!closeUnsupport) { 1126 bluetooth.disableBluetooth(); 1127 await clickTheWindow(CLOSE_BT_TEXT); 1128 await sleep(3000); 1129 let state = bluetooth.getState(); 1130 console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state)); 1131 function onReceiveEvent(data) 1132 { 1133 console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data)); 1134 expect(data.length == 0).assertTrue(); 1135 } 1136 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 1137 bluetooth.BLE.startBLEScan( 1138 [{}], 1139 { 1140 interval: 100, 1141 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 1142 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 1143 } 1144 ); 1145 await sleep(1000); 1146 console.info('[bluetooth_js] BLE scan off8'); 1147 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 1148 bluetooth.BLE.stopBLEScan(); 1149 } else { 1150 expect(true).assertTrue(); 1151 } 1152 done(); 1153 }) 1154 1155 /** 1156 * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCH_0400 1157 * @tc.name SUB_COMMUNICATION_BTMANAGER_SWITCH_0400 1158 * @tc.desc Test EnableBluetooth api by promise. 1159 * @tc.type Function 1160 * @tc.size MediumTest 1161 * @tc.level Level 3 1162 */ 1163 it('SUB_COMMUNICATION_BTMANAGER_SWITCH_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1164 if (!closeUnsupport) { 1165 let state = bluetooth.getState(); 1166 console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state)); 1167 if(state == bluetooth.BluetoothState.STATE_OFF) { 1168 let result2= bluetooth.disableBluetooth(); 1169 await clickTheWindow(CLOSE_BT_TEXT); 1170 console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2)); 1171 expect(result2).assertFalse(); 1172 let state1 = bluetooth.getState(); 1173 console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1)); 1174 expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF); 1175 } 1176 } else { 1177 expect(true).assertTrue(); 1178 } 1179 done(); 1180 }) 1181 1182 /** 1183 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_A2DP_0100 1184 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_A2DP_0100 1185 * @tc.desc test disable bt use api 1186 * @tc.type Function 1187 * @tc.size MediumTest 1188 * @tc.level Level 2 1189 */ 1190 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_A2DP_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1191 if (!closeUnsupport) { 1192 try { 1193 let a2dpProfile = a2dp.createA2dpSrcProfile(); 1194 let state = a2dpProfile.getPlayingState('11:22:33:44:55:66'); 1195 expect().assertFail(); 1196 } catch (err) { 1197 console.info("bluetooth a2dp getPlayingState errCode:" + err.code + ",bluetooth a2dp getPlayingState errMessage:" + err.message); 1198 expect(Number(err.code)).assertEqual(2900003); 1199 } 1200 } else { 1201 expect(true).assertTrue(); 1202 } 1203 done(); 1204 }) 1205 1206 /** 1207 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0100 1208 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0100 1209 * @tc.desc test disable bt use api 1210 * @tc.type Function 1211 * @tc.size MediumTest 1212 * @tc.level Level 2 1213 */ 1214 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1215 if (!closeUnsupport) { 1216 try { 1217 await access.addPersistentDeviceId('00:00:00:00:00:00').then(() => { 1218 console.info('[bluetooth_js] addPersistentDeviceId success'); 1219 }); 1220 expect().assertFail(); 1221 } catch (error) { 1222 console.info("addPersistentDeviceId errCode:" + error.code + ",errMessage:" + error.message); 1223 expect(Number(error.code)).assertEqual(2900003); 1224 } 1225 } else { 1226 expect(true).assertTrue(); 1227 } 1228 done(); 1229 }) 1230 1231 /** 1232 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0200 1233 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0200 1234 * @tc.desc test disable bt use api 1235 * @tc.type Function 1236 * @tc.size MediumTest 1237 * @tc.level Level 2 1238 */ 1239 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1240 if (!closeUnsupport) { 1241 try { 1242 await access.deletePersistentDeviceId('00:00:00:00:00:00').then(() => { 1243 console.info('[bluetooth_js] deletePersistentDeviceId success'); 1244 }); 1245 expect().assertFail(); 1246 } catch (error) { 1247 console.info("deletePersistentDeviceId errCode:" + error.code + ",errMessage:" + error.message); 1248 expect(Number(error.code)).assertEqual(2900003); 1249 } 1250 } else { 1251 expect(true).assertTrue(); 1252 } 1253 done(); 1254 }) 1255 1256 /** 1257 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0300 1258 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0300 1259 * @tc.desc test disable bt use api 1260 * @tc.type Function 1261 * @tc.size MediumTest 1262 * @tc.level Level 2 1263 */ 1264 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1265 if (!closeUnsupport) { 1266 try { 1267 let macs = access.getPersistentDeviceIds(); 1268 console.info("[bluetooth_js]getPersistentDeviceIds result:" + JSON.stringify(macs)); 1269 expect().assertFail(); 1270 } catch (error) { 1271 console.info("getPersistentDeviceIds errCode:" + error.code + ",errMessage:" + error.message); 1272 expect(Number(error.code)).assertEqual(2900003); 1273 } 1274 } else { 1275 expect(true).assertTrue(); 1276 } 1277 done(); 1278 }) 1279 1280 /** 1281 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0400 1282 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0400 1283 * @tc.desc test disable bt use api 1284 * @tc.type Function 1285 * @tc.size MediumTest 1286 * @tc.level Level 2 1287 */ 1288 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_ACCESS_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1289 if (!closeUnsupport) { 1290 try { 1291 let isValidRandom = access.isValidRandomDeviceId("00:00:00:00:00:00"); 1292 console.info("[bluetooth_js]isValidRandomDeviceId result:" + JSON.stringify(isValidRandom)); 1293 expect().assertFail(); 1294 } catch (error) { 1295 console.info("isValidRandomDeviceId errCode:" + error.code + ",errMessage:" + error.message); 1296 expect(Number(error.code)).assertEqual(2900003); 1297 } 1298 } else { 1299 expect(true).assertTrue(); 1300 } 1301 done(); 1302 }) 1303 1304 /** 1305 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0100 1306 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0100 1307 * @tc.desc test disable bt use api 1308 * @tc.type Function 1309 * @tc.size MediumTest 1310 * @tc.level Level 2 1311 */ 1312 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1313 if (!closeUnsupport) { 1314 try { 1315 let a2dpProfile = a2dp.createA2dpSrcProfile(); 1316 let devices = a2dpProfile.getConnectedDevices(); 1317 console.info("address of connected devices list:" + devices); 1318 expect().assertFail(); 1319 } catch (error) { 1320 console.info("getConnectedDevices errCode:" + error.code + ",errMessage:" + error.message); 1321 expect(Number(error.code)).assertEqual(2900003); 1322 } 1323 } else { 1324 expect(true).assertTrue(); 1325 } 1326 done(); 1327 }) 1328 1329 /** 1330 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0200 1331 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0200 1332 * @tc.desc test disable bt use api 1333 * @tc.type Function 1334 * @tc.size MediumTest 1335 * @tc.level Level 2 1336 */ 1337 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BASEPROFILE_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1338 if (!closeUnsupport) { 1339 try { 1340 let a2dpProfile = a2dp.createA2dpSrcProfile(); 1341 let state = a2dpProfile.getConnectionState("11:22:33:AA:BB:FF"); 1342 console.info("the connection state:" + state); 1343 expect().assertFail(); 1344 } catch (error) { 1345 console.info("getConnectionState errCode:" + error.code + ",errMessage:" + error.message); 1346 expect(Number(error.code)).assertEqual(2900003); 1347 } 1348 } else { 1349 expect(true).assertTrue(); 1350 } 1351 done(); 1352 }) 1353 1354 /** 1355 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0100 1356 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0100 1357 * @tc.desc test disable bt use api 1358 * @tc.type Function 1359 * @tc.size MediumTest 1360 * @tc.level Level 2 1361 */ 1362 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1363 if (!closeUnsupport) { 1364 try { 1365 let serverNumber = -1; 1366 let serverSocket = (code, number) => { 1367 if (code) { 1368 console.error('sppListen error, code is ' + code); 1369 return; 1370 } else { 1371 serverNumber = number; 1372 console.info('sppListen success, serverNumber = ' + serverNumber); 1373 } 1374 } 1375 let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0}; 1376 socket.sppListen('server1', sppOption, serverSocket); 1377 } catch (error) { 1378 console.info("sppListen errCode:" + error.code + ",errMessage:" + error.message); 1379 expect(Number(error.code)).assertEqual(2900003); 1380 } 1381 } else { 1382 expect(true).assertTrue(); 1383 } 1384 done(); 1385 }) 1386 1387 /** 1388 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0200 1389 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0200 1390 * @tc.desc test disable bt use api 1391 * @tc.type Function 1392 * @tc.size MediumTest 1393 * @tc.level Level 2 1394 */ 1395 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1396 function acceptClientSocket(code, number) { 1397 console.log('bluetooth error code: ' + code.code); 1398 let clientNumber = -1; 1399 if (code.code == 0) { 1400 console.log('bluetooth clientSocket Number: ' + number); 1401 clientNumber = number; 1402 expect(true).assertEqual(clientNumber != -1); 1403 } 1404 } 1405 let serverNumber = -1; 1406 if (!closeUnsupport) { 1407 try { 1408 socket.sppAccept(serverNumber, acceptClientSocket); 1409 } catch (error) { 1410 console.info("sppAccept errCode:" + error.code + ",errMessage:" + error.message); 1411 expect(true).assertEqual(Number(error.code) == 2900003 || Number(error.code) == 401); 1412 } 1413 } else { 1414 expect(true).assertTrue(); 1415 } 1416 done(); 1417 }) 1418 1419 /** 1420 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0300 1421 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0300 1422 * @tc.desc test disable bt use api 1423 * @tc.type Function 1424 * @tc.size MediumTest 1425 * @tc.level Level 2 1426 */ 1427 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_SOCKET_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1428 if (!closeUnsupport) { 1429 try { 1430 let clientSocket = (code, number) => { 1431 if (code) { 1432 console.error('sppListen error, code is ' + code); 1433 return; 1434 } else { 1435 console.info('bluetooth serverSocket Number: ' + number); 1436 } 1437 } 1438 let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0}; 1439 socket.sppConnect('00:11:22:33:44:55', sppOption, clientSocket); 1440 } catch (error) { 1441 console.info("sppConnect errCode:" + error.code + ",errMessage:" + error.message); 1442 expect(Number(error.code)).assertEqual(2900003); 1443 } 1444 } else { 1445 expect(true).assertTrue(); 1446 } 1447 done(); 1448 }) 1449 1450 /** 1451 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0100 1452 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0100 1453 * @tc.desc test disable bt use api 1454 * @tc.type Function 1455 * @tc.size MediumTest 1456 * @tc.level Level 2 1457 */ 1458 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1459 if (!closeUnsupport) { 1460 try { 1461 let connectionState = connection.getProfileConnectionState(); 1462 console.info("getProfileConnectionState result:" + connectionState); 1463 expect().assertFail(); 1464 } catch (error) { 1465 console.info("getProfileConnectionState errCode:" + error.code + ",errMessage:" + error.message); 1466 expect(Number(error.code)).assertEqual(2900003); 1467 } 1468 } else { 1469 expect(true).assertTrue(); 1470 } 1471 done(); 1472 }) 1473 1474 /** 1475 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0200 1476 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0200 1477 * @tc.desc test disable bt use api 1478 * @tc.type Function 1479 * @tc.size MediumTest 1480 * @tc.level Level 2 1481 */ 1482 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1483 if (!closeUnsupport) { 1484 try { 1485 function functionPairDevice() { 1486 return new Promise((resolve,reject) => { 1487 connection.pairDevice('11:22:33:44:55:66', (error) => { 1488 if (error) { 1489 console.info('pairDevice failed' + error); 1490 reject(error.code); 1491 } 1492 resolve(); 1493 }); 1494 }); 1495 } 1496 await functionPairDevice().then(() => { 1497 console.info("[bluetooth_js]functionPairDevice success"); 1498 expect(true).assertFalse(); 1499 done(); 1500 }) 1501 .catch(e => { 1502 console.info("[bluetooth_js]functionPairDevice failed" + e); 1503 expect(e).assertEqual(2900003); 1504 done(); 1505 }) 1506 } catch (e) { 1507 console.error(`pairDevice callback error, error code is: ${e.code}, error message is: ${e.message}`); 1508 } 1509 } else { 1510 expect(true).assertTrue(); 1511 } 1512 done(); 1513 }) 1514 1515 /** 1516 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0300 1517 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0300 1518 * @tc.desc test disable bt use api 1519 * @tc.type Function 1520 * @tc.size MediumTest 1521 * @tc.level Level 2 1522 */ 1523 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1524 if (!closeUnsupport) { 1525 try { 1526 await connection.pairDevice('11:22:33:44:55:66').then(() => { 1527 console.info('[bluetooth_js] pairDevice success'); 1528 }); 1529 expect(true).assertFalse(); 1530 } catch (e) { 1531 console.error( `pairDevice promise error, error code is: ${e.code}, error message is: ${e.message}`); 1532 expect(Number(e.code)).assertEqual(2900003); 1533 } 1534 } else { 1535 expect(true).assertTrue(); 1536 } 1537 done(); 1538 }) 1539 1540 /** 1541 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0400 1542 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0400 1543 * @tc.desc test disable bt use api 1544 * @tc.type Function 1545 * @tc.size MediumTest 1546 * @tc.level Level 2 1547 */ 1548 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1549 if (!closeUnsupport) { 1550 try { 1551 let ret = connection.getRemoteDeviceName("00:00:00:00:00:00"); 1552 expect(true).assertFalse(); 1553 } catch (e) { 1554 console.error( `getRemoteDeviceName error, error code is: ${e.code}, error message is: ${e.message}`); 1555 expect(Number(e.code)).assertEqual(2900003); 1556 } 1557 } else { 1558 expect(true).assertTrue(); 1559 } 1560 done(); 1561 }) 1562 1563 /** 1564 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0500 1565 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0500 1566 * @tc.desc test disable bt use api 1567 * @tc.type Function 1568 * @tc.size MediumTest 1569 * @tc.level Level 2 1570 */ 1571 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1572 if (!closeUnsupport) { 1573 try { 1574 let ret = connection.getRemoteDeviceName("00:00:00:00:00:00", true); 1575 expect(true).assertFalse(); 1576 } catch (e) { 1577 console.error( `testGetRemoteDeviceName use alias error, error code is: ${e.code}, error message is: ${e.message}`); 1578 expect(Number(e.code)).assertEqual(2900003); 1579 } 1580 } else { 1581 expect(true).assertTrue(); 1582 } 1583 done(); 1584 }) 1585 1586 /** 1587 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0600 1588 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0600 1589 * @tc.desc test disable bt use api 1590 * @tc.type Function 1591 * @tc.size MediumTest 1592 * @tc.level Level 2 1593 */ 1594 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1595 if (!closeUnsupport) { 1596 try { 1597 let DeviceClass = connection.getRemoteDeviceClass("00:11:22:33:44:55"); 1598 except().assertFail(); 1599 } catch (e) { 1600 console.error( `getRemoteDeviceClass error, error code is: ${e.code}, error message is: ${e.message}`); 1601 expect(Number(e.code)).assertEqual(2900003); 1602 } 1603 } else { 1604 expect(true).assertTrue(); 1605 } 1606 done(); 1607 }) 1608 1609 /** 1610 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0700 1611 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0700 1612 * @tc.desc test disable bt use api 1613 * @tc.type Function 1614 * @tc.size MediumTest 1615 * @tc.level Level 2 1616 */ 1617 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1618 if (!closeUnsupport) { 1619 try { 1620 let ret = connection.getPairedDevices(); 1621 except().assertFail(); 1622 } catch (e) { 1623 console.error( `getPairedDevices error, error code is: ${e.code}, error message is: ${e.message}`); 1624 expect(Number(e.code)).assertEqual(2900003); 1625 } 1626 } else { 1627 expect(true).assertTrue(); 1628 } 1629 done(); 1630 }) 1631 1632 /** 1633 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0800 1634 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0800 1635 * @tc.desc test disable bt use api 1636 * @tc.type Function 1637 * @tc.size MediumTest 1638 * @tc.level Level 2 1639 */ 1640 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1641 if (!closeUnsupport) { 1642 try { 1643 let state = connection.getPairState("00:11:22:33:44:55"); 1644 } catch (e) { 1645 console.error( `getPairState error, error code is: ${e.code}, error message is: ${e.message}`); 1646 expect(Number(e.code)).assertEqual(2900003); 1647 } 1648 } else { 1649 expect(true).assertTrue(); 1650 } 1651 done(); 1652 }) 1653 1654 /** 1655 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0900 1656 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0900 1657 * @tc.desc test disable bt use api 1658 * @tc.type Function 1659 * @tc.size MediumTest 1660 * @tc.level Level 2 1661 */ 1662 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1663 if (!closeUnsupport) { 1664 try { 1665 connection.setDevicePairingConfirmation("00:11:22:33:44:55", true); 1666 except().assertFail(); 1667 } catch (e) { 1668 console.error( `setDevicePairingConfirmation error, error code is: ${e.code}, error message is: ${e.message}`); 1669 expect(Number(e.code)).assertEqual(2900003); 1670 } 1671 } else { 1672 expect(true).assertTrue(); 1673 } 1674 done(); 1675 }) 1676 1677 /** 1678 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1000 1679 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1000 1680 * @tc.desc test disable bt use api 1681 * @tc.type Function 1682 * @tc.size MediumTest 1683 * @tc.level Level 2 1684 */ 1685 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1686 if (!closeUnsupport) { 1687 try { 1688 function functionSetDevicePinCode() { 1689 return new Promise((resolve,reject) => { 1690 connection.setDevicePinCode('11:22:33:44:55:66', '12345', (error) => { 1691 if (error) { 1692 console.info('setDevicePinCode failed' + error); 1693 reject(error.code); 1694 } 1695 resolve(); 1696 }); 1697 }); 1698 } 1699 await functionSetDevicePinCode().then(() => { 1700 console.info("[bluetooth_js]setDevicePinCode success"); 1701 expect(true).assertFalse(); 1702 done(); 1703 }) 1704 .catch(e => { 1705 console.info("[bluetooth_js]setDevicePinCode failed" + e); 1706 expect(true).assertEqual(Number(e) == 2900003 || Number(e) == 2900099); 1707 done(); 1708 }) 1709 } catch (e) { 1710 console.error(`setDevicePinCode callback error, error code is: ${e.code}, error message is: ${e.message}`); 1711 } 1712 } else { 1713 expect(true).assertTrue(); 1714 } 1715 done(); 1716 }) 1717 1718 /** 1719 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1100 1720 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1100 1721 * @tc.desc test disable bt use api 1722 * @tc.type Function 1723 * @tc.size MediumTest 1724 * @tc.level Level 2 1725 */ 1726 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1727 if (!closeUnsupport) { 1728 try { 1729 await connection.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => { 1730 console.info('[bluetooth_js] setDevicePinCode success'); 1731 }); 1732 expect(true).assertFalse(); 1733 } catch (e) { 1734 console.error( `setDevicePinCode promise error, error code is: ${e.code}, error message is: ${e.message}`); 1735 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 2900099); 1736 } 1737 } else { 1738 expect(true).assertTrue(); 1739 } 1740 done(); 1741 }) 1742 1743 /** 1744 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1200 1745 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1200 1746 * @tc.desc test disable bt use api 1747 * @tc.type Function 1748 * @tc.size MediumTest 1749 * @tc.level Level 2 1750 */ 1751 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1752 if (!closeUnsupport) { 1753 try { 1754 connection.setBluetoothScanMode(-1, 0); 1755 expect(true).assertFalse(); 1756 } catch (e) { 1757 console.error( `setBluetoothScanMode error, error code is: ${e.code}, error message is: ${e.message}`); 1758 expect(Number(e.code)).assertEqual(2900003); 1759 } 1760 } else { 1761 expect(true).assertTrue(); 1762 } 1763 done(); 1764 }) 1765 1766 /** 1767 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1300 1768 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1300 1769 * @tc.desc test disable bt use api 1770 * @tc.type Function 1771 * @tc.size MediumTest 1772 * @tc.level Level 2 1773 */ 1774 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1775 if (!closeUnsupport) { 1776 try { 1777 let scanMode = connection.getBluetoothScanMode(); 1778 expect(true).assertFalse(); 1779 } catch (e) { 1780 console.error( `getBluetoothScanMode error, error code is: ${e.code}, error message is: ${e.message}`); 1781 expect(Number(e.code)).assertEqual(2900003); 1782 } 1783 } else { 1784 expect(true).assertTrue(); 1785 } 1786 done(); 1787 }) 1788 /** 1789 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1400 1790 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1400 1791 * @tc.desc test disable bt use api 1792 * @tc.type Function 1793 * @tc.size MediumTest 1794 * @tc.level Level 2 1795 */ 1796 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1797 if (!closeUnsupport) { 1798 try { 1799 connection.startBluetoothDiscovery(); 1800 expect(true).assertFalse(); 1801 } catch (e) { 1802 console.error( `startBluetoothDiscovery error, error code is: ${e.code}, error message is: ${e.message}`); 1803 expect(Number(e.code)).assertEqual(2900003); 1804 } 1805 } else { 1806 expect(true).assertTrue(); 1807 } 1808 done(); 1809 }) 1810 /** 1811 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1500 1812 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1500 1813 * @tc.desc test disable bt use api 1814 * @tc.type Function 1815 * @tc.size MediumTest 1816 * @tc.level Level 2 1817 */ 1818 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1819 if (!closeUnsupport) { 1820 try { 1821 connection.stopBluetoothDiscovery(); 1822 expect(true).assertFalse(); 1823 } catch (e) { 1824 console.error( `stopBluetoothDiscovery error, error code is: ${e.code}, error message is: ${e.message}`); 1825 expect(Number(e.code)).assertEqual(2900003); 1826 } 1827 } else { 1828 expect(true).assertTrue(); 1829 } 1830 done(); 1831 }) 1832 /** 1833 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1600 1834 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1600 1835 * @tc.desc test disable bt use api 1836 * @tc.type Function 1837 * @tc.size MediumTest 1838 * @tc.level Level 2 1839 */ 1840 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1841 if (!closeUnsupport) { 1842 try { 1843 let result = connection.isBluetoothDiscovering(); 1844 expect(true).assertFalse(); 1845 } catch (e) { 1846 console.error( `isBluetoothDiscovering error, error code is: ${e.code}, error message is: ${e.message}`); 1847 expect(Number(e.code)).assertEqual(2900003); 1848 } 1849 } else { 1850 expect(true).assertTrue(); 1851 } 1852 done(); 1853 }) 1854 1855 /** 1856 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1700 1857 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1700 1858 * @tc.desc test disable bt use api 1859 * @tc.type Function 1860 * @tc.size MediumTest 1861 * @tc.level Level 2 1862 */ 1863 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1864 if (!closeUnsupport) { 1865 try { 1866 function functionGetRemoteProfileUuids() { 1867 return new Promise((resolve,reject) => { 1868 connection.getRemoteProfileUuids('11:22:33:44:55:66', (error) => { 1869 if (error) { 1870 console.info('getRemoteProfileUuids failed' + error); 1871 reject(error.code); 1872 } 1873 resolve(); 1874 }); 1875 }); 1876 } 1877 await functionGetRemoteProfileUuids().then(() => { 1878 console.info("[bluetooth_js]getRemoteProfileUuids success"); 1879 expect(true).assertFalse(); 1880 done(); 1881 }) 1882 .catch(e => { 1883 console.info("[bluetooth_js]getRemoteProfileUuids failed" + e); 1884 expect(e).assertEqual(2900003); 1885 done(); 1886 }) 1887 } catch (e) { 1888 console.error(`getRemoteProfileUuids callback error, error code is: ${e.code}, error message is: ${e.message}`); 1889 } 1890 } else { 1891 expect(true).assertTrue(); 1892 } 1893 done(); 1894 }) 1895 1896 /** 1897 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1800 1898 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1800 1899 * @tc.desc test disable bt use api 1900 * @tc.type Function 1901 * @tc.size MediumTest 1902 * @tc.level Level 2 1903 */ 1904 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1905 if (!closeUnsupport) { 1906 try { 1907 await connection.getRemoteProfileUuids('11:22:33:44:55:66').then(() => { 1908 console.info('[bluetooth_js] getRemoteProfileUuids success'); 1909 }); 1910 expect(true).assertFalse(); 1911 } catch (e) { 1912 console.error( `getRemoteProfileUuids promise error, error code is: ${e.code}, error message is: ${e.message}`); 1913 expect(Number(e.code)).assertEqual(2900003); 1914 } 1915 } else { 1916 expect(true).assertTrue(); 1917 } 1918 done(); 1919 }) 1920 1921 /** 1922 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1900 1923 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1900 1924 * @tc.desc test disable bt use api 1925 * @tc.type Function 1926 * @tc.size MediumTest 1927 * @tc.level Level 2 1928 */ 1929 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1930 if (!closeUnsupport) { 1931 try { 1932 function functionConnectAllowedProfiles() { 1933 return new Promise((resolve,reject) => { 1934 connection.connectAllowedProfiles('11:22:33:44:55:66', (error) => { 1935 if (error) { 1936 console.info('connectAllowedProfiles failed' + error); 1937 reject(error.code); 1938 } 1939 resolve(); 1940 }); 1941 }); 1942 } 1943 await functionConnectAllowedProfiles().then(() => { 1944 console.info("[bluetooth_js]connectAllowedProfiles success"); 1945 expect(true).assertFalse(); 1946 done(); 1947 }) 1948 .catch(e => { 1949 console.info("[bluetooth_js]connectAllowedProfiles failed" + e); 1950 expect(e).assertEqual(2900003); 1951 done(); 1952 }) 1953 } catch (e) { 1954 console.error(`connectAllowedProfiles callback error, error code is: ${e.code}, error message is: ${e.message}`); 1955 } 1956 } else { 1957 expect(true).assertTrue(); 1958 } 1959 done(); 1960 }) 1961 1962 /** 1963 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2000 1964 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2000 1965 * @tc.desc test disable bt use api 1966 * @tc.type Function 1967 * @tc.size MediumTest 1968 * @tc.level Level 2 1969 */ 1970 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1971 if (!closeUnsupport) { 1972 try { 1973 await connection.connectAllowedProfiles('11:22:33:44:55:66').then(() => { 1974 console.info('[bluetooth_js] connectAllowedProfiles success'); 1975 }); 1976 expect(true).assertFalse(); 1977 } catch (e) { 1978 console.error( `connectAllowedProfiles promise error, error code is: ${e.code}, error message is: ${e.message}`); 1979 expect(Number(e.code)).assertEqual(2900003); 1980 } 1981 } else { 1982 expect(true).assertTrue(); 1983 } 1984 done(); 1985 }) 1986 1987 /** 1988 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2100 1989 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2100 1990 * @tc.desc test disable bt use api 1991 * @tc.type Function 1992 * @tc.size MediumTest 1993 * @tc.level Level 2 1994 */ 1995 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1996 if (!closeUnsupport) { 1997 try { 1998 await connection.getRemoteDeviceBatteryInfo('11:22:33:44:55:66').then(() => { 1999 console.info('[bluetooth_js] getRemoteDeviceBatteryInfo success'); 2000 }); 2001 expect(true).assertFalse(); 2002 } catch (e) { 2003 console.error( `getRemoteDeviceBatteryInfo error, error code is: ${e.code}, error message is: ${e.message}`); 2004 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 2900099); 2005 } 2006 } else { 2007 expect(true).assertTrue(); 2008 } 2009 done(); 2010 }) 2011 2012 /** 2013 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2200 2014 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2200 2015 * @tc.desc test disable bt use api 2016 * @tc.type Function 2017 * @tc.size MediumTest 2018 * @tc.level Level 2 2019 */ 2020 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2021 if (!closeUnsupport) { 2022 try { 2023 await connection.setRemoteDeviceName('11:22:33:44:55:66', 'RemoteDeviceName').then(() => { 2024 console.info('[bluetooth_js] setRemoteDeviceName success'); 2025 }); 2026 expect(true).assertFalse(); 2027 } catch (e) { 2028 console.error( `setRemoteDeviceName error, error code is: ${e.code}, error message is: ${e.message}`); 2029 expect(Number(e.code)).assertEqual(2900003); 2030 } 2031 } else { 2032 expect(true).assertTrue(); 2033 } 2034 done(); 2035 }) 2036 2037 /** 2038 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2300 2039 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2300 2040 * @tc.desc test disable bt use api 2041 * @tc.type Function 2042 * @tc.size MediumTest 2043 * @tc.level Level 2 2044 */ 2045 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_CONNECTION_2300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2046 if (!closeUnsupport) { 2047 try { 2048 await connection.getLastConnectionTime('54:71:DD:5F:75:06').then((time) => { 2049 console.info('[bluetooth_js] getLastConnectionTime success'); 2050 }); 2051 expect(true).assertFalse(); 2052 } catch (e) { 2053 console.error( `getLastConnectionTime error, error code is: ${e.code}, error message is: ${e.message}`); 2054 expect(Number(e.code)).assertEqual(2900003); 2055 } 2056 } else { 2057 expect(true).assertTrue(); 2058 } 2059 done(); 2060 }) 2061 2062 /** 2063 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0100 2064 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0100 2065 * @tc.desc test disable bt use api 2066 * @tc.type Function 2067 * @tc.size MediumTest 2068 * @tc.level Level 2 2069 */ 2070 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2071 if (!closeUnsupport) { 2072 try { 2073 let result = ble.getConnectedBLEDevices(); 2074 } catch (e) { 2075 console.error( `getConnectedBLEDevices error, error code is: ${e.code}, error message is: ${e.message}`); 2076 expect(Number(e.code)).assertEqual(2900003); 2077 } 2078 } else { 2079 expect(true).assertTrue(); 2080 } 2081 done(); 2082 }) 2083 2084 /** 2085 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0200 2086 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0200 2087 * @tc.desc test disable bt use api 2088 * @tc.type Function 2089 * @tc.size MediumTest 2090 * @tc.level Level 2 2091 */ 2092 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2093 if (!closeUnsupport) { 2094 try { 2095 ble.startBLEScan([{}]); 2096 expect(true).assertFalse(); 2097 } catch (e) { 2098 console.error( `startBLEScan error, error code is: ${e.code}, error message is: ${e.message}`); 2099 expect(Number(e.code)).assertEqual(2900003); 2100 } 2101 } else { 2102 expect(true).assertTrue(); 2103 } 2104 done(); 2105 }) 2106 2107 /** 2108 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0300 2109 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0300 2110 * @tc.desc test disable bt use api 2111 * @tc.type Function 2112 * @tc.size MediumTest 2113 * @tc.level Level 2 2114 */ 2115 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2116 if (!closeUnsupport) { 2117 try { 2118 ble.stopBLEScan(); 2119 expect(true).assertFalse(); 2120 } catch (e) { 2121 console.error( `stopBLEScan error, error code is: ${e.code}, error message is: ${e.message}`); 2122 expect(Number(e.code)).assertEqual(2900003); 2123 } 2124 } else { 2125 expect(true).assertTrue(); 2126 } 2127 done(); 2128 }) 2129 2130 /** 2131 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0400 2132 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0400 2133 * @tc.desc test disable bt use api 2134 * @tc.type Function 2135 * @tc.size MediumTest 2136 * @tc.level Level 2 2137 */ 2138 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2139 let manufactureValueBuffer = new Uint8Array(4); 2140 manufactureValueBuffer[0] = 1; 2141 manufactureValueBuffer[1] = 2; 2142 manufactureValueBuffer[2] = 3; 2143 manufactureValueBuffer[3] = 4; 2144 let serviceValueBuffer = new Uint8Array(4); 2145 serviceValueBuffer[0] = 4; 2146 serviceValueBuffer[1] = 6; 2147 serviceValueBuffer[2] = 7; 2148 serviceValueBuffer[3] = 8; 2149 let setting = { 2150 interval:32, 2151 txPower:1, 2152 connectable:true, 2153 } 2154 let manufactureDataUnit1 = { 2155 manufactureId:4567, 2156 manufactureValue:manufactureValueBuffer.buffer 2157 }; 2158 let advData = { 2159 serviceUuids : ["00001888-0000-1000-8000-00805f9b34fb"], 2160 manufactureData : [manufactureDataUnit1], 2161 serviceData:[{ 2162 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", 2163 serviceValue:serviceValueBuffer.buffer 2164 }], 2165 includeDeviceName:false 2166 } 2167 let manufactureDataUnit2 = { 2168 manufactureId:1789, 2169 manufactureValue:manufactureValueBuffer.buffer 2170 } 2171 let serviceDataUnit = { 2172 serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", 2173 serviceValue:serviceValueBuffer.buffer 2174 } 2175 let advResponse = { 2176 serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], 2177 manufactureData : [manufactureDataUnit2], 2178 serviceData : [serviceDataUnit], 2179 } 2180 if (!closeUnsupport) { 2181 try { 2182 ble.startAdvertising(setting, advData, advResponse); 2183 expect(true).assertFalse(); 2184 } catch (e) { 2185 console.error( `startAdvertising error, error code is: ${e.code}, error message is: ${e.message}`); 2186 expect(Number(e.code)).assertEqual(2900003); 2187 } 2188 } else { 2189 expect(true).assertTrue(); 2190 } 2191 done(); 2192 }) 2193 2194 /** 2195 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0500 2196 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0500 2197 * @tc.desc test disable bt use api 2198 * @tc.type Function 2199 * @tc.size MediumTest 2200 * @tc.level Level 2 2201 */ 2202 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2203 if (!closeUnsupport) { 2204 try { 2205 ble.stopAdvertising(); 2206 expect(true).assertFalse(); 2207 } catch (e) { 2208 console.error( `stopAdvertising error, error code is: ${e.code}, error message is: ${e.message}`); 2209 expect(Number(e.code)).assertEqual(2900003); 2210 } 2211 } else { 2212 expect(true).assertTrue(); 2213 } 2214 done(); 2215 }) 2216 2217 /** 2218 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0600 2219 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0600 2220 * @tc.desc test disable bt use api 2221 * @tc.type Function 2222 * @tc.size MediumTest 2223 * @tc.level Level 2 2224 */ 2225 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2226 if (!closeUnsupport) { 2227 try { 2228 await ble.disableAdvertising(0).then((data) => { 2229 console.info('[bluetooth_js] disableAdvertising promise success:' + JSON.stringify(data)); 2230 }); 2231 expect(true).assertFalse(); 2232 } catch (e) { 2233 console.error( `disableAdvertising error, error code is: ${e.code}, error message is: ${e.message}`); 2234 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 401); 2235 } 2236 } else { 2237 expect(true).assertTrue(); 2238 } 2239 done(); 2240 }) 2241 2242 /** 2243 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0700 2244 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0700 2245 * @tc.desc test disable bt use api 2246 * @tc.type Function 2247 * @tc.size MediumTest 2248 * @tc.level Level 2 2249 */ 2250 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2251 if (!closeUnsupport) { 2252 try { 2253 function functionDisableAdvertising() { 2254 return new Promise((resolve,reject) => { 2255 ble.disableAdvertising(0, (error) => { 2256 if (error) { 2257 console.info('disableAdvertising failed' + error); 2258 reject(error.code); 2259 } 2260 resolve(); 2261 }); 2262 }); 2263 } 2264 await functionDisableAdvertising().then(() => { 2265 console.info("[bluetooth_js]disableAdvertising success"); 2266 }); 2267 expect(true).assertFalse(); 2268 } catch (e) { 2269 console.error( `disableAdvertising error, error code is: ${e.code}, error message is: ${e.message}`); 2270 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 401); 2271 } 2272 } else { 2273 expect(true).assertTrue(); 2274 } 2275 done(); 2276 }) 2277 2278 /** 2279 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0800 2280 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0800 2281 * @tc.desc test disable bt use api 2282 * @tc.type Function 2283 * @tc.size MediumTest 2284 * @tc.level Level 2 2285 */ 2286 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2287 if (!closeUnsupport) { 2288 try { 2289 function functionStopAdvertising() { 2290 return new Promise((resolve,reject) => { 2291 ble.stopAdvertising(0, (error) => { 2292 if (error) { 2293 console.info('stopAdvertising failed' + error); 2294 reject(error.code); 2295 } 2296 resolve(); 2297 }); 2298 }); 2299 } 2300 await functionStopAdvertising().then(() => { 2301 console.info("[bluetooth_js]stopAdvertising success"); 2302 expect(true).assertFalse(); 2303 done(); 2304 }) 2305 .catch(e => { 2306 console.info("[bluetooth_js]stopAdvertising failed" + e); 2307 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 401); 2308 }) 2309 } catch (e) { 2310 console.error(`stopAdvertising callback error, error code is: ${e.code}, error message is: ${e.message}`); 2311 } 2312 } else { 2313 expect(true).assertTrue(); 2314 } 2315 done(); 2316 }) 2317 2318 /** 2319 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0900 2320 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0900 2321 * @tc.desc test disable bt use api 2322 * @tc.type Function 2323 * @tc.size MediumTest 2324 * @tc.level Level 2 2325 */ 2326 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2327 if (!closeUnsupport) { 2328 try { 2329 await ble.stopAdvertising(0).then(() => { 2330 console.info('[bluetooth_js] stopAdvertising success'); 2331 }); 2332 expect(true).assertFalse(); 2333 } catch (e) { 2334 console.error( `stopAdvertising promise error, error code is: ${e.code}, error message is: ${e.message}`); 2335 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 401); 2336 } 2337 } else { 2338 expect(true).assertTrue(); 2339 } 2340 done(); 2341 }) 2342 2343 /** 2344 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1000 2345 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1000 2346 * @tc.desc test disable bt use api 2347 * @tc.type Function 2348 * @tc.size MediumTest 2349 * @tc.level Level 2 2350 */ 2351 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2352 let descriptors = []; 2353 let arrayBuffer = new ArrayBuffer(8); 2354 let descV = new Uint8Array(arrayBuffer); 2355 descV[0] = 11; 2356 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2357 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 2358 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 2359 descriptors[0] = descriptor; 2360 let arrayBufferC = new ArrayBuffer(8); 2361 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2362 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 2363 let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2364 characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false}; 2365 if (!closeUnsupport) { 2366 try { 2367 function functionNotifyCharacteristicChanged() { 2368 return new Promise((resolve,reject) => { 2369 gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic, (error) => { 2370 if (error) { 2371 console.info('notifyCharacteristicChanged failed' + error); 2372 reject(error.code); 2373 } 2374 resolve(); 2375 }); 2376 }); 2377 } 2378 await functionNotifyCharacteristicChanged().then(() => { 2379 console.info("[bluetooth_js]notifyCharacteristicChanged success"); 2380 expect(true).assertFalse(); 2381 done(); 2382 }) 2383 .catch(e => { 2384 console.info("[bluetooth_js]notifyCharacteristicChanged failed" + e); 2385 expect(true).assertEqual(Number(e) == 2900003 || Number(e) == 2900099); 2386 done(); 2387 }) 2388 } catch (e) { 2389 console.error(`notifyCharacteristicChanged callback error, error code is: ${e.code}, error message is: ${e.message}`); 2390 } 2391 } else { 2392 expect(true).assertTrue(); 2393 } 2394 done(); 2395 }) 2396 2397 /** 2398 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1100 2399 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1100 2400 * @tc.desc test disable bt use api 2401 * @tc.type Function 2402 * @tc.size MediumTest 2403 * @tc.level Level 2 2404 */ 2405 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2406 let descriptors = []; 2407 let arrayBuffer = new ArrayBuffer(8); 2408 let descV = new Uint8Array(arrayBuffer); 2409 descV[0] = 11; 2410 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2411 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', 2412 descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; 2413 descriptors[0] = descriptor; 2414 let arrayBufferC = new ArrayBuffer(8); 2415 let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2416 characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; 2417 let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', 2418 characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false}; 2419 if (!closeUnsupport) { 2420 try { 2421 await gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic).then(() => { 2422 console.info('[bluetooth_js] notifyCharacteristicChanged success'); 2423 }); 2424 expect(true).assertFalse(); 2425 } catch (e) { 2426 console.error( `notifyCharacteristicChanged promise error, error code is: ${e.code}, error message is: ${e.message}`); 2427 expect(true).assertEqual(Number(e.code) == 2900003 || Number(e.code) == 2900099); 2428 } 2429 } else { 2430 expect(true).assertTrue(); 2431 } 2432 done(); 2433 }) 2434 2435 /** 2436 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1200 2437 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1200 2438 * @tc.desc test disable bt use api 2439 * @tc.type Function 2440 * @tc.size MediumTest 2441 * @tc.level Level 2 2442 */ 2443 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2444 let arrayBuffer = new ArrayBuffer(8); 2445 let scanFilter = { 2446 deviceId: "00:11:22:33:44:55", 2447 name: "testStartScan", 2448 serviceUuid: "00001888-0000-1000-8000-00805f9b34fb", 2449 serviceUuidMask: "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 2450 serviceSolicitationUuid: "00001888-0000-1000-8000-00805F9B34FB", 2451 serviceSolicitationUuidMask: "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 2452 serviceData: arrayBuffer, 2453 serviceDataMask: arrayBuffer, 2454 manufactureId: 4567, 2455 manufactureData: arrayBuffer, 2456 manufactureDataMask: arrayBuffer 2457 }; 2458 if (!closeUnsupport) { 2459 try { 2460 await BleScanner.startScan([scanFilter]).then(() => { 2461 console.info('[bluetooth_js] bleScanner startScan success'); 2462 }); 2463 expect(true).assertFalse(); 2464 } catch (e) { 2465 console.error( `bleScanner startScan promise error, error code is: ${e.code}, error message is: ${e.message}`); 2466 expect(Number(e.code)).assertEqual(2900003); 2467 } 2468 } else { 2469 expect(true).assertTrue(); 2470 } 2471 done(); 2472 }) 2473 2474 /** 2475 * @tc.number SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1300 2476 * @tc.name SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1300 2477 * @tc.desc test disable bt use api 2478 * @tc.type Function 2479 * @tc.size MediumTest 2480 * @tc.level Level 2 2481 */ 2482 it('SUB_COMMUNICATION_BLUETOOTH_DISABLED_BLE_1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 2483 if (!closeUnsupport) { 2484 try { 2485 await BleScanner.stopScan().then(() => { 2486 console.info('[bluetooth_js] bleScanner stopScan success'); 2487 }); 2488 expect(true).assertFalse(); 2489 } catch (e) { 2490 console.error( `bleScanner stopScan promise error, error code is: ${e.code}, error message is: ${e.message}`); 2491 expect(Number(e.code)).assertEqual(2900003); 2492 } 2493 } else { 2494 expect(true).assertTrue(); 2495 } 2496 done(); 2497 }) 2498 2499 /** 2500 * @tc.number SUB_COMMUNICATION_BLUETOOTH_CONNECTION_GETREMOTEDEVICETRANSPORT_0100 2501 * @tc.name SUB_COMMUNICATION_BLUETOOTH_CONNECTION_GETREMOTEDEVICETRANSPORT_0100 2502 * @tc.desc Test getRemoteDeviceTransport 2503 * @tc.type Function 2504 * @tc.size MediumTest 2505 * @tc.level Level 0 2506 */ 2507 it('SUB_COMMUNICATION_BLUETOOTH_CONNECTION_GETREMOTEDEVICETRANSPORT_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 2508 if (!closeUnsupport) { 2509 try { 2510 let transport = connection.getRemoteDeviceTransport("00:11:22:33:44:55"); 2511 console.info('[bluetooth_js] getRemoteDeviceTransport result:' + transport); 2512 expect(true).assertFalse(); 2513 } catch (e) { 2514 console.error( `getRemoteDeviceTransport get error, error code is: ${e.code}, error message is: ${e.message}`); 2515 expect(Number(e.code)).assertEqual(2900003); 2516 } 2517 } else { 2518 expect(true).assertTrue(); 2519 } 2520 done(); 2521 }) 2522}) 2523}