BRSetLocalName.test.js 16.8 KB
Newer Older
Q
quanli 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * 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';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let Btname = {
    NUM_TEST :'012345678901234567890123456789012345678901234567890123'+
    '45678901234567890123456789012345678901234567890123456789012345678901234567',
    NUM_TEST1 :'0123456789012345678901234567890123456789012345678901'
    +'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
    +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
    +'01234567890123456789012345678912',
    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'
    +'012345678901234567890123456789123'
}
export default function bluetoothhostTest1() {
describe('bluetoothhostTest1', function() {
    function sleep(delay) {
        return new Promise(resovle => setTimeout(resovle, delay))
    }
    async function tryToEnableBt() {
        let sta = bluetooth.getState();
        switch(sta){
            case 0:
                bluetooth.enableBluetooth();
                await sleep(5000);
                let sta1 = bluetooth.getState();
                console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1));
                break;
            case 1:
                console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta));
                await sleep(3000);
                break;
            case 2:
                console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta));
                break;
            case 3:
                bluetooth.enableBluetooth();
                await sleep(3000);
                let sta2 = bluetooth.getState();
                console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2));
                break;
            default:
                console.info('[bluetooth_js] enable success');
        }
    }
    beforeAll(function () {
        console.info('beforeAll called')
    })
    beforeEach(async function(done) {
        console.info('beforeEach called')
        await tryToEnableBt()
        done()
    })
    afterEach(function () {
        console.info('afterEach called')
    })
    afterAll(function () {
        console.info('afterAll called')
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
94
     * @tc.level Level 1 
Q
quanli 已提交
95 96
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100', 0, async function (done) {
Q
quanli 已提交
97
        let result = bluetooth.setLocalName(Btname.LETTERS_TEST);
Q
quanli 已提交
98 99 100
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
101
        expect(true).assertEqual(Btname.LETTERS_TEST == getNewName);
Q
quanli 已提交
102 103 104 105 106 107 108 109 110 111
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
112
     * @tc.level Level 3
Q
quanli 已提交
113 114
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200', 0, async function (done) {
Q
quanli 已提交
115
        let result = bluetooth.setLocalName(Btname.CHINESES_TEST);
Q
quanli 已提交
116 117 118
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
119
        expect(true).assertEqual(Btname.CHINESES_TEST == getNewName);
Q
quanli 已提交
120 121 122 123 124 125 126 127 128 129
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
130
     * @tc.level Level 2
Q
quanli 已提交
131 132
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300', 0, async function (done) {
Q
quanli 已提交
133
        let result = bluetooth.setLocalName(Btname.NUM_TEST);
Q
quanli 已提交
134 135 136
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0300 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
137
        expect(true).assertEqual(Btname.NUM_TEST == getNewName);
Q
quanli 已提交
138 139 140
        done();
    })

