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 'deccjsunit/index'
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 69 70 71
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,
    WIDTH_INVALID
}

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

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

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

W
wtwanga 已提交
80

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

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

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

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

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

Q
q00313334 已提交
183 184 185 186 187

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

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

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

                let state = wifi.getLinkedInfo().connState;
                if(state == connState.SCANNING){
                    expect(true).assertEqual(state == 0);
                }
                if(state == connState.CONNECTING){
                    expect(true).assertEqual(state == 1);
                }
                if(state == connState.AUTHENTICATING){
                    expect(true).assertEqual(state == 2);
                }
                if(state == connState.OBTAINING_IPADDR){
                    expect(true).assertEqual(state == 3);
                }
                if(state == connState.CONNECTED){
                    expect(true).assertEqual(state == 4);
                }
                if(state == connState.DISCONNECTING){
                    expect(true).assertEqual(state == 5);
                }
                if(state == connState.DISCONNECTED){
                    expect(true).assertEqual(state == 6);
                }
                if(state == connState.UNKNOWN){
                    expect(true).assertEqual(state == 7);
                }
Q
q00313334 已提交
316
                done();
Q
q00313334 已提交
317
            });   
318 319
    })

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

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

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

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