diff --git a/communication/BUILD.gn b/communication/BUILD.gn
index 08aed112359ceafb33ebf26a836965a22be30eec..7e7ac0c773f2ad5994d3184d1a14272edafd26fc 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..5093ede64819284677eead808e09ba53e3c292d8
--- /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));
+ except(true).assertTrue(data.length>0);
+ }
+ bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent)
+ bluetooth.BLE.startBLEScan(null);
+ await sleep(1000);
+ bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
+ bluetooth.BLE.stopBLEScan();
+ done();
+ } 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));
+ except(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));
+ except(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));
+ except(true).assertTrue(data.length>0);
+ }
+ bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
+ bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]);
+ await sleep(1000);
+ console.info('[bluetooth_js] BLE scan off4');
+ bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
+ 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));
+ except(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));
+ except(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));
+ except(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));
+ except(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));
+ except(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));
+ except(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));
+ except(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));
+ except(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));
+ except(true).assertTrue(data.length>0);
+ }
+ bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
+ bluetooth.BLE.startBLEScan(
+ [{
+ deviceId:"11:22:33:44:55:66",
+ name:"test",
+ serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
+ }],
+ {
+ interval: 500,
+ dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
+ matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
+ }
+ );
+ await sleep(1000);
+ console.info('[bluetooth_js] BLE scan off13');
+ bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
+ bluetooth.BLE.stopBLEScan();
+ done();
+ } 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);
+ except(true).assertTrue(ScanResult.length>0);
+ await sleep(1000);
+ let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId);
+ let ret = gattClient.connect();
+ await sleep(2000);
+ console.info('[bluetooth_js] gattClient connect' + ret)
+ expect(ret).assertTrue();
+ let disconnect = gattClient.disconnect();
+ console.info('[bluetooth_js] gatt disconnect:' + disconnect);
+ expect(disconnect).assertEqual(false);
+ }
+ await bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent);
+ bluetooth.BLE.startBLEScan(
+ [{}],
+ {
+ interval: 500,
+ dutyMode: 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..36950999acb1dd0cbf4a9653bd6593cb416a5eef
--- /dev/null
+++ b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js
@@ -0,0 +1,1128 @@
+/*
+ * 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_1300
+ * @tc.name testSppListen
+ * @tc.desc Test 2900003 - Bluetooth switch is off
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('COMMUNICATION_BLUETOOTH_SwitchOff_1300', 0, async function (done) {
+ try {
+ let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
+ secure: true, type: bluetooth.SppType.SPP_RFCOMM};
+ let serverNumber = -1;
+ function serverSocket(code, number) {
+ if (code) {
+ console.log('bluetooth error code01: ' + code);
+ }else{
+ console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
+ serverNumber = number;
+ expect(true).assertEqual(number!=null);
+ }
+ }
+ bluetooth.sppListen('server1', SppOption, serverSocket);
+ expect(true).assertFalse();
+ done()
+ } catch (error) {
+ console.error('[bluetooth_js]sppListen error.code:'
+ +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
+ expect(error.code).assertEqual('2900003');
+ done()
+ }
+ })
+
+ /**
+ * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1400
+ * @tc.name testSppAccept
+ * @tc.desc Test 2900003 - Bluetooth switch is off.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('COMMUNICATION_BLUETOOTH_SwitchOff_1400', 0, async function (done) {
+ try {
+ function acceptClientSocket(code, number) {
+
+ if (code) {
+ console.log('[bluetooth_js] error code05: ' + JSON.stringify(code));
+ }else{
+ console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number));
+ expect(true).assertEqual(number!=null);
+ }
+ }
+ bluetooth.sppAccept(0, acceptClientSocket);
+ expect(true).assertFalse();
+ done()
+ } catch (error) {
+ console.error('[bluetooth_js]sppAccept error.code:'
+ +JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
+ expect(error.code).assertEqual('2900003');
+ done()
+ }
+ })
+
+ /**
+ * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1500
+ * @tc.name testSppConnect
+ * @tc.desc Test 2900003 - Bluetooth switch is off.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('COMMUNICATION_BLUETOOTH_SwitchOff_1500', 0, async function (done) {
+ try {
+ let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
+ secure: true, type: 0};
+ bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, number) {
+ if (code) {
+ console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
+ } else {
+ console.log('[bluetooth_js]sppConnect Number:'
+ + JSON.stringify(number));
+ }
+ });
+ expect(true).assertFalse();
+ done()
+ } catch (error) {
+ console.error('[bluetooth_js]sppConnect 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_2700
+ * @tc.name test getConnectedBLEDevices
+ * @tc.desc Test 2900003 - Bluetooth switch is off.
+ * @tc.size MEDIUM
+ * @ since 7
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('COMMUNICATION_BLUETOOTH_SwitchOff_2700', 0, function () {
+ try {
+ let result = bluetooth.BLE.getConnectedBLEDevices();
+ console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result)
+ + "length:" +result.length);
+ expect(true).assertFalse();
+ } catch (error) {
+ console.error(`[bluetooth_js]getConnDev failed, code is ${error.code},
+ message is ${error.message}`);
+ expect(error.code).assertEqual('2900003');
+ }
+ })
+
+ /**
+ * @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_3500
+ * @tc.name testNotifyCharacteristicChanged
+ * @tc.desc Test 2900003 - Bluetooth switch is off.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('COMMUNICATION_BLUETOOTH_SwitchOff_3500', 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('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/location/BUILD.gn b/location/BUILD.gn
index ac5383466bf5dba009e392f9005f36463924537d..75d63399a33ef4c3b07863b752fd73e05e551572 100644
--- a/location/BUILD.gn
+++ b/location/BUILD.gn
@@ -15,8 +15,14 @@ import("//build/ohos_var.gni")
group("location") {
testonly = true
if (is_standard_system) {
- deps = [ "geolocation_standard:ActslocationJsTest" ]
+ deps = [
+ "geolocation_errorCode:ActslocationErrorCodeTest",
+ "geolocation_standard:ActslocationJsTest",
+ ]
} else {
- deps = [ "geolocation_standard:ActslocationJsTest" ]
+ deps = [
+ "geolocation_errorCode:ActslocationErrorCodeTest",
+ "geolocation_standard:ActslocationJsTest",
+ ]
}
}
diff --git a/location/geolocation_errorCode/BUILD.gn b/location/geolocation_errorCode/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8bb99a591a1f0ce382a4346127cf4492b2efd1bc
--- /dev/null
+++ b/location/geolocation_errorCode/BUILD.gn
@@ -0,0 +1,37 @@
+# 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("ActslocationErrorCodeTest") {
+ hap_profile = "./src/main/config.json"
+ deps = [
+ ":geolocation_js_assets",
+ ":geolocation_resources",
+ ]
+
+ # shared_libraries = [
+ # "//third_party/giflib:libgif",
+ # "//third_party/libpng:libpng",
+ # ]
+ certificate_profile = "./signature/openharmony_sx.p7b"
+ hap_name = "ActslocationErrorCodeApiTest"
+ part_name = "location"
+ subsystem_name = "location"
+}
+ohos_js_assets("geolocation_js_assets") {
+ source_dir = "./src/main/js/default"
+}
+ohos_resources("geolocation_resources") {
+ sources = [ "./src/main/resources" ]
+ hap_profile = "./src/main/config.json"
+}
diff --git a/location/geolocation_errorCode/Test.json b/location/geolocation_errorCode/Test.json
new file mode 100644
index 0000000000000000000000000000000000000000..1fda4b1775a9d736ea4d6b7cf160e6fe212cb3e5
--- /dev/null
+++ b/location/geolocation_errorCode/Test.json
@@ -0,0 +1,24 @@
+{
+ "description": "Configuration for geolocation js api Tests",
+ "driver": {
+ "type": "JSUnitTest",
+ "test-timeout": "600000",
+ "package": "ohos.acts.location.geolocation.function",
+ "shell-timeout": "60000"
+ },
+ "kits": [
+ {
+ "test-file-name": [
+ "ActslocationErrorCodeApiTest.hap"
+ ],
+ "type": "AppInstallKit",
+ "cleanup-apps": true
+ },
+ {
+ "type": "ShellKit",
+ "run-command": [
+ "hilog -Q pidoff"
+ ]
+ }
+ ]
+}
diff --git a/location/geolocation_errorCode/signature/openharmony_sx.p7b b/location/geolocation_errorCode/signature/openharmony_sx.p7b
new file mode 100644
index 0000000000000000000000000000000000000000..94290b95b64486edfe5af7b09059da881672d1a1
Binary files /dev/null and b/location/geolocation_errorCode/signature/openharmony_sx.p7b differ
diff --git a/location/geolocation_errorCode/src/main/config.json b/location/geolocation_errorCode/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..969cc6f318a10bb1d866fcae76a2cbc6a4757868
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/config.json
@@ -0,0 +1,131 @@
+{
+ "app": {
+ "bundleName": "ohos.acts.location.geolocation.function",
+ "vendor": "acts",
+ "version": {
+ "code": 1000000,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 4,
+ "target": 5,
+ "releaseType": "Beta1"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "ohos.acts.location.geolocation.function",
+ "name": ".MyApplication",
+ "mainAbility": "ohos.acts.location.geolocation.function.MainAbility",
+ "deviceType": [
+ "tablet",
+ "default",
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "visible": true,
+ "name": "ohos.acts.location.geolocation.function.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:app_name",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.LOCATION",
+ "reason": "need use ohos.permission.LOCATION",
+ "usedScene": {
+ "ability": [
+ "ohos.acts.location.geolocation.function.MainAbility"
+ ],
+ "when": "inuse"
+ }
+ },
+ {
+ "name":"ohos.permission.ACCESS_LOCATION",
+ "reason":"need use ohos.permission.ACCESS_LOCATION",
+ "usedScene": {
+ "ability": [
+ "ohos.acts.location.geolocation.function.MainAbility"
+ ],
+ "when": "inuse"
+ }
+ },
+ {
+ "name":"ohos.permission.APPROXIMATELY_LOCATION",
+ "reason":"need use ohos.permission.APPROXIMATELY_LOCATION",
+ "usedScene": {
+ "ability": [
+ "ohos.acts.location.geolocation.function.MainAbility"
+ ],
+ "when": "inuse"
+ }
+ },
+ {
+ "name":"ohos.permission.LOCATION_IN_BACKGROUND",
+ "reason":"need use ohos.permission.LOCATION_IN_BACKGROUND",
+ "usedScene": {
+ "ability": [
+ "ohos.acts.location.geolocation.function.MainAbility"
+ ],
+ "when": "inuse"
+ }
+ },
+ {
+ "name":"ohos.permission.MANAGE_SECURE_SETTINGS",
+ "reason":"need use ohos.permission.MANAGE_SECURE_SETTINGS",
+ "usedScene": {
+ "ability": [
+ "ohos.acts.location.geolocation.function.MainAbility"
+ ],
+ "when": "inuse"
+ }
+ },
+ {
+ "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
+ "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
+ },
+ {
+ "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
+ "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
+ },
+ {
+ "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
+ },
+ {
+ "name": "ohos.permission.GET_BUNDLE_INFO"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
+ }
+ ]
+ }
+}
+
diff --git a/location/geolocation_errorCode/src/main/js/default/app.js b/location/geolocation_errorCode/src/main/js/default/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..84f1448f02152e5e1772661d85159776611f8d54
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/app.js
@@ -0,0 +1,36 @@
+/*
+ * 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 {Core, ExpectExtend} from 'deccjsunit/index'
+
+export default {
+ onCreate() {
+ console.info('AceApplication onCreate');
+ const core = Core.getInstance()
+ const expectExtend = new ExpectExtend({
+ 'id': 'extend'
+ })
+ core.addService('expect', expectExtend)
+ core.init()
+
+ const configService = core.getDefaultService('config')
+ configService.setConfig({'timeout': 12000})
+
+ require('./test/List.test')
+ core.execute()
+ },
+ onDestroy() {
+ console.info('AceApplication onDestroy');
+ }
+};
diff --git a/location/geolocation_errorCode/src/main/js/default/i18n/en-US.json b/location/geolocation_errorCode/src/main/js/default/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/i18n/en-US.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "Hello",
+ "world": "World"
+ }
+}
\ No newline at end of file
diff --git a/location/geolocation_errorCode/src/main/js/default/i18n/zh-CN.json b/location/geolocation_errorCode/src/main/js/default/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/i18n/zh-CN.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "您好",
+ "world": "世界"
+ }
+}
\ No newline at end of file
diff --git a/location/geolocation_errorCode/src/main/js/default/pages/index/index.css b/location/geolocation_errorCode/src/main/js/default/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/pages/index/index.css
@@ -0,0 +1,9 @@
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.title {
+ font-size: 100px;
+}
diff --git a/location/geolocation_errorCode/src/main/js/default/pages/index/index.hml b/location/geolocation_errorCode/src/main/js/default/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/pages/index/index.hml
@@ -0,0 +1,5 @@
+
+
+ {{ $t('strings.hello') }} {{ title }}
+
+
diff --git a/location/geolocation_errorCode/src/main/js/default/pages/index/index.js b/location/geolocation_errorCode/src/main/js/default/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..3a5f99e66eb0a1ba6f72bb0057da5d9b8b5db5df
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/pages/index/index.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 app from '@system.app'
+
+
+export default {
+ data: {
+ title: ""
+ },
+ onInit() {
+ this.title = this.$t('strings.world');
+ },
+ onShow() {
+ console.info('onShow finish')
+ },
+ onReady() {
+ },
+}
\ No newline at end of file
diff --git a/location/geolocation_errorCode/src/main/js/default/test/GeocoderErrorTest.test.js b/location/geolocation_errorCode/src/main/js/default/test/GeocoderErrorTest.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..7e38ab815af17248938218b8b8c81a5de4a512e8
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/test/GeocoderErrorTest.test.js
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import geolocation from '@ohos.geolocation';
+import geolocationm from '@ohos.geoLocationManager';
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
+import bundle from '@ohos.bundle'
+import osaccount from '@ohos.account.osAccount'
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+async function changedLocationMode(){
+ let result1 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result1));
+ if(!result1){
+ await geolocation.requestEnableLocation().then((result) => {
+ console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
+ }).catch((error) => {
+ console.info("[lbs_js] promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ }
+ let result2 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result2));
+}
+
+
+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.location.geolocation.function', 0, localId);
+ let atManager = abilityAccessCtrl.createAtManager();
+ if (atManager != null) {
+ let tokenID = appInfo.accessTokenId;
+ console.info('[permission] case accessTokenID is ' + tokenID);
+ let permissionName1 = 'ohos.permission.LOCATION';
+ let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
+ await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
+ });
+ await atManager.grantUserGrantedPermission(tokenID, permissionName2, 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');
+ }
+}
+
+describe('geolocationTest_GeoErr', function () {
+
+ console.log('#start AccessTokenTests#');
+ beforeAll(async function (done) {
+ console.info('beforeAll case');
+ await applyPermission();
+ await changedLocationMode();
+ done();
+ })
+
+ beforeEach(async function (done) {
+ console.info('beforeEach case');
+ done();
+ })
+
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoErr_0400
+ * @tc.name testGetAddressesFromLocation
+ * @tc.desc Incorrect input parameters are used to invoke the reverse geocoding service.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_GeoErr_0400', 0, async function (done) {
+ try {
+ let reverseGeocodeRequest = "1";
+ geolocationm.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
+ if (err) {
+ console.info('[lbs_js] getAddressesFromLocation4 callback err is:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ } else {
+ console.info("[lbs_js] getAddressesFromLocation4 callback data is:" + JSON.stringify(data));
+ expect(true).assertFalse();
+ }
+ });
+ } catch (error) {
+ console.info("[lbs_js] getAddressesFromLocation4 callback try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoErr_0500
+ * @tc.name testGetAddressesFromLocation
+ * @tc.desc Incorrect input parameters are used to invoke the reverse geocoding service.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_GeoErr_0500', 0, async function (done) {
+ (async () => {
+ try {
+ let reverseGeocodeRequest = "1";
+ let result = await geolocationm.getAddressesFromLocation(reverseGeocodeRequest);
+ console.info("[lbs_js] getAddressesFromLocation5 promise successful:" + JSON.stringify(result));
+ } catch(error) {
+ console.info('[lbs_js] getAddressesFromLocation5 promise err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })();
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoErr_0600
+ * @tc.name testGetAddressesFromLocationName
+ * @tc.desc Invoke the geocoding service with incorrect input parameters.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_GeoErr_0600', 0, async function (done) {
+ try {
+ let geocodeRequest = 1;
+ geolocationm.getAddressesFromLocationName(geocodeRequest, (err, data) => {
+ if (err) {
+ console.info('[lbs_js] getAddressesFromLocationName6 callback err is:' + JSON.stringify(err));
+ expect(err.code).assertEqual(401);
+ return;
+ } else {
+ console.info("[lbs_js] getAddressesFromLocationName6 callback data is: " + JSON.stringify(data));
+ expect(true).assertFalse();
+ }
+ });
+ }catch(error){
+ console.info("[lbs_js] getAddressesFromLocationName6 try err." + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoErr_0700
+ * @tc.name testGetAddressesFromLocationName
+ * @tc.desc Invoke the geocoding service with incorrect input parameters.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_GeoErr_0700', 0, async function (done) {
+ (async () => {
+ try {
+ let geocodeRequest = 1;
+ let result = await geolocationm.getAddressesFromLocationName(geocodeRequest);
+ console.info("[lbs_js] getAddressesFromLocationName7 promise successful:" + JSON.stringify(result));
+ } catch(error) {
+ console.info('[lbs_js] getAddressesFromLocationName7 promise err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })();
+ await sleep(1000);
+ done();
+ })
+
+
+})
diff --git a/location/geolocation_errorCode/src/main/js/default/test/GetCountryCodeError.test.js b/location/geolocation_errorCode/src/main/js/default/test/GetCountryCodeError.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..90dbbd669837efb7a8b032d6ffa805a54efbcf88
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/test/GetCountryCodeError.test.js
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import geolocation from '@ohos.geolocation';
+import geolocationm from '@ohos.geoLocationManager';
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
+import bundle from '@ohos.bundle'
+import osaccount from '@ohos.account.osAccount'
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+ console.info('[lbs_js]sleep function');
+}
+
+async function changedLocationMode(){
+ let result1 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result1));
+ if(!result1){
+ await geolocation.requestEnableLocation().then(async(result) => {
+ await sleep(3000);
+ console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
+ }).catch((error) => {
+ console.info("[lbs_js] promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ }
+ let result2 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result2));
+}
+
+async function applyPermission() {
+ let osAccountManager = osaccount.getAccountManager();
+ console.info("====>testgetuserid get AccountManager finish====");
+ let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
+ console.info("====>testgetuserid localId obtained by process:" + localId);
+ let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
+ let atManager = abilityAccessCtrl.createAtManager();
+ if (atManager != null) {
+ let tokenID = appInfo.accessTokenId;
+ console.info('[permission] case accessTokenID is ' + tokenID);
+ let permissionName1 = 'ohos.permission.LOCATION';
+ let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
+ await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + result);
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + err);
+ });
+ await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + result);
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + err);
+ });
+ } else {
+ console.info('[permission] case apply permission failed, createAtManager failed');
+ }
+}
+
+describe('geolocationTest_counterr', function () {
+ beforeAll(async function (done) {
+ console.info('beforeAll case');
+ await applyPermission();
+ await changedLocationMode();
+ done();
+ })
+
+ beforeEach(async function (done) {
+ console.info('beforeEach case');
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_CountryCodeErr_0100
+ * @tc.name Test getCountryCode
+ * @tc.desc Incorrect input parameter to obtain the country code information.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_CountryCodeErr_0100', 0, async function (done) {
+ try {
+ geolocationm.getCountryCode("test",(err,data) => {
+ if (err) {
+ console.info('[lbs_js] getCountryCode callback err:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info("[lbs_js] getCountryCode callback success"+ JSON.stringify(data));
+ expect(true).assertFalse();
+ })
+ } catch (error) {
+ console.info('[lbs_js] getCountryCode callback try err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+})
diff --git a/location/geolocation_errorCode/src/main/js/default/test/List.test.js b/location/geolocation_errorCode/src/main/js/default/test/List.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..5dcc745a464875ce46cb28968d53eba1e15ddf26
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/test/List.test.js
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+
+require('./GeocoderErrorTest.test.js')
+require('./LocationErrorTest.test.js')
+require('./GetCountryCodeError.test.js')
+require('./ListeningError.test.js')
\ No newline at end of file
diff --git a/location/geolocation_errorCode/src/main/js/default/test/ListeningError.test.js b/location/geolocation_errorCode/src/main/js/default/test/ListeningError.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..9d48ab74f1f8c119431b3ab7e46b5da738c31e40
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/test/ListeningError.test.js
@@ -0,0 +1,465 @@
+/*
+ * Copyright (C) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import geolocation from '@ohos.geolocation';
+import geolocationm from '@ohos.geoLocationManager';
+import wantAgent from '@ohos.wantAgent';
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
+import bundle from '@ohos.bundle'
+import osaccount from '@ohos.account.osAccount'
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+async function changedLocationMode(){
+ let result1 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result1));
+ if(!result1){
+ await geolocation.requestEnableLocation().then(async(result) => {
+ await sleep(3000);
+ console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
+ }).catch((error) => {
+ console.info("[lbs_js] promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ }
+ let result2 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result2));
+}
+
+async function applyPermission() {
+ let osAccountManager = osaccount.getAccountManager();
+ console.info("====>testgetuserid get AccountManager finish====");
+ let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
+ console.info("====>testgetuserid localId obtained by process:" + localId);
+ let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
+ let atManager = abilityAccessCtrl.createAtManager();
+ if (atManager != null) {
+ let tokenID = appInfo.accessTokenId;
+ console.info('[permission] case accessTokenID is ' + tokenID);
+ let permissionName1 = 'ohos.permission.LOCATION';
+ let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
+ await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + result);
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + err);
+ });
+ await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + result);
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + err);
+ });
+ } else {
+ console.info('[permission] case apply permission failed, createAtManager failed');
+ }
+}
+
+
+describe('geolocationTest_6', function () {
+ beforeAll(async function (done) {
+ console.info('beforeAll case');
+ await applyPermission();
+ await changedLocationMode();
+ done();
+ })
+
+ beforeEach(async function (done) {
+ console.info('beforeEach case');
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_CountryCodeErr_0200
+ * @tc.name getCountryCode_on_off
+ * @tc.desc The interception country code is changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_CountryCodeErr_0200', 0, function () {
+ try {
+ console.info("[lbs_js] SUB_HSS_LocationSystem_CountryCodeErr_0200");
+ geolocationm.on('countryCodeChange', 1);
+ } catch (error) {
+ console.info("[lbs_js] countryCodeOn2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_CountryCodeErr_0300
+ * @tc.name getCountryCode_on_off
+ * @tc.desc The interception country code is changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_CountryCodeErr_0300', 0, function () {
+ try {
+ console.info("[lbs_js] SUB_HSS_LocationSystem_CountryCodeErr_0300");
+ geolocationm.off('countryCodeChange',1);
+ } catch (error) {
+ console.info("[lbs_js] countryCodeOff3 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })
+
+
+ it('SUB_HSS_LocationSystem_CountryCodeErr_0201', 0, async function (done) {
+ var callback = (code) => {
+ console.log('countryCodeChange: ' + JSON.stringify(code));
+ }
+ try {
+ console.info("[lbs_js] SUB_HSS_LocationSystem_CountryCodeErr_0200");
+ geolocationm.on('countryCodeChange', 1,callback);
+ console.info('[lbs_js] countryCodeOn2' +JSON.stringify(callback));
+ } catch (error) {
+ console.info("[lbs_js] countryCodeOn2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ it('SUB_HSS_LocationSystem_CountryCodeErr_0301', 0, async function (done) {
+ var callback = (code) => {
+ console.log('countryCodeChange: ' + JSON.stringify(code));
+ }
+ try {
+ console.info("[lbs_js] SUB_HSS_LocationSystem_CountryCodeErr_0300");
+ geolocationm.off('countryCodeChange',1,"test", callback);
+ console.info('[lbs_js] countryCodeOff3' +JSON.stringify(callback));
+ } catch (error) {
+ console.info("[lbs_js] countryCodeOff3 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+
+ it('SUB_HSS_LocationSystem_BatchingErr_0801', 0, function () {
+ try {
+ geolocationm.on('cachedGnssLocationsChange',1);
+ } catch (error) {
+ console.info("[lbs_js] cacheOn8 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })
+
+ it('SUB_HSS_LocationSystem_BatchingErr_0901', 0, function () {
+ try {
+ geolocationm.off('cachedGnssLocationsChange',1);
+ } catch (error) {
+ console.info("[lbs_js] cacheOff9 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })
+
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_BatchingErr_0800
+ * @tc.name cachedGnssLocationsChange_on_off
+ * @tc.desc Subscribe to cache GNSS locations update messages.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_BatchingErr_0800', 0, async function (done) {
+ var cachedLocationsCb = (locations) => {
+ console.log('[lbs_js] cachedGnssLocationsReporting8:locations:' + JSON.stringify(locations));
+ expect(true).assertEqual(locations !=null);
+ }
+ var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true};
+ try {
+ geolocationm.on(1,'cachedGnssLocationsChange', CachedGnssLoactionsRequest,cachedLocationsCb);
+ console.info('[lbs_js] cacheOn8' +JSON.stringify(cachedLocationsCb));
+ } catch (error) {
+ console.info("[lbs_js] cacheOn8 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_BatchingErr_0900
+ * @tc.name cachedGnssLocationsChange_on_off
+ * @tc.desc Unsubscribe to cache GNSS locations update messages.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_BatchingErr_0900', 0, async function (done) {
+ var cachedLocationsCb = (locations) => {
+ console.log('[lbs_js] cachedGnssLocationsReporting9:locations:' + JSON.stringify(locations));
+ expect(true).assertEqual(locations !=null);
+ }
+ try {
+ geolocationm.off(1,'cachedGnssLocationsChange',"test",cachedLocationsCb);
+ console.info('[lbs_js] cacheOff9' +JSON.stringify(cachedLocationsCb));
+ } catch (error) {
+ console.info("[lbs_js] cacheOff9 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0100
+ * @tc.name satelliteStatusChange_on_off
+ * @tc.desc Subscribe satellite status changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0100', 0, async function (done) {
+ var gnssStatusCb = (satelliteStatusInfo) => {
+ console.info('[lbs_js] gnssStatusChange1: ' + satelliteStatusInfo);
+ expect(true).assertEqual(satelliteStatusInfo != null);
+ }
+ try {
+ geolocationm.on(1,'satelliteStatusChange',gnssStatusCb);
+ console.info('[lbs_js] satelliteOn1' +JSON.stringify(gnssStatusCb));
+ } catch (error) {
+ console.info("[lbs_js] satelliteOn1 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0400
+ * @tc.name satelliteStatusChange_on_off
+ * @tc.desc Unsubscribe satellite status changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0400', 0, async function (done) {
+ var gnssStatusCb = (satelliteStatusInfo) => {
+ console.info('[lbs_js] gnssStatusChange4: ' + satelliteStatusInfo);
+ expect(true).assertEqual(satelliteStatusInfo != null);
+ }
+ try {
+ geolocationm.off(1,'satelliteStatusChange', "test",gnssStatusCb);
+ console.info('[lbs_js] satelliteOff4' +JSON.stringify(gnssStatusCb));
+ } catch (error) {
+ console.info("[lbs_js] satelliteOff4 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0200
+ * @tc.name locationChange_on_off
+ * @tc.desc Subscribe location changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0200', 0, async function (done) {
+ let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
+ "distanceInterval": 0, "maxAccuracy": 0};
+ var locationChange = (location) => {
+ console.log('[lbs_js] gnsslocationChanger2: data: ' + JSON.stringify(location));
+ expect(true).assertEqual(locationChange !=null);
+ };
+ try {
+ geolocationm.on(1,'locationChange', requestInfo,locationChange);
+ console.info('[lbs_js] locationChangeOn2' +JSON.stringify(locationChange));
+ } catch (error) {
+ console.info("[lbs_js] locationChangeOn2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0500
+ * @tc.name locationChange_on_off
+ * @tc.desc Unsubscribe location changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0500', 0, async function (done) {
+ var locationChange = (location) => {
+ console.log('[lbs_js] gnsslocationChanger5: data: ' + JSON.stringify(location));
+ expect(true).assertEqual(locationChange !=null);
+ };
+ try {
+ geolocationm.off(1,'locationChange',"test",locationChange);
+ console.info('[lbs_js] locationChangeOff5' +JSON.stringify(locationChange));
+ } catch (error) {
+ console.info("[lbs_js] locationChangeOff5 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0300
+ * @tc.name nmeaMessage_on_off
+ * @tc.desc Subscribe nmea message changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0300', 0, async function (done) {
+ var nmeaCb = (str) => {
+ console.log('[lbs_js] nmeaMessage: ' + str);
+ }
+ try {
+ geolocationm.on(1,'nmeaMessage',nmeaCb);
+ console.info('[lbs_js] nmeaMessageOn2' +JSON.stringify(nmeaCb));
+ } catch (error) {
+ console.info("[lbs_js] nmeaMessageOn2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GnssErr_0600
+ * @tc.name nmeaMessage_on_off
+ * @tc.desc Unsubscribe nmea message changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GnssErr_0600', 0, async function (done) {
+ var nmeaCb = (str) => {
+ console.log('[lbs_js] nmeaMessage: ' + str);
+ }
+ try {
+ geolocationm.off(1,'nmeaMessage',nmeaCb);
+ console.info('[lbs_js] nmeaMessageOff6' +JSON.stringify(nmeaCb));
+ } catch (error) {
+ console.info("[lbs_js] nmeaMessageOff6 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoFenceErr_0100
+ * @tc.name gnssFenceStatusChange_on_off
+ * @tc.desc Add a geofence and subscribe geo fence status changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GeoFenceErr_0100', 0, async function (done) {
+ let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""};
+ let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence};
+ let want = (wantAgent) => {
+ console.log('[lbs_js] wantAgent: ' + JSON.stringify(wantAgent));
+ };
+ try {
+ geolocationm.on(1,'gnssFenceStatusChange', geofenceRequest,
+ (want) => {
+ if(err){
+ console.info('[lbs_js] FenceStatusOn1 callback err:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info("[lbs_js] FenceStatusOn1 callback result:" + JSON.stringify(want));
+ expect(true).assertEqual(want !=null);
+ done();
+ });
+ } catch (error) {
+ console.info("[lbs_js] FenceStatusOn1 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_GeoFenceErr_0200
+ * @tc.name gnssFenceStatusChange_on_off
+ * @tc.desc Remove a geofence and unsubscribe geo fence status changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_GeoFenceErr_0200', 0, async function (done) {
+ let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""};
+ let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence};
+ let want = (wantAgent) => {
+ console.log('[lbs_js] wantAgent: ' + JSON.stringify(wantAgent));
+ };
+ try {
+ geolocationm.off(1,"test",'gnssFenceStatusChange',geofenceRequest,
+ (want) => {
+ if(err){
+ console.info('[lbs_js] FenceStatusOff2 callback err:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info("[lbs_js] FenceStatusOff2 callback result:" + JSON.stringify(want));
+ expect(true).assertEqual(want !=null);
+ });
+ } catch (error) {
+ console.info("[lbs_js] FenceStatusOff2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_LocSwitchErr_0100
+ * @tc.name locationEnabledChange_on_off
+ * @tc.desc Subscribe location switch changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_LocSwitchErr_0100', 0, async function (done) {
+ var locationServiceState = (state) => {
+ console.log('[lbs_js] locationServiceState: state: ' + JSON.stringify(state));
+ }
+ try {
+ geolocationm.on(1,'locationEnabledChange', locationServiceState);
+ console.info('[lbs_js] nEnabledChangeOn1' +JSON.stringify(locationServiceState));
+ } catch (error) {
+ console.info("[lbs_js] nEnabledChangeOn1 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_LocSwitchErr_0100
+ * @tc.name locationEnabledChange_on_off
+ * @tc.desc Unsubscribe location switch changed.
+ * @tc.type Function
+ * @tc.level since 9
+ */
+ it('SUB_HSS_LocationSystem_LocSwitchErr_0200', 0, async function (done) {
+ var locationServiceState = (state) => {
+ console.log('[lbs_js] locationServiceState: state: ' + JSON.stringify(state));
+ }
+ try {
+ geolocationm.off(1,'locationEnabledChange',locationServiceState);
+ console.info('[lbs_js] EnabledChangeOff2' +JSON.stringify(locationServiceState));
+ } catch (error) {
+ console.info("[lbs_js] EnabledChangeOff2 try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+})
diff --git a/location/geolocation_errorCode/src/main/js/default/test/LocationErrorTest.test.js b/location/geolocation_errorCode/src/main/js/default/test/LocationErrorTest.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..1ffbcbfb8373b94e95917e4067a529f1cf4bb5a3
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/js/default/test/LocationErrorTest.test.js
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import geolocation from '@ohos.geolocation';
+import geolocationm from '@ohos.geoLocationManager';
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
+import bundle from '@ohos.bundle'
+import osaccount from '@ohos.account.osAccount'
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 ,
+ TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303,
+ DAILY_LIFE_SERVICE : 0x304 ,NO_POWER : 0x305}
+let LocationRequestPriority = {UNSET : 0x200 ,ACCURACY : 0x201 ,LOW_POWER : 0x202 ,FIRST_FIX :0x203}
+let LocationPrivacyType = {
+ OTHERS : 0,
+ STARTUP: 1,
+ CORE_LOCATION : 2
+}
+
+function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+async function changedLocationMode(){
+ let result1 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result1));
+ if(!result1){
+ await geolocation.requestEnableLocation().then(async(result) => {
+ await sleep(3000);
+ console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
+ }).catch((error) => {
+ console.info("[lbs_js] promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ }
+ let result2 = geolocationm.isLocationEnabled();
+ console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result2));
+}
+
+async function enableLocationSwitch(){
+ function enableLocationSwitchCallback(){
+ return new Promise((resolve, reject)=>{
+ geolocation.requestEnableLocation((err, data) => {
+ if (err) {
+ console.info('[lbs_js] requestEnableLocation callback err is : ' + err );
+ }else {
+ console.info("[lbs_js] requestEnableLocation callback data: " + data);
+ expect(data).assertTrue();
+ }
+ });
+ })
+ }
+ await enableLocationSwitchCallback();
+ done();
+
+}
+
+
+async function applyPermission() {
+ let osAccountManager = osaccount.getAccountManager();
+ console.info("=== getAccountManager finish");
+ let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
+ console.info("LocalId is :" + localId);
+ let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
+ let atManager = abilityAccessCtrl.createAtManager();
+ if (atManager != null) {
+ let tokenID = appInfo.accessTokenId;
+ console.info('[permission] case accessTokenID is ' + tokenID);
+ let permissionName1 = 'ohos.permission.LOCATION';
+ let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
+ await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
+ console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
+ }).catch((err) => {
+ console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
+ });
+ await atManager.grantUserGrantedPermission(tokenID, permissionName2, 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');
+ }
+}
+
+describe('geolocationTest_LocErr', function () {
+ beforeAll(async function (done) {
+ console.info('beforeAll case');
+ await applyPermission();
+ await changedLocationMode();
+ done();
+ })
+
+ beforeEach(function () {
+ console.info('beforeEach case');
+ })
+ afterEach(function () {
+ })
+
+
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_SingleLocErr_0100
+ * @tc.name Test getCurrentLocation
+ * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_SingleLocErr_0100', 0, async function (done) {
+ try {
+ let currentLocationRequest = 1;
+ geolocationm.getCurrentLocation(currentLocationRequest, (err, result) => {
+ if (err) {
+ console.info("[lbs_js] getCurrentLocation1 callback err: " + JSON.stringify(err));
+ expect(err.code).assertEqual(401);
+ return;
+ } else {
+ console.info("[lbs_js] getCurrentLocation1 callback result:" + JSON.stringify(result));
+ expect(true).assertFalse();
+ }
+ });
+ } catch (error) {
+ console.error('[lbs_js] getCurrentLocation1 callback try err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_SingleLocErr_0200
+ * @tc.name Test getCurrentLocation
+ * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_SingleLocErr_0200', 0, async function (done) {
+ (async () => {
+ try {
+ let currentLocationRequest = 1;
+ let result = await geolocationm.getCurrentLocation(currentLocationRequest);
+ console.info("[wifi_test] getCurrentLocation2 promise:" + JSON.stringify(result));
+ } catch(error) {
+ console.info('[lbs_js] getCurrentLocation2 promise try err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })();
+ await sleep(600);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_SendCommandErr_0100
+ * @tc.name Test sendCommand
+ * @tc.desc An incorrect extended command is sent to each component of the location service subsystem.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_SendCommandErr_0100', 0, async function (done) {
+ let requestInfo = "lbstest";
+ try {
+ geolocationm.sendCommand(requestInfo,(err, result) => {
+ if (err) {
+ console.info('sendcommand callback err:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info('sendcommand callback result:' + JSON.stringify(result));
+ });
+ } catch (error) {
+ console.info('sendcommand callback try err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_SendCommandErr_0200
+ * @tc.name Test sendCommand
+ * @tc.desc An incorrect extended command is sent to each component of the location service subsystem.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_SendCommandErr_0200', 0, async function (done) {
+ let requestInfo = "test";
+ (async () => {
+ try {
+ let result = await geolocationm.sendCommand(requestInfo);
+ console.info("[lbs_js] sendCommand promise:" + JSON.stringify(result));
+ } catch(error) {
+ console.info('[lbs_js] sendCommand promise err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })();
+ await sleep(1500);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_BatchingErr_0100
+ * @tc.name Test getCachedGnssLocationsSize
+ * @tc.desc An incorrect parameter is used to obtain the number of GNSS cache locations reported at a time.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_BatchingErr_0100', 0, async function (done) {
+ try {
+ geolocationm.getCachedGnssLocationsSize("test",(err, data) => {
+ if (err) {
+ console.info('[lbs_js] getCachedSiz1 callback err is:' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info("[lbs_js] getCachedSiz1 callback data is:" + JSON.stringify(data));
+ expect(true).assertFalse();
+ });
+ } catch (error) {
+ console.info("[lbs_js] getCachedSiz1 callback try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(2000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_BatchingErr_0400
+ * @tc.name Test flushCachedGnssLocations
+ * @tc.desc All prepared GNSS locations are returned to the application and the underlying buffers are cleared.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_BatchingErr_0400', 0, async function (done) {
+ try {
+ geolocationm.flushCachedGnssLocations("test",(err, data) => {
+ if (err) {
+ console.info('[lbs_js] flushCachedGnssLocations4 callback err is : ' + JSON.stringify(err));
+ expect(err.code).assertEqual("401");
+ return;
+ }
+ console.info("[lbs_js] flushCachedGnssLocations4 callback data is: " + JSON.stringify(data));
+ expect(true).assertFalse();
+ });
+ } catch (error) {
+ console.info("[lbs_js] flushCachedGnssLocations4 callback try error:"+ JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ await sleep(2000);
+ done();
+ })
+
+ /**
+ * @tc.number SUB_HSS_LocationSystem_BatchingErr_0500
+ * @tc.name Test flushCachedGnssLocations
+ * @tc.desc All prepared GNSS locations are returned to the application and the underlying buffers are cleared.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 2
+ */
+ it('SUB_HSS_LocationSystem_BatchingErr_0500', 0, async function (done) {
+ (async () => {
+ try {
+ let result = await geolocationm.flushCachedGnssLocations(1);
+ console.info("[lbs_js] flushCachedGnssLocations5 promise successful :" + JSON.stringify(result));
+ } catch(error) {
+ console.info('[lbs_js] flushCachedGnssLocations5 promise err:' + JSON.stringify(error) +"code"+ error.code +"mes"+ error.message);
+ expect(error.code).assertEqual("401");
+ }
+ })();
+ await sleep(2000);
+ done();
+ })
+
+})
diff --git a/location/geolocation_errorCode/src/main/resources/base/element/string.json b/location/geolocation_errorCode/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..14f9c3a9210f78b12caf3b945dc2b2c0f63f7d3d
--- /dev/null
+++ b/location/geolocation_errorCode/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "OsAccountTest"
+ },
+ {
+ "name": "mainability_description",
+ "value": "JS_Phone_Empty Feature Ability"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/location/geolocation_errorCode/src/main/resources/base/media/icon.png b/location/geolocation_errorCode/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/location/geolocation_errorCode/src/main/resources/base/media/icon.png differ