From 7cf8cd0208a632022ed711e017183113cefc92e6 Mon Sep 17 00:00:00 2001 From: quanli Date: Wed, 30 Nov 2022 04:40:39 +0800 Subject: [PATCH] quanli1@huawei.com Signed-off-by: quanli --- communication/BUILD.gn | 1 + communication/bluetooth_manager/BUILD.gn | 35 + communication/bluetooth_manager/Test.json | 20 + .../signature/openharmony_sx.p7b | Bin 0 -> 3647 bytes .../bluetooth_manager/src/main/config.json | 137 + .../src/main/js/MainAbility/app.js | 23 + .../src/main/js/MainAbility/i18n/en-US.json | 6 + .../src/main/js/MainAbility/i18n/zh-CN.json | 6 + .../main/js/MainAbility/pages/index/index.css | 24 + .../main/js/MainAbility/pages/index/index.hml | 20 + .../main/js/MainAbility/pages/index/index.js | 32 + .../src/main/js/TestAbility/app.js | 31 + .../src/main/js/TestAbility/i18n/en-US.json | 8 + .../src/main/js/TestAbility/i18n/zh-CN.json | 8 + .../main/js/TestAbility/pages/index/index.css | 30 + .../main/js/TestAbility/pages/index/index.hml | 5 + .../main/js/TestAbility/pages/index/index.js | 26 + .../js/TestRunner/OpenHarmonyTestRunner.js | 59 + .../src/main/js/test/BleAdvertiser.test.js | 948 +++++++ .../src/main/js/test/BleAdvertiser401.test.js | 588 +++++ .../src/main/js/test/BleGattManager.test.js | 972 +++++++ .../main/js/test/BleGattManager401.test.js | 2316 +++++++++++++++++ .../src/main/js/test/BleScanResult.test.js | 797 ++++++ .../src/main/js/test/BleService.test.js | 1190 +++++++++ .../src/main/js/test/List.test.js | 31 + .../src/main/js/test/SwitchOff003.test.js | 1128 ++++++++ .../main/resources/base/element/string.json | 28 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes location/BUILD.gn | 10 +- location/geolocation_errorCode/BUILD.gn | 37 + location/geolocation_errorCode/Test.json | 24 + .../signature/openharmony_sx.p7b | Bin 0 -> 3833 bytes .../src/main/config.json | 131 + .../src/main/js/default/app.js | 36 + .../src/main/js/default/i18n/en-US.json | 6 + .../src/main/js/default/i18n/zh-CN.json | 6 + .../src/main/js/default/pages/index/index.css | 9 + .../src/main/js/default/pages/index/index.hml | 5 + .../src/main/js/default/pages/index/index.js | 31 + .../js/default/test/GeocoderErrorTest.test.js | 191 ++ .../default/test/GetCountryCodeError.test.js | 109 + .../src/main/js/default/test/List.test.js | 20 + .../js/default/test/ListeningError.test.js | 465 ++++ .../js/default/test/LocationErrorTest.test.js | 293 +++ .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes 46 files changed, 9852 insertions(+), 2 deletions(-) create mode 100644 communication/bluetooth_manager/BUILD.gn create mode 100644 communication/bluetooth_manager/Test.json create mode 100644 communication/bluetooth_manager/signature/openharmony_sx.p7b create mode 100644 communication/bluetooth_manager/src/main/config.json create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/app.js create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/i18n/en-US.json create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/i18n/zh-CN.json create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.css create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.hml create mode 100644 communication/bluetooth_manager/src/main/js/MainAbility/pages/index/index.js create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/app.js create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/i18n/en-US.json create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/i18n/zh-CN.json create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.css create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.hml create mode 100644 communication/bluetooth_manager/src/main/js/TestAbility/pages/index/index.js create mode 100644 communication/bluetooth_manager/src/main/js/TestRunner/OpenHarmonyTestRunner.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/BleService.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/List.test.js create mode 100644 communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js create mode 100644 communication/bluetooth_manager/src/main/resources/base/element/string.json create mode 100644 communication/bluetooth_manager/src/main/resources/base/media/icon.png create mode 100644 location/geolocation_errorCode/BUILD.gn create mode 100644 location/geolocation_errorCode/Test.json create mode 100644 location/geolocation_errorCode/signature/openharmony_sx.p7b create mode 100644 location/geolocation_errorCode/src/main/config.json create mode 100644 location/geolocation_errorCode/src/main/js/default/app.js create mode 100644 location/geolocation_errorCode/src/main/js/default/i18n/en-US.json create mode 100644 location/geolocation_errorCode/src/main/js/default/i18n/zh-CN.json create mode 100644 location/geolocation_errorCode/src/main/js/default/pages/index/index.css create mode 100644 location/geolocation_errorCode/src/main/js/default/pages/index/index.hml create mode 100644 location/geolocation_errorCode/src/main/js/default/pages/index/index.js create mode 100644 location/geolocation_errorCode/src/main/js/default/test/GeocoderErrorTest.test.js create mode 100644 location/geolocation_errorCode/src/main/js/default/test/GetCountryCodeError.test.js create mode 100644 location/geolocation_errorCode/src/main/js/default/test/List.test.js create mode 100644 location/geolocation_errorCode/src/main/js/default/test/ListeningError.test.js create mode 100644 location/geolocation_errorCode/src/main/js/default/test/LocationErrorTest.test.js create mode 100644 location/geolocation_errorCode/src/main/resources/base/element/string.json create mode 100644 location/geolocation_errorCode/src/main/resources/base/media/icon.png diff --git a/communication/BUILD.gn b/communication/BUILD.gn index 08aed1123..7e7ac0c77 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 000000000..80a55acca --- /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 000000000..41e138953 --- /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 GIT binary patch literal 3647 zcmcgvdvp_38gCvg7HFv!0a2g?q%0-voixuX;!HA0Ce0+BG-;X`tdnH&Xp)(bNit0k zWW!oT1ef)!us}7uaRuB1Xl2h4AG?D1T$IHcJLd#Ll+2c9n zkIa1E{qDWL`+dLfch7)A^&J(J^Lov_Usj36h>L~l`JhleS1b}iRbX62<$b+o5ham| zMW9eVa5Yd=ER?@3EtDT!BFj=KHpWDEA9XjJ*!i01#DNJD4t|*#Q!PPs-Rq_0$Mq#qX5*b z42392E9^tYqrqr8Cu>TGDYa^qLZzKw@{^%7mEzrMtxl`96?lc@wl=lIxBX9-ZLbTkwV zkZIvaa^Z)dCd^i+M;%Vgi0NS`TJrj69K-aEyj~9n)M1#z5IBsXoyK(3=!9F5aCmVf z)@^Si2m{=WbmIie=?RaagCI;OXE8XtQ5U}gf|+2*h3dnc)!B^1{jo?Skbts&I@V)y z!ktLi)`7q*j-oow>sDc&PD|RaP^mDZBkpm79v_Y6;mA-Fj+~v0Hba2J0w{Zo2Dp7_ zM+Vme9p|G*BEuaq&d8O{X*D27Tfo$jX*U^jetv(d9dUWx#x&j@<}Be-jKP5D+I;ji zQAogyu%z1-37XNX@ zO%6-0J!?hOK$)?)BWf+3BVrAm9+%RsHMz8Tg%L7%Ja$#6-KasV){vJ7_-HN`Yzs5F zCfKS{HZ=h#&xYbTm8H{>@g|f2i#ZnCQhbUzvrt6`up@{EHJUZ7m9evIH<9(xk)+1a zga<4Z9M|O&F7t5af+$DmaTw+d!kHbQ4JOP@2+Z>$Ou;yU3)u}?2m0i*A&cd zlP%)GUERNgF+~Y78%XmoM~&Pg#PT>Zf)dJ-v1mzoQ#7A|rNu(UKS4o!Cn$(sDoVs6 zu~@3vnK%T-SKPqg4(}|GN+jiFAOMX6l@$_~w4zq5w?PxZO@cADcH9VUgl++o1@E}p zni1YQCq*WpSzx9xB&nS`atKZ)Q-``#ypfAG-PI zFXnF8W7MpuT0cYd_dWA||LDnq)6?-?n$IQgeR`M{H#is0cbv9@y3?;cmaBcWFv zp0Z&p-`QXW4`_RA*yaopzC{=wUq9Q?F==@z*OR0{zUM56ynr4sR& zeIed;;0NyLjBg-OR-Jrd`<6>xH(#1FV^wOf?kCd-)`Kn6j4}OdD+2BY69l5v z3dAV~68Xi)$fjfq2=K82ba%N<$c>X-zInAhW}*Hv&n7QzD*awy2bXjxf44lA8*+4j%iA7InN`K=h4|=9!;lS zUN9QTb*$b9F@jXhijh1L%(A?mN&h}^30){BPVLlEDhDz&zfDQRxZCK(vSW7___X@-#d5WMqaEA z-@tHBx1=^Z`sc_mJ=eMWwI`mac{P5=;H1KB-#mQMwmNlo4S6Q%Nv{sSp?vC&4;!I^ z2Okqp}>Dz+Z~|g$UF@tJHvI zFKD_tDurayI@Mw~ct|-me7W`BS(omACH3gKt>AcVdho5*zJX(J9%=<+uiWHfsR^Ls znPo-u0vstKd#zP{3&$R~@Q2-F@y&Nyi?!;tcN-=YUw>X)SJ}J9)OvE!skef!40zpL Wb)97!mfV{9Aewg{_yC>Of9ikgCzfge literal 0 HcmV?d00001 diff --git a/communication/bluetooth_manager/src/main/config.json b/communication/bluetooth_manager/src/main/config.json new file mode 100644 index 000000000..2b3e44f06 --- /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 000000000..363f2555b --- /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 000000000..a4c13dcbd --- /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 000000000..b1c02368f --- /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 000000000..e84b0d630 --- /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 000000000..43848d302 --- /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 000000000..014e63a26 --- /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 000000000..cdc31f3dc --- /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 000000000..3cb24b374 --- /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 000000000..c804e32c0 --- /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 000000000..b1bcd4338 --- /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 000000000..f629c71a9 --- /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 000000000..88b083a7f --- /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 000000000..c5fa8620c --- /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 000000000..71ea19e33 --- /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 000000000..e770c8ff8 --- /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 000000000..5a86892e0 --- /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 000000000..ed7b5f7c0 --- /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 000000000..5093ede64 --- /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 000000000..42c8d5d41 --- /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 000000000..ac47b6163 --- /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 000000000..36950999a --- /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 000000000..d4b2a0a05 --- /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 GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}yD+hMJX)Cmx>e)S> zL;vXH-tYH)-*4{y-Fwe~e94!pq8q!cU0)Z=#>so~C4U3?l8@vv8Bz?!tBRI&S!Jw3 zDVKq~YSU$)tS7Hpqs*)BTCVP3Q|TDbX@Y!+Ro5YlE;%?R0Uc_j3RD60B6TJc3qey4 zw6y`Fk=5wK@Smny;g5nH0Wo-0-J*F z8iP?+TMgYS7O4XnE)-`qF)qwY+e2&z8|Ra3N;62^o@6;IlS=ShC%k7AnIM}IV&Pbj z5hT_c=?}vR(pF)@oo>=Xnou`B=xyOBk~C2{lL-y55mY2GG(zHx-LyDoMky>3X^*zG z+8s1)Mnw-w5meTcL+i1K&5NNvH`->i!xNmeh(~;8FHJASMZpmyycri^=?pX)GprkL zrm!G^A|Bk7rD%6G77w&Vqrn8y5#ZV)Ucwt~;R0^Fl``RjC^SnkSEA@9Obih5R$r4d z8PMt?G{8k`G-#t*agl08J0S-*nYFvAY$NpA%xzh!mC9c7wPHL)r$rMz$dSOsdb7I~ z_fQx)#4AcQv~XA4nI+t4)6jdS-8gO(n;Z3{uc=-LX!Uy1;*9$mL3XJbO$=cucME3) zSDGH2Nlc1#3pW&N3d2O32}RujpWQ^$ z$wqxR)aJ9=bovg^RE=7hETV07U?JShr!7vh8DX0eS-UUiB3ih5kqW1+QIE$6a6_B~ z?j~O|XG=sVB+YkZ0xaE*x_N{YJ!Uj4F}J!XoG_z}5zHNkrh>5+&LVgkcu%If+U2dy zgmFulAq8g+wGX0c1BQkTIEGRtOoxhADWXnb$1opmaR}K|CK_+yf=-N1*N4Plb9+O^ z$lE;L2t%PFVKTK7E=p&FyUiGlni&)on`ttO)(Z@9(AuQVOlB4*(=A*B6>2bB7)7&O_$WLPlJC@ET98C2WI#=Wt{d<&OD;}&2r zbAkGl-7eTUx?L|??T)zFhw1EsCujH7!()QHkixn8Y<-SMM;EtngC&96%wv=Ztgzu~ z9PT50luuVNK_Oig=V6_}Vy}v@{H5RF3>O^k08BCti;&|}2__DYkvd11WrU2>1=R2q zf4Va*un9k0P{X2Ug7LIe?Myt*i)=_UWZ$kHybuEU*hHo`Rq zkZ__lHw4&Rq?`2Oeh2QPNS6z~$yjJ7?zJzK&imis1n%}@kYEE230v%bhm-V@4LE_1 zMfnP_`VJWV%K;utLW-4Id{BUS7`1Y{goTO7NIhGfY>N$c{S*f?yaLXmPe5LNGsw$c z=uyaJa=Eg0cj9?4L3IrrY;WG8R457yKoA)Zic|`ZQdK55*^tR#l4M+4Hhx4~N3I9c zB=7jL(h=SYH_IfDxnPd8q$ry)atTc)<5Js)0;w>eVD_|PEdsPai)i6f-#o2YXGFBs z$gl~LKavChRYN2yzmJ3?#fM{Yw!%3yIe`z9sm2Y4K`tAPhe9?^ffXnl-;)2czxTjL zX#4Y1Uj6lghxS=&R~L7e%l@(N#y{Ts;nCx>sXet{D&G10ASYkwzODR)S9<6TMN|Lq zfbLBNx9;HdhjuuD1C&ELv*s$NgQ=?~|D~%>J@viu+m`kX+_1d=^THL|H3TS;025`h z|0tCT`M6bJmSmSGrz$7E&YXH~cg}YBtp}gH>rCN=ul&U_=jfa%Vg(>9M+)}dx4$SK z=-h9ecO7=-S8RV&bzsugQqgkjg)`f``#!?%4;>AEd3^V|jP2YRw(H zIH3+bGw+Uu!a4W+zIT-!95w&-p7{gL886CAdrr-Ja)-V&`{>2=%99^Yd=l!%4E6Ks zuzn^UH>?}Y1w?;j>K1_cL#ZqOzSKE+UbsR;hz>D~5YeD{6`6E^(#zs0T=)xRfm#tL zP*ODmog3PUS8q96Tz~N50{+t=npnELUo(D7$8)EBzPE4RynRXj+h^YODT#Fy(Vg6g z?b_ROuHS#&-8-RVAh_oKKNHvOxV!knXLoHs@1Jshe)+o8K*djI(P|tHQJ-tswQZ*6;lnTU%DFLLrLb8J<~=^| zm;4=j=Z z09FnXM}KBm{Tt!zoxlC2F6w{uP|d?9o-aLgr0m3saH;*I)pKm^s_UbDM_$uC za?=M@NM5!CitJ|il?K|bN*aeJ>c|hmo*0;Z>4UIHfxxxzJ|ksd<|U)35Sa*vA{>aI z79faTuWts6FRv;QwX$OC66G + + {{ $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 000000000..3a5f99e66 --- /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 000000000..7e38ab815 --- /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 000000000..90dbbd669 --- /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 000000000..5dcc745a4 --- /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 000000000..9d48ab74f --- /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 000000000..1ffbcbfb8 --- /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 000000000..14f9c3a92 --- /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 GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y