未验证 提交 0a24adaf 编写于 作者: O openharmony_ci 提交者: Gitee

!2191 【communication】修改WIFI JS 3568测试用例超时问题

Merge pull request !2191 from 权力/myfeature1
...@@ -17,16 +17,11 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -17,16 +17,11 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
// delay x ms
function sleep(delay) { function sleep(delay) {
var start = (new Date()).getTime(); return new Promise(resovle => setTimeout(resovle, delay))
while(true){
if((new Date()).getTime() - start > delay) {
break;
}
}
} }
var GroupOwnerBand = { var GroupOwnerBand = {
GO_BAND_AUTO : 0, GO_BAND_AUTO : 0,
GO_BAND_2GHZ : 1, GO_BAND_2GHZ : 1,
...@@ -47,7 +42,7 @@ describe('ACTS_WifiTest', function () { ...@@ -47,7 +42,7 @@ describe('ACTS_WifiTest', function () {
* @tc.desc Test setDeviceName infos * @tc.desc Test setDeviceName infos
*/ */
it('SUB_Communication_WiFi_P2P_Setting_0001', 0, function() { it('SUB_Communication_WiFi_P2P_Setting_0001', 0, function() {
console.info("[wifi_test] check the state of wifi, if it's close, open it."); console.info("[wifi_test] test setDeviceName start.");
var devName = wifi.setDeviceName("P2PTest"); var devName = wifi.setDeviceName("P2PTest");
console.info("[wifi_test] test start setDeviceName->" + devName); console.info("[wifi_test] test start setDeviceName->" + devName);
expect(devName).assertTrue(); expect(devName).assertTrue();
...@@ -71,7 +66,7 @@ describe('ACTS_WifiTest', function () { ...@@ -71,7 +66,7 @@ describe('ACTS_WifiTest', function () {
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(3000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
...@@ -79,7 +74,7 @@ describe('ACTS_WifiTest', function () { ...@@ -79,7 +74,7 @@ describe('ACTS_WifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
console.info("[wifi_test] test start createGroup ."); console.info("[wifi_test] test start createGroup .");
var addConfig = wifi.createGroup(WifiP2PConfig); var addConfig = wifi.createGroup(WifiP2PConfig);
sleep(3000); await sleep(2000);
console.info("[wifi_test] test start createGroup result." + addConfig); console.info("[wifi_test] test start createGroup result." + addConfig);
expect(addConfig).assertTrue(); expect(addConfig).assertTrue();
await wifi.getCurrentGroup() await wifi.getCurrentGroup()
...@@ -136,7 +131,7 @@ describe('ACTS_WifiTest', function () { ...@@ -136,7 +131,7 @@ describe('ACTS_WifiTest', function () {
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(3000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
...@@ -144,7 +139,7 @@ describe('ACTS_WifiTest', function () { ...@@ -144,7 +139,7 @@ describe('ACTS_WifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
console.info("[wifi_test] test start create 2.4G band Group ."); console.info("[wifi_test] test start create 2.4G band Group .");
var addConfig = wifi.createGroup(WifiP2PConfig2); var addConfig = wifi.createGroup(WifiP2PConfig2);
sleep(3000); await sleep(2000);
console.info("[wifi_test] test start createGroup result." + addConfig); console.info("[wifi_test] test start createGroup result." + addConfig);
expect(addConfig).assertTrue(); expect(addConfig).assertTrue();
await wifi.getCurrentGroup() await wifi.getCurrentGroup()
...@@ -169,7 +164,6 @@ describe('ACTS_WifiTest', function () { ...@@ -169,7 +164,6 @@ describe('ACTS_WifiTest', function () {
* @tc.desc Test createGroup and deletePersistentGroup infos * @tc.desc Test createGroup and deletePersistentGroup infos
*/ */
it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) {
console.info("[wifi_test] check the state of wifi, if it's close, open it.");
var WifiP2PConfig = { var WifiP2PConfig = {
deviceAddress : "02:11:65:f2:0d:6e", deviceAddress : "02:11:65:f2:0d:6e",
netId : -2, netId : -2,
...@@ -177,10 +171,11 @@ describe('ACTS_WifiTest', function () { ...@@ -177,10 +171,11 @@ describe('ACTS_WifiTest', function () {
groupName : "AAAZZZ", groupName : "AAAZZZ",
goBand : 0 goBand : 0
}; };
console.info("[wifi_test] check the state of wifi, if it's close, open it.");
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(3000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
...@@ -188,7 +183,7 @@ describe('ACTS_WifiTest', function () { ...@@ -188,7 +183,7 @@ describe('ACTS_WifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
console.info("[wifi_test] test start createGroup [promise]."); console.info("[wifi_test] test start createGroup [promise].");
var addConfig = wifi.createGroup(WifiP2PConfig); var addConfig = wifi.createGroup(WifiP2PConfig);
sleep(3000); await sleep(2000);
console.info("[wifi_test] test start createGroup [promise]." + addConfig); console.info("[wifi_test] test start createGroup [promise]." + addConfig);
expect(addConfig).assertTrue(); expect(addConfig).assertTrue();
await wifi.getCurrentGroup() await wifi.getCurrentGroup()
...@@ -213,7 +208,7 @@ describe('ACTS_WifiTest', function () { ...@@ -213,7 +208,7 @@ describe('ACTS_WifiTest', function () {
* @tc.author wudangping wwx1075776 * @tc.author wudangping wwx1075776
* @tc.desc Test p2pConnect infos * @tc.desc Test p2pConnect infos
*/ */
it('SUB_Communication_WiFi_P2P_Config_0004', 0, function() { it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) {
var WifiP2PConfig3 = { var WifiP2PConfig3 = {
deviceAddress : "02:11:65:f2:0d:6e", deviceAddress : "02:11:65:f2:0d:6e",
netId : -2, netId : -2,
...@@ -225,7 +220,7 @@ describe('ACTS_WifiTest', function () { ...@@ -225,7 +220,7 @@ describe('ACTS_WifiTest', function () {
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(3000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
...@@ -233,16 +228,17 @@ describe('ACTS_WifiTest', function () { ...@@ -233,16 +228,17 @@ describe('ACTS_WifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
console.info("[wifi_test] test start startDiscoverDevices."); console.info("[wifi_test] test start startDiscoverDevices.");
var scanConfig = wifi.startDiscoverDevices(); var scanConfig = wifi.startDiscoverDevices();
sleep(3000); await sleep(2000);
console.info("[wifi_test] test startDiscoverDevices result." + scanConfig); console.info("[wifi_test] test startDiscoverDevices result." + scanConfig);
expect(scanConfig).assertTrue(); expect(scanConfig).assertTrue();
console.info("[wifi_test] test start p2pConnect."); console.info("[wifi_test] test start p2pConnect.");
var connConfig = wifi.p2pConnect(WifiP2PConfig3); var connConfig = wifi.p2pConnect(WifiP2PConfig3);
sleep(5000);
console.info("[wifi_test] test p2pConnect result." + connConfig); console.info("[wifi_test] test p2pConnect result." + connConfig);
expect(connConfig).assertTrue(); expect(connConfig).assertTrue();
console.info("[wifi_test] test start stopDiscoverDevices."); console.info("[wifi_test] test start stopDiscoverDevices.");
var stopScan = wifi.stopDiscoverDevices(); var stopScan = wifi.stopDiscoverDevices();
console.info("[wifi_test] test stopDiscoverDevices result." + stopScan);
done()
}) })
/** /**
...@@ -263,7 +259,6 @@ describe('ACTS_WifiTest', function () { ...@@ -263,7 +259,6 @@ describe('ACTS_WifiTest', function () {
}).catch((error) => { }).catch((error) => {
console.info("[wifi_test]getP2pLinkedInfo promise then error." + JSON.stringify(error)); console.info("[wifi_test]getP2pLinkedInfo promise then error." + JSON.stringify(error));
expect(error).assertFail(); expect(error).assertFail();
}); });
wifi.getP2pLinkedInfo((err, result) => { wifi.getP2pLinkedInfo((err, result) => {
if (err) { if (err) {
...@@ -287,16 +282,17 @@ describe('ACTS_WifiTest', function () { ...@@ -287,16 +282,17 @@ describe('ACTS_WifiTest', function () {
* @tc.author wudangping wwx1075776 * @tc.author wudangping wwx1075776
* @tc.desc Test p2pCancelConnect infos * @tc.desc Test p2pCancelConnect infos
*/ */
it('SUB_Communication_WiFi_P2P_Config_0006', 0, function() { it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) {
console.info("[wifi_test] test start p2pCancelConnect."); console.info("[wifi_test] test start p2pCancelConnect.");
var disConn = wifi.p2pCancelConnect(); var disConn = wifi.p2pCancelConnect();
sleep(5000); await sleep(2000);
console.info("[wifi_test] test p2pCancelConnect result." + disConn); console.info("[wifi_test] test p2pCancelConnect result." + disConn);
expect(disConn).assertTrue(); expect(disConn).assertTrue();
console.info("[wifi_test] test start removeGroup"); console.info("[wifi_test] test start removeGroup");
var removeConfig = wifi.removeGroup(); var removeConfig = wifi.removeGroup();
console.info("[wifi_test] test start removeGroup" + removeConfig); console.info("[wifi_test] test start removeGroup" + removeConfig);
expect(removeConfig).assertTrue(); expect(removeConfig).assertTrue();
done();
}) })
/** /**
...@@ -317,7 +313,7 @@ describe('ACTS_WifiTest', function () { ...@@ -317,7 +313,7 @@ describe('ACTS_WifiTest', function () {
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(3000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
...@@ -325,7 +321,7 @@ describe('ACTS_WifiTest', function () { ...@@ -325,7 +321,7 @@ describe('ACTS_WifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
console.info("[wifi_test] test start startDiscoverDevices."); console.info("[wifi_test] test start startDiscoverDevices.");
var scanConfig = wifi.startDiscoverDevices(); var scanConfig = wifi.startDiscoverDevices();
sleep(10000); await sleep(2000);
console.info("[wifi_test] test startDiscoverDevices result." + scanConfig); console.info("[wifi_test] test startDiscoverDevices result." + scanConfig);
expect(scanConfig).assertTrue(); expect(scanConfig).assertTrue();
await wifi.getP2pDevices() await wifi.getP2pDevices()
...@@ -367,7 +363,6 @@ describe('ACTS_WifiTest', function () { ...@@ -367,7 +363,6 @@ describe('ACTS_WifiTest', function () {
} }
console.info("[wifi_test] test stopDiscoverDevices."); console.info("[wifi_test] test stopDiscoverDevices.");
var stopScan = wifi.stopDiscoverDevices(); var stopScan = wifi.stopDiscoverDevices();
sleep(3000);
console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); console.info("[wifi_test] test stopDiscoverDevices result." + stopScan);
expect(stopScan).assertTrue(); expect(stopScan).assertTrue();
done(); done();
...@@ -394,7 +389,7 @@ describe('ACTS_WifiTest', function () { ...@@ -394,7 +389,7 @@ describe('ACTS_WifiTest', function () {
console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
...@@ -435,7 +430,7 @@ describe('ACTS_WifiTest', function () { ...@@ -435,7 +430,7 @@ describe('ACTS_WifiTest', function () {
console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc));
expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); expect(true).assertEqual(recvP2pConnectionChangeFunc !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
...@@ -458,7 +453,7 @@ describe('ACTS_WifiTest', function () { ...@@ -458,7 +453,7 @@ describe('ACTS_WifiTest', function () {
console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
...@@ -506,7 +501,7 @@ describe('ACTS_WifiTest', function () { ...@@ -506,7 +501,7 @@ describe('ACTS_WifiTest', function () {
console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
...@@ -550,7 +545,7 @@ describe('ACTS_WifiTest', function () { ...@@ -550,7 +545,7 @@ describe('ACTS_WifiTest', function () {
console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
...@@ -573,12 +568,10 @@ describe('ACTS_WifiTest', function () { ...@@ -573,12 +568,10 @@ describe('ACTS_WifiTest', function () {
console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
}); });
}, 10 * 1000); }, 1 * 1000);
done(); done();
}) })
console.log("*************[wifi_test] start wifi js unit test end*************"); console.log("*************[wifi_test] start wifi js unit test end*************");
}) })
...@@ -17,15 +17,8 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -17,15 +17,8 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
// delay x ms
function sleep(delay) { function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
var start = (new Date()).getTime();
while(true){
if(new Date().getTime() - start >delay) {
break;
}
}
} }
var WifiSecurityType = { var WifiSecurityType = {
...@@ -55,15 +48,14 @@ describe('ACTS_WifiTest', function() { ...@@ -55,15 +48,14 @@ describe('ACTS_WifiTest', function() {
* @tc.number OPEN_0002 * @tc.number OPEN_0002
* @tc.name SUB_Communication_WiFi_Hotspot_Open_0002 * @tc.name SUB_Communication_WiFi_Hotspot_Open_0002
* @tc.desc Test wifi.enableHotspot and wifi.disableHotspot API functionality1. * @tc.desc Test wifi.enableHotspot and wifi.disableHotspot API functionality1.
* @tc.author wudangping wwx1075776
* @tc.level Level 0 * @tc.level Level 0
*/ */
it('SUB_Communication_WiFi_Hotspot_Open_0002', 0, function () { it('SUB_Communication_WiFi_Hotspot_Open_0002', 0, async function (done) {
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Open_0002"); console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Open_0002");
console.info("[wifi_test] enableHotspot and disableHotspot test start."); console.info("[wifi_test] enableHotspot and disableHotspot test start.");
if (wifi.isWifiActive()) { if (wifi.isWifiActive()) {
var disable = wifi.disableWifi(); var disable = wifi.disableWifi();
sleep(5000); await sleep(2000);
console.log("[wifi_test] wifi close result: " + disable); console.log("[wifi_test] wifi close result: " + disable);
expect(disable).assertTrue(); expect(disable).assertTrue();
} }
...@@ -72,41 +64,42 @@ describe('ACTS_WifiTest', function() { ...@@ -72,41 +64,42 @@ describe('ACTS_WifiTest', function() {
expect(close).assertFalse(); expect(close).assertFalse();
if (!wifi.isHotspotActive()) { if (!wifi.isHotspotActive()) {
var on = wifi.enableHotspot(); var on = wifi.enableHotspot();
sleep(5000); await sleep(3000);
console.info("[wifi_test] enableHotspot result -> " + on); console.info("[wifi_test] enableHotspot result -> " + on);
expect(on).assertTrue(); expect(on).assertTrue();
} }
console.info("[wifi_test] AP status result -> " + wifi.isHotspotActive()); console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive());
expect(wifi.isHotspotActive()).assertTrue(); expect(wifi.isHotspotActive()).assertTrue();
console.info("[wifi_test] enableHotspot and close wifi test end."); console.info("[wifi_test] enableHotspot and disableHotspot test end.");
done();
}) })
/** /**
* @tc.number CONFIG_0001 * @tc.number CONFIG_0001
* @tc.name SUB_Communication_WiFi_Hotspot_Config_0001 * @tc.name SUB_Communication_WiFi_Hotspot_Config_0001
* @tc.author wudangping wwx1075776
* @tc.desc Test set a valid 2.4G hotspot config * @tc.desc Test set a valid 2.4G hotspot config
* @tc.level Level 0 * @tc.level Level 0
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0001', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0001', 0, async function () {
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0001"); console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0001");
console.info("[wifi_test] set a valid 2.4G hotspot config start."); console.info("[wifi_test] set a valid 2.4G hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(2000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
console.info("[wifi_test] AP status result -> " + wifi.isHotspotActive()); console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive());
expect(wifi.isHotspotActive()).assertFalse(); expect(wifi.isHotspotActive()).assertFalse();
var isSuccess = wifi.setHotspotConfig(HotspotConfig); var isSuccess = wifi.setHotspotConfig(HotspotConfig);
console.log("[wifi_test] set 2.4G hotspot config result: " + isSuccess); console.log("[wifi_test] set 2.4G hotspot config result: " + isSuccess);
expect(isSuccess).assertTrue(); expect(isSuccess).assertTrue();
console.info("[wifi_test] check band of current band should be 2.4G."); console.info("[wifi_test] check band of current band should be 2.4G.");
var hotspotConfig = wifi.getHotspotConfig(); var hotspotConfig = wifi.getHotspotConfig();
console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig)); console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig));
expect(hotspotConfig.band).assertEqual(1); expect(hotspotConfig.band).assertEqual(1);
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0001 end");
done();
}) })
/** /**
...@@ -115,12 +108,12 @@ describe('ACTS_WifiTest', function() { ...@@ -115,12 +108,12 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a valid 5G hotspot config * @tc.desc Test set a valid 5G hotspot config
* @tc.level Level 1 * @tc.level Level 1
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0002', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0002', 0, async function (done) {
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0002"); console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0002");
console.info("[wifi_test] set a valid hotspot config start."); console.info("[wifi_test] set a valid hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(3000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -138,6 +131,7 @@ describe('ACTS_WifiTest', function() { ...@@ -138,6 +131,7 @@ describe('ACTS_WifiTest', function() {
var hotspotConfig5 = wifi.getHotspotConfig(); var hotspotConfig5 = wifi.getHotspotConfig();
console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig5)); console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig5));
expect(hotspotConfig5.band).assertEqual(1); expect(hotspotConfig5.band).assertEqual(1);
done();
}) })
/** /**
...@@ -146,11 +140,11 @@ describe('ACTS_WifiTest', function() { ...@@ -146,11 +140,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a invalid hotspot config * @tc.desc Test set a invalid hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0003', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0003', 0, async function (done) {
console.info("[wifi_test] set a invalid hotspot config start."); console.info("[wifi_test] set a invalid hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(10000); await sleep(3000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -164,21 +158,23 @@ describe('ACTS_WifiTest', function() { ...@@ -164,21 +158,23 @@ describe('ACTS_WifiTest', function() {
var isSuccess1 = wifi.setHotspotConfig(HotspotConfig1); var isSuccess1 = wifi.setHotspotConfig(HotspotConfig1);
console.log("[wifi_test] set invalid band hotspot config result1:" + isSuccess1); console.log("[wifi_test] set invalid band hotspot config result1:" + isSuccess1);
expect(isSuccess1).assertFalse(); expect(isSuccess1).assertFalse();
done();
}) })
/** /**
* @tc.number CONFIG_0004 * @tc.number CONFIG_0004
* @tc.name SUB_Communication_WiFi_Hotspot_Config_0004 * @tc.name SUB_Communication_WiFi_Hotspot_Config_0004
* @tc.desc Test set a max preSharedKey is hotspot config * @tc.desc Test set a max preSharedKey is hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0004', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0004', 0, async function (done) {
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0004"); console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0004");
console.info("[wifi_test] check the state of hotspot, if it's open, close it."); console.info("[wifi_test] check the state of hotspot, if it's open, close it.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -204,6 +200,7 @@ describe('ACTS_WifiTest', function() { ...@@ -204,6 +200,7 @@ describe('ACTS_WifiTest', function() {
var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM1); var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM1);
console.log("[wifi_test] set 65 preSharedKey invalid hotspot config result: " + isSuccess1); console.log("[wifi_test] set 65 preSharedKey invalid hotspot config result: " + isSuccess1);
expect(isSuccess1).assertFalse(); expect(isSuccess1).assertFalse();
done();
}) })
/** /**
...@@ -212,11 +209,11 @@ describe('ACTS_WifiTest', function() { ...@@ -212,11 +209,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a min preSharedKey is hotspot config * @tc.desc Test set a min preSharedKey is hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0005', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0005', 0, async function (done) {
console.info("[wifi_test] check the state of hotspot, if it's open, close it."); console.info("[wifi_test] check the state of hotspot, if it's open, close it.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -252,6 +249,7 @@ describe('ACTS_WifiTest', function() { ...@@ -252,6 +249,7 @@ describe('ACTS_WifiTest', function() {
console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
console.info("preSharedKey: " + config.preSharedKey); console.info("preSharedKey: " + config.preSharedKey);
expect(config.preSharedKey.length).assertEqual(8); expect(config.preSharedKey.length).assertEqual(8);
done();
}) })
/** /**
...@@ -260,11 +258,11 @@ describe('ACTS_WifiTest', function() { ...@@ -260,11 +258,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a max ssid for hotspot config * @tc.desc Test set a max ssid for hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0006', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0006', 0, async function (done) {
console.info("[wifi_test] check the state of hotspot, if it's open, close it."); console.info("[wifi_test] check the state of hotspot, if it's open, close it.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(on2).assertTrue(); expect(on2).assertTrue();
} }
...@@ -295,6 +293,7 @@ describe('ACTS_WifiTest', function() { ...@@ -295,6 +293,7 @@ describe('ACTS_WifiTest', function() {
var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS1); var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS1);
console.log("[wifi_test] set 33bit ssid invalid hotspot config result: " + isSuccess1); console.log("[wifi_test] set 33bit ssid invalid hotspot config result: " + isSuccess1);
expect(isSuccess1).assertFalse(); expect(isSuccess1).assertFalse();
done();
}) })
...@@ -304,10 +303,11 @@ describe('ACTS_WifiTest', function() { ...@@ -304,10 +303,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a null ssid invalid hotspot config * @tc.desc Test set a null ssid invalid hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0007', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0007', 0, async function (done) {
console.info("[wifi_test] set a null ssid invalid hotspot config start."); console.info("[wifi_test] set a null ssid invalid hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
await sleep(2000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -321,6 +321,7 @@ describe('ACTS_WifiTest', function() { ...@@ -321,6 +321,7 @@ describe('ACTS_WifiTest', function() {
var isSuccess1 = wifi.setHotspotConfig(HotspotConfigN); var isSuccess1 = wifi.setHotspotConfig(HotspotConfigN);
console.log("[wifi_test] set a null ssid invalid hotspot config result1:" + isSuccess1); console.log("[wifi_test] set a null ssid invalid hotspot config result1:" + isSuccess1);
expect(isSuccess1).assertFalse(); expect(isSuccess1).assertFalse();
done();
}) })
/** /**
...@@ -332,7 +333,7 @@ describe('ACTS_WifiTest', function() { ...@@ -332,7 +333,7 @@ describe('ACTS_WifiTest', function() {
it('SUB_Communication_WiFi_Hotspot_Config_0008', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0008', 0, function () {
console.info("[wifi_test] set contains Chinese valid hotspot config start."); console.info("[wifi_test] set contains Chinese valid hotspot config start.");
var HotspotConfigC= { var HotspotConfigC= {
"ssid": "¥%¥#@12测试 ", "ssid": "�?�?@12测试 ",
"band": 1, "band": 1,
"preSharedKey": "12345678", "preSharedKey": "12345678",
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
...@@ -354,11 +355,11 @@ describe('ACTS_WifiTest', function() { ...@@ -354,11 +355,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a invalid preSharedKey hotspot config * @tc.desc Test set a invalid preSharedKey hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0009', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0009', 0, async function (done) {
console.info("[wifi_test] set invalid hotspot config start."); console.info("[wifi_test] set invalid hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(3000);
console.info("[wifi_test] enableHotspot result -> " + off); console.info("[wifi_test] enableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
...@@ -395,6 +396,7 @@ describe('ACTS_WifiTest', function() { ...@@ -395,6 +396,7 @@ describe('ACTS_WifiTest', function() {
var isSuccess3 = wifi.setHotspotConfig(HotspotConfigC); var isSuccess3 = wifi.setHotspotConfig(HotspotConfigC);
console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess3); console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess3);
expect(isSuccess3).assertFalse(); expect(isSuccess3).assertFalse();
done();
}) })
...@@ -404,11 +406,11 @@ describe('ACTS_WifiTest', function() { ...@@ -404,11 +406,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a valid PSK preSharedKey hotspot config * @tc.desc Test set a valid PSK preSharedKey hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0010', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0010', 0, async function (done) {
console.info("[wifi_test] set valid hotspot config start."); console.info("[wifi_test] set valid hotspot config start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] enableHotspot result -> " + off); console.info("[wifi_test] enableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
...@@ -429,6 +431,7 @@ describe('ACTS_WifiTest', function() { ...@@ -429,6 +431,7 @@ describe('ACTS_WifiTest', function() {
var isHotspotActive = wifi.isHotspotActive(); var isHotspotActive = wifi.isHotspotActive();
console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
expect(isHotspotActive).assertFalse(); expect(isHotspotActive).assertFalse();
done();
}) })
...@@ -438,11 +441,11 @@ describe('ACTS_WifiTest', function() { ...@@ -438,11 +441,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a valid OPEN preSharedKey hotspot config * @tc.desc Test set a valid OPEN preSharedKey hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0011', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0011', 0, async function (done) {
console.info("[wifi_test] wifi disableHotspot start."); console.info("[wifi_test] wifi disableHotspot start.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
} }
...@@ -457,6 +460,7 @@ describe('ACTS_WifiTest', function() { ...@@ -457,6 +460,7 @@ describe('ACTS_WifiTest', function() {
var isSuccess1 = wifi.setHotspotConfig(HotspotConfigO); var isSuccess1 = wifi.setHotspotConfig(HotspotConfigO);
console.log("[wifi_test] set a open preSharedKey hotspot config result1: " + isSuccess1); console.log("[wifi_test] set a open preSharedKey hotspot config result1: " + isSuccess1);
expect(isSuccess1).assertTrue(); expect(isSuccess1).assertTrue();
done();
}) })
...@@ -466,11 +470,11 @@ describe('ACTS_WifiTest', function() { ...@@ -466,11 +470,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a maxConn and more maxConn hotspot config * @tc.desc Test set a maxConn and more maxConn hotspot config
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Conn_0001', 0, function () { it('SUB_Communication_WiFi_Hotspot_Conn_0001', 0, async function (done) {
console.info("[wifi_test] check the state of hotspot, if it's open, close it."); console.info("[wifi_test] check the state of hotspot, if it's open, close it.");
if (wifi.isHotspotActive()) { if (wifi.isHotspotActive()) {
var off = wifi.disableHotspot(); var off = wifi.disableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] disableHotspot result -> " + off); console.info("[wifi_test] disableHotspot result -> " + off);
expect(off).assertTrue(); expect(off).assertTrue();
...@@ -508,6 +512,7 @@ describe('ACTS_WifiTest', function() { ...@@ -508,6 +512,7 @@ describe('ACTS_WifiTest', function() {
console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
console.info("ssid: " + config.maxConn); console.info("ssid: " + config.maxConn);
expect(config.maxConn).assertEqual(8); expect(config.maxConn).assertEqual(8);
done();
}) })
/** /**
...@@ -516,12 +521,12 @@ describe('ACTS_WifiTest', function() { ...@@ -516,12 +521,12 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test set a valid hotspot config after open Hotspot * @tc.desc Test set a valid hotspot config after open Hotspot
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Config_0012', 0, function () { it('SUB_Communication_WiFi_Hotspot_Config_0012', 0, async function (done) {
console.info("[wifi_test] wifi enableHotspot start."); console.info("[wifi_test] wifi enableHotspot start.");
console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0012."); console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0012.");
if (!wifi.isHotspotActive()) { if (!wifi.isHotspotActive()) {
var on = wifi.enableHotspot(); var on = wifi.enableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] enableHotspot result -> " + on); console.info("[wifi_test] enableHotspot result -> " + on);
expect(on).assertTrue(); expect(on).assertTrue();
} }
...@@ -554,6 +559,7 @@ describe('ACTS_WifiTest', function() { ...@@ -554,6 +559,7 @@ describe('ACTS_WifiTest', function() {
expect(config.preSharedKey).assertEqual('12345678'); expect(config.preSharedKey).assertEqual('12345678');
expect(config.securityType).assertEqual(3); expect(config.securityType).assertEqual(3);
expect(config.maxConn).assertEqual(8); expect(config.maxConn).assertEqual(8);
done();
}) })
...@@ -563,11 +569,11 @@ describe('ACTS_WifiTest', function() { ...@@ -563,11 +569,11 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test Obtains the list of clients that are connected to a Wi-Fi hotspot. * @tc.desc Test Obtains the list of clients that are connected to a Wi-Fi hotspot.
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_WiFi_Hotspot_Conn_0002', 0, function () { it('SUB_Communication_WiFi_Hotspot_Conn_0002', 0, async function (done) {
console.info("[wifi_test] check the state of hotspot, if it's open, close it."); console.info("[wifi_test] check the state of hotspot, if it's open, close it.");
if (!wifi.isHotspotActive()) { if (!wifi.isHotspotActive()) {
var on = wifi.enableHotspot(); var on = wifi.enableHotspot();
sleep(5000); await sleep(5000);
console.info("[wifi_test] enableHotspot result -> " + on); console.info("[wifi_test] enableHotspot result -> " + on);
expect(on).assertTrue(); expect(on).assertTrue();
...@@ -582,6 +588,7 @@ describe('ACTS_WifiTest', function() { ...@@ -582,6 +588,7 @@ describe('ACTS_WifiTest', function() {
console.info("ssid: " + stationInfo.name); console.info("ssid: " + stationInfo.name);
console.info("macAddress: " + stationInfo.macAddress); console.info("macAddress: " + stationInfo.macAddress);
console.info("ipAddress: " + stationInfo.ipAddress); console.info("ipAddress: " + stationInfo.ipAddress);
done();
}) })
...@@ -596,11 +603,11 @@ describe('ACTS_WifiTest', function() { ...@@ -596,11 +603,11 @@ describe('ACTS_WifiTest', function() {
it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) { it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) {
console.info("[wifi_test]hotspotStateChange On test"); console.info("[wifi_test]hotspotStateChange On test");
try { try {
wifi.on('hotspotStateChange', (data) => { await wifi.on('hotspotStateChange', (data) => {
console.info("[wifi_test] hotspotStateChange On ->" + data); console.info("[wifi_test] hotspotStateChange On ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -617,12 +624,12 @@ describe('ACTS_WifiTest', function() { ...@@ -617,12 +624,12 @@ describe('ACTS_WifiTest', function() {
*/ */
it('SUB_Communication_WiFi_Sta_Off_0002', 0, async function (done) { it('SUB_Communication_WiFi_Sta_Off_0002', 0, async function (done) {
try { try {
wifi.off('hotspotStateChange', (data) => { await wifi.off('hotspotStateChange', (data) => {
console.info("[wifi_test] hotspotStateChange Off ->" + data); console.info("[wifi_test] hotspotStateChange Off ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
console.info("[wifi_test] wifiRssiChange unregister end"); console.info("[wifi_test] wifiRssiChange unregister end");
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -640,11 +647,11 @@ describe('ACTS_WifiTest', function() { ...@@ -640,11 +647,11 @@ describe('ACTS_WifiTest', function() {
it('SUB_Communication_WiFi_Hotspot_ON_0003', 0, async function (done) { it('SUB_Communication_WiFi_Hotspot_ON_0003', 0, async function (done) {
console.info("[wifi_test]hotspotStaJoin On test"); console.info("[wifi_test]hotspotStaJoin On test");
try { try {
wifi.on('hotspotStaJoin', (data) => { await wifi.on('hotspotStaJoin', (data) => {
console.info("[wifi_test] hotspotStaJoin On ->" + data); console.info("[wifi_test] hotspotStaJoin On ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -661,12 +668,12 @@ describe('ACTS_WifiTest', function() { ...@@ -661,12 +668,12 @@ describe('ACTS_WifiTest', function() {
*/ */
it('SUB_Communication_WiFi_Sta_Off_0004', 0, async function (done) { it('SUB_Communication_WiFi_Sta_Off_0004', 0, async function (done) {
try { try {
wifi.off('hotspotStaJoin', (data) => { await wifi.off('hotspotStaJoin', (data) => {
console.info("[wifi_test] hotspotStaJoin Off ->" + data); console.info("[wifi_test] hotspotStaJoin Off ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
console.info("[wifi_test] wifiRssiChange unregister end"); console.info("[wifi_test] wifiRssiChange unregister end");
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -684,11 +691,11 @@ describe('ACTS_WifiTest', function() { ...@@ -684,11 +691,11 @@ describe('ACTS_WifiTest', function() {
it('SUB_Communication_WiFi_Hotspot_ON_0005', 0, async function (done) { it('SUB_Communication_WiFi_Hotspot_ON_0005', 0, async function (done) {
console.info("[wifi_test]hotspotStaLeave On test"); console.info("[wifi_test]hotspotStaLeave On test");
try { try {
wifi.on('hotspotStaLeave', (data) => { await wifi.on('hotspotStaLeave', (data) => {
console.info("[wifi_test] hotspotStaLeave On ->" + data); console.info("[wifi_test] hotspotStaLeave On ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -705,12 +712,12 @@ describe('ACTS_WifiTest', function() { ...@@ -705,12 +712,12 @@ describe('ACTS_WifiTest', function() {
*/ */
it('SUB_Communication_WiFi_Sta_Off_0006', 0, async function (done) { it('SUB_Communication_WiFi_Sta_Off_0006', 0, async function (done) {
try { try {
wifi.off('hotspotStaLeave', (data) => { await wifi.off('hotspotStaLeave', (data) => {
console.info("[wifi_test] hotspotStaLeave Off ->" + data); console.info("[wifi_test] hotspotStaLeave Off ->" + data);
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
console.info("[wifi_test] hotspotStaLeave unregister end"); console.info("[wifi_test] hotspotStaLeave unregister end");
}); });
await(3000);
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -719,3 +726,4 @@ describe('ACTS_WifiTest', function() { ...@@ -719,3 +726,4 @@ describe('ACTS_WifiTest', function() {
console.log("*************[wifi_test] start wifi js unit test end*************"); console.log("*************[wifi_test] start wifi js unit test end*************");
}) })
...@@ -17,17 +17,10 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from ...@@ -17,17 +17,10 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
// delay x ms
function sleep(delay) { function sleep(delay) {
var start = (new Date()).getTime(); return new Promise(resovle => setTimeout(resovle, delay))
while(true){
if((new Date()).getTime() - start > delay) {
break;
}
}
} }
var WifiSecurityType = { var WifiSecurityType = {
WIFI_SEC_TYPE_INVALID: 0, WIFI_SEC_TYPE_INVALID: 0,
WIFI_SEC_TYPE_OPEN: 1, WIFI_SEC_TYPE_OPEN: 1,
...@@ -85,29 +78,31 @@ describe('ACTS_WifiTest', function() { ...@@ -85,29 +78,31 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number open_0001 * @tc.number open_0001
* @tc.name SUB_Communication_WiFi_Sta_Open_0001 * @tc.name SUB_Communication_WiFi_Sta_Open_0001
* @tc.author wudangping wwx1075776
* @tc.desc Test wifi.isWifiEnable API functionality. * @tc.desc Test wifi.isWifiEnable API functionality.
*/ */
it('SUB_Communication_WiFi_Sta_Open_0001', 0, function() { it('SUB_Communication_WiFi_Sta_Open_0001', 0, async function(done) {
console.info("[wifi_test][SUB_Communication_WiFi_Sta_Open_0001]"); console.info("[wifi_test][SUB_Communication_WiFi_Sta_Open_0001]");
console.info("[wifi_test] check the state of wifi, if it's close, open it."); console.info("[wifi_test] check the state of wifi, if it's close, open it.");
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
if (!active) { if (!active) {
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(5000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
console.info("[wifi_test] close wifi test start.");
var disable = wifi.disableWifi();
await sleep(5000);
console.log("[wifi_test] wifi close result: " + disable);
expect(disable).assertTrue();
console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertFalse();
sleep(3000); done();
}) })
/** /**
* @tc.number Scan_0001 * @tc.number Scan_0001
* @tc.name SUB_Communication_WiFi_Sta_Scan_0001 * @tc.name SUB_Communication_WiFi_Sta_Scan_0001
* @tc.author wudangping wwx1075776
* @tc.desc Test get ScanInfos callback API functionality. * @tc.desc Test get ScanInfos callback API functionality.
*/ */
it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) {
...@@ -115,12 +110,12 @@ describe('ACTS_WifiTest', function() { ...@@ -115,12 +110,12 @@ describe('ACTS_WifiTest', function() {
var active1 = wifi.isWifiActive(); var active1 = wifi.isWifiActive();
if (!active1) { if (!active1) {
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(5000); await sleep(5000);
console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
var scan = wifi.scan(); var scan = wifi.scan();
sleep(5000); await sleep(3000);
console.log("[wifi_test] open wifi scan result: " + scan); console.log("[wifi_test] open wifi scan result: " + scan);
expect(scan).assertTrue(); expect(scan).assertTrue();
...@@ -163,7 +158,6 @@ describe('ACTS_WifiTest', function() { ...@@ -163,7 +158,6 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Scan_0004 * @tc.number Scan_0004
* @tc.name SUB_Communication_WiFi_Sta_Scan_0004 * @tc.name SUB_Communication_WiFi_Sta_Scan_0004
* @tc.author wudangping wwx1075776
* @tc.desc Test wifi.getSignalLevel API functionality. * @tc.desc Test wifi.getSignalLevel API functionality.
*/ */
it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() { it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() {
...@@ -202,13 +196,12 @@ describe('ACTS_WifiTest', function() { ...@@ -202,13 +196,12 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Config_0001 * @tc.number Config_0001
* @tc.name SUB_Communication_WiFi_Sta_Config_0001 * @tc.name SUB_Communication_WiFi_Sta_Config_0001
* @tc.author wudangping wwx1075776
* @tc.desc Test create a OPEN SecurityType wifi device config * @tc.desc Test create a OPEN SecurityType wifi device config
*/ */
it('SUB_Communication_WiFi_Sta_Config_0001', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Config_0001', 0, async function(done) {
console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0001]"); console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0001]");
console.info("[wifi_test] create a OPEN SecurityType wifi device config start."); console.info("[wifi_test] create a OPEN SecurityType wifi device config start.");
wifi.removeAllNetwork(); var remov = wifi.removeAllNetwork();
var wifiDeviceConfig1 = { var wifiDeviceConfig1 = {
"ssid": "TEST_OPEN", "ssid": "TEST_OPEN",
"bssid": "", "bssid": "",
...@@ -258,7 +251,6 @@ describe('ACTS_WifiTest', function() { ...@@ -258,7 +251,6 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Config_0002 * @tc.number Config_0002
* @tc.name SUB_Communication_WiFi_Sta_Config_0002 * @tc.name SUB_Communication_WiFi_Sta_Config_0002
* @tc.author wudangping wwx1075776
* @tc.desc Test create a PSK SecurityType wifi device config * @tc.desc Test create a PSK SecurityType wifi device config
*/ */
it('SUB_Communication_WiFi_Sta_Config_0002', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Config_0002', 0, async function(done) {
...@@ -298,7 +290,6 @@ describe('ACTS_WifiTest', function() { ...@@ -298,7 +290,6 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Config_0005 * @tc.number Config_0005
* @tc.name SUB_Communication_WiFi_Sta_Config_0005 * @tc.name SUB_Communication_WiFi_Sta_Config_0005
* @tc.author wudangping wwx1075776
* @tc.desc Test remove all wifi device config * @tc.desc Test remove all wifi device config
*/ */
it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) {
...@@ -364,7 +355,6 @@ describe('ACTS_WifiTest', function() { ...@@ -364,7 +355,6 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Config_0007 * @tc.number Config_0007
* @tc.name SUB_Communication_WiFi_Sta_Config_0007 * @tc.name SUB_Communication_WiFi_Sta_Config_0007
* @tc.author wudangping wwx1075776
* @tc.desc Test update wifi device config * @tc.desc Test update wifi device config
*/ */
it('SUB_Communication_WiFi_Sta_Config_0007', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Config_0007', 0, async function(done) {
...@@ -375,7 +365,7 @@ describe('ACTS_WifiTest', function() { ...@@ -375,7 +365,7 @@ describe('ACTS_WifiTest', function() {
"bssid": "", "bssid": "",
"preSharedKey": "12345678", "preSharedKey": "12345678",
"isHiddenSsid": false, "isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK
}; };
await wifi.addDeviceConfig(wifiDeviceConfig1) await wifi.addDeviceConfig(wifiDeviceConfig1)
...@@ -417,15 +407,14 @@ describe('ACTS_WifiTest', function() { ...@@ -417,15 +407,14 @@ describe('ACTS_WifiTest', function() {
* @tc.number SUB_Communication_WiFi_Sta_info_0001 * @tc.number SUB_Communication_WiFi_Sta_info_0001
* @tc.name testgetMacAddress * @tc.name testgetMacAddress
* @tc.desc Test getMacAddress api. * @tc.desc Test getMacAddress api.
* @tc.author wudangping wwx1075776
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_Communication_WiFi_Sta_info_0001', 0, function () { it('SUB_Communication_WiFi_Sta_info_0001', 0, async function (done) {
if (!wifi.isWifiActive()) { if (!wifi.isWifiActive()) {
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(3000); await sleep(3000);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
...@@ -433,21 +422,21 @@ describe('ACTS_WifiTest', function() { ...@@ -433,21 +422,21 @@ describe('ACTS_WifiTest', function() {
var result = wifi.getDeviceMacAddress(); var result = wifi.getDeviceMacAddress();
console.info("[wifi_test] getDeviceMacAddress -> " + JSON.stringify(result)); console.info("[wifi_test] getDeviceMacAddress -> " + JSON.stringify(result));
expect(true).assertEqual(result.length >= 1) expect(true).assertEqual(result.length >= 1)
done();
}) })
/** /**
* @tc.number SUB_Communication_WiFi_Sta_info_0002 * @tc.number SUB_Communication_WiFi_Sta_info_0002
* @tc.name testgetCountryCode * @tc.name testgetCountryCode
* @tc.desc Test getCountryCode api. * @tc.desc Test getCountryCode api.
* @tc.author wudangping wwx1075776
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_Communication_WiFi_Sta_Info_0002', 0, function() { it('SUB_Communication_WiFi_Sta_Info_0002', 0, async function(done) {
if (!wifi.isWifiActive()) { if (!wifi.isWifiActive()) {
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
sleep(3000); await sleep(3000);
expect(enable).assertTrue(); expect(enable).assertTrue();
} }
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
...@@ -455,13 +444,13 @@ describe('ACTS_WifiTest', function() { ...@@ -455,13 +444,13 @@ describe('ACTS_WifiTest', function() {
var countryCode = wifi.getCountryCode(); var countryCode = wifi.getCountryCode();
console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode)); console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode));
expect(JSON.stringify(countryCode)).assertEqual('"CN"'); expect(JSON.stringify(countryCode)).assertEqual('"CN"');
done()
}) })
/** /**
* @tc.number SUB_Communication_WiFi_Sta_info_0004 * @tc.number SUB_Communication_WiFi_Sta_info_0004
* @tc.name testFeatureSupported * @tc.name testFeatureSupported
* @tc.desc Test FeatureSupported api. * @tc.desc Test FeatureSupported api.
* @tc.author wudangping wwx1075776
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
...@@ -478,10 +467,9 @@ describe('ACTS_WifiTest', function() { ...@@ -478,10 +467,9 @@ describe('ACTS_WifiTest', function() {
/** /**
* @tc.number Conn_Info_0001 * @tc.number Conn_Info_0001
* @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0001 * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0001
* @tc.author wudangping wwx1075776
* @tc.desc Test reconnect wifi * @tc.desc Test reconnect wifi
*/ */
it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, function () { it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, async function (done) {
console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Info_0001]"); console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Info_0001]");
console.info("[wifi_test] wifi connectToDevice test."); console.info("[wifi_test] wifi connectToDevice test.");
var wifiDeviceConfigConn = { var wifiDeviceConfigConn = {
...@@ -492,15 +480,13 @@ describe('ACTS_WifiTest', function() { ...@@ -492,15 +480,13 @@ describe('ACTS_WifiTest', function() {
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
}; };
var active = wifi.isWifiActive(); var active = wifi.isWifiActive();
sleep(3000);
console.log("[wifi_test] wifi active result2: " + active); console.log("[wifi_test] wifi active result2: " + active);
if(!active){ if(!active){
var enable = wifi.enableWifi(); var enable = wifi.enableWifi();
expect(enable).assertTrue(); expect(enable).assertTrue();
sleep(3000); await sleep(3000);
} }
var result1 = wifi.connectToDevice(wifiDeviceConfigConn); var result1 = wifi.connectToDevice(wifiDeviceConfigConn);
sleep(5000);
console.log("[wifi_test] wifi connectToDevice result: " + result1); console.log("[wifi_test] wifi connectToDevice result: " + result1);
expect(result1).assertTrue(); expect(result1).assertTrue();
console.info("[wifi_test] check isconnected wifi"); console.info("[wifi_test] check isconnected wifi");
...@@ -518,38 +504,37 @@ describe('ACTS_WifiTest', function() { ...@@ -518,38 +504,37 @@ describe('ACTS_WifiTest', function() {
var configs = wifi.getDeviceConfigs(); var configs = wifi.getDeviceConfigs();
console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length == 0); expect(true).assertEqual(configs.length == 0);
done()
}) })
/** /**
* @tc.number conn_Config_0002 * @tc.number conn_Config_0002
* @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0002 * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0002
* @tc.author wudangping wwx1075776
* @tc.desc Test getLinkedInfo information * @tc.desc Test getLinkedInfo information
*/ */
it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) { it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) {
console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Info_0002]"); console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Info_0002]");
console.info(' console.info("[wifi_test] Wifi getlink infos test[1]."'); console.info("[wifi_test] Wifi get link infos test[1].");
await wifi.getLinkedInfo() await wifi.getLinkedInfo()
.then((result) => { .then((result) => {
console.info("[wifi_test] get wifilink [promise] -> " + JSON.stringify(result)); console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result));
expect(JSON.stringify(result)).assertContain('band'); expect(JSON.stringify(result)).assertContain('band');
console.info("[wifi_test] get wifi link [promise]."); console.info("[wifi_js] get wifi link [promise].");
done(); done();
}).catch((error) => { }).catch((error) => {
console.info("[wifi_test] promise then error." + JSON.stringify(error)); console.info("[wifi_test] promise then error." + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
}); });
wifi.getLinkedInfo( await wifi.getLinkedInfo(
(err, result) => { (err,result) => {
if(err) { if(err) {
console.error('failed to getlink infos callback because ' + JSON.stringify(err)); console.log("[wifi_test] wifi getLinkedInfo failed " + err);
} }
var clen = Object.key(result).length; var clen = Object.keys(result).length;
console.info("[wifi_test] get wifilink callback result length -> " + clen); console.log("[wifi_test] wifi getLinkedInfo callback result length: " + clen);
if(!(clen == 0)) { expect(clen).assertLarger(0);
console.info("[wifi_test] get wifi link [callback] -> " + JSON.stringify(result)); console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result));
console.info("ssid: " + result.ssid); console.info("ssid: " + result.ssid);
console.info("bssid: " + result.bssid); console.info("bssid: " + result.bssid);
console.info("band: " + result.band); console.info("band: " + result.band);
...@@ -565,19 +550,17 @@ describe('ACTS_WifiTest', function() { ...@@ -565,19 +550,17 @@ describe('ACTS_WifiTest', function() {
console.info("ipAddress: " + result.ipAddress); console.info("ipAddress: " + result.ipAddress);
console.info("suppState: " + result.suppState); console.info("suppState: " + result.suppState);
console.info("connState: " + result.connState); console.info("connState: " + result.connState);
}
done(); done();
}); });
}) })
/** /**
* @tc.number Conn_Info_0003 * @tc.number Conn_Info_0003
* @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003
* @tc.author wudangping wwx1075776
* @tc.desc Test get IpInfo information * @tc.desc Test get IpInfo information
*/ */
it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, function () { it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function (done) {
console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Info_0003]");
console.info("[wifi_test] wifi connectToDevice test."); console.info("[wifi_test] wifi connectToDevice test.");
var wifiDeviceConfigIp = { var wifiDeviceConfigIp = {
"ssid": "TEST1", "ssid": "TEST1",
...@@ -587,7 +570,7 @@ describe('ACTS_WifiTest', function() { ...@@ -587,7 +570,7 @@ describe('ACTS_WifiTest', function() {
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
}; };
var result1 = wifi.connectToDevice(wifiDeviceConfigIp); var result1 = wifi.connectToDevice(wifiDeviceConfigIp);
sleep(5000); await sleep(2000);
console.log("[wifi_test] wifi connectToDevice result: " + result1); console.log("[wifi_test] wifi connectToDevice result: " + result1);
expect(result1).assertTrue(); expect(result1).assertTrue();
console.info("[wifi_test] check isconnected wifi"); console.info("[wifi_test] check isconnected wifi");
...@@ -595,9 +578,9 @@ describe('ACTS_WifiTest', function() { ...@@ -595,9 +578,9 @@ describe('ACTS_WifiTest', function() {
console.log("[wifi_test] wifi isConnected result: " + isConnected); console.log("[wifi_test] wifi isConnected result: " + isConnected);
expect(isConnected).assertFalse(); expect(isConnected).assertFalse();
console.info("[wifi_test] reassociate wifi"); console.info("[wifi_test] reassociate wifi");
var reassoc= wifi.reassociate(); var reass= wifi.reassociate();
console.log("[wifi_test] wifi reassociate result: " + reassoc); console.log("[wifi_test] wifi reassociate result: " + reass);
expect(reassoc).assertTrue(); expect(reass).assertTrue();
console.info("[wifi_test] get IpInfo."); console.info("[wifi_test] get IpInfo.");
var ipInfo = wifi.getIpInfo(); var ipInfo = wifi.getIpInfo();
console.info("[wifi_test] getIpInfo -> " + JSON.stringify(ipInfo)); console.info("[wifi_test] getIpInfo -> " + JSON.stringify(ipInfo));
...@@ -616,35 +599,11 @@ describe('ACTS_WifiTest', function() { ...@@ -616,35 +599,11 @@ describe('ACTS_WifiTest', function() {
var configs = wifi.getDeviceConfigs(); var configs = wifi.getDeviceConfigs();
console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length == 0); expect(true).assertEqual(configs.length == 0);
done()
})
/**
* @tc.number SUB_Communication_WiFi_Sta_Off_0002
* @tc.name testwifiStateChangeOff
* @tc.desc Test wifiStateChangeOff api.
* @tc.author wudangping wwx1075776
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Sta_ON_0002', 0, async function (done) {
console.info("[wifi_test] wifiConnectionChange On test");
await wifi.on('wifiConnectionChange',function (data) {
console.info("[wifi_test] wifiConnectionChangeOn ->" + data);
expect(true).assertEqual(data != null);
done();
});
wifi.off('wifiConnectionChange',function (data) {
console.info("[wifi_test] wifiConnectionChangeOff ->" + data);
expect(true).assertEqual(data != null);
done();
});
}) })
console.log("*************[wifi_test] start wifi js unit test end*************"); 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.
先完成此消息的编辑!
想要评论请 注册