WifiSta.test.js 19.9 KB
Newer Older
Q
q00313334 已提交
1
/*
Q
q00313334 已提交
2
 * Copyright (C) 2022 Huawei Device Co., Ltd.
Q
q00313334 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Q
quanli 已提交
16
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
Q
q00313334 已提交
17

Q
q00313334 已提交
18
import wifi from '@ohos.wifi'
Q
q00313334 已提交
19 20

function sleep(delay) {
Q
quanli 已提交
21 22 23 24 25 26 27 28 29 30 31 32
    var start = (new Date()).getTime();
    while ((new Date()).getTime() - start > delay) {
        break;
    }
}

function checkWifiPowerOn(){
	console.info("Wifi_test/wifi status:" + wifi.isWifiActive());
}

function resolve(ip) {
    return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF ) + (ip>>8 & 0xFF ) + (ip & 0xFF );
Q
q00313334 已提交
33
}
Q
q00313334 已提交
34

Q
q00313334 已提交
35

Q
q00313334 已提交
36
let WifiSecurityType = {
Q
q00313334 已提交
37 38 39 40 41
    WIFI_SEC_TYPE_INVALID: 0,
    WIFI_SEC_TYPE_OPEN: 1,
    WIFI_SEC_TYPE_WEP: 2,
    WIFI_SEC_TYPE_PSK: 3,
    WIFI_SEC_TYPE_SAE: 4,
Q
q00313334 已提交
42
}
Q
q00313334 已提交
43

Q
q00313334 已提交
44
let ConnState = {
Q
q00313334 已提交
45 46 47 48 49 50 51 52 53 54
    SCANNING: 0,
    CONNECTING: 1,
    AUTHENTICATING: 2,
    OBTAINING_IPADDR: 3,
    CONNECTED: 4,
    DISCONNECTING: 5,
    DISCONNECTED: 6,
    UNKNOWN: 7,
}

Q
quanli 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68
let untrustedDeviceConfig = {
    "ssid": "untrusted_ssid",
    "bssid": "",
    "preSharedKey": "12345678",
    "isHiddenSsid": false,
    "securityType":WifiSecurityType.WIFI_SEC_TYPE_PSK
}

let WifiChannelWidth = {
    WIDTH_20MHZ : 0,
    WIDTH_40MHZ : 1,
    WIDTH_80MHZ : 2,
    WIDTH_160MHZ : 3,
    WIDTH_280MHZ_PLUS : 4,
Q
quanli 已提交
69
    WIDTH_INVALID : null,
Q
quanli 已提交
70 71
}

Q
quanli 已提交
72
export default function ACTS_WifiTest() {
Q
q00313334 已提交
73
describe('ACTS_WifiTest', function() {
W
wtwanga 已提交
74

Q
q00313334 已提交
75 76 77
    beforeEach(function() {
        checkWifiPowerOn();
    })
Q
q00313334 已提交
78

Q
q00313334 已提交
79
    afterEach(function() {})
Q
q00313334 已提交
80

W
wtwanga 已提交
81

Q
q00313334 已提交
82 83 84
    /**
     * @tc.number     open_0001
     * @tc.name       SUB_Communication_WiFi_Sta_Open_0001
Q
quanli 已提交
85 86
     * @since 6
     * @tc.desc       Test wifi.isWifiActive API functionality.
Q
q00313334 已提交
87
     */
Q
quanli 已提交
88 89
    it('SUB_Communication_WiFi_Sta_WifiActive_0001', 0,  function() {
        sleep(3000);
Q
q00313334 已提交
90
        console.log("[wifi_test]  check the state of wifi: " + wifi.isWifiActive());
Q
q00313334 已提交
91
        expect(wifi.isWifiActive()).assertTrue();
Q
q00313334 已提交
92
    })
Q
q00313334 已提交
93

Q
q00313334 已提交
94 95 96 97 98
    /**
     * @tc.number     Scan_0001
     * @tc.name       SUB_Communication_WiFi_Sta_Scan_0001
     * @tc.desc       Test get ScanInfos callback API functionality.
     */
