From 1122d90319852ea2933c5ffe720990ef2b1fd7d9 Mon Sep 17 00:00:00 2001 From: q00313334 Date: Fri, 25 Feb 2022 00:58:59 +0800 Subject: [PATCH] 3516quanli1@huawei.com Signed-off-by: q00313334 --- communication/BUILD.gn | 15 +- communication/wifi_hotspot/BUILD.gn | 31 + communication/wifi_hotspot/Test.json | 18 + .../wifi_hotspot/signature/openharmony_sx.p7b | Bin 0 -> 3443 bytes .../wifi_hotspot/src/main/config.json | 99 ++ .../wifi_hotspot/src/main/js/default/app.js | 23 + .../src/main/js/default/i18n/en-US.json | 6 + .../src/main/js/default/i18n/zh-CN.json | 6 + .../src/main/js/default/pages/index/index.css | 25 + .../src/main/js/default/pages/index/index.hml | 21 + .../src/main/js/default/pages/index/index.js | 49 + .../src/main/js/default/test/List.test.js | 18 + .../main/js/default/test/WifiSoftAP.test.js | 702 +++++++++++ .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes communication/wifi_p2p/BUILD.gn | 31 + communication/wifi_p2p/Test.json | 18 + .../wifi_p2p/signature/openharmony_sx.p7b | Bin 0 -> 3443 bytes communication/wifi_p2p/src/main/config.json | 99 ++ .../wifi_p2p/src/main/js/default/app.js | 23 + .../src/main/js/default/i18n/en-US.json | 6 + .../src/main/js/default/i18n/zh-CN.json | 6 + .../src/main/js/default/pages/index/index.css | 25 + .../src/main/js/default/pages/index/index.hml | 21 + .../src/main/js/default/pages/index/index.js | 50 + .../src/main/js/default/test/List.test.js | 19 + .../src/main/js/default/test/WifiP2P.test.js | 565 +++++++++ .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes communication/wifi_standard/BUILD.gn | 4 +- .../signature/openharmony_sx.p7b | Bin 3437 -> 3443 bytes .../wifi_standard/src/main/config.json | 41 +- .../wifi_standard/src/main/js/default/app.js | 2 +- .../src/main/js/default/pages/index/index.css | 15 + .../src/main/js/default/pages/index/index.hml | 16 + .../src/main/js/default/pages/index/index.js | 21 +- .../src/main/js/default/test/List.test.js | 7 +- .../src/main/js/default/test/WifiSta.test.js | 1050 +++++++++++++++-- 38 files changed, 2947 insertions(+), 109 deletions(-) create mode 100755 communication/wifi_hotspot/BUILD.gn create mode 100755 communication/wifi_hotspot/Test.json create mode 100755 communication/wifi_hotspot/signature/openharmony_sx.p7b create mode 100755 communication/wifi_hotspot/src/main/config.json create mode 100644 communication/wifi_hotspot/src/main/js/default/app.js create mode 100644 communication/wifi_hotspot/src/main/js/default/i18n/en-US.json create mode 100644 communication/wifi_hotspot/src/main/js/default/i18n/zh-CN.json create mode 100644 communication/wifi_hotspot/src/main/js/default/pages/index/index.css create mode 100644 communication/wifi_hotspot/src/main/js/default/pages/index/index.hml create mode 100755 communication/wifi_hotspot/src/main/js/default/pages/index/index.js create mode 100755 communication/wifi_hotspot/src/main/js/default/test/List.test.js create mode 100755 communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js create mode 100755 communication/wifi_hotspot/src/main/resources/base/element/string.json create mode 100644 communication/wifi_hotspot/src/main/resources/base/media/icon.png create mode 100755 communication/wifi_p2p/BUILD.gn create mode 100755 communication/wifi_p2p/Test.json create mode 100755 communication/wifi_p2p/signature/openharmony_sx.p7b create mode 100755 communication/wifi_p2p/src/main/config.json create mode 100644 communication/wifi_p2p/src/main/js/default/app.js create mode 100644 communication/wifi_p2p/src/main/js/default/i18n/en-US.json create mode 100644 communication/wifi_p2p/src/main/js/default/i18n/zh-CN.json create mode 100644 communication/wifi_p2p/src/main/js/default/pages/index/index.css create mode 100644 communication/wifi_p2p/src/main/js/default/pages/index/index.hml create mode 100755 communication/wifi_p2p/src/main/js/default/pages/index/index.js create mode 100755 communication/wifi_p2p/src/main/js/default/test/List.test.js create mode 100644 communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js create mode 100755 communication/wifi_p2p/src/main/resources/base/element/string.json create mode 100644 communication/wifi_p2p/src/main/resources/base/media/icon.png mode change 100755 => 100644 communication/wifi_standard/src/main/js/default/app.js diff --git a/communication/BUILD.gn b/communication/BUILD.gn index 7676dd882..a585b4a86 100755 --- a/communication/BUILD.gn +++ b/communication/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# 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 @@ -15,8 +15,17 @@ import("//build/ohos_var.gni") group("communication") { testonly = true if (is_standard_system) { - deps = [ "wifi_standard:wifi_standard_test" ] + deps = [ + # "bluetooth_ble:ActsBluetoothBleJsTest", + # "bluetooth_on:ActsBluetoothOnJsTest", + # "bluetooth_standard:ActsBluetoothJsTest", + # "dsoftbus/rpc:ActsRpcJsTest", + "wifi_hotspot:ActsHotSpotJSTest", + "wifi_p2p:ActsP2PJSTest", + "wifi_standard:ActsWifiJSTest", + ] } else { - deps = [ "wifi_standard:wifi_standard_test" ] + deps = [ "wifi_standard:ActsWifiJSTest" ] } } + diff --git a/communication/wifi_hotspot/BUILD.gn b/communication/wifi_hotspot/BUILD.gn new file mode 100755 index 000000000..1780dd415 --- /dev/null +++ b/communication/wifi_hotspot/BUILD.gn @@ -0,0 +1,31 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsHotSpotJSTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":wifi_js_assets", + ":wifi_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsHotSpotJSApiTest" +} +ohos_js_assets("wifi_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("wifi_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/communication/wifi_hotspot/Test.json b/communication/wifi_hotspot/Test.json new file mode 100755 index 000000000..857d50b5e --- /dev/null +++ b/communication/wifi_hotspot/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for wifi js api Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "600000", + "package": "ohos.acts.communication.wifi.wifidevice", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "ActsHotSpotJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/communication/wifi_hotspot/signature/openharmony_sx.p7b b/communication/wifi_hotspot/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 GIT binary patch literal 3443 zcmcgvYj6|S8MPj^V?bbHu)zUrguxV$eOH!j$tfhe(&~j*^2(BJ8Bw#6Ru5a+m8F$e z7KKoe&=>-grhpq>=4Bu;(DE|wG>}Juk_0FTWjZM)HPlI=G?d~bG!)vE?SRd|k4|RL z5AA&4J@@X}@1F16xgaj0Q_^NE(=Gc(#7pJ3#zhN2Tx93-c#sGTPf1&_OvfVyLOu_~ zlSe%S@>=7`Ny51BKMTc;WGL*TDT$MIk>XNl)`J8^1h|A4DgXsQJWCvj_*`5l2htLU zQb|hWZthQ3EO$wia-fh9N)kXtGPj$A6damq3MM9pNIyx0NiIPIgA$i7%!GW72$Oi< z0D=zJ`Y49^Lr|^Wn5#m~7QIHVf-PuY)=pu1y$Xw|RIr2ez^opDJ$jTdsS0Ci7(+as25)_x zsT{}EFl&V|Ef!V9U<2YYRwA&?0@oW&+zMu#MLjlkC63QUS*F~nt&CJ?HBF8xWrVb# zH5lU5!jKhJMKRn`g!moxUavC%H9DwzPo=ifYo{C*v<_3DeJD7J5s#wqYJ_!Y{dKl# zbI>7`d2oQTI#itWjMb#pQF0&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t@0PS + + {{ $t('strings.hello') }} {{ title }} + + diff --git a/communication/wifi_hotspot/src/main/js/default/pages/index/index.js b/communication/wifi_hotspot/src/main/js/default/pages/index/index.js new file mode 100755 index 000000000..696aad4cf --- /dev/null +++ b/communication/wifi_hotspot/src/main/js/default/pages/index/index.js @@ -0,0 +1,49 @@ +/* + * 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 {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: '', + myTimeout: 15000 + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + console.info('onReady finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + this.timeout = this.myTimeout + configService.setConfig(this) + + require('../../test/List.test') + core.execute() + + }, +} + diff --git a/communication/wifi_hotspot/src/main/js/default/test/List.test.js b/communication/wifi_hotspot/src/main/js/default/test/List.test.js new file mode 100755 index 000000000..c82020ceb --- /dev/null +++ b/communication/wifi_hotspot/src/main/js/default/test/List.test.js @@ -0,0 +1,18 @@ +/* + * 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. + */ +require('./WifiSoftAP.test.js') + + + 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 new file mode 100755 index 000000000..4014472fa --- /dev/null +++ b/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js @@ -0,0 +1,702 @@ +/* + * 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 'deccjsunit/index' + +import wifi from '@ohos.wifi' + +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, + WIFI_SEC_TYPE_WEP : 2, + WIFI_SEC_TYPE_PSK : 3, + WIFI_SEC_TYPE_SAE : 4, +} + +var HotspotConfig = { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 +} + +describe('ACTS_WifiTest', function() { + beforeEach(function () { + }) + + afterEach(function () { + }) + + /** + * @tc.number OPEN_0002 + * @tc.name SUB_Communication_WiFi_Hotspot_Open_0002 + * @tc.desc Test wifi.enableHotspot and wifi.disableHotspot API functionality1. + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_Hotspot_Open_0002', 0, async function (done) { + if (wifi.isWifiActive()) { + var disable = wifi.disableWifi(); + await sleep(5000); + expect(disable).assertTrue(); + } + var close =wifi.isWifiActive(); + console.info("[wifi_test] wifi status result: " + close); + expect(close).assertFalse(); + if (!wifi.isHotspotActive()) { + var on = wifi.enableHotspot(); + await sleep(5000); + expect(on).assertTrue(); + } + console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); + expect(wifi.isHotspotActive()).assertTrue(); + done(); + }) + + /** + * @tc.number CONFIG_0001 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0001 + * @tc.desc Test set a valid 2.4G hotspot config + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0001', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(3000); + expect(off).assertTrue(); + } + console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); + expect(wifi.isHotspotActive()).assertFalse(); + var isSuccess = wifi.setHotspotConfig(HotspotConfig); + expect(isSuccess).assertTrue(); + + var hotspotConfig = wifi.getHotspotConfig(); + console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig)); + expect(hotspotConfig.band).assertEqual(1); + done() + }) + + /** + * @tc.number CONFIG_0002 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0002 + * @tc.desc Test set a valid 5G hotspot config + * @tc.level Level 1 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0002', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(3000); + expect(off).assertTrue(); + } + console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive()); + var HotspotConfig5G = { + "ssid": "testWgr", + "band": 2, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess5 = wifi.setHotspotConfig(HotspotConfig5G); + expect(isSuccess5).assertFalse(); + + var hotspotConfig5 = wifi.getHotspotConfig(); + console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig5)); + expect(hotspotConfig5.band).assertEqual(1); + done() + }) + + /** + * @tc.number CONFIG_0003 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0003 + * @tc.desc Test set a invalid band hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0003', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(3000); + console.info("[wifi_test] disableHotspot result -> " + off); + expect(off).assertTrue(); + } + var HotspotConfig1= { + "ssid": "testWgr", + "band": 21, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfig1); + console.log("[wifi_test] set invalid band hotspot config result1:" + isSuccess1); + expect(isSuccess1).assertFalse(); + done(); + + }) + + + /** + * @tc.number CONFIG_0004 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0004 + * @tc.desc Test set a max preSharedKey is hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0004', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + } + var HotspotConfigM= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "123456789123456789123456789123456789123456789123456789123456789", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM); + console.log("[wifi_test] set max preSharedKey valid hotspot config result: " + isSuccess1); + expect(isSuccess1).assertTrue(); + + var HotspotConfigM1= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "1234567891234567891234567891234567891234567891234567891234567891", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM1); + expect(isSuccess1).assertFalse(); + var hotspotConfigS= wifi.getHotspotConfig(); + console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfigS)); + expect(hotspotConfigS.preSharedKey.length).assertEqual(63); + done(); + }) + + /** + * @tc.number CONFIG_0005 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0005 + * @tc.desc Test set a min preSharedKey is hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0005', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + } + + var HotspotConfigI= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI); + expect(isSuccess1).assertTrue(); + + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + console.info("preSharedKey: " + config.preSharedKey); + expect(config.preSharedKey.length).assertEqual(8); + + var HotspotConfigI2= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "1234567", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2); + expect(isSuccess1).assertFalse(); + + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.preSharedKey.length).assertEqual(8); + done(); + }) + + /** + * @tc.number CONFIG_0006 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0006 + * @tc.desc Test set a max ssid for hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0006', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + } + var isHotspotActive = wifi.isHotspotActive(); + console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); + expect(isHotspotActive).assertFalse(); + + var HotspotConfigS= { + "ssid": "testWgr123testWgr123testWgr12356", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS); + expect(isSuccess1).assertTrue(); + + var HotspotConfigS1= { + "ssid": "testWgr123testWgr123testWgr123567", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS1); + console.log("[wifi_test] set 33bit ssid invalid hotspot config result: " + isSuccess1); + expect(isSuccess1).assertFalse(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.ssid.length).assertEqual(32); + done(); + + }) + + /** + * @tc.number CONFIG_0007 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0007 + * @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) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(2000); + expect(off).assertTrue(); + } + var HotspotConfigN= { + "ssid": "", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigN); + console.log("[wifi_test] set a null ssid invalid hotspot config result1:" + isSuccess1); + expect(isSuccess1).assertFalse(); + done(); + }) + + /** + * @tc.number CONFIG_0008 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0008 + * @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) { + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(3000); + expect(off).assertTrue(); + } + var HotspotConfigC= { + "ssid": "测试123!@#¥%……&*( ", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigC); + expect(isSuccess1).assertTrue(); + + var isHotspotActive = wifi.isHotspotActive(); + console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); + expect(isHotspotActive).assertFalse(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(true).assertEqual(config.ssid==HotspotConfigC.ssid); + done(); + }) + + /** + * @tc.number CONFIG_0009 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0009 + * @tc.desc Test set a invalid preSharedKey hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0009', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(3000); + expect(off).assertTrue(); + + } + var HotspotConfigWep= { + "ssid": "test123", + "band": 1, + "preSharedKey": "12345678", + "securityType":WifiSecurityType.WIFI_SEC_TYPE_WEP, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigWep); + console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess1); + expect(isSuccess1).assertFalse(); + + var HotspotConfigSAE= { + "ssid": "test123", + "band": 1, + "preSharedKey": "12345678", + "securityType":WifiSecurityType.WIFI_SEC_TYPE_SAE, + "maxConn": 8 + }; + var isSuccess2 = wifi.setHotspotConfig(HotspotConfigSAE); + console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess2); + expect(isSuccess2).assertFalse(); + + var HotspotConfigC= { + "ssid": "test123", + "band": 1, + "preSharedKey": "12345678", + "securityType":12, + "maxConn": 8 + }; + var isSuccess3 = wifi.setHotspotConfig(HotspotConfigC); + console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess3); + expect(isSuccess3).assertFalse(); + done(); + + }) + + /** + * @tc.number CONFIG_0010 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0010 + * @tc.desc Test set a valid PSK preSharedKey hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0010', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + } + + var HotspotConfigPSK= { + "ssid": "test123", + "band": 1, + "preSharedKey": "12345678", + "securityType":WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + } + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigPSK); + expect(isSuccess1).assertTrue(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.securityType).assertEqual(3); + console.log("[wifi_test] check the state of Hotspot" ); + var isHotspotActive = wifi.isHotspotActive(); + console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); + expect(isHotspotActive).assertFalse(); + done(); + + }) + + /** + * @tc.number CONFIG_0011 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0011 + * @tc.desc Test set a valid OPEN preSharedKey hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0011', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + } + + var HotspotConfigO= { + "ssid": "test123", + "band": 1, + "preSharedKey": "", + "securityType":WifiSecurityType.WIFI_SEC_TYPE_OPEN, + "maxConn": 8 + } + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigO); + console.log("[wifi_test] set a open preSharedKey hotspot config result1: " + isSuccess1); + expect(isSuccess1).assertTrue(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.securityType).assertEqual(1); + done(); + + }) + + /** + * @tc.number CONN_0001 + * @tc.name SUB_Communication_WiFi_Hotspot_Conn_0001 + * @tc.desc Test set a maxConn and more maxConn hotspot config + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Conn_0001', 0, async function (done) { + await tryToDisableWifi(); + if (wifi.isHotspotActive()) { + var off = wifi.disableHotspot(); + await sleep(5000); + expect(off).assertTrue(); + + } + var HotspotConfigI= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "12345678", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI); + console.log("[wifi_test] set maxConn valid hotspot config result: " + isSuccess1); + expect(isSuccess1).assertTrue(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.maxConn).assertEqual(8); + + var HotspotConfigI2= { + "ssid": "testWgr", + "band": 1, + "preSharedKey": "1234567", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 9 + }; + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2); + console.log("[wifi_test] set more maxConn invalid hotspot config result: " + isSuccess1); + expect(isSuccess1).assertFalse(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.maxConn).assertEqual(8); + done(); + }) + + /** + * @tc.number CONFIG_0012 + * @tc.name SUB_Communication_WiFi_Hotspot_Config_0012 + * @tc.desc Test set a valid hotspot config after open Hotspot + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Config_0012', 0, async function (done) { + await tryToDisableWifi(); + if (!wifi.isHotspotActive()) { + var on = wifi.enableHotspot(); + await sleep(5000); + expect(on).assertTrue(); + } + var isHotspotActive = wifi.isHotspotActive(); + console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); + expect(isHotspotActive).assertTrue(); + var HotspotConfigWO= { + "ssid": "WIFITEST", + "band": 1, + "preSharedKey": "123456789", + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + "maxConn": 8 + } + var isSuccess1 = wifi.setHotspotConfig(HotspotConfigWO); + console.log("[wifi_test] set a psk preSharedKey hotspot config result1: " + isSuccess1); + expect(isSuccess1).assertTrue(); + var config = wifi.getHotspotConfig(); + console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config)); + expect(config.ssid).assertEqual('WIFITEST'); + done(); + + }) + + + /** + * @tc.number CONN_0002 + * @tc.name SUB_Communication_WiFi_Hotspot_Conn_0002 + * @tc.desc Test Obtains the list of clients that are connected to a Wi-Fi hotspot. + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_Hotspot_Conn_0002', 0, async function (done) { + await tryToDisableWifi(); + if (!wifi.isHotspotActive()) { + var on = wifi.enableHotspot(); + await sleep(5000); + expect(on).assertTrue(); + } + var isHotspotActive = wifi.isHotspotActive(); + console.info("[wifi_test] isHotspotActive -> " + isHotspotActive); + expect(isHotspotActive).assertTrue(); + var stationInfo = wifi.getStations(); + 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(); + + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_ON_0001 + * @tc.name testhotspotStateChangeOn + * @tc.desc Test hotspotStateChangeOn api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) { + console.info("[wifi_test]hotspotStateChange On test"); + try { + await wifi.on('hotspotStateChange', (data) => { + console.info("[wifi_test] hotspotStateChange On ->" + data); + expect(true).assertEqual(data != null); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_Off_0002 + * @tc.name testhotspotStateChangeOff + * @tc.desc Test hotspotStateChange api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Sta_Off_0002', 0, async function (done) { + try { + await wifi.off('hotspotStateChange', (data) => { + console.info("[wifi_test] hotspotStateChange Off ->" + data); + expect(true).assertEqual(data != null); + console.info("[wifi_test] wifiRssiChange unregister end"); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_ON_0003 + * @tc.name testhotspotStaJoinOn + * @tc.desc Test hotspotStaJoinOn api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Hotspot_ON_0003', 0, async function (done) { + console.info("[wifi_test]hotspotStaJoin On test"); + try { + await wifi.on('hotspotStaJoin', (data) => { + console.info("[wifi_test] hotspotStaJoin On ->" + data); + expect(true).assertEqual(data != null); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_Off_0004 + * @tc.name testhotspotStaJoinOff + * @tc.desc Test hotspotStaJoin api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Sta_Off_0004', 0, async function (done) { + try { + await wifi.off('hotspotStaJoin', (data) => { + console.info("[wifi_test] hotspotStaJoin Off ->" + data); + expect(true).assertEqual(data != null); + console.info("[wifi_test] wifiRssiChange unregister end"); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_ON_0005 + * @tc.name testhotspotStaLeaveOn + * @tc.desc Test hotspotStaLeaveOn api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Hotspot_ON_0005', 0, async function (done) { + console.info("[wifi_test]hotspotStaLeave On test"); + try { + await wifi.on('hotspotStaLeave', (data) => { + console.info("[wifi_test] hotspotStaLeave On ->" + data); + expect(true).assertEqual(data != null); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Hotspot_Off_0006 + * @tc.name testhotspotStaLeaveOff + * @tc.desc Test hotspotStaLeave api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Hotspot_Off_0006', 0, async function (done) { + try { + await wifi.off('hotspotStaLeave', (data) => { + console.info("[wifi_test] hotspotStaLeave Off ->" + data); + expect(true).assertEqual(data != null); + console.info("[wifi_test] hotspotStaLeave unregister end"); + }); + + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + console.log("*************[wifi_test] start wifi js unit test end*************"); +}) + + diff --git a/communication/wifi_hotspot/src/main/resources/base/element/string.json b/communication/wifi_hotspot/src/main/resources/base/element/string.json new file mode 100755 index 000000000..14f9c3a92 --- /dev/null +++ b/communication/wifi_hotspot/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OsAccountTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/communication/wifi_hotspot/src/main/resources/base/media/icon.png b/communication/wifi_hotspot/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O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{ title }} + + diff --git a/communication/wifi_p2p/src/main/js/default/pages/index/index.js b/communication/wifi_p2p/src/main/js/default/pages/index/index.js new file mode 100755 index 000000000..a756c422e --- /dev/null +++ b/communication/wifi_p2p/src/main/js/default/pages/index/index.js @@ -0,0 +1,50 @@ +/* + * 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 {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: '', + myTimeout: 15000 + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + console.info('onReady finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + + this.timeout = this.myTimeout + configService.setConfig(this) + + require('../../test/List.test') + core.execute() + + }, +} + diff --git a/communication/wifi_p2p/src/main/js/default/test/List.test.js b/communication/wifi_p2p/src/main/js/default/test/List.test.js new file mode 100755 index 000000000..4be23311c --- /dev/null +++ b/communication/wifi_p2p/src/main/js/default/test/List.test.js @@ -0,0 +1,19 @@ +/* + * 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. + */ +//require('./WifiSta.test.js') +//require('./WifiSoftAP.test.js') +require('./WifiP2P.test.js') + + 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 new file mode 100644 index 000000000..c216faa0d --- /dev/null +++ b/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js @@ -0,0 +1,565 @@ +/* + * 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 'deccjsunit/index' + +import wifi from '@ohos.wifi' + +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, + GO_BAND_2GHZ : 1, + GO_BAND_5GHZ : 2, +} + +describe('ACTS_WifiTest', function () { + beforeEach(function () { + }) + + afterEach(function () { + }) + + /** + * @tc.number Setting_0001 + * @tc.name SUB_Communication_WiFi_P2P_Setting_0001 + * @tc.desc Test setDeviceName infos + */ + 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.desc Test createGroup and getCurrentGroup promise 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() + .then((data) => { + var resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + }).catch((error) => { + console.info("[wifi_js]getCurrentGroup promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + done(); + + }) + + /** + * @tc.number config_0002 + * @tc.name SUB_Communication_WiFi_P2P_Config_0002 + * @tc.desc Test getCurrentGroup callback infos + */ + it('SUB_Communication_WiFi_P2P_Config_0002', 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 + + "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(); + expect(removeConfig).assertTrue(); + done(); + }); + }) + + /** + * @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_0003', 0, async function(done) { + await tryToEnableWifi(); + var WifiP2PConfig2 = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ", + goBand : 1 + }; + + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + var addConfig = wifi.createGroup(WifiP2PConfig2); + await sleep(2000); + 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); + }).catch((error) => { + console.info("[wifi_test]getCurrentGroup promise then error." + JSON.stringify(error)); + expect(error).assertFail(); + }); + var removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + done(); + }) + + /** + * @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_0004', 0, async function(done) { + await tryToEnableWifi(); + var WifiP2PConfig = { + deviceAddress : "00:00:00:00:00:00", + netId : -2, + 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() + .then((data) => { + var resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + + var removePConfig = wifi.deletePersistentGroup(data.networkId); + expect(removePConfig).assertTrue(); + + var removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number config_0005 + * @tc.name SUB_Communication_WiFi_P2P_Config_0005 + * @tc.desc Test p2pConnect infos + */ + it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) { + await tryToEnableWifi(); + var WifiP2PConfig3 = { + deviceAddress : "00:00:00:00:00:00", + netId : -2, + passphrase : "12345678", + groupName : "AAAZZZ", + goBand : 0 + }; + + 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(); + + var connConfig = wifi.p2pConnect(WifiP2PConfig3); + console.info("[wifi_test] test p2pConnect result." + connConfig); + expect(connConfig).assertTrue(); + var stopScan = wifi.stopDiscoverDevices(); + console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); + done() + }) + + /** + * @tc.number config_0006 + * @tc.name SUB_Communication_WiFi_P2P_Config_0006 + * @tc.desc Test getP2pLinkedInfo promise infos + */ + it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) { + await tryToEnableWifi(); + var P2pConnectState = { + DISCONNECTED :0, + CONNECTED : 1, + }; + await wifi.getP2pLinkedInfo() + .then((data) => { + var resultLength = Object.keys(data).length; + console.info("[wifi_test] getP2pLinkedInfo [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + }).catch((error) => { + console.info("[wifi_test]getP2pLinkedInfo promise then error." + JSON.stringify(error)); + expect(error).assertFail(); + }); + + 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 + + "isGroupOwner: " + result.isGroupOwner + + "groupOwnerAddr: " + result.groupOwnerAddr); + expect(false).assertEqual(result.connectState ==P2pConnectState.CONNECTED); + }); + done(); + }) + + /** + * @tc.number config_0008 + * @tc.name SUB_Communication_WiFi_P2P_Config_0008 + * @tc.desc Test p2pCancelConnect infos + */ + 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(); + var removeConfig = wifi.removeGroup(); + console.info("[wifi_test] test start removeGroup" + removeConfig); + expect(removeConfig).assertTrue(); + done(); + }) + + /** + * @tc.number config_0009 + * @tc.name SUB_Communication_WiFi_P2P_Config_0009 + * @tc.desc Test getP2pPeerDevices infos + */ + it('SUB_Communication_WiFi_P2P_Config_0009', 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() + .then((data) => { + var resultLength = Object.keys(data).length; + console.info("[wifi_test] getP2pPeerDevices [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength >= 0); + }).catch((error) => { + console.info("[wifi_test]getP2pPeerDevices promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + 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; + } + 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 + + "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); + } + if(result[j].deviceStatus ==P2pDeviceStatus.CONNECTED){ + console.info("deviceStatus: " + result[j].deviceStatus); + } + if(result[j].deviceStatus ==P2pDeviceStatus.INVITED){ + console.info("deviceStatus: " + result[j].deviceStatus); + } + if(result[j].deviceStatus ==P2pDeviceStatus.FAILED){ + console.info("deviceStatus: " + result[j].deviceStatus); + } + if(result[j].deviceStatus ==P2pDeviceStatus.AVAILABLE){ + console.info("deviceStatus: " + result[j].deviceStatus); + } + } + var stopScan = wifi.stopDiscoverDevices(); + expect(stopScan).assertTrue(); + done(); + }); + }) + + /** + * @tc.number p2pStateChange_0001 + * @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001 + * @tc.desc Test p2pStateChange callback + */ + it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) { + await tryToEnableWifi(); + await wifi.on('p2pStateChange', result => { + console.info("onP2pStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + + wifi.off('p2pStateChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number p2pConnectionChange_0002 + * @tc.name SUB_Communication_WiFi_P2P_p2pConnectionChange_0002 + * @tc.desc Test p2pConnectionChange callback + */ + it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) { + await tryToEnableWifi(); + await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pStateChange test start ...'); + wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number p2pDeviceChange_0003 + * @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003 + * @tc.desc Test p2pDeviceChange callback + */ + it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) { + console.info('[wifi_test] Onp2pDeviceChange test start ...'); + await wifi.on('p2pDeviceChange', result => { + console.info("onP2pDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pDeviceChange test start ...'); + wifi.off('p2pDeviceChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number p2pPeerDeviceChange_0004 + * @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004 + * @tc.desc Test p2pPeerDeviceChange callback + */ + it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) { + await tryToEnableWifi(); + var recvP2pPeerDeviceChangeFunc = result => { + console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result)); + wifi.getP2pDevices((err, data) => { + if (err) { + console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data)); + var len = Object.keys(data).length; + console.log("getP2pDevices number: " + len); + for (var i = 0; i < len; ++i) { + if (data[i].deviceName === "GRE") { + console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress); + var config = { + "deviceAddress":data[i].deviceAddress, + "netId":-1, + "passphrase":"", + "groupName":"", + "goBand":0, + } + wifi.p2pConnect(config); + } + } + }); + } + await wifi.on('p2pPeerDeviceChange', result => { + console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pPeerDeviceChange', result => { + console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number p2pPersistentGroupChange_0005 + * @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005 + * @tc.desc Test p2pPersistentGroupChange callback + */ + it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) { + await tryToEnableWifi(); + var recvP2pPersistentGroupChangeFunc = result => { + console.info("wifi_test / p2p persistent group change receive event" + JSON.stringify(result)); + var config = { + "deviceAddress" : "02:11:65:f2:0d:6e", + "netId":-2, + "passphrase":"", + "groupName":"", + "goBand":0, + }; + var addConfig = wifi.createGroup(config); + expect(addConfig).assertTrue(); + wifi.getCurrentGroup((err, data) => { + if (err) { + console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data)); + }); + }; + await wifi.on('p2pPersistentGroupChange', result => { + console.info("p2pPersistentGroupChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pPersistentGroupChange', result => { + console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number p2pDiscoveryChange_0006 + * @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006 + * @tc.desc Test p2pDiscoveryChange callback + */ + it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) { + await tryToEnableWifi(); + await wifi.on('p2pDiscoveryChange', result => { + console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pDiscoveryChange', result => { + console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + console.log("*************[wifi_test] start wifi js unit test end*************"); +}) + diff --git a/communication/wifi_p2p/src/main/resources/base/element/string.json b/communication/wifi_p2p/src/main/resources/base/element/string.json new file mode 100755 index 000000000..14f9c3a92 --- /dev/null +++ b/communication/wifi_p2p/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OsAccountTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/communication/wifi_p2p/src/main/resources/base/media/icon.png b/communication/wifi_p2p/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%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qpwJ($9nfsOkBQ* zqqE4hupFp9mloCe&G_>3|1Zh>^LX+ILvvUbO{Mecyohd}cV;DqA+dGu;i~cpcCYm~ z`o-;ygDY#z8`p)OKYb|wb@I(;Kjhze7rnUjT-e9&uErLkF$yK4>voBFHNN)ew@!LE zdGn^t;gj#hzl$HrhsB>BzaM|?jp!>EzRW1zqXqWI8%W~P+KYFrUw`}P;NC&`_6K+F MkH7x?LGzb?0ItqZ1poj5 diff --git a/communication/wifi_standard/src/main/config.json b/communication/wifi_standard/src/main/config.json index da83908d6..01796c829 100755 --- a/communication/wifi_standard/src/main/config.json +++ b/communication/wifi_standard/src/main/config.json @@ -15,12 +15,13 @@ "module": { "package": "ohos.acts.communication.wifi.wifidevice", "name": ".MyApplication", + "mainAbility": "ohos.acts.communication.wifi.wifidevice.MainAbility", "deviceType": [ "phone" ], "distro": { "deliveryWithInstall": true, - "moduleName": "entry", + "moduleName": "wifi_standard", "moduleType": "entry" }, "abilities": [ @@ -55,6 +56,44 @@ "autoDesignWidth": false } } + ], + "reqPermissions": [ + { + "name" : "ohos.permission.GET_WIFI_INFO", + "reason" : "use ohos.permission.GET_WIFI_INFO" + }, + { + "name" : "ohos.permission.SET_WIFI_INFO", + "reason" : "use ohos.permission.SET_WIFI_INFO" + }, + { + "name" : "ohos.permission.MANAGE_WIFI_CONNECTION", + "reason" : "use ohos.permission.MANAGE_WIFI_CONNECTION" + }, + { + "name" : "ohos.permission.SET_WIFI_CONFIG", + "reason" : "use ohos.permission.SET_WIFI_CONFIG" + }, + { + "name" : "ohos.permission.GET_WIFI_CONFIG", + "reason" : "use ohos.permission.GET_WIFI_CONFIG" + }, + { + "name" : "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason" : "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GET_WIFI_LOCAL_MAC", + "reason" : "use ohos.permission.GET_WIFI_LOCAL_MAC" + }, + { + "name" : "ohos.permission.MANAGE_WIFI_HOTSPOT", + "reason" : "use ohos.permission.MANAGE_WIFI_HOTSPOT" + }, + { + "name" : "ohos.permission.GET_WIFI_INFO_INTERNAL", + "reason" : "use ohos.permission.GET_WIFI_INFO_INTERNAL" + } ] } } diff --git a/communication/wifi_standard/src/main/js/default/app.js b/communication/wifi_standard/src/main/js/default/app.js old mode 100755 new mode 100644 index 363f2555b..8fe0b77dc --- a/communication/wifi_standard/src/main/js/default/app.js +++ b/communication/wifi_standard/src/main/js/default/app.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.css b/communication/wifi_standard/src/main/js/default/pages/index/index.css index 6fda79275..72baaffca 100644 --- a/communication/wifi_standard/src/main/js/default/pages/index/index.css +++ b/communication/wifi_standard/src/main/js/default/pages/index/index.css @@ -1,3 +1,18 @@ +/* + * 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. + */ + .container { flex-direction: column; justify-content: center; diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.hml b/communication/wifi_standard/src/main/js/default/pages/index/index.hml index f64b040a5..0053057b5 100644 --- a/communication/wifi_standard/src/main/js/default/pages/index/index.hml +++ b/communication/wifi_standard/src/main/js/default/pages/index/index.hml @@ -1,3 +1,19 @@ +/* + * 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. + */ + +
{{ $t('strings.hello') }} {{ title }} diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.js b/communication/wifi_standard/src/main/js/default/pages/index/index.js index 96b91894f..6e05db1fe 100755 --- a/communication/wifi_standard/src/main/js/default/pages/index/index.js +++ b/communication/wifi_standard/src/main/js/default/pages/index/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 @@ -13,36 +13,35 @@ * limitations under the License. */ -import app from '@system.app' - import {Core, ExpectExtend} from 'deccjsunit/index' export default { data: { - title: "" + title: '', + myTimeout: 15000 }, onInit() { this.title = this.$t('strings.world'); }, onShow() { console.info('onShow finish') + }, + onReady() { + console.info('onReady finish') const core = Core.getInstance() - const expectExtend = new ExpectExtend({ 'id': 'extend' }) core.addService('expect', expectExtend) - // core.addService('report', instrumentLog) core.init() - const configService = core.getDefaultService('config') - - this.timeout = 600000 + this.timeout = this.myTimeout configService.setConfig(this) + require('../../test/List.test') core.execute() - }, - onReady() { + }, } + diff --git a/communication/wifi_standard/src/main/js/default/test/List.test.js b/communication/wifi_standard/src/main/js/default/test/List.test.js index 7613fbe92..00a5ef997 100755 --- a/communication/wifi_standard/src/main/js/default/test/List.test.js +++ b/communication/wifi_standard/src/main/js/default/test/List.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 @@ -12,5 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - require('./WifiSta.test.js') +//require('./WifiSoftAP.test.js') +//require('./WifiP2P.test.js') + + 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 2d757b370..5f6b2cac9 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 @@ -17,12 +17,16 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from import wifi from '@ohos.wifi' -// delay x ms function sleep(delay) { - var start = (new Date()).getTime(); - while ((new Date()).getTime() - start < delay) { - console.log("sleep ms:"+ 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 = { @@ -33,12 +37,30 @@ var WifiSecurityType = { WIFI_SEC_TYPE_SAE: 4, } -var wifiDeviceConfig = { - "ssid": "TEST", - "bssid": "A1:B1:C1:D1:E1:F1", - "preSharedKey": "12345678", - "isHiddenSsid": false, - "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, +var SuppState = { + DISCONNECTED: 0, + INTERFACE_DISABLED: 1, + INACTIVE : 2, + SCANNING: 3, + AUTHENTICATING: 4, + ASSOCIATING: 5, + ASSOCIATED: 6, + FOUR_WAY_HANDSHAKE: 7, + GROUP_HANDSHAKE: 8, + COMPLETED: 9, + UNINITIALIZED: 10, + INVALID: 11, +} + +var ConnState = { + SCANNING: 0, + CONNECTING: 1, + AUTHENTICATING: 2, + OBTAINING_IPADDR: 3, + CONNECTED: 4, + DISCONNECTING: 5, + DISCONNECTED: 6, + UNKNOWN: 7, } var ipConfig = { @@ -48,6 +70,12 @@ var ipConfig = { "domains": ["aaa"], } +var IpType = { + STATIC : 0, + DHCP : 1, + UNKNOWN: 2 +} + describe('ACTS_WifiTest', function() { beforeEach(function() {}) @@ -58,23 +86,23 @@ describe('ACTS_WifiTest', function() { * @tc.name SUB_Communication_WiFi_Sta_Open_0001 * @tc.desc Test wifi.isWifiEnable API functionality. */ - it('SUB_Communication_WiFi_Sta_Open_0001', 0, function() { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Open_0001]"); + it('SUB_Communication_WiFi_Sta_Open_0001', 0, async function(done) { 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(); - sleep(3000); + await sleep(5000); console.log("[wifi_test] wifi open result: " + enable); expect(enable).assertTrue(); } - console.info("[wifi_test] close wifi test start."); var disable = wifi.disableWifi(); - sleep(3000); + 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(); }) /** @@ -83,34 +111,26 @@ 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]"); - if (!wifi.isWifiActive()) { - var enable = wifi.enableWifi(); - sleep(3000); - console.log("[wifi_test] wifi open result: " + enable); - expect(enable).assertTrue(); - } - + await tryToEnableWifi(); var scan = wifi.scan(); - sleep(3000); + 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( - (result) => { + (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 && i < 3)) { + if (!(clen == 0)) { expect(clen).assertLarger(0); console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result)); for (var j = 0; j < clen; ++j) { @@ -127,7 +147,6 @@ describe('ACTS_WifiTest', function() { } done() }); - }) /** @@ -135,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); @@ -166,6 +185,7 @@ describe('ACTS_WifiTest', function() { expect(wifi.getSignalLevel(-86, 2)).assertEqual(0); expect(wifi.getSignalLevel(-127, 2)).assertEqual(0); + done(); }) /** @@ -174,21 +194,28 @@ 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", "bssid": "", "preSharedKey": "", "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_OPEN, + "netId": -1, + "ipType": IpType.DHCP, + "creatorUid": 7, + "disableReason": 0, + "randomMacType": 0, + "randomMacAddr": "11:22:33:44:55:66", + "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); @@ -197,22 +224,23 @@ describe('ACTS_WifiTest', function() { }); wifi.addDeviceConfig(wifiDeviceConfig1, - (netWorkId) => { + (err, netWorkId) => { + if(err) { + console.info("[wifi_test]add OPEN callback failed : " + JSON.stringify(err)); + return; + } 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() }); @@ -224,21 +252,28 @@ 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": "", "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}, }; await wifi.addDeviceConfig(wifiDeviceConfig1) .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); @@ -246,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)); @@ -256,20 +289,64 @@ describe('ACTS_WifiTest', function() { }); done() }) + + /** + * @tc.number Config_0003 + * @tc.name SUB_Communication_WiFi_Sta_Config_0003 + * @tc.desc Test create a WEP SecurityType wifi device config + */ + it('SUB_Communication_WiFi_Sta_Config_0003', 0, async function(done) { + await tryToEnableWifi(); + + var wifiDeviceConfig1 = { + "ssid": "TEST_WEP", + "bssid": "", + "preSharedKey": "ABCDEF1234", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP, + "netId": -1, + "ipType": 1, + "creatorUid": 7, + "disableReason": 0, + "randomMacType": 0, + "randomMacAddr": "11:22:33:44:55:66", + "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936}, + }; + + await wifi.addDeviceConfig(wifiDeviceConfig1) + .then(netWorkId => { + console.info("[wifi_test]add WEP Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + + var configs = wifi.getDeviceConfigs(); + console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); + console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs)); + expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType); + expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig1.isHiddenSsid); + expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfig1.preSharedKey); + expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid); + + var isRemoved = wifi.removeDevice(netWorkId); + expect(isRemoved).assertTrue(); + var configs = wifi.getDeviceConfigs(); + expect(true).assertEqual(configs.length == 0); + }); + done() + }) /** - * @tc.number Config_0005 - * @tc.name SUB_Communication_WiFi_Sta_Config_0005 + * @tc.number Config_0004 + * @tc.name SUB_Communication_WiFi_Sta_Config_0004 * @tc.desc Test remove all wifi 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 multiple valid wifi device config and add it."); + it('SUB_Communication_WiFi_Sta_Config_0004', 0, async function(done) { + await tryToEnableWifi(); var wifiDeviceConfig1 = { "ssid": "TESTWgr1", "bssid": "", - "preSharedKey": "12345678", - "isHiddenSsid": "false", + "preSharedKey": "123456789", + "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, }; var wifiDeviceConfig2 = { @@ -281,32 +358,37 @@ describe('ACTS_WifiTest', function() { }; let promiseOne = new Promise((resolve, reject) => { wifi.addDeviceConfig(wifiDeviceConfig1, - (netWorkId1) => { + (err,netWorkId1) => { + if(err) { + console.info("[wifi_test]add callback failed : " + JSON.stringify(err)); + return; + } 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); resolve() }); }) - let promiseTwo = new Promise((resolve, reject) => { wifi.addDeviceConfig(wifiDeviceConfig2, - (netWorkId2) => { + (err,netWorkId2) => { + if(err) { + console.info("[wifi_test]add callback failed : " + JSON.stringify(err)); + return; + } 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() }); @@ -315,42 +397,129 @@ describe('ACTS_WifiTest', function() { }) /** - * @tc.number Config_0007 - * @tc.name SUB_Communication_WiFi_Sta_Config_0007 + * @tc.number Config_0005 + * @tc.name SUB_Communication_WiFi_Sta_Config_0005 + * @tc.desc Test disableNetwork device config + */ + it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfigD = { + "ssid": "TESTD", + "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}, + }; + await wifi.addDeviceConfig(wifiDeviceConfigD) + .then(netWorkId => { + console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); + var disconNet = wifi.disableNetwork(netWorkId); + expect(disconNet).assertTrue(); + + var configs = wifi.getDeviceConfigs(); + console.info("[wifi_test] wifi device config result : " + JSON.stringify(configs)); + expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigD.ssid); + + var isRemoved = wifi.removeAllNetwork(); + expect(isRemoved).assertTrue(); + var configs = wifi.getDeviceConfigs(); + expect(true).assertEqual(configs.length == 0); + }); + done() + }) + + /** + * @tc.number Config_0006 + * @tc.name SUB_Communication_WiFi_Sta_Config_0006 * @tc.desc Test update wifi device config */ - it('SUB_Communication_WiFi_Sta_Config_0007', 0, async function(done) { - console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0007]"); - console.info("[wifi_test] create a valid wifi device config start."); - var wifiDeviceConfig1 = { + it('SUB_Communication_WiFi_Sta_Config_0006', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfigU = { "ssid": "TEST", "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}, }; - - await wifi.addDeviceConfig(wifiDeviceConfig1) + await wifi.addDeviceConfig(wifiDeviceConfigU) .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)); - wifiDeviceConfig1.ssid = "UPDATE"; - wifiDeviceConfig1.preSharedKey = "1234567890"; - console.info("[wifi_test] wifi new wifiDeviceConfig1:" + wifi.updateNetwork(wifiDeviceConfig1)); - - console.info("[wifi_test] check update device configs successfully "); + wifiDeviceConfigU.ssid = "UPDATE"; + wifiDeviceConfigU.preSharedKey = "1234567890"; + 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 == wifiDeviceConfig1.ssid); - expect(true).assertEqual(configs[1].preSharedKey == wifiDeviceConfig1.preSharedKey); + expect(true).assertEqual(configs[1].ssid == wifiDeviceConfigU.ssid); + expect(true).assertEqual(configs[1].preSharedKey == wifiDeviceConfigU.preSharedKey); + + var isRemoved = wifi.removeAllNetwork(); + expect(isRemoved).assertTrue(); + var configs = wifi.getDeviceConfigs(); + expect(true).assertEqual(configs.length == 0); + }); + done() + }) + + /** + * @tc.number Config_SSID_0001 + * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0001 + * @tc.desc Test SSID wifi device config + */ + it('SSUB_Communication_WiFi_Sta_Conn_SSID_0001', 0, async function(done) { + await tryToEnableWifi(); + + var wifiDeviceConfigZ = { + "ssid": "中文测试SSID", + "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}, + }; + await wifi.addDeviceConfig(wifiDeviceConfigZ) + .then(netWorkId => { + console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); + + var disconNet = wifi.disableNetwork(netWorkId); + expect(disconNet).assertTrue(); + + 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)); @@ -359,23 +528,726 @@ describe('ACTS_WifiTest', function() { done() }) + /** - * @tc.number Info_0002 - * @tc.name SUB_Communication_WiFi_Sta_Info_0002 - * @tc.desc Test get CountryCode + * @tc.number Config_SSID_0002 + * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0002 + * @tc.desc Test SSID wifi device config */ - it('SUB_Communication_WiFi_Sta_Info_0002', 0, function() { - if (!wifi.isWifiActive()) { - var enable = wifi.enableWifi(); - sleep(3000); - expect(enable).assertTrue(); - } + it('SSUB_Communication_WiFi_Sta_Conn_SSID_0002', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfigK = { + "ssid": "test text", + "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}, + }; + + await wifi.addDeviceConfig(wifiDeviceConfigK) + .then(netWorkId => { + console.info("[wifi_test]add kongge SSID Deviceconfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + + expect(wifi.connectToNetwork(netWorkId)).assertTrue(); + + var disconNet = wifi.disableNetwork(netWorkId); + expect(disconNet).assertTrue(); + + 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); + + var isRemoved = wifi.removeAllNetwork(); + expect(isRemoved).assertTrue(); + var configs = wifi.getDeviceConfigs(); + expect(true).assertEqual(configs.length == 0); + }); + done() + }) + + /** + * @tc.number Config_SSID_0003 + * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0003 + * @tc.desc Test contains chinese SSID device config + */ + it('SSUB_Communication_WiFi_Sta_Conn_SSID_0003', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfigT = { + "ssid": "!@#¥%&*/", + "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}, + }; + + await wifi.addDeviceConfig(wifiDeviceConfigT) + .then(netWorkId => { + + expect(true).assertEqual(netWorkId != -1); + console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); + 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); + + var isRemoved = wifi.removeAllNetwork(); + 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() + }) + + /** + * @tc.number Config_SSID_0007 + * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0007 + * @tc.desc Test hidden SSID wifi device config + */ + it('SUB_Communication_WiFi_Sta_Conn_SSID_0007', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfigT = { + "ssid": "test", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": true, + "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}, + }; + + await wifi.addDeviceConfig(wifiDeviceConfigT) + .then(netWorkId => { + + expect(true).assertEqual(netWorkId != -1); + console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId)); + 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); + + var isRemoved = wifi.removeAllNetwork(); + 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() + }) + + /** + * @tc.number SUB_Communication_WiFi_Sta_info_0001 + * @tc.name testgetMacAddress + * @tc.desc Test getMacAddress api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Sta_info_0001', 0, async function (done) { + await tryToEnableWifi(); + expect(wifi.isWifiActive()).assertTrue(); + console.info('[wifi_test] getDeviceMacAddress test start ...'); + var result = wifi.getDeviceMacAddress(); + console.info("[wifi_test] getDeviceMacAddress -> " + JSON.stringify(result)); + expect(true).assertEqual(result.length >= 1) + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Sta_info_0002 + * @tc.name testgetCountryCode + * @tc.desc Test getCountryCode api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Sta_Info_0002', 0, async function(done) { + await tryToEnableWifi(); expect(wifi.isWifiActive()).assertTrue(); console.info(" [wifi_test] getCountryCode start ... "); var countryCode = wifi.getCountryCode(); console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode)); expect(JSON.stringify(countryCode)).assertEqual('"CN"'); + done() + }) + + /** + * @tc.number SUB_Communication_WiFi_Sta_info_0004 + * @tc.name testFeatureSupported + * @tc.desc Test FeatureSupported api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + 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. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + 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(); + done(); + + }) + + /** + * @tc.number Conn_Info_0001 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0001 + * @tc.desc Test reconnect wifi + */ + it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, async function (done) { + 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}, + }; + expect(wifi.isWifiActive()).assertTrue(); + var result1 = wifi.connectToDevice(wifiDeviceConfigConn); + expect(result1).assertTrue(); + console.info("[wifi_test]isConnected : " + wifi.isConnected()); + expect(wifi.isConnected()).assertFalse(); + expect(wifi.reconnect()).assertTrue(); + var isRemoved = wifi.removeAllNetwork(); + 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() + + }) + + /** + * @tc.number conn_Config_0002 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0002 + * @tc.desc Test getLinkedInfo information + */ + it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) { + await tryToEnableWifi(); + 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(); + }); + }) + + /** + * @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; + expect(clen).assertLarger(0); + console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result)); + 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); + done(); + }); + }) + + /** + * @tc.number Conn_Security_0001 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0001 + * @tc.desc Test connectToDevice 10 bits WEP Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0001', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST10", + "bssid": "", + "preSharedKey": "ABCDEF1234", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP, + "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(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + 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) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST26", + "bssid": "", + "preSharedKey": "12345678901234567890123456", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP, + "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(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Security_0005 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0005 + * @tc.desc Test connectToDevice 5bits ASCLL WEP Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0005', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST5", + "bssid": "", + "preSharedKey": "aB1@g", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP, + "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(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Security_0007 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0007 + * @tc.desc Test connectToDevice 13bits ASCLL WEP Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0007', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST7", + "bssid": "", + "preSharedKey": "1234aA@fFgGzZ", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP, + "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(); + console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); + expect(isConnected).assertFalse(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Security_0013 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0013 + * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0013', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST13", + "bssid": "", + "preSharedKey": "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH1234567", + "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(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Security_0014 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0014 + * @tc.desc Test connectToDevice 8bits ASCLL PSK Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0014', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST13", + "bssid": "", + "preSharedKey": "ABCDEFGH", + "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(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Security_0015 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0015 + * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig + */ + it('SUB_Communication_WiFi_Sta_Conn_Security_0015', 0, async function(done) { + await tryToEnableWifi(); + var wifiDeviceConfig1 = { + "ssid": "TEST13", + "bssid": "", + "preSharedKey": "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH1234567", + "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(); + console.info("[wifi_test] check isconnected wifi"); + var isConnected= wifi.isConnected(); + expect(isConnected).assertFalse(); + var isRemoved = wifi.removeAllNetwork(); + console.info("[wifi_test] check remove configs successfully,result:" + isRemoved); + expect(isRemoved).assertTrue(); + done() + }) + + /** + * @tc.number Conn_Info_0003 + * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 + * @tc.desc Test get IpInfo information + */ + it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function (done) { + await tryToEnableWifi(); + var wifiDeviceConfigIp = { + "ssid": "TEST1", + "bssid": "", + "preSharedKey": "123456789", + "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(wifiDeviceConfigIp); + console.log("[wifi_test] wifi connectToDevice result: " + result1); + expect(result1).assertTrue(); + + var isConnected= wifi.isConnected(); + expect(isConnected).assertFalse(); + + var reass= wifi.reassociate(); + expect(reass).assertTrue(); + + var ipInfo = wifi.getIpInfo(); + expect(JSON.stringify(ipInfo)).assertContain("gateway"); + 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(); + 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() + }) + + /** + * @tc.number wifiStateChange_0001 + * @tc.name SUB_Communication_WiFi_Sta_wifiStateChange_0001 + * @tc.desc Test wifiStateChange callback + */ + it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) { + 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) => { + wifi.off('wifiStateChange', 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); + var enable = wifi.enableWifi(); + await sleep(5000); + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + done(); + + }) + + /** + * @tc.number wifiConnectionChange_0002 + * @tc.name SUB_Communication_WiFi_Sta_wifiConnectionChange_0002 + * @tc.desc Test wifiStateChange callback + */ + it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) { + 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('[wifi_test] offwifiConnectionChange test start ...'); + wifi.off('wifiConnectionChange', result => { + console.info("offwifiConnectionChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + + }) + + /** + * @tc.number wifiScanStateChange_0003 + * @tc.name SUB_Communication_WiFi_Sta_wifiScanStateChange_0003 + * @tc.desc Test wifiScanStateChange callback + */ + it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) { + await tryToEnableWifi(); + wifi.on('wifiScanStateChange', async result => { + console.info("wifiScanStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offwifiScanStateChange test start ...'); + wifi.off('wifiScanStateChange', result => { + console.info("offwifiScanStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + resolve() + }); + }) + await promise.then(done) + }); + var scan = wifi.scan(); + await sleep(3000); + done(); + + }) + + /** + * @tc.number wifiRssiChange_0004 + * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0004 + * @tc.desc Test wifiRssiChange callback + */ + it('SUB_Communication_WiFi_Sta_wifiRssiChange_0004', 0, async function (done) { + await tryToEnableWifi(); + wifi.on('wifiRssiChange', async result => { + console.info("wifiRssiChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offwifiRssiChange test start ...'); + wifi.off('wifiRssiChange', result => { + console.info("offwifiRssiChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + + }) + + /** + * @tc.number streamChange_0005 + * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0005 + * @tc.desc Test streamChange callback + */ + it('SUB_Communication_WiFi_Sta_streamChange_0005', 0, async function (done) { + await tryToEnableWifi(); + + wifi.on('streamChange', async result => { + console.info("streamChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offstreamChange test start ...'); + wifi.off('streamChange', result => { + console.info("offstreamChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + + }) console.log("*************[wifi_test] start wifi js unit test end*************"); }) + -- GitLab