• 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 wifiMg from '@ohos.wifiManager'
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:" + wifiMg.isWifiActive());
50}
51
52export default function actsWifiManagerFunctionTest() {
53    describe('actsWifiManagerFunctionTest', 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 SUB_Communication_WiFi_XTS_P2P_0003
70        * @tc.name testcreateP2pGroup
71        * @tc.desc Test createP2pGroup and getCurrentP2pGroup API Function
72        * @tc.type Function
73        * @tc.level Level 3
74        */
75        it('SUB_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 : wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
82            };
83            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
84            expect(wifiMg.isWifiActive()).assertTrue();
85            let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
86            await sleep(2000);
87            try {
88                await wifiMg.getCurrentP2pGroup()
89                    .then(data => {
90                        console.info("[wifi_test] getCurrentP2pGroup  promise result :" + JSON.stringify(data));
91                        expect(true).assertEqual(data.deviceName == null);
92                    }).catch((error) => {
93                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
94                        expect(true).assertEqual(error !=null);
95                    });
96            }catch(error){
97                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
98                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
99            }
100            function getCurrentP2pGroupResult(){
101                return new Promise((resolve, reject) => {
102                    wifiMg.getCurrentP2pGroup(
103                        (err, result) => {
104                            if(err) {
105                                console.info("[wifi_test]failed to get getCurrentP2pGroup:" + JSON.stringify(err));
106                                expect().assertFail();
107                            }
108                            console.info("[wifi_test]getCurrentP2pGroup callback:" + JSON.stringify(result));
109                            console.info("isP2pGo: " + result.isP2pGo +
110                            "deviceName: " + result.ownerInfo.deviceName +
111                            "deviceAddress: " + result.ownerInfo.deviceAddress +
112                            "primaryDeviceType: " + result.ownerInfo.primaryDeviceType +
113                            "deviceStatus: " + result.ownerInfo.deviceStatus +
114                            "groupCapabilitys: " + result.ownerInfo.groupCapabilitys +
115                            "passphrase: " + result.passphrase + "interface: "+ result.interface
116                            + "groupName: " + result.groupName +
117                            "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress);
118                            console.info("[wifi_test] clientDevices:" + JSON.stringify(result.clientDevices));
119                            console.info("[wifi_test] ownerInfo:" + JSON.stringify(result.WifiP2pDevice));
120                            resolve();
121                        });
122                });
123            }
124            await getCurrentP2pGroupResult();
125            let removeP2pGroupResult = wifiMg.removeP2pGroup();
126            await sleep(2000);
127            try {
128                await wifiMg.getCurrentP2pGroup()
129                    .then(data => {
130                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
131                        expect(true).assertEqual(data.deviceName == null);
132                    }).catch((error) => {
133                        console.error('[wifi_test] getCurrentP2pGroup  promise failed1 :' + JSON.stringify(error));
134                        expect(true).assertEqual(error !=null);
135                    });
136            }catch(error){
137                console.info("[wifi_test]getCurrentP2pGroup promise error1: " + JSON.stringify(error.message));
138                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
139            }
140            done();
141        })
142
143        /**
144        * @tc.number SUB_Communication_WiFi_XTS_P2P_0004
145        * @tc.name testcreateP2pGroup
146        * @tc.desc Test createP2pGroup-Setting a 7-bit Key Function.
147        * @tc.type Function
148        * @tc.level Level 3
149        */
150        it('SUB_Communication_WiFi_XTS_P2P_0004', 0, async function (done) {
151            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
152            expect(wifiMg.isWifiActive()).assertTrue();
153            let wifiP2PConfig = {
154                deviceAddress: "00:00:00:00:00:00",
155                netId: -1,
156                passphrase: "1234567",
157                groupName: "DIRECT-test_pass",
158                goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
159            };
160            try {
161                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
162                await sleep(2000);
163            }catch(error){
164                console.info("[wifi_test]createP2pGroup error: " + JSON.stringify(error.message));
165                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
166            }
167            try {
168                await wifiMg.getCurrentP2pGroup()
169                    .then(data => {
170                        console.info("[wifi_test] getCurrentP2pGroup  promise result :" + JSON.stringify(data));
171                        expect(true).assertEqual(data.networkId == -999);
172                    }).catch((error) => {
173                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
174                        expect(true).assertEqual(error !=null);
175                    });
176            }catch(error){
177                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
178                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
179            }
180            try {
181                let removeP2pGroupResult = wifiMg.removeP2pGroup();
182                await sleep(2000);
183            }catch(error){
184                console.info("[wifi_test]removeP2pGroup  error: " + JSON.stringify(error.message));
185                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
186            }
187            try {
188                await wifiMg.getCurrentP2pGroup()
189                    .then(data => {
190                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
191                        expect(true).assertEqual(data.deviceName == null);
192                    }).catch((error) => {
193                        console.error('[wifi_test] getCurrentP2pGroup  promise failed1 :' + JSON.stringify(error));
194                        expect(true).assertEqual(error !=null);
195                    });
196            }catch(error){
197                console.info("[wifi_test]getCurrentP2pGroup promise error1: " + JSON.stringify(error.message));
198                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
199            }
200            done();
201        })
202
203        /**
204        * @tc.number SUB_Communication_WiFi_XTS_P2P_0104
205        * @tc.name testcreateP2pGroup
206        * @tc.desc Test createP2pGroup-Key setting: Chinese, English, and characters Function.
207        * @tc.type Function
208        * @tc.level Level 3
209        */
210        it('SUB_Communication_WiFi_XTS_P2P_0104', 0, async function (done) {
211            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
212            expect(wifiMg.isWifiActive()).assertTrue();
213            let wifiP2PConfig = {
214                deviceAddress: "00:00:00:00:00:00",
215                netId: -1,
216                passphrase: "123@%abcD",
217                groupName: "DIRECT-test_pass1",
218                goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
219            };
220            let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
221            await sleep(2000);
222            await wifiMg.getCurrentP2pGroup()
223                .then(data => {
224                    console.info("[wifi_test]getCurrentP2pGroup  promise result : " + JSON.stringify(data));
225                    expect(true).assertEqual(data.passphrase == wifiP2PConfig.passphrase);
226                });
227            let removeP2pGroupResult = wifiMg.removeP2pGroup();
228            await sleep(2000);
229            try {
230                await wifiMg.getCurrentP2pGroup()
231                    .then(data => {
232                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
233                        expect(true).assertEqual(data.deviceName == null);
234                    }).catch((error) => {
235                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
236                        expect(true).assertEqual(error !=null);
237                    });
238            }catch(error){
239                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
240                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
241            }
242            done();
243        })
244
245        /**
246        * @tc.number SUB_Communication_WiFi_XTS_P2P_0204
247        * @tc.name testcreateP2pGroup
248        * @tc.desc Test createP2pGroup-Key setting 64 bit Function.
249        * @tc.type Function
250        * @tc.level Level 3
251        */
252        it('SUB_Communication_WiFi_XTS_P2P_0204', 0, async function (done) {
253            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
254            expect(wifiMg.isWifiActive()).assertTrue();
255            let wifiP2PConfig = {
256                deviceAddress: "00:00:00:00:00:00",
257                netId: -1,
258                passphrase: "abc345678901234567890123456789012345678901234567890123456789012",
259                groupName: "DIRECT-test_pass2",
260                goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
261            };
262            let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
263            await sleep(2000);
264            await wifiMg.getCurrentP2pGroup()
265                .then(data => {
266                    console.info("[wifi_test]getCurrentP2pGroup promise result : " + JSON.stringify(data));
267                    expect(true).assertEqual(data.passphrase == wifiP2PConfig.passphrase);
268                });
269            let removeP2pGroupResult = wifiMg.removeP2pGroup();
270            await sleep(2000);
271            try {
272                await wifiMg.getCurrentP2pGroup()
273                    .then(data => {
274                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
275                        expect(true).assertEqual(data.deviceName == null);
276                    }).catch((error) => {
277                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
278                        expect(true).assertEqual(error !=null);
279                    });
280            }catch(error){
281                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
282                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
283            }
284            done();
285        })
286
287        /**
288        * @tc.number SUB_Communication_WiFi_XTS_P2P_0304
289        * @tc.name testcreateP2pGroup
290        * @tc.desc Test createP2pGroup-Key setting 65 bitsFunction.
291        * @tc.type Function
292        * @tc.level Level 3
293        */
294        it('SUB_Communication_WiFi_XTS_P2P_0304', 0, async function (done) {
295            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
296            expect(wifiMg.isWifiActive()).assertTrue();
297            let wifiP2PConfig = {
298                deviceAddress: "00:00:00:00:00:00",
299                netId: -1,
300                passphrase: "abc3456789012345678901234567890123456789012345678901234567890123",
301                groupName: "DIRECT-test_pass3",
302                goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
303            };
304            try {
305                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
306                await sleep(2000);
307            }catch(error){
308                console.info("[wifi_test]createP2pGroup error: " + JSON.stringify(error.message));
309                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
310            }
311            try {
312                await wifiMg.getCurrentP2pGroup()
313                    .then(data => {
314                        console.info("[wifi_test] getCurrentP2pGroup  promise result :" + JSON.stringify(data));
315                        expect(true).assertEqual(data.networkId == -999);
316                    }).catch((error) => {
317                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
318                        expect(true).assertEqual(error !=null);
319                    });
320            }catch(error){
321                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
322                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
323            }
324            try {
325                let removeP2pGroupResult = wifiMg.removeP2pGroup();
326                await sleep(2000);
327            }catch(error){
328                console.info("[wifi_test]removeP2pGroup error: " + JSON.stringify(error.message));
329                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
330            }
331            try {
332                await wifiMg.getCurrentP2pGroup()
333                    .then(data => {
334                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
335                        expect(true).assertEqual(data.deviceName == null);
336                    }).catch((error) => {
337                        console.error('[wifi_test] getCurrentP2pGroup  promise failed1 :' + JSON.stringify(error));
338                        expect(true).assertEqual(error !=null);
339                    });
340            }catch(error){
341                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
342                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
343            }
344            done();
345        })
346
347        /**
348        * @tc.number SUB_Communication_WiFi_XTS_P2P_0007
349        * @tc.name testcreateP2pGroup
350        * @tc.desc Test createP2pGroup-2.4 GHz frequency band setting Function
351        * @tc.type Function
352        * @tc.level Level 0
353        */
354        it('SUB_Communication_WiFi_XTS_P2P_0007', 0, async function(done) {
355            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
356            expect(wifiMg.isWifiActive()).assertTrue();
357            let wifiP2PConfig = {
358                deviceAddress : "00:00:00:00:00:00",
359                netId : -1,
360                passphrase : "12345678",
361                groupName : "DIRECT-test_band1",
362                goBand : wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
363            };
364            let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
365            await sleep(2000);
366            await wifiMg.getCurrentP2pGroup()
367                .then(data => {
368                    console.info("[wifi_test]getCurrentP2pGroup  promise result :" + JSON.stringify(data));
369                    expect(true).assertEqual(2412 < data.frequency < 2484 );
370                });
371            let removeP2pGroupResult = wifiMg.removeP2pGroup();
372            await sleep(2000);
373            try {
374                await wifiMg.getCurrentP2pGroup()
375                    .then(data => {
376                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
377                        expect(true).assertEqual(data.deviceName == null);
378                    }).catch((error) => {
379                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
380                        expect(true).assertEqual(error !=null);
381                    });
382            }catch(error){
383                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
384                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
385            }
386            done();
387        })
388
389        /**
390        * @tc.number SUB_Communication_WiFi_XTS_P2P_0107
391        * @tc.name testcreateP2pGroup
392        * @tc.desc Test createP2pGroup-5 GHz frequency band setting Function
393        * @tc.type Function
394        * @tc.level Level 0
395        */
396        it('SUB_Communication_WiFi_XTS_P2P_0107', 0, async function(done) {
397            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
398            expect(wifiMg.isWifiActive()).assertTrue();
399            try {
400                let wifiP2PConfig = {
401                    deviceAddress : "00:00:00:00:00:00",
402                    netId : -1,
403                    passphrase : "12345678",
404                    groupName : "DIRECT-test_band2",
405                    goBand : wifiMg.GroupOwnerBand.GO_BAND_5GHZ,
406                };
407                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
408                await sleep(2000);
409                await wifiMg.getCurrentP2pGroup()
410                    .then(data => {
411                        console.info("[wifi_test] getCurrentP2pGroup  promise result :" + JSON.stringify(data));
412                        expect(true).assertEqual(data.deviceName == null);
413                    }).catch((error) => {
414                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
415                        expect(true).assertEqual(error !=null);
416                    });
417                let removeP2pGroupResult = await wifiMg.removeP2pGroup();
418                await sleep(2000);
419                await wifiMg.getCurrentP2pGroup()
420                    .then(data => {
421                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
422                        expect(true).assertEqual(data.deviceName == null);
423                    }).catch((error) => {
424                        console.error('[wifi_test] getCurrentP2pGroup  promise failed1 :' + JSON.stringify(error));
425                        expect(true).assertEqual(error !=null);
426                    });
427            }catch(error){
428                console.info("[wifi_test]createP2pGroup 5G goBand fail : " + JSON.stringify(error.message));
429                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
430            }
431            done();
432        })
433
434        /**
435        * @tc.number SUB_Communication_WiFi_XTS_P2P_0207
436        * @tc.name testcreateP2pGroup
437        * @tc.desc Test createP2pGroup-Auto frequency band setting Function
438        * @tc.type Function
439        * @tc.level Level 0
440        */
441        it('SUB_Communication_WiFi_XTS_P2P_0207', 0, async function(done) {
442            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
443            expect(wifiMg.isWifiActive()).assertTrue();
444            try {
445                let wifiP2PConfig = {
446                    deviceAddress : "00:00:00:00:00:00",
447                    netId : -1,
448                    passphrase : "12345678",
449                    groupName : "DIRECT-test_band3",
450                    goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO,
451                };
452                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
453                await sleep(2000);
454                await wifiMg.getCurrentP2pGroup()
455                    .then(data => {
456                        console.info("[wifi_test]getCurrentP2pGroup promise result : " + JSON.stringify(data));
457                        expect(true).assertEqual(data.frequency != null );
458                    });
459                let removeP2pGroupResult = await wifiMg.removeP2pGroup();
460                await sleep(2000);
461                await wifiMg.getCurrentP2pGroup()
462                    .then(data => {
463                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
464                        expect(true).assertEqual(data.deviceName == null);
465                    }).catch((error) => {
466                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
467                        expect(true).assertEqual(error !=null);
468                    });
469            }catch(error){
470                console.info("[wifi_test]createP2pGroup auto  goBand result : " + JSON.stringify(error.message));
471                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
472            }
473            done();
474        })
475
476        /**
477        * @tc.number SUB_Communication_WiFi_XTS_P2P_0008
478        * @tc.name testcreateP2pGroup
479        * @tc.desc Test createP2pGroup-SSID is an empty string Function.
480        * @tc.type Function
481        * @tc.level Level 0
482        */
483        it('SUB_Communication_WiFi_XTS_P2P_0008', 0, async function (done) {
484            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
485            expect(wifiMg.isWifiActive()).assertTrue();
486            try {
487                let wifiP2PConfig = {
488                    deviceAddress: "00:00:00:00:00:00",
489                    netId: -1,
490                    passphrase: "12345678",
491                    groupName: "",
492                    goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
493                };
494                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
495                await sleep(2000);
496                await wifiMg.getCurrentP2pGroup()
497                    .then(data => {
498                        console.info("[wifi_test]getCurrentP2pGroup  promise result : " + JSON.stringify(data));
499                    });
500                let removeP2pGroupResult = wifiMg.removeP2pGroup();
501                await sleep(2000);
502                await wifiMg.getCurrentP2pGroup()
503                    .then(data => {
504                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
505                        expect(true).assertEqual(data.deviceName == null);
506                    }).catch((error) => {
507                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
508                        expect(true).assertEqual(error !=null);
509                    });
510            }catch(error){
511                console.info("[wifi_test]createP2pGroup error passphrase result : " + JSON.stringify(error.message));
512                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
513            }
514            done();
515        })
516
517        /**
518        * @tc.number SUB_Communication_WiFi_XTS_P2P_0108
519        * @tc.name testcreateP2pGroup
520        * @tc.desc Test createP2pGroup-SSID is a space Function.
521        * @tc.type Function
522        * @tc.level Level 0
523        */
524        it('SUB_Communication_WiFi_XTS_P2P_0108', 0, async function (done) {
525            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
526            expect(wifiMg.isWifiActive()).assertTrue();
527            try {
528                let wifiP2PConfig = {
529                    deviceAddress: "00:00:00:00:00:00",
530                    netId: -1,
531                    passphrase: "12345678",
532                    groupName: " ",
533                    goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
534                };
535                let createP2pGroupResult = wifiMg.createP2pGroup(wifiP2PConfig);
536                await sleep(2000);
537                await wifiMg.getCurrentP2pGroup()
538                    .then(data => {
539                        console.info("[wifi_test]getCurrentP2pGroup promise result :" + JSON.stringify(data));
540                    });
541                let removeP2pGroupResult = wifi.removeP2pGroup();
542                await sleep(2000);
543                await wifiMg.getCurrentP2pGroup()
544                    .then(data => {
545                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
546                        expect(true).assertEqual(data.deviceName == null);
547                    }).catch((error) => {
548                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
549                        expect(true).assertEqual(error !=null);
550                    });
551            }catch(error){
552                console.info("[wifi_test]createP2pGroup error passphrase result : " + JSON.stringify(error.message));
553                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
554            }
555            done();
556        })
557
558        /**
559       * @tc.number SUB_Communication_WiFi_XTS_P2P_0308
560       * @tc.name testcreateP2pGroup
561       * @tc.desc Test createP2pGroup-the password must be a space.
562       * @tc.type Function
563       * @tc.level Level 0
564       */
565        it('SUB_Communication_WiFi_XTS_P2P_0308', 0, async function (done) {
566            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
567            expect(wifiMg.isWifiActive()).assertTrue();
568            try {
569                let wifiP2PConfig = {
570                    deviceAddress: "00:00:00:00:00:00",
571                    netId: -1,
572                    passphrase: " ",
573                    groupName: "DIRECT-testpassword",
574                    goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
575                };
576                let createP2pGroupResult = wifi.createP2pGroup(wifiP2PConfig);
577                await sleep(2000);
578                await wifi.getCurrentP2pGroup()
579                    .then(data => {
580                        console.info("[wifi_test] getCurrentP2pGroup  promise result :" + JSON.stringify(data));
581                    });
582                let removeP2pGroupResult = wifi.removeP2pGroup();
583                await sleep(2000);
584                await wifiMg.getCurrentP2pGroup()
585                    .then(data => {
586                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
587                        expect(true).assertEqual(data.deviceName == null);
588                    }).catch((error) => {
589                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
590                        expect(true).assertEqual(error !=null);
591                    });
592            }catch(error){
593                console.info("[wifi_test]createP2pGroup error passphrase result : " + JSON.stringify(error.message));
594                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
595            }
596            done();
597        })
598
599        /**
600        * @tc.number SUB_Communication_WiFi_XTS_P2P_0009
601        * @tc.name testP2pCancelConnect
602        * @tc.desc Test p2pCancelConnect Group API functionality.
603        * @tc.type Function
604        * @tc.level Level 3
605        */
606        it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) {
607            let DeviceAddressType  = {
608                RANDOM_DEVICE_ADDRESS : 0 ,
609                REAL_DEVICE_ADDRESS : 1 ,
610            };
611            let wifiP2PConfig = {
612                deviceAddress : "11:22:33:44:55:66",
613                deviceAddressType : wifiMg.DeviceAddressType.REAL_DEVICE_ADDRESS,
614                netId : -1,
615                passphrase : "12345678",
616                groupName : "DIRECT-AAAZZZ456",
617                goBand : wifiMg.GroupOwnerBand.GO_BAND_2GHZ,
618            };
619            let p2pConnectResult = wifiMg.p2pConnect(wifiP2PConfig);
620            console.info("[wifi_test]test p2pConnect successful." );
621            let p2pCancelResult = wifiMg.p2pCancelConnect();
622            await sleep(2000);
623            console.info("[wifi_test]test p2pCancelConnect successful." );
624            try {
625                let removeP2pGroupResult = wifiMg.removeP2pGroup();
626            }catch(error){
627                console.info("[wifi_test]removeP2pGroup  error: " + JSON.stringify(error.message));
628                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
629            }
630            try {
631                await wifiMg.getCurrentP2pGroup()
632                    .then(data => {
633                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
634                        expect(true).assertEqual(data.deviceName == null);
635                    }).catch((error) => {
636                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
637                        expect(true).assertEqual(error !=null);
638                    });
639            }catch(error){
640                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
641                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
642            }
643            done();
644        })
645
646        /**
647        * @tc.number SUB_Communication_WiFi_XTS_P2P_0011
648        * @tc.name testremoveP2pGroup
649        * @tc.desc Test remove a nonexistent group.
650        * @tc.type Function
651        * @tc.level Level 3
652        */
653        it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) {
654            try {
655                let removeP2pGroupResult = wifiMg.removeP2pGroup(10000);
656            }catch(error){
657                console.info("[wifi_test]removeP2pGroup error: " + JSON.stringify(error.message));
658                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
659            }
660            try {
661                await wifiMg.getCurrentP2pGroup()
662                    .then(data => {
663                        console.info("[wifi_test] getCurrentP2pGroup  promise result1 :" + JSON.stringify(data));
664                        expect(true).assertEqual(data.deviceName == null);
665                    }).catch((error) => {
666                        console.error('[wifi_test] getCurrentP2pGroup  promise failed :' + JSON.stringify(error));
667                        expect(true).assertEqual(error !=null);
668                    });
669            }catch(error){
670                console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
671                expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
672            }
673            done();
674        })
675
676        /**
677        * @tc.number     SUB_Communication_WiFi_XTS_P2P_0002
678        * @tc.name       testP2pLocalDevice
679        * @tc.desc       Test get P2pLocalDevice API functionality.
680        * @tc.type Function
681        * @tc.level Level 3
682        */
683        it('SUB_Communication_WiFi_XTS_P2P_0002', 0, async function (done) {
684            await wifiMg.getP2pLocalDevice()
685                .then(data => {
686                    console.info("[wifi_test]getP2pLocalDevice  promise result :" + JSON.stringify(data));
687                    expect(true).assertEqual(data.deviceName !=null);
688                }).catch((error) => {
689                    console.info("[wifi_test]getP2pLocalDevice promise error." + JSON.stringify(error));
690                    expect().assertFail();
691                });
692            function getP2pLocal(){
693                return new Promise((resolve, reject) => {
694                    wifiMg.getP2pLocalDevice(
695                        (err, ret) => {
696                            if(err) {
697                                console.info("[wifi_test]getP2pLocalDevice callback failed : " + JSON.stringify(err));
698                                return;
699                            }
700                            console.info("[wifi_test]getP2pLocalDevice callback result: " + JSON.stringify(ret));
701                            console.info("deviceName: " + ret.deviceName + "deviceAddress: " +
702                            ret.deviceAddress + "deviceAddressType: " + ret.deviceAddressType +
703                            "primaryDeviceType: " + ret.primaryDeviceType +
704                            "deviceStatus: " + ret.deviceStatus + "groupCapabilitys: " +
705                            ret.groupCapabilitys );
706                            resolve();
707                        });
708                });
709            }
710            await getP2pLocal();
711            done();
712        })
713
714        /**
715        * @tc.number SUB_Communication_WiFi_XTS_P2P_0010
716        * @tc.name testGetP2pLinkedInfo
717        * @tc.desc Test getP2pLinkedInfo API functionality
718        * @tc.type Function
719        * @tc.level Level 2
720        */
721        it('SUB_Communication_WiFi_XTS_P2P_0010', 0, async function(done) {
722            let p2pConnectState = {
723                DISCONNECTED :0,
724                CONNECTED : 1,
725            };
726            await wifiMg.getP2pLinkedInfo()
727                .then(data => {
728                    let resultLength = Object.keys(data).length;
729                    console.info("[wifi_test]getP2pLinkedInfo promise result :" + JSON.stringify(data));
730                    expect(true).assertEqual(resultLength!=0);
731                    done()
732                });
733            function getP2pLinkedInfoResult(){
734                return new Promise((resolve, reject) => {
735                    wifiMg.getP2pLinkedInfo(
736                        (err, result) => {
737                            if(err) {
738                                console.info("[wifi_test]failed to getP2pLinkedInfo callback:" + JSON.stringify(err));
739                                return;
740                            }
741                            let resultLength = Object.keys(result).length;
742                            console.info("[wifi_test]getP2pLinkedInfo callback:" + JSON.stringify(resultLength));
743                            console.info("connectState: " + result.connectState +
744                            "isGroupOwner: " + result.isGroupOwner +
745                            "groupOwnerAddr: " + result.groupOwnerAddr);
746                            expect(true).assertEqual(resultLength!=0);
747                            resolve();
748                        });
749                });
750            }
751            await getP2pLinkedInfoResult();
752            done();
753        })
754
755        /**
756        * @tc.number SUB_Communication_WiFi_XTS_P2P_0001
757        * @tc.name testGetP2pPeerDevices
758        * @tc.desc Test getP2pPeerDevices promise API functionality
759        * @tc.type Function
760        * @tc.level Level 0
761        */
762        it('SUB_Communication_WiFi_XTS_P2P_0001', 0, async function(done){
763            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
764            expect(wifiMg.isWifiActive()).assertTrue();
765            let startDiscover = wifiMg.startDiscoverP2pDevices();
766            await sleep(2000);
767            await wifiMg.getP2pPeerDevices()
768                .then((data)  => {
769                    let resultLength = Object.keys(data).length;
770                    console.info("[wifi_test]getP2pPeerDevices  promise result -> " + JSON.stringify(data));
771                    expect(true).assertEqual(resultLength >= 0);
772                }).catch((error) => {
773                    console.info("[wifi_test]getP2pPeerDevices promise then error." + JSON.stringify(error));
774                    expect().assertFail();
775                });
776            let stopDiscover = wifiMg.stopDiscoverP2pDevices();
777            done();
778        })
779
780        /**
781        * @tc.number SUB_Communication_WiFi_XTS_P2P_0101
782        * @tc.name testGetP2pPeerDevices
783        * @tc.desc Test getP2pPeerDevices callback API functionality
784        * @tc.type Function
785        * @tc.level Level 0
786        */
787        it('SUB_Communication_WiFi_XTS_P2P_0101', 0, async function(done){
788            console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive());
789            expect(wifiMg.isWifiActive()).assertTrue();
790            let startDiscover = wifiMg.startDiscoverP2pDevices();
791            await sleep(2000);
792            function getP2pPeerDevicesResult(){
793                return new Promise((resolve, reject) => {
794                    wifiMg.getP2pPeerDevices(
795                        (err, result) => {
796                            if(err) {
797                                console.error('[wifi_test]failed to getP2pPeerDevices :' + JSON.stringify(err));
798                            }
799                            console.info("[wifi_test] getP2pPeerDevices callback result :" + JSON.stringify(result));
800                            let len = Object.keys(result).length;
801                            for (let j = 0; j < len; ++j) {
802                                console.info("deviceName: " + result[j].deviceName +
803                                "deviceAddress: " + result[j].deviceAddress +
804                                "primaryDeviceType: " + result[j].primaryDeviceType +
805                                "deviceStatus: " + result[j].deviceStatus +
806                                "groupCapabilitys: " + result[j].groupCapabilitys );
807                                if(result[j].deviceStatus == wifiMg.P2pDeviceStatus.UNAVAILABLE){
808                                    console.info("deviceStatus: " + result[j].deviceStatus);
809                                }
810                                if(result[j].deviceStatus == wifiMg.P2pDeviceStatus.CONNECTED){
811                                    console.info("deviceStatus: " + result[j].deviceStatus);
812                                }
813                                if(result[j].deviceStatus == wifiMg.P2pDeviceStatus.INVITED){
814                                    console.info("deviceStatus: " + result[j].deviceStatus);
815                                }
816                                if(result[j].deviceStatus == wifiMg.P2pDeviceStatus.FAILED){
817                                    console.info("deviceStatus: " + result[j].deviceStatus);
818                                }
819                                if(result[j].deviceStatus == wifiMg.P2pDeviceStatus.AVAILABLE){
820                                    console.info("deviceStatus: " + result[j].deviceStatus);
821                                }
822                            }
823                            resolve();
824                        });
825                });
826            }
827            await getP2pPeerDevicesResult();
828            done();
829        });
830        console.log("*************[wifi_test] start wifi js unit test end*************");
831    })
832}
833
834