Q
q00313334 已提交
99
    it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) { 
Q
q00313334 已提交
100
        let scan = wifi.scan();
Q
quanli 已提交
101
        sleep(3000);
Q
q00313334 已提交
102 103
        console.log("[wifi_test] open wifi scan result: " + scan);
        expect(scan).assertTrue();
Q
q00313334 已提交
104

Q
q00313334 已提交
105 106
        await wifi.getScanInfos()
            .then(result => {
Q
q00313334 已提交
107
                let clen = Object.keys(result).length;
Q
q00313334 已提交
108 109 110 111
                expect(clen).assertLarger(0);
                console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
            });

Q
q00313334 已提交
112
        wifi.getScanInfos(
113 114 115 116
            (err,result) => {
                if(err) {
                    console.log("[wifi_test] wifi getScanInfos failed " + err);
                }
Q
q00313334 已提交
117
                let clen = Object.keys(result).length;
Q
q00313334 已提交
118
                if (!(clen == 0)) {
Q
q00313334 已提交
119 120
                    expect(clen).assertLarger(0);
                    console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
Q
q00313334 已提交
121 122 123 124 125 126
                    for (let j = 0; j < clen; ++j) {
                        console.info("ssid: " + result[j].ssid + "bssid: " + result[j].bssid + 
                        "securityType: " + result[j].securityType + 
                         "rssi: " + result[j].rssi + "band: " + result[j].band + 
                          "frequency: " + result[j].frequency +
                          "timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities
Q
quanli 已提交
127 128 129
                          + "channelWidth: " + result[j].channelWidth+"centerFrequency0"+result[j].centerFrequency0
                          +"centerFrequency1"+result[j].centerFrequency1+"infoElems"+result[j].infoElems
                          );
Q
q00313334 已提交
130
                    }
Q
q00313334 已提交
131
                }
Q
q00313334 已提交
132
                done()
Q
q00313334 已提交
133 134
            });
    })
Q
q00313334 已提交
135 136 137 138

    /**
     * @tc.number     Scan_0004
     * @tc.name       SUB_Communication_WiFi_Sta_Scan_0004
Q
quanli 已提交
139
     * @since 7
Q
q00313334 已提交
140 141
     * @tc.desc       Test wifi.getSignalLevel API functionality.
     */
Q
q00313334 已提交
142
    it('SUB_Communication_WiFi_Sta_Scan_0004', 0,  function() {
Q
q00313334 已提交
143
        console.info("[wifi_test] check the 2.4G rssi assgined to level test.");
Q
quanli 已提交
144
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-65,1));
Q
q00313334 已提交
145
        expect(wifi.getSignalLevel(-65, 1)).assertEqual(4);
Q
quanli 已提交
146
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-66,1));
Q
q00313334 已提交
147
        expect(wifi.getSignalLevel(-66, 1)).assertEqual(3);
Q
quanli 已提交
148
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-75,1));
Q
q00313334 已提交
149
        expect(wifi.getSignalLevel(-75, 1)).assertEqual(3);
Q
quanli 已提交
150
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-76,1));
Q
q00313334 已提交
151
        expect(wifi.getSignalLevel(-76, 1)).assertEqual(2);
Q
quanli 已提交
152
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-82,1));
Q
q00313334 已提交
153
        expect(wifi.getSignalLevel(-82, 1)).assertEqual(2);
Q
quanli 已提交
154
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-83,1));
Q
q00313334 已提交
155
        expect(wifi.getSignalLevel(-83, 1)).assertEqual(1);
Q
quanli 已提交
156
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-88,1));
Q
q00313334 已提交
157
        expect(wifi.getSignalLevel(-88, 1)).assertEqual(1);
Q
quanli 已提交
158
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-89,1));
Q
q00313334 已提交
159
        expect(wifi.getSignalLevel(-89, 1)).assertEqual(0);
Q
quanli 已提交
160
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-127,1));
Q
q00313334 已提交
161 162
        expect(wifi.getSignalLevel(-127, 1)).assertEqual(0);
        console.info("[wifi_test] check the 5G rssi assgined to level test.");
Q
quanli 已提交
163
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-65,2));
Q
q00313334 已提交
164
        expect(wifi.getSignalLevel(-65, 2)).assertEqual(4);
Q
quanli 已提交
165
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-66,2));
Q
q00313334 已提交
166
        expect(wifi.getSignalLevel(-66, 2)).assertEqual(3);
Q
quanli 已提交
167
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-72,2));
Q
q00313334 已提交
168
        expect(wifi.getSignalLevel(-72, 2)).assertEqual(3);
