diff --git a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js index ea57acb1ad84f029ec5a390029cf50027d851c31..ac5f196886d718efed4a182210abf2c05ad6a13e 100644 --- a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -475,7 +475,7 @@ describe('bluetoothhostTest', function() { }]); await sleep(1000); console.info('[bluetooth_js] BLE scan off14 '); - bluetooth.BLE.off('BLEDeviceFind'); + bluetooth.BLE.stopBLEScan(); bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); done(); diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothADD.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothADD.test.js deleted file mode 100644 index 10d546a254e1f9c426a3e7e95192809b374869e6..0000000000000000000000000000000000000000 --- a/communication/bluetooth_on/src/main/js/test/BluetoothADD.test.js +++ /dev/null @@ -1,1772 +0,0 @@ - -/* - * 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 bluetooth from '@ohos.bluetooth'; -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' - -let BluetoothState= - { - STATE_OFF : 0, - STATE_TURNING_ON : 1, - STATE_ON : 2, - STATE_TURNING_OFF : 3, - STATE_BLE_TURNING_ON : 4, - STATE_BLE_ON : 5, - STATE_BLE_TURNING_OFF : 6, - } - -let ScanMode = - { - SCAN_MODE_NONE : 0, - SCAN_MODE_CONNECTABLE : 1, - SCAN_MODE_GENERAL_DISCOVERABLE : 2, - SCAN_MODE_LIMITED_DISCOVERABLE : 3, - SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4, - SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5, - } - -export default function bluetoothTEST() { -describe('bluetoothTEST', function() { - beforeAll(function () { - console.info('beforeAll called') - }) - beforeEach(function () { - console.info('beforeEach called') - - }) - afterEach(function () { - console.info('afterEach called') - }) - afterAll(function () { - console.info('afterAll called') - }) - - function sleep(delay) { - return new Promise(resovle => setTimeout(resovle, delay)) - } - - async function tryToEnableBt() { - let sta = bluetooth.getState(); - switch(sta){ - case 0: - console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); - bluetooth.enableBluetooth(); - await sleep(3000); - break; - case 1: - console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); - await sleep(3000); - break; - case 2: - console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); - break; - case 3: - console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); - bluetooth.enableBluetooth(); - await sleep(3000); - break; - default: - console.info('[bluetooth_js] enable success'); - } - } - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500 - * @tc.name setLocalName - * @tc.desc Test setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) { - await sleep(1000); - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0500 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = 'my bluetooth'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0500 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600 - * @tc.name TEST setLocalName - * @tc.desc Test setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) { - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = 'bluetooth123'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0600 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700 - * @tc.name TEST setLocalName - * @tc.desc TEST setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) { - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0700 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = '蓝牙设备bluetooth'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0700 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_0700 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100 - * @tc.name TEST setLocalName - * @tc.desc TEST setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) { - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1100 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = '蓝牙设备123'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1100 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200 - * @tc.name TEST setLocalName - * @tc.desc TEST setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) { - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1200 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = '蓝牙设备bluetooth12'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1200 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1200 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400 - * @tc.name TEST setLocalName - * @tc.desc TEST setLocalName api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) { - await tryToEnableBt(); - let localName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1400 localName = '+ JSON.stringify(localName)); - expect(true).assertEqual(localName!=null); - let newName = '蓝牙设备*{bluetooth}'; - let result = bluetooth.setLocalName(newName); - expect(result).assertTrue(); - let getNewName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(newName == getNewName); - result=bluetooth.setLocalName(localName); - expect(result).assertTrue(); - let getLocalName = bluetooth.getLocalName(); - console.info('[bluetooth_js] LocalName_1400 localName = '+ JSON.stringify(getLocalName)); - expect(true).assertEqual(localName == getLocalName); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_NONE,0); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0100 newscanmode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_NONE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0100 setoldscanmode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 newscanmode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 setoldscanmode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,40000); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0200 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,40000); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0400 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0400 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,0); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0500 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0500 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,0); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0600 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0600 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,20000); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0700 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0700 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0800 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,30000); - expect(result).assertTrue(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0900 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE); - result=bluetooth.setBluetoothScanMode(oldScanMode,0); - expect(result).assertTrue(); - let getOldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_0900 getOldScanMode = '+ JSON.stringify(getOldScanMode)); - expect(true).assertEqual(oldScanMode == getOldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000 - * @tc.name TEST scanmode - * @tc.desc TEST scanmode api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 4 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000', 0, async function (done) { - await tryToEnableBt(); - let oldScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_1000 oldScanMode = '+ JSON.stringify(oldScanMode)); - let result = bluetooth.setBluetoothScanMode(-1,0); - expect(result).assertFalse(); - let getScanMode = bluetooth.getBluetoothScanMode(); - console.info('[bluetooth_js] ScanMode_1000 getScanMode = '+ JSON.stringify(getScanMode)); - expect(true).assertEqual(getScanMode == oldScanMode); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400 - * @tc.name testGetRemoteDeviceClass - * @tc.desc Test GetRemoteDeviceClass api 8. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400', 0, async function (done) { - console.info('[bluetooth_js] getRemoteDeviceClass start'); - await tryToEnableBt(); - let ret = bluetooth.getRemoteDeviceClass("00:11:22:33:44:55"); - console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(ret) + 'majorClass:' + - ret.majorClass + 'majorMinorClass:'+ ret.majorMinorClass + 'classOfDevice:' + ret.classOfDevice); - expect(ret.majorClass).assertEqual(0); - done(); - }) - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001 - * @tc.name testSppListen - * @tc.desc Test SppListen api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001', 0, async function (done) { - console.log("[bluetooth_js]: spp listen start"); - await tryToEnableBt(); - let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', - secure: true, type: 0}; - bluetooth.sppListen('server1', sppOption, function(code, serverSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - expect(true).assertEqual(true); - done(); - } else { - expect(true).assertEqual(false); - done(); - } - }) - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200 - * @tc.name testSppListen - * @tc.desc Test SppListen api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0200', 0, async function (done) { - console.log("[bluetooth_js]: spp listen start"); - await tryToEnableBt(); - let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', - secure: false, type: 0}; - let serverNumber = -1; - function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - } - } - bluetooth.sppListen('server1', sppOption, serverSocket); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300 - * @tc.name testSppListen - * @tc.desc Test SppListen api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0300', 0, async function (done) { - console.log("[bluetooth_js]: spp listen start"); - await tryToEnableBt(); - let sppOption = {uuid: '00000000', - secure: true, type: 0}; - let serverNumber = -1; - function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - } - } - bluetooth.sppListen('server1', sppOption, serverSocket); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400 - * @tc.name testSppListen - * @tc.desc Test SppListen api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0400', 0, async function (done) { - console.log("[bluetooth_js]: spp listen start"); - await tryToEnableBt(); - let sppOption = {uuid: '00000000-0000-1000-8000-00805F9B34FB', - secure: false, type: 0}; - let serverNumber = -1; - function serverSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] serverSocket Number: ' + number); - serverNumber = number; - } - } - bluetooth.sppListen('server1', sppOption, serverSocket); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500 - * @tc.name testSppAccept - * @tc.desc Test SppAccept api 8 by callbck. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0500', 0, async function (done) { - console.log("[bluetooth_js] spp accept start"); - await tryToEnableBt(); - function acceptClientSocket(code, number) { - console.log('[bluetooth_js] error code: ' + code.code); - if (code.code == 0) { - console.log('[bluetooth_js] clientSocket Number: ' + number); - } - } - bluetooth.sppAccept(0, acceptClientSocket); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600 - * @tc.name testSppAccept - * @tc.desc Test SppAccept api 8 by callbck. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0600', 0, async function (done) { - console.log("[bluetooth_js] spp accept start"); - await tryToEnableBt(); - bluetooth.sppAccept(-1, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - expect(true).assertEqual(true); - } else { - expect(true).assertEqual(false); - } - }); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700 - * @tc.name testSppConnect - * @tc.desc Test SppConnect api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0700', 0, async function (done) { - console.info('[bluetooth_js] spp_connect start'); - await tryToEnableBt(); - let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', - secure: true, type: 0}; - bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - expect(true).assertEqual(true); - } else { - expect(true).assertEqual(false); - } - }); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800 - * @tc.name testSppConnect - * @tc.desc Test SppConnect api 8 by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0800', 0, async function (done) { - console.info('[bluetooth_js] spp_connect start'); - await tryToEnableBt(); - let sppOption = {uuid: '0000', - secure: false, type: 0}; - bluetooth.sppConnect('ABC', sppOption, function(code, clientSocketNumber) { - console.info('[bluetooth_js] code is: ' + code.code); - if (code.code == 0) { - expect(true).assertEqual(true); - } else { - expect(true).assertEqual(false); - } - }); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:60, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:20, - txPower:60, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:16385, - txPower:60, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:16400, - txPower:60, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:19, - txPower:60, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-10, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-127, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:1, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:10, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-130, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:1, - connectable:false, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1700 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1700', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb-010203", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - console.info('[bluetooth_js] BLE advertising end'); - gattServer.stopAdvertising(); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "" , - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2000 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2000', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "", - serviceValue : "", - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2400 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 1 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2400', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising end'); - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0200 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0200', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let manufactureValueBuffer = new Uint8Array(4); - manufactureValueBuffer[0] = 1; - manufactureValueBuffer[1] = 2; - manufactureValueBuffer[2] = 3; - manufactureValueBuffer[3] = 4; - let serviceValueBuffer = new Uint8Array(4); - serviceValueBuffer[0] = 4; - serviceValueBuffer[1] = 6; - serviceValueBuffer[2] = 7; - serviceValueBuffer[3] = 8; - let setting={ - interval:1000, - txPower:-70, - connectable:true, - } - let advData={ - serviceUuids : "00001888-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : "4567", - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001888-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - let advResponse ={ - serviceUuids : "00001889-0000-1000-8000-00805f9b34fb", - manufactureData : { - manufactureId : 1789, - manufactureValue : manufactureValueBuffer.buffer, - }, - serviceData :{ - serviceUuid : "00001889-0000-1000-8000-00805f9b34fb", - serviceValue : serviceValueBuffer.buffer, - } - } - for(let i = 0;i<10;i++) - { - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.startAdvertising(setting,advData,advResponse); - gattServer.stopAdvertising(); - console.info('[bluetooth_js] BLE advertising 第'+ JSON.stringify(i) +'次 end'); - } - done(); - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400 - * @tc.name testStartAdvertising - * @tc.desc Test StartAdvertising api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400', 0, async function (done) { - console.info('[bluetooth_js] BLE advertising start'); - await tryToEnableBt(); - let gattServer =bluetooth.BLE.createGattServer(); - gattServer.stopAdvertising(); - done(); - }) - }) -} diff --git a/communication/wifi_p2p/src/main/js/test/List.test.js b/communication/wifi_p2p/src/main/js/test/List.test.js index 244af299caffe638be9510fcbe2b1c7e493d0fb4..d5770730cfd6bfcbaee8c5d038ce87820da31fbb 100644 --- a/communication/wifi_p2p/src/main/js/test/List.test.js +++ b/communication/wifi_p2p/src/main/js/test/List.test.js @@ -12,10 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import actsWifiTestNew from './WifiP2P.testsame.js' -import actsWifiTest from './WifiP2P.test2.js' +import actsWifiFunctionTest from './WifiP2PFunction.test.js' +import actsWifiEventTest from './WifiP2PEvent.test.js' export default function testsuite() { -actsWifiTestNew() -actsWifiTest() +actsWifiFunctionTest() +actsWifiEventTest() } - diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js b/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js deleted file mode 100644 index 89ac3015f4e5ede45da9f00e2d510119a3fc66e9..0000000000000000000000000000000000000000 --- a/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' -import wifi from '@ohos.wifi' - -function sleep(delay) { - return new Promise(resovle => setTimeout(resovle, delay)) -} - -function checkWifiPowerOn(){ - console.info("wifi_test/wifi status:" + wifi.isWifiActive()); -} - -export default function actsWifiTestNew() { -describe('actsWifiTestNew', function () { - beforeEach(function () { - checkWifiPowerOn(); - }) - afterEach(function () { - }) - - /** - * @tc.number SUB_Communication_WiFi_XTS_P2P_0009 - * @tc.name testp2pCancelConnect - * @tc.desc Test p2pCancelConnect Group API functionality. - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) { - let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", - netId : -1, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 0 - }; - let addConfig = wifi.createGroup(WifiP2PConfig); - console.info("[wifi_test] test p2pConnect result." + addConfig); - let disConn = wifi.p2pCancelConnect(); - sleep(2000); - console.info("[wifi_test] test p2pCancelConnect result." + disConn); - expect(disConn).assertTrue(); - let removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); - expect(removeConfig).assertTrue(); - done(); - }) - - /** - * @tc.number SUB_Communication_WiFi_XTS_P2P_0011 - * @tc.name testremoveGroup - * @tc.desc Test remove error Group functionality. - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) { - let isRemoved = wifi.removeGroup(10000); - console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved)); - expect(isRemoved).assertTrue(); - done(); - }) - - /** - * @tc.number SUB_Communication_WiFi_XTS_P2P_0002 - * @tc.name testP2pLocalDevice - * @tc.desc Test get TO P2pLocalDevice API functionality. - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_XTS_P2P_0002', 0, async function (done) { - await wifi.getP2pLocalDevice() - .then(data => { - let resultLength = Object.keys(data).length; - console.info("[wifi_test] getP2pLocalDevice [promise] result :" + JSON.stringify(data)); - expect(true).assertEqual(resultLength >= 0); - }).catch((error) => { - console.info("[wifi_test]getP2pLocalDevice promise error." + JSON.stringify(error)); - expect().assertFail(); - }); - function getP2pLocal(){ - return new Promise((resolve, reject) => { - wifi.getP2pLocalDevice( - (err, ret) => { - if(err) { - console.info("[wifi_test]getP2pLocalDevice callback failed : " + JSON.stringify(err)); - return; - } - console.info("[wifi_test] getP2pLocalDevice callback result: " + JSON.stringify(ret)); - console.info("deviceName: " + ret.deviceName + "deviceAddress: " + - ret.deviceAddress + "primaryDeviceType: " + ret.primaryDeviceType + - "deviceStatus: " + ret.deviceStatus + "groupCapabilitys: " + - ret.groupCapabilitys ); - resolve(); - }); - }); - } - await getP2pLocal(); - done(); - }) - }) -} - diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2P.testsame.js b/communication/wifi_p2p/src/main/js/test/WifiP2P.testsame.js deleted file mode 100644 index db1e602dbe1e8f58183a50abf6b7bdeea00a3153..0000000000000000000000000000000000000000 --- a/communication/wifi_p2p/src/main/js/test/WifiP2P.testsame.js +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' - -import wifi from '@ohos.wifi' - -function sleep(delay) { // delay x ms - var start = (new Date()).getTime(); - while ((new Date()).getTime() - start > delay) { - break; - } -} - -function checkWifiPowerOn(){ - console.info("wifi_test/wifi status:" + wifi.isWifiActive()); -} - -let GroupOwnerBand = { - GO_BAND_AUTO : 0, - GO_BAND_2GHZ : 1, - GO_BAND_5GHZ : 2, -} - -export default function actsWifiTest() { - describe('actsWifiTest', function () { - beforeEach(function () { - console.info("beforeEach start" ); - checkWifiPowerOn(); - }) - afterEach(async function () { - console.info("afterEach start" ); - }) - - /** - * @tc.number P2P_Config_0001 - * @tc.name SUB_Communication_WiFi_P2P_Config_0001 - * @tc.desc Test createGroup and getCurrentGroup promise infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) { - let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", - netId : -1, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 0 - }; - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let addConfig = wifi.createGroup(WifiP2PConfig); - console.info("[wifi_test] test createGroup end." + addConfig); - sleep(2000); - expect(addConfig).assertTrue(); - wifi.getCurrentGroup() - .then(data => { - let resultLength = Object.keys(data).length; - console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); - expect(true).assertEqual(resultLength!=0); - let removeConfig = wifi.removeGroup(); - expect(removeConfig).assertTrue(); - }); - done() - }) - - /** - * @tc.number P2P_Config_0002 - * @tc.name SUB_Communication_WiFi_P2P_Config_0002 - * @tc.desc Test getCurrentGroup callback infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_Config_0002', 0, async function(done) { - let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", - netId : -1, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 0 - }; - console.log("[wifi_test] check the state of wifi: " + JSON.stringify(wifi.isWifiActive())); - expect(wifi.isWifiActive()).assertTrue(); - let addConfig = wifi.createGroup(WifiP2PConfig); - sleep(2000); - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive(addConfig)); - expect(addConfig).assertTrue(); - wifi.getCurrentGroup( - (err, result) => { - if (err) { - console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); - expect().assertFail(); - }else{ - 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 + - "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress); - let removeConfig = wifi.removeGroup(); - expect(removeConfig).assertTrue(); - } - done(); - }); - }) - - /** - * @tc.number P2P_Config_0003 - * @tc.name SUB_Communication_WiFi_P2P_Config_0003 - * @tc.desc Test createGroup 2.4G band and getCurrentGroup infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) { - let WifiP2PConfig2 = { - deviceAddress : "00:00:00:00:00:00", - netId : -1, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 1 - }; - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let addConfig = wifi.createGroup(WifiP2PConfig2); - sleep(2000); - console.info("[wifi_test] test createGroup3 result." + addConfig) - expect(addConfig).assertTrue(); - await wifi.getCurrentGroup() - .then(data => { - let resultLength = Object.keys(data).length; - console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); - expect(true).assertEqual(resultLength!=0); - let removeConfig = wifi.removeGroup(); - expect(removeConfig).assertTrue(); - }); - done() - }) - - /** - * @tc.number P2P_Config_0004 - * @tc.name SUB_Communication_WiFi_P2P_Config_0004 - * @tc.desc Test create PersistentGroup infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) { - let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", - netId : -2, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 0 - }; - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let addConfig = wifi.createGroup(WifiP2PConfig); - sleep(2000); - console.info("[wifi_test] test p2pConnect result." + addConfig); - expect(addConfig).assertTrue(); - await wifi.getCurrentGroup() - .then((data) => { - let resultLength = Object.keys(data).length; - console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); - expect(true).assertEqual(resultLength!=0); - let removeConfig = wifi.removeGroup(); - expect(removeConfig).assertTrue(); - }); - done(); - }) - - /** - * @tc.number P2P_Config_0005 - * @tc.name SUB_Communication_WiFi_P2P_Config_0005 - * @tc.desc Test p2pConnect infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) { - let WifiP2PConfig3 = { - deviceAddress : "00:00:00:00:00:00", - netId : -2, - passphrase : "12345678", - groupName : "AAAZZZ", - goBand : 2 - }; - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let scanConfig = wifi.startDiscoverDevices(); - sleep(2000); - expect(scanConfig).assertTrue(); - - let connConfig = wifi.p2pConnect(WifiP2PConfig3); - console.info("[wifi_test] test p2pConnect result." + connConfig); - expect(connConfig).assertTrue(); - let stopScan = wifi.stopDiscoverDevices(); - console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); - done() - }) - - /** - * @tc.number P2P_Config_0006 - * @tc.name SUB_Communication_WiFi_P2P_Config_0006 - * @tc.desc Test getP2pLinkedInfo promise infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) { - await wifi.getP2pLinkedInfo() - .then(data => { - let resultLength = Object.keys(data).length; - console.info("[wifi_test] getP2pLinkedInfo [promise] result -> " + JSON.stringify(data)); - expect(true).assertEqual(resultLength!=0); - done() - }); - }) - - /** - * @tc.number P2P_Config_0007 - * @tc.name SUB_Communication_WiFi_P2P_Config_0007 - * @tc.desc Test getP2pLinkedInfo callback infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) { - let P2pConnectState = { - DISCONNECTED :0, - CONNECTED : 1, - }; - function getP2pInfo(){ - return new Promise((resolve, reject) => { - wifi.getP2pLinkedInfo( - (err, result) => { - if(err) { - console.info("[wifi_test]failed to getP2pLinkedInfo callback" + JSON.stringify(err)); - return; - } - let resultLength = Object.keys(result).length; - console.info("[wifi_test] getP2pLinkedInfo [callback] -> " + JSON.stringify(resultLength)); - console.info("connectState: " + result.connectState + - "isGroupOwner: " + result.isGroupOwner + - "groupOwnerAddr: " + result.groupOwnerAddr); - expect(true).assertEqual(resultLength!=0); - resolve(); - }); - }); - } - await getP2pInfo(); - done(); - }) - - /** - * @tc.number P2P_Config_0008 - * @tc.name SUB_Communication_WiFi_P2P_Config_0008 - * @tc.desc Test p2pCancelConnect infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_Config_0008', 0, async function(done) { - let disConn = wifi.p2pCancelConnect(); - sleep(2000); - console.info("[wifi_test] test p2pCancelConnect result." + disConn); - expect(disConn).assertTrue(); - let removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); - expect(removeConfig).assertTrue(); - done(); - }) - - /** - * @tc.number P2P_Config_0009 - * @tc.name SUB_Communication_WiFi_P2P_Config_0009 - * @tc.desc Test getP2pPeerDevices promise infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_Config_0009', 0, async function(done){ - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let scanConfig = wifi.startDiscoverDevices(); - sleep(2000); - expect(scanConfig).assertTrue(); - await wifi.getP2pPeerDevices() - .then((data) => { - let 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 P2P_Config_0010 - * @tc.name SUB_Communication_WiFi_P2P_Config_0010 - * @tc.desc Test getP2pPeerDevices callback infos - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_Config_0010', 0, async function(done){ - let 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(); - let scanConfig = wifi.startDiscoverDevices(); - sleep(2000); - expect(scanConfig).assertTrue(); - await wifi.getP2pPeerDevices((err, result) => { - if (err) { - console.error('failed to getP2pPeerDevices infos callback because ' + JSON.stringify(err)); - }else{ - console.info("[wifi_test] getP2pPeerDevices [callback] -> " + JSON.stringify(result)); - let len = Object.keys(result).length; - for (let 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); - } - } - let stopScan = wifi.stopDiscoverDevices(); - expect(stopScan).assertTrue(); - } - done(); - }); - }) - - /** - * @tc.number P2P_P2pStateChange_0001 - * @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001 - * @tc.desc Test p2pStateChange callback - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) { - 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 - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) { - await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { - console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc); - expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); - done(); - }); - setTimeout(function() { - console.info('[wifi_test] offP2pStateChange test start ...'); - wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => { - console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); - expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); - }); - }, 1 * 1000); - done(); - }) - - /** - * @tc.number P2P_p2pDeviceChange_0003 - * @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003 - * @tc.desc Test p2pDeviceChange callback - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) { - 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 P2P_p2pPeerDeviceChange_0004 - * @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004 - * @tc.desc Test p2pDeviceChange callback - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION - */ - it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) { - let recvP2pPeerDeviceChangeFunc = result => { - console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result)); - wifi.getP2pDevices((err, data) => { - if (err) { - console.error('wifi_test / failed to get getP2pDevices: ' + JSON.stringify(err)); - return; - } - console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data)); - let len = Object.keys(data).length; - console.log("getP2pDevices number: " + len); - for (let i = 0; i < len; ++i) { - if (data[i].deviceName === "GRE") { - console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress); - let config = { - "deviceAddress":data[i].deviceAddress, - "netId":-1, - "passphrase":"", - "groupName":"", - "goBand":0, - } - wifi.p2pConnect(config); - } - } - }); - } - await wifi.on('p2pPeerDeviceChange', result => { - console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - setTimeout(function() { - wifi.off('p2pPeerDeviceChange', result => { - console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - }); - }, 1 * 1000); - done(); - }) - - /** - * @tc.number P2P_p2pPersistentGroupChange_0005 - * @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005 - * @tc.desc Test p2pPersistentGroupChange callback - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) { - let recvP2pPersistentGroupChangeFunc = () => { - console.info("wifi_test / p2p persistent group change receive event"); - let config = { - "deviceAddress" : "02:11:65:f2:0d:6e", - "netId":-2, - "passphrase":"", - "groupName":"", - "goBand":0, - }; - let addConfig = wifi.createGroup(config); - expect(addConfig).assertTrue(); - wifi.getCurrentGroup((err, data) => { - if (err) { - console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); - return; - } - console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data)); - }); - }; - wifi.on("p2pPersistentGroupChange",recvP2pPersistentGroupChangeFunc); - setTimeout(async function() { - wifi.off('p2pPersistentGroupChange', result => { - console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - }); - }, 1 * 1000); - done(); - }) - - /** - * @tc.number P2P_p2pDiscoveryChange_0006 - * @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006 - * @tc.desc Test p2pDiscoveryChange callback - * @since 8 - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) { - 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/js/test/WifiP2PEvent.test.js b/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b3aa4b7f24af0d247f05f81d4b2719bcfcb4eb63 --- /dev/null +++ b/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +import wifi from '@ohos.wifi' + +function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) +} + +function checkWifiPowerOn(){ + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} + +let GroupOwnerBand = { + GO_BAND_AUTO : 0, + GO_BAND_2GHZ : 1, + GO_BAND_5GHZ : 2, +} + +export default function actsWifiEventTest() { + describe('actsWifiEventTest', function () { + beforeEach(function () { + console.info("beforeEach start" ); + checkWifiPowerOn(); + }) + afterEach(async function () { + console.info("afterEach start" ); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0008 + * @tc.name testp2pStateChange + * @tc.desc Test p2pStateChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0008', 0, async function (done) { + await wifi.on('p2pStateChange', result => { + console.info("onP2pStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pStateChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0009 + * @tc.name testp2pConnectionChange + * @tc.desc Test p2pConnectionChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0009', 0, async function (done) { + await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pStateChange test start ...'); + wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0012 + * @tc.name testp2pDeviceChange + * @tc.desc Test p2pDeviceChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0012', 0, async function (done) { + console.info('[wifi_test] Onp2pDeviceChange test start ...'); + await wifi.on('p2pDeviceChange', result => { + console.info("onP2pDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pDeviceChange test start ...'); + wifi.off('p2pDeviceChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0010 + * @tc.name testp2pDeviceChange + * @tc.desc Test p2pDeviceChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0010', 0, async function (done) { + let recvP2pPeerDeviceChangeFunc = result => { + console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result)); + wifi.getP2pDevices((err, data) => { + if (err) { + console.error('wifi_test / failed to get getP2pDevices: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data)); + let len = Object.keys(data).length; + console.log("getP2pDevices number: " + len); + for (let i = 0; i < len; ++i) { + if (data[i].deviceName === "GRE") { + console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress); + let config = { + "deviceAddress":data[i].deviceAddress, + "netId":-1, + "passphrase":"", + "groupName":"", + "goBand":0, + } + wifi.p2pConnect(config); + } + } + }); + } + await wifi.on('p2pPeerDeviceChange', result => { + console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pPeerDeviceChange', result => { + console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0013 + * @tc.name testp2pPersistentGroupChange + * @tc.desc Test p2pPersistentGroupChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0013', 0, async function (done) { + let recvP2pPersistentGroupChangeFunc = () => { + console.info("wifi_test / p2p persistent group change receive event"); + let config = { + "deviceAddress" : "02:11:65:f2:0d:6e", + "netId":-2, + "passphrase":"", + "groupName":"", + "goBand":0, + }; + let addConfig = wifi.createGroup(config); + expect(addConfig).assertTrue(); + wifi.getCurrentGroup((err, data) => { + if (err) { + console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data)); + }); + }; + wifi.on("p2pPersistentGroupChange",recvP2pPersistentGroupChangeFunc); + setTimeout(async function() { + wifi.off('p2pPersistentGroupChange', result => { + console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0011 + * @tc.name testpp2pDiscoveryChange + * @tc.desc Test p2pDiscoveryChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0011', 0, async function (done) { + await wifi.on('p2pDiscoveryChange', result => { + console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual((result !=null)); + done(); + }); + setTimeout(function() { + wifi.off('p2pDiscoveryChange', result => { + console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + console.log("*************[wifi_test] start wifi js unit test end*************"); + }) +} + + + + + diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js b/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b0f6c4cdd8206ccb3f3042139ee653c2e8bff688 --- /dev/null +++ b/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js @@ -0,0 +1,831 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +import wifi from '@ohos.wifi' + +function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) +} + +function checkWifiPowerOn(){ + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} + +let GroupOwnerBand = { + GO_BAND_AUTO : 0, + GO_BAND_2GHZ : 1, + GO_BAND_5GHZ : 2, +} + +export default function actsWifiFunctionTest() { + describe('actsWifiFunctionTest', function () { + beforeEach(function () { + console.info("beforeEach start" ); + checkWifiPowerOn(); + }) + afterEach(async function () { + console.info("afterEach start" ); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0003 + * @tc.name testcreateGroup + * @tc.desc Test createGroup and getCurrentGroup infos + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0003', 0, async function(done) { + let WifiP2PConfig = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ123", + goBand : 0 + }; + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let addConfig = wifi.createGroup(WifiP2PConfig); + console.log("[wifi_test] check the state of wifi: " + JSON.stringify(addConfig)); + await sleep(2000); + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + }); + wifi.getCurrentGroup( + (err, result) => { + if (err) { + console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); + expect().assertFail(); + }else{ + 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 + + "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress); + } + }); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0004 + * @tc.name testcreateGroup + * @tc.desc Test set password createGroup API Function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0004', 0, async function (done) { + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let WifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "1234567", + groupName: "test_pass", + goBand: 0, + }; + let addConfig = wifi.createGroup(WifiP2PConfig); + console.info("[wifi_test] test createGroup end." + JSON.stringify(addConfig)); + await sleep(2000); + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0104 + * @tc.name testcreateGroup + * @tc.desc Test set password createGroup API Function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0104', 0, async function (done) { + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let WifiP2PConfig1 = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "123@%abcD", + groupName: "test_pass1", + goBand: 0, + }; + let addConfig1 = wifi.createGroup(WifiP2PConfig1); + console.info("[wifi_test] test createGroup end." + JSON.stringify(addConfig1)); + await sleep(2000); + expect(addConfig1).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done() + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0204 + * @tc.name testcreateGroup + * @tc.desc Test set password createGroup API Function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0204', 0, async function (done) { + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let WifiP2PConfig2 = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "abc3456789012345678901234567890123456789012345678901234567890123", + groupName: "test_pass2", + goBand: 0, + }; + let addConfig2 = wifi.createGroup(WifiP2PConfig2); + console.info("[wifi_test] test createGroup end." + JSON.stringify(addConfig2)); + await sleep(2000); + expect(addConfig2).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done() + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0304 + * @tc.name testcreateGroup + * @tc.desc Test set password createGroup API Function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0304', 0, async function (done) { + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let WifiP2PConfig3 = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "abc34567890123456789012345678901234567890123456789012345678901234", + groupName: "test_pass3", + goBand: 0, + }; + let addConfig3 = wifi.createGroup(WifiP2PConfig3); + console.info("[wifi_test] test createGroup end." + JSON.stringify(addConfig3)); + await sleep(2000); + expect(addConfig3).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0007 + * @tc.name testsethotspot + * @tc.desc Test createGroup band setting infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0007', 0, async function(done) { + let WifiP2PConfig2 = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ123", + goBand : 1, + }; + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let addConfig = wifi.createGroup(WifiP2PConfig2); + await sleep(2000); + console.info("[wifi_test] test createGroup3 result." + addConfig) + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0107 + * @tc.name testsethotspot + * @tc.desc Test createGroup band setting infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0107', 0, async function(done) { + let WifiP2PConfig2 = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ123", + goBand : 2, + }; + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let addConfig = wifi.createGroup(WifiP2PConfig2); + await (2000); + console.info("[wifi_test] test createGroup3 result." + addConfig) + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0207 + * @tc.name testsethotspot + * @tc.desc Test createGroup band setting infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0207', 0, async function(done) { + let WifiP2PConfig2 = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ123", + goBand : 0, + }; + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let addConfig = wifi.createGroup(WifiP2PConfig2); + await sleep(2000); + console.info("[wifi_test] test createGroup3 result." + addConfig) + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0307 + * @tc.name testsethotspot + * @tc.desc Test createGroup band setting infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0307', 0, async function(done) { + let WifiP2PConfig2 = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ123", + goBand : 3, + }; + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let addConfig = wifi.createGroup(WifiP2PConfig2); + await sleep(2000); + console.info("[wifi_test] test createGroup3 result." + addConfig) + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0008 + * @tc.name testsethotspot + * @tc.desc Test create P2P error SSID Group functionality. + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0008', 0, async function (done) { + let GroupOwnerBand = { + GO_BAND_AUTO: 0, + GO_BAND_2GHZ: 1, + GO_BAND_5GHZ: 2, + } + let WifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "12345678", + groupName: "", + goBand: 0, + }; + let addConfig = wifi.createGroup(WifiP2PConfig); + console.info("[wifi_test] test createGroup result:" + JSON.stringify(addConfig)); + await sleep(2000); + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0108 + * @tc.name testsethotspot + * @tc.desc Test create P2P error SSID Group functionality. + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0108', 0, async function (done) { + let GroupOwnerBand = { + GO_BAND_AUTO: 0, + GO_BAND_2GHZ: 1, + GO_BAND_5GHZ: 2, + } + let WifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "12345678", + groupName: " ", + goBand: 0, + }; + let addConfig = wifi.createGroup(WifiP2PConfig); + console.info("[wifi_test] test createGroup result:" + JSON.stringify(addConfig)); + await sleep(2000); + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0308 + * @tc.name testsethotspot + * @tc.desc Test create P2P error SSID Group functionality. + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0308', 0, async function (done) { + let GroupOwnerBand = { + GO_BAND_AUTO: 0, + GO_BAND_2GHZ: 1, + GO_BAND_5GHZ: 2, + } + let WifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: " ", + groupName: "testpassword", + goBand: 0, + }; + let addConfig = wifi.createGroup(WifiP2PConfig); + console.info("[wifi_test] test createGroup result:" + JSON.stringify(addConfig)); + await sleep(2000); + expect(addConfig).assertTrue(); + await wifi.getCurrentGroup() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data)); + let removeConfig = wifi.removeGroup(); + expect(removeConfig).assertTrue(); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0009 + * @tc.name testp2pCancelConnect + * @tc.desc Test p2pCancelConnect Group API functionality. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) { + let WifiP2PConfig = { + deviceAddress : "00:00:00:00:00:00", + netId : -1, + passphrase : "12345678", + groupName : "AAAZZZ456", + goBand : 0 + }; + let addConfig = wifi.createGroup(WifiP2PConfig); + console.info("[wifi_test] test p2pConnect result." + addConfig); + let disConn = wifi.p2pCancelConnect(); + await sleep(2000); + console.info("[wifi_test] test p2pCancelConnect result." + disConn); + expect(disConn).assertTrue(); + let removeConfig = wifi.removeGroup(); + console.info("[wifi_test] test start removeGroup:" + removeConfig); + expect(removeConfig).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0011 + * @tc.name testremoveGroup + * @tc.desc Test remove error Group functionality. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) { + let isRemoved = wifi.removeGroup(10000); + console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved)); + expect(isRemoved).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0002 + * @tc.name testP2pLocalDevice + * @tc.desc Test get TO P2pLocalDevice API functionality. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_P2P_0002', 0, async function (done) { + await wifi.getP2pLocalDevice() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getP2pLocalDevice [promise] result :" + JSON.stringify(data)); + expect(true).assertEqual(resultLength >= 0); + }).catch((error) => { + console.info("[wifi_test]getP2pLocalDevice promise error." + JSON.stringify(error)); + expect().assertFail(); + }); + function getP2pLocal(){ + return new Promise((resolve, reject) => { + wifi.getP2pLocalDevice( + (err, ret) => { + if(err) { + console.info("[wifi_test]getP2pLocalDevice callback failed : " + JSON.stringify(err)); + return; + } + console.info("[wifi_test] getP2pLocalDevice callback result: " + JSON.stringify(ret)); + console.info("deviceName: " + ret.deviceName + "deviceAddress: " + + ret.deviceAddress + "primaryDeviceType: " + ret.primaryDeviceType + + "deviceStatus: " + ret.deviceStatus + "groupCapabilitys: " + + ret.groupCapabilitys ); + resolve(); + }); + }); + } + await getP2pLocal(); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0010 + * @tc.name testgetP2pLinkedInfo + * @tc.desc Test Test getP2pLinkedInfo infos + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_XTS_P2P_0010', 0, async function(done) { + let P2pConnectState = { + DISCONNECTED :0, + CONNECTED : 1, + }; + await wifi.getP2pLinkedInfo() + .then(data => { + let resultLength = Object.keys(data).length; + console.info("[wifi_test] getP2pLinkedInfo [promise] result -> " + JSON.stringify(data)); + expect(true).assertEqual(resultLength!=0); + done() + }); + function getP2pInfo(){ + return new Promise((resolve, reject) => { + wifi.getP2pLinkedInfo( + (err, result) => { + if(err) { + console.info("[wifi_test]failed to getP2pLinkedInfo callback" + JSON.stringify(err)); + return; + } + let resultLength = Object.keys(result).length; + console.info("[wifi_test] getP2pLinkedInfo [callback] -> " + JSON.stringify(resultLength)); + console.info("connectState: " + result.connectState + + "isGroupOwner: " + result.isGroupOwner + + "groupOwnerAddr: " + result.groupOwnerAddr); + expect(true).assertEqual(resultLength!=0); + resolve(); + }); + }); + } + await getP2pInfo(); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0001 + * @tc.name testgetP2pPeerDevices + * @tc.desc Test getP2pPeerDevices promise infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0001', 0, async function(done){ + console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); + expect(wifi.isWifiActive()).assertTrue(); + let scanConfig = wifi.startDiscoverDevices(); + await sleep(2000); + expect(scanConfig).assertTrue(); + await wifi.getP2pPeerDevices() + .then((data) => { + let 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(); + }); + let stopScan = wifi.stopDiscoverDevices(); + console.info("[wifi_test] test stopDiscoverDevices result." + stopScan); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_P2P_0101 + * @tc.name testgetP2pPeerDevices + * @tc.desc Test getP2pPeerDevices callback infos + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_Communication_WiFi_XTS_P2P_0101', 0, async function(done){ + let 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(); + let 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)); + }else{ + console.info("[wifi_test] getP2pPeerDevices [callback] -> " + JSON.stringify(result)); + let len = Object.keys(result).length; + for (let 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); + } + } + let stopScan = wifi.stopDiscoverDevices(); + expect(stopScan).assertTrue(); + } + done(); + }); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0008 + * @tc.name testp2pStateChange + * @tc.desc Test p2pStateChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0008', 0, async function (done) { + await wifi.on('p2pStateChange', result => { + console.info("onP2pStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pStateChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0009 + * @tc.name testp2pConnectionChange + * @tc.desc Test p2pConnectionChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0009', 0, async function (done) { + await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pStateChange test start ...'); + wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => { + console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); + expect(true).assertEqual(recvP2pConnectionChangeFunc !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0012 + * @tc.name testp2pDeviceChange + * @tc.desc Test p2pDeviceChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0012', 0, async function (done) { + console.info('[wifi_test] Onp2pDeviceChange test start ...'); + await wifi.on('p2pDeviceChange', result => { + console.info("onP2pDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + console.info('[wifi_test] offP2pDeviceChange test start ...'); + wifi.off('p2pDeviceChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0010 + * @tc.name testp2pDeviceChange + * @tc.desc Test p2pDeviceChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0010', 0, async function (done) { + let recvP2pPeerDeviceChangeFunc = result => { + console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result)); + wifi.getP2pDevices((err, data) => { + if (err) { + console.error('wifi_test / failed to get getP2pDevices: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data)); + let len = Object.keys(data).length; + console.log("getP2pDevices number: " + len); + for (let i = 0; i < len; ++i) { + if (data[i].deviceName === "GRE") { + console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress); + let config = { + "deviceAddress":data[i].deviceAddress, + "netId":-1, + "passphrase":"", + "groupName":"", + "goBand":0, + } + wifi.p2pConnect(config); + } + } + }); + } + await wifi.on('p2pPeerDeviceChange', result => { + console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + done(); + }); + setTimeout(function() { + wifi.off('p2pPeerDeviceChange', result => { + console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0013 + * @tc.name testp2pPersistentGroupChange + * @tc.desc Test p2pPersistentGroupChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0013', 0, async function (done) { + let recvP2pPersistentGroupChangeFunc = () => { + console.info("wifi_test / p2p persistent group change receive event"); + let config = { + "deviceAddress" : "02:11:65:f2:0d:6e", + "netId":-2, + "passphrase":"", + "groupName":"", + "goBand":0, + }; + let addConfig = wifi.createGroup(config); + expect(addConfig).assertTrue(); + wifi.getCurrentGroup((err, data) => { + if (err) { + console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err)); + return; + } + console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data)); + }); + }; + wifi.on("p2pPersistentGroupChange",recvP2pPersistentGroupChangeFunc); + setTimeout(async function() { + wifi.off('p2pPersistentGroupChange', result => { + console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0011 + * @tc.name testpp2pDiscoveryChange + * @tc.desc Test p2pDiscoveryChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0011', 0, async function (done) { + await wifi.on('p2pDiscoveryChange', result => { + console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual((result !=null)); + done(); + }); + setTimeout(function() { + wifi.off('p2pDiscoveryChange', result => { + console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); + done(); + }) + console.log("*************[wifi_test] start wifi js unit test end*************"); + }) +} + + + + + diff --git a/communication/wifi_standard/src/main/js/test/List.test.js b/communication/wifi_standard/src/main/js/test/List.test.js index a815a54b3ae5747ed1470ff0eec59ed4f9378e69..1e7e3fd6c6bcf139c0ae9ec860bad5295e816e92 100644 --- a/communication/wifi_standard/src/main/js/test/List.test.js +++ b/communication/wifi_standard/src/main/js/test/List.test.js @@ -12,10 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import actsWifiTestNew from './WifiJsunit.test1.js' -import actsWifiTest from './WifiJsunit.testsame.js' +import actsWifiCandidateNetWorkTest from './WifiCandidateNetWork.test.js' +import actsWifiFunctionsTest from './WifiStationFunctions.test.js' +import actsWifiEventTest from './WifiStationEvent.test.js' export default function testsuite() { -actsWifiTestNew() -actsWifiTest() +actsWifiCandidateNetWorkTest() +actsWifiFunctionsTest() +actsWifiEventTest() } + diff --git a/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js b/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js similarity index 75% rename from communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js rename to communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js index 1b105e6cd74cffb453f2fef3fccec033b94fb625..1b944fabfe0791b16b65eb580e0b58964a1905c9 100644 --- a/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js +++ b/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js @@ -56,8 +56,8 @@ let WifiChannelWidth = { WIDTH_INVALID:null, } -export default function actsWifiTestNew() { - describe('actsWifiTestNew', function () { +export default function actsWifiCandidateNetWorkTest() { + describe('actsWifiCandidateNetWorkTest', function () { beforeEach(function () { checkWifiPowerOn(); }) @@ -65,12 +65,11 @@ export default function actsWifiTestNew() { }) /** - * @tc.number CandidateNetWork_0001 - * @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0001 - * @since 9 - * @tc.desc Test add OPEN and WEP CandidateConfig Promise API functionality. - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.SET_WIFI_INFO + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0001 + * @tc.name testaddCandidateConfig + * @tc.desc Test add OPEN and WEP CandidateConfig Promise API functionality. + * @tc.type Function + * @tc.level Level 2 */ it('SUB_Communication_WiFi_XTS_CandidateNetWork_0001', 0, async function (done) { let wifiDeviceConfig = { @@ -113,12 +112,11 @@ export default function actsWifiTestNew() { }) /** - * @tc.number CandidateNetWork_0001 - * @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0002 - * @since 8 - * @tc.desc Test add PSK CandidateConfig and removeCandidateConfig Promise API functionality. - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.SET_WIFI_INFO + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0002 + * @tc.name testaddCandidateConfig + * @tc.desc Test add PSK CandidateConfig and removeCandidateConfig Promise API functionality. + * @tc.type Function + * @tc.level Level 2 */ it('SUB_Communication_WiFi_XTS_CandidateNetWork_0002', 0, async function (done) { let wifiDeviceConfig = { @@ -156,12 +154,11 @@ export default function actsWifiTestNew() { }) /** - * @tc.number CandidateNetWork_0003 - * @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0003 - * @since 8 - * @tc.desc Test add SAE CandidateConfig Promise API functionality. - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.SET_WIFI_INFO + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0003 + * @tc.name testaddCandidateConfig + * @tc.desc Test add SAE CandidateConfig Promise API functionality. + * @tc.type Function + * @tc.level Level 2 */ it('SUB_Communication_WiFi_XTS_CandidateNetWork_0003', 0, async function (done) { let wifiDeviceConfig = { @@ -198,12 +195,72 @@ export default function actsWifiTestNew() { }) /** - * @tc.number CandidateNetWork_0005 - * @tc.name SUB_Communication_WiFi_XTS_CandidateNetWork_0005 - * @since 8 - * @tc.desc Test add CandidateConfig and removeCandidateConfig callback API functionality. - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.SET_WIFI_INFO + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0004 + * @tc.name testaddCandidateConfig + * @tc.desc Test add MAX CandidateConfig and removeall CandidateConfig. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_XTS_CandidateNetWork_0004', 0, async function (done) { + let SSID = "TYPE_PSK" + for (let i = 0; i < 16; i++) { + SSID = "TYPE_PSK" + i + console.info("[wifi_test] get canshu result : "); + let wifiDeviceConfig = { + "ssid": SSID, + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + }; + console.info("[wifi_test] get wifiDeviceConfig ssid result : " + JSON.stringify(wifiDeviceConfig.ssid)); + await wifi.addCandidateConfig(wifiDeviceConfig) + .then(netWorkId => { + console.info("[wifi_test]add 16th CandidateConfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + }).catch((error) => { + console.error('[wifi_js] add 16th CandidateConfig promise failed -> ' + JSON.stringify(error)); + expect().assertFail(); + }); + } + let wifiDeviceConfig1 = { + "ssid": "TYPE_17", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + }; + await wifi.addCandidateConfig(wifiDeviceConfig1) + .then(netWorkId => { + console.info("[wifi_test]add 17th CandidateConfig promise : " + JSON.stringify(netWorkId)); + expect(true).assertEqual(netWorkId != -1); + }).catch((error) => { + console.error('[wifi_js] add 17th CandidateConfig promise failed -> ' + JSON.stringify(error)); + }); + let getconfig = wifi.getCandidateConfigs(); + console.info("[wifi_test] wifi get 16 CandidateConfigs result : " + JSON.stringify(getconfig)); + for (let i = 0; i < 16; i++) { + var networkId = getconfig[i].netId; + console.info("[wifi_test] wifi get networkId result : " + JSON.stringify(networkId)); + await wifi.removeCandidateConfig(networkId) + .then(ret => { + console.info("[wifi_test]remove CandidateConfig promise" + JSON.stringify(ret)); + let getconfig1 = wifi.getCandidateConfigs(); + console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig1)); + console.info("[wifi_test] wifi getconfiglength result : " + JSON.stringify(getconfig1.length)); + }).catch((error) => { + console.error('[wifi_js] remove CandidateConfig promise failed -> ' + JSON.stringify(error)); + }); + } + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0005 + * @tc.name testaddCandidateConfig + * @tc.desc Test add CandidateConfig and removeCandidateConfig callback API functionality. + * @tc.type Function + * @tc.level Level 2 */ it('SUB_Communication_WiFi_XTS_CandidateNetWork_0005', 0, async function (done) { let wifiDeviceConfig = { @@ -249,18 +306,16 @@ export default function actsWifiTestNew() { }); }); } - await removeCandidate(); done(); }) /** - * @tc.number CandidateNetWork_0006 - * @tc.name SUB_Communication_WiFi_XTS_SUB_Communication_WiFi_XTS_CandidateNetWork_0006 - * @tc.desc Test connect To CandidateConfig API functionality. - * @since 9 - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.SET_WIFI_INFO + * @tc.number SUB_Communication_WiFi_XTS_CandidateNetWork_0006 + * @tc.name testaddCandidateConfig + * @tc.desc Test connect To CandidateConfig API functionality. + * @tc.type Function + * @tc.level Level 2 */ it('SUB_Communication_WiFi_XTS_CandidateNetWork_0006', 0, async function (done) { let WifiSecurityType = { @@ -302,69 +357,6 @@ export default function actsWifiTestNew() { done(); }) - - /** - * @tc.number Sta_0002 - * @tc.name SUB_Communication_WiFi_XTS_Sta_0002 - * @tc.desc Test get to ScanInfos promise and callback API functionality. - * @since 6 - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION) - */ - it('SUB_Communication_WiFi_XTS_Sta_0002', 0, async function (done) { - await wifi.getScanInfos() - .then(result => { - let clen = Object.keys(result).length; - expect(clen).assertLarger(0); - console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result)); - }); - function getScanInfos() { - return new Promise((resolve, reject) => { - wifi.getScanInfos( - (err, result) => { - if (err) { - console.log("[wifi_test] wifi getScanInfos failed " + err); - } - let clen = Object.keys(result).length; - if (!(clen == 0)) { - expect(clen).assertLarger(0); - console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result)); - for (let j = 0; j < clen; ++j) { - console.info("ssid: " + result[j].ssid + "bssid: " + result[j].bssid + - "securityType: " + result[j].securityType + - "rssi: " + result[j].rssi + "band: " + result[j].band + - "frequency: " + result[j].frequency + "channelWidth: " + result[j].channelWidth + - "timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities - + "centerFrequency0: " + result[j].centerFrequency0 - + "centerFrequency1: " + result[j].centerFrequency1 - + "infoElems: " + result[j].infoElems); - } - } - resolve(); - }); - }); - } - await getScanInfos(); - done(); - }) - - /** - * @tc.number Sta_0034 - * @tc.name SUB_Communication_WiFi_XTS_Sta_0034 - * @tc.desc Test get to ScanInfos Sync API functionality. - * @since 9 - * @syscap SystemCapability.Communication.WiFi.STA - * @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION) - */ - it('SUB_Communication_WiFi_XTS_Sta_0034', 0, async function (done) { - let getScanInfos = wifi.getScanInfosSync(); - console.info("[wifi_test] wifi get to ScanInfosSync result : " + JSON.stringify(getScanInfos)); - let lenth = Object.keys(getScanInfos).length; - console.info("[wifi_test] wifi ScanInfosSync length result : " + JSON.stringify(lenth)); - expect(lenth).assertLarger(0); - done(); - }) - /** * @tc.number SUB_Communication_WiFi_XTS_UntrustedConfig_0001 * @tc.name testaddUntrustedConfig @@ -448,3 +440,7 @@ export default function actsWifiTestNew() { }) }) } + + + + diff --git a/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e088ffce603827ff100efd0e8bd3fc59989f44a2 --- /dev/null +++ b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +import wifi from '@ohos.wifi' + +function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) +} + +function checkWifiPowerOn(){ + console.info("wifi_test/wifi status:" + wifi.isWifiActive()); +} +function resolveIP(ip) { + return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF); +} + +let WifiSecurityType = { + WIFI_SEC_TYPE_INVALID: 0, + WIFI_SEC_TYPE_OPEN: 1, + WIFI_SEC_TYPE_WEP: 2, + WIFI_SEC_TYPE_PSK: 3, + WIFI_SEC_TYPE_SAE: 4, +} + +let ConnState = { + SCANNING: 0, + CONNECTING: 1, + AUTHENTICATING: 2, + OBTAINING_IPADDR: 3, + CONNECTED: 4, + DISCONNECTING: 5, + DISCONNECTED: 6, + UNKNOWN: 7, +} + +let untrustedDeviceConfig = { + "ssid": "untrusted_ssid", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK +} + +let WifiChannelWidth = { + WIDTH_20MHZ : 0, + WIDTH_40MHZ : 1, + WIDTH_80MHZ : 2, + WIDTH_160MHZ : 3, + WIDTH_80MHZ_PLUS : 4, + WIDTH_INVALID:null, +} + +export default function actsWifiEventTest() { + describe('actsWifiEventTest', function() { + beforeEach(function () { + checkWifiPowerOn(); + }) + afterEach(function () { + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0001 + * @tc.name testwifiStateChange + * @tc.desc Test wifiStateChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0001', 0, async function (done) { + wifi.on('wifiStateChange', async result => { + console.info("wifiStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result != null); + let promise = new Promise((resolve) => { + wifi.off('wifiStateChange', result => { + console.info("offwifiStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0002 + * @tc.name testwifiConnectionChange + * @tc.desc Test wifiConnectionChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0002', 0, async function (done) { + wifi.on('wifiConnectionChange', async result => { + console.info("wifiConnectionChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result != null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offwifiConnectionChange test start ...'); + wifi.off('wifiConnectionChange', result => { + console.info("offwifiConnectionChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0003 + * @tc.name testwifiScanStateChange + * @tc.desc Test Test wifiScanStateChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0003', 0, async function (done) { + wifi.on('wifiScanStateChange', async result => { + console.info("wifiScanStateChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result != null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offwifiScanStateChange test start ...'); + wifi.off('wifiScanStateChange', result => { + console.info("offwifiScanStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve() + }); + }) + await promise.then(done) + }); + let scan = wifi.scan(); + await sleep(3000); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0004 + * @tc.name testwifiRssiChange + * @tc.desc Test wifiRssiChange callback + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0004', 0, async function (done) { + wifi.on('wifiRssiChange', async result => { + console.info("wifiRssiChange callback, result:" + JSON.stringify(result)); + expect(true).assertEqual(result != null); + let promise = new Promise((resolve) => { + console.info('[wifi_test] offwifiRssiChange test start ...'); + wifi.off('wifiRssiChange', result => { + console.info("offwifiRssiChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve() + }); + }) + await promise.then(done) + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_Event_Test_0005 + * @tc.name testhotspotStateChange + * @tc.desc Test hotspotStateChange api. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_Event_Test_0005', 0, async function (done) { + console.info("[wifi_test]hotspotStateChange On test"); + try { + await wifi.on('hotspotStateChange', (data) => { + console.info("[wifi_test] hotspotStateChange On ->" + data); + expect(true).assertEqual(data != null); + }); + + } catch (e) { + expect(null).assertFail(); + } + console.info("[wifi_test]hotspotStateChange Off test"); + try { + await wifi.off('hotspotStateChange', (data) => { + console.info("[wifi_test] hotspotStateChange Off ->" + data); + expect(true).assertEqual(data != null); + }); + } catch (e) { + expect(null).assertFail(); + } + done(); + }) + console.log("*************[wifi_test] start wifi js unit test end*************"); + }) +} + + + diff --git a/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js b/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js similarity index 61% rename from communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js rename to communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js index 068e4a3c0c9c03b6a6c7a69a6e2f28ac36ceb7c9..1952da36d39b2d93d98a8ae8afab9e21ddf92c0a 100644 --- a/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js +++ b/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js @@ -66,8 +66,8 @@ let WifiChannelWidth = { WIDTH_INVALID:null, } -export default function actsWifiTest() { - describe('actsWifiTest', function() { +export default function actsWifiFunctionsTest() { + describe('actsWifiFunctionsTest', function() { beforeEach(function () { checkWifiPowerOn(); }) @@ -77,43 +77,47 @@ export default function actsWifiTest() { /** * @tc.number SUB_Communication_WiFi_XTS_Sta_0002 * @tc.name testgetScanInfos - * @tc.desc Test get ScanInfos callback API functionality.. + * @tc.desc Test get to ScanInfos promise and callback API functionality. * @tc.type Function * @tc.level Level 0 */ it('SUB_Communication_WiFi_XTS_Sta_0002', 0, async function (done) { let scan = wifi.scan(); - sleep(3000); - console.log("[wifi_test] open wifi scan result: " + scan); + await sleep(3000); await wifi.getScanInfos() .then(result => { let clen = Object.keys(result).length; expect(clen).assertLarger(0); console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result)); }); - wifi.getScanInfos( - (err, result) => { - if (err) { - console.log("[wifi_test] wifi getScanInfos failed " + err); - } - let clen = Object.keys(result).length; - if (!(clen == 0)) { - expect(clen).assertLarger(0); - console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result)); - for (let j = 0; j < clen; ++j) { - console.info("ssid: " + result[j].ssid + "bssid: " + result[j].bssid + - "securityType: " + result[j].securityType + - "rssi: " + result[j].rssi + "band: " + result[j].band + - "frequency: " + result[j].frequency + - "timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities - + "channelWidth: " + result[j].channelWidth + "centerFrequency0: " - + result[j].centerFrequency0 - + "centerFrequency1: " + result[j].centerFrequency1 - + "infoElems: " + result[j].infoElems); - } - } - done() + function getScanInfos() { + return new Promise((resolve, reject) => { + wifi.getScanInfos( + (err, result) => { + if (err) { + console.log("[wifi_test] wifi getScanInfos failed " + err); + } + let clen = Object.keys(result).length; + if (!(clen == 0)) { + expect(clen).assertLarger(0); + console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result)); + for (let j = 0; j < clen; ++j) { + console.info("ssid: " + result[j].ssid + "bssid: " + result[j].bssid + + "securityType: " + result[j].securityType + + "rssi: " + result[j].rssi + "band: " + result[j].band + + "frequency: " + result[j].frequency + "channelWidth: " + result[j].channelWidth + + "timestamp" + result[j].timestamp + "capabilities" + result[j].capabilities + + "centerFrequency0: " + result[j].centerFrequency0 + + "centerFrequency1: " + result[j].centerFrequency1 + + "infoElems: " + result[j].infoElems); + } + } + resolve(); + }); }); + } + await getScanInfos(); + done(); }) /** @@ -297,163 +301,24 @@ export default function actsWifiTest() { }); }) - /** - * @tc.number Conn_Info_0003 - * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 - * @since 7 - * @tc.desc Test get IpInfo information - */ - it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, function () { - let isConnected = wifi.isConnected(); - expect(isConnected).assertFalse(); - let ipInfo = wifi.getIpInfo(); - expect(JSON.stringify(ipInfo)).assertContain("gateway"); - let ipAddress = resolveIP(ipInfo.ipAddress); - console.info("ipAddress result: " + ipAddress); - console.info("gateway: " + ipInfo.gateway + "ipAddress: " + ipInfo.ipAddress - + "leaseDuration: " + ipInfo.leaseDuration + - "leaseDuration: " + ipInfo.leaseDuration + - "netmask: " + ipInfo.netmask + "primaryDns:" + ipInfo.primaryDns + - "secondDns: " + ipInfo.secondDns + "serverIp: " + ipInfo.serverIp); - }) - - /** - * @tc.number wifiStateChange_0001 - * @tc.name SUB_Communication_WiFi_Sta_wifiStateChange_0001 - * @since 7 - * @tc.desc Test wifiStateChange callback - */ - it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) { - wifi.on('wifiStateChange', async result => { - console.info("wifiStateChange callback, result:" + JSON.stringify(result)); - expect(true).assertEqual(result != null); - let promise = new Promise((resolve) => { - wifi.off('wifiStateChange', result => { - console.info("offwifiStateChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result != null); - resolve() - }); - }) - await promise.then(done) - }); - done(); - }) - - /** - * @tc.number wifiConnectionChange_0002 - * @tc.name SUB_Communication_WiFi_Sta_wifiConnectionChange_0002 - * @since 7 - * @tc.desc Test wifiStateChange callback - */ - it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) { - wifi.on('wifiConnectionChange', async result => { - console.info("wifiConnectionChange callback, result:" + JSON.stringify(result)); - expect(true).assertEqual(result != null); - let promise = new Promise((resolve) => { - console.info('[wifi_test] offwifiConnectionChange test start ...'); - wifi.off('wifiConnectionChange', result => { - console.info("offwifiConnectionChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result != null); - resolve() - }); - }) - await promise.then(done) - }); - done(); - }) - - /** - * @tc.number wifiScanStateChange_0003 - * @tc.name SUB_Communication_WiFi_Sta_wifiScanStateChange_0003 - * @since 7 - * @tc.desc Test wifiScanStateChange callback - */ - it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) { - wifi.on('wifiScanStateChange', async result => { - console.info("wifiScanStateChange callback, result:" + JSON.stringify(result)); - expect(true).assertEqual(result != null); - let promise = new Promise((resolve) => { - console.info('[wifi_test] offwifiScanStateChange test start ...'); - wifi.off('wifiScanStateChange', result => { - console.info("offwifiScanStateChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result != null); - resolve() - }); - }) - await promise.then(done) - }); - let scan = wifi.scan(); - sleep(3000); - done(); - }) - - /** - * @tc.number wifiRssiChange_0004 - * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0004 - * @since 7 - * @tc.desc Test wifiRssiChange callback - */ - it('SUB_Communication_WiFi_Sta_wifiRssiChange_0004', 0, async function (done) { - wifi.on('wifiRssiChange', async result => { - console.info("wifiRssiChange callback, result:" + JSON.stringify(result)); - expect(true).assertEqual(result != null); - let promise = new Promise((resolve) => { - console.info('[wifi_test] offwifiRssiChange test start ...'); - wifi.off('wifiRssiChange', result => { - console.info("offwifiRssiChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result != null); - resolve() - }); - }) - await promise.then(done) - }); - done(); - }) - - /** - * @tc.number SUB_Communication_WiFi_Hotspot_ON_0001 - * @tc.name testhotspotStateChangeOn - * @since 7 - * @tc.desc Test hotspotStateChangeOn api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) { - console.info("[wifi_test]hotspotStateChange On test"); - try { - await wifi.on('hotspotStateChange', (data) => { - console.info("[wifi_test] hotspotStateChange On ->" + data); - expect(true).assertEqual(data != null); - }); - - } catch (e) { - expect(null).assertFail(); - } - done(); - }) - - /** - * @tc.number SUB_Communication_WiFi_Hotspot_Off_0002 - * @tc.name testhotspotStateChangeOff - * @since 7 - * @tc.desc Test hotspotStateChange api. - * @tc.size MEDIUM + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0034 + * @tc.name testgetScanInfosSync + * @tc.desc Test get to ScanInfos Sync API functionality. * @tc.type Function - * @tc.level Level 3 + * @tc.level Level 0 */ - it('SUB_Communication_WiFi_Hotspot_Off_0002', 0, async function (done) { - console.info("[wifi_test]hotspotStateChange Off test"); - try { - await wifi.off('hotspotStateChange', (data) => { - console.info("[wifi_test] hotspotStateChange Off ->" + data); - expect(true).assertEqual(data != null); - }); - } catch (e) { - expect(null).assertFail(); - } + it('SUB_Communication_WiFi_XTS_Sta_0034', 0, async function (done) { + let getScanInfos = wifi.getScanInfosSync(); + console.info("[wifi_test] wifi get to ScanInfosSync result : " + JSON.stringify(getScanInfos)); + let lenth = Object.keys(getScanInfos).length; + console.info("[wifi_test] wifi ScanInfosSync length result : " + JSON.stringify(lenth)); + expect(lenth).assertLarger(0); done(); }) console.log("*************[wifi_test] start wifi js unit test end*************"); }) } + + +