• 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
17
18import wifi from '@ohos.wifi'
19import osaccount from '@ohos.account.osAccount'
20import bundle from '@ohos.bundle'
21import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
22
23async function applyPermission() {
24    let osAccountManager = osaccount.getAccountManager();
25    console.info("=== getAccountManager finish");
26    let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
27    console.info("LocalId is :" + localId);
28    let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 0, localId);
29    let atManager = abilityAccessCtrl.createAtManager();
30    if (atManager != null) {
31        let tokenID = appInfo.accessTokenId;
32        console.info('[permission] case accessTokenID is ' + tokenID);
33        let permissionName1 = 'ohos.permission.LOCATION';
34        await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
35            console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
36        }).catch((err) => {
37            console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
38        });
39    } else {
40        console.info('[permission] case apply permission failed, createAtManager failed');
41    }
42}
43
44function sleep(delay) {
45    return new Promise(resovle => setTimeout(resovle, delay))
46}
47
48function checkWifiPowerOn(){
49    console.info("[wifi_test]/wifi status:" + wifi.isWifiActive());
50}
51
52export default function actsWifiFunctionTest() {
53    describe('actsWifiFunctionTest', function () {
54        beforeAll(async function (done) {
55            console.info('beforeAll case');
56            await applyPermission();
57            done();
58        })
59
60        beforeEach(function () {
61            console.info("[wifi_test]beforeEach start" );
62            checkWifiPowerOn();
63        })
64        afterEach(async function () {
65            console.info("[wifi_test]afterEach start" );
66        })
67
68        /**
69        * @tc.number Communication_WiFi_XTS_P2P_0003
70        * @tc.name testCreateGroup
71        * @tc.desc Test createGroup and getCurrentGroup API Function
72        * @tc.type Function
73        * @tc.level Level 3
74        */
75        it('Communication_WiFi_XTS_P2P_0003', 0, async function(done) {
76            let wifiP2PConfig = {
77                deviceAddress : "00:00:00:00:00:00",
78                netId : -1,
79                passphrase : "12345678",
80                groupName : "DIRECT-AAAZZZ123",
81                goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ,
82            };
83            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
84            expect(wifi.isWifiActive()).assertTrue();
85            let createGroupResult = wifi.createGroup(wifiP2PConfig);
86            console.log("[wifi_test]createGroup result: " + JSON.stringify(createGroupResult));
87            await sleep(2000);
88            expect(createGroupResult).assertTrue();
89            try {
90                await wifi.getCurrentGroup()
91                    .then(data => {
92                        console.info("[wifi_test] getCurrentGroup  promise result :" + JSON.stringify(data));
93                        expect(true).assertEqual(data.groupName != null);
94                    }).catch((error) => {
95                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
96                        expect(true).assertEqual(error != null);
97                    });
98            }catch(error){
99                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
100                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
101            }
102            function getCurrentGroupResult(){
103                return new Promise((resolve, reject) => {
104                    wifi.getCurrentGroup(
105                        (err, result) => {
106                            if(err) {
107                                console.info("[wifi_test]failed to get getCurrentGroup:" + JSON.stringify(err));
108                                expect().assertFail();
109                            }
110                            console.info("[wifi_test]getCurrentGroup callback:" + JSON.stringify(result));
111                            console.info("isP2pGo: " + result.isP2pGo +
112                            "deviceName: " + result.ownerInfo.deviceName +
113                            "deviceAddress: " + result.ownerInfo.deviceAddress +
114                            "primaryDeviceType: " + result.ownerInfo.primaryDeviceType +
115                            "deviceStatus: " + result.ownerInfo.deviceStatus +
116                            "groupCapabilitys: " + result.ownerInfo.groupCapabilitys +
117                            "passphrase: " + result.passphrase + "interface: "+ result.interface
118                            + "groupName: " + result.groupName +
119                            "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress);
120                            console.info("[wifi_test] clientDevices:" + JSON.stringify(result.clientDevices));
121                            console.info("[wifi_test] ownerInfo:" + JSON.stringify(result.WifiP2pDevice));
122                            resolve();
123                        });
124                });
125            }
126            await getCurrentGroupResult();
127            let removeGroupResult = wifi.removeGroup();
128            await sleep(2000);
129            expect(removeGroupResult).assertTrue();
130            try {
131                await wifi.getCurrentGroup()
132                    .then(data => {
133                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
134                        expect(true).assertEqual(data.deviceName == null);
135                    }).catch((error) => {
136                        console.error('[wifi_test] getCurrentGroup  promise failed1 :' + JSON.stringify(error));
137                        expect(true).assertEqual(error != null);
138                    });
139            }catch(error){
140                console.info("[wifi_test]getCurrentGroup promise error1: " + JSON.stringify(error.message));
141                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
142            }
143            done();
144        })
145
146        /**
147        * @tc.number Communication_WiFi_XTS_P2P_0004
148        * @tc.name testCreateGroup
149        * @tc.desc Test createGroup-Setting a 7-bit Key Function.
150        * @tc.type Function
151        * @tc.level Level 3
152        */
153        it('Communication_WiFi_XTS_P2P_0004', 0, async function (done) {
154            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
155            expect(wifi.isWifiActive()).assertTrue();
156            let wifiP2PConfig = {
157                deviceAddress: "00:00:00:00:00:00",
158                netId: -1,
159                passphrase: "1234567",
160                groupName: "DIRECT-test_pass",
161                goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ,
162            };
163            let createGroupResult = wifi.createGroup(wifiP2PConfig);
164            console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult));
165            await sleep(2000);
166            expect(createGroupResult).assertFalse();
167            await wifi.getCurrentGroup()
168                .then(data => {
169                    console.info("[wifi_test] getCurrentGroup  promise result :" + JSON.stringify(data));
170                    expect(true).assertEqual(data.networkId == -999);
171                }).catch((error) => {
172                    console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
173                    expect(true).assertEqual(error !=null);
174                });
175            let removeGroupResult = wifi.removeGroup();
176            await sleep(2000);
177            expect(removeGroupResult).assertFalse();
178            try {
179                await wifi.getCurrentGroup()
180                    .then(data => {
181                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
182                        expect(true).assertEqual(data.deviceName == null);
183                    }).catch((error) => {
184                        console.error('[wifi_test] getCurrentGroup  promise failed1 :' + JSON.stringify(error));
185                        expect(true).assertEqual(error !=null);
186                    });
187            }catch(error){
188                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
189                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
190            }
191            done();
192        })
193
194        /**
195        * @tc.number Communication_WiFi_XTS_P2P_0104
196        * @tc.name testCreateGroup
197        * @tc.desc Test createGroup-Key setting: Chinese, English, and characters Function.
198        * @tc.type Function
199        * @tc.level Level 3
200        */
201        it('Communication_WiFi_XTS_P2P_0104', 0, async function (done) {
202            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
203            expect(wifi.isWifiActive()).assertTrue();
204            let wifiP2PConfig = {
205                deviceAddress: "00:00:00:00:00:00",
206                netId: -1,
207                passphrase: "123@%abcD",
208                groupName: "DIRECT-test_pass1",
209                goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ,
210            };
211            let createGroupResult = wifi.createGroup(wifiP2PConfig);
212            console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult));
213            await sleep(2000);
214            expect(createGroupResult).assertTrue();
215            await wifi.getCurrentGroup()
216                .then(data => {
217                    console.info("[wifi_test]getCurrentGroup  promise result : " + JSON.stringify(data));
218                    expect(true).assertEqual(data.passphrase == wifiP2PConfig.passphrase);
219                });
220            let removeGroupResult = wifi.removeGroup();
221            await sleep(2000);
222            expect(removeGroupResult).assertTrue();
223            try {
224                await wifi.getCurrentGroup()
225                    .then(data => {
226                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
227                        expect(true).assertEqual(data.deviceName == null);
228                    }).catch((error) => {
229                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
230                        expect(true).assertEqual(error !=null);
231                    });
232            }catch(error){
233                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
234                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
235            }
236            done();
237        })
238
239        /**
240        * @tc.number Communication_WiFi_XTS_P2P_0204
241        * @tc.name testCreateGroup
242        * @tc.desc Test createGroup-Key setting 64 bit Function.
243        * @tc.type Function
244        * @tc.level Level 3
245        */
246        it('Communication_WiFi_XTS_P2P_0204', 0, async function (done) {
247            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
248            expect(wifi.isWifiActive()).assertTrue();
249            let wifiP2PConfig = {
250                deviceAddress: "00:00:00:00:00:00",
251                netId: -1,
252                passphrase: "abc345678901234567890123456789012345678901234567890123456789012",
253                groupName: "DIRECT-test_pass2",
254                goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ,
255            };
256            let createGroupResult = wifi.createGroup(wifiP2PConfig);
257            console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult));
258            await sleep(2000);
259            expect(createGroupResult).assertTrue();
260            await wifi.getCurrentGroup()
261                .then(data => {
262                    console.info("[wifi_test]getCurrentGroup promise result : " + JSON.stringify(data));
263                    expect(true).assertEqual(data.passphrase == wifiP2PConfig.passphrase);
264                });
265            let removeGroupResult = wifi.removeGroup();
266            await sleep(2000);
267            expect(removeGroupResult).assertTrue();
268            try {
269                await wifi.getCurrentGroup()
270                    .then(data => {
271                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
272                        expect(true).assertEqual(data.deviceName == null);
273                    }).catch((error) => {
274                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
275                        expect(true).assertEqual(error !=null);
276                    });
277            }catch(error){
278                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
279                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
280            }
281            done();
282        })
283
284        /**
285        * @tc.number Communication_WiFi_XTS_P2P_0304
286        * @tc.name testCreateGroup
287        * @tc.desc Test createGroup-Key setting 65 bitsFunction.
288        * @tc.type Function
289        * @tc.level Level 3
290        */
291        it('Communication_WiFi_XTS_P2P_0304', 0, async function (done) {
292            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
293            expect(wifi.isWifiActive()).assertTrue();
294            let wifiP2PConfig = {
295                deviceAddress: "00:00:00:00:00:00",
296                netId: -1,
297                passphrase: "abc3456789012345678901234567890123456789012345678901234567890123",
298                groupName: "DIRECT-test_pass3",
299                goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ,
300            };
301            let createGroupResult = wifi.createGroup(wifiP2PConfig);
302            console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult));
303            await sleep(2000);
304            expect(createGroupResult).assertFalse();
305            await wifi.getCurrentGroup()
306                .then(data => {
307                    console.info("[wifi_test]getCurrentGroup  promise result :" + JSON.stringify(data));
308                    expect(true).assertEqual(data.passphrase != wifiP2PConfig.passphrase);
309                }).catch((error) => {
310                    console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
311                    expect(true).assertEqual(error !=null);
312                });
313            let removeGroupResult = wifi.removeGroup();
314            await sleep(2000);
315            expect(removeGroupResult).assertFalse();
316            try {
317                await wifi.getCurrentGroup()
318                    .then(data => {
319                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
320                        expect(true).assertEqual(data.deviceName == null);
321                    }).catch((error) => {
322                        console.error('[wifi_test] getCurrentGroup  promise failed1 :' + JSON.stringify(error));
323                        expect(true).assertEqual(error !=null);
324                    });
325            }catch(error){
326                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
327                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
328            }
329            done();
330        })
331
332        /**
333        * @tc.number Communication_WiFi_XTS_P2P_0007
334        * @tc.name testCreateGroup
335        * @tc.desc Test createGroup-2.4 GHz frequency band setting Function
336        * @tc.type Function
337        * @tc.level Level 0
338        */
339        it('Communication_WiFi_XTS_P2P_0007', 0, async function(done) {
340            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
341            expect(wifi.isWifiActive()).assertTrue();
342            let wifiP2PConfig = {
343                deviceAddress : "00:00:00:00:00:00",
344                netId : -1,
345                passphrase : "12345678",
346                groupName : "DIRECT-test_band1",
347                goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ,
348            };
349            let createGroupResult = wifi.createGroup(wifiP2PConfig);
350            await sleep(2000);
351            console.info("[wifi_test] test createGroup result." + createGroupResult)
352            expect(createGroupResult).assertTrue();
353            await wifi.getCurrentGroup()
354                .then(data => {
355                    console.info("[wifi_test]getCurrentGroup  promise result :" + JSON.stringify(data));
356                    expect(true).assertEqual(2412 < data.frequency < 2484 );
357                });
358            let removeGroupResult = wifi.removeGroup();
359            await sleep(2000);
360            expect(removeGroupResult).assertTrue();
361            try {
362                await wifi.getCurrentGroup()
363                    .then(data => {
364                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
365                        expect(true).assertEqual(data.deviceName == null);
366                    }).catch((error) => {
367                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
368                        expect(true).assertEqual(error !=null);
369                    });
370            }catch(error){
371                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
372                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
373            }
374            done();
375        })
376
377        /**
378        * @tc.number Communication_WiFi_XTS_P2P_0107
379        * @tc.name testCreateGroup
380        * @tc.desc Test createGroup-5 GHz frequency band setting Function
381        * @tc.type Function
382        * @tc.level Level 0
383        */
384        it('Communication_WiFi_XTS_P2P_0107', 0, async function(done) {
385            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
386            expect(wifi.isWifiActive()).assertTrue();
387            try {
388                let wifiP2PConfig = {
389                    deviceAddress : "00:00:00:00:00:00",
390                    netId : -1,
391                    passphrase : "12345678",
392                    groupName : "DIRECT-test_band2",
393                    goBand : wifi.GroupOwnerBand.GO_BAND_5GHZ,
394                };
395                let createGroupResult = wifi.createGroup(wifiP2PConfig);
396                await sleep(2000);
397                console.info("[wifi_test]test createGroup result." + createGroupResult)
398                expect(createGroupResult).assertTrue();
399                await wifi.getCurrentGroup()
400                    .then(data => {
401                        console.info("[wifi_test] getCurrentGroup  promise result :" + JSON.stringify(data));
402                        expect(true).assertEqual(data.deviceName == null);
403                    }).catch((error) => {
404                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
405                        expect(true).assertEqual(error != null);
406                    });
407                let removeGroupResult = await wifi.removeGroup();
408                await sleep(2000);
409                expect(removeGroupResult).assertTrue();
410                await wifi.getCurrentGroup()
411                    .then(data => {
412                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
413                        expect(true).assertEqual(data.deviceName == null);
414                    }).catch((error) => {
415                        console.error('[wifi_test] getCurrentGroup  promise failed1 :' + JSON.stringify(error));
416                        expect(true).assertEqual(error != null);
417                    });
418            }catch(error){
419                console.info("[wifi_test]createGroup 5G goBand fail : " + JSON.stringify(error.message));
420                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
421            }
422            done();
423        })
424
425        /**
426        * @tc.number Communication_WiFi_XTS_P2P_0207
427        * @tc.name testCreateGroup
428        * @tc.desc Test createGroup-Auto frequency band setting Function
429        * @tc.type Function
430        * @tc.level Level 0
431        */
432        it('Communication_WiFi_XTS_P2P_0207', 0, async function(done) {
433            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
434            expect(wifi.isWifiActive()).assertTrue();
435            try {
436                let wifiP2PConfig = {
437                    deviceAddress : "00:00:00:00:00:00",
438                    netId : -1,
439                    passphrase : "12345678",
440                    groupName : "DIRECT-test_band3",
441                    goBand : wifi.GroupOwnerBand.GO_BAND_AUTO,
442                };
443                let createGroupResult = wifi.createGroup(wifiP2PConfig);
444                await sleep(2000);
445                console.info("[wifi_test]test createGroup result." + createGroupResult)
446                expect(createGroupResult).assertTrue();
447                await wifi.getCurrentGroup()
448                    .then(data => {
449                        console.info("[wifi_test]getCurrentGroup promise result : " + JSON.stringify(data));
450                        expect(true).assertEqual(data.frequency != null );
451                    });
452                let removeGroupResult = await wifi.removeGroup();
453                await sleep(2000);
454                expect(removeGroupResult).assertTrue();
455                await wifi.getCurrentGroup()
456                    .then(data => {
457                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
458                        expect(true).assertEqual(data.deviceName == null);
459                    }).catch((error) => {
460                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
461                        expect(true).assertEqual(error !=null);
462                    });
463            }catch(error){
464                console.info("[wifi_test]createGroup auto  goBand result : " + JSON.stringify(error.message));
465                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
466            }
467            done();
468        })
469
470        /**
471        * @tc.number Communication_WiFi_XTS_P2P_0009
472        * @tc.name testP2pCancelConnect
473        * @tc.desc Test p2pCancelConnect Group API functionality.
474        * @tc.type Function
475        * @tc.level Level 3
476        */
477        it('Communication_WiFi_XTS_P2P_0009', 0, async function (done) {
478            let wifiP2PConfig = {
479                deviceAddress : "11:22:33:44:55:66",
480                netId : -1,
481                passphrase : "12345678",
482                groupName : "DIRECT-AAAZZZ456",
483                goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ,
484            };
485            let p2pConnectResult = wifi.p2pConnect(wifiP2PConfig);
486            console.info("[wifi_test]test p2pConnect result." + p2pConnectResult);
487            let p2pCancelResult = wifi.p2pCancelConnect();
488            await sleep(2000);
489            console.info("[wifi_test]test p2pCancelConnect result." + p2pCancelResult);
490            expect(p2pCancelResult).assertTrue();
491            let removeGroupResult = wifi.removeGroup();
492            console.info("[wifi_test]test start removeGroup:" + removeGroupResult);
493            expect(removeGroupResult).assertFalse();
494            try {
495                await wifi.getCurrentGroup()
496                    .then(data => {
497                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
498                        expect(true).assertEqual(data.deviceName == null);
499                    }).catch((error) => {
500                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
501                        expect(true).assertEqual(error !=null);
502                    });
503            }catch(error){
504                console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
505                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
506            }
507            done();
508        })
509
510        /**
511        * @tc.number Communication_WiFi_XTS_P2P_0011
512        * @tc.name testRemoveGroup
513        * @tc.desc Test remove a nonexistent group.
514        * @tc.type Function
515        * @tc.level Level 3
516        */
517        it('Communication_WiFi_XTS_P2P_0011', 0, async function (done) {
518            let removeGroupResult = wifi.removeGroup(10000);
519            console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(removeGroupResult));
520            expect(removeGroupResult).assertFalse();
521            try {
522                await wifi.getCurrentGroup()
523                    .then(data => {
524                        console.info("[wifi_test] getCurrentGroup  promise result1 :" + JSON.stringify(data));
525                        expect(true).assertEqual(data.deviceName == null);
526                    }).catch((error) => {
527                        console.error('[wifi_test] getCurrentGroup  promise failed :' + JSON.stringify(error));
528                        expect(true).assertEqual(error !=null);
529                    });
530            }catch(error){
531                console.info("[wifi_test]getCurrentGroup  promise error message : " + JSON.stringify(error.message));
532                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
533            }
534            done();
535        })
536
537        /**
538        * @tc.number Communication_WiFi_XTS_P2P_0010
539        * @tc.name testGetP2pLinkedInfo
540        * @tc.desc Test getP2pLinkedInfo API functionality
541        * @tc.type Function
542        * @tc.level Level 2
543        */
544        it('Communication_WiFi_XTS_P2P_0010', 0, async function(done) {
545            let P2pConnectState = {
546                DISCONNECTED :0,
547                CONNECTED : 1,
548            };
549            await wifi.getP2pLinkedInfo()
550                .then(data => {
551                    let resultLength = Object.keys(data).length;
552                    console.info("[wifi_test]getP2pLinkedInfo promise result :" + JSON.stringify(data));
553                    expect(true).assertEqual(resultLength!=0);
554                    done()
555                });
556            function getP2pLinkedInfoResult(){
557                return new Promise((resolve, reject) => {
558                    wifi.getP2pLinkedInfo(
559                        (err, result) => {
560                            if(err) {
561                                console.info("[wifi_test]failed to getP2pLinkedInfo callback:" + JSON.stringify(err));
562                                return;
563                            }
564                            let resultLength = Object.keys(result).length;
565                            console.info("[wifi_test]getP2pLinkedInfo callback:" + JSON.stringify(resultLength));
566                            console.info("connectState: " + result.connectState +
567                            "isGroupOwner: " + result.isGroupOwner +
568                            "groupOwnerAddr: " + result.groupOwnerAddr);
569                            expect(true).assertEqual(resultLength!=0);
570                            resolve();
571                        });
572                });
573            }
574            await getP2pLinkedInfoResult();
575            done();
576        })
577
578        /**
579        * @tc.number Communication_WiFi_XTS_P2P_0001
580        * @tc.name testGetP2pPeerDevices
581        * @tc.desc Test getP2pPeerDevices promise API functionality
582        * @tc.type Function
583        * @tc.level Level 0
584        */
585        it('Communication_WiFi_XTS_P2P_0001', 0, async function(done){
586            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
587            expect(wifi.isWifiActive()).assertTrue();
588            let startDiscover = wifi.startDiscoverDevices();
589            await sleep(2000);
590            expect(startDiscover).assertTrue();
591            await wifi.getP2pPeerDevices()
592                .then((data)  => {
593                    let resultLength = Object.keys(data).length;
594                    console.info("[wifi_test]getP2pPeerDevices  promise result -> " + JSON.stringify(data));
595                    expect(true).assertEqual(resultLength >= 0);
596                }).catch((error) => {
597                    console.info("[wifi_test]getP2pPeerDevices promise then error." + JSON.stringify(error));
598                    expect().assertFail();
599                });
600            let stopDiscover = wifi.stopDiscoverDevices();
601            console.info("[wifi_test]test stopDiscoverDevices result." + stopDiscover);
602            done();
603        })
604
605        /**
606        * @tc.number Communication_WiFi_XTS_P2P_0101
607        * @tc.name testGetP2pPeerDevices
608        * @tc.desc Test getP2pPeerDevices callback API functionality
609        * @tc.type Function
610        * @tc.level Level 0
611        */
612        it('Communication_WiFi_XTS_P2P_0101', 0, async function(done){
613            console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive());
614            expect(wifi.isWifiActive()).assertTrue();
615            let startDiscover = wifi.startDiscoverDevices();
616            await sleep(2000);
617            expect(startDiscover).assertTrue();
618
619            function getP2pPeerDevicesResult(){
620                return new Promise((resolve, reject) => {
621                    wifi.getP2pPeerDevices(
622                        (err, result) => {
623                            if(err) {
624                                console.error('[wifi_test]failed to getP2pPeerDevices :' + JSON.stringify(err));
625                            }
626                            console.info("[wifi_test] getP2pPeerDevices callback result :" + JSON.stringify(result));
627                            let len = Object.keys(result).length;
628                            for (let j = 0; j < len; ++j) {
629                                console.info("deviceName: " + result[j].deviceName +
630                                "deviceAddress: " + result[j].deviceAddress +
631                                "primaryDeviceType: " + result[j].primaryDeviceType +
632                                "deviceStatus: " + result[j].deviceStatus +
633                                "groupCapabilitys: " + result[j].groupCapabilitys );
634                                if(result[j].deviceStatus == wifi.P2pDeviceStatus.UNAVAILABLE){
635                                    console.info("deviceStatus: " + result[j].deviceStatus);
636                                }
637                                if(result[j].deviceStatus == wifi.P2pDeviceStatus.CONNECTED){
638                                    console.info("deviceStatus: " + result[j].deviceStatus);
639                                }
640                                if(result[j].deviceStatus == wifi.P2pDeviceStatus.INVITED){
641                                    console.info("deviceStatus: " + result[j].deviceStatus);
642                                }
643                                if(result[j].deviceStatus == wifi.P2pDeviceStatus.FAILED){
644                                    console.info("deviceStatus: " + result[j].deviceStatus);
645                                }
646                                if(result[j].deviceStatus == wifi.P2pDeviceStatus.AVAILABLE){
647                                    console.info("deviceStatus: " + result[j].deviceStatus);
648                                }
649                            }
650                            resolve();
651
652
653
654
655                        });
656                });
657            }
658            await getP2pPeerDevicesResult();
659            done();
660        });
661        console.log("*************[wifi_test] start wifi js unit test end*************");
662    })
663}
664
665