Bluetooth.test.js 26.7 KB
Newer Older
1
/*
Q
q00313334 已提交
2
 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import bluetooth from '@ohos.bluetooth';
J
jiyong_sd 已提交
17
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
18

Q
q00313334 已提交
19

Q
q00313334 已提交
20
let Btname = {
Q
q00313334 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    NUM_TEST :'012345678901234567890123456789012345678901234567890123'+
    '45678901234567890123456789012345678901234567890123456789012345678901234567',
    NUM_TEST1 :'01234567890123456789012345678901234567890123456'
    +'7890123456789012345678901234567890123456789012345678901234567890123456789012345678',
    LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙',
    SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×'
    +'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓',
    MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw',
    MIXES2:'——◎◇◆□■△▲测试蓝牙',
    MIXES3:'78453-、、。。◎◇◆□■△▲',
    MIXES4:'hhhfdf-、、。。◎◇◆□■△▲',
    MIXES5:'#01-5@<?;:!@$%^&*(1[]{【+-;:‘’“”测试=》《\'[6]',
    MIXES6:'#01-567890@<>?/;:5675ASDF012345678!@'
    +'$%^&*()9012378901[]{}【】566~·67890blue',
    MIXES7:'0123456789012345678901234567890123456789012345678901'
    +'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
    +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
Q
q00313334 已提交
39
}
Q
q00313334 已提交
40

J
jiyong_sd 已提交
41
export default function bluetoothhostTest() {
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
describe('bluetoothhostTest', function() {

    beforeAll(function () {
        console.info('beforeAll called')
    })
    beforeEach(function () {
        console.info('beforeEach called')

    })
    afterEach(function () {
        console.info('afterEach called')
    })
    afterAll(function () {
        console.info('afterAll called')
    })

Q
q00313334 已提交
58 59 60
    function sleep(delay) {
        return new Promise(resovle => setTimeout(resovle, delay))
    }
61

Q
q00313334 已提交
62
    async function tryToEnableBt() {
Q
q00313334 已提交
63
        let sta = bluetooth.getState();
Q
q00313334 已提交
64 65
        switch(sta){
            case 0:
Q
q00313334 已提交
66
                console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
Q
q00313334 已提交
67
                bluetooth.enableBluetooth();
Q
q00313334 已提交
68
                await sleep(3000);
Q
q00313334 已提交
69 70 71
                break;
            case 1:
                console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta));
Q
q00313334 已提交
72
                await sleep(3000);
Q
q00313334 已提交
73 74
                break;
            case 2:
Q
q00313334 已提交
75
                console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta));
Q
q00313334 已提交
76 77
                break;
            case 3:
Q
q00313334 已提交
78
                console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta));
Q
q00313334 已提交
79
                bluetooth.enableBluetooth();
Q
q00313334 已提交
80
                await sleep(3000);
Q
q00313334 已提交
81 82 83
                break;
            default:
                console.info('[bluetooth_js] enable success');
Q
q00313334 已提交
84 85 86 87 88
        }
    }


    /**
Q
q00313334 已提交
89
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_STATE_0001
Q
q00313334 已提交
90 91
     * @tc.name testEnableBluetooth
     * @tc.desc Test EnableBluetooth api by promise.
92 93 94 95
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
96
    it('SUB_COMMUNACATION_bluetooth_GET_STATE_0001', 0, async function (done) {
Q
q00313334 已提交
97
        console.info('[bluetooth_js] getState start');
Q
q00313334 已提交
98
        await tryToEnableBt();
Q
q00313334 已提交
99
        let state = bluetooth.getState();
100 101
        console.info('[bluetooth_js] get bluetooth state result = '+ JSON.stringify(state));
        expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON);
Q
q00313334 已提交
102 103 104 105 106 107
        expect(bluetooth.BluetoothState.STATE_OFF != state).assertTrue();
        expect(bluetooth.BluetoothState.STATE_TURNING_ON != state).assertTrue();
        expect(bluetooth.BluetoothState.STATE_TURNING_OFF != state).assertTrue();
        expect(bluetooth.BluetoothState.STATE_BLE_TURNING_ON != state).assertTrue();
        expect(bluetooth.BluetoothState.STATE_BLE_ON != state).assertTrue();
        expect(bluetooth.BluetoothState.STATE_BLE_TURNING_OFF != state).assertTrue();
Q
q00313334 已提交
108
        done();
109 110
    })

Q
q00313334 已提交
111

112
    /**
Q
q00313334 已提交
113
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001
114 115 116 117 118 119
     * @tc.name testClassicSetLocalName
     * @tc.desc Test ClassicSetLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
120
    it('SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001', 0, async function (done) {
Q
q00313334 已提交
121
        console.info('[bluetooth_js] set localname start');
Q
q00313334 已提交
122
        await tryToEnableBt();
Q
q00313334 已提交
123
        let name = bluetooth.setLocalName('bluetooth_test');
Q
q00313334 已提交
124 125
        console.info('[bluetooth_js] appInfoTest enable bluetooth result = '+ JSON.stringify(name));
        expect(name).assertEqual(true);
Q
q00313334 已提交
126
        done();
Q
q00313334 已提交
127
    })
128

Q
q00313334 已提交
129
    /**
Q
q00313334 已提交
130
     * @tc.number SUB_COMMUNACATION_bluetooth_START_PAIR_0001
Q
q00313334 已提交
131 132 133 134 135 136
     * @tc.name testStartpair
     * @tc.desc Test Startpair api by promise.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
137
    it('SUB_COMMUNACATION_bluetooth_START_PAIR_0001', 0, async function (done) {
Q
q00313334 已提交
138
        console.info('[bluetooth_js] Startpair test start ...');
Q
q00313334 已提交
139
        await tryToEnableBt();
Q
q00313334 已提交
140
        let result = bluetooth.pairDevice("00:00:00:00:00:00");
Q
q00313334 已提交
141 142
        console.info("[bluetooth_js] onStartpair -> " + JSON.stringify(result));
        expect(result).assertFalse();
Q
q00313334 已提交
143
        done();
144 145 146
    })

    /**
Q
q00313334 已提交
147
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001
148 149 150 151 152 153
     * @tc.name testClassicGetLocalName
     * @tc.desc Test ClassicGetLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
154
    it('SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001', 0, async function (done) {
Q
q00313334 已提交
155
        console.info('[bluetooth_js] get localName start');
Q
q00313334 已提交
156
        await tryToEnableBt();
Q
q00313334 已提交
157
        let localName = bluetooth.getLocalName();
158 159
        console.info('[bluetooth_js] get local Name result = ' + JSON.stringify(localName));
        expect(localName).assertEqual('bluetooth_test');
Q
q00313334 已提交
160
        done();
161 162 163
    })

    /**
Q
q00313334 已提交
164
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001
165 166 167 168 169 170
     * @tc.name testClassicSetBluetoothScanMode
     * @tc.desc Test ClassicSetBluetoothScanMode api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
171
    it('SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
Q
q00313334 已提交
172
        console.info('[bluetooth_js] set scan mode start');
Q
q00313334 已提交
173
        await tryToEnableBt();
Q
q00313334 已提交
174
        let result = bluetooth.setBluetoothScanMode(1,10000);
Q
q00313334 已提交
175 176 177
        expect(true).assertTrue(JSON.stringify(bluetooth.ScanDuty.SCAN_MODE_LOW_POWER) !=result );
        expect(true).assertTrue(JSON.stringify(bluetooth.ScanDuty.SCAN_MODE_BALANCED) != result);
        expect(true).assertTrue(JSON.stringify(bluetooth.ScanDuty.SCAN_MODE_BALANCED) != result );
178
        expect(result).assertEqual(true);
Q
q00313334 已提交
179
        done();
180 181 182
    })

    /**
Q
q00313334 已提交
183
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001
184 185 186 187 188 189
     * @tc.name testClassicGetBluetoothScanMode
     * @tc.desc Test ClassicGetBluetoothScanMode api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
190
    it('SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
Q
q00313334 已提交
191
        console.info('[bluetooth_js] get scan mode start');
Q
q00313334 已提交
192
        await tryToEnableBt();
Q
q00313334 已提交
193
        let result = bluetooth.setBluetoothScanMode(1,10000);
194
        expect(result).assertEqual(true);
Q
q00313334 已提交
195
        let scanMode = bluetooth.getBluetoothScanMode();
Q
q00313334 已提交
196
        console.info('[bluetooth_js] get scan mode result2 = ' + JSON.stringify(scanMode));
197
        expect(scanMode).assertEqual(1);
Q
q00313334 已提交
198 199 200 201 202 203 204 205 206 207 208
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_NONE != scanMode);
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE != scanMode);
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE != scanMode);
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE != scanMode);
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE != scanMode);
        expect(true).assertTrue(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE != scanMode);
        done();
    })

    /**
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001
209 210 211 212 213 214
     * @tc.name testClassicGetBtConnectionState
     * @tc.desc Test ClassicGetBtConnectionState api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
215
    it('SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001', 0, async function (done) {
Q
q00313334 已提交
216
        console.info('[bluetooth_js] get connection state start');
Q
q00313334 已提交
217
        await tryToEnableBt();
Q
q00313334 已提交
218
        let connState = bluetooth.getBtConnectionState();
219 220
        console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState));
        expect(connState).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
Q
q00313334 已提交
221 222 223 224
        expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTING!= connState );
        expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTED!= connState );
        expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_DISCONNECTING!= connState );
        done();
225 226 227
    })

    /**
Q
q00313334 已提交
228
     * @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001
229 230 231 232 233 234
     * @tc.name testClassicStartBluetoothDiscovery
     * @tc.desc Test ClassicStartBluetoothDiscovery api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
235
    it('SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
Q
q00313334 已提交
236
        console.info('[bluetooth_js] discovery start');
Q
q00313334 已提交
237
        await tryToEnableBt();
Q
q00313334 已提交
238 239 240
        let result = bluetooth.startBluetoothDiscovery();
        console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(result));
        expect(result).assertEqual(true);
Q
q00313334 已提交
241
        done();
242 243 244
    })

    /**
Q
q00313334 已提交
245
     * @tc.number SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001
246 247 248 249 250 251
     * @tc.name testClassicStopBluetoothDiscovery
     * @tc.desc Test ClassicStopBluetoothDiscovery api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
252
    it('SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
Q
q00313334 已提交
253
        console.info('[bluetooth_js] stop discovery start');
Q
q00313334 已提交
254
        await tryToEnableBt();
Q
q00313334 已提交
255 256 257
        let result = bluetooth.stopBluetoothDiscovery();
        console.info("stopBluetoothDiscovery :" + JSON.stringify(result));
        expect(result).assertTrue();
Q
q00313334 已提交
258
        done();
259 260 261
    })

    /**
Q
q00313334 已提交
262
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001
263 264 265 266 267 268
     * @tc.name testClassicGetPairedDevices
     * @tc.desc Test ClassicGetPairedDevices api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
269
    it('SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001', 0, async function (done) {
Q
q00313334 已提交
270
        console.info('[bluetooth_js] get paired devices start');
Q
q00313334 已提交
271
        await tryToEnableBt();
Q
q00313334 已提交
272
        let devices = bluetooth.getPairedDevices();
Q
q00313334 已提交
273
        console.info('[bluetooth_js] get paired devices:' + JSON.stringify(devices) +'length:' + devices.length);
274
        expect(devices.length).assertEqual(0);
Q
q00313334 已提交
275
        done();
276 277
    })

278

279
    /**
Q
q00313334 已提交
280
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
281 282 283 284 285 286
     * @tc.name testSppListen
     * @tc.desc Test SppListen api by callback.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
287
    it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) {
Q
q00313334 已提交
288
        console.log("[bluetooth_js]: spp listen start");
Q
q00313334 已提交
289
        await tryToEnableBt();
290
        let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
Q
q00313334 已提交
291
            secure: false, type: 0};
292
        bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) {
Q
q00313334 已提交
293
            console.info('[bluetooth_js] code is: ' + code.code);
294 295 296 297 298 299 300 301 302 303 304
            if (code.code == 0) {
                expect(true).assertEqual(true);
                done();
            } else {
                expect(true).assertEqual(false);
                done();
            }
        });
    })

    /**
Q
q00313334 已提交
305
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001
306 307 308 309 310 311
     * @tc.name testSppAccept
     * @tc.desc Test SppAccept api by callbck.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
312
    it('SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001', 0, async function (done) {
Q
q00313334 已提交
313
        console.log("[bluetooth_js] spp accept start");
Q
q00313334 已提交
314
        await tryToEnableBt();
315
        bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
Q
q00313334 已提交
316
            console.info('[bluetooth_js] code is: ' + code.code);
317 318 319 320 321 322 323 324 325 326
            if (code.code == 0) {
                expect(true).assertEqual(true);
            } else {
                expect(true).assertEqual(false);
            }
        });
        done();
    })

    /**
Q
q00313334 已提交
327
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001
328 329 330 331 332 333
     * @tc.name testSppCloseServerSocket
     * @tc.desc Test SppCloseServerSocket api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
334
    it('SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001', 0, async function (done) {
Q
q00313334 已提交
335
        console.log("[bluetooth_js] spp closeServerSocket start");
Q
q00313334 已提交
336
        await tryToEnableBt();
Q
q00313334 已提交
337 338 339
	setTimeout(async ()=>{
            bluetooth.sppCloseServerSocket(-1);
	},3000);
Q
q00313334 已提交
340
        done();
341 342 343
    })

    /**
Q
q00313334 已提交
344
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001
345 346 347 348 349 350
     * @tc.name testSppConnect
     * @tc.desc Test SppConnect api by callback.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
351
    it('SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001', 0, async function (done) {
Q
q00313334 已提交
352
        console.info('[bluetooth_js] spp_connect start');
Q
q00313334 已提交
353
        await tryToEnableBt();
354 355 356
        let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
            secure: true, type: 0};
        bluetooth.sppConnect(55, sppOption, function(code, clientSocketNumber) {
Q
q00313334 已提交
357
            console.info('[bluetooth_js] code is: ' + code.code);
358 359 360 361 362 363 364 365 366 367
            if (code.code == 0) {
                expect(true).assertEqual(true);
            } else {
                expect(true).assertEqual(false);
            }
        });
        done();
    })

    /**
Q
q00313334 已提交
368
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001
369 370 371 372 373 374
     * @tc.name testSppWrite
     * @tc.desc Test SppWrite api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
375
    it('SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001', 0, async function (done) {
Q
q00313334 已提交
376
        console.info('[bluetooth_js] spp write start');
Q
q00313334 已提交
377
        await tryToEnableBt();
378 379 380 381 382 383
        let arrayBuffer = new ArrayBuffer(8);
        let data =  new Uint8Array(arrayBuffer);
        data[0] = 123;
        let ret = bluetooth.sppWrite(-1, arrayBuffer);
        console.info('[bluetooth_js] bluetooth sppWrite ret : ' + ret);
        expect(ret).assertEqual(false);
Q
q00313334 已提交
384
        done();
385 386
    })

Q
q00313334 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    /**
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_CLOSE_CLIENT_SOCKET_0001
     * @tc.name testSppCloseClientSocket
     * @tc.desc Test SppCloseClientSocket api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_COMMUNACATION_bluetooth_SPP_CLOSE_CLIENT_SOCKET_0001', 0, async function (done) {
        console.log("[bluetooth_js] spp closeClientSocket start");
        await tryToEnableBt();
        setTimeout(async ()=>{
            bluetooth.sppCloseClientSocket(-1);
        },3000);
        done();
    })



Q
q00313334 已提交
406
    /**
Q
q00313334 已提交
407
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001
Q
q00313334 已提交
408 409 410 411 412 413
     * @tc.name testGetRemoteDeviceName
     * @tc.desc Test GetRemoteDeviceName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
414
    it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001', 0, async function (done) {
Q
q00313334 已提交
415
        console.info('[bluetooth_js] getRemoteDeviceName start');
Q
q00313334 已提交
416
        await tryToEnableBt();
Q
q00313334 已提交
417 418 419
        let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00");
        console.info('[bluetooth_js] getRemoteDeviceName ret2 : ' + JSON.stringify(ret));
        expect(ret.length).assertEqual(0);
Q
q00313334 已提交
420
        done();
Q
q00313334 已提交
421 422 423
    })

    /**
Q
q00313334 已提交
424
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001
Q
q00313334 已提交
425 426 427 428 429 430
     * @tc.name testGetRemoteDeviceClass
     * @tc.desc Test GetRemoteDeviceClass api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
431
    it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001', 0, async function (done) {
Q
q00313334 已提交
432
        console.info('[bluetooth_js] getRemoteDeviceClass start');
Q
q00313334 已提交
433
        await tryToEnableBt();
Q
q00313334 已提交
434
        let ret = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00");
Q
q00313334 已提交
435 436
        console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(ret) + 'majorClass:' +
        ret.majorClass + 'majorMinorClass:'+ ret.majorMinorClass + 'classOfDevice:' + ret.classOfDevice);
Q
q00313334 已提交
437
        expect(ret.majorClass).assertEqual(0);
Q
q00313334 已提交
438
        done();
Q
q00313334 已提交
439 440 441 442
    })


    /**
Q
q00313334 已提交
443
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001
Q
q00313334 已提交
444 445 446 447 448 449
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
450 451
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
452 453 454
        let name = bluetooth.getLocalName();
        let set = bluetooth.setLocalName('');
        expect(set).assertFalse();
Q
q00313334 已提交
455
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
456
        expect(true).assertTrue(localName==name);
Q
q00313334 已提交
457
        console.info('[bluetooth_js] getLocalName result1 = ' + JSON.stringify(localName));
Q
q00313334 已提交
458
        done();
Q
q00313334 已提交
459 460 461 462
    })


    /**
Q
q00313334 已提交
463
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002
Q
q00313334 已提交
464 465 466 467 468 469
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
470 471
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
472 473
        let localName = bluetooth.getLocalName();
        let name = bluetooth.setLocalName();
Q
q00313334 已提交
474 475
        console.info('[bluetooth_js] getName result2 = '+ JSON.stringify(localName) +
        'setName result2 =' + JSON.stringify(name));
Q
q00313334 已提交
476
        expect(name).assertFalse();
Q
q00313334 已提交
477
        done();
Q
q00313334 已提交
478 479 480
    })

    /**
Q
q00313334 已提交
481
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0003
Q
q00313334 已提交
482 483 484 485 486 487
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
488 489
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0003', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
490
        let name = bluetooth.setLocalName(Btname.NUM_TEST);
Q
q00313334 已提交
491
        expect(name).assertTrue();
Q
q00313334 已提交
492
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
493 494
        expect(true).assertTrue(Btname.NUM_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
495 496 497
    })

    /**
Q
q00313334 已提交
498
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0004
Q
q00313334 已提交
499 500 501 502 503 504
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
505 506
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0004', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
507
        let name = bluetooth.setLocalName(Btname.NUM_TEST1);
Q
q00313334 已提交
508
        expect(name).assertTrue();
Q
q00313334 已提交
509
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
510 511
        expect(true).assertTrue(Btname.NUM_TEST1 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
512 513 514
    })

    /**
Q
q00313334 已提交
515
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005
Q
q00313334 已提交
516 517 518 519 520 521
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
522 523
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
524
        let name = bluetooth.setLocalName(Btname.LETTERS_TEST);
Q
q00313334 已提交
525
        expect(name).assertTrue();
Q
q00313334 已提交
526
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
527 528
        expect(true).assertTrue(Btname.LETTERS_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
529 530
    })

Q
q00313334 已提交
531

Q
q00313334 已提交
532
    /**
Q
q00313334 已提交
533
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006
Q
q00313334 已提交
534 535 536 537 538 539
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
540 541
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
542
        let name = bluetooth.setLocalName(Btname.CHINESES_TEST);
Q
q00313334 已提交
543
        expect(name).assertTrue();
Q
q00313334 已提交
544
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
545 546
        expect(true).assertTrue(Btname.CHINESES_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
547 548
    })

Q
q00313334 已提交
549

Q
q00313334 已提交
550
    /**
Q
q00313334 已提交
551
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0007
Q
q00313334 已提交
552 553 554 555 556 557
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
558 559
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0007', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
560
        let name = bluetooth.setLocalName(Btname.SYMBOL_TEST);
Q
q00313334 已提交
561 562
        console.info('[bluetooth_js] setLocalName result7 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
563
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
564 565
        expect(true).assertTrue(Btname.SYMBOL_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
566 567 568
    })

    /**
Q
q00313334 已提交
569
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0008
Q
q00313334 已提交
570 571 572 573 574 575
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
576 577
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0008', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
578
        let name = bluetooth.setLocalName(Btname.MIXES);
Q
q00313334 已提交
579 580
        console.info('[bluetooth_js] setLocalName result8 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
581
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
582 583
        expect(true).assertTrue(Btname.MIXES == JSON.stringify(localName));
        done();
Q
q00313334 已提交
584 585 586
    })

    /**
Q
q00313334 已提交
587
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0009
Q
q00313334 已提交
588 589 590 591 592 593
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
594 595
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0009', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
596
        let name = bluetooth.setLocalName(Btname.MIXES2);
Q
q00313334 已提交
597 598
        console.info('[bluetooth_js] setLocalName result9 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
599
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
600 601
        expect(true).assertTrue(Btname.MIXES2 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
602 603 604
    })

    /**
Q
q00313334 已提交
605
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00010
Q
q00313334 已提交
606 607 608 609 610 611
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
612 613
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00010', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
614
        let name = bluetooth.setLocalName(Btname.MIXES3);
Q
q00313334 已提交
615 616
        console.info('[bluetooth_js] setLocalName result10 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
617
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
618 619
        expect(true).assertTrue(Btname.MIXES3 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
620 621 622
    })

    /**
Q
q00313334 已提交
623
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00011
Q
q00313334 已提交
624 625 626 627 628 629
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
630 631
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00011', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
632
        let name = bluetooth.setLocalName(Btname.MIXES4);
Q
q00313334 已提交
633 634
        console.info('[bluetooth_js] setLocalName result11 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
635
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
636 637
        expect(true).assertTrue(Btname.MIXES4 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
638 639 640
    })

    /**
Q
q00313334 已提交
641
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00012
Q
q00313334 已提交
642 643 644 645 646 647
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
648 649
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00012', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
650
        let name = bluetooth.setLocalName(Btname.MIXES5);
Q
q00313334 已提交
651 652
        console.info('[bluetooth_js] setLocalName result12 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
653
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
654 655
        expect(true).assertTrue(Btname.MIXES5 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
656 657 658
    })

    /**
Q
q00313334 已提交
659
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013
Q
q00313334 已提交
660 661 662 663 664 665
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
666 667
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
668
        let name = bluetooth.setLocalName(Btname.MIXES6);
Q
q00313334 已提交
669 670
        console.info('[bluetooth_js] setLocalName result13 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
671
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
672 673
        expect(true).assertTrue(Btname.MIXES6 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
674 675
    })

Q
q00313334 已提交
676

Q
q00313334 已提交
677
    /**
Q
q00313334 已提交
678
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014
Q
q00313334 已提交
679 680 681 682 683 684
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
685 686
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
687
        let name = bluetooth.setLocalName(Btname.MIXES7);
Q
q00313334 已提交
688 689
        console.info('[bluetooth_js] setLocalName result14 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
690
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
691 692
        expect(true).assertTrue(Btname.MIXES7 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
693 694 695
    })


Q
q00313334 已提交
696

Q
q00313334 已提交
697
    /**
Q
q00313334 已提交
698
     * @tc.number SUB_COMMUNACATION_bluetooth_DISABLE_0001
Q
q00313334 已提交
699 700 701 702 703 704
     * @tc.name testdisablebluetooth
     * @tc.desc Test disablebluetooth api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
705 706
    it('SUB_COMMUNACATION_bluetooth_DISABLE_0001', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
707
        console.info('[bluetooth_js] disable test start');
Q
q00313334 已提交
708 709 710
        let disable = bluetooth.disableBluetooth();
        console.info('[bluetooth_js] disable:' + JSON.stringify(disable));
        expect(disable).assertTrue();
Q
q00313334 已提交
711
        let state = bluetooth.getState();
Q
q00313334 已提交
712
        console.info('[bluetooth_js] bt state:' + JSON.stringify(state));
Q
q00313334 已提交
713
        done();
Q
q00313334 已提交
714
    })
715 716

})
Q
q00313334 已提交
717

J
jiyong_sd 已提交
718
}