• 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 bluetooth from '@ohos.bluetooth';
17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
18import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest'
19
20let Btname = {
21    NUM_TEST :'012345678901234567890123456789012345678901234567890123'+
22    '45678901234567890123456789012345678901234567890123456789012345678901234567',
23    NUM_TEST1 :'0123456789012345678901234567890123456789012345678901'
24    +'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
25    +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
26    +'01234567890123456789012345678912',
27    LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
28    CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙',
29    CHINESES_TEST2 :'测试蓝牙名称正常',
30    SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×'
31    +'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓',
32    MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw',
33    MIXES2:'——◎◇◆□■△▲测试蓝牙',
34    MIXES3:'78453-、、。。◎◇◆□■△▲',
35    MIXES4:'hhhfdf-、、。。◎◇◆□■△▲',
36    MIXES5:'#01-5@<?;:!@$%^&*(1[]{【+-;:‘’“”测试=》《\'[6]',
37    MIXES6:'#01-567890@<>?/;:5675ASDF012345678!@'
38    +'$%^&*()9012378901[]{}【】566~·67890blue',
39    MIXES7:'0123456789012345678901234567890123456789012345678901'
40    +'23456789012345678901234567890123456789012345678901234567890123456789012345678012'
41    +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568'
42    +'012345678901234567890123456789123'
43}
44export default function btLocalNameTest() {
45describe('btLocalNameTest', function() {
46    function sleep(delay) {
47        return new Promise(resovle => setTimeout(resovle, delay))
48    }
49
50    async function openPhone() {
51        try{
52            let drivers = Driver.create();
53            console.info('[bluetooth_js] bt driver create:'+ drivers);
54            await drivers.delayMs(1000);
55            await drivers.wakeUpDisplay();
56            await drivers.delayMs(5000);
57            await drivers.swipe(1500, 1000, 1500, 100);
58            await drivers.delayMs(10000);
59        } catch (error) {
60            console.info('[bluetooth_js] driver error info:'+ error);
61        }
62    }
63
64    async function clickTheWindow() {
65        try{
66            let driver = Driver.create();
67            console.info('[bluetooth_js] bt driver create:'+ driver);
68            await driver.delayMs(1000);
69            await driver.click(950, 2550);
70            await driver.delayMs(5000);
71            await driver.click(950, 2550);
72            await driver.delayMs(3000);
73        } catch (error) {
74            console.info('[bluetooth_js] driver error info:'+ error);
75        }
76    }
77
78    async function tryToEnableBt() {
79        let sta = bluetooth.getState();
80        switch(sta){
81            case 0:
82                bluetooth.enableBluetooth();
83                await clickTheWindow();
84                await sleep(10000);
85                let sta1 = bluetooth.getState();
86                console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1));
87                break;
88            case 1:
89                console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta));
90                await sleep(3000);
91                break;
92            case 2:
93                console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta));
94                break;
95            case 3:
96                bluetooth.enableBluetooth();
97                await clickTheWindow();
98                await sleep(10000);
99                let sta2 = bluetooth.getState();
100                console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2));
101                break;
102            default:
103                console.info('[bluetooth_js] enable success');
104        }
105    }
106    beforeAll(async function (done) {
107        console.info('beforeAll called')
108        await openPhone();
109        done();
110    })
111    beforeEach(async function(done) {
112        console.info('beforeEach called')
113        await tryToEnableBt()
114        done()
115    })
116    afterEach(function () {
117        console.info('afterEach called')
118    })
119    afterAll(function () {
120        console.info('afterAll called')
121    })
122
123    /**
124     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0100
125     * @tc.name setLocalName
126     * @tc.desc Test setLocalName api by promise.
127     * @tc.type Function
128     * @tc.level Level 1
129     */
130    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0100', 0, async function (done) {
131        let result = bluetooth.setLocalName(Btname.LETTERS_TEST);
132        expect(result).assertTrue();
133        await sleep(1000);
134        let getNewName = bluetooth.getLocalName();
135        console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName));
136        expect(true).assertEqual(Btname.LETTERS_TEST == getNewName);
137        done();
138    })
139
140    /**
141     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0200
142     * @tc.name setLocalName
143     * @tc.desc Test setLocalName api by promise.
144     * @tc.type Function
145     * @tc.level Level 3
146     */
147    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0200', 0, async function (done) {
148        let result = bluetooth.setLocalName(Btname.CHINESES_TEST2);
149        expect(result).assertTrue();
150        await sleep(1000);
151        let getNewName = bluetooth.getLocalName();
152        console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName));
153        expect(true).assertEqual(Btname.CHINESES_TEST2 == getNewName);
154        done();
155    })
156
157    /**
158     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0300
159     * @tc.name setLocalName
160     * @tc.desc Test setLocalName api by promise.
161     * @tc.type Function
162     * @tc.level Level 2
163     */
164    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0300', 0, async function (done) {
165        let result = bluetooth.setLocalName(Btname.NUM_TEST);
166        expect(result).assertTrue();
167        await sleep(1000);
168        let getNewName = bluetooth.getLocalName();
169        console.info('[bluetooth_js] LocalName_0300 NewName = '+ JSON.stringify(getNewName));
170        expect(true).assertEqual(Btname.NUM_TEST == getNewName);
171        done();
172    })
173
174   /**
175     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0400
176     * @tc.name setLocalName
177     * @tc.desc Test setLocalName api by promise.
178     * @tc.type Function
179     * @tc.level Level 1
180     */
181    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0400', 0, async function (done) {
182        let result = bluetooth.setLocalName(Btname.SYMBOL_TEST);
183        expect(result).assertTrue();
184        await sleep(1000);
185        let getNewName = bluetooth.getLocalName();
186        console.info('[bluetooth_js] LocalName_0400 NewName = '+ JSON.stringify(getNewName));
187        expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName);
188        done();
189    })
190
191    /**
192     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0500
193     * @tc.name setLocalName
194     * @tc.desc Test setLocalName api by promise.
195     * @tc.type Function
196     * @tc.level Level 2
197     */
198    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0500', 0, async function (done) {
199        let newName = 'my bluetooth';
200        let result = bluetooth.setLocalName(newName);
201        expect(result).assertTrue();
202        await sleep(1000);
203        let getNewName = bluetooth.getLocalName();
204        console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName));
205        expect(true).assertEqual(newName == getNewName);
206        done();
207    })
208
209    /**
210     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0600
211     * @tc.name setLocalName
212     * @tc.desc Test setLocalName api by promise.
213     * @tc.type Function
214     * @tc.level Level 3
215     */
216    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0600', 0, async function (done) {
217        let newName = 'bluetooth1234ABCDEFGH';
218        let result = bluetooth.setLocalName(newName);
219        expect(result).assertTrue();
220        await sleep(1000);
221        let getNewName = bluetooth.getLocalName();
222        console.info('[bluetooth_js] LocalName_0600 NewName = '+ JSON.stringify(getNewName));
223        expect(true).assertEqual(newName == getNewName);
224        done();
225    })
226
227    /**
228     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0700
229     * @tc.name TEST setLocalName
230     * @tc.desc TEST setLocalName api by promise.
231     * @tc.type Function
232     * @tc.level Level 3
233     */
234    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0700', 0, async function (done) {
235        let newName = '蓝牙设备bluetooth';
236        let result = bluetooth.setLocalName(newName);
237        expect(result).assertTrue();
238        await sleep(1000);
239        let getNewName = bluetooth.getLocalName();
240        console.info('[bluetooth_js] LocalName_0700 NewName = '+ JSON.stringify(getNewName));
241        expect(true).assertEqual(newName == getNewName);
242        done();
243    })
244
245    /**
246     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0800
247     * @tc.name TEST setLocalName
248     * @tc.desc TEST setLocalName api by promise.
249     * @tc.type Function
250     * @tc.level Level 3
251     */
252     it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0800', 0, async function (done) {
253        let result = bluetooth.setLocalName(Btname.MIXES4);
254        expect(result).assertTrue();
255        await sleep(1000);
256        let getNewName = bluetooth.getLocalName();
257        console.info('[bluetooth_js] LocalName_0800 NewName = '+ JSON.stringify(getNewName));
258        expect(true).assertEqual(Btname.MIXES4 == getNewName);
259        done();
260    })
261
262    /**
263     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0900
264     * @tc.name TEST setLocalName
265     * @tc.desc TEST setLocalName api by promise.
266     * @tc.type Function
267     * @tc.level Level 3
268     */
269    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_0900', 0, async function (done) {
270        let result = bluetooth.setLocalName(Btname.MIXES2);
271        expect(result).assertTrue();
272        await sleep(1000);
273        let getNewName = bluetooth.getLocalName();
274        console.info('[bluetooth_js] LocalName_0900 NewName = '+ JSON.stringify(getNewName));
275        expect(true).assertEqual(Btname.MIXES2 == getNewName);
276        done();
277    })
278
279    /**
280     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1000
281     * @tc.name TEST setLocalName
282     * @tc.desc TEST setLocalName api by promise.
283     * @tc.type Function
284     * @tc.level Level 3
285     */
286    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1000', 0, async function (done) {
287        let result = bluetooth.setLocalName(Btname.MIXES3);
288        expect(result).assertTrue();
289        await sleep(1000);
290        let getNewName = bluetooth.getLocalName();
291        console.info('[bluetooth_js] LocalName_1000 NewName = '+ JSON.stringify(getNewName));
292        expect(true).assertEqual(Btname.MIXES3 == getNewName);
293        done();
294    })
295
296    /**
297     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1100
298     * @tc.name TEST setLocalName
299     * @tc.desc TEST setLocalName api by promise.
300     * @tc.type Function
301     * @tc.level Level 2
302     */
303    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1100', 0, async function (done) {
304        let newName = '蓝牙设备123';
305        let result = bluetooth.setLocalName(newName);
306        expect(result).assertTrue();
307        await sleep(1000);
308        let getNewName = bluetooth.getLocalName();
309        console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName));
310        expect(true).assertEqual(newName == getNewName);
311        done();
312    })
313
314    /**
315     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1200
316     * @tc.name TEST setLocalName
317     * @tc.desc TEST setLocalName api by promise.
318     * @tc.type Function
319     * @tc.level Level 3
320     */
321    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1200', 0, async function (done) {
322        let newName = '蓝牙设备bluetooth12';
323        let result = bluetooth.setLocalName(newName);
324        expect(result).assertTrue();
325        await sleep(1000);
326        let getNewName = bluetooth.getLocalName();
327        console.info('[bluetooth_js] LocalName1200 NewName = '+ JSON.stringify(getNewName));
328        expect(true).assertEqual(newName == getNewName);
329        done();
330    })
331
332    /**
333     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1300
334     * @tc.name TEST setLocalName
335     * @tc.desc TEST setLocalName api by promise.
336     * @tc.type Function
337     * @tc.level Level 3
338     */
339      it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1300', 0, async function (done) {
340        let result = bluetooth.setLocalName(Btname.MIXES6);
341        expect(result).assertTrue();
342        await sleep(1000);
343        let getNewName = bluetooth.getLocalName();
344        console.info('[bluetooth_js] LocalName_1300 NewName = '+ JSON.stringify(getNewName));
345        expect(true).assertEqual(Btname.MIXES6 == getNewName);
346        done();
347    })
348
349    /**
350     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1400
351     * @tc.name TEST setLocalName
352     * @tc.desc TEST setLocalName api by promise.
353     * @tc.type Function
354     * @tc.level Level 3
355     */
356    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1400', 0, async function (done) {
357        let result = bluetooth.setLocalName(Btname.MIXES);
358        expect(result).assertTrue();
359        await sleep(1000);
360        let getNewName = bluetooth.getLocalName();
361        console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName));
362        expect(true).assertEqual(Btname.MIXES == getNewName);
363
364        done();
365    })
366
367    /**
368     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1500
369     * @tc.name TEST setLocalName
370     * @tc.desc TEST setLocalName api by promise.
371     * @tc.type Function
372     * @tc.level Level 3
373     */
374    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1500', 0, async function (done) {
375        let result = bluetooth.setLocalName(Btname.MIXES5);
376        expect(result).assertTrue();
377        await sleep(1000);
378        let getNewName = bluetooth.getLocalName();
379        console.info('[bluetooth_js] LocalName_1500 NewName = '+ JSON.stringify(getNewName));
380        expect(true).assertEqual(Btname.MIXES5 == getNewName);
381        done();
382    })
383
384    /**
385     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1600
386     * @tc.name TEST setLocalName
387     * @tc.desc TEST setLocalName api by promise.
388     * @tc.type Function
389     * @tc.level Level 3
390     */
391    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1600', 0, async function (done) {
392        let result = bluetooth.setLocalName(Btname.NUM_TEST1);
393        expect(result).assertTrue();
394        await sleep(1000);
395        let getNewName = bluetooth.getLocalName();
396        console.info('[bluetooth_js] LocalName_1600 NewName = '+ JSON.stringify(getNewName));
397        expect(true).assertEqual(Btname.NUM_TEST1 == getNewName);
398        done();
399    })
400
401    /**
402     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1700
403     * @tc.name TEST setLocalName
404     * @tc.desc TEST setLocalName api by promise.
405     * @tc.type Function
406     * @tc.level Level 3
407     */
408    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1700', 0, async function (done) {
409        let result = bluetooth.setLocalName(Btname.MIXES7);
410        expect(result).assertTrue();
411        await sleep(1000);
412        let getNewName = bluetooth.getLocalName();
413        console.info('[bluetooth_js] LocalName_1700 NewName = '+ JSON.stringify(getNewName));
414        expect(false).assertEqual(Btname.MIXES7 == getNewName);
415        done();
416    })
417
418    /**
419     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1800
420     * @tc.name TEST setLocalName
421     * @tc.desc TEST setLocalName api by promise.
422     * @tc.type Function
423     * @tc.level Level 3
424     */
425    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1800', 0, async function (done) {
426        let name = bluetooth.getLocalName();
427        let set = bluetooth.setLocalName('');
428        expect(set).assertFalse();
429        await sleep(1000);
430        let localName = bluetooth.getLocalName();
431        expect(true).assertTrue(localName==name);
432        console.info('[bluetooth_js] getLocalName1800=' + JSON.stringify(localName));
433        done();
434    })
435
436    /**
437     * @tc.number SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1900
438     * @tc.name set LocalName
439     * @tc.desc Test setLocalName api by promise.
440     * @tc.type Function
441     * @tc.level Level 3
442     */
443    it('SUB_COMMUNICATION_BLUETOOTH_LOCALNAME_1900', 0, async function (done) {
444        let localName = bluetooth.getLocalName();
445        console.info('[bluetooth_js] LocalName_1900 localName = '+ JSON.stringify(localName));
446        expect(true).assertEqual(localName!=null);
447        let newName = 'bluetoothtest';
448        let result = bluetooth.setLocalName(newName);
449        expect(result).assertTrue();
450        await sleep(1000);
451        let getNewName = bluetooth.getLocalName();
452        console.info('[bluetooth_js] LocalName_1900 NewName = '+ JSON.stringify(getNewName));
453        expect(true).assertEqual(newName == getNewName);
454        let result1=bluetooth.setLocalName(localName);
455        expect(result1).assertTrue();
456        await sleep(1000);
457        let getLocalName = bluetooth.getLocalName();
458        console.info('[bluetooth_js] LocalNam1900 localName ='+ JSON.stringify(getLocalName));
459        expect(true).assertEqual(localName == getLocalName);
460        done();
461    })
462
463})
464}