diff --git a/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js b/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js index 13720bc9b277954f1e8792231519cb5b38f74e29..4014472fa2ba66d3fce575a00ea47a2d2b6253b9 100755 --- a/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js +++ b/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js @@ -21,6 +21,14 @@ function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) } +async function tryToDisableWifi(){ + if(wifi.isWifiActive()){ + console.info("wifi_test/disable wifi:" + wifi.disableWifi()); + await sleep(5000); + } + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} + var WifiSecurityType = { WIFI_SEC_TYPE_INVALID : 0, WIFI_SEC_TYPE_OPEN : 1, @@ -51,12 +59,9 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 0 */ 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] enableHotspot and disableHotspot test start."); - if (wifi.isWifiActive()) { + if (wifi.isWifiActive()) { var disable = wifi.disableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi close result: " + disable); + await sleep(5000); expect(disable).assertTrue(); } var close =wifi.isWifiActive(); @@ -65,12 +70,10 @@ describe('ACTS_WifiTest', function() { if (!wifi.isHotspotActive()) { var on = wifi.enableHotspot(); await sleep(5000); - console.info("[wifi_test] enableHotspot result -> " + on); expect(on).assertTrue(); } console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); expect(wifi.isHotspotActive()).assertTrue(); - console.info("[wifi_test] enableHotspot and disableHotspot test end."); done(); }) @@ -81,24 +84,20 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 0 */ it('SUB_Communication_WiFi_Hotspot_Config_0001', 0, async function (done) { - console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0001"); - console.info("[wifi_test] set a valid 2.4G hotspot config start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(3000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); expect(wifi.isHotspotActive()).assertFalse(); var isSuccess = wifi.setHotspotConfig(HotspotConfig); - console.log("[wifi_test] set 2.4G hotspot config result: " + isSuccess); expect(isSuccess).assertTrue(); - console.info("[wifi_test] check band of current band should be 2.4G."); + var hotspotConfig = wifi.getHotspotConfig(); console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig)); expect(hotspotConfig.band).assertEqual(1); - console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0001 end"); done() }) @@ -109,14 +108,13 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 1 */ 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] set a valid hotspot config start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(3000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } + console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); var HotspotConfig5G = { "ssid": "testWgr", "band": 2, @@ -125,9 +123,8 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess5 = wifi.setHotspotConfig(HotspotConfig5G); - console.log("[wifi_test] set 5G hotspot config result1: " + isSuccess5); expect(isSuccess5).assertFalse(); - console.info("[wifi_test] check band of current band should be 5G."); + var hotspotConfig5 = wifi.getHotspotConfig(); console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig5)); expect(hotspotConfig5.band).assertEqual(1); @@ -141,7 +138,7 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ it('SUB_Communication_WiFi_Hotspot_Config_0003', 0, async function (done) { - console.info("[wifi_test] set a invalid hotspot config start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(3000); @@ -170,15 +167,12 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ 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] check the state of hotspot, if it's open, close it."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } - console.log("[wifi_test] set max preSharedKey valid hotspot config " ); var HotspotConfigM= { "ssid": "testWgr", "band": 1, @@ -189,7 +183,7 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM); console.log("[wifi_test] set max preSharedKey valid hotspot config result: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] set 65 preSharedKey invalid hotspot config " ); + var HotspotConfigM1= { "ssid": "testWgr", "band": 1, @@ -198,9 +192,7 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM1); - console.log("[wifi_test] set 65 preSharedKey invalid hotspot config result: " + isSuccess1); expect(isSuccess1).assertFalse(); - console.info("[wifi_test] check band of current band should be 5G."); var hotspotConfigS= wifi.getHotspotConfig(); console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfigS)); expect(hotspotConfigS.preSharedKey.length).assertEqual(63); @@ -214,14 +206,13 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ 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."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } - console.log("[wifi_test] set min preSharedKey valid hotspot config " ); + var HotspotConfigI= { "ssid": "testWgr", "band": 1, @@ -230,14 +221,13 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI); - console.log("[wifi_test] set 8 preSharedKey valid hotspot config result: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); + var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); console.info("preSharedKey: " + config.preSharedKey); expect(config.preSharedKey.length).assertEqual(8); - console.log("[wifi_test] set 7 preSharedKey invalid hotspot config" ); + var HotspotConfigI2= { "ssid": "testWgr", "band": 1, @@ -246,12 +236,10 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2); - console.log("[wifi_test] set 7 preSharedKey invalid hotspot config result:" + isSuccess1); expect(isSuccess1).assertFalse(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); + var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("preSharedKey: " + config.preSharedKey); expect(config.preSharedKey.length).assertEqual(8); done(); }) @@ -263,18 +251,16 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ 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."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); - expect(on2).assertTrue(); + expect(off).assertTrue(); } - console.log("[wifi_test] check the state of Hotspot" ); var isHotspotActive = wifi.isHotspotActive(); console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); expect(isHotspotActive).assertFalse(); - console.log("[wifi_test] set max ssid invalid hotspot config" ); + var HotspotConfigS= { "ssid": "testWgr123testWgr123testWgr12356", "band": 1, @@ -283,10 +269,8 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS); - console.log("[wifi_test] set 32bit ssid invalid hotspot config result: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] set 33bit ssid invalid hotspot config" ); var HotspotConfigS1= { "ssid": "testWgr123testWgr123testWgr123567", "band": 1, @@ -297,10 +281,8 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS1); console.log("[wifi_test] set 33bit ssid invalid hotspot config result: " + isSuccess1); expect(isSuccess1).assertFalse(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.ssid); expect(config.ssid.length).assertEqual(32); done(); @@ -312,12 +294,11 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test set a null ssid invalid hotspot config * @tc.level Level 2 */ - it('SUB_Communication_WiFi_Hotspot_Config_0007', 0, async function (done) { - console.info("[wifi_test] set a null ssid invalid hotspot config start."); + it('SUB_Communication_WiFi_Hotspot_Config_0007', 0, async function(done) { + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(2000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } var HotspotConfigN= { @@ -339,15 +320,12 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test set a contains Chinese.special.digits valid hotspot config * @tc.level Level 2 */ - it('SUB_Communication_WiFi_Hotspot_Config_0008', 0, async function (done) { + it('SUB_Communication_WiFi_Hotspot_Config_0008', 0, async function(done) { if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(3000); - console.info("[wifi_test] enableHotspot result -> " + off); expect(off).assertTrue(); - } - console.info("[wifi_test] set contains Chinese valid hotspot config start."); var HotspotConfigC= { "ssid": "测试123!@#¥%……&*( ", "band": 1, @@ -356,17 +334,13 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 }; var isSuccess1 = wifi.setHotspotConfig(HotspotConfigC); - console.log("[wifi_test] set a valid hotspot config result1:" + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check the state of Hotspot " ); var isHotspotActive = wifi.isHotspotActive(); console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); expect(isHotspotActive).assertFalse(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.ssid); expect(true).assertEqual(config.ssid==HotspotConfigC.ssid); done(); }) @@ -378,11 +352,10 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ it('SUB_Communication_WiFi_Hotspot_Config_0009', 0, async function (done) { - console.info("[wifi_test] set invalid hotspot config start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(3000); - console.info("[wifi_test] enableHotspot result -> " + off); expect(off).assertTrue(); } @@ -429,16 +402,13 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ it('SUB_Communication_WiFi_Hotspot_Config_0010', 0, async function (done) { - console.info("[wifi_test] set valid hotspot config start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); - } - console.info("[wifi_test] set PSK securityType hotspot config start."); var HotspotConfigPSK= { "ssid": "test123", "band": 1, @@ -447,12 +417,9 @@ describe('ACTS_WifiTest', function() { "maxConn": 8 } var isSuccess1 = wifi.setHotspotConfig(HotspotConfigPSK); - console.log("[wifi_test] set a PSK preSharedKey hotspot config result1: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.ssid); expect(config.securityType).assertEqual(3); console.log("[wifi_test] check the state of Hotspot" ); var isHotspotActive = wifi.isHotspotActive(); @@ -469,14 +436,13 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ it('SUB_Communication_WiFi_Hotspot_Config_0011', 0, async function (done) { - console.info("[wifi_test] wifi disableHotspot start."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } - console.info("[wifi_test] set open securityType hotspot config start."); + var HotspotConfigO= { "ssid": "test123", "band": 1, @@ -487,10 +453,8 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigO); console.log("[wifi_test] set a open preSharedKey hotspot config result1: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.ssid); expect(config.securityType).assertEqual(1); done(); @@ -503,15 +467,13 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ 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."); + await tryToDisableWifi(); if (wifi.isHotspotActive()) { var off = wifi.disableHotspot(); await sleep(5000); - console.info("[wifi_test] disableHotspot result -> " + off); expect(off).assertTrue(); } - console.log("[wifi_test] set min maxConn valid hotspot config " ); var HotspotConfigI= { "ssid": "testWgr", "band": 1, @@ -522,13 +484,10 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI); console.log("[wifi_test] set maxConn valid hotspot config result: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check current hotspot config maxConn is 8 " ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("maxConn: " + config.maxConn); expect(config.maxConn).assertEqual(8); - console.log("[wifi_test] set more maxConn invalid hotspot config" ); var HotspotConfigI2= { "ssid": "testWgr", "band": 1, @@ -539,10 +498,8 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2); console.log("[wifi_test] set more maxConn invalid hotspot config result: " + isSuccess1); expect(isSuccess1).assertFalse(); - console.log("[wifi_test] check current hotspot config maxConn" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.maxConn); expect(config.maxConn).assertEqual(8); done(); }) @@ -554,19 +511,15 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ it('SUB_Communication_WiFi_Hotspot_Config_0012', 0, async function (done) { - console.info("[wifi_test] wifi enableHotspot start."); - console.info("[wifi_test] SUB_Communication_WiFi_Hotspot_Config_0012."); + await tryToDisableWifi(); if (!wifi.isHotspotActive()) { var on = wifi.enableHotspot(); await sleep(5000); - console.info("[wifi_test] enableHotspot result -> " + on); expect(on).assertTrue(); } - console.log("[wifi_test] check the state of Hotspot" ); var isHotspotActive = wifi.isHotspotActive(); console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); expect(isHotspotActive).assertTrue(); - console.info("[wifi_test] open Hotspot, set valid hotspot config start."); var HotspotConfigWO= { "ssid": "WIFITEST", "band": 1, @@ -577,10 +530,8 @@ describe('ACTS_WifiTest', function() { var isSuccess1 = wifi.setHotspotConfig(HotspotConfigWO); console.log("[wifi_test] set a psk preSharedKey hotspot config result1: " + isSuccess1); expect(isSuccess1).assertTrue(); - console.log("[wifi_test] check current hotspot config preSharedKey is 8bit" ); var config = wifi.getHotspotConfig(); console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); - console.info("ssid: " + config.ssid); expect(config.ssid).assertEqual('WIFITEST'); done(); @@ -594,24 +545,20 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 2 */ 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."); + await tryToDisableWifi(); if (!wifi.isHotspotActive()) { var on = wifi.enableHotspot(); await sleep(5000); - console.info("[wifi_test] enableHotspot result -> " + on); expect(on).assertTrue(); - } - console.log("[wifi_test] check the state of Hotspot" ); var isHotspotActive = wifi.isHotspotActive(); console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); expect(isHotspotActive).assertTrue(); - console.log("[wifi_test] Obtains the list of clients that are connected to Wi-Fi hotspot" ); var stationInfo = wifi.getStations(); - console.info("[wifi_test] getStations result -> " + JSON.stringify(stationInfo)); - console.info("ssid: " + stationInfo.name); - console.info("macAddress: " + stationInfo.macAddress); - console.info("ipAddress: " + stationInfo.ipAddress); + console.info("[wifi_test] getStations result ->" + JSON.stringify(stationInfo)); + console.info("ssid: " + stationInfo.name + + "macAddress: " + stationInfo.macAddress + + "ipAddress: " + stationInfo.ipAddress); expect(stationInfo.length).assertEqual(0); done(); @@ -753,4 +700,3 @@ describe('ACTS_WifiTest', function() { }) - diff --git a/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js b/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js index 96ea6240297c4235c0fbba7fecb82a64e3c2c043..c2d29726e1137a5aed07fcaf5ae49c1283331410 100644 --- a/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js +++ b/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js @@ -21,6 +21,13 @@ function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) } +async function tryToEnableWifi(){ + if(!wifi.isWifiActive()){ + console.info("wifi_test/enable wifi:" + wifi.enableWifi()); + await sleep(3000); + } + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} var GroupOwnerBand = { GO_BAND_AUTO : 0, @@ -38,44 +45,36 @@ describe('ACTS_WifiTest', function () { /** * @tc.number Setting_0001 * @tc.name SUB_Communication_WiFi_P2P_Setting_0001 - * @tc.author wudangping wwx1075776 * @tc.desc Test setDeviceName infos */ - it('SUB_Communication_WiFi_P2P_Setting_0001', 0, function() { + it('SUB_Communication_WiFi_P2P_Setting_0001', 0, async function(done) { + await tryToEnableWifi(); console.info("[wifi_test] test setDeviceName start."); var devName = wifi.setDeviceName("P2PTest"); console.info("[wifi_test] test start setDeviceName->" + devName); expect(devName).assertTrue(); + done(); }) /** * @tc.number config_0001 * @tc.name SUB_Communication_WiFi_P2P_Config_0001 - * @tc.author wudangping wwx1075776 - * @tc.desc Test createGroup and getCurrentGroup infos + * @tc.desc Test createGroup and getCurrentGroup promise infos */ it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) { + await tryToEnableWifi(); var WifiP2PConfig = { - deviceAddress : "02:11:65:f2:0d:6e", + deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", groupName : "AAAZZZ", goBand : 0 }; - console.info("[wifi_test] check the state of wifi, if it's close, open it."); - var active = wifi.isWifiActive(); - if(!active){ - var enable = wifi.enableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - console.info("[wifi_test] test start createGroup ."); var addConfig = wifi.createGroup(WifiP2PConfig); await sleep(2000); - console.info("[wifi_test] test start createGroup result." + addConfig); expect(addConfig).assertTrue(); await wifi.getCurrentGroup() .then((data) => { @@ -86,62 +85,72 @@ describe('ACTS_WifiTest', function () { console.info("[wifi_js]getCurrentGroup promise then error." + JSON.stringify(error)); expect().assertFail(); }); - wifi.getCurrentGroup( + + }) + + /** + * @tc.number config_0002 + * @tc.name SUB_Communication_WiFi_P2P_Config_0002 + * @tc.desc Test getCurrentGroup callback infos + */ + it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) { + await tryToEnableWifi(); + var WifiP2PConfig = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ", + goBand : 0 + }; + + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + var addConfig = wifi.createGroup(WifiP2PConfig); + await sleep(2000); + expect(addConfig).assertTrue(); + + await wifi.getCurrentGroup( (err, result) => { if (err) { console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); return; } console.info("[wifi_test] getCurrentGroup [callback] -> " + JSON.stringify(result)); - console.info("isP2pGo: " + result.isP2pGo); - console.info("deviceName: " + result.ownerInfo.deviceName); - console.info("deviceAddress: " + result.ownerInfo.deviceAddress); - console.info("primaryDeviceType: " + result.ownerInfo.primaryDeviceType); - console.info("deviceStatus: " + result.ownerInfo.deviceStatus); - console.info("groupCapabilitys: " + result.ownerInfo.groupCapabilitys); - console.info("passphrase: " + result.passphrase); - console.info("interface: " + result.interface); - console.info("groupName: " + result.groupName); - console.info("clientDevices: " + result.clientDevices); - console.info("networkId: " + result.networkId); - console.info("frequency: " + result.frequency); - console.info("goIpAddress: " + result.goIpAddress); - console.info("[wifi_test] test start removeGroup"); + console.info("isP2pGo: " + result.isP2pGo + + "deviceName: " + result.ownerInfo.deviceName + + "deviceAddress: " + result.ownerInfo.deviceAddress + + "primaryDeviceType: " + result.ownerInfo.primaryDeviceType + + "deviceStatus: " + result.ownerInfo.deviceStatus + + "groupCapabilitys: " + result.ownerInfo.groupCapabilitys + + "passphrase: " + result.passphrase + "interface: "+ result.interface + + "groupName: " + result.groupName + + "clientDevices: " + result.clientDevices +"networkId: " + result.networkId + + "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress); var removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); expect(removeConfig).assertTrue(); done(); }); }) /** - * @tc.number config_0002 - * @tc.name SUB_Communication_WiFi_P2P_Config_0002 - * @tc.author wudangping wwx1075776 + * @tc.number config_0003 + * @tc.name SUB_Communication_WiFi_P2P_Config_0003 * @tc.desc Test createGroup 2.4G band and getCurrentGroup infos */ - it('SUB_Communication_WiFi_P2P_Config_0002', 0, async function(done) { + it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) { + await tryToEnableWifi(); var WifiP2PConfig2 = { - deviceAddress : "02:11:65:f2:0d:6e", + deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", groupName : "AAAZZZ", goBand : 1 }; - console.info("[wifi_test] check the state of wifi, if it's close, open it."); - var active = wifi.isWifiActive(); - if(!active){ - var enable = wifi.enableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - console.info("[wifi_test] test start create 2.4G band Group ."); var addConfig = wifi.createGroup(WifiP2PConfig2); await sleep(2000); - console.info("[wifi_test] test start createGroup result." + addConfig); expect(addConfig).assertTrue(); await wifi.getCurrentGroup() .then((data) => { @@ -152,106 +161,82 @@ describe('ACTS_WifiTest', function () { console.info("[wifi_test]getCurrentGroup promise then error." + JSON.stringify(error)); expect(error).assertFail(); }); - console.info("[wifi_test] test start removeGroup"); var removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); expect(removeConfig).assertTrue(); done(); }) /** - * @tc.number config_0003 - * @tc.name SUB_Communication_WiFi_P2P_Config_0003 - * @tc.author wudangping wwx1075776 + * @tc.number config_0004 + * @tc.name SUB_Communication_WiFi_P2P_Config_0004 * @tc.desc Test createGroup and deletePersistentGroup infos */ - it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) { + it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) { + await tryToEnableWifi(); var WifiP2PConfig = { - deviceAddress : "02:11:65:f2:0d:6e", + deviceAddress : "00:00:00:00:00:00", netId : -2, passphrase : "12345678", groupName : "AAAZZZ", goBand : 0 }; - console.info("[wifi_test] check the state of wifi, if it's close, open it."); - var active = wifi.isWifiActive(); - if(!active){ - var enable = wifi.enableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - console.info("[wifi_test] test start createGroup [promise]."); var addConfig = wifi.createGroup(WifiP2PConfig); await sleep(2000); - console.info("[wifi_test] test start createGroup [promise]." + addConfig); expect(addConfig).assertTrue(); await wifi.getCurrentGroup() .then((data) => { var resultLength = Object.keys(data).length; console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); expect(true).assertEqual(resultLength!=0); - - console.info("[wifi_test] test start deletePersistentGroup"); + var removePConfig = wifi.deletePersistentGroup(data.networkId); - console.info("[wifi_test] test start deletePersistentGroup" + removePConfig); expect(removePConfig).assertTrue(); - console.info("[wifi_test] test start removeGroup"); + var removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); expect(removeConfig).assertTrue(); }); done(); }) /** - * @tc.number config_0004 - * @tc.name SUB_Communication_WiFi_P2P_Config_0004 - * @tc.author wudangping wwx1075776 - * @tc.desc Test p2pConnect infos + * @tc.number config_0005 + * @tc.name SUB_Communication_WiFi_P2P_Config_0005 + * @tc.desc Test p2pConnect infos */ - it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) { + it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) { + await tryToEnableWifi(); var WifiP2PConfig3 = { - deviceAddress : "02:11:65:f2:0d:6e", + deviceAddress : "00:00:00:00:00:00", netId : -2, passphrase : "12345678", groupName : "AAAZZZ", goBand : 0 }; - console.info("[wifi_test] check the state of wifi, if it's close, open it."); - var active = wifi.isWifiActive(); - if(!active){ - var enable = wifi.enableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - console.info("[wifi_test] test start startDiscoverDevices."); var scanConfig = wifi.startDiscoverDevices(); await sleep(2000); - console.info("[wifi_test] test startDiscoverDevices result." + scanConfig); expect(scanConfig).assertTrue(); - console.info("[wifi_test] test start p2pConnect."); + var connConfig = wifi.p2pConnect(WifiP2PConfig3); console.info("[wifi_test] test p2pConnect result." + connConfig); expect(connConfig).assertTrue(); - console.info("[wifi_test] test start stopDiscoverDevices."); var stopScan = wifi.stopDiscoverDevices(); console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); done() }) /** - * @tc.number config_0005 - * @tc.name SUB_Communication_WiFi_P2P_Config_0005 - * @tc.author wudangping wwx1075776 - * @tc.desc Test getP2pLinkedInfo infos + * @tc.number config_0006 + * @tc.name SUB_Communication_WiFi_P2P_Config_0006 + * @tc.desc Test getP2pLinkedInfo promise infos */ - it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) { + it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) { + await tryToEnableWifi(); var P2pConnectState = { DISCONNECTED :0, CONNECTED : 1, @@ -265,34 +250,47 @@ describe('ACTS_WifiTest', function () { console.info("[wifi_test]getP2pLinkedInfo promise then error." + JSON.stringify(error)); expect(error).assertFail(); }); - wifi.getP2pLinkedInfo((err, result) => { + + done(); + }) + +/** + * @tc.number config_0007 + * @tc.name SUB_Communication_WiFi_P2P_Config_0007 + * @tc.desc Test getP2pLinkedInfo callback infos + */ + it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) { + await tryToEnableWifi(); + var P2pConnectState = { + DISCONNECTED :0, + CONNECTED : 1, + }; + + await wifi.getP2pLinkedInfo((err, result) => { if (err) { console.error('failed to getP2pLinkedInfo callback ' + JSON.stringify(err)); return; } console.info("[wifi_test] getP2pLinkedInfo [callback] -> " + JSON.stringify(result)); - console.info("connectState: " + result.connectState); - console.info("isGroupOwner: " + result.isGroupOwner); - console.info("groupOwnerAddr: " + result.groupOwnerAddr); + console.info("connectState: " + result.connectState + + "isGroupOwner: " + result.isGroupOwner + + "groupOwnerAddr: " + result.groupOwnerAddr); expect(false).assertEqual(result.connectState ==P2pConnectState.CONNECTED); - }); done(); }) /** - * @tc.number config_0006 - * @tc.name SUB_Communication_WiFi_P2P_Config_0006 - * @tc.author wudangping wwx1075776 + * @tc.number config_0008 + * @tc.name SUB_Communication_WiFi_P2P_Config_0008 * @tc.desc Test p2pCancelConnect infos */ - it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) { - console.info("[wifi_test] test start p2pCancelConnect."); + it('SUB_Communication_WiFi_P2P_Config_0008', 0, async function(done) { + await tryToEnableWifi(); var disConn = wifi.p2pCancelConnect(); await sleep(2000); console.info("[wifi_test] test p2pCancelConnect result." + disConn); expect(disConn).assertTrue(); - console.info("[wifi_test] test start removeGroup"); var removeConfig = wifi.removeGroup(); console.info("[wifi_test] test start removeGroup" + removeConfig); expect(removeConfig).assertTrue(); @@ -300,12 +298,12 @@ describe('ACTS_WifiTest', function () { }) /** - * @tc.number config_0007 - * @tc.name SUB_Communication_WiFi_P2P_Config_0007 - * @tc.author wudangping wwx1075776 + * @tc.number config_0009 + * @tc.name SUB_Communication_WiFi_P2P_Config_0009 * @tc.desc Test getP2pPeerDevices infos */ - it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) { + it('SUB_Communication_WiFi_P2P_Config_0009', 0, async function(done){ + await tryToEnableWifi(); var P2pDeviceStatus = { CONNECTED : 0, INVITED : 1, @@ -313,20 +311,11 @@ describe('ACTS_WifiTest', function () { AVAILABLE : 3, UNAVAILABLE : 4, }; - console.info("[wifi_test] check the state of wifi, if it's close, open it."); - var active = wifi.isWifiActive(); - if(!active){ - var enable = wifi.enableWifi(); - await sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - console.info("[wifi_test] test start startDiscoverDevices."); var scanConfig = wifi.startDiscoverDevices(); await sleep(2000); - console.info("[wifi_test] test startDiscoverDevices result." + scanConfig); expect(scanConfig).assertTrue(); await wifi.getP2pPeerDevices() .then((data) => { @@ -337,7 +326,32 @@ describe('ACTS_WifiTest', function () { console.info("[wifi_test]getP2pPeerDevices promise then error." + JSON.stringify(error)); expect().assertFail(); }); - wifi.getP2pPeerDevices((err, result) => { + done(); + + }) + + /** + * @tc.number config_0010 + * @tc.name SUB_Communication_WiFi_P2P_Config_0010 + * @tc.desc Test getP2pPeerDevices infos + */ + it('SUB_Communication_WiFi_P2P_Config_0010', 0, async function(done){ + await tryToEnableWifi(); + var P2pDeviceStatus = { + CONNECTED : 0, + INVITED : 1, + FAILED : 2, + AVAILABLE : 3, + UNAVAILABLE : 4, + }; + + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + var scanConfig = wifi.startDiscoverDevices(); + await sleep(2000); + expect(scanConfig).assertTrue(); + + await wifi.getP2pPeerDevices((err, result) => { if (err) { console.error('failed to getP2pPeerDevices infos callback because ' + JSON.stringify(err)); return; @@ -345,11 +359,11 @@ describe('ACTS_WifiTest', function () { console.info("[wifi_test] getP2pPeerDevices [callback] -> " + JSON.stringify(result)); var len = Object.keys(result).length; for (var j = 0; j < len; ++j) { - console.info("deviceName: " + result[j].deviceName); - console.info("deviceAddress: " + result[j].deviceAddress); - console.info("primaryDeviceType: " + result[j].primaryDeviceType); - console.info("deviceStatus: " + result[j].deviceStatus); - console.info("groupCapabilitys: " + result[j].groupCapabilitys); + console.info("deviceName: " + result[j].deviceName + + "deviceAddress: " + result[j].deviceAddress + + "primaryDeviceType: " + result[j].primaryDeviceType + + "deviceStatus: " + result[j].deviceStatus + + "groupCapabilitys: " + result[j].groupCapabilitys ); if(result[j].deviceStatus ==P2pDeviceStatus.UNAVAILABLE){ console.info("deviceStatus: " + result[j].deviceStatus); } @@ -366,30 +380,26 @@ describe('ACTS_WifiTest', function () { console.info("deviceStatus: " + result[j].deviceStatus); } } - console.info("[wifi_test] test stopDiscoverDevices."); var stopScan = wifi.stopDiscoverDevices(); - console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); expect(stopScan).assertTrue(); done(); }); - }) /** * @tc.number p2pStateChange_0001 * @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pStateChange callback */ it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) { - console.info('[wifi_test] OnP2pStateChange test start ...'); + await tryToEnableWifi(); await wifi.on('p2pStateChange', result => { console.info("onP2pStateChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); done(); }); setTimeout(function() { - console.info('[wifi_test] offP2pStateChange test start ...'); + wifi.off('p2pStateChange', result => { console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -401,29 +411,10 @@ describe('ACTS_WifiTest', function () { /** * @tc.number p2pConnectionChange_0002 * @tc.name SUB_Communication_WiFi_P2P_p2pConnectionChange_0002 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pConnectionChange callback */ it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) { - console.info('[wifi_test] p2pConnectionChange test start ...'); - var recvP2pConnectionChangeFunc = result => { - console.info("wifi_test / p2p connection change receive event: " + JSON.stringify(result)); - - wifi.getP2pLinkedInfo((err, data) => { - if (err) { - console.error('wifi_test / failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); - return; - } - console.info("wifi_test / get getP2pLinkedInfo [callback] -> " + JSON.stringify(data)); - }); - 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)); - }); - }; + await tryToEnableWifi(); await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc); expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); @@ -442,7 +433,6 @@ describe('ACTS_WifiTest', function () { /** * @tc.number p2pDeviceChange_0003 * @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pDeviceChange callback */ it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) { @@ -465,11 +455,10 @@ describe('ACTS_WifiTest', function () { /** * @tc.number p2pPeerDeviceChange_0004 * @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pPeerDeviceChange callback */ it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) { - console.info('[wifi_test] Onp2pDeviceChange test start ...'); + await tryToEnableWifi(); var recvP2pPeerDeviceChangeFunc = result => { console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result)); wifi.getP2pDevices((err, data) => { @@ -501,7 +490,6 @@ describe('ACTS_WifiTest', function () { done(); }); setTimeout(function() { - console.info('[wifi_test] offP2pPeerDeviceChange test start ...'); wifi.off('p2pPeerDeviceChange', result => { console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -513,11 +501,10 @@ describe('ACTS_WifiTest', function () { /** * @tc.number p2pPersistentGroupChange_0005 * @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pPersistentGroupChange callback */ it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) { - console.info('[wifi_test] OnP2pPersistentGroupChange test start ...'); + await tryToEnableWifi(); var recvP2pPersistentGroupChangeFunc = result => { console.info("wifi_test / p2p persistent group change receive event" + JSON.stringify(result)); var config = { @@ -527,9 +514,7 @@ describe('ACTS_WifiTest', function () { "groupName":"", "goBand":0, }; - console.info("[wifi_test] test start createGroup ."); var addConfig = wifi.createGroup(config); - console.info("[wifi_test] test start createGroup result." + addConfig); expect(addConfig).assertTrue(); wifi.getCurrentGroup((err, data) => { if (err) { @@ -545,7 +530,6 @@ describe('ACTS_WifiTest', function () { done(); }); setTimeout(function() { - console.info('[wifi_test] offP2pPersistentGroupChange test start ...'); wifi.off('p2pPersistentGroupChange', result => { console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -557,18 +541,16 @@ describe('ACTS_WifiTest', function () { /** * @tc.number p2pDiscoveryChange_0006 * @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006 - * @tc.author wudangping wwx1075776 * @tc.desc Test p2pDiscoveryChange callback */ it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) { - console.info('[wifi_test] Onp2pDiscoveryChange test start ...'); + await tryToEnableWifi(); await wifi.on('p2pDiscoveryChange', result => { console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); done(); }); setTimeout(function() { - console.info('[wifi_test] offp2pDiscoveryChange test start ...'); wifi.off('p2pDiscoveryChange', result => { console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -580,4 +562,3 @@ describe('ACTS_WifiTest', function () { console.log("*************[wifi_test] start wifi js unit test end*************"); }) - diff --git a/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js b/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js index 0e2262ec2309c989c48d0fd2c5dc4993086bef77..fa6c684d9ab35dfdce9c1232f1bcd74d377dcdad 100755 --- a/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js +++ b/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js @@ -21,6 +21,14 @@ function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) } +async function tryToEnableWifi(){ + if(!wifi.isWifiActive()){ + console.info("wifi_test/enable wifi:" + wifi.enableWifi()); + await sleep(3000); + } + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} + var WifiSecurityType = { WIFI_SEC_TYPE_INVALID: 0, WIFI_SEC_TYPE_OPEN: 1, @@ -44,21 +52,6 @@ var SuppState = { INVALID: 11, } -var wifiDeviceConfig = { - "ssid": "TEST", - "bssid": "A1:B1:C1:D1:E1:F1", - "preSharedKey": "12345678", - "isHiddenSsid": false, - "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, - "netId": -1, - "ipType": 1, - "creatorUid": 7, - "disableReason": 0, - "randomMacType": 0, - "randomMacAddr": "11:22:33:44:55:66", - "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, -} - var ConnState = { SCANNING: 0, CONNECTING: 1, @@ -77,6 +70,12 @@ var ipConfig = { "domains": ["aaa"], } +var IpType = { + STATIC : 0, + DHCP : 1, + UNKNOWN: 2 +} + describe('ACTS_WifiTest', function() { beforeEach(function() {}) @@ -88,7 +87,6 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test wifi.isWifiEnable API functionality. */ 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] check the state of wifi, if it's close, open it."); var active = wifi.isWifiActive(); if (!active) { @@ -97,11 +95,11 @@ describe('ACTS_WifiTest', function() { console.log("[wifi_test] wifi open result: " + enable); 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()); expect(wifi.isWifiActive()).assertFalse(); done(); @@ -113,36 +111,25 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test get ScanInfos callback API functionality. */ it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Scan_0001]"); - var active1 = wifi.isWifiActive(); - if (!active1) { - var enable = wifi.enableWifi(); - await sleep(5000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } + await tryToEnableWifi(); var scan = wifi.scan(); await sleep(3000); console.log("[wifi_test] open wifi scan result: " + scan); expect(scan).assertTrue(); - console.info("[wifi_test] Wifi getScanInfos promise test[1]."); await wifi.getScanInfos() .then(result => { var clen = Object.keys(result).length; - console.log("[wifi_test] wifi getScanInfos promise result length: " + clen); expect(clen).assertLarger(0); console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result)); }); - console.info("[wifi_test] Wifi getScanInfos callback test[2]."); wifi.getScanInfos( (err,result) => { if(err) { console.log("[wifi_test] wifi getScanInfos failed " + err); } var clen = Object.keys(result).length; - console.log("[wifi_test] wifi getScanInfos callback result length: " + clen); if (!(clen == 0)) { expect(clen).assertLarger(0); console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result)); @@ -167,8 +154,8 @@ describe('ACTS_WifiTest', function() { * @tc.name SUB_Communication_WiFi_Sta_Scan_0004 * @tc.desc Test wifi.getSignalLevel API functionality. */ - it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Scan_0004]"); + it('SUB_Communication_WiFi_Sta_Scan_0004', 0, async function(done) { + await tryToEnableWifi(); console.info("[wifi_test] check the 2.4G rssi assgined to level test."); expect(wifi.getSignalLevel(-65, 1)).assertEqual(4); @@ -198,6 +185,7 @@ describe('ACTS_WifiTest', function() { expect(wifi.getSignalLevel(-86, 2)).assertEqual(0); expect(wifi.getSignalLevel(-127, 2)).assertEqual(0); + done(); }) /** @@ -206,8 +194,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test create a OPEN SecurityType wifi device config */ 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] create a OPEN SecurityType wifi device config start."); + await tryToEnableWifi(); wifi.removeAllNetwork(); var wifiDeviceConfig1 = { "ssid": "TEST_OPEN", @@ -216,19 +203,19 @@ describe('ACTS_WifiTest', function() { "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_OPEN, "netId": -1, - "ipType": 1, + "ipType": IpType.DHCP, "creatorUid": 7, "disableReason": 0, "randomMacType": 0, "randomMacAddr": "11:22:33:44:55:66", - "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, + "staticIp": ipConfig, }; await wifi.addDeviceConfig(wifiDeviceConfig1) .then(netWorkId => { console.info("[wifi_test]add OPEN Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType); @@ -244,19 +231,16 @@ describe('ACTS_WifiTest', function() { } console.info("[wifi_test]add OPEN Deviceconfig callback : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result2 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType); expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig1.isHiddenSsid); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); done() }); @@ -268,8 +252,8 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test create a PSK SecurityType wifi device config */ it('SUB_Communication_WiFi_Sta_Config_0002', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0002]"); - console.info("[wifi_test] create a PSK SecurityType wifi device config start."); + await tryToEnableWifi(); + var wifiDeviceConfig1 = { "ssid": "TEST_PSK", "bssid": "", @@ -289,7 +273,7 @@ describe('ACTS_WifiTest', function() { .then(netWorkId => { console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType); @@ -297,9 +281,7 @@ describe('ACTS_WifiTest', function() { expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfig1.preSharedKey); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeDevice(netWorkId); - console.info("[wifi_test] check remove config successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current getConfig: " + JSON.stringify(configs)); @@ -311,11 +293,11 @@ describe('ACTS_WifiTest', function() { /** * @tc.number Config_0003 * @tc.name SUB_Communication_WiFi_Sta_Config_0003 - * @tc.desc Test create a PSK SecurityType wifi device config + * @tc.desc Test create a WEP SecurityType wifi device config */ it('SUB_Communication_WiFi_Sta_Config_0003', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0003]"); - console.info("[wifi_test] create WEP SecurityType wifi device config start."); + await tryToEnableWifi(); + var wifiDeviceConfig1 = { "ssid": "TEST_WEP", "bssid": "", @@ -335,7 +317,7 @@ describe('ACTS_WifiTest', function() { .then(netWorkId => { console.info("[wifi_test]add WEP Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); expect(wifi.connectToNetwork(netWorkId)).assertTrue(); @@ -345,12 +327,9 @@ describe('ACTS_WifiTest', function() { expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfig1.preSharedKey); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeDevice(netWorkId); - console.info("[wifi_test] check remove config successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove config,current getConfig: " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); }); done() @@ -362,8 +341,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test remove all wifi device config */ it('SUB_Communication_WiFi_Sta_Config_0004', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0004]"); - console.info("[wifi_test] create multiple valid wifi device config and add it."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TESTWgr1", "bssid": "", @@ -387,7 +365,7 @@ describe('ACTS_WifiTest', function() { } console.info("[wifi_test] wifi addDeviceconfig1 callback:" + JSON.stringify(netWorkId1)); expect(true).assertEqual(netWorkId1 != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length >= 1); @@ -403,16 +381,14 @@ describe('ACTS_WifiTest', function() { } console.info("[wifi_test] wifi addDeviceconfig2 callback : " + JSON.stringify(netWorkId2)); expect(true).assertEqual(netWorkId2 != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length >= 1); - console.info("[wifi_test] remove all configs"); + var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove configs,current get Configs : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); resolve() }); @@ -426,8 +402,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test disableNetwork device config */ it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0005]"); - console.info("[wifi_test] create a valid wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfigD = { "ssid": "TESTD", "bssid": "", @@ -446,23 +421,17 @@ describe('ACTS_WifiTest', function() { .then(netWorkId => { console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); expect(wifi.connectToNetwork(netWorkId)).assertTrue(); - console.info("[wifi_test] disableNetwork test start."); var disconNet = wifi.disableNetwork(netWorkId); - console.log("[wifi_test] wifi disableNetwork result: " + disconNet); expect(disconNet).assertTrue(); - console.info("[wifi_test] check device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi device config result : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigD.ssid); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); }); done() @@ -474,8 +443,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test update wifi device config */ it('SUB_Communication_WiFi_Sta_Config_0006', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0006]"); - console.info("[wifi_test] create a valid wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfigU = { "ssid": "TEST", "bssid": "", @@ -494,26 +462,21 @@ describe('ACTS_WifiTest', function() { .then(netWorkId => { console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); wifiDeviceConfigU.ssid = "UPDATE"; wifiDeviceConfigU.preSharedKey = "1234567890"; - console.info("[wifi_test] wifi new wifiDeviceConfig1:" + wifi.updateNetwork(wifiDeviceConfigU)); - - console.info("[wifi_test] check update device configs successfully "); + expect(true).assertEqual(wifi.updateNetwork(wifiDeviceConfigU) >= 0); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] updated wifi device config result : " + JSON.stringify(configs)); expect(true).assertEqual(configs[1].ssid == wifiDeviceConfigU.ssid); expect(true).assertEqual(configs[1].preSharedKey == wifiDeviceConfigU.preSharedKey); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); }); done() @@ -525,8 +488,8 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test SSID wifi device config */ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0001', 0, async function(done) { - console.info("[wifi_test][SSUB_Communication_WiFi_Sta_Conn_SSID_0001]"); - console.info("[wifi_test] create a contains chinese SSID wifi device config start."); + await tryToEnableWifi(); + var wifiDeviceConfigZ = { "ssid": "中文测试SSID", "bssid": "", @@ -545,21 +508,18 @@ describe('ACTS_WifiTest', function() { .then(netWorkId => { console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); - console.info("[wifi_test] disableNetwork test start."); + var disconNet = wifi.disableNetwork(netWorkId); - console.log("[wifi_test] wifi disableNetwork result: " + disconNet); expect(disconNet).assertTrue(); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigZ.ssid); expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigZ.preSharedKey); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); @@ -575,8 +535,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test SSID wifi device config */ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0002', 0, async function(done) { - console.info("[wifi_test][SSUB_Communication_WiFi_Sta_Conn_SSID_0002]"); - console.info("[wifi_test] create a kongge SSID wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfigK = { "ssid": "test text", "bssid": "", @@ -594,26 +553,22 @@ describe('ACTS_WifiTest', function() { await wifi.addDeviceConfig(wifiDeviceConfigK) .then(netWorkId => { - console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId)); + console.info("[wifi_test]add kongge SSID Deviceconfig promise : " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); - console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); - console.info("[wifi_test] disableNetwork test start."); + var disconNet = wifi.disableNetwork(netWorkId); - console.log("[wifi_test] wifi disableNetwork result: " + disconNet); expect(disconNet).assertTrue(); - console.info("[wifi_test] check add device configs successfully "); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigK.ssid); expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigK.preSharedKey); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); - console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); }); done() @@ -622,11 +577,10 @@ describe('ACTS_WifiTest', function() { /** * @tc.number Config_SSID_0003 * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0003 - * @tc.desc Test SSID wifi device config + * @tc.desc Test contains chinese SSID device config */ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0003', 0, async function(done) { - console.info("[wifi_test][SSUB_Communication_WiFi_Sta_Conn_SSID_0003]"); - console.info("[wifi_test] create a kongge SSID wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfigT = { "ssid": "!@#¥%&*/", "bssid": "", @@ -644,19 +598,17 @@ describe('ACTS_WifiTest', function() { await wifi.addDeviceConfig(wifiDeviceConfigT) .then(netWorkId => { - console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); - console.info("[wifi_test] check add device configs successfully "); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigT.ssid); expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigT.preSharedKey); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); + var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); expect(true).assertEqual(configs.length == 0); @@ -667,11 +619,10 @@ describe('ACTS_WifiTest', function() { /** * @tc.number Config_SSID_0007 * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0007 - * @tc.desc Test SSID wifi device config + * @tc.desc Test hidden SSID wifi device config */ it('SUB_Communication_WiFi_Sta_Conn_SSID_0007', 0, async function(done) { - console.info("[wifi_test][SSUB_Communication_WiFi_Sta_Conn_SSID_0007]"); - console.info("[wifi_test] create a kongge SSID wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfigT = { "ssid": "test", "bssid": "", @@ -689,18 +640,15 @@ describe('ACTS_WifiTest', function() { await wifi.addDeviceConfig(wifiDeviceConfigT) .then(netWorkId => { - console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); - console.info("[wifi_test] check add device configs successfully "); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigT.ssid); expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfigT.isHiddenSsid); - console.info("[wifi_test] remove config"); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); @@ -718,11 +666,7 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 3 */ it('SUB_Communication_WiFi_Sta_info_0001', 0, async function (done) { - if (!wifi.isWifiActive()) { - var enable = wifi.enableWifi(); - await sleep(3000); - expect(enable).assertTrue(); - } + await tryToEnableWifi(); expect(wifi.isWifiActive()).assertTrue(); console.info('[wifi_test] getDeviceMacAddress test start ...'); var result = wifi.getDeviceMacAddress(); @@ -740,11 +684,7 @@ describe('ACTS_WifiTest', function() { * @tc.level Level 3 */ it('SUB_Communication_WiFi_Sta_Info_0002', 0, async function(done) { - if (!wifi.isWifiActive()) { - var enable = wifi.enableWifi(); - await sleep(3000); - expect(enable).assertTrue(); - } + await tryToEnableWifi(); expect(wifi.isWifiActive()).assertTrue(); console.info(" [wifi_test] getCountryCode start ... "); var countryCode = wifi.getCountryCode(); @@ -761,15 +701,17 @@ describe('ACTS_WifiTest', function() { * @tc.type Function * @tc.level Level 3 */ - it('SUB_Communication_WiFi_Sta_info_0004', 0, function () { - console.info('[wifi_test]FeatureSupported test start ...'); + it('SUB_Communication_WiFi_Sta_info_0004', 0, async function (done) { + await tryToEnableWifi(); + expect(wifi.isWifiActive()).assertTrue(); var result = wifi.getSupportedFeatures(); console.info("[wifi_test] getFeatureSupported -> " + JSON.stringify(result)); console.info("[wifi_test] isFeatureSupported: " + result +"->" + wifi.isFeatureSupported(result)); expect(wifi.isFeatureSupported(result)).assertTrue(); + done(); }) - /** + /** * @tc.number SUB_Communication_WiFi_Sta_info_0005 * @tc.name testHotspotDualBandSupported * @tc.desc Test HotspotDualBandSupported api. @@ -779,6 +721,8 @@ describe('ACTS_WifiTest', function() { */ it('SUB_Communication_WiFi_Sta_Info_0005', 0, async function(done) { console.info(" [wifi_test] isHotspotDualBandSupported start ... "); + await tryToEnableWifi(); + expect(wifi.isWifiActive()).assertTrue(); var DualBand = wifi.isHotspotDualBandSupported(); console.info("[wifi_test] isHotspotDualBandSupported -> " + JSON.stringify(DualBand)); expect(DualBand).assertFalse(); @@ -792,43 +736,28 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test reconnect wifi */ 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] wifi connectToDevice test."); + await tryToEnableWifi(); var wifiDeviceConfigConn = { - "ssid": "TESTCONN", - "bssid": "", - "preSharedKey": "12345678", - "isHiddenSsid": false, - "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, - "netId": -1, - "ipType": 1, - "creatorUid": 7, - "disableReason": 0, - "randomMacType": 0, - "randomMacAddr": "11:22:33:44:55:66", - "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, + "ssid": "TESTCONN", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "netId": -1, + "ipType": 1, + "creatorUid": 7, + "disableReason": 0, + "randomMacType": 0, + "randomMacAddr": "11:22:33:44:55:66", + "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, }; - var active = wifi.isWifiActive(); - console.log("[wifi_test] wifi active result2: " + active); - if(!active){ - var enable = wifi.enableWifi(); - expect(enable).assertTrue(); - await sleep(3000); - } + expect(wifi.isWifiActive()).assertTrue(); var result1 = wifi.connectToDevice(wifiDeviceConfigConn); - console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); - var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); - expect(isConnected).assertFalse(); - console.info("[wifi_test] reconnect wifi"); - var reconn= wifi.reconnect(); - console.log("[wifi_test] wifi reconnect result: " + reconn); - expect(reconn).assertTrue(); - console.info("[wifi_test] remove config"); + console.info("[wifi_test]isConnected : " + wifi.isConnected()); + expect(wifi.isConnected()).assertFalse(); + expect(wifi.reconnect()).assertTrue(); var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); @@ -843,42 +772,42 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test getLinkedInfo information */ 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] Wifi get link infos test[1]."); + await tryToEnableWifi(); await wifi.getLinkedInfo() .then((result) => { console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result)); expect(JSON.stringify(result)).assertContain('band'); - console.info("[wifi_js] get wifi link [promise]."); done(); }).catch((error) => { console.info("[wifi_test] promise then error." + JSON.stringify(error)); expect().assertFail(); }); + }) + + /** + * @tc.number conn_Config_0003 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 + * @tc.desc Test getLinkedInfo callback information + */ + it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function(done) { + await tryToEnableWifi(); await wifi.getLinkedInfo( (err,result) => { if(err) { console.log("[wifi_test] wifi getLinkedInfo failed " + err); } var clen = Object.keys(result).length; - console.log("[wifi_test] wifi getLinkedInfo callback result length: " + clen); expect(clen).assertLarger(0); console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result)); - console.info("ssid: " + result.ssid); - console.info("bssid: " + result.bssid); - console.info("band: " + result.band); - console.info("isHidden: " + result.isHidden); - console.info("isRestricted: " + result.isRestricted); - console.info("chload: " + result.chload); - console.info("rssi " + result.rssi); - console.info("netWorkId: " + result.netWorkId); - console.info("linkSpeed: " + result.linkSpeed); - console.info("frequency: " + result.frequency); - console.info("snr: " + result.snr); - console.info("macAddress: " + result.macAddress); - console.info("ipAddress: " + result.ipAddress); - console.info("suppState: " + result.suppState); - console.info("connState: " + result.connState); + console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+ + "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted + + "chload: " + result.chload + "rssi " + result.rssi + "netWorkId: " + result.netWorkId+ + "linkSpeed: " + result.linkSpeed + "frequency:" + + result.frequency +"snr:" + result.snr+ + "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress + + "suppState: " + result.suppState + "connState: " + result.connState); + expect(true).assertEqual(result.connState==ConnState.CONNECTING); + expect(false).assertEqual(result.suppState==suppState.DISCONNECTED); done(); }); await sleep(2000); @@ -890,8 +819,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 10 bits WEP Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0001', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0001]"); - console.info("[wifi_test] create WEP SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST10", "bssid": "", @@ -909,9 +837,7 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfig1); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -919,14 +845,48 @@ describe('ACTS_WifiTest', function() { done() }) - /** + /** + * @tc.number Conn_Security_0002 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0002 + * @tc.desc Test disconnect Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0002', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TESTDIS", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "netId": -1, + "ipType": 1, + "creatorUid": 7, + "disableReason": 0, + "randomMacType": 0, + "randomMacAddr": "11:22:33:44:55:66", + "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, + }; + var result1 = wifi.connectToDevice(wifiDeviceConfig1); + console.log("[wifi_test] wifi connectToDevice result: " + result1); + expect(result1).assertTrue(); + + var isConnected= wifi.isConnected(); + expect(isConnected).assertFalse(); + + expect(wifi.disconnect()).assertTrue(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** * @tc.number Conn_Security_0003 * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0003 * @tc.desc Test connectToDevice 26 bits WEP Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0003', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0003]"); - console.info("[wifi_test] create WEP SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST26", "bssid": "", @@ -944,9 +904,8 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfig1); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -960,8 +919,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 5bits ASCLL WEP Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0005', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0005]"); - console.info("[wifi_test] create WEP SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST5", "bssid": "", @@ -979,9 +937,8 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfig1); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -995,8 +952,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 13bits ASCLL WEP Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0007', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0007]"); - console.info("[wifi_test] create WEP SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST7", "bssid": "", @@ -1016,7 +972,6 @@ describe('ACTS_WifiTest', function() { expect(result1).assertTrue(); console.info("[wifi_test] check isconnected wifi"); var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -1030,8 +985,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0013', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0013]"); - console.info("[wifi_test] create 63bits PSK SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST13", "bssid": "", @@ -1049,9 +1003,8 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfig1); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -1065,8 +1018,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 8bits ASCLL PSK Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0014', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0014]"); - console.info("[wifi_test] create 8bits PSK SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST13", "bssid": "", @@ -1084,9 +1036,8 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfig1); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -1100,8 +1051,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig */ it('SUB_Communication_WiFi_Sta_Conn_Security_0015', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Conn_Security_0015]"); - console.info("[wifi_test] create 63bits PSK SecurityType wifi device config start."); + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TEST13", "bssid": "", @@ -1121,7 +1071,6 @@ describe('ACTS_WifiTest', function() { expect(result1).assertTrue(); console.info("[wifi_test] check isconnected wifi"); var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); var isRemoved = wifi.removeAllNetwork(); console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); @@ -1135,7 +1084,7 @@ describe('ACTS_WifiTest', function() { * @tc.desc Test get IpInfo information */ it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function (done) { - console.info("[wifi_test] wifi connectToDevice test."); + await tryToEnableWifi(); var wifiDeviceConfigIp = { "ssid": "TEST1", "bssid": "", @@ -1153,28 +1102,22 @@ describe('ACTS_WifiTest', function() { var result1 = wifi.connectToDevice(wifiDeviceConfigIp); console.log("[wifi_test] wifi connectToDevice result: " + result1); expect(result1).assertTrue(); - console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); - console.log("[wifi_test] wifi isConnected result: " + isConnected); expect(isConnected).assertFalse(); - console.info("[wifi_test] reassociate wifi"); + var reass= wifi.reassociate(); - console.log("[wifi_test] wifi reassociate result: " + reass); expect(reass).assertTrue(); - console.info("[wifi_test] get IpInfo."); + var ipInfo = wifi.getIpInfo(); - console.info("[wifi_test] getIpInfo -> " + JSON.stringify(ipInfo)); expect(JSON.stringify(ipInfo)).assertContain("gateway"); - console.info("gateway: " + ipInfo.gateway); - console.info("ipAddress: " + ipInfo.ipAddress); - console.info("leaseDuration: " + ipInfo.leaseDuration); - console.info("netmask: " + ipInfo.netmask); - console.info("primaryDns: " + ipInfo.primaryDns); - console.info("secondDns: " + ipInfo.secondDns); - console.info("serverIp: " + ipInfo.serverIp); - console.info("[wifi_test] remove config"); + 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 ); + var isRemoved = wifi.removeAllNetwork(); - console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); expect(isRemoved).assertTrue(); var configs = wifi.getDeviceConfigs(); console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs)); @@ -1185,32 +1128,26 @@ describe('ACTS_WifiTest', function() { /** * @tc.number wifiStateChange_0001 * @tc.name SUB_Communication_WiFi_Sta_wifiStateChange_0001 - * @tc.author wudangping wwx1075776 * @tc.desc Test wifiStateChange callback */ it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) { - console.info('[wifi_test] OnWifiStateChange test start ...'); - + await tryToEnableWifi(); wifi.on('wifiStateChange', async result => { console.info("wifiStateChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); let promise = new Promise((resolve) => { - console.info('[wifi_test] offwifiStateChange test start ...'); wifi.off('wifiStateChange', result => { - console.info("offwifiStateChange callback, result: " + JSON.stringify(result)); + console.info("offwifiStateChange callback, result: " + JSON.stringify(result)); expect(true).assertEqual(result !=null); resolve() }); }) await promise.then(done) }); - var disable = wifi.disableWifi() await sleep(5000); - console.log("[wifi_test] wifi close result: " + disable); var enable = wifi.enableWifi(); await sleep(5000); - console.log("[wifi_test] wifi open result: " + enable); console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); done(); @@ -1219,16 +1156,14 @@ describe('ACTS_WifiTest', function() { /** * @tc.number wifiConnectionChange_0002 * @tc.name SUB_Communication_WiFi_Sta_wifiConnectionChange_0002 - * @tc.author wudangping wwx1075776 * @tc.desc Test wifiStateChange callback */ it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) { - console.info('[wifi_test] OnWifiStateChange test start ...'); - + await tryToEnableWifi(); 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("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)); @@ -1236,7 +1171,7 @@ describe('ACTS_WifiTest', function() { resolve() }); }) - await promise.then(done) + await promise.then(done) }); done(); @@ -1245,12 +1180,10 @@ describe('ACTS_WifiTest', function() { /** * @tc.number wifiScanStateChange_0003 * @tc.name SUB_Communication_WiFi_Sta_wifiScanStateChange_0003 - * @tc.author wudangping wwx1075776 * @tc.desc Test wifiScanStateChange callback */ it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) { - console.info('[wifi_test] OnwifiScanStateChange test start ...'); - + await tryToEnableWifi(); wifi.on('wifiScanStateChange', async result => { console.info("wifiScanStateChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -1266,7 +1199,6 @@ describe('ACTS_WifiTest', function() { }); var scan = wifi.scan(); await sleep(3000); - console.log("[wifi_test] open wifi scan result: " + scan); done(); }) @@ -1274,12 +1206,10 @@ describe('ACTS_WifiTest', function() { /** * @tc.number wifiRssiChange_0004 * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0004 - * @tc.author wudangping wwx1075776 * @tc.desc Test wifiRssiChange callback */ it('SUB_Communication_WiFi_Sta_wifiRssiChange_0004', 0, async function (done) { - console.info('[wifi_test] OnwifiRssiChange test start ...'); - + await tryToEnableWifi(); wifi.on('wifiRssiChange', async result => { console.info("wifiRssiChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); @@ -1300,11 +1230,10 @@ describe('ACTS_WifiTest', function() { /** * @tc.number streamChange_0005 * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0005 - * @tc.author wudangping wwx1075776 * @tc.desc Test streamChange callback */ it('SUB_Communication_WiFi_Sta_streamChange_0005', 0, async function (done) { - console.info('[wifi_test] OnstreamChange test start ...'); + await tryToEnableWifi(); wifi.on('streamChange', async result => { console.info("streamChange callback, result:" + JSON.stringify(result)); @@ -1325,6 +1254,3 @@ describe('ACTS_WifiTest', function() { console.log("*************[wifi_test] start wifi js unit test end*************"); }) - - -