diff --git a/communication/BUILD.gn b/communication/BUILD.gn index 615c6d2b9a341f33a3b66b63b357089a68967cb6..1b03605ec9cd28752777899aafc10a5e44eea894 100644 --- a/communication/BUILD.gn +++ b/communication/BUILD.gn @@ -17,6 +17,7 @@ group("communication") { if (is_standard_system) { deps = [ "bluetooth_ble:ActsBluetoothBleJsTest", + "bluetooth_manager:ActsBluetoothBleJs1Test", "bluetooth_on:ActsBluetoothOnJsTest", "bluetooth_profile:ActsBluetoothProFileJsTest", "bluetooth_standard:ActsBluetoothJsTest", diff --git a/communication/bluetooth_manager/BUILD.gn b/communication/bluetooth_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..80a55acca99f0afc583948daeab8887ca174ee4c --- /dev/null +++ b/communication/bluetooth_manager/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("ActsBluetoothBleJs1Test") { + hap_profile = "./src/main/config.json" + deps = [ + ":bluetooth_js_assets", + ":bluetooth_resources", + ] + + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsBluetoothBleManagerHapTest" + part_name = "bluetooth" + subsystem_name = "communication" +} +ohos_js_assets("bluetooth_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("bluetooth_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/communication/bluetooth_manager/Test.json b/communication/bluetooth_manager/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..41e1389539144d66bc62697644fd2242d70a98c9 --- /dev/null +++ b/communication/bluetooth_manager/Test.json @@ -0,0 +1,20 @@ +{ + "description": "Configuration for bluetooth js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "shell-timeout": "600000", + "bundle-name": "ohos.acts.communication.bluetooth.bluetoothhost", + "package-name": "ohos.acts.communication.bluetooth.bluetoothhost", + "testcase-timeout": 70000 + }, + "kits": [ + { + "test-file-name": [ + "ActsBluetoothBleManagerHapTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/communication/bluetooth_manager/signature/openharmony_sx.p7b b/communication/bluetooth_manager/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..5f165bc5913d474d4e5bd0e5a2f3b492f5087a63 Binary files /dev/null and b/communication/bluetooth_manager/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_manager/src/main/config.json b/communication/bluetooth_manager/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..2b3e44f06cc9c61f7c22faec8570caeaebc07f74 --- /dev/null +++ b/communication/bluetooth_manager/src/main/config.json @@ -0,0 +1,137 @@ +{ + "app": { + "bundleName": "ohos.acts.communication.bluetooth.bluetoothhost", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.communication.bluetooth.bluetoothhost", + "name": ".entry", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.USE_BLUETOOTH", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.MANAGE_BLUETOOTH", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.DISCOVER_BLUETOOTH", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/app.js b/communication/bluetooth_manager/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/i18n/en-US.json b/communication/bluetooth_manager/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..a4c13dcbdc39c537073f638393d7726ac9a5cdc4 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/i18n/zh-CN.json b/communication/bluetooth_manager/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..b1c02368f72f929e4375a43170444de95dcc5984 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.css b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..e84b0d6300d7a299aed5376be2cba12327f9d9d2 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.hml b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..43848d302f5c5cd40b7aad5e19f6c7ea15373d91 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.js b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..014e63a263c208b0afc5eb3809a206d5b879f038 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* + * 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. + */ + + + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + console.info('onReady finish') + }, +} + diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/app.js b/communication/bluetooth_manager/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/i18n/en-US.json b/communication/bluetooth_manager/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/i18n/zh-CN.json b/communication/bluetooth_manager/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.css b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.hml b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.js b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/communication/bluetooth_manager/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/communication/bluetooth_manager/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..c5fa8620ca77d381f20b65a903b833e6e3378c97 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js new file mode 100644 index 0000000000000000000000000000000000000000..71ea19e33ef3e3788abc4c999034df05ceaca177 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js @@ -0,0 +1,948 @@ + +/* + * 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.bluetoothManager'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + + +export default function bluetoothBLETest2() { +describe('bluetoothBLETest2', function() { + let gattServer = 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(async function (done) { + console.info('beforeAll called') + await tryToEnableBt() + gattServer = bluetooth.BLE.createGattServer(); + done() + }) + 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 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0100', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:150, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0200', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:20, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0300', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10485, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0400', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:16400, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0500', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:19, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0800', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_0900', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-127, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1000', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1100', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error('[bluetooth_js]startAdvertising11 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1200', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-130, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error('[bluetooth_js]startAdvertising12 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1400', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:false, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1500', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising15 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1800', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:[""], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:[""], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising18 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_1900', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising19 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_2100', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:1000, + txPower:1, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + gattServer.stopAdvertising(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising21 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400 + * @tc.name testStartAdvertising + * @tc.desc Test StartAdvertising api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_StartAdvertise_0400', 0, function () { + let isRet = true; + try{ + gattServer.stopAdvertising(); + expect(isRet).assertTrue(); + }catch(error){ + console.info("[bluetooth_js] GattclientClose err:" + JSON.stringify(error)); + let isRet = false; + expect(isRet).assertFalse(); + } + }) + +}) + +} diff --git a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e770c8ff82b68bbaa1a2c02511b3338974708d04 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js @@ -0,0 +1,588 @@ + +/* + * 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 bluetooth from '@ohos.bluetoothManager'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + + +export default function bluetoothBLETest5() { +describe('bluetoothBLETest5', function() { + let gattServer = 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(async function (done) { + console.info('beforeAll called') + await tryToEnableBt() + gattServer = bluetooth.BLE.createGattServer(); + done() + }) + 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 COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3000 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - parameters setting is null. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3000', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(advData,advResponse); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error('[bluetooth_js]startAdvertising30 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3100 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - parameters setting is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3100', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(null,advData,advResponse); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error('[bluetooth_js]startAdvertising31 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3200 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - interval of setting is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3200', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:'sss', + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising32 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3300 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - txPower of setting is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3300', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:'ttt', + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising33 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3400 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - connectable of setting is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3400', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:123123, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising34 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3500 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - parameters advData is null. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3500', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + try { + gattServer.startAdvertising(setting); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising35 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3600 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - serviceUuids of advData is null. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3600', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + let advData={ + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising36 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3700 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - manufactureData of advData is null. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3700', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising37 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3800 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - serviceData of advData is null. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3800', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising38 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3900 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - manufactureValue of advData is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_3900', 0, async function (done) { + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:123 + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising39 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_4000 + * @tc.name testStartAdvertising + * @tc.desc Test api 401 - serviceValue of advData is error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AdvertiseData_4000', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let setting={ + interval:10385, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:123123 + }], + } + try { + gattServer.startAdvertising(setting,advData); + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error(`[bluetooth_js]startAdvertising40 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + + + + +}) + +} diff --git a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js new file mode 100644 index 0000000000000000000000000000000000000000..5a86892e054d0f73073642947acd4d29347cac8a --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js @@ -0,0 +1,972 @@ +/* + * 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.bluetoothManager'; +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("11:22:33:44:55:66"); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(async function (done) { + console.info('afterAll called') + await sleep(6000); + gattClient.close(); + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_GattConnect_0100 + * @tc.name test gatt connect and disconnect + * @tc.desc Test api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_GattConnect_0100', 0, async function (done) { + try { + gattClient.connect(); + await sleep(2000); + gattClient.disconnect(); + expect(true).assertFalse(); + } catch(error) { + console.error(`[bluetooth_js]disconnect failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_Connect_0200 + * @tc.name testGetConnectedBLEDevices + * @tc.desc Test api 201 - Permission denied. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_GattConnect_0200', 0, function () { + try { + let result = bluetooth.BLE.getConnectedBLEDevices(); + console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result) + + "length:" +result.length); + expect(result.length).assertEqual(0); + } catch (error) { + console.error(`[bluetooth_js]getConnDev failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_Connect_0300 + * test Client BLEconnectStateChange + * @tc.desc Test on and off api + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_GattConnect_0300', 0, async function (done) { + try { + function ConnectStateChanged(state) { + console.log('bluetooth connect state changed'); + let connectState = state.state; + console.info('[bluetooth_js] state changed' + connectState) + expect(true).assertEqual(connectState!=null); + } + await gattClient.on('BLEConnectionStateChange', ConnectStateChanged); + gattClient.connect(); + gattClient.disconnect(); + await sleep(2000); + await gattClient.off("BLEConnectionStateChange"); + done() + } catch (error) { + console.error(`[bluetooth_js]GattConnect_0300 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0100', 0, async function (done) { + try { + 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); + done(); + }).catch(err => { + console.info('bluetooth getRssiValue has error: '+ JSON.stringify(err)); + done(); + }); + } catch (error) { + console.error(`[bluetooth_js]GetRssiValue_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetRssiValue_0200', 0, async function (done) { + try { + let promise = new Promise((resolve) => { + gattClient.getRssiValue((err, data)=> { + if (err) { + console.error('getRssi failed '); + } + console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); + expect(data).assertNull(); + }); + resolve() + }) + await promise.then(done) + } catch (error) { + console.error(`[bluetooth_js]GetRssiValue_0200 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0100', 0, async function (done) { + await sleep(5000) + try { + await gattClient.getDeviceName().then((data) => { + console.info('[bluetooth_js] device name' + JSON.stringify(data)) + expect(data).assertNull(); + done(); + }).catch(err => { + console.error('bluetooth getDeviceName has error: '+ err); + expect(true).assertFalse(); + done(); + }); + } catch (error) { + console.error(`[bluetooth_js]GetDeviceName_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetDeviceName_0200', 0, async function (done) { + try { + gattClient.getDeviceName((err, data)=> { + if (err) { + console.error('getname1 failed '); + } + console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); + expect(data).assertNull(); + }); + await sleep(2000); + done(); + } catch (error) { + console.error(`[bluetooth_js]GetDeviceName_0200 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetService_0100', 0, async function (done) { + try { + await gattClient.getServices().then((GattService) => { + console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); + expect(GattService).assertNull(); + done(); + }).catch(err => { + console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); + expect(true).assertEqual(true); + done(); + }); + } catch (error) { + console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_GetService_0200', 0, async function (done) { + try { + 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); + } + done(); + }); + } catch (error) { + console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0100', 0, function () { + try { + gattClient.setBLEMtuSize(100); + console.info("[bluetooth_js]setBLEMtuSize success") + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]MtuSize_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () { + try { + gattClient.setBLEMtuSize(22); + console.info("[bluetooth_js]setBLEMtuSize success") + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]MtuSize_0200 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () { + try { + gattClient.setBLEMtuSize(21); + console.info("[bluetooth_js]setBLEMtuSize success") + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]MtuSize_0300 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400 + * @tc.name testSetBLEMtuSize + * @tc.desc Test SetBLEMtuSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0400', 0, function () { + try { + gattClient.setBLEMtuSize(512); + console.info("[bluetooth_js]setBLEMtuSize success") + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]MtuSize_0400 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0500', 0, function () { + try { + gattClient.setBLEMtuSize(513); + console.info("[bluetooth_js]setBLEMtuSize success") + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]MtuSize_0500 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1900 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1900', 0, async function (done) { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + expect(true).assertEqual(data.length>=0); + done(); + }).catch(err => { + console.error(`bluetooth readCharacteValue19 promise has error: ${err}`); + expect(true).assertEqual(true); + done(); + }) + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readDescrValue19 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_2000 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_2000', 0, async function(done) { + try { + function readCcc(code, BLECharacteristic) { + if (code.code != 0) { + return; + } + console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); + expect(true).assertEqual(data==null); + let value = new Uint8Array(BLECharacteristic.characteristicValue); + console.log('bluetooth characteristic value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.readCharacteristicValue(characteristic,readCcc); + expect(true).assertFalse(); + done() + } catch (error) { + console.error(`[bluetooth_js]readDescrValue20 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_2100 + * @tc.name test characteristicReadOn + * @tc.desc Test On and off api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_2100', 0, async function (done) { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1123; + function ReadCharacteristicReq(CharacteristicReadReq) { + let deviceId = CharacteristicReadReq.deviceId; + let transId = CharacteristicReadReq.transId; + let offset = CharacteristicReadReq.offset; + let characteristicUuid = CharacteristicReadReq.characteristicUuid; + + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferCCC}; + gattServer.sendResponse(serverResponse); + } + let gattServer = bluetooth.BLE.createGattServer(); + await gattServer.on("characteristicRead", ReadCharacteristicReq); + await gattServer.off("characteristicRead"); + gattServer.close(); + done() + } catch (error) { + console.error(`[bluetooth_js]readDescrValue21 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1300 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1300', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertEqual(object!=null); + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)) + expect(true).assertEqual(true); + done(); + }) + expect(true).assertFalse(); + } catch (error) { + console.error('[bluetooth_js]readDescrValue13 error code:'+JSON.stringify(error.code)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1400 + * @tc.name testReadDescriptorValue + * @tc.desc Test ReadDescriptorValue api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1400', 0, async function (done) { + try { + function readDesc(code, BLEDescriptor) { + if (code.code != 0) { + console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); + expect(true).assertEqual(BLEDescriptor.descriptorUuid==null); + } + 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', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.readDescriptorValue(descriptor,readDesc); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]readDescrValue14 error code:'+JSON.stringify(error)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1500 + * @tc.name test ReadDescriptorOn + * @tc.desc Test On and Off api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1500', 0, async function (done) { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1011; + function ReadDescriptorReq(DescriptorReadReq) { + let deviceId = DescriptorReadReq.deviceId; + let transId = DescriptorReadReq.transId; + let offset = DescriptorReadReq.offset; + let characteristicUuid = DescriptorReadReq.characteristicUuid; + + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferCCC}; + gattServer.sendResponse(serverResponse); + console.info("[bluetooth_js] DesRedon jsondata:" + + 'deviceId:' + deviceId + 'transId:' +transId + 'offset:' + + offset +'descriptorUuid:' + DescriptorReadReq.descriptorUuid + + 'characteristicUuid:' +characteristicUuid + + 'serviceUuid:' + DescriptorReadReq.serviceUuid); + expect(true).assertEqual(DescriptorReadReq !=null); + } + let gattServer = bluetooth.BLE.createGattServer(); + await gattServer.on("descriptorRead", ReadDescriptorReq); + await gattServer.off("descriptorRead"); + gattServer.close(); + done() + } catch (error) { + console.error(`[bluetooth_js]readDescrValue15 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1900 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test Client WriteCharacteristicValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1900', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeCharacteristicValue19 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_2000 + * @tc.name test characteristicWriteOn + * @tc.desc Test on and off api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_2000', 0, async function (done) { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + function WriteCharacteristicReq(CharacteristicWriteReq) { + let deviceId = CharacteristicWriteReq.deviceId; + let transId = CharacteristicWriteReq.transId; + let offset = CharacteristicWriteReq.offset; + let isPrep = CharacteristicWriteReq.isPrep; + let needRsp = CharacteristicWriteReq.needRsp; + let value = new Uint8Array(CharacteristicWriteReq.value); + let characteristicUuid = CharacteristicWriteReq.characteristicUuid; + + cccValue[0] = value[0]; + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferCCC}; + gattServer.sendResponse(serverResponse); + } + let gattServer = bluetooth.BLE.createGattServer(); + gattServer.on("characteristicWrite", WriteCharacteristicReq); + gattServer.off("characteristicWrite"); + gattServer.close(); + done() + } catch (error) { + console.error(`[bluetooth_js]writeCharacteristicValue20 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1100 + * @tc.name testWriteDescriptorValue + * @tc.desc Test Client WriteDescriptorValue api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1100', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue11 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1200 + * @tc.name test WriteDescriptorOn + * @tc.desc Test on and off api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1200', 0, async function (done) { + try { + let arrayBufferDesc = new ArrayBuffer(8); + let descValue = new Uint8Array(arrayBufferDesc); + function WriteDescriptorReq(DescriptorWriteReq) { + let deviceId = DescriptorWriteReq.deviceId; + let transId = DescriptorWriteReq.transId; + let offset = DescriptorWriteReq.offset; + let isPrep = DescriptorWriteReq.isPrep; + let needRsp = DescriptorWriteReq.needRsp; + let value = new Uint8Array(DescriptorWriteReq.value); + let descriptorUuid = DescriptorWriteReq.descriptorUuid; + descValue[0] = value[0]; + let serverResponse = {deviceId: deviceId, transId: transId, + status: 0, offset: offset, value:arrayBufferDesc}; + gattServer.sendResponse(serverResponse); + console.info("[bluetooth_js] desWriOn jsondata: " +'deviceId: ' + + deviceId + 'transId:' + transId + 'offset:' + offset +'descriptorUuid:' + + descriptorUuid + 'charUuid:' + DescriptorWriteReq.characteristicUuid + + 'serviceUuid:' + DescriptorWriteReq.serviceUuid + + 'value:' + DescriptorWriteReq.value + 'needRsp' + + needRsp + 'isPrep:' +isPrep ); + expect(true).assertEqual(DescriptorWriteReq !=null); + } + let gattServer = bluetooth.BLE.createGattServer(); + gattServer.on("descriptorWrite", WriteDescriptorReq); + gattServer.off("descriptorWrite"); + gattServer.close(); + done() + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue12 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1200 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1200', 0, async function (done) { + try { + 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', + characteristicUuid: '00001820-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}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged12 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1300 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test SetNotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1300', 0, async function (done) { + try { + 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', + characteristicUuid: '00001820-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}; + gattClient.setNotifyCharacteristicChanged(characteristic, false); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged13 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1400 + * @tc.name test BLECharacteristicChangeON + * @tc.desc Test On and off api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1400', 0, async function (done) { + try { + function CharacteristicChange(CharacteristicChangeReq) { + let serviceUuid = CharacteristicChangeReq.serviceUuid; + let characteristicUuid = CharacteristicChangeReq.characteristicUuid; + let value = new Uint8Array(CharacteristicChangeReq.characteristicValue); + expect(true).assertEqual(CharacteristicChangeReq !=null); + } + gattClient.on('BLECharacteristicChange', CharacteristicChange); + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, false); + gattClient.off('BLECharacteristicChange'); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged14 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_GattClose_0100 + * @tc.name test gattClient close + * @tc.desc Test close api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_GattClose_0100', 0, async function (done) { + try { + let gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + gattClient.close(); + done(); + } catch (error) { + console.error(`[bluetooth_js]GattClose_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + +}) +} + + diff --git a/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js b/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ed7b5f7c00cd6c65d009b89d644994a864bf8e25 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js @@ -0,0 +1,2316 @@ +/* + * 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 bluetooth from '@ohos.bluetoothManager'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function bluetoothBLETest4() { +describe('bluetoothBLETest4', function() { + 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') + gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToEnableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(async function (done) { + console.info('afterAll called') + await sleep(6000); + gattClient.close(); + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200 + * @tc.name testSetBLEMtuSize + * @tc.desc Test api 401 - Invalid null parameters. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_COMMUNICATION_BLUETOOTH_BLE_MtuSize_0200', 0, function () { + try { + gattClient.setBLEMtuSize(); + expect(true).assertFalse(); + } catch(error) { + console.error('[bluetooth_js]error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300 + * @tc.name testSetBLEMtuSize + * @tc.desc Test api 401 -error type. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_MtuSize_0300', 0, function () { + try { + gattClient.setBLEMtuSize(null); + expect(true).assertFalse(); + } catch(error) { + console.error(`[bluetooth_js]setBLEMtuSize3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - Invalid null parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { + try { + await gattClient.readCharacteristicValue().then((data) => { + if (object != null) { + expect(true).assertEqual(true); + } else { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + } + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - Invalid null parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0200', 0, async function (done) { + try { + await gattClient.readCharacteristicValue(null).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0300 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - null serviceUuid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0300', 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', + characteristicUuid: '00001820-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 = { + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0400 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if serviceUuid type is error. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0400', 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', + characteristicUuid: '00001820-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: 123, + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0500 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - null characteristicUuid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0500', 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', + characteristicUuid: '00001820-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', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0600 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if characteristicUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0600', 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', + characteristicUuid: '00001820-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: null, + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue6 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0700 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - null characteristicValue. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0700', 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', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue7 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0800 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if characteristicValue is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0800', 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', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: null, descriptors:descriptors}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue8 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0900 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - null descriptors. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0900', 0, async function (done) { + 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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1000 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if descriptors type is error. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1000', 0, async function (done) { + 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:123}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue10 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1100 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if serviceUuid of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1100', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = { + characteristicUuid: '00001820-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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue11 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1200 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if serviceUuid of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1200', 0, async function (done) { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: 1111222, + characteristicUuid: '00001820-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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue12 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1300 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if descriptorUuid of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1300', 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', + characteristicUuid: '00001820-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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue13 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1400 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if descriptorUuid of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1400', 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', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: 444555, + 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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue14 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1500 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if descriptorValue of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1500', 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', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB'}; + 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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done() + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue15 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1600 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - if descriptorValue of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1600', 0, async function (done) { + let descriptors = []; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: 4455}; + 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}; + try { + await gattClient.readCharacteristicValue(characteristic).then((data) => { + console.info('[bluetooth_js] readCharacValue promise data:' + + JSON.stringify(data)); + }).catch(err => { + console.error(`bluetooth readCharacteValue promise has error: ${err}`); + expect(true).assertFalse(); + }); + done() + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue16 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1700 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 -null api by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1700', 0, async function(done) { + try { + gattClient.readCharacteristicValue(); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]readCharacteValue17 failed, error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1800 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 -null readCharacteristicValue by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_1800', 0, async function(done) { + try { + function readCcc(code, BLECharacteristic) { + if (coderror.code != 0) { + return; + } + console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); + expect(true).assertEqual(data==null); + let value = new Uint8Array(BLECharacteristic.characteristicValue); + console.log('bluetooth characteristic value: ' + + value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + } + gattClient.readCharacteristicValue(null,readCcc); + expect(true).assertFalse(); + done() + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue18 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - null descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { + try { + await gattClient.readDescriptorValue().then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - descriptor is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0200', 0, async function (done) { + try { + await gattClient.readDescriptorValue(null).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0300 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - serviceUuid of descriptor is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0300', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = { + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0400 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - serviceUuid of descriptor is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0400', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = { serviceUuid: 1234, + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0500 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - characteristicUuid of descriptor is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0500', 0, async function (done) { + try { + 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}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0600 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - characteristicUuid of descriptor is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0600', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: 1234, + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue6 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0700 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - descriptorUuid of descriptor is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0700', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue7 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0800 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - descriptorUuid of descriptor is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0800', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: 1234, + descriptorValue: arrayBuffer}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue8 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0900 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - descriptorValue of descriptor is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0900', 0, async function (done) { + try { + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB'}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1000 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 - descriptorValue of descriptor is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1000', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: 1236454}; + await gattClient.readDescriptorValue(descriptor).then((object) => { + if (object != null) { + console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + + } else { + console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); + expect(true).assertFalse(); + } + done(); + }).catch(err => { + console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); + expect(true).assertFalse(); + done(); + }) + } catch (error) { + console.error(`[bluetooth_js]readDescrValue10 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1100 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 -null readDescriptorValue by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1100', 0, async function (done) { + try { + gattClient.readDescriptorValue(); + expect(true).assertFalse(); + done() + } catch (error) { + console.error(`[bluetooth_js]readDescrValue11 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1200 + * @tc.name testReadDescriptorValue + * @tc.desc Test 401 -null readDescriptorValue by callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_1200', 0, async function (done) { + try { + function readDesc(code, BLEDescriptor) { + if (code.code != 0) { + console.info('[bluetooth_js] descriptor code: ' + BLEDescriptor.descriptorUuid); + expect(true).assertEqual(BLEDescriptor.descriptorUuid==null); + } + 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]); + } + gattClient.readDescriptorValue(null,readDesc); + expect(true).assertFalse(); + done() + } catch (error) { + console.error(`[bluetooth_js]readDescrValue12 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - api of null parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0100', 0, function () { + try { + gattClient.writeCharacteristicValue(); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - api of error parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0200', 0, function () { + try { + gattClient.writeCharacteristicValue(null); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0300 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -null serviceUuid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0300', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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 = { + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0400 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -serviceUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0400', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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: 123123, + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0500 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - null characteristicUuid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0500', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0600 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - characteristicUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0600', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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: 123123, + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue6 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0700 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - null characteristicValue. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0700', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue7 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0800 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - characteristicValue is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0800', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: "string", descriptors:descriptors}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue8 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0900 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 - null descriptors. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_0900', 0, function () { + try { + 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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1000 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1000', 0, function () { + try { + 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:'123ss'}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue10 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1100 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -null serviceUuid of descriptors. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1100', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = { + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue11 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1200 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -serviceUuid of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1200', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:123123, + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue12 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1300 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -characteristicUuid of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1300', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:'00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue13 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1400 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -characteristicUuid of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1400', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: 123123, + 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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue14 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1500 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -descriptorUuid of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1500', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue15 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1600 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -descriptorUuid of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1600', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: 123123, 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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue16 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1700 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -descriptorValue of descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1600', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue17 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1800 + * @tc.name testWriteCharacteristicValue + * @tc.desc Test 401 -descriptorValue of descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteCharacteristic_1800', 0, function () { + try { + let descriptors = []; + let descriptor = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: "string"}; + 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}; + gattClient.writeCharacteristicValue(characteristic); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]readCharacteValue18 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - api is null parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0100', 0, function () { + try { + gattClient.writeDescriptorValue(); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - api is error parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0200', 0, function () { + try { + gattClient.writeDescriptorValue(null); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0300 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - null serviceUuid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0300', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = { + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0400 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - serviceUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0400', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: 123123, + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0500 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - characteristicUuid is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0500', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0600 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - characteristicUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0600', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: 123123, + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue6 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0700 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - descriptorUuid is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0700', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue7 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0800 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - descriptorUuid is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0800', 0, function () { + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: 123123, descriptorValue: arrayBuffer}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue8 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0900 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - descriptorValue is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_0900', 0, function () { + try { + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB'}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1000 + * @tc.name testWriteDescriptorValue + * @tc.desc Test 401 - descriptorValue is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_WriteDescriptor_1000', 0, function () { + try { + let descriptor = {serviceUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: 'string'}; + gattClient.writeDescriptorValue(descriptor); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]writeDescriptorValue10 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - parameter of api is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0100', 0, function () { + try { + gattClient.setNotifyCharacteristicChanged(); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - first parameter of api is error type . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0200', 0, function () { + try { + gattClient.setNotifyCharacteristicChanged(null, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - second parameter of api is null . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0300', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, 222); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0400 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - serviceUuid is null . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0400', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = { + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0500 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - serviceUuid is error type . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0500', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid:123123, + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0600 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - characteristicUuid is null . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0600', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged6 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0700 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - characteristicUuid is error type . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0700', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: 123123, + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged7 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0800 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - characteristicValue is null . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0800', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-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] = 1; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged8 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0900 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - characteristicValue is error type . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_0900', 0, function () { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: '123', descriptors:descriptors}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged9 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1000 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - descriptors is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1000', 0, function () { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged10 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1100 + * @tc.name testSetNotifyCharacteristicChanged + * @tc.desc Test 401 - descriptors is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_SetNotifyCharacteristic_1100', 0, function () { + try { + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 1; + let characteristic = {serviceUuid:'00001820-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:'123'}; + gattClient.setNotifyCharacteristicChanged(characteristic, true); + expect(true).assertFalse(); + } catch (error) { + console.error(`[bluetooth_js]setNotifyCharacteristicChanged11 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_createGattClientDevice_0100 + * @tc.name test createGattClientDevice + * @tc.desc Test createGattClientDevice 401. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_createGattClientDevice_0100', 0, async function (done) { + try { + let gattClient = bluetooth.BLE.createGattClientDevice(); + gattClient.close(); + done(); + } catch (error) { + console.error(`[bluetooth_js]createGattClientDevice01 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_createGattClientDevice_0200 + * @tc.name test createGattClientDevice + * @tc.desc Test createGattClientDevice 401. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_createGattClientDevice_0200', 0, async function (done) { + try { + let gattClient = bluetooth.BLE.createGattClientDevice(null); + gattClient.close(); + done(); + } catch (error) { + console.error(`[bluetooth_js]createGattClientDevice02 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + +}) +} + + diff --git a/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js new file mode 100644 index 0000000000000000000000000000000000000000..066aae03fdea8dd8500f2f626b5ebe02ead29f2c --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js @@ -0,0 +1,797 @@ +/* + * 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.bluetoothManager'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function bluetoothBLETest6() { +describe('bluetoothBLETest6', 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 COMMUNICATION_BLUETOOTH_BLE_Scan_0100 + * @tc.name testClassicStartBLEScan + * @tc.desc Test startBLEScan 401 - Invalid parameter. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_BLE_Scan_0100', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data)); + expect(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(); + } catch (error) { + console.error('[bluetooth_js]Scan_0100 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0200', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); + await sleep(1000); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0200 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0300', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan([{name:"blue_test"}]); + await sleep(1000); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0300 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0400', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device 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 off4'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0400 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0500', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off5'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0500 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0600', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + let ScanOptions= { + interval: 100, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_BALANCED, + matchMode: bluetooth.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(); + } catch (error) { + console.error('[bluetooth_js]Scan_0600 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0700', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off7'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0700 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0800', 0, async function (done) { + try { + 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)); + expect(true).assertTrue(data.length=0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 100, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + expect(true).assertFalse(); + console.info('[bluetooth_js] BLE scan off8'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0800 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_0900', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 0, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off7'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_0900 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1000', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off10'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1000 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1100', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off11'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1100 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1200', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); + } + bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) + bluetooth.BLE.startBLEScan( + [{}], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, + } + ); + await sleep(1000); + console.info('[bluetooth_js] BLE scan off12'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1200 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1300', 0, async function (done) { + try { + function onReceiveEvent(data) + { + console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data)); + expect(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(); + } catch (error) { + console.error('[bluetooth_js]Scan_1300 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /* @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1400', 0, async function (done) { + try { + 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.stopBLEScan(); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1400 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1500', 0, async function (done) { + try { + 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(); + } catch (error) { + console.error('[bluetooth_js]Scan_1500 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1600', 0, async function (done) { + try { + 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:serviceDataArrayBuffer, + serviceDataMask:serviceDataMaskArrayBuffer, + } + 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(); + } catch (error) { + console.error('[bluetooth_js]Scan_1600 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_Scan_1700', 0, async function (done) { + try { + 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); + expect(true).assertFalse(); + console.info('[bluetooth_js] BLE scan off17 '); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1700 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1800 + * @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('COMMUNICATION_BLUETOOTH_BLE_Scan_1800', 0, async function (done) { + try { + async function onReceiveEvent(ScanResult) + { + console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(ScanResult) + +ScanResult.deviceId+ScanResult.rssi+ ScanResult.data); + expect(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: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, + } + ); + console.info('[bluetooth_js] BLE scan offC'); + bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); + bluetooth.BLE.stopBLEScan(); + done() + } catch (error) { + console.error('[bluetooth_js]Scan_1800 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_1900 + * @tc.name testClassicStartBLEScan + * @tc.desc Test startBLEScan 401 - Invalid parameter. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_BLE_Scan_1900', 0, async function (done) { + try { + bluetooth.BLE.startBLEScan(123); + expect(true).assertFalse(); + bluetooth.BLE.stopBLEScan(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_1900 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_Scan_2000 + * @tc.name testClassicStartBLEScan + * @tc.desc Test startBLEScan 401 - Invalid parameter. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_BLE_Scan_2000', 0, async function (done) { + try { + bluetooth.BLE.startBLEScan([{ + serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", + serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", + }]); + bluetooth.BLE.stopBLEScan("test"); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]Scan_2000 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + +}) +} + diff --git a/communication/bluetooth_manager/src/main/js/test/BleService.test.js b/communication/bluetooth_manager/src/main/js/test/BleService.test.js new file mode 100644 index 0000000000000000000000000000000000000000..42c8d5d41df0ce2b14319cb65d3ddfdce825d783 --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/BleService.test.js @@ -0,0 +1,1190 @@ +/* + * 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.bluetoothManager'; +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(async function (done) { + console.info('beforeAll called') + await tryToEnableBt() + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + done() + }) + 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 COMMUNICATION_BLUETOOTH_BLE_Connect_0100 + * @tc.name test Server connectStateChange + * @tc.desc Test on and off api . + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_Connect_0100', 0, async function (done) { + try { + function Connected(BLEConnectChangedState) { + let deviceId = BLEConnectChangedState.deviceId; + let status = BLEConnectChangedState.state; + console.info("[bluetooth_js] connectStateChange jsondata:" + +'deviceId:' + deviceId + 'status:' + status); + expect(true).assertEqual(BLEConnectChangedState !=null); + } + await gattServer.on("connectStateChange", Connected); + gattClient.connect(); + await sleep(2000); + await gattServer.off("connectStateChange"); + done() + } catch (error) { + console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0100 + * @tc.name testAddService + * @tc.desc Test api 401 - characteristics of service is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0100', 0, async function (done) { + try { + let service = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + isPrimary: true, includeServices: []}; + gattServer.addService(service); + await sleep(1000); + expect(true).assertFalse(); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService1 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0200 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0200', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService2 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0300 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0300', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService3 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0400 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0400', 0, async function (done) { + try { + 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}; + characteristics[0] = characteristic; + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:characteristics, includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + expect(true).assertFalse(); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService4 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0500 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0500', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService5 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0600 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0600', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService6 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0700 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0700', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService7 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0800 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0800', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService8 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_0900 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_0900', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + expect(true).assertFalse(); + await sleep(1000); + gattServer.removeService(''); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService9 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_1000 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_1000', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + expect(true).assertFalse(); + gattServer.removeService('123@ad'); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService10 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_1100 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_1100', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + expect(true).assertFalse(); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService11 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_1200 + * @tc.name testAddService + * @tc.desc Test AddService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_1200', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + expect(true).assertFalse(); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + done(); + } catch (error) { + console.error('[bluetooth_js]AddService12 failed, error.code:'+JSON.stringify(error.code) + +'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2000 + * @tc.name testAddService + * @tc.desc Test api 401 - null gattService parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2000', 0, async function (done) { + try { + gattServer.addService(); + expect(true).assertFalse(); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]addService20 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2100 + * @tc.name testAddService + * @tc.desc Test api 401 - parameters is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2100', 0, async function (done) { + try { + gattServer.addService(null); + expect(true).assertFalse(); + await sleep(1000); + done(); + } catch (error) { + console.error('[bluetooth_js]addService21 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2200 + * @tc.name testAddService + * @tc.desc Test api 401 - serviceUuid of gattService is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2200', 0, async function (done) { + try { + 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 = {isPrimary: true, + characteristics:characteristics, includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]addService22 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2300 + * @tc.name testAddService + * @tc.desc Test api 401 - serviceUuid of gattService is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2300', 0, async function (done) { + try { + 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:123123, isPrimary: true, + characteristics:characteristics, includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]addService23 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2400 + * @tc.name testAddService + * @tc.desc Test api 401 - isPrimary of gattService is null. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2400', 0, async function (done) { + try { + 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', + characteristics:characteristics, includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]addService24 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2500 + * @tc.name testAddService + * @tc.desc Test api 401 - isPrimary of gattService is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2500', 0, async function (done) { + try { + 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: '123S123', + characteristics:characteristics, includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]addService25 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_AddService_2600 + * @tc.name testAddService + * @tc.desc Test api 401 - characteristics of gattService is error type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_AddService_2600', 0, async function (done) { + try { + let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, + characteristics:"123sss",includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]addService26 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_RemoveService_0100', 0, async function (done) { + try { + 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 gattService1 = {serviceUuid:'00001888-0000-1000-8000-00805f9b34fb', + isPrimary: false,characteristics:characteristics,includeServices:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.addService(gattService1); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService1 failed, code is ${error.code}, + message is ${error.message}`); + expect(true).assertFalse(); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_RemoveService_0200', 0, async function (done) { + try { + gattServer.removeService('00001800-0000-1000-8000-00805f9b3442'); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300 + * @tc.name testRemoveService + * @tc.desc Test RemoveService api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_RemoveService_0300', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + await sleep(1000); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService3 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_RemoveService_0400 + * @tc.name testRemoveService + * @tc.desc Test RemoveService 401-null parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_RemoveService_0400', 0, async function (done) { + try { + gattServer.removeService(); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_RemoveService_0500 + * @tc.name testRemoveService + * @tc.desc Test RemoveService 401-error parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_RemoveService_0500', 0, async function (done) { + try { + gattServer.removeService("sss"); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService5 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0100', 0, async function (done) { + try { + 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}; + gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]notifyCharacteristicChanged1 failed, code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200', 0, async function (done) { + try { + 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}; + gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]notifyCharacteristicChanged2 failed, code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300 + * @tc.name testNotifyCharacteristicChanged + * @tc.desc Test NotifyCharacteristicChanged api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0300', 0, async function (done) { + try { + console.info('[bluetooth_js] COMMUNICATION_BLUETOOTH_BLE_notifyCharacteristic_0200'); + gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', null); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]notifyCharacteristicChanged3 failed, code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_sendResponse_0100', 0, async function (done) { + try { + 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}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse1 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done() + } + + }) + + /** + * @tc.number 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('COMMUNICATION_BLUETOOTH_BLE_sendResponse_0200', 0, async function (done) { + try { + 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: -1, offset: 0, value: arrayBuffer}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse2 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900099'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_sendResponse_0300 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse 401 -null parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_sendResponse_0300', 0, async function (done) { + try { + gattServer.sendResponse(); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]sendResponse3 error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('401'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_BLE_sendResponse_0400 + * @tc.name testSendResponse success + * @tc.desc Test SendResponse 401 -error parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_BLE_sendResponse_0400', 0, async function (done) { + try { + let arrayBuffer = new ArrayBuffer(8); + let value = new Uint8Array(arrayBuffer); + value[0] = 1; + let ServerResponse = {transId: 1, + status: -1, offset: 0, value: arrayBuffer}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse4 failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + + }) + + +}) +} + + diff --git a/communication/bluetooth_manager/src/main/js/test/List.test.js b/communication/bluetooth_manager/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ac47b6163eea3e49b3d570d4d53e6f1d741c52fa --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/List.test.js @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 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 bluetoothBLETest from './BleGattManager.test.js' +import bluetoothBLETest4 from './BleGattManager401.test.js' +import bluetoothBLETest1 from './BleService.test.js' +import bluetoothBLETest2 from './BleAdvertiser.test.js' +import bluetoothBLETest5 from './BleAdvertiser401.test.js' +import bluetoothBLETest3 from './SwitchOff003.test.js' +import bluetoothBLETest6 from './BleScanResult.test.js' +export default function testsuite() { +bluetoothBLETest() +bluetoothBLETest1() +bluetoothBLETest2() +bluetoothBLETest4() +bluetoothBLETest5() +bluetoothBLETest3() +bluetoothBLETest6() +} diff --git a/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6b4f16aa757c8f743b075da357f3bf0aa594348c --- /dev/null +++ b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js @@ -0,0 +1,976 @@ +/* + * 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.bluetoothManager'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function bluetoothBLETest3() { +describe('bluetoothBLETest3', function() { + let gattServer = null; + let gattClient = null; + function sleep(delay) { + return new Promise(resovle => setTimeout(resovle, delay)) + } + + async function tryToDisableBt() { + let sta = bluetooth.getState(); + switch(sta){ + case 0: + console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); + 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)); + bluetooth.disableBluetooth(); + await sleep(3000); + break; + case 3: + console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); + break; + default: + console.info('[bluetooth_js] enable success'); + } + } + beforeAll(function () { + console.info('beforeAll called') + gattServer = bluetooth.BLE.createGattServer(); + gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); + }) + beforeEach(async function(done) { + console.info('beforeEach called') + await tryToDisableBt() + done() + }) + afterEach(function () { + console.info('afterEach called') + }) + afterAll(async function (done) { + console.info('afterAll called') + await sleep(6000); + gattClient.close(); + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0100 + * @tc.name test bluetooth Profile ConnectionState + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0100', 0, async function (done) { + await sleep(3000); + let sta = bluetooth.getState(); + console.info('[bluetooth_js] bt getState:'+ JSON.stringify(sta)); + try { + let connState = bluetooth.getBtConnectionState(); + console.info('[bluetooth_js] get bt connection state result' + + JSON.stringify(connState)); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error('[bluetooth_js]getBtConnectionState error.code:' + +JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0200 + * @tc.name Test pairDevice api + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0200', 0, async function (done) { + try { + bluetooth.pairDevice("11:22:55:66:33:44"); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]pairDevice error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0300 + * @tc.name test getRemoteDeviceName + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0300', 0, async function (done) { + try { + let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00"); + console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret)); + expect(ret.length).assertEqual(0); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getRemoteDeviceName error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0400 + * @tc.name test getRemoteDeviceClass + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0400', 0, async function (done) { + try { + 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(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getRemoteDeviceClass error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0500 + * @tc.name test get PairedDevices + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0500', 0, async function (done) { + try { + let ret = bluetooth.getPairedDevices(); + console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getPairedDevices error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0600 + * @tc.name test Get A2DP ConnectionState + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0600', 0, async function (done) { + try { + let a2dpSrcConn = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); + console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getProfileConnState error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0700 + * @tc.name Test setDevicePairing + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0700', 0, async function (done) { + try { + bluetooth.setDevicePairingConfirmation("11:22:55:66:33:44",false); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]setDevicePairingConfirmation error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0800 + * @tc.name setLocalName + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0800', 0, async function (done) { + try { + let newName = 'my bluetooth'; + bluetooth.setLocalName(newName); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]setLocalName error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0900 + * @tc.name TEST setBluetoothScanMode + * @tc.desc TEST 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_0900', 0, async function (done) { + try { + bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]setBluetoothScanMode error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1000 + * @tc.name TEST getBluetoothScanMode + * @tc.desc TEST 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1000', 0, async function (done) { + try { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] getBluetoothScanMode = '+ JSON.stringify(oldScanMode)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getBluetoothScanMode error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1100 + * @tc.name TEST startBluetoothDiscovery + * @tc.desc TEST 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1100', 0, async function (done) { + try { + bluetooth.startBluetoothDiscovery(); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]startBluetoothDiscovery error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1200 + * @tc.name TEST stopBluetoothDiscovery + * @tc.desc TEST 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1200', 0, async function (done) { + try { + bluetooth.stopBluetoothDiscovery(); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]stopBluetoothDiscovery error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1600 + * @tc.name test getDevice HFP State. + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1600', 0, async function (done) { + try { + let hfpSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + let retArray = hfpSrc.getConnectionDevices(); + console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getConnectionDevices error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1700 + * @tc.name test getDeviceState. + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1700', 0, async function (done) { + try { + let hfpSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + let ret = hfpSrc.getDeviceState('11:22:33:44:55:66'); + console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getDeviceState error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1800 + * @tc.name test A2DP Connect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1800', 0, async function (done) { + try { + let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); + a2dpSrc.connect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]A2DPconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1900 + * @tc.name test A2DP disconnect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_1900', 0, async function (done) { + try { + let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); + a2dpSrc.disconnect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]A2DPdisconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2000 + * @tc.name test get A2DP Playing State + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2000', 0, async function (done) { + try { + let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); + console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); + let state = a2dpSrc.getPlayingState('11:22:33:44:55:66'); + console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state)); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]getPlayingState error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2100 + * @tc.name test HFP Connect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2100', 0, async function (done) { + try { + let hfpSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + hfpSrc.connect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]HFPconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2200 + * @tc.name test HFP disconnect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2200', 0, async function (done) { + try { + let hfpSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + hfpSrc.disconnect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]HFPdisconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2300 + * @tc.name test Hid Connect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2300', 0, async function (done) { + try { + let hidSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST); + hidSrc.connect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]Hidconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2400 + * @tc.name test Hid disconnect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2400', 0, async function (done) { + try { + let hidSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST); + hidSrc.disconnect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]Hiddisconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2500 + * @tc.name test PAN disconnect + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2500', 0, async function (done) { + try { + let panSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); + panSrc.disconnect('11:22:33:44:55:77'); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]Pandisconnect error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2600 + * @tc.name test PAN setTethering + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2600', 0, async function (done) { + try { + let panSrc = + bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); + panSrc.setTethering(true); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]PansetTethering error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2800 + * @tc.name testClassicStartBLEScan + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2800', 0, async function (done) { + try { + 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, + } + ); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]startBLEScan error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2900 + * @tc.name testClassicStartBLEScan + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_2900', 0, async function (done) { + try { + bluetooth.BLE.stopBLEScan(); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]startBLEScan error.code:' + +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3000 + * @tc.name testStartAdvertising + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3000', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let setting={ + interval:20, + txPower:-10, + connectable:true, + } + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.startAdvertising(setting,advData,advResponse); + expect(true).assertFalse(); + }catch(error) { + console.error('[bluetooth_js]startAdvertising error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + } + await sleep(2000); + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3100 + * @tc.name teststopAdvertising + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 0 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3100', 0, async function (done) { + let manufactureValueBuffer = new Uint8Array(4); + manufactureValueBuffer[0] = 1; + manufactureValueBuffer[1] = 2; + manufactureValueBuffer[2] = 3; + manufactureValueBuffer[3] = 4; + let serviceValueBuffer = new Uint8Array(4); + serviceValueBuffer[0] = 4; + serviceValueBuffer[1] = 6; + serviceValueBuffer[2] = 7; + serviceValueBuffer[3] = 8; + let advData={ + serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:4567, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + let advResponse ={ + serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"], + manufactureData:[{ + manufactureId:1789, + manufactureValue:manufactureValueBuffer.buffer + }], + serviceData:[{ + serviceUuid:"00001889-0000-1000-8000-00805f9b34fb", + serviceValue:serviceValueBuffer.buffer + }], + } + try { + gattServer.stopAdvertising(); + expect(true).assertFalse(); + }catch(error) { + console.error('[bluetooth_js]stopAdvertising error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + } + done(); + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3200 + * @tc.name testAddService + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3200', 0, async function (done) { + try { + 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:[]}; + gattServer.addService(gattService); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]AddService failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3300 + * @tc.name test removeService + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3300', 0, async function (done) { + try { + gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB'); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]removeService failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('401'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3400 + * @tc.name test removeService + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3400', 0, async function (done) { + try { + gattServer.close(); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]close failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + done() + } + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3600 + * @tc.name testSendResponse success + * @tc.desc Test 2900003 - Bluetooth switch is off. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3600', 0, async function (done) { + try { + 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}; + gattServer.sendResponse(ServerResponse); + expect(true).assertFalse(); + done(); + } catch (error) { + console.error(`[bluetooth_js]sendResponse failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + done() + } + + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3700 + * @tc.name test gatt connect + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3700', 0, async function (done) { + try { + gattClient.connect(); + await sleep(2000); + expect(true).assertFalse(); + } catch(error) { + console.error(`[bluetooth_js]connect failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + } + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3800 + * @tc.name test gatt disconnect + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3800', 0, async function (done) { + try { + gattClient.disconnect(); + expect(true).assertFalse(); + } catch(error) { + console.error(`[bluetooth_js]disconnect failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + } + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3900 + * @tc.name test gatt close + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 3 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_3900', 0, async function (done) { + try { + gattClient.close(); + expect(true).assertFalse(); + } catch(error) { + console.error(`[bluetooth_js]gattClient close failed, code is ${error.code}, + message is ${error.message}`); + expect(error.code).assertEqual('2900003'); + } + done() + }) + + /** + * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_4000 + * @tc.name Test cancelPairedDevice api + * @tc.desc Test 2900003 - Bluetooth switch is off + * @tc.size MEDIUM + * @ since 8 + * @tc.type Function + * @tc.level Level 2 + */ + it('COMMUNICATION_BLUETOOTH_SwitchOff_4000', 0, async function (done) { + + try { + bluetooth.cancelPairedDevice("11:22:55:66:33:44"); + expect(true).assertFalse(); + done() + } catch (error) { + console.error('[bluetooth_js]cancelPairedDevice error.code:'+JSON.stringify(error.code)+ + 'error.message:'+JSON.stringify(error.message)); + expect(error.code).assertEqual('2900003'); + done() + } + }) + +}) +} + + diff --git a/communication/bluetooth_manager/src/main/resources/base/element/string.json b/communication/bluetooth_manager/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d4b2a0a059d21198f9767cea679a5cc2bb8f6dad --- /dev/null +++ b/communication/bluetooth_manager/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OsAccountTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/communication/bluetooth_manager/src/main/resources/base/media/icon.png b/communication/bluetooth_manager/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/communication/bluetooth_manager/src/main/resources/base/media/icon.png differ diff --git a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js index 66aae7b887f09c78c25a50b7b435086b06a5412a..11ec404d23b084b966f4f8a3da25f32804d55e8c 100644 --- a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -76,7 +76,7 @@ describe('bluetoothhostTest', function() { function onReceiveEvent(data) { console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data)); - except(true).assertTrue(data.length>0); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) bluetooth.BLE.startBLEScan(null); @@ -98,8 +98,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); @@ -122,8 +122,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan([{name:"blue_test"}]); @@ -146,8 +146,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result4'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]); @@ -170,8 +170,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -201,8 +201,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } let ScanOptions= { interval: 100, @@ -230,8 +230,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -264,8 +264,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result8'+JSON.stringify(data)); + expect(true).assertTrue(data.length=0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -295,8 +295,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -326,8 +326,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -357,8 +357,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -388,8 +388,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -419,8 +419,8 @@ describe('bluetoothhostTest', function() { 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); + console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data)); + expect(true).assertTrue(data.length>0); } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan( @@ -584,8 +584,8 @@ describe('bluetoothhostTest', function() { 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); + +ScanResult.deviceId+ScanResult.rssi+ ScanResult.data); + expect(true).assertTrue(ScanResult.length>0); await sleep(1000); let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId); let ret = gattClient.connect(); diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js index 696c5a89355440f35b14ca50ff6804cade6cd90b..0af005c4d0636c400480a70b1b1405a7ea9e3bfb 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -223,7 +223,7 @@ describe('bluetoothhostTest2', function() { 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); + expect(true).assertEqual(ret.length>=0); done(); }) diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js index d23024e7c7949af0ae5a5f4441d47d36d56ddfc8..9a143b55b11af6e26cda2ca5e12c6fa65fe97b53 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js @@ -132,8 +132,10 @@ describe('bluetoothhostTest_host_3', function () { } let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); hfpSrc.on('connectionStateChange', StateChangeParam); - hfpSrc.connect('11:22:33:44:55:66'); + let conn = hfpSrc.connect('11:22:33:44:55:66'); await sleep(6000); + console.info('[bluetooth_js]hfp connect result:' + JSON.stringify(conn)); + expect(conn).assertFalse(); hfpSrc.off('connectionStateChange', StateChangeParam); done(); }) @@ -220,4 +222,3 @@ describe('bluetoothhostTest_host_3', function () { } - diff --git a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js index a18e3d25e32951c6d4ca0eb4637825f18e69c2b2..865597e37e982b3e20d5169d4c081cc0c35a12bd 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js @@ -72,19 +72,31 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } + }) /** @@ -97,19 +109,31 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -122,19 +146,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -147,19 +182,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -171,19 +217,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -196,19 +253,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -221,19 +289,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -246,19 +325,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -271,19 +361,30 @@ describe('bluetoothhostTest2', 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(bluetooth.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 == bluetooth.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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + let oldScanMode = bluetooth.getBluetoothScanMode(); + console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode)); + let result = bluetooth.setBluetoothScanMode(bluetooth.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 == bluetooth.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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + done(); + } }) /** @@ -296,14 +397,25 @@ describe('bluetoothhostTest2', 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(); + let state = bluetooth.getState(); + console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); + if(state==bluetooth.BluetoothState.STATE_ON) + { + 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(); + } + else + { + console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state)); + expect(true).assertFalse(); + 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 index 5bdb62e508fd431e7c07f6a031cd0f442e124cd0..1aebc38ba900d07d67bdfacc4eef182e1c4ebfeb 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js @@ -24,6 +24,7 @@ let Btname = { +'01234567890123456789012345678912', LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', CHINESES_TEST :'测试蓝牙名称是否正常测试蓝牙名称是否试蓝牙', + CHINESES_TEST2 :'测试蓝牙名称正常', SYMBOL_TEST:'*^_^* 、。·ˉˇ¨〃々—~‖·‘’“”「『』〖❂【±×' +'÷∶∧∨∑∏∪∩∈∷√⊥‖∠⌒⊙∫∮≡≌≈∽∝≠♂♀°℃$¤¢£‰§№☆★○●◎◇□■△※→←↑↓〓', MIXES:'测试蓝牙名称是否正试蓝牙\'名称是否[666]aaw', @@ -113,12 +114,12 @@ describe('bluetoothhostTest1', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_LocalName_0200', 0, async function (done) { - let result = bluetooth.setLocalName(Btname.CHINESES_TEST); + let result = bluetooth.setLocalName(Btname.CHINESES_TEST2); expect(result).assertTrue(); await sleep(1000); let getNewName = bluetooth.getLocalName(); console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName)); - expect(true).assertEqual(Btname.CHINESES_TEST == getNewName); + expect(true).assertEqual(Btname.CHINESES_TEST2 == getNewName); done(); }) diff --git a/communication/nfc_Controller/BUILD.gn b/communication/nfc_Controller/BUILD.gn index 06d8e28a0e95cb6cc69ede6a40186630a2a85796..0541fe628967ec467589f73f4974b581c183fa0a 100644 --- a/communication/nfc_Controller/BUILD.gn +++ b/communication/nfc_Controller/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2023 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 @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") diff --git a/communication/nfc_Controller/src/main/js/MainAbility/app.js b/communication/nfc_Controller/src/main/js/MainAbility/app.js index 8fe0b77dcef1db4bb1706399fd481541de8166cd..dc4c404a40e0095dc405638ea3ab78688aa84cc7 100644 --- a/communication/nfc_Controller/src/main/js/MainAbility/app.js +++ b/communication/nfc_Controller/src/main/js/MainAbility/app.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.css b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.css index 3a8326a076cdb9ecabf543df9dba84240f5b52a4..f709257c9c37edf2627fbd6d6ee68161fd4251a1 100644 --- a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.css +++ b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.css @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.hml b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.hml index 0053057b5ff7362e00db48887ee1663cffa35988..d28045f2adb8200db6a527b89b456112274416ec 100644 --- a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.hml +++ b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.hml @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.js b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.js index 3300c9cfc4ff94297fee72c00d5c28d3114854f3..91cae6d8d6eeb19df7fc9d0bc24d8b46c98b3ebb 100644 --- a/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.js +++ b/communication/nfc_Controller/src/main/js/MainAbility/pages/index/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/TestAbility/app.js b/communication/nfc_Controller/src/main/js/TestAbility/app.js index cdc31f3dcf031e2f6a7665d9653e53bb649e21c5..bc68f20cbcd6b0d3b9a9a0967d6c553bd9548aed 100644 --- a/communication/nfc_Controller/src/main/js/TestAbility/app.js +++ b/communication/nfc_Controller/src/main/js/TestAbility/app.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/TestAbility/pages/index/index.js b/communication/nfc_Controller/src/main/js/TestAbility/pages/index/index.js index 88b083a7f6b979019d6a2c5ad20b19c5fd43286b..2836c005dfa3cbed39dac1787f69b727e7faf7df 100644 --- a/communication/nfc_Controller/src/main/js/TestAbility/pages/index/index.js +++ b/communication/nfc_Controller/src/main/js/TestAbility/pages/index/index.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/communication/nfc_Controller/src/main/js/TestRunner/OpenHarmonyTestRunner.js index c5fa8620ca77d381f20b65a903b833e6e3378c97..071dc1be82bf7da505797ed07c2d15001f09c02d 100644 --- a/communication/nfc_Controller/src/main/js/TestRunner/OpenHarmonyTestRunner.js +++ b/communication/nfc_Controller/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -35,7 +35,7 @@ function translateParamsToString(parameters) { console.info('OpenHarmonyTestRunner OnPrepare') }, onRun() { - console.log('OpenHarmonyTestRunner onRun run') + console.info('OpenHarmonyTestRunner onRun run') var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() diff --git a/communication/nfc_Controller/src/main/js/test/List.test.js b/communication/nfc_Controller/src/main/js/test/List.test.js index eee4d6bc73cb482a60b1c6242c1da254fff4887d..dba6f69f9b9271d74c103281332f99df6b8a7e4a 100644 --- a/communication/nfc_Controller/src/main/js/test/List.test.js +++ b/communication/nfc_Controller/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js b/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js index 16aedd625e796de0f73d4619e1aae1937899f2ad..8ea6e540668bdb7416dd1bfbd37ad062984ad456 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -39,7 +39,7 @@ let getAtag = null ; export default function nfcATagSessionTest() { describe('nfcATagSessionTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') try { getAtag = tag.getNfcATag(aTag) console.info('Nfcget Connected data' + getAtag) @@ -48,13 +48,13 @@ export default function nfcATagSessionTest() { } }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -70,15 +70,15 @@ export default function nfcATagSessionTest() { let NfcConnected; try { NfcConnected = getAtag.connectTag(); - console.info("NfcConnected:" + NfcConnected); + console.log("[NFC_test] tagsession1 NfcConnected:" + NfcConnected); expect(NfcConnected).assertFalse(); } catch (error) { - console.info('NfcConnected error' + error) - expect(true).assertFalse(); + console.log('[NFC_test] tagsession1 NfcConnected error' + error) + expect().assertFail(); } } else { - console.info("[NFC_test]getAtag1 = null & = undefined: "); - expect(true).assertFalse(); + console.log("[NFC_test]getAtag1 = null & = undefined: "); + expect().assertFail(); } }) @@ -93,17 +93,17 @@ export default function nfcATagSessionTest() { */ it('SUB_Communication_NFC_nfcAtage_js_0200', 0, function () { if (getAtag != null && getAtag != undefined) { - try { + try { getAtag.reset(); + console.log('[NFC_test] tagsession2 reset1 pass' ) expect(true).assertTrue(); - console.info('reset1 pass' ) } catch (error) { - console.info('reset1 error' + error) - expect(true).assertFalse(); + console.log('[NFC_test] tagsession2 reset1 error' + error) + expect().assertFail(); } } else { - console.info("[NFC_test]getAtag2 = null & = undefined: "); - expect(true).assertFalse(); + console.log("[NFC_test]getAtag2 = null & = undefined: "); + expect().assertFail(); } }) @@ -121,15 +121,15 @@ export default function nfcATagSessionTest() { let isNfcConnected; try { isNfcConnected = getAtag.isTagConnected(); - console.info("isNfcConnected:" +isNfcConnected); + console.log("[NFC_test] tagsession3 isNfcConnected:" +isNfcConnected); expect(isNfcConnected).assertFalse(); } catch (error) { - console.info('isNfcConnected error' + error) - expect(true).assertFalse(); + console.log('[NFC_test] tagsession3 isNfcConnected error' + error) + expect().assertFail(); } } else { - console.info("[NFC_test]getAtag3 = null & = undefined: "); - expect(true).assertFalse(); + console.log("[NFC_test]getAtag3 = null & = undefined: "); + expect().assertFail(); } }) @@ -147,16 +147,15 @@ export default function nfcATagSessionTest() { let mazSendLen; try { mazSendLen = getAtag.getMaxSendLength(); - console.info("getMaxSendLength:" + mazSendLen); + console.info("[NFC_test] tagsession4 getMaxSendLength:" + mazSendLen); expect(mazSendLen >= 0).assertTrue(); - console.info('getMaxSendLength pass' ) } catch (error) { - console.info('getMaxSendLength error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] tagsession4 getMaxSendLength error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]getAtag4 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -173,16 +172,17 @@ export default function nfcATagSessionTest() { if (getAtag != null && getAtag != undefined) { let settime; try { - settime = getAtag.setSendDataTimeout(1000); - console.info("setSendDataTimeout:" + settime); - expect(settime >= 0).assertTrue(); + let timeoutMs = 1000; + settime = getAtag.setSendDataTimeout(timeoutMs); + console.info("[NFC_test] tagsession5 setSendDataTimeout:" + settime); + expect(settime).assertTrue(); } catch (error) { - console.info('setSendDataTimeout error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] tagsession5 setSendDataTimeout error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]getAtag5 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -200,16 +200,15 @@ export default function nfcATagSessionTest() { let gettime; try { gettime = getAtag.getSendDataTimeout(); - console.info("getMaxSendLength:" + gettime + 'aTag is--<-!!!->' + JSON.stringify(gettime)); - expect(gettime >= 0).assertTrue(); - console.info('getMaxSendLength pass' ) + console.info("[NFC_test] tagsession6 getMaxSendLength:" + gettime); + expect(gettime).assertInstanceOf('Number') } catch (error) { - console.info('getMaxSendLength error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] tagsession6 getMaxSendLength error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]getAtag6 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -226,17 +225,18 @@ export default function nfcATagSessionTest() { if (getAtag != null && getAtag != undefined) { let sendDatas = [0x01, 0x02, 0x03, 0x04]; await getAtag.sendData(sendDatas).then((data) => { - console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] tagsession7 nfcAtage sendData1 data: " + data); + expect(data).assertInstanceOf('Array') done(); }).catch((err)=> { - console.log("nfcAtage sendData1 err: " + err); - expect(true).assertFalse(); + console.info("[NFC_test] tagsession7 nfcAtage sendData1 err: " + err); + expect().assertFail(); + done(); }); sleep(3500); } else { console.info("[NFC_test]getAtag7 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -254,19 +254,20 @@ export default function nfcATagSessionTest() { let sendDatas = [0x01, 0x02, 0x03, 0x04]; getAtag.sendData(sendDatas, (err, data)=> { if (err) { - console.log("nfcAtage sendData2 data err: " + err); - expect(true).assertFalse(); + console.info("[NFC_test] tagsession8 nfcAtage sendData2 data err: " + err); + expect().assertFail(); + done(); } else { sleep(2500); - console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] tagsession8 nfcAtage sendData2 data: " + data ); + data + done(); } }); sleep(500); - done(); } else { console.info("[NFC_test]getAtag8 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -275,18 +276,18 @@ export default function nfcATagSessionTest() { * @tc.name testreset * @tc.desc Test reset api. * @tc.size MEDIUM - * @ since 7 + * @ since 9 * @tc.type Function * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0900', 0, function () { try { tag.getNfcA(aTag).resetConnection(); + console.info('[NFC_test] tagsession9 resetConnection pass' ) expect(true).assertTrue(); - console.info('reset1 pass' ) } catch (error) { - console.info('reset1 error' + error) - expect(true).assertTrue(); + console.info('[NFC_test] tagsession9 resetConnection error' + error) + expect(3100201).assertEqual(error.code) } }) @@ -302,12 +303,12 @@ export default function nfcATagSessionTest() { it('SUB_Communication_NFC_nfcAtage_js_1000', 0, function () { let settime; try { - settime = tag.getNfcATag(aTag).getTimeout(1000); - console.info("setSendDataTimeout:" +settime); - expect(settime >= 0).assertTrue(); + settime = tag.getNfcATag(aTag).getTimeout(); + console.info("[NFC_test] tagsession10 getSendDataTimeout:" + settime); + expect(settime).assertInstanceOf('Number') } catch (error) { - console.info('setSendDataTimeout error' + error) - expect(true).assertTrue(); + console.info('[NFC_test] tagsession10 getSendDataTimeout error' + error) + expect(3100201).assertEqual(error.code) } }) @@ -323,12 +324,13 @@ export default function nfcATagSessionTest() { it('SUB_Communication_NFC_nfcAtage_js_1100', 0, async function (done) { let sendDatas = [0x01, 0x02, 0x03, 0x04]; await tag.getNfcATag(aTag).transmit(sendDatas).then((data) => { - console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] tagsession11 nfcAtage sendData1 data: " + data ); + expect(data).assertInstanceOf('Array') done(); }).catch((err)=> { - console.log("nfcAtage sendData1 err: " + err); - expect(true).assertTrue(); + console.info("[NFC_test] tagsession11 nfcAtage sendData1 err: " + err); + expect().assertFail(); + done(); }); sleep(3500); }) @@ -346,16 +348,17 @@ export default function nfcATagSessionTest() { let sendDatas = [0x01, 0x02, 0x03, 0x04]; tag.getNfcATag(aTag).transmit(sendDatas, (err, data)=> { if (err) { - console.log("nfcAtage sendData2 data err: " + err); - expect(true).assertFalse(); + console.info("[NFC_test] tagsession12 nfcAtage sendData2 data err: " + err); + expect().assertFail(); + done(); } else { sleep(2500); - console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] tagsession12 nfcAtage sendData2 data: " + data); + expect(data).assertInstanceOf('Array') + done(); } }); sleep(500); - done(); }) /** @@ -371,12 +374,38 @@ export default function nfcATagSessionTest() { let mazSendLen; try { mazSendLen = tag.getNfcATag(aTag).getMaxTransmitSize(); - console.info("getMaxTransmitSize:" +mazSendLen); - expect(mazSendLen >= 0).assertTrue(); - console.info('getMaxTransmitSize pass' ) + console.info("[NFC_test] tagsession13 getMaxTransmitSize:" +mazSendLen); + expect(mazSendLen).assertInstanceOf('Number') } catch (error) { - console.info('getMaxTransmitSize error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] tagsession13 getMaxTransmitSize error' + error) + expect().assertFail(); + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0500 + * @tc.name testsetSendDataTimeout + * @tc.desc Test setSendDataTimeout api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_nfcAtage_js_1400', 0, function () { + if (getAtag != null && getAtag != undefined) { + let settime; + try { + let timeoutMs = 1000; + settime = getAtag.setTimeout(timeoutMs); + console.info("[NFC_test] tagsession14 setTimeout:" + settime); + expect(settime).assertTrue(); + } catch (error) { + console.info('[NFC_test] tagsession14 setTimeout error' + error) + expect(3100201).assertEqual(error.code) + } + } else { + console.info("[NFC_test]getAtag14 = null & = undefined: "); + expect().assertFail(); } }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js index 18f02e8c7e6b30bd57fc9196b933338245cd27c4..34730de00f0ebd3f2392f0625f6a540b8da9392f 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -32,16 +32,16 @@ let NfcRfType = { export default function ConnectedTagTest() { describe('ConnectedTagTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -60,8 +60,8 @@ export default function ConnectedTagTest() { expect(isAccessToken).assertFalse() } else { let inittag = connectedTag.init(); + console.info("[NFC_test] ConnectedTag1 readMultiplePages1 err: " + inittag ); expect(inittag).assertTrue(); - console.info("ConnectedTag readMultiplePages1 err: " + inittag ); } }) @@ -82,12 +82,12 @@ export default function ConnectedTagTest() { done(); } else { await connectedTag.readNdefTag().then(result => { - console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("[NFC_test] ConnectedTag2 readMultiplePages1 result: " + result ); expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("ConnectedTag readMultiplePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] ConnectedTag2 readMultiplePages1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); @@ -112,11 +112,11 @@ export default function ConnectedTagTest() { } else { connectedTag.readNdefTag((err, result)=> { if (err) { + console.info("[NFC_test] ConnectedTag3 isExtendedApduSupported err: " + err); expect().assertFail(); - console.info("isoDep isExtendedApduSupported err: " + err); } else { - expect(result!=null).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + result); + console.info("[NFC_test] ConnectedTag3 isExtendedApduSupported result: " + result); + expect(result!=null).assertTrue(); } }); } @@ -140,12 +140,12 @@ export default function ConnectedTagTest() { done(); } else { await connectedTag.writeNdefTag().then(result => { - console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("[NFC_test] ConnectedTag4 readMultiplePages1 result: " + result ); expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("ConnectedTag readMultiplePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] ConnectedTag4 readMultiplePages1 err: " + err); + expect(true).assertTrue(true); done(); }); sleep(3000); @@ -166,18 +166,20 @@ export default function ConnectedTagTest() { if (!isAccessToken) { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() + done() } else { connectedTag.writeNdefTag((err, result)=> { if (err) { + console.info("[NFC_test] ConnectedTag5 isExtendedApduSupported err: " + err); expect().assertFail(); - console.info("isoDep isExtendedApduSupported err: " + err); + done(); } else { - expect(result!=null).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + result); + console.info("[NFC_test] ConnectedTag5 isExtendedApduSupported result: " + result); + expect(result!=null).assertTrue(); + done(); } }); } - done(); }) /** @@ -196,11 +198,11 @@ export default function ConnectedTagTest() { expect(isAccessToken).assertFalse() } else { let recvNfcRfNotifyFunc = result => { - console.info("nfc state receive state ->" + result); + console.info("[NFC_test] ConnectedTag6 nfc state receive state ->" + result); expect(result != null).assertTrue(); } - connectedTag.on('notify',recvNfcRfNotifyFunc) - connectedTag.off('notify',recvNfcRfNotifyFunc) + connectedTag.on('[NFC_test] ConnectedTag6 notify',recvNfcRfNotifyFunc) + connectedTag.off('[NFC_test] ConnectedTag6 notify',recvNfcRfNotifyFunc) } }) @@ -220,8 +222,8 @@ export default function ConnectedTagTest() { expect(isAccessToken).assertFalse() } else { let uninittag = connectedTag.uninit(); + console.info("[NFC_test] ConnectedTag7 readMultiplePages1 err: " + uninittag ); expect(uninittag).assertTrue(); - console.info("ConnectedTag readMultiplePages1 err: " + uninittag ); } }) @@ -242,8 +244,8 @@ export default function ConnectedTagTest() { } else{ let inittag = connectedTag.initialize(); + console.info("[NFC_test] ConnectedTag8 readMultiplePages1 err: " + inittag ); expect(inittag).assertTrue(); - console.info("mifareUltralight readMultiplePages1 err: " + inittag ); } }) @@ -264,8 +266,8 @@ export default function ConnectedTagTest() { } else{ let uninittag = connectedTag.uninitialize(); + console.info("[NFC_test] ConnectedTag9 readMultiplePages1 err: " + uninittag ); expect(uninittag).assertTrue(); - console.info("mifareUltralight readMultiplePages1 err: " + uninittag ); } }) @@ -287,12 +289,12 @@ export default function ConnectedTagTest() { } else{ await connectedTag.read().then(result => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("[NFC_test] ConnectedTag10 readMultiplePages1 result: " + result); expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] ConnectedTag10 readMultiplePages1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); @@ -318,15 +320,16 @@ export default function ConnectedTagTest() { else{ connectedTag.read((err, result)=> { if (err) { + console.info("[NFC_test] ConnectedTag11 isExtendedApduSupported err: " + err); expect().assertFail(); - console.info("isoDep isExtendedApduSupported err: " + err); + done(); } else { - expect(result!=null).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + result); + console.info("[NFC_test] ConnectedTag11 isExtendedApduSupported result: " + result); + expect(result!=null).assertTrue(); + done(); } }); } - done(); }) /** @@ -347,12 +350,12 @@ export default function ConnectedTagTest() { } else{ await connectedTag.write().then(result => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("[NFC_test] ConnectedTag12 readMultiplePages1 result: " + result); expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] ConnectedTag12 readMultiplePages1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); @@ -373,19 +376,21 @@ export default function ConnectedTagTest() { if (!isAccessToken) { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() + done(); } else{ connectedTag.write((err, result)=> { if (err) { + console.info("[NFC_test] ConnectedTag13 isExtendedApduSupported err: " + err); expect().assertFail(); - console.info("isoDep isExtendedApduSupported err: " + err); + done(); } else { - expect(result!=null).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + result); + console.info("[NFC_test] ConnectedTag13 isExtendedApduSupported result: " + result); + expect(result!=null).assertTrue(); + done(); } }); } - done(); }) console.info("*************[nfc_test] start nfc js unit test end*************"); diff --git a/communication/nfc_Controller/src/main/js/test/nfc.Controller.js b/communication/nfc_Controller/src/main/js/test/nfc.Controller.js index 5d24aad2d79c38685a8e868f4afca47cf7eaae35..d630a8ada87bbab86cb9ccfb359e5568347b52eb 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.Controller.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.Controller.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -35,16 +35,16 @@ let NfcState={ export default function nfcControllerTest() { describe('nfcControllerTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -58,7 +58,7 @@ export default function nfcControllerTest() { it('SUB_COMMUNICATION_NFC_Cont_0100', 0, function () { let NFC_STATE_NOTIFY = "nfcStateChange"; let recvNfcStateNotifyFunc = result => { - console.info("nfc state receive state ->" + result); + console.info("[NFC_test] controller1 nfc state receive state ->" + result); expect(result != null).assertTrue(); } controller.on(NFC_STATE_NOTIFY, recvNfcStateNotifyFunc); @@ -75,10 +75,10 @@ export default function nfcControllerTest() { */ it('SUB_COMMUNICATION_NFC_Cont_0200', 0, function () { let nfcisAvailable = controller.isNfcAvailable(); + console.info('[NFC_test] controller2 Nfc Available ->' + JSON.stringify(nfcisAvailable)); expect(nfcisAvailable).assertTrue(); - console.info('[nfc_js] Nfc Available ->' + JSON.stringify(nfcisAvailable)); }) - + /** * @tc.number SUB_COMMUNICATION_NFC_Cont_0300 * @tc.name Test isNfcOpenapi @@ -86,11 +86,11 @@ export default function nfcControllerTest() { * @tc.size since 7 * @tc.type Function * @tc.level Level 2 - */ + */ it('SUB_COMMUNICATION_NFC_Cont_0300', 0, function () { let nfcswitchis = controller.isNfcOpen(); + console.info('[NFC_test] controller3 Nfc isopen state is ->' + JSON.stringify(nfcswitchis)); expect(nfcswitchis).assertTrue(); - console.info('[nfc_js] Nfc isopen state is ->' + JSON.stringify(nfcswitchis)); }) /** @@ -100,14 +100,14 @@ export default function nfcControllerTest() { * @tc.size since 7 * @tc.type Function * @tc.level Level 2 - */ + */ it('SUB_COMMUNICATION_NFC_Cont_0400', 0, function () { let nfcisAvailable1 = controller.isNfcAvailable(); + console.info('[NFC_test] controller4 NfcAvailable 1 ->' + JSON.stringify(nfcisAvailable1)); expect(nfcisAvailable1).assertTrue(); - console.info('[nfc_js] NfcAvailable 1 ->' + JSON.stringify(nfcisAvailable1)); let nfcenable1 = controller.isNfcOpen(); + console.info('[NFC_test] controller4 Nfc isopen 1 state is ->' + JSON.stringify(nfcenable1)); expect(nfcenable1).assertTrue(); - console.info('[nfc_js] Nfc isopen 1 state is ->' + JSON.stringify(nfcenable1)); }) /** @@ -120,11 +120,11 @@ export default function nfcControllerTest() { */ it('SUB_COMMUNICATION_NFC_Cont_0500', 0, function () { let checkopennfc = controller.getNfcState(); + console.info("[NFC_test] controller5 checkopen the state of nfc-> " + JSON.stringify(checkopennfc)); expect(checkopennfc).assertEqual(NfcState.STATE_ON); - console.log("[nfc_test] checkopen the state of nfc-> " + JSON.stringify(checkopennfc)); }) - console.log("*************[nfc_test] start nfc js unit test end*************"); + console.info("*************[nfc_test] start nfc js unit test end*************"); }) } diff --git a/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js b/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js index 8ab4a87052a8c53186891653add415b4b0cd7558..ae95d9b6d0836ba080bc002d5748649558d56f9c 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -75,7 +75,7 @@ let IsoDepTag ; export default function nfcIsoDepTagTest() { describe('nfcIsoDepTagTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') try { IsoDepTag = tag.getIsoDep(isoDepTaginfo); } catch (error) { @@ -83,13 +83,13 @@ export default function nfcIsoDepTagTest() { } }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -104,10 +104,10 @@ export default function nfcIsoDepTagTest() { if (IsoDepTag != null && IsoDepTag != undefined) { let ResponseFlags = IsoDepTag.getHistoricalBytes(); expect(ResponseFlags).assertInstanceOf('Array') - console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags); + console.info('[NFC_test] Isodep1 test ResponseFlags data>:' + ResponseFlags); } else { console.info("[NFC_test]IsoDepTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -123,10 +123,10 @@ export default function nfcIsoDepTagTest() { if (IsoDepTag != null && IsoDepTag != undefined) { let HiLayerResponse = IsoDepTag.getHiLayerResponse(); expect(HiLayerResponse).assertInstanceOf('Array') - console.info('[nfc_js] test ResponseFlags data2>:' + HiLayerResponse); + console.info('[NFC_test] Isodep2 test ResponseFlags data2>:' + HiLayerResponse); } else { console.info("[NFC_test]IsoDepTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -141,17 +141,17 @@ export default function nfcIsoDepTagTest() { it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, async function (done) { if (IsoDepTag != null && IsoDepTag != undefined) { await IsoDepTag.isExtendedApduSupported().then((data) => { - expect(false).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + data); + console.info("[NFC_test] Isodep3 isExtendedApduSupported data: " + data); + expect(true).assertEqual(data); done(); }).catch((err)=> { - console.info("isoDep isExtendedApduSupported err: " + err); - expect(true).assertFalse(); + console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err); + expect().assertFail(); done(); }); } else { console.info("[NFC_test]IsoDepTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -167,17 +167,18 @@ export default function nfcIsoDepTagTest() { if (IsoDepTag != null && IsoDepTag != undefined) { IsoDepTag.isExtendedApduSupported((err, data)=> { if (err) { - expect(true).assertFalse(); - console.info("isoDep isExtendedApduSupported err: " + err); + console.info("[NFC_test] Isodep4 isExtendedApduSupported err: " + err); + expect().assertFail(); + done(); } else { - expect(false).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + data); + console.info("[NFC_test] Isodep4 isExtendedApduSupported data: " + data); + expect(true).assertEqual(data); + done(); } }); - done(); } else { console.info("[NFC_test]IsoDepTag4 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -194,15 +195,15 @@ export default function nfcIsoDepTagTest() { let cardEmulationnfc ; try { cardEmulationnfc = cardEmulation.isSupported(FeatureType.ESE); - console.info('cardEmulationnfc type ->' + cardEmulationnfc ) + console.info('[NFC_test] cardEmulationnfc5 type ->' + cardEmulationnfc ) expect(cardEmulationnfc).assertFalse(); } catch (error) { - console.info('cardEmulationnfc error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] cardEmulationnfc5 error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]IsoDepTag5 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -218,11 +219,11 @@ export default function nfcIsoDepTagTest() { let cardEmulationnfc ; try { cardEmulationnfc = cardEmulation.hasHceCapability(); - console.info('cardEmulationnfc hasHceCapability type ->' + cardEmulationnfc ) + console.info('[NFC_test] cardEmulationnfc6 hasHceCapability type ->' + cardEmulationnfc ) expect(cardEmulationnfc).assertFalse(); } catch (error) { - console.info('cardEmulationnfc error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] cardEmulationnfc6 error' + error) + expect().assertFail(); } }) @@ -242,11 +243,11 @@ export default function nfcIsoDepTagTest() { }; try { cardEmulationnfc = cardEmulation.isDefaultService(elementName, CardType.PAYMENT); - console.info('cardEmulationnfc isDefaultService type ->' + cardEmulationnfc ) + console.info('[NFC_test] cardEmulationnfc7 isDefaultService type ->' + cardEmulationnfc ) expect(cardEmulationnfc).assertFalse(); } catch (error) { - console.info('cardEmulationnfc error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] cardEmulationnfc7 error' + error) + expect().assertFail(); } }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js b/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js index cfea7489591866d6c48a8338e9a767d41fc374ec..a0e24d542fac037c6996c1c5b2ad4fb21d209248 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -55,7 +55,7 @@ let MifareClassicTag = null; export default function nfcMifareClassicTag() { describe('nfcMifareClassicTag', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') try{ MifareClassicTag = tag.getMifareClassic(mifareclassicTaginfo); } catch (error) { @@ -63,13 +63,13 @@ export default function nfcMifareClassicTag() { } }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -86,18 +86,18 @@ export default function nfcMifareClassicTag() { let sectorIndex = 1; let key = [0x04, 0x05]; await MifareClassicTag.authenticateSector(sectorIndex, key, true).then((data) => { - console.info("mifareClassic authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); - expect(data).assertTrue(); + console.info("[NFC_test] MifareClassicTag1 authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); + expect(data != 0).assertTrue(); done(); }).catch((err)=> { - console.info("mifareClassic authenticateSector1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag1 authenticateSector1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -116,18 +116,19 @@ export default function nfcMifareClassicTag() { let key = [0x04, 0x05]; MifareClassicTag.authenticateSector(sectorIndex, key, true, (err, data)=> { if (err) { - console.info("mifareClassic authenticateSector2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag2 authenticateSector2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); - expect(data).assertTrue(); + console.info("[NFC_test] MifareClassicTag2 authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); + expect(data != 0).assertTrue(); + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]MifareClassicTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -144,18 +145,18 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { let blockIndex = 1; await MifareClassicTag.readSingleBlock(blockIndex).then((data) => { - console.info("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag3 readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); expect(data).assertInstanceOf('Array') done(); }).catch((err)=> { - console.info("mifareClassic readSingleBlock1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag3 readSingleBlock1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -173,17 +174,19 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; MifareClassicTag.readSingleBlock(blockIndex, (err, data)=> { if (err) { - console.info("mifareClassic readSingleBlock2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag4 readSingleBlock2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag4 readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); expect(data).assertInstanceOf('Array') + done(); } }); - done(); + sleep(3000); } else { console.info("[NFC_test]MifareClassicTag4 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -201,18 +204,18 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; let rawData = [0x0a, 0x14]; await MifareClassicTag.writeSingleBlock(blockIndex, rawData).then((data) => { - console.info("mifareClassic writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); - expect(data).assertTrue(); + console.info("[NFC_test] MifareClassicTag5 writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.info("mifareClassic writeSingleBlock1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag5 writeSingleBlock1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag5 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -231,18 +234,19 @@ export default function nfcMifareClassicTag() { let rawData = [0x0a, 0x14]; MifareClassicTag.writeSingleBlock(blockIndex, rawData, (err, data)=> { if (err) { - console.info("mifareClassic writeSingleBlock2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag6 writeSingleBlock2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); - expect(data).assertTrue(); + console.info("[NFC_test] MifareClassicTag6 writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]MifareClassicTag6 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -260,18 +264,18 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; let value = 0x20; await MifareClassicTag.incrementBlock(blockIndex, value).then((data) => { - console.info("mifareClassic incrementBlock1 data: " + data + "json7:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag7 incrementBlock1 data: " + data ); expect(data).assertInstanceOf('Number') - done(); }).catch((err)=> { - console.info("mifareClassic incrementBlock1 err: " + err); + console.info("[NFC_test] MifareClassicTag7 incrementBlock1 err: " + err); expect(true).assertEqual(true); - done(); }); + done(); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag7 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); + done(); } }) @@ -284,16 +288,17 @@ export default function nfcMifareClassicTag() { * @tc.type Function * @tc.level Level 2 */ + it('SUB_Communication_NFC_mifareClassic_js_0800', 0, async function (done) { if (MifareClassicTag != null && MifareClassicTag != undefined) { let blockIndex = 1; let value = 0x20; MifareClassicTag.incrementBlock(blockIndex, value, (err, data)=> { if (err) { - console.info("mifareClassic incrementBlock2 err: " + err); + console.info("[NFC_test] mifareClassic8 incrementBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.info("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); + console.info("[NFC_test] mifareClassic8 incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') } }); @@ -301,7 +306,7 @@ export default function nfcMifareClassicTag() { done(); } else { console.info("[NFC_test]MifareClassicTag8 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -319,18 +324,18 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; let value = 0x20; await MifareClassicTag.decrementBlock(blockIndex, value).then((data) => { - console.info("mifareClassic decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag9 decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.info("mifareClassic decrementBlock1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag9 decrementBlock1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag9 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -349,18 +354,19 @@ export default function nfcMifareClassicTag() { let value = 0x20; MifareClassicTag.decrementBlock(blockIndex, value, (err, data)=> { if (err) { - console.info("mifareClassic decrementBlock2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag10 decrementBlock2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag10 decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]MifareClassicTag10 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -373,16 +379,17 @@ export default function nfcMifareClassicTag() { * @tc.type Function * @tc.level Level 2 */ + it('SUB_Communication_NFC_mifareClassic_js_1100', 0, async function (done) { if (MifareClassicTag != null && MifareClassicTag != undefined) { let blockIndex = 1; await MifareClassicTag.transferToBlock(blockIndex).then((data) => { - console.info("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data)); + console.info("[NFC_test] mifareClassic11 transferToBlock1 data: " + data ); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.info("mifareClassic transferToBlock1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] mifareClassic11 transferToBlock1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); @@ -406,18 +413,19 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; MifareClassicTag.transferToBlock(blockIndex, (err, data)=> { if (err) { - console.info("mifareClassic transferToBlock2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag12 transferToBlock2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag12 transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]MifareClassicTag12 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -434,18 +442,18 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { let blockIndex = 1; await MifareClassicTag.restoreFromBlock(blockIndex).then((data) => { - console.info("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag13 restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.info("mifareClassic restoreFromBlock1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag13 restoreFromBlock1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]MifareClassicTag13 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -463,18 +471,19 @@ export default function nfcMifareClassicTag() { let blockIndex = 1; MifareClassicTag.restoreFromBlock(blockIndex, (err, data)=> { if (err) { - console.info("mifareClassic restoreFromBlock2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] MifareClassicTag14 restoreFromBlock2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); + console.info("[NFC_test] MifareClassicTag14 restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]MifareClassicTag14 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -491,15 +500,15 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { try{ let sectorCount = MifareClassicTag.getSectorCount(); - console.info("mifareClassic sectorCount: " + sectorCount); + console.info("[NFC_test] MifareClassicTag15 sectorCount: " + sectorCount); expect(sectorCount).assertInstanceOf('Number') } catch (error) { - console.info('mifareClassic sectorCount error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag15 sectorCount error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag15 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -517,15 +526,15 @@ export default function nfcMifareClassicTag() { try{ let sectorIndex = 1; let blockCountInSector = MifareClassicTag.getBlockCountInSector(sectorIndex); - console.info("mifareClassic blockCountInSector: " + blockCountInSector); + console.info("[NFC_test] MifareClassicTag16 blockCountInSector: " + blockCountInSector); expect(blockCountInSector).assertInstanceOf('Number') } catch (error) { - console.info('mifareClassic blockCountInSector error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag16 blockCountInSector error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag16 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -542,15 +551,15 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { try{ let getType = MifareClassicTag.getType(); - console.info("mifareClassic getType: " + getType); + console.info("[NFC_test] MifareClassicTag17 getType: " + getType); expect(getType >= -1).assertTrue(); } catch (error) { - console.info('mifareClassic getType error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag17 getType error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag17 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -567,15 +576,15 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { try{ let tagSize = MifareClassicTag.getTagSize(); - console.info("mifareClassic tagSize: " + tagSize); + console.info("[NFC_test] MifareClassicTag18 tagSize: " + tagSize); expect(tagSize).assertInstanceOf('Number') } catch (error) { - console.info('mifareClassic tagSize error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag18 tagSize error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag18 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -592,15 +601,15 @@ export default function nfcMifareClassicTag() { if (MifareClassicTag != null && MifareClassicTag != undefined) { try{ let isEmulatedTag = MifareClassicTag.isEmulatedTag(); - console.info("mifareClassic isEmulatedTag: " + isEmulatedTag); + console.info("[NFC_test] MifareClassicTag19 isEmulatedTag: " + isEmulatedTag); expect(false).assertEqual(isEmulatedTag); } catch (error) { - console.info('mifareClassic isEmulatedTag error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag19 isEmulatedTag error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag19 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -618,15 +627,15 @@ export default function nfcMifareClassicTag() { try{ let sectorIndex = 1; let blockIndex = MifareClassicTag.getBlockIndex(sectorIndex); - console.info("mifareClassic blockIndex: " + blockIndex); + console.info("[NFC_test] MifareClassicTag20 blockIndex: " + blockIndex); expect(blockIndex >= 0).assertTrue(); } catch (error) { - console.info('mifareClassic blockIndex error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] MifareClassicTag20 blockIndex error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag20 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -644,15 +653,15 @@ export default function nfcMifareClassicTag() { try{ let blockIndex = 1; let sectorIndex = MifareClassicTag.getSectorIndex(blockIndex); - console.info("mifareClassic sectorIndex: " + sectorIndex); + console.info("[NFC_test] mifareClassic21 sectorIndex: " + sectorIndex); expect(sectorIndex >= 0).assertTrue(); } catch (error) { - console.info('mifareClassic sectorIndex error' + error) - expect(true).assertFalse(); + console.info('[NFC_test] mifareClassic21 sectorIndex error' + error) + expect().assertFail(); } } else { console.info("[NFC_test]MifareClassicTag21 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js index 4c33bc7b52e948681b59063f4405ccae567b6820..4ee1f8e01637edca32f7dc8ba5aca1dfb8c1494e 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -39,7 +39,7 @@ let mifareUltralightTaginfo = { }; let MifareUltralightType = { - TYPE_UNKOWN : 0x04, + TYPE_UNKOWN : 0, TYPE_ULTRALIGHT : 1, TYPE_ULTRALIGHT_C : 2, } @@ -49,7 +49,7 @@ let MifareUltralightTag = null; export default function nfcMifareUltralightTag() { describe('nfcMifareUltralightTag', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') }) beforeEach(function() { try { @@ -58,13 +58,13 @@ export default function nfcMifareUltralightTag() { } catch (error) { console.info(' mifareUltralight error' + error) } - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -80,18 +80,18 @@ export default function nfcMifareUltralightTag() { if (MifareUltralightTag != null && MifareUltralightTag != undefined) { let pageIndex = 1; await MifareUltralightTag.readMultiplePages(pageIndex).then((data) => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] mifareUltralight1 readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Array') done(); }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] mifareUltralight1 readMultiplePages1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]mifareUltralight1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -109,18 +109,19 @@ export default function nfcMifareUltralightTag() { let pageIndex = 1; MifareUltralightTag.readMultiplePages(pageIndex, (err, data)=> { if (err) { - console.info("mifareUltralight readMultiplePages2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] mifareUltralight2 readMultiplePages2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.info("mifareUltralight readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data)); - expect(data >= 0).assertTrue(); + console.info("[NFC_test] mifareUltralight2 readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Array') + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]mifareUltralight2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -138,18 +139,18 @@ export default function nfcMifareUltralightTag() { let pageIndex = 1; let rawData = [0x01, 0x02]; await MifareUltralightTag.writeSinglePage(pageIndex, rawData).then((data) => { - console.log("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("[NFC_test] mifareUltralight3 writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); expect(data >= 0).assertTrue(); done(); }).catch((err)=> { - console.log("mifareUltralight writeSinglePages1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] mifareUltralight3 writeSinglePages1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]mifareUltralight3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -168,18 +169,19 @@ export default function nfcMifareUltralightTag() { let rawData = [0x01, 0x02]; MifareUltralightTag.writeSinglePage(pageIndex, rawData, (err, data)=> { if (err) { - console.log("mifareUltralight writeSinglePages2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test] mifareUltralight4 writeSinglePages2 err: " + err); + expect(true).assertTrue(); + done(); } else { - console.log("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); + console.info("[NFC_test] mifareUltralight4 writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); expect(data >= 0).assertTrue(); + done(); } }); sleep(3000); - done(); } else { console.info("[NFC_test]mifareUltralight4 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -195,11 +197,11 @@ export default function nfcMifareUltralightTag() { it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () { if (MifareUltralightTag != null && MifareUltralightTag != undefined) { let getType = MifareUltralightTag.getType(); - console.info("mifareUltralight getType: " + getType); - expect(getType >= -1).assertTrue(); + console.info("[NFC_test] mifareUltralight5 getType: " + getType); + expect(getType).assertEqual(MifareUltralightType.TYPE_UNKOWN); } else { console.info("[NFC_test]mifareUltralight5 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js b/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js index 30b9fbe9bf5fa32a380ba5aa2a03dc0b507d5890..112322a4b795a295f1072aa3a21ed397b814e5ea 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -99,7 +99,7 @@ let NdefTag ; export default function nfcNDEFTagTest() { describe('nfcNDEFTagTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') try { NdefTag = tag.getNdef(NDEFTaginfo); console.info("[NFC_test]NdefTag001 ->: "+ JSON.stringify(NdefTag)); @@ -108,13 +108,13 @@ export default function nfcNDEFTagTest() { } }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -131,16 +131,17 @@ export default function nfcNDEFTagTest() { 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 ]; try { - ndefMessage = tag.ndef.createNdefMessage(rawData); + let ndefMessage = tag.ndef.createNdefMessage(rawData); + console.info("[NFC_test]ndef1 ndefMessage1: " + ndefMessage); expect(ndefMessage !=null).assertTrue(); expect(ndefMessage instanceof Object).assertTrue(); - console.info("[NFC_test]ndef ndefMessage1: " + ndefMessage); } catch (error) { - console.info("[NFC_test]ndef ndefMessage1 error: " + error); + console.info("[NFC_test]ndef1 ndefMessage1 error: " + error); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } sleep(3000); }) @@ -161,22 +162,23 @@ export default function nfcNDEFTagTest() { console.info("ndefRecords is object2" ); try { let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result: "); + console.info("[NFC_test]ndef2 ndefMessage result: "); if (ndefMessage != null && ndefMessage != undefined) { let ndefRecords = ndefMessage.getNdefRecords(); - console.info("[NFC_test]ndef ndefRecords number: " + JSON.stringify(ndefRecords)); + console.info("[NFC_test]ndef2 ndefRecords number: " + JSON.stringify(ndefRecords)); expect(ndefRecords).assertInstanceOf('Array') } else{ - console.info("[NFC_test]ndef ndefMessage = null & = undefined: "); - expect(true).assertFalse(); + console.info("[NFC_test]ndef2 ndefMessage = null & = undefined: "); + expect().assertFail(); } }catch(error){ console.info("ndef ndefMessage2 error: " + error); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } sleep(3000); }) @@ -200,21 +202,21 @@ export default function nfcNDEFTagTest() { try { ndefMessage = tag.ndef.createNdefMessage(ndefRecords); if (ndefMessage != null && ndefMessage != undefined) { - console.info("[NFC_test]ndef ndefMessage1113: " + ndefMessage); + console.info("[NFC_test]ndef3 ndefMessage1113: " + ndefMessage); expect(ndefMessage != null).assertTrue(); expect(ndefMessage instanceof Object).assertTrue(); } else{ - console.info("[NFC_test]ndef ndefMessage = null & = undefined: "); - expect(true).assertFalse(); + console.info("[NFC_test]ndef3 ndefMessage = null & = undefined: "); + expect().assertFail(); } } catch (error) { console.info('SUB_Communication_NFC_nfcNDEF_js_03002 error' + error) - expect(true).assertFalse(); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } sleep(3000); }) @@ -230,11 +232,11 @@ export default function nfcNDEFTagTest() { it('SUB_Communication_NFC_nfcNDEF_js_0400', 0, function () { if (NdefTag != null && NdefTag != undefined) { let ndefTagType = NdefTag.getNdefTagType(); + console.info("[NFC_test]ndef4 ndefTagType: " + ndefTagType); expect(NfcForumType.NFC_FORUM_TYPE_1).assertEqual(ndefTagType); - console.info("[NFC_test]ndef ndefTagType: " + ndefTagType); } else { console.info("[NFC_test]NdefTag4 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -250,15 +252,15 @@ export default function nfcNDEFTagTest() { if (NdefTag != null && NdefTag != undefined) { try { let getMessage = NdefTag.getNdefMessage(); + console.info('[NFC_test]ndef5 NdefMessage:' + getMessage) expect(getMessage != null).assertTrue(); - console.info('[NFC_test]ndef NdefMessage:' + getMessage) } catch (error) { console.info('ndef NdefMessage error' + error) - expect(true).assertFalse(); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag5 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -293,14 +295,15 @@ export default function nfcNDEFTagTest() { } if (NdefTag1 != null && NdefTag1 != undefined) { let data = NdefTag1.isNdefWritable(); - console.info("[NFC_test]ndef isNdefWritable data: " + data); + console.info("[NFC_test]ndef6 isNdefWritable data: " + data); expect(data).assertTrue(); done(); - sleep(3000); } else { console.info("[NFC_test]NdefTag6 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); + done(); } + sleep(3000); }) /** @@ -314,17 +317,18 @@ export default function nfcNDEFTagTest() { it('SUB_Communication_NFC_nfcNDEF_js_0700', 0, async function (done) { if (NdefTag != null && NdefTag != undefined) { await NdefTag.readNdef().then((data) => { - console.info("[NFC_test]ndef readNdef1 data: " + data); + console.info("[NFC_test]ndef7 readNdef1 data: " + data); + expect(data!= null).assertTrue(); done(); }).catch((err)=> { - console.info("ndef readNdef1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test]ndef7 readNdef1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]NdefTag7 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -340,18 +344,19 @@ export default function nfcNDEFTagTest() { if (NdefTag != null && NdefTag != undefined) { NdefTag.readNdef((err, data)=> { if (err) { - expect(true).assertEqual(true); - console.info("[NFC_test]ndef readNdef2 err: " + err); + console.info("[NFC_test]ndef8 readNdef2 err: " + err); + expect(true).assertTrue(); + done(); } else { - expect(data!=true).assertTrue(); - console.info("[NFC_test]ndef readNdef2 data: " + data); + console.info("[NFC_test]ndef8 readNdef2 data: " + data); + expect(data!= null).assertTrue(); + done(); } }); - done(); sleep(3000); } else { console.info("[NFC_test]NdefTag8 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -370,18 +375,18 @@ export default function nfcNDEFTagTest() { ]; let ndefMessage = tag.ndef.createNdefMessage(rawData); await NdefTag.writeNdef(ndefMessage).then((data) => { + console.info("[NFC_test]ndef9 writeNdef1 data: " + data); expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef writeNdef1 data: " + data); done(); }).catch((err)=> { - console.info("[NFC_test]ndef writeNdef1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test]ndef9 writeNdef1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { - console.info("[NFC_test]NdefTag = null & = undefined: "); - expect(true).assertFalse(); + console.info("[NFC_test]NdefTag9 = null & = undefined: "); + expect().assertFail(); } }) @@ -401,18 +406,19 @@ export default function nfcNDEFTagTest() { let ndefMessage = tag.ndef.createNdefMessage(rawData); NdefTag.writeNdef(ndefMessage, (err, data)=> { if (err) { - console.info("[NFC_test]ndef writeNdef2 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test]ndef10 writeNdef2 err: " + err); + expect(true).assertTrue(); + done(); } else { - expect(data).assertInstanceOf('Number') console.info("[NFC_test]ndef10 writeNdef2 data: " + data); + expect(data).assertInstanceOf('Number') + done(); } }); - done(); sleep(3000); } else { - console.info("[NFC_test]NdefTag = null & = undefined: "); - expect(true).assertFalse(); + console.info("[NFC_test]NdefTag10 = null & = undefined: "); + expect().assertFail(); } }) @@ -428,15 +434,15 @@ export default function nfcNDEFTagTest() { if (NdefTag != null && NdefTag != undefined) { try { let canSetReadOnly = NdefTag.canSetReadOnly(); - console.info("[NFC_test]ndef canSetReadOnly: " + canSetReadOnly); + console.info("[NFC_test]ndef11 canSetReadOnly: " + canSetReadOnly); expect(canSetReadOnly).assertTrue(); } catch (error) { - console.info('NdefTag NdefTag error' + error) + console.info('[NFC_test]NdefTag11 NdefTag error' + error) expect(true).assertTrue(); } } else { console.info("[NFC_test]NdefTag11 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -451,18 +457,18 @@ export default function nfcNDEFTagTest() { it('SUB_Communication_NFC_nfcNDEF_js_1200', 0, async function (done) { if (NdefTag != null && NdefTag != undefined) { await NdefTag.setReadOnly().then((data) => { + console.info("[NFC_test]ndef12 setReadOnly1 data: " + data); expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef setReadOnly1 data: " + data); done(); }).catch((err)=> { - console.info("[NFC_test]ndef setReadOnly1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test]ndef12 setReadOnly1 err: " + err); + expect(true).assertTrue(); done(); }); sleep(3000); } else { console.info("[NFC_test]NdefTag12 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -478,18 +484,19 @@ export default function nfcNDEFTagTest() { if (NdefTag != null && NdefTag != undefined) { NdefTag.setReadOnly((err, data)=> { if (err) { - expect(true).assertEqual(true); - console.info("[NFC_test]ndef setReadOnly2 err: " + err); + console.info("[NFC_test]ndef13 setReadOnly2 err: " + err); + expect(true).assertTrue(); + done(); } else { - expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef setReadOnly2 data: " + data); + console.info("[NFC_test]ndef13 setReadOnly2 data: " + data); + expect().assertFail(); + done(); } }); - done(); sleep(3000); } else { console.info("[NFC_test]NdefTag13 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -504,11 +511,11 @@ export default function nfcNDEFTagTest() { it('SUB_Communication_NFC_nfcNDEF_js_1400', 0, function () { if (NdefTag != null && NdefTag != undefined) { let ndefTypeString = NdefTag.getNdefTagTypeString(NfcForumType.NFC_FORUM_TYPE_1); - console.info("[NFC_test]ndef ndefTypeString: " + JSON.stringify(ndefTypeString)); + console.info("[NFC_test]ndef14 ndefTypeString: " + JSON.stringify(ndefTypeString)); expect(ndefTypeString.length >= 0).assertTrue(); } else { console.info("[NFC_test]NdefTag14 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -527,14 +534,15 @@ export default function nfcNDEFTagTest() { let ndefmessage = tag.ndef.createNdefMessage(rawData); let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); await NdefFormatable.format(ndefmessage).then(() => { - console.info("[NFC_test]ndefFormatable format1 "); + console.info("[NFC_test]ndef15 Formatable format1 "); + expect().assertFail(); }).catch((err)=> { - console.info("[NFC_test]ndefFormatable format1 err: " + err); - expect(true).assertEqual(true); + console.info("[NFC_test]ndef15 Formatable format1 err: " + err); + expect(true).assertTrue(); }); } else { console.info("[NFC_test]NdefTag15 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -553,16 +561,19 @@ export default function nfcNDEFTagTest() { let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); NdefFormatable.format(ndefmessage, (err, data)=> { if (err) { - console.log("ndefFormatable format err: " + err); + console.info("[NFC_test]ndef16 Formatable format err: " + err); expect(true).assertTrue(); + done(); } else { - console.info("[NFC_test]ndefFormatable formatReadOnly2" ); + console.info("[NFC_test]ndef16 Formatable formatReadOnly2" ); + expect().assertFail(); + done(); } }); - done(); + sleep(3000); } else { console.info("[NFC_test]NdefTag16 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -582,14 +593,15 @@ export default function nfcNDEFTagTest() { let ndefmessage = tag.ndef.createNdefMessage(rawData); let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); await NdefFormatable.formatReadOnly(ndefmessage).then(() => { - console.info("[NFC_test]ndefFormatable formatReadOnly1 " + data); + console.info("[NFC_test]ndef17 Formatable formatReadOnly1 " + data); + expect().assertFail(); }).catch((err)=> { - console.info("[NFC_test]ndefFormatable formatReadOnly1 err: " + err); + console.info("[NFC_test]ndef17 Formatable formatReadOnly1 err: " + err); expect(true).assertTrue(); }); } else { console.info("[NFC_test]NdefTag17 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -610,16 +622,19 @@ export default function nfcNDEFTagTest() { let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); NdefFormatable.formatReadOnly(ndefmessage, (err, data)=> { if (err) { - console.log("ndefFormatable format err: " + err); + console.info("[NFC_test]ndef18 Formatable format err: " + err); expect(true).assertTrue(); + done(); } else { - console.info("[NFC_test]ndefFormatable formatReadOnly2" ); + console.info("[NFC_test]ndef18 Formatable formatReadOnly2" ); + expect().assertFail(); + done(); } }); - done(); + sleep(3000); } else { console.info("[NFC_test]NdefTag18 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -638,17 +653,17 @@ export default function nfcNDEFTagTest() { console.info("makeUriRecord is object3" ); try { let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result: " + JSON.stringify(ndefMessage)); + console.info("[NFC_test]ndef19 Message result: " + JSON.stringify(ndefMessage)); let makeRecords = tag.ndef.makeUriRecord("D4010354787473"); - console.info("[NFC_test]makeUriRecord result: " + JSON.stringify(makeRecords)); + console.info("[NFC_test]ndrf19 result: " + JSON.stringify(makeRecords)); expect(JSON.stringify(makeRecords)!=null).assertTrue(); } catch (error) { - console.info("ndef ndefMessage error: " + error); - expect(true).assertFalse(); + console.info("[NFC_test]ndef19 ndefMessage error: " + error); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag19 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -666,17 +681,17 @@ export default function nfcNDEFTagTest() { console.info("makeTextRecord is object4" ); try { let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result1: " + JSON.stringify(ndefMessage)); + console.info("[NFC_test]ndef20 Message result1: " + JSON.stringify(ndefMessage)); let makeTRecords = tag.ndef.makeTextRecord("test112HW","test"); - console.info("[NFC_test]makeTextRecord result1: " + JSON.stringify(makeTRecords)); + console.info("[NFC_test]ndef20 result1: " + JSON.stringify(makeTRecords)); expect(JSON.stringify(makeTRecords)!=null).assertTrue(); } catch (error) { - console.info("ndef ndefMessage1 error: " + error); - expect(true).assertFalse(); + console.info("[NFC_test]ndef20 ndefMessage1 error: " + error); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag20 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -696,24 +711,27 @@ export default function nfcNDEFTagTest() { console.info('SUB_Communication_NFC_nfcNDEF_js_2100 error' + error) } let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; + let mimeType = "text/plain"; + let mimeData = [0x01, 0x02, 0x03, 0x04]; if (NdefTag!= undefined){ console.info("makeMimeRecord is object5" ); try{ let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result2: " + JSON.stringify(ndefMessage)); - let makeMRecords = tag.ndef.makeMimeRecord("BYTE" , "0112"); - console.info("[NFC_test]makeMimeRecord result2: " + JSON.stringify(makeMRecords)); + console.info("[NFC_test]nde21 fMessage result2: " + JSON.stringify(ndefMessage)); + let makeMRecords = tag.ndef.makeMimeRecord(mimeType , mimeData); + console.info("[NFC_test]ndef21 result2: " + JSON.stringify(makeMRecords)); expect(JSON.stringify(makeMRecords)!=null).assertTrue(); }catch(error){ - console.info("ndef ndefMessage2 error: " + error); + console.info("[NFC_test]ndef21 ndefMessage2 error: " + error); + expect().assertFail(); } }else{ - console.info("[NFC_test]ndef typeof2 ->: "+ typeof(NdefTag) ); + console.info("[NFC_test]ndef21 typeof2 ->: "+ typeof(NdefTag) ); + expect().assertFail(); } }) - /** * @tc.number SUB_Communication_NFC_nfcNDEF_js_2200 * @tc.name Test makeExternalRecord NDEF @@ -728,17 +746,17 @@ export default function nfcNDEFTagTest() { console.info("makeExternalRecord is object6" ); try { let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result3: " + JSON.stringify(ndefMessage)); + console.info("[NFC_test]ndef22 Message result3: " + JSON.stringify(ndefMessage)); let makeERecords = tag.ndef.makeExternalRecord("NFC","NFCtest",[0x01, 0x02]); - console.info("[NFC_test]makeExternalRecord result13: " + JSON.stringify(makeERecords)); + console.info("[NFC_test]ndef22 result13: " + JSON.stringify(makeERecords)); expect(makeERecords instanceof Object).assertTrue(); } catch (error) { - console.info("ndef ndefMessage3 error: " + error); - expect(true).assertFalse(); + console.info("[NFC_test]ndef22 ndefMessage3 error: " + error); + expect().assertFail(); } } else { console.info("[NFC_test]NdefTag22 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -756,17 +774,17 @@ export default function nfcNDEFTagTest() { console.info("messageToBytes is object7" ); try { let ndefMessage = tag.ndef.createNdefMessage(rawData); - console.info("[NFC_test]ndefMessage result4: " + JSON.stringify(ndefMessage)); + console.info("[NFC_test]ndef23 Message result4: " + JSON.stringify(ndefMessage)); let makeERecords = tag.ndef.messageToBytes(ndefMessage); - console.info("[NFC_test]messageToBytes result4: " + JSON.stringify(makeERecords)); + console.info("[NFC_test]ndef23 result4: " + JSON.stringify(makeERecords)); expect(makeERecords).assertInstanceOf('Array') } catch (error) { - console.info("ndef ndefMessage4 error: " + error); - expect(true).assertFalse(); + console.info("[NFC_test]ndef23 ndefMessage4 error: " + error); + expect().assertFail(); } }else{ console.info("[NFC_test]NdefTag23 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js index c88a4ecc6d44669fcf10eae6e4717c40d58b50c5..5fc5b8b39dd14ed96c661c7085b36287a760b3bb 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -89,27 +89,33 @@ let vTag = { "tagRfDiscId": 1, }; -let Want = { - "uid" : '01020304', - "technology" : [1], - "tagRfDiscId" :1, - "Sak": 0x08, - "Atqa": "B000", +var Want = { + uid: [0x5B, 0x7F, 0xCF, 0xA9], + technology: [1, 8], + tagRfDiscId: 1, + extrasData : [ + {Sak: 0x08, Atqa: '0400'}, + {MifareUltralightC: true}, + {NdefMsg: '030DD207036162632F646566676869', + NdefForumType: 1, + NdefTagLength: 253, + NdefTagMode: 1} + ] } export default function nfcTagABFVTest() { describe('nfcTagABFVTest', function () { beforeAll(function () { - console.info('[NFC_test]beforeAll called') + console.info('rbeforeAll called') }) beforeEach(function() { - console.info('[NFC_test]beforeEach called') + console.info('beforeEach called') }) afterEach(function () { - console.info('[NFC_test]afterEach called') + console.info('afterEach called') }) afterAll(function () { - console.info('[NFC_test]afterAll called') + console.info('afterAll called') }) /** @@ -128,12 +134,12 @@ export default function nfcTagABFVTest() { console.info('Nfcget tagABFV error' + error) } if (NfcATag != null && NfcATag != undefined) { + console.info('[NFC_test] aTag1 is--<-!!!->' + JSON.stringify(NfcATag)); expect(NfcATag != null).assertTrue(); expect(NfcATag instanceof Object).assertTrue(); - console.info('aTag is--<-!!!->' + JSON.stringify(NfcATag)); } else { console.info("[NFC_test]NfcATag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -153,12 +159,12 @@ export default function nfcTagABFVTest() { console.info('Nfcget tagABFV error' + error) } if (NfcBTag != null && NfcBTag != undefined) { + console.info('[NFC_test] bTag2 is--<-!!!->' + JSON.stringify(NfcBTag)); expect(NfcBTag != null).assertTrue(); expect(NfcBTag instanceof Object).assertTrue(); - console.info('bTag is--<-!!!->' + JSON.stringify(NfcBTag)); } else { console.info("[NFC_test]NfcBTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -178,12 +184,12 @@ export default function nfcTagABFVTest() { console.info('Nfcget tagABFV error' + error) } if (NfcFTag != null && NfcFTag != undefined) { + console.info('[NFC_test] fTag3 is--<-!!!->' + JSON.stringify(NfcFTag)); expect(NfcFTag != null).assertTrue(); expect(NfcFTag instanceof Object).assertTrue(); - console.info('fTag is--<-!!!->' + JSON.stringify(NfcFTag)); } else { console.info("[NFC_test]NfcFTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -203,12 +209,12 @@ export default function nfcTagABFVTest() { console.info('Nfcget tagABFV error' + error) } if (NfcVTag != null && NfcVTag != undefined) { + console.info('[NFC_test] vTag4 is--<-!!!->' + JSON.stringify(NfcVTag)); expect(NfcVTag != null).assertTrue(); expect(NfcVTag instanceof Object).assertTrue(); - console.info('vTag is--<-!!!->' + JSON.stringify(NfcVTag)); } else { console.info("[NFC_test]NfcVTag1 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -229,11 +235,11 @@ export default function nfcTagABFVTest() { } if (NfcATag != null && NfcATag != undefined) { let sak = NfcATag.getSak(); + console.info('[NFC_test] tag5 test sak data>:' + sak); expect(sak).assertInstanceOf('Number'); - console.info('[nfc_js] test sak data>:' + sak); } else { console.info("[NFC_test]NfcATag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -254,11 +260,11 @@ export default function nfcTagABFVTest() { } if (NfcATag != null && NfcATag != undefined) { let Atqa = NfcATag.getAtqa(); + console.info('[NFC_test] tag6 test Atqa data>:' + Atqa); expect(Atqa).assertInstanceOf('Array'); - console.info('[nfc_js] test Atqa data>:' + Atqa); } else { console.info("[NFC_test]NfcATag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -279,11 +285,11 @@ export default function nfcTagABFVTest() { } if (NfcBTag != null && NfcBTag != undefined) { let AppData = NfcBTag.getRespAppData(); + console.info('[NFC_test] tag7 test AppData data>:' + AppData); expect(AppData).assertInstanceOf('Array'); - console.info('[nfc_js] test AppData data>:' + AppData); } else { console.info("[NFC_test]NfcBTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -304,11 +310,11 @@ export default function nfcTagABFVTest() { } if (NfcBTag != null && NfcBTag != undefined) { let Protocol = NfcBTag.getRespProtocol(); + console.info('[NFC_test] tag8 test Protocol data>:' + Protocol); expect(Protocol).assertInstanceOf('Array'); - console.info('[nfc_js] test Protocol data>:' + Protocol); } else { console.info("[NFC_test]NfcBTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -329,11 +335,11 @@ export default function nfcTagABFVTest() { } if (NfcFTag != null && NfcFTag != undefined) { let SystemCode = NfcFTag.getSystemCode(); + console.info('[NFC_test] tag9 test SystemCode data>:' + SystemCode); expect(SystemCode).assertInstanceOf('Array'); - console.info('[nfc_js] test SystemCode data>:' + SystemCode); } else { console.info("[NFC_test]NfcFTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -354,11 +360,11 @@ export default function nfcTagABFVTest() { } if (NfcFTag != null && NfcFTag != undefined) { let Pmm = NfcFTag.getPmm(); + console.info('[NFC_test] tag10 test Pmm data>:' + Pmm); expect(Pmm).assertInstanceOf('Array'); - console.info('[nfc_js] test Pmm data>:' + Pmm); } else { console.info("[NFC_test]NfcFTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -379,11 +385,11 @@ export default function nfcTagABFVTest() { } if (NfcVTag != null && NfcVTag != undefined) { let ResponseFlags = NfcVTag.getResponseFlags(); + console.info('[NFC_test] tag11 test ResponseFlags3 data>:' + ResponseFlags); expect(ResponseFlags).assertInstanceOf('Number'); - console.info('[nfc_js] test ResponseFlags3 data>:' + ResponseFlags); } else { console.info("[NFC_test]NfcVTag2 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -404,11 +410,11 @@ export default function nfcTagABFVTest() { } if (NfcVTag != null && NfcVTag != undefined) { let DsfId = NfcVTag.getDsfId(); + console.info('[NFC_test] tag12 test DsfId data>:' + DsfId); expect(DsfId).assertInstanceOf('Number'); - console.info('[nfc_js] test DsfId data>:' + DsfId); } else { console.info("[NFC_test]NfcVTag3 = null & = undefined: "); - expect(true).assertFalse(); + expect().assertFail(); } }) @@ -421,16 +427,16 @@ export default function nfcTagABFVTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfctage_js_1300', 0, function () { - let TagInfo ; + let getTagtest ; try { - TagInfo = tag.getTagInfo(Want); - console.info('Nfcget tagABFV gettaginfo is: ' + TagInfo) - expect(TagInfo instanceof Object).assertTrue(); + getTagtest = tag.getTagInfo(Want); + console.info('[NFC_test] tag13 Nfcget tagABFV gettaginfo is: ' + getTagtest) + expect(getTagtest instanceof Object).assertTrue(); }catch(error){ - console.info('Nfcget taginfo error' + error) + console.info('[NFC_test] tag13 Nfcget taginfo error' + error) expect(true).assertTrue(); } - console.info('[nfc_js] test TagInfo data>:' + TagInfo); + console.info('[NFC_test] tag13 test TagInfo data>:' + getTagtest); }) /** @@ -448,9 +454,9 @@ export default function nfcTagABFVTest() { } catch (error) { console.info('nfc gertaga error' + error) } + console.info('[NFC_test] aTag14 is--<-!!!->' + JSON.stringify(NfcATag)); expect(NfcATag != null).assertTrue(); expect(NfcATag instanceof Object).assertTrue(); - console.info('aTag is--<-!!!->' + JSON.stringify(NfcATag)); }) /** @@ -466,11 +472,11 @@ export default function nfcTagABFVTest() { try { NfcBTag = tag.getNfcB(bTag); } catch (error) { - console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error) + console.info('nfc getNfcB error' + error) } + console.info('[NFC_test] bTag15 is--<-!!!->' + JSON.stringify(NfcBTag)); expect(NfcBTag != null).assertTrue(); expect(NfcBTag instanceof Object).assertTrue(); - console.info('bTag is--<-!!!->' + JSON.stringify(NfcBTag)); }) /** @@ -486,11 +492,11 @@ export default function nfcTagABFVTest() { try { NfcFTag = tag.getNfcF(fTag); } catch (error) { - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) + console.info('nfc getNfcF error' + error) } + console.info('[NFC_test] fTag16 is--<-!!!->' + JSON.stringify(NfcFTag)); expect(NfcFTag != null).assertTrue(); expect(NfcFTag instanceof Object).assertTrue(); - console.info('fTag is--<-!!!->' + JSON.stringify(NfcFTag)); }) /** @@ -506,11 +512,11 @@ export default function nfcTagABFVTest() { try { NfcVTag = tag.getNfcV(vTag); } catch (error) { - console.info('SUB_Communication_NFC_nfctage_js_0400 error' + error) + console.info('nfc getNfcV error' + error) } + console.info('[NFC_test] vTag17 is--<-!!!->' + JSON.stringify(NfcVTag)); expect(NfcVTag != null).assertTrue(); expect(NfcVTag instanceof Object).assertTrue(); - console.info('vTag is--<-!!!->' + JSON.stringify(NfcVTag)); }) console.info("*************[nfc_test] start nfc js unit test end*************"); diff --git a/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css b/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css index 3a8326a076cdb9ecabf543df9dba84240f5b52a4..f709257c9c37edf2627fbd6d6ee68161fd4251a1 100644 --- a/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css +++ b/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml b/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml index 0053057b5ff7362e00db48887ee1663cffa35988..d28045f2adb8200db6a527b89b456112274416ec 100644 --- a/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml +++ b/communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js index cea29018263bab2f13d82d2f8c0ccc70150cf6ff..071dc1be82bf7da505797ed07c2d15001f09c02d 100644 --- a/communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js +++ b/communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -35,7 +35,7 @@ function translateParamsToString(parameters) { console.info('OpenHarmonyTestRunner OnPrepare') }, onRun() { - console.log('OpenHarmonyTestRunner onRun run') + console.info('OpenHarmonyTestRunner onRun run') var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() diff --git a/communication/nfc_ErrorCode/src/main/js/test/List.test.js b/communication/nfc_ErrorCode/src/main/js/test/List.test.js index f2fdcbf9a78c9a7cef18ae558762ca3db99ddf04..be05a32d291547c8074e7b5663e313d8bf21b235 100644 --- a/communication/nfc_ErrorCode/src/main/js/test/List.test.js +++ b/communication/nfc_ErrorCode/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js b/communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js index 3549d6b9889e58dbe081fd5fb83e949440c9abf2..fc955c1a132326dbb4bda2b9da08a0b7fcfb511a 100644 --- a/communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js +++ b/communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js @@ -23,7 +23,7 @@ function sleep(delay) { // delay x ms continue; } } - + let NdefRecord = { NFC_A : 1, NFC_B : 2, @@ -63,7 +63,10 @@ let isoDepTaginfo = { ], "tagRfDiscId": 1, }; + let IsoDepTag ; + +let parametertest = 1; export default function nfcIsoDepErrorTest() { describe('nfcIsoDepErrorTest', function () { beforeAll(function () { @@ -93,10 +96,11 @@ export default function nfcIsoDepErrorTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, async function (done) { - if (IsoDepTag != null && IsoDepTag != undefined) { + if (IsoDepTag != null && IsoDepTag != undefined) { (async () => { try { - let result = await IsoDepTag.isExtendedApduSupported('test'); + + let result = await IsoDepTag.isExtendedApduSupported("test"); console.info("[NFC_test]isoDep1 isExtendedApduSupported data: " + result); expect(result).assertInstanceOf('Array') expect().assertFail() @@ -124,7 +128,7 @@ export default function nfcIsoDepErrorTest() { it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, async function (done) { if (IsoDepTag != null && IsoDepTag != undefined) { try { - IsoDepTag.isExtendedApduSupported('test')((err, data)=> { + IsoDepTag.isExtendedApduSupported("test")((err, data)=> { if (err) { expect().assertFail(); console.info("[NFC_test]isoDep2 isExtendedApduSupported errcode: " + err); @@ -169,4 +173,4 @@ export default function nfcIsoDepErrorTest() { console.info("*************[nfc_test] start nfc js unit test end*************"); }) -} +} \ No newline at end of file diff --git a/communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js b/communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js index 6a5fedfdfb50a161cbd123bb33d6e8e819ec632d..34df0e4722c0a9e08c36f75c37a5ee551cf765a5 100644 --- a/communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js +++ b/communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js @@ -176,10 +176,10 @@ export default function UltralightTagErrorTest() { try { MifareUltralightTag.writeSinglePage('test', rawData, (err, data)=> { if (err) { - console.log("[NFC_test]mifareUltralight4 writeSinglePage errcode: " + err); + console.info("[NFC_test]mifareUltralight4 writeSinglePage errcode: " + err); expect(true).assertEqual(true); } else { - console.log("[NFC_test]mifareUltralight4 writeSinglePage data: " + data + "json2:" + JSON.stringify(data)); + console.info("[NFC_test]mifareUltralight4 writeSinglePage data: " + data + "json2:" + JSON.stringify(data)); expect(true).assertTrue(data >= 0); } }); diff --git a/communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js b/communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js index 752208ca21353882d62bd303afe041a91bc84899..d528f1e3e7f3f0b75ad78041f8f2eb41b436a2e3 100644 --- a/communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js +++ b/communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js @@ -461,7 +461,7 @@ export default function nfcNDEFErrorTest() { try { NdefFormatable.format('test', (err, data)=> { if (err) { - console.log("[NFC_test]ndef12 format errcode: " + err); + console.info("[NFC_test]ndef12 format errcode: " + err); expect(true).assertTrue(); } else { console.info("[NFC_test]ndef12 format formatReadOnly2" ); diff --git a/communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js b/communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js index dc0ac7aa8fd850cf134ad29935aa6a11db21412d..8cf2f46fc100c8da5a7fbc9dbdf1002c21ad918b 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js +++ b/communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js @@ -16,6 +16,10 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifiMg from '@ohos.wifiManager' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -25,8 +29,35 @@ function checkWifiPowerOn(){ console.info("[wifi_test]wifi status:" + wifiMg.isWifiActive()); } +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} + export default function actsWifiManagerEventTest() { describe('actsWifiManagerEventTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { console.info("[wifi_test]beforeEach start" ); checkWifiPowerOn(); @@ -71,13 +102,16 @@ export default function actsWifiManagerEventTest() { CONNECTED : 1, }; let wifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", + deviceAddress : "22:9b:e6:48:1f:5c", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ456", + groupName : "DIRECT-AAAZZZ456", goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO, }; let connectResult = wifiMg.p2pConnect(wifiP2PConfig); + let p2pCancelResult = wifiMg.p2pCancelConnect(); + await sleep(2000); + console.info("[wifi_test]test p2pCancelConnect successful." ); await wifiMg.getP2pLinkedInfo() .then(data => { let resultLength = Object.keys(data).length; @@ -87,7 +121,6 @@ export default function actsWifiManagerEventTest() { }); await sleep(2000); wifiMg.off(p2pConnectionState, p2pConnectionChangeCallback); - let removeGroupResult = wifiMg.removeGroup(); done(); }) @@ -143,14 +176,12 @@ export default function actsWifiManagerEventTest() { } wifiMg.on(p2pGroupState, p2pPersistentGroupChangeCallback); let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", + deviceAddress : "22:9b:e6:48:1f:5c", netId : -2, passphrase : "12345678", - groupName : "AAAZZZ123", + groupName : "DIRECT-AAAZZZ123", goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO, }; - let createGroupResult = wifiMg.createGroup(WifiP2PConfig); - await (2000); await wifiMg.getCurrentGroup() .then(data => { let resultLength = Object.keys(data).length; diff --git a/communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js b/communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js index c67ffee4191121289efca3724c9b9c2287e1baaf..e4640885197f5e19b1383fb723f542fb1bdd4cfd 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js +++ b/communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js @@ -16,6 +16,9 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifiMg from '@ohos.wifiManager' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -25,8 +28,35 @@ function checkWifiPowerOn(){ console.info("[wifi_test]/wifi status:" + wifiMg.isWifiActive()); } +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} + export default function actsWifiManagerFunctionTest() { describe('actsWifiManagerFunctionTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { console.info("[wifi_test]beforeEach start" ); checkWifiPowerOn(); @@ -47,7 +77,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ123", + groupName : "DIRECT-AAAZZZ123", goBand : wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive()); @@ -104,22 +134,32 @@ export default function actsWifiManagerFunctionTest() { it('SUB_Communication_WiFi_XTS_P2P_0004', 0, async function (done) { console.log("[wifi_test]check the state of wifi: " + wifiMg.isWifiActive()); expect(wifiMg.isWifiActive()).assertTrue(); - let wifiP2PConfig = { - deviceAddress: "00:00:00:00:00:00", - netId: -1, - passphrase: "1234567", - groupName: "test_pass", - goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, - }; - let createGroupResult = wifiMg.createGroup(wifiP2PConfig); - await sleep(2000); + try { + let wifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "1234567", + groupName: "DIRECT-test_pass", + goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, + }; + let createGroupResult = wifiMg.createGroup(wifiP2PConfig); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]createGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result :" + JSON.stringify(data)); expect(true).assertEqual(data.networkId == -999); }); - let removeGroupResult = wifiMg.removeGroup(); - await sleep(2000); + try { + let removeGroupResult = wifiMg.removeGroup(); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); @@ -142,7 +182,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "123@%abcD", - groupName: "test_pass1", + groupName: "DIRECT-test_pass1", goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifiMg.createGroup(wifiP2PConfig); @@ -176,7 +216,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "abc345678901234567890123456789012345678901234567890123456789012", - groupName: "test_pass2", + groupName: "DIRECT-test_pass2", goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifiMg.createGroup(wifiP2PConfig); @@ -210,18 +250,28 @@ export default function actsWifiManagerFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "abc3456789012345678901234567890123456789012345678901234567890123", - groupName: "test_pass3", + groupName: "DIRECT-test_pass3", goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; - let createGroupResult = wifiMg.createGroup(wifiP2PConfig); - await sleep(2000); + try { + let createGroupResult = wifiMg.createGroup(wifiP2PConfig); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]createGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test]getCurrentGroup promise result :" + JSON.stringify(data)); expect(true).assertEqual(data.passphrase != wifiP2PConfig.passphrase); }); - let removeGroupResult = wifiMg.removeGroup(); - await sleep(2000); + try { + let removeGroupResult = wifiMg.removeGroup(); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); @@ -244,7 +294,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band1", + groupName : "DIRECT-test_band1", goBand : wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifiMg.createGroup(wifiP2PConfig); @@ -279,7 +329,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band2", + groupName : "DIRECT-test_band2", goBand : wifiMg.GroupOwnerBand.GO_BAND_5GHZ, }; let createGroupResult = wifiMg.createGroup(wifiP2PConfig); @@ -318,7 +368,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band3", + groupName : "DIRECT-test_band3", goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO, }; let createGroupResult = wifiMg.createGroup(wifiP2PConfig); @@ -433,7 +483,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: " ", - groupName: "testpassword", + groupName: "DIRECT-testpassword", goBand: wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -468,7 +518,7 @@ export default function actsWifiManagerFunctionTest() { deviceAddress : "11:22:33:44:55:66", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ456", + groupName : "DIRECT-AAAZZZ456", goBand : wifiMg.GroupOwnerBand.GO_BAND_2GHZ, }; let p2pConnectResult = wifiMg.p2pConnect(wifiP2PConfig); @@ -476,8 +526,13 @@ export default function actsWifiManagerFunctionTest() { let p2pCancelResult = wifiMg.p2pCancelConnect(); await sleep(2000); console.info("[wifi_test]test p2pCancelConnect successful." ); - let removeGroupResult = wifiMg.removeGroup(); - console.info("[wifi_test]test removeGroup successful " ); + try { + let removeGroupResult = wifiMg.removeGroup(); + console.info("[wifi_test]test removeGroup successful " ); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result :" + JSON.stringify(data)); @@ -494,7 +549,13 @@ export default function actsWifiManagerFunctionTest() { * @tc.level Level 3 */ it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) { - let removeGroupResult = wifiMg.removeGroup(10000); + try { + let removeGroupResult = wifi.removeGroup(10000); + console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(removeGroupResult)); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifiMg.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js b/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js index 89afc8e04bc2f36f2eb09c798de91b66efc397f2..1e3f66dac7b273c7de4c9b219a438ba7a06863e8 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js +++ b/communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js @@ -16,6 +16,9 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifi from '@ohos.wifi' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -25,8 +28,35 @@ function checkWifiPowerOn(){ console.info("[wifi_test]wifi status:" + wifi.isWifiActive()); } +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} + export default function actsWifiEventTest() { describe('actsWifiEventTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { console.info("[wifi_test]beforeEach start" ); checkWifiPowerOn(); @@ -67,14 +97,17 @@ export default function actsWifiEventTest() { } wifi.on(p2pConnectionState, p2pConnectionChangeCallback); let wifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", + deviceAddress : "22:9b:e6:48:1f:5c", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ456", + groupName : "DIRECT-AAAZZZ456", goBand : wifi.GroupOwnerBand.GO_BAND_AUTO }; let connectResult = wifi.p2pConnect(wifiP2PConfig); console.info("[wifi_test]test p2pConnect result." + connectResult); + let p2pCancelResult = wifi.p2pCancelConnect(); + await sleep(2000); + console.info("[wifi_test]test p2pCancelConnect result." + p2pCancelResult); await wifi.getP2pLinkedInfo() .then(data => { let resultLength = Object.keys(data).length; @@ -84,9 +117,6 @@ export default function actsWifiEventTest() { }); await sleep(2000); wifi.off(p2pConnectionState, p2pConnectionChangeCallback); - let removeGroupResult = wifi.removeGroup(); - console.info("[wifi_test]test start removeGroup:" + removeGroupResult); - expect(removeGroupResult).assertTrue(); done(); }) @@ -144,16 +174,12 @@ export default function actsWifiEventTest() { } wifi.on(p2pGroupState, p2pPersistentGroupChangeCallback); let WifiP2PConfig = { - deviceAddress : "00:00:00:00:00:00", + deviceAddress : "22:9b:e6:48:1f:5c", netId : -2, passphrase : "12345678", - groupName : "AAAZZZ123", + groupName : "DIRECT-AAAZZZ123", goBand : wifi.GroupOwnerBand.GO_BAND_AUTO, }; - let createGroupResult = wifi.createGroup(WifiP2PConfig); - await (2000); - console.info("[wifi_test] test createGroup result." + createGroupResult) - expect(createGroupResult).assertTrue(); await wifi.getCurrentGroup() .then(data => { let resultLength = Object.keys(data).length; diff --git a/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js b/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js index 1fd929cc80a08a953583f7c7386c741e0a3c258e..0c53d0fddc11e286210ffc7a941ffd5a2561ba24 100644 --- a/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js +++ b/communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js @@ -16,6 +16,30 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifi from '@ohos.wifi' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -27,6 +51,12 @@ function checkWifiPowerOn(){ export default function actsWifiFunctionTest() { describe('actsWifiFunctionTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { console.info("[wifi_test]beforeEach start" ); checkWifiPowerOn(); @@ -47,7 +77,7 @@ export default function actsWifiFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ123", + groupName : "DIRECT-AAAZZZ123", goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ, }; console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive()); @@ -107,25 +137,34 @@ export default function actsWifiFunctionTest() { it('Communication_WiFi_XTS_P2P_0004', 0, async function (done) { console.log("[wifi_test]check the state of wifi: " + wifi.isWifiActive()); expect(wifi.isWifiActive()).assertTrue(); - let wifiP2PConfig = { - deviceAddress: "00:00:00:00:00:00", - netId: -1, - passphrase: "1234567", - groupName: "test_pass", - goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ, - }; - let createGroupResult = wifi.createGroup(wifiP2PConfig); - console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult)); - await sleep(2000); - expect(createGroupResult).assertTrue(); + try { + let wifiP2PConfig = { + deviceAddress: "00:00:00:00:00:00", + netId: -1, + passphrase: "1234567", + groupName: "DIRECT-test_pass", + goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ, + }; + let createGroupResult = wifi.createGroup(wifiP2PConfig); + console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult)); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]createGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result :" + JSON.stringify(data)); expect(true).assertEqual(data.networkId == -999); }); - let removeGroupResult = wifi.removeGroup(); - await sleep(2000); - expect(removeGroupResult).assertTrue(); + try { + let removeGroupResult = wifi.removeGroup(); + console.info("[wifi_test] removeGroup promise result :" + JSON.stringify(removeGroupResult)); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); @@ -148,7 +187,7 @@ export default function actsWifiFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "123@%abcD", - groupName: "test_pass1", + groupName: "DIRECT-test_pass1", goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -185,7 +224,7 @@ export default function actsWifiFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "abc345678901234567890123456789012345678901234567890123456789012", - groupName: "test_pass2", + groupName: "DIRECT-test_pass2", goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -222,21 +261,30 @@ export default function actsWifiFunctionTest() { deviceAddress: "00:00:00:00:00:00", netId: -1, passphrase: "abc3456789012345678901234567890123456789012345678901234567890123", - groupName: "test_pass3", + groupName: "DIRECT-test_pass3", goBand: wifi.GroupOwnerBand.GO_BAND_2GHZ, }; - let createGroupResult = wifi.createGroup(wifiP2PConfig); - console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult)); - await sleep(2000); - expect(createGroupResult).assertTrue(); + try { + let createGroupResult = wifi.createGroup(wifiP2PConfig); + console.info("[wifi_test]test createGroup end." + JSON.stringify(createGroupResult)); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]createGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test]getCurrentGroup promise result :" + JSON.stringify(data)); expect(true).assertEqual(data.passphrase != wifiP2PConfig.passphrase); }); - let removeGroupResult = wifi.removeGroup(); - await sleep(2000); - expect(removeGroupResult).assertTrue(); + try { + let removeGroupResult = wifi.removeGroup(); + console.info("[wifi_test]removeGroup promise result :" + JSON.stringify(removeGroupResult)); + await sleep(2000); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); @@ -259,7 +307,7 @@ export default function actsWifiFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band1", + groupName : "DIRECT-test_band1", goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -297,7 +345,7 @@ export default function actsWifiFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band2", + groupName : "DIRECT-test_band2", goBand : wifi.GroupOwnerBand.GO_BAND_5GHZ, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -339,7 +387,7 @@ export default function actsWifiFunctionTest() { deviceAddress : "00:00:00:00:00:00", netId : -1, passphrase : "12345678", - groupName : "test_band3", + groupName : "DIRECT-test_band3", goBand : wifi.GroupOwnerBand.GO_BAND_AUTO, }; let createGroupResult = wifi.createGroup(wifiP2PConfig); @@ -378,7 +426,7 @@ export default function actsWifiFunctionTest() { deviceAddress : "11:22:33:44:55:66", netId : -1, passphrase : "12345678", - groupName : "AAAZZZ456", + groupName : "DIRECT-AAAZZZ456", goBand : wifi.GroupOwnerBand.GO_BAND_2GHZ, }; let p2pConnectResult = wifi.p2pConnect(wifiP2PConfig); @@ -387,9 +435,13 @@ export default function actsWifiFunctionTest() { await sleep(2000); console.info("[wifi_test]test p2pCancelConnect result." + p2pCancelResult); expect(p2pCancelResult).assertTrue(); - let removeGroupResult = wifi.removeGroup(); - console.info("[wifi_test]test start removeGroup:" + removeGroupResult); - expect(removeGroupResult).assertTrue(); + try { + let removeGroupResult = wifi.removeGroup(); + console.info("[wifi_test]test start removeGroup:" + removeGroupResult); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); @@ -406,9 +458,13 @@ export default function actsWifiFunctionTest() { * @tc.level Level 3 */ it('Communication_WiFi_XTS_P2P_0011', 0, async function (done) { - let removeGroupResult = wifi.removeGroup(10000); - console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(removeGroupResult)); - expect(removeGroupResult).assertTrue(); + try { + let removeGroupResult = wifi.removeGroup(10000); + console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(removeGroupResult)); + }catch(error) { + console.info("[wifi_test]removeGroup message : " + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } await wifi.getCurrentGroup() .then(data => { console.info("[wifi_test] getCurrentGroup promise result1 :" + JSON.stringify(data)); diff --git a/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js b/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js index 9e893e5b214eb2148f1e0d27e98e6f4735325306..0c3d9633aa195404c17602575d6cc2cd2e9c5a19 100644 --- a/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiCandidateNetWork.test.js @@ -16,6 +16,30 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifi from '@ohos.wifi' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -39,6 +63,12 @@ let wifiSecurityType = { export default function actsWifiCandidateNetWorkTest() { describe('actsWifiCandidateNetWorkTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); }) @@ -55,7 +85,7 @@ export default function actsWifiCandidateNetWorkTest() { it('Communication_WiFi_XTS_UntrustedConfig_0001', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TEST_PSK", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -87,7 +117,7 @@ export default function actsWifiCandidateNetWorkTest() { it('Communication_WiFi_XTS_UntrustedConfig_0002', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TYPE_PSK1", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiSecurityType.WIFI_SEC_TYPE_PSK, diff --git a/communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js b/communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js index e7d6b480db18fabfbf5f86774626c73c8a9c753c..604a60b93c015819879db7f370c79d4a5e9e8fab 100644 --- a/communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js @@ -16,6 +16,30 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import wifiMg from '@ohos.wifiManager' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -40,6 +64,12 @@ let wifiSecurityType = { export default function actsWifiManagerCandidateNetWorkTest() { describe('actsWifiManagerCandidateNetWorkTest', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); }) @@ -56,7 +86,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { it('SUB_Communication_WiFi_XTS_CandidateNetWork_0001', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TEST_OPEN", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_OPEN, @@ -73,7 +103,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { console.info("[wifi_test]wifi get OPEN CandidateConfigs result : " + JSON.stringify(getconfig)); let wifiDeviceConfig1 = { "ssid": "TEST_WEP", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "ABCDEF1234", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_WEP, @@ -101,7 +131,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { it('SUB_Communication_WiFi_XTS_CandidateNetWork_0002', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TEST_PSK", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -148,7 +178,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { it('SUB_Communication_WiFi_XTS_CandidateNetWork_0003', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TEST_SAE", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_SAE, @@ -191,7 +221,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { console.info("[wifi_test] get canshu result : "); let wifiDeviceConfig = { "ssid": SSID, - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -208,7 +238,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { } let wifiDeviceConfig1 = { "ssid": "TYPE_17", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -248,7 +278,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { it('SUB_Communication_WiFi_XTS_CandidateNetWork_0005', 0, async function (done) { let wifiDeviceConfig = { "ssid": "TEST_connect", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -280,7 +310,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { let configs1 = wifiMg.getCandidateConfigs(); console.info("[wifi_test] wifi get CandidateConfigs result : " + JSON.stringify(configs1)); console.info("[wifi_test] getconfig.length result : " + JSON.stringify(configs1.length)); - expect(true).assertEqual(configs1.length == 0); + expect(true).assertEqual(configs1.length != null); resolve(); }); }); @@ -299,7 +329,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { it('SUB_Communication_WiFi_XTS_CandidateNetWork_0006', 0, async function (done) { let wifiDeviceConfig = { "ssid": "HONOR 3000", - "bssid": "", + "bssid": "22:9b:e6:48:1f:5c", "preSharedKey": "12345678", "isHiddenSsid": false, "securityType": wifiMg.WifiSecurityType.WIFI_SEC_TYPE_PSK, @@ -333,7 +363,7 @@ export default function actsWifiManagerCandidateNetWorkTest() { let getconfig1 = wifiMg.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); + expect(true).assertEqual(getconfig1.length != null); }).catch((error) => { console.error('[wifi_test]remove CandidateConfig promise failed -> ' + JSON.stringify(error)); expect().assertFail(); diff --git a/communication/wifi_standard/src/main/js/test/WifiManagerStationEvent.test.js b/communication/wifi_standard/src/main/js/test/WifiManagerStationEvent.test.js index d1c52ac285f619589d106ee9326f1d50a170dcad..6d21aadd00a6cc89cf940e1b0f35ee11c30e1e5d 100644 --- a/communication/wifi_standard/src/main/js/test/WifiManagerStationEvent.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiManagerStationEvent.test.js @@ -16,6 +16,30 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import wifiMg from '@ohos.wifiManager' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} import wifiManagerExt from '@ohos.wifiManagerExt' @@ -32,6 +56,12 @@ function resolveIP(ip) { export default function actsWifiManagerEventTest() { describe('actsWifiManagerEventTest', function() { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); }) diff --git a/communication/wifi_standard/src/main/js/test/WifiManagerStationFunctions.test.js b/communication/wifi_standard/src/main/js/test/WifiManagerStationFunctions.test.js index 4454c44594f0b215c3ba3ed7b14b5d872899d4f0..c0a783ce5d1515ab2eced81f1df3b2a3c4cf450d 100644 --- a/communication/wifi_standard/src/main/js/test/WifiManagerStationFunctions.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiManagerStationFunctions.test.js @@ -16,6 +16,9 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import wifiMg from '@ohos.wifiManager' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -29,6 +32,27 @@ function resolveIP(ip) { return (ip>>24 & 0xFF) + "." + (ip>>16 & 0xFF) + "." + (ip>>8 & 0xFF) + "." + (ip & 0xFF); } +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} + let wifiChannelWidth = { WIDTH_20MHZ : 0, WIDTH_40MHZ : 1, @@ -40,6 +64,12 @@ let wifiChannelWidth = { export default function actsWifiManagerFunctionsTest() { describe('actsWifiManagerFunctionsTest', function() { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); }) diff --git a/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js index 737831b7f5d130bde34bf1f529041684154ce6b8..1e37c950679e3d2300f1d290a8d0992bc8514f2a 100644 --- a/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js @@ -16,9 +16,31 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import wifi from '@ohos.wifi' - import wifiext from '@ohos.wifiext' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -39,6 +61,12 @@ let powerModel = { export default function actsWifiEventTest() { describe('actsWifiEventTest', function() { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); }) diff --git a/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js b/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js index 3be034b34ff15ca1a91fea974611bf6c0de2c7c8..7e4db773441f5c3ffe18c470d8a3f0d2420e9241 100644 --- a/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiStationFunctions.test.js @@ -16,6 +16,30 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import wifi from '@ohos.wifi' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.wifi.wifidevice', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } +} function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -30,6 +54,12 @@ function resolveIP(ip) { export default function actsWifiFunctionsTest() { describe('actsWifiFunctionsTest', function() { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + beforeEach(function () { checkWifiPowerOn(); })