Q
quanli 已提交
169
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-73,2));
Q
q00313334 已提交
170
        expect(wifi.getSignalLevel(-73, 2)).assertEqual(2);
Q
quanli 已提交
171
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-79,2));
Q
q00313334 已提交
172
        expect(wifi.getSignalLevel(-79, 2)).assertEqual(2);
Q
quanli 已提交
173
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-80,2));
Q
q00313334 已提交
174
        expect(wifi.getSignalLevel(-80, 2)).assertEqual(1);
Q
quanli 已提交
175
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-85,2));
Q
q00313334 已提交
176
        expect(wifi.getSignalLevel(-85, 2)).assertEqual(1);
Q
quanli 已提交
177
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-86,2));
Q
q00313334 已提交
178
        expect(wifi.getSignalLevel(-86, 2)).assertEqual(0);
Q
quanli 已提交
179
        console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-127,2));
Q
q00313334 已提交
180
        expect(wifi.getSignalLevel(-127, 2)).assertEqual(0);
Q
q00313334 已提交
181
       
Q
q00313334 已提交
182 183
    })

Q
q00313334 已提交
184 185 186 187 188

    /**
     * @tc.number SUB_Communication_WiFi_Sta_info_0002
     * @tc.name testgetCountryCode
     * @tc.desc Test getCountryCode api.
Q
quanli 已提交
189
     * @since 7
Q
q00313334 已提交
190 191 192
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 3
Q
q00313334 已提交
193
     */
Q
q00313334 已提交
194
    it('SUB_Communication_WiFi_Sta_Info_0002', 0,  function() {
Q
q00313334 已提交
195
        expect(wifi.isWifiActive()).assertTrue();
Q
q00313334 已提交
196
        let countryCode = wifi.getCountryCode();
Q
q00313334 已提交
197
        console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode));
Q
quanli 已提交
198 199
        console.info("[wifi_test] getCountryCode.length -> " + JSON.stringify(countryCode.length));
        expect(true).assertEqual(countryCode.length == 2);
Q
q00313334 已提交
200
    })
Q
q00313334 已提交
201 202 203 204 205
   
    /**
     * @tc.number SUB_Communication_WiFi_Sta_info_0004
     * @tc.name testFeatureSupported
     * @tc.desc Test FeatureSupported api.
Q
quanli 已提交
206
     * @since 7
Q
q00313334 已提交
207 208 209 210
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 3
     */
Q
q00313334 已提交
211 212

    it('SUB_Communication_WiFi_Sta_info_0004', 0,  function () {
Q
q00313334 已提交
213
        expect(wifi.isWifiActive()).assertTrue();
Q
q00313334 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226
        let WifiUtils = {
            WIFI_FEATURE_INFRA: 0x0001,
            WIFI_FEATURE_INFRA_5G: 0x0002,
            WIFI_GAS_ANQP: 0x0004,
            WIFI_WIFI_DIRECT: 0x0008,
            WIFI_FEATURE_MOBILE_HOTSPOT: 0x0010,
            WIFI_FEATURE_AWARE: 0x0040,
            WIFI_FEATURE_AP_STA: 0x8000,
            WIFI_FEATURE_WPA3_SAE: 0x8000000,
            WIFI_FEATURE_WPA3_SUITE_B:0x10000000,
            WIFI_FEATURE_OWE:0x20000000
        }
        let isSupport1 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA);
Q
quanli 已提交
227
        console.info("[wifi_test] isFeatureSupported -> " + isSupport1);       
Q
q00313334 已提交
228
        let isSupport2 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA_5G);
Q
quanli 已提交
229
        console.info("[wifi_test] isFeatureSupported2 -> " + isSupport2);
Q
q00313334 已提交
230
        let isSupport3 = wifi.isFeatureSupported(WifiUtils.WIFI_GAS_ANQP);
Q
quanli 已提交
231
        console.info("[wifi_test] isFeatureSupported3 -> " + isSupport3);
Q
q00313334 已提交
232
        let isSupport4 = wifi.isFeatureSupported(WifiUtils.WIFI_WIFI_DIRECT);
Q
quanli 已提交
233
        console.info("[wifi_test] isFeatureSupported4 -> " + isSupport4);
Q
q00313334 已提交
234
        let isSupport5 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_MOBILE_HOTSPOT);
Q
quanli 已提交
235
        console.info("[wifi_test] isFeatureSupported5 -> " + isSupport5);
