未验证 提交 7caee5bf 编写于 作者: O openharmony_ci 提交者: Gitee

!5253 【communication】修改WIFI JS L2测试用例

Merge pull request !5253 from 权力/myfeature
......@@ -475,7 +475,7 @@ describe('bluetoothhostTest', function() {
}]);
await sleep(1000);
console.info('[bluetooth_js] BLE scan off14 ');
bluetooth.BLE.off('BLEDeviceFind');
bluetooth.BLE.stopBLEScan();
bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
done();
......
......@@ -12,10 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import actsWifiTestNew from './WifiP2P.testsame.js'
import actsWifiTest from './WifiP2P.test2.js'
import actsWifiFunctionTest from './WifiP2PFunction.test.js'
import actsWifiEventTest from './WifiP2PEvent.test.js'
export default function testsuite() {
actsWifiTestNew()
actsWifiTest()
actsWifiFunctionTest()
actsWifiEventTest()
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* 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.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
export default function actsWifiTestNew() {
describe('actsWifiTestNew', function () {
beforeEach(function () {
checkWifiPowerOn();
})
afterEach(function () {
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0009
* @tc.name testp2pCancelConnect
* @tc.desc Test p2pCancelConnect Group API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) {
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : 0
};
let addConfig = wifi.createGroup(WifiP2PConfig);
console.info("[wifi_test] test p2pConnect result." + addConfig);
let disConn = wifi.p2pCancelConnect();
sleep(2000);
console.info("[wifi_test] test p2pCancelConnect result." + disConn);
expect(disConn).assertTrue();
let removeConfig = wifi.removeGroup();
console.info("[wifi_test] test start removeGroup" + removeConfig);
expect(removeConfig).assertTrue();
done();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0011
* @tc.name testremoveGroup
* @tc.desc Test remove error Group functionality.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) {
let isRemoved = wifi.removeGroup(10000);
console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved));
expect(isRemoved).assertTrue();
done();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0002
* @tc.name testP2pLocalDevice
* @tc.desc Test get TO P2pLocalDevice API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_XTS_P2P_0002', 0, async function (done) {
await wifi.getP2pLocalDevice()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test] getP2pLocalDevice [promise] result :" + JSON.stringify(data));
expect(true).assertEqual(resultLength >= 0);
}).catch((error) => {
console.info("[wifi_test]getP2pLocalDevice promise error." + JSON.stringify(error));
expect().assertFail();
});
function getP2pLocal(){
return new Promise((resolve, reject) => {
wifi.getP2pLocalDevice(
(err, ret) => {
if(err) {
console.info("[wifi_test]getP2pLocalDevice callback failed : " + JSON.stringify(err));
return;
}
console.info("[wifi_test] getP2pLocalDevice callback result: " + JSON.stringify(ret));
console.info("deviceName: " + ret.deviceName + "deviceAddress: " +
ret.deviceAddress + "primaryDeviceType: " + ret.primaryDeviceType +
"deviceStatus: " + ret.deviceStatus + "groupCapabilitys: " +
ret.groupCapabilitys );
resolve();
});
});
}
await getP2pLocal();
done();
})
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* 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.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
let GroupOwnerBand = {
GO_BAND_AUTO : 0,
GO_BAND_2GHZ : 1,
GO_BAND_5GHZ : 2,
}
export default function actsWifiEventTest() {
describe('actsWifiEventTest', function () {
beforeEach(function () {
console.info("beforeEach start" );
checkWifiPowerOn();
})
afterEach(async function () {
console.info("afterEach start" );
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0008', 0, async function (done) {
await wifi.on('p2pStateChange', result => {
console.info("onP2pStateChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual(result !=null);
done();
});
setTimeout(function() {
wifi.off('p2pStateChange', result => {
console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}, 1 * 1000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0009', 0, async function (done) {
await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => {
console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc);
expect(true).assertEqual(recvP2pConnectionChangeFunc !=null);
done();
});
setTimeout(function() {
console.info('[wifi_test] offP2pStateChange test start ...');
wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => {
console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc));
expect(true).assertEqual(recvP2pConnectionChangeFunc !=null);
});
}, 1 * 1000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0012', 0, async function (done) {
console.info('[wifi_test] Onp2pDeviceChange test start ...');
await wifi.on('p2pDeviceChange', result => {
console.info("onP2pDeviceChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual(result !=null);
done();
});
setTimeout(function() {
console.info('[wifi_test] offP2pDeviceChange test start ...');
wifi.off('p2pDeviceChange', result => {
console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}, 1 * 1000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0010
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0010', 0, async function (done) {
let recvP2pPeerDeviceChangeFunc = result => {
console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result));
wifi.getP2pDevices((err, data) => {
if (err) {
console.error('wifi_test / failed to get getP2pDevices: ' + JSON.stringify(err));
return;
}
console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data));
let len = Object.keys(data).length;
console.log("getP2pDevices number: " + len);
for (let i = 0; i < len; ++i) {
if (data[i].deviceName === "GRE") {
console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress);
let config = {
"deviceAddress":data[i].deviceAddress,
"netId":-1,
"passphrase":"",
"groupName":"",
"goBand":0,
}
wifi.p2pConnect(config);
}
}
});
}
await wifi.on('p2pPeerDeviceChange', result => {
console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual(result !=null);
done();
});
setTimeout(function() {
wifi.off('p2pPeerDeviceChange', result => {
console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}, 1 * 1000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0013', 0, async function (done) {
let recvP2pPersistentGroupChangeFunc = () => {
console.info("wifi_test / p2p persistent group change receive event");
let config = {
"deviceAddress" : "02:11:65:f2:0d:6e",
"netId":-2,
"passphrase":"",
"groupName":"",
"goBand":0,
};
let addConfig = wifi.createGroup(config);
expect(addConfig).assertTrue();
wifi.getCurrentGroup((err, data) => {
if (err) {
console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err));
return;
}
console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data));
});
};
wifi.on("p2pPersistentGroupChange",recvP2pPersistentGroupChangeFunc);
setTimeout(async function() {
wifi.off('p2pPersistentGroupChange', result => {
console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}, 1 * 1000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0011', 0, async function (done) {
await wifi.on('p2pDiscoveryChange', result => {
console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual((result !=null));
done();
});
setTimeout(function() {
wifi.off('p2pDiscoveryChange', result => {
console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
}, 1 * 1000);
done();
})
console.log("*************[wifi_test] start wifi js unit test end*************");
})
}
......@@ -12,10 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import actsWifiTestNew from './WifiJsunit.test1.js'
import actsWifiTest from './WifiJsunit.testsame.js'
import actsWifiCandidateNetWorkTest from './WifiCandidateNetWork.test.js'
import actsWifiFunctionsTest from './WifiStationFunctions.test.js'
import actsWifiEventTest from './WifiStationEvent.test.js'
export default function testsuite() {
actsWifiTestNew()
actsWifiTest()
actsWifiCandidateNetWorkTest()
actsWifiFunctionsTest()
actsWifiEventTest()
}
......@@ -56,8 +56,8 @@ let WifiChannelWidth = {
WIDTH_INVALID:null,
}
export default function actsWifiTestNew() {
describe('actsWifiTestNew', function () {
export default function actsWifiCandidateNetWorkTest() {
describe('actsWifiCandidateNetWorkTest', function () {
beforeEach(function () {
checkWifiPowerOn();
})
......@@ -65,12 +65,11 @@ export default function actsWifiTestNew() {
})
/**
* @tc.number CandidateNetWork_0001
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0001
* @since 9
* @tc.desc Test add OPEN and WEP CandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0001
* @tc.name testaddCandidateConfig
* @tc.desc Test add OPEN and WEP CandidateConfig Promise API functionality.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0001', 0, async function (done) {
let wifiDeviceConfig = {
......@@ -113,12 +112,11 @@ export default function actsWifiTestNew() {
})
/**
* @tc.number CandidateNetWork_0001
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0002
* @since 8
* @tc.desc Test add PSK CandidateConfig and removeCandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0002
* @tc.name testaddCandidateConfig
* @tc.desc Test add PSK CandidateConfig and removeCandidateConfig Promise API functionality.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0002', 0, async function (done) {
let wifiDeviceConfig = {
......@@ -156,12 +154,11 @@ export default function actsWifiTestNew() {
})
/**
* @tc.number CandidateNetWork_0003
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0003
* @since 8
* @tc.desc Test add SAE CandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0003
* @tc.name testaddCandidateConfig
* @tc.desc Test add SAE CandidateConfig Promise API functionality.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0003', 0, async function (done) {
let wifiDeviceConfig = {
......@@ -198,12 +195,72 @@ export default function actsWifiTestNew() {
})
/**
* @tc.number CandidateNetWork_0005
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0005
* @since 8
* @tc.desc Test add CandidateConfig and removeCandidateConfig callback API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0004
* @tc.name testaddCandidateConfig
* @tc.desc Test add MAX CandidateConfig and removeall CandidateConfig.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0004', 0, async function (done) {
let SSID = "TYPE_PSK"
for (let i = 0; i < 16; i++) {
SSID = "TYPE_PSK" + i
console.info("[wifi_test] get canshu result : ");
let wifiDeviceConfig = {
"ssid": SSID,
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
};
console.info("[wifi_test] get wifiDeviceConfig ssid result : " + JSON.stringify(wifiDeviceConfig.ssid));
await wifi.addCandidateConfig(wifiDeviceConfig)
.then(netWorkId => {
console.info("[wifi_test]add 16th CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
}).catch((error) => {
console.error('[wifi_js] add 16th CandidateConfig promise failed -> ' + JSON.stringify(error));
expect().assertFail();
});
}
let wifiDeviceConfig1 = {
"ssid": "TYPE_17",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
};
await wifi.addCandidateConfig(wifiDeviceConfig1)
.then(netWorkId => {
console.info("[wifi_test]add 17th CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
}).catch((error) => {
console.error('[wifi_js] add 17th CandidateConfig promise failed -> ' + JSON.stringify(error));
});
let getconfig = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get 16 CandidateConfigs result : " + JSON.stringify(getconfig));
for (let i = 0; i < 16; i++) {
var networkId = getconfig[i].netId;
console.info("[wifi_test] wifi get networkId result : " + JSON.stringify(networkId));
await wifi.removeCandidateConfig(networkId)
.then(ret => {
console.info("[wifi_test]remove CandidateConfig promise" + JSON.stringify(ret));
let getconfig1 = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig1));
console.info("[wifi_test] wifi getconfiglength result : " + JSON.stringify(getconfig1.length));
}).catch((error) => {
console.error('[wifi_js] remove CandidateConfig promise failed -> ' + JSON.stringify(error));
});
}
done();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0005
* @tc.name testaddCandidateConfig
* @tc.desc Test add CandidateConfig and removeCandidateConfig callback API functionality.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0005', 0, async function (done) {
let wifiDeviceConfig = {
......@@ -249,18 +306,16 @@ export default function actsWifiTestNew() {
});
});
}
await removeCandidate();
done();
})
/**
* @tc.number CandidateNetWork_0006
* @tc.name SUB_Communication_WiFi_XTS_SUB_Communication_WiFi_XTS_CandidateNetWork_0006
* @tc.desc Test connect To CandidateConfig API functionality.
* @since 9
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
* @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0006
* @tc.name testaddCandidateConfig
* @tc.desc Test connect To CandidateConfig API functionality.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0006', 0, async function (done) {
let WifiSecurityType = {
......@@ -302,69 +357,6 @@ export default function actsWifiTestNew() {
done();
})
/**
* @tc.number Sta_0002
* @tc.name SUB_Communication_WiFi_XTS_Sta_0002
* @tc.desc Test get to ScanInfos promise and callback API functionality.
* @since 6
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION)
*/
it('SUB_Communication_WiFi_XTS_Sta_0002', 0, async function (done) {
await wifi.getScanInfos()
.then(result => {
let clen = Object.keys(result).length;
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
});
function getScanInfos() {
return new Promise((resolve, reject) => {
wifi.getScanInfos(
(err, result) => {
if (err) {
console.log("[wifi_test] wifi getScanInfos failed " + err);
}
let clen = Object.keys(result).length;
if (!(clen == 0)) {
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
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 + "channelWidth: " + result[j].channelWidth +
"timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities
+ "centerFrequency0: " + result[j].centerFrequency0
+ "centerFrequency1: " + result[j].centerFrequency1
+ "infoElems: " + result[j].infoElems);
}
}
resolve();
});
});
}
await getScanInfos();
done();
})
/**
* @tc.number Sta_0034
* @tc.name SUB_Communication_WiFi_XTS_Sta_0034
* @tc.desc Test get to ScanInfos Sync API functionality.
* @since 9
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION)
*/
it('SUB_Communication_WiFi_XTS_Sta_0034', 0, async function (done) {
let getScanInfos = wifi.getScanInfosSync();
console.info("[wifi_test] wifi get to ScanInfosSync result : " + JSON.stringify(getScanInfos));
let lenth = Object.keys(getScanInfos).length;
console.info("[wifi_test] wifi ScanInfosSync length result : " + JSON.stringify(lenth));
expect(lenth).assertLarger(0);
done();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_UntrustedConfig_0001
* @tc.name testaddUntrustedConfig
......@@ -448,3 +440,7 @@ export default function actsWifiTestNew() {
})
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* 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.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
function resolveIP(ip) {
return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF);
}
let WifiSecurityType = {
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,
}
let ConnState = {
SCANNING: 0,
CONNECTING: 1,
AUTHENTICATING: 2,
OBTAINING_IPADDR: 3,
CONNECTED: 4,
DISCONNECTING: 5,
DISCONNECTED: 6,
UNKNOWN: 7,
}
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_80MHZ_PLUS : 4,
WIDTH_INVALID:null,
}
export default function actsWifiEventTest() {
describe('actsWifiEventTest', function() {
beforeEach(function () {
checkWifiPowerOn();
})
afterEach(function () {
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0001
* @tc.name testwifiStateChange
* @tc.desc Test wifiStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0001', 0, async function (done) {
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 => {
console.info("offwifiStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result != null);
resolve()
});
})
await promise.then(done)
});
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0002
* @tc.name testwifiConnectionChange
* @tc.desc Test wifiConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0002', 0, async function (done) {
wifi.on('wifiConnectionChange', async result => {
console.info("wifiConnectionChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual(result != null);
let promise = new Promise((resolve) => {
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()
});
})
await promise.then(done)
});
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0003
* @tc.name testwifiScanStateChange
* @tc.desc Test Test wifiScanStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0003', 0, async function (done) {
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)
});
let scan = wifi.scan();
await sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0004
* @tc.name testwifiRssiChange
* @tc.desc Test wifiRssiChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_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();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0005
* @tc.name testhotspotStateChange
* @tc.desc Test hotspotStateChange api.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0005', 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();
}
console.info("[wifi_test]hotspotStateChange Off test");
try {
await wifi.off('hotspotStateChange', (data) => {
console.info("[wifi_test] hotspotStateChange Off ->" + data);
expect(true).assertEqual(data != null);
});
} catch (e) {
expect(null).assertFail();
}
done();
})
console.log("*************[wifi_test] start wifi js unit test end*************");
})
}
......@@ -66,8 +66,8 @@ let WifiChannelWidth = {
WIDTH_INVALID:null,
}
export default function actsWifiTest() {
describe('actsWifiTest', function() {
export default function actsWifiFunctionsTest() {
describe('actsWifiFunctionsTest', function() {
beforeEach(function () {
checkWifiPowerOn();
})
......@@ -77,43 +77,47 @@ export default function actsWifiTest() {
/**
* @tc.number SUB_Communication_WiFi_XTS_Sta_0002
* @tc.name testgetScanInfos
* @tc.desc Test get ScanInfos callback API functionality..
* @tc.desc Test get to ScanInfos promise and callback API functionality.
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_Communication_WiFi_XTS_Sta_0002', 0, async function (done) {
let scan = wifi.scan();
sleep(3000);
console.log("[wifi_test] open wifi scan result: " + scan);
await sleep(3000);
await wifi.getScanInfos()
.then(result => {
let clen = Object.keys(result).length;
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
});
wifi.getScanInfos(
(err, result) => {
if (err) {
console.log("[wifi_test] wifi getScanInfos failed " + err);
}
let clen = Object.keys(result).length;
if (!(clen == 0)) {
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
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
+ "channelWidth: " + result[j].channelWidth + "centerFrequency0: "
+ result[j].centerFrequency0
+ "centerFrequency1: " + result[j].centerFrequency1
+ "infoElems: " + result[j].infoElems);
}
}
done()
function getScanInfos() {
return new Promise((resolve, reject) => {
wifi.getScanInfos(
(err, result) => {
if (err) {
console.log("[wifi_test] wifi getScanInfos failed " + err);
}
let clen = Object.keys(result).length;
if (!(clen == 0)) {
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
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 + "channelWidth: " + result[j].channelWidth +
"timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities
+ "centerFrequency0: " + result[j].centerFrequency0
+ "centerFrequency1: " + result[j].centerFrequency1
+ "infoElems: " + result[j].infoElems);
}
}
resolve();
});
});
}
await getScanInfos();
done();
})
/**
......@@ -297,163 +301,24 @@ export default function actsWifiTest() {
});
})
/**
* @tc.number Conn_Info_0003
* @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003
* @since 7
* @tc.desc Test get IpInfo information
*/
it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, function () {
let isConnected = wifi.isConnected();
expect(isConnected).assertFalse();
let ipInfo = wifi.getIpInfo();
expect(JSON.stringify(ipInfo)).assertContain("gateway");
let ipAddress = resolveIP(ipInfo.ipAddress);
console.info("ipAddress result: " + ipAddress);
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);
})
/**
* @tc.number wifiStateChange_0001
* @tc.name SUB_Communication_WiFi_Sta_wifiStateChange_0001
* @since 7
* @tc.desc Test wifiStateChange callback
*/
it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) {
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 => {
console.info("offwifiStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result != null);
resolve()
});
})
await promise.then(done)
});
done();
})
/**
* @tc.number wifiConnectionChange_0002
* @tc.name SUB_Communication_WiFi_Sta_wifiConnectionChange_0002
* @since 7
* @tc.desc Test wifiStateChange callback
*/
it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) {
wifi.on('wifiConnectionChange', async result => {
console.info("wifiConnectionChange callback, result:" + JSON.stringify(result));
expect(true).assertEqual(result != null);
let promise = new Promise((resolve) => {
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()
});
})
await promise.then(done)
});
done();
})
/**
* @tc.number wifiScanStateChange_0003
* @tc.name SUB_Communication_WiFi_Sta_wifiScanStateChange_0003
* @since 7
* @tc.desc Test wifiScanStateChange callback
*/
it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) {
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)
});
let scan = wifi.scan();
sleep(3000);
done();
})
/**
* @tc.number wifiRssiChange_0004
* @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0004
* @since 7
* @tc.desc Test wifiRssiChange callback
*/
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();
})
/**
* @tc.number SUB_Communication_WiFi_Hotspot_ON_0001
* @tc.name testhotspotStateChangeOn
* @since 7
* @tc.desc Test hotspotStateChangeOn api.
* @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
* @since 7
* @tc.desc Test hotspotStateChange api.
* @tc.size MEDIUM
/**
* @tc.number SUB_Communication_WiFi_XTS_Sta_0034
* @tc.name testgetScanInfosSync
* @tc.desc Test get to ScanInfos Sync API functionality.
* @tc.type Function
* @tc.level Level 3
* @tc.level Level 0
*/
it('SUB_Communication_WiFi_Hotspot_Off_0002', 0, async function (done) {
console.info("[wifi_test]hotspotStateChange Off test");
try {
await wifi.off('hotspotStateChange', (data) => {
console.info("[wifi_test] hotspotStateChange Off ->" + data);
expect(true).assertEqual(data != null);
});
} catch (e) {
expect(null).assertFail();
}
it('SUB_Communication_WiFi_XTS_Sta_0034', 0, async function (done) {
let getScanInfos = wifi.getScanInfosSync();
console.info("[wifi_test] wifi get to ScanInfosSync result : " + JSON.stringify(getScanInfos));
let lenth = Object.keys(getScanInfos).length;
console.info("[wifi_test] wifi ScanInfosSync length result : " + JSON.stringify(lenth));
expect(lenth).assertLarger(0);
done();
})
console.log("*************[wifi_test] start wifi js unit test end*************");
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册