提交 bee291f6 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 101bc10a
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
//require('./WifiSta.test.js') import actsWifiTestNew from './WifiP2P.testsame.js'
//require('./WifiSoftAP.test.js') import actsWifiTest from './WifiP2P.test2.js'
import ActsWifiTest from './WifiP2P.test.js'
export default function testsuite() { export default function testsuite() {
ActsWifiTest() actsWifiTestNew()
actsWifiTest()
} }
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
export default function actsWifiTestNew() {
describe('actsWifiTestNew', function () {
beforeEach(function () {
checkWifiPowerOn();
})
afterEach(function () {
})
/**
* @tc.number P2P_0009
* @tc.name SUB_Communication_WiFi_XTS_P2P_0009
* @since 8
* @tc.desc Test p2pCancelConnect Group API functionality.
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) {
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : 0
};
let addConfig = wifi.createGroup(WifiP2PConfig);
console.info("[wifi_test] test p2pConnect result." + addConfig);
let disConn = wifi.p2pCancelConnect();
sleep(2000);
console.info("[wifi_test] test p2pCancelConnect result." + disConn);
expect(disConn).assertTrue();
let removeConfig = wifi.removeGroup();
console.info("[wifi_test] test start removeGroup" + removeConfig);
expect(removeConfig).assertTrue();
done();
})
/**
* @tc.number P2P_0011
* @tc.name SUB_Communication_WiFi_XTS_P2P_0011
* @since 8
* @tc.desc Test remove error Group functionality.
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) {
let isRemoved = wifi.removeGroup(10000);
console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved));
expect(isRemoved).assertTrue();
done();
})
})
}
...@@ -17,7 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -17,7 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
function sleep(delay) { function sleep(delay) { // delay x ms
var start = (new Date()).getTime(); var start = (new Date()).getTime();
while ((new Date()).getTime() - start > delay) { while ((new Date()).getTime() - start > delay) {
break; break;
...@@ -25,7 +25,7 @@ function sleep(delay) { ...@@ -25,7 +25,7 @@ function sleep(delay) {
} }
function checkWifiPowerOn(){ function checkWifiPowerOn(){
console.info("Wifi_test/wifi status:" + wifi.isWifiActive()); console.info("wifi_test/wifi status:" + wifi.isWifiActive());
} }
let GroupOwnerBand = { let GroupOwnerBand = {
...@@ -33,21 +33,24 @@ let GroupOwnerBand = { ...@@ -33,21 +33,24 @@ let GroupOwnerBand = {
GO_BAND_2GHZ : 1, GO_BAND_2GHZ : 1,
GO_BAND_5GHZ : 2, GO_BAND_5GHZ : 2,
} }
export default function ActsWifiTest() {
describe('ActsWifiTest', function () { export default function actsWifiTest() {
describe('actsWifiTest', function () {
beforeEach(function () { beforeEach(function () {
console.info("beforeEach start"); console.info("beforeEach start" );
checkWifiPowerOn(); checkWifiPowerOn();
}) })
afterEach(async function () { afterEach(async function () {
console.info("afterEach start"); console.info("afterEach start" );
}) })
/** /**
* @tc.number config_0001 * @tc.number P2P_Config_0001
* @tc.name SUB_Communication_WiFi_P2P_Config_0001 * @tc.name SUB_Communication_WiFi_P2P_Config_0001
* @tc.desc Test createGroup and getCurrentGroup promise infos * @tc.desc Test createGroup and getCurrentGroup promise infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) {
let WifiP2PConfig = { let WifiP2PConfig = {
...@@ -57,11 +60,10 @@ describe('ActsWifiTest', function () { ...@@ -57,11 +60,10 @@ describe('ActsWifiTest', function () {
groupName : "AAAZZZ123", groupName : "AAAZZZ123",
goBand : 0 goBand : 0
}; };
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()).assertTrue();
let addConfig = wifi.createGroup(WifiP2PConfig); let addConfig = wifi.createGroup(WifiP2PConfig);
console.info("[wifi_test] test createGroup end."+ addConfig); console.info("[wifi_test] test createGroup end." + addConfig);
sleep(2000); sleep(2000);
expect(addConfig).assertTrue(); expect(addConfig).assertTrue();
wifi.getCurrentGroup() wifi.getCurrentGroup()
...@@ -76,9 +78,12 @@ describe('ActsWifiTest', function () { ...@@ -76,9 +78,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0002 * @tc.number P2P_Config_0002
* @tc.name SUB_Communication_WiFi_P2P_Config_0002 * @tc.name SUB_Communication_WiFi_P2P_Config_0002
* @tc.desc Test getCurrentGroup callback infos * @tc.desc Test getCurrentGroup callback infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_Config_0002', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0002', 0, async function(done) {
let WifiP2PConfig = { let WifiP2PConfig = {
...@@ -93,17 +98,25 @@ describe('ActsWifiTest', function () { ...@@ -93,17 +98,25 @@ describe('ActsWifiTest', function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
let addConfig = wifi.createGroup(WifiP2PConfig); let addConfig = wifi.createGroup(WifiP2PConfig);
sleep(2000); sleep(2000);
console.log("[wifi_test] check the state of wifi:" + addConfig); console.log("[wifi_test] check the state of wifi: " + addConfig);
expect(addConfig).assertTrue(); expect(addConfig).assertTrue();
wifi.getCurrentGroup( wifi.getCurrentGroup(
(err, result) => { (err, result) => {
if (err) { if (err) {
console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err));
expect().assertFail(); expect().assertFail();
return;
}else{ }else{
console.info("[wifi_test] getCurrentGroup [callback] -> " + JSON.stringify(result)); console.info("[wifi_test] getCurrentGroup [callback] -> " + JSON.stringify(result));
// 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);
let removeConfig = wifi.removeGroup(); let removeConfig = wifi.removeGroup();
expect(removeConfig).assertTrue(); expect(removeConfig).assertTrue();
} }
...@@ -112,9 +125,12 @@ describe('ActsWifiTest', function () { ...@@ -112,9 +125,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0003 * @tc.number P2P_Config_0003
* @tc.name SUB_Communication_WiFi_P2P_Config_0003 * @tc.name SUB_Communication_WiFi_P2P_Config_0003
* @tc.desc Test createGroup 2.4G band and getCurrentGroup infos * @tc.desc Test createGroup 2.4G band and getCurrentGroup infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) {
let WifiP2PConfig2 = { let WifiP2PConfig2 = {
...@@ -124,7 +140,6 @@ describe('ActsWifiTest', function () { ...@@ -124,7 +140,6 @@ describe('ActsWifiTest', function () {
groupName : "AAAZZZ123", groupName : "AAAZZZ123",
goBand : 1 goBand : 1
}; };
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()).assertTrue();
let addConfig = wifi.createGroup(WifiP2PConfig2); let addConfig = wifi.createGroup(WifiP2PConfig2);
...@@ -143,9 +158,12 @@ describe('ActsWifiTest', function () { ...@@ -143,9 +158,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0004 * @tc.number P2P_Config_0004
* @tc.name SUB_Communication_WiFi_P2P_Config_0004 * @tc.name SUB_Communication_WiFi_P2P_Config_0004
* @tc.desc Test create PersistentGroup infos * @tc.desc Test create PersistentGroup infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) {
let WifiP2PConfig = { let WifiP2PConfig = {
...@@ -155,7 +173,6 @@ describe('ActsWifiTest', function () { ...@@ -155,7 +173,6 @@ describe('ActsWifiTest', function () {
groupName : "AAAZZZ123", groupName : "AAAZZZ123",
goBand : 0 goBand : 0
}; };
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()).assertTrue();
let addConfig = wifi.createGroup(WifiP2PConfig); let addConfig = wifi.createGroup(WifiP2PConfig);
...@@ -167,7 +184,6 @@ describe('ActsWifiTest', function () { ...@@ -167,7 +184,6 @@ describe('ActsWifiTest', function () {
let resultLength = Object.keys(data).length; let resultLength = Object.keys(data).length;
console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0); expect(true).assertEqual(resultLength!=0);
let removeConfig = wifi.removeGroup(); let removeConfig = wifi.removeGroup();
expect(removeConfig).assertTrue(); expect(removeConfig).assertTrue();
}); });
...@@ -175,9 +191,12 @@ describe('ActsWifiTest', function () { ...@@ -175,9 +191,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0005 * @tc.number P2P_Config_0005
* @tc.name SUB_Communication_WiFi_P2P_Config_0005 * @tc.name SUB_Communication_WiFi_P2P_Config_0005
* @tc.desc Test p2pConnect infos * @tc.desc Test p2pConnect infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) {
let WifiP2PConfig3 = { let WifiP2PConfig3 = {
...@@ -187,7 +206,6 @@ describe('ActsWifiTest', function () { ...@@ -187,7 +206,6 @@ describe('ActsWifiTest', function () {
groupName : "AAAZZZ", groupName : "AAAZZZ",
goBand : 2 goBand : 2
}; };
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()).assertTrue();
let scanConfig = wifi.startDiscoverDevices(); let scanConfig = wifi.startDiscoverDevices();
...@@ -203,9 +221,12 @@ describe('ActsWifiTest', function () { ...@@ -203,9 +221,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0006 * @tc.number P2P_Config_0006
* @tc.name SUB_Communication_WiFi_P2P_Config_0006 * @tc.name SUB_Communication_WiFi_P2P_Config_0006
* @tc.desc Test getP2pLinkedInfo promise infos * @tc.desc Test getP2pLinkedInfo promise infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) {
await wifi.getP2pLinkedInfo() await wifi.getP2pLinkedInfo()
...@@ -215,21 +236,21 @@ describe('ActsWifiTest', function () { ...@@ -215,21 +236,21 @@ describe('ActsWifiTest', function () {
expect(true).assertEqual(resultLength!=0); expect(true).assertEqual(resultLength!=0);
done() done()
}); });
done();
}) })
/** /**
* @tc.number config_0007 * @tc.number P2P_Config_0007
* @tc.name SUB_Communication_WiFi_P2P_Config_0007 * @tc.name SUB_Communication_WiFi_P2P_Config_0007
* @tc.desc Test getP2pLinkedInfo callback infos * @tc.desc Test getP2pLinkedInfo callback infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) {
let P2pConnectState = { let P2pConnectState = {
DISCONNECTED :0, DISCONNECTED :0,
CONNECTED : 1, CONNECTED : 1,
}; };
wifi.getP2pLinkedInfo((err, result) => { wifi.getP2pLinkedInfo((err, result) => {
if (err) { if (err) {
console.error('failed to getP2pLinkedInfo callback ' + JSON.stringify(err)); console.error('failed to getP2pLinkedInfo callback ' + JSON.stringify(err));
...@@ -243,12 +264,16 @@ describe('ActsWifiTest', function () { ...@@ -243,12 +264,16 @@ describe('ActsWifiTest', function () {
} }
done(); done();
}); });
}) })
/** /**
* @tc.number config_0008 * @tc.number P2P_Config_0008
* @tc.name SUB_Communication_WiFi_P2P_Config_0008 * @tc.name SUB_Communication_WiFi_P2P_Config_0008
* @tc.desc Test p2pCancelConnect infos * @tc.desc Test p2pCancelConnect infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_Config_0008', 0, async function(done) { it('SUB_Communication_WiFi_P2P_Config_0008', 0, async function(done) {
let disConn = wifi.p2pCancelConnect(); let disConn = wifi.p2pCancelConnect();
...@@ -262,9 +287,12 @@ describe('ActsWifiTest', function () { ...@@ -262,9 +287,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number config_0009 * @tc.number P2P_Config_0009
* @tc.name SUB_Communication_WiFi_P2P_Config_0009 * @tc.name SUB_Communication_WiFi_P2P_Config_0009
* @tc.desc Test getP2pPeerDevices infos * @tc.desc Test getP2pPeerDevices promise infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_Config_0009', 0, async function(done){ it('SUB_Communication_WiFi_P2P_Config_0009', 0, async function(done){
console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
...@@ -282,13 +310,15 @@ describe('ActsWifiTest', function () { ...@@ -282,13 +310,15 @@ describe('ActsWifiTest', function () {
expect().assertFail(); expect().assertFail();
}); });
done(); done();
}) })
/** /**
* @tc.number config_0010 * @tc.number P2P_Config_0010
* @tc.name SUB_Communication_WiFi_P2P_Config_0010 * @tc.name SUB_Communication_WiFi_P2P_Config_0010
* @tc.desc Test getP2pPeerDevices infos * @tc.desc Test getP2pPeerDevices callback infos
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_Config_0010', 0, async function(done){ it('SUB_Communication_WiFi_P2P_Config_0010', 0, async function(done){
let P2pDeviceStatus = { let P2pDeviceStatus = {
...@@ -298,13 +328,11 @@ describe('ActsWifiTest', function () { ...@@ -298,13 +328,11 @@ describe('ActsWifiTest', function () {
AVAILABLE : 3, AVAILABLE : 3,
UNAVAILABLE : 4, UNAVAILABLE : 4,
}; };
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()).assertTrue();
let scanConfig = wifi.startDiscoverDevices(); let scanConfig = wifi.startDiscoverDevices();
sleep(2000); sleep(2000);
expect(scanConfig).assertTrue(); expect(scanConfig).assertTrue();
await wifi.getP2pPeerDevices((err, result) => { await wifi.getP2pPeerDevices((err, result) => {
if (err) { if (err) {
console.error('failed to getP2pPeerDevices infos callback because ' + JSON.stringify(err)); console.error('failed to getP2pPeerDevices infos callback because ' + JSON.stringify(err));
...@@ -341,9 +369,12 @@ describe('ActsWifiTest', function () { ...@@ -341,9 +369,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number p2pStateChange_0001 * @tc.number P2P_P2pStateChange_0001
* @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001 * @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001
* @tc.desc Test p2pStateChange callback * @tc.desc Test p2pStateChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) { it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) {
await wifi.on('p2pStateChange', result => { await wifi.on('p2pStateChange', result => {
...@@ -352,7 +383,6 @@ describe('ActsWifiTest', function () { ...@@ -352,7 +383,6 @@ describe('ActsWifiTest', function () {
done(); done();
}); });
setTimeout(function() { setTimeout(function() {
wifi.off('p2pStateChange', result => { wifi.off('p2pStateChange', result => {
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);
...@@ -365,6 +395,9 @@ describe('ActsWifiTest', function () { ...@@ -365,6 +395,9 @@ describe('ActsWifiTest', function () {
* @tc.number p2pConnectionChange_0002 * @tc.number p2pConnectionChange_0002
* @tc.name SUB_Communication_WiFi_P2P_p2pConnectionChange_0002 * @tc.name SUB_Communication_WiFi_P2P_p2pConnectionChange_0002
* @tc.desc Test p2pConnectionChange callback * @tc.desc Test p2pConnectionChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) { it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) {
await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => {
...@@ -383,9 +416,12 @@ describe('ActsWifiTest', function () { ...@@ -383,9 +416,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number p2pDeviceChange_0003 * @tc.number P2P_p2pDeviceChange_0003
* @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003 * @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003
* @tc.desc Test p2pDeviceChange callback * @tc.desc Test p2pDeviceChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) { it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) {
console.info('[wifi_test] Onp2pDeviceChange test start ...'); console.info('[wifi_test] Onp2pDeviceChange test start ...');
...@@ -405,9 +441,12 @@ describe('ActsWifiTest', function () { ...@@ -405,9 +441,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number p2pPeerDeviceChange_0004 * @tc.number P2P_p2pPeerDeviceChange_0004
* @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004 * @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004
* @tc.desc Test p2pPeerDeviceChange callback * @tc.desc Test p2pDeviceChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/ */
it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) { it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) {
let recvP2pPeerDeviceChangeFunc = result => { let recvP2pPeerDeviceChangeFunc = result => {
...@@ -450,9 +489,12 @@ describe('ActsWifiTest', function () { ...@@ -450,9 +489,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number p2pPersistentGroupChange_0005 * @tc.number P2P_p2pPersistentGroupChange_0005
* @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005 * @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005
* @tc.desc Test p2pPersistentGroupChange callback * @tc.desc Test p2pPersistentGroupChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) { it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) {
let recvP2pPersistentGroupChangeFunc = () => { let recvP2pPersistentGroupChangeFunc = () => {
...@@ -474,7 +516,7 @@ describe('ActsWifiTest', function () { ...@@ -474,7 +516,7 @@ describe('ActsWifiTest', function () {
console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data)); console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data));
}); });
}; };
wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); wifi.on("p2pPersistentGroupChange",recvP2pPersistentGroupChangeFunc);
setTimeout(async function() { setTimeout(async function() {
wifi.off('p2pPersistentGroupChange', result => { wifi.off('p2pPersistentGroupChange', result => {
console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result));
...@@ -485,9 +527,12 @@ describe('ActsWifiTest', function () { ...@@ -485,9 +527,12 @@ describe('ActsWifiTest', function () {
}) })
/** /**
* @tc.number p2pDiscoveryChange_0006 * @tc.number P2P_p2pDiscoveryChange_0006
* @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006 * @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006
* @tc.desc Test p2pDiscoveryChange callback * @tc.desc Test p2pDiscoveryChange callback
* @since 8
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO
*/ */
it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) { it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) {
await wifi.on('p2pDiscoveryChange', result => { await wifi.on('p2pDiscoveryChange', result => {
...@@ -503,7 +548,10 @@ describe('ActsWifiTest', function () { ...@@ -503,7 +548,10 @@ describe('ActsWifiTest', function () {
}, 1 * 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*************");
}) })
} }
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
require('./WifiSta.test.js') import actsWifiTestNew from './WifiJsunit.test1.js'
//require('./WifiSoftAP.test.js') import actsWifiTest from './WifiJsunit.testsame.js'
import ActsWifiTest from './WifiSta.test.js'
export default function testsuite() { export default function testsuite() {
ActsWifiTest() actsWifiTestNew()
actsWifiTest()
} }
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
function resolveIP(ip) {
return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF);
}
let WifiSecurityType = {
WIFI_SEC_TYPE_INVALID: 0,
WIFI_SEC_TYPE_OPEN: 1,
WIFI_SEC_TYPE_WEP: 2,
WIFI_SEC_TYPE_PSK: 3,
WIFI_SEC_TYPE_SAE: 4,
}
let ConnState = {
SCANNING: 0,
CONNECTING: 1,
AUTHENTICATING: 2,
OBTAINING_IPADDR: 3,
CONNECTED: 4,
DISCONNECTING: 5,
DISCONNECTED: 6,
UNKNOWN: 7,
}
let WifiChannelWidth = {
WIDTH_20MHZ : 0,
WIDTH_40MHZ : 1,
WIDTH_80MHZ : 2,
WIDTH_160MHZ : 3,
WIDTH_80MHZ_PLUS : 4,
WIDTH_INVALID:null,
}
export default function actsWifiTestNew() {
describe('actsWifiTestNew', function () {
beforeEach(function () {
checkWifiPowerOn();
})
afterEach(function () {
})
/**
* @tc.number CandidateNetWork_0001
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0001
* @since 9
* @tc.desc Test add OPEN and WEP CandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0001', 0, async function (done) {
let wifiDeviceConfig = {
"ssid": "TEST_OPEN",
"bssid": "",
"preSharedKey": "",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_OPEN,
};
await wifi.addCandidateConfig(wifiDeviceConfig)
.then(netWorkId => {
console.info("[wifi_test]add OPEN CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId = -1);
}).catch((error) => {
console.error('[wifi_js] add OPEN CandidateConfig promise failed -> ' + JSON.stringify(error));
expect(false).assertFalse();
});
let getconfig = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get OPEN CandidateConfigs result : " + JSON.stringify(getconfig));
let wifiDeviceConfig1 = {
"ssid": "TEST_WEP",
"bssid": "",
"preSharedKey": "ABCDEF1234",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
};
await wifi.addCandidateConfig(wifiDeviceConfig1)
.then(netWorkId => {
console.info("[wifi_test]add WEP CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId = -1);
}).catch((error) => {
console.error('[wifi_js] add WEP CandidateConfig promise failed -> ' + JSON.stringify(error));
expect(false).assertFalse();
});
console.info("[wifi_test] wifi get WEP CandidateConfigs result : " + JSON.stringify(getconfig));
done();
})
/**
* @tc.number CandidateNetWork_0001
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0002
* @since 8
* @tc.desc Test add PSK CandidateConfig and removeCandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0002', 0, async function (done) {
let wifiDeviceConfig = {
"ssid": "TEST_PSK",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
"netId": "",
};
await wifi.addCandidateConfig(wifiDeviceConfig)
.then(netWorkId => {
console.info("[wifi_test]add PSK CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
}).catch((error) => {
console.error('[wifi_js] add PSK CandidateConfig promise failed -> ' + JSON.stringify(error));
expect().assertFail();
});
let getconfig = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get PSK CandidateConfigs result : " + JSON.stringify(getconfig));
expect(true).assertEqual(getconfig[0].securityType == wifiDeviceConfig.securityType);
expect(true).assertEqual(getconfig[0].isHiddenSsid == wifiDeviceConfig.isHiddenSsid);
expect(true).assertEqual(getconfig[0].ssid == wifiDeviceConfig.ssid);
var networkId = getconfig[0].netId;
console.info("[wifi_test] wifi get networkId result : " + JSON.stringify(networkId));
await wifi.removeCandidateConfig(networkId)
.then(ret => {
console.info("[wifi_test]remove CandidateConfig promise" + JSON.stringify(ret));
expect(false).assertFalse();
let getconfig1 = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig1));
console.info("[wifi_test] wifi getconfig.length result : " + JSON.stringify(getconfig1.length));
expect(true).assertEqual(getconfig1.length == 0);
}).catch((error) => {
console.error('[wifi_js] remove CandidateConfig promise failed -> ' + JSON.stringify(error));
expect().assertFail();
});
done();
})
/**
* @tc.number CandidateNetWork_0003
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0003
* @since 8
* @tc.desc Test add SAE CandidateConfig Promise API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0003', 0, async function (done) {
let wifiDeviceConfig = {
"ssid": "TEST_SAE",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_SAE,
};
await wifi.addCandidateConfig(wifiDeviceConfig)
.then(netWorkId => {
console.info("[wifi_test]add SAE CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId = -1);
}).catch((error) => {
console.error('[wifi_js] add SAE CandidateConfig promise failed -> ' + JSON.stringify(error));
});
let getconfig = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get SAE CandidateConfigs result : " + JSON.stringify(getconfig));
done();
})
/**
* @tc.number CandidateNetWork_0005
* @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0005
* @since 8
* @tc.desc Test add CandidateConfig and removeCandidateConfig callback API functionality.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0005', 0, async function (done) {
let wifiDeviceConfig = {
"ssid": "TYPE_PSK1",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
}
function addCandidate() {
return new Promise((resolve, reject) => {
wifi.addCandidateConfig(wifiDeviceConfig,
(err, netWorkId) => {
if (err) {
console.info("[wifi_test]add CandidateConfig callback failed : " + JSON.stringify(err));
return;
}
console.info("[wifi_test]addCandidateConfig callback result: " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
resolve();
});
});
}
await addCandidate();
let configs = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi getCandidateConfigs result : " + JSON.stringify(configs));
expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig.securityType);
expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig.isHiddenSsid);
expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig.ssid);
var networkId = configs[0].netId;
function removeCandidate() {
return new Promise((resolve, reject) => {
wifi.removeCandidateConfig(networkId,
(err, ret) => {
if (err) {
console.info("[wifi_test]removeCandidate callback failed : " + JSON.stringify(err));
return;
}
console.info("[wifi_test] removeCandidateConfig callback result:" + JSON.stringify(ret));
expect(ret).assertTrue();
let configs1 = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(configs1));
console.info("[wifi_test] getconfig.length result : " + JSON.stringify(configs1.length));
expect(true).assertEqual(configs1.length == 0);
resolve();
});
});
}
await removeCandidate();
done();
})
/**
* @tc.number CandidateNetWork_0006
* @tc.name SUB_Communication_WiFi_XTS_SUB_Communication_WiFi_XTS_CandidateNetWork_0006
* @tc.desc Test connect To CandidateConfig API functionality.
* @since 9
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
it('SUB_Communication_WiFi_XTS_CandidateNetWork_0006', 0, async function (done) {
let WifiSecurityType = {
WIFI_SEC_TYPE_INVALID: 0,
WIFI_SEC_TYPE_OPEN: 1,
WIFI_SEC_TYPE_WEP: 2,
WIFI_SEC_TYPE_PSK: 3,
WIFI_SEC_TYPE_SAE: 4,
}
let wifiDeviceConfig = {
"ssid": "HONOR 3000",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
};
await wifi.addCandidateConfig(wifiDeviceConfig)
.then(netWorkId => {
console.info("[wifi_test]add CandidateConfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
}).catch((error) => {
console.error('[wifi_js] add CandidateConfig promise failed -> ' + JSON.stringify(error));
expect().assertFail();
});
let getconfig = wifi.getCandidateConfigs();
console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig));
let connectToCandidate = wifi.connectToCandidateConfig(getconfig[0].netId);
console.info("[wifi_test] connect To CandidateConfig result : " + JSON.stringify(connectToCandidate));
await sleep(3000);
await wifi.getLinkedInfo()
.then((result) => {
console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result));
expect(JSON.stringify(result)).assertContain('band');
done();
}).catch((error) => {
console.info("[wifi_test] promise then error." + JSON.stringify(error));
expect().assertFail();
});
done();
})
/**
* @tc.number Sta_0002
* @tc.name SUB_Communication_WiFi_XTS_Sta_0002
* @tc.desc Test get to ScanInfos promise and callback API functionality.
* @since 6
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION)
*/
it('SUB_Communication_WiFi_XTS_Sta_0002', 0, async function (done) {
await wifi.getScanInfos()
.then(result => {
let clen = Object.keys(result).length;
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
});
function getScanInfos() {
return new Promise((resolve, reject) => {
wifi.getScanInfos(
(err, result) => {
if (err) {
console.log("[wifi_test] wifi getScanInfos failed " + err);
}
let clen = Object.keys(result).length;
if (!(clen == 0)) {
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
for (let j = 0; j < clen; ++j) {
console.info("ssid: " + result[j].ssid + "bssid: " + result[j].bssid +
"securityType: " + result[j].securityType +
"rssi: " + result[j].rssi + "band: " + result[j].band +
"frequency: " + result[j].frequency + "channelWidth: " + result[j].channelWidth +
"timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities
+ "centerFrequency0: " + result[j].centerFrequency0
+ "centerFrequency1: " + result[j].centerFrequency1
+ "infoElems: " + result[j].infoElems);
}
}
resolve();
});
});
}
await getScanInfos();
done();
})
/**
* @tc.number Sta_0034
* @tc.name SUB_Communication_WiFi_XTS_Sta_0034
* @tc.desc Test get to ScanInfos Sync API functionality.
* @since 9
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION)
*/
it('SUB_Communication_WiFi_XTS_Sta_0034', 0, async function (done) {
let getScanInfos = wifi.getScanInfosSync();
console.info("[wifi_test] wifi get to ScanInfosSync result : " + JSON.stringify(getScanInfos));
let lenth = Object.keys(getScanInfos).length;
console.info("[wifi_test] wifi ScanInfosSync length result : " + JSON.stringify(lenth));
expect(lenth).assertLarger(0);
done();
})
})
}
...@@ -13,26 +13,23 @@ ...@@ -13,26 +13,23 @@
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
function sleep(delay) { function sleep(delay) { // delay x ms
var start = (new Date()).getTime(); var start = (new Date()).getTime();
while ((new Date()).getTime() - start > delay) { while ((new Date()).getTime() - start > delay) {
break; break;
} }
} }
function checkWifiPowerOn(){ function checkWifiPowerOn(){
console.info("Wifi_test/wifi status:" + wifi.isWifiActive()); console.info("wifi_test/wifi status:" + wifi.isWifiActive());
} }
function resolveIP(ip) {
function resolve(ip) { return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF);
return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF ) + (ip>>8 & 0xFF ) + (ip & 0xFF );
} }
let WifiSecurityType = { let WifiSecurityType = {
WIFI_SEC_TYPE_INVALID: 0, WIFI_SEC_TYPE_INVALID: 0,
WIFI_SEC_TYPE_OPEN: 1, WIFI_SEC_TYPE_OPEN: 1,
...@@ -57,27 +54,25 @@ let untrustedDeviceConfig = { ...@@ -57,27 +54,25 @@ let untrustedDeviceConfig = {
"bssid": "", "bssid": "",
"preSharedKey": "12345678", "preSharedKey": "12345678",
"isHiddenSsid": false, "isHiddenSsid": false,
"securityType":WifiSecurityType.WIFI_SEC_TYPE_PSK "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK
} }
let WifiChannelWidth = { let WifiChannelWidth = {
WIDTH_20MHZ : 0, WIDTH_20MHZ : 0,
WIDTH_40MHZ : 1, WIDTH_40MHZ : 1,
WIDTH_80MHZ : 2, WIDTH_80MHZ : 2,
WIDTH_160MHZ : 3, WIDTH_160MHZ : 3,
WIDTH_280MHZ_PLUS : 4, WIDTH_80MHZ_PLUS : 4,
WIDTH_INVALID : null, WIDTH_INVALID:null,
} }
export default function ActsWifiTest() { export default function actsWifiTest() {
describe('ActsWifiTest', function() { describe('actsWifiTest', function() {
beforeEach(function() { beforeEach(function() {
checkWifiPowerOn(); checkWifiPowerOn();
}) })
afterEach(function() {
afterEach(function() {}) })
/** /**
* @tc.number open_0001 * @tc.number open_0001
...@@ -94,6 +89,7 @@ describe('ActsWifiTest', function() { ...@@ -94,6 +89,7 @@ describe('ActsWifiTest', function() {
/** /**
* @tc.number Scan_0001 * @tc.number Scan_0001
* @tc.name SUB_Communication_WiFi_Sta_Scan_0001 * @tc.name SUB_Communication_WiFi_Sta_Scan_0001
* @since 6
* @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) {
...@@ -101,14 +97,12 @@ describe('ActsWifiTest', function() { ...@@ -101,14 +97,12 @@ describe('ActsWifiTest', function() {
sleep(3000); 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();
await wifi.getScanInfos() await wifi.getScanInfos()
.then(result => { .then(result => {
let clen = Object.keys(result).length; let clen = Object.keys(result).length;
expect(clen).assertLarger(0); expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result)); console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
}); });
wifi.getScanInfos( wifi.getScanInfos(
(err,result) => { (err,result) => {
if(err) { if(err) {
...@@ -124,9 +118,10 @@ describe('ActsWifiTest', function() { ...@@ -124,9 +118,10 @@ describe('ActsWifiTest', function() {
"rssi: " + result[j].rssi + "band: " + result[j].band + "rssi: " + result[j].rssi + "band: " + result[j].band +
"frequency: " + result[j].frequency + "frequency: " + result[j].frequency +
"timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities "timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities
+ "channelWidth: " + result[j].channelWidth+"centerFrequency0"+result[j].centerFrequency0 + "channelWidth: " + result[j].channelWidth+ "centerFrequency0: "
+"centerFrequency1"+result[j].centerFrequency1+"infoElems"+result[j].infoElems + result[j].centerFrequency0
); + "centerFrequency1: " + result[j].centerFrequency1
+"infoElems: " + result[j].infoElems);
} }
} }
done() done()
...@@ -141,47 +136,46 @@ describe('ActsWifiTest', function() { ...@@ -141,47 +136,46 @@ describe('ActsWifiTest', function() {
*/ */
it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() { it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() {
console.info("[wifi_test] check the 2.4G rssi assgined to level test."); console.info("[wifi_test] check the 2.4G rssi assgined to level test.");
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-65,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 1));
expect(wifi.getSignalLevel(-65, 1)).assertEqual(4); expect(wifi.getSignalLevel(-65, 1)).assertEqual(4);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-66,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 1));
expect(wifi.getSignalLevel(-66, 1)).assertEqual(3); expect(wifi.getSignalLevel(-66, 1)).assertEqual(3);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-75,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-75, 1));
expect(wifi.getSignalLevel(-75, 1)).assertEqual(3); expect(wifi.getSignalLevel(-75, 1)).assertEqual(3);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-76,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-76, 1));
expect(wifi.getSignalLevel(-76, 1)).assertEqual(2); expect(wifi.getSignalLevel(-76, 1)).assertEqual(2);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-82,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-82, 1));
expect(wifi.getSignalLevel(-82, 1)).assertEqual(2); expect(wifi.getSignalLevel(-82, 1)).assertEqual(2);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-83,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-83, 1));
expect(wifi.getSignalLevel(-83, 1)).assertEqual(1); expect(wifi.getSignalLevel(-83, 1)).assertEqual(1);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-88,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-88, 1));
expect(wifi.getSignalLevel(-88, 1)).assertEqual(1); expect(wifi.getSignalLevel(-88, 1)).assertEqual(1);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-89,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-89, 1));
expect(wifi.getSignalLevel(-89, 1)).assertEqual(0); expect(wifi.getSignalLevel(-89, 1)).assertEqual(0);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-127,1)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 1));
expect(wifi.getSignalLevel(-127, 1)).assertEqual(0); expect(wifi.getSignalLevel(-127, 1)).assertEqual(0);
console.info("[wifi_test] check the 5G rssi assgined to level test."); console.info("[wifi_test] check the 5G rssi assgined to level test.");
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-65,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 2));
expect(wifi.getSignalLevel(-65, 2)).assertEqual(4); expect(wifi.getSignalLevel(-65, 2)).assertEqual(4);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-66,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 2));
expect(wifi.getSignalLevel(-66, 2)).assertEqual(3); expect(wifi.getSignalLevel(-66, 2)).assertEqual(3);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-72,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-72, 2));
expect(wifi.getSignalLevel(-72, 2)).assertEqual(3); expect(wifi.getSignalLevel(-72, 2)).assertEqual(3);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-73,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-73, 2));
expect(wifi.getSignalLevel(-73, 2)).assertEqual(2); expect(wifi.getSignalLevel(-73, 2)).assertEqual(2);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-79,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-79, 2));
expect(wifi.getSignalLevel(-79, 2)).assertEqual(2); expect(wifi.getSignalLevel(-79, 2)).assertEqual(2);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-80,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-80, 2));
expect(wifi.getSignalLevel(-80, 2)).assertEqual(1); expect(wifi.getSignalLevel(-80, 2)).assertEqual(1);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-85,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-85, 2));
expect(wifi.getSignalLevel(-85, 2)).assertEqual(1); expect(wifi.getSignalLevel(-85, 2)).assertEqual(1);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-86,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-86, 2));
expect(wifi.getSignalLevel(-86, 2)).assertEqual(0); expect(wifi.getSignalLevel(-86, 2)).assertEqual(0);
console.info("[wifi_test] getSignalLevel" + wifi.getSignalLevel(-127,2)); console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 2));
expect(wifi.getSignalLevel(-127, 2)).assertEqual(0); expect(wifi.getSignalLevel(-127, 2)).assertEqual(0);
}) })
/** /**
* @tc.number SUB_Communication_WiFi_Sta_info_0002 * @tc.number SUB_Communication_WiFi_Sta_info_0002
* @tc.name testgetCountryCode * @tc.name testgetCountryCode
...@@ -195,8 +189,9 @@ describe('ActsWifiTest', function() { ...@@ -195,8 +189,9 @@ describe('ActsWifiTest', function() {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
let countryCode = wifi.getCountryCode(); let countryCode = wifi.getCountryCode();
console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode)); console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode));
console.info("[wifi_test] getCountryCode.length -> " + JSON.stringify(countryCode.length)); let countrylen = countryCode.length;
expect(true).assertEqual(countryCode.length == 2); console.info("[wifi_test] getCountryCode.length -> " + JSON.stringify(countrylen));
expect(true).assertEqual(countrylen ==2);
}) })
/** /**
...@@ -208,7 +203,6 @@ describe('ActsWifiTest', function() { ...@@ -208,7 +203,6 @@ describe('ActsWifiTest', function() {
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_Communication_WiFi_Sta_info_0004', 0, function () { it('SUB_Communication_WiFi_Sta_info_0004', 0, function () {
expect(wifi.isWifiActive()).assertTrue(); expect(wifi.isWifiActive()).assertTrue();
let WifiUtils = { let WifiUtils = {
...@@ -252,7 +246,7 @@ describe('ActsWifiTest', function() { ...@@ -252,7 +246,7 @@ describe('ActsWifiTest', function() {
* @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) {
let isConnected = wifi.isConnected(); let isConnected= wifi.isConnected();
expect(isConnected).assertFalse(); expect(isConnected).assertFalse();
await wifi.getLinkedInfo() await wifi.getLinkedInfo()
.then((result) => { .then((result) => {
...@@ -282,12 +276,12 @@ describe('ActsWifiTest', function() { ...@@ -282,12 +276,12 @@ describe('ActsWifiTest', function() {
console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result)); console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result));
console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+ console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+
"isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted + "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted +
"chload: " + result.chload + "rssi " + result.rssi + "netWorkId" + result.netWorkId + "chload: " + result.chload + "rssi " + result.rssi + "netWorkId: " + result.netWorkId+
"linkSpeed: " + result.linkSpeed + "frequency:" "linkSpeed: " + result.linkSpeed + "frequency:"
+ result.frequency + "snr:" +result.snr + + result.frequency +"snr:" + result.snr+
"macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress + "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress +
"suppState" + result.suppState +"connState: " + result.connState+ "suppState: " + result.suppState + "connState: " + result.connState
"macType: " + result.macType); + "macType: " + result.macType);
let state = wifi.getLinkedInfo().connState; let state = wifi.getLinkedInfo().connState;
if(state == ConnState.SCANNING){ if(state == ConnState.SCANNING){
...@@ -319,12 +313,12 @@ describe('ActsWifiTest', function() { ...@@ -319,12 +313,12 @@ describe('ActsWifiTest', function() {
}) })
/** /**
* @tc.number Conn_Info_0001 * @tc.number Conn_Info_0003
* @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003
* @since 7 * @since 7
* @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_0001', 0, function () {
let isConnected= wifi.isConnected(); let isConnected= wifi.isConnected();
expect(isConnected).assertFalse(); expect(isConnected).assertFalse();
let ipInfo = wifi.getIpInfo(); let ipInfo = wifi.getIpInfo();
...@@ -358,6 +352,7 @@ describe('ActsWifiTest', function() { ...@@ -358,6 +352,7 @@ describe('ActsWifiTest', function() {
await promise.then(done) await promise.then(done)
}); });
done(); done();
}) })
/** /**
...@@ -381,6 +376,7 @@ describe('ActsWifiTest', function() { ...@@ -381,6 +376,7 @@ describe('ActsWifiTest', function() {
await promise.then(done) await promise.then(done)
}); });
done(); done();
}) })
/** /**
...@@ -430,14 +426,13 @@ describe('ActsWifiTest', function() { ...@@ -430,14 +426,13 @@ describe('ActsWifiTest', function() {
await promise.then(done) await promise.then(done)
}); });
done(); done();
}) })
/** /**
* @tc.number SUB_Communication_WiFi_Hotspot_ON_0001 * @tc.number SUB_Communication_WiFi_Hotspot_ON_0001
* @tc.name testhotspotStateChangeOn * @tc.name testhotspotStateChangeOn
* @tc.desc Test hotspotStateChangeOn api.
* @since 7 * @since 7
* @tc.desc Test hotspotStateChangeOn api.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
...@@ -459,20 +454,19 @@ describe('ActsWifiTest', function() { ...@@ -459,20 +454,19 @@ describe('ActsWifiTest', function() {
/** /**
* @tc.number SUB_Communication_WiFi_Hotspot_Off_0002 * @tc.number SUB_Communication_WiFi_Hotspot_Off_0002
* @tc.name testhotspotStateChangeOff * @tc.name testhotspotStateChangeOff
* @tc.desc Test hotspotStateChange api.
* @since 7 * @since 7
* @tc.desc Test hotspotStateChange api.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_Communication_WiFi_Hotspot_Off_0002', 0, async function (done) { it('SUB_Communication_WiFi_Hotspot_Off_0002', 0, async function (done) {
console.info("[wifi_test]hotspotStateChange Off test");
try { try {
await 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");
}); });
}catch(e) { }catch(e) {
expect(null).assertFail(); expect(null).assertFail();
} }
...@@ -482,3 +476,4 @@ describe('ActsWifiTest', function() { ...@@ -482,3 +476,4 @@ describe('ActsWifiTest', function() {
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册