Q
q00313334 已提交
236
        let isSupport6 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AWARE);
Q
quanli 已提交
237
        console.info("[wifi_test] isFeatureSupported6 -> " + isSupport6);
Q
q00313334 已提交
238
        let isSupport7 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AP_STA);
Q
quanli 已提交
239
        console.info("[wifi_test] isFeatureSupported7 -> " + isSupport7);
Q
q00313334 已提交
240
        let isSupport8 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SAE);
Q
quanli 已提交
241
        console.info("[wifi_test] isFeatureSupported8 -> " + isSupport8);
Q
q00313334 已提交
242
        let isSupport9 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SUITE_B);
Q
quanli 已提交
243
        console.info("[wifi_test] isFeatureSupported9 -> " + isSupport9);
Q
q00313334 已提交
244
        let isSupport = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_OWE);
Q
quanli 已提交
245
        console.info("[wifi_test] isFeatureSupported -> " + isSupport);
Q
q00313334 已提交
246
    })
Q
q00313334 已提交
247
 
Q
q00313334 已提交
248 249 250
    /**
     * @tc.number     conn_Config_0002
     * @tc.name       SUB_Communication_WiFi_Sta_Conn_Info_0002
Q
quanli 已提交
251
     * @since 7
Q
q00313334 已提交
252
     * @tc.desc       Test getLinkedInfo information
253
     */
Q
q00313334 已提交
254
    it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) {
Q
quanli 已提交
255 256
        let isConnected = wifi.isConnected();
        expect(isConnected).assertFalse();
Q
q00313334 已提交
257
        await wifi.getLinkedInfo()
Q
q00313334 已提交
258 259
            .then((result) => {
                console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result));
Q
q00313334 已提交
260 261 262
                expect(JSON.stringify(result)).assertContain('band');
                done();
            }).catch((error) => {
Q
q00313334 已提交
263
                console.info("[wifi_test] promise then error." + JSON.stringify(error));
Q
q00313334 已提交
264 265
                expect().assertFail();
            });
Q
q00313334 已提交
266 267 268 269 270
    })

    /**
     * @tc.number     conn_Config_0003
     * @tc.name       SUB_Communication_WiFi_Sta_Conn_Info_0003
Q
quanli 已提交
271
     * @since 7
Q
q00313334 已提交
272 273 274
     * @tc.desc       Test getLinkedInfo callback information
     */
    it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function(done) {
Q
quanli 已提交
275
        wifi.getLinkedInfo(
Q
q00313334 已提交
276
            (err,result) => {
Q
q00313334 已提交
277
                if(err) {
Q
q00313334 已提交
278
                    console.log("[wifi_test] wifi getLinkedInfo failed " + err);
279
                }
Q
q00313334 已提交
280
                let clen = Object.keys(result).length;
Q
q00313334 已提交
281 282
                expect(clen).assertLarger(0);
                console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result));
Q
q00313334 已提交
283 284
                console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+
                "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted +
Q
quanli 已提交
285
                "chload: " + result.chload + "rssi " + result.rssi + "netWorkId" + result.netWorkId +
Q
q00313334 已提交
286
                "linkSpeed: " + result.linkSpeed + "frequency:" 
Q
quanli 已提交
287
                 + result.frequency + "snr:" +result.snr +
Q
q00313334 已提交
288
                "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress + 
Q
quanli 已提交
289 290 291 292
                "suppState" + result.suppState +"connState: " + result.connState+
                "macType: " + result.macType);

                let state = wifi.getLinkedInfo().connState;
Q
quanli 已提交
293
                if(state == ConnState.SCANNING){
Q
quanli 已提交
294 295
                    expect(true).assertEqual(state == 0);
                }
Q
quanli 已提交
296
                if(state == ConnState.CONNECTING){
Q
quanli 已提交
297 298
                    expect(true).assertEqual(state == 1);
                }
Q
quanli 已提交
299
                if(state == ConnState.AUTHENTICATING){
Q
quanli 已提交
300 301
                    expect(true).assertEqual(state == 2);
                }
Q
quanli 已提交
302
                if(state == ConnState.OBTAINING_IPADDR){
Q
quanli 已提交
303 304
                    expect(true).assertEqual(state == 3);
                }
Q
quanli 已提交
305
                if(state == ConnState.CONNECTED){
Q
quanli 已提交
306 307
                    expect(true).assertEqual(state == 4);
                }
