Bluetooth.test.js 27.5 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();
H
hwx951322 已提交
100 101 102 103 104 105 106 107 108 109 110
        let BluetoothState=
        {
            STATE_OFF : 0,
            STATE_TURNING_ON : 1,
            STATE_ON : 2,
            STATE_TURNING_OFF : 3,
            STATE_BLE_TURNING_ON : 4,
            STATE_BLE_ON : 5,
            STATE_BLE_TURNING_OFF : 6,
		} ;
		console.info('[bluetooth_js] get bluetooth state result = '+ JSON.stringify(state));
111
        expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON);
H
hwx951322 已提交
112 113 114 115 116 117
        expect(BluetoothState.STATE_OFF != state).assertTrue();
        expect(BluetoothState.STATE_TURNING_ON != state).assertTrue();
        expect(BluetoothState.STATE_TURNING_OFF != state).assertTrue();
        expect(BluetoothState.STATE_BLE_TURNING_ON != state).assertTrue();
        expect(BluetoothState.STATE_BLE_ON != state).assertTrue();
        expect(BluetoothState.STATE_BLE_TURNING_OFF != state).assertTrue();
Q
q00313334 已提交
118
        done();
119 120
    })

Q
q00313334 已提交
121

122
    /**
Q
q00313334 已提交
123
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001
124 125 126 127 128 129
     * @tc.name testClassicSetLocalName
     * @tc.desc Test ClassicSetLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
130
    it('SUB_COMMUNACATION_bluetooth_SET_LOCALNAME_0001', 0, async function (done) {
Q
q00313334 已提交
131
        console.info('[bluetooth_js] set localname start');
Q
q00313334 已提交
132
        await tryToEnableBt();
Q
q00313334 已提交
133
        let name = bluetooth.setLocalName('bluetooth_test');
Q
q00313334 已提交
134 135
        console.info('[bluetooth_js] appInfoTest enable bluetooth result = '+ JSON.stringify(name));
        expect(name).assertEqual(true);
Q
q00313334 已提交
136
        done();
Q
q00313334 已提交
137
    })
138

Q
q00313334 已提交
139
    /**
Q
q00313334 已提交
140
     * @tc.number SUB_COMMUNACATION_bluetooth_START_PAIR_0001
Q
q00313334 已提交
141 142 143 144 145 146
     * @tc.name testStartpair
     * @tc.desc Test Startpair api by promise.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
147
    it('SUB_COMMUNACATION_bluetooth_START_PAIR_0001', 0, async function (done) {
Q
q00313334 已提交
148
        console.info('[bluetooth_js] Startpair test start ...');
Q
q00313334 已提交
149
        await tryToEnableBt();
Q
q00313334 已提交
150
        let result = bluetooth.pairDevice("00:00:00:00:00:00");
Q
q00313334 已提交
151 152
        console.info("[bluetooth_js] onStartpair -> " + JSON.stringify(result));
        expect(result).assertFalse();
Q
q00313334 已提交
153
        done();
154 155 156
    })

    /**
Q
q00313334 已提交
157
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001
158 159 160 161 162 163
     * @tc.name testClassicGetLocalName
     * @tc.desc Test ClassicGetLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
164
    it('SUB_COMMUNACATION_bluetooth_GET_LOCALNAME_0001', 0, async function (done) {
Q
q00313334 已提交
165
        console.info('[bluetooth_js] get localName start');
Q
q00313334 已提交
166
        await tryToEnableBt();
Q
q00313334 已提交
167
        let localName = bluetooth.getLocalName();
168 169
        console.info('[bluetooth_js] get local Name result = ' + JSON.stringify(localName));
        expect(localName).assertEqual('bluetooth_test');
Q
q00313334 已提交
170
        done();
171 172 173
    })

    /**
Q
q00313334 已提交
174
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001
175 176 177 178 179 180
     * @tc.name testClassicSetBluetoothScanMode
     * @tc.desc Test ClassicSetBluetoothScanMode api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
181
    it('SUB_COMMUNACATION_bluetooth_SET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
Q
q00313334 已提交
182
        console.info('[bluetooth_js] set scan mode start');
Q
q00313334 已提交
183
        await tryToEnableBt();
Q
q00313334 已提交
184
        let result = bluetooth.setBluetoothScanMode(1,10000);
H
hwx951322 已提交
185 186 187 188 189 190 191 192 193
        let ScanDuty=
        {
            SCAN_MODE_LOW_POWER : 0,
            SCAN_MODE_BALANCED : 1,
            SCAN_MODE_BALANCED : 2,
        };
		expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_LOW_POWER) !=result );
        expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_BALANCED) != result);
        expect(true).assertTrue(JSON.stringify(ScanDuty.SCAN_MODE_BALANCED) != result );
194
        expect(result).assertEqual(true);
Q
q00313334 已提交
195
        done();
196 197 198
    })

    /**
Q
q00313334 已提交
199
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001
200 201 202 203 204 205
     * @tc.name testClassicGetBluetoothScanMode
     * @tc.desc Test ClassicGetBluetoothScanMode api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
206
    it('SUB_COMMUNACATION_bluetooth_GET_BLUETOOTH_SCAN_MODE_0001', 0, async function (done) {
Q
q00313334 已提交
207
        console.info('[bluetooth_js] get scan mode start');
Q
q00313334 已提交
208
        await tryToEnableBt();
Q
q00313334 已提交
209
        let result = bluetooth.setBluetoothScanMode(1,10000);
210
        expect(result).assertEqual(true);
H
hwx951322 已提交
211 212 213 214 215 216 217 218 219 220 221 222
        let ScanMode=
        {
            SCAN_MODE_NONE : 0,
            SCAN_MODE_CONNECTABLE : 1,
            SCAN_MODE_GENERAL_DISCOVERABLE : 2,
            SCAN_MODE_LIMITED_DISCOVERABLE : 3,
            SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
            SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
		};
        let scanModeResult = bluetooth.getBluetoothScanMode();
        console.info('[bluetooth_js] get scan mode result2 = ' + JSON.stringify(scanModeResult));
        expect(scanModeResult).assertEqual(1);
H
comm1  
hwx951322 已提交
223 224 225 226 227 228
        expect(true).assertTrue(ScanMode.SCAN_MODE_NONE != scanModeResult);
        expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE != scanModeResult);
        expect(true).assertTrue(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE != scanModeResult);
        expect(true).assertTrue(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE != scanModeResult);
        expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE != scanModeResult);
        expect(true).assertTrue(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE != scanModeResult);
Q
q00313334 已提交
229 230 231 232 233
        done();
    })

    /**
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001
234 235 236 237 238 239
     * @tc.name testClassicGetBtConnectionState
     * @tc.desc Test ClassicGetBtConnectionState api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
240
    it('SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001', 0, async function (done) {
Q
q00313334 已提交
241
        console.info('[bluetooth_js] get connection state start');
Q
q00313334 已提交
242
        await tryToEnableBt();
H
hwx951322 已提交
243 244 245 246 247 248 249
        let ProfileConnectionState=
        {
            STATE_CONNECTING : 1,
            STATE_CONNECTED : 2,
            STATE_DISCONNECTED : 0,
            STATE_DISCONNECTING : 3,
        };
Q
q00313334 已提交
250
        let connState = bluetooth.getBtConnectionState();
251
        console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState));
H
hwx951322 已提交
252 253 254 255
        expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED);
        expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState );
        expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState );
        expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState );
Q
q00313334 已提交
256
        done();
257 258 259
    })

    /**
Q
q00313334 已提交
260
     * @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001
261 262 263 264 265 266
     * @tc.name testClassicStartBluetoothDiscovery
     * @tc.desc Test ClassicStartBluetoothDiscovery api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
267
    it('SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
Q
q00313334 已提交
268
        console.info('[bluetooth_js] discovery start');
Q
q00313334 已提交
269
        await tryToEnableBt();
Q
q00313334 已提交
270 271 272
        let result = bluetooth.startBluetoothDiscovery();
        console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(result));
        expect(result).assertEqual(true);
Q
q00313334 已提交
273
        done();
274 275 276
    })

    /**
Q
q00313334 已提交
277
     * @tc.number SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001
278 279 280 281 282 283
     * @tc.name testClassicStopBluetoothDiscovery
     * @tc.desc Test ClassicStopBluetoothDiscovery api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
284
    it('SUB_COMMUNACATION_bluetooth_STOP_BLUETOOTH_DISCOVERY_0001', 0, async function (done) {
Q
q00313334 已提交
285
        console.info('[bluetooth_js] stop discovery start');
Q
q00313334 已提交
286
        await tryToEnableBt();
Q
q00313334 已提交
287 288 289
        let result = bluetooth.stopBluetoothDiscovery();
        console.info("stopBluetoothDiscovery :" + JSON.stringify(result));
        expect(result).assertTrue();
Q
q00313334 已提交
290
        done();
291 292 293
    })

    /**
Q
q00313334 已提交
294
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001
295 296 297 298 299 300
     * @tc.name testClassicGetPairedDevices
     * @tc.desc Test ClassicGetPairedDevices api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
301
    it('SUB_COMMUNACATION_bluetooth_GET_PAIRED_DEVICES_0001', 0, async function (done) {
Q
q00313334 已提交
302
        console.info('[bluetooth_js] get paired devices start');
Q
q00313334 已提交
303
        await tryToEnableBt();
Q
q00313334 已提交
304
        let devices = bluetooth.getPairedDevices();
Q
q00313334 已提交
305
        console.info('[bluetooth_js] get paired devices:' + JSON.stringify(devices) +'length:' + devices.length);
306
        expect(devices.length).assertEqual(0);
Q
q00313334 已提交
307
        done();
308 309
    })

310

311
    /**
Q
q00313334 已提交
312
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
313 314 315 316 317 318
     * @tc.name testSppListen
     * @tc.desc Test SppListen api by callback.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
319
    it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) {
Q
q00313334 已提交
320
        console.log("[bluetooth_js]: spp listen start");
Q
q00313334 已提交
321
        await tryToEnableBt();
322
        let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
Q
q00313334 已提交
323
            secure: false, type: 0};
324
        bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) {
Q
q00313334 已提交
325
            console.info('[bluetooth_js] code is: ' + code.code);
326 327 328 329 330 331 332 333 334 335 336
            if (code.code == 0) {
                expect(true).assertEqual(true);
                done();
            } else {
                expect(true).assertEqual(false);
                done();
            }
        });
    })

    /**
Q
q00313334 已提交
337
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001
338 339 340 341 342 343
     * @tc.name testSppAccept
     * @tc.desc Test SppAccept api by callbck.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
344
    it('SUB_COMMUNACATION_bluetooth_SPP_ACCEPT_0001', 0, async function (done) {
Q
q00313334 已提交
345
        console.log("[bluetooth_js] spp accept start");
Q
q00313334 已提交
346
        await tryToEnableBt();
347
        bluetooth.sppAccept(-1, function(code, clientSocketNumber) {
Q
q00313334 已提交
348
            console.info('[bluetooth_js] code is: ' + code.code);
349 350 351 352 353 354 355 356 357 358
            if (code.code == 0) {
                expect(true).assertEqual(true);
            } else {
                expect(true).assertEqual(false);
            }
        });
        done();
    })

    /**
Q
q00313334 已提交
359
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001
360 361 362 363 364 365
     * @tc.name testSppCloseServerSocket
     * @tc.desc Test SppCloseServerSocket api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
366
    it('SUB_COMMUNACATION_bluetooth_SPP_CLOSE_SERVER_SOCKET_0001', 0, async function (done) {
Q
q00313334 已提交
367
        console.log("[bluetooth_js] spp closeServerSocket start");
Q
q00313334 已提交
368
        await tryToEnableBt();
Q
q00313334 已提交
369 370 371
	setTimeout(async ()=>{
            bluetooth.sppCloseServerSocket(-1);
	},3000);
Q
q00313334 已提交
372
        done();
373 374 375
    })

    /**
Q
q00313334 已提交
376
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001
377 378 379 380 381 382
     * @tc.name testSppConnect
     * @tc.desc Test SppConnect api by callback.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
383
    it('SUB_COMMUNACATION_bluetooth_SPP_CONNECT_0001', 0, async function (done) {
Q
q00313334 已提交
384
        console.info('[bluetooth_js] spp_connect start');
Q
q00313334 已提交
385
        await tryToEnableBt();
386 387 388
        let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
            secure: true, type: 0};
        bluetooth.sppConnect(55, sppOption, function(code, clientSocketNumber) {
Q
q00313334 已提交
389
            console.info('[bluetooth_js] code is: ' + code.code);
390 391 392 393 394 395 396 397 398 399
            if (code.code == 0) {
                expect(true).assertEqual(true);
            } else {
                expect(true).assertEqual(false);
            }
        });
        done();
    })

    /**
Q
q00313334 已提交
400
     * @tc.number SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001
401 402 403 404 405 406
     * @tc.name testSppWrite
     * @tc.desc Test SppWrite api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
407
    it('SUB_COMMUNACATION_bluetooth_SPP_WRITE_0001', 0, async function (done) {
Q
q00313334 已提交
408
        console.info('[bluetooth_js] spp write start');
Q
q00313334 已提交
409
        await tryToEnableBt();
410 411 412 413 414 415
        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 已提交
416
        done();
417 418
    })

Q
q00313334 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    /**
     * @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 已提交
438
    /**
Q
q00313334 已提交
439
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001
Q
q00313334 已提交
440 441 442 443 444 445
     * @tc.name testGetRemoteDeviceName
     * @tc.desc Test GetRemoteDeviceName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
446
    it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_NAME_0001', 0, async function (done) {
Q
q00313334 已提交
447
        console.info('[bluetooth_js] getRemoteDeviceName start');
Q
q00313334 已提交
448
        await tryToEnableBt();
Q
q00313334 已提交
449 450 451
        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 已提交
452
        done();
Q
q00313334 已提交
453 454 455
    })

    /**
Q
q00313334 已提交
456
     * @tc.number SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001
Q
q00313334 已提交
457 458 459 460 461 462
     * @tc.name testGetRemoteDeviceClass
     * @tc.desc Test GetRemoteDeviceClass api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
463
    it('SUB_COMMUNACATION_bluetooth_GET_REMO_DEV_CLASS_0001', 0, async function (done) {
Q
q00313334 已提交
464
        console.info('[bluetooth_js] getRemoteDeviceClass start');
Q
q00313334 已提交
465
        await tryToEnableBt();
Q
q00313334 已提交
466
        let ret = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00");
Q
q00313334 已提交
467 468
        console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(ret) + 'majorClass:' +
        ret.majorClass + 'majorMinorClass:'+ ret.majorMinorClass + 'classOfDevice:' + ret.classOfDevice);
Q
q00313334 已提交
469
        expect(ret.majorClass).assertEqual(0);
Q
q00313334 已提交
470
        done();
Q
q00313334 已提交
471 472 473 474
    })


    /**
Q
q00313334 已提交
475
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001
Q
q00313334 已提交
476 477 478 479 480 481
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
482 483
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0001', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
484 485 486
        let name = bluetooth.getLocalName();
        let set = bluetooth.setLocalName('');
        expect(set).assertFalse();
Q
q00313334 已提交
487
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
488
        expect(true).assertTrue(localName==name);
Q
q00313334 已提交
489
        console.info('[bluetooth_js] getLocalName result1 = ' + JSON.stringify(localName));
Q
q00313334 已提交
490
        done();
Q
q00313334 已提交
491 492 493 494
    })


    /**
Q
q00313334 已提交
495
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002
Q
q00313334 已提交
496 497 498 499 500 501
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
502 503
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0002', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
504 505
        let localName = bluetooth.getLocalName();
        let name = bluetooth.setLocalName();
Q
q00313334 已提交
506 507
        console.info('[bluetooth_js] getName result2 = '+ JSON.stringify(localName) +
        'setName result2 =' + JSON.stringify(name));
Q
q00313334 已提交
508
        expect(name).assertFalse();
Q
q00313334 已提交
509
        done();
Q
q00313334 已提交
510 511 512
    })

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

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

    /**
Q
q00313334 已提交
547
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005
Q
q00313334 已提交
548 549 550 551 552 553
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
554 555
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0005', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
556
        let name = bluetooth.setLocalName(Btname.LETTERS_TEST);
Q
q00313334 已提交
557
        expect(name).assertTrue();
Q
q00313334 已提交
558
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
559 560
        expect(true).assertTrue(Btname.LETTERS_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
561 562
    })

Q
q00313334 已提交
563

Q
q00313334 已提交
564
    /**
Q
q00313334 已提交
565
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006
Q
q00313334 已提交
566 567 568 569 570 571
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
572 573
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_0006', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
574
        let name = bluetooth.setLocalName(Btname.CHINESES_TEST);
Q
q00313334 已提交
575
        expect(name).assertTrue();
Q
q00313334 已提交
576
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
577 578
        expect(true).assertTrue(Btname.CHINESES_TEST == JSON.stringify(localName));
        done();
Q
q00313334 已提交
579 580
    })

Q
q00313334 已提交
581

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

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

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

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

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

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

    /**
Q
q00313334 已提交
691
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013
Q
q00313334 已提交
692 693 694 695 696 697
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
698 699
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00013', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
700
        let name = bluetooth.setLocalName(Btname.MIXES6);
Q
q00313334 已提交
701 702
        console.info('[bluetooth_js] setLocalName result13 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
703
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
704 705
        expect(true).assertTrue(Btname.MIXES6 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
706 707
    })

Q
q00313334 已提交
708

Q
q00313334 已提交
709
    /**
Q
q00313334 已提交
710
     * @tc.number SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014
Q
q00313334 已提交
711 712 713 714 715 716
     * @tc.name testsetLocalName
     * @tc.desc Test setLocalName api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
717 718
    it('SUB_COMMUNACATION_bluetooth_SET_LOCAL_NAME_00014', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
719
        let name = bluetooth.setLocalName(Btname.MIXES7);
Q
q00313334 已提交
720 721
        console.info('[bluetooth_js] setLocalName result14 = '+ JSON.stringify(name));
        expect(name).assertTrue();
Q
q00313334 已提交
722
        let localName = bluetooth.getLocalName();
Q
q00313334 已提交
723 724
        expect(true).assertTrue(Btname.MIXES7 == JSON.stringify(localName));
        done();
Q
q00313334 已提交
725 726 727
    })


Q
q00313334 已提交
728

Q
q00313334 已提交
729
    /**
Q
q00313334 已提交
730
     * @tc.number SUB_COMMUNACATION_bluetooth_DISABLE_0001
Q
q00313334 已提交
731 732 733 734 735 736
     * @tc.name testdisablebluetooth
     * @tc.desc Test disablebluetooth api.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
q00313334 已提交
737 738
    it('SUB_COMMUNACATION_bluetooth_DISABLE_0001', 0, async function (done) {
        await tryToEnableBt();
Q
q00313334 已提交
739
        console.info('[bluetooth_js] disable test start');
Q
q00313334 已提交
740 741 742
        let disable = bluetooth.disableBluetooth();
        console.info('[bluetooth_js] disable:' + JSON.stringify(disable));
        expect(disable).assertTrue();
Q
q00313334 已提交
743
        let state = bluetooth.getState();
Q
q00313334 已提交
744
        console.info('[bluetooth_js] bt state:' + JSON.stringify(state));
Q
q00313334 已提交
745
        done();
Q
q00313334 已提交
746
    })
747 748

})
Q
q00313334 已提交
749

J
jiyong_sd 已提交
750
}