Q
quanli 已提交
141
   /**
Q
quanli 已提交
142 143 144 145 146 147
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
148
     * @tc.level Level 1
Q
quanli 已提交
149 150
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400', 0, async function (done) {
Q
quanli 已提交
151
        let result = bluetooth.setLocalName(Btname.SYMBOL_TEST);
Q
quanli 已提交
152 153 154
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0400 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
155
        expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName);
Q
quanli 已提交
156 157 158
        done();
    })

Q
quanli 已提交
159
    /**
Q
quanli 已提交
160 161 162 163 164 165
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
166
     * @tc.level Level 2
Q
quanli 已提交
167 168
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) {
Q
quanli 已提交
169 170
        let newName = 'my bluetooth';
        let result = bluetooth.setLocalName(newName);
Q
quanli 已提交
171 172 173
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
174
        expect(true).assertEqual(newName == getNewName);
Q
quanli 已提交
175 176 177 178 179 180 181 182 183 184
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600
     * @tc.name setLocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
185
     * @tc.level Level 3
Q
quanli 已提交
186 187
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) {
Q
quanli 已提交
188
        let newName = 'bluetooth1234ABCDEFGH';
Q
quanli 已提交
189 190 191 192 193 194 195 196 197 198
        let result = bluetooth.setLocalName(newName);
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0600 NewName = '+ JSON.stringify(getNewName));
        expect(true).assertEqual(newName == getNewName);
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700
Q
quanli 已提交
199 200
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
Q
quanli 已提交
201 202 203 204 205 206
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) {
Q
quanli 已提交
207
        let newName = '蓝牙设备bluetooth';
Q
quanli 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
        let result = bluetooth.setLocalName(newName);
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0700 NewName = '+ JSON.stringify(getNewName));
        expect(true).assertEqual(newName == getNewName);
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
Q
quanli 已提交
225 226
     it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800', 0, async function (done) {
        let result = bluetooth.setLocalName(Btname.MIXES4);
Q
quanli 已提交
227 228 229
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0800 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
230
        expect(true).assertEqual(Btname.MIXES4 == getNewName);
Q
quanli 已提交
231 232 233 234 235 236 237 238 239 240 241 242
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
Q
quanli 已提交
243 244
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900', 0, async function (done) {
        let result = bluetooth.setLocalName(Btname.MIXES2);
Q
quanli 已提交
245 246 247
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_0900 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
248
        expect(true).assertEqual(Btname.MIXES2 == getNewName);
Q
quanli 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000', 0, async function (done) {
Q
quanli 已提交
262
        let result = bluetooth.setLocalName(Btname.MIXES3);
Q
quanli 已提交
263 264 265
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1000 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
266
        expect(true).assertEqual(Btname.MIXES3 == getNewName);
Q
quanli 已提交
267 268 269 270 271 272 273 274 275 276
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
277
     * @tc.level Level 2
Q
quanli 已提交
278 279
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) {
Q
quanli 已提交
280 281
        let newName = '蓝牙设备123';
        let result = bluetooth.setLocalName(newName);
Q
quanli 已提交
282 283 284
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
285
        expect(true).assertEqual(newName == getNewName);
Q
quanli 已提交
286 287 288 289 290 291 292 293 294 295
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
Q
quanli 已提交
296
     * @tc.level Level 3
Q
quanli 已提交
297 298
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) {
Q
quanli 已提交
299
        let newName = '蓝牙设备bluetooth12';
Q
quanli 已提交
300 301 302
        let result = bluetooth.setLocalName(newName);
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
Q
quanli 已提交
303
        console.info('[bluetooth_js] LocalName1200 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316
        expect(true).assertEqual(newName == getNewName);
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
Q
quanli 已提交
317 318
      it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300', 0, async function (done) {
        let result = bluetooth.setLocalName(Btname.MIXES6);
Q
quanli 已提交
319 320 321
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1300 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
322
        expect(true).assertEqual(Btname.MIXES6 == getNewName);
Q
quanli 已提交
323 324 325 326 327 328 329 330 331 332 333 334
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
Q
quanli 已提交
335 336
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) {
        let result = bluetooth.setLocalName(Btname.MIXES);
Q
quanli 已提交
337 338 339
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
340 341
        expect(true).assertEqual(Btname.MIXES == getNewName);
        
Q
quanli 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500', 0, async function (done) {
Q
quanli 已提交
355
        let result = bluetooth.setLocalName(Btname.MIXES5);
Q
quanli 已提交
356 357 358
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1500 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
359
        expect(true).assertEqual(Btname.MIXES5 == getNewName);
Q
quanli 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600', 0, async function (done) {
Q
quanli 已提交
373
        let result = bluetooth.setLocalName(Btname.NUM_TEST1);
Q
quanli 已提交
374 375 376
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1600 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
377
        expect(true).assertEqual(Btname.NUM_TEST1 == getNewName);
Q
quanli 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700', 0, async function (done) {
Q
quanli 已提交
391
        let result = bluetooth.setLocalName(Btname.MIXES7);
Q
quanli 已提交
392 393 394
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1700 NewName = '+ JSON.stringify(getNewName));
Q
quanli 已提交
395
        expect(false).assertEqual(Btname.MIXES7 == getNewName);
Q
quanli 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800
     * @tc.name TEST setLocalName
     * @tc.desc TEST setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800', 0, async function (done) {
Q
quanli 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
        let name = bluetooth.getLocalName();
        let set = bluetooth.setLocalName('');
        expect(set).assertFalse();
        let localName = bluetooth.getLocalName();
        expect(true).assertTrue(localName==name);
        console.info('[bluetooth_js] getLocalName1800=' + JSON.stringify(localName));
        done();
    })

    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1900
     * @tc.name set LocalName
     * @tc.desc Test setLocalName api by promise.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1900', 0, async function (done) {
        let localName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalName_1900 localName = '+ JSON.stringify(localName));
        expect(true).assertEqual(localName!=null);
        let newName = 'bluetoothtest';
        let result = bluetooth.setLocalName(newName);
Q
quanli 已提交
433 434
        expect(result).assertTrue();
        let getNewName = bluetooth.getLocalName();
Q
quanli 已提交
435 436 437 438 439 440 441
        console.info('[bluetooth_js] LocalName_1900 NewName = '+ JSON.stringify(getNewName));
        expect(true).assertEqual(newName == getNewName);
        let result1=bluetooth.setLocalName(localName);
        expect(result1).assertTrue();
        let getLocalName = bluetooth.getLocalName();
        console.info('[bluetooth_js] LocalNam1900 localName ='+ JSON.stringify(getLocalName));
        expect(true).assertEqual(localName == getLocalName);
Q
quanli 已提交
442 443 444 445 446 447
        done();
    })

})
}

Q
quanli 已提交
448