Q
quanli 已提交
308
                if(state == ConnState.DISCONNECTING){
Q
quanli 已提交
309 310
                    expect(true).assertEqual(state == 5);
                }
Q
quanli 已提交
311
                if(state == ConnState.DISCONNECTED){
Q
quanli 已提交
312 313
                    expect(true).assertEqual(state == 6);
                }
Q
quanli 已提交
314
                if(state == ConnState.UNKNOWN){
Q
quanli 已提交
315 316
                    expect(true).assertEqual(state == 7);
                }
Q
q00313334 已提交
317
                done();
Q
q00313334 已提交
318
            });   
319 320
    })

Q
q00313334 已提交
321
    /**
Q
q00313334 已提交
322
    * @tc.number     Conn_Info_0001
Q
quanli 已提交
323 324
    * @tc.name       SUB_Communication_WiFi_Sta_Conn_Info_0003
    * @since 7
325 326
    * @tc.desc       Test get IpInfo information
    */
Q
quanli 已提交
327
    it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0,  function () {
Q
q00313334 已提交
328
        let isConnected= wifi.isConnected();
Q
q00313334 已提交
329
        expect(isConnected).assertFalse();
Q
q00313334 已提交
330
        let ipInfo = wifi.getIpInfo();
331
        expect(JSON.stringify(ipInfo)).assertContain("gateway");
Q
quanli 已提交
332 333
        let ipAddress = resolveIP(ipInfo.ipAddress);
        console.info("ipAddress result: " + ipAddress);
Q
q00313334 已提交
334 335 336 337 338
        console.info("gateway: " + ipInfo.gateway + "ipAddress: " + ipInfo.ipAddress
         + "leaseDuration: " + ipInfo.leaseDuration + 
        "leaseDuration: " + ipInfo.leaseDuration + 
        "netmask: " + ipInfo.netmask + "primaryDns:" + ipInfo.primaryDns +
        "secondDns: " + ipInfo.secondDns + "serverIp: " + ipInfo.serverIp );
Q
q00313334 已提交
339
    })
Q
q00313334 已提交
340 341 342 343

   /**
    * @tc.number     wifiStateChange_0001
    * @tc.name       SUB_Communication_WiFi_Sta_wifiStateChange_0001
Q
quanli 已提交
344
    * @since 7
Q
q00313334 已提交
345 346 347
    * @tc.desc       Test wifiStateChange callback
    */
    it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) {
Q
q00313334 已提交
348 349 350 351 352
        wifi.on('wifiStateChange', async result => {
             console.info("wifiStateChange callback, result:" + JSON.stringify(result));
             expect(true).assertEqual(result !=null);
             let promise = new Promise((resolve) => {
                wifi.off('wifiStateChange', result => {
Q
q00313334 已提交
353
                    console.info("offwifiStateChange callback, result: " + JSON.stringify(result));
Q
q00313334 已提交
354 355 356 357 358
                    expect(true).assertEqual(result !=null);
                    resolve()
                });
            })
             await promise.then(done)
Q
q00313334 已提交
359 360
        }); 
        done();
Q
q00313334 已提交
361 362
    })

Q
q00313334 已提交
363
  /**
Q
q00313334 已提交
364 365
    * @tc.number     wifiConnectionChange_0002
    * @tc.name       SUB_Communication_WiFi_Sta_wifiConnectionChange_0002
Q
quanli 已提交
366
    * @since 7
Q
q00313334 已提交
367
    * @tc.desc       Test wifiStateChange callback
Q
q00313334 已提交
368 369
    */
    it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) {
Q
q00313334 已提交
370
        wifi.on('wifiConnectionChange', async result => {
Q
q00313334 已提交
371 372 373
            console.info("wifiConnectionChange callback, result:" + JSON.stringify(result));
            expect(true).assertEqual(result !=null);
            let promise = new Promise((resolve) => {
Q
q00313334 已提交
374 375 376 377 378 379 380
                console.info('[wifi_test] offwifiConnectionChange test start ...');
                wifi.off('wifiConnectionChange', result => {
                    console.info("offwifiConnectionChange callback, result:  " + JSON.stringify(result));
                    expect(true).assertEqual(result !=null);
                    resolve()
                });
            })
Q
q00313334 已提交
381
            await promise.then(done)
Q
q00313334 已提交
382 383
         });
        done(); 
Q
q00313334 已提交
384
    })
