• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
19import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest'
20
21export default function btManagerError003Test() {
22describe('btManagerError003Test', function() {
23    let gattServer = null;
24    let gattClient = null;
25    function sleep(delay) {
26        return new Promise(resovle => setTimeout(resovle, delay))
27    }
28
29    async function tryToDisableBt() {
30        let sta = bluetoothManager.getState();
31        switch(sta){
32            case 0:
33                console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
34                break;
35            case 1:
36                console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta));
37                await sleep(3000);
38                break;
39            case 2:
40                console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta));
41                bluetoothManager.disableBluetooth();
42                await clickTheWindow();
43                await sleep(3000);
44                break;
45            case 3:
46                console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta));
47                break;
48            default:
49                console.info('[bluetooth_js] enable success');
50        }
51    }
52
53    async function openPhone() {
54        try{
55            let drivers = Driver.create();
56            console.info('[bluetooth_js] bt driver create:'+ drivers);
57            await drivers.delayMs(1000);
58            await drivers.wakeUpDisplay();
59            await drivers.delayMs(5000);
60            await drivers.swipe(1500, 1000, 1500, 100);
61            await drivers.delayMs(10000);
62        } catch (error) {
63            console.info('[bluetooth_js] driver error info:'+ error);
64        }
65    }
66
67    async function clickTheWindow() {
68        try {
69            console.info('[bluetooth_js] clickRequestPermission start');
70            let driver = Driver.create();
71            await driver.delayMs(3000);
72            let button = await driver.findComponent(ON.text("允许"));
73            await button.click();
74            await driver.delayMs(3000);
75            console.info('[bluetooth_js] clickRequestPermission end');
76        } catch (err) {
77            console.info('[bluetooth_js] clickRequestPermission failed');
78        }
79    }
80
81    beforeAll(async function (done) {
82        console.info('beforeAll called')
83        gattServer = bluetoothManager.BLE.createGattServer();
84        gattClient = bluetoothManager.BLE.createGattClientDevice("11:22:33:44:55:66");
85        await openPhone();
86        done();
87    })
88    beforeEach(async function(done) {
89        console.info('beforeEach called')
90        await tryToDisableBt()
91        done()
92    })
93    afterEach(function () {
94        console.info('afterEach called')
95    })
96    afterAll(async function (done) {
97        console.info('afterAll called')
98        await sleep(6000);
99        gattClient.close();
100        done()
101    })
102
103    /**
104     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0100
105     * @tc.name test bluetooth Profile ConnectionState
106     * @tc.desc Test 2900003 - Bluetooth switch is off.
107     * @tc.type Function
108     * @tc.level Level 2
109     */
110    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0100', 0, async function (done) {
111        await sleep(3000);
112        try {
113            let sta = bluetoothManager.getState();
114            console.info('[bluetooth_js] bt getState:'+ JSON.stringify(sta));
115            let connState = bluetoothManager.getBtConnectionState();
116            console.info('[bluetooth_js] get bt connection state result'
117                         + JSON.stringify(connState));
118            expect(true).assertFalse();
119            done();
120        } catch (error) {
121            console.error('[bluetooth_js]getBtConnectionState error.code:'
122            +JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message));
123            expect(error.code).assertEqual('2900003');
124            done()
125        }
126    })
127
128    /**
129     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0200
130     * @tc.name Test pairDevice api
131     * @tc.desc Test 2900003 - Bluetooth switch is off
132     * @tc.type Function
133     * @tc.level Level 2
134     */
135    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0200', 0, async function (done) {
136        try {
137            bluetoothManager.pairDevice("11:22:55:66:33:44");
138            expect(true).assertFalse();
139            done()
140        } catch (error) {
141            console.error('[bluetooth_js]pairDevice error.code:'+JSON.stringify(error.code)+
142                   'error.message:'+JSON.stringify(error.message));
143            expect(error.code).assertEqual('2900003');
144            done()
145        }
146    })
147
148    /**
149     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0300
150     * @tc.name test getRemoteDeviceName
151     * @tc.desc Test 2900003 - Bluetooth switch is off
152     * @tc.type Function
153     * @tc.level Level 3
154     */
155    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0300', 0, async function (done) {
156        try {
157            let ret = bluetoothManager.getRemoteDeviceName("00:00:00:00:00:00");
158            console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret));
159            expect(ret.length).assertEqual(0);
160            expect(true).assertFalse();
161            done()
162        } catch (error) {
163            console.error('[bluetooth_js]getRemoteDeviceName error.code:'+JSON.stringify(error.code)+
164                   'error.message:'+JSON.stringify(error.message));
165            expect(error.code).assertEqual('2900003');
166            done()
167        }
168    })
169
170    /**
171     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0400
172     * @tc.name test getRemoteDeviceClass
173     * @tc.desc Test 2900003 - Bluetooth switch is off
174     * @tc.type Function
175     * @tc.level Level 3
176     */
177    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0400', 0, async function (done) {
178        try {
179            let DeviceClass = bluetoothManager.getRemoteDeviceClass("00:00:00:00:00:00");
180            console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(DeviceClass)
181            + 'majorClass:' +DeviceClass.majorClass + 'majorMinorClass:'+ DeviceClass.majorMinorClass
182            + 'classOfDevice:' + DeviceClass.classOfDevice);
183            expect(true).assertFalse();
184            done()
185        } catch (error) {
186            console.error('[bluetooth_js]getRemoteDeviceClass error.code:'+JSON.stringify(error.code)+
187                   'error.message:'+JSON.stringify(error.message));
188            expect(error.code).assertEqual('2900003');
189            done()
190        }
191    })
192
193    /**
194     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0500
195     * @tc.name test get PairedDevices
196     * @tc.desc Test 2900003 - Bluetooth switch is off
197     * @tc.type Function
198     * @tc.level Level 3
199     */
200    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0500', 0, async function (done) {
201        try {
202            let ret = bluetoothManager.getPairedDevices();
203            console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret));
204            expect(true).assertFalse();
205            done()
206        } catch (error) {
207            console.error('[bluetooth_js]getPairedDevices error.code:'+JSON.stringify(error.code)+
208                   'error.message:'+JSON.stringify(error.message));
209            expect(error.code).assertEqual('2900003');
210            done()
211        }
212    })
213
214    /**
215     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0600
216     * @tc.name test Get A2DP ConnectionState
217     * @tc.desc Test 2900003 - Bluetooth switch is off.
218     * @tc.type Function
219     * @tc.level Level 3
220     */
221    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0600', 0, async function (done) {
222        try {
223            let a2dpSrcConn = bluetoothManager.getProfileConnectionState(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
224            console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn));
225            expect(true).assertFalse();
226            done()
227        } catch (error) {
228            console.error('[bluetooth_js]getProfileConnState error.code:'+JSON.stringify(error.code)+
229                   'error.message:'+JSON.stringify(error.message));
230            expect(error.code).assertEqual('2900003');
231            done()
232        }
233    })
234
235    /**
236     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0700
237     * @tc.name Test setDevicePairing
238     * @tc.desc Test 2900003 - Bluetooth switch is off
239     * @tc.type Function
240     * @tc.level Level 3
241     */
242    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0700', 0, async function (done) {
243        try {
244            bluetoothManager.setDevicePairingConfirmation("11:22:55:66:33:44",false);
245            expect(true).assertFalse();
246            done()
247        } catch (error) {
248            console.error('[bluetooth_js]setDevicePairingConfirmation error.code:'
249               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
250            expect(error.code).assertEqual('2900003');
251            done()
252        }
253    })
254
255    /**
256     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0800
257     * @tc.name setLocalName
258     * @tc.desc Test 2900003 - Bluetooth switch is off.
259     * @tc.type Function
260     * @tc.level Level 2
261     */
262     it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0800', 0, async function (done) {
263        try {
264            let newName = 'my bluetooth';
265            bluetoothManager.setLocalName(newName);
266            expect(true).assertFalse();
267            done()
268        } catch (error) {
269            console.error('[bluetooth_js]setLocalName error.code:'
270               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
271            expect(error.code).assertEqual('2900003');
272            done()
273        }
274    })
275
276    /**
277     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0900
278     * @tc.name TEST setBluetoothScanMode
279     * @tc.desc TEST 2900003 - Bluetooth switch is off.
280     * @tc.type Function
281     * @tc.level Level 2
282     */
283    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_0900', 0, async function (done) {
284        try {
285            bluetoothManager.setBluetoothScanMode(bluetoothManager.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0);
286            expect(true).assertFalse();
287            done()
288        } catch (error) {
289            console.error('[bluetooth_js]setBluetoothScanMode error.code:'
290               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
291            expect(error.code).assertEqual('2900003');
292            done()
293        }
294    })
295
296     /**
297     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1000
298     * @tc.name TEST getBluetoothScanMode
299     * @tc.desc TEST 2900003 - Bluetooth switch is off.
300     * @tc.type Function
301     * @tc.level Level 2
302     */
303    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1000', 0, async function (done) {
304        try {
305            let oldScanMode = bluetoothManager.getBluetoothScanMode();
306            console.info('[bluetooth_js] getBluetoothScanMode = '+ JSON.stringify(oldScanMode));
307            expect(true).assertFalse();
308            done()
309        } catch (error) {
310            console.error('[bluetooth_js]getBluetoothScanMode error.code:'
311               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
312            expect(error.code).assertEqual('2900003');
313            done()
314        }
315    })
316
317    /**
318     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1100
319     * @tc.name TEST startBluetoothDiscovery
320     * @tc.desc TEST 2900003 - Bluetooth switch is off.
321     * @tc.type Function
322     * @tc.level Level 2
323     */
324    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1100', 0, async function (done) {
325        try {
326            bluetoothManager.startBluetoothDiscovery();
327            expect(true).assertFalse();
328            done()
329        } catch (error) {
330            console.error('[bluetooth_js]startBluetoothDiscovery error.code:'
331               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
332            expect(error.code).assertEqual('2900003');
333            done()
334        }
335    })
336
337    /**
338     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1200
339     * @tc.name TEST stopBluetoothDiscovery
340     * @tc.desc TEST 2900003 - Bluetooth switch is off.
341     * @tc.type Function
342     * @tc.level Level 2
343     */
344    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1200', 0, async function (done) {
345        try {
346            bluetoothManager.stopBluetoothDiscovery();
347            expect(true).assertFalse();
348            done()
349        } catch (error) {
350            console.error('[bluetooth_js]stopBluetoothDiscovery error.code:'
351               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
352            expect(error.code).assertEqual('2900003');
353            done()
354        }
355    })
356
357    /**
358     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1600
359     * @tc.name test getDevice HFP State.
360     * @tc.desc Test 2900003 - Bluetooth switch is off.
361     * @tc.type Function
362     * @tc.level Level 1
363     */
364    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1600', 0, async function (done) {
365        try {
366            let hfpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
367            let retArray = hfpSrc.getConnectionDevices();
368            console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray));
369            expect(true).assertFalse();
370            done()
371        } catch (error) {
372            console.error('[bluetooth_js]getConnectionDevices error.code:'
373               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
374            expect(error.code).assertEqual('2900003');
375            done()
376        }
377    })
378
379    /**
380     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1700
381     * @tc.name test getDeviceState.
382     * @tc.desc Test 2900003 - Bluetooth switch is off.
383     * @tc.type Function
384     * @tc.level Level 1
385     */
386    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1700', 0, async function (done) {
387        try {
388            let hfpSrc = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
389            let ret = hfpSrc.getDeviceState('11:22:33:44:55:66');
390            console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret));
391            expect(true).assertFalse();
392            done()
393        } catch (error) {
394            console.error('[bluetooth_js]getDeviceState error.code:'
395               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
396            expect(error.code).assertEqual('2900003');
397            done()
398        }
399    })
400
401    /**
402     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1800
403     * @tc.name test A2DP Connect
404     * @tc.desc Test 2900003 - Bluetooth switch is off.
405     * @tc.type Function
406     * @tc.level Level 1
407     */
408    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1800', 0, async function (done) {
409        try {
410            let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
411            a2dpSrc.connect('11:22:33:44:55:77');
412            expect(true).assertFalse();
413            done()
414        } catch (error) {
415            console.error('[bluetooth_js]A2DPconnect error.code:'
416               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
417            expect(error.code).assertEqual('2900003');
418            done()
419        }
420    })
421
422
423    /**
424     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1900
425     * @tc.name test A2DP disconnect
426     * @tc.desc Test 2900003 - Bluetooth switch is off.
427     * @tc.type Function
428     * @tc.level Level 3
429     */
430    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_1900', 0, async function (done) {
431        try {
432            let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
433            a2dpSrc.disconnect('11:22:33:44:55:77');
434            expect(true).assertFalse();
435            done()
436        } catch (error) {
437            console.error('[bluetooth_js]A2DPdisconnect error.code:'
438               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
439            expect(error.code).assertEqual('2900003');
440            done()
441        }
442    })
443
444    /**
445     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2000
446     * @tc.name test  get A2DP Playing State
447     * @tc.desc Test  2900003 - Bluetooth switch is off.
448     * @tc.type Function
449     * @tc.level Level 3
450     */
451    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2000', 0, async function (done) {
452        try {
453            let a2dpSrc = bluetoothManager.getProfile(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
454            console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
455            let state = a2dpSrc.getPlayingState('11:22:33:44:55:66');
456            console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state));
457            expect(true).assertFalse();
458            done()
459        } catch (error) {
460            console.error('[bluetooth_js]getPlayingState error.code:'
461               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
462            expect(error.code).assertEqual('2900003');
463            done()
464        }
465    })
466
467    /**
468     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2100
469     * @tc.name test HFP Connect
470     * @tc.desc Test 2900003 - Bluetooth switch is off.
471     * @tc.type Function
472     * @tc.level Level 1
473     */
474    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2100', 0, async function (done) {
475        try {
476            let hfpSrc =
477                bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
478            hfpSrc.connect('11:22:33:44:55:77');
479            expect(true).assertFalse();
480            done()
481        } catch (error) {
482            console.error('[bluetooth_js]HFPconnect error.code:'
483               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
484            expect(error.code).assertEqual('2900003');
485            done()
486        }
487    })
488
489    /**
490     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2200
491     * @tc.name test HFP disconnect
492     * @tc.desc Test 2900003 - Bluetooth switch is off.
493     * @tc.type Function
494     * @tc.level Level 3
495     */
496    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2200', 0, async function (done) {
497        try {
498            let hfpSrc =
499               bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
500            hfpSrc.disconnect('11:22:33:44:55:77');
501            expect(true).assertFalse();
502            done()
503        } catch (error) {
504            console.error('[bluetooth_js]HFPdisconnect error.code:'
505               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
506            expect(error.code).assertEqual('2900003');
507            done()
508        }
509    })
510
511    /**
512     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2800
513     * @tc.name testClassicStartBLEScan
514     * @tc.desc Test 2900003 - Bluetooth switch is off.
515     * @tc.type Function
516     * @tc.level Level 2
517     */
518    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2800', 0, async function (done) {
519        try {
520            bluetoothManager.BLE.startBLEScan(
521                [{
522                    deviceId:"11:22:33:44:55:66",
523                    name:"test",
524                    serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
525                }],
526                {
527                    interval: 500,
528                    dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER,
529                    matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE,
530                }
531            );
532            expect(true).assertFalse();
533            done()
534        } catch (error) {
535            console.error('[bluetooth_js]startBLEScan error.code:'
536               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
537            expect(error.code).assertEqual('2900003');
538            done()
539        }
540    })
541
542    /**
543     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2900
544     * @tc.name testClassicStartBLEScan
545     * @tc.desc Test 2900003 - Bluetooth switch is off.
546     * @tc.type Function
547     * @tc.level Level 2
548     */
549    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_2900', 0, async function (done) {
550        try {
551            bluetoothManager.BLE.stopBLEScan();
552            expect(true).assertFalse();
553            done()
554        } catch (error) {
555            console.error('[bluetooth_js]startBLEScan error.code:'
556               +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
557            expect(error.code).assertEqual('2900003');
558            done()
559        }
560    })
561
562    /**
563     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3000
564     * @tc.name testStartAdvertising
565     * @tc.desc Test 2900003 - Bluetooth switch is off.
566     * @tc.type Function
567     * @tc.level Level 0
568     */
569    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3000', 0, async function (done) {
570          let manufactureValueBuffer = new Uint8Array(4);
571          manufactureValueBuffer[0] = 1;
572          manufactureValueBuffer[1] = 2;
573          manufactureValueBuffer[2] = 3;
574          manufactureValueBuffer[3] = 4;
575          let serviceValueBuffer = new Uint8Array(4);
576          serviceValueBuffer[0] = 4;
577          serviceValueBuffer[1] = 6;
578          serviceValueBuffer[2] = 7;
579          serviceValueBuffer[3] = 8;
580          let setting={
581            interval:32,
582            txPower:-10,
583            connectable:true,
584            }
585          let advData={
586               serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
587               manufactureData:[{
588                    manufactureId:4567,
589                    manufactureValue:manufactureValueBuffer.buffer
590               }],
591               serviceData:[{
592                    serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
593                    serviceValue:serviceValueBuffer.buffer
594               }],
595          }
596          let advResponse ={
597               serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
598               manufactureData:[{
599                    manufactureId:1789,
600                    manufactureValue:manufactureValueBuffer.buffer
601               }],
602               serviceData:[{
603                    serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
604                    serviceValue:serviceValueBuffer.buffer
605               }],
606          }
607          try {
608               gattServer.startAdvertising(setting,advData,advResponse);
609               expect(true).assertFalse();
610          }catch(error) {
611               console.error('[bluetooth_js]startAdvertising error.code:'+JSON.stringify(error.code)+
612                   'error.message:'+JSON.stringify(error.message));
613               expect(error.code).assertEqual('2900003');
614          }
615          await sleep(2000);
616          done();
617     })
618
619       /**
620     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3100
621     * @tc.name teststopAdvertising
622     * @tc.desc Test 2900003 - Bluetooth switch is off.
623     * @tc.type Function
624     * @tc.level Level 0
625     */
626    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3100', 0, async function (done) {
627          let manufactureValueBuffer = new Uint8Array(4);
628          manufactureValueBuffer[0] = 1;
629          manufactureValueBuffer[1] = 2;
630          manufactureValueBuffer[2] = 3;
631          manufactureValueBuffer[3] = 4;
632          let serviceValueBuffer = new Uint8Array(4);
633          serviceValueBuffer[0] = 4;
634          serviceValueBuffer[1] = 6;
635          serviceValueBuffer[2] = 7;
636          serviceValueBuffer[3] = 8;
637          let advData={
638               serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
639               manufactureData:[{
640                    manufactureId:4567,
641                    manufactureValue:manufactureValueBuffer.buffer
642               }],
643               serviceData:[{
644                    serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
645                    serviceValue:serviceValueBuffer.buffer
646               }],
647          }
648          let advResponse ={
649               serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
650               manufactureData:[{
651                    manufactureId:1789,
652                    manufactureValue:manufactureValueBuffer.buffer
653               }],
654               serviceData:[{
655                    serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
656                    serviceValue:serviceValueBuffer.buffer
657               }],
658          }
659          try {
660               gattServer.stopAdvertising();
661               expect(true).assertFalse();
662          }catch(error) {
663               console.error('[bluetooth_js]stopAdvertising error.code:'+JSON.stringify(error.code)+
664                   'error.message:'+JSON.stringify(error.message));
665               expect(error.code).assertEqual('2900003');
666          }
667          done();
668     })
669
670    /**
671     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3200
672     * @tc.name testAddService
673     * @tc.desc Test 2900003 - Bluetooth switch is off.
674     * @tc.type Function
675     * @tc.level Level 2
676     */
677    it('SUB_COMMUNICATION_BTMANAGER_SwitchOff_3200', 0, async function (done) {
678        try {
679            let descriptors = [];
680            let arrayBuffer = new ArrayBuffer(8);
681            let descV = new Uint8Array(arrayBuffer);
682            descV[0] = 11;
683            let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
684            characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
685            descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
686            descriptors[0] = descriptor;
687            let characteristics = [];
688            let arrayBufferC = new ArrayBuffer(8);
689            let cccV = new Uint8Array(arrayBufferC);
690            cccV[0] = 1;
691            let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
692            characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
693            characteristicValue: arrayBufferC, descriptors:descriptors};
694            characteristics[0] = characteristic;
695            let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true,
696            characteristics:characteristics, includeServices:[]};
697            gattServer.addService(gattService);
698            expect(true).assertFalse();
699            done();
700        } catch (error) {
701            console.error(`[bluetooth_js]AddService failed, code is ${error.code},
702                  message is ${error.message}`);
703            expect(error.code).assertEqual('2900003');
704            done()
705        }
706    })
707
708    /**
709     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3300
710     * @tc.name test removeService
711     * @tc.desc Test 2900003 - Bluetooth switch is off.
712     * @tc.type Function
713     * @tc.level Level 2
714     */
715    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3300', 0, async function (done) {
716        try {
717            gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
718            expect(true).assertFalse();
719            done();
720        } catch (error) {
721            console.error(`[bluetooth_js]removeService failed, code is ${error.code},
722                  message is ${error.message}`);
723            expect(error.code).assertEqual('401');
724            done()
725        }
726    })
727
728    /**
729     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3400
730     * @tc.name test removeService
731     * @tc.desc Test 2900003 - Bluetooth switch is off.
732     * @tc.type Function
733     * @tc.level Level 3
734     */
735    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3400', 0, async function (done) {
736        try {
737            gattServer.close();
738            expect(true).assertFalse();
739            done();
740        } catch (error) {
741            console.error(`[bluetooth_js]close failed, code is ${error.code},
742                  message is ${error.message}`);
743            expect(error.code).assertEqual('2900003');
744            done()
745        }
746    })
747
748    /**
749     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3600
750     * @tc.name testSendResponse success
751     * @tc.desc Test 2900003 - Bluetooth switch is off.
752     * @tc.type Function
753     * @tc.level Level 1
754     */
755    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3600', 0, async function (done) {
756        try {
757            let arrayBuffer = new ArrayBuffer(8);
758            let value =  new Uint8Array(arrayBuffer);
759            value[0] = 1;
760            let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1,
761                status: 0, offset: 0, value: arrayBuffer};
762            gattServer.sendResponse(ServerResponse);
763            expect(true).assertFalse();
764            done();
765        } catch (error) {
766            console.error(`[bluetooth_js]sendResponse failed, code is ${error.code},
767            message is ${error.message}`);
768            expect(error.code).assertEqual('2900003');
769            done()
770        }
771
772    })
773
774    /**
775     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3700
776     * @tc.name test gatt connect
777     * @tc.desc Test 2900003 - Bluetooth switch is off
778     * @tc.type Function
779     * @tc.level Level 3
780     */
781    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3700', 0, async function (done) {
782        try {
783            gattClient.connect();
784            await sleep(2000);
785            expect(true).assertFalse();
786        } catch(error) {
787            console.error(`[bluetooth_js]connect failed, code is ${error.code},
788            message is ${error.message}`);
789            expect(error.code).assertEqual('2900003');
790        }
791        done()
792    })
793
794    /**
795     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3800
796     * @tc.name test gatt disconnect
797     * @tc.desc Test 2900003 - Bluetooth switch is off
798     * @tc.type Function
799     * @tc.level Level 3
800     */
801    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3800', 0, async function (done) {
802        try {
803            gattClient.disconnect();
804            expect(true).assertFalse();
805          } catch(error) {
806            console.error(`[bluetooth_js]disconnect failed, code is ${error.code},
807            message is ${error.message}`);
808            expect(error.code).assertEqual('2900003');
809        }
810        done()
811    })
812
813    /**
814     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3900
815     * @tc.name test gatt close
816     * @tc.desc Test 2900003 - Bluetooth switch is off
817     * @tc.type Function
818     * @tc.level Level 3
819     */
820    it('SUB_COMMUNICATION_BTMANAGER_SWITCHOFF_3900', 0, async function (done) {
821        try {
822            gattClient.close();
823            expect(true).assertFalse();
824          } catch(error) {
825            console.error(`[bluetooth_js]gattClient close failed, code is ${error.code},
826            message is ${error.message}`);
827            expect(error.code).assertEqual('2900003');
828        }
829        done()
830    })
831
832    /**
833    * @tc.number SUB_COMMUNICATION_BTMANAGER_BLESCAN_0800
834    * @tc.name testClassicStartBLEScan
835    * @tc.desc Test ClassicStartBLEScan api.
836    * @tc.type Function
837    * @tc.level Level 3
838    */
839    it('SUB_COMMUNICATION_BTMANAGER_BLESCAN_0800', 0, async function (done) {
840        function onReceiveEvent(data)
841        {
842            console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data));
843            expect(true).assertTrue(data.length=0);
844        }
845        try {
846            let state = bluetoothManager.getState();
847            console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state));
848            if(state == bluetoothManager.BluetoothState.STATE_ON) {
849                let result2= bluetoothManager.disableBluetooth();
850                await clickTheWindow();
851                console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2));
852                let state1 = bluetoothManager.getState();
853                console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1));
854                expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF);
855            }
856            console.info('[bluetooth_js] BLE BLEDeviceFind on start!');
857            bluetoothManager.BLE.on("BLEDeviceFind", onReceiveEvent)
858            bluetoothManager.BLE.startBLEScan(
859                [{}],
860                {
861                    interval: 100,
862                    dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER,
863                    matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE,
864                }
865            );
866            await sleep(1000);
867            // expect(true).assertFalse();
868            console.info('[bluetooth_js] BLE scan off8');
869            bluetoothManager.BLE.stopBLEScan();
870            done();
871        } catch (error) {
872            console.error('[bluetooth_js]Scan_0800 error.code:'+JSON.stringify(error.code)+
873            'error.message:'+JSON.stringify(error.message));
874            expect(error.code).assertEqual('2900003');
875        }
876        console.info('[bluetooth_js] BLE BLEDeviceFind off start!');
877        bluetoothManager.BLE.off('BLEDeviceFind', onReceiveEvent);
878        await sleep(2000);
879        done();
880    })
881
882    /**
883         * @tc.number SUB_COMMUNICATION_BTMANAGER_BLESCAN_0900
884         * @tc.name testClassicStartBLEScan
885         * @tc.desc Test ClassicStartBLEScan api.
886         * @tc.type Function
887         * @tc.level Level 3
888         */
889    it('SUB_COMMUNICATION_BTMANAGER_BLESCAN_0900', 0, async function (done) {
890        bluetooth.disableBluetooth();
891        await clickTheWindow();
892        await sleep(3000);
893        let state = bluetooth.getState();
894        console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state));
895        function onReceiveEvent(data)
896        {
897            console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data));
898            expect(true).assertTrue(data.length=0);
899        }
900        bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
901        bluetooth.BLE.startBLEScan(
902            [{}],
903            {
904                interval: 100,
905                dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
906                matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
907            }
908        );
909        await sleep(1000);
910        console.info('[bluetooth_js] BLE scan off8');
911        bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
912        bluetooth.BLE.stopBLEScan();
913        done();
914    })
915
916    /**
917     * @tc.number SUB_COMMUNICATION_BTMANAGER_SWITCH_0400
918     * @tc.name testEnableBluetooth
919     * @tc.desc Test EnableBluetooth api by promise.
920     * @tc.type Function
921     * @tc.level Level 3
922     */
923    it('SUB_COMMUNICATION_BTMANAGER_SWITCH_0400', 0, async function (done) {
924        let state = bluetooth.getState();
925        console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state));
926        if(state == bluetooth.BluetoothState.STATE_OFF) {
927            let result2= bluetooth.disableBluetooth();
928            await clickTheWindow();
929            console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2));
930            expect(result2).assertFalse();
931            let state1 = bluetooth.getState();
932            console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1));
933            expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF);
934        }
935        done();
936    })
937})
938}