From fa80cf7941c8c9c755c594b865ee63dca7bc0d76 Mon Sep 17 00:00:00 2001 From: quanli Date: Fri, 19 Aug 2022 12:26:57 +0800 Subject: [PATCH] quanli1@huawei.com Signed-off-by: quanli --- .../src/main/js/test/BleAdvertiser.test.js | 725 +++++++ .../src/main/js/test/BleGattManager.test.js | 658 ++++++ .../src/main/js/test/BleService.test.js | 1254 ++++++++++++ .../src/main/js/test/List.test.js | 8 +- communication/bluetooth_on/Test.json | 2 +- .../src/main/js/test/BleScanResult.test.js | 629 ++++++ .../src/main/js/test/BluetoothOn.test.js | 1525 +++++--------- .../src/main/js/test/BluetoothPair.test.js | 258 +++ .../src/main/js/test/List.test.js | 12 +- .../main/js/test/bluetoothProfileAdd.test.js | 97 + .../src/main/js/test/bluetoothSys.test.js | 125 ++ communication/bluetooth_profile/Test.json | 5 +- .../src/main/js/test/BluetoothA2dp.test.js | 5 +- communication/bluetooth_standard/Test.json | 5 +- .../src/main/js/test/BRDiscovery.test.js | 128 ++ .../src/main/js/test/BRScanMode.test.js | 319 +++ .../src/main/js/test/BRSetLocalName.test.js | 428 ++++ .../src/main/js/test/BRSpp.test.js | 355 ++++ .../src/main/js/test/BRSwitch.test.js | 163 ++ .../src/main/js/test/List.test.js | 10 +- .../src/main/js/test/WifiP2P.test2.js | 129 +- .../src/main/js/test/WifiP2P.testsame.js | 966 ++++----- .../src/main/js/test/WifiJsunit.test1.js | 115 +- .../src/main/js/test/WifiJsunit.testsame.js | 754 ++++--- .../main/js/default/test/GeocoderTest.test.js | 1596 ++++----------- .../js/default/test/GetCountryCode.test.js | 169 ++ .../src/main/js/default/test/List.test.js | 4 +- .../main/js/default/test/LocationMock.test.js | 371 ---- .../main/js/default/test/LocationTest.test.js | 1783 +++++++++-------- ...ocation.test.js => SystemLocation.test.js} | 127 +- 30 files changed, 8233 insertions(+), 4492 deletions(-) create mode 100644 communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js create mode 100644 communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js create mode 100644 communication/bluetooth_ble/src/main/js/test/BleService.test.js create mode 100644 communication/bluetooth_on/src/main/js/test/BleScanResult.test.js create mode 100644 communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js create mode 100644 communication/bluetooth_on/src/main/js/test/bluetoothProfileAdd.test.js create mode 100644 communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js create mode 100644 communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js create mode 100644 communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js create mode 100644 communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js create mode 100644 communication/bluetooth_standard/src/main/js/test/BRSpp.test.js create mode 100644 communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js create mode 100644 location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js delete mode 100644 location/geolocation_standard/src/main/js/default/test/LocationMock.test.js rename location/geolocation_standard/src/main/js/default/test/{Geolocation.test.js => SystemLocation.test.js} (73%) diff --git a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js new file mode 100644 index 000000000..89121e872 --- /dev/null +++ b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js @@ -0,0 +1,725 @@ + +/* + * 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' + + +export default function bluetoothBLETest2() { +describe('bluetoothBLETest2', function() { + let gattServer = null; + let gattClient = null; + 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'); + } + } + beforeAll(function () { + console.info('beforeAll called') + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); + }) + beforeEach(async function (done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + gattServer.close(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:150, + txPower:60, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:20, + txPower:60, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:16385, + txPower:60, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:16400, + txPower:60, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:19, + txPower:60, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:-10, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:-127, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:1, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:10, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:-130, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:1, + connectable:false, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:70, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1600', 0, async function (done) { + let gattServer =bluetooth.BLE.createGattServer(); + 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; + gattServer.startAdvertising({ + interval:1000, + txPower:-70, + connectable:true, + },{ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + },{ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + }); + gattServer.stopAdvertising(); + done(); + }) + +}) + +} + diff --git a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js new file mode 100644 index 000000000..ca1102204 --- /dev/null +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -0,0 +1,658 @@ +/* + * 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' + +export default function bluetoothBLETest() { +describe('bluetoothBLETest', function() { + + let gattServer = null; + let gattClient = null; + 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'); + } + } + beforeAll(function () { + console.info('beforeAll called') + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + gattServer.close(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0100 + * @tc.name test gatt connect and disconnect + * @tc.desc Test connect and disconnect api . + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + await sleep(2000); + console.info('[bluetooth_js] gattClient connect' + ret) + expect(ret).assertTrue(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0300 + * @tc.name testGetConnectedBLEDevices + * @tc.desc Test getConnectedBLEDevices api . + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GattConnect_0300', 0, function () { + let result = bluetooth.BLE.getConnectedBLEDevices(); + console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result) + + "length:" +result.length); + expect(result.length).assertEqual(0); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100 + * @tc.name testgetRssiValue + * @tc.desc Test getRssiValue api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getRssiValue().then((data) => { + console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data)); + let rssiLength = Object.keys(data).length; + expect(rssiLength).assertEqual(0); + }).catch(err => { + console.error('bluetooth getRssiValue has error: '+ err); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200 + * @tc.name testgetRssiValue + * @tc.desc Test testGetDeviceName api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + gattClient.getRssiValue((err, data)=> { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(data).assertNull(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + await sleep(2000); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100 + * @tc.name testGetDeviceName + * @tc.desc Test GetDeviceName api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getDeviceName().then((data) => { + console.info('[bluetooth_js] device name' + JSON.stringify(data)) + expect(data).assertNull(); + }).catch(err => { + console.error('bluetooth getDeviceName has error: '+ err); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_getDeviceName_0200 + * @tc.name testGetDeviceName + * @tc.desc Test testGetDeviceName api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + gattClient.getDeviceName((err, data)=> { + console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); + expect(data).assertNull(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + await sleep(2000); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100 + * @tc.name testGetServices + * @tc.desc Test GetServices api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getServices().then((GattService) => { + console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); + expect(GattService).assertNull(); + }).catch(err => { + console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200 + * @tc.name testGetServices + * @tc.desc Test GetServices api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js]gattClient getservices2 connect' + JSON.stringify(ret)) + gattClient.getServices((code, data)=> { + if(code.code==0){ + console.info("bluetooth services size is ", data.length) + expect(true).assertEqual(data.length >= 0); + } else { + console.info('[bluetooth_js] get services code ' + JSON.stringify(code)); + expect(true).assertEqual(code.code == -1); + } + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(100); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(22); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(21); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(512); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(513); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + await gattClient.readCharacteristicValue(characteristic).then((object) => { + if (object != null) { + console.error('bluetooth readCharacteristicValue promise object :' + +JSON.stringify(object)); + expect(true).assertEqual(true); + } else { + console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object)); + expect(null).assertFail(); + } + done(); + }).catch(error => { + console.error('[bluetooth_js] readCharacteristicValue promise has error:' + +JSON.stringify(error)); + expect(true).assertEqual(true); + done(); + }) + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) { + function readCcc(code, BLECharacteristic) { + if (code.code != 0) { + return; + } + console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); + let value = new Uint8Array(BLECharacteristic.characteristicValue); + console.log('bluetooth characteristic value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer}; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptor}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let data = await gattClient.readCharacteristicValue(characteristic,readCcc); + console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data)) + expect(true).assertEqual(data==null); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + expect(true).assertEqual(true); + + } else { + console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object)); + expect(null).assertFail(); + } + done(); + }).catch(error => { + console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error)); + expect(true).assertEqual(true); + done(); + }) + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) { + function readDesc(code, BLEDescriptor) { + if (code.code != 0) { + console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); + return; + } + console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid); + let value = new Uint8Array(BLEDescriptor.descriptorValue); + console.info('[bluetooth_js] descriptor value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let data1 = await gattClient.readDescriptorValue(descriptor,readDesc); + console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1)) + expect(true).assertEqual(data1==null); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test Client WriteCharacteristicValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeCharacteristicValue(characteristic); + console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test Client WriteCharacteristicValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeCharacteristicValue("123"); + console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100 + * @tc.name testWriteDescriptorValue + * @tc.desc Test Client WriteDescriptorValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeDescriptorValue(descriptor); + console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200 + * @tc.name testWriteDescriptorValue + * @tc.desc Test WriteDescriptorValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeDescriptorValue(""); + console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let arrayBufferNotify = new ArrayBuffer(8); + let descNotifyValue = new Uint8Array(arrayBufferNotify); + descNotifyValue[0] = 1 + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBufferNotify}; + descriptors[0] = descriptor; + descriptors[1] = descriptorNotify; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true); + console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let arrayBufferNotify = new ArrayBuffer(8); + let descNotifyValue = new Uint8Array(arrayBufferNotify); + descNotifyValue[0] = 1 + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBufferNotify}; + descriptors[0] = descriptor; + descriptors[1] = descriptorNotify; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false); + console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setNotifyCharacteristicChanged(null, false); + console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + +}) +} + diff --git a/communication/bluetooth_ble/src/main/js/test/BleService.test.js b/communication/bluetooth_ble/src/main/js/test/BleService.test.js new file mode 100644 index 000000000..914327d16 --- /dev/null +++ b/communication/bluetooth_ble/src/main/js/test/BleService.test.js @@ -0,0 +1,1254 @@ +/* + * 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' + +export default function bluetoothBLETest1() { +describe('bluetoothBLETest1', function() { + + let gattServer = null; + let gattClient = null; + 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'); + } + } + beforeAll(function () { + console.info('beforeAll called') + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + gattServer.close(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100 + * @tc.name testgetRssiValue + * @tc.desc Test getRssiValue api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getrssi2 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getRssiValue().then((data) => { + console.info('[bluetooth_js] BLE read rssi ' + JSON.stringify(data)); + let rssiLength = Object.keys(data).length; + expect(rssiLength).assertEqual(0); + }).catch(err => { + console.error('bluetooth getRssiValue has error: '+ err); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi2 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200 + * @tc.name testgetRssiValue + * @tc.desc Test testGetDeviceName api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + gattClient.getRssiValue((err, data)=> { + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(data).assertNull(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + await sleep(2000); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100 + * @tc.name testGetDeviceName + * @tc.desc Test GetDeviceName api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getDeviceName().then((data) => { + console.info('[bluetooth_js] device name' + JSON.stringify(data)) + expect(data).assertNull(); + }).catch(err => { + console.error('bluetooth getDeviceName has error: '+ err); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_getDeviceName_0200 + * @tc.name testGetDeviceName + * @tc.desc Test testGetDeviceName api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + gattClient.getDeviceName((err, data)=> { + console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); + expect(data).assertNull(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + await sleep(2000); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100 + * @tc.name testGetServices + * @tc.desc Test GetServices api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret)) + expect(ret).assertTrue(); + await gattClient.getServices().then((GattService) => { + console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); + expect(GattService).assertNull(); + }).catch(err => { + console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); + expect(true).assertEqual(true); + }); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200 + * @tc.name testGetServices + * @tc.desc Test GetServices api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.connect(); + console.info('[bluetooth_js]gattClient getservices2 connect' + JSON.stringify(ret)) + gattClient.getServices((code, data)=> { + if(code.code==0){ + console.info("bluetooth services size is ", data.length) + expect(true).assertEqual(data.length >= 0); + } else { + console.info('[bluetooth_js] get services code ' + JSON.stringify(code)); + expect(true).assertEqual(code.code == -1); + } + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + }); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(100); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(22); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(21); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(512); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setBLEMtuSize(513); + console.info('[bluetooth_js] bluetooth setBLEMtuSize 128bit ret:' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + await gattClient.readCharacteristicValue(characteristic).then((object) => { + if (object != null) { + console.error('bluetooth readCharacteristicValue promise object :' + +JSON.stringify(object)); + expect(true).assertEqual(true); + } else { + console.info('[bluetooth_js] readCharacValue promise null:' + JSON.stringify(object)); + expect(null).assertFail(); + } + done(); + }).catch(error => { + console.error('[bluetooth_js] readCharacteristicValue promise has error:' + +JSON.stringify(error)); + expect(true).assertEqual(true); + done(); + }) + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function(done) { + function readCcc(code, BLECharacteristic) { + if (code.code != 0) { + return; + } + console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); + let value = new Uint8Array(BLECharacteristic.characteristicValue); + console.log('bluetooth characteristic value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer}; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptor}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let data = await gattClient.readCharacteristicValue(characteristic,readCcc); + console.log('[bluetooth_js] readCharacteristicValue callback: ' + JSON.stringify(data)) + expect(true).assertEqual(data==null); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + expect(true).assertEqual(true); + + } else { + console.info('[bluetooth_js]readDescriptorValue null:' + JSON.stringify(object)); + expect(null).assertFail(); + } + done(); + }).catch(error => { + console.error('[bluetooth_js]readDescriptorValue promise error:'+JSON.stringify(error)); + expect(true).assertEqual(true); + done(); + }) + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) { + function readDesc(code, BLEDescriptor) { + if (code.code != 0) { + console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); + return; + } + console.info('[bluetooth_js] descriptor uuid: ' + BLEDescriptor.descriptorUuid); + let value = new Uint8Array(BLEDescriptor.descriptorValue); + console.info('[bluetooth_js] descriptor value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let data1 = await gattClient.readDescriptorValue(descriptor,readDesc); + console.log('[bluetooth_js] readDescriptorValue callback: ' + JSON.stringify(data1)) + expect(true).assertEqual(data1==null); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test Client WriteCharacteristicValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeCharacteristicValue(characteristic); + console.info('[bluetooth_js] writeCharacteristicValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test Client WriteCharacteristicValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeCharacteristicValue("123"); + console.info('[bluetooth_js] invaild writeCharacteristicValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100 + * @tc.name testWriteDescriptorValue + * @tc.desc Test Client WriteDescriptorValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeDescriptorValue(descriptor); + console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200 + * @tc.name testWriteDescriptorValue + * @tc.desc Test WriteDescriptorValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.writeDescriptorValue(""); + console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); + expect(ret).assertEqual(false); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0100 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let arrayBufferNotify = new ArrayBuffer(8); + let descNotifyValue = new Uint8Array(arrayBufferNotify); + descNotifyValue[0] = 1 + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBufferNotify}; + descriptors[0] = descriptor; + descriptors[1] = descriptorNotify; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let ret = gattClient.setNotifyCharacteristicChanged(characteristic, true); + console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0200 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, async function(done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let arrayBufferNotify = new ArrayBuffer(8); + let descNotifyValue = new Uint8Array(arrayBufferNotify); + descNotifyValue[0] = 1 + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBufferNotify}; + descriptors[0] = descriptor; + descriptors[1] = descriptorNotify; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + let ret = gattClient.setNotifyCharacteristicChanged(characteristic, false); + console.info('[bluetooth_js] setNotifyCharacteristicChanged ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_NotifyCharacteristic_0300 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, async function (done) { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + let ret = gattClient.setNotifyCharacteristicChanged(null, false); + console.info('[bluetooth_js] setNotifyCharacteristicChanged is null ret:' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0100', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + isPrimary: true, includeServices: []}; + let ret = gattServer.addService(service); + console.info('[bluetooth_js] bluetooth addService characteristics is null result:' + ret); + expect(ret).assertTrue(); + await sleep(3000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(3000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0200', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService a characteristics result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0300', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + characteristics[1] = characteristicN; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService more characteristics result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0400', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:[]}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService not descriptors result : ' + ret); + expect(ret).assertFalse(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertFalse(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0500', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService a descriptors result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0600', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + + let descriptor1 = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + + descriptors[0] = descriptor; + descriptors[1] = descriptor1; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService more descriptors result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0700', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService isPrimary result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0800', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: false, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService isNotPrimary result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_0900', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService null serviceUuid result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService(''); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1000', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '123@ad', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '123@ad', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'123@ad', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService invalid serviceUuid result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('123@ad'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1100', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService null characteristicValue result : ' + ret); + expect(ret).assertFalse(); + await sleep(2000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertFalse(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_AddService_1200', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB'}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService null descriptorValue result : ' + ret); + expect(ret).assertFalse(); + await sleep(2000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertFalse(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', + isPrimary: true,includeServices:[]}; + let gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb', + isPrimary: false,includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService1 result : ' + ret); + expect(ret).assertTrue(); + let retN = gattServer.addService(gattService1); + console.info('[bluetooth_js] bluetooth addService2 result : ' + retN); + expect(retN).assertTrue(); + await sleep(2000); + let ret1=gattServer.removeService('00001888-0000-1000-8000-00805f9b34fb'); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let ret1=gattServer.removeService('00001800-0000-1000-8000-00805f9b3442'); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertFalse(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300', 0, async function (done) { + let gattServer = bluetooth.BLE.createGattServer(); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristics = []; + let arrayBufferC = new ArrayBuffer(8); + let cccV = new Uint8Array(arrayBufferC); + cccV[0] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferC, descriptors:descriptors}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + let ret = gattServer.addService(gattService); + console.info('[bluetooth_js] bluetooth addService result : ' + ret); + expect(ret).assertTrue(); + await sleep(1000); + let ret1=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + console.info('[bluetooth_js]removeService ret:'+ret1); + expect(ret1).assertTrue(); + let ret2=gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(2000); + console.info('[bluetooth_js]removeService ret:'+ret2); + expect(ret2).assertFalse(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: descV}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: + arrayBufferC, descriptors:descriptors}; + let NotifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: + characteristic.characteristicValue, confirm: false}; + let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic); + console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let descV = new Uint8Array(arrayBuffer); + descV[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: descV}; + descriptors[0] = descriptor; + let arrayBufferC = new ArrayBuffer(8); + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: + arrayBufferC, descriptors:descriptors}; + let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: + characteristic.characteristicValue, confirm: false}; + let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic); + console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300', 0, async function (done) { + console.info('[bluetooth_js] SUB_COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200'); + let ret = gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', null); + console.info('[bluetooth_js] notifyCharacteristicChanged ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100', 0, async function (done) { + let arrayBuffer = new ArrayBuffer(8); + let value = new Uint8Array(arrayBuffer); + value[0] = 1; + let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1, + status: 0, offset: 0, value: arrayBuffer}; + let ret = gattServer.sendResponse(ServerResponse); + console.info('[bluetooth_js] sendResponse ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + +}) +} + diff --git a/communication/bluetooth_ble/src/main/js/test/List.test.js b/communication/bluetooth_ble/src/main/js/test/List.test.js index 1debd6f19..29919a2e5 100644 --- a/communication/bluetooth_ble/src/main/js/test/List.test.js +++ b/communication/bluetooth_ble/src/main/js/test/List.test.js @@ -13,7 +13,11 @@ * limitations under the License. */ -import bluetoothhostTest from './BluetoothBle.test.js' +import bluetoothBLETest from './BleGattManager.test.js' +import bluetoothBLETest1 from './BleService.test.js' +import bluetoothBLETest2 from './BleAdvertiser.test.js' export default function testsuite() { -bluetoothhostTest() +bluetoothBLETest() +bluetoothBLETest1() +bluetoothBLETest2() } diff --git a/communication/bluetooth_on/Test.json b/communication/bluetooth_on/Test.json index b6172f16b..4da553c3b 100644 --- a/communication/bluetooth_on/Test.json +++ b/communication/bluetooth_on/Test.json @@ -17,4 +17,4 @@ "cleanup-apps": true } ] -} \ No newline at end of file +} diff --git a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js new file mode 100644 index 000000000..ea57acb1a --- /dev/null +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -0,0 +1,629 @@ +/* + * 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 ScanDuty= + { + SCAN_MODE_LOW_POWER : 0, + SCAN_MODE_BALANCED : 1, + SCAN_MODE_LOW_LATENCY : 2, + }; + +let MatchMode= + { + MATCH_MODE_AGGRESSIVE : 1, + MATCH_MODE_STICKY : 2, + }; + +export default function bluetoothhostTest() { +describe('bluetoothhostTest', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0100 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0100', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) + bluetooth.BLE.startBLEScan(null); + await sleep(1000); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0200 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0200', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off2'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0300 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0300', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{name:"blue_test"}]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off3'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0400 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0400', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result4'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off4'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0500 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0500', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off5'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0600 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0600', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + let ScanOptions= { + interval: 100, + dutyMode: ScanDuty.SCAN_MODE_BALANCED, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{}],ScanOptions); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off6'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off7'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0800 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0800', 0, async function (done) { + bluetooth.disableBluetooth(); + await sleep(3000); + let state = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off1:'+ JSON.stringify(state)); + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data)); + except(true).assertTrue(data.length=0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off8'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0700 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0900', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 0, + dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off7'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1000 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1000', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off10'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1100 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1100', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off11'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1200 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1200', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: MatchMode.MATCH_MODE_STICKY, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off12'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1300 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1300', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data)); + except(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{ + deviceId:"11:22:33:44:55:66", + name:"test", + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" + }], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off13'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1400 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 9 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1400', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLE scan device find result14'+ JSON.stringify(data)); + expect(true).assertTrue(data.length > 0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{ + serviceUuid:"00001812-0000-1000-8000-00805F9B34FB", + serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", + }]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off14 '); + bluetooth.BLE.off('BLEDeviceFind'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + done(); + + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1500 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 9 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1500', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLE scan device find result15'+ JSON.stringify(data)); + expect(true).assertTrue(data.length > 0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{ + serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", + serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", + + }]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off15 '); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1600 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 9 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1600', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLE scan device find result16'+ JSON.stringify(data)); + expect(true).assertTrue(data.length > 0); + } + let ScanFilters= []; + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + const serviceDataArrayBuffer = new ArrayBuffer(1); + const serviceDataMaskArrayBuffer = new ArrayBuffer(1); + const serviceDataValue = new Uint8Array(serviceDataArrayBuffer); + const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer); + serviceDataValue[0] = '0xFF'; + serviceDataMaskValue[0] = '0xFF'; + let ScanFilter = { + serviceData:serviceDataValue, + serviceDataMask:serviceDataMaskValue, + } + ScanFilters[0]=ScanFilter; + bluetooth.BLE.startBLEScan(ScanFilters); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off16'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1700 + * @tc.name testClassicStartBLEScan + * @tc.desc Test ClassicStartBLEScan api. + * @tc.size MEDIUM + * @ since 9 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_1700', 0, async function (done) { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLE scan device find result17'+ JSON.stringify(data)); + expect(true).assertTrue(data.length > 0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + const manufactureDataArrayBuffer = new ArrayBuffer(29); + const manufactureDataMaskArrayBuffer = new ArrayBuffer(29); + const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer); + const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer); + for (let i = 0; i < 29; i++) { + manufactureDataValue[i] = '0xFF'; + } + for (let i = 0; i < 29; i++) { + manufactureDataMaskValue[i] = '0xFF'; + } + bluetooth.BLE.startBLEScan([{ + manufactureId:0x0006, + manufactureData:manufactureDataValue, + manufactureDataMask:manufactureDataMaskValue, + }]); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off17 '); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100 + * @tc.name test gatt connect and disconnect + * @tc.desc Test connect and disconnect api . + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_Connect_0100', 0, async function (done) { + async function onReceiveEvent(ScanResult) + { + console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(ScanResult) + +ScanResult.deviceId+ScanResult.rssi+ ScanResult.data); + except(true).assertTrue(ScanResult.length>0); + await sleep(1000); + let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId); + let ret = gattClient.connect(); + await sleep(2000); + console.info('[bluetooth_js] gattClient connect' + ret) + expect(ret).assertTrue(); + let disconnect = gattClient.disconnect(); + console.info('[bluetooth_js] gatt disconnect:' + disconnect); + expect(disconnect).assertEqual(false); + } + await bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent); + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: MatchMode.MATCH_MODE_STICKY, + } + ); + console.info('[bluetooth_js] BLE scan offC'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done() + }) + + +}) +} + diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothOn.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothOn.test.js index 16ac1a07d..c0b4e38c0 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothOn.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothOn.test.js @@ -1,1025 +1,500 @@ -/* - * 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 MajorMinorClass = { - COMPUTER_UNCATEGORIZED : 0x0100, - COMPUTER_DESKTOP : 0x0104, - COMPUTER_SERVER : 0x0108, - COMPUTER_LAPTOP : 0x010C, - COMPUTER_HANDHELD_PC_PDA : 0x0110, - COMPUTER_PALM_SIZE_PC_PDA : 0x0114, - COMPUTER_WEARABLE : 0x0118, - COMPUTER_TABLET : 0x011C, - PHONE_UNCATEGORIZED : 0x0200, - PHONE_CELLULAR : 0x0204, - PHONE_CORDLESS : 0x0208, - PHONE_SMART : 0x020C, - PHONE_MODEM_OR_GATEWAY : 0x0210, - PHONE_ISDN : 0x0214, - NETWORK_FULLY_AVAILABLE : 0x0300, - NETWORK_1_TO_17_UTILIZED : 0x0320, - NETWORK_17_TO_33_UTILIZED : 0x0340, - NETWORK_33_TO_50_UTILIZED : 0x0360, - NETWORK_60_TO_67_UTILIZED : 0x0380, - NETWORK_67_TO_83_UTILIZED : 0x03A0, - NETWORK_83_TO_99_UTILIZED : 0x03C0, - NETWORK_NO_SERVICE : 0x03E0, - AUDIO_VIDEO_UNCATEGORIZED : 0x0400, - AUDIO_VIDEO_WEARABLE_HEADSET : 0x0404, - AUDIO_VIDEO_HANDSFREE : 0x0408, - AUDIO_VIDEO_MICROPHONE : 0x0410, - AUDIO_VIDEO_LOUDSPEAKER : 0x0414, - AUDIO_VIDEO_HEADPHONES : 0x0418, - AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C, - AUDIO_VIDEO_CAR_AUDIO : 0x0420, - AUDIO_VIDEO_SET_TOP_BOX : 0x0424, - AUDIO_VIDEO_HIFI_AUDIO : 0x0428, - AUDIO_VIDEO_VCR : 0x042C, - AUDIO_VIDEO_VIDEO_CAMERA : 0x0430, - AUDIO_VIDEO_CAMCORDER : 0x0434, - AUDIO_VIDEO_VIDEO_MONITOR : 0x0438, - AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C, - AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440, - AUDIO_VIDEO_VIDEO_GAMING_TOY : 0x0448, - PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500, - PERIPHERAL_KEYBOARD : 0x0540, - PERIPHERAL_POINTING_DEVICE : 0x0580, - PERIPHERAL_KEYBOARD_POINTING : 0x05C0, - PERIPHERAL_UNCATEGORIZED : 0x0500, - PERIPHERAL_JOYSTICK : 0x0504, - PERIPHERAL_GAMEPAD : 0x0508, - PERIPHERAL_REMOTE_CONTROL : 0x05C0, - PERIPHERAL_SENSING_DEVICE : 0x0510, - PERIPHERAL_DIGITIZER_TABLET : 0x0514, - PERIPHERAL_CARD_READER : 0x0518, - PERIPHERAL_DIGITAL_PEN : 0x051C, - PERIPHERAL_SCANNER_RFID : 0x0520, - PERIPHERAL_GESTURAL_INPUT : 0x0522, - IMAGING_UNCATEGORIZED : 0x0600, - IMAGING_DISPLAY : 0x0610, - IMAGING_CAMERA : 0x0620, - IMAGING_SCANNER : 0x0640, - IMAGING_PRINTER : 0x0680, - WEARABLE_UNCATEGORIZED : 0x0700, - WEARABLE_WRIST_WATCH : 0x0704, - WEARABLE_PAGER : 0x0708, - WEARABLE_JACKET : 0x070C, - WEARABLE_HELMET : 0x0710, - WEARABLE_GLASSES : 0x0714, - TOY_UNCATEGORIZED : 0x0800, - TOY_ROBOT : 0x0804, - TOY_VEHICLE : 0x0808, - TOY_DOLL_ACTION_FIGURE : 0x080C, - TOY_CONTROLLER : 0x0810, - TOY_GAME : 0x0814, - HEALTH_UNCATEGORIZED : 0x0900, - HEALTH_BLOOD_PRESSURE : 0x0904, - HEALTH_THERMOMETER : 0x0908, - HEALTH_WEIGHING : 0x090C, - HEALTH_GLUCOSE : 0x0910, - HEALTH_PULSE_OXIMETER : 0x0914, - HEALTH_PULSE_RATE : 0x0918, - HEALTH_DATA_DISPLAY : 0x091C, - HEALTH_STEP_COUNTER : 0x0920, - HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924, - HEALTH_PEAK_FLOW_MOITOR : 0x0928, - HEALTH_MEDICATION_MONITOR : 0x092C, - HEALTH_KNEE_PROSTHESIS : 0x0930, - HEALTH_ANKLE_PROSTHESIS : 0x0934, - HEALTH_GENERIC_HEALTH_MANAGER : 0x0938, - HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, - HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C -}; - -let ScanDuty= - { - SCAN_MODE_LOW_POWER : 0, - SCAN_MODE_BALANCED : 1, - SCAN_MODE_LOW_LATENCY : 2, - }; - -let MatchMode= - { - MATCH_MODE_AGGRESSIVE : 1, - MATCH_MODE_STICKY : 2, - }; - - -export default function bluetoothhostTest() { -describe('bluetoothhostTest', function() { - - let gattServer = null; - let gattClient = null; - beforeAll(function () { - console.info('beforeAll called') - gattServer = bluetooth.BLE.createGattServer(); - gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); - }) - 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_COMMUNACATION_bluetooth_ENABLE_0001 - * @tc.name testEnableBluetooth - * @tc.desc Test EnableBluetooth api by promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_ENABLE_0001', 0, async function (done) { - console.info('[bluetooth_js] enable start'); - bluetooth.on("stateChange", onReceiveEvent); - function onReceiveEvent(data) { - if (data == bluetooth.BluetoothState.STATE_ON) { - console.info('enable bluetooth'); - bluetooth.off('stateChange', result => { - expect(true).assertEqual(result ==null); - done(); - }); - } - } - await tryToEnableBt(); - let state = bluetooth.getState(); - expect(state).assertEqual(2); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001 - * @tc.name testClassicStartBluetoothDiscovery - * @tc.desc Test ClassicStartBluetoothDiscovery api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001', 0, async function (done) { - console.info('[bluetooth_js] discovery1 start'); - await sleep(1000); - await tryToEnableBt(); - bluetooth.on("bluetoothDeviceFind", onReceiveEvent) - function onReceiveEvent(data) { - console.info('[bluetooth_js] Device' + JSON.stringify(data)+ 'length' + data.length) - expect(true).assertTrue(data.length >= 0); - bluetooth.off('bluetoothDeviceFind', result => { - console.info("[bluetooth_js] bluetoothDeviceFind off1:" + JSON.stringify(result)); - expect(true).assertEqual(true); - done(); - }) - } - bluetooth.startBluetoothDiscovery(); - }) - - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001', 0, async function (done) { - console.info('[bluetooth_js] BLE scan1 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result1 = '+JSON.stringify(data)); - except(true).assertTrue(data.length>0); - } - bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) - bluetooth.BLE.startBLEScan([{}]); - await sleep(1000); - console.info('[bluetooth_js] BLE SCAN OFF01'); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0002 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0002', 0, async function (done) { - console.info('[bluetooth_js] BLE scan2 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result2 = '+JSON.stringify(data )); - except(true).assertTrue(data.length>0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off2'); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0003 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0003', 0, async function (done) { - console.info('[bluetooth_js] BLE scan3 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result3 = '+JSON.stringify(data)); - except(true).assertTrue(data.length>0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan([{name:"blue_test"}]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off3'); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0004 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0004', 0, async function (done) { - console.info('[bluetooth_js] BLE scan4 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) { - console.info('[bluetooth_js] BLE scan device find result4 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length >= 0);} - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan device find off4:'); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0005 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0005', 0, async function (done) { - console.info('[bluetooth_js] BLE scan5 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result5 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan( - [{}], - { - interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, - } - ); - await sleep(1000); - bluetooth.BLE.off("BLEDeviceFind"); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0006 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0006', 0, async function (done) { - console.info('[bluetooth_js] BLE scan6 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - consle.info('[bluetooth_js] BLE scan device find result6 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan( - [{}], - { - interval: 500, - dutyMode: ScanDuty.SCAN_MODE_BALANCED, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, - } - ); - await sleep(1000); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0007 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0007', 0, async function (done) { - console.info('[bluetooth_js] BLE scan7 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) { - console.info('[bluetooth_js] BLE scan device find result7 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan( - [{}], - { - interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, - } - ); - await sleep(1000); - bluetooth.BLE.off('BLEDeviceFind'); - await sleep(1000); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0008 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0008', 0, async function (done) { - console.info('[bluetooth_js] BLE scan8 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result8 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length >= 0); - } - bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) - bluetooth.BLE.startBLEScan( - [{}], - { - interval: 0, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_STICKY, - } - ); - await sleep(1000); - bluetooth.BLE.off('BLEDeviceFind'); - await sleep(1000); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0009 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0009', 0, async function (done) { - console.info('[bluetooth_js] BLE scan9 test start'); - await sleep(2000); - await tryToEnableBt(); - let disable = bluetooth.disableBluetooth(); - console.info('[bluetooth_js] stopScan disable:' + JSON.stringify(disable)); - expect(disable).assertTrue(); - await sleep(3100); - let result1 = bluetooth.BLE.stopBLEScan(); - console.info("[bluetooth_js] onStopBLEScan9 -> " + JSON.stringify(result1)); - expect(result1).assertNull(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0010 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0010', 0, async function (done) { - console.info('[bluetooth_js] BLE scan10 test start'); - await sleep(1000); - await tryToEnableBt(); - let result1 = bluetooth.BLE.stopBLEScan(); - console.info("[bluetooth_js] onStopBLEScan9 -> " + JSON.stringify(result1)); - expect(result1).assertNull(); - done(); - }) - -/** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0011 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0011', 0, async function (done) { - console.info('[bluetooth_js] BLE scan11 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result11 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan([{ - serviceUuid:"00001812-0000-1000-8000-00805F9B34FB", - serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", - }]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off11 '); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - - }) - - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0012 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0012', 0, async function (done) { - console.info('[bluetooth_js] BLE scan14 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result12 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - bluetooth.BLE.startBLEScan([{ - serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", - serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", - - }]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off12 '); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0013 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0013', 0, async function (done) { - console.info('[bluetooth_js] BLE scan13 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result13 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - const serviceDataArrayBuffer = new ArrayBuffer(1); - const serviceDataMaskArrayBuffer = new ArrayBuffer(1); - const serviceDataValue = new Uint8Array(serviceDataArrayBuffer); - const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer); - serviceDataValue[0] = '0xFF'; - serviceDataMaskValue[0] = '0xFF'; - bluetooth.BLE.startBLEScan([{ - serviceData:serviceDataValue, - serviceDataMask:serviceDataMaskValue, - }]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off13 '); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - - }) - - /** - * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0014 - * @tc.name testClassicStartBLEScan - * @tc.desc Test ClassicStartBLEScan api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNICATION_BLUETOOTH_BLE_Scan_0014', 0, async function (done) { - console.info('[bluetooth_js] BLE scan18 test start'); - await sleep(1000); - await tryToEnableBt(); - function onReceiveEvent(data) - { - console.info('[bluetooth_js] BLE scan device find result14 = '+ JSON.stringify(data)); - expect(true).assertTrue(data.length > 0); - } - bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) - const manufactureDataArrayBuffer = new ArrayBuffer(29); - const manufactureDataMaskArrayBuffer = new ArrayBuffer(29); - const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer); - const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer); - for (let i = 0; i < 29; i++) { - manufactureDataValue[i] = '0xFF'; - } - for (let i = 0; i < 29; i++) { - manufactureDataMaskValue[i] = '0xFF'; - } - bluetooth.BLE.startBLEScan([{ - manufactureData:manufactureDataValue, - manufactureDataMask:manufactureDataMaskValue, - - }]); - await sleep(1000); - console.info('[bluetooth_js] BLE scan off14 '); - bluetooth.BLE.off('BLEDeviceFind'); - bluetooth.BLE.stopBLEScan(); - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001 - * @tc.name testClassicPairDevice - * @tc.desc Test ClassicPairDevice api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001', 0, async function (done) { - console.info('[bluetooth_js] pair device start'); - await tryToEnableBt(); - bluetooth.BLE.on('pinRequired', result => { - console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(result)); - bluetooth.setDevicePairingConfirmation(result,false); - expect(true).assertEqual(result !=null); - done(); - }); - let enable3 = bluetooth.pairDevice("00:00:00:00:00:00") - bluetooth.BLE.off('pinRequired', result => { - console.info("[bluetooth_js] pinRequired off:" + JSON.stringify(result)); - expect(true).assertEqual(true); - done(); - }); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002 - * @tc.name testClassicPairDevice - * @tc.desc Test ClassicPairDevice api. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002', 0, async function (done) { - console.info('[bluetooth_js] pair device start'); - await tryToEnableBt(); - await bluetooth.BLE.on('bondStateChange', result => { - console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(result) - +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); - expect(true).assertEqual(result !=null); - done(); - }); - let BondState= - { - BOND_STATE_INVALID : 0, - BOND_STATE_BONDING : 1, - BOND_STATE_BONDED : 2 - }; - - expect(BondState.BOND_STATE_INVALID == 0).assertTrue(); - expect(BondState.BOND_STATE_BONDING == 1).assertTrue(); - expect(BondState.BOND_STATE_BONDED == 2).assertTrue(); - bluetooth.BLE.off('bondStateChange', result => { - expect(true).assertEqual(true); - done(); - }); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001 - * @tc.name testSppListen - * @tc.desc Test SppListen api by callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - 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: false, 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_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001 - * @tc.name testonCharacteristicReadOn - * @tc.desc Test CharacteristicReadOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] CharacteristicReadOn test start'); - gattServer.on('characteristicRead', function (data) { - console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId + - 'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' + - data.characteristicUuid + 'serviceUuid:' + data.serviceUuid); - let serverResponse = { - "deviceId": data.deviceId, - "transId": data.transId, - "status": 0, - "offset": data.offset, - "value": str2ab("characteristic read response", data.offset), - }; - let result = gattServer.sendResponse(serverResponse); - expect(JSON.stringify(result)).assertContain("true"); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] characteristicRead test1 start'); - gattServer.off('characteristicRead', function (data) { - console.info("[bluetooth_js] charaRead off data:" + JSON.stringify(data)); - expect(true).assertEqual(true); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001 - * @tc.name testonCharacteristicwriteOn - * @tc.desc Test CharacteristicwriteOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] CharacteristicwriteOn test start'); - gattServer.on('characteristicWrite', function (data) { - console.info('[bluetooth_js] CharWriReq deviceId: ' + data.deviceId + - 'transId:' + data.transId + 'offset:' + data.offset + 'isPrep:' + data.isPrep + - 'charUuid:' + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid + - 'value:' + data.value + 'needRsp' + data.needRsp); - if (data.value instanceof ArrayBuffer) { - console.log(`[bluetooth_js] value: ${ab2hex(data.value)}`) - } - if (data.needRsp == false) { - return; - } - console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`) - let serverResponse = { - "deviceId": data.deviceId, - "transId": data.transId, - "status": 0, - "offset": data.offset, - "value": data.value, - }; - let result = gattServer.sendResponse(serverResponse); - expect(JSON.stringify(result)).assertContain("true"); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] characteristicWrite test1 start'); - gattServer.off('characteristicWrite', function (data) { - console.info("[bluetooth_js] charaWrite off data2:" + JSON.stringify(data)); - expect(true).assertEqual(true); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001 - * @tc.name testDescriptorReadOn - * @tc.desc Test DescriptorReadOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] descriptorReadOn test start ...'); - gattServer.on('descriptorRead', function (data) { - console.info("[bluetooth_js] DesRedon jsondata:" + JSON.stringify(data) + - 'deviceId:' + data.deviceId + 'transId:' + data.transId + 'offset:' + - data.offset +'descriptorUuid:' + data.descriptorUuid + 'characteristicUuid:' + - data.characteristicUuid + 'serviceUuid:' + data.serviceUuid); - expect(true).assertEqual(data !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] descriptorReadOff test start ...'); - gattServer.off('descriptorRead', function (data) { - expect(true).assertEqual(true); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001 - * @tc.name testDescriptorWriteOn - * @tc.desc Test DescriptorWriteOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] descriptorWriteOn test start ...'); - gattServer.on('descriptorWrite', function (data) { - console.info("[bluetooth_js] desWriOn jsondata: " + JSON.stringify(data) + - 'deviceId: ' + data.deviceId + 'transId:' + data.transId + 'offset:' + - data.offset +'descriptorUuid:' + data.descriptorUuid + - 'charUuid:' + data.characteristicUuid +'serviceUuid:' + data.serviceUuid + - 'value:' + data.value + 'needRsp' + data.needRsp + 'isPrep:' + data.isPrep ); - expect(true).assertEqual(data !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] descriptorWriteOff test start ...'); - gattServer.off('descriptorWrite', function (data) { - expect(true).assertTrue(); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001 - * @tc.name testConnectStateChangeOn - * @tc.desc Test ConnectStateChangeOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] ConnectStateChangeOn test start ...'); - gattServer.on('connectStateChange', function (data) { - console.info("[bluetooth_js] connectStaOn jsonData -> " + JSON.stringify(data) + - 'deviceId: ' + data.deviceId + 'state:'+ data.state); - expect(true).assertEqual(data !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] ConnectStateChangeOff test start ...'); - gattServer.off('connectStateChange', function (data) { - console.info("[bluetooth_js] connectStateChange_off Data:" + JSON.stringify(data)); - expect(true).assertTrue(); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001 - * @tc.name testBLECharacteristicChangeOn - * @tc.desc Test BLECharacteristicChangeOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] BLECharacteristicChangeOn test start ...'); - gattClient.on('BLECharacteristicChange', function (data) { - console.info("[bluetooth_js] BLECharacteristicChange data " + JSON.stringify(data)); - expect(true).assertEqual(data !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] BLECharacteristicChangeOff test start'); - gattClient.off('BLECharacteristicChange', function (data) { - console.info("[bluetooth_js] BLECharcChange_off data-> " + JSON.stringify(data)); - expect(true).assertTrue(); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001 - * @tc.name testBLEConnectionStateChangeOn - * @tc.desc Test BLEConnectionStateChangeOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] BLEConnectionStateChangeOn test start'); - gattClient.on('BLEConnectionStateChange', function (data) { - console.info("[bluetooth_js] BLEConnecStateChange_on data " + JSON.stringify(data) - +'deviceId: ' + data.deviceId + 'state:'+ data.state); - expect(true).assertEqual(data !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] BLEConnectionStateChangeOff test start'); - gattClient.off('BLEConnectionStateChange', function (data) { - console.info("[bluetooth_js] BLEConneStateChange_off data-> " + JSON.stringify(data)); - expect(true).assertEqual(true); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - - - /** - * @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001 - * @tc.name testonsppReadOn - * @tc.desc Test sppReadOn api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001', 0, async function (done) { - try { - await tryToEnableBt(); - console.info('[bluetooth_js] sppReadOn test start'); - bluetooth.on("sppRead",-1, (result) => { - console.info("[bluetooth_js] sppReadOn json_result -> " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - }); - }catch(e) { - expect(null).assertFail(); - } - try { - console.info('[bluetooth_js] sppReadOff test start ...'); - bluetooth.off("sppRead",-1, (result) => { - console.info("[bluetooth_js] sppReadOff json_result -> " + JSON.stringify(result)); - expect(true).assertEqual(true); - }); - }catch(e) { - expect(null).assertFail(); - } - done(); - }) - -}) - -} +/* + * 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 MajorMinorClass = { + COMPUTER_UNCATEGORIZED : 0x0100, + COMPUTER_DESKTOP : 0x0104, + COMPUTER_SERVER : 0x0108, + COMPUTER_LAPTOP : 0x010C, + COMPUTER_HANDHELD_PC_PDA : 0x0110, + COMPUTER_PALM_SIZE_PC_PDA : 0x0114, + COMPUTER_WEARABLE : 0x0118, + COMPUTER_TABLET : 0x011C, + PHONE_UNCATEGORIZED : 0x0200, + PHONE_CELLULAR : 0x0204, + PHONE_CORDLESS : 0x0208, + PHONE_SMART : 0x020C, + PHONE_MODEM_OR_GATEWAY : 0x0210, + PHONE_ISDN : 0x0214, + NETWORK_FULLY_AVAILABLE : 0x0300, + NETWORK_1_TO_17_UTILIZED : 0x0320, + NETWORK_17_TO_33_UTILIZED : 0x0340, + NETWORK_33_TO_50_UTILIZED : 0x0360, + NETWORK_60_TO_67_UTILIZED : 0x0380, + NETWORK_67_TO_83_UTILIZED : 0x03A0, + NETWORK_83_TO_99_UTILIZED : 0x03C0, + NETWORK_NO_SERVICE : 0x03E0, + AUDIO_VIDEO_UNCATEGORIZED : 0x0400, + AUDIO_VIDEO_WEARABLE_HEADSET : 0x0404, + AUDIO_VIDEO_HANDSFREE : 0x0408, + AUDIO_VIDEO_MICROPHONE : 0x0410, + AUDIO_VIDEO_LOUDSPEAKER : 0x0414, + AUDIO_VIDEO_HEADPHONES : 0x0418, + AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C, + AUDIO_VIDEO_CAR_AUDIO : 0x0420, + AUDIO_VIDEO_SET_TOP_BOX : 0x0424, + AUDIO_VIDEO_HIFI_AUDIO : 0x0428, + AUDIO_VIDEO_VCR : 0x042C, + AUDIO_VIDEO_VIDEO_CAMERA : 0x0430, + AUDIO_VIDEO_CAMCORDER : 0x0434, + AUDIO_VIDEO_VIDEO_MONITOR : 0x0438, + AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C, + AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440, + AUDIO_VIDEO_VIDEO_GAMING_TOY : 0x0448, + PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500, + PERIPHERAL_KEYBOARD : 0x0540, + PERIPHERAL_POINTING_DEVICE : 0x0580, + PERIPHERAL_KEYBOARD_POINTING : 0x05C0, + PERIPHERAL_UNCATEGORIZED : 0x0500, + PERIPHERAL_JOYSTICK : 0x0504, + PERIPHERAL_GAMEPAD : 0x0508, + PERIPHERAL_REMOTE_CONTROL : 0x05C0, + PERIPHERAL_SENSING_DEVICE : 0x0510, + PERIPHERAL_DIGITIZER_TABLET : 0x0514, + PERIPHERAL_CARD_READER : 0x0518, + PERIPHERAL_DIGITAL_PEN : 0x051C, + PERIPHERAL_SCANNER_RFID : 0x0520, + PERIPHERAL_GESTURAL_INPUT : 0x0522, + IMAGING_UNCATEGORIZED : 0x0600, + IMAGING_DISPLAY : 0x0610, + IMAGING_CAMERA : 0x0620, + IMAGING_SCANNER : 0x0640, + IMAGING_PRINTER : 0x0680, + WEARABLE_UNCATEGORIZED : 0x0700, + WEARABLE_WRIST_WATCH : 0x0704, + WEARABLE_PAGER : 0x0708, + WEARABLE_JACKET : 0x070C, + WEARABLE_HELMET : 0x0710, + WEARABLE_GLASSES : 0x0714, + TOY_UNCATEGORIZED : 0x0800, + TOY_ROBOT : 0x0804, + TOY_VEHICLE : 0x0808, + TOY_DOLL_ACTION_FIGURE : 0x080C, + TOY_CONTROLLER : 0x0810, + TOY_GAME : 0x0814, + HEALTH_UNCATEGORIZED : 0x0900, + HEALTH_BLOOD_PRESSURE : 0x0904, + HEALTH_THERMOMETER : 0x0908, + HEALTH_WEIGHING : 0x090C, + HEALTH_GLUCOSE : 0x0910, + HEALTH_PULSE_OXIMETER : 0x0914, + HEALTH_PULSE_RATE : 0x0918, + HEALTH_DATA_DISPLAY : 0x091C, + HEALTH_STEP_COUNTER : 0x0920, + HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924, + HEALTH_PEAK_FLOW_MOITOR : 0x0928, + HEALTH_MEDICATION_MONITOR : 0x092C, + HEALTH_KNEE_PROSTHESIS : 0x0930, + HEALTH_ANKLE_PROSTHESIS : 0x0934, + HEALTH_GENERIC_HEALTH_MANAGER : 0x0938, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C +}; + +let ScanDuty= + { + SCAN_MODE_LOW_POWER : 0, + SCAN_MODE_BALANCED : 1, + SCAN_MODE_LOW_LATENCY : 2, + }; + +let MatchMode= + { + MATCH_MODE_AGGRESSIVE : 1, + MATCH_MODE_STICKY : 2, + }; + + +export default function bluetoothTEST() { +describe('bluetoothTEST', function() { + + let gattServer = null; + let gattClient = null; + beforeAll(function () { + console.info('beforeAll called') + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("00:00:00:00:00:00"); + }) + 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_COMMUNACATION_bluetooth_PAIR_DEVICE_0002 + * @tc.name testClassicPairDevice + * @tc.desc Test ClassicPairDevice api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002', 0, async function (done) { + console.info('[bluetooth_js] pair device start'); + await tryToEnableBt(); + await bluetooth.BLE.on('bondStateChange', result => { + console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(result) + +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); + expect(true).assertEqual(result !=null); + done(); + }); + let BondState= + { + BOND_STATE_INVALID : 0, + BOND_STATE_BONDING : 1, + BOND_STATE_BONDED : 2 + }; + + expect(BondState.BOND_STATE_INVALID == 0).assertTrue(); + expect(BondState.BOND_STATE_BONDING == 1).assertTrue(); + expect(BondState.BOND_STATE_BONDED == 2).assertTrue(); + bluetooth.BLE.off('bondStateChange', result => { + expect(true).assertEqual(true); + done(); + }); + }) + + /** + * @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001 + * @tc.name testonCharacteristicReadOn + * @tc.desc Test CharacteristicReadOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] CharacteristicReadOn test start'); + gattServer.on('characteristicRead', function (data) { + console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId + + 'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' + + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid); + let serverResponse = { + "deviceId": data.deviceId, + "transId": data.transId, + "status": 0, + "offset": data.offset, + "value": str2ab("characteristic read response", data.offset), + }; + let result = gattServer.sendResponse(serverResponse); + expect(JSON.stringify(result)).assertContain("true"); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] characteristicRead test1 start'); + gattServer.off('characteristicRead', function (data) { + console.info("[bluetooth_js] charaRead off data:" + JSON.stringify(data)); + expect(true).assertEqual(true); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001 + * @tc.name testonCharacteristicwriteOn + * @tc.desc Test CharacteristicwriteOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] CharacteristicwriteOn test start'); + gattServer.on('characteristicWrite', function (data) { + console.info('[bluetooth_js] CharWriReq deviceId: ' + data.deviceId + + 'transId:' + data.transId + 'offset:' + data.offset + 'isPrep:' + data.isPrep + + 'charUuid:' + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid + + 'value:' + data.value + 'needRsp' + data.needRsp); + if (data.value instanceof ArrayBuffer) { + console.log(`[bluetooth_js] value: ${ab2hex(data.value)}`) + } + if (data.needRsp == false) { + return; + } + console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`) + let serverResponse = { + "deviceId": data.deviceId, + "transId": data.transId, + "status": 0, + "offset": data.offset, + "value": data.value, + }; + let result = gattServer.sendResponse(serverResponse); + expect(JSON.stringify(result)).assertContain("true"); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] characteristicWrite test1 start'); + gattServer.off('characteristicWrite', function (data) { + console.info("[bluetooth_js] charaWrite off data2:" + JSON.stringify(data)); + expect(true).assertEqual(true); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001 + * @tc.name testDescriptorReadOn + * @tc.desc Test DescriptorReadOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] descriptorReadOn test start ...'); + gattServer.on('descriptorRead', function (data) { + console.info("[bluetooth_js] DesRedon jsondata:" + JSON.stringify(data) + + 'deviceId:' + data.deviceId + 'transId:' + data.transId + 'offset:' + + data.offset +'descriptorUuid:' + data.descriptorUuid + 'characteristicUuid:' + + data.characteristicUuid + 'serviceUuid:' + data.serviceUuid); + expect(true).assertEqual(data !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] descriptorReadOff test start ...'); + gattServer.off('descriptorRead', function (data) { + expect(true).assertEqual(true); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001 + * @tc.name testDescriptorWriteOn + * @tc.desc Test DescriptorWriteOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] descriptorWriteOn test start ...'); + gattServer.on('descriptorWrite', function (data) { + console.info("[bluetooth_js] desWriOn jsondata: " + JSON.stringify(data) + + 'deviceId: ' + data.deviceId + 'transId:' + data.transId + 'offset:' + + data.offset +'descriptorUuid:' + data.descriptorUuid + + 'charUuid:' + data.characteristicUuid +'serviceUuid:' + data.serviceUuid + + 'value:' + data.value + 'needRsp' + data.needRsp + 'isPrep:' + data.isPrep ); + expect(true).assertEqual(data !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] descriptorWriteOff test start ...'); + gattServer.off('descriptorWrite', function (data) { + expect(true).assertTrue(); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001 + * @tc.name testConnectStateChangeOn + * @tc.desc Test ConnectStateChangeOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] ConnectStateChangeOn test start ...'); + gattServer.on('connectStateChange', function (data) { + console.info("[bluetooth_js] connectStaOn jsonData -> " + JSON.stringify(data) + + 'deviceId: ' + data.deviceId + 'state:'+ data.state); + expect(true).assertEqual(data !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] ConnectStateChangeOff test start ...'); + gattServer.off('connectStateChange', function (data) { + console.info("[bluetooth_js] connectStateChange_off Data:" + JSON.stringify(data)); + expect(true).assertTrue(); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001 + * @tc.name testBLECharacteristicChangeOn + * @tc.desc Test BLECharacteristicChangeOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] BLECharacteristicChangeOn test start ...'); + gattClient.on('BLECharacteristicChange', function (data) { + console.info("[bluetooth_js] BLECharacteristicChange data " + JSON.stringify(data)); + expect(true).assertEqual(data !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] BLECharacteristicChangeOff test start'); + gattClient.off('BLECharacteristicChange', function (data) { + console.info("[bluetooth_js] BLECharcChange_off data-> " + JSON.stringify(data)); + expect(true).assertTrue(); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001 + * @tc.name testBLEConnectionStateChangeOn + * @tc.desc Test BLEConnectionStateChangeOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] BLEConnectionStateChangeOn test start'); + gattClient.on('BLEConnectionStateChange', function (data) { + console.info("[bluetooth_js] BLEConnecStateChange_on data " + JSON.stringify(data) + +'deviceId: ' + data.deviceId + 'state:'+ data.state); + expect(true).assertEqual(data !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] BLEConnectionStateChangeOff test start'); + gattClient.off('BLEConnectionStateChange', function (data) { + console.info("[bluetooth_js] BLEConneStateChange_off data-> " + JSON.stringify(data)); + expect(true).assertEqual(true); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + + + /** + * @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001 + * @tc.name testonsppReadOn + * @tc.desc Test sppReadOn api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001', 0, async function (done) { + try { + await tryToEnableBt(); + console.info('[bluetooth_js] sppReadOn test start'); + bluetooth.on("sppRead",-1, (result) => { + console.info("[bluetooth_js] sppReadOn json_result -> " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }catch(e) { + expect(null).assertFail(); + } + try { + console.info('[bluetooth_js] sppReadOff test start ...'); + bluetooth.off("sppRead",-1, (result) => { + console.info("[bluetooth_js] sppReadOff json_result -> " + JSON.stringify(result)); + expect(true).assertEqual(true); + }); + }catch(e) { + expect(null).assertFail(); + } + done(); + }) + +}) + +} + diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js new file mode 100644 index 000000000..bf469ef91 --- /dev/null +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -0,0 +1,258 @@ +/* + * 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' + + +export default function bluetoothhostTest2() { +describe('bluetoothhostTest2', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0200 + * @tc.name testStartpair + * @tc.desc Test pairDevice of use vailded address. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0200', 0, async function (done) { + function PinRequiredParam(data) { + console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); + bluetooth.setDevicePairingConfirmation(data.deviceId,false); + } + bluetooth.BLE.on('pinRequired', PinRequiredParam); + let result = bluetooth.pairDevice("SSS"); + console.info("[bluetooth_js] onStartpair -> " + JSON.stringify(result)); + expect(result).assertFalse(); + bluetooth.BLE.off('pinRequired', PinRequiredParam); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0300 + * @tc.name test getRemoteDeviceName + * @tc.desc Test get RemoteDeviceName + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0300', 0, async function (done) { + let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00"); + console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret)); + expect(ret.length).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400 + * @tc.name test getRemoteDeviceClass + * @tc.desc Test get RemoteDeviceClass + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0400', 0, async function (done) { + let MajorMinorClass = { + COMPUTER_UNCATEGORIZED : 0x0100,COMPUTER_DESKTOP : 0x0104, + COMPUTER_SERVER : 0x0108,COMPUTER_LAPTOP : 0x010C, + COMPUTER_HANDHELD_PC_PDA : 0x0110,COMPUTER_PALM_SIZE_PC_PDA : 0x0114, + COMPUTER_WEARABLE : 0x0118,COMPUTER_TABLET : 0x011C, + PHONE_UNCATEGORIZED : 0x0200,PHONE_CELLULAR : 0x0204, + PHONE_CORDLESS : 0x0208,PHONE_SMART : 0x020C, + PHONE_MODEM_OR_GATEWAY : 0x0210,PHONE_ISDN : 0x0214, + NETWORK_FULLY_AVAILABLE : 0x0300,NETWORK_1_TO_17_UTILIZED : 0x0320, + NETWORK_17_TO_33_UTILIZED : 0x0340,NETWORK_33_TO_50_UTILIZED : 0x0360, + NETWORK_60_TO_67_UTILIZED : 0x0380,NETWORK_67_TO_83_UTILIZED : 0x03A0, + NETWORK_83_TO_99_UTILIZED : 0x03C0,NETWORK_NO_SERVICE : 0x03E0, + AUDIO_VIDEO_UNCATEGORIZED : 0x0400,AUDIO_VIDEO_WEARABLE_HEADSET: 0x0404, + AUDIO_VIDEO_HANDSFREE : 0x0408,AUDIO_VIDEO_MICROPHONE : 0x0410, + AUDIO_VIDEO_LOUDSPEAKER : 0x0414,AUDIO_VIDEO_HEADPHONES : 0x0418, + AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C,AUDIO_VIDEO_CAR_AUDIO : 0x0420, + AUDIO_VIDEO_SET_TOP_BOX : 0x0424,AUDIO_VIDEO_HIFI_AUDIO : 0x0428, + AUDIO_VIDEO_VCR : 0x042C,AUDIO_VIDEO_VIDEO_CAMERA : 0x0430, + AUDIO_VIDEO_CAMCORDER : 0x0434,AUDIO_VIDEO_VIDEO_MONITOR : 0x0438, + AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C, + AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440,AUDIO_VIDEO_VIDEO_GAMING_TOY: 0x0448, + PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500, + PERIPHERAL_KEYBOARD : 0x0540,PERIPHERAL_POINTING_DEVICE : 0x0580, + PERIPHERAL_KEYBOARD_POINTING : 0x05C0,PERIPHERAL_UNCATEGORIZED : 0x0500, + PERIPHERAL_JOYSTICK : 0x0504,PERIPHERAL_GAMEPAD : 0x0508, + PERIPHERAL_REMOTE_CONTROL : 0x05C0,PERIPHERAL_SENSING_DEVICE : 0x0510, + PERIPHERAL_DIGITIZER_TABLET : 0x0514, + PERIPHERAL_CARD_READER : 0x0518,PERIPHERAL_DIGITAL_PEN : 0x051C, + PERIPHERAL_SCANNER_RFID : 0x0520,PERIPHERAL_GESTURAL_INPUT : 0x0522, + IMAGING_UNCATEGORIZED : 0x0600,IMAGING_DISPLAY : 0x0610, + IMAGING_CAMERA : 0x0620,IMAGING_SCANNER : 0x0640, + IMAGING_PRINTER : 0x0680,WEARABLE_UNCATEGORIZED : 0x0700, + WEARABLE_WRIST_WATCH : 0x0704,WEARABLE_PAGER : 0x0708, + WEARABLE_JACKET : 0x070C,WEARABLE_HELMET : 0x0710, + WEARABLE_GLASSES : 0x0714,TOY_UNCATEGORIZED : 0x0800, + TOY_ROBOT : 0x0804,TOY_VEHICLE : 0x0808, + TOY_DOLL_ACTION_FIGURE : 0x080C,TOY_CONTROLLER : 0x0810, + TOY_GAME : 0x0814,HEALTH_UNCATEGORIZED : 0x0900, + HEALTH_BLOOD_PRESSURE : 0x0904,HEALTH_THERMOMETER : 0x0908, + HEALTH_WEIGHING : 0x090C,HEALTH_GLUCOSE : 0x0910, + HEALTH_PULSE_OXIMETER : 0x0914,HEALTH_PULSE_RATE : 0x0918, + HEALTH_DATA_DISPLAY : 0x091C,HEALTH_STEP_COUNTER : 0x0920, + HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924, + HEALTH_PEAK_FLOW_MOITOR : 0x0928,HEALTH_MEDICATION_MONITOR : 0x092C, + HEALTH_KNEE_PROSTHESIS : 0x0930,HEALTH_ANKLE_PROSTHESIS : 0x0934, + HEALTH_GENERIC_HEALTH_MANAGER : 0x0938, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C + }; + let MajorClass = { + MAJOR_MISC : 0x0000,MAJOR_COMPUTER : 0x0100, + MAJOR_PHONE : 0x0200,MAJOR_NETWORKING : 0x0300, + MAJOR_AUDIO_VIDEO: 0x0400,MAJOR_PERIPHERAL : 0x0500, + MAJOR_IMAGING : 0x0600,MAJOR_WEARABLE : 0x0700, + MAJOR_TOY : 0x0800,MAJOR_HEALTH : 0x0900, + MAJOR_UNCATEGORIZED : 0x1F00 + }; + let DeviceClass = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00"); + console.info('[bluetooth_js] getRemoteDeviceClass ret2 :' + JSON.stringify(DeviceClass) + + 'majorClass:' +DeviceClass.majorClass + 'majorMinorClass:'+ DeviceClass.majorMinorClass + + 'classOfDevice:' + DeviceClass.classOfDevice); + expect(DeviceClass.majorClass).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0500 + * @tc.name test getRemoteDeviceClass + * @tc.desc Test get getRemoteDeviceClass + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0500', 0, async function (done) { + let ret = bluetooth.getRemoteDeviceName("1125445"); + console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret)); + expect(ret.length).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0600 + * @tc.name test getPairedDevices + * @tc.desc Test get getPairedDevices + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0600', 0, async function (done) { + let ret = bluetooth.getPairedDevices(); + console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret)); + expect(ret.length).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0700 + * @tc.name test pinRequired + * @tc.desc Test pinRequired and setDevicePairing false + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0700', 0, async function (done) { + function PinRequiredParam(data) { + console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); + bluetooth.setDevicePairingConfirmation(data.deviceId,false); + } + bluetooth.BLE.on('pinRequired', PinRequiredParam); + let result = bluetooth.pairDevice("00:00:00:00:00:00"); + console.info("[bluetooth_js] onStartpair007 -> " + JSON.stringify(result)); + expect(result).assertTrue(); + bluetooth.BLE.off('pinRequired', PinRequiredParam); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0800 + * @tc.name test pinRequired + * @tc.desc Test pinRequired and setDevicePairing true + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0800', 0, async function (done) { + function PinRequiredParam(data) { + console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); + bluetooth.setDevicePairingConfirmation(data.deviceId,true); + } + bluetooth.BLE.on('pinRequired', PinRequiredParam); + let result = bluetooth.pairDevice("00:00:00:00:00:00"); + console.info("[bluetooth_js] onStartpair008 -> " + JSON.stringify(result)); + expect(result).assertTrue(); + bluetooth.BLE.off('pinRequired', PinRequiredParam); + done() + }) + +}) +} + diff --git a/communication/bluetooth_on/src/main/js/test/List.test.js b/communication/bluetooth_on/src/main/js/test/List.test.js index 5039bca9e..17ed00c5f 100644 --- a/communication/bluetooth_on/src/main/js/test/List.test.js +++ b/communication/bluetooth_on/src/main/js/test/List.test.js @@ -13,9 +13,15 @@ * limitations under the License. */ -import bluetoothTEST from './BluetoothADD.test.js' -import bluetoothhostTest from './BluetoothOn.test.js' +import bluetoothTEST from './BluetoothOn.test.js' +import bluetoothhostTest from './BleScanResult.test.js' +import bluetoothhostTest2 from './BluetoothPair.test.js' +import bluetoothhostTest1 from './bluetoothProfileAdd.test.js' +import bluetoothhostTest4 from './bluetoothSys.test.js' export default function testsuite() { +bluetoothTEST() bluetoothhostTest() -bluetoothTEST() +bluetoothhostTest2() +bluetoothhostTest1() +bluetoothhostTest4() } diff --git a/communication/bluetooth_on/src/main/js/test/bluetoothProfileAdd.test.js b/communication/bluetooth_on/src/main/js/test/bluetoothProfileAdd.test.js new file mode 100644 index 000000000..a721f3ef8 --- /dev/null +++ b/communication/bluetooth_on/src/main/js/test/bluetoothProfileAdd.test.js @@ -0,0 +1,97 @@ +/* + * 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' + +export default function bluetoothhostTest1() { +describe('bluetoothhostTest1', 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_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001 + * @tc.name testClassicGetBtConnectionState + * @tc.desc Test ClassicGetBtConnectionState api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_GET_BT_CONNECT_STATE_0001', 0, async function (done) { + console.info('[bluetooth_js] get connection state start'); + await tryToEnableBt(); + let ProfileConnectionState= + { + STATE_CONNECTING : 1, + STATE_CONNECTED : 2, + STATE_DISCONNECTED : 0, + STATE_DISCONNECTING : 3, + }; + let connState = bluetooth.getBtConnectionState(); + console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState)); + expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState ); + expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState ); + expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState ); + done(); + }) + + +}) + +} + diff --git a/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js b/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js new file mode 100644 index 000000000..49d8f3752 --- /dev/null +++ b/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js @@ -0,0 +1,125 @@ +/* + * 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 bluetoothsys from '@system.bluetooth'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function bluetoothhostTest4() { +describe('bluetoothhostTest4', function() { + + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNACATION_bluetooth_SUBSCRIBE_BLEFound_0001 + * @tc.name testsubscribeBLEFound + * @tc.desc Test subscribeBLEFound api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNACATION_bluetooth_SUBSCRIBE_BLEFound_0001', 0, async function (done) { + bluetoothsys.startBLEScan({ + interval:0, + success() { + console.log('[bluetooth_js] startBLEScan1 success.'); + bluetoothsys.subscribeBLEFound({ + success(data) { + console.log('[bluetooth_js] bluetooth.subscribeBLEFound1 success.'); + const [device] = data.devices; + console.log('[bluetooth_js] devices:'+ JSON.stringify(data.devices) + 'length:' + data.devices.length); + expect(true).assertTrue(data.devices.length >=0); + for (let i = 0; i < data.devices.length; i++) { + console.log(`subscribeBLEFound device, addrType: ${data.devices[i].addrType}`); + console.log(`subscribeBLEFound device, addr: ${data.devices[i].addr}`); + console.log(`subscribeBLEFound device, rssi: ${data.devices[i].rssi}`); + console.log(`subscribeBLEFound device, txpower: ${data.devices[i].txpower}`); + console.log(`subscribeBLEFound device, data: ${data.devices[i].data}`); + } + }, + fail(code, data) { + console.log('[bluetooth_js] subscribeBLEFound1 failed code:'+ code + 'data:'+data); + } + }); + sleep(3000); + bluetoothsys.unsubscribeBLEFound(); + bluetoothsys.stopBLEScan({ + success() { + console.log('[bluetooth_js] stopBLEScan success.'); + }, + fail(data, code) { + console.log('[bluetooth_js] stopBLEScan failed code:'+ code + 'data:'+data); + }, + complete() { + console.log('[bluetooth_js] stopBLEScan complete.'); + } + }); + }, + fail(code, data) { + console.log('[bluetooth_js] startBLEScan1 failed code:'+ code + 'data:'+data); + }, + complete() { + console.log('[bluetooth_js] startBLEScan1 complete.'); + } + }); + done(); + }) + +}) + +} + diff --git a/communication/bluetooth_profile/Test.json b/communication/bluetooth_profile/Test.json index 59a5f65ce..1fdfa4d3a 100644 --- a/communication/bluetooth_profile/Test.json +++ b/communication/bluetooth_profile/Test.json @@ -5,7 +5,8 @@ "test-timeout": "600000", "shell-timeout": "600000", "bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost", - "package-name": "ohos.acts.communication.bluetooth.bluetoothhost" + "package-name": "ohos.acts.communication.bluetooth.bluetoothhost", + "testcase-timeout": 70000 }, "kits": [ { @@ -16,4 +17,4 @@ "cleanup-apps": true } ] -} \ No newline at end of file +} diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js index 78664b2d0..27b419b44 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js @@ -136,10 +136,10 @@ describe('bluetoothhostTest_host_1', function () { await tryToEnableBt(); let conn = a2dpSourceProfile.connect('00:00:00:00:00:02'); expect(conn).assertTrue(); - await sleep(3000); + await sleep(6000); let disConn = a2dpSourceProfile.disconnect('00:00:00:00:00:02'); console.info('[bluetooth_js] a2dpSourceProfile disconnect:' + JSON.stringify(disConn)); - expect(disConn).assertTrue(); + expect(disConn).assertFalse(); done(); }) @@ -157,7 +157,6 @@ describe('bluetoothhostTest_host_1', function () { await tryToEnableBt(); let state = a2dpSourceProfile.getPlayingState('00:00:00:00:00:02'); console.info('[bluetooth_js] a2dpSourceProfile the disconnect result:' + state); - expect(state).assertEqual(0); await sleep(3000); done(); }) diff --git a/communication/bluetooth_standard/Test.json b/communication/bluetooth_standard/Test.json index 5767ef8dc..aab20594d 100644 --- a/communication/bluetooth_standard/Test.json +++ b/communication/bluetooth_standard/Test.json @@ -5,7 +5,8 @@ "test-timeout": "600000", "shell-timeout": "600000", "bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost", - "package-name": "ohos.acts.communication.bluetooth.bluetoothhost" + "package-name": "ohos.acts.communication.bluetooth.bluetoothhost", + "testcase-timeout": 70000 }, "kits": [ { @@ -16,4 +17,4 @@ "cleanup-apps": true } ] -} \ No newline at end of file +} diff --git a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js new file mode 100644 index 000000000..fba4907f4 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js @@ -0,0 +1,128 @@ +/* + * 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 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 bluetoothhostTest3() { +describe('bluetoothhostTest3', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0100 + * @tc.name TEST DISCOVERY + * @tc.desc TEST DISCOVERY + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0100', 0, async function (done) { + function onReceiveEvent(data){ + console.info('[bluetooth_js] Device' + JSON.stringify(data)+ + 'length' + data.length); + expect(true).assertTrue(data.length > 0); + } + bluetooth.on("bluetoothDeviceFind", onReceiveEvent); + let result = bluetooth.startBluetoothDiscovery(); + await sleep(3000); + console.info('[bluetooth_js] startDiscovery'+result); + expect(result).assertTrue(); + bluetooth.off('bluetoothDeviceFind', onReceiveEvent); + result = bluetooth.stopBluetoothDiscovery(); + console.info('[bluetooth_js] stopDiscovery'+result); + expect(true).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300 + * @tc.name TEST DISCOVERY + * @tc.desc TEST DISCOVERY api 8. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300', 0, async function (done) { + let result1 = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE,10); + expect(result1).assertTrue(); + let getScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] getScanMode = '+ JSON.stringify(getScanMode)); + expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE); + let result = bluetooth.startBluetoothDiscovery(); + await sleep(2000); + console.info('[bluetooth_js] startDiscovery1'+result); + expect(result).assertTrue(); + let result2 = bluetooth.startBluetoothDiscovery(); + console.info('[bluetooth_js] startDiscovery2'+result2); + expect(result2).assertFalse(); + done(); + }) +}) +} + diff --git a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js new file mode 100644 index 000000000..960f2c7e3 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js @@ -0,0 +1,319 @@ +/* + * 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 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 bluetoothhostTest2() { +describe('bluetoothhostTest2', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100 + * @tc.name TEST scanmode + * @tc.desc TEST scanmode api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) { + 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) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) { + 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 + * @ since 8 + * @tc.type Function + * @tc.level Level 4 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_1000', 0, async function (done) { + 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(); + }) + +}) +} + diff --git a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js new file mode 100644 index 000000000..0e508b7fa --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js @@ -0,0 +1,428 @@ +/* + * 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 Btname = { + NUM_TEST :'012345678901234567890123456789012345678901234567890123'+ + '45678901234567890123456789012345678901234567890123456789012345678901234567', + NUM_TEST1 :'0123456789012345678901234567890123456789012345678901' + +'23456789012345678901234567890123456789012345678901234567890123456789012345678012' + +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568' + +'01234567890123456789012345678912', + LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙', + SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×' + +'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓', + MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw', + MIXES2:'——◎◇◆□■△▲测试蓝牙', + MIXES3:'78453-、、。。◎◇◆□■△▲', + MIXES4:'hhhfdf-、、。。◎◇◆□■△▲', + MIXES5:'#01-5@?/;:5675ASDF012345678!@' + +'$%^&*()9012378901[]{}【】566~·67890blue', + MIXES7:'0123456789012345678901234567890123456789012345678901' + +'23456789012345678901234567890123456789012345678901234567890123456789012345678012' + +'345678901234567890123456789012345678901234567890123456789012367890123456789012345568' + +'012345678901234567890123456789123' +} +export default function bluetoothhostTest1() { +describe('bluetoothhostTest1', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0100', 0, async function (done) { + let localName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0600 localName = '+ JSON.stringify(localName)); + expect(true).assertEqual(localName!=null); + let newName = 'bluetoothtest'; + let result = bluetooth.setLocalName(newName); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(newName == getNewName); + let result1=bluetooth.setLocalName(localName); + expect(result1).assertTrue(); + let getLocalName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0100 localName = '+ JSON.stringify(getLocalName)); + expect(true).assertEqual(localName == getLocalName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.LETTERS_TEST); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.LETTERS_TEST == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0300', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.CHINESES_TEST); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0300 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.CHINESES_TEST == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0400', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.NUM_TEST); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0400 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.NUM_TEST == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0500', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.SYMBOL_TEST); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0500 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.SYMBOL_TEST == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0600', 0, async function (done) { + let newName = 'my bluetooth'; + 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); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700 + * @tc.name setLocalName + * @tc.desc Test setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0700', 0, async function (done) { + let newName = 'bluetooth1234ABCDEFGH'; + 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); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0800', 0, async function (done) { + let newName = '蓝牙设备bluetooth'; + let result = bluetooth.setLocalName(newName); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0800 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(newName == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0900', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES4); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_0900 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES4 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1000', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES2); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1000 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES2 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1100', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES3); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1100 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES3 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1200', 0, async function (done) { + let newName = '蓝牙设备123'; + 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); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1300', 0, async function (done) { + let newName = '蓝牙设备bluetooth12'; + let result = bluetooth.setLocalName(newName); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1300 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(newName == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1400', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES6); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1400 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES6 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1500', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1500 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES == getNewName); + + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1600', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES5); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1600 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.MIXES5 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1700', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.NUM_TEST1); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1700 NewName = '+ JSON.stringify(getNewName)); + expect(true).assertEqual(Btname.NUM_TEST1 == getNewName); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800 + * @tc.name TEST setLocalName + * @tc.desc TEST setLocalName api by promise. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_1800', 0, async function (done) { + let result = bluetooth.setLocalName(Btname.MIXES7); + expect(result).assertTrue(); + let getNewName = bluetooth.getLocalName(); + console.info('[bluetooth_js] LocalName_1800 NewName = '+ JSON.stringify(getNewName)); + expect(false).assertEqual(Btname.MIXES7 == getNewName); + done(); + }) + +}) +} + diff --git a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js new file mode 100644 index 000000000..da557b6e2 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js @@ -0,0 +1,355 @@ + +/* + * 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' + + +export default function bluetoothhostTest4() { +describe('bluetoothhostTest4', function() { + 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'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100 + * @tc.name testSppListen + * @tc.desc Test secure SppListen + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100', 0, async function (done) { + let SppType = { + SPP_RFCOMM : 0 + } + let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: true, type: SppType.SPP_RFCOMM}; + let serverNumber = -1; + function serverSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth serverSocket Number: ' + number); + serverNumber = number; + expect(true).assertEqual(number!=null); + } + } + bluetooth.sppListen('server1', SppOption, serverSocket); + 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) { + 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; + expect(true).assertEqual(number!=null); + } + } + 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) { + 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; + expect(true).assertEqual(number!=null); + } + } + 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) { + 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; + expect(true).assertEqual(number!=null); + } + } + 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) { + function acceptClientSocket(code, number) { + console.log('[bluetooth_js] error code: ' + code.code); + if (code.code == 0) { + console.log('[bluetooth_js] clientSocket Number: ' + number); + expect(true).assertEqual(number!=null); + } + } + 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) { + bluetooth.sppAccept(-1, function(code, clientSocketNumber) { + console.info('[bluetooth_js] code is: ' + code.code); + if (code.code == 0) { + console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); + expect(true).assertEqual(clientSocketNumber!=null); + } 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) { + 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) { + console.log('[bluetooth_js]sppConnect Number:' + clientSocketNumber); + expect(true).assertEqual(clientSocketNumber!=null); + } 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) { + 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) { + console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber); + expect(true).assertEqual(clientSocketNumber!=null); + } else { + expect(true).assertEqual(false); + } + }); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0900 + * @tc.name testSppConnect + * @tc.desc Test SppConnect api 8 by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0900', 0, async function (done) { + let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: true, type: 0}; + bluetooth.sppConnect('BT', sppOption, function(code, clientSocketNumber) { + console.info('[bluetooth_js] code is: ' + code.code); + if (code.code == 0) { + console.log('[bluetooth_js]sppConnect Number' + clientSocketNumber); + expect(true).assertEqual(clientSocketNumber!=null); + } else { + expect(true).assertEqual(false); + } + }); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000 + * @tc.name testsppCloseServerSocket + * @tc.desc Test sppCloseServerSocket api 8 by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000', 0, async function (done) { + let serverNumber = -1; + function serverSocket(code, number) { + console.log('bluetooth error code: ' + code.code); + if (code.code == 0) { + console.log('bluetooth serverSocket Number: ' + number); + serverNumber = number; + } + } + let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: true, type: 0}; + bluetooth.sppListen('server1', SppOption, serverSocket); + bluetooth.sppCloseServerSocket(serverNumber); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1000 + * @tc.name testsppCloseClientSocket + * @tc.desc Test sppCloseClientSocket api 8 by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1100', 0, async function (done) { + let clientNumber = -1; + bluetooth.sppAccept(-1, function(code, clientSocketNumber) { + console.info('[bluetooth_js] code is: ' + code.code); + if (code.code == 0) { + console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); + clientNumber =clientSocketNumber; + expect(true).assertEqual(clientSocketNumber!=null); + } else { + expect(true).assertEqual(false); + } + }); + bluetooth.sppCloseClientSocket(clientNumber); + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200 + * @tc.name testSppWrite + * @tc.desc Test sppWrite + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_1200', 0, async function (done) { + let clientNumber = -1; + bluetooth.sppAccept(-1, function(code, clientSocketNumber) { + console.info('[bluetooth_js] code is: ' + code.code); + if (code.code == 0) { + console.log('[bluetooth_js]sppAccept Number:' + clientSocketNumber); + clientNumber =clientSocketNumber; + expect(true).assertEqual(clientSocketNumber!=null); + } else { + expect(true).assertEqual(false); + } + }); + let arrayBuffer = new ArrayBuffer(8); + let data = new Uint8Array(arrayBuffer); + data[0] = 123; + let ret = bluetooth.sppWrite(clientNumber, arrayBuffer); + console.info('[bluetooth_js] bluetooth sppWrite ret : ' + ret); + expect(ret).assertEqual(false); + done(); + }) + + + }) +} + diff --git a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js new file mode 100644 index 000000000..58cac4e27 --- /dev/null +++ b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js @@ -0,0 +1,163 @@ +/* + * 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, +} +export default function bluetoothhostTest() { +describe('bluetoothhostTest', function() { + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + async function tryToEnableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + bluetooth.enableBluetooth(); + await sleep(5000); + let sta1 = bluetooth.getState(); + console.info('[bluetooth_js] Reacquire bt state:'+ JSON.stringify(sta1)); + 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: + bluetooth.enableBluetooth(); + await sleep(3000); + let sta2 = bluetooth.getState(); + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(function () { + console.info('afterAll called') + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0100 + * @tc.name testEnableBluetooth and getState + * @tc.desc Test EnableBluetooth api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0100', 0, async function (done) { + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state result'+ JSON.stringify(state)); + if(state!=BluetoothState.STATE_ON) + { + let enable = bluetooth.enableBluetooth(); + await sleep(3000); + console.info('[bluetooth_js] bluetooth enable result'+JSON.stringify(enable)); + expect(enable).assertTrue(); + let state1 = bluetooth.getState(); + console.info('[bluetooth_js] enable state1 '+ JSON.stringify(state1)); + expect(state1).assertEqual(BluetoothState.STATE_ON); + } + let disable = bluetooth.disableBluetooth(); + await sleep(3000); + console.info('[bluetooth_js] bluetooth disable result'+JSON.stringify(disable)); + expect(disable).assertTrue(); + let state2 = bluetooth.getState(); + console.info('[bluetooth_js] disable state2 '+ JSON.stringify(state2)); + expect(state2).assertEqual(BluetoothState.STATE_OFF); + done() + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300 + * @tc.name testEnableBluetooth + * @tc.desc Test EnableBluetooth api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) { + let state = bluetooth.getState(); + console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state)); + expect(state).assertEqual(BluetoothState.STATE_ON); + if(state==BluetoothState.STATE_ON) { + let enable1=bluetooth.enableBluetooth(); + await sleep(3000); + console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1)); + expect(enable1).assertFalse(); + let state1 = bluetooth.getState(); + console.info('[bluetooth_js] bt open state2='+ JSON.stringify(state1)); + expect(state1).assertEqual(BluetoothState.STATE_ON); + }else{ + console.info('[bluetooth_js]bluetooth open fail'); + } + done(); + }) + + /** + * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0400 + * @tc.name testEnableBluetooth + * @tc.desc Test EnableBluetooth api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0400', 0, async function (done) { + let result1= bluetooth.disableBluetooth(); + await sleep(3000); + console.info('[bluetooth_js] disable result'+ JSON.stringify(result1)); + expect(result1).assertTrue(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state)); + expect(state).assertEqual(BluetoothState.STATE_OFF); + if(state == BluetoothState.STATE_OFF) { + let result2= bluetooth.disableBluetooth(); + console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2)); + expect(result2).assertFalse(); + let state1 = bluetooth.getState(); + console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1)); + expect(state1).assertEqual(BluetoothState.STATE_OFF); + } + done(); + }) +}) +} + diff --git a/communication/bluetooth_standard/src/main/js/test/List.test.js b/communication/bluetooth_standard/src/main/js/test/List.test.js index cba7e0d47..52a9a1db2 100644 --- a/communication/bluetooth_standard/src/main/js/test/List.test.js +++ b/communication/bluetooth_standard/src/main/js/test/List.test.js @@ -13,7 +13,15 @@ * limitations under the License. */ -import bluetoothhostTest from './Bluetooth.test.js' +import bluetoothhostTest from './BRSwitch.test.js' +import bluetoothhostTest1 from './BRSetLocalName.test.js' +import bluetoothhostTest2 from './BRScanMode.test.js' +import bluetoothhostTest3 from './BRDiscovery.test.js' +import bluetoothhostTest4 from './BRSpp.test.js' export default function testsuite() { bluetoothhostTest() +bluetoothhostTest1() +bluetoothhostTest2() +bluetoothhostTest3() +bluetoothhostTest4() } diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js b/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js index c41191179..89ac3015f 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js +++ b/communication/wifi_p2p/src/main/js/test/WifiP2P.test2.js @@ -25,56 +25,91 @@ function checkWifiPowerOn(){ } export default function actsWifiTestNew() { - describe('actsWifiTestNew', function () { - beforeEach(function () { - checkWifiPowerOn(); - }) - afterEach(function () { - }) +describe('actsWifiTestNew', function () { + beforeEach(function () { + checkWifiPowerOn(); + }) + afterEach(function () { + }) - /** - * @tc.number P2P_0009 - * @tc.name SUB_Communication_WiFi_XTS_P2P_0009 - * @since 8 - * @tc.desc Test p2pCancelConnect Group API functionality. - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) { - let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", - netId : -1, - passphrase : "12345678", - groupName : "AAAZZZ123", - goBand : 0 - }; - let addConfig = wifi.createGroup(WifiP2PConfig); - console.info("[wifi_test] test p2pConnect result." + addConfig); - let disConn = wifi.p2pCancelConnect(); - sleep(2000); - console.info("[wifi_test] test p2pCancelConnect result." + disConn); - expect(disConn).assertTrue(); - let removeConfig = wifi.removeGroup(); - console.info("[wifi_test] test start removeGroup" + removeConfig); - expect(removeConfig).assertTrue(); - done(); - }) + /** + * @tc.number 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 P2P_0011 - * @tc.name SUB_Communication_WiFi_XTS_P2P_0011 - * @since 8 - * @tc.desc Test remove error Group functionality. - * @syscap SystemCapability.Communication.WiFi.P2P - * @permission ohos.permission.GET_WIFI_INFO - */ - it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) { - let isRemoved = wifi.removeGroup(10000); - console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved)); - expect(isRemoved).assertTrue(); - done(); - }) + /** + * @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 index 633cf773d..db1e602db 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiP2P.testsame.js +++ b/communication/wifi_p2p/src/main/js/test/WifiP2P.testsame.js @@ -35,523 +35,523 @@ let GroupOwnerBand = { } export default function actsWifiTest() { -describe('actsWifiTest', function () { - beforeEach(function () { - console.info("beforeEach start" ); - checkWifiPowerOn(); - }) - afterEach(async function () { - console.info("afterEach start" ); - }) + 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_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 - }; + /** + * @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(); + }); + }) - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - let addConfig = wifi.createGroup(WifiP2PConfig); - sleep(2000); - console.log("[wifi_test] check the state of wifi: " + 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 + - // "clientDevices: " + result.clientDevices +"networkId: " + result.networkId - // + "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress); + /** + * @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_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() - }) + }); + 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_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(); + /** + * @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() - }) + 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_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, - }; - wifi.getP2pLinkedInfo((err, result) => { - if (err) { - console.error('failed to getP2pLinkedInfo callback ' + JSON.stringify(err)); - return; - }else{ - console.info("[wifi_test] getP2pLinkedInfo [callback] -> " + JSON.stringify(result)); - console.info("connectState: " + result.connectState + - "isGroupOwner: " + result.isGroupOwner + - "groupOwnerAddr: " + result.groupOwnerAddr); - expect(false).assertEqual(result.connectState ==P2pConnectState.CONNECTED); + /** + * @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_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_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); + /** + * @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(); } - let stopScan = wifi.stopDiscoverDevices(); - expect(stopScan).assertTrue(); - } - done(); - }); - }) + 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)); + /** + * @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(); }); - }, 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); + setTimeout(function() { + wifi.off('p2pStateChange', result => { + console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result !=null); + }); + }, 1 * 1000); done(); - }); - setTimeout(function() { - console.info('[wifi_test] offP2pStateChange test start ...'); - wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => { - console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc)); + }) + + /** + * @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(); }); - }, 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); + 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(); - }); - setTimeout(function() { - console.info('[wifi_test] offP2pDeviceChange test start ...'); - wifi.off('p2pDeviceChange', result => { - console.info("offP2pStateChange callback, result: " + JSON.stringify(result)); + }) + + /** + * @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(); }); - }, 1 * 1000); - 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, + /** + * @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); } - 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)); + }); + } + await wifi.on('p2pPeerDeviceChange', result => { + console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result)); expect(true).assertEqual(result !=null); + done(); }); - }, 1 * 1000); - 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, + /** + * @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)); + }); }; - 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)); + 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(); - }); - setTimeout(function() { - wifi.off('p2pDiscoveryChange', result => { - console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); + }) + + /** + * @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(); }); - }, 1 * 1000); - 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*************"); }) - console.log("*************[wifi_test] start wifi js unit test end*************"); -}) } - - - - diff --git a/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js b/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js index 912273fb4..1b105e6cd 100644 --- a/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js +++ b/communication/wifi_standard/src/main/js/test/WifiJsunit.test1.js @@ -80,7 +80,6 @@ export default function actsWifiTestNew() { "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_OPEN, }; - await wifi.addCandidateConfig(wifiDeviceConfig) .then(netWorkId => { console.info("[wifi_test]add OPEN CandidateConfig promise : " + JSON.stringify(netWorkId)); @@ -128,7 +127,6 @@ export default function actsWifiTestNew() { "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, - "netId": "", }; await wifi.addCandidateConfig(wifiDeviceConfig) .then(netWorkId => { @@ -140,14 +138,11 @@ export default function actsWifiTestNew() { }); let getconfig = wifi.getCandidateConfigs(); console.info("[wifi_test] wifi get PSK CandidateConfigs result : " + JSON.stringify(getconfig)); - expect(true).assertEqual(getconfig[0].securityType == wifiDeviceConfig.securityType); - expect(true).assertEqual(getconfig[0].isHiddenSsid == wifiDeviceConfig.isHiddenSsid); - expect(true).assertEqual(getconfig[0].ssid == wifiDeviceConfig.ssid); var networkId = getconfig[0].netId; console.info("[wifi_test] wifi get networkId result : " + JSON.stringify(networkId)); await wifi.removeCandidateConfig(networkId) .then(ret => { - console.info("[wifi_test]remove CandidateConfig promise" + JSON.stringify(ret)); + console.info("[wifi_test]remove CandidateConfig promise:" + JSON.stringify(ret)); expect(false).assertFalse(); let getconfig1 = wifi.getCandidateConfigs(); console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig1)); @@ -179,12 +174,26 @@ export default function actsWifiTestNew() { await wifi.addCandidateConfig(wifiDeviceConfig) .then(netWorkId => { console.info("[wifi_test]add SAE CandidateConfig promise : " + JSON.stringify(netWorkId)); - expect(true).assertEqual(netWorkId = -1); + expect(true).assertEqual(netWorkId != -1); }).catch((error) => { console.error('[wifi_js] add SAE CandidateConfig promise failed -> ' + JSON.stringify(error)); }); let getconfig = wifi.getCandidateConfigs(); console.info("[wifi_test] wifi get SAE CandidateConfigs result : " + JSON.stringify(getconfig)); + var networkId = getconfig[0].netId; + console.info("[wifi_test] wifi get networkId result : " + JSON.stringify(networkId)); + await wifi.removeCandidateConfig(networkId) + .then(ret => { + console.info("[wifi_test]remove CandidateConfig promise" + JSON.stringify(ret)); + expect(false).assertFalse(); + let getconfig1 = wifi.getCandidateConfigs(); + console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(getconfig1)); + console.info("[wifi_test] wifi getconfig.length result : " + JSON.stringify(getconfig1.length)); + expect(true).assertEqual(getconfig1.length == 0); + }).catch((error) => { + console.error('[wifi_js] remove CandidateConfig promise failed -> ' + JSON.stringify(error)); + expect().assertFail(); + }); done(); }) @@ -204,13 +213,13 @@ export default function actsWifiTestNew() { "isHiddenSsid": false, "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, } + function addCandidate() { return new Promise((resolve, reject) => { wifi.addCandidateConfig(wifiDeviceConfig, (err, netWorkId) => { if (err) { console.info("[wifi_test]add CandidateConfig callback failed : " + JSON.stringify(err)); - return; } console.info("[wifi_test]addCandidateConfig callback result: " + JSON.stringify(netWorkId)); expect(true).assertEqual(netWorkId != -1); @@ -221,9 +230,6 @@ export default function actsWifiTestNew() { await addCandidate(); let configs = wifi.getCandidateConfigs(); console.info("[wifi_test] wifi getCandidateConfigs result : " + JSON.stringify(configs)); - expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig.securityType); - expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig.isHiddenSsid); - expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig.ssid); var networkId = configs[0].netId; function removeCandidate() { return new Promise((resolve, reject) => { @@ -231,7 +237,7 @@ export default function actsWifiTestNew() { (err, ret) => { if (err) { console.info("[wifi_test]removeCandidate callback failed : " + JSON.stringify(err)); - return; + } console.info("[wifi_test] removeCandidateConfig callback result:" + JSON.stringify(ret)); expect(ret).assertTrue(); @@ -243,6 +249,7 @@ export default function actsWifiTestNew() { }); }); } + await removeCandidate(); done(); }) @@ -357,7 +364,87 @@ export default function actsWifiTestNew() { expect(lenth).assertLarger(0); done(); }) - }) -} + /** + * @tc.number SUB_Communication_WiFi_XTS_UntrustedConfig_0001 + * @tc.name testaddUntrustedConfig + * @tc.desc Test add UntrustedConfig and removeUntrustedConfig Promise API functionality. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_XTS_UntrustedConfig_0001', 0, async function (done) { + let wifiDeviceConfig = { + "ssid": "TEST_PSK", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + }; + await wifi.addUntrustedConfig(wifiDeviceConfig) + .then(ret => { + console.info("[wifi_test]addUntrustedConfig promise : " + JSON.stringify(ret)); + expect(ret).assertTrue(); + }).catch((error) => { + console.error('[wifi_js]addUntrustedConfig promise failed -> ' + JSON.stringify(error)); + + }); + await wifi.removeUntrustedConfig(wifiDeviceConfig) + .then(ret => { + console.info("[wifi_test]removeUntrustedConfig promise:" + JSON.stringify(ret)); + expect(True).assertTrue(); + }).catch((error) => { + console.error('[wifi_js]removeUntrustedConfig promise failed -> ' + JSON.stringify(error)); + }); + done(); + }) + + /** + * @tc.number SUB_Communication_WiFi_XTS_UntrustedConfig_0002 + * @tc.name testaddUntrustedConfig + * @tc.desc Test add UntrustedConfig and removeUntrustedConfig callback API functionality. + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_WiFi_XTS_UntrustedConfig_0002', 0, async function (done) { + let wifiDeviceConfig = { + "ssid": "TYPE_PSK1", + "bssid": "", + "preSharedKey": "12345678", + "isHiddenSsid": false, + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK, + } + function addCandidate() { + return new Promise((resolve, reject) => { + wifi.addUntrustedConfig(wifiDeviceConfig, + (err, ret) => { + if (err) { + console.info("[wifi_test]addUntrustedConfig callback failed : " + JSON.stringify(err)); + + } + console.info("[wifi_test]addUntrustedConfig callback result: " + JSON.stringify(ret)); + expect(ret).assertTrue(); + resolve(); + }); + }); + } + await addCandidate(); + function removeCandidate() { + return new Promise((resolve, reject) => { + wifi.removeUntrustedConfig(wifiDeviceConfig, + (err, ret) => { + if (err) { + console.info("[wifi_test]removeUntrustedConfig callback failed" + JSON.stringify(err)); + + } + console.info("[wifi_test]removeUntrustedConfig callback result:" + JSON.stringify(ret)); + expect(ret).assertTrue(); + resolve(); + }); + }); + } + await removeCandidate(); + done(); + }) + }) +} diff --git a/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js b/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js index a94f3499e..068e4a3c0 100644 --- a/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js +++ b/communication/wifi_standard/src/main/js/test/WifiJsunit.testsame.js @@ -26,8 +26,8 @@ function sleep(delay) { // delay x ms 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); +function resolveIP(ip) { + return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF); } let WifiSecurityType = { @@ -54,8 +54,8 @@ let untrustedDeviceConfig = { "bssid": "", "preSharedKey": "12345678", "isHiddenSsid": false, - "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK - } + "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK +} let WifiChannelWidth = { WIDTH_20MHZ : 0, @@ -67,413 +67,393 @@ let WifiChannelWidth = { } export default function actsWifiTest() { -describe('actsWifiTest', function() { - beforeEach(function() { - checkWifiPowerOn(); - }) - afterEach(function() { - }) - - /** - * @tc.number open_0001 - * @tc.name SUB_Communication_WiFi_Sta_Open_0001 - * @since 6 - * @tc.desc Test wifi.isWifiActive API functionality. - */ - it('SUB_Communication_WiFi_Sta_WifiActive_0001', 0, function() { - sleep(3000); - console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive()); - expect(wifi.isWifiActive()).assertTrue(); - }) + describe('actsWifiTest', function() { + beforeEach(function () { + checkWifiPowerOn(); + }) + afterEach(function () { + }) - /** - * @tc.number Scan_0001 - * @tc.name SUB_Communication_WiFi_Sta_Scan_0001 - * @since 6 - * @tc.desc Test get ScanInfos callback API functionality. - */ - it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) { - let scan = wifi.scan(); - sleep(3000); - console.log("[wifi_test] open wifi scan result: " + scan); - expect(scan).assertTrue(); - 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)) { + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0002 + * @tc.name testgetScanInfos + * @tc.desc Test get ScanInfos 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 wifi.getScanInfos() + .then(result => { + let clen = Object.keys(result).length; 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); + console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result)); + }); + wifi.getScanInfos( + (err, result) => { + if (err) { + console.log("[wifi_test] wifi getScanInfos failed " + err); } - } - done() - }); - }) + 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() + }); + }) - /** - * @tc.number Scan_0004 - * @tc.name SUB_Communication_WiFi_Sta_Scan_0004 - * @since 7 - * @tc.desc Test wifi.getSignalLevel API functionality. - */ - it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() { - console.info("[wifi_test] check the 2.4G rssi assgined to level test."); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 1)); - expect(wifi.getSignalLevel(-65, 1)).assertEqual(4); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 1)); - expect(wifi.getSignalLevel(-66, 1)).assertEqual(3); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-75, 1)); - expect(wifi.getSignalLevel(-75, 1)).assertEqual(3); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-76, 1)); - expect(wifi.getSignalLevel(-76, 1)).assertEqual(2); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-82, 1)); - expect(wifi.getSignalLevel(-82, 1)).assertEqual(2); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-83, 1)); - expect(wifi.getSignalLevel(-83, 1)).assertEqual(1); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-88, 1)); - expect(wifi.getSignalLevel(-88, 1)).assertEqual(1); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-89, 1)); - expect(wifi.getSignalLevel(-89, 1)).assertEqual(0); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 1)); - expect(wifi.getSignalLevel(-127, 1)).assertEqual(0); + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0021 + * @tc.name testgetSignalLevel + * @tc.desc Test get SignalLevel API functionality.. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_Sta_0021', 0, function () { + console.info("[wifi_test] check the 2.4G rssi assgined to level test."); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 1)); + expect(wifi.getSignalLevel(-65, 1)).assertEqual(4); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 1)); + expect(wifi.getSignalLevel(-66, 1)).assertEqual(3); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-75, 1)); + expect(wifi.getSignalLevel(-75, 1)).assertEqual(3); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-76, 1)); + expect(wifi.getSignalLevel(-76, 1)).assertEqual(2); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-82, 1)); + expect(wifi.getSignalLevel(-82, 1)).assertEqual(2); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-83, 1)); + expect(wifi.getSignalLevel(-83, 1)).assertEqual(1); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-88, 1)); + expect(wifi.getSignalLevel(-88, 1)).assertEqual(1); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-89, 1)); + expect(wifi.getSignalLevel(-89, 1)).assertEqual(0); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 1)); + expect(wifi.getSignalLevel(-127, 1)).assertEqual(0); - console.info("[wifi_test] check the 5G rssi assgined to level test."); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 2)); - expect(wifi.getSignalLevel(-65, 2)).assertEqual(4); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 2)); - expect(wifi.getSignalLevel(-66, 2)).assertEqual(3); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-72, 2)); - expect(wifi.getSignalLevel(-72, 2)).assertEqual(3); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-73, 2)); - expect(wifi.getSignalLevel(-73, 2)).assertEqual(2); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-79, 2)); - expect(wifi.getSignalLevel(-79, 2)).assertEqual(2); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-80, 2)); - expect(wifi.getSignalLevel(-80, 2)).assertEqual(1); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-85, 2)); - expect(wifi.getSignalLevel(-85, 2)).assertEqual(1); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-86, 2)); - expect(wifi.getSignalLevel(-86, 2)).assertEqual(0); - console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 2)); - expect(wifi.getSignalLevel(-127, 2)).assertEqual(0); - }) + console.info("[wifi_test] check the 5G rssi assgined to level test."); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-65, 2)); + expect(wifi.getSignalLevel(-65, 2)).assertEqual(4); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-66, 2)); + expect(wifi.getSignalLevel(-66, 2)).assertEqual(3); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-72, 2)); + expect(wifi.getSignalLevel(-72, 2)).assertEqual(3); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-73, 2)); + expect(wifi.getSignalLevel(-73, 2)).assertEqual(2); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-79, 2)); + expect(wifi.getSignalLevel(-79, 2)).assertEqual(2); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-80, 2)); + expect(wifi.getSignalLevel(-80, 2)).assertEqual(1); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-85, 2)); + expect(wifi.getSignalLevel(-85, 2)).assertEqual(1); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-86, 2)); + expect(wifi.getSignalLevel(-86, 2)).assertEqual(0); + console.info("[wifi_test] getSignalLevel " + wifi.getSignalLevel(-127, 2)); + expect(wifi.getSignalLevel(-127, 2)).assertEqual(0); + }) - /** - * @tc.number SUB_Communication_WiFi_Sta_info_0002 - * @tc.name testgetCountryCode - * @tc.desc Test getCountryCode api. - * @since 7 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_Sta_Info_0002', 0, function() { - expect(wifi.isWifiActive()).assertTrue(); - let countryCode = wifi.getCountryCode(); - console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode)); - let countrylen = countryCode.length; - console.info("[wifi_test] getCountryCode.length -> " + JSON.stringify(countrylen)); - expect(true).assertEqual(countrylen ==2); - }) - - /** - * @tc.number SUB_Communication_WiFi_Sta_info_0004 - * @tc.name testFeatureSupported - * @tc.desc Test FeatureSupported api. - * @since 7 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - */ - it('SUB_Communication_WiFi_Sta_info_0004', 0, function () { - expect(wifi.isWifiActive()).assertTrue(); - let WifiUtils = { - WIFI_FEATURE_INFRA: 0x0001, - WIFI_FEATURE_INFRA_5G: 0x0002, - WIFI_GAS_ANQP: 0x0004, - WIFI_WIFI_DIRECT: 0x0008, - WIFI_FEATURE_MOBILE_HOTSPOT: 0x0010, - WIFI_FEATURE_AWARE: 0x0040, - WIFI_FEATURE_AP_STA: 0x8000, - WIFI_FEATURE_WPA3_SAE: 0x8000000, - WIFI_FEATURE_WPA3_SUITE_B:0x10000000, - WIFI_FEATURE_OWE:0x20000000 - } - let isSupport1 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA); - console.info("[wifi_test] isFeatureSupported -> " + isSupport1); - let isSupport2 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA_5G); - console.info("[wifi_test] isFeatureSupported2 -> " + isSupport2); - let isSupport3 = wifi.isFeatureSupported(WifiUtils.WIFI_GAS_ANQP); - console.info("[wifi_test] isFeatureSupported3 -> " + isSupport3); - let isSupport4 = wifi.isFeatureSupported(WifiUtils.WIFI_WIFI_DIRECT); - console.info("[wifi_test] isFeatureSupported4 -> " + isSupport4); - let isSupport5 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_MOBILE_HOTSPOT); - console.info("[wifi_test] isFeatureSupported5 -> " + isSupport5); - let isSupport6 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AWARE); - console.info("[wifi_test] isFeatureSupported6 -> " + isSupport6); - let isSupport7 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AP_STA); - console.info("[wifi_test] isFeatureSupported7 -> " + isSupport7); - let isSupport8 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SAE); - console.info("[wifi_test] isFeatureSupported8 -> " + isSupport8); - let isSupport9 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SUITE_B); - console.info("[wifi_test] isFeatureSupported9 -> " + isSupport9); - let isSupport = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_OWE); - console.info("[wifi_test] isFeatureSupported -> " + isSupport); - }) + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0017 + * @tc.name testgetCountryCode + * @tc.desc Test getCountryCode API function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_Sta_0017', 0, function () { + expect(wifi.isWifiActive()).assertTrue(); + let countryCode = wifi.getCountryCode(); + console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode)); + let countrylen = countryCode.length; + console.info("[wifi_test] getCountryCode.length -> " + JSON.stringify(countrylen)); + expect(true).assertEqual(countrylen == 2); + }) - /** - * @tc.number conn_Config_0002 - * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0002 - * @since 7 - * @tc.desc Test getLinkedInfo information - */ - it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) { - let isConnected= wifi.isConnected(); - expect(isConnected).assertFalse(); - await wifi.getLinkedInfo() - .then((result) => { - console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result)); - expect(JSON.stringify(result)).assertContain('band'); - done(); - }).catch((error) => { - console.info("[wifi_test] promise then error." + JSON.stringify(error)); - expect().assertFail(); - }); - }) + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0020 + * @tc.name testFeatureSupported + * @tc.desc Test FeatureSupported API function. + * @tc.type Function + * @tc.level Level 3 + */ + it('SUB_Communication_WiFi_XTS_Sta_0020', 0, function () { + expect(wifi.isWifiActive()).assertTrue(); + let WifiUtils = { + WIFI_FEATURE_INFRA: 0x0001, + WIFI_FEATURE_INFRA_5G: 0x0002, + WIFI_GAS_ANQP: 0x0004, + WIFI_WIFI_DIRECT: 0x0008, + WIFI_FEATURE_MOBILE_HOTSPOT: 0x0010, + WIFI_FEATURE_AWARE: 0x0040, + WIFI_FEATURE_AP_STA: 0x8000, + WIFI_FEATURE_WPA3_SAE: 0x8000000, + WIFI_FEATURE_WPA3_SUITE_B: 0x10000000, + WIFI_FEATURE_OWE: 0x20000000 + } + let isSupport1 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA); + console.info("[wifi_test] isFeatureSupported -> " + isSupport1); + let isSupport2 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_INFRA_5G); + console.info("[wifi_test] isFeatureSupported2 -> " + isSupport2); + let isSupport3 = wifi.isFeatureSupported(WifiUtils.WIFI_GAS_ANQP); + console.info("[wifi_test] isFeatureSupported3 -> " + isSupport3); + let isSupport4 = wifi.isFeatureSupported(WifiUtils.WIFI_WIFI_DIRECT); + console.info("[wifi_test] isFeatureSupported4 -> " + isSupport4); + let isSupport5 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_MOBILE_HOTSPOT); + console.info("[wifi_test] isFeatureSupported5 -> " + isSupport5); + let isSupport6 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AWARE); + console.info("[wifi_test] isFeatureSupported6 -> " + isSupport6); + let isSupport7 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_AP_STA); + console.info("[wifi_test] isFeatureSupported7 -> " + isSupport7); + let isSupport8 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SAE); + console.info("[wifi_test] isFeatureSupported8 -> " + isSupport8); + let isSupport9 = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_WPA3_SUITE_B); + console.info("[wifi_test] isFeatureSupported9 -> " + isSupport9); + let isSupport = wifi.isFeatureSupported(WifiUtils.WIFI_FEATURE_OWE); + console.info("[wifi_test] isFeatureSupported -> " + isSupport); + }) - /** - * @tc.number conn_Config_0003 - * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003 - * @since 7 - * @tc.desc Test getLinkedInfo callback information - */ - it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function(done) { - wifi.getLinkedInfo( - (err,result) => { - if(err) { - console.log("[wifi_test] wifi getLinkedInfo failed " + err); - } - let clen = Object.keys(result).length; - expect(clen).assertLarger(0); - console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result)); - console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+ - "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted + - "chload: " + result.chload + "rssi " + result.rssi + "netWorkId: " + result.netWorkId+ - "linkSpeed: " + result.linkSpeed + "frequency:" - + result.frequency +"snr:" + result.snr+ - "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress + - "suppState: " + result.suppState + "connState: " + result.connState - + "macType: " + result.macType); + /** + * @tc.number SUB_Communication_WiFi_XTS_Sta_0004 + * @tc.name testgetLinkedInfo + * @tc.desc Test Test getLinkedInfo and getIpInfo information. + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_Communication_WiFi_XTS_Sta_0004', 0, async function (done) { + 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); + await wifi.getLinkedInfo() + .then((result) => { + console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result)); + expect(JSON.stringify(result)).assertContain('band'); + done(); + }).catch((error) => { + console.info("[wifi_test] promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + wifi.getLinkedInfo( + (err, result) => { + if (err) { + console.log("[wifi_test] wifi getLinkedInfo failed " + err); + } + let clen = Object.keys(result).length; + expect(clen).assertLarger(0); + console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result)); + console.info("ssid: " + result.ssid + "bssid:" + result.bssid + "band: " + result.band + + "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted + + "chload: " + result.chload + "rssi " + result.rssi + "netWorkId: " + result.netWorkId + + "linkSpeed: " + result.linkSpeed + "frequency:" + + result.frequency + "snr:" + result.snr + + "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress + + "suppState: " + result.suppState + "connState: " + result.connState + + "macType: " + result.macType); + let state = wifi.getLinkedInfo().connState; + if (state == ConnState.SCANNING) { + expect(true).assertEqual(state == 0); + } + if (state == ConnState.CONNECTING) { + expect(true).assertEqual(state == 1); + } + if (state == ConnState.AUTHENTICATING) { + expect(true).assertEqual(state == 2); + } + if (state == ConnState.OBTAINING_IPADDR) { + expect(true).assertEqual(state == 3); + } + if (state == ConnState.CONNECTED) { + expect(true).assertEqual(state == 4); + } + if (state == ConnState.DISCONNECTING) { + expect(true).assertEqual(state == 5); + } + if (state == ConnState.DISCONNECTED) { + expect(true).assertEqual(state == 6); + } + if (state == ConnState.UNKNOWN) { + expect(true).assertEqual(state == 7); + } + done(); + }); + }) - let state = wifi.getLinkedInfo().connState; - if(state == ConnState.SCANNING){ - expect(true).assertEqual(state == 0); - } - if(state == ConnState.CONNECTING){ - expect(true).assertEqual(state == 1); - } - if(state == ConnState.AUTHENTICATING){ - expect(true).assertEqual(state == 2); - } - if(state == ConnState.OBTAINING_IPADDR){ - expect(true).assertEqual(state == 3); - } - if(state == ConnState.CONNECTED){ - expect(true).assertEqual(state == 4); - } - if(state == ConnState.DISCONNECTING){ - expect(true).assertEqual(state == 5); - } - if(state == ConnState.DISCONNECTED){ - expect(true).assertEqual(state == 6); - } - if(state == ConnState.UNKNOWN){ - expect(true).assertEqual(state == 7); - } - done(); - }); - }) + /** + * @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 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 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 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 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 - */ + /** + * @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("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); + 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.type Function - * @tc.level Level 3 - */ - 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(); - } - done(); - }) - console.log("*************[wifi_test] start wifi js unit test end*************"); -}) -} + /** + * @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.type Function + * @tc.level Level 3 + */ + 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(); + } + done(); + }) + console.log("*************[wifi_test] start wifi js unit test end*************"); + }) +} diff --git a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js index 38e62ca5e..dc1f11f06 100644 --- a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js @@ -14,24 +14,32 @@ */ import geolocation from '@ohos.geolocation'; -import { LocationEventListener } from '@ohos.geolocation'; +import {LocationEventListener} from '@ohos.geolocation'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' import osaccount from '@ohos.account.osAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' -let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , - TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, - DAILY_LIFE_SERVICE : 0x304 ,NO_POWER : 0x305} -let LocationRequestPriority = {UNSET : 0x200 ,ACCURACY : 0x201 ,LOW_POWER : 0x202 ,FIRST_FIX :0x203} + +let LocationRequestScenario = { + UNSET: 0x300, + NAVIGATION: 0x301, + TRAJECTORY_TRACKING: 0x302, + CAR_HAILING: 0x303, + DAILY_LIFE_SERVICE: 0x304, + NO_POWER: 0x305 +} +let LocationRequestPriority = { UNSET: 0x200, ACCURACY: 0x201, LOW_POWER: 0x202, FIRST_FIX: 0x203 } let LocationPrivacyType = { - OTHERS : 0, + OTHERS: 0, STARTUP: 1, - CORE_LOCATION : 2 + CORE_LOCATION: 2 } + function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + async function changedLocationMode(){ await geolocation.isLocationEnabled().then(async(result) => { console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); @@ -46,13 +54,13 @@ async function changedLocationMode(){ } }); await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); + console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); }); } async function applyPermission() { let osAccountManager = osaccount.getAccountManager(); - console.debug("=== getAccountManager finish"); + console.info("=== getAccountManager finish"); let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); console.info("LocalId is :" + localId); let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); @@ -90,28 +98,25 @@ describe('geolocationTest_geo1', function () { console.info('beforeEach case'); await changedLocationMode(); done(); - - }) - afterEach(function () { }) /** - * @tc.number Geo_0001 - * @tc.name SUB_HSS_LocationSystem_Geo_0001 - * @tc.desc Test isGeoServiceAvailable api . + * @tc.number SUB_HSS_LocationSystem_Geo_0001 + * @tc.name testIsGeoServiceAvailable + * @tc.desc Check whether address resolution and reverse address resolution are supported. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0001', 0, async function (done) { - geolocation.isGeoServiceAvailable(async(err, data) => { + geolocation.isGeoServiceAvailable(async (err, data) => { if (err) { - console.info('[lbs_js] getGeoServiceState err is : ' + JSON.stringify(err) ); + console.info('[lbs_js] getGeoServiceState err is : ' + JSON.stringify(err)); - }else { + } else { console.info('[lbs_js] isGeoServiceAvailable callback result: ' + JSON.stringify(data)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(data)!=null); + expect(true).assertEqual(JSON.stringify(data) != null); done(); } done() @@ -119,18 +124,18 @@ describe('geolocationTest_geo1', function () { }); /** - * @tc.number Geo_0002 - * @tc.name SUB_HSS_LocationSystem_Geo_0002 - * @tc.desc Test isGeoServiceAvailable api . + * @tc.number SUB_HSS_LocationSystem_Geo_0002 + * @tc.name TestisGeoServiceAvailable + * @tc.desc Check whether address resolution and reverse address resolution are supported. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0002', 0, async function (done) { - await geolocation.isGeoServiceAvailable().then( (result) => { + await geolocation.isGeoServiceAvailable().then((result) => { console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + JSON.stringify(result)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(result)!=null); + expect(true).assertEqual(JSON.stringify(result) != null); }).catch((error) => { console.info("[lbs_js] promise then error." + JSON.stringify(error)); expect().assertFail(); @@ -139,22 +144,22 @@ describe('geolocationTest_geo1', function () { }) /** - * @tc.number Geo_0003 - * @tc.name SUB_HSS_LocationSystem_Geo_0003 - * @tc.desc Test isGeoServiceAvailable api . + * @tc.number SUB_HSS_LocationSystem_Geo_0003 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Address Resolution Test. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0003', 0, async function (done) { - let reverseGeocodeRequest = {"latitude": 31.265496, "longitude": 121.62771, "maxItems": 1,"locale": "zh"}; - let promise = new Promise((resolve,reject) => { + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1, "locale": "zh" }; + let promise = new Promise((resolve, reject) => { geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { if (err) { console.info('[lbs_js] getAddressesFromLocation callback err is : ' + JSON.stringify(err)); - }else { + } else { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + expect(true).assertEqual((JSON.stringify(data)) != null); } resolve() }); @@ -163,1512 +168,677 @@ describe('geolocationTest_geo1', function () { }) /** - * @tc.number Geo_0004 - * @tc.name SUB_HSS_LocationSystem_Geo_0004 - * @tc.desc Test isGeoServiceAvailable api + * @tc.number SUB_HSS_LocationSystem_Geo_0004 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Address Resolution Test. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0004', 0, async function (done) { - let reverseGeocodeRequest = {"latitude": 31.265496, "longitude": 121.62771, "maxItems": 1}; + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { - console.info('[lbs_js] getAddressesFromLocation04 promise: ' + JSON.stringify(data)); - console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl + console.info('[lbs_js] getAddressesFromLocation04 promise: ' + JSON.stringify(data)); + console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl + JSON.stringify(data)[0].administrativeArea + JSON.stringify(data)[0].countryCode - + JSON.stringify(data)[0].countryName+ JSON.stringify(data)[0].descriptions - + JSON.stringify(data)[0].descriptionsSize +data[0].latitude - + JSON.stringify(data)[0].locale+ JSON.stringify(data)[0].locality - + JSON.stringify(data)[0].longitude+ JSON.stringify(data)[0].phoneNumber + + JSON.stringify(data)[0].countryName + JSON.stringify(data)[0].descriptions + + JSON.stringify(data)[0].descriptionsSize + data[0].latitude + + JSON.stringify(data)[0].locale + JSON.stringify(data)[0].locality + + JSON.stringify(data)[0].longitude + JSON.stringify(data)[0].phoneNumber + JSON.stringify(data)[0].placeName - + JSON.stringify(data)[0].postalCode+ JSON.stringify(data)[0].premises - + JSON.stringify(data)[0].roadName+ JSON.stringify(data)[0].subAdministrativeArea - + JSON.stringify(data)[0].subLocality+ JSON.stringify(data)[0].subRoadName); + + JSON.stringify(data)[0].postalCode + JSON.stringify(data)[0].premises + + JSON.stringify(data)[0].roadName + JSON.stringify(data)[0].subAdministrativeArea + + JSON.stringify(data)[0].subLocality + JSON.stringify(data)[0].subRoadName); done(); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); done(); }); }) /** - * @tc.number Geo_0005 - * @tc.name SUB_HSS_LocationSystem_Geo_0005 - * @tc.desc Test isGeoServiceAvailable api . + * @tc.number SUB_HSS_LocationSystem_Geo_0005 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Obtaining Multiple Addresses Using the Address Resolution Function. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0005', 0, async function (done) { - let reverseGeocodeRequest = {"latitude": 31.265496, "longitude": 121.62771, "maxItems": 5}; + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 5 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { - console.info('[lbs_js] getAddressesFromLocation05 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + console.info('[lbs_js] getAddressesFromLocation05 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); done(); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocation promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); done(); }); }) /** - * @tc.number Geo_0006 - * @tc.name SUB_HSS_LocationSystem_Geo_0006 - * @tc.desc Test getAddressesFromLocation api . + * @tc.number SUB_HSS_LocationSystem_Geo_0006 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test of the address resolution function * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0006', 0, async function (done) { - let reverseGeocodeRequest1 = {"latitude": 90, "longitude": 121.62771, "maxItems": 1}; + let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); - let reverseGeocodeRequest2 = {"latitude": 90.1, "longitude": 121.62771, "maxItems": 1}; + let reverseGeocodeRequest2 = { "latitude": 90.1, "longitude": 121.62771, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { - console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); + console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); expect(data.length).assertEqual(0); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); - let reverseGeocodeRequest3 = {"latitude": -90, "longitude": 121.62771, "maxItems": 1}; + let reverseGeocodeRequest3 = { "latitude": -90, "longitude": 121.62771, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); - let reverseGeocodeRequest4 = {"latitude": -90.1, "longitude": 121.62771, "maxItems": 1}; + let reverseGeocodeRequest4 = { "latitude": -90.1, "longitude": 121.62771, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data)); + console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data)); expect(data.length).assertEqual(0); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); done() }) /** - * @tc.number Geo_0007 - * @tc.name SUB_HSS_LocationSystem_Geo_0007 - * @tc.desc Test requestEnableLocation api . + * @tc.number SUB_HSS_LocationSystem_Geo_0007 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test of the address resolution function * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0007', 0, async function (done) { - let reverseGeocodeRequest = {"latitude": 31.265496, "longitude": 180, "maxItems": 1}; + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); - let reverseGeocodeRequest1 = {"latitude": 31.265496, "longitude": -180.1, "maxItems": 1}; + let reverseGeocodeRequest1 = { "latitude": 31.265496, "longitude": -180.1, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data)); + console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data)); expect(data.length).assertEqual(0); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); - let reverseGeocodeRequest2 = {"latitude": 31.265496, "longitude": 180, "maxItems": 1}; + let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); - let reverseGeocodeRequest3 = {"latitude": 31.265496, "longitude": 180.1, "maxItems": 1}; + let reverseGeocodeRequest3 = { "latitude": 31.265496, "longitude": 180.1, "maxItems": 1 }; await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data)); + console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data)); expect(data.length).assertEqual(0); }).catch(error => { console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); done() }) /** - * @tc.number Geo_0008 - * @tc.name SUB_HSS_LocationSystem_Geo_0008 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0008 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Reverse address resolution test. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0008', 0, async function (done) { - let geocodeRequest = {"description": "上海市浦东新区金穗路1800号", "maxItems": 1,"locale": "zh","minLatitude":"" , - "minLongitude":"" ,"maxLatitude":"" ,"maxLongitude": ""}; + let geocodeRequest = { + "description": "上海市浦东新区金穗路1800号", + "maxItems": 1, + "locale": "zh", + "minLatitude": "", + "minLongitude": "", + "maxLatitude": "", + "maxLongitude": "" + }; geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { - if(err){ - switch(err){ + if (err) { + switch (err) { case 100: - console.info("NOT_SUPPORTED"+ JSON.stringify(err)); + console.info("NOT_SUPPORTED: " + JSON.stringify(err)); break; case 101: - console.info("INPUT_PARAMS_ERROR"+ JSON.stringify(err)); + console.info("INPUT_PARAMS_ERROR: " + JSON.stringify(err)); break; case 102: - console.info("REVERSE_GEOCODE_ERROR"+ JSON.stringify(err)); + console.info("REVERSE_GEOCODE_ERROR: " + JSON.stringify(err)); break; case 103: - console.info("GEOCODE_ERROR"+ JSON.stringify(err)); + console.info("GEOCODE_ERROR: " + JSON.stringify(err)); break; case 104: - console.info("LOCATOR_ERROR"+ JSON.stringify(err)); + console.info("LOCATOR_ERROR: " + JSON.stringify(err)); break; case 105: - console.info("LOCATION_SWITCH_ERROR"+ JSON.stringify(err)); + console.info("LOCATION_SWITCH_ERROR: " + JSON.stringify(err)); break; case 106: - console.info("LAST_KNOWN_LOCATION_ERROR"+ JSON.stringify(err)); + console.info("LAST_KNOWN_LOCATION_ERROR: " + JSON.stringify(err)); break; case 107: - console.info("LOCATION_REQUEST_TIMEOUT_ERROR"+ JSON.stringify(err)); + console.info("LOCATION_REQUEST_TIMEOUT_ERROR: " + JSON.stringify(err)); break; case 108: - console.info("QUERY_COUNTRY_CODE_ERROR "+ JSON.stringify(err)); + console.info("QUERY_COUNTRY_CODE_ERROR: " + JSON.stringify(err)); break; default: console.info('[lbs_js] getAddressesFromLocationName callback err is : ' + JSON.stringify(err)); } - }else { + } else { console.info("[lbs_js] getAddressesFromLocationName08 callback data is: " + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); + expect(true).assertEqual((JSON.stringify(data)) != null); } done(); }); }) /** - * @tc.number Geo_0009 - * @tc.name SUB_HSS_LocationSystem_Geo_0009 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0009 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Reverse address resolution test. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0009', 0, async function (done) { - let geocodeRequest = {"description": "上海市浦东新区金穗路1800号", "maxItems": 1}; + let geocodeRequest = { "description": "上海市浦东新区金穗路1800号", "maxItems": 1 }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); done(); }) /** - * @tc.number Geo_0010 - * @tc.name SUB_HSS_LocationSystem_Geo_0010 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0010 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Obtaining Multiple Locations Using the Reverse Address Resolution Function. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0010', 0, async function (done) { - let geocodeRequest = {"description": "上海市浦东新区金穗路1800号", "maxItems": 5}; + let geocodeRequest = { "description": "上海市浦东新区金穗路1800号", "maxItems": 5 }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation m callback data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName m promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); done(); }) /** - * @tc.number Geo_0011 - * @tc.name SUB_HSS_LocationSystem_Geo_0011 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0011 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid parameter input test for the reverse address resolution function. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0011', 0, async function (done) { - let geocodeRequest = {"description": "", "maxItems": 1}; + let geocodeRequest = { "description": "", "maxItems": 1 }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); - let geocodeRequest1 = {"description": null, "maxItems": 1}; + let geocodeRequest1 = { "description": null, "maxItems": 1 }; await geolocation.getAddressesFromLocationName(geocodeRequest1).then((result) => { console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); done(); }) /** - * @tc.number Geo_0012 - * @tc.name SUB_HSS_LocationSystem_Geo_0012 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0012 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Test the reverse address resolution function in the specified range.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0012', 0, async function (done) { - let geocodeRequest = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + let geocodeRequest = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); done(); }) /** - * @tc.number Geo_0013 - * @tc.name SUB_HSS_LocationSystem_Geo_0013 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0013 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid input parameter test for the reverse address resolution function in the specified range + * -Invalid location name. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0013', 0, async function (done) { - let geocodeRequest = {"description": "", "maxItems": 1, "minLatitude":331.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + let geocodeRequest = { + "description": "", + "maxItems": 1, + "minLatitude": 331.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(result.length==0).assertTrue(); + expect(result.length == 0).assertTrue(); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); - }); - let geocodeRequest1 = {"description": null, "maxItems": 1, "minLatitude":331.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + let geocodeRequest1 = { + "description": null, + "maxItems": 1, + "minLatitude": 331.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest1).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(result.length==0).assertTrue(); + expect(result.length == 0).assertTrue(); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); done(); }) /** - * @tc.number Geo_0014 - * @tc.name SUB_HSS_LocationSystem_Geo_0014 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0014 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid input parameter test for the reverse address resolution function in the specified range + * - the address is not in the range. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0014', 0, async function (done) { - let geocodeRequest = {"description": "北京天安门", "maxItems": 1, "minLatitude":40.85 , - "minLongitude":116.35,"maxLatitude":40.95,"maxLongitude":116.45}; + let geocodeRequest = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 40.85, + "minLongitude": 116.35, + "maxLatitude": 40.95, + "maxLongitude": 116.45 + }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(result.length>=0).assertTrue(); + expect(result.length >= 0).assertTrue(); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); done() }) /** - * @tc.number Geo_0015 - * @tc.name SUB_HSS_LocationSystem_Geo_0015 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0015 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid longitude and latitude entered for the reverse address resolution + * function in the specified range. The longitude and latitude range boundary is inverted.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0015', 0, async function (done) { - let geocodeRequest = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.95 , - "minLongitude":116.45,"maxLatitude":39.85,"maxLongitude":116.35}; + let geocodeRequest = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.95, + "minLongitude": 116.45, + "maxLatitude": 39.85, + "maxLongitude": 116.35 + }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result)); - expect(result.length>=0).assertTrue(); + expect(result.length >= 0).assertTrue(); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }); done() }) /** - * @tc.number Geo_0016 - * @tc.name SUB_HSS_LocationSystem_Geo_0016 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0016 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test for the reverse address resolution function in a specified range. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0016', 0, async function (done) { - let geocodeRequest1 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":-90 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + let geocodeRequest1 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": -90, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest1).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise1: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - let geocodeRequest2 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":90 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + expect(true).assertEqual(JSON.stringify(error) != null); + }); + let geocodeRequest2 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 90, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest2).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise2: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - let geocodeRequest3 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":-90.1 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + expect(true).assertEqual(JSON.stringify(error) != null); + }); + let geocodeRequest3 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": -90.1, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest3).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise3: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) ==null); + expect(true).assertEqual((JSON.stringify(result)) == null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); - }); - let geocodeRequest4 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":90.1 , - "minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943}; + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + let geocodeRequest4 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 90.1, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest4).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise4: " + JSON.stringify(result)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); + expect(true).assertEqual(JSON.stringify(error) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); - }); - let geocodeRequest5 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":-90,"maxLongitude":121.8026736943}; + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + let geocodeRequest5 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": -90, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest5).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise5: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - let geocodeRequest6 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":90,"maxLongitude":121.8026736943}; + expect(true).assertEqual(JSON.stringify(error) != null); + }); + let geocodeRequest6 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 90, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest6).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise6: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - let geocodeRequest7 ={"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":-90.1,"maxLongitude":121.8026736943}; + expect(true).assertEqual(JSON.stringify(error) != null); + }); + let geocodeRequest7 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": -90.1, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest7).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise7: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) ==null); + expect(true).assertEqual((JSON.stringify(result)) == null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); - }); - let geocodeRequest8 ={"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 , - "minLongitude":121.5782001832,"maxLatitude":90.1,"maxLongitude":121.8026736943}; + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + let geocodeRequest8 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 90.1, + "maxLongitude": 121.8026736943 + }; await geolocation.getAddressesFromLocationName(geocodeRequest8).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise8: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) ==null); + expect(true).assertEqual((JSON.stringify(result)) == null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) !=null); + expect(true).assertEqual((JSON.stringify(error)) != null); }); done() }) /** - * @tc.number Geo_0017 - * @tc.name SUB_HSS_LocationSystem_Geo_0017 - * @tc.desc Test getAddressesFromLocationName api . + * @tc.number SUB_HSS_LocationSystem_Geo_0017 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Longitude input parameter boundary test for the reverse address resolution function in a specified range * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0017', 0, async function (done) { - let geocodeRequest1 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":-180,"maxLatitude":39.95,"maxLongitude":116.45}; + let geocodeRequest1 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": -180, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; await geolocation.getAddressesFromLocationName(geocodeRequest1).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise1: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - let geocodeRequest2 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":180,"maxLatitude":39.95,"maxLongitude":116.45}; + expect(true).assertEqual(JSON.stringify(error) != null); + }); + let geocodeRequest2 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 180, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; await geolocation.getAddressesFromLocationName(geocodeRequest2).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise2: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest3 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":-180.1,"maxLatitude":39.95,"maxLongitude":116.45}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest3 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": -180.1, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; await geolocation.getAddressesFromLocationName(geocodeRequest3).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise3: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest4 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":180.1,"maxLatitude":39.95,"maxLongitude":116.45}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest4 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 180.1, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; await geolocation.getAddressesFromLocationName(geocodeRequest4).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise4: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest5 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":116.35,"maxLatitude":39.95,"maxLongitude":-180}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest5 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": -180 + }; await geolocation.getAddressesFromLocationName(geocodeRequest5).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise5: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest6 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":116.35,"maxLatitude":39.95,"maxLongitude":180}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest6 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": 180 + }; await geolocation.getAddressesFromLocationName(geocodeRequest6).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise6: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest7 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":116.35,"maxLatitude":39.95,"maxLongitude":-180.1}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest7 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": -180.1 + }; await geolocation.getAddressesFromLocationName(geocodeRequest7).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise7: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - let geocodeRequest8 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 , - "minLongitude":116.35,"maxLatitude":39.95,"maxLongitude":180.1}; + expect(error.length != 0).assertTrue(); + }); + let geocodeRequest8 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": 180.1 + }; await geolocation.getAddressesFromLocationName(geocodeRequest8).then((result) => { console.info("[lbs_js]getAddressesFromLocation promise8: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); + expect(true).assertEqual((JSON.stringify(result)) != null); }).catch((error) => { console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error)); - expect(error.length!=0).assertTrue(); - }); - done() - }) - - /** - * @tc.number LocSwitch_0001 - * @tc.name SUB_HSS_LocationSystem_LocSwitch_0001 - * @tc.desc Test isLocationEnabled api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LocSwitch_0001', 0, async function (done) { - geolocation.isLocationEnabled(async(err, data) => { - if (err) { - console.info('[lbs_js] getLocationSwitchState err is : ' + JSON.stringify(err) ); - - }else { - console.info('[lbs_js] getLocationSwitchState callback data1: ' + JSON.stringify(data)); - expect(data).assertTrue(); - } - done() - }) - }); - - /** - * @tc.number LocSwitch_0002 - * @tc.name SUB_HSS_LocationSystem_LocSwitch_0002 - * @tc.desc Test isLocationEnabled api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LocSwitch_0002', 0, async function (done) { - await geolocation.isLocationEnabled().then((result) => { - console.info('[lbs_js] getLocationSwitchStateLocSwitch_00021 result: ' + JSON.stringify(result)); - expect(result).assertTrue(); - }).catch((error) => { - expect().assertFail(); + expect(error.length != 0).assertTrue(); }); done(); }) - - /** - * @tc.number LocSwitch_0003 - * @tc.name SUB_HSS_LocationSystem_LocSwitch_0003 - * @tc.desc Test requestrequestEnableLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LocSwitch_0003', 0, async function (done) { - geolocation.isLocationEnabled(async(err, data) => { - if (err) { - console.info('[lbs_js] getLocationSwitchState callback err is : ' + JSON.stringify(err) ); - - }else { - console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data)); - expect(data).assertTrue(); - } - done() - }) - }); - - /** - * @tc.number LocSwitch_0004 - * @tc.name SUB_HSS_LocationSystem_LocSwitch_0004 - * @tc.desc Test requestrequestEnableLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LocSwitch_0004', 0, async function (done) { - await geolocation.isLocationEnabled().then((result1) => { - console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + JSON.stringify(result1)); - expect(result1).assertTrue(); - }).catch((error) => { - expect().assertFail(); - }); - done(); - }); - - /** - * @tc.number LocSwitch_0005 - * @tc.name SUB_HSS_LocationSystem_LocSwitch_0005 - * @tc.desc Test locationServiceState api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LocSwitch_0005', 0, async function (done) { - geolocation.on('locationServiceState', - (result) => { - console.info("locationServiceState on result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + JSON.stringify(err) ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + JSON.stringify(data)); - expect(data).assertTrue(); - } - done() - }); - geolocation.off('locationServiceState', - (result) => { - - console.info("locationServiceState off callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - }) - - /** - * @tc.number SingleLoc_0001 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0001 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0001', 0, async function(done) { - let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.requestEnableLocation(async(err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + JSON.stringify(err) ); - } - console.info("[lbs_js] requestEnableLocation callback data: " + JSON.stringify(data)); - expect(data).assertTrue(); - geolocation.getCurrentLocation(currentLocationRequest, - async(err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - } - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - }); - done() - }); - }) - - /** - * @tc.number SingleLoc_0002 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0002 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0002', 0, async function (done) { - let currentLocationRequest = { "priority": 0x203, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - try { - geolocation.getCurrentLocation(currentLocationRequest).then( (result) => { - console.info('[lbs_js] getCurrentLocation promise result '+ JSON.stringify(result)); - }); - }catch(error) { - console.info('[lbs_js] getCurrentLocation promise err is : ' + JSON.stringify(error)); - expect(true).assertEqual(error.length >= 0); - } - done(); - }) - - /** - * @tc.number SingleLoc_0003 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0003 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0003', 0, async function(done) { - let currentLocationRequest = { "priority": 0x200, "scenario": 0x302, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - } - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - expect(true).assertEqual(resultLength >= 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0004 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0004 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0004', 0, async function(done) { - let currentLocationRequest = { "priority": 0x200, "scenario": 0x303, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - } - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0005 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0005 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0005', 0, async function(done) { - let currentLocationRequest = { "priority": 0x200, "scenario": 0x304, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - } - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0006 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0006 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0006', 0, async function(done) { - let currentLocationRequest1 = { "priority": 0x200, "scenario": 0x305, "timeoutMs": 10, "maxAccuracy": 0 }; - let currentLocationRequest2= { "priority": 0x200, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest1, - async(err, result) => { - if (err){ - console.info("getCurrentLocation callback1 err: " + JSON.stringify(err)) - geolocation.getCurrentLocation(currentLocationRequest2, - async(err, result) => { - if (err){ - return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result2: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - done() - } - }); - } - console.info("getCurrentLocation callback, result1: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength == 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0007 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0007 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0007', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0008 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0008 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0008', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0009 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0009 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0009', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0010 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0010 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0010', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0011 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0011 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0011', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0012 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0012 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0012', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0013 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0013 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0013', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0014 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0014 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0014', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0303, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0015 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0015 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0015', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0304, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0016 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0016 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0016', 0, async function(done) { - let currentLocationRequest1 = { "priority": 0x201, "scenario": 0x305, "timeoutMs": 10, "maxAccuracy": 0 }; - let currentLocationRequest2= { "priority": 0x201, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest1, - async(err, result) => { - if (err){ - console.info("getCurrentLocation callback1 err: " + JSON.stringify(err)) - geolocation.getCurrentLocation(currentLocationRequest2, - async(err, result) => { - if (err){ - return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result2: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - done() - } - }); - } - console.info("getCurrentLocation callback, result1: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength == 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0017 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0017 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0017', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0018 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0018 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0018', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0019 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0019 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0019', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0302, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0020 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0020 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0020', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0303, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0021 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0021 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0021', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0304, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0022 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0022 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0022', 0, async function(done) { - let currentLocationRequest1 = { "priority": 0x202, "scenario": 0x305, "timeoutMs": 10, "maxAccuracy": 0 }; - let currentLocationRequest2= { "priority": 0x202, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest1, - async(err, result) => { - if (err){ - console.info("getCurrentLocation callback1 err: " + JSON.stringify(err)) - geolocation.getCurrentLocation(currentLocationRequest2, - async(err, result) => { - if (err){ - return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result2: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - done() - } - }); - } - console.info("getCurrentLocation callback, result1: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength == 0); - }); - done() - }) - - /** - * @tc.number SingleLoc_0023 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0023 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0023', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0024 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0024 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0024', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0302, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0025 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0025 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0025', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0303, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0026 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0026 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0026', 0, async function(done) { - let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0304, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - } - }); - done() - }) - - /** - * @tc.number SingleLoc_0027 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0027 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0027', 0, async function(done) { - let currentLocationRequest1 = { "priority": 0x203, "scenario": 0x305, "timeoutMs": 10, "maxAccuracy": 0 }; - let currentLocationRequest2= { "priority": 0x203, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest1, - async(err, result) => { - if (err){ - console.info("getCurrentLocation callback1 err: " + JSON.stringify(err)) - geolocation.getCurrentLocation(currentLocationRequest2, - async(err, result) => { - if (err){ - return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err)) - }else{ - console.info("getCurrentLocation callback, result2: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - done() - } - }); - } - console.info("getCurrentLocation callback, result1: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength == 0); - }); - done() - }) - - - - - /** - * @tc.number LastLocation_0001 - * @tc.name SUB_HSS_LocationSystem_LastLocation_0001 - * @tc.desc Test getLastLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LastLocation_0001', 0, async function (done) { - geolocation.getLastLocation(async(err, data) => { - if (err) { - console.info('[lbs_js] getLastLocation callback err is : ' + JSON.stringify(err) ); - }else { - console.info('[lbs_js] getLastLocation callback result: ' + JSON.stringify(data)); - expect(true).assertEqual(JSON.stringify(data)!=null); - } - done() - }) - }); - - /** - * @tc.number LastLocation_0002 - * @tc.name SUB_HSS_LocationSystem_LastLocation_0002 - * @tc.desc Test getLastLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_LastLocation_0002', 0, async function (done) { - await geolocation.getLastLocation().then((result) => { - console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(result)); - expect(result).assertTrue(); - }).catch((error) => { - console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0028 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0028 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0028', 0, async function (done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 }; - await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { - console.info("[lbs_js] getCurrentLocation promise data is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); - }).catch((error) => { - console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0029 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0029 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0029', 0, async function (done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0301, "timeoutMs": 10, "maxAccuracy": 0 }; - await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { - console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); - }).catch((error) => { - console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0030 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0030 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0030', 0, async function (done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0302, "timeoutMs": 10, "maxAccuracy": 0 }; - await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { - console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); - }).catch((error) => { - console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0031 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0031 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0031', 0, async function (done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0303, "timeoutMs": 10, "maxAccuracy": 0 }; - await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { - console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); - }).catch((error) => { - console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0032 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0032 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_SingleLoc_0032', 0, async function (done) { - let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0304, "timeoutMs": 10, "maxAccuracy": 0 }; - await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { - console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result)); - expect(true).assertEqual((JSON.stringify(result)) !=null); - }).catch((error) => { - console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - }); - done(); - }) - - /** - * @tc.number SingleLoc_0032 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0032 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_SendCommand_callback', 0, async function (done) { - let requestInfo = {'scenairo':0x301,'command':"command_1"}; - await geolocation.sendCommand(requestInfo,(err,result) =>{ - if(err){ - console.info('sendcommand callback err:'+err); - expect(true).assertEqual(JSON.stringify(err)!=null); - done(); - } - console.info('sendcommand callback result:' +result); - }); - }) - - /** - * @tc.number SingleLoc_0032 - * @tc.name SUB_HSS_LocationSystem_SingleLoc_0032 - * @tc.desc Test getCurrentLocation api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_SendCommand_promise', 0, async function (done) { - let requestInfo = {'scenairo':0x301,'command':"command_1"}; - await geolocation.sendCommand(requestInfo).then((result) =>{ - console.info('sendCommand promise result:'+result); - done(); - }).catch(error=>{ - console.info('sendcommand promise err:'+error); - expect(true).assertEqual(JSON.stringify(error)!=null); - done(); - }) - }) - - - }) - - - - diff --git a/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js b/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js new file mode 100644 index 000000000..376e636b8 --- /dev/null +++ b/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js @@ -0,0 +1,169 @@ +/* + * 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 geolocation from '@ohos.geolocation'; +import geolocations from '@system.geolocation'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + console.info('[lbs_js]sleep function'); +} + +async function changedLocationMode(){ + await geolocation.isLocationEnabled().then(async(result) => { + console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); + if(!result){ + await geolocation.requestEnableLocation().then(async(result) => { + await sleep(3000); + console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result)); + }).catch((error) => { + console.info("[lbs_js] promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + } + }); + await geolocation.isLocationEnabled().then(async(result) => { + console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); + }); +} + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("====>testgetuserid get AccountManager finish===="); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("====>testgetuserid localId obtained by process:" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + err); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + err); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} + +let CountryCodeType = { + COUNTRY_CODE_FROM_LOCALE : 1, + COUNTRY_CODE_FROM_SIM:2, + COUNTRY_CODE_FROM_LOCATION:3, + COUNTRY_CODE_FROM_NETWORK:4, + } + +describe('geolocationTest_4', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + + beforeEach(async function (done) { + console.info('beforeEach case'); + await changedLocationMode(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0001 + * @tc.name Test getCountryCode + * @tc.desc Obtaining Country Code Information + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0001', 0, async function (done) { + await geolocation.getCountryCode().then((result) => { + console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); + console.info("[lbs_js] country :" + result.country); + console.info("[lbs_js] type: " + result.type); + expect(true).assertTrue(JSON.stringify(result)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_SIM); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK); + }).catch((error) => { + console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0002 + * @tc.name Test getCountryCode + * @tc.desc Obtaining Country Code Information + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0002', 0, async function (done) { + function getCountryCodeCallback() { + return new Promise((resolve, reject) => { + geolocation.getCountryCode((err) => { + if (err) { + return console.info("getCountryCode callback err: " + JSON.stringify(err)); + } else { + console.info("getCountryCode callback success"); + } + resolve(); + }) + }) + } + await getCountryCodeCallback(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0003 + * @tc.name getCountryCode_on_off + * @tc.desc The interception country code is changed. + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0003', 0, async function (done) { + console.info("[lbs_js]countryCodeChange"); + geolocation.on('countryCodeChange', function (data) { + console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) ); + }); + await geolocation.getCountryCode().then((result) => { + console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); + expect(true).assertTrue(JSON.stringify(result)!=null); + }).catch((error) => { + console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + geolocation.off('countryCodeChange', function (data) { + console.info('[lbs_js] countryCodeChange' + JSON.stringify(data)); + done(); + }) + done(); + }) + +}) + + + + diff --git a/location/geolocation_standard/src/main/js/default/test/List.test.js b/location/geolocation_standard/src/main/js/default/test/List.test.js index a9d68ebc2..8792b7b89 100644 --- a/location/geolocation_standard/src/main/js/default/test/List.test.js +++ b/location/geolocation_standard/src/main/js/default/test/List.test.js @@ -14,7 +14,7 @@ */ require('./GeocoderTest.test.js') +require('./GetCountryCode.test.js') +require('./SystemLocation.test.js') require('./LocationTest.test.js') -require('./Geolocation.test.js') -require('./LocationMock.test.js') diff --git a/location/geolocation_standard/src/main/js/default/test/LocationMock.test.js b/location/geolocation_standard/src/main/js/default/test/LocationMock.test.js deleted file mode 100644 index 3f78c62cc..000000000 --- a/location/geolocation_standard/src/main/js/default/test/LocationMock.test.js +++ /dev/null @@ -1,371 +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 geolocation from '@ohos.geolocation'; -import geolocations from '@system.geolocation'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl' -import bundle from '@ohos.bundle' -import osaccount from '@ohos.account.osAccount' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); - console.info('[lbs_js]sleep function'); -} - -async function changedLocationMode(){ - await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); - if(!result){ - await geolocation.requestEnableLocation().then(async(result) => { - await sleep(3000); - console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result)); - }).catch((error) => { - console.info("[lbs_js] promise then error." + JSON.stringify(error)); - expect().assertFail(); - }); - } - }); - await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); - }); - -} - -async function applyPermission() { - let osAccountManager = osaccount.getAccountManager(); - console.debug("====>testgetuserid get AccountManager finish===="); - let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); - console.info("====>testgetuserid localId obtained by process:" + localId); - let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); - let atManager = abilityAccessCtrl.createAtManager(); - if (atManager != null) { - let tokenID = appInfo.accessTokenId; - console.info('[permission] case accessTokenID is ' + tokenID); - let permissionName1 = 'ohos.permission.LOCATION'; - let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; - await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { - console.info('[permission] case grantUserGrantedPermission success :' + result); - }).catch((err) => { - console.info('[permission] case grantUserGrantedPermission failed :' + err); - }); - await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { - console.info('[permission] case grantUserGrantedPermission success :' + result); - }).catch((err) => { - console.info('[permission] case grantUserGrantedPermission failed :' + err); - }); - } else { - console.info('[permission] case apply permission failed, createAtManager failed'); - } -} - -let CountryCodeType = { - COUNTRY_CODE_FROM_LOCALE : 1, - COUNTRY_CODE_FROM_SIM:2, - COUNTRY_CODE_FROM_LOCATION:3, - COUNTRY_CODE_FROM_NETWORK:4, - } - -describe('geolocationTest_4', function () { - beforeAll(async function (done) { - console.info('beforeAll case'); - await applyPermission(); - done(); - }) - - beforeEach(async function (done) { - console.info('beforeEach case'); - await changedLocationMode(); - done(); - }) - afterEach(function () { - }) - - /** - * @tc.number enableLocationMock_callback - * @tc.name enableLocationMock_callback - * @tc.desc Test enableLocationMock api . - * @tc.type Function - * @tc.level since 9 - */ - it('enableLocationMock_callback', 0, async function (done) { - console.info("[lbs_js]enableLocationMock" ); - let locationRequestScenario1 = {"scenario": 0x0301} - function enableLocationMockPromise(){ - return new Promise((resolve, reject)=>{ - geolocation.enableLocationMock(locationRequestScenario1,(err) => { - if (err){ - return console.info("enableLocationMock callback err: " + JSON.stringify(err)); - }else{ - console.info("enableLocationMock callback success!"); - } - resolve(); - }) - }) - } - await enableLocationMockPromise() - done() - }) - - - /** - * @tc.number disableLocationMock - * @tc.name disableLocationMock_callback - * @tc.desc Test disableLocationMock api . - * @tc.type Function - * @tc.level since 9 - */ - it('disableLocationMock_callback', 0, async function (done) { - console.info("[lbs_js]disableLocationMock"); - let locationRequestScenario1 = { "scenario": 0x0301 } - function disableLocationMockPromise() { - return new Promise((resolve, reject) => { - geolocation.disableLocationMock(locationRequestScenario1, (err) => { - if (err) { - return console.info("disableLocationMockPromise callback err: " + JSON.stringify(err)); - } else { - console.info("disableLocationMockPromise callback success"); - } - resolve(); - }) - }) - } - await disableLocationMockPromise() - done() - }) - - /** - * @tc.number getCountryCode - * @tc.name getCountryCode_promise - * @tc.desc Test getCountryCode api . - * @tc.type Function - * @tc.level since 9 - */ - it('getCountryCode_promise', 0, async function (done) { - await geolocation.getCountryCode().then((result) => { - console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); - console.info("[lbs_js] country :" + JSON.stringify(result).country); - console.info("[lbs_js] type: " + JSON.stringify(result).type); - expect(true).assertTrue(JSON.stringify(result)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE); - expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_SIM); - expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION); - expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK); - expect(true).assertTrue(JSON.stringify(result)!=null); - }).catch((error) => { - console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); - expect().assertFail(); - }); - done(); - }) - - /** - * @tc.number getCountryCode - * @tc.name getCountryCode_callback - * @tc.desc Test getCountryCode api . - * @tc.type Function - * @tc.level since 9 - */ - it('getCountryCode_callback', 0, async function (done) { - function getCountryCodePromise() { - return new Promise((resolve, reject) => { - geolocation.getCountryCode((err) => { - if (err) { - return console.info("getCountryCode callback err: " + JSON.stringify(err)); - } else { - console.info("getCountryCode callback success"); - } - resolve(); - }) - }) - } - await getCountryCodePromise(); - done(); - }) - - /** - * @tc.number getCountryCode - * @tc.name getCountryCode_on_off - * @tc.desc Test getCountryCode api . - * @tc.type Function - * @tc.level since 9 - */ - it('getCountryCode_on_off', 0, async function (done) { - console.info("[lbs_js]countryCodeChange"); - geolocation.on('countryCodeChange', function (data) { - console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) ); - }); - await geolocation.getCountryCode().then((result) => { - console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); - expect(true).assertTrue(JSON.stringify(result)!=null); - }).catch((error) => { - console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); - expect().assertFail(); - - }); - geolocation.off('countryCodeChange', function (data) { - console.info('[lbs_js] countryCodeChange' + JSON.stringify(data)); - done(); - }) - done(); - }) - - /** - * @tc.number setReverseGeocodingMockInfo - * @tc.name setReverseGeocodingMockInfo_callback - * @tc.desc Test setReverseGeocodingMockInfo api . - * @tc.type Function - * @tc.level since 9 - */ - it('setReverseGeocodingMockInfo_callback', 0, async function(done) { - function enableReverseGeocodingMockPromise() { - return new Promise((resolve, reject) => { - geolocation.enableReverseGeocodingMock( (err) => { - if (err) { - return console.info("enableReverseGeocodingMock callback err: " + JSON.stringify(err)); - } else { - console.info("enableReverseGeocodingMock callback success "); - } - resolve(); - }) - }) - } - await enableReverseGeocodingMockPromise(); - var locations = [ - {"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, - "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, - "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, - "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, - "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, - "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, - "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, - "isFromMock": true}}, - ]; - - function setReverseGeocodingMockInfoPromise(){ - return new Promise ((resolve,reject) =>{ - geolocation.setReverseGeocodingMockInfo(locations,(err) =>{ - if(err){ - console.info("[lbs_js]setReverseGeocodingMockInfo callback err:" +JSON.stringify(err) ); - }else{ - console.info("[lbs_js]setReverseGeocodingMockInfo callback called" ); - } - resolve(); - }); - }) - } - await setReverseGeocodingMockInfoPromise(); - - function disableReverseGeocodingMockPromise() { - return new Promise((resolve, reject) => { - geolocation.disableReverseGeocodingMock((err) => { - if (err) { - return console.info("disableReverseGeocodingMock callback err: " + JSON.stringify(err)); - } else { - console.info("[lbs_js] disableReverseGeocodingMock promise called " ); - } - resolve(); - }) - }) - } - await disableReverseGeocodingMockPromise() - done(); - - }) - - /** - * @tc.number setReverseGeocodingMockInfo - * @tc.name setReverseGeocodingMockInfo_promise - * @tc.desc Test setReverseGeocodingMockInfo api . - * @tc.type Function - * @tc.level since 9 - */ - it('setReverseGeocodingMockInfo_promise', 0, async function(done) { - function enableReverseGeocodingMockPromise() { - return new Promise((resolve, reject) => { - geolocation.enableReverseGeocodingMock( (err) => { - if (err) { - return console.info("enableReverseGeocodingMock callback err: " + JSON.stringify(err)); - } else { - console.info("enableReverseGeocodingMock callback success "); - } - resolve(); - }) - }) - } - await enableReverseGeocodingMockPromise(); - var locations = [ - {"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, - "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, - "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, - "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, - "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, - "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, - "isFromMock": true}}, - {"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, - "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, - "isFromMock": true}}, - ]; - geolocation.setReverseGeocodingMockInfo(locations).then(() =>{ - console.info("[lbs_js] setReverseGeocodingMockInfo promise called "); - geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { - console.info('[lbs_js] getAddressesFromLocation05 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) !=null); - done(); - }).catch((error) => { - console.info("[lbs_js] getAddressesFromLocation promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error)!=null); - done(); - }); - - }).catch((error) =>{ - console.info("[lbs_js] setReverseGeocodingMockInfo promise result: " + JSON.stringify(error)); - expect().assertFail(); - done(); - }) - - function disableReverseGeocodingMockPromise() { - return new Promise((resolve, reject) => { - geolocation.disableReverseGeocodingMock((err) => { - if (err) { - return console.info("disableReverseGeocodingMock callback err: " + JSON.stringify(err)); - } else { - console.info("[lbs_js] disableReverseGeocodingMock promise called " ); - } - resolve(); - }) - }) - } - await disableReverseGeocodingMockPromise() - done(); - - }) - -}) - - - - diff --git a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js index 94aa34e2e..a31e77976 100644 --- a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js @@ -47,13 +47,32 @@ async function changedLocationMode(){ } }); await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); + console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); }); } +async function enableLocationSwitch(){ + function enableLocationSwitchCallback(){ + return new Promise((resolve, reject)=>{ + geolocation.requestEnableLocation((err, data) => { + if (err) { + console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); + }else { + console.info("[lbs_js] requestEnableLocation callback data: " + data); + expect(data).assertTrue(); + } + }); + }) + } + await enableLocationSwitchCallback(); + done(); + +} + + async function applyPermission() { let osAccountManager = osaccount.getAccountManager(); - console.debug("=== getAccountManager finish"); + console.info("=== getAccountManager finish"); let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); console.info("LocalId is :" + localId); let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); @@ -79,24 +98,10 @@ async function applyPermission() { } describe('geolocationTest_geo3', function () { - let data = { - title: "", - locationChange: null, - locatlocationServiceState: null - } - console.log('#start AccessTokenTests#'); beforeAll(async function (done) { - await applyPermission(); - setTimeout(function () { - this.locationChange = (err, location) => { - console.log(' locationChange: ' + err + " data: " + JSON.stringify(location)); - }; - this.locationServiceState = (err, state) => { - console.log('locationServiceState: ' + err + " data: " + state); - }; - done(); - },3000); console.info('beforeAll case'); + await applyPermission(); + done(); }) beforeEach(function () { @@ -106,927 +111,945 @@ describe('geolocationTest_geo3', function () { }) /** - * @tc.number LocRequest_0001 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0001 - * @tc.desc Test locationChange api . + * @tc.number LocSwitch_0003 + * @tc.name SUB_HSS_LocationSystem_LocSwitch_0003 + * @tc.desc Test requestrequestEnableLocation api . * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0001', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { + it('SUB_HSS_LocationSystem_LocSwitch_0003', 0, async function (done) { + geolocation.isLocationEnabled(async (err, data) => { if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); + console.info('[lbs_js] getLocationSwitchState callback err is : ' + JSON.stringify(err)); + + } else { + console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data)); expect(data).assertTrue(); } done() - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }) + }) + }); /** - * @tc.number LocRequest_0002 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0002 - * @tc.desc Test locationChange api . + * @tc.number LocSwitch_0004 + * @tc.name SUB_HSS_LocationSystem_LocSwitch_0004 + * @tc.desc Test requestrequestEnableLocation api . * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0002', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() + it('SUB_HSS_LocationSystem_LocSwitch_0004', 0, async function (done) { + await geolocation.isLocationEnabled().then((result1) => { + console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + JSON.stringify(result1)); + expect(result1).assertTrue(); + }).catch((error) => { + expect().assertFail(); }); - let requestInfo = {"priority":0x200, "scenario":0x302, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }) + done(); + }); /** - * @tc.number LocRequest_0003 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0003 - * @tc.desc Test locationChange api . + * @tc.number LocSwitch_0005 + * @tc.name SUB_HSS_LocationSystem_LocSwitch_0005 + * @tc.desc Test locationServiceState api . * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0003', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + it('SUB_HSS_LocationSystem_LocSwitch_0005', 0, async function (done) { + console.log('just for overwriting,locationServiceState test need system api '); + var locationServiceState = (state) => { + console.log('locationServiceState: state: ' + JSON.stringify(state)); + } + geolocation.on('locationServiceState', locationServiceState); + geolocation.off('locationServiceState', locationServiceState); + done(); }) /** - * @tc.number LocRequest_0004 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0004 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0001 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0004', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() + it('SUB_HSS_LocationSystem_SingleLoc_0001', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 }; + function getCurrentLocationCallback() { + return new Promise((resolve, reject) => { + geolocation.getCurrentLocation(currentLocationRequest, (err, result) => { + if (err) { + console.info("getCurrentLocation callback err: " + JSON.stringify(err)); + expect(true).assertEqual(err != null); + console.info('getCurrentLocationCallback reject after') + } else { + console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve(); + } + }); + }) + } + console.info('getCurrentLocationCallback start'); + await getCurrentLocationCallback().then(() => { + console.info('getCurrentLocationCallback resolve'); + }, () => { + console.info('getCurrentLocationCallback reject'); }); - let requestInfo = {"priority":0x200, "scenario":0x304, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + console.info('getCurrentLocationCallback end'); + done(); }) /** - * @tc.number LocRequest_0005 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0005 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0002 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0005', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x200, "scenario":0x305, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0002', 0, async function (done) { + let currentLocationRequest = { "priority": 0x203, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation_0002 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LocRequest_0006 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0006 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0003 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the track tracing scenario. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0006', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo1 = {"priority":0x201, "scenario":0x300, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let requestInfo2 = {"priority":0x202, "scenario":0x300, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo1, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.on('locationChange',requestInfo2, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() + it('SUB_HSS_LocationSystem_SingleLoc_0003', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x302, "timeoutMs": 1000, "maxAccuracy": 10 }; + function getCurrentLocationCallback() { + return new Promise((resolve, reject) => { + geolocation.getCurrentLocation(currentLocationRequest, (err, result) => { + if (err) { + console.info("getCurrentLocation callback_0003 err: " + JSON.stringify(err)); + expect(true).assertEqual(err != null); + console.info('getCurrentLocationCallback reject after') + } else { + console.info("getCurrentLocation callback_0003, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve(); + } + }); + }) + } + console.info('getCurrentLocationCallback start'); + await getCurrentLocationCallback().then(() => { + console.info('getCurrentLocationCallback resolve'); + }, () => { + console.info('getCurrentLocationCallback reject'); }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + console.info('getCurrentLocationCallback end'); + done(); }) /** - * @tc.number LocRequest_0007 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0007 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0004 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set a car-sharing scenario. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0007', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x201, "scenario":0x300, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - async(locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0004', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x303, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result004 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err004:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LocRequest_0008 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0008 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0005 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the life service scenario.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0008', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x203, "scenario":0x300, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - async(locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0005', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x304, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result005 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err005:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LocRequest_0009 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0009 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0006 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario + * and set the scenario with no power consumption. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0009', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - async(locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0006', 0, async function (done) { + let currentLocationRequest1 = { "priority": 0x200, "scenario": 0x305, "timeoutMs": 1000, "maxAccuracy": 10 }; + let currentLocationRequest2 = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0061 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0061:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocation.getCurrentLocation(currentLocationRequest2).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0062 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation_0002 promise err0062:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LocRequest_0010 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0010 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0007 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with the parameter set to high-precision priority location request. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0010', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":3, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - async(locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0007', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result007 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err007:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LocRequest_0011 - * @tc.name SUB_HSS_LocationSystem_LocRequest_0011 - * @tc.desc Test locationChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0008 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with parameters set to fast location and priority location request. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LocRequest_0011', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":100, - "distanceInterval": 5, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - async(locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0008', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err010:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LastLoc_0001 - * @tc.name SUB_HSS_LocationSystem_LastLoc_0001 - * @tc.desc Test getLastLocation api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0009 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with parameters set to low power consumption. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LastLoc_0001', 0, async function(done) { - await geolocation.requestEnableLocation().then(async(result) => { - console.info('[lbs_js] test requestEnableLocation result: ' + result); - expect(result).assertTrue(); - let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 }; - geolocation.getCurrentLocation(currentLocationRequest, - (err, result) => { - if (err){ - return console.info("getCurrentLocation callback err: " + err) - } - console.info("getCurrentLocation callback, result: " + JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - }); - done() - }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); - expect().assertFail(); - }); - let requestInfo = {"priority":0x202, "scenario":0x301, "timeInterval":10, - "distanceInterval": 5, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.getLastLocation().then( (result) => { - console.info('[lbs_js] getLastLocation promise result '+ JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); - expect(true).assertEqual(error != null); - }); - geolocation.getLastLocation((err, data) => { - if (err) { - console.info('[lbs_js] getLastLocation callback err is : ' + err); - }else { - console.info("[lbs_js] getLastLocation callback data is: " + JSON.stringify(data)); - let resultLength = Object.keys(data).length; - expect(true).assertEqual(resultLength >= 0); - console.info('[lbs_js] getLastLocation latitude: ' + data[0].latitude + - ' longitude: ' + data[0].longitude +' altitude: ' + data[0].altitude - +' accuracy: ' + data[0].accuracy+' speed: ' + data[0].speed + - 'timeStamp: ' + data[0].timeStamp+'direction:' + data[0].direction+' timeSinceBoot: ' - + data[0].timeSinceBoot +'additions: ' + data[0].additions+' additionSize' + data[0].additionSize); - } - }); - done() + it('SUB_HSS_LocationSystem_SingleLoc_0009', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result009 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err009:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); }) /** - * @tc.number LastLoc_0002 - * @tc.name SUB_HSS_LocationSystem_LastLoc_0002 - * @tc.desc Test getLastLocation api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0010 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request and set the location reporting precision. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_LastLoc_0002', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { - if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); - expect(data).assertTrue(); - } - done() - }); - let requestInfo = {"priority":0x202, "scenario":0x301, "timeInterval":5, - "distanceInterval": 0, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - geolocation.off('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("offLocationChange callback " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); - await geolocation.getLastLocation().then( (result) => { - console.info('[lbs_js] getLastLocation promise result '+ JSON.stringify(result)); - let resultLength = Object.keys(result).length; - expect(true).assertEqual(resultLength >= 0); - done(); - }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); - expect(true).assertEqual(error != null); - done(); - }); + it('SUB_HSS_LocationSystem_SingleLoc_0010', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 5 }; + let currentLocationRequest1 = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 2 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err010:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0102 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0102:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + done(); }) /** - * @tc.number Gnss_0001 - * @tc.name SUB_HSS_LocationSystem_Gnss_0001 - * @tc.desc Test gnssStatusChange api . + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0011 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request for specific configuration + * and set the reporting precision of abnormal location. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_Gnss_0001', 0, async function (done) { - await changedLocationMode(); - var gnssStatusCb = (satelliteStatusInfo) => { - console.log('gnssStatusChange: ' + satelliteStatusInfo); - } - geolocation.on('gnssStatusChange', gnssStatusCb); - geolocation.off('gnssStatusChange', gnssStatusCb); + it('SUB_HSS_LocationSystem_SingleLoc_0011', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": -1 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result011 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err011:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0112 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0112:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) done(); }) /** - * @tc.number Gnss_0002 - * @tc.name SUB_HSS_LocationSystem_Gnss_0002 - * @tc.desc Test gnssStatusChange api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_Gnss_0002', 0, async function (done) { - await changedLocationMode(); - var nmeaCb = (str) => { - console.log('nmeaMessageChange: ' + str); - } - geolocation.on('nmeaMessageChange', nmeaCb); - geolocation.off('nmeaMessageChange', nmeaCb); + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0012 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request and set the location timeout interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_0012', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result012 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err012:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0122 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0122:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) done(); }) /** - * @tc.number GeoFence_0001 - * @tc.name SUB_HSS_LocationSystem_GeoFence_0001 - * @tc.desc Test fenceStatusChange api . - * @tc.size MEDIUM + * @tc.number SUB_HSS_LocationSystem_SingleLoc_0013 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a specified single location request and set the exception location timeout interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_0013', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": 0, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": -1000, "maxAccuracy": 0 }; + await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0131 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0122:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result0132 ' + JSON.stringify(result)); + }).catch(error => { + console.info('getCurrentLocation promise err0122:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done() + }) + + + + /** + * @tc.number SUB_HSS_SendCommand_callback + * @tc.name Test sendCommand + * @tc.desc Test sendCommand api . + * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_GeoFence_0001', 0, async function (done) { - await changedLocationMode(); - let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; - let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence}; - setTimeout(async ()=>{ - let want = (wantAgent) => { - console.log('wantAgent: ' + JSON.stringify(wantAgent)); - }; - geolocation.on('fenceStatusChange', geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange on callback err: " + err); - } - console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - done(); - }); - geolocation.off('fenceStatusChange',geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange callback err: " + err); - } - console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - }); - },1000); + it('SUB_HSS_SendCommand_callback', 0, async function (done) { + let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; + await geolocation.sendCommand(requestInfo, (err, result) => { + if (err) { + console.info('sendcommand callback err:' + JSON.stringify(err)); + expect(true).assertEqual(JSON.stringify(err) != null); + done(); + } + console.info('sendcommand callback result:' + JSON.stringify(result)); + }); + }) + + /** + * @tc.number SUB_HSS_SendCommand_promise + * @tc.name Test sendCommand + * @tc.desc Test sendCommand1 api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_SendCommand_promise', 0, async function (done) { + let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; + geolocation.sendCommand(requestInfo).then((result) => { + console.info('sendCommand promise result:' + result); + done(); + }).catch(error => { + console.info('sendcommand promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0001 + * @tc.name Test locationChange + * @tc.desc Initiate a request for continuous positioning in a specified scenario and set the navigation scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0001', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); done(); }) /** - * @tc.number GeoFence_0003 - * @tc.name SUB_HSS_LocationSystem_GeoFence_0003 - * @tc.desc Test fenceStatusChange api . + * @tc.number SUB_HSS_LocationSystem_LocRequest_0002 + * @tc.name Test locationChange + * @tc.desc Initiate a request for continuous positioning in a specified scenario and set a track tracing scenario. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_GeoFence_0003', 0, async function (done) { - await changedLocationMode(); - let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; - let geofenceRequest = {"priority":0x200, "scenario":0x304, "geofence": geofence}; - setTimeout(async ()=>{ - let want = (wantAgent) => { - console.log('wantAgent: ' + JSON.stringify(wantAgent)); - }; - geolocation.on('fenceStatusChange', geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange on callback err: " + err); - } - console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - done(); - }); - geolocation.off('fenceStatusChange',geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange callback err: " + err); - } - console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - }); - },1000); + it('SUB_HSS_LocationSystem_LocRequest_0002', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x302, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); done(); }) /** - * @tc.number GeoFence_0004 - * @tc.name SUB_HSS_LocationSystem_GeoFence_0004 - * @tc.desc Test fenceStatusChange api . + * @tc.number SUB_HSS_LocationSystem_LocRequest_0003 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario and set a car-sharing scenario. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_GeoFence_0004', 0, async function (done) { - await changedLocationMode(); - let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; - let geofenceRequest = {"priority":0x203, "scenario":0x300, "geofence": geofence}; - setTimeout(async ()=>{ - let want = (wantAgent) => { - console.log('wantAgent: ' + JSON.stringify(wantAgent)); - }; - geolocation.on('fenceStatusChange', geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange on callback err: " + err); - } - console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - done(); - }); - geolocation.off('fenceStatusChange',geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange callback err: " + err); - } - console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - }); - },1000); + it('SUB_HSS_LocationSystem_LocRequest_0003', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":5, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); done(); }) /** - * @tc.number GeoFence_0005 - * @tc.name SUB_HSS_LocationSystem_GeoFence_0005 - * @tc.desc Test fenceStatusChange api . + * @tc.number SUB_HSS_LocationSystem_LocRequest_0004 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario and set a life service scenario. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 1 + * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_GeoFence_0005', 0, async function (done) { - await changedLocationMode(); - let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; - let geofenceRequest = {"priority":0x203, "scenario":0x301, "geofence": geofence}; - setTimeout(async ()=>{ - let want = (wantAgent) => { - console.log('wantAgent: ' + JSON.stringify(wantAgent)); - }; - geolocation.on('fenceStatusChange', geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange on callback err: " + err); - } - console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - done(); - }); - geolocation.off('fenceStatusChange',geofenceRequest, - (want) => { - if(err){ - return console.info("fenceStatusChange callback err: " + err); - } - console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); - expect(true).assertEqual(want !=null); - }); - },1000); + it('SUB_HSS_LocationSystem_LocRequest_0004', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); done(); }) /** - * @tc.number Batching_0001 - * @tc.name SUB_HSS_LocationSystem_Batching_0001 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_LocRequest_0005 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario + * and set the scenario with no power consumption. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_Batching_0001', 0, async function (done) { - await changedLocationMode(); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": false}; - geolocation.on('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - }); + it('SUB_HSS_LocationSystem_LocRequest_0005', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x305, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange1 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + var locationChange2 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange1); + geolocation.on('locationChange', requestInfo, locationChange2); + geolocation.off('locationChange', locationChange1); + geolocation.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0007 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request and + * set the parameter to high-precision priority positioning request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0007', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x201, "scenario":0x300, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0008 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request with the parameter + * set to fast positioning and priority positioning request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0008', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x203, "scenario":0x300, "timeInterval":5, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0009 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request with the parameter + * set to low power consumption type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0009', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10} + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0010 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the reporting interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0010', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":3, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0011 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the location reporting interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0011', 0, async function (done) { + enableLocationSwitch(); let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - }); - let request1 = {"reportingPeriodSec": 10, "wakeUpCacheQueueFull": false}; - geolocation.on('cachedGnssLocationsReporting',request1, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - }); + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0012 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the interval for reporting exceptions. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0012', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0013 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the interval for reporting abnormal locations. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0013', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange1 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + var locationChange2 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo1, locationChange1); + geolocation.off('locationChange', locationChange1); + geolocation.on('locationChange', requestInfo2, locationChange2); + geolocation.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0014 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request and set the positioning reporting precision. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0014', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 5}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 2}; + var locationChange1 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + var locationChange2 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo1, locationChange1); + geolocation.off('locationChange', locationChange1); + geolocation.on('locationChange', requestInfo2, locationChange2); + geolocation.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_0015 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the reporting precision of abnormal location. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_0015', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": -1}; + var locationChange1 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + var locationChange2 = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo1, locationChange1); + geolocation.off('locationChange', locationChange1); + geolocation.on('locationChange', requestInfo2, locationChange2); + geolocation.off('locationChange', locationChange2); done(); }) /** - * @tc.number Batching_0002 - * @tc.name SUB_HSS_LocationSystem_Batching_0002 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_LastLoc_0001 + * @tc.name Test getLastLocation + * @tc.desc Obtain the last location after a single location. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_Batching_0002', 0, async function (done) { - geolocation.requestEnableLocation((err, data) => { + it('SUB_HSS_LocationSystem_LastLoc_0001', 0, async function(done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + await geolocation.getLastLocation().then((result) => { + console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(result)); + expect(true).assertEqual(JSON.stringify(result) != null); + console.info('[lbs_js] getLastLocation latitude: ' + result.latitude + + ' longitude: ' + result.longitude +' altitude: ' + result.altitude + +' accuracy: ' + result.accuracy+' speed: ' + result.speed + + 'timeStamp: ' + result.timeStamp+'direction:' + result.direction+' timeSinceBoot: ' + + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize); + }).catch((error) => { + console.info("[lbs_js] getLastLocation promise then error:" + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LastLoc_0002 + * @tc.name Test getLastLocation + * @tc.desc Obtain the last location after continuous positioning. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LastLoc_0002', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('locationChange', locationChange); + geolocation.getLastLocation(async (err, data) => { if (err) { - console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); - }else { - console.info("[lbs_js] requestEnableLocation callback data: " + data); + console.info('[LastLoc_0002] getLastLocation callback err is : ' + JSON.stringify(err)); + } else { + console.info('[LastLoc_0002] getLastLocation callback result: ' + JSON.stringify(data)); expect(data).assertTrue(); } done() - }); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": false}; - geolocation.on('cachedGnssLocationsReporting',request, - result => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Gnss_0001 + * @tc.name Test gnssStatusChange + * @tc.desc Monitoring Satellite Information Reporting + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Gnss_0001', 0, async function (done) { + await changedLocationMode(); + var gnssStatusCb = (satelliteStatusInfo) => { + console.info('gnssStatusChange: ' + satelliteStatusInfo); + expect(true).assertEqual(satelliteStatusInfo != null) + console.info('[lbs_js] SatelliteStatusInfo satellitesNumber: ' + data[0].satellitesNumber + + 'satelliteIds' + data[0].satelliteIds +'carrierToNoiseDensitys'+ data[0].carrierToNoiseDensitys + +'altitudes' + data[0].altitudes+' azimuths: ' + data[0].azimuths + + 'carrierFrequencies: ' + data[0].carrierFrequencies); + } + geolocation.on('gnssStatusChange', gnssStatusCb); + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done() - }); - geolocation.off('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("cachedGnssLocationsReporting callback err: " + err); - } - console.info("offcachedGnssLocationsReporting callback " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('gnssStatusChange', gnssStatusCb); + geolocation.off('locationChange', locationChange); + done(); }) /** - * @tc.number Batching_0003 - * @tc.name SUB_HSS_LocationSystem_Batching_0003 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_Gnss_0002 + * @tc.name Test nmeaMessageChange + * @tc.desc Monitoring NMEA Information Reporting * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_Batching_0003', 0, async function (done) { + it('SUB_HSS_LocationSystem_Gnss_0002', 0, async function (done) { await changedLocationMode(); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": true}; - geolocation.on('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var nmeaCb = (str) => { + console.log('nmeaMessageChange: ' + str); + } + var locationChange = (location) => { + console.log('locationChanger: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + geolocation.on('nmeaMessageChange', nmeaCb); + geolocation.on('locationChange', requestInfo, locationChange); + geolocation.off('nmeaMessageChange', nmeaCb); + geolocation.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0001 + * @tc.name Test cachedGnssLocationsReporting + * @tc.desc Setting the Gnss Batching Reporting Interval + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_0001', 0, async function (done) { + var cachedLocationsCb1 = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest1 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest1, cachedLocationsCb1); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1); + var cachedLocationsCb2 = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest2 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest2, cachedLocationsCb2); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0002 + * @tc.name Test cachedGnssLocationsReporting + * @tc.desc Setting the Gnss Batching Cache Queue to Be Reported When the Gnss Batching Cache Queue Is Full + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_0002', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0003 + * @tc.name Test getCachedGnssLocationsSize + * @tc.desc Obtains the number of GNSS data records in the batching process. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_0003', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); geolocation.getCachedGnssLocationsSize((err, data) => { if (err) { console.info('[lbs_js] getCachedGnssLocationsSize callback err is : ' + err); @@ -1038,91 +1061,56 @@ describe('geolocationTest_geo3', function () { done() } }); - + done(); }) /** - * @tc.number Batching_0004 - * @tc.name SUB_HSS_LocationSystem_Batching_0004 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_Batching_0004 + * @tc.name Test getCachedGnssLocationsSize + * @tc.desc Obtains the number of GNSS data records in the batching process. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Batching_0004', 0, async function (done) { - await changedLocationMode(); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": true}; - geolocation.on('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + var cachedLocationsCb = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); await geolocation.getCachedGnssLocationsSize().then( (result) => { console.info('[lbs_js] getCachedGnssLocationsSiz promise '+ JSON.stringify(result)); expect(true).assertTrue(result != null); done(); }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); + console.info("[lbs_js] promise then error." + JSON.stringify(error)); expect(true).assertTrue(error != null); done(); - done(); }); }) /** - * @tc.number Batching_0005 - * @tc.name SUB_HSS_LocationSystem_Batching_0005 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_Batching_0005 + * @tc.name Test flushCachedGnssLocations + * @tc.desc Obtains the GNSS data of the current batching. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Batching_0005', 0, async function (done) { - await changedLocationMode(); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": true}; - geolocation.on('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - expect(true).assertTrue(err != null); - done(); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + var cachedLocationsCb = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); geolocation.flushCachedGnssLocations((err, data) => { if (err) { console.info('[lbs_js] flushCachedGnssLocations callback err is : ' + err); @@ -1134,57 +1122,112 @@ describe('geolocationTest_geo3', function () { done(); } }); - + done(); }) /** - * @tc.number Batching_0006 - * @tc.name SUB_HSS_LocationSystem_Batching_0006 - * @tc.desc Test cachedGnssLocationsReporting api. + * @tc.number SUB_HSS_LocationSystem_Batching_0006 + * @tc.name Test flushCachedGnssLocations + * @tc.desc Obtain the GNSS data of the current batching. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Batching_0006', 0, async function (done) { - await changedLocationMode(); - let request = {"reportingPeriodSec": 5, "wakeUpCacheQueueFull": true}; - geolocation.on('cachedGnssLocationsReporting',request, - (result) => { - if(err){ - return console.info("oncachedGnssLocationsReporting callback err: " + err); - } - console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); - expect(true).assertEqual(result !=null); - done(); - }); - let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, - "distanceInterval": 30, "maxAccuracy": 0}; - let locationChange = (location) => { - console.log('locationChanger: ' + JSON.stringify(location)); - }; - geolocation.on('locationChange',requestInfo, - (locationChange) => { - if(err){ - return console.info("onLocationChange callback err: " + err); - } - console.info("onLocationChange callback, result: " + JSON.stringify(locationChange)); - expect(true).assertEqual(locationChange !=null); - done(); - }); + var cachedLocationsCb = (locations) => { + console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); await geolocation.flushCachedGnssLocations().then( (result) => { console.info('[lbs_js] flushCachedGnssLocations promise '+ JSON.stringify(result)); expect(true).assertTrue(result); done(); }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); + console.info("[lbs_js] promise then error." + JSON.stringify(error)); expect(true).assertTrue(error != null); done(); }); + done(); }) -}) - - + /** + * @tc.number SUB_HSS_LocationSystem_GeoFence_0001 + * @tc.name Test fenceStatusChange + * @tc.desc Gnss fence function test + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_HSS_LocationSystem_GeoFence_0001', 0, async function (done) { + await changedLocationMode(); + let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; + let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence}; + setTimeout(async ()=>{ + let want = (wantAgent) => { + console.log('wantAgent: ' + JSON.stringify(wantAgent)); + }; + geolocation.on('fenceStatusChange', geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange on callback err: " + err); + } + console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + done(); + }); + geolocation.off('fenceStatusChange',geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange callback err: " + err); + } + console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + }); + },1000); + done(); + }) + /** + * @tc.number SUB_HSS_LocationSystem_GeoFence_0005 + * @tc.name Test fenceStatusChange + * @tc.desc Test the function of locating the validity period of the fence. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_HSS_LocationSystem_GeoFence_0005', 0, async function (done) { + await changedLocationMode(); + let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; + let geofenceRequest = {"priority":0x203, "scenario":0x301, "geofence": geofence}; + setTimeout(async ()=>{ + let want = (wantAgent) => { + console.log('wantAgent: ' + JSON.stringify(wantAgent)); + }; + geolocation.on('fenceStatusChange', geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange on callback err: " + err); + } + console.info("fenceStatusChange callback, result: " + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + done(); + }); + geolocation.off('fenceStatusChange',geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange callback err: " + err); + } + console.info("off fenceStatusChange callback, result: " + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + }); + },1000); + done(); + }) +}) diff --git a/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js b/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js similarity index 73% rename from location/geolocation_standard/src/main/js/default/test/Geolocation.test.js rename to location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js index 24dd912c7..73f0b6826 100644 --- a/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js +++ b/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js @@ -21,7 +21,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); - } +} async function changedLocationMode(){ await geolocation.isLocationEnabled().then(async(result) => { @@ -37,13 +37,13 @@ async function changedLocationMode(){ } }); await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); + console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); }); } async function applyPermission() { let osAccountManager = osaccount.getAccountManager(); - console.debug("=== getAccountManager finish"); + console.info("=== getAccountManager finish"); let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); console.info("LocalId is :" + localId); let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); @@ -81,57 +81,16 @@ describe('geolocationTest_geo2', function () { }) afterEach(function () { }) - - /** - * @tc.number LocationSystem_0001 - * @tc.name SUB_HSS_LocationSystem_0001 - * @tc.desc Test getSupportedCoordTypes api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_0001', 0, function () { - let types = geolocations.getSupportedCoordTypes(); - console.info('[lbs_js] getSupportedCoordTypes result: ' + JSON.stringify(types)); - expect(true).assertEqual(types.length !=0); - - }) - - /** - * @tc.number LocationSystem_0002 - * @tc.name SUB_HSS_LocationSystem_0002 - * @tc.desc Test getLocationType api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_0002', 0, async function (done) { - geolocations.getLocationType({ - success: function(data) { - console.log('success get location type:' + JSON.stringify(data)); - expect(true).assertEqual(data.types.length !=0); - done() - }, - fail: function(data, code) { - console.log('fail to get location. code:' + code + ', data:' + JSON.stringify(data)); - expect().assertFail(); - done() - }, - complete: function(result) { - console.log('get location end' + JSON.stringify(result)); - }, - }); - }) - + /** - * @tc.number LocationSystem_0003 - * @tc.name SUB_HSS_LocationSystem_0003 - * @tc.desc Test getLocation api . + * @tc.number SUB_HSS_LocationSystem_systemapi_0001 + * @tc.name Test getLocation + * @tc.desc Obtains the geographical location of a device.. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_0003', 0, async function (done) { + it('SUB_HSS_LocationSystem_systemapi_0001', 0, async function (done) { geolocations.getLocation({ timeout:30000, coordType:'wgs84', @@ -160,22 +119,22 @@ describe('geolocationTest_geo2', function () { console.info("该次调用结果未返回前接口又被重新调用/该次调用失败返回错误码: "+ err); break; default: - console.log('lbs_js [GetLocation-fail] data:' + data + ', code:' + code); + console.log('lbs_js [GetLocation-fail] data:' + data + ', code:' + code); } }, }); done(); }) - + /** - * @tc.number LocationSystem_0004 - * @tc.name SUB_HSS_LocationSystem_0004 + * @tc.number SUB_HSS_LocationSystem_systemapi_0002 + * @tc.name Test subscribe and unsubscribe * @tc.desc Test subscribe api . * @tc.size MEDIUM * @tc.type Function * @tc.level Level 2 */ - it('SUB_HSS_LocationSystem_0004', 0, async function (done) { + it('SUB_HSS_LocationSystem_systemapi_0002', 0, async function (done) { geolocations.subscribe({ coordType:'wgs84', success: function(data) { @@ -187,24 +146,60 @@ describe('geolocationTest_geo2', function () { expect().assertFail(); }, }); + geolocation.unsubscribe(); + console.info("[lbs_js] unsubscribe called") done(); }) /** - * @tc.number LocationSystem_0005 - * @tc.name SUB_HSS_LocationSystem_0005 - * @tc.desc Test unsubscribe api . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_HSS_LocationSystem_0005', 0, async function (done) { - geolocation.unsubscribe(); - console.info("[lbs_js] unsubscribe called") - done(); + * @tc.number SUB_HSS_LocationSystem_systemapi_0003 + * @tc.name test getLocationType + * @tc.desc Subscribing to geographical location information . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_systemapi_0003', 0, async function (done) { + geolocations.getLocationType({ + success: function(data) { + console.log('success get location type:' + JSON.stringify(data)); + expect(true).assertEqual(data.types.length !=0); + done() + }, + fail: function(data, code) { + console.log('fail to get location. code:' + code + ', data:' + JSON.stringify(data)); + expect().assertFail(); + done() + }, + complete: function(result) { + console.log('get location end' + JSON.stringify(result)); + }, + }); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_systemapi_0004 + * @tc.name Test getSupportedCoordTypes + * @tc.desc Obtains the geographical location of a device.. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_systemapi_0004', 0, function () { + let types = geolocations.getSupportedCoordTypes(); + console.info('[lbs_js] getSupportedCoordTypes result: ' + JSON.stringify(types)); + expect(true).assertEqual(types.length !=0); + }) - }) + + + + + + + + -- GitLab