Q
q00313334 已提交
385

Q
q00313334 已提交
386
   /**
Q
q00313334 已提交
387 388
    * @tc.number     wifiScanStateChange_0003
    * @tc.name       SUB_Communication_WiFi_Sta_wifiScanStateChange_0003
Q
quanli 已提交
389
    * @since 7
Q
q00313334 已提交
390
    * @tc.desc       Test wifiScanStateChange callback
Q
q00313334 已提交
391 392
    */
    it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) {
Q
q00313334 已提交
393 394 395 396 397 398 399 400 401 402 403 404 405
        wifi.on('wifiScanStateChange', async result => {
             console.info("wifiScanStateChange callback, result:" + JSON.stringify(result));
             expect(true).assertEqual(result !=null);
             let promise = new Promise((resolve) => {
                console.info('[wifi_test] offwifiScanStateChange test start ...');
                wifi.off('wifiScanStateChange', result => {
                    console.info("offwifiScanStateChange callback, result:  " + JSON.stringify(result));
                    expect(true).assertEqual(result !=null);
                    resolve()
                });
            })
             await promise.then(done)
         });  
Q
q00313334 已提交
406
        let scan = wifi.scan();
Q
quanli 已提交
407
        sleep(3000);
Q
q00313334 已提交
408 409
        done();  
       
Q
q00313334 已提交
410
    })
Q
q00313334 已提交
411
 
Q
q00313334 已提交
412 413
   /**
    * @tc.number     wifiRssiChange_0004
Q
q00313334 已提交
414
    * @tc.name       SUB_Communication_WiFi_Sta_wifiRssiChange_0004
Q
quanli 已提交
415
    * @since 7
Q
q00313334 已提交
416 417
    * @tc.desc       Test wifiRssiChange callback
    */
Q
q00313334 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
   it('SUB_Communication_WiFi_Sta_wifiRssiChange_0004', 0, async function (done) {
        wifi.on('wifiRssiChange', async result => {
             console.info("wifiRssiChange callback, result:" + JSON.stringify(result));
             expect(true).assertEqual(result !=null);
             let promise = new Promise((resolve) => {
                console.info('[wifi_test] offwifiRssiChange test start ...');
                wifi.off('wifiRssiChange', result => {
                    console.info("offwifiRssiChange callback, result:  " + JSON.stringify(result));
                    expect(true).assertEqual(result !=null);
                    resolve()
                });
            })
            await promise.then(done)
         });  
         done();  
Q
q00313334 已提交
433
           
Q
q00313334 已提交
434
    })
Q
q00313334 已提交
435
 
Q
q00313334 已提交
436 437 438 439
    /**
     * @tc.number SUB_Communication_WiFi_Hotspot_ON_0001
     * @tc.name testhotspotStateChangeOn
     * @tc.desc Test hotspotStateChangeOn api.
Q
quanli 已提交
440
     * @since 7
Q
q00313334 已提交
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) {
        console.info("[wifi_test]hotspotStateChange On test");
        try {
            await wifi.on('hotspotStateChange', (data) => {
                console.info("[wifi_test] hotspotStateChange On ->" + data);
                expect(true).assertEqual(data != null);
            });
            
        }catch(e) {
            expect(null).assertFail();
        }
        done();
    })
    
    /**
     * @tc.number SUB_Communication_WiFi_Hotspot_Off_0002
     * @tc.name testhotspotStateChangeOff
     * @tc.desc Test hotspotStateChange api.
Q
quanli 已提交
463
     * @since 7
Q
q00313334 已提交
464 465 466 467
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 3
     */
Q
quanli 已提交
468
    it('SUB_Communication_WiFi_Hotspot_Off_0002', 0, async function (done) {
Q
q00313334 已提交
469 470 471 472 473 474 475 476 477 478 479
        try {
           await wifi.off('hotspotStateChange', (data) => {
                console.info("[wifi_test] hotspotStateChange Off ->" + data);
                expect(true).assertEqual(data != null);
                console.info("[wifi_test] wifiRssiChange unregister end");
            });
            
        }catch(e) {
            expect(null).assertFail();
        }
        done();
Q
q00313334 已提交
480
    })
Q
q00313334 已提交
481 482
    console.log("*************[wifi_test] start wifi js unit test end*************");
})
Q
quanli 已提交